Skip to contentSkip to conversation

Add multiple-consumer support to int3472-tps68470 driver

PATCH In review Daniel Scally 4 participants 13 messages Sep 21, 2022 – Sep 27, 2022

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

v3 cover Add multiple-consumer support to int3472-tps68470 driver

Hello all

At the moment there are a few places in the int3472-tps68470 driver that are limited to just working with a single consuming device dependent on the PMIC. There are systems where multiple camera sensors share a single TPS68470, so we need to extend the driver to support them. This requires a couple of tweaks to the ACPI functions to fetch dependent devices, which also assumes that only a single dependent will be found.

The v2 for this series was some time ago...it's kept falling to the back of my to-do list so I've only just gotten round to it; sorry about that. v2 here:

https://lore.kernel.org/linux-acpi/[email protected]/

Thanks
Dan

Daniel Scally (5):
ACPI: scan: Add acpi_dev_get_next_consumer_dev()
ACPI: bus: Add iterator for dependent devices platform/x86: int3472: Support multiple clock consumers platform/x86: int3472: Support multiple gpio lookups in board data platform/x86: int3472: Add board data for Surface Go2 IR camera

 drivers/acpi/scan.c                           | 40 +++++++---
 drivers/clk/clk-tps68470.c                    | 13 +++-
 drivers/platform/x86/intel/int3472/common.c   |  2 +-
 drivers/platform/x86/intel/int3472/tps68470.c | 76 ++++++++++++++++---
 drivers/platform/x86/intel/int3472/tps68470.h |  3 +-
 .../x86/intel/int3472/tps68470_board_data.c   | 54 ++++++++++++-
 include/acpi/acpi_bus.h                       | 15 +++-
 include/linux/platform_data/tps68470.h        |  7 +-
 8 files changed, 177 insertions(+), 33 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH v3 1/5 ACPI: scan: Add acpi_dev_get_next_consumer_dev()

In commit b83e2b306736 ("ACPI: scan: Add function to fetch dependent of ACPI device") we added a means of fetching the first device to declare itself dependent on another ACPI device in the _DEP method. One assumption in that patch was that there would only be a single consuming device, but this has not held.

Replace that function with a new function that fetches the next consumer of a supplier device. Where no "previous" consumer is passed in, it behaves identically to the original function.

---
Changes since v2:

- Separated adev_p and adev instead of relying on a cast (Rafael)
- Used a separate if block to check for adev == start in acpi_dev_get_next_consumer_dev() (Rafael)

 drivers/acpi/scan.c                         | 40 +++++++++++++++------
 drivers/platform/x86/intel/int3472/common.c |  2 +-
 include/acpi/acpi_bus.h                     |  4 ++-
 3 files changed, 34 insertions(+), 12 deletions(-)
drivers/acpi/scan.c +30 -10
index 42cec8120f18..12ac2f3ae5d2 100644
@@ -2235,9 +2235,22 @@ static int acpi_bus_attach(struct acpi_device *device, void *first_pass)
 	return 0;
 }
 
-static int acpi_dev_get_first_consumer_dev_cb(struct acpi_dep_data *dep, void *data)
+static int acpi_dev_get_next_consumer_dev_cb(struct acpi_dep_data *dep, void *data)
 {
-	struct acpi_device *adev;
+	struct acpi_device **adev_p = data;
+	struct acpi_device *adev = *adev_p;
+
+	/*
+	 * If we're passed a 'previous' consumer device then we need to skip
+	 * any consumers until we meet the previous one, and then NULL @data
+	 * so the next one can be returned.
+	 */
+	if (adev) {
+		if (dep->consumer == adev->handle)
+			*adev_p = NULL;
+
+		return 0;
+	}
 
 	adev = acpi_bus_get_acpi_device(dep->consumer);
 	if (adev) {
@@ -2368,25 +2381,32 @@ bool acpi_dev_ready_for_enumeration(const struct acpi_device *device)
 EXPORT_SYMBOL_GPL(acpi_dev_ready_for_enumeration);
 
 /**
- * acpi_dev_get_first_consumer_dev - Return ACPI device dependent on @supplier
+ * acpi_dev_get_next_consumer_dev - Return the next adev dependent on @supplier
  * @supplier: Pointer to the dependee device
+ * @start: Pointer to the current dependent device
  *
- * Returns the first &struct acpi_device which declares itself dependent on
+ * Returns the next &struct acpi_device which declares itself dependent on
  * @supplier via the _DEP buffer, parsed from the acpi_dep_list.
  *
- * The caller is responsible for putting the reference to adev when it is no
- * longer needed.
+ * If the returned adev is not passed as @start to this function, the caller is
+ * responsible for putting the reference to adev when it is no longer needed.
  */
-struct acpi_device *acpi_dev_get_first_consumer_dev(struct acpi_device *supplier)
+struct acpi_device *acpi_dev_get_next_consumer_dev(struct acpi_device *supplier,
+						   struct acpi_device *start)
 {
-	struct acpi_device *adev = NULL;
+	struct acpi_device *adev = start;
 
 	acpi_walk_dep_device_list(supplier->handle,
-				  acpi_dev_get_first_consumer_dev_cb, &adev);
+				  acpi_dev_get_next_consumer_dev_cb, &adev);
+
+	acpi_dev_put(start);
+
+	if (adev == start)
+		return NULL;
 
 	return adev;
 }
-EXPORT_SYMBOL_GPL(acpi_dev_get_first_consumer_dev);
+EXPORT_SYMBOL_GPL(acpi_dev_get_next_consumer_dev);
 
 /**
  * acpi_bus_scan - Add ACPI device node objects in a given namespace scope.
drivers/platform/x86/intel/int3472/common.c +1 -1
index 77cf058e4168..9db2bb0bbba4 100644
@@ -62,7 +62,7 @@ int skl_int3472_get_sensor_adev_and_name(struct device *dev,
 	struct acpi_device *sensor;
 	int ret = 0;
 
-	sensor = acpi_dev_get_first_consumer_dev(adev);
+	sensor = acpi_dev_get_next_consumer_dev(adev, NULL);
 	if (!sensor) {
 		dev_err(dev, "INT3472 seems to have no dependents.\n");
 		return -ENODEV;
include/acpi/acpi_bus.h +3 -1
index e7d27373ff71..bf0886dca6eb 100644
@@ -736,7 +736,9 @@ bool acpi_dev_hid_uid_match(struct acpi_device *adev, const char *hid2, const ch
 
 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_consumer_dev(struct acpi_device *supplier,
+						   struct acpi_device *start);
+
 struct acpi_device *
 acpi_dev_get_next_match_dev(struct acpi_device *adev, const char *hid, const char *uid, s64 hrv);
 struct acpi_device *
Signature · 1 line
2.25.1
#2 lore raw

PATCH v3 2/5 ACPI: bus: Add iterator for dependent devices

In reply to Daniel Scally

Add a helper macro to iterate over ACPI devices that are flagged as consumers of an initial supplier ACPI device.

---
Changes since v2:

- None

 include/acpi/acpi_bus.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
include/acpi/acpi_bus.h +11 -0
index bf0886dca6eb..abce6f0219ea 100644
@@ -739,6 +739,17 @@ bool acpi_dev_ready_for_enumeration(const struct acpi_device *device);
 struct acpi_device *acpi_dev_get_next_consumer_dev(struct acpi_device *supplier,
 						   struct acpi_device *start);
 
+/**
+ * for_each_acpi_consumer_dev - iterate over the consumer ACPI devices for a
+ *				given supplier
+ * @supplier: Pointer to the supplier's ACPI device
+ * @consumer: Pointer to &struct acpi_device to hold the consumer, initially NULL
+ */
+#define for_each_acpi_consumer_dev(supplier, consumer)			\
+	for (consumer = acpi_dev_get_next_consumer_dev(supplier, NULL);	\
+	     consumer;							\
+	     consumer = acpi_dev_get_next_consumer_dev(supplier, consumer))
+
 struct acpi_device *
 acpi_dev_get_next_match_dev(struct acpi_device *adev, const char *hid, const char *uid, s64 hrv);
 struct acpi_device *
Signature · 1 line
2.25.1
#3 lore raw

PATCH v3 3/5 platform/x86: int3472: Support multiple clock consumers

In reply to Daniel Scally

At present, the tps68470.c only supports a single clock consumer when passing platform data to the clock driver. In some devices multiple sensors depend on the clock provided by a single TPS68470 and so all need to be able to acquire the clock. Support passing multiple consumers as platform data.

---
Changes since v2:

- None

 drivers/clk/clk-tps68470.c                    | 13 ++--
 drivers/platform/x86/intel/int3472/tps68470.c | 59 ++++++++++++++++---
 include/linux/platform_data/tps68470.h        |  7 ++-
 3 files changed, 67 insertions(+), 12 deletions(-)
drivers/clk/clk-tps68470.c +9 -4
index e5fbefd6ac2d..38f44b5b9b1b 100644
@@ -200,7 +200,9 @@ static int tps68470_clk_probe(struct platform_device *pdev)
 		.flags = CLK_SET_RATE_GATE,
 	};
 	struct tps68470_clkdata *tps68470_clkdata;
+	struct tps68470_clk_consumer *consumer;
 	int ret;
+	int i;
 
 	tps68470_clkdata = devm_kzalloc(&pdev->dev, sizeof(*tps68470_clkdata),
 					GFP_KERNEL);
@@ -223,10 +225,13 @@ static int tps68470_clk_probe(struct platform_device *pdev)
 		return ret;
 
 	if (pdata) {
-		ret = devm_clk_hw_register_clkdev(&pdev->dev,
-						  &tps68470_clkdata->clkout_hw,
-						  pdata->consumer_con_id,
-						  pdata->consumer_dev_name);
+		for (i = 0; i < pdata->n_consumers; i++) {
+			consumer = &pdata->consumers[i];
+			ret = devm_clk_hw_register_clkdev(&pdev->dev,
+							  &tps68470_clkdata->clkout_hw,
+							  consumer->consumer_con_id,
+							  consumer->consumer_dev_name);
+		}
 	}
 
 	return ret;
drivers/platform/x86/intel/int3472/tps68470.c +52 -7

86 lines not on this page · raw message

include/linux/platform_data/tps68470.h +6 -1
index 126d082c3f2e..e605a2cab07f 100644
@@ -27,9 +27,14 @@ struct tps68470_regulator_platform_data {
 	const struct regulator_init_data *reg_init_data[TPS68470_NUM_REGULATORS];
 };
 
-struct tps68470_clk_platform_data {
+struct tps68470_clk_consumer {
 	const char *consumer_dev_name;
 	const char *consumer_con_id;
 };
 
+struct tps68470_clk_platform_data {
+	unsigned int n_consumers;
+	struct tps68470_clk_consumer consumers[];
+};
+
 #endif
Signature · 1 line
2.25.1
Reviewed-by Stephen Boyd Acked-by Stephen Boyd on v3 3/5
#4 lore raw

Re: [PATCH v3 3/5] platform/x86: int3472: Support multiple clock consumers

Hi,

Quoted 8 lines · Daniel Scally

At present, the tps68470.c only supports a single clock consumer when passing platform data to the clock driver. In some devices multiple sensors depend on the clock provided by a single TPS68470 and so all need to be able to acquire the clock. Support passing multiple consumers as platform data.

Note this one already has a review + ack from Stephen Boyd for merging this through the pdx86 tree (from v1 of the series):

https://lore.kernel.org/platform-driver-x86/[email protected]/

Regards,

Hans

Quoted 155 lines

---
Changes since v2:

- None

 drivers/clk/clk-tps68470.c                    | 13 ++--
 drivers/platform/x86/intel/int3472/tps68470.c | 59 ++++++++++++++++---
 include/linux/platform_data/tps68470.h        |  7 ++-
 3 files changed, 67 insertions(+), 12 deletions(-)
drivers/clk/clk-tps68470.c +9 -4
index e5fbefd6ac2d..38f44b5b9b1b 100644
@@ -200,7 +200,9 @@ static int tps68470_clk_probe(struct platform_device *pdev)
 		.flags = CLK_SET_RATE_GATE,
 	};
 	struct tps68470_clkdata *tps68470_clkdata;
+	struct tps68470_clk_consumer *consumer;
 	int ret;
+	int i;
 
 	tps68470_clkdata = devm_kzalloc(&pdev->dev, sizeof(*tps68470_clkdata),
 					GFP_KERNEL);
@@ -223,10 +225,13 @@ static int tps68470_clk_probe(struct platform_device *pdev)
 		return ret;
 
 	if (pdata) {
-		ret = devm_clk_hw_register_clkdev(&pdev->dev,
-						  &tps68470_clkdata->clkout_hw,
-						  pdata->consumer_con_id,
-						  pdata->consumer_dev_name);
+		for (i = 0; i < pdata->n_consumers; i++) {
+			consumer = &pdata->consumers[i];
+			ret = devm_clk_hw_register_clkdev(&pdev->dev,
+							  &tps68470_clkdata->clkout_hw,
+							  consumer->consumer_con_id,
+							  consumer->consumer_dev_name);
+		}
 	}
 
 	return ret;
drivers/platform/x86/intel/int3472/tps68470.c +52 -7
index 22f61b47f9e5..8a684030933d 100644
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
 /* Author: Dan Scally <[email protected]> */
 
+#include <linux/acpi.h>
 #include <linux/i2c.h>
 #include <linux/kernel.h>
 #include <linux/mfd/core.h>
@@ -95,20 +96,64 @@ static int skl_int3472_tps68470_calc_type(struct acpi_device *adev)
 	return DESIGNED_FOR_WINDOWS;
 }
 
+/*
+ * Return the size of the flexible array member, because we'll need that later
+ * on to pass .pdata_size to cells.
+ */
+static int
+skl_int3472_fill_clk_pdata(struct device *dev, struct tps68470_clk_platform_data **clk_pdata)
+{
+	struct acpi_device *adev = ACPI_COMPANION(dev);
+	struct acpi_device *consumer;
+	unsigned int n_consumers = 0;
+	const char *sensor_name;
+	unsigned int i = 0;
+
+	for_each_acpi_consumer_dev(adev, consumer)
+		n_consumers++;
+
+	if (!n_consumers) {
+		dev_err(dev, "INT3472 seems to have no dependents\n");
+		return -ENODEV;
+	}
+
+	*clk_pdata = devm_kzalloc(dev, struct_size(*clk_pdata, consumers, n_consumers),
+				  GFP_KERNEL);
+	if (!*clk_pdata)
+		return -ENOMEM;
+
+	(*clk_pdata)->n_consumers = n_consumers;
+	i = 0;
+
+	for_each_acpi_consumer_dev(adev, consumer) {
+		sensor_name = devm_kasprintf(dev, GFP_KERNEL, I2C_DEV_NAME_FORMAT,
+					     acpi_dev_name(consumer));
+		if (!sensor_name)
+			return -ENOMEM;
+
+		(*clk_pdata)->consumers[i].consumer_dev_name = sensor_name;
+		i++;
+	}
+
+	acpi_dev_put(consumer);
+
+	return n_consumers;
+}
+
 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 tps68470_clk_platform_data *clk_pdata;
 	struct mfd_cell *cells;
 	struct regmap *regmap;
+	int n_consumers;
 	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;
+	n_consumers = skl_int3472_fill_clk_pdata(&client->dev, &clk_pdata);
+	if (n_consumers < 0)
+		return n_consumers;
 
 	regmap = devm_regmap_init_i2c(client, &tps68470_regmap_config);
 	if (IS_ERR(regmap)) {
@@ -142,8 +187,8 @@ static int skl_int3472_tps68470_probe(struct i2c_client *client)
 		 * 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[0].platform_data = clk_pdata;
+		cells[0].pdata_size = struct_size(clk_pdata, consumers, n_consumers);
 		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);
include/linux/platform_data/tps68470.h +6 -1
index 126d082c3f2e..e605a2cab07f 100644
@@ -27,9 +27,14 @@ struct tps68470_regulator_platform_data {
 	const struct regulator_init_data *reg_init_data[TPS68470_NUM_REGULATORS];
 };
 
-struct tps68470_clk_platform_data {
+struct tps68470_clk_consumer {
 	const char *consumer_dev_name;
 	const char *consumer_con_id;
 };
 
+struct tps68470_clk_platform_data {
+	unsigned int n_consumers;
+	struct tps68470_clk_consumer consumers[];
+};
+
 #endif
#5 lore raw

Re: [PATCH v3 3/5] platform/x86: int3472: Support multiple clock consumers

In reply to Daniel Scally
Quoted 5 lines · Daniel Scally

At present, the tps68470.c only supports a single clock consumer when passing platform data to the clock driver. In some devices multiple sensors depend on the clock provided by a single TPS68470 and so all need to be able to acquire the clock. Support passing multiple consumers as platform data.

...

drivers/platform/x86/intel/int3472/tps68470.c static int skl_int3472_tps68470_calc_type(struct acpi_device *adev) · line 113

Quoted 11 lines
drivers/platform/x86/intel/int3472/tps68470.c +11 -0
+static int
+skl_int3472_fill_clk_pdata(struct device *dev, struct tps68470_clk_platform_data **clk_pdata)
+{
+	struct acpi_device *adev = ACPI_COMPANION(dev);
+	struct acpi_device *consumer;
+	unsigned int n_consumers = 0;
+	const char *sensor_name;
+	unsigned int i = 0;
+
+	for_each_acpi_consumer_dev(adev, consumer)
+		n_consumers++;

Here no put for consumer (and IIUC it's correct).

Quoted 1 line

+

(Also no need to have a blank line here, the condition is tighten to
the for-loop.)

Quoted 14 lines
drivers/platform/x86/intel/int3472/tps68470.c +14 -0
+	if (!n_consumers) {
+		dev_err(dev, "INT3472 seems to have no dependents\n");
+		return -ENODEV;
+	}
+
+	*clk_pdata = devm_kzalloc(dev, struct_size(*clk_pdata, consumers, n_consumers),
+				  GFP_KERNEL);
+	if (!*clk_pdata)
+		return -ENOMEM;
+
+	(*clk_pdata)->n_consumers = n_consumers;
+	i = 0;
+
+	for_each_acpi_consumer_dev(adev, consumer) {

drivers/platform/x86/intel/int3472/tps68470.c static int skl_int3472_tps68470_calc_type(struct acpi_device *adev)

Quoted 10 lines
drivers/platform/x86/intel/int3472/tps68470.c +9 -0
+		sensor_name = devm_kasprintf(dev, GFP_KERNEL, I2C_DEV_NAME_FORMAT,
+					     acpi_dev_name(consumer));
+		if (!sensor_name)
+			return -ENOMEM;
+
+		(*clk_pdata)->consumers[i].consumer_dev_name = sensor_name;
+		i++;
+	}
 
+	acpi_dev_put(consumer);

Why is it here?

Quoted 2 lines
drivers/platform/x86/intel/int3472/tps68470.c +2 -0
+	return n_consumers;
+}
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#6 lore raw

Re: [PATCH v3 3/5] platform/x86: int3472: Support multiple clock consumers

Quoted 6 lines · Andy Shevchenko
Quoted 5 lines · Daniel Scally

At present, the tps68470.c only supports a single clock consumer when passing platform data to the clock driver. In some devices multiple sensors depend on the clock provided by a single TPS68470 and so all need to be able to acquire the clock. Support passing multiple consumers as platform data.

...

Quoted 42 lines

drivers/platform/x86/intel/int3472/tps68470.c static int skl_int3472_tps68470_calc_type(struct acpi_device *adev) · line 113

Quoted 11 lines
drivers/platform/x86/intel/int3472/tps68470.c +11 -0
+static int
+skl_int3472_fill_clk_pdata(struct device *dev, struct tps68470_clk_platform_data **clk_pdata)
+{
+	struct acpi_device *adev = ACPI_COMPANION(dev);
+	struct acpi_device *consumer;
+	unsigned int n_consumers = 0;
+	const char *sensor_name;
+	unsigned int i = 0;
+
+	for_each_acpi_consumer_dev(adev, consumer)
+		n_consumers++;

Here no put for consumer (and IIUC it's correct).

Quoted 1 line

+

(Also no need to have a blank line here, the condition is tighten to
the for-loop.)

Quoted 22 lines
drivers/platform/x86/intel/int3472/tps68470.c +22 -0
+	if (!n_consumers) {
+		dev_err(dev, "INT3472 seems to have no dependents\n");
+		return -ENODEV;
+	}
+
+	*clk_pdata = devm_kzalloc(dev, struct_size(*clk_pdata, consumers, n_consumers),
+				  GFP_KERNEL);
+	if (!*clk_pdata)
+		return -ENOMEM;
+
+	(*clk_pdata)->n_consumers = n_consumers;
+	i = 0;
+
+	for_each_acpi_consumer_dev(adev, consumer) {
+		sensor_name = devm_kasprintf(dev, GFP_KERNEL, I2C_DEV_NAME_FORMAT,
+					     acpi_dev_name(consumer));
+		if (!sensor_name)
+			return -ENOMEM;
+
+		(*clk_pdata)->consumers[i].consumer_dev_name = sensor_name;
+		i++;
+	}
Quoted 3 lines

drivers/platform/x86/intel/int3472/tps68470.c static int skl_int3472_tps68470_calc_type(struct acpi_device *adev) · line 138

Quoted 1 line
drivers/platform/x86/intel/int3472/tps68470.c +1 -0
+	acpi_dev_put(consumer);

Why is it here?

Now I got it, you need to move it to the error path before returning from inside the for-loop.

Quoted 2 lines
Quoted 2 lines
drivers/platform/x86/intel/int3472/tps68470.c +2 -0
+	return n_consumers;
+}
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#7 lore raw

PATCH v3 4/5 platform/x86: int3472: Support multiple gpio lookups in board data

In reply to Daniel Scally

Currently, we only support passing a single gpiod_lookup_table as part of the board data for the tps68470 driver. This carries the implicit assumption that each TPS68470 device will only support a single sensor, which does not hold true.

Extend the code to support the possibility of multiple sensors each having a gpiod_lookup_table, and opportunistically add the lookup table for the Surface Go line's IR camera.

---
Changes since v2:

- None

 drivers/platform/x86/intel/int3472/tps68470.c | 17 ++++++++++-----
 drivers/platform/x86/intel/int3472/tps68470.h |  3 ++-
 .../x86/intel/int3472/tps68470_board_data.c   | 21 ++++++++++++++++---
 3 files changed, 32 insertions(+), 9 deletions(-)
drivers/platform/x86/intel/int3472/tps68470.c +12 -5
index 8a684030933d..49fc379fe680 100644
@@ -150,6 +150,7 @@ static int skl_int3472_tps68470_probe(struct i2c_client *client)
 	int n_consumers;
 	int device_type;
 	int ret;
+	int i;
 
 	n_consumers = skl_int3472_fill_clk_pdata(&client->dev, &clk_pdata);
 	if (n_consumers < 0)
@@ -194,15 +195,18 @@ static int skl_int3472_tps68470_probe(struct i2c_client *client)
 		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);
+		for (i = 0; i < board_data->n_gpiod_lookups; i++)
+			gpiod_add_lookup_table(board_data->tps68470_gpio_lookup_tables[i]);
 
 		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);
+		if (ret) {
+			for (i = 0; i < board_data->n_gpiod_lookups; i++)
+				gpiod_remove_lookup_table(board_data->tps68470_gpio_lookup_tables[i]);
+		}
 
 		break;
 	case DESIGNED_FOR_CHROMEOS:
@@ -226,10 +230,13 @@ static int skl_int3472_tps68470_probe(struct i2c_client *client)
 static int skl_int3472_tps68470_remove(struct i2c_client *client)
 {
 	const struct int3472_tps68470_board_data *board_data;
+	int i;
 
 	board_data = int3472_tps68470_get_board_data(dev_name(&client->dev));
-	if (board_data)
-		gpiod_remove_lookup_table(board_data->tps68470_gpio_lookup_table);
+	if (board_data) {
+		for (i = 0; i < board_data->n_gpiod_lookups; i++)
+			gpiod_remove_lookup_table(board_data->tps68470_gpio_lookup_tables[i]);
+	}
 
 	return 0;
 }
drivers/platform/x86/intel/int3472/tps68470.h +2 -1
index cfd33eb62740..35915e701593 100644
@@ -16,8 +16,9 @@ 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;
+	unsigned int n_gpiod_lookups;
+	struct gpiod_lookup_table *tps68470_gpio_lookup_tables[];
 };
 
 const struct int3472_tps68470_board_data *int3472_tps68470_get_board_data(const char *dev_name);
drivers/platform/x86/intel/int3472/tps68470_board_data.c +18 -3
index 525f09a3b5ff..e6cc8f40f5af 100644
@@ -96,7 +96,7 @@ static const struct tps68470_regulator_platform_data surface_go_tps68470_pdata =
 	},
 };
 
-static struct gpiod_lookup_table surface_go_tps68470_gpios = {
+static struct gpiod_lookup_table surface_go_int347a_gpios = {
 	.dev_id = "i2c-INT347A:00",
 	.table = {
 		GPIO_LOOKUP("tps68470-gpio", 9, "reset", GPIO_ACTIVE_LOW),
@@ -105,16 +105,31 @@ static struct gpiod_lookup_table surface_go_tps68470_gpios = {
 	}
 };
 
+static struct gpiod_lookup_table surface_go_int347e_gpios = {
+	.dev_id = "i2c-INT347E:00",
+	.table = {
+		GPIO_LOOKUP("tps68470-gpio", 5, "enable", GPIO_ACTIVE_HIGH),
+		{ }
+	}
+};
+
 static const struct int3472_tps68470_board_data surface_go_tps68470_board_data = {
 	.dev_name = "i2c-INT3472:05",
-	.tps68470_gpio_lookup_table = &surface_go_tps68470_gpios,
 	.tps68470_regulator_pdata = &surface_go_tps68470_pdata,
+	.n_gpiod_lookups = 2,
+	.tps68470_gpio_lookup_tables = {
+		&surface_go_int347a_gpios,
+		&surface_go_int347e_gpios,
+	},
 };
 
 static const struct int3472_tps68470_board_data surface_go3_tps68470_board_data = {
 	.dev_name = "i2c-INT3472:01",
-	.tps68470_gpio_lookup_table = &surface_go_tps68470_gpios,
 	.tps68470_regulator_pdata = &surface_go_tps68470_pdata,
+	.n_gpiod_lookups = 1,
+	.tps68470_gpio_lookup_tables = {
+		&surface_go_int347a_gpios
+	},
 };
 
 static const struct dmi_system_id int3472_tps68470_board_data_table[] = {
Signature · 1 line
2.25.1
#8 lore raw

PATCH v3 5/5 platform/x86: int3472: Add board data for Surface Go2 IR camera

In reply to Daniel Scally

Add the board data describing the regulators for the Microsoft Surface Go line's IR camera.

---
Changes since v2:

- None

 .../x86/intel/int3472/tps68470_board_data.c   | 33 +++++++++++++++++++
 1 file changed, 33 insertions(+)
drivers/platform/x86/intel/int3472/tps68470_board_data.c +33 -0
index e6cc8f40f5af..309eab9c0558 100644
@@ -30,6 +30,15 @@ static struct regulator_consumer_supply int347a_vcm_consumer_supplies[] = {
 static struct regulator_consumer_supply int347a_vsio_consumer_supplies[] = {
 	REGULATOR_SUPPLY("dovdd", "i2c-INT347A:00"),
 	REGULATOR_SUPPLY("vsio", "i2c-INT347A:00-VCM"),
+	REGULATOR_SUPPLY("vddd", "i2c-INT347E:00"),
+};
+
+static struct regulator_consumer_supply int347a_aux1_consumer_supplies[] = {
+	REGULATOR_SUPPLY("vdda", "i2c-INT347E:00"),
+};
+
+static struct regulator_consumer_supply int347a_aux2_consumer_supplies[] = {
+	REGULATOR_SUPPLY("vdddo", "i2c-INT347E:00"),
 };
 
 static const struct regulator_init_data surface_go_tps68470_core_reg_init_data = {
@@ -86,6 +95,28 @@ static const struct regulator_init_data surface_go_tps68470_vsio_reg_init_data =
 	.consumer_supplies = int347a_vsio_consumer_supplies,
 };
 
+static const struct regulator_init_data surface_go_tps68470_aux1_reg_init_data = {
+	.constraints = {
+		.min_uV = 2815200,
+		.max_uV = 2815200,
+		.apply_uV = 1,
+		.valid_ops_mask = REGULATOR_CHANGE_STATUS,
+	},
+	.num_consumer_supplies = ARRAY_SIZE(int347a_aux1_consumer_supplies),
+	.consumer_supplies = int347a_aux1_consumer_supplies,
+};
+
+static const struct regulator_init_data surface_go_tps68470_aux2_reg_init_data = {
+	.constraints = {
+		.min_uV = 1800600,
+		.max_uV = 1800600,
+		.apply_uV = 1,
+		.valid_ops_mask = REGULATOR_CHANGE_STATUS,
+	},
+	.num_consumer_supplies = ARRAY_SIZE(int347a_aux2_consumer_supplies),
+	.consumer_supplies = int347a_aux2_consumer_supplies,
+};
+
 static const struct tps68470_regulator_platform_data surface_go_tps68470_pdata = {
 	.reg_init_data = {
 		[TPS68470_CORE] = &surface_go_tps68470_core_reg_init_data,
@@ -93,6 +124,8 @@ static const struct tps68470_regulator_platform_data surface_go_tps68470_pdata =
 		[TPS68470_VCM]  = &surface_go_tps68470_vcm_reg_init_data,
 		[TPS68470_VIO] = &surface_go_tps68470_vio_reg_init_data,
 		[TPS68470_VSIO] = &surface_go_tps68470_vsio_reg_init_data,
+		[TPS68470_AUX1] = &surface_go_tps68470_aux1_reg_init_data,
+		[TPS68470_AUX2] = &surface_go_tps68470_aux2_reg_init_data,
 	},
 };
 
Signature · 1 line
2.25.1
#9 lore raw
In reply to Daniel Scally

Hi All,

Quoted 9 lines · Daniel Scally

Hello all

At the moment there are a few places in the int3472-tps68470 driver that are limited to just working with a single consuming device dependent on the PMIC. There are systems where multiple camera sensors share a single TPS68470, so we need to extend the driver to support them. This requires a couple of tweaks to the ACPI functions to fetch dependent devices, which also assumes that only a single dependent will be found.

Quoted 4 lines

The v2 for this series was some time ago...it's kept falling to the back of my to-do list so I've only just gotten round to it; sorry about that. v2 here:

https://lore.kernel.org/linux-acpi/[email protected]/

Rafael, I would like to merge this through the pdx86 tree may I have your ack for patches 1 + 2 for this. As a reminder (since it has been a while) here are your review remarks to v2 of patch 1:

https://lore.kernel.org/platform-driver-x86/CAJZ5v0i2ciLHP-=8eQcZc0v0xCzhKHKpxLC=Kgv6W5E_5=HQJA@mail.gmail.com/

(which both seem to have been addressed)

AFAICT you did not have any remarks for v2 of patch 2.

Regards,

Hans

p.s.

Dan, if I want to give the IR cam a test run on my own Surface Go (version 1) I guess I may need a sensor driver? Where can I find that sensor driver and what do I need in userspace to test this ?

Quoted 17 lines

Daniel Scally (5):
ACPI: scan: Add acpi_dev_get_next_consumer_dev()
ACPI: bus: Add iterator for dependent devices platform/x86: int3472: Support multiple clock consumers platform/x86: int3472: Support multiple gpio lookups in board data platform/x86: int3472: Add board data for Surface Go2 IR camera

 drivers/acpi/scan.c                           | 40 +++++++---
 drivers/clk/clk-tps68470.c                    | 13 +++-
 drivers/platform/x86/intel/int3472/common.c   |  2 +-
 drivers/platform/x86/intel/int3472/tps68470.c | 76 ++++++++++++++++---
 drivers/platform/x86/intel/int3472/tps68470.h |  3 +-
 .../x86/intel/int3472/tps68470_board_data.c   | 54 ++++++++++++-
 include/acpi/acpi_bus.h                       | 15 +++-
 include/linux/platform_data/tps68470.h        |  7 +-
 8 files changed, 177 insertions(+), 33 deletions(-)
#10 lore raw

Hi Hans

Quoted 28 lines · Hans de Goede

Hi All,

Quoted 9 lines · Daniel Scally

Hello all

At the moment there are a few places in the int3472-tps68470 driver that are limited to just working with a single consuming device dependent on the PMIC. There are systems where multiple camera sensors share a single TPS68470, so we need to extend the driver to support them. This requires a couple of tweaks to the ACPI functions to fetch dependent devices, which also assumes that only a single dependent will be found.

Quoted 4 lines

The v2 for this series was some time ago...it's kept falling to the back of my to-do list so I've only just gotten round to it; sorry about that. v2 here:

https://lore.kernel.org/linux-acpi/[email protected]/

Rafael, I would like to merge this through the pdx86 tree may I have your ack for patches 1 + 2 for this. As a reminder (since it has been a while) here are your review remarks to v2 of patch 1:

https://lore.kernel.org/platform-driver-x86/CAJZ5v0i2ciLHP-=8eQcZc0v0xCzhKHKpxLC=Kgv6W5E_5=HQJA@mail.gmail.com/

(which both seem to have been addressed)

AFAICT you did not have any remarks for v2 of patch 2.

Regards,

Quoted 7 lines

Hans

p.s.

Dan, if I want to give the IR cam a test run on my own Surface Go (version 1) I guess I may need a sensor driver? Where can I find that sensor driver and what do I need in userspace to test this ?

It's the ov7251 sensor driver - the required changes are in mainline now actually so you should be good there. The format of the data is a bit unconventional; it's Y10 but passed through Intel's CIO2 CSI receiver which packs it into a different format [1]. I'm probably just going to add support for that format to Howdy [2] which is what people want to use this camera for, but for now you can just test by using the ipu3-unpack utility in libcamera [3] to convert back to proper Y10 and then raw2rgbpnm [4] to turn it into a ppm. I use this script for now:
https://paste.debian.net/1254629. Be warned that unless you are in sunlight the image is basically just grey - the IR LED on the front of the surface needs driving to give a clear image otherwise. I have an led driver for the tps68470 which can do that, I'm just working on getting it all tied in so it triggers when streaming starts.

[1]
https://www.linuxtv.org/downloads/v4l-dvb-apis-new/userspace-api/v4l/pixfmt-yuv-luma.html

[2] https://github.com/boltgolt/howdy

[3] https://git.libcamera.org/libcamera/libcamera.git/tree/utils/ipu3

[4] https://paste.debian.net/1254629

Quoted 19 lines
Quoted 19 lines

Daniel Scally (5):
ACPI: scan: Add acpi_dev_get_next_consumer_dev()
ACPI: bus: Add iterator for dependent devices platform/x86: int3472: Support multiple clock consumers platform/x86: int3472: Support multiple gpio lookups in board data platform/x86: int3472: Add board data for Surface Go2 IR camera

 drivers/acpi/scan.c                           | 40 +++++++---
 drivers/clk/clk-tps68470.c                    | 13 +++-
 drivers/platform/x86/intel/int3472/common.c   |  2 +-
 drivers/platform/x86/intel/int3472/tps68470.c | 76 ++++++++++++++++---
 drivers/platform/x86/intel/int3472/tps68470.h |  3 +-
 .../x86/intel/int3472/tps68470_board_data.c   | 54 ++++++++++++-
 include/acpi/acpi_bus.h                       | 15 +++-
 include/linux/platform_data/tps68470.h        |  7 +-
 8 files changed, 177 insertions(+), 33 deletions(-)
#11 lore raw
In reply to Hans de Goede
Quoted 22 lines · Hans de Goede

Hi All,

Quoted 9 lines · Daniel Scally

Hello all

At the moment there are a few places in the int3472-tps68470 driver that are limited to just working with a single consuming device dependent on the PMIC. There are systems where multiple camera sensors share a single TPS68470, so we need to extend the driver to support them. This requires a couple of tweaks to the ACPI functions to fetch dependent devices, which also assumes that only a single dependent will be found.

Quoted 4 lines

The v2 for this series was some time ago...it's kept falling to the back of my to-do list so I've only just gotten round to it; sorry about that. v2 here:

https://lore.kernel.org/linux-acpi/[email protected]/

Rafael, I would like to merge this through the pdx86 tree may I have your ack for patches 1 + 2 for this. As a reminder (since it has been a while) here are your review remarks to v2 of patch 1:

Quoted 5 lines

https://lore.kernel.org/platform-driver-x86/CAJZ5v0i2ciLHP-=8eQcZc0v0xCzhKHKpxLC=Kgv6W5E_5=HQJA@mail.gmail.com/

(which both seem to have been addressed)

AFAICT you did not have any remarks for v2 of patch 2.

No, I didn't.

However, because acpi_bus_get_acpi_device() becomes acpi_get_acpi_dev() in my tree, I think it's better to route this material through it, if that's not a problem.

I've tentatively queued it up for 6.1.

Thanks!

Quoted 26 lines

p.s.

Dan, if I want to give the IR cam a test run on my own Surface Go (version 1) I guess I may need a sensor driver? Where can I find that sensor driver and what do I need in userspace to test this ?

Quoted 17 lines

Daniel Scally (5):
ACPI: scan: Add acpi_dev_get_next_consumer_dev()
ACPI: bus: Add iterator for dependent devices platform/x86: int3472: Support multiple clock consumers platform/x86: int3472: Support multiple gpio lookups in board data platform/x86: int3472: Add board data for Surface Go2 IR camera

 drivers/acpi/scan.c                           | 40 +++++++---
 drivers/clk/clk-tps68470.c                    | 13 +++-
 drivers/platform/x86/intel/int3472/common.c   |  2 +-
 drivers/platform/x86/intel/int3472/tps68470.c | 76 ++++++++++++++++---
 drivers/platform/x86/intel/int3472/tps68470.h |  3 +-
 .../x86/intel/int3472/tps68470_board_data.c   | 54 ++++++++++++-
 include/acpi/acpi_bus.h                       | 15 +++-
 include/linux/platform_data/tps68470.h        |  7 +-
 8 files changed, 177 insertions(+), 33 deletions(-)
#12 lore raw

Hi,

Quoted 27 lines · Rafael J. Wysocki
Quoted 26 lines · Hans de Goede

Hi All,

Quoted 9 lines · Daniel Scally

Hello all

At the moment there are a few places in the int3472-tps68470 driver that are limited to just working with a single consuming device dependent on the PMIC. There are systems where multiple camera sensors share a single TPS68470, so we need to extend the driver to support them. This requires a couple of tweaks to the ACPI functions to fetch dependent devices, which also assumes that only a single dependent will be found.

Quoted 4 lines

The v2 for this series was some time ago...it's kept falling to the back of my to-do list so I've only just gotten round to it; sorry about that. v2 here:

https://lore.kernel.org/linux-acpi/[email protected]/

Rafael, I would like to merge this through the pdx86 tree may I have your ack for patches 1 + 2 for this. As a reminder (since it has been a while) here are your review remarks to v2 of patch 1:

https://lore.kernel.org/platform-driver-x86/CAJZ5v0i2ciLHP-=8eQcZc0v0xCzhKHKpxLC=Kgv6W5E_5=HQJA@mail.gmail.com/

(which both seem to have been addressed)

Quoted 7 lines
Quoted 1 line

AFAICT you did not have any remarks for v2 of patch 2.

No, I didn't.

However, because acpi_bus_get_acpi_device() becomes acpi_get_acpi_dev() in my tree, I think it's better to route this material through it, if that's not a problem.

Routing it to your tree is fine.

Quoted 1 line

I've tentatively queued it up for 6.1.

Great, thank you!

Regards,

Hans

Quoted 27 lines
Quoted 26 lines

p.s.

Dan, if I want to give the IR cam a test run on my own Surface Go (version 1) I guess I may need a sensor driver? Where can I find that sensor driver and what do I need in userspace to test this ?

Quoted 17 lines

Daniel Scally (5):
ACPI: scan: Add acpi_dev_get_next_consumer_dev()
ACPI: bus: Add iterator for dependent devices platform/x86: int3472: Support multiple clock consumers platform/x86: int3472: Support multiple gpio lookups in board data platform/x86: int3472: Add board data for Surface Go2 IR camera

 drivers/acpi/scan.c                           | 40 +++++++---
 drivers/clk/clk-tps68470.c                    | 13 +++-
 drivers/platform/x86/intel/int3472/common.c   |  2 +-
 drivers/platform/x86/intel/int3472/tps68470.c | 76 ++++++++++++++++---
 drivers/platform/x86/intel/int3472/tps68470.h |  3 +-
 .../x86/intel/int3472/tps68470_board_data.c   | 54 ++++++++++++-
 include/acpi/acpi_bus.h                       | 15 +++-
 include/linux/platform_data/tps68470.h        |  7 +-
 8 files changed, 177 insertions(+), 33 deletions(-)