Add support for X86/ACPI camera sensor/PMIC setup with clk and regulator platform data
Subsystems (12)
v6 cover Add support for X86/ACPI camera sensor/PMIC setup with clk and regulator platform data
Here is v6 of my patch-set adding support for camera sensor connected to a TPS68470 PMIC on x86/ACPI devices.
Changes in v6:
- Add support for the VCM (Voice Coil Motor) controlling the focus of the back/main sensor camera lens:
- Patch 3 and patches 13-15 are new patches for this
- While working on this I learned that the VIO regulator is an always on regulator and must be configured at the same voltage as VSIO, the tps68470-regulator driver and the constraints have been updated for this
- Addressed clk-tps68470 driver review-remarks
- Some minor tweaks based on review-remarks from Andy
- Add Andy's Reviewed-by to all patches which were also in v5
I'm quite happy with how this works now, so from my pov this is ready for merging now.
Patch 2 already has acks for merging through another tree. Patch 3 "i2c: acpi: Add i2c_acpi_new_device_by_fwnode() function" is new, Mika, Wolfram may we have your Ack for merging this one through Rafael's ACPI or through my platform/drivers/x86 tree too ?
Once we have acks to merge both i2c-core-acpi.c through another tree, there are 2 options:
a. 1. Patches 1-3 merged by Rafael, Rafael provides an IM branch
2. I create an IM branch with patches 4 + 7-12
3. clk + regulator maintainers merge my IM branch + clk / regulator patch
4. media maintainers merge Rafael's IM branch + media patches
b. 1. I create an IM branch with patches 1-4 + 7-12 (with Rafael's ack for 1)
2. clk / regulator / media maintainers merge my IM branch + their resp. patches
Assuming Rafael does not foresee any conflicts caused by the few small ACPI patches I believe that going with plan b would be best.
Rafael is plan b. ok with you ? You did already Ack patch 1 but IIRC that was not specifically for merging it through another tree.
Regards,
Hans
p.s.
For the record here is part of the old cover-letter of v5:
Changes in v5:
- Update regulator_init_data in patch 10/11 to include the VCM regulator
- Address various small review remarks from Andy
- Make a couple of functions / vars static in the clk + regulator drivers
Changes in v4:
[PATCH 01/11] ACPI: delay enumeration of devices with a _DEP
pointing to an INT3472 device:
- Move the acpi_dev_ready_for_enumeration() check to acpi_bus_attach() (replacing the acpi_device_is_present() check there)
[PATCH 04/11] regulator: Introduce tps68470-regulator driver:
- Make the top comment block use c++ style comments
- Drop the bogus builtin regulator_init_data
- Make the driver enable the PMIC clk when enabling the Core buck regulator, this switching regulator needs the PLL to be on
- Kconfig: add || COMPILE_TEST, fix help text
[PATCH 05/11] clk: Introduce clk-tps68470 driver
- Kconfig: select REGMAP_I2C, add || COMPILE_TEST, fix help text
- tps68470_clk_prepare(): Wait for the PLL to lock before returning
- tps68470_clk_unprepare(): Remove unnecessary clearing of divider regs
- tps68470_clk_probe(): Use devm_clk_hw_register()
- Misc. small cleanups
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.
Daniel Scally (1):
platform/x86: int3472: Enable I2c daisy chain
Hans de Goede (14):
ACPI: delay enumeration of devices with a _DEP pointing to an INT3472
device
i2c: acpi: Use acpi_dev_ready_for_enumeration() helper
i2c: acpi: Add i2c_acpi_new_device_by_fwnode() function
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-cell platform/x86: int3472: Deal with probe ordering issues
media: ipu3-cio2: Defer probing until the PMIC is fully setup
media: ipu3-cio2: Call cio2_bridge_init() before anything else
media: ipu3-cio2: Add support for instantiating i2c-clients for VCMs
drivers/acpi/scan.c | 37 ++-
drivers/clk/Kconfig | 8 +
drivers/clk/Makefile | 1 +
drivers/clk/clk-tps68470.c | 257 ++++++++++++++++++
drivers/i2c/i2c-core-acpi.c | 23 +-
drivers/media/pci/intel/ipu3/cio2-bridge.c | 92 +++++++
drivers/media/pci/intel/ipu3/cio2-bridge.h | 16 +-
drivers/media/pci/intel/ipu3/ipu3-cio2-main.c | 10 +-
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} | 99 ++++++-
drivers/platform/x86/intel/int3472/tps68470.h | 25 ++
.../x86/intel/int3472/tps68470_board_data.c | 145 ++++++++++
drivers/regulator/Kconfig | 9 +
drivers/regulator/Makefile | 1 +
drivers/regulator/tps68470-regulator.c | 201 ++++++++++++++
include/acpi/acpi_bus.h | 5 +-
include/linux/i2c.h | 17 +-
include/linux/mfd/tps68470.h | 11 +
include/linux/platform_data/tps68470.h | 35 +++
24 files changed, 1080 insertions(+), 168 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} (54%)
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.33.1
PATCH v6 1/15 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.
---
Changes in v4:
- Move the acpi_dev_ready_for_enumeration() check to acpi_bus_attach() (replacing the acpi_device_is_present() check there)
--- drivers/acpi/scan.c | 37 +++++++++++++++++++++++++++++++++---- include/acpi/acpi_bus.h | 5 ++++- 2 files changed, 37 insertions(+), 5 deletions(-)
drivers/acpi/scan.c +33 -4
@@ -797,6 +797,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 ;
@@ -1762,8 +1768,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++; + } } }
@@ -1967,7 +1977,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)) {
@@ -1976,6 +1986,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)
@@ -1989,6 +2000,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);
@@ -2155,8 +2167,8 @@ static void acpi_bus_attach(struct acpi_device *device, bool first_pass)register_dock_dependent_device (device, ejd);acpi_bus_get_status (device); -/* Skip devices that are not present. */ -if (!acpi_device_is_present (device)) { +/* Skip devices that are not ready for enumeration (e.g. not present) */ +if (!acpi_dev_ready_for_enumeration (device)) { device->flags.initialized = false;acpi_device_clear_enumerated (device); device->flags.power_manageable =0 ;
@@ -2318,6 +2330,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 */
@@ -285,6 +286,7 @@ struct acpi_dep_data {struct list_head node;acpi_handle supplier;acpi_handle consumer; +bool honor_dep; };/* Performance Management */
@@ -694,6 +696,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.33.1
PATCH v6 2/15 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.33.1
Re: [PATCH v6 02/15] i2c: acpi: Use acpi_dev_ready_for_enumeration() helper
Quoted 17 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.
Quoted 7 lines
Call the new
acpi_dev_ready_for_enumeration()helper to avoid enumerating / instantiating i2c-clients too early.Acked-by Wolfram Sang <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>Signed-off-by Hans de Goede <[email protected]>
PATCH v6 3/15 i2c: acpi: Add i2c_acpi_new_device_by_fwnode() function
In reply to Hans de GoedeChange i2c_acpi_new_device() into i2c_acpi_new_device_by_fwnode() and add a static inline wrapper providing the old i2c_acpi_new_device() behavior.
This is necessary because in some cases we may only have access to the fwnode / acpi_device and not to the matching physical-node struct device *.
---
Changes in v6:
- New patch in v6 of this patch series
--- drivers/i2c/i2c-core-acpi.c | 18 ++++++++++++------ include/linux/i2c.h | 17 +++++++++++++---- 2 files changed, 25 insertions(+), 10 deletions(-)
drivers/i2c/i2c-core-acpi.c +12 -6
@@ -476,8 +476,9 @@ struct notifier_block i2c_acpi_notifier = { };/** -* i2c_acpi_new_device - Create i2c-client for the Nth I2cSerialBus resource -* @dev: Device owning the ACPI resources to get the client from +* i2c_acpi_new_device_by_fwnode - Create i2c-client for the Nth I2cSerialBus +* resource +* @fwnode: fwnode with the ACPI resources to get the client from * @index: Index of ACPI resource to get * @info: describes the I2C device; note this is modified (addr gets set) * Context: can sleep
@@ -493,15 +494,20 @@ struct notifier_block i2c_acpi_notifier = {* Returns a pointer to the new i2c-client, or error pointer in case of failure. * Specifically, -EPROBE_DEFER is returned if the adapter is not found. */ -struct i2c_client *i2c_acpi_new_device (struct device *dev,int index, -struct i2c_board_info *info) +struct i2c_client *i2c_acpi_new_device_by_fwnode (struct fwnode_handle *fwnode, +int index, +struct i2c_board_info *info) { -struct acpi_device *adev =ACPI_COMPANION (dev);struct i2c_acpi_lookup lookup;struct i2c_adapter *adapter; +struct acpi_device *adev;LIST_HEAD (resource_list);int ret; + adev =to_acpi_device_node (fwnode); +if (!adev) +return ERR_PTR (-ENODEV ); +memset (&lookup,0 ,sizeof (lookup)); lookup.info = info; lookup.device_handle =acpi_device_handle (adev);
@@ -523,7 +529,7 @@ struct i2c_client *i2c_acpi_new_device(struct device *dev, int index,return i2c_new_client_device (adapter, info); } -EXPORT_SYMBOL_GPL (i2c_acpi_new_device); +EXPORT_SYMBOL_GPL (i2c_acpi_new_device_by_fwnode);bool i2c_acpi_waive_d0_probe (struct device *dev) {
include/linux/i2c.h +13 -4
@@ -1025,8 +1025,9 @@ bool i2c_acpi_get_i2c_resource(struct acpi_resource *ares, struct acpi_resource_i2c_serialbus **i2c);int i2c_acpi_client_count (struct acpi_device *adev);u32 i2c_acpi_find_bus_speed (struct device *dev); -struct i2c_client *i2c_acpi_new_device (struct device *dev,int index, -struct i2c_board_info *info); +struct i2c_client *i2c_acpi_new_device_by_fwnode (struct fwnode_handle *fwnode, +int index, +struct i2c_board_info *info);struct i2c_adapter *i2c_acpi_find_adapter_by_handle (acpi_handle handle);bool i2c_acpi_waive_d0_probe (struct device *dev);#else
@@ -1043,8 +1044,9 @@ static inline u32 i2c_acpi_find_bus_speed(struct device *dev) {return 0 ; } -static inline struct i2c_client *i2c_acpi_new_device (struct device *dev, -int index,struct i2c_board_info *info) +static inline struct i2c_client *i2c_acpi_new_device_by_fwnode ( +struct fwnode_handle *fwnode,int index, +struct i2c_board_info *info) {return ERR_PTR (-ENODEV ); }
@@ -1058,4 +1060,11 @@ static inline bool i2c_acpi_waive_d0_probe(struct device *dev) }#endif /* CONFIG_ACPI */ +static inline struct i2c_client *i2c_acpi_new_device (struct device *dev, +int index, +struct i2c_board_info *info) +{ +return i2c_acpi_new_device_by_fwnode (dev_fwnode (dev), index, info); +} +#endif /* _LINUX_I2C_H */
Signature · 1 line
2.33.1
Re: [PATCH v6 03/15] i2c: acpi: Add i2c_acpi_new_device_by_fwnode() function
Quoted 8 lines · Hans de Goede
Change
i2c_acpi_new_device()intoi2c_acpi_new_device_by_fwnode()and add a static inline wrapper providing the oldi2c_acpi_new_device()behavior.This is necessary because in some cases we may only have access to the fwnode /
acpi_deviceand not to the matching physical-node struct device *.
One nit-pick below.
Thanks!
Quoted 15 lines
Suggested-by Andy Shevchenko <[email protected]>Signed-off-by Hans de Goede <[email protected]>---
Changes in v6:
- New patch in v6 of this patch series--- drivers/i2c/i2c-core-acpi.c | 18 ++++++++++++------ include/linux/i2c.h | 17 +++++++++++++---- 2 files changed, 25 insertions(+), 10 deletions(-)drivers/i2c/i2c-core-acpi.c +0
-0
drivers/i2c/i2c-core-acpi.c struct notifier_block i2c_acpi_notifier = { · line 481
Quoted 8 lines
drivers/i2c/i2c-core-acpi.c +2
-2@@ -476,8 +476,9 @@ struct notifier_block i2c_acpi_notifier = { };/** -* i2c_acpi_new_device - Create i2c-client for the Nth I2cSerialBus resource -* @dev: Device owning the ACPI resources to get the client from +* i2c_acpi_new_device_by_fwnode - Create i2c-client for the Nth I2cSerialBus +* resource
Can be on one line.
Quoted 80 lines
drivers/i2c/i2c-core-acpi.c +1
-0+* @fwnode: fwnode with the ACPI resources to get the client from * @index: Index of ACPI resource to get * @info: describes the I2C device; note this is modified (addr gets set) * Context: can sleep
drivers/i2c/i2c-core-acpi.c +9
-4@@ -493,15 +494,20 @@ struct notifier_block i2c_acpi_notifier = {* Returns a pointer to the new i2c-client, or error pointer in case of failure. * Specifically, -EPROBE_DEFER is returned if the adapter is not found. */ -struct i2c_client *i2c_acpi_new_device (struct device *dev,int index, -struct i2c_board_info *info) +struct i2c_client *i2c_acpi_new_device_by_fwnode (struct fwnode_handle *fwnode, +int index, +struct i2c_board_info *info) { -struct acpi_device *adev =ACPI_COMPANION (dev);struct i2c_acpi_lookup lookup;struct i2c_adapter *adapter; +struct acpi_device *adev;LIST_HEAD (resource_list);int ret; + adev =to_acpi_device_node (fwnode); +if (!adev) +return ERR_PTR (-ENODEV ); +memset (&lookup,0 ,sizeof (lookup)); lookup.info = info; lookup.device_handle =acpi_device_handle (adev);@@ -523,7 +529,7 @@ struct i2c_client *i2c_acpi_new_device(struct device *dev, int index,return i2c_new_client_device (adapter, info); } -EXPORT_SYMBOL_GPL (i2c_acpi_new_device); +EXPORT_SYMBOL_GPL (i2c_acpi_new_device_by_fwnode);bool i2c_acpi_waive_d0_probe (struct device *dev) {include/linux/i2c.h +13
-5@@ -1025,8 +1025,9 @@ bool i2c_acpi_get_i2c_resource(struct acpi_resource *ares, struct acpi_resource_i2c_serialbus **i2c);int i2c_acpi_client_count (struct acpi_device *adev);u32 i2c_acpi_find_bus_speed (struct device *dev); -struct i2c_client *i2c_acpi_new_device (struct device *dev,int index, -struct i2c_board_info *info); +struct i2c_client *i2c_acpi_new_device_by_fwnode (struct fwnode_handle *fwnode, +int index, +struct i2c_board_info *info);struct i2c_adapter *i2c_acpi_find_adapter_by_handle (acpi_handle handle);bool i2c_acpi_waive_d0_probe (struct device *dev);#else @@ -1043,8 +1044,9 @@ static inline u32 i2c_acpi_find_bus_speed(struct device *dev) {return 0 ; } -static inline struct i2c_client *i2c_acpi_new_device (struct device *dev, -int index,struct i2c_board_info *info) +static inline struct i2c_client *i2c_acpi_new_device_by_fwnode ( +struct fwnode_handle *fwnode,int index, +struct i2c_board_info *info) {return ERR_PTR (-ENODEV ); }@@ -1058,4 +1060,11 @@ static inline bool i2c_acpi_waive_d0_probe(struct device *dev) }#endif /* CONFIG_ACPI */ +static inline struct i2c_client *i2c_acpi_new_device (struct device *dev, +int index, +struct i2c_board_info *info) +{ +return i2c_acpi_new_device_by_fwnode (dev_fwnode (dev), index, info); +} +#endif /* _LINUX_I2C_H */ --2.33.1
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v6 03/15] i2c: acpi: Add i2c_acpi_new_device_by_fwnode() function
Hi,
Quoted 6 lines · Andy Shevchenko
Quoted 5 lines · Hans de Goede
Change
i2c_acpi_new_device()intoi2c_acpi_new_device_by_fwnode()and add a static inline wrapper providing the oldi2c_acpi_new_device()behavior.
Quoted 6 lines
Quoted 3 lines
This is necessary because in some cases we may only have access to the fwnode /
acpi_deviceand not to the matching physical-node struct device *.One nit-pick below.
Reviewed-by Andy Shevchenko <[email protected]>
Thank you, I've fixed the nit-pick in my local tree, either for v7 of the series, of for in the immutable branch which I plan to create for this.
Regards,
Hans
Quoted 108 lines
Quoted 15 lines
Suggested-by Andy Shevchenko <[email protected]>Signed-off-by Hans de Goede <[email protected]>---
Changes in v6:
- New patch in v6 of this patch series--- drivers/i2c/i2c-core-acpi.c | 18 ++++++++++++------ include/linux/i2c.h | 17 +++++++++++++---- 2 files changed, 25 insertions(+), 10 deletions(-)drivers/i2c/i2c-core-acpi.c +0
-0drivers/i2c/i2c-core-acpi.c struct notifier_block i2c_acpi_notifier = { · line 481
Quoted 8 lines
drivers/i2c/i2c-core-acpi.c +2
-2@@ -476,8 +476,9 @@ struct notifier_block i2c_acpi_notifier = { };/** -* i2c_acpi_new_device - Create i2c-client for the Nth I2cSerialBus resource -* @dev: Device owning the ACPI resources to get the client from +* i2c_acpi_new_device_by_fwnode - Create i2c-client for the Nth I2cSerialBus +* resource Can be on one line.
Quoted 80 lines
drivers/i2c/i2c-core-acpi.c +1
-0+* @fwnode: fwnode with the ACPI resources to get the client from * @index: Index of ACPI resource to get * @info: describes the I2C device; note this is modified (addr gets set) * Context: can sleep
drivers/i2c/i2c-core-acpi.c +9
-4@@ -493,15 +494,20 @@ struct notifier_block i2c_acpi_notifier = {* Returns a pointer to the new i2c-client, or error pointer in case of failure. * Specifically, -EPROBE_DEFER is returned if the adapter is not found. */ -struct i2c_client *i2c_acpi_new_device (struct device *dev,int index, -struct i2c_board_info *info) +struct i2c_client *i2c_acpi_new_device_by_fwnode (struct fwnode_handle *fwnode, +int index, +struct i2c_board_info *info) { -struct acpi_device *adev =ACPI_COMPANION (dev);struct i2c_acpi_lookup lookup;struct i2c_adapter *adapter; +struct acpi_device *adev;LIST_HEAD (resource_list);int ret; + adev =to_acpi_device_node (fwnode); +if (!adev) +return ERR_PTR (-ENODEV ); +memset (&lookup,0 ,sizeof (lookup)); lookup.info = info; lookup.device_handle =acpi_device_handle (adev);@@ -523,7 +529,7 @@ struct i2c_client *i2c_acpi_new_device(struct device *dev, int index,return i2c_new_client_device (adapter, info); } -EXPORT_SYMBOL_GPL (i2c_acpi_new_device); +EXPORT_SYMBOL_GPL (i2c_acpi_new_device_by_fwnode);bool i2c_acpi_waive_d0_probe (struct device *dev) {include/linux/i2c.h +13
-5@@ -1025,8 +1025,9 @@ bool i2c_acpi_get_i2c_resource(struct acpi_resource *ares, struct acpi_resource_i2c_serialbus **i2c);int i2c_acpi_client_count (struct acpi_device *adev);u32 i2c_acpi_find_bus_speed (struct device *dev); -struct i2c_client *i2c_acpi_new_device (struct device *dev,int index, -struct i2c_board_info *info); +struct i2c_client *i2c_acpi_new_device_by_fwnode (struct fwnode_handle *fwnode, +int index, +struct i2c_board_info *info);struct i2c_adapter *i2c_acpi_find_adapter_by_handle (acpi_handle handle);bool i2c_acpi_waive_d0_probe (struct device *dev);#else @@ -1043,8 +1044,9 @@ static inline u32 i2c_acpi_find_bus_speed(struct device *dev) {return 0 ; } -static inline struct i2c_client *i2c_acpi_new_device (struct device *dev, -int index,struct i2c_board_info *info) +static inline struct i2c_client *i2c_acpi_new_device_by_fwnode ( +struct fwnode_handle *fwnode,int index, +struct i2c_board_info *info) {return ERR_PTR (-ENODEV ); }@@ -1058,4 +1060,11 @@ static inline bool i2c_acpi_waive_d0_probe(struct device *dev) }#endif /* CONFIG_ACPI */ +static inline struct i2c_client *i2c_acpi_new_device (struct device *dev, +int index, +struct i2c_board_info *info) +{ +return i2c_acpi_new_device_by_fwnode (dev_fwnode (dev), index, info); +} +#endif /* _LINUX_I2C_H */ --2.33.1
Re: [PATCH v6 03/15] i2c: acpi: Add i2c_acpi_new_device_by_fwnode() function
In reply to Hans de GoedeQuoted 10 lines · Hans de Goede
Change
i2c_acpi_new_device()intoi2c_acpi_new_device_by_fwnode()and add a static inline wrapper providing the oldi2c_acpi_new_device()behavior.This is necessary because in some cases we may only have access to the fwnode /
acpi_deviceand not to the matching physical-node struct device *.Suggested-by Andy Shevchenko <[email protected]>Signed-off-by Hans de Goede <[email protected]>
Re: [PATCH v6 03/15] i2c: acpi: Add i2c_acpi_new_device_by_fwnode() function
In reply to Hans de GoedeQuoted 10 lines · Hans de Goede
Change
i2c_acpi_new_device()intoi2c_acpi_new_device_by_fwnode()and add a static inline wrapper providing the oldi2c_acpi_new_device()behavior.This is necessary because in some cases we may only have access to the fwnode /
acpi_deviceand not to the matching physical-node struct device *.Suggested-by Andy Shevchenko <[email protected]>Signed-off-by Hans de Goede <[email protected]>
PATCH v6 4/15 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.33.1
PATCH v6 5/15 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 v6:
- Drop the unused volt_table argument from the TPS68470_REGULATOR() macro
- While working on VCM (voice coil motor) support for the camera-module behind this PMIC I learned that the VIO voltage is always on. Instead of pointing its enable_reg and enable_mask at the same register-bits as the VSIO regulator (which is wrong), add a new tps68470_always_on_reg_ops struct without is_enabled, enable and disable ops and use that for the VIO regulator.
Changes in v5:
- Small comment / code cleanups based on review from Andy
Changes in v4:
- Make the top comment block use c++ style comments
- Drop the bogus builtin regulator_init_data
- Add || COMPILE_TEST to Kconfig snippet
- Make the driver enable the PMIC clk when enabling the Core buck regulator, this switching regulator needs the PLL to be on
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 | 201 +++++++++++++++++++++++++ 3 files changed, 211 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 TPS68470 PMIC Regulators Driver" + depends on INTEL_SKL_INT3472 || COMPILE_TEST + 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_TWL4030 tristate "TI TWL4030/TWL5030/TWL6030/TPS659x0 PMIC" depends on TWL4030_CORE
drivers/regulator/Makefile +1 -0
@@ -159,6 +159,7 @@ obj-$(CONFIG_REGULATOR_TPS6586X) += tps6586x-regulator.o obj-$(CONFIG_REGULATOR_TPS65910) += tps65910-regulator.o obj-$(CONFIG_REGULATOR_TPS65912) += tps65912-regulator.o obj-$(CONFIG_REGULATOR_TPS65132) += tps65132-regulator.o +obj-$(CONFIG_REGULATOR_TPS68470) += tps68470-regulator.o obj-$(CONFIG_REGULATOR_TWL4030) += twl-regulator.o twl6030-regulator.o obj-$(CONFIG_REGULATOR_UNIPHIER) += uniphier-regulator.o obj-$(CONFIG_REGULATOR_VCTRL) += vctrl-regulator.o
drivers/regulator/tps68470-regulator.c new file +201 -0
201 lines not on this page · raw message
Signature · 1 line
2.33.1
Re: [PATCH v6 05/15] regulator: Introduce tps68470-regulator driver
Hi Hans,
Thank you for the patch.
I've had a quick look and the driver seems fine. Just a few comments below.
Quoted 196 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.Reviewed-by Andy Shevchenko <[email protected]>Signed-off-by Hans de Goede <[email protected]>---
Changes in v6:
- Drop the unusedvolt_tableargument from theTPS68470_REGULATOR()macro
- While working on VCM (voice coil motor) support for the camera-module behind this PMIC I learned that the VIO voltage is always on. Instead of pointing itsenable_regandenable_maskat the same register-bits as the VSIO regulator (which is wrong), add a newtps68470_always_on_reg_opsstruct withoutis_enabled, enable and disable ops and use that for the VIO regulator.Changes in v5:
- Small comment / code cleanups based on review from AndyChanges in v4:
- Make the top comment block use c++ style comments
- Drop the bogus builtinregulator_init_data
- Add ||COMPILE_TESTtoKconfigsnippet
- Make the driver enable the PMIC clk when enabling the Core buck regulator, this switching regulator needs the PLL to be onChanges 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 | 201 +++++++++++++++++++++++++ 3 files changed, 211 insertions(+) create mode 100644 drivers/regulator/tps68470-regulator.cdrivers/regulator/Kconfig +9
-0@@ -1339,6 +1339,15 @@ config REGULATOR_TPS65912 help This driver supports TPS65912 voltage regulator chip. +config REGULATOR_TPS68470 + tristate "TI TPS68470 PMIC Regulators Driver" + depends on INTEL_SKL_INT3472 || COMPILE_TEST + 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_TWL4030 tristate "TI TWL4030/TWL5030/TWL6030/TPS659x0 PMIC" depends on TWL4030_COREdrivers/regulator/Makefile +1
-0@@ -159,6 +159,7 @@ obj-$(CONFIG_REGULATOR_TPS6586X) += tps6586x-regulator.o obj-$(CONFIG_REGULATOR_TPS65910) += tps65910-regulator.o obj-$(CONFIG_REGULATOR_TPS65912) += tps65912-regulator.o obj-$(CONFIG_REGULATOR_TPS65132) += tps65132-regulator.o +obj-$(CONFIG_REGULATOR_TPS68470) += tps68470-regulator.o obj-$(CONFIG_REGULATOR_TWL4030) += twl-regulator.o twl6030-regulator.o obj-$(CONFIG_REGULATOR_UNIPHIER) += uniphier-regulator.o obj-$(CONFIG_REGULATOR_VCTRL) += vctrl-regulator.odrivers/regulator/tps68470-regulator.c new file +113
-0@@ -0,0 +1,201 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// Regulator driver for TPS68470 PMIC +// +// Copyright (c) 2021 Red Hat Inc. +// Copyright (C) 2018 Intel Corporation +// +// Authors: +// Hans de Goede <[email protected]> +// Zaikuo Wang <[email protected]> +// Tianshu Qiu <[email protected]> +// Jian Xu Zheng <[email protected]> +// Yuning Pu <[email protected]> +// Rajmohan Mani <[email protected]> + +#include <linux/clk.h> +#include <linux/device.h> +#include <linux/err.h> +#include <linux/init.h> +#include <linux/kernel.h> +#include <linux/mfd/tps68470.h> +#include <linux/module.h> +#include <linux/platform_data/tps68470.h> +#include <linux/platform_device.h> +#include <linux/regulator/driver.h> +#include <linux/regulator/machine.h> + +struct tps68470_regulator_data { +struct clk *clk; +}; + +#define TPS68470_REGULATOR (_name, _id, _ops, _n, \ + _vr, _vm, _er, _em, _lr, _nlr) \ + [TPS68470_ ## _name] = { \ + .name = # _name, \ + .id = _id, \ + .ops = &_ops, \ + .n_voltages = _n, \ + .type = REGULATOR_VOLTAGE, \ + .owner = THIS_MODULE, \ + .vsel_reg = _vr, \ + .vsel_mask = _vm, \ + .enable_reg = _er, \ + .enable_mask = _em, \ + .linear_ranges = _lr, \ + .n_linear_ranges = _nlr, \ + } + +static const struct linear_range tps68470_ldo_ranges[] = { +REGULATOR_LINEAR_RANGE (875000 ,0 ,125 ,17800 ), +}; + +static const struct linear_range tps68470_core_ranges[] = { +REGULATOR_LINEAR_RANGE (900000 ,0 ,42 ,25000 ), +}; + +static int tps68470_regulator_enable (struct regulator_dev *rdev) +{ +struct tps68470_regulator_data *data = rdev->reg_data; +int ret; + +/* The Core buck regulator needs the PMIC's PLL to be enabled */ +if (rdev->desc->id ==TPS68470_CORE ) { + ret =clk_prepare_enable (data->clk); +if (ret) { +dev_err (&rdev->dev,"Error enabling TPS68470 clock\n" ); +return ret; + } + } + +return regulator_enable_regmap (rdev); +} + +static int tps68470_regulator_disable (struct regulator_dev *rdev) +{ +struct tps68470_regulator_data *data = rdev->reg_data; + +if (rdev->desc->id ==TPS68470_CORE ) +clk_disable_unprepare (data->clk); + +return regulator_disable_regmap (rdev); +} + +/* Operations permitted on DCDCx, LDO2, LDO3 and LDO4 */ +static const struct regulator_ops tps68470_regulator_ops = { + .is_enabled = regulator_is_enabled_regmap, + .enable = tps68470_regulator_enable, + .disable = tps68470_regulator_disable, + .get_voltage_sel = regulator_get_voltage_sel_regmap, + .set_voltage_sel = regulator_set_voltage_sel_regmap, + .list_voltage = regulator_list_voltage_linear_range, + .map_voltage = regulator_map_voltage_linear_range, +}; + +static const struct regulator_ops tps68470_always_on_reg_ops = { + .get_voltage_sel = regulator_get_voltage_sel_regmap, + .set_voltage_sel = regulator_set_voltage_sel_regmap, + .list_voltage = regulator_list_voltage_linear_range, + .map_voltage = regulator_map_voltage_linear_range, +}; + +static const struct regulator_desc regulators[] = { +TPS68470_REGULATOR (CORE ,TPS68470_CORE , tps68470_regulator_ops,43 , +TPS68470_REG_VDVAL ,TPS68470_VDVAL_DVOLT_MASK , +TPS68470_REG_VDCTL ,TPS68470_VDCTL_EN_MASK , + tps68470_core_ranges,ARRAY_SIZE (tps68470_core_ranges)), +TPS68470_REGULATOR (ANA ,TPS68470_ANA , tps68470_regulator_ops,126 , +TPS68470_REG_VAVAL ,TPS68470_VAVAL_AVOLT_MASK , +TPS68470_REG_VACTL ,TPS68470_VACTL_EN_MASK , + tps68470_ldo_ranges,ARRAY_SIZE (tps68470_ldo_ranges)), + TPS68470_REGULATOR(VCM, TPS68470_VCM, tps68470_regulator_ops, 126, + TPS68470_REG_VCMVAL, TPS68470_VCMVAL_VCVOLT_MASK, + TPS68470_REG_VCMCTL, TPS68470_VCMCTL_EN_MASK,
drivers/regulator/tps68470-regulator.c line 123
Quoted 10 lines
drivers/regulator/tps68470-regulator.c new file +10
-0+ tps68470_ldo_ranges, ARRAY_SIZE(tps68470_ldo_ranges)), +TPS68470_REGULATOR (VIO ,TPS68470_VIO , tps68470_always_on_reg_ops,126 , +TPS68470_REG_VIOVAL ,TPS68470_VIOVAL_IOVOLT_MASK , +0 ,0 , + tps68470_ldo_ranges, ARRAY_SIZE(tps68470_ldo_ranges)), +/* +* (1) This regulator must have the same voltage as VIO if S_IO LDO is used to +* power a sensor/VCM which I2C is daisy chained behind the PMIC. +* (2) If there is no I2C daisy chain it can be set freely. +*/
Do we need safety checks for this ?
Quoted 34 lines
drivers/regulator/tps68470-regulator.c new file +34
-0+TPS68470_REGULATOR (VSIO ,TPS68470_VSIO , tps68470_regulator_ops,126 , +TPS68470_REG_VSIOVAL ,TPS68470_VSIOVAL_IOVOLT_MASK , +TPS68470_REG_S_I2C_CTL ,TPS68470_S_I2C_CTL_EN_MASK , + tps68470_ldo_ranges,ARRAY_SIZE (tps68470_ldo_ranges)), +TPS68470_REGULATOR (AUX1 ,TPS68470_AUX1 , tps68470_regulator_ops,126 , +TPS68470_REG_VAUX1VAL ,TPS68470_VAUX1VAL_AUX1VOLT_MASK , +TPS68470_REG_VAUX1CTL ,TPS68470_VAUX1CTL_EN_MASK , + tps68470_ldo_ranges,ARRAY_SIZE (tps68470_ldo_ranges)), +TPS68470_REGULATOR (AUX2 ,TPS68470_AUX2 , tps68470_regulator_ops,126 , +TPS68470_REG_VAUX2VAL ,TPS68470_VAUX2VAL_AUX2VOLT_MASK , +TPS68470_REG_VAUX2CTL ,TPS68470_VAUX2CTL_EN_MASK , + tps68470_ldo_ranges, ARRAY_SIZE(tps68470_ldo_ranges)), +}; + +static int tps68470_regulator_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct tps68470_regulator_platform_data *pdata =dev_get_platdata (dev); +struct tps68470_regulator_data *data; +struct regulator_config config = { }; +struct regulator_dev *rdev; +int i; + + data =devm_kzalloc (dev,sizeof (*data),GFP_KERNEL ); +if (!data) +return -ENOMEM ; + + data->clk =devm_clk_get (dev,"tps68470-clk" ); +if (IS_ERR (data->clk)) +return dev_err_probe (dev,PTR_ERR (data->clk),"getting tps68470-clk\n" ); + + config.dev = dev->parent; + config.regmap =dev_get_drvdata (dev->parent); + config.driver_data = data;
drivers/regulator/tps68470-regulator.c line 167
Quoted 10 lines
drivers/regulator/tps68470-regulator.c new file +10
-0+ +for (i =0 ; i <TPS68470_NUM_REGULATORS ; i++) { +if (pdata) + config.init_data = pdata->reg_init_data[i]; +else + config.init_data =NULL ; + + rdev =devm_regulator_register (dev, ®ulators[i], &config); +if (IS_ERR (rdev)) + return dev_err_probe(dev, PTR_ERR(data->clk),
This should be PTR_ERR(rdev).
Quoted 34 lines
drivers/regulator/tps68470-regulator.c new file +34
-0+"registering %s regulator\n" , + regulators[i].name); + } + +return 0 ; +} + +static struct platform_driver tps68470_regulator_driver = { + .driver = { + .name ="tps68470-regulator" , + }, + .probe = tps68470_regulator_probe, +}; + +/* +* The ACPI tps68470 probe-ordering depends on the clk/gpio/regulator drivers +* registering before the drivers for the camera-sensors which use them bind. +* subsys_initcall() ensures this when the drivers are builtin. +*/ +static int __init tps68470_regulator_init (void ) +{ +return platform_driver_register (&tps68470_regulator_driver); +} +subsys_initcall (tps68470_regulator_init); + +static void __exit tps68470_regulator_exit(void) +{ +platform_driver_unregister (&tps68470_regulator_driver); +} +module_exit (tps68470_regulator_exit); + +MODULE_ALIAS ("platform:tps68470-regulator" ); +MODULE_DESCRIPTION ("TPS68470 voltage regulator driver" ); +MODULE_LICENSE ("GPL v2" );
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH v6 05/15] regulator: Introduce tps68470-regulator driver
Hi Laurent,
Quoted 208 lines · Laurent Pinchart
Hi Hans,
Thank you for the patch.
I've had a quick look and the driver seems fine. Just a few comments below.
Quoted 200 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.Reviewed-by Andy Shevchenko <[email protected]>Signed-off-by Hans de Goede <[email protected]>---
Changes in v6:
- Drop the unusedvolt_tableargument from theTPS68470_REGULATOR()macro
- While working on VCM (voice coil motor) support for the camera-module behind this PMIC I learned that the VIO voltage is always on. Instead of pointing itsenable_regandenable_maskat the same register-bits as the VSIO regulator (which is wrong), add a newtps68470_always_on_reg_opsstruct withoutis_enabled, enable and disable ops and use that for the VIO regulator.Changes in v5:
- Small comment / code cleanups based on review from AndyChanges in v4:
- Make the top comment block use c++ style comments
- Drop the bogus builtinregulator_init_data
- Add ||COMPILE_TESTtoKconfigsnippet
- Make the driver enable the PMIC clk when enabling the Core buck regulator, this switching regulator needs the PLL to be onChanges 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 | 201 +++++++++++++++++++++++++ 3 files changed, 211 insertions(+) create mode 100644 drivers/regulator/tps68470-regulator.cdrivers/regulator/Kconfig +9
-0@@ -1339,6 +1339,15 @@ config REGULATOR_TPS65912 help This driver supports TPS65912 voltage regulator chip. +config REGULATOR_TPS68470 + tristate "TI TPS68470 PMIC Regulators Driver" + depends on INTEL_SKL_INT3472 || COMPILE_TEST + 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_TWL4030 tristate "TI TWL4030/TWL5030/TWL6030/TPS659x0 PMIC" depends on TWL4030_COREdrivers/regulator/Makefile +1
-0@@ -159,6 +159,7 @@ obj-$(CONFIG_REGULATOR_TPS6586X) += tps6586x-regulator.o obj-$(CONFIG_REGULATOR_TPS65910) += tps65910-regulator.o obj-$(CONFIG_REGULATOR_TPS65912) += tps65912-regulator.o obj-$(CONFIG_REGULATOR_TPS65132) += tps65132-regulator.o +obj-$(CONFIG_REGULATOR_TPS68470) += tps68470-regulator.o obj-$(CONFIG_REGULATOR_TWL4030) += twl-regulator.o twl6030-regulator.o obj-$(CONFIG_REGULATOR_UNIPHIER) += uniphier-regulator.o obj-$(CONFIG_REGULATOR_VCTRL) += vctrl-regulator.odrivers/regulator/tps68470-regulator.c new file +117
-0@@ -0,0 +1,201 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// Regulator driver for TPS68470 PMIC +// +// Copyright (c) 2021 Red Hat Inc. +// Copyright (C) 2018 Intel Corporation +// +// Authors: +// Hans de Goede <[email protected]> +// Zaikuo Wang <[email protected]> +// Tianshu Qiu <[email protected]> +// Jian Xu Zheng <[email protected]> +// Yuning Pu <[email protected]> +// Rajmohan Mani <[email protected]> + +#include <linux/clk.h> +#include <linux/device.h> +#include <linux/err.h> +#include <linux/init.h> +#include <linux/kernel.h> +#include <linux/mfd/tps68470.h> +#include <linux/module.h> +#include <linux/platform_data/tps68470.h> +#include <linux/platform_device.h> +#include <linux/regulator/driver.h> +#include <linux/regulator/machine.h> + +struct tps68470_regulator_data { +struct clk *clk; +}; + +#define TPS68470_REGULATOR (_name, _id, _ops, _n, \ + _vr, _vm, _er, _em, _lr, _nlr) \ + [TPS68470_ ## _name] = { \ + .name = # _name, \ + .id = _id, \ + .ops = &_ops, \ + .n_voltages = _n, \ + .type = REGULATOR_VOLTAGE, \ + .owner = THIS_MODULE, \ + .vsel_reg = _vr, \ + .vsel_mask = _vm, \ + .enable_reg = _er, \ + .enable_mask = _em, \ + .linear_ranges = _lr, \ + .n_linear_ranges = _nlr, \ + } + +static const struct linear_range tps68470_ldo_ranges[] = { +REGULATOR_LINEAR_RANGE (875000 ,0 ,125 ,17800 ), +}; + +static const struct linear_range tps68470_core_ranges[] = { +REGULATOR_LINEAR_RANGE (900000 ,0 ,42 ,25000 ), +}; + +static int tps68470_regulator_enable (struct regulator_dev *rdev) +{ +struct tps68470_regulator_data *data = rdev->reg_data; +int ret; + +/* The Core buck regulator needs the PMIC's PLL to be enabled */ +if (rdev->desc->id ==TPS68470_CORE ) { + ret =clk_prepare_enable (data->clk); +if (ret) { +dev_err (&rdev->dev,"Error enabling TPS68470 clock\n" ); +return ret; + } + } + +return regulator_enable_regmap (rdev); +} + +static int tps68470_regulator_disable (struct regulator_dev *rdev) +{ +struct tps68470_regulator_data *data = rdev->reg_data; + +if (rdev->desc->id ==TPS68470_CORE ) +clk_disable_unprepare (data->clk); + +return regulator_disable_regmap (rdev); +} + +/* Operations permitted on DCDCx, LDO2, LDO3 and LDO4 */ +static const struct regulator_ops tps68470_regulator_ops = { + .is_enabled = regulator_is_enabled_regmap, + .enable = tps68470_regulator_enable, + .disable = tps68470_regulator_disable, + .get_voltage_sel = regulator_get_voltage_sel_regmap, + .set_voltage_sel = regulator_set_voltage_sel_regmap, + .list_voltage = regulator_list_voltage_linear_range, + .map_voltage = regulator_map_voltage_linear_range, +}; + +static const struct regulator_ops tps68470_always_on_reg_ops = { + .get_voltage_sel = regulator_get_voltage_sel_regmap, + .set_voltage_sel = regulator_set_voltage_sel_regmap, + .list_voltage = regulator_list_voltage_linear_range, + .map_voltage = regulator_map_voltage_linear_range, +}; + +static const struct regulator_desc regulators[] = { +TPS68470_REGULATOR (CORE ,TPS68470_CORE , tps68470_regulator_ops,43 , +TPS68470_REG_VDVAL ,TPS68470_VDVAL_DVOLT_MASK , +TPS68470_REG_VDCTL ,TPS68470_VDCTL_EN_MASK , + tps68470_core_ranges,ARRAY_SIZE (tps68470_core_ranges)), +TPS68470_REGULATOR (ANA ,TPS68470_ANA , tps68470_regulator_ops,126 , +TPS68470_REG_VAVAL ,TPS68470_VAVAL_AVOLT_MASK , +TPS68470_REG_VACTL ,TPS68470_VACTL_EN_MASK , + tps68470_ldo_ranges,ARRAY_SIZE (tps68470_ldo_ranges)), +TPS68470_REGULATOR (VCM ,TPS68470_VCM , tps68470_regulator_ops,126 , +TPS68470_REG_VCMVAL ,TPS68470_VCMVAL_VCVOLT_MASK , +TPS68470_REG_VCMCTL ,TPS68470_VCMCTL_EN_MASK , + tps68470_ldo_ranges,ARRAY_SIZE (tps68470_ldo_ranges)), + TPS68470_REGULATOR(VIO, TPS68470_VIO, tps68470_always_on_reg_ops, 126, + TPS68470_REG_VIOVAL, TPS68470_VIOVAL_IOVOLT_MASK, + 0, 0,
Quoted 8 lines
drivers/regulator/tps68470-regulator.c line 123
Quoted 6 lines
drivers/regulator/tps68470-regulator.c new file +6
-0+ tps68470_ldo_ranges, ARRAY_SIZE(tps68470_ldo_ranges)), +/* +* (1) This regulator must have the same voltage as VIO if S_IO LDO is used to +* power a sensor/VCM which I2C is daisy chained behind the PMIC. +* (2) If there is no I2C daisy chain it can be set freely. +*/ Do we need safety checks for this ?
There really is no way to deal this condition needs to matches inside the driver, this should be enforced by setting proper constraints on the 2 regulators where the PMIC is used with a sensor I2C daisy chained behind it.
Quoted 39 lines
Quoted 39 lines
drivers/regulator/tps68470-regulator.c new file +38
-0+TPS68470_REGULATOR (VSIO ,TPS68470_VSIO , tps68470_regulator_ops,126 , +TPS68470_REG_VSIOVAL ,TPS68470_VSIOVAL_IOVOLT_MASK , +TPS68470_REG_S_I2C_CTL ,TPS68470_S_I2C_CTL_EN_MASK , + tps68470_ldo_ranges,ARRAY_SIZE (tps68470_ldo_ranges)), +TPS68470_REGULATOR (AUX1 ,TPS68470_AUX1 , tps68470_regulator_ops,126 , +TPS68470_REG_VAUX1VAL ,TPS68470_VAUX1VAL_AUX1VOLT_MASK , +TPS68470_REG_VAUX1CTL ,TPS68470_VAUX1CTL_EN_MASK , + tps68470_ldo_ranges,ARRAY_SIZE (tps68470_ldo_ranges)), +TPS68470_REGULATOR (AUX2 ,TPS68470_AUX2 , tps68470_regulator_ops,126 , +TPS68470_REG_VAUX2VAL ,TPS68470_VAUX2VAL_AUX2VOLT_MASK , +TPS68470_REG_VAUX2CTL ,TPS68470_VAUX2CTL_EN_MASK , + tps68470_ldo_ranges, ARRAY_SIZE(tps68470_ldo_ranges)), +}; + +static int tps68470_regulator_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct tps68470_regulator_platform_data *pdata =dev_get_platdata (dev); +struct tps68470_regulator_data *data; +struct regulator_config config = { }; +struct regulator_dev *rdev; +int i; + + data =devm_kzalloc (dev,sizeof (*data),GFP_KERNEL ); +if (!data) +return -ENOMEM ; + + data->clk =devm_clk_get (dev,"tps68470-clk" ); +if (IS_ERR (data->clk)) +return dev_err_probe (dev,PTR_ERR (data->clk),"getting tps68470-clk\n" ); + + config.dev = dev->parent; + config.regmap =dev_get_drvdata (dev->parent); + config.driver_data = data; + +for (i =0 ; i <TPS68470_NUM_REGULATORS ; i++) { +if (pdata) + config.init_data = pdata->reg_init_data[i];
Quoted 8 lines
drivers/regulator/tps68470-regulator.c line 167
Quoted 6 lines
drivers/regulator/tps68470-regulator.c new file +6
-0+else + config.init_data =NULL ; + + rdev =devm_regulator_register (dev, ®ulators[i], &config); +if (IS_ERR (rdev)) + return dev_err_probe(dev, PTR_ERR(data->clk),This should be
PTR_ERR(rdev).
Good catch, thanks. Fixed for v7.
Regards,
Hans
Quoted 36 lines
Quoted 35 lines
drivers/regulator/tps68470-regulator.c new file +34
-0+"registering %s regulator\n" , + regulators[i].name); + } + +return 0 ; +} + +static struct platform_driver tps68470_regulator_driver = { + .driver = { + .name ="tps68470-regulator" , + }, + .probe = tps68470_regulator_probe, +}; + +/* +* The ACPI tps68470 probe-ordering depends on the clk/gpio/regulator drivers +* registering before the drivers for the camera-sensors which use them bind. +* subsys_initcall() ensures this when the drivers are builtin. +*/ +static int __init tps68470_regulator_init (void ) +{ +return platform_driver_register (&tps68470_regulator_driver); +} +subsys_initcall (tps68470_regulator_init); + +static void __exit tps68470_regulator_exit(void) +{ +platform_driver_unregister (&tps68470_regulator_driver); +} +module_exit (tps68470_regulator_exit); + +MODULE_ALIAS ("platform:tps68470-regulator" ); +MODULE_DESCRIPTION ("TPS68470 voltage regulator driver" ); +MODULE_LICENSE ("GPL v2" );
Re: [PATCH v6 05/15] regulator: Introduce tps68470-regulator driver
Hi Hans,
Quoted 211 lines · Hans de Goede
Quoted 201 lines · Laurent Pinchart
Quoted 200 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.Reviewed-by Andy Shevchenko <[email protected]>Signed-off-by Hans de Goede <[email protected]>---
Changes in v6:
- Drop the unusedvolt_tableargument from theTPS68470_REGULATOR()macro
- While working on VCM (voice coil motor) support for the camera-module behind this PMIC I learned that the VIO voltage is always on. Instead of pointing itsenable_regandenable_maskat the same register-bits as the VSIO regulator (which is wrong), add a newtps68470_always_on_reg_opsstruct withoutis_enabled, enable and disable ops and use that for the VIO regulator.Changes in v5:
- Small comment / code cleanups based on review from AndyChanges in v4:
- Make the top comment block use c++ style comments
- Drop the bogus builtinregulator_init_data
- Add ||COMPILE_TESTtoKconfigsnippet
- Make the driver enable the PMIC clk when enabling the Core buck regulator, this switching regulator needs the PLL to be onChanges 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 | 201 +++++++++++++++++++++++++ 3 files changed, 211 insertions(+) create mode 100644 drivers/regulator/tps68470-regulator.cdrivers/regulator/Kconfig +9
-0@@ -1339,6 +1339,15 @@ config REGULATOR_TPS65912 help This driver supports TPS65912 voltage regulator chip. +config REGULATOR_TPS68470 + tristate "TI TPS68470 PMIC Regulators Driver" + depends on INTEL_SKL_INT3472 || COMPILE_TEST + 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_TWL4030 tristate "TI TWL4030/TWL5030/TWL6030/TPS659x0 PMIC" depends on TWL4030_COREdrivers/regulator/Makefile +1
-0@@ -159,6 +159,7 @@ obj-$(CONFIG_REGULATOR_TPS6586X) += tps6586x-regulator.o obj-$(CONFIG_REGULATOR_TPS65910) += tps65910-regulator.o obj-$(CONFIG_REGULATOR_TPS65912) += tps65912-regulator.o obj-$(CONFIG_REGULATOR_TPS65132) += tps65132-regulator.o +obj-$(CONFIG_REGULATOR_TPS68470) += tps68470-regulator.o obj-$(CONFIG_REGULATOR_TWL4030) += twl-regulator.o twl6030-regulator.o obj-$(CONFIG_REGULATOR_UNIPHIER) += uniphier-regulator.o obj-$(CONFIG_REGULATOR_VCTRL) += vctrl-regulator.odrivers/regulator/tps68470-regulator.c new file +117
-0@@ -0,0 +1,201 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// Regulator driver for TPS68470 PMIC +// +// Copyright (c) 2021 Red Hat Inc. +// Copyright (C) 2018 Intel Corporation +// +// Authors: +// Hans de Goede <[email protected]> +// Zaikuo Wang <[email protected]> +// Tianshu Qiu <[email protected]> +// Jian Xu Zheng <[email protected]> +// Yuning Pu <[email protected]> +// Rajmohan Mani <[email protected]> + +#include <linux/clk.h> +#include <linux/device.h> +#include <linux/err.h> +#include <linux/init.h> +#include <linux/kernel.h> +#include <linux/mfd/tps68470.h> +#include <linux/module.h> +#include <linux/platform_data/tps68470.h> +#include <linux/platform_device.h> +#include <linux/regulator/driver.h> +#include <linux/regulator/machine.h> + +struct tps68470_regulator_data { +struct clk *clk; +}; + +#define TPS68470_REGULATOR (_name, _id, _ops, _n, \ + _vr, _vm, _er, _em, _lr, _nlr) \ + [TPS68470_ ## _name] = { \ + .name = # _name, \ + .id = _id, \ + .ops = &_ops, \ + .n_voltages = _n, \ + .type = REGULATOR_VOLTAGE, \ + .owner = THIS_MODULE, \ + .vsel_reg = _vr, \ + .vsel_mask = _vm, \ + .enable_reg = _er, \ + .enable_mask = _em, \ + .linear_ranges = _lr, \ + .n_linear_ranges = _nlr, \ + } + +static const struct linear_range tps68470_ldo_ranges[] = { +REGULATOR_LINEAR_RANGE (875000 ,0 ,125 ,17800 ), +}; + +static const struct linear_range tps68470_core_ranges[] = { +REGULATOR_LINEAR_RANGE (900000 ,0 ,42 ,25000 ), +}; + +static int tps68470_regulator_enable (struct regulator_dev *rdev) +{ +struct tps68470_regulator_data *data = rdev->reg_data; +int ret; + +/* The Core buck regulator needs the PMIC's PLL to be enabled */ +if (rdev->desc->id ==TPS68470_CORE ) { + ret =clk_prepare_enable (data->clk); +if (ret) { +dev_err (&rdev->dev,"Error enabling TPS68470 clock\n" ); +return ret; + } + } + +return regulator_enable_regmap (rdev); +} + +static int tps68470_regulator_disable (struct regulator_dev *rdev) +{ +struct tps68470_regulator_data *data = rdev->reg_data; + +if (rdev->desc->id ==TPS68470_CORE ) +clk_disable_unprepare (data->clk); + +return regulator_disable_regmap (rdev); +} + +/* Operations permitted on DCDCx, LDO2, LDO3 and LDO4 */ +static const struct regulator_ops tps68470_regulator_ops = { + .is_enabled = regulator_is_enabled_regmap, + .enable = tps68470_regulator_enable, + .disable = tps68470_regulator_disable, + .get_voltage_sel = regulator_get_voltage_sel_regmap, + .set_voltage_sel = regulator_set_voltage_sel_regmap, + .list_voltage = regulator_list_voltage_linear_range, + .map_voltage = regulator_map_voltage_linear_range, +}; + +static const struct regulator_ops tps68470_always_on_reg_ops = { + .get_voltage_sel = regulator_get_voltage_sel_regmap, + .set_voltage_sel = regulator_set_voltage_sel_regmap, + .list_voltage = regulator_list_voltage_linear_range, + .map_voltage = regulator_map_voltage_linear_range, +}; + +static const struct regulator_desc regulators[] = { +TPS68470_REGULATOR (CORE ,TPS68470_CORE , tps68470_regulator_ops,43 , +TPS68470_REG_VDVAL ,TPS68470_VDVAL_DVOLT_MASK , +TPS68470_REG_VDCTL ,TPS68470_VDCTL_EN_MASK , + tps68470_core_ranges,ARRAY_SIZE (tps68470_core_ranges)), +TPS68470_REGULATOR (ANA ,TPS68470_ANA , tps68470_regulator_ops,126 , +TPS68470_REG_VAVAL ,TPS68470_VAVAL_AVOLT_MASK , +TPS68470_REG_VACTL ,TPS68470_VACTL_EN_MASK , + tps68470_ldo_ranges,ARRAY_SIZE (tps68470_ldo_ranges)), +TPS68470_REGULATOR (VCM ,TPS68470_VCM , tps68470_regulator_ops,126 , +TPS68470_REG_VCMVAL ,TPS68470_VCMVAL_VCVOLT_MASK , +TPS68470_REG_VCMCTL ,TPS68470_VCMCTL_EN_MASK , + tps68470_ldo_ranges,ARRAY_SIZE (tps68470_ldo_ranges)), + TPS68470_REGULATOR(VIO, TPS68470_VIO, tps68470_always_on_reg_ops, 126, + TPS68470_REG_VIOVAL, TPS68470_VIOVAL_IOVOLT_MASK, + 0, 0,Quoted 8 lines
drivers/regulator/tps68470-regulator.c line 123
Quoted 6 lines
drivers/regulator/tps68470-regulator.c new file +6
-0+ tps68470_ldo_ranges, ARRAY_SIZE(tps68470_ldo_ranges)), +/* +* (1) This regulator must have the same voltage as VIO if S_IO LDO is used to +* power a sensor/VCM which I2C is daisy chained behind the PMIC. +* (2) If there is no I2C daisy chain it can be set freely. +*/ Do we need safety checks for this ?
Quoted 3 lines
There really is no way to deal this condition needs to matches inside the driver, this should be enforced by setting proper constraints on the 2 regulators where the PMIC is used with a sensor I2C daisy chained behind it.
Right. I tend to be cautious here, as incorrect settings can destroy the hardware. We should err on the side of too many safety checks rather than too few. I was thinking that the cio2-bridge driver could set a daisy-chaining flag, which could trigger additional checks here, but it wouldn't protect against someone experimenting to support a new device and setting different voltages without the daisy-chaining flag.
My biggest worry is that someone with an unsupported machine may start by copying and pasting an existing configuration to try it out, and fry their hardware.
Quoted 83 lines
Quoted 38 lines
Quoted 38 lines
drivers/regulator/tps68470-regulator.c new file +38
-0+TPS68470_REGULATOR (VSIO ,TPS68470_VSIO , tps68470_regulator_ops,126 , +TPS68470_REG_VSIOVAL ,TPS68470_VSIOVAL_IOVOLT_MASK , +TPS68470_REG_S_I2C_CTL ,TPS68470_S_I2C_CTL_EN_MASK , + tps68470_ldo_ranges,ARRAY_SIZE (tps68470_ldo_ranges)), +TPS68470_REGULATOR (AUX1 ,TPS68470_AUX1 , tps68470_regulator_ops,126 , +TPS68470_REG_VAUX1VAL ,TPS68470_VAUX1VAL_AUX1VOLT_MASK , +TPS68470_REG_VAUX1CTL ,TPS68470_VAUX1CTL_EN_MASK , + tps68470_ldo_ranges,ARRAY_SIZE (tps68470_ldo_ranges)), +TPS68470_REGULATOR (AUX2 ,TPS68470_AUX2 , tps68470_regulator_ops,126 , +TPS68470_REG_VAUX2VAL ,TPS68470_VAUX2VAL_AUX2VOLT_MASK , +TPS68470_REG_VAUX2CTL ,TPS68470_VAUX2CTL_EN_MASK , + tps68470_ldo_ranges, ARRAY_SIZE(tps68470_ldo_ranges)), +}; + +static int tps68470_regulator_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct tps68470_regulator_platform_data *pdata =dev_get_platdata (dev); +struct tps68470_regulator_data *data; +struct regulator_config config = { }; +struct regulator_dev *rdev; +int i; + + data =devm_kzalloc (dev,sizeof (*data),GFP_KERNEL ); +if (!data) +return -ENOMEM ; + + data->clk =devm_clk_get (dev,"tps68470-clk" ); +if (IS_ERR (data->clk)) +return dev_err_probe (dev,PTR_ERR (data->clk),"getting tps68470-clk\n" ); + + config.dev = dev->parent; + config.regmap =dev_get_drvdata (dev->parent); + config.driver_data = data; + +for (i =0 ; i <TPS68470_NUM_REGULATORS ; i++) { +if (pdata) + config.init_data = pdata->reg_init_data[i];Quoted 8 lines
drivers/regulator/tps68470-regulator.c line 167
Quoted 6 lines
drivers/regulator/tps68470-regulator.c new file +6
-0+else + config.init_data =NULL ; + + rdev =devm_regulator_register (dev, ®ulators[i], &config); +if (IS_ERR (rdev)) + return dev_err_probe(dev, PTR_ERR(data->clk),This should be
PTR_ERR(rdev).Good catch, thanks. Fixed for v7.
Quoted 34 lines
Quoted 34 lines
drivers/regulator/tps68470-regulator.c new file +34
-0+"registering %s regulator\n" , + regulators[i].name); + } + +return 0 ; +} + +static struct platform_driver tps68470_regulator_driver = { + .driver = { + .name ="tps68470-regulator" , + }, + .probe = tps68470_regulator_probe, +}; + +/* +* The ACPI tps68470 probe-ordering depends on the clk/gpio/regulator drivers +* registering before the drivers for the camera-sensors which use them bind. +* subsys_initcall() ensures this when the drivers are builtin. +*/ +static int __init tps68470_regulator_init (void ) +{ +return platform_driver_register (&tps68470_regulator_driver); +} +subsys_initcall (tps68470_regulator_init); + +static void __exit tps68470_regulator_exit(void) +{ +platform_driver_unregister (&tps68470_regulator_driver); +} +module_exit (tps68470_regulator_exit); + +MODULE_ALIAS ("platform:tps68470-regulator" ); +MODULE_DESCRIPTION ("TPS68470 voltage regulator driver" ); +MODULE_LICENSE ("GPL v2" );
Signature · 3 lines
Regards, Laurent Pinchart
Mark Brown
maintainerRe: [PATCH v6 05/15] regulator: Introduce tps68470-regulator driver
Quoted 6 lines · Laurent Pinchart
Quoted 5 lines · Hans de Goede
Quoted 4 lines · Laurent Pinchart
Quoted 3 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
Please delete unneeded context from mails when replying. Doing this makes it much easier to find your reply in the message, helping ensure it won't be missed by people scrolling through the irrelevant quoted material.
Quoted 18 lines
Quoted 10 lines
Quoted 6 lines
Quoted 4 lines
+ * (1) This regulator must have the same voltage as VIO if
S_IOLDO is used to
+ * power a sensor/VCM which I2C is daisy chained behind the PMIC.
+ * (2) If there is no I2C daisy chain it can be set freely.
+ */Do we need safety checks for this ?
There really is no way to deal this condition needs to matches inside the driver, this should be enforced by setting proper constraints on the 2 regulators where the PMIC is used with a sensor I2C daisy chained behind it.
Right. I tend to be cautious here, as incorrect settings can destroy the hardware. We should err on the side of too many safety checks rather than too few. I was thinking that the cio2-bridge driver could set a daisy-chaining flag, which could trigger additional checks here, but it wouldn't protect against someone experimenting to support a new device and setting different voltages without the daisy-chaining flag.
Quoted 3 lines
My biggest worry is that someone with an unsupported machine may start by copying and pasting an existing configuration to try it out, and fry their hardware.
There's really nothing you can do that prevents this, especially in the cut'n'paste scenario. Overrides tend to get copied along with the rest of the configuration, or checks hacked out if people think they're getting in the way without realising what they're there for.
Re: [PATCH v6 05/15] regulator: Introduce tps68470-regulator driver
Hi Mark,
Quoted 4 lines · Mark Brown
Quoted 3 lines · Laurent Pinchart
Quoted 2 lines · Hans de Goede
Quoted 1 line · Laurent Pinchart
On Thu, Nov 25, 2021 at 05:54:02PM +0100, Hans de Goede wrote:
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
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
Please delete unneeded context from mails when replying. Doing this makes it much easier to find your reply in the message, helping ensure it won't be missed by people scrolling through the irrelevant quoted material.
I have mixed feelings about that, someones the context is indeed not needed, but I've found myself more often than not replying deep in a mail thread and wishing the context hadn't been deleted, because it ended up being relevant.
Quoted 18 lines
Quoted 17 lines
Quoted 10 lines
Quoted 6 lines
Quoted 4 lines
+ * (1) This regulator must have the same voltage as VIO if
S_IOLDO is used to
+ * power a sensor/VCM which I2C is daisy chained behind the PMIC.
+ * (2) If there is no I2C daisy chain it can be set freely.
+ */Do we need safety checks for this ?
There really is no way to deal this condition needs to matches inside the driver, this should be enforced by setting proper constraints on the 2 regulators where the PMIC is used with a sensor I2C daisy chained behind it.
Right. I tend to be cautious here, as incorrect settings can destroy the hardware. We should err on the side of too many safety checks rather than too few. I was thinking that the cio2-bridge driver could set a daisy-chaining flag, which could trigger additional checks here, but it wouldn't protect against someone experimenting to support a new device and setting different voltages without the daisy-chaining flag.
Quoted 8 lines
Quoted 3 lines
My biggest worry is that someone with an unsupported machine may start by copying and pasting an existing configuration to try it out, and fry their hardware.
There's really nothing you can do that prevents this, especially in the cut'n'paste scenario. Overrides tend to get copied along with the rest of the configuration, or checks hacked out if people think they're getting in the way without realising what they're there for.
Maybe a big fat warning comment in the code ? Apart from that, I agree, I don't think we can do much.
Signature · 3 lines
Regards, Laurent Pinchart
PATCH v6 6/15 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.
---
Chnages in v6:
- Use CLK_SET_RATE_GATE flag
- Move programming of dividers to tps68470_clk_set_rate()
- Put struct clk_init_data tps68470_clk_initdata on the stack
Changes in v5:
- Small comment cleanups based on review from Andy
Changes in v4:
- Kconfig: select REGMAP_I2C, add || COMPILE_TEST, fix help text
- tps68470_clk_prepare(): Wait for the PLL to lock before returning
- tps68470_clk_unprepare(): Remove unnecesary clearing of divider regs
- tps68470_clk_probe(): Use devm_clk_hw_register()
- Misc. small cleanups
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 | 8 ++ drivers/clk/Makefile | 1 + drivers/clk/clk-tps68470.c | 261 +++++++++++++++++++++++++++++++++++ include/linux/mfd/tps68470.h | 11 ++ 4 files changed, 281 insertions(+) create mode 100644 drivers/clk/clk-tps68470.c
drivers/clk/Kconfig +8 -0
@@ -169,6 +169,14 @@ 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 + depends on INTEL_SKL_INT3472 || COMPILE_TEST + select REGMAP_I2C + help + This driver supports the clocks provided by the TPS68470 PMIC. + 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 +261 -0
261 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.33.1
PATCH v6 7/15 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.33.1
Re: [PATCH v6 07/15] platform/x86: int3472: Enable I2c daisy chain
Hi Hans,
Thank you for the patch.
Quoted 6 lines · Hans de Goede
From: 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.
Is there any drawback doing this unconditionally, if nothing is connected to the bus on the other side (including no pull-ups) ?
Quoted 24 lines
Reviewed-by Andy Shevchenko <[email protected]>Signed-off-by Daniel Scally <[email protected]>--- .../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 · 3 lines
Regards, Laurent Pinchart
Re: [PATCH v6 07/15] platform/x86: int3472: Enable I2c daisy chain
Hi,
Quoted 7 lines · Laurent Pinchart
Hi Hans,
Thank you for the patch.
Quoted 2 lines · Hans de Goede
From: Daniel Scally <[email protected]>
Quoted 7 lines
Quoted 4 lines
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.
Is there any drawback doing this unconditionally, if nothing is connected to the bus on the other side (including no pull-ups) ?
I actually never took a really close look at this patch, I just sorta inherited it from Daniel.
Now that I have taken a close look, I see that it is setting the exact same bits as which get set when enabling the VSIO regulator.
The idea here is that the I2C-passthrough only gets enabled when the VSIO regulator is turned on, because some sensors end up shorting the I2C pins to ground when the sensor is not powered.
Since we set these bits when powering up the VSIO regulator and since we do that before trying to talk to the sensor I don't think that we need this (hack) anymore.
I will give things a try without this change and if things still work I will drop this patch from the set.
Daniel, what do you think?
Regards,
Hans
Quoted 26 lines
Quoted 25 lines
Reviewed-by Andy Shevchenko <[email protected]>Signed-off-by Daniel Scally <[email protected]>--- .../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 ;
Re: [PATCH v6 07/15] platform/x86: int3472: Enable I2c daisy chain
Hello
Quoted 26 lines · Hans de Goede
Hi,
Quoted 5 lines · Laurent Pinchart
Hi Hans,
Thank you for the patch.
On Thu, Nov 25, 2021 at 05:54:04PM +0100, Hans de Goede wrote:
Quoted 8 lines
Quoted 6 lines
From: 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.
Is there any drawback doing this unconditionally, if nothing is connected to the bus on the other side (including no pull-ups) ?
I actually never took a really close look at this patch, I just sorta inherited it from Daniel.
Now that I have taken a close look, I see that it is setting the exact same bits as which get set when enabling the VSIO regulator.
The idea here is that the I2C-passthrough only gets enabled when the VSIO regulator is turned on, because some sensors end up shorting the I2C pins to ground when the sensor is not powered.
Quoted 8 lines
Since we set these bits when powering up the VSIO regulator and since we do that before trying to talk to the sensor I don't think that we need this (hack) anymore.
I will give things a try without this change and if things still work I will drop this patch from the set.
Daniel, what do you think?
Humm, we're only using the VSIO regulator with the VCM though right? Which might not be on when the ov8865 tries to probe. I haven't tried without this patch to be honest; I set it because that was what Windows does when powering on the PMIC.
Quoted 33 lines
Regards,
Hans
Quoted 24 lines
Quoted 24 lines
Reviewed-by Andy Shevchenko <[email protected]>Signed-off-by Daniel Scally <[email protected]>--- .../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 ;
Re: [PATCH v6 07/15] platform/x86: int3472: Enable I2c daisy chain
Hi,
Quoted 33 lines · Daniel Scally
Hello
Quoted 30 lines · Hans de Goede
Hi,
Quoted 5 lines · Laurent Pinchart
Hi Hans,
Thank you for the patch.
On Thu, Nov 25, 2021 at 05:54:04PM +0100, Hans de Goede wrote:
Quoted 8 lines
Quoted 6 lines
From: 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.
Is there any drawback doing this unconditionally, if nothing is connected to the bus on the other side (including no pull-ups) ?
I actually never took a really close look at this patch, I just sorta inherited it from Daniel.
Now that I have taken a close look, I see that it is setting the exact same bits as which get set when enabling the VSIO regulator.
The idea here is that the I2C-passthrough only gets enabled when the VSIO regulator is turned on, because some sensors end up shorting the I2C pins to ground when the sensor is not powered.
Since we set these bits when powering up the VSIO regulator and since we do that before trying to talk to the sensor I don't think that we need this (hack) anymore.
Quoted 7 lines
Quoted 4 lines
I will give things a try without this change and if things still work I will drop this patch from the set.
Daniel, what do you think?
Humm, we're only using the VSIO regulator with the VCM though right?
Nope, there is a mapping from VSIO to dovdd for the ov8865 in the board_data; and I'm pretty sure I copied that from your earlier attempts at getting regulator lookups registered :)
And even if the VSIO regulator was only used by the VCM, then it would get turned off after probing the VCM, clearing the 2 bits which this commit sets. Which would break things if we did not re-enable it when the ov8865 needs it.
Quoted 3 lines
Which might not be on when the ov8865 tries to probe. I haven't tried without this patch to be honest; I set it because that was what Windows does when powering on the PMIC.
See above, I'm pretty sure we can do without this patch which means that the INT3472 code will no longer be poking at the PMIC directly itself, which is good :)
Anyways I'll give this a try sometime next week and then drop the patch.
Regards,
Hans
Quoted 25 lines
Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
Reviewed-by Andy Shevchenko <[email protected]>Signed-off-by Daniel Scally <[email protected]>--- .../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 ;
Re: [PATCH v6 07/15] platform/x86: int3472: Enable I2c daisy chain
Quoted 39 lines · Hans de Goede
Hi,
Quoted 36 lines · Daniel Scally
Hello
Quoted 33 lines · Hans de Goede
Hi,
Quoted 5 lines · Laurent Pinchart
Hi Hans,
Thank you for the patch.
On Thu, Nov 25, 2021 at 05:54:04PM +0100, Hans de Goede wrote:
Quoted 8 lines
Quoted 6 lines
From: 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.
Is there any drawback doing this unconditionally, if nothing is connected to the bus on the other side (including no pull-ups) ?
I actually never took a really close look at this patch, I just sorta inherited it from Daniel.
Now that I have taken a close look, I see that it is setting the exact same bits as which get set when enabling the VSIO regulator.
The idea here is that the I2C-passthrough only gets enabled when the VSIO regulator is turned on, because some sensors end up shorting the I2C pins to ground when the sensor is not powered.
Since we set these bits when powering up the VSIO regulator and since we do that before trying to talk to the sensor I don't think that we need this (hack) anymore.
I will give things a try without this change and if things still work I will drop this patch from the set.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Daniel, what do you think?
Humm, we're only using the VSIO regulator with the VCM though right?
Nope, there is a mapping from VSIO to dovdd for the ov8865 in the
board_data; and I'm pretty sure I copied that from your earlier attempts at getting regulator lookups registered :)
Oh yeah derp; I was looking at the supply names rather than the regulator names, my bad!
Quoted 11 lines
And even if the VSIO regulator was only used by the VCM, then it would get turned off after probing the VCM, clearing the 2 bits which this commit sets. Which would break things if we did not re-enable it when the ov8865 needs it.
Quoted 3 lines
Which might not be on when the ov8865 tries to probe. I haven't tried without this patch to be honest; I set it because that was what Windows does when powering on the PMIC.
See above, I'm pretty sure we can do without this patch which means that the INT3472 code will no longer be poking at the PMIC directly itself, which is good :)
Yeah, in that case I think you're right and this can be dropped.
Quoted 2 lines
Anyways I'll give this a try sometime next week and then drop the patch.
Sounds good
Quoted 32 lines
Regards,
Hans
Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
Reviewed-by Andy Shevchenko <[email protected]>Signed-off-by Daniel Scally <[email protected]>--- .../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 ;
Re: [PATCH v6 07/15] platform/x86: int3472: Enable I2c daisy chain
In reply to Hans de GoedeHi,
Quoted 57 lines · Hans de Goede
Hi,
Quoted 33 lines · Daniel Scally
Hello
Quoted 30 lines · Hans de Goede
Hi,
Quoted 5 lines · Laurent Pinchart
Hi Hans,
Thank you for the patch.
On Thu, Nov 25, 2021 at 05:54:04PM +0100, Hans de Goede wrote:
Quoted 8 lines
Quoted 6 lines
From: 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.
Is there any drawback doing this unconditionally, if nothing is connected to the bus on the other side (including no pull-ups) ?
I actually never took a really close look at this patch, I just sorta inherited it from Daniel.
Now that I have taken a close look, I see that it is setting the exact same bits as which get set when enabling the VSIO regulator.
The idea here is that the I2C-passthrough only gets enabled when the VSIO regulator is turned on, because some sensors end up shorting the I2C pins to ground when the sensor is not powered.
Since we set these bits when powering up the VSIO regulator and since we do that before trying to talk to the sensor I don't think that we need this (hack) anymore.
Quoted 7 lines
Quoted 4 lines
I will give things a try without this change and if things still work I will drop this patch from the set.
Daniel, what do you think?
Humm, we're only using the VSIO regulator with the VCM though right?
Nope, there is a mapping from VSIO to dovdd for the ov8865 in the
board_data; and I'm pretty sure I copied that from your earlier attempts at getting regulator lookups registered :)And even if the VSIO regulator was only used by the VCM, then it would get turned off after probing the VCM, clearing the 2 bits which this commit sets. Which would break things if we did not re-enable it when the ov8865 needs it.
Quoted 3 lines
Which might not be on when the ov8865 tries to probe. I haven't tried without this patch to be honest; I set it because that was what Windows does when powering on the PMIC.
Quoted 6 lines
See above, I'm pretty sure we can do without this patch which means that the INT3472 code will no longer be poking at the PMIC directly itself, which is good :)
Anyways I'll give this a try sometime next week and then drop the patch.
I can confirm that this patch indeed is no longer necessary with the current regulator code already taking care of this.
I will post version 7 of this patch-set soon, with this patch dropped.
Regards,
Hans
Quoted 25 lines
Quoted 25 lines
Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
Reviewed-by Andy Shevchenko <[email protected]>Signed-off-by Daniel Scally <[email protected]>--- .../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 ;
PATCH v6 8/15 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.33.1
PATCH v6 9/15 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.33.1
PATCH v6 10/15 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 v5:
- Add TPS68470_WIN_MFD_CELL_COUNT define
Changes in v4:
- Update the comment about the cell ordering
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 | 35 +++++++++++++++---- 1 file changed, 28 insertions(+), 7 deletions(-)
drivers/platform/x86/intel/int3472/tps68470.c +28 -7
@@ -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"
@@ -12,17 +13,13 @@#define DESIGNED_FOR_CHROMEOS 1#define DESIGNED_FOR_WINDOWS 2 +#define TPS68470_WIN_MFD_CELL_COUNT 3 +static const struct mfd_cell tps68470_cros[] = { { .name ="tps68470-gpio" }, { .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 +102,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 +130,26 @@ 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 : + cells =kcalloc (TPS68470_WIN_MFD_CELL_COUNT ,sizeof (*cells),GFP_KERNEL ); +if (!cells) +return -ENOMEM ; + +/* +* The order of the cells matters here! The clk must be first +* because the regulator depends on it. The gpios must be last, +* acpi_gpiochip_add() calls acpi_dev_clear_dependencies() and +* the clk + regulators must be ready when this happens. +*/ + cells[0 ].name ="tps68470-clk" ; + cells[0 ].platform_data = &clk_pdata; + cells[0 ].pdata_size =sizeof (clk_pdata); + cells[1 ].name ="tps68470-regulator" ; + cells[2 ].name ="tps68470-gpio" ; + ret =devm_mfd_add_devices (&client->dev,PLATFORM_DEVID_NONE , - tps68470_win,ARRAY_SIZE (tps68470_win), + cells,TPS68470_WIN_MFD_CELL_COUNT ,NULL ,0 ,NULL ); +kfree (cells);break ;case DESIGNED_FOR_CHROMEOS : ret = devm_mfd_add_devices(&client->dev, PLATFORM_DEVID_NONE,
Signature · 1 line
2.33.1
PATCH v6 11/15 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 IO lines which may be connected to the tps68470 GPIOs.
---
Changes in v6:
- Also list the VCM module as VSIO regulator consumer
- Add constraints for VIO, it MUST have the same voltage configured as VSIO and mark it as always-on (it is always on there is no on/off control for it in the PMIC, as the PMIC uses it internally)
- Fix logic error in int3472_tps68470_get_board_data() (thank you Andy)
Changes in v5:
- Also pass regulator_init_data for the regulator used for the VCM (Voice Coil Motor) used for the focus of the back-camera lens
--- 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 | 145 ++++++++++++++++++ 4 files changed, 199 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
@@ -2,13 +2,16 @@/* Author: Dan Scally <[email protected]> */ #include <linux/i2c.h> +#include <linux/kernel.h> #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 <linux/string.h> #include "common.h" +#include "tps68470.h" #define DESIGNED_FOR_CHROMEOS 1#define DESIGNED_FOR_WINDOWS 2
@@ -102,6 +105,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;
@@ -130,6 +134,10 @@ 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) +return dev_err_probe (&client->dev, -ENODEV ,"No board-data found for this model\n" ); + cells =kcalloc (TPS68470_WIN_MFD_CELL_COUNT ,sizeof (*cells),GFP_KERNEL );if (!cells)return -ENOMEM ;
@@ -144,12 +152,20 @@ 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 ); 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,TPS68470_WIN_MFD_CELL_COUNT ,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,
@@ -164,6 +180,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 }, { }
@@ -176,6 +203,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 +145 -0
145 lines not on this page · raw message
Signature · 1 line
2.33.1
PATCH v6 12/15 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
@@ -177,6 +177,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; }
@@ -210,3 +215,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.33.1
PATCH v6 13/15 media: ipu3-cio2: Defer probing until the PMIC is fully setup
In reply to Hans de GoedeOn devices where things are not fully describe in devicetree (1) and where the code thus falls back to calling cio2_bridge_init(), the i2c-clients for any VCMs also need to be instantiated manually.
The VCM can be probed by its driver as soon as the code instantiates the i2c-client and this probing must not happen before the PMIC is fully setup.
Make cio2_bridge_init() return -EPROBE_DEFER when the PMIC is not fully-setup, deferring the probe of the ipu3-cio2 driver.
This is a preparation patch for adding VCM enumeration support to the ipu3-cio2-bridge code.
1) Through embedding of devicetree info in the ACPI tables
--- drivers/media/pci/intel/ipu3/cio2-bridge.c | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+)
drivers/media/pci/intel/ipu3/cio2-bridge.c +37 -0
@@ -308,6 +308,40 @@ static int cio2_bridge_connect_sensors(struct cio2_bridge *bridge,return ret; } +/* +* The VCM cannot be probed until the PMIC is completely setup. We cannot rely +* on -EPROBE_DEFER for this, since the consumer<->supplier relations between +* the VCM and regulators/clks are not described in ACPI, instead they are +* passed as board-data to the PMIC drivers. Since -PROBE_DEFER does not work +* for the clks/regulators the VCM i2c-clients must not be instantiated until +* the PMIC is fully setup. +* +* The sensor/VCM ACPI device has an ACPI _DEP on the PMIC, check this using the +* acpi_dev_ready_for_enumeration() helper, like the i2c-core-acpi code does +* for the sensors. +*/ +int cio2_bridge_sensors_are_ready (void ) +{ +struct acpi_device *adev; +bool ready = true; +unsigned int i; + +for (i =0 ; i <ARRAY_SIZE (cio2_supported_sensors); i++) { +const struct cio2_sensor_config *cfg = + &cio2_supported_sensors[i]; + +for_each_acpi_dev_match (adev, cfg->hid,NULL ,-1 ) { +if (!adev->status.enabled) +continue ; + +if (!acpi_dev_ready_for_enumeration (adev)) + ready = false; + } + } + +return ready; +} +int cio2_bridge_init (struct pci_dev *cio2) {struct device *dev = &cio2->dev;
@@ -316,6 +350,9 @@ int cio2_bridge_init(struct pci_dev *cio2)unsigned int i;int ret; +if (!cio2_bridge_sensors_are_ready ()) +return -EPROBE_DEFER ; + bridge =kzalloc (sizeof (*bridge),GFP_KERNEL );if (!bridge)return -ENOMEM ;
Signature · 1 line
2.33.1
kernel test robot
build botRe: [PATCH v6 13/15] media: ipu3-cio2: Defer probing until the PMIC is fully setup
I love your patch! Perhaps something to improve:
Hi Hans,
I love your patch! Perhaps something to improve:
[auto build test WARNING on media-tree/master]
[also build test WARNING on wsa/i2c/for-next broonie-regulator/for-next linus/master v5.16-rc2 next-20211125] [cannot apply to clk/clk-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Hans-de-Goede/Add-support-for-X86-ACPI-camera-sensor-PMIC-setup-with-clk-and-regulator-platform-data/20211126-005917 base: git://linuxtv.org/media_tree.git master config: i386-allyesconfig (https://download.01.org/0day-ci/archive/20211126/202111260530.KpKC5Rrw-lkp(a)intel.com/config) compiler: gcc-9 (Debian 9.3.0-22) 9.3.0 reproduce (this is a W=1 build): # https://github.com/0day-ci/linux/commit/e5cd2c79411cf24a2cabc5c7d2a222c1a3557460 git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Hans-de-Goede/Add-support-for-X86-ACPI-camera-sensor-PMIC-setup-with-clk-and-regulator-platform-data/20211126-005917 git checkout e5cd2c79411cf24a2cabc5c7d2a222c1a3557460 # save the config file to linux build tree make W=1 ARCH=i386
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> drivers/media/pci/intel/ipu3/cio2-bridge.c:321:5: warning: no previous prototype for 'cio2_bridge_sensors_are_ready' [-Wmissing-prototypes]
321 | int cio2_bridge_sensors_are_ready(void)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
vim +/cio2_bridge_sensors_are_ready +321 drivers/media/pci/intel/ipu3/cio2-bridge.c
308
309 /*
310 * The VCM cannot be probed until the PMIC is completely setup. We cannot rely
311 * on -EPROBE_DEFER for this, since the consumer<->supplier relations between
312 * the VCM and regulators/clks are not described in ACPI, instead they are
313 * passed as board-data to the PMIC drivers. Since -PROBE_DEFER does not work
314 * for the clks/regulators the VCM i2c-clients must not be instantiated until
315 * the PMIC is fully setup.
316 *
317 * The sensor/VCM ACPI device has an ACPI _DEP on the PMIC, check this using the
318 * acpi_dev_ready_for_enumeration() helper, like the i2c-core-acpi code does
319 * for the sensors.
320 */
> 321 int cio2_bridge_sensors_are_ready(void)
322 {
323 struct acpi_device *adev;
324 bool ready = true;
325 unsigned int i;
326
327 for (i = 0; i < ARRAY_SIZE(cio2_supported_sensors); i++) {
328 const struct cio2_sensor_config *cfg =
329 &cio2_supported_sensors[i];
330
331 for_each_acpi_dev_match(adev, cfg->hid, NULL, -1) {
332 if (!adev->status.enabled)
333 continue;
334
335 if (!acpi_dev_ready_for_enumeration(adev))
336 ready = false;
337 }
338 }
339
340 return ready;
341 }
342
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Re: [PATCH v6 13/15] media: ipu3-cio2: Defer probing until the PMIC is fully setup
Hi,
Quoted 23 lines · kernel test robot
Hi Hans,
I love your patch! Perhaps something to improve:
[auto build test WARNING on media-tree/master]
[also build test WARNING on wsa/i2c/for-next broonie-regulator/for-next linus/master v5.16-rc2 next-20211125] [cannot apply to clk/clk-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]url: https://github.com/0day-ci/linux/commits/Hans-de-Goede/Add-support-for-X86-ACPI-camera-sensor-PMIC-setup-with-clk-and-regulator-platform-data/20211126-005917 base: git://linuxtv.org/media_tree.git master config: i386-allyesconfig (https://download.01.org/0day-ci/archive/20211126/202111260530.KpKC5Rrw-lkp(a)intel.com/config) compiler: gcc-9 (Debian 9.3.0-22) 9.3.0 reproduce (this is a W=1 build): # https://github.com/0day-ci/linux/commit/e5cd2c79411cf24a2cabc5c7d2a222c1a3557460 git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Hans-de-Goede/Add-support-for-X86-ACPI-camera-sensor-PMIC-setup-with-clk-and-regulator-platform-data/20211126-005917 git checkout e5cd2c79411cf24a2cabc5c7d2a222c1a3557460 # save the config file to linux build tree make W=1 ARCH=i386
Quoted 8 lines
If you fix the issue, kindly add following tag as appropriate
Reported-by kernel test robot <[email protected]>All warnings (new ones prefixed by >>):
Quoted 1 line
Quoted 1 line
drivers/media/pci/intel/ipu3/cio2-bridge.c:321:5: warning: no previous prototype for 'cio2_bridge_sensors_are_ready' [-Wmissing-prototypes]321 | int
cio2_bridge_sensors_are_ready(void)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Right this needs to be static I will fix this for v7 of the series.
Regards,
Hans
Quoted 44 lines
vim +/cio2_bridge_sensors_are_ready +321
drivers/media/pci/intel/ipu3/cio2-bridge.c308
309 /*
310 * The VCM cannot be probed until the PMIC is completely setup. We cannot rely
311 * on -EPROBE_DEFER for this, since the consumer<->supplier relations between
312 * the VCM and regulators/clks are not described in ACPI, instead they are
313 * passed as board-data to the PMIC drivers. Since -PROBE_DEFER does not work
314 * for the clks/regulators the VCM i2c-clients must not be instantiated until
315 * the PMIC is fully setup.
316 *
317 * The sensor/VCM ACPI device has an ACPI_DEPon the PMIC, check this using the
318 *acpi_dev_ready_for_enumeration()helper, like the i2c-core-acpi code does
319 * for the sensors.
320 */Quoted 1 line
321 int
cio2_bridge_sensors_are_ready(void)322 { 323 struct acpi_device *adev; 324 bool ready = true; 325 unsigned int i; 326 327 for (i = 0; i < ARRAY_SIZE(cio2_supported_sensors); i++) { 328 const struct cio2_sensor_config *cfg = 329 &cio2_supported_sensors[i]; 330 331 for_each_acpi_dev_match(adev, cfg->hid, NULL, -1) { 332 if (!adev->status.enabled) 333 continue; 334 335 if (!acpi_dev_ready_for_enumeration(adev)) 336 ready = false; 337 } 338 } 339 340 return ready; 341 } 342---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
PATCH v6 14/15 media: ipu3-cio2: Call cio2_bridge_init() before anything else
In reply to Hans de GoedeSince cio2_bridge_init() may now return -EPROBE_DEFER it is best to call it before anything else.
--- drivers/media/pci/intel/ipu3/ipu3-cio2-main.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/media/pci/intel/ipu3/ipu3-cio2-main.c +5 -5
@@ -1713,11 +1713,6 @@ static int cio2_pci_probe(struct pci_dev *pci_dev,struct cio2_device *cio2;int r; - cio2 =devm_kzalloc (dev,sizeof (*cio2),GFP_KERNEL ); -if (!cio2) -return -ENOMEM ; - cio2->pci_dev = pci_dev; -/* * On some platforms no connections to sensors are defined in firmware, * if the device has no endpoints then we can try to build those as
@@ -1735,6 +1730,11 @@ static int cio2_pci_probe(struct pci_dev *pci_dev,return r; } + cio2 =devm_kzalloc (dev,sizeof (*cio2),GFP_KERNEL ); +if (!cio2) +return -ENOMEM ; + cio2->pci_dev = pci_dev; + r =pcim_enable_device (pci_dev);if (r) {dev_err (dev,"failed to enable device (%d)\n" , r);
Signature · 1 line
2.33.1
PATCH v6 15/15 media: ipu3-cio2: Add support for instantiating i2c-clients for VCMs
In reply to Hans de GoedeSome sensors come with a variable-focus lens where the lens focus is controller by a VCM (Voice Coil Motor). If there is a VCM for the lens-focus, and if so which one, is described on the vcm_type field of the ACPI SSDB table.
These VCMs are a second I2C device listed as an extra I2cSerialBusV2 resource in the same ACPI device as the sensor. The i2c-core-acpi.c code only instantiates an i2c-client for the first I2cSerialBusV2 resource.
Add support for instantiating an i2c-client for the VCM with the type of the i2c-client set based on the SSDB vcm_type field.
--- drivers/media/pci/intel/ipu3/cio2-bridge.c | 55 ++++++++++++++++++++++ drivers/media/pci/intel/ipu3/cio2-bridge.h | 16 ++++++- 2 files changed, 69 insertions(+), 2 deletions(-)
drivers/media/pci/intel/ipu3/cio2-bridge.c +55 -0
@@ -3,6 +3,7 @@#include <linux/acpi.h> #include <linux/device.h> +#include <linux/i2c.h> #include <linux/pci.h> #include <linux/property.h> #include <media/v4l2-fwnode.h>
@@ -38,6 +39,18 @@ static const struct cio2_property_names prop_names = { .link_frequencies = "link-frequencies", }; +static const char *const cio2_vcm_types[] = { +"ad5823" , +"dw9714" , +"ad5816" , +"dw9719" , +"dw9718" , +"dw9806b" , +"wv517s" , +"lc898122xa" , +"lc898212axb" , +}; +static int cio2_bridge_read_acpi_buffer (struct acpi_device *adev,char *id,void *data,u32 size) {
@@ -134,6 +147,12 @@ static void cio2_bridge_create_fwnode_properties( sensor->dev_properties[2 ] =PROPERTY_ENTRY_U32 ( sensor->prop_names.orientation, orientation); +if (sensor->ssdb.vcmtype) { + sensor->vcm_ref[0 ] = +SOFTWARE_NODE_REFERENCE (&sensor->swnodes[SWNODE_VCM ]); + sensor->dev_properties[3 ] = +PROPERTY_ENTRY_REF_ARRAY ("lens-focus" , sensor->vcm_ref); + } sensor->ep_properties[0] = PROPERTY_ENTRY_U32( sensor->prop_names.bus_type,
@@ -195,6 +214,33 @@ static void cio2_bridge_create_connection_swnodes(struct cio2_bridge *bridge, sensor->node_names.endpoint, &nodes[SWNODE_CIO2_PORT ], sensor->cio2_properties); +if (sensor->ssdb.vcmtype) + nodes[SWNODE_VCM ] = +NODE_VCM (cio2_vcm_types[sensor->ssdb.vcmtype -1 ]); +} + +static void cio2_bridge_instantiate_vcm_i2c_client (struct cio2_sensor *sensor) +{ +struct i2c_board_info board_info = { }; +char name[16 ]; + +if (!sensor->ssdb.vcmtype) +return ; + +snprintf (name,sizeof (name),"%s-VCM" ,acpi_dev_name (sensor->adev)); + board_info.dev_name = name; +strscpy (board_info.type, cio2_vcm_types[sensor->ssdb.vcmtype -1 ], +ARRAY_SIZE (board_info.type)); + board_info.swnode = &sensor->swnodes[SWNODE_VCM ]; + + sensor->vcm_i2c_client = +i2c_acpi_new_device_by_fwnode (acpi_fwnode_handle (sensor->adev), +1 , &board_info); +if (IS_ERR (sensor->vcm_i2c_client)) { +dev_warn (&sensor->adev->dev,"Error instantiation VCM i2c-client: %ld\n" , +PTR_ERR (sensor->vcm_i2c_client)); + sensor->vcm_i2c_client =NULL ; + } }static void cio2_bridge_unregister_sensors (struct cio2_bridge *bridge)
@@ -207,6 +253,7 @@ static void cio2_bridge_unregister_sensors(struct cio2_bridge *bridge)software_node_unregister_nodes (sensor->swnodes);ACPI_FREE (sensor->pld);acpi_dev_put (sensor->adev); +i2c_unregister_device (sensor->vcm_i2c_client); } }
@@ -239,6 +286,12 @@ static int cio2_bridge_connect_sensor(const struct cio2_sensor_config *cfg,if (ret) goto err_put_adev; +if (sensor->ssdb.vcmtype >ARRAY_SIZE (cio2_vcm_types)) { +dev_warn (&adev->dev,"Unknown VCM type %d\n" , + sensor->ssdb.vcmtype); + sensor->ssdb.vcmtype =0 ; + } + status =acpi_get_physical_device_location (adev->handle, &sensor->pld);if (ACPI_FAILURE (status)) { ret = -ENODEV ;
@@ -269,6 +322,8 @@ static int cio2_bridge_connect_sensor(const struct cio2_sensor_config *cfg, sensor->adev =acpi_dev_get (adev); adev->fwnode.secondary = fwnode; +cio2_bridge_instantiate_vcm_i2c_client (sensor); +dev_info (&cio2->dev,"Found supported sensor %s\n" ,acpi_dev_name (adev));
drivers/media/pci/intel/ipu3/cio2-bridge.h +14 -2
@@ -8,6 +8,8 @@#include "ipu3-cio2.h" +struct i2c_client ; +#define CIO2_HID "INT343E"#define CIO2_MAX_LANES 4#define MAX_NUM_LINK_FREQS 3
@@ -42,12 +44,19 @@ .properties = _PROPS, \ } +#define NODE_VCM (_TYPE) \ + (const struct software_node) { \ + .name = _TYPE, \ + } +enum cio2_sensor_swnodes {SWNODE_SENSOR_HID ,SWNODE_SENSOR_PORT ,SWNODE_SENSOR_ENDPOINT ,SWNODE_CIO2_PORT ,SWNODE_CIO2_ENDPOINT , +/* Must be last because it is optional / maybe empty */ +SWNODE_VCM ,SWNODE_COUNT };
@@ -106,8 +115,10 @@ struct cio2_sensor_config {struct cio2_sensor {char name[ACPI_ID_LEN ];struct acpi_device *adev; +struct i2c_client *vcm_i2c_client; -struct software_node swnodes[6 ]; +/* SWNODE_COUNT + 1 for terminating empty node */ +struct software_node swnodes[SWNODE_COUNT +1 ];struct cio2_node_names node_names;struct cio2_sensor_ssdb ssdb;
@@ -115,10 +126,11 @@ struct cio2_sensor {struct cio2_property_names prop_names;struct property_entry ep_properties[5 ]; -struct property_entry dev_properties[4 ]; +struct property_entry dev_properties[5 ];struct property_entry cio2_properties[3 ];struct software_node_ref_args local_ref[1 ];struct software_node_ref_args remote_ref[1 ]; +struct software_node_ref_args vcm_ref[1 ]; };struct cio2_bridge {
Signature · 1 line
2.33.1