i2c-multi-instantiate pseudo driver
Subsystems (3)
v5 cover i2c-multi-instantiate pseudo driver
Hi All,
Here is v5 of my patch-series for dealing with multiple independent i2c devices being described in a single ACPI fwnode.
Changes in v5:
-s/no_clients/num_clients/
-Change patch 4 Subject prefix to platform/x86
Changes in v4:
-Rewrite commit message of first patch as this is NOT a bug fix for
acpi_is_indirect_io_slave() as I thought at first, it is still necessary as a preperation patch for the rest of the series
-MAINTAINER and Kconfig entry fixes
-Some minor coding style fixes
Changes in v3:
-Drop the patch adding the I2C_CLIENT_IGNORE_BUSY flag/hack -Add patches to make ACPI fwnode-s with affected acpi_ids get enumerated as
platform device instead of i2c-client
-Change the i2c-multi-instantiate driver to a platform driver
Changes in v2:
-Rebase on 4.18-rc2
Changes in v1:
-Second attempt at dealing with this using a new design where a separate
driver (which can be build as a module) is used to instantiate the i2c-clients instead of modifying the i2c core
-Add an I2C_CLIENT_IGNORE_BUSY flag to make it possible for this driver to bind
to the client instantiated for the first i2c resource and still create a new client using the i2c_client_id for the actual driver for the first resource, resulting in 2 clients at the same address (of which one is inactive)
About merging this series, the platform-driver and ACPI patches can be merged independently of each other, they platform driver relies on the ACPI changes to gets its platform device instantiated, but if those changes are not in place yet, nothing bad happens.
So if everyone is happy with this series I suggest that each part gets merged separately through the relevant trees.
Regards,
Hans
PATCH v5 1/4 ACPI / scan: Initialize status to ACPI_STA_DEFAULT
Since commit 63347db0affa ("ACPI / scan: Use acpi_bus_get_status() to initialize ACPI_TYPE_DEVICE devs") the status field of normal acpi_devices gets set to 0 by acpi_bus_type_and_status() and filled with its actual value later when acpi_add_single_object() calls acpi_bus_get_status().
This means that any acpi_match_device_ids() calls in between will always fail with -ENOENT.
We already have a workaround for this, which temporary forces status to ACPI_STA_DEFAULT in drivers/acpi/x86/utils.c: acpi_device_always_present() and the next commit in this series adds another acpi_match_device_ids() call between status being initialized as 0 and the acpi_bus_get_status() call.
Rather then adding another workaround, this commit makes acpi_bus_type_and_status() initialize status to ACPI_STA_DEFAULT, this is safe to do as the only code looking at status between the initialization and the acpi_bus_get_status() call is those acpi_match_device_ids() calls.
Note this does mean that we need to (re)set status to 0 in case the acpi_bus_get_status() call fails.
---
Changes in v3:
-New patch in v3 of this patch-set
Changes in v4:
-This is not a fix for acpi_is_indirect_io_slave() as I thought at first,
acpi_is_indirect_io_slave() calls acpi_match_device_ids() on its parent device, where status is already set properly. Rewrite the commit message accordingly.
--- drivers/acpi/scan.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/acpi/scan.c +3 -2
@@ -1612,7 +1612,8 @@ static int acpi_add_single_object(struct acpi_device **child,* Note this must be done before the get power-/wakeup_dev-flags calls. */ if (type ==ACPI_BUS_TYPE_DEVICE ) -acpi_bus_get_status (device); +if (acpi_bus_get_status (device) <0 ) +acpi_set_device_status (device,0 );acpi_bus_get_power_flags (device);acpi_bus_get_wakeup_device_flags (device);
@@ -1690,7 +1691,7 @@ static int acpi_bus_type_and_status(acpi_handle handle, int *type,* acpi_add_single_object updates this once we've an acpi_device * so that acpi_bus_get_status' quirk handling can be used. */ - *sta =0 ; + *sta =ACPI_STA_DEFAULT ;break ;case ACPI_TYPE_PROCESSOR : *type =ACPI_BUS_TYPE_PROCESSOR ;
Signature · 1 line
2.18.0
Rafael J. Wysocki
maintainerRe: [PATCH v5 1/4] ACPI / scan: Initialize status to ACPI_STA_DEFAULT
Quoted 27 lines · Hans de Goede
Since commit
63347db0affa("ACPI / scan: Useacpi_bus_get_status()to initializeACPI_TYPE_DEVICEdevs") the status field of normalacpi_devicesgets set to 0 byacpi_bus_type_and_status()and filled with its actual value later whenacpi_add_single_object()callsacpi_bus_get_status().This means that any
acpi_match_device_ids()calls in between will always fail with-ENOENT.We already have a workaround for this, which temporary forces status to
ACPI_STA_DEFAULTindrivers/acpi/x86/utils.c:acpi_device_always_present()and the next commit in this series adds anotheracpi_match_device_ids()call between status being initialized as 0 and theacpi_bus_get_status()call.Rather then adding another workaround, this commit makes
acpi_bus_type_and_status()initialize status toACPI_STA_DEFAULT, this is safe to do as the only code looking at status between the initialization and theacpi_bus_get_status()call is thoseacpi_match_device_ids()calls.Note this does mean that we need to (re)set status to 0 in case the
acpi_bus_get_status()call fails.Signed-off-by Hans de Goede <[email protected]>---
Changes in v3:
-New patch in v3 of this patch-set
Quoted 5 lines
Changes in v4:
-This is not a fix foracpi_is_indirect_io_slave()as I thought at first,
acpi_is_indirect_io_slave()callsacpi_match_device_ids()on its parent device, where status is already set properly. Rewrite the commit message accordingly.
I've applied the v4 of this patch and I don't think there are any changes from it here.
As for the rest of the series I'll wait from comments from Wolfram and the other reviewers.
Thanks,
Rafael
Re: [PATCH v5 1/4] ACPI / scan: Initialize status to ACPI_STA_DEFAULT
Hi,
Quoted 28 lines · Rafael J. Wysocki
Quoted 27 lines · Hans de Goede
Since commit
63347db0affa("ACPI / scan: Useacpi_bus_get_status()to initializeACPI_TYPE_DEVICEdevs") the status field of normalacpi_devicesgets set to 0 byacpi_bus_type_and_status()and filled with its actual value later whenacpi_add_single_object()callsacpi_bus_get_status().This means that any
acpi_match_device_ids()calls in between will always fail with-ENOENT.We already have a workaround for this, which temporary forces status to
ACPI_STA_DEFAULTindrivers/acpi/x86/utils.c:acpi_device_always_present()and the next commit in this series adds anotheracpi_match_device_ids()call between status being initialized as 0 and theacpi_bus_get_status()call.Rather then adding another workaround, this commit makes
acpi_bus_type_and_status()initialize status toACPI_STA_DEFAULT, this is safe to do as the only code looking at status between the initialization and theacpi_bus_get_status()call is thoseacpi_match_device_ids()calls.Note this does mean that we need to (re)set status to 0 in case the
acpi_bus_get_status()call fails.Signed-off-by Hans de Goede <[email protected]>---
Changes in v3:
-New patch in v3 of this patch-set
Quoted 8 lines
Quoted 5 lines
Changes in v4:
-This is not a fix foracpi_is_indirect_io_slave()as I thought at first,
acpi_is_indirect_io_slave()callsacpi_match_device_ids()on its parent device, where status is already set properly. Rewrite the commit message accordingly.I've applied the v4 of this patch and I don't think there are any changes from it here.
Correct, there were only changes to the 4th patch in the series.
Quoted 2 lines
As for the rest of the series I'll wait from comments from Wolfram and the other reviewers.
Ok, note if you've taken patch 1 you may also want to take patch 3 which is an ACPI code cleanup made possible by patch 1 and otherwise is unrelated.
Regards,
Hans
Re: [PATCH v5 1/4] ACPI / scan: Initialize status to ACPI_STA_DEFAULT
Quoted 10 lines · Hans de Goede
Quoted 5 lines · Rafael J. Wysocki
On Thu, Aug 9, 2018 at 11:15 AM, Hans de Goede <[email protected]> wrote:
I've applied the v4 of this patch and I don't think there are any changes from it here.
Correct, there were only changes to the 4th patch in the series.
Quoted 7 lines
Quoted 2 lines
As for the rest of the series I'll wait from comments from Wolfram and the other reviewers.
Ok, note if you've taken patch 1 you may also want to take patch 3 which is an ACPI code cleanup made possible by patch 1 and otherwise is unrelated.
I'm under impression Rafael is going to take entire series (at least for patch 4 I'm expecting to give an Ack).
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v5 1/4] ACPI / scan: Initialize status to ACPI_STA_DEFAULT
Hi,
Quoted 15 lines · Andy Shevchenko
Quoted 14 lines · Hans de Goede
Quoted 5 lines · Rafael J. Wysocki
On Thu, Aug 9, 2018 at 11:15 AM, Hans de Goede <[email protected]> wrote:
I've applied the v4 of this patch and I don't think there are any changes from it here.
Correct, there were only changes to the 4th patch in the series.
Quoted 2 lines
As for the rest of the series I'll wait from comments from Wolfram and the other reviewers.
Quoted 6 lines
Quoted 3 lines
Ok, note if you've taken patch 1 you may also want to take patch 3 which is an ACPI code cleanup made possible by patch 1 and otherwise is unrelated.
I'm under impression Rafael is going to take entire series (at least for patch 4 I'm expecting to give an Ack).
As I mentioned in the coverletter, my idea was to have Rafael take patches 1-3 and then merge the 4th patch through the platform/x86 tree. There are only runtime dependencies between the 2 parts and merging them independently should not cause any issues.
Regards,
Hans
Rafael J. Wysocki
maintainerRe: [PATCH v5 1/4] ACPI / scan: Initialize status to ACPI_STA_DEFAULT
Quoted 30 lines · Hans de Goede
Hi,
Quoted 27 lines · Andy Shevchenko
Quoted 22 lines · Hans de Goede
Quoted 7 lines · Rafael J. Wysocki
On Thu, Aug 9, 2018 at 11:15 AM, Hans de Goede <[email protected]> wrote:
I've applied the v4 of this patch and I don't think there are any changes from it here.
Correct, there were only changes to the 4th patch in the series.
Quoted 2 lines
As for the rest of the series I'll wait from comments from Wolfram and the other reviewers.
Ok, note if you've taken patch 1 you may also want to take patch 3 which is an ACPI code cleanup made possible by patch 1 and otherwise is unrelated.
Quoted 8 lines
Quoted 2 lines
I'm under impression Rafael is going to take entire series (at least for patch 4 I'm expecting to give an Ack).
As I mentioned in the coverletter, my idea was to have Rafael take patches 1-3 and then merge the 4th patch through the platform/x86 tree. There are only runtime dependencies between the 2 parts and merging them independently should not cause any issues.
I can apply the 4th one too if it is ACKed by everyone with a vested interest.
Re: [PATCH v5 1/4] ACPI / scan: Initialize status to ACPI_STA_DEFAULT
Hi,
Quoted 35 lines · Rafael J. Wysocki
Quoted 34 lines · Hans de Goede
Hi,
Quoted 29 lines · Andy Shevchenko
Quoted 14 lines · Hans de Goede
Quoted 7 lines · Rafael J. Wysocki
On Thu, Aug 9, 2018 at 11:15 AM, Hans de Goede <[email protected]> wrote:
I've applied the v4 of this patch and I don't think there are any changes from it here.
Correct, there were only changes to the 4th patch in the series.
Quoted 8 lines
Quoted 2 lines
As for the rest of the series I'll wait from comments from Wolfram and the other reviewers.
Ok, note if you've taken patch 1 you may also want to take patch 3 which is an ACPI code cleanup made possible by patch 1 and otherwise is unrelated.
I'm under impression Rafael is going to take entire series (at least for patch 4 I'm expecting to give an Ack).
Quoted 6 lines
Quoted 4 lines
As I mentioned in the coverletter, my idea was to have Rafael take patches 1-3 and then merge the 4th patch through the platform/x86 tree. There are only runtime dependencies between the 2 parts and merging them independently should not cause any issues.
I can apply the 4th one too if it is ACKed by everyone with a vested interest.
That works for me, note I'm about to send out a v6 (with only changes to the 4th patch), so hold of a bit with merging this please.
Andy does your ack for the 4th patch mean you're ok with Rafael merging this?
Regards,
Hans
Re: [PATCH v5 1/4] ACPI / scan: Initialize status to ACPI_STA_DEFAULT
Quoted 3 lines · Hans de Goede
Andy does your ack for the 4th patch mean you're ok with Rafael merging
this?
Yes.
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Re: [PATCH v5 1/4] ACPI / scan: Initialize status to ACPI_STA_DEFAULT
In reply to Rafael J. WysockiQuoted 3 lines
As for the rest of the series I'll wait from comments from Wolfram and the other reviewers.
Well, I acked patch 4 now because I like the general approach. I can't say much about the rest since this is mostly ACPI/FW related.
Thanks Hans, for keeping at it.
PATCH v5 2/4 ACPI / scan: Create platform device for fwnodes with multiple i2c devices
In reply to Hans de GoedeSome devices have multiple I2cSerialBus resources and for things to work an i2c-client must be instantiated for each, each with its own i2c_device_id.
Normally we only instantiate an i2c-client for the first resource, using the ACPI HID as id.
This commit adds a list of HIDs of devices, which need multiple i2c-clients instantiated from a single fwnode, to acpi_device_enumeration_by_parent and makes acpi_device_enumeration_by_parent return false for these devices so that a platform device will be instantiated.
This allows the drivers/platform/x86/i2c-multi-instantiate.c driver, which knows which i2c_device_id to use for each resource, to bind to the fwnode and initiate an i2c-client for each resource.
---
Changes in v3:
-New patch in v3 of this patch-set
Changes in v4:
-Some small code-style fixes
--- drivers/acpi/scan.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
drivers/acpi/scan.c +16 -0
@@ -1540,6 +1540,18 @@ static bool acpi_device_enumeration_by_parent(struct acpi_device *device) {struct list_head resource_list;bool is_serial_bus_slave = false; +/* +* These devices have multiple I2cSerialBus resources and an i2c-client +* must be instantiated for each, each with its own i2c_device_id. +* Normally we only instantiate an i2c-client for the first resource, +* using the ACPI HID as id. These special cases are handled by the +* drivers/platform/x86/i2c-multi-instantiate.c driver, which knows +* which i2c_device_id to use for each resource. +*/ +static const struct acpi_device_id i2c_multi_instantiate_ids[] = { + {"BSG1160" , }, + {} + };if (acpi_is_indirect_io_slave (device))return true;
@@ -1551,6 +1563,10 @@ static bool acpi_device_enumeration_by_parent(struct acpi_device *device) fwnode_property_present(&device->fwnode, "baud")))return true; +/* Instantiate a pdev for the i2c-multi-instantiate drv to bind to */ +if (!acpi_match_device_ids (device, i2c_multi_instantiate_ids)) +return false; +INIT_LIST_HEAD (&resource_list); acpi_dev_get_resources(device, &resource_list, acpi_check_serial_bus_slave,
Signature · 1 line
2.18.0
Re: [PATCH v5 2/4] ACPI / scan: Create platform device for fwnodes with multiple i2c devices
Quoted 17 lines · Hans de Goede
Some devices have multiple I2cSerialBus resources and for things to work
an i2c-client must be instantiated for each, each with its owni2c_device_id.Normally we only instantiate an i2c-client for the first resource, using
the ACPI HID as id.This commit adds a list of HIDs of devices, which need multiple i2c- clients
instantiated from a single fwnode, toacpi_device_enumeration_by_parentand
makesacpi_device_enumeration_by_parentreturn false for these devices so
that a platform device will be instantiated.
Quoted 6 lines
This allows the
drivers/platform/x86/i2c-multi-instantiate.cdriver, which
knows whichi2c_device_idto use for each resource, to bind to the fwnode
and initiate an i2c-client for each resource.
I like this approach
Quoted 54 lines
Signed-off-by Hans de Goede <[email protected]>---
Changes in v3:
-New patch in v3 of this patch-setChanges in v4:
(quoted diff) +0
-2-Some small code-style fixes --- drivers/acpi/scan.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)drivers/acpi/scan.c +2
-0@@ -1540,6 +1540,18 @@ static bool acpi_device_enumeration_by_parent(struct acpi_device *device) {struct list_head resource_list;bool is_serial_bus_slave = false; +/* +* These devices have multiple I2cSerialBus resources and an i2c-client
drivers/acpi/scan.c +1
-0+* must be instantiated for each, each with its own
i2c_device_id.drivers/acpi/scan.c +1
-0+* Normally we only instantiate an i2c-client for the first resource,
drivers/acpi/scan.c +1
-0+* using the ACPI HID as id. These special cases are handled by the
drivers/acpi/scan.c +1
-0+* drivers/platform/x86/i2c-multi-instantiate.c driver, which knows
drivers/acpi/scan.c +3
-0+* which i2c_device_id to use for each resource. +*/ + static const struct acpi_device_id i2c_multi_instantiate_ids[] ={
drivers/acpi/scan.c +4
-0+ {"BSG1160", }, + {} + };if (acpi_is_indirect_io_slave (device))return true;@@ -1551,6 +1563,10 @@ static bool acpi_device_enumeration_by_parent(struct acpi_device *device) fwnode_property_present(&device->fwnode, "baud")))return true; +/* Instantiate a pdev for the i2c-multi-instantiate drv to bind to */
drivers/acpi/scan.c +3
-0+if (!acpi_match_device_ids (device, i2c_multi_instantiate_ids)) +return false; +INIT_LIST_HEAD (&resource_list); acpi_dev_get_resources(device, &resource_list, acpi_check_serial_bus_slave,
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
PATCH v5 3/4 ACPI / x86-utils: Remove status workaround from acpi_device_always_present()
In reply to Hans de GoedeNow that we init the status field to ACPI_STA_DEFAULT rather then to 0, the workaround for acpi_match_device_ids() always returning -ENOENT when status is 0 is no longer needed.
---
Changes in v3:
-New patch in v3 of this patch-set
--- drivers/acpi/x86/utils.c | 10 ---------- 1 file changed, 10 deletions(-)
drivers/acpi/x86/utils.c +0 -10
@@ -103,13 +103,9 @@ static const struct always_present_id always_present_ids[] = {bool acpi_device_always_present (struct acpi_device *adev) { -u32 *status = (u32 *)&adev->status; -u32 old_status = *status;bool ret = false;unsigned int i; -/* acpi_match_device_ids checks status, so set it to default */ - *status =ACPI_STA_DEFAULT ;for (i =0 ; i <ARRAY_SIZE (always_present_ids); i++) {if (acpi_match_device_ids (adev, always_present_ids[i].hid))continue ;
@@ -125,15 +121,9 @@ bool acpi_device_always_present(struct acpi_device *adev) !dmi_check_system(always_present_ids[i].dmi_ids)) continue; -if (old_status !=ACPI_STA_DEFAULT )/* Log only once */ -dev_info (&adev->dev, -"Device [%s] is in always present list\n" , - adev->pnp.bus_id); - ret = true;break ; } - *status = old_status;return ret; }
Signature · 1 line
2.18.0
Re: [PATCH v5 3/4] ACPI / x86-utils: Remove status workaround from acpi_device_always_present()
Quoted 6 lines · Hans de Goede
Now that we init the status field to
ACPI_STA_DEFAULTrather then to 0,
the workaround foracpi_match_device_ids()always returning-ENOENTwhen
status is 0 is no longer needed.
Always good to have only "minus" statistics
Quoted 46 lines
Signed-off-by Hans de Goede <[email protected]>---
Changes in v3:(quoted diff) +0
-2-New patch in v3 of this patch-set --- drivers/acpi/x86/utils.c | 10 ---------- 1 file changed, 10 deletions(-)drivers/acpi/x86/utils.c +0
-4@@ -103,13 +103,9 @@ static const struct always_present_id always_present_ids[] = {bool acpi_device_always_present (struct acpi_device *adev) { -u32 *status = (u32 *)&adev->status; -u32 old_status = *status;bool ret = false;unsigned int i; -/* acpi_match_device_ids checks status, so set it to default */ - *status =ACPI_STA_DEFAULT ;for (i =0 ; i <ARRAY_SIZE (always_present_ids); i++) { if (acpi_match_device_ids(adev,always_present_ids[i].hid))
drivers/acpi/x86/utils.c +0
-6continue ;@@ -125,15 +121,9 @@ bool acpi_device_always_present(struct acpi_device *adev) !dmi_check_system(always_present_ids[i].dmi_ids))continue ; -if (old_status !=ACPI_STA_DEFAULT )/* Log only once */ -dev_info (&adev->dev, -"Device [%s] is in always present list\n", - adev->pnp.bus_id); - ret = true;break ; } - *status = old_status;return ret;
}
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
PATCH v5 4/4 platform/x86: Add ACPI i2c-multi-instantiate pseudo driver
In reply to Hans de GoedeOn systems with ACPI instantiated i2c-clients, normally there is 1 fw_node per i2c-device and that fw-node contains 1 I2cSerialBus resource for that 1 i2c-device.
But in some rare cases the manufacturer has decided to describe multiple i2c-devices in a single ACPI fwnode with multiple I2cSerialBus resources.
An earlier attempt to fix this in the i2c-core resulted in a lot of extra code to support this corner-case.
This commit introduces a new i2c-multi-instantiate driver which fixes this in a different way. This new driver can be built as a module which will only loaded on affected systems.
This driver will instantiate a new i2c-client per I2cSerialBus resource, using the driver_data from the acpi_device_id it is binding to to tell it which chip-type (and optional irq-resource) to use when instantiating.
Note this driver depends on a platform device being instantiated for the ACPI fwnode, see the i2c_multi_instantiate_ids list of ACPI device-ids in drivers/acpi/scan.c: acpi_device_enumeration_by_parent().
---
Changes in v2:
-Rebase on top of 4.18-rc2
Changes in v3:
-Change from an i2c-driver using a hack to allow having multiple i2c clients
at the same address to a platform-driver
Changes in v4:
-Tweak MAINTAINERS entry a bit
Changes in v5:
-s/no_clients/num_clients/
-Change patch Subject prefix to platform/x86
--- MAINTAINERS | 6 + drivers/platform/x86/Kconfig | 11 ++ drivers/platform/x86/Makefile | 1 + drivers/platform/x86/i2c-multi-instantiate.c | 131 +++++++++++++++++++ 4 files changed, 149 insertions(+) create mode 100644 drivers/platform/x86/i2c-multi-instantiate.c
MAINTAINERS +6 -0
@@ -367,6 +367,12 @@ L: [email protected] S: Maintained F: drivers/acpi/arm64 +ACPI I2C MULTI INSTANTIATE DRIVER +M: Hans de Goede <[email protected]> +L: [email protected] +S: Maintained +F: drivers/platform/x86/i2c-multi-instantiate.c + ACPI PMIC DRIVERS M: "Rafael J. Wysocki" <[email protected]> M: Len Brown <[email protected]>
drivers/platform/x86/Kconfig +11 -0
@@ -1219,6 +1219,17 @@ config INTEL_CHTDC_TI_PWRBTN To compile this driver as a module, choose M here: the module will be called intel_chtdc_ti_pwrbtn. +config I2C_MULTI_INSTANTIATE + tristate "I2C multi instantiate pseudo device driver" + depends on I2C && ACPI + help + Some ACPI-based systems list multiple i2c-devices in a single ACPI + firmware-node. This driver will instantiate separate i2c-clients + for each device in the firmware-node. + + To compile this driver as a module, choose M here: the module + will be called i2c-multi-instantiate. + endif # X86_PLATFORM_DEVICES config PMC_ATOM
drivers/platform/x86/Makefile +1 -0
@@ -91,3 +91,4 @@ obj-$(CONFIG_PMC_ATOM) += pmc_atom.o obj-$(CONFIG_MLX_PLATFORM) += mlx-platform.o obj-$(CONFIG_INTEL_TURBO_MAX_3) += intel_turbo_max_3.o obj-$(CONFIG_INTEL_CHTDC_TI_PWRBTN) += intel_chtdc_ti_pwrbtn.o +obj-$(CONFIG_I2C_MULTI_INSTANTIATE) += i2c-multi-instantiate.o
drivers/platform/x86/i2c-multi-instantiate.c new file +131 -0
131 lines not on this page · raw message
Signature · 1 line
2.18.0
Re: [PATCH v5 4/4] platform/x86: Add ACPI i2c-multi-instantiate pseudo driver
Quoted 18 lines · Hans de Goede
On systems with ACPI instantiated i2c-clients, normally there is 1
fw_nodeper i2c-device and that fw-node contains 1 I2cSerialBus resource for that 1 i2c-device.But in some rare cases the manufacturer has decided to describe multiple i2c-devices in a single ACPI fwnode with multiple I2cSerialBus resources.
An earlier attempt to fix this in the i2c-core resulted in a lot of extra code to support this corner-case.
This commit introduces a new i2c-multi-instantiate driver which fixes this in a different way. This new driver can be built as a module which will only loaded on affected systems.
This driver will instantiate a new i2c-client per I2cSerialBus resource, using the
driver_datafrom theacpi_device_idit is binding to to tell it which chip-type (and optional irq-resource) to use when instantiating.
Quoted 5 lines
Note this driver depends on a platform device being instantiated for the ACPI fwnode, see the
i2c_multi_instantiate_idslist of ACPI device-ids indrivers/acpi/scan.c:acpi_device_enumeration_by_parent().Signed-off-by Hans de Goede <[email protected]>
From my I2C PoV:
Re: [PATCH v5 4/4] platform/x86: Add ACPI i2c-multi-instantiate pseudo driver
In reply to Hans de GoedeQuoted 27 lines · Hans de Goede
On systems with ACPI instantiated i2c-clients, normally there is 1
fw_node
per i2c-device and that fw-node contains 1 I2cSerialBus resource for that 1
i2c-device.But in some rare cases the manufacturer has decided to describe multiple
i2c-devices in a single ACPI fwnode with multiple I2cSerialBus resources.An earlier attempt to fix this in the i2c-core resulted in a lot of extra
code to support this corner-case.This commit introduces a new i2c-multi-instantiate driver which fixes this
in a different way. This new driver can be built as a module which will
only loaded on affected systems.This driver will instantiate a new i2c-client per I2cSerialBus resource,
using thedriver_datafrom theacpi_device_idit is binding to to tell it
which chip-type (and optional irq-resource) to use when instantiating.
Quoted 6 lines
Note this driver depends on a platform device being instantiated for the
ACPI fwnode, see thei2c_multi_instantiate_idslist of ACPI device-ids indrivers/acpi/scan.c:acpi_device_enumeration_by_parent().
(From PDx86 prospective)
Quoted 223 lines
Signed-off-by Hans de Goede <[email protected]>---
Changes in v2:
-Rebase on top of 4.18-rc2Changes in v3:
-Change from an i2c-driver using a hack to allow having multiple i2c clients
at the same address to a platform-driverChanges in v4:
-TweakMAINTAINERSentry a bitChanges in v5:
(quoted diff) +1
-3-s/no_clients/num_clients/ -Change patch Subject prefix to platform/x86 --- MAINTAINERS | 6 + drivers/platform/x86/Kconfig | 11 ++ drivers/platform/x86/Makefile | 1 + drivers/platform/x86/i2c-multi-instantiate.c | 131 +++++++++++++++++++ 4 files changed, 149 insertions(+) create mode 100644 drivers/platform/x86/i2c-multi-instantiate.cMAINTAINERS +6
-0@@ -367,6 +367,12 @@ L: [email protected] S: Maintained F: drivers/acpi/arm64 +ACPI I2C MULTI INSTANTIATE DRIVER +M: Hans de Goede <[email protected]> +L: [email protected] +S: Maintained +F: drivers/platform/x86/i2c-multi-instantiate.c + ACPI PMIC DRIVERS M: "Rafael J. Wysocki" <[email protected]> M: Len Brown <[email protected]>drivers/platform/x86/Kconfig +5
-0@@ -1219,6 +1219,17 @@ config INTEL_CHTDC_TI_PWRBTN To compile this driver as a module, choose M here: the module will be called intel_chtdc_ti_pwrbtn. +config I2C_MULTI_INSTANTIATE + tristate "I2C multi instantiate pseudo device driver" + depends on I2C && ACPI + help + Some ACPI-based systems list multiple i2c-devices in a singleACPI
drivers/platform/x86/Kconfig +1
-0+ firmware-node. This driver will instantiate separate i2c-clients
drivers/platform/x86/Kconfig +5
-0+ for each device in the firmware-node. + + To compile this driver as a module, choose M here: the module + will be called i2c-multi-instantiate. + endif # X86_PLATFORM_DEVICES config PMC_ATOMdrivers/platform/x86/Makefile +1
-0@@ -91,3 +91,4 @@ obj-$(CONFIG_PMC_ATOM) += pmc_atom.o obj-$(CONFIG_MLX_PLATFORM) += mlx-platform.o obj-$(CONFIG_INTEL_TURBO_MAX_3) += intel_turbo_max_3.o obj-$(CONFIG_INTEL_CHTDC_TI_PWRBTN) += intel_chtdc_ti_pwrbtn.o +obj-$(CONFIG_I2C_MULTI_INSTANTIATE) += i2c-multi-instantiate.odrivers/platform/x86/i2c-multi-instantiate.c new file +3
-0@@ -0,0 +1,131 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* I2C multi-instantiate driver, pseudo driver to instantiate multiple
+ * i2c-clients from a single fwnode.
+ *
+ * Copyright 2018 Hans de Goede <[email protected]>
+ */drivers/platform/x86/i2c-multi-instantiate.c new file +43
-0+ +#include <linux/acpi.h> +#include <linux/i2c.h> +#include <linux/interrupt.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/platform_device.h> + +struct i2c_inst_data { +const char *type; +int irq_idx; +}; + +struct i2c_multi_inst_data { +int num_clients; +struct i2c_client *clients[0 ]; +}; + +static int i2c_multi_inst_probe (struct platform_device *pdev) +{ +struct i2c_multi_inst_data *multi; +const struct acpi_device_id *match; +const struct i2c_inst_data *inst_data; +struct i2c_board_info board_info = {}; +struct device *dev = &pdev->dev; +struct acpi_device *adev; +char name[32 ]; +int i, ret; + + match =acpi_match_device (dev->driver->acpi_match_table, dev); +if (!match) { +dev_err (dev,"Error ACPI match data is missing\n" ); +return -ENODEV ; + } + inst_data = (const struct i2c_inst_data *)match->driver_data; + + adev =ACPI_COMPANION (dev); + +/* Count number of clients to instantiate */ +for (i =0 ; inst_data[i].type; i++) {} + + multi = devm_kmalloc(dev, + offsetof(struct i2c_multi_inst_data,clients[i]),
drivers/platform/x86/i2c-multi-instantiate.c new file +9
-0+ GFP_KERNEL); +if (!multi) +return -ENOMEM ; + + multi->num_clients = i; + +for (i =0 ; i < multi->num_clients; i++) { +memset (&board_info,0 ,sizeof (board_info)); + strlcpy(board_info.type, inst_data[i].type,
I2C_NAME_SIZE);drivers/platform/x86/i2c-multi-instantiate.c new file +6
-0+snprintf (name,sizeof (name),"%s-%s" , match->id, + inst_data[i].type); + board_info.dev_name = name; + board_info.irq =0 ; +if (inst_data[i].irq_idx !=-1 ) { + ret = acpi_dev_gpio_irq_get(adev,inst_data[i].irq_idx);
drivers/platform/x86/i2c-multi-instantiate.c new file +2
-0+if (ret <0 ) { + dev_err(dev, "Error requesting irq atindex %d: %d\n",
drivers/platform/x86/i2c-multi-instantiate.c new file +6
-0+ inst_data[i].irq_idx, ret); + goto error; + } + board_info.irq = ret; + } + multi->clients[i] = i2c_acpi_new_device(dev, i,
&board_info);drivers/platform/x86/i2c-multi-instantiate.c new file +2
-0+if (!multi->clients[i]) { + dev_err(dev, "Error creating i2c-client, idx%d\n", i);
drivers/platform/x86/i2c-multi-instantiate.c new file +35
-0+ ret = -ENODEV ; + goto error; + } + } + +platform_set_drvdata (pdev, multi); +return 0 ; + +error: +while (--i >=0 ) +i2c_unregister_device (multi->clients[i]); + +return ret; +} + +static int i2c_multi_inst_remove (struct platform_device *pdev) +{ +struct i2c_multi_inst_data *multi =platform_get_drvdata (pdev); +int i; + +for (i =0 ; i < multi->num_clients; i++) +i2c_unregister_device (multi->clients[i]); + +return 0 ; +} + +static const struct i2c_inst_data bsg1160_data[] = { + {"bmc150_accel" ,0 }, + {"bmc150_magn" ,-1 }, + {"bmg160" ,-1 }, + {} +}; + +/* +* Note new device-ids must also be added to
i2c_multi_instantiate_idsin
+ *drivers/acpi/scan.c:acpi_device_enumeration_by_parent().
+ */drivers/platform/x86/i2c-multi-instantiate.c new file +19
-0+static const struct acpi_device_id i2c_multi_inst_acpi_ids[] = { + {"BSG1160" , (unsigned long )bsg1160_data }, + { } +}; +MODULE_DEVICE_TABLE (acpi, i2c_multi_inst_acpi_ids); + +static struct platform_driver i2c_multi_inst_driver = { + .driver = { + .name ="I2C multi instantiate pseudo device driver" , + .acpi_match_table =ACPI_PTR (i2c_multi_inst_acpi_ids), + }, + .probe = i2c_multi_inst_probe, + .remove = i2c_multi_inst_remove, +}; +module_platform_driver (i2c_multi_inst_driver); + +MODULE_DESCRIPTION ("I2C multi instantiate pseudo device driver" ); +MODULE_AUTHOR ("Hans de Goede <[email protected]>" ); +MODULE_LICENSE ("GPL" );
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Re: [PATCH v5 4/4] platform/x86: Add ACPI i2c-multi-instantiate pseudo driver
In reply to Hans de GoedeQuoted 24 lines · Hans de Goede
On systems with ACPI instantiated i2c-clients, normally there is 1
fw_nodeper i2c-device and that fw-node contains 1 I2cSerialBus resource for that 1 i2c-device.But in some rare cases the manufacturer has decided to describe multiple i2c-devices in a single ACPI fwnode with multiple I2cSerialBus resources.
An earlier attempt to fix this in the i2c-core resulted in a lot of extra code to support this corner-case.
This commit introduces a new i2c-multi-instantiate driver which fixes this in a different way. This new driver can be built as a module which will only loaded on affected systems.
This driver will instantiate a new i2c-client per I2cSerialBus resource, using the
driver_datafrom theacpi_device_idit is binding to to tell it which chip-type (and optional irq-resource) to use when instantiating.Note this driver depends on a platform device being instantiated for the ACPI fwnode, see the
i2c_multi_instantiate_idslist of ACPI device-ids indrivers/acpi/scan.c:acpi_device_enumeration_by_parent().Signed-off-by Hans de Goede <[email protected]>---
<snip>
Quoted 34 lines
drivers/platform/x86/i2c-multi-instantiate.c new file +34
-0+static int i2c_multi_inst_probe (struct platform_device *pdev) +{ +struct i2c_multi_inst_data *multi; +const struct acpi_device_id *match; +const struct i2c_inst_data *inst_data; +struct i2c_board_info board_info = {}; +struct device *dev = &pdev->dev; +struct acpi_device *adev; +char name[32 ]; +int i, ret; + + match =acpi_match_device (dev->driver->acpi_match_table, dev); +if (!match) { +dev_err (dev,"Error ACPI match data is missing\n" ); +return -ENODEV ; + } + inst_data = (const struct i2c_inst_data *)match->driver_data; + + adev =ACPI_COMPANION (dev); + +/* Count number of clients to instantiate */ +for (i =0 ; inst_data[i].type; i++) {} + + multi =devm_kmalloc (dev, + offsetof(struct i2c_multi_inst_data, clients[i]), + GFP_KERNEL); +if (!multi) +return -ENOMEM ; + + multi->num_clients = i; + +for (i =0 ; i < multi->num_clients; i++) { +memset (&board_info,0 ,sizeof (board_info)); +strlcpy (board_info.type, inst_data[i].type,I2C_NAME_SIZE );
drivers/platform/x86/i2c-multi-instantiate.c line 69
Quoted 10 lines
drivers/platform/x86/i2c-multi-instantiate.c new file +10
-0+snprintf (name,sizeof (name),"%s-%s" , match->id, + inst_data[i].type); + board_info.dev_name = name; + board_info.irq =0 ; +if (inst_data[i].irq_idx !=-1 ) { + ret =acpi_dev_gpio_irq_get (adev, inst_data[i].irq_idx); +if (ret <0 ) { +dev_err (dev,"Error requesting irq at index %d: %d\n" , + inst_data[i].irq_idx, ret); + goto error;
This seems to assume that we always have GpioInt with assigned for these devices, but that's wrong. This needs to work with normal Interrupt type resources as well.
The TI USB PD controller instances (HID 3515) for exmaple have normal Interrupts assigned to them
Why not use the "irq_idx" with normal interrupts, and add a new member for the GpioInts, something like gpio_irq_idx?
Quoted 10 lines
drivers/platform/x86/i2c-multi-instantiate.c new file +10
-0+ } + board_info.irq = ret; + } + multi->clients[i] =i2c_acpi_new_device (dev, i, &board_info); +if (!multi->clients[i]) { +dev_err (dev,"Error creating i2c-client, idx %d\n" , i); + ret = -ENODEV ; + goto error; + } + }
drivers/platform/x86/i2c-multi-instantiate.c line 89
Quoted 10 lines
drivers/platform/x86/i2c-multi-instantiate.c new file +10
-0+ +platform_set_drvdata (pdev, multi); +return 0 ; + +error: +while (--i >=0 ) +i2c_unregister_device (multi->clients[i]); + +return ret; +}
Thanks,
Signature · 1 line
heikki
Re: [PATCH v5 4/4] platform/x86: Add ACPI i2c-multi-instantiate pseudo driver
Hi,
Quoted 77 lines · Heikki Krogerus
Quoted 24 lines · Hans de Goede
On systems with ACPI instantiated i2c-clients, normally there is 1
fw_nodeper i2c-device and that fw-node contains 1 I2cSerialBus resource for that 1 i2c-device.But in some rare cases the manufacturer has decided to describe multiple i2c-devices in a single ACPI fwnode with multiple I2cSerialBus resources.
An earlier attempt to fix this in the i2c-core resulted in a lot of extra code to support this corner-case.
This commit introduces a new i2c-multi-instantiate driver which fixes this in a different way. This new driver can be built as a module which will only loaded on affected systems.
This driver will instantiate a new i2c-client per I2cSerialBus resource, using the
driver_datafrom theacpi_device_idit is binding to to tell it which chip-type (and optional irq-resource) to use when instantiating.Note this driver depends on a platform device being instantiated for the ACPI fwnode, see the
i2c_multi_instantiate_idslist of ACPI device-ids indrivers/acpi/scan.c:acpi_device_enumeration_by_parent().Signed-off-by Hans de Goede <[email protected]>---
<snip>
Quoted 34 lines
drivers/platform/x86/i2c-multi-instantiate.c new file +34
-0+static int i2c_multi_inst_probe (struct platform_device *pdev) +{ +struct i2c_multi_inst_data *multi; +const struct acpi_device_id *match; +const struct i2c_inst_data *inst_data; +struct i2c_board_info board_info = {}; +struct device *dev = &pdev->dev; +struct acpi_device *adev; +char name[32 ]; +int i, ret; + + match =acpi_match_device (dev->driver->acpi_match_table, dev); +if (!match) { +dev_err (dev,"Error ACPI match data is missing\n" ); +return -ENODEV ; + } + inst_data = (const struct i2c_inst_data *)match->driver_data; + + adev =ACPI_COMPANION (dev); + +/* Count number of clients to instantiate */ +for (i =0 ; inst_data[i].type; i++) {} + + multi =devm_kmalloc (dev, + offsetof(struct i2c_multi_inst_data, clients[i]), + GFP_KERNEL); +if (!multi) +return -ENOMEM ; + + multi->num_clients = i; + +for (i =0 ; i < multi->num_clients; i++) { +memset (&board_info,0 ,sizeof (board_info)); +strlcpy (board_info.type, inst_data[i].type,I2C_NAME_SIZE );drivers/platform/x86/i2c-multi-instantiate.c line 69
Quoted 10 lines
drivers/platform/x86/i2c-multi-instantiate.c new file +10
-0+snprintf (name,sizeof (name),"%s-%s" , match->id, + inst_data[i].type); + board_info.dev_name = name; + board_info.irq =0 ; +if (inst_data[i].irq_idx !=-1 ) { + ret =acpi_dev_gpio_irq_get (adev, inst_data[i].irq_idx); +if (ret <0 ) { +dev_err (dev,"Error requesting irq at index %d: %d\n" , + inst_data[i].irq_idx, ret); + goto error;This seems to assume that we always have GpioInt with assigned for these devices, but that's wrong. This needs to work with normal Interrupt type resources as well.
Quoted 5 lines
The TI USB PD controller instances (HID 3515) for exmaple have normal Interrupts assigned to them
Why not use the "
irq_idx" with normal interrupts, and add a new member for the GpioInts, something likegpio_irq_idx?
I don't have any use-cases to test using normal interrupts, so I will leave adding support for that to the first patch adding support for a device which needs that, such as the HID3515 you mention.
I do agree that it is good to prepare for adding this later, so I'm going to post a v6 doing s/irq_idx/gpio_irq_idx/
Regards,
Hans
Quoted 24 lines
Quoted 11 lines
drivers/platform/x86/i2c-multi-instantiate.c new file +10
-0+ } + board_info.irq = ret; + } + multi->clients[i] =i2c_acpi_new_device (dev, i, &board_info); +if (!multi->clients[i]) { +dev_err (dev,"Error creating i2c-client, idx %d\n" , i); + ret = -ENODEV ; + goto error; + } + }drivers/platform/x86/i2c-multi-instantiate.c line 89
Quoted 10 lines
drivers/platform/x86/i2c-multi-instantiate.c new file +10
-0+ +platform_set_drvdata (pdev, multi); +return 0 ; + +error: +while (--i >=0 ) +i2c_unregister_device (multi->clients[i]); + +return ret; +}Thanks,