platform/x86: intel_cht_int33fe: Work around BIOS bug on some devices
Subsystems (2)
PATCH v2 1/1 platform/x86: intel_cht_int33fe: Work around BIOS bug on some devices
At least one BIOS enumerates the max17047 both through the INT33FE ACPI device (it is right there in the resources table) as well as through a separate MAX17047 device.
This commit checks for the max17047 already being enumerated through a separate MAX17047 ACPI device and if so it uses the i2c-client instantiated for this and attaches the device-props for the max17047 to that i2c-client.
---
Changes in v2:
-Check acpi_companion HID instead of dev_name
--- drivers/platform/x86/intel_cht_int33fe.c | 71 +++++++++++++++++++++++++++----- 1 file changed, 61 insertions(+), 10 deletions(-)
drivers/platform/x86/intel_cht_int33fe.c +61 -10
@@ -34,6 +34,42 @@ struct cht_int33fe_data {struct i2c_client *pi3usb30532; }; +/* +* Grrr I severly dislike buggy BIOS-es. At least one BIOS enumerates +* the max17047 both through the INT33FE ACPI device (it is right there +* in the resources table) as well as through a separate MAX17047 device. +* +* These helpers are used to work around this by checking if an i2c-client +* for the max17047 has already been registered. +*/ +int cht_int33fe_check_for_max17047 (struct device *dev,void *data) +{ +struct acpi_device *companion =ACPI_COMPANION (dev); +struct i2c_client **max17047 = data; +const char *hid; + +if (!companion) +return 0 ; + + hid =acpi_device_hid (companion); + +/* The MAX17047 ACPI node doesn't have an UID, so we don't check that */ +if (strcmp (hid,"MAX17047" ) ==0 ) { + *max17047 =to_i2c_client (dev); +return 1 ; + } + +return 0 ; +} + +struct i2c_client *cht_int33fe_find_max17047 (void ) +{ +struct i2c_client *max17047 =NULL ; + +i2c_for_each_dev (&max17047, cht_int33fe_check_for_max17047); +return max17047; +} +static const char *const max17047_suppliers[] = {"bq24190-charger" };static const struct property_entry max17047_props[] = {
@@ -46,9 +82,10 @@ static int cht_int33fe_probe(struct i2c_client *client)struct device *dev = &client->dev;struct i2c_board_info board_info;struct cht_int33fe_data *data; +struct i2c_client *max17047;unsigned long long ptyp;acpi_status status; -int fusb302_irq; +int ret, fusb302_irq; status =acpi_evaluate_integer (ACPI_HANDLE (dev),"PTYP" ,NULL , &ptyp);if (ACPI_FAILURE (status)) {
@@ -75,13 +112,25 @@ static int cht_int33fe_probe(struct i2c_client *client)if (!data)return -ENOMEM ; -memset (&board_info,0 ,sizeof (board_info)); -strlcpy (board_info.type,"max17047" ,I2C_NAME_SIZE ); - board_info.properties = max17047_props; - - data->max17047 =i2c_acpi_new_device (dev,1 , &board_info); -if (!data->max17047) -return -EPROBE_DEFER ;/* Wait for the i2c-adapter to load */ +/* Work around BIOS bug, see comment on cht_int33fe_find_max17047 */ + max17047 =cht_int33fe_find_max17047 (); +if (max17047) { +/* Pre-existing i2c-client for the max17047, add device-props */ + ret =device_add_properties (&max17047->dev, max17047_props); +if (ret) +return ret; +/* And re-probe to get the new device-props applied. */ + ret =device_reprobe (&max17047->dev); +if (ret) +dev_warn (dev,"Reprobing max17047 error: %d\n" , ret); + }else { +memset (&board_info,0 ,sizeof (board_info)); +strlcpy (board_info.type,"max17047" ,I2C_NAME_SIZE ); + board_info.properties = max17047_props; + data->max17047 =i2c_acpi_new_device (dev,1 , &board_info); +if (!data->max17047) +return -EPROBE_DEFER ;/* Wait for i2c-adapter to load */ + }memset (&board_info,0 ,sizeof (board_info));strlcpy (board_info.type,"fusb302" ,I2C_NAME_SIZE );
@@ -106,7 +155,8 @@ static int cht_int33fe_probe(struct i2c_client *client)i2c_unregister_device (data->fusb302); out_unregister_max17047: -i2c_unregister_device (data->max17047); +if (data->max17047) +i2c_unregister_device (data->max17047);return -EPROBE_DEFER ;/* Wait for the i2c-adapter to load */ }
@@ -117,7 +167,8 @@ static int cht_int33fe_remove(struct i2c_client *i2c)i2c_unregister_device (data->pi3usb30532);i2c_unregister_device (data->fusb302); -i2c_unregister_device (data->max17047); +if (data->max17047) +i2c_unregister_device (data->max17047);return 0 ; }
Signature · 1 line
2.13.4
Quoted 10 lines · Hans de Goede
At least one BIOS enumerates the max17047 both through the INT33FE ACPI device (it is right there in the resources table) as well as through a separate MAX17047 device.
This commit checks for the max17047 already being enumerated through a separate MAX17047 ACPI device and if so it uses the i2c-client instantiated for this and attaches the device-props for the max17047 to that i2c-client.
Signed-off-by Hans de Goede <[email protected]>
I won't say this looks good to me, but since this seems to be the only sane way to deal with the crappy BIOS,
Quoted 10 lines · Hans de Goede
At least one BIOS enumerates the max17047 both through the INT33FE ACPI
device (it is right there in the resources table) as well as through a separate MAX17047 device.This commit checks for the max17047 already being enumerated through a separate MAX17047 ACPI device and if so it uses the i2c-client instantiated for this and attaches the device-props for the max17047 to
that i2c-client.
This one looks acceptable wrt buggy BIOS workaround, few comments below (I can do it when applying)
Quoted 30 lines
Signed-off-by Hans de Goede <[email protected]>---
Changes in v2:
-Checkacpi_companionHID instead ofdev_name
---
drivers/platform/x86/intel_cht_int33fe.c | 71
+++++++++++++++++++++++++++-----1 file changed, 61 insertions(+), 10 deletions(-)drivers/platform/x86/intel_cht_int33fe.c +0
-0@@ -34,6 +34,42 @@ struct cht_int33fe_data { struct i2c_client *pi3usb30532; };
+/*
+ * Grrr I severly dislike buggy BIOS-es. At least one BIOS enumerates
+ * the max17047 both through the INT33FE ACPI device (it is right there
+ * in the resources table) as well as through a separate MAX17047 device.
+ *
+ * These helpers are used to work around this by checking if an i2c- client
+ * for the max17047 has already been registered.
+ */
drivers/platform/x86/intel_cht_int33fe.c struct cht_int33fe_data { · line 50
Quoted 6 lines
drivers/platform/x86/intel_cht_int33fe.c +6
-0+int cht_int33fe_check_for_max17047 (struct device *dev,void *data) +{ +struct acpi_device *companion =ACPI_COMPANION (dev); +struct i2c_client **max17047 = data; +const char *hid; +
I would assign companion right here.
drivers/platform/x86/intel_cht_int33fe.c struct cht_int33fe_data { · line 57
Quoted 9 lines
drivers/platform/x86/intel_cht_int33fe.c +6
-0+if (!companion) +return 0 ; + + hid =acpi_device_hid (companion); + +/* The MAX17047 ACPI node doesn't have an UID, so we don't check that */
drivers/platform/x86/intel_cht_int33fe.c +1
-0+if (strcmp (hid,"MAX17047" ) ==0 ) {
if (strcmp())
return 0;
?
Quoted 97 lines
drivers/platform/x86/intel_cht_int33fe.c +15
-0+ *max17047 =to_i2c_client (dev); +return 1 ; + } + +return 0 ; +} + +struct i2c_client *cht_int33fe_find_max17047 (void ) +{ +struct i2c_client *max17047 =NULL ; + +i2c_for_each_dev (&max17047, cht_int33fe_check_for_max17047); +return max17047; +} +static const char * const max17047_suppliers[] = { "bq24190-charger" };
static const structproperty_entrymax17047_props[] = {drivers/platform/x86/intel_cht_int33fe.c +2
-1@@ -46,9 +82,10 @@ static int cht_int33fe_probe(struct i2c_client *client) struct device *dev = &client->dev; struct i2c_board_info board_info; struct cht_int33fe_data *data; +struct i2c_client *max17047; unsigned long long ptyp; acpi_status status; -int fusb302_irq; +int ret, fusb302_irq;
status =acpi_evaluate_integer(ACPI_HANDLE(dev), "PTYP", NULL, &ptyp);
if (ACPI_FAILURE(status)) {drivers/platform/x86/intel_cht_int33fe.c +0
-0@@ -75,13 +112,25 @@ static int cht_int33fe_probe(struct i2c_client *client) if (!data) return -ENOMEM;drivers/platform/x86/intel_cht_int33fe.c +0
-7-memset (&board_info,0 ,sizeof (board_info)); -strlcpy (board_info.type,"max17047" ,I2C_NAME_SIZE ); - board_info.properties = max17047_props; - - data->max17047 =i2c_acpi_new_device (dev,1 , &board_info); -if (!data->max17047) -return -EPROBE_DEFER ;/* Wait for the i2c-adapter to load */
drivers/platform/x86/intel_cht_int33fe.c +1
-0+/* Work around BIOS bug, see comment on
cht_int33fe_find_max17047*/drivers/platform/x86/intel_cht_int33fe.c +3
-0+ max17047 =cht_int33fe_find_max17047 (); +if (max17047) { +/* Pre-existing i2c-client for the max17047, add device-props */
drivers/platform/x86/intel_cht_int33fe.c +1
-0+ ret = device_add_properties(&max17047->dev,
max17047_props);drivers/platform/x86/intel_cht_int33fe.c +3
-0+if (ret) +return ret; +/* And re-probe to get the new device-props applied. */
drivers/platform/x86/intel_cht_int33fe.c +3
-0+ ret =device_reprobe (&max17047->dev); +if (ret) + dev_warn(dev, "Reprobing max17047 error:%d\n", ret);
drivers/platform/x86/intel_cht_int33fe.c +5
-0+ }else { +memset (&board_info,0 ,sizeof (board_info)); +strlcpy (board_info.type,"max17047" ,I2C_NAME_SIZE ); + board_info.properties = max17047_props; + data->max17047 = i2c_acpi_new_device(dev, 1,
&board_info);drivers/platform/x86/intel_cht_int33fe.c +2
-0+if (!data->max17047) +return -EPROBE_DEFER ;/* Wait for i2c-adapter to load */
drivers/platform/x86/intel_cht_int33fe.c +1
-0+ }
memset(&board_info, 0, sizeof(board_info));strlcpy(board_info.type, "fusb302", I2C_NAME_SIZE);drivers/platform/x86/intel_cht_int33fe.c +0
-0@@ -106,7 +155,8 @@ static int cht_int33fe_probe(struct i2c_client *client) i2c_unregister_device(data->fusb302);
out_unregister_max17047:drivers/platform/x86/intel_cht_int33fe.c +2
-1-i2c_unregister_device (data->max17047); +if (data->max17047) +i2c_unregister_device (data->max17047);
return -EPROBE_DEFER; /* Wait for the i2c-adapter to load */ }drivers/platform/x86/intel_cht_int33fe.c +0
-0@@ -117,7 +167,8 @@ static int cht_int33fe_remove(struct i2c_client *i2c)
i2c_unregister_device(data->pi3usb30532);
i2c_unregister_device(data->fusb302);drivers/platform/x86/intel_cht_int33fe.c +2
-1-i2c_unregister_device (data->max17047); +if (data->max17047) +i2c_unregister_device (data->max17047);
return 0;
}
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Hi,
Quoted 6 lines · Andy Shevchenko
Quoted 5 lines · Hans de Goede
At least one BIOS enumerates the max17047 both through the INT33FE ACPI
device (it is right there in the resources table) as well as through a separate MAX17047 device.
Quoted 8 lines
Quoted 5 lines
This commit checks for the max17047 already being enumerated through a separate MAX17047 ACPI device and if so it uses the i2c-client instantiated for this and attaches the device-props for the max17047 to
that i2c-client.This one looks acceptable wrt buggy BIOS workaround, few comments below (I can do it when applying)
The suggested comments are fine with me, feel free to fix those up while applying.
Thanks & Regards,
Hans
Quoted 152 lines
Quoted 31 lines
Signed-off-by Hans de Goede <[email protected]>---
Changes in v2:(quoted diff) +1
-2-Check acpi_companion HID instead of dev_name --- drivers/platform/x86/intel_cht_int33fe.c | 71 +++++++++++++++++++++++++++----- 1 file changed, 61 insertions(+), 10 deletions(-)drivers/platform/x86/intel_cht_int33fe.c +3
-0@@ -34,6 +34,42 @@ struct cht_int33fe_data {struct i2c_client *pi3usb30532; }; +/* +* Grrr I severly dislike buggy BIOS-es. At least one BIOS enumerates +* the max17047 both through the INT33FE ACPI device (it is right there
+ * in the resources table) as well as through a separate MAX17047 device.
+ *
+ * These helpers are used to work around this by checking if an i2c- client
+ * for the max17047 has already been registered.
+ */drivers/platform/x86/intel_cht_int33fe.c struct cht_int33fe_data { · line 50
Quoted 6 lines
drivers/platform/x86/intel_cht_int33fe.c +6
-0+int cht_int33fe_check_for_max17047 (struct device *dev,void *data) +{ +struct acpi_device *companion =ACPI_COMPANION (dev); +struct i2c_client **max17047 = data; +const char *hid; +I would assign companion right here.
drivers/platform/x86/intel_cht_int33fe.c struct cht_int33fe_data { · line 57
Quoted 9 lines
drivers/platform/x86/intel_cht_int33fe.c +6
-0+if (!companion) +return 0 ; + + hid =acpi_device_hid (companion); + +/* The MAX17047 ACPI node doesn't have an UID, so we don't check that */
drivers/platform/x86/intel_cht_int33fe.c +1
-0+if (strcmp (hid,"MAX17047" ) ==0 ) {if (
strcmp())
return 0;?
Quoted 97 lines
drivers/platform/x86/intel_cht_int33fe.c +15
-0+ *max17047 =to_i2c_client (dev); +return 1 ; + } + +return 0 ; +} + +struct i2c_client *cht_int33fe_find_max17047 (void ) +{ +struct i2c_client *max17047 =NULL ; + +i2c_for_each_dev (&max17047, cht_int33fe_check_for_max17047); +return max17047; +} +static const char *const max17047_suppliers[] = {"bq24190-charger" };
static const struct property_entry max17047_props[] = {drivers/platform/x86/intel_cht_int33fe.c +2
-1@@ -46,9 +82,10 @@ static int cht_int33fe_probe(struct i2c_client *client)struct device *dev = &client->dev;struct i2c_board_info board_info;struct cht_int33fe_data *data; +struct i2c_client *max17047;unsigned long long ptyp;acpi_status status; -int fusb302_irq; +int ret, fusb302_irq; status = acpi_evaluate_integer(ACPI_HANDLE(dev), "PTYP",NULL, &ptyp);
if (ACPI_FAILURE(status)) {drivers/platform/x86/intel_cht_int33fe.c +0
-7@@ -75,13 +112,25 @@ static int cht_int33fe_probe(struct i2c_client *client)if (!data)return -ENOMEM ; -memset (&board_info,0 ,sizeof (board_info)); -strlcpy (board_info.type,"max17047" ,I2C_NAME_SIZE ); - board_info.properties = max17047_props; - - data->max17047 =i2c_acpi_new_device (dev,1 , &board_info); -if (!data->max17047) -return -EPROBE_DEFER ;/* Wait for the i2c-adapter to load */
drivers/platform/x86/intel_cht_int33fe.c +1
-0+/* Work around BIOS bug, see comment on
cht_int33fe_find_max17047*/drivers/platform/x86/intel_cht_int33fe.c +3
-0+ max17047 =cht_int33fe_find_max17047 (); +if (max17047) { +/* Pre-existing i2c-client for the max17047, add device-props */
drivers/platform/x86/intel_cht_int33fe.c +1
-0+ ret = device_add_properties(&max17047->dev,
max17047_props);drivers/platform/x86/intel_cht_int33fe.c +3
-0+if (ret) +return ret; +/* And re-probe to get the new device-props applied. */
drivers/platform/x86/intel_cht_int33fe.c +3
-0+ ret =device_reprobe (&max17047->dev); +if (ret) + dev_warn(dev, "Reprobing max17047 error:%d\n", ret);
drivers/platform/x86/intel_cht_int33fe.c +5
-0+ }else { +memset (&board_info,0 ,sizeof (board_info)); +strlcpy (board_info.type,"max17047" ,I2C_NAME_SIZE ); + board_info.properties = max17047_props; + data->max17047 = i2c_acpi_new_device(dev, 1,
&board_info);drivers/platform/x86/intel_cht_int33fe.c +2
-0+if (!data->max17047) +return -EPROBE_DEFER ;/* Wait for i2c-adapter to load */
drivers/platform/x86/intel_cht_int33fe.c +3
-1+ }memset (&board_info,0 ,sizeof (board_info));strlcpy (board_info.type,"fusb302" ,I2C_NAME_SIZE );@@ -106,7 +155,8 @@ static int cht_int33fe_probe(struct i2c_client *client)i2c_unregister_device (data->fusb302); out_unregister_max17047: -i2c_unregister_device (data->max17047); +if (data->max17047) +i2c_unregister_device (data->max17047);return -EPROBE_DEFER ;/* Wait for the i2c-adapter to load */ }drivers/platform/x86/intel_cht_int33fe.c +2
-1@@ -117,7 +167,8 @@ static int cht_int33fe_remove(struct i2c_client *i2c)i2c_unregister_device (data->pi3usb30532);i2c_unregister_device (data->fusb302); -i2c_unregister_device (data->max17047); +if (data->max17047) +i2c_unregister_device (data->max17047);return 0 ;}
Andy Shevchenko
AppliedQuoted 18 lines · Hans de Goede
Hi,
Quoted 15 lines · Andy Shevchenko
Quoted 11 lines · Hans de Goede
At least one BIOS enumerates the max17047 both through the INT33FE ACPI
device (it is right there in the resources table) as well as through a separate MAX17047 device.This commit checks for the max17047 already being enumerated through a separate MAX17047 ACPI device and if so it uses the i2c-client instantiated for this and attaches the device-props for the max17047 to
that i2c-client.
Quoted 6 lines
Quoted 2 lines
This one looks acceptable wrt buggy BIOS workaround, few comments below (I can do it when applying)
The suggested comments are fine with me, feel free to fix those up while applying.
Pushed to review-andy.
Quoted 157 lines
Thanks & Regards,
Hans
Quoted 148 lines
Quoted 30 lines
Signed-off-by Hans de Goede <[email protected]>---
Changes in v2:(quoted diff) +1
-2-Check acpi_companion HID instead of dev_name --- drivers/platform/x86/intel_cht_int33fe.c | 71 +++++++++++++++++++++++++++----- 1 file changed, 61 insertions(+), 10 deletions(-)drivers/platform/x86/intel_cht_int33fe.c +2
-0@@ -34,6 +34,42 @@ struct cht_int33fe_data {struct i2c_client *pi3usb30532; }; +/* +* Grrr I severly dislike buggy BIOS-es. At least one BIOS enumerates +* the max17047 both through the INT33FE ACPI device (it is right there
+ * in the resources table) as well as through a separate MAX17047 device.
+ *
+ * These helpers are used to work around this by checking if an i2c- client
+ * for the max17047 has already been registered.
+ */drivers/platform/x86/intel_cht_int33fe.c struct cht_int33fe_data { · line 50
Quoted 6 lines
drivers/platform/x86/intel_cht_int33fe.c +6
-0+int cht_int33fe_check_for_max17047 (struct device *dev,void *data) +{ +struct acpi_device *companion =ACPI_COMPANION (dev); +struct i2c_client **max17047 = data; +const char *hid; +I would assign companion right here.
Quoted 11 lines
drivers/platform/x86/intel_cht_int33fe.c +6
-0+if (!companion) +return 0 ; + + hid =acpi_device_hid (companion); + +/* The MAX17047 ACPI node doesn't have an UID, so we don't check that */
+ if (
strcmp(hid, "MAX17047")== 0) {if (
strcmp())
return 0;?
Quoted 89 lines
drivers/platform/x86/intel_cht_int33fe.c +15
-0+ *max17047 =to_i2c_client (dev); +return 1 ; + } + +return 0 ; +} + +struct i2c_client *cht_int33fe_find_max17047 (void ) +{ +struct i2c_client *max17047 =NULL ; + +i2c_for_each_dev (&max17047, cht_int33fe_check_for_max17047); +return max17047; +} +static const char *const max17047_suppliers[] = {"bq24190-charger" }; static const struct property_entry max17047_props[] = {drivers/platform/x86/intel_cht_int33fe.c +2
-1@@ -46,9 +82,10 @@ static int cht_int33fe_probe(struct i2c_client *client)struct device *dev = &client->dev;struct i2c_board_info board_info;struct cht_int33fe_data *data; +struct i2c_client *max17047;unsigned long long ptyp;acpi_status status; -int fusb302_irq; +int ret, fusb302_irq; status =acpi_evaluate_integer (ACPI_HANDLE (dev),"PTYP" ,NULL , &ptyp);if (ACPI_FAILURE(status)) {drivers/platform/x86/intel_cht_int33fe.c +0
-6@@ -75,13 +112,25 @@ static int cht_int33fe_probe(struct i2c_client *client)if (!data)return -ENOMEM ; -memset (&board_info,0 ,sizeof (board_info)); -strlcpy (board_info.type,"max17047" ,I2C_NAME_SIZE ); - board_info.properties = max17047_props; - - data->max17047 =i2c_acpi_new_device (dev,1 , &board_info); -if (!data->max17047) -return -EPROBE_DEFER ;/* Wait for the i2c-adapter to load */
+ /* Work around BIOS bug, see comment oncht_int33fe_find_max17047*/drivers/platform/x86/intel_cht_int33fe.c +3
-0+ max17047 =cht_int33fe_find_max17047 (); +if (max17047) { +/* Pre-existing i2c-client for the max17047, add device-props */
+ ret = device_add_properties(&max17047->dev,max17047_props);drivers/platform/x86/intel_cht_int33fe.c +3
-0+if (ret) +return ret; +/* And re-probe to get the new device-props applied. */
drivers/platform/x86/intel_cht_int33fe.c +3
-0+ ret =device_reprobe (&max17047->dev); +if (ret) + dev_warn(dev, "Reprobing max17047 error:%d\n", ret);
drivers/platform/x86/intel_cht_int33fe.c +5
-0+ }else { +memset (&board_info,0 ,sizeof (board_info)); +strlcpy (board_info.type,"max17047" ,I2C_NAME_SIZE ); + board_info.properties = max17047_props; + data->max17047 = i2c_acpi_new_device(dev, 1,
&board_info);drivers/platform/x86/intel_cht_int33fe.c +2
-0+if (!data->max17047) +return -EPROBE_DEFER ;/* Wait for i2c-adapter to load */
drivers/platform/x86/intel_cht_int33fe.c +5
-2+ }memset (&board_info,0 ,sizeof (board_info));strlcpy (board_info.type,"fusb302" ,I2C_NAME_SIZE );@@ -106,7 +155,8 @@ static int cht_int33fe_probe(struct i2c_client *client)i2c_unregister_device (data->fusb302); out_unregister_max17047: -i2c_unregister_device (data->max17047); +if (data->max17047) +i2c_unregister_device (data->max17047);return -EPROBE_DEFER ;/* Wait for the i2c-adapter to load */ }@@ -117,7 +167,8 @@ static int cht_int33fe_remove(struct i2c_client *i2c)i2c_unregister_device (data->pi3usb30532);i2c_unregister_device (data->fusb302); -i2c_unregister_device (data->max17047); +if (data->max17047) +i2c_unregister_device (data->max17047);return 0 ; }
Signature · 2 lines
With Best Regards, Andy Shevchenko