platform/x86: x86-android-tablets: Unregister devices in reverse order
PATCH 1/3 platform/x86: x86-android-tablets: Unregister devices in reverse order
Not all subsystems support a device getting removed while there are still consumers of the device with a reference to the device.
One example of this is the regulator subsystem. If a regulator gets unregistered while there are still drivers holding a reference a WARN() at drivers/regulator/core.c:5829 triggers, e.g.:
WARNING: CPU: 1 PID: 1587 at drivers/regulator/core.c:5829 regulator_unregister Hardware name: Intel Corp. VALLEYVIEW C0 PLATFORM/BYT-T FFD8, BIOS BLADE_21.X64.0005.R00.1504101516 FFD8_X64_R_2015_04_10_1516 04/10/2015 RIP: 0010:regulator_unregister Call Trace: <TASK> regulator_unregister devres_release_group i2c_device_remove device_release_driver_internal bus_remove_device device_del device_unregister x86_android_tablet_remove
On the Lenovo Yoga Tablet 2 series the bq24190 charger chip also provides a 5V boost converter output for powering USB devices connected to the micro USB port, the bq24190-charger driver exports this as a Vbus regulator.
On the 830 (8") and 1050 ("10") models this regulator is controlled by a platform_device and x86_android_tablet_remove() removes platform_device-s before i2c_clients so the consumer gets removed first.
But on the 1380 (13") model there is a lc824206xa micro-USB switch connected over I2C and the extcon driver for that controls the regulator. The bq24190 i2c-client *must* be registered first, because that creates the regulator with the lc824206xa listed as its consumer. If the regulator has not been registered yet the lc824206xa driver will end up getting a dummy regulator.
Since in this case both the regulator provider and consumer are I2C devices, the only way to ensure that the consumer is unregistered first is to unregister the I2C devices in reverse order of in which they were created.
For consistency and to avoid similar problems in the future change x86_android_tablet_remove() to unregister all device types in reverse order.
--- drivers/platform/x86/x86-android-tablets/core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/platform/x86/x86-android-tablets/core.c +4 -4
@@ -278,25 +278,25 @@ static void x86_android_tablet_remove(struct platform_device *pdev) {int i; -for (i =0 ; i < serdev_count; i++) { +for (i = serdev_count -1 ; i >=0 ; i--) {if (serdevs[i])serdev_device_remove (serdevs[i]); }kfree (serdevs); -for (i =0 ; i < pdev_count; i++) +for (i = pdev_count -1 ; i >=0 ; i--)platform_device_unregister (pdevs[i]);kfree (pdevs);kfree (buttons); -for (i =0 ; i < spi_dev_count; i++) +for (i = spi_dev_count -1 ; i >=0 ; i--)spi_unregister_device (spi_devs[i]);kfree (spi_devs); -for (i =0 ; i < i2c_client_count; i++) +for (i = i2c_client_count -1 ; i >=0 ; i--)i2c_unregister_device (i2c_clients[i]);kfree (i2c_clients);
Signature · 1 line
2.44.0
PATCH 2/3 platform/x86: x86-android-tablets: Add Lenovo Yoga Tablet 2 Pro 1380F/L data
The Lenovo Yoga Tablet 2 Pro 1380F/L is a x86 ACPI tablet which ships with Android x86 as factory OS. Its DSDT contains a bunch of I2C devices which are not actually there, causing various resource conflicts. Enumeration of these is skipped through the acpi_quirk_skip_i2c_client_enumeration().
Add support for manually instantiating the I2C + other devices which are actually present on this tablet by adding the necessary device info to the x86-android-tablets module.
--- .../platform/x86/x86-android-tablets/dmi.c | 18 ++ .../platform/x86/x86-android-tablets/lenovo.c | 216 ++++++++++++++++++ .../x86-android-tablets/x86-android-tablets.h | 1 + 3 files changed, 235 insertions(+)
drivers/platform/x86/x86-android-tablets/dmi.c +18 -0
@@ -104,6 +104,24 @@ const struct dmi_system_id x86_android_tablet_ids[] __initconst = { }, .driver_data = (void *)&lenovo_yogabook_x91_info, }, + { +/* +* Lenovo Yoga Tablet 2 Pro 1380F/L (13") This has more or less +* the same BIOS as the 830F/L or 1050F/L (8" and 10") below, +* but unlike the 8" / 10" models which share the same mainboard +* this model has a different mainboard. +* This match for the 13" model MUST come before the 8" + 10" +* match since that one will also match the 13" model! +*/ + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Intel Corp." ), +DMI_MATCH (DMI_PRODUCT_NAME ,"VALLEYVIEW C0 PLATFORM" ), +DMI_MATCH (DMI_BOARD_NAME ,"BYT-T FFD8" ), +/* Full match so as to NOT match the 830/1050 BIOS */ + DMI_MATCH(DMI_BIOS_VERSION, "BLADE_21.X64.0005.R00.1504101516"), + }, + .driver_data = (void *)&lenovo_yoga_tab2_1380_info, + }, {/* * Lenovo Yoga Tablet 2 830F/L or 1050F/L (The 8" and 10"
drivers/platform/x86/x86-android-tablets/lenovo.c +216 -0
228 lines not on this page · raw message
drivers/platform/x86/x86-android-tablets/x86-android-tablets.h +1 -0
@@ -112,6 +112,7 @@ extern const struct x86_dev_info czc_p10t;extern const struct x86_dev_info lenovo_yogabook_x90_info;extern const struct x86_dev_info lenovo_yogabook_x91_info;extern const struct x86_dev_info lenovo_yoga_tab2_830_1050_info; +extern const struct x86_dev_info lenovo_yoga_tab2_1380_info;extern const struct x86_dev_info lenovo_yt3_info;extern const struct x86_dev_info medion_lifetab_s10346_info;extern const struct x86_dev_info nextbook_ares8_info;
Signature · 1 line
2.44.0
PATCH 3/3 platform/x86: Add lenovo-yoga-tab2-pro-1380-fastcharger driver
In reply to Hans de GoedeAdd a new driver for the custom fast charging protocol found on Lenovo Yoga Tablet 2 1380F / 1380L models.
--- drivers/platform/x86/Kconfig | 11 + drivers/platform/x86/Makefile | 1 + .../lenovo-yoga-tab2-pro-1380-fastcharger.c | 340 ++++++++++++++++++ 3 files changed, 352 insertions(+) create mode 100644 drivers/platform/x86/lenovo-yoga-tab2-pro-1380-fastcharger.c
drivers/platform/x86/Kconfig +11 -0
@@ -133,6 +133,17 @@ config YOGABOOK To compile this driver as a module, choose M here: the module will be called lenovo-yogabook. +config YT2_1380 + tristate "Lenovo Yoga Tablet 2 1380 fast charge driver" + depends on SERIAL_DEV_BUS + depends on ACPI + help + Say Y here to enable support for the custom fast charging protocol + found on the Lenovo Yoga Tablet 2 1380F / 1380L models. + + To compile this driver as a module, choose M here: the module will + be called lenovo-yogabook. + config ACERHDF tristate "Acer Aspire One temperature and fan driver" depends on ACPI && THERMAL
drivers/platform/x86/Makefile +1 -0
@@ -66,6 +66,7 @@ obj-$(CONFIG_SENSORS_HDAPS) += hdaps.o obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.o obj-$(CONFIG_THINKPAD_LMI) += think-lmi.o obj-$(CONFIG_YOGABOOK) += lenovo-yogabook.o +obj-$(CONFIG_YT2_1380) += lenovo-yoga-tab2-pro-1380-fastcharger.o obj-$(CONFIG_LENOVO_WMI_CAMERA) += lenovo-wmi-camera.o # Intel
drivers/platform/x86/lenovo-yoga-tab2-pro-1380-fastcharger.c new file +340 -0
340 lines not on this page · raw message
Signature · 1 line
2.44.0
Re: [PATCH 3/3] platform/x86: Add lenovo-yoga-tab2-pro-1380-fastcharger driver
Quoted 3 lines · Hans de Goede
Add a new driver for the custom fast charging protocol found on Lenovo Yoga Tablet 2 1380F / 1380L models.
...
Quoted 1 line
+#include <
linux/delay.h>
+ err.h
+ errno.h
drivers/platform/x86/lenovo-yoga-tab2-pro-1380-fastcharger.c line 12
Quoted 2 lines
drivers/platform/x86/lenovo-yoga-tab2-pro-1380-fastcharger.c new file +2
-0+#include <linux/extcon.h> +#include <linux/gpio/consumer.h>
+ mod_devicetable.h
drivers/platform/x86/lenovo-yoga-tab2-pro-1380-fastcharger.c line 18
Quoted 6 lines
drivers/platform/x86/lenovo-yoga-tab2-pro-1380-fastcharger.c new file +6
-0+#include <linux/module.h> +#include <linux/notifier.h> +#include <linux/pinctrl/consumer.h> +#include <linux/pinctrl/machine.h> +#include <linux/platform_device.h> +#include <linux/serdev.h>
+ types.h
Quoted 2 lines
drivers/platform/x86/lenovo-yoga-tab2-pro-1380-fastcharger.c new file +2
-0+#include <linux/workqueue.h> +#include "serdev_helpers.h"
...
drivers/platform/x86/lenovo-yoga-tab2-pro-1380-fastcharger.c line 30
Quoted 3 lines
drivers/platform/x86/lenovo-yoga-tab2-pro-1380-fastcharger.c new file +3
-0+#define YT2_1380_FC_PIN_SW_DELAY_US 10000 +#define YT2_1380_FC_UART_DRAIN_DELAY_US 50000 +#define YT2_1380_FC_VOLT_SW_DELAY_US 1000000
Hmm... perhaps
10 * USEC_PER_MSEC
50 * USEC_PER_MSEC
1 * USEC_PER_SEC
?
...
drivers/platform/x86/lenovo-yoga-tab2-pro-1380-fastcharger.c line 65
Quoted 6 lines
drivers/platform/x86/lenovo-yoga-tab2-pro-1380-fastcharger.c new file +6
-0+static bool yt2_1380_fc_dedicated_charger_connected (struct yt2_1380_fc *fc) +{ +int ret; + + ret =extcon_get_state (fc->extcon,EXTCON_CHG_USB_DCP ); +return ret >0 ;
This and other functions can be shorter by eliminating the ret variable, but it's up to you.
Quoted 1 line
+}
...
Quoted 1 line
+ ret =
serdev_device_write_buf(to_serdev_device(fc->dev), "SC", 2);
Hmm... I would replace magic 2 in both cases by strlen("SC") or so.
Quoted 4 lines
drivers/platform/x86/lenovo-yoga-tab2-pro-1380-fastcharger.c new file +4
-0+if (ret !=2 ) { +dev_err (fc->dev,"Error %d writing to uart\n" , ret); +return ; + }
...
drivers/platform/x86/lenovo-yoga-tab2-pro-1380-fastcharger.c line 307
Quoted 7 lines
drivers/platform/x86/lenovo-yoga-tab2-pro-1380-fastcharger.c new file +7
-0+static struct platform_driver yt2_1380_fc_pdev_driver = { + .probe = yt2_1380_fc_pdev_probe, + .remove_new = yt2_1380_fc_pdev_remove, + .driver = { + .name =YT2_1380_FC_PDEV_NAME , + .probe_type =PROBE_PREFER_ASYNCHRONOUS , + },
+ .id_table = ... (see below why)
drivers/platform/x86/lenovo-yoga-tab2-pro-1380-fastcharger.c line 337
Quoted 3 lines
drivers/platform/x86/lenovo-yoga-tab2-pro-1380-fastcharger.c new file +2
-0+}; +MODULE_ALIAS ("platform:" YT2_1380_FC_PDEV_NAME );
The _standard_ MODULE_ALIAS() is not an excuse to have no ID table. Just provide an accurate platform device ID table instead.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 3/3] platform/x86: Add lenovo-yoga-tab2-pro-1380-fastcharger driver
Hi,
Quoted 9 lines · Andy Shevchenko
Quoted 3 lines · Hans de Goede
Add a new driver for the custom fast charging protocol found on Lenovo Yoga Tablet 2 1380F / 1380L models.
...
Quoted 1 line
+#include <
linux/delay.h>
Quoted 7 lines
+
err.h
+errno.hdrivers/platform/x86/lenovo-yoga-tab2-pro-1380-fastcharger.c line 12
Quoted 2 lines
drivers/platform/x86/lenovo-yoga-tab2-pro-1380-fastcharger.c new file +2
-0+#include <linux/extcon.h> +#include <linux/gpio/consumer.h> +
mod_devicetable.h
This one won't be necessary, see below.
Quoted 10 lines
drivers/platform/x86/lenovo-yoga-tab2-pro-1380-fastcharger.c line 18
Quoted 7 lines
drivers/platform/x86/lenovo-yoga-tab2-pro-1380-fastcharger.c new file +6
-0+#include <linux/module.h> +#include <linux/notifier.h> +#include <linux/pinctrl/consumer.h> +#include <linux/pinctrl/machine.h> +#include <linux/platform_device.h> +#include <linux/serdev.h> +
types.h
Quoted 2 lines
drivers/platform/x86/lenovo-yoga-tab2-pro-1380-fastcharger.c line 20
Quoted 2 lines
drivers/platform/x86/lenovo-yoga-tab2-pro-1380-fastcharger.c new file +2
-0+#include <linux/workqueue.h> +#include "serdev_helpers.h"
Ack others added for v2.
Quoted 9 lines
...
drivers/platform/x86/lenovo-yoga-tab2-pro-1380-fastcharger.c line 30
Quoted 3 lines
drivers/platform/x86/lenovo-yoga-tab2-pro-1380-fastcharger.c new file +3
-0+#define YT2_1380_FC_PIN_SW_DELAY_US 10000 +#define YT2_1380_FC_UART_DRAIN_DELAY_US 50000 +#define YT2_1380_FC_VOLT_SW_DELAY_US 1000000Hmm... perhaps
Quoted 5 lines
10 *
USEC_PER_MSEC
50 *USEC_PER_MSEC
1 *USEC_PER_SEC?
Ack, changed for v2.
Quoted 14 lines
...
drivers/platform/x86/lenovo-yoga-tab2-pro-1380-fastcharger.c line 65
Quoted 6 lines
drivers/platform/x86/lenovo-yoga-tab2-pro-1380-fastcharger.c new file +6
-0+static bool yt2_1380_fc_dedicated_charger_connected (struct yt2_1380_fc *fc) +{ +int ret; + + ret =extcon_get_state (fc->extcon,EXTCON_CHG_USB_DCP ); +return ret >0 ;This and other functions can be shorter by eliminating the ret variable, but it's up to you.
Quoted 1 line
+}
Ack, changed for v2.
Quoted 6 lines
...
Quoted 1 line
+ ret =
serdev_device_write_buf(to_serdev_device(fc->dev), "SC", 2);Hmm... I would replace magic 2 in both cases by
strlen("SC")or so.
Ack, changed for v2.
Quoted 16 lines
Quoted 5 lines
drivers/platform/x86/lenovo-yoga-tab2-pro-1380-fastcharger.c new file +4
-0+if (ret !=2 ) { +dev_err (fc->dev,"Error %d writing to uart\n" , ret); +return ; + }...
drivers/platform/x86/lenovo-yoga-tab2-pro-1380-fastcharger.c line 307
Quoted 7 lines
drivers/platform/x86/lenovo-yoga-tab2-pro-1380-fastcharger.c new file +7
-0+static struct platform_driver yt2_1380_fc_pdev_driver = { + .probe = yt2_1380_fc_pdev_probe, + .remove_new = yt2_1380_fc_pdev_remove, + .driver = { + .name =YT2_1380_FC_PDEV_NAME , + .probe_type =PROBE_PREFER_ASYNCHRONOUS , + },
Quoted 8 lines
+ .id_table = ... (see below why)
drivers/platform/x86/lenovo-yoga-tab2-pro-1380-fastcharger.c line 337
Quoted 3 lines
drivers/platform/x86/lenovo-yoga-tab2-pro-1380-fastcharger.c new file +2
-0+}; +MODULE_ALIAS ("platform:" YT2_1380_FC_PDEV_NAME );The _standard_
MODULE_ALIAS()is not an excuse to have no ID table. Just provide an accurate platform device ID table instead.
I personally have no strong preference either way (although the MODULE_ALIAS way seems to be used the most in other code), but in this specific case adding a platform_device_id table does not work:
drivers/platform/x86/lenovo-yoga-tab2-pro-1380-fastcharger.c:26:41: warning: initializer-string for array of ‘char’ is too long
26 | #define YT2_1380_FC_PDEV_NAME "lenovo-yoga-tab2-pro-1380-fastcharger"
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~from mod_devicetable.h:
#define PLATFORM_NAME_SIZE 20
#define PLATFORM_MODULE_PREFIX "platform:"
struct platform_device_id {
char name[PLATFORM_NAME_SIZE];
kernel_ulong_t driver_data;
};So the driver / pdev name can only by 20 chars, I tried shortening:
"lenovo-yoga-tab2-pro-1380-fastcharger"
to:
"lenovo-yt2-pro-fastcharger"
But that still is too long, making it even shorter will make the name really cryptic, where as without using the platform_device_id approach things work fine, so I'm going to stick with the MODULE_ALIAS() for v2.
Regards,
Hans
Hi All,
I've added patch 1/3 and 2/3 of this series to my review-hans (soon to be for-next) branch now.
I'll send out a v2 of patch 3/3 to address the review comments.
Regards,
Hans
Quoted 84 lines · Hans de Goede
Not all subsystems support a device getting removed while there are still consumers of the device with a reference to the device.
One example of this is the regulator subsystem. If a regulator gets unregistered while there are still drivers holding a reference a
WARN()atdrivers/regulator/core.c:5829triggers, e.g.:WARNING: CPU: 1 PID: 1587 at drivers/regulator/core.c:5829 regulator_unregister Hardware name: Intel Corp. VALLEYVIEW C0 PLATFORM/BYT-T FFD8, BIOS BLADE_21.X64.0005.R00.1504101516 FFD8_X64_R_2015_04_10_1516 04/10/2015 RIP: 0010:regulator_unregister Call Trace: <TASK> regulator_unregister devres_release_group i2c_device_remove device_release_driver_internal bus_remove_device device_del device_unregister x86_android_tablet_removeOn the Lenovo Yoga Tablet 2 series the bq24190 charger chip also provides a 5V boost converter output for powering USB devices connected to the micro USB port, the bq24190-charger driver exports this as a Vbus regulator.
On the 830 (8") and 1050 ("10") models this regulator is controlled by a
platform_deviceandx86_android_tablet_remove()removes platform_device-s beforei2c_clientsso the consumer gets removed first.But on the 1380 (13") model there is a lc824206xa micro-USB switch connected over I2C and the extcon driver for that controls the regulator. The bq24190 i2c-client *must* be registered first, because that creates the regulator with the lc824206xa listed as its consumer. If the regulator has not been registered yet the lc824206xa driver will end up getting a dummy regulator.
Since in this case both the regulator provider and consumer are I2C devices, the only way to ensure that the consumer is unregistered first is to unregister the I2C devices in reverse order of in which they were created.
For consistency and to avoid similar problems in the future change
x86_android_tablet_remove()to unregister all device types in reverse order.Signed-off-by Hans de Goede <[email protected]>--- drivers/platform/x86/x86-android-tablets/core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/platform/x86/x86-android-tablets/core.c +4
-4@@ -278,25 +278,25 @@ static void x86_android_tablet_remove(struct platform_device *pdev) {int i; -for (i =0 ; i < serdev_count; i++) { +for (i = serdev_count -1 ; i >=0 ; i--) {if (serdevs[i])serdev_device_remove (serdevs[i]); }kfree (serdevs); -for (i =0 ; i < pdev_count; i++) +for (i = pdev_count -1 ; i >=0 ; i--)platform_device_unregister (pdevs[i]);kfree (pdevs);kfree (buttons); -for (i =0 ; i < spi_dev_count; i++) +for (i = spi_dev_count -1 ; i >=0 ; i--)spi_unregister_device (spi_devs[i]);kfree (spi_devs); -for (i =0 ; i < i2c_client_count; i++) +for (i = i2c_client_count -1 ; i >=0 ; i--)i2c_unregister_device (i2c_clients[i]);kfree (i2c_clients);