Add support for X86/ACPI camera sensor/PMIC setup with clk and regulator platform data
Subsystems (11)
v3 cover Add support for X86/ACPI camera sensor/PMIC setup with clk and regulator platform data
Hi All,
Here is v2 of my patch-set adding support for camera sensor connected to a TPS68470 PMIC on x86/ACPI devices.
v3 of this patch-set further reworks how to defer the binding of the camera-sensor drivers till all clk/regulator/gpio consumer/lookup info has been registered. See the new patch 1 + 2 (replacing v1 patch 1-3 / v2 patch 1-2).
I'm quite happy with how this works now, so from my pov this is the final version of the device-instantiation deferral code / approach.
###
The clk and regulator frameworks expect clk/regulator consumer-devices to have info about the consumed clks/regulators described in the device's fw_node, but on ACPI this info is missing.
This series worksaround this by providing platform_data with the info to the TPS68470 clk/regulator MFD cells.
Patches 1 - 2 deal with a probe-ordering problem this introduces, since the lookups are only registered when the provider-driver binds, trying to get these clks/regulators before then results in a -ENOENT error for clks and a dummy regulator for regulators. See the patches for more details.
Patch 3 adds a header file which adds tps68470_clk_platform_data and tps68470_regulator_platform_data structs. The futher patches depend on this new header file.
Patch 4 + 5 add the TPS68470 clk and regulator drivers
Patches 6 - 11 Modify the INT3472 driver which instantiates the MFD cells to provide the necessary platform-data.
Assuming this series is acceptable to everyone, we need to talk about how to merge this.
Assuming the i2c-core-acpi.c are ok with it patches 1 + 2 can both be merged into linux-pm by Rafael, independent of the rest of the series (there are some runtime deps on other changes for everything to work, but the camera-sensors impacted by this are not fully supported yet in the mainline kernel anyways).
For "[PATCH 03/13] platform_data: Add linux/platform_data/tps68470.h file", which all further patches depend on I plan to provide an immutable branch myself (once it has been reviewed), which the clk / regulator maintainers can then merge before merging the clk / regulator driver which depends on this.
And I will merge that IM-branch + patches 6-11 into the pdx86 tree myself.
Regards,
Hans
Daniel Scally (1):
platform/x86: int3472: Enable I2c daisy chain
Hans de Goede (10):
ACPI: delay enumeration of devices with a _DEP pointing to an INT3472
device
i2c: acpi: Use acpi_dev_ready_for_enumeration() helper
platform_data: Add linux/platform_data/tps68470.h file
regulator: Introduce tps68470-regulator driver
clk: Introduce clk-tps68470 driver
platform/x86: int3472: Split into 2 drivers
platform/x86: int3472: Add get_sensor_adev_and_name() helper platform/x86: int3472: Pass tps68470_clk_platform_data to the
tps68470-regulator MFD-cell
platform/x86: int3472: Pass tps68470_regulator_platform_data to the
tps68470-regulator MFD-cellplatform/x86: int3472: Deal with probe ordering issues
drivers/acpi/scan.c | 36 ++-
drivers/clk/Kconfig | 6 +
drivers/clk/Makefile | 1 +
drivers/clk/clk-tps68470.c | 256 ++++++++++++++++++
drivers/i2c/i2c-core-acpi.c | 5 +-
drivers/platform/x86/intel/int3472/Makefile | 9 +-
...lk_and_regulator.c => clk_and_regulator.c} | 2 +-
drivers/platform/x86/intel/int3472/common.c | 82 ++++++
.../{intel_skl_int3472_common.h => common.h} | 6 +-
...ntel_skl_int3472_discrete.c => discrete.c} | 51 ++--
.../intel/int3472/intel_skl_int3472_common.c | 106 --------
...ntel_skl_int3472_tps68470.c => tps68470.c} | 97 ++++++-
drivers/platform/x86/intel/int3472/tps68470.h | 25 ++
.../x86/intel/int3472/tps68470_board_data.c | 118 ++++++++
drivers/regulator/Kconfig | 9 +
drivers/regulator/Makefile | 1 +
drivers/regulator/tps68470-regulator.c | 193 +++++++++++++
include/acpi/acpi_bus.h | 5 +-
include/linux/mfd/tps68470.h | 11 +
include/linux/platform_data/tps68470.h | 35 +++
20 files changed, 904 insertions(+), 150 deletions(-)
create mode 100644 drivers/clk/clk-tps68470.c
rename drivers/platform/x86/intel/int3472/{intel_skl_int3472_clk_and_regulator.c => clk_and_regulator.c} (99%)
create mode 100644 drivers/platform/x86/intel/int3472/common.c
rename drivers/platform/x86/intel/int3472/{intel_skl_int3472_common.h => common.h} (94%)
rename drivers/platform/x86/intel/int3472/{intel_skl_int3472_discrete.c => discrete.c} (91%)
delete mode 100644 drivers/platform/x86/intel/int3472/intel_skl_int3472_common.c
rename drivers/platform/x86/intel/int3472/{intel_skl_int3472_tps68470.c => tps68470.c} (55%)
create mode 100644 drivers/platform/x86/intel/int3472/tps68470.h
create mode 100644 drivers/platform/x86/intel/int3472/tps68470_board_data.c
create mode 100644 drivers/regulator/tps68470-regulator.c
create mode 100644 include/linux/platform_data/tps68470.hSignature · 1 line
2.31.1
PATCH v3 1/11 ACPI: delay enumeration of devices with a _DEP pointing to an INT3472 device
The clk and regulator frameworks expect clk/regulator consumer-devices to have info about the consumed clks/regulators described in the device's fw_node.
To work around cases where this info is not present in the firmware tables, which is often the case on x86/ACPI devices, both frameworks allow the provider-driver to attach info about consumers to the clks/regulators when registering these.
This causes problems with the probe ordering wrt drivers for consumers of these clks/regulators. Since the lookups are only registered when the provider-driver binds, trying to get these clks/regulators before then results in a -ENOENT error for clks and a dummy regulator for regulators.
One case where we hit this issue is camera sensors such as e.g. the OV8865 sensor found on the Microsoft Surface Go. The sensor uses clks, regulators and GPIOs provided by a TPS68470 PMIC which is described in an INT3472 ACPI device. There is special platform code handling this and setting platform_data with the necessary consumer info on the MFD cells instantiated for the PMIC under: drivers/platform/x86/intel/int3472.
For this to work properly the ov8865 driver must not bind to the I2C-client for the OV8865 sensor until after the TPS68470 PMIC gpio, regulator and clk MFD cells have all been fully setup.
The OV8865 on the Microsoft Surface Go is just one example, all X86 devices using the Intel IPU3 camera block found on recent Intel SoCs have similar issues where there is an INT3472 HID ACPI-device, which describes the clks and regulators, and the driver for this INT3472 device must be fully initialized before the sensor driver (any sensor driver) binds for things to work properly.
On these devices the ACPI nodes describing the sensors all have a _DEP dependency on the matching INT3472 ACPI device (there is one per sensor).
This allows solving the probe-ordering problem by delaying the enumeration (instantiation of the I2C-client in the ov8865 example) of ACPI-devices which have a _DEP dependency on an INT3472 device.
The new acpi_dev_ready_for_enumeration() helper used for this is also exported because for devices, which have the enumeration_by_parent flag set, the parent-driver will do its own scan of child ACPI devices and it will try to enumerate those during its probe(). Code doing this such as e.g. the i2c-core-acpi.c code must call this new helper to ensure that it too delays the enumeration until all the _DEP dependencies are met on devices which have the new honor_deps flag set.
--- drivers/acpi/scan.c | 36 ++++++++++++++++++++++++++++++++++-- include/acpi/acpi_bus.h | 5 ++++- 2 files changed, 38 insertions(+), 3 deletions(-)
drivers/acpi/scan.c +34 -2
@@ -796,6 +796,12 @@ static const char * const acpi_ignore_dep_ids[] = { NULL }; +/* List of HIDs for which we honor deps of matching ACPI devs, when checking _DEP lists. */ +static const char *const acpi_honor_dep_ids[] = { +"INT3472" ,/* Camera sensor PMIC / clk and regulator info */ +NULL +}; +static struct acpi_device *acpi_bus_get_parent (acpi_handle handle) {struct acpi_device *device =NULL ;
@@ -1757,8 +1763,12 @@ static void acpi_scan_dep_init(struct acpi_device *adev)struct acpi_dep_data *dep;list_for_each_entry (dep, &acpi_dep_list, node) { -if (dep->consumer == adev->handle) +if (dep->consumer == adev->handle) { +if (dep->honor_dep) + adev->flags.honor_deps =1 ; + adev->dep_unmet++; + } } }
@@ -1962,7 +1972,7 @@ static u32 acpi_scan_check_dep(acpi_handle handle, bool check_dep)for (count =0 , i =0 ; i < dep_devices.count; i++) {struct acpi_device_info *info;struct acpi_dep_data *dep; -bool skip; +bool skip, honor_dep; status =acpi_get_object_info (dep_devices.handles[i], &info);if (ACPI_FAILURE (status)) {
@@ -1971,6 +1981,7 @@ static u32 acpi_scan_check_dep(acpi_handle handle, bool check_dep) } skip =acpi_info_matches_ids (info, acpi_ignore_dep_ids); + honor_dep =acpi_info_matches_ids (info, acpi_honor_dep_ids);kfree (info);if (skip)
@@ -1984,6 +1995,7 @@ static u32 acpi_scan_check_dep(acpi_handle handle, bool check_dep) dep->supplier = dep_devices.handles[i]; dep->consumer = handle; + dep->honor_dep = honor_dep;mutex_lock (&acpi_dep_list_lock);list_add_tail (&dep->node , &acpi_dep_list);
@@ -2071,6 +2083,9 @@ static acpi_status acpi_bus_check_add_2(acpi_handle handle, u32 lvl_not_used,static void acpi_default_enumeration (struct acpi_device *device) { +if (!acpi_dev_ready_for_enumeration (device)) +return ; +/* * Do not enumerate devices with enumeration_by_parent flag set as * they will be enumerated by their respective parents.
@@ -2313,6 +2328,23 @@ void acpi_dev_clear_dependencies(struct acpi_device *supplier) }EXPORT_SYMBOL_GPL (acpi_dev_clear_dependencies); +/** +* acpi_dev_ready_for_enumeration - Check if the ACPI device is ready for enumeration +* @device: Pointer to the &struct acpi_device to check +* +* Check if the device is present and has no unmet dependencies. +* +* Return true if the device is ready for enumeratino. Otherwise, return false. +*/ +bool acpi_dev_ready_for_enumeration (const struct acpi_device *device) +{ +if (device->flags.honor_deps && device->dep_unmet) +return false; + +return acpi_device_is_present (device); +} +EXPORT_SYMBOL_GPL (acpi_dev_ready_for_enumeration); +/** * acpi_dev_get_first_consumer_dev - Return ACPI device dependent on @supplier * @supplier: Pointer to the dependee device
include/acpi/acpi_bus.h +4 -1
@@ -202,7 +202,8 @@ struct acpi_device_flags { u32 coherent_dma:1; u32 cca_seen:1; u32 enumeration_by_parent:1; - u32 reserved:19; + u32 honor_deps:1; + u32 reserved:18; };/* File System */
@@ -284,6 +285,7 @@ struct acpi_dep_data {struct list_head node;acpi_handle supplier;acpi_handle consumer; +bool honor_dep; };/* Performance Management */
@@ -693,6 +695,7 @@ static inline bool acpi_device_can_poweroff(struct acpi_device *adev)bool acpi_dev_hid_uid_match (struct acpi_device *adev,const char *hid2,const char *uid2);void acpi_dev_clear_dependencies (struct acpi_device *supplier); +bool acpi_dev_ready_for_enumeration (const struct acpi_device *device);struct acpi_device *acpi_dev_get_first_consumer_dev (struct acpi_device *supplier);struct acpi_device *acpi_dev_get_next_match_dev (struct acpi_device *adev,const char *hid,const char *uid,s64 hrv);
Signature · 1 line
2.31.1
Re: [PATCH v3 01/11] ACPI: delay enumeration of devices with a _DEP pointing to an INT3472 device
Hi,
drivers/acpi/scan.c static const char * const acpi_ignore_dep_ids[] = { · line 801
Quoted 3 lines · Hans de Goede
drivers/acpi/scan.c +3
-0+/* List of HIDs for which we honor deps of matching ACPI devs, when checking _DEP lists. */ +static const char *const acpi_honor_dep_ids[] = { +"INT3472" ,/* Camera sensor PMIC / clk and regulator info */
Is there some reason why we can't do this for all devices with _DEP? That way we don't need to maintain lists like this.
Otherwise looks good.
Re: [PATCH v3 01/11] ACPI: delay enumeration of devices with a _DEP pointing to an INT3472 device
Hi,
Quoted 9 lines · Mika Westerberg
Hi,
drivers/acpi/scan.c static const char * const acpi_ignore_dep_ids[] = { · line 801
Quoted 3 lines · Hans de Goede
drivers/acpi/scan.c +3
-0+/* List of HIDs for which we honor deps of matching ACPI devs, when checking _DEP lists. */ +static const char *const acpi_honor_dep_ids[] = { +"INT3472" ,/* Camera sensor PMIC / clk and regulator info */ Is there some reason why we can't do this for all devices with
_DEP? That way we don't need to maintain lists like this.
Up until now the ACPI core deliberate mostly ignores _DEP-s because the _DEP method may point to pretty much any random ACPI object and Linux does not necessarily have a driver for all ACPI objects the driver points too, which would lead to the devices never getting instantiated.
In hindsight this might not have been the best solution (1), but if we now start honoring _DEP-s for all devices all of a sudden then this will almost certainly lead to a whole bunch of regressions.
Note that in this case the HID which triggers this is for the device being depended upon and for all camera sensors used with the IPU3 and IPU4 Intel camera blocks this is the INT3472 device. By triggering on this HID (rather then on the sensor HIDs) I expect that we will not need to update this list all that often.
Regards,
Hans
1) I believe that Windows does pay more reference to the _DEP-s and we've had some other related issues lately.
Re: [PATCH v3 01/11] ACPI: delay enumeration of devices with a _DEP pointing to an INT3472 device
Quoted 22 lines · Hans de Goede
Hi,
Quoted 9 lines · Mika Westerberg
Hi,
drivers/acpi/scan.c static const char * const acpi_ignore_dep_ids[] = { · line 801
Quoted 3 lines · Hans de Goede
drivers/acpi/scan.c +3
-0+/* List of HIDs for which we honor deps of matching ACPI devs, when checking _DEP lists. */ +static const char *const acpi_honor_dep_ids[] = { +"INT3472" ,/* Camera sensor PMIC / clk and regulator info */ Is there some reason why we can't do this for all devices with
_DEP? That way we don't need to maintain lists like this.Up until now the ACPI core deliberate mostly ignores _DEP-s because the
_DEPmethod may point to pretty much any random ACPI object and Linux does not necessarily have a driver for all ACPI objects the driver points too, which would lead to the devices never getting instantiated.In hindsight this might not have been the best solution (1), but if we now start honoring _DEP-s for all devices all of a sudden then this will almost certainly lead to a whole bunch of regressions.
Quoted 5 lines
Note that in this case the HID which triggers this is for the device being depended upon and for all camera sensors used with the IPU3 and IPU4 Intel camera blocks this is the INT3472 device. By triggering on this HID (rather then on the sensor HIDs) I expect that we will not need to update this list all that often.
I see and agree. Thanks for the explanation!
No objections from my side then :)
Rafael J. Wysocki
maintainerRe: [PATCH v3 01/11] ACPI: delay enumeration of devices with a _DEP pointing to an INT3472 device
In reply to Hans de GoedeQuoted 72 lines · Hans de Goede
The clk and regulator frameworks expect clk/regulator consumer-devices to have info about the consumed clks/regulators described in the device's
fw_node.To work around cases where this info is not present in the firmware tables, which is often the case on x86/ACPI devices, both frameworks allow the provider-driver to attach info about consumers to the clks/regulators when registering these.
This causes problems with the probe ordering wrt drivers for consumers of these clks/regulators. Since the lookups are only registered when the provider-driver binds, trying to get these clks/regulators before then results in a
-ENOENTerror for clks and a dummy regulator for regulators.One case where we hit this issue is camera sensors such as e.g. the OV8865 sensor found on the Microsoft Surface Go. The sensor uses clks, regulators and GPIOs provided by a TPS68470 PMIC which is described in an INT3472 ACPI device. There is special platform code handling this and setting
platform_datawith the necessary consumer info on the MFD cells instantiated for the PMIC under:drivers/platform/x86/intel/int3472.For this to work properly the ov8865 driver must not bind to the I2C-client for the OV8865 sensor until after the TPS68470 PMIC gpio, regulator and clk MFD cells have all been fully setup.
The OV8865 on the Microsoft Surface Go is just one example, all X86 devices using the Intel IPU3 camera block found on recent Intel SoCs have similar issues where there is an INT3472 HID ACPI-device, which describes the clks and regulators, and the driver for this INT3472 device must be fully initialized before the sensor driver (any sensor driver) binds for things to work properly.
On these devices the ACPI nodes describing the sensors all have a
_DEPdependency on the matching INT3472 ACPI device (there is one per sensor).This allows solving the probe-ordering problem by delaying the enumeration (instantiation of the I2C-client in the ov8865 example) of ACPI-devices which have a
_DEPdependency on an INT3472 device.The new
acpi_dev_ready_for_enumeration()helper used for this is also exported because for devices, which have theenumeration_by_parentflag set, the parent-driver will do its own scan of child ACPI devices and it will try to enumerate those during itsprobe(). Code doing this such as e.g. thei2c-core-acpi.ccode must call this new helper to ensure that it too delays the enumeration until all the_DEPdependencies are met on devices which have the newhonor_depsflag set.Signed-off-by Hans de Goede <[email protected]>--- drivers/acpi/scan.c | 36 ++++++++++++++++++++++++++++++++++-- include/acpi/acpi_bus.h | 5 ++++- 2 files changed, 38 insertions(+), 3 deletions(-)drivers/acpi/scan.c +6
-0@@ -796,6 +796,12 @@ static const char * const acpi_ignore_dep_ids[] = { NULL }; +/* List of HIDs for which we honor deps of matching ACPI devs, when checking _DEP lists. */ +static const char *const acpi_honor_dep_ids[] = { +"INT3472" ,/* Camera sensor PMIC / clk and regulator info */ +NULL +}; +static struct acpi_device *acpi_bus_get_parent (acpi_handle handle) {struct acpi_device *device =NULL ;
drivers/acpi/scan.c static void acpi_scan_dep_init(struct acpi_device *adev) · line 1768
Quoted 7 lines
drivers/acpi/scan.c +3
-1@@ -1757,8 +1763,12 @@ static void acpi_scan_dep_init(struct acpi_device *adev)struct acpi_dep_data *dep;list_for_each_entry (dep, &acpi_dep_list, node) { -if (dep->consumer == adev->handle) +if (dep->consumer == adev->handle) { +if (dep->honor_dep) + adev->flags.honor_deps =1 ;
Any concerns about doing
adev->flags.honor_deps = dep->honor_dep;
here?
Quoted 32 lines
drivers/acpi/scan.c +5
-1+ adev->dep_unmet++; + } } }@@ -1962,7 +1972,7 @@ static u32 acpi_scan_check_dep(acpi_handle handle, bool check_dep)for (count =0 , i =0 ; i < dep_devices.count; i++) {struct acpi_device_info *info;struct acpi_dep_data *dep; -bool skip; +bool skip, honor_dep; status =acpi_get_object_info (dep_devices.handles[i], &info);if (ACPI_FAILURE (status)) {@@ -1971,6 +1981,7 @@ static u32 acpi_scan_check_dep(acpi_handle handle, bool check_dep) } skip =acpi_info_matches_ids (info, acpi_ignore_dep_ids); + honor_dep =acpi_info_matches_ids (info, acpi_honor_dep_ids);kfree (info);if (skip)@@ -1984,6 +1995,7 @@ static u32 acpi_scan_check_dep(acpi_handle handle, bool check_dep) dep->supplier = dep_devices.handles[i]; dep->consumer = handle; + dep->honor_dep = honor_dep;mutex_lock (&acpi_dep_list_lock);list_add_tail (&dep->node , &acpi_dep_list);
drivers/acpi/scan.c static acpi_status acpi_bus_check_add_2(acpi_handle handle, u32 lvl_not_used, · line 2087
Quoted 5 lines
drivers/acpi/scan.c +2
-0@@ -2071,6 +2083,9 @@ static acpi_status acpi_bus_check_add_2(acpi_handle handle, u32 lvl_not_used,static void acpi_default_enumeration (struct acpi_device *device) { +if (!acpi_dev_ready_for_enumeration (device)) +return ;
I'm not sure about this.
First of all, this adds an acpi_device_is_present() check here which potentially is a change in behavior and I'm not sure how it is related to the other changes in this patch (it is not mentioned in the changelog AFAICS).
I'm saying "potentially", because if we get here at all, acpi_device_is_present() has been evaluated already by acpi_bus_attach().
Now, IIUC, the new acpi_dev_ready_for_enumeration() is kind of an extension of acpi_device_is_present(), so shouldn't it be called by acpi_bus_attach() instead of the latter rather than from here?
Quoted 59 lines
drivers/acpi/scan.c +18
-0+/* * Do not enumerate devices with enumeration_by_parent flag set as * they will be enumerated by their respective parents. @@ -2313,6 +2328,23 @@ void acpi_dev_clear_dependencies(struct acpi_device *supplier) }EXPORT_SYMBOL_GPL (acpi_dev_clear_dependencies); +/** +* acpi_dev_ready_for_enumeration - Check if the ACPI device is ready for enumeration +* @device: Pointer to the &struct acpi_device to check +* +* Check if the device is present and has no unmet dependencies. +* +* Return true if the device is ready for enumeratino. Otherwise, return false. +*/ +bool acpi_dev_ready_for_enumeration (const struct acpi_device *device) +{ +if (device->flags.honor_deps && device->dep_unmet) +return false; + +return acpi_device_is_present (device); +} +EXPORT_SYMBOL_GPL (acpi_dev_ready_for_enumeration); +/** * acpi_dev_get_first_consumer_dev - Return ACPI device dependent on @supplier * @supplier: Pointer to the dependee device include/acpi/acpi_bus.h +4
-2@@ -202,7 +202,8 @@ struct acpi_device_flags { u32 coherent_dma:1; u32 cca_seen:1; u32 enumeration_by_parent:1; - u32 reserved:19; + u32 honor_deps:1; + u32 reserved:18; };/* File System */ @@ -284,6 +285,7 @@ struct acpi_dep_data {struct list_head node;acpi_handle supplier;acpi_handle consumer; +bool honor_dep; };/* Performance Management */ @@ -693,6 +695,7 @@ static inline bool acpi_device_can_poweroff(struct acpi_device *adev)bool acpi_dev_hid_uid_match (struct acpi_device *adev,const char *hid2,const char *uid2);void acpi_dev_clear_dependencies (struct acpi_device *supplier); +bool acpi_dev_ready_for_enumeration (const struct acpi_device *device);struct acpi_device *acpi_dev_get_first_consumer_dev (struct acpi_device *supplier);struct acpi_device *acpi_dev_get_next_match_dev (struct acpi_device *adev,const char *hid,const char *uid,s64 hrv); --
Re: [PATCH v3 01/11] ACPI: delay enumeration of devices with a _DEP pointing to an INT3472 device
Hi,
Quoted 83 lines · Rafael J. Wysocki
Quoted 72 lines · Hans de Goede
The clk and regulator frameworks expect clk/regulator consumer-devices to have info about the consumed clks/regulators described in the device's
fw_node.To work around cases where this info is not present in the firmware tables, which is often the case on x86/ACPI devices, both frameworks allow the provider-driver to attach info about consumers to the clks/regulators when registering these.
This causes problems with the probe ordering wrt drivers for consumers of these clks/regulators. Since the lookups are only registered when the provider-driver binds, trying to get these clks/regulators before then results in a
-ENOENTerror for clks and a dummy regulator for regulators.One case where we hit this issue is camera sensors such as e.g. the OV8865 sensor found on the Microsoft Surface Go. The sensor uses clks, regulators and GPIOs provided by a TPS68470 PMIC which is described in an INT3472 ACPI device. There is special platform code handling this and setting
platform_datawith the necessary consumer info on the MFD cells instantiated for the PMIC under:drivers/platform/x86/intel/int3472.For this to work properly the ov8865 driver must not bind to the I2C-client for the OV8865 sensor until after the TPS68470 PMIC gpio, regulator and clk MFD cells have all been fully setup.
The OV8865 on the Microsoft Surface Go is just one example, all X86 devices using the Intel IPU3 camera block found on recent Intel SoCs have similar issues where there is an INT3472 HID ACPI-device, which describes the clks and regulators, and the driver for this INT3472 device must be fully initialized before the sensor driver (any sensor driver) binds for things to work properly.
On these devices the ACPI nodes describing the sensors all have a
_DEPdependency on the matching INT3472 ACPI device (there is one per sensor).This allows solving the probe-ordering problem by delaying the enumeration (instantiation of the I2C-client in the ov8865 example) of ACPI-devices which have a
_DEPdependency on an INT3472 device.The new
acpi_dev_ready_for_enumeration()helper used for this is also exported because for devices, which have theenumeration_by_parentflag set, the parent-driver will do its own scan of child ACPI devices and it will try to enumerate those during itsprobe(). Code doing this such as e.g. thei2c-core-acpi.ccode must call this new helper to ensure that it too delays the enumeration until all the_DEPdependencies are met on devices which have the newhonor_depsflag set.Signed-off-by Hans de Goede <[email protected]>--- drivers/acpi/scan.c | 36 ++++++++++++++++++++++++++++++++++-- include/acpi/acpi_bus.h | 5 ++++- 2 files changed, 38 insertions(+), 3 deletions(-)drivers/acpi/scan.c +6
-0@@ -796,6 +796,12 @@ static const char * const acpi_ignore_dep_ids[] = { NULL }; +/* List of HIDs for which we honor deps of matching ACPI devs, when checking _DEP lists. */ +static const char *const acpi_honor_dep_ids[] = { +"INT3472" ,/* Camera sensor PMIC / clk and regulator info */ +NULL +}; +static struct acpi_device *acpi_bus_get_parent (acpi_handle handle) {struct acpi_device *device =NULL ;drivers/acpi/scan.c static void acpi_scan_dep_init(struct acpi_device *adev) · line 1768
Quoted 7 lines
drivers/acpi/scan.c +3
-1@@ -1757,8 +1763,12 @@ static void acpi_scan_dep_init(struct acpi_device *adev)struct acpi_dep_data *dep;list_for_each_entry (dep, &acpi_dep_list, node) { -if (dep->consumer == adev->handle) +if (dep->consumer == adev->handle) { +if (dep->honor_dep) + adev->flags.honor_deps =1 ;Any concerns about doing
Quoted 3 lines
adev->flags.honor_deps=dep->honor_dep;here?
The idea is to set adev->flags.honor_deps even if the device has multiple deps and only one of them has the honor_dep flag set.
If we just do:
adev->flags.honor_deps = dep->honor_dep;
Then adev->flags.honor_deps ends up having the honor_dep flag of the last dependency checked.
Quoted 41 lines
Quoted 33 lines
drivers/acpi/scan.c +5
-1+ adev->dep_unmet++; + } } }@@ -1962,7 +1972,7 @@ static u32 acpi_scan_check_dep(acpi_handle handle, bool check_dep)for (count =0 , i =0 ; i < dep_devices.count; i++) {struct acpi_device_info *info;struct acpi_dep_data *dep; -bool skip; +bool skip, honor_dep; status =acpi_get_object_info (dep_devices.handles[i], &info);if (ACPI_FAILURE (status)) {@@ -1971,6 +1981,7 @@ static u32 acpi_scan_check_dep(acpi_handle handle, bool check_dep) } skip =acpi_info_matches_ids (info, acpi_ignore_dep_ids); + honor_dep =acpi_info_matches_ids (info, acpi_honor_dep_ids);kfree (info);if (skip)@@ -1984,6 +1995,7 @@ static u32 acpi_scan_check_dep(acpi_handle handle, bool check_dep) dep->supplier = dep_devices.handles[i]; dep->consumer = handle; + dep->honor_dep = honor_dep;mutex_lock (&acpi_dep_list_lock);list_add_tail (&dep->node , &acpi_dep_list);drivers/acpi/scan.c static acpi_status acpi_bus_check_add_2(acpi_handle handle, u32 lvl_not_used, · line 2087
Quoted 5 lines
drivers/acpi/scan.c +2
-0@@ -2071,6 +2083,9 @@ static acpi_status acpi_bus_check_add_2(acpi_handle handle, u32 lvl_not_used,static void acpi_default_enumeration (struct acpi_device *device) { +if (!acpi_dev_ready_for_enumeration (device)) +return ;I'm not sure about this.
Quoted 8 lines
First of all, this adds an
acpi_device_is_present()check here which potentially is a change in behavior and I'm not sure how it is related to the other changes in this patch (it is not mentioned in the changelog AFAICS).I'm saying "potentially", because if we get here at all,
acpi_device_is_present()has been evaluated already byacpi_bus_attach().
Right the idea was that for this code-path the extra acpi_device_is_present() check is a no-op since the only caller of acpi_default_enumeration() has already done that check before calling acpi_default_enumeration(), where as the is_present check is useful for users outside of the ACPI core code, like e.g. the i2c ACPI enumeration code.
Although I see this is also called from acpi_generic_device_attach which comes into play when there is devicetree info embedded inside the ACPI tables.
Quoted 3 lines
Now, IIUC, the new
acpi_dev_ready_for_enumeration()is kind of an extension ofacpi_device_is_present(), so shouldn't it be called byacpi_bus_attach()instead of the latter rather than from here?
That is an interesting proposal. I assume you want this to replace the current acpi_device_is_present() call in acpi_bus_attach() then ?
For the use-case at hand here that should work fine and it would also make the honor_deps flag work for devices which bind to the actual acpi_device (because we delay the device_attach()) or
use an acpi_scan_handler.
This would mean though that we can now have acpi_device-s where acpi_device_is_present() returns true, but which are not initialized (do not have device->flags.initialized set) that would be a new acpi_device state which we have not had before. I do not immediately forsee this causing issues, but still...
If you want me to replace the current acpi_device_is_present() call in acpi_bus_attach() with the new acpi_dev_ready_for_enumeration() helper, let me know and I'll prepare a new version with this change (and run some tests with that new version).
Regards,
Hans
Quoted 61 lines
Quoted 60 lines
drivers/acpi/scan.c +18
-0+/* * Do not enumerate devices with enumeration_by_parent flag set as * they will be enumerated by their respective parents. @@ -2313,6 +2328,23 @@ void acpi_dev_clear_dependencies(struct acpi_device *supplier) }EXPORT_SYMBOL_GPL (acpi_dev_clear_dependencies); +/** +* acpi_dev_ready_for_enumeration - Check if the ACPI device is ready for enumeration +* @device: Pointer to the &struct acpi_device to check +* +* Check if the device is present and has no unmet dependencies. +* +* Return true if the device is ready for enumeratino. Otherwise, return false. +*/ +bool acpi_dev_ready_for_enumeration (const struct acpi_device *device) +{ +if (device->flags.honor_deps && device->dep_unmet) +return false; + +return acpi_device_is_present (device); +} +EXPORT_SYMBOL_GPL (acpi_dev_ready_for_enumeration); +/** * acpi_dev_get_first_consumer_dev - Return ACPI device dependent on @supplier * @supplier: Pointer to the dependee device include/acpi/acpi_bus.h +4
-2@@ -202,7 +202,8 @@ struct acpi_device_flags { u32 coherent_dma:1; u32 cca_seen:1; u32 enumeration_by_parent:1; - u32 reserved:19; + u32 honor_deps:1; + u32 reserved:18; };/* File System */ @@ -284,6 +285,7 @@ struct acpi_dep_data {struct list_head node;acpi_handle supplier;acpi_handle consumer; +bool honor_dep; };/* Performance Management */ @@ -693,6 +695,7 @@ static inline bool acpi_device_can_poweroff(struct acpi_device *adev)bool acpi_dev_hid_uid_match (struct acpi_device *adev,const char *hid2,const char *uid2);void acpi_dev_clear_dependencies (struct acpi_device *supplier); +bool acpi_dev_ready_for_enumeration (const struct acpi_device *device);struct acpi_device *acpi_dev_get_first_consumer_dev (struct acpi_device *supplier);struct acpi_device *acpi_dev_get_next_match_dev (struct acpi_device *adev,const char *hid,const char *uid,s64 hrv); --
Rafael J. Wysocki
maintainerRe: [PATCH v3 01/11] ACPI: delay enumeration of devices with a _DEP pointing to an INT3472 device
Quoted 94 lines · Hans de Goede
Hi,
Quoted 83 lines · Rafael J. Wysocki
Quoted 72 lines · Hans de Goede
The clk and regulator frameworks expect clk/regulator consumer-devices to have info about the consumed clks/regulators described in the device's
fw_node.To work around cases where this info is not present in the firmware tables, which is often the case on x86/ACPI devices, both frameworks allow the provider-driver to attach info about consumers to the clks/regulators when registering these.
This causes problems with the probe ordering wrt drivers for consumers of these clks/regulators. Since the lookups are only registered when the provider-driver binds, trying to get these clks/regulators before then results in a
-ENOENTerror for clks and a dummy regulator for regulators.One case where we hit this issue is camera sensors such as e.g. the OV8865 sensor found on the Microsoft Surface Go. The sensor uses clks, regulators and GPIOs provided by a TPS68470 PMIC which is described in an INT3472 ACPI device. There is special platform code handling this and setting
platform_datawith the necessary consumer info on the MFD cells instantiated for the PMIC under:drivers/platform/x86/intel/int3472.For this to work properly the ov8865 driver must not bind to the I2C-client for the OV8865 sensor until after the TPS68470 PMIC gpio, regulator and clk MFD cells have all been fully setup.
The OV8865 on the Microsoft Surface Go is just one example, all X86 devices using the Intel IPU3 camera block found on recent Intel SoCs have similar issues where there is an INT3472 HID ACPI-device, which describes the clks and regulators, and the driver for this INT3472 device must be fully initialized before the sensor driver (any sensor driver) binds for things to work properly.
On these devices the ACPI nodes describing the sensors all have a
_DEPdependency on the matching INT3472 ACPI device (there is one per sensor).This allows solving the probe-ordering problem by delaying the enumeration (instantiation of the I2C-client in the ov8865 example) of ACPI-devices which have a
_DEPdependency on an INT3472 device.The new
acpi_dev_ready_for_enumeration()helper used for this is also exported because for devices, which have theenumeration_by_parentflag set, the parent-driver will do its own scan of child ACPI devices and it will try to enumerate those during itsprobe(). Code doing this such as e.g. thei2c-core-acpi.ccode must call this new helper to ensure that it too delays the enumeration until all the_DEPdependencies are met on devices which have the newhonor_depsflag set.Signed-off-by Hans de Goede <[email protected]>--- drivers/acpi/scan.c | 36 ++++++++++++++++++++++++++++++++++-- include/acpi/acpi_bus.h | 5 ++++- 2 files changed, 38 insertions(+), 3 deletions(-)drivers/acpi/scan.c +6
-0@@ -796,6 +796,12 @@ static const char * const acpi_ignore_dep_ids[] = { NULL }; +/* List of HIDs for which we honor deps of matching ACPI devs, when checking _DEP lists. */ +static const char *const acpi_honor_dep_ids[] = { +"INT3472" ,/* Camera sensor PMIC / clk and regulator info */ +NULL +}; +static struct acpi_device *acpi_bus_get_parent (acpi_handle handle) {struct acpi_device *device =NULL ;drivers/acpi/scan.c static void acpi_scan_dep_init(struct acpi_device *adev) · line 1768
Quoted 7 lines
drivers/acpi/scan.c +3
-1@@ -1757,8 +1763,12 @@ static void acpi_scan_dep_init(struct acpi_device *adev)struct acpi_dep_data *dep;list_for_each_entry (dep, &acpi_dep_list, node) { -if (dep->consumer == adev->handle) +if (dep->consumer == adev->handle) { +if (dep->honor_dep) + adev->flags.honor_deps =1 ;Any concerns about doing
Quoted 3 lines
adev->flags.honor_deps=dep->honor_dep;here?
The idea is to set
adev->flags.honor_depseven if the device has multiple deps and only one of them has thehonor_depflag set.
Quoted 6 lines
If we just do:
adev->flags.honor_deps = dep->honor_dep;Then
adev->flags.honor_depsends up having thehonor_depflag of the last dependency checked.
OK, but in that case dep_unmet may be blocking the enumeration of the device even if the one in the acpi_honor_dep_ids[] list has probed successfully.
Isn't that a concern?
Quoted 58 lines
Quoted 41 lines
Quoted 33 lines
drivers/acpi/scan.c +5
-1+ adev->dep_unmet++; + } } }@@ -1962,7 +1972,7 @@ static u32 acpi_scan_check_dep(acpi_handle handle, bool check_dep)for (count =0 , i =0 ; i < dep_devices.count; i++) {struct acpi_device_info *info;struct acpi_dep_data *dep; -bool skip; +bool skip, honor_dep; status =acpi_get_object_info (dep_devices.handles[i], &info);if (ACPI_FAILURE (status)) {@@ -1971,6 +1981,7 @@ static u32 acpi_scan_check_dep(acpi_handle handle, bool check_dep) } skip =acpi_info_matches_ids (info, acpi_ignore_dep_ids); + honor_dep =acpi_info_matches_ids (info, acpi_honor_dep_ids);kfree (info);if (skip)@@ -1984,6 +1995,7 @@ static u32 acpi_scan_check_dep(acpi_handle handle, bool check_dep) dep->supplier = dep_devices.handles[i]; dep->consumer = handle; + dep->honor_dep = honor_dep;mutex_lock (&acpi_dep_list_lock);list_add_tail (&dep->node , &acpi_dep_list);drivers/acpi/scan.c static acpi_status acpi_bus_check_add_2(acpi_handle handle, u32 lvl_not_used, · line 2087
Quoted 5 lines
drivers/acpi/scan.c +2
-0@@ -2071,6 +2083,9 @@ static acpi_status acpi_bus_check_add_2(acpi_handle handle, u32 lvl_not_used,static void acpi_default_enumeration (struct acpi_device *device) { +if (!acpi_dev_ready_for_enumeration (device)) +return ;I'm not sure about this.
Quoted 8 lines
First of all, this adds an
acpi_device_is_present()check here which potentially is a change in behavior and I'm not sure how it is related to the other changes in this patch (it is not mentioned in the changelog AFAICS).I'm saying "potentially", because if we get here at all,
acpi_device_is_present()has been evaluated already byacpi_bus_attach().Right the idea was that for this code-path the extra
acpi_device_is_present()check is a no-op since the only caller ofacpi_default_enumeration()has already done that check before callingacpi_default_enumeration(), where as theis_presentcheck is useful for users outside of the ACPI core code, like e.g. the i2c ACPI enumeration code.
Quoted 3 lines
Although I see this is also called from
acpi_generic_device_attachwhich comes into play when there is devicetree info embedded inside the ACPI tables.
That too, but generally speaking this change should at least be mentioned in the changelog.
Quoted 7 lines
Quoted 3 lines
Now, IIUC, the new
acpi_dev_ready_for_enumeration()is kind of an extension ofacpi_device_is_present(), so shouldn't it be called byacpi_bus_attach()instead of the latter rather than from here?That is an interesting proposal. I assume you want this to replace the current
acpi_device_is_present()call inacpi_bus_attach()then ?
That seems consistent to me.
Quoted 12 lines
For the use-case at hand here that should work fine and it would also make the
honor_depsflag work for devices which bind to the actualacpi_device(because we delay thedevice_attach()) or
use anacpi_scan_handler.This would mean though that we can now have acpi_device-s where
acpi_device_is_present()returns true, but which are not initialized (do not havedevice->flags.initializedset) that would be a newacpi_devicestate which we have not had before. I do not immediately forsee this causing issues, but still...
Quoted 4 lines
If you want me to replace the current
acpi_device_is_present()call inacpi_bus_attach()with the newacpi_dev_ready_for_enumeration()helper, let me know and I'll prepare a new version with this change (and run some tests with that new version).
I would prefer doing that to making acpi_default_enumeration() special with respect to the handling of dependencies.
Re: [PATCH v3 01/11] ACPI: delay enumeration of devices with a _DEP pointing to an INT3472 device
Hi,
Quoted 99 lines · Rafael J. Wysocki
Quoted 98 lines · Hans de Goede
Hi,
Quoted 83 lines · Rafael J. Wysocki
Quoted 72 lines · Hans de Goede
The clk and regulator frameworks expect clk/regulator consumer-devices to have info about the consumed clks/regulators described in the device's
fw_node.To work around cases where this info is not present in the firmware tables, which is often the case on x86/ACPI devices, both frameworks allow the provider-driver to attach info about consumers to the clks/regulators when registering these.
This causes problems with the probe ordering wrt drivers for consumers of these clks/regulators. Since the lookups are only registered when the provider-driver binds, trying to get these clks/regulators before then results in a
-ENOENTerror for clks and a dummy regulator for regulators.One case where we hit this issue is camera sensors such as e.g. the OV8865 sensor found on the Microsoft Surface Go. The sensor uses clks, regulators and GPIOs provided by a TPS68470 PMIC which is described in an INT3472 ACPI device. There is special platform code handling this and setting
platform_datawith the necessary consumer info on the MFD cells instantiated for the PMIC under:drivers/platform/x86/intel/int3472.For this to work properly the ov8865 driver must not bind to the I2C-client for the OV8865 sensor until after the TPS68470 PMIC gpio, regulator and clk MFD cells have all been fully setup.
The OV8865 on the Microsoft Surface Go is just one example, all X86 devices using the Intel IPU3 camera block found on recent Intel SoCs have similar issues where there is an INT3472 HID ACPI-device, which describes the clks and regulators, and the driver for this INT3472 device must be fully initialized before the sensor driver (any sensor driver) binds for things to work properly.
On these devices the ACPI nodes describing the sensors all have a
_DEPdependency on the matching INT3472 ACPI device (there is one per sensor).This allows solving the probe-ordering problem by delaying the enumeration (instantiation of the I2C-client in the ov8865 example) of ACPI-devices which have a
_DEPdependency on an INT3472 device.The new
acpi_dev_ready_for_enumeration()helper used for this is also exported because for devices, which have theenumeration_by_parentflag set, the parent-driver will do its own scan of child ACPI devices and it will try to enumerate those during itsprobe(). Code doing this such as e.g. thei2c-core-acpi.ccode must call this new helper to ensure that it too delays the enumeration until all the_DEPdependencies are met on devices which have the newhonor_depsflag set.Signed-off-by Hans de Goede <[email protected]>--- drivers/acpi/scan.c | 36 ++++++++++++++++++++++++++++++++++-- include/acpi/acpi_bus.h | 5 ++++- 2 files changed, 38 insertions(+), 3 deletions(-)drivers/acpi/scan.c +6
-0@@ -796,6 +796,12 @@ static const char * const acpi_ignore_dep_ids[] = { NULL }; +/* List of HIDs for which we honor deps of matching ACPI devs, when checking _DEP lists. */ +static const char *const acpi_honor_dep_ids[] = { +"INT3472" ,/* Camera sensor PMIC / clk and regulator info */ +NULL +}; +static struct acpi_device *acpi_bus_get_parent (acpi_handle handle) {struct acpi_device *device =NULL ;drivers/acpi/scan.c static void acpi_scan_dep_init(struct acpi_device *adev) · line 1768
Quoted 7 lines
drivers/acpi/scan.c +3
-1@@ -1757,8 +1763,12 @@ static void acpi_scan_dep_init(struct acpi_device *adev)struct acpi_dep_data *dep;list_for_each_entry (dep, &acpi_dep_list, node) { -if (dep->consumer == adev->handle) +if (dep->consumer == adev->handle) { +if (dep->honor_dep) + adev->flags.honor_deps =1 ;Any concerns about doing
Quoted 3 lines
adev->flags.honor_deps=dep->honor_dep;here?
The idea is to set
adev->flags.honor_depseven if the device has multiple deps and only one of them has thehonor_depflag set.If we just do:
adev->flags.honor_deps = dep->honor_dep;
Quoted 8 lines
Quoted 2 lines
Then
adev->flags.honor_depsends up having thehonor_depflag of the last dependency checked.OK, but in that case
dep_unmetmay be blocking the enumeration of the device even if the one in the acpi_honor_dep_ids[] list has probed successfully.Isn't that a concern?
For the devices where we set the dep->honor_dep flag this is not a concern (based on the DSDTs which I've seen).
I also don't expect it to be a concern for other cases where we may set that flag in the future either. This is an opt-in thing, so I expect that in cases where we opt in to this, we also ensure that any other _DEPs are also met (by having a Linux driver which calls acpi_dev_clear_dependencies() for them).
And now a days we also have the acpi_ignore_dep_ids[] list so if in the future there are some _DEP-s which never get fulfilled/met on a device where we set the adev->flags.honor_deps flag, then we can always add the ACPI HIDs for those devices to that list.
Quoted 86 lines
Quoted 57 lines
Quoted 40 lines
Quoted 32 lines
drivers/acpi/scan.c +5
-1+ adev->dep_unmet++; + } } }@@ -1962,7 +1972,7 @@ static u32 acpi_scan_check_dep(acpi_handle handle, bool check_dep)for (count =0 , i =0 ; i < dep_devices.count; i++) {struct acpi_device_info *info;struct acpi_dep_data *dep; -bool skip; +bool skip, honor_dep; status =acpi_get_object_info (dep_devices.handles[i], &info);if (ACPI_FAILURE (status)) {@@ -1971,6 +1981,7 @@ static u32 acpi_scan_check_dep(acpi_handle handle, bool check_dep) } skip =acpi_info_matches_ids (info, acpi_ignore_dep_ids); + honor_dep =acpi_info_matches_ids (info, acpi_honor_dep_ids);kfree (info);if (skip)@@ -1984,6 +1995,7 @@ static u32 acpi_scan_check_dep(acpi_handle handle, bool check_dep) dep->supplier = dep_devices.handles[i]; dep->consumer = handle; + dep->honor_dep = honor_dep;mutex_lock (&acpi_dep_list_lock);list_add_tail (&dep->node , &acpi_dep_list);drivers/acpi/scan.c static acpi_status acpi_bus_check_add_2(acpi_handle handle, u32 lvl_not_used, · line 2087
Quoted 5 lines
drivers/acpi/scan.c +2
-0@@ -2071,6 +2083,9 @@ static acpi_status acpi_bus_check_add_2(acpi_handle handle, u32 lvl_not_used,static void acpi_default_enumeration (struct acpi_device *device) { +if (!acpi_dev_ready_for_enumeration (device)) +return ;I'm not sure about this.
Quoted 8 lines
First of all, this adds an
acpi_device_is_present()check here which potentially is a change in behavior and I'm not sure how it is related to the other changes in this patch (it is not mentioned in the changelog AFAICS).I'm saying "potentially", because if we get here at all,
acpi_device_is_present()has been evaluated already byacpi_bus_attach().Right the idea was that for this code-path the extra
acpi_device_is_present()check is a no-op since the only caller ofacpi_default_enumeration()has already done that check before callingacpi_default_enumeration(), where as theis_presentcheck is useful for users outside of the ACPI core code, like e.g. the i2c ACPI enumeration code.Quoted 3 lines
Although I see this is also called from
acpi_generic_device_attachwhich comes into play when there is devicetree info embedded inside the ACPI tables.That too, but generally speaking this change should at least be mentioned in the changelog.
Quoted 7 lines
Quoted 3 lines
Now, IIUC, the new
acpi_dev_ready_for_enumeration()is kind of an extension ofacpi_device_is_present(), so shouldn't it be called byacpi_bus_attach()instead of the latter rather than from here?That is an interesting proposal. I assume you want this to replace the current
acpi_device_is_present()call inacpi_bus_attach()then ?That seems consistent to me.
Quoted 12 lines
For the use-case at hand here that should work fine and it would also make the
honor_depsflag work for devices which bind to the actualacpi_device(because we delay thedevice_attach()) or
use anacpi_scan_handler.This would mean though that we can now have acpi_device-s where
acpi_device_is_present()returns true, but which are not initialized (do not havedevice->flags.initializedset) that would be a newacpi_devicestate which we have not had before. I do not immediately forsee this causing issues, but still...
Quoted 7 lines
Quoted 4 lines
If you want me to replace the current
acpi_device_is_present()call inacpi_bus_attach()with the newacpi_dev_ready_for_enumeration()helper, let me know and I'll prepare a new version with this change (and run some tests with that new version).I would prefer doing that to making
acpi_default_enumeration()special with respect to the handling of dependencies.
Ok I will make this change in the next version (ETA sometime next week).
Regards,
Hans
PATCH v3 2/11 i2c: acpi: Use acpi_dev_ready_for_enumeration() helper
In reply to Hans de GoedeThe clk and regulator frameworks expect clk/regulator consumer-devices to have info about the consumed clks/regulators described in the device's fw_node.
To work around cases where this info is not present in the firmware tables, which is often the case on x86/ACPI devices, both frameworks allow the provider-driver to attach info about consumers to the clks/regulators when registering these.
This causes problems with the probe ordering wrt drivers for consumers of these clks/regulators. Since the lookups are only registered when the provider-driver binds, trying to get these clks/regulators before then results in a -ENOENT error for clks and a dummy regulator for regulators.
To ensure the correct probe-ordering the ACPI core has code to defer the enumeration of consumers affected by this until the providers are ready.
Call the new acpi_dev_ready_for_enumeration() helper to avoid enumerating / instantiating i2c-clients too early.
--- drivers/i2c/i2c-core-acpi.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/i2c/i2c-core-acpi.c +4 -1
@@ -144,9 +144,12 @@ static int i2c_acpi_do_lookup(struct acpi_device *adev,struct list_head resource_list;int ret; -if (acpi_bus_get_status (adev) || !adev->status.present) +if (acpi_bus_get_status (adev))return -EINVAL ; +if (!acpi_dev_ready_for_enumeration (adev)) +return -ENODEV ; +if (acpi_match_device_ids (adev, i2c_acpi_ignored_device_ids) ==0 )return -ENODEV ;
Signature · 1 line
2.31.1
Re: [PATCH v3 02/11] i2c: acpi: Use acpi_dev_ready_for_enumeration() helper
Quoted 14 lines · Hans de Goede
The clk and regulator frameworks expect clk/regulator consumer-devices to have info about the consumed clks/regulators described in the device's
fw_node.To work around cases where this info is not present in the firmware tables, which is often the case on x86/ACPI devices, both frameworks allow the provider-driver to attach info about consumers to the clks/regulators when registering these.
This causes problems with the probe ordering wrt drivers for consumers of these clks/regulators. Since the lookups are only registered when the provider-driver binds, trying to get these clks/regulators before then results in a
-ENOENTerror for clks and a dummy regulator for regulators.
Quoted 7 lines
To ensure the correct probe-ordering the ACPI core has code to defer the enumeration of consumers affected by this until the providers are ready.
Call the new
acpi_dev_ready_for_enumeration()helper to avoid enumerating / instantiating i2c-clients too early.Signed-off-by Hans de Goede <[email protected]>
If the ACPI and I2C-ACPI maintainers are happy, I am fine with this, too:
Rafael J. Wysocki
maintainerRe: [PATCH v3 02/11] i2c: acpi: Use acpi_dev_ready_for_enumeration() helper
In reply to Hans de GoedeQuoted 33 lines · Hans de Goede
The clk and regulator frameworks expect clk/regulator consumer-devices to have info about the consumed clks/regulators described in the device's
fw_node.To work around cases where this info is not present in the firmware tables, which is often the case on x86/ACPI devices, both frameworks allow the provider-driver to attach info about consumers to the clks/regulators when registering these.
This causes problems with the probe ordering wrt drivers for consumers of these clks/regulators. Since the lookups are only registered when the provider-driver binds, trying to get these clks/regulators before then results in a
-ENOENTerror for clks and a dummy regulator for regulators.To ensure the correct probe-ordering the ACPI core has code to defer the enumeration of consumers affected by this until the providers are ready.
Call the new
acpi_dev_ready_for_enumeration()helper to avoid enumerating / instantiating i2c-clients too early.Signed-off-by Hans de Goede <[email protected]>--- drivers/i2c/i2c-core-acpi.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/i2c/i2c-core-acpi.c +0
-0@@ -144,9 +144,12 @@ static int i2c_acpi_do_lookup(struct acpi_device *adev,struct list_head resource_list;int ret;
drivers/i2c/i2c-core-acpi.c static int i2c_acpi_do_lookup(struct acpi_device *adev, · line 154
Quoted 10 lines
drivers/i2c/i2c-core-acpi.c +4
-1-if (acpi_bus_get_status (adev) || !adev->status.present) +if (acpi_bus_get_status (adev))return -EINVAL ; +if (!acpi_dev_ready_for_enumeration (adev)) +return -ENODEV ; +if (acpi_match_device_ids (adev, i2c_acpi_ignored_device_ids) ==0 )return -ENODEV ;
I kind of prefer combining checks that cause the same error code to be returned, but this is fine with me too.
PATCH v3 3/11 platform_data: Add linux/platform_data/tps68470.h file
In reply to Hans de GoedeThe clk and regulator frameworks expect clk/regulator consumer-devices to have info about the consumed clks/regulators described in the device's fw_node.
To work around cases where this info is not present in the firmware tables, which is often the case on x86/ACPI devices, both frameworks allow the provider-driver to attach info about consumers to the provider-device during probe/registration of the provider device.
The TI TPS68470 PMIC is used x86/ACPI devices with the consumer-info missing from the ACPI tables. Thus the tps68470-clk and tps68470-regulator drivers must provide the consumer-info at probe time.
Define tps68470_clk_platform_data and tps68470_regulator_platform_data structs to allow the x86 platform code to pass the necessary consumer info to these drivers.
--- include/linux/platform_data/tps68470.h | 35 ++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 include/linux/platform_data/tps68470.h
include/linux/platform_data/tps68470.h new file +35 -0
@@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* TI TPS68470 PMIC platform data definition. +* +* Copyright (c) 2021 Red Hat Inc. +* +* Red Hat authors: +* Hans de Goede <[email protected]> +*/ +#ifndef __PDATA_TPS68470_H +#define __PDATA_TPS68470_H + +enum tps68470_regulators { +TPS68470_CORE , +TPS68470_ANA , +TPS68470_VCM , +TPS68470_VIO , +TPS68470_VSIO , +TPS68470_AUX1 , +TPS68470_AUX2 , +TPS68470_NUM_REGULATORS +}; + +struct regulator_init_data ; + +struct tps68470_regulator_platform_data { +const struct regulator_init_data *reg_init_data[TPS68470_NUM_REGULATORS ]; +}; + +struct tps68470_clk_platform_data { +const char *consumer_dev_name; +const char *consumer_con_id; +}; + +#endif
Signature · 1 line
2.31.1
PATCH v3 4/11 regulator: Introduce tps68470-regulator driver
In reply to Hans de GoedeThe TPS68470 PMIC provides Clocks, GPIOs and Regulators. At present in the kernel the Regulators and Clocks are controlled by an OpRegion driver designed to work with power control methods defined in ACPI, but some platforms lack those methods, meaning drivers need to be able to consume the resources of these chips through the usual frameworks.
This commit adds a driver for the regulators provided by the tps68470, and is designed to bind to the platform_device registered by the intel_skl_int3472 module.
This is based on this out of tree driver written by Intel:
https://github.com/intel/linux-intel-lts/blob/4.14/base/drivers/regulator/tps68470-regulator.c
with various cleanups added.
---
Changes in v2:
- Update the comment on why a subsys_initcall is used to register the drv
- Make struct regulator_ops const
--- drivers/regulator/Kconfig | 9 ++ drivers/regulator/Makefile | 1 + drivers/regulator/tps68470-regulator.c | 193 +++++++++++++++++++++++++ 3 files changed, 203 insertions(+) create mode 100644 drivers/regulator/tps68470-regulator.c
drivers/regulator/Kconfig +9 -0
@@ -1339,6 +1339,15 @@ config REGULATOR_TPS65912 help This driver supports TPS65912 voltage regulator chip. +config REGULATOR_TPS68470 + tristate "TI TPS68370 PMIC Regulators Driver" + depends on INTEL_SKL_INT3472 + help + This driver adds support for the TPS68470 PMIC to register + regulators against the usual framework. + + The module will be called "tps68470-regulator" + config REGULATOR_TPS80031 tristate "TI TPS80031/TPS80032 power regulator driver" depends on MFD_TPS80031
drivers/regulator/Makefile +1 -0
@@ -158,6 +158,7 @@ obj-$(CONFIG_REGULATOR_TPS6524X) += tps6524x-regulator.o obj-$(CONFIG_REGULATOR_TPS6586X) += tps6586x-regulator.o obj-$(CONFIG_REGULATOR_TPS65910) += tps65910-regulator.o obj-$(CONFIG_REGULATOR_TPS65912) += tps65912-regulator.o +obj-$(CONFIG_REGULATOR_TPS68470) += tps68470-regulator.o obj-$(CONFIG_REGULATOR_TPS80031) += tps80031-regulator.o obj-$(CONFIG_REGULATOR_TPS65132) += tps65132-regulator.o obj-$(CONFIG_REGULATOR_TWL4030) += twl-regulator.o twl6030-regulator.o
drivers/regulator/tps68470-regulator.c new file +193 -0
193 lines not on this page · raw message
Signature · 1 line
2.31.1
Re: [PATCH v3 04/11] regulator: Introduce tps68470-regulator driver
Quoted 32 lines · Hans de Goede
The TPS68470 PMIC provides Clocks, GPIOs and Regulators. At present in the kernel the Regulators and Clocks are controlled by an OpRegion driver designed to work with power control methods defined in ACPI, but some platforms lack those methods, meaning drivers need to be able to consume the resources of these chips through the usual frameworks.
This commit adds a driver for the regulators provided by the tps68470, and is designed to bind to the
platform_deviceregistered by theintel_skl_int3472module.This is based on this out of tree driver written by Intel:
https://github.com/intel/linux-intel-lts/blob/4.14/base/drivers/regulator/tps68470-regulator.c
with various cleanups added.Signed-off-by Hans de Goede <[email protected]>---
Changes in v2:
- Update the comment on why asubsys_initcallis used to register the drv
- Make structregulator_opsconst--- drivers/regulator/Kconfig | 9 ++ drivers/regulator/Makefile | 1 + drivers/regulator/tps68470-regulator.c | 193 +++++++++++++++++++++++++ 3 files changed, 203 insertions(+)create mode 100644
drivers/regulator/tps68470-regulator.cdrivers/regulator/Kconfig +0
-0@@ -1339,6 +1339,15 @@ config REGULATOR_TPS65912 help
drivers/regulator/Kconfig config REGULATOR_TPS65912 · line 1349
Quoted 10 lines
drivers/regulator/Kconfig +8
-0This driver supports TPS65912 voltage regulator chip. +config REGULATOR_TPS68470 + tristate "TI TPS68370 PMIC Regulators Driver" + depends on INTEL_SKL_INT3472 + help + This driver adds support for the TPS68470 PMIC to register + regulators against the usual framework. + + The module will be called "tps68470-regulator"
End the final sentence with a period (a.k.a. full stop).
Signature · 1 line
~Randy
PATCH v3 5/11 clk: Introduce clk-tps68470 driver
In reply to Hans de GoedeThe TPS68470 PMIC provides Clocks, GPIOs and Regulators. At present in the kernel the Regulators and Clocks are controlled by an OpRegion driver designed to work with power control methods defined in ACPI, but some platforms lack those methods, meaning drivers need to be able to consume the resources of these chips through the usual frameworks.
This commit adds a driver for the clocks provided by the tps68470, and is designed to bind to the platform_device registered by the intel_skl_int3472 module.
This is based on this out of tree driver written by Intel:
https://github.com/intel/linux-intel-lts/blob/4.14/base/drivers/clk/clk-tps68470.c
with various cleanups added.
---
Changes in v2:
- Update the comment on why a subsys_initcall is used to register the drv
- Fix trailing whitespice on line 100
--- drivers/clk/Kconfig | 6 + drivers/clk/Makefile | 1 + drivers/clk/clk-tps68470.c | 256 +++++++++++++++++++++++++++++++++++ include/linux/mfd/tps68470.h | 11 ++ 4 files changed, 274 insertions(+) create mode 100644 drivers/clk/clk-tps68470.c
drivers/clk/Kconfig +6 -0
@@ -169,6 +169,12 @@ config COMMON_CLK_CDCE706 help This driver supports TI CDCE706 programmable 3-PLL clock synthesizer. +config COMMON_CLK_TPS68470 + tristate "Clock Driver for TI TPS68470 PMIC" + depends on I2C && REGMAP_I2C && INTEL_SKL_INT3472 + help + This driver supports the clocks provided by TPS68470 + config COMMON_CLK_CDCE925 tristate "Clock driver for TI CDCE913/925/937/949 devices" depends on I2C
drivers/clk/Makefile +1 -0
@@ -63,6 +63,7 @@ obj-$(CONFIG_COMMON_CLK_SI570) += clk-si570.o obj-$(CONFIG_COMMON_CLK_STM32F) += clk-stm32f4.o obj-$(CONFIG_COMMON_CLK_STM32H7) += clk-stm32h7.o obj-$(CONFIG_COMMON_CLK_STM32MP157) += clk-stm32mp1.o +obj-$(CONFIG_COMMON_CLK_TPS68470) += clk-tps68470.o obj-$(CONFIG_CLK_TWL6040) += clk-twl6040.o obj-$(CONFIG_ARCH_VT8500) += clk-vt8500.o obj-$(CONFIG_COMMON_CLK_VC5) += clk-versaclock5.o
drivers/clk/clk-tps68470.c new file +256 -0
256 lines not on this page · raw message
include/linux/mfd/tps68470.h +11 -0
@@ -75,6 +75,17 @@#define TPS68470_CLKCFG1_MODE_A_MASK GENMASK(1, 0)#define TPS68470_CLKCFG1_MODE_B_MASK GENMASK(3, 2) +#define TPS68470_CLKCFG2_DRV_STR_2MA 0x05 +#define TPS68470_PLL_OUTPUT_ENABLE 0x02 +#define TPS68470_CLK_SRC_XTAL BIT(0) +#define TPS68470_PLLSWR_DEFAULT GENMASK(1, 0) +#define TPS68470_OSC_EXT_CAP_DEFAULT 0x05 + +#define TPS68470_OUTPUT_A_SHIFT 0x00 +#define TPS68470_OUTPUT_B_SHIFT 0x02 +#define TPS68470_CLK_SRC_SHIFT GENMASK(2, 0) +#define TPS68470_OSC_EXT_CAP_SHIFT BIT(2) +#define TPS68470_GPIO_CTL_REG_A (x) (TPS68470_REG_GPCTL0A + (x) * 2)#define TPS68470_GPIO_CTL_REG_B (x) (TPS68470_REG_GPCTL0B + (x) * 2)#define TPS68470_GPIO_MODE_MASK GENMASK(1, 0)
Signature · 1 line
2.31.1
Re: [PATCH v3 05/11] clk: Introduce clk-tps68470 driver
Quoted 32 lines · Hans de Goede
The TPS68470 PMIC provides Clocks, GPIOs and Regulators. At present in the kernel the Regulators and Clocks are controlled by an OpRegion driver designed to work with power control methods defined in ACPI, but some platforms lack those methods, meaning drivers need to be able to consume the resources of these chips through the usual frameworks.
This commit adds a driver for the clocks provided by the tps68470, and is designed to bind to the
platform_deviceregistered by theintel_skl_int3472module.This is based on this out of tree driver written by Intel:
https://github.com/intel/linux-intel-lts/blob/4.14/base/drivers/clk/clk-tps68470.c
with various cleanups added.Signed-off-by Hans de Goede <[email protected]>---
Changes in v2:
- Update the comment on why asubsys_initcallis used to register the drv
- Fix trailing whitespice on line 100--- drivers/clk/Kconfig | 6 + drivers/clk/Makefile | 1 + drivers/clk/clk-tps68470.c | 256 +++++++++++++++++++++++++++++++++++ include/linux/mfd/tps68470.h | 11 ++ 4 files changed, 274 insertions(+)create mode 100644
drivers/clk/clk-tps68470.cdrivers/clk/Kconfig +0
-0
drivers/clk/Kconfig config COMMON_CLK_CDCE706 · line 176
Quoted 8 lines
drivers/clk/Kconfig +5
-0@@ -169,6 +169,12 @@ config COMMON_CLK_CDCE706 help This driver supports TI CDCE706 programmable 3-PLL clock synthesizer. +config COMMON_CLK_TPS68470 + tristate "Clock Driver for TI TPS68470 PMIC" + depends on I2C && REGMAP_I2C && INTEL_SKL_INT3472 + help + This driver supports the clocks provided by TPS68470
End that sentence with a period (full stop): '.'.
Also it should be indented with one tab + 2 spaces.
Signature · 1 line
~Randy
A message that is not in the archive (sent off-list or not yet received): 163415237957.936110.1269283416777498553@swboyd.mtv.corp.google.com
Re: [PATCH v3 05/11] clk: Introduce clk-tps68470 driver
Hi Stephen,
Thank you for the review.
Quoted 15 lines · Stephen Boyd
Quoting Hans de Goede (2021-10-10 11:57:01)
drivers/clk/Kconfig config COMMON_CLK_CDCE706 · line 174
Quoted 11 lines
drivers/clk/Kconfig +3
-0@@ -169,6 +169,12 @@ config COMMON_CLK_CDCE706 help This driver supports TI CDCE706 programmable 3-PLL clock synthesizer. +config COMMON_CLK_TPS68470 + tristate "Clock Driver for TI TPS68470 PMIC" + depends on I2C && REGMAP_I2C && INTEL_SKL_INT3472Pretty sure
REGMAP_I2Cshould be selected, not depended on.
Quoted 6 lines
Can it
depends on INTEL_SKL_INT3472 || COMPILE_TESTso that we don't have to enable the intel specific config to compile test this driver?
Ack, all fixed for v4.
Quoted 142 lines
Quoted 142 lines
drivers/clk/Kconfig +3
-0+ help + This driver supports the clocks provided by TPS68470 + config COMMON_CLK_CDCE925 tristate "Clock driver for TI CDCE913/925/937/949 devices" depends on I2Cdrivers/clk/Makefile +1
-0@@ -63,6 +63,7 @@ obj-$(CONFIG_COMMON_CLK_SI570) += clk-si570.o obj-$(CONFIG_COMMON_CLK_STM32F) += clk-stm32f4.o obj-$(CONFIG_COMMON_CLK_STM32H7) += clk-stm32h7.o obj-$(CONFIG_COMMON_CLK_STM32MP157) += clk-stm32mp1.o +obj-$(CONFIG_COMMON_CLK_TPS68470) += clk-tps68470.o obj-$(CONFIG_CLK_TWL6040) += clk-twl6040.o obj-$(CONFIG_ARCH_VT8500) += clk-vt8500.o obj-$(CONFIG_COMMON_CLK_VC5) += clk-versaclock5.odrivers/clk/clk-tps68470.c new file +118
-0@@ -0,0 +1,256 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Clock driver for TPS68470 PMIC +* +* Copyright (C) 2018 Intel Corporation +* +* Authors: +* Zaikuo Wang <[email protected]> +* Tianshu Qiu <[email protected]> +* Jian Xu Zheng <[email protected]> +* Yuning Pu <[email protected]> +* Antti Laakso <[email protected]> +*/ + +#include <linux/clk-provider.h> +#include <linux/clkdev.h> +#include <linux/kernel.h> +#include <linux/mfd/tps68470.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/platform_data/tps68470.h> +#include <linux/regmap.h> + +#define TPS68470_CLK_NAME "tps68470-clk" + +#define to_tps68470_clkdata (clkd) \ + container_of(clkd, struct tps68470_clkdata, clkout_hw) + +struct tps68470_clkout_freqs { +unsigned long freq; +unsigned int xtaldiv; +unsigned int plldiv; +unsigned int postdiv; +unsigned int buckdiv; +unsigned int boostdiv; +} clk_freqs[] = { +/* +* The PLL is used to multiply the crystal oscillator +* frequency range of 3 MHz to 27 MHz by a programmable +* factor of F = (M/N)*(1/P) such that the output +* available at the HCLK_A or HCLK_B pins are in the range +* of 4 MHz to 64 MHz in increments of 0.1 MHz +* +* hclk_# = osc_in * (((plldiv*2)+320) / (xtaldiv+30)) * (1 / 2^postdiv) +* +* PLL_REF_CLK should be as close as possible to 100kHz +* PLL_REF_CLK = input clk / XTALDIV[7:0] + 30) +* +* PLL_VCO_CLK = (PLL_REF_CLK * (plldiv*2 + 320)) +* +* BOOST should be as close as possible to 2Mhz +* BOOST = PLL_VCO_CLK / (BOOSTDIV[4:0] + 16) * +* +* BUCK should be as close as possible to 5.2Mhz +* BUCK = PLL_VCO_CLK / (BUCKDIV[3:0] + 5) +* +* osc_in xtaldiv plldiv postdiv hclk_# +* 20Mhz 170 32 1 19.2Mhz +* 20Mhz 170 40 1 20Mhz +* 20Mhz 170 80 1 24Mhz +* +*/ + {19200000 ,170 ,32 ,1 ,2 ,3 }, + {20000000 ,170 ,40 ,1 ,3 ,4 }, + {24000000 ,170 ,80 ,1 ,4 ,8 }, +}; + +struct tps68470_clkdata { +struct clk_hw clkout_hw; +struct regmap *regmap; +struct clk *clk; +int clk_cfg_idx; +}; + +static int tps68470_clk_is_prepared (struct clk_hw *hw) +{ +struct tps68470_clkdata *clkdata =to_tps68470_clkdata (hw); +int val; + +if (regmap_read (clkdata->regmap,TPS68470_REG_PLLCTL , &val)) +return 0 ; + +return val &TPS68470_PLL_EN_MASK ; +} + +static int tps68470_clk_prepare (struct clk_hw *hw) +{ +struct tps68470_clkdata *clkdata =to_tps68470_clkdata (hw); +int idx = clkdata->clk_cfg_idx; + +regmap_write (clkdata->regmap,TPS68470_REG_BOOSTDIV , clk_freqs[idx].boostdiv); +regmap_write (clkdata->regmap,TPS68470_REG_BUCKDIV , clk_freqs[idx].buckdiv); +regmap_write (clkdata->regmap,TPS68470_REG_PLLSWR ,TPS68470_PLLSWR_DEFAULT ); +regmap_write (clkdata->regmap,TPS68470_REG_XTALDIV , clk_freqs[idx].xtaldiv); +regmap_write (clkdata->regmap,TPS68470_REG_PLLDIV , clk_freqs[idx].plldiv); +regmap_write (clkdata->regmap,TPS68470_REG_POSTDIV , clk_freqs[idx].postdiv); +regmap_write (clkdata->regmap,TPS68470_REG_POSTDIV2 , clk_freqs[idx].postdiv); +regmap_write (clkdata->regmap,TPS68470_REG_CLKCFG2 ,TPS68470_CLKCFG2_DRV_STR_2MA ); + +regmap_write (clkdata->regmap,TPS68470_REG_PLLCTL , +TPS68470_OSC_EXT_CAP_DEFAULT <<TPS68470_OSC_EXT_CAP_SHIFT | +TPS68470_CLK_SRC_XTAL <<TPS68470_CLK_SRC_SHIFT ); + +regmap_write (clkdata->regmap,TPS68470_REG_CLKCFG1 , + (TPS68470_PLL_OUTPUT_ENABLE << +TPS68470_OUTPUT_A_SHIFT ) | + (TPS68470_PLL_OUTPUT_ENABLE << +TPS68470_OUTPUT_B_SHIFT )); + +regmap_update_bits (clkdata->regmap,TPS68470_REG_PLLCTL , +TPS68470_PLL_EN_MASK ,TPS68470_PLL_EN_MASK ); + +return 0 ; +} + +static void tps68470_clk_unprepare (struct clk_hw *hw) +{ +struct tps68470_clkdata *clkdata =to_tps68470_clkdata (hw);
Quoted 8 lines
drivers/clk/clk-tps68470.c line 123
Quoted 5 lines
drivers/clk/clk-tps68470.c new file +5
-0+ +/* disable clock first*/ +regmap_update_bits (clkdata->regmap,TPS68470_REG_PLLCTL ,TPS68470_PLL_EN_MASK ,0 ); + +/* write hw defaults */ Is it necessary to reset the registers to 0? Can the comment indicate why it is necessary instead of stating what the code is doing?
As mentioned in the commit msg this driver started out of tree, this part comes unmodified from the out of tree driver.
After inspecting the datasheet you are right and most of these register clears are not necessary to disable the clock.
Only the clearing of TPS68470_REG_CLKCFG1 is necesary to tristate the clk output pin. I will remove the rest and add a comment about the clearing of TPS68470_REG_CLKCFG1.
Quoted 13 lines
Quoted 13 lines
drivers/clk/clk-tps68470.c new file +12
-0+regmap_write (clkdata->regmap,TPS68470_REG_BOOSTDIV ,0 ); +regmap_write (clkdata->regmap,TPS68470_REG_BUCKDIV ,0 ); +regmap_write (clkdata->regmap,TPS68470_REG_PLLSWR ,0 ); +regmap_write (clkdata->regmap,TPS68470_REG_XTALDIV ,0 ); +regmap_write (clkdata->regmap,TPS68470_REG_PLLDIV ,0 ); +regmap_write (clkdata->regmap,TPS68470_REG_POSTDIV ,0 ); +regmap_write (clkdata->regmap,TPS68470_REG_CLKCFG2 ,0 ); +regmap_write (clkdata->regmap,TPS68470_REG_CLKCFG1 ,0 ); +} + +static unsigned long tps68470_clk_recalc_rate (struct clk_hw *hw,unsigned long parent_rate) +{
Quoted 8 lines
drivers/clk/clk-tps68470.c line 141
Quoted 6 lines
drivers/clk/clk-tps68470.c new file +6
-0+struct tps68470_clkdata *clkdata =to_tps68470_clkdata (hw); + +return clk_freqs[clkdata->clk_cfg_idx].freq; +} + +static int tps68470_clk_cfg_lookup (unsigned long rate)unsigned? Doesn't seem to return negative numbers.
Will fix for v4.
Quoted 18 lines
Quoted 18 lines
drivers/clk/clk-tps68470.c new file +17
-0+{ +long diff, best_diff =LONG_MAX ; +int i, best_idx =0 ; + +for (i =0 ; i <ARRAY_SIZE (clk_freqs); i++) { + diff = clk_freqs[i].freq - rate; +if (diff ==0 ) +return i; + + diff =abs (diff); +if (diff < best_diff) { + best_diff = diff; + best_idx = i; + } + } + +return best_idx;
Quoted 8 lines
drivers/clk/clk-tps68470.c line 164
Quoted 6 lines
drivers/clk/clk-tps68470.c new file +6
-0+} + +static long tps68470_clk_round_rate (struct clk_hw *hw,unsigned long rate, +unsigned long *parent_rate) +{ +int idx =tps68470_clk_cfg_lookup (rate);unsigned?
Will fix for v4.
Quoted 17 lines
Quoted 5 lines
drivers/clk/clk-tps68470.c new file +4
-0+ +return clk_freqs[idx].freq; +} +drivers/clk/clk-tps68470.c line 178
Quoted 10 lines
drivers/clk/clk-tps68470.c new file +10
-0+static int tps68470_clk_set_rate (struct clk_hw *hw,unsigned long rate, +unsigned long parent_rate) +{ +struct tps68470_clkdata *clkdata =to_tps68470_clkdata (hw); +int idx =tps68470_clk_cfg_lookup (rate); + +if (rate != clk_freqs[idx].freq) +return -EINVAL ; + + clkdata->clk_cfg_idx = idx;Newline here please.
Done.
Quoted 2 lines
Also, why isn't this function actually writing
hardware?
set_rate can only be called when the clock is disabled, all the necessary values are programmed based on the clk_cfg_idx in tps68470_clk_prepare().
Note there is no enable() since enable() may not sleep and this device is interfaced over I2C, so the clock is already enabled from the prepare() op.
Quoted 16 lines
Quoted 4 lines
drivers/clk/clk-tps68470.c new file +3
-0+return 0 ; +} +drivers/clk/clk-tps68470.c line 191
Quoted 10 lines
drivers/clk/clk-tps68470.c new file +10
-0+static const struct clk_ops tps68470_clk_ops = { + .is_prepared = tps68470_clk_is_prepared, + .prepare = tps68470_clk_prepare, + .unprepare = tps68470_clk_unprepare, + .recalc_rate = tps68470_clk_recalc_rate, + .round_rate = tps68470_clk_round_rate, + .set_rate = tps68470_clk_set_rate, +}; + +static struct clk_init_data tps68470_clk_initdata = {const?
Ack.
Quoted 13 lines
Quoted 13 lines
drivers/clk/clk-tps68470.c new file +12
-0+ .name = TPS68470_CLK_NAME, + .ops = &tps68470_clk_ops, +}; + +static int tps68470_clk_probe (struct platform_device *pdev) +{ +struct tps68470_clk_platform_data *pdata = pdev->dev.platform_data; +struct tps68470_clkdata *tps68470_clkdata; +int ret; + + tps68470_clkdata =devm_kzalloc (&pdev->dev,sizeof (*tps68470_clkdata), +GFP_KERNEL );
Quoted 8 lines
drivers/clk/clk-tps68470.c line 209
Quoted 6 lines
drivers/clk/clk-tps68470.c new file +6
-0+if (!tps68470_clkdata) +return -ENOMEM ; + + tps68470_clkdata->regmap =dev_get_drvdata (pdev->dev.parent); + tps68470_clkdata->clkout_hw.init = &tps68470_clk_initdata; + tps68470_clkdata->clk =devm_clk_register (&pdev->dev, &tps68470_clkdata->clkout_hw);Please use
devm_clk_hw_register()
Good idea, done for v4.
Quoted 19 lines
Quoted 6 lines
drivers/clk/clk-tps68470.c new file +5
-0+if (IS_ERR (tps68470_clkdata->clk)) +return PTR_ERR (tps68470_clkdata->clk); + + ret =devm_clk_hw_register_clkdev (&pdev->dev, &tps68470_clkdata->clkout_hw, +TPS68470_CLK_NAME ,NULL );drivers/clk/clk-tps68470.c line 224
Quoted 10 lines
drivers/clk/clk-tps68470.c new file +10
-0+if (ret) +return ret; + +if (pdata) { + ret =devm_clk_hw_register_clkdev (&pdev->dev, + &tps68470_clkdata->clkout_hw, + pdata->consumer_con_id, + pdata->consumer_dev_name); +if (ret) +return ret;Drop these two lines?
Quoted 7 lines
drivers/clk/clk-tps68470.c line 113
Quoted 3 lines
drivers/clk/clk-tps68470.c new file +3
-0+ } + +return 0 ;And then
return ret;
Done for v4.
Regards,
Hans
Re: [PATCH v3 05/11] clk: Introduce clk-tps68470 driver
Quoted 1 line · Hans de Goede
On 10/13/21 21:12, Stephen Boyd wrote:
...
Quoted 4 lines
Quoted 4 lines
drivers/clk/clk-tps68470.c line 106
Quoted 4 lines
drivers/clk/clk-tps68470.c new file +3
-0+ regmap_write(clkdata->regmap, TPS68470_REG_CLKCFG1, + (TPS68470_PLL_OUTPUT_ENABLE << + TPS68470_OUTPUT_A_SHIFT) |
One line, please?
Quoted 2 lines
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ (TPS68470_PLL_OUTPUT_ENABLE << + TPS68470_OUTPUT_B_SHIFT));
Ditto.
...
Quoted 10 lines
Quoted 2 lines
Also, why isn't this function actually writing
hardware?
set_ratecan only be called when the clock is disabled, all the necessary values are programmed based on theclk_cfg_idxintps68470_clk_prepare().Note there is no
enable()sinceenable()may not sleep and this device is interfaced over I2C, so the clock is already enabled from theprepare()op.
This reminds me other drivers that do commit the changes to the hardware on bus lock, but I'm not sure if anything like that is applicable here.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v3 05/11] clk: Introduce clk-tps68470 driver
Hi,
Quoted 10 lines · Andy Shevchenko
Quoted 1 line · Hans de Goede
On 10/13/21 21:12, Stephen Boyd wrote:
...
Quoted 4 lines
Quoted 4 lines
drivers/clk/clk-tps68470.c line 106
Quoted 4 lines
drivers/clk/clk-tps68470.c new file +3
-0+ regmap_write(clkdata->regmap, TPS68470_REG_CLKCFG1, + (TPS68470_PLL_OUTPUT_ENABLE << + TPS68470_OUTPUT_A_SHIFT) |
Quoted 6 lines
One line, please?
Quoted 2 lines
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ (TPS68470_PLL_OUTPUT_ENABLE << + TPS68470_OUTPUT_B_SHIFT));Ditto.
Ack, both fixed for v4.
Regards,
Hans
PATCH v3 6/11 platform/x86: int3472: Enable I2c daisy chain
In reply to Hans de GoedeFrom: Daniel Scally <[email protected]>
The TPS68470 PMIC has an I2C passthrough mode through which I2C traffic can be forwarded to a device connected to the PMIC as though it were connected directly to the system bus. Enable this mode when the chip is initialised.
--- .../x86/intel/int3472/intel_skl_int3472_tps68470.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/platform/x86/intel/int3472/intel_skl_int3472_tps68470.c +7 -0
@@ -45,6 +45,13 @@ static int tps68470_chip_init(struct device *dev, struct regmap *regmap)return ret; } +/* Enable I2C daisy chain */ + ret =regmap_write (regmap,TPS68470_REG_S_I2C_CTL ,0x03 ); +if (ret) { +dev_err (dev,"Failed to enable i2c daisy chain\n" ); +return ret; + } +dev_info (dev,"TPS68470 REVID: 0x%02x\n" , version);return 0 ;
Signature · 1 line
2.31.1
PATCH v3 7/11 platform/x86: int3472: Split into 2 drivers
In reply to Hans de GoedeThe intel_skl_int3472.ko module contains 2 separate drivers, the int3472_discrete platform driver and the int3472_tps68470 I2C-driver.
These 2 drivers contain very little shared code, only skl_int3472_get_acpi_buffer() and skl_int3472_fill_cldb() are shared.
Split the module into 2 drivers, linking the little shared code directly into both.
This will allow us to add soft-module dependencies for the tps68470 clk, gpio and regulator drivers to the new intel_skl_int3472_tps68470.ko to help with probe ordering issues without causing these modules to get loaded on boards which only use the int3472_discrete platform driver.
While at it also rename the .c and .h files to remove the cumbersome intel_skl_int3472_ prefix.
---
Note git rename detection is failing for the new common.c but this is just the old intel_skl_int3472_common.c with the driver registering bits removed.
---
drivers/platform/x86/intel/int3472/Makefile | 9 +-
...lk_and_regulator.c => clk_and_regulator.c} | 2 +-
drivers/platform/x86/intel/int3472/common.c | 54 +++++++++
.../{intel_skl_int3472_common.h => common.h} | 3 -
...ntel_skl_int3472_discrete.c => discrete.c} | 28 ++++-
.../intel/int3472/intel_skl_int3472_common.c | 106 ------------------
...ntel_skl_int3472_tps68470.c => tps68470.c} | 23 +++-
7 files changed, 105 insertions(+), 120 deletions(-)
rename drivers/platform/x86/intel/int3472/{intel_skl_int3472_clk_and_regulator.c => clk_and_regulator.c} (99%)
create mode 100644 drivers/platform/x86/intel/int3472/common.c
rename drivers/platform/x86/intel/int3472/{intel_skl_int3472_common.h => common.h} (94%)
rename drivers/platform/x86/intel/int3472/{intel_skl_int3472_discrete.c => discrete.c} (93%)
delete mode 100644 drivers/platform/x86/intel/int3472/intel_skl_int3472_common.c
rename drivers/platform/x86/intel/int3472/{intel_skl_int3472_tps68470.c => tps68470.c} (86%)drivers/platform/x86/intel/int3472/Makefile +4 -5
@@ -1,5 +1,4 @@ -obj-$(CONFIG_INTEL_SKL_INT3472) += intel_skl_int3472.o -intel_skl_int3472-y := intel_skl_int3472_common.o \ - intel_skl_int3472_discrete.o \ - intel_skl_int3472_tps68470.o \ - intel_skl_int3472_clk_and_regulator.o +obj-$(CONFIG_INTEL_SKL_INT3472) += intel_skl_int3472_discrete.o \ + intel_skl_int3472_tps68470.o +intel_skl_int3472_discrete-y := discrete.o clk_and_regulator.o common.o +intel_skl_int3472_tps68470-y := tps68470.o common.o
drivers/platform/x86/intel/int3472/clk_and_regulator.c renamed from drivers/platform/x86/intel/int3472/intel_skl_int3472_clk_and_regulator.c +1 -1
@@ -9,7 +9,7 @@#include <linux/regulator/driver.h> #include <linux/slab.h> -#include "intel_skl_int3472_common.h" +#include "common.h" /* * The regulators have to have .ops to be valid, but the only ops we actually
drivers/platform/x86/intel/int3472/common.c new file +54 -0
54 lines not on this page · raw message
drivers/platform/x86/intel/int3472/common.h renamed from drivers/platform/x86/intel/int3472/intel_skl_int3472_common.h +0 -3
@@ -105,9 +105,6 @@ struct int3472_discrete_device {struct gpiod_lookup_table gpios; }; -int skl_int3472_discrete_probe (struct platform_device *pdev); -int skl_int3472_discrete_remove (struct platform_device *pdev); -int skl_int3472_tps68470_probe (struct i2c_client *client);union acpi_object *skl_int3472_get_acpi_buffer (struct acpi_device *adev,char *id);int skl_int3472_fill_cldb (struct acpi_device *adev,struct int3472_cldb *cldb);
drivers/platform/x86/intel/int3472/discrete.c renamed from drivers/platform/x86/intel/int3472/intel_skl_int3472_discrete.c +25 -3
@@ -14,7 +14,7 @@#include <linux/platform_device.h> #include <linux/uuid.h> -#include "intel_skl_int3472_common.h" +#include "common.h" /* * 79234640-9e10-4fea-a5c1-b5aa8b19756f
@@ -332,7 +332,9 @@ static int skl_int3472_parse_crs(struct int3472_discrete_device *int3472)return 0 ; } -int skl_int3472_discrete_probe (struct platform_device *pdev) +static int skl_int3472_discrete_remove (struct platform_device *pdev); + +static int skl_int3472_discrete_probe (struct platform_device *pdev) {struct acpi_device *adev =ACPI_COMPANION (&pdev->dev);struct int3472_discrete_device *int3472;
@@ -395,7 +397,7 @@ int skl_int3472_discrete_probe(struct platform_device *pdev)return ret; } -int skl_int3472_discrete_remove (struct platform_device *pdev) +static int skl_int3472_discrete_remove (struct platform_device *pdev) {struct int3472_discrete_device *int3472 =platform_get_drvdata (pdev);
@@ -411,3 +413,23 @@ int skl_int3472_discrete_remove(struct platform_device *pdev)return 0 ; } + +static const struct acpi_device_id int3472_device_id[] = { + {"INT3472" ,0 }, + { } +}; +MODULE_DEVICE_TABLE (acpi, int3472_device_id); + +static struct platform_driver int3472_discrete = { + .driver = { + .name ="int3472-discrete" , + .acpi_match_table = int3472_device_id, + }, + .probe = skl_int3472_discrete_probe, + .remove = skl_int3472_discrete_remove, +}; +module_platform_driver (int3472_discrete); + +MODULE_DESCRIPTION ("Intel SkyLake INT3472 ACPI Discrete Device Driver" ); +MODULE_AUTHOR ("Daniel Scally <[email protected]>" ); +MODULE_LICENSE ("GPL v2" );
drivers/platform/x86/intel/int3472/intel_skl_int3472_common.c deleted +0 -106
106 lines not on this page · raw message
drivers/platform/x86/intel/int3472/tps68470.c renamed from drivers/platform/x86/intel/int3472/intel_skl_int3472_tps68470.c +21 -2
@@ -7,7 +7,7 @@#include <linux/platform_device.h> #include <linux/regmap.h> -#include "intel_skl_int3472_common.h" +#include "common.h" #define DESIGNED_FOR_CHROMEOS 1#define DESIGNED_FOR_WINDOWS 2
@@ -102,7 +102,7 @@ static int skl_int3472_tps68470_calc_type(struct acpi_device *adev)return DESIGNED_FOR_WINDOWS ; } -int skl_int3472_tps68470_probe (struct i2c_client *client) +static int skl_int3472_tps68470_probe (struct i2c_client *client) {struct acpi_device *adev =ACPI_COMPANION (&client->dev);struct regmap *regmap;
@@ -142,3 +142,22 @@ int skl_int3472_tps68470_probe(struct i2c_client *client)return ret; } + +static const struct acpi_device_id int3472_device_id[] = { + {"INT3472" ,0 }, + { } +}; +MODULE_DEVICE_TABLE (acpi, int3472_device_id); + +static struct i2c_driver int3472_tps68470 = { + .driver = { + .name ="int3472-tps68470" , + .acpi_match_table = int3472_device_id, + }, + .probe_new = skl_int3472_tps68470_probe, +}; +module_i2c_driver (int3472_tps68470); + +MODULE_DESCRIPTION ("Intel SkyLake INT3472 ACPI TPS68470 Device Driver" ); +MODULE_AUTHOR ("Daniel Scally <[email protected]>" ); +MODULE_LICENSE ("GPL v2" );
Signature · 1 line
2.31.1
PATCH v3 8/11 platform/x86: int3472: Add get_sensor_adev_and_name() helper
In reply to Hans de GoedeThe discrete.c code is not the only code which needs to lookup the acpi_device and device-name for the sensor for which the INT3472 ACPI-device is a GPIO/clk/regulator provider.
The tps68470.c code also needs this functionality, so factor this out into a new get_sensor_adev_and_name() helper.
--- drivers/platform/x86/intel/int3472/common.c | 28 +++++++++++++++++++ drivers/platform/x86/intel/int3472/common.h | 3 ++ drivers/platform/x86/intel/int3472/discrete.c | 22 +++------------ 3 files changed, 35 insertions(+), 18 deletions(-)
drivers/platform/x86/intel/int3472/common.c +28 -0
@@ -52,3 +52,31 @@ int skl_int3472_fill_cldb(struct acpi_device *adev, struct int3472_cldb *cldb)kfree (obj);return ret; } + +/* sensor_adev_ret may be NULL, name_ret must not be NULL */ +int skl_int3472_get_sensor_adev_and_name (struct device *dev, +struct acpi_device **sensor_adev_ret, +const char **name_ret) +{ +struct acpi_device *adev =ACPI_COMPANION (dev); +struct acpi_device *sensor; +int ret =0 ; + + sensor =acpi_dev_get_first_consumer_dev (adev); +if (!sensor) { +dev_err (dev,"INT3472 seems to have no dependents.\n" ); +return -ENODEV ; + } + + *name_ret =devm_kasprintf (dev,GFP_KERNEL ,I2C_DEV_NAME_FORMAT , +acpi_dev_name (sensor)); +if (!*name_ret) + ret = -ENOMEM ; + +if (ret ==0 && sensor_adev_ret) + *sensor_adev_ret = sensor; +else +acpi_dev_put (sensor); + +return ret; +}
drivers/platform/x86/intel/int3472/common.h +3 -0
@@ -108,6 +108,9 @@ struct int3472_discrete_device {union acpi_object *skl_int3472_get_acpi_buffer (struct acpi_device *adev,char *id);int skl_int3472_fill_cldb (struct acpi_device *adev,struct int3472_cldb *cldb); +int skl_int3472_get_sensor_adev_and_name (struct device *dev, +struct acpi_device **sensor_adev_ret, +const char **name_ret);int skl_int3472_register_clock (struct int3472_discrete_device *int3472);void skl_int3472_unregister_clock (struct int3472_discrete_device *int3472);
drivers/platform/x86/intel/int3472/discrete.c +4 -18
@@ -363,19 +363,10 @@ static int skl_int3472_discrete_probe(struct platform_device *pdev) int3472->dev = &pdev->dev;platform_set_drvdata (pdev, int3472); - int3472->sensor =acpi_dev_get_first_consumer_dev (adev); -if (!int3472->sensor) { -dev_err (&pdev->dev,"INT3472 seems to have no dependents.\n" ); -return -ENODEV ; - } - - int3472->sensor_name =devm_kasprintf (int3472->dev,GFP_KERNEL , -I2C_DEV_NAME_FORMAT , -acpi_dev_name (int3472->sensor)); -if (!int3472->sensor_name) { - ret = -ENOMEM ; - goto err_put_sensor; - } + ret =skl_int3472_get_sensor_adev_and_name (&pdev->dev, &int3472->sensor, + &int3472->sensor_name); +if (ret) +return ret;/* * Initialising this list means we can call gpiod_remove_lookup_table()
@@ -390,11 +381,6 @@ static int skl_int3472_discrete_probe(struct platform_device *pdev) }return 0 ; - -err_put_sensor: -acpi_dev_put (int3472->sensor); - -return ret; }static int skl_int3472_discrete_remove (struct platform_device *pdev)
Signature · 1 line
2.31.1
PATCH v3 9/11 platform/x86: int3472: Pass tps68470_clk_platform_data to the tps68470-regulator MFD-cell
In reply to Hans de GoedePass tps68470_clk_platform_data to the tps68470-clk MFD-cell, so that sensors which use the TPS68470 can find their clock.
---
Changes in v2:
- Put the GPIO cell last because acpi_gpiochip_add() calls acpi_dev_clear_dependencies() and the clk + regulators must be ready when this happens.
--- drivers/platform/x86/intel/int3472/tps68470.c | 33 ++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-)
drivers/platform/x86/intel/int3472/tps68470.c +25 -8
@@ -5,6 +5,7 @@#include <linux/mfd/core.h> #include <linux/mfd/tps68470.h> #include <linux/platform_device.h> +#include <linux/platform_data/tps68470.h> #include <linux/regmap.h> #include "common.h"
@@ -17,12 +18,6 @@ static const struct mfd_cell tps68470_cros[] = { { .name = "tps68470_pmic_opregion" }, }; -static const struct mfd_cell tps68470_win[] = { - { .name ="tps68470-gpio" }, - { .name ="tps68470-clk" }, - { .name ="tps68470-regulator" }, -}; -static const struct regmap_config tps68470_regmap_config = { .reg_bits =8 , .val_bits = 8,
@@ -105,10 +100,17 @@ static int skl_int3472_tps68470_calc_type(struct acpi_device *adev)static int skl_int3472_tps68470_probe (struct i2c_client *client) {struct acpi_device *adev =ACPI_COMPANION (&client->dev); +struct tps68470_clk_platform_data clk_pdata = {}; +struct mfd_cell *cells;struct regmap *regmap;int device_type;int ret; + ret =skl_int3472_get_sensor_adev_and_name (&client->dev,NULL , + &clk_pdata.consumer_dev_name); +if (ret) +return ret; + regmap =devm_regmap_init_i2c (client, &tps68470_regmap_config);if (IS_ERR (regmap)) {dev_err (&client->dev,"Failed to create regmap: %ld\n" ,PTR_ERR (regmap));
@@ -126,9 +128,24 @@ static int skl_int3472_tps68470_probe(struct i2c_client *client) device_type =skl_int3472_tps68470_calc_type (adev);switch (device_type) {case DESIGNED_FOR_WINDOWS : - ret =devm_mfd_add_devices (&client->dev,PLATFORM_DEVID_NONE , - tps68470_win,ARRAY_SIZE (tps68470_win), + cells =kcalloc (3 ,sizeof (*cells),GFP_KERNEL ); +if (!cells) +return -ENOMEM ; + + cells[0 ].name ="tps68470-clk" ; + cells[0 ].platform_data = &clk_pdata; + cells[0 ].pdata_size =sizeof (clk_pdata); + cells[1 ].name ="tps68470-regulator" ; +/* +* The GPIO cell must be last because acpi_gpiochip_add() calls +* acpi_dev_clear_dependencies() and the clk + regulators must +* be ready when this happens. +*/ + cells[2 ].name ="tps68470-gpio" ; + + ret =devm_mfd_add_devices (&client->dev,PLATFORM_DEVID_NONE , cells,3 ,NULL ,0 ,NULL ); +kfree (cells);break ;case DESIGNED_FOR_CHROMEOS : ret = devm_mfd_add_devices(&client->dev, PLATFORM_DEVID_NONE,
Signature · 1 line
2.31.1
PATCH v3 10/11 platform/x86: int3472: Pass tps68470_regulator_platform_data to the tps68470-regulator MFD-cell
In reply to Hans de GoedePass tps68470_regulator_platform_data to the tps68470-regulator MFD-cell, specifying the voltages of the various regulators and tying the regulators to the sensor supplies so that sensors which use the TPS68470 can find their regulators.
Since the voltages and supply connections are board-specific, this introduces a DMI matches int3472_tps68470_board_data struct which contains the necessary per-board info.
This per-board info also includes GPIO lookup information for the sensor GPIOs which may be connected to the tps68470 gpios.
--- drivers/platform/x86/intel/int3472/Makefile | 2 +- drivers/platform/x86/intel/int3472/tps68470.c | 28 +++++ drivers/platform/x86/intel/int3472/tps68470.h | 25 ++++ .../x86/intel/int3472/tps68470_board_data.c | 118 ++++++++++++++++++ 4 files changed, 172 insertions(+), 1 deletion(-) create mode 100644 drivers/platform/x86/intel/int3472/tps68470.h create mode 100644 drivers/platform/x86/intel/int3472/tps68470_board_data.c
drivers/platform/x86/intel/int3472/Makefile +1 -1
@@ -1,4 +1,4 @@ obj-$(CONFIG_INTEL_SKL_INT3472) += intel_skl_int3472_discrete.o \ intel_skl_int3472_tps68470.o intel_skl_int3472_discrete-y := discrete.o clk_and_regulator.o common.o -intel_skl_int3472_tps68470-y := tps68470.o common.o +intel_skl_int3472_tps68470-y := tps68470.o tps68470_board_data.o common.o
drivers/platform/x86/intel/int3472/tps68470.c +28 -0
@@ -9,6 +9,7 @@#include <linux/regmap.h> #include "common.h" +#include "tps68470.h" #define DESIGNED_FOR_CHROMEOS 1#define DESIGNED_FOR_WINDOWS 2
@@ -100,6 +101,7 @@ static int skl_int3472_tps68470_calc_type(struct acpi_device *adev)static int skl_int3472_tps68470_probe (struct i2c_client *client) {struct acpi_device *adev =ACPI_COMPANION (&client->dev); +const struct int3472_tps68470_board_data *board_data;struct tps68470_clk_platform_data clk_pdata = {};struct mfd_cell *cells;struct regmap *regmap;
@@ -128,6 +130,12 @@ static int skl_int3472_tps68470_probe(struct i2c_client *client) device_type =skl_int3472_tps68470_calc_type (adev);switch (device_type) {case DESIGNED_FOR_WINDOWS : + board_data =int3472_tps68470_get_board_data (dev_name (&client->dev)); +if (!board_data) { +dev_err (&client->dev,"No board-data found for this laptop/tablet model\n" ); +return -ENODEV ; + } + cells =kcalloc (3 ,sizeof (*cells),GFP_KERNEL );if (!cells)return -ENOMEM ;
@@ -136,6 +144,8 @@ static int skl_int3472_tps68470_probe(struct i2c_client *client) cells[0 ].platform_data = &clk_pdata; cells[0 ].pdata_size =sizeof (clk_pdata); cells[1 ].name ="tps68470-regulator" ; + cells[1 ].platform_data = (void *)board_data->tps68470_regulator_pdata; + cells[1 ].pdata_size =sizeof (struct tps68470_regulator_platform_data );/* * The GPIO cell must be last because acpi_gpiochip_add() calls * acpi_dev_clear_dependencies() and the clk + regulators must
@@ -143,9 +153,15 @@ static int skl_int3472_tps68470_probe(struct i2c_client *client)*/ cells[2 ].name ="tps68470-gpio" ; +gpiod_add_lookup_table (board_data->tps68470_gpio_lookup_table); + ret =devm_mfd_add_devices (&client->dev,PLATFORM_DEVID_NONE , cells,3 ,NULL ,0 ,NULL );kfree (cells); + +if (ret) +gpiod_remove_lookup_table (board_data->tps68470_gpio_lookup_table); +break ;case DESIGNED_FOR_CHROMEOS : ret = devm_mfd_add_devices(&client->dev, PLATFORM_DEVID_NONE,
@@ -160,6 +176,17 @@ static int skl_int3472_tps68470_probe(struct i2c_client *client)return ret; } +static int skl_int3472_tps68470_remove (struct i2c_client *client) +{ +const struct int3472_tps68470_board_data *board_data; + + board_data =int3472_tps68470_get_board_data (dev_name (&client->dev)); +if (board_data) +gpiod_remove_lookup_table (board_data->tps68470_gpio_lookup_table); + +return 0 ; +} +static const struct acpi_device_id int3472_device_id[] = { {"INT3472" ,0 }, { }
@@ -172,6 +199,7 @@ static struct i2c_driver int3472_tps68470 = { .acpi_match_table = int3472_device_id, }, .probe_new = skl_int3472_tps68470_probe, + .remove = skl_int3472_tps68470_remove, };module_i2c_driver (int3472_tps68470);
drivers/platform/x86/intel/int3472/tps68470.h new file +25 -0
@@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* TI TPS68470 PMIC platform data definition. +* +* Copyright (c) 2021 Red Hat Inc. +* +* Red Hat authors: +* Hans de Goede <[email protected]> +*/ + +#ifndef _INTEL_SKL_INT3472_TPS68470_H +#define _INTEL_SKL_INT3472_TPS68470_H + +struct gpiod_lookup_table ; +struct tps68470_regulator_platform_data ; + +struct int3472_tps68470_board_data { +const char *dev_name; +struct gpiod_lookup_table *tps68470_gpio_lookup_table; +const struct tps68470_regulator_platform_data *tps68470_regulator_pdata; +}; + +const struct int3472_tps68470_board_data *int3472_tps68470_get_board_data (const char *dev_name); + +#endif
drivers/platform/x86/intel/int3472/tps68470_board_data.c new file +118 -0
118 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v3 11/11 platform/x86: int3472: Deal with probe ordering issues
In reply to Hans de GoedeThe clk and regulator frameworks expect clk/regulator consumer-devices to have info about the consumed clks/regulators described in the device's fw_node.
To work around this info missing from the ACPI tables on devices where the int3472 driver is used, the int3472 MFD-cell drivers attach info about consumers to the clks/regulators when registering these.
This causes problems with the probe ordering wrt drivers for consumers of these clks/regulators. Since the lookups are only registered when the provider-driver binds, trying to get these clks/regulators before then results in a -ENOENT error for clks and a dummy regulator for regulators.
All the sensor ACPI fw-nodes have a _DEP dependency on the INT3472 ACPI fw-node, so to work around these probe ordering issues the ACPI core / i2c-code does not instantiate the I2C-clients for any ACPI devices which have a _DEP dependency on an INT3472 ACPI device until all _DEP-s are met.
This relies on acpi_dev_clear_dependencies() getting called by the driver for the _DEP-s when they are ready, add a acpi_dev_clear_dependencies() call to the discrete.c probe code.
In the tps68470 case calling acpi_dev_clear_dependencies() is already done by the acpi_gpiochip_add() call done by the driver for the GPIO MFD cell (The GPIO cell is deliberately the last cell created to make sure the clk + regulator cells are already instantiated when this happens).
However for proper probe ordering, the clk/regulator cells must not just be instantiated the must be fully ready (the clks + regulators must be registered with their subsystems).
Add MODULE_SOFTDEP dependencies for the clk and regulator drivers for the instantiated MFD-cells so that these are loaded before us and so that they bind immediately when the platform-devs are instantiated.
---
Changes in v2:
- Only call acpi_dev_clear_dependencies() in the discrete.c case, for the tps68470 case this is already done by the acpi_gpiochip_add() for the GPIO MFD cell.
--- drivers/platform/x86/intel/int3472/discrete.c | 1 + drivers/platform/x86/intel/int3472/tps68470.c | 6 ++++++ 2 files changed, 7 insertions(+)
drivers/platform/x86/intel/int3472/discrete.c +1 -0
@@ -380,6 +380,7 @@ static int skl_int3472_discrete_probe(struct platform_device *pdev)return ret; } +acpi_dev_clear_dependencies (adev);return 0 ; }
drivers/platform/x86/intel/int3472/tps68470.c +6 -0
@@ -173,6 +173,11 @@ static int skl_int3472_tps68470_probe(struct i2c_client *client)return device_type; } +/* +* No acpi_dev_clear_dependencies() here, since the acpi_gpiochip_add() +* for the GPIO cell already does this. +*/ +return ret; }
@@ -206,3 +211,4 @@ module_i2c_driver(int3472_tps68470);MODULE_DESCRIPTION ("Intel SkyLake INT3472 ACPI TPS68470 Device Driver" );MODULE_AUTHOR ("Daniel Scally <[email protected]>" );MODULE_LICENSE ("GPL v2" ); +MODULE_SOFTDEP ("pre: clk-tps68470 tps68470-regulator" );
Signature · 1 line
2.31.1