Skip to contentSkip to conversation

Add software node support to regulator framework

RFC PATCH In review Daniel Scally 5 participants 41 messages Jul 8, 2021 – Jul 14, 2021

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

cover Add software node support to regulator framework

Hello all

See previous series for some background context [1]

Some x86 laptops with ACPI tables designed for Windows have a TPS68470 PMIC providing regulators and clocks to camera modules. The DSDT tables for those cameras lack any power control methods, declaring only a dependency on the ACPI device representing the TPS68470. This leaves the regulator framework with no means of determining appropriate voltages for the regulators provided by the PMIC, or of determining which regulators relate to which of the sensor's requested supplies.

This series is a prototype of an emulation of the device tree regulator initialisation and lookup functions, using software nodes. Software nodes relating to each regulator are registered as children of the TPS68470's ACPI firmware node. Those regulators have properties describing their constraints (for example "regulator-min-microvolt"). Similarly, software nodes are registered and assigned as secondary to the Camera's firmware node - these software nodes have reference properties named after the supply in the same way as device tree's phandles, for example "avdd-supply", and linking to the software node assigned to the appropriate regulator. We can then use those constraints to specify the appropriate voltages and the references to allow the camera drivers to look up the correct regulator device.

Although not included in this series, I would plan to use a similar method for linking the clocks provided by the TPS68470 to the sensor so that it can be discovered too.

I'm posting this to see if people agree it's a good approach for tackling the problem; I may be overthinking this and there's a much easier way that I should be looking at instead. It will have knock-ons in the cio2-bridge code [2], as that is adding software nodes to the same sensors to connect them to the media graph. Similarly, is the board file an acceptable solution, or should we just define the configuration for these devices (there's three orf our laptop models in scope) in int3472-tps68470 instead?

Thanks
Dan

[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://elixir.bootlin.com/linux/latest/source/drivers/media/pci/intel/ipu3/cio2-bridge.c#L166

Daniel Scally (2):
regulator: Add support for software node connections platform/surface: Add Surface Go 2 board file

 MAINTAINERS                                |   6 +
 drivers/platform/surface/Kconfig           |  10 ++
 drivers/platform/surface/Makefile          |   1 +
 drivers/platform/surface/surface_go_2.c    | 135 +++++++++++++++++++++
 drivers/regulator/Kconfig                  |   6 +
 drivers/regulator/Makefile                 |   1 +
 drivers/regulator/core.c                   |  23 ++++
 drivers/regulator/swnode_regulator.c       | 111 +++++++++++++++++
 include/linux/regulator/swnode_regulator.h |  33 +++++
 9 files changed, 326 insertions(+)
 create mode 100644 drivers/platform/surface/surface_go_2.c
 create mode 100644 drivers/regulator/swnode_regulator.c
 create mode 100644 include/linux/regulator/swnode_regulator.h
Signature · 1 line
2.25.1
#1 lore raw

RFC PATCH 1/2 regulator: Add support for software node connections

On some x86 platforms, firmware provided by the OEM does not adequately describe the constraints of regulator resources nor their connections to consuming devices via ACPI. To compensate, extend the regulator framework to allow discovery of constraints and supply-consumer relationships via software node references and properties. This will allow us to define those platform specific connections so that the resources can be used in the usual way.

---

swnode_get_regulator_constraints() here is not as extensive as the equivalent function in of_regulator...I could include all that now, but it didn't seem worth it so we don't know what any of those values should be.

 drivers/regulator/Kconfig                  |   6 ++
 drivers/regulator/Makefile                 |   1 +
 drivers/regulator/core.c                   |  23 +++++
 drivers/regulator/swnode_regulator.c       | 111 +++++++++++++++++++++
 include/linux/regulator/swnode_regulator.h |  33 ++++++
 5 files changed, 174 insertions(+)
 create mode 100644 drivers/regulator/swnode_regulator.c
 create mode 100644 include/linux/regulator/swnode_regulator.h
drivers/regulator/Kconfig +6 -0
index 9d84d9245490..7e0351f8fe38 100644
@@ -1171,6 +1171,12 @@ config REGULATOR_SY8827N
 	help
 	  This driver supports SY8827N single output regulator.
 
+config REGULATOR_SWNODE
+	bool "Software Node Regulator Support"
+	help
+	  This option configures support for providing regulator constraints and
+	  mappings to consumers through the use of software nodes.
+
 config REGULATOR_TPS51632
 	tristate "TI TPS51632 Power Regulator"
 	depends on I2C
drivers/regulator/Makefile +1 -0
index 580b015296ea..25cb7bbad652 100644
@@ -9,6 +9,7 @@ obj-$(CONFIG_OF) += of_regulator.o
 obj-$(CONFIG_REGULATOR_FIXED_VOLTAGE) += fixed.o
 obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o
 obj-$(CONFIG_REGULATOR_USERSPACE_CONSUMER) += userspace-consumer.o
+obj-$(CONFIG_REGULATOR_SWNODE) += swnode_regulator.o
 
 obj-$(CONFIG_REGULATOR_88PG86X) += 88pg86x.o
 obj-$(CONFIG_REGULATOR_88PM800) += 88pm800-regulator.o
drivers/regulator/core.c +23 -0
index f192bf19492e..6e10f511db80 100644
@@ -20,11 +20,13 @@
 #include <linux/gpio/consumer.h>
 #include <linux/of.h>
 #include <linux/regmap.h>
+#include <linux/property.h>
 #include <linux/regulator/of_regulator.h>
 #include <linux/regulator/consumer.h>
 #include <linux/regulator/coupler.h>
 #include <linux/regulator/driver.h>
 #include <linux/regulator/machine.h>
+#include <linux/regulator/swnode_regulator.h>
 #include <linux/module.h>
 
 #define CREATE_TRACE_POINTS
@@ -1763,6 +1765,7 @@ static struct regulator_dev *regulator_dev_lookup(struct device *dev,
 						  const char *supply)
 {
 	struct regulator_dev *r = NULL;
+	struct fwnode_handle *swnode;
 	struct device_node *node;
 	struct regulator_map *map;
 	const char *devname = NULL;
@@ -1785,6 +1788,22 @@ static struct regulator_dev *regulator_dev_lookup(struct device *dev,
 		}
 	}
 
+	/* next, try software nodes */
+	if (dev && dev->fwnode && is_software_node(dev->fwnode->secondary)) {
+		swnode = swnode_get_regulator_node(dev, supply);
+		if (!IS_ERR(swnode)) {
+			r = swnode_find_regulator_by_node(swnode);
+			if (r)
+				return r;
+
+			/*
+			 * We have a node, but there is no device.
+			 * assume it has not registered yet.
+			 */
+			return ERR_PTR(-EPROBE_DEFER);
+		}
+	}
+
 	/* if not found, try doing it non-dt way */
 	if (dev)
 		devname = dev_name(dev);
@@ -5242,6 +5261,10 @@ regulator_register(const struct regulator_desc *regulator_desc,
 	init_data = regulator_of_get_init_data(dev, regulator_desc, config,
 					       &rdev->dev.of_node);
 
+	if (!init_data)
+		init_data = regulator_swnode_get_init_data(dev, regulator_desc,
+							   config, &rdev->dev.fwnode);
+
 	/*
 	 * Sometimes not all resources are probed already so we need to take
 	 * that into account. This happens most the time if the ena_gpiod comes
drivers/regulator/swnode_regulator.c new file +111 -0

111 lines not on this page · raw message

include/linux/regulator/swnode_regulator.h new file +33 -0
new file mode 100644
index 000000000000..97527f7dbe80
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Author: Dan Scally <[email protected]> */
+#ifndef __LINUX_SWNODE_REG_H
+#define __LINUX_SWNODE_REG_H
+
+#if defined(CONFIG_REGULATOR_SWNODE)
+struct regulator_init_data *regulator_swnode_get_init_data(struct device *dev,
+							   const struct regulator_desc *desc,
+							   struct regulator_config *config,
+							   struct fwnode_handle **regnode);
+struct regulator_dev *swnode_find_regulator_by_node(struct fwnode_handle *swnode);
+struct fwnode_handle *swnode_get_regulator_node(struct device *dev, const char *supply);
+#else
+struct regulator_init_data *regulator_swnode_get_init_data(struct device *dev,
+							   const struct regulator_desc *desc,
+							   struct regulator_config *config)
+{
+	return NULL;
+}
+
+struct regulator_dev *swnode_find_regulator_by_node(struct fwnode_handle *swnode)
+{
+	return NULL;
+}
+
+struct fwnode_handle *swnode_get_regulator_node(struct device *dev, const char *supply)
+{
+	return NULL;
+}
+
+#endif
+
+#endif
Signature · 1 line
2.25.1
#2 lore raw

Re: [RFC PATCH 1/2] regulator: Add support for software node connections

[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]

Hi Daniel,

[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on regulator/for-next]
[also build test WARNING on linux/master platform-drivers-x86/for-next linus/master v5.13 next-20210708] [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/Daniel-Scally/Add-software-node-support-to-regulator-framework/20210709-064330
base:   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git for-next
config: nios2-allyesconfig (attached as .config)
compiler: nios2-linux-gcc (GCC) 9.3.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/e4e62fb5242b2107b82a626f0fafbbf5d6ab2a5c
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Daniel-Scally/Add-software-node-support-to-regulator-framework/20210709-064330 git checkout e4e62fb5242b2107b82a626f0fafbbf5d6ab2a5c
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=nios2

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>):

>> drivers/regulator/swnode_regulator.c:61:1: warning: no previous prototype for 'regulator_swnode_get_init_data' [-Wmissing-prototypes]
      61 | regulator_swnode_get_init_data(struct device *dev,
         | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/regulator/swnode_regulator.c:92:1: warning: no previous prototype for 'swnode_find_regulator_by_node' [-Wmissing-prototypes]
      92 | swnode_find_regulator_by_node(struct fwnode_handle *swnode)
         | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/regulator/swnode_regulator.c:101:23: warning: no previous prototype for 'swnode_get_regulator_node' [-Wmissing-prototypes]

101 | struct fwnode_handle *swnode_get_regulator_node(struct device *dev, const char *supply)
| ^~~~~~~~~~~~~~~~~~~~~~~~~

vim +/regulator_swnode_get_init_data +61 drivers/regulator/swnode_regulator.c

59
60 struct regulator_init_data *

  > 61	regulator_swnode_get_init_data(struct device *dev,
    62				       const struct regulator_desc *desc,
    63				       struct regulator_config *config,
    64				       struct fwnode_handle **regnode)
    65	{
    66		struct fwnode_handle *fwnode = dev_fwnode(dev);
    67		struct regulator_init_data *init_data;
    68		struct fwnode_handle *regulator;
    69		int ret;
    70	
    71		if (!fwnode || !is_software_node(fwnode->secondary))
    72			return NULL;
    73	
    74		regulator = regulator_swnode_get_init_node(fwnode, desc);
    75		if (!regulator)
    76			return NULL;
    77	
    78		init_data = devm_kzalloc(dev, sizeof(*init_data), GFP_KERNEL);
    79		if (!init_data)
    80			return ERR_PTR(-ENOMEM);
    81	
    82		ret = swnode_get_regulator_constraints(regulator, init_data);
    83		if (ret)
    84			return ERR_PTR(ret);
    85	
    86		*regnode = regulator;
    87	
    88		return init_data;
    89	}
    90	
    91	struct regulator_dev *
  > 92	swnode_find_regulator_by_node(struct fwnode_handle *swnode)
    93	{
    94		struct device *dev;
    95	
    96		dev = class_find_device_by_fwnode(&regulator_class, swnode);
    97	
    98		return dev ? dev_to_rdev(dev) : NULL;
    99	}
   100	
 > 101	struct fwnode_handle *swnode_get_regulator_node(struct device *dev, const char *supply)

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

maintainer
#3 lore raw

Re: [RFC PATCH 1/2] regulator: Add support for software node connections

In reply to Daniel Scally

drivers/regulator/Makefile obj-$(CONFIG_OF) += of_regulator.o · line 12

Quoted 7 lines · Daniel Scally
drivers/regulator/Makefile +1 -0
@@ -9,6 +9,7 @@ obj-$(CONFIG_OF) += of_regulator.o
 obj-$(CONFIG_REGULATOR_FIXED_VOLTAGE) += fixed.o
 obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o
 obj-$(CONFIG_REGULATOR_USERSPACE_CONSUMER) += userspace-consumer.o
+obj-$(CONFIG_REGULATOR_SWNODE) += swnode_regulator.o

This appears to be sorted with regulator drivers but as far as I understand it this is not a driver? I'd put it next to the OF file.

drivers/regulator/Makefile static struct regulator_dev *regulator_dev_lookup(struct device *dev,

Quoted 1 line
drivers/regulator/Makefile +0 -0
@@ -1785,6 +1788,22 @@ static struct regulator_dev *regulator_dev_lookup(struct device *dev,

The line numbers here look off...

drivers/regulator/Makefile line 3

Quoted 5 lines
drivers/regulator/Makefile +4 -0
+++ b/drivers/regulator/swnode_regulator.c
@@ -0,0 +1,111 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Author: Dan Scally <[email protected]> */
+

Please make the entire comment a C++ one so things look more intentional.

Quoted 6 lines
drivers/regulator/Makefile +6 -0
+static struct fwnode_handle *
+regulator_swnode_get_init_node(struct fwnode_handle *fwnode,
+			       const struct regulator_desc *desc)
+{
+	const struct software_node *parent, *child;
+

drivers/regulator/Makefile line 19

Quoted 10 lines
drivers/regulator/Makefile +10 -0
+	parent = to_software_node(fwnode->secondary);
+
+	if (desc->regulators_node)
+		child = software_node_find_by_name(parent,
+						   desc->regulators_node);
+	else
+		child = software_node_find_by_name(parent, desc->name);
+
+	return software_node_fwnode(child);
+}

Nothing is documenting what the binding for these swnodes is supposed to be so it's hard to tell if any of this is correct and makes sense, nor how someone is supposed to take this stuff and integrate it into a system. I think this needs some more explicit documentation of what's going on adding to the tree, this will help with review and help anyone who needs to use this stuff figure out how to do so.

#4 lore raw

RFC PATCH 2/2 platform/surface: Add Surface Go 2 board file

In reply to Daniel Scally

The DSDT tables on the Surface Go 2 contain no power control methods for the world facing camera, so the regulator, gpio and clk frameworks have no way to discover the appropriate connections and settings.

To compensate for the shortcomings, define the connections and other parameters in a board file for this device.

---
 MAINTAINERS                             |   6 ++
 drivers/platform/surface/Kconfig        |  10 ++
 drivers/platform/surface/Makefile       |   1 +
 drivers/platform/surface/surface_go_2.c | 135 ++++++++++++++++++++++++
 4 files changed, 152 insertions(+)
 create mode 100644 drivers/platform/surface/surface_go_2.c
MAINTAINERS +6 -0
index 52e61092c63b..f11e68daf939 100644
@@ -12143,6 +12143,12 @@ F:	Documentation/driver-api/surface_aggregator/clients/dtx.rst
 F:	drivers/platform/surface/surface_dtx.c
 F:	include/uapi/linux/surface_aggregator/dtx.h
 
+MICROSOFT SURFACE GO 2 SUPPORT
+M:	Daniel Scally <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/platform/surface/surface_go_2.c
+
 MICROSOFT SURFACE GPE LID SUPPORT DRIVER
 M:	Maximilian Luz <[email protected]>
 L:	[email protected]
drivers/platform/surface/Kconfig +10 -0
index 3105f651614f..0c55bd531592 100644
@@ -124,6 +124,16 @@ config SURFACE_DTX
 	  Aggregator Bus (i.e. CONFIG_SURFACE_AGGREGATOR_BUS=n). In that case,
 	  some devices, specifically the Surface Book 3, will not be supported.
 
+config SURFACE_GO_2
+	bool "Surface Go 2 Specific Driver"
+	help
+	  This board file performs some platform specific configuration to help
+	  the regulator, gpio and clk frameworks link those resources to the
+	  consuming devices - specifically the world facing camera.
+
+	  Select Y here if your device is a Microsoft Surface Go 2, otherwise
+	  select N.
+
 config SURFACE_GPE
 	tristate "Surface GPE/Lid Support Driver"
 	depends on DMI
drivers/platform/surface/Makefile +1 -0
index 32889482de55..9f858d2a3d77 100644
@@ -12,6 +12,7 @@ obj-$(CONFIG_SURFACE_AGGREGATOR)	+= aggregator/
 obj-$(CONFIG_SURFACE_AGGREGATOR_CDEV)	+= surface_aggregator_cdev.o
 obj-$(CONFIG_SURFACE_AGGREGATOR_REGISTRY) += surface_aggregator_registry.o
 obj-$(CONFIG_SURFACE_DTX)		+= surface_dtx.o
+obj-$(CONFIG_SURFACE_GO_2)		+= surface_go_2.o
 obj-$(CONFIG_SURFACE_GPE)		+= surface_gpe.o
 obj-$(CONFIG_SURFACE_HOTPLUG)		+= surface_hotplug.o
 obj-$(CONFIG_SURFACE_PLATFORM_PROFILE)	+= surface_platform_profile.o
drivers/platform/surface/surface_go_2.c new file +135 -0

135 lines not on this page · raw message

Signature · 1 line
2.25.1
maintainer
#5 lore raw

Re: [RFC PATCH 2/2] platform/surface: Add Surface Go 2 board file

Quoted 3 lines · Daniel Scally

The DSDT tables on the Surface Go 2 contain no power control methods for the world facing camera, so the regulator, gpio and clk frameworks have no way to discover the appropriate connections and settings.

Does anything actually need these connections or settings?

drivers/platform/surface/surface_go_2.c line 33

Quoted 6 lines
drivers/platform/surface/surface_go_2.c new file +6 -0
+static const struct property_entry core_properties[] = {
+	PROPERTY_ENTRY_STRING("regulator-name", "CORE"),
+	PROPERTY_ENTRY_U32("regulator-min-microvolt", 1200000),
+	PROPERTY_ENTRY_U32("regulator-max-microvolt", 1200000),
+	{ }
+};

Does anything actually care about the voltages here - why specify them? As far as I can tell from grepping all the supplies you're adding are digital.

drivers/platform/surface/surface_go_2.c line 45

Quoted 11 lines
drivers/platform/surface/surface_go_2.c new file +10 -0
+static const struct software_node regulator_nodes[] = {
+	{"ANA", &tps68470_node, ana_properties},
+	{"VSIO", &tps68470_node, vsio_properties},
+	{"CORE", &tps68470_node, core_properties},
+};
 
+static const struct property_entry sensor_properties[] = {
+	PROPERTY_ENTRY_REF("avdd-supply", &regulator_nodes[0]),
+	PROPERTY_ENTRY_REF("dovdd-supply", &regulator_nodes[1]),
+	PROPERTY_ENTRY_REF("dvdd-supply", &regulator_nodes[2]),
+	{ }

I would strongly caution against this idiom of referencing elements in other arrays using magic numbers, it is both hard to read and error prone when someone goes in making changes. If they need to be in arrays then constants for the array indexes would help a lot.

drivers/platform/surface/surface_go_2.c line 59

Quoted 12 lines
drivers/platform/surface/surface_go_2.c new file +12 -0
+static struct software_node sensor_node = {
+	.name		= "INT347A",
+	.properties	= sensor_properties,
+};
+
+static struct gpiod_lookup_table surface_go_2_gpios = {
+	.dev_id = "i2c-INT347A:00",
+	.table = {
+		GPIO_LOOKUP("tps68470-gpio", 9, "reset", GPIO_ACTIVE_LOW),
+		GPIO_LOOKUP("tps68470-gpio", 7, "powerdown", GPIO_ACTIVE_LOW)
+	}
+};

This appears to be using regular board file stuff for GPIOs, if this swnode stuff is somehow needed for regulators why is it not also needed for GPIOs? I think this is going back to the thing I was saying earlier about not really understanding the problem being solved here.

maintainer
#6 lore raw
In reply to Daniel Scally
Quoted 1 line · Daniel Scally

See previous series for some background context [1]

That's a link to a series "[PATCH v5 0/6] Introduce intel_skl_int3472 module" which doesn't have any explanatory text as to what it's doing in the cover letter (just an inter version changelog) nor any obvious relevance to this series, are you sure that's the right link? In general it's best if your patch series contains enough explanatory information to allow someone to have a reasonable idea what the series does without having to follow links like this.

Quoted 2 lines

This series is a prototype of an emulation of the device tree regulator initialisation and lookup functions, using software nodes. Software nodes

What is a software node and why would we want to use one here?

Quoted 9 lines

relating to each regulator are registered as children of the TPS68470's ACPI firmware node. Those regulators have properties describing their constraints (for example "regulator-min-microvolt"). Similarly, software nodes are registered and assigned as secondary to the Camera's firmware node - these software nodes have reference properties named after the supply in the same way as device tree's phandles, for example "avdd-supply", and linking to the software node assigned to the appropriate regulator. We can then use those constraints to specify the appropriate voltages and the references to allow the camera drivers to look up the correct regulator device.

So these systems lack an enumerable description of the system provided by hardware or firmware (or given that these are ACPI systems I guess the firmware description is just broken) so we need to use board files. Why are we not just using board files, what does this new abstraction solve?

Quoted 2 lines

I'm posting this to see if people agree it's a good approach for tackling the problem; I may be overthinking this and there's a much easier way that I should

I don't think I understand what the problem you are trying to solve is so it's hard to say if this is a good approach to solving it.

#7 lore raw

Hi Mark, thanks for the feedback - much appreciated.

Quoted 10 lines · Mark Brown
Quoted 1 line · Daniel Scally

See previous series for some background context [1]

That's a link to a series "[PATCH v5 0/6] Introduce intel_skl_int3472 module" which doesn't have any explanatory text as to what it's doing in the cover letter (just an inter version changelog) nor any obvious relevance to this series, are you sure that's the right link? In general it's best if your patch series contains enough explanatory information to allow someone to have a reasonable idea what the series does without having to follow links like this.

It is, but I certainly could have done a better job of explaining context there rather than throwing it in (particularly given the uselessness of the cover letter there, I forgot about that - sorry). That series contains an i2c driver that binds to the TPS68470 when enumerated via ACPI. That i2c driver is effectively an MFD driver, it registers a regmap plus platform devices for the GPIO, clk, regulator and OpRegion parts of the TPS68470, each of which has their own platform driver to control them (though only the GPIO and OpRegion ones are currently upstream - I need to post the clk and regulator ones), all sharing the same regmap. This series is a follow on from that, attempting to remedy problems with the ACPI that prevent those resources from being discoverable by consumers on some devices.

Quoted 3 lines
Quoted 2 lines

This series is a prototype of an emulation of the device tree regulator initialisation and lookup functions, using software nodes. Software nodes

What is a software node and why would we want to use one here?

Like of_nodes, but defined entirely within kernel code rather than parsed out of devicetree or from ACPI. I think we need to use them to make up for the deficiencies in ACPI on these platforms.

Quoted 9 lines
Quoted 9 lines

relating to each regulator are registered as children of the TPS68470's ACPI firmware node. Those regulators have properties describing their constraints (for example "regulator-min-microvolt"). Similarly, software nodes are registered and assigned as secondary to the Camera's firmware node - these software nodes have reference properties named after the supply in the same way as device tree's phandles, for example "avdd-supply", and linking to the software node assigned to the appropriate regulator. We can then use those constraints to specify the appropriate voltages and the references to allow the camera drivers to look up the correct regulator device.

Quoted 5 lines

So these systems lack an enumerable description of the system provided by hardware or firmware (or given that these are ACPI systems I guess the firmware description is just broken) so we need to use board files. Why are we not just using board files, what does this new abstraction solve?

I went with this approach because the ACPI isn't entirely lacking, it enumerates the TPS68470 as an i2c device for its driver to bind to without a problem which results in the regulator driver registering the regulator devices (7 of them for this chip), so I was thinking along the lines of repairing the problems with ACPI to give those rdevs the right init_data rather than sidestepping it altogether. I could register the platform devices for the regulator driver to bind to in a board file instead if that's the preferred option...usually this would involve using i2c_board_info I think but as ACPI will enumerate the i2c device for the chip independently we'd need to handle that somehow to stop them racing each other I guess.

I'll take a look and see if I can make it work that way.

Quoted 4 lines
Quoted 2 lines

I'm posting this to see if people agree it's a good approach for tackling the problem; I may be overthinking this and there's a much easier way that I should

I don't think I understand what the problem you are trying to solve is so it's hard to say if this is a good approach to solving it.

Hope this is a bit clearer now?

maintainer
#8 lore raw
Quoted 11 lines · Daniel Scally

I went with this approach because the ACPI isn't entirely lacking, it enumerates the TPS68470 as an i2c device for its driver to bind to without a problem which results in the regulator driver registering the regulator devices (7 of them for this chip), so I was thinking along the lines of repairing the problems with ACPI to give those rdevs the right init_data rather than sidestepping it altogether. I could register the platform devices for the regulator driver to bind to in a board file instead if that's the preferred option...usually this would involve using i2c_board_info I think but as ACPI will enumerate the i2c device for the chip independently we'd need to handle that somehow to stop them racing each other I guess.

Like I said elsewhere it seems a lot easier to just have the I2C driver set platform data based on parsing DMI information like we do elsewhere. I really don't see any benefit to introducing an additional layer of abstraction and binding here, it just seems to be making things more fragile.

I'm not sure what you mean by "register the platform devices for the regualtor to bind to" - if the PMIC is an I2C device it's going to need to be an I2C device, and if the device is enumerated by firmware we'd need to suppress that firmware enumeration to replace it.

Quoted 13 lines

I'll take a look and see if I can make it work that way.

Quoted 4 lines
Quoted 2 lines

I'm posting this to see if people agree it's a good approach for tackling the problem; I may be overthinking this and there's a much easier way that I should

I don't think I understand what the problem you are trying to solve is so it's hard to say if this is a good approach to solving it.

Hope this is a bit clearer now?

#9 lore raw

Hi Mark,

Quoted 14 lines · Mark Brown
Quoted 11 lines · Daniel Scally

I went with this approach because the ACPI isn't entirely lacking, it enumerates the TPS68470 as an i2c device for its driver to bind to without a problem which results in the regulator driver registering the regulator devices (7 of them for this chip), so I was thinking along the lines of repairing the problems with ACPI to give those rdevs the right init_data rather than sidestepping it altogether. I could register the platform devices for the regulator driver to bind to in a board file instead if that's the preferred option...usually this would involve using i2c_board_info I think but as ACPI will enumerate the i2c device for the chip independently we'd need to handle that somehow to stop them racing each other I guess.

Quoted 5 lines

Like I said elsewhere it seems a lot easier to just have the I2C driver set platform data based on parsing DMI information like we do elsewhere. I really don't see any benefit to introducing an additional layer of abstraction and binding here, it just seems to be making things more fragile.

The idea behind software nodes is that individual device drivers shouldn't care about where platform-specific data come from. They can use the same fwnode API, regardless of whether the device is described through OF, ACPI, or software nodes created by a board file in the kernel. It allows grouping all platform data that should be provided by firmware in a single place, conditioned by a DMI match, instead of distributing DMI matches to lots of drivers.

Quoted 4 lines

I'm not sure what you mean by "register the platform devices for the regualtor to bind to" - if the PMIC is an I2C device it's going to need to be an I2C device, and if the device is enumerated by firmware we'd need to suppress that firmware enumeration to replace it.

We can't. ACPI describes the device, and that's how it's enumerated. ACPI does provide information (as well as ACPI methods) needed by the driver, but fails to provide all the required information. That's why a mechanism to supplement the information provided by ACPI is needed.

Quoted 8 lines
Quoted 8 lines

I'll take a look and see if I can make it work that way.

Quoted 4 lines
Quoted 2 lines

I'm posting this to see if people agree it's a good approach for tackling the problem; I may be overthinking this and there's a much easier way that I should

I don't think I understand what the problem you are trying to solve is so it's hard to say if this is a good approach to solving it.

Hope this is a bit clearer now?

Signature · 3 lines
Regards,

Laurent Pinchart
maintainer
#10 lore raw
Quoted 8 lines · Laurent Pinchart
Quoted 5 lines · Mark Brown

Like I said elsewhere it seems a lot easier to just have the I2C driver set platform data based on parsing DMI information like we do elsewhere. I really don't see any benefit to introducing an additional layer of abstraction and binding here, it just seems to be making things more fragile.

Quoted 4 lines

The idea behind software nodes is that individual device drivers shouldn't care about where platform-specific data come from. They can use the same fwnode API, regardless of whether the device is described through OF, ACPI, or software nodes created by a board file in the

That's much more fwnode than swnode. fwnode is a cute hack for letting ACPI based systems that don't fit the ACPI model reuse DT bindings which can work well for some things which are just outside the scope of ACPI completely but is a really bad idea for things where there's specific firmware modelling for the thing being handled, in those cases it should be avoided and firmware specific handling used instead. Power handling (including regulators) is one of those areas - ACPI has really strong opinions on how it should be done and we don't want to be encouraging systems to go against that model. AFAICT swnode is mostly just a way of patching up firmware that could be getting away with fwnode but didn't for some reason, in this case we don't want to ever see ACPI systems trying to use the DT regulator bindings in their firmware descriptions.

Quoted 3 lines

kernel. It allows grouping all platform data that should be provided by firmware in a single place, conditioned by a DMI match, instead of distributing DMI matches to lots of drivers.

Like I said in reply to Andy's mail if we're essentially filling in a C struct through a massive pile of indirection involving writing C code containing a bunch of static initialisations of less specific structs that doesn't seem great. We can probably arrange to pass the init_data from different files rather than putting the quirks in the driver, that'd be fine if a bit more work, but swnodes only seem to be adding problems here.

#11 lore raw
In reply to Mark Brown
Quoted 6 lines · Mark Brown
Quoted 2 lines · Daniel Scally

This series is a prototype of an emulation of the device tree regulator initialisation and lookup functions, using software nodes. Software nodes

What is a software node and why would we want to use one here?

Software node is a representation of (missed and / or quirked) firmware nodes in the code.

Quoted 2 lines

Why are we not just using board files, what does this new abstraction solve?

Software node _is_ a board file part. The idea behind that is that the driver, which requires any additional / necessary property that has been missed in the firmware nodes, wouldn't need special treatment if that property comes from a board file rather than firmware.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
Quoted 39 lines · Mark Brown
Quoted 1 line · Daniel Scally

See previous series for some background context [1]

That's a link to a series "[PATCH v5 0/6] Introduce intel_skl_int3472 module" which doesn't have any explanatory text as to what it's doing in the cover letter (just an inter version changelog) nor any obvious relevance to this series, are you sure that's the right link? In general it's best if your patch series contains enough explanatory information to allow someone to have a reasonable idea what the series does without having to follow links like this.

Quoted 2 lines

This series is a prototype of an emulation of the device tree regulator initialisation and lookup functions, using software nodes. Software nodes

What is a software node and why would we want to use one here?

Quoted 9 lines

relating to each regulator are registered as children of the TPS68470's ACPI firmware node. Those regulators have properties describing their constraints (for example "regulator-min-microvolt"). Similarly, software nodes are registered and assigned as secondary to the Camera's firmware node - these software nodes have reference properties named after the supply in the same way as device tree's phandles, for example "avdd-supply", and linking to the software node assigned to the appropriate regulator. We can then use those constraints to specify the appropriate voltages and the references to allow the camera drivers to look up the correct regulator device.

So these systems lack an enumerable description of the system provided by hardware or firmware (or given that these are ACPI systems I guess the firmware description is just broken) so we need to use board files. Why are we not just using board files, what does this new abstraction solve?

Quoted 2 lines

I'm posting this to see if people agree it's a good approach for tackling the problem; I may be overthinking this and there's a much easier way that I should

I don't think I understand what the problem you are trying to solve is so it's hard to say if this is a good approach to solving it.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#12 lore raw
Quoted 8 lines · Andy Shevchenko
Quoted 3 lines · Mark Brown

On Thu, Jul 08, 2021 at 11:42:24PM +0100, Daniel Scally wrote:

What is a software node and why would we want to use one here?

Software node is a representation of (missed and / or quirked) firmware nodes in the code.

Quoted 7 lines
Quoted 2 lines

Why are we not just using board files, what does this new abstraction solve?

Software node _is_ a board file part. The idea behind that is that the driver, which requires any additional / necessary property that has been missed in the firmware nodes, wouldn't need special treatment if that property comes from a board file rather than firmware.

This doesn't seem to correspond with what these patches are doing, they're creating something which bears no relation to any firmware interface and the code is specifically looking for swnodes.

#13 lore raw
Quoted 12 lines · Mark Brown
Quoted 10 lines · Andy Shevchenko
Quoted 3 lines · Mark Brown

On Thu, Jul 08, 2021 at 11:42:24PM +0100, Daniel Scally wrote:

What is a software node and why would we want to use one here?

Software node is a representation of (missed and / or quirked) firmware nodes in the code.

Quoted 2 lines

Why are we not just using board files, what does this new abstraction solve?

Quoted 8 lines
Quoted 4 lines

Software node _is_ a board file part. The idea behind that is that the driver, which requires any additional / necessary property that has been missed in the firmware nodes, wouldn't need special treatment if that property comes from a board file rather than firmware.

This doesn't seem to correspond with what these patches are doing, they're creating something which bears no relation to any firmware interface and the code is specifically looking for swnodes.

Okay, this seems like a different story.
The software nodes shouldn't appear on its own in the generic code. When we use software nodes API in it, it means that we have tried other providers _explicitly_ and haven't found what we are looking for and hence we have to check if software nodes are providing the same. For example, here it's done that way:
https://elixir.bootlin.com/linux/v5.14-rc1/source/kernel/irq/irqdomain.c#L178.

In all other cases it shouldn't be called explicitly.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#14 lore raw
Quoted 8 lines · Andy Shevchenko

The software nodes shouldn't appear on its own in the generic code. When we use software nodes API in it, it means that we have tried other providers _explicitly_ and haven't found what we are looking for and hence we have to check if software nodes are providing the same. For example, here it's done that way:
https://elixir.bootlin.com/linux/v5.14-rc1/source/kernel/irq/irqdomain.c#L178.

In all other cases it shouldn't be called explicitly.

But why? I'm not seeing the advantage over providing platform data based on DMI quirks here, it seems like a bunch of work for no reason.

#15 lore raw
Quoted 10 lines · Mark Brown
Quoted 6 lines · Andy Shevchenko

The software nodes shouldn't appear on its own in the generic code. When we use software nodes API in it, it means that we have tried other providers _explicitly_ and haven't found what we are looking for and hence we have to check if software nodes are providing the same. For example, here it's done that way:
https://elixir.bootlin.com/linux/v5.14-rc1/source/kernel/irq/irqdomain.c#L178.

Quoted 4 lines
Quoted 1 line

In all other cases it shouldn't be called explicitly.

But why? I'm not seeing the advantage over providing platform data based on DMI quirks here, it seems like a bunch of work for no reason.

What do you mean by additional work? It's exactly opposite since most of the drivers in the kernel are using the fwnode interface rather than platform data. Why should we _add_ the specific platform data handling code in the certain drivers instead of not touching them at all?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#16 lore raw
Quoted 10 lines · Andy Shevchenko
Quoted 2 lines · Mark Brown

But why? I'm not seeing the advantage over providing platform data based on DMI quirks here, it seems like a bunch of work for no reason.

What do you mean by additional work? It's exactly opposite since most of the drivers in the kernel are using the fwnode interface rather than platform data. Why should we _add_ the specific platform data handling code in the certain drivers instead of not touching them at all?

It's adding an entirely new representation of standard data with less validation support than either DT or platform data which seems like a needlessly roundabout and error prone way of moving the data about with less tooling support. As far as I can tell the only advantage is that it lets you write the quirk in a different source file but I'm finding it hard to get excited about that. If we were fixing up an existing ACPI binding or something this approach would make sense to me but it's making something entirely new out of whole cloth here.

We already have generic platform data support for the regulator API so driver modifications would just be the DMI matching which is going to have to happen somewhere anyway, I don't see a huge win from putting them in one file rather than another. It should basically just boil down to being another data table, I imagine you could write a helper for it, or probably even come up with some generic thing that let you register a platform data/DMI combo independently of the driver to get it out of the driver code (looking more like the existing GPIO code which is already being used in another bit of this quirking).

It feels like this should be making more use of existing stuff than it is. If you look at what the core part of the code does it's taking data which was provided by one part of the kernel in one set of C structs and parsing those into a struct init_data which is what the core actually wants to consume. This seems like an entirely redundant process, we should be able to just write the machine configuration into some struct init_datas and get that associated with the regulators without creating an otherwise entirely unused intermediate representation of the data.

#17 lore raw

Hi Mark - sorry for the late reply.

Quoted 9 lines · Mark Brown
Quoted 8 lines · Andy Shevchenko
Quoted 2 lines · Mark Brown

But why? I'm not seeing the advantage over providing platform data based on DMI quirks here, it seems like a bunch of work for no reason.

What do you mean by additional work? It's exactly opposite since most of the drivers in the kernel are using the fwnode interface rather than platform data. Why should we _add_ the specific platform data handling code in the certain drivers instead of not touching them at all?

Quoted 6 lines

It's adding an entirely new representation of standard data with less validation support than either DT or platform data which seems like a needlessly roundabout and error prone way of moving the data about with less tooling support. As far as I can tell the only advantage is that it lets you write the quirk in a different source file but I'm finding it hard to get excited about that.

I do think it can simplify driver code too; a lot of them aren't written to parse platform data to get the init data, as they're just relying on reading it from devicetree so in the event that we get more cases like this, we need to modify those drivers to look for platform data too. On the other hand, even the drivers that don't directly call of_get_regulator_init_data() still do that lookup during the regulator_of_get_init_data() call in regulator_register(), so the ones that do parse platform data for init_data structs will check DT as part of regulator_register() anyway. Imitating that seems simpler to me.

It also creates some problems to suppress the enumeration of the i2c device via ACPI (which we'll have to do in a machine specific fashion, because some laptops have this chip with properly configured ACPI and thus work fine as-is) to re-enumerate it in a board file with the platform data; the ACPI methods and buffers are used by the i2c device's driver; there's a bunch of regrettably non-standards-compliant information in there that we need to check to make sure we do things properly.

I take the point about this being error-prone lacking tooling support - happy to work on this as much as needed to alleviate your concerns if we decide to proceed down this route.

Quoted 14 lines

If we were fixing up an existing
ACPI binding or something this approach would make sense to me but it's making something entirely new out of whole cloth here.

We already have generic platform data support for the regulator API so driver modifications would just be the DMI matching which is going to have to happen somewhere anyway, I don't see a huge win from putting them in one file rather than another. It should basically just boil down to being another data table, I imagine you could write a helper for it, or probably even come up with some generic thing that let you register a platform data/DMI combo independently of the driver to get it out of the driver code (looking more like the existing GPIO code which is already being used in another bit of this quirking).

Quoted 8 lines

It feels like this should be making more use of existing stuff than it is. If you look at what the core part of the code does it's taking data which was provided by one part of the kernel in one set of C structs and parsing those into a struct init_data which is what the core actually wants to consume. This seems like an entirely redundant process, we should be able to just write the machine configuration into some struct init_datas and get that associated with the regulators without creating an otherwise entirely unused intermediate representation of the data.

The advantage of the GPIO lookups is there's no need to have the pointer to the registered devices to register the lookup table; we could imitate that, by adding entries to a list with the lookup values being device and regulator name (with the init data as the thing that's "looked up") and check for those during regulator_register() maybe?

maintainer
#18 lore raw
Quoted 9 lines · Daniel Scally

I do think it can simplify driver code too; a lot of them aren't written to parse platform data to get the init data, as they're just relying on reading it from devicetree so in the event that we get more cases like this, we need to modify those drivers to look for platform data too. On the other hand, even the drivers that don't directly call of_get_regulator_init_data() still do that lookup during the regulator_of_get_init_data() call in regulator_register(), so the ones that do parse platform data for init_data structs will check DT as part of regulator_register() anyway. Imitating that seems simpler to me.

The driver code is trivial boilerplate, assuming someone doesn't go and implement a helper to register stuff separately like I suggested. The proposed swnode stuff would involve duplicating the DT parsing code. This seems like a whole lot of effort for something that provides a worse result than either of the existing things.

Quoted 3 lines

It also creates some problems to suppress the enumeration of the i2c device via ACPI (which we'll have to do in a machine specific fashion, because some laptops have this chip with properly configured ACPI and

To be clear I think that's a terrible idea.

Quoted 11 lines
Quoted 5 lines

down to being another data table, I imagine you could write a helper for it, or probably even come up with some generic thing that let you register a platform data/DMI combo independently of the driver to get it out of the driver code (looking more like the existing GPIO code which is already being used in another bit of this quirking).

The advantage of the GPIO lookups is there's no need to have the pointer to the registered devices to register the lookup table; we could imitate that, by adding entries to a list with the lookup values being device and regulator name (with the init data as the thing that's "looked up") and check for those during regulator_register() maybe?

Like I keep saying I think that's a much better approach than trying to use swnodes, they just seem like a terrible fit for the problem.

#19 lore raw

Hi Mark,

Quoted 18 lines · Mark Brown
Quoted 9 lines · Daniel Scally

I do think it can simplify driver code too; a lot of them aren't written to parse platform data to get the init data, as they're just relying on reading it from devicetree so in the event that we get more cases like this, we need to modify those drivers to look for platform data too. On the other hand, even the drivers that don't directly call of_get_regulator_init_data() still do that lookup during the regulator_of_get_init_data() call in regulator_register(), so the ones that do parse platform data for init_data structs will check DT as part of regulator_register() anyway. Imitating that seems simpler to me.

The driver code is trivial boilerplate, assuming someone doesn't go and implement a helper to register stuff separately like I suggested. The proposed swnode stuff would involve duplicating the DT parsing code. This seems like a whole lot of effort for something that provides a worse result than either of the existing things.

Quoted 5 lines
Quoted 3 lines

It also creates some problems to suppress the enumeration of the i2c device via ACPI (which we'll have to do in a machine specific fashion, because some laptops have this chip with properly configured ACPI and

To be clear I think that's a terrible idea.

If you're talking about the ACPI implementation on those machines, nobody disagrees :-)

To make sure I understand you correctly, do you advocate for suppressing registration of the I2C devices from ACPI and instantiate them from board code instead, or to somehow supplement the I2C device with board-specific data ?

Quoted 14 lines
Quoted 11 lines
Quoted 5 lines

down to being another data table, I imagine you could write a helper for it, or probably even come up with some generic thing that let you register a platform data/DMI combo independently of the driver to get it out of the driver code (looking more like the existing GPIO code which is already being used in another bit of this quirking).

The advantage of the GPIO lookups is there's no need to have the pointer to the registered devices to register the lookup table; we could imitate that, by adding entries to a list with the lookup values being device and regulator name (with the init data as the thing that's "looked up") and check for those during regulator_register() maybe?

Like I keep saying I think that's a much better approach than trying to use swnodes, they just seem like a terrible fit for the problem.

Signature · 3 lines
Regards,

Laurent Pinchart
maintainer
#20 lore raw
Quoted 9 lines · Laurent Pinchart
Quoted 7 lines · Mark Brown
Quoted 3 lines · Daniel Scally

It also creates some problems to suppress the enumeration of the i2c device via ACPI (which we'll have to do in a machine specific fashion, because some laptops have this chip with properly configured ACPI and

To be clear I think that's a terrible idea.

Quoted 7 lines

If you're talking about the ACPI implementation on those machines, nobody disagrees :-)

To make sure I understand you correctly, do you advocate for suppressing registration of the I2C devices from ACPI and instantiate them from board code instead, or to somehow supplement the I2C device with board-specific data ?

No, to repeat yet again that is what I think is a terrible idea.

#21 lore raw
Quoted 12 lines · Mark Brown
Quoted 11 lines · Laurent Pinchart
Quoted 6 lines · Mark Brown
Quoted 3 lines · Daniel Scally

It also creates some problems to suppress the enumeration of the i2c device via ACPI (which we'll have to do in a machine specific fashion, because some laptops have this chip with properly configured ACPI and

To be clear I think that's a terrible idea.

If you're talking about the ACPI implementation on those machines, nobody disagrees :-)

Quoted 6 lines
Quoted 4 lines

To make sure I understand you correctly, do you advocate for suppressing registration of the I2C devices from ACPI and instantiate them from board code instead, or to somehow supplement the I2C device with board-specific data ?

No, to repeat yet again that is what I think is a terrible idea.

Which of those two ? :-)

Signature · 3 lines
Regards,

Laurent Pinchart
maintainer
#22 lore raw
Quoted 10 lines · Laurent Pinchart
Quoted 6 lines · Mark Brown
Quoted 4 lines

To make sure I understand you correctly, do you advocate for suppressing registration of the I2C devices from ACPI and instantiate them from board code instead, or to somehow supplement the I2C device with board-specific data ?

No, to repeat yet again that is what I think is a terrible idea.

Which of those two ? :-)

Suppressing the registration data. Frankly the way that ACPI systems rely so extensively on OS provided fixups on non-server systems while still being deployed routinely there is also a substantial failure, but it's not quite so bad.

#23 lore raw
In reply to Mark Brown
Quoted 12 lines · Mark Brown
Quoted 9 lines · Daniel Scally

I do think it can simplify driver code too; a lot of them aren't written to parse platform data to get the init data, as they're just relying on reading it from devicetree so in the event that we get more cases like this, we need to modify those drivers to look for platform data too. On the other hand, even the drivers that don't directly call of_get_regulator_init_data() still do that lookup during the regulator_of_get_init_data() call in regulator_register(), so the ones that do parse platform data for init_data structs will check DT as part of regulator_register() anyway. Imitating that seems simpler to me.

Quoted 5 lines

The driver code is trivial boilerplate, assuming someone doesn't go and implement a helper to register stuff separately like I suggested. The proposed swnode stuff would involve duplicating the DT parsing code. This seems like a whole lot of effort for something that provides a worse result than either of the existing things.

I'm not sure I follow. Where did you see the duplication when I saw the other way around?
Converting code from OF to fwnode APIs in most cases is smooth and doesn't add any overhead to the codebase,

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#24 lore raw
Quoted 10 lines · Andy Shevchenko
Quoted 5 lines · Mark Brown

The driver code is trivial boilerplate, assuming someone doesn't go and implement a helper to register stuff separately like I suggested. The proposed swnode stuff would involve duplicating the DT parsing code. This seems like a whole lot of effort for something that provides a worse result than either of the existing things.

I'm not sure I follow. Where did you see the duplication when I saw the other way around?

The current patch consists entirely of additions, it does not remove any existing code at all, the diffstat is:

 5 files changed, 174 insertions(+)
Quoted 2 lines

Converting code from OF to fwnode APIs in most cases is smooth and doesn't add any overhead to the codebase,

We explicitly do not want to attempt to parse regulator properties out of ACPI platform descriptions because using the regulator binding on ACPI platforms conflicts with the ACPI model for power management and we really don't want to encourage platforms to attempt to mix and match here, it's not going to lead to anything robust. System integrators that need this sort of OS visible low level power management really should be working with the UEFI forum to get an ACPI specification for it, or if they don't really need it fixing up their AML to DTRT.

If you were to say that we could bodge around that by somehow forcing this binding to exist only for swnodes when running on ACPI systems then we'd still have the problems with creating something with worse tooling than what's there already.

Like I said in the other mail fwnode is a nice hack for systems that are using ACPI but have hardware that's doing something totally outside the ACPI model to allow them to reuse work that's been done for DT, it's not a universal solution to the lack of appropriate support for describing modern systems in ACPI.

#25 lore raw
Quoted 10 lines · Mark Brown
Quoted 7 lines · Andy Shevchenko
Quoted 5 lines · Mark Brown

The driver code is trivial boilerplate, assuming someone doesn't go and implement a helper to register stuff separately like I suggested. The proposed swnode stuff would involve duplicating the DT parsing code. This seems like a whole lot of effort for something that provides a worse result than either of the existing things.

Quoted 7 lines
Quoted 2 lines

I'm not sure I follow. Where did you see the duplication when I saw the other way around?

The current patch consists entirely of additions, it does not remove any existing code at all, the diffstat is:

 5 files changed, 174 insertions(+)

Ah, okay, you are talking with regard to the current patch. I talked in generic terms.

Quoted 11 lines
Quoted 2 lines

Converting code from OF to fwnode APIs in most cases is smooth and doesn't add any overhead to the codebase,

We explicitly do not want to attempt to parse regulator properties out of ACPI platform descriptions because using the regulator binding on ACPI platforms conflicts with the ACPI model for power management and we really don't want to encourage platforms to attempt to mix and match here, it's not going to lead to anything robust. System integrators that need this sort of OS visible low level power management really should be working with the UEFI forum to get an ACPI specification for it, or if they don't really need it fixing up their AML to DTRT.

No-one is objecting to this. I agree that integration of regulators and ACPI should be done in a specific way if needed at all.

Quoted 4 lines

If you were to say that we could bodge around that by somehow forcing this binding to exist only for swnodes when running on ACPI systems then we'd still have the problems with creating something with worse tooling than what's there already.

Of course, no objections to this.

Quoted 5 lines

Like I said in the other mail fwnode is a nice hack for systems that are using ACPI but have hardware that's doing something totally outside the ACPI model to allow them to reuse work that's been done for DT, it's not a universal solution to the lack of appropriate support for describing modern systems in ACPI.

In some (I suppose rear) cases it may be used by DT-enabled platforms as well. I can imagine the case when you have a system in ROM and only what you can do to change DTB there is either use DT overlays (which seems to be not working, plenty of gaps there according to a Wiki I saw once) or do something in the board files.

So, if you replace "ACPI" with the "firmware resource provider" in the above paragraph, I will agree 100% with you.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#26 lore raw
Quoted 8 lines · Andy Shevchenko
Quoted 5 lines · Mark Brown

Like I said in the other mail fwnode is a nice hack for systems that are using ACPI but have hardware that's doing something totally outside the ACPI model to allow them to reuse work that's been done for DT, it's not a universal solution to the lack of appropriate support for describing modern systems in ACPI.

Quoted 5 lines

In some (I suppose rear) cases it may be used by DT-enabled platforms as well. I can imagine the case when you have a system in ROM and only what you can do to change DTB there is either use DT overlays (which seems to be not working, plenty of gaps there according to a Wiki I saw once) or do something in the board files.

DT overlays are pretty extensively deployed, it's just that there's very few use cases where it's done in the kernel - it tends to be better to do them in either the firmware or a thin wrapper around the kernel so that the kernel never has to see an unfixed DT, and we don't have to try to do fixups super early in the boot on a supposedly generic kernel. The main kernel use cases are things like FPGAs loading a dynamic image and matching DT at runtime which is a whole additional ball of fun.

#27 lore raw
In reply to Mark Brown

Hi Mark,

Quoted 34 lines · Mark Brown
Quoted 10 lines · Andy Shevchenko
Quoted 5 lines · Mark Brown

The driver code is trivial boilerplate, assuming someone doesn't go and implement a helper to register stuff separately like I suggested. The proposed swnode stuff would involve duplicating the DT parsing code. This seems like a whole lot of effort for something that provides a worse result than either of the existing things.

I'm not sure I follow. Where did you see the duplication when I saw the other way around?

The current patch consists entirely of additions, it does not remove any existing code at all, the diffstat is:

 5 files changed, 174 insertions(+)
Quoted 2 lines

Converting code from OF to fwnode APIs in most cases is smooth and doesn't add any overhead to the codebase,

We explicitly do not want to attempt to parse regulator properties out of ACPI platform descriptions because using the regulator binding on ACPI platforms conflicts with the ACPI model for power management and we really don't want to encourage platforms to attempt to mix and match here, it's not going to lead to anything robust. System integrators that need this sort of OS visible low level power management really should be working with the UEFI forum to get an ACPI specification for it, or if they don't really need it fixing up their AML to DTRT.

If you were to say that we could bodge around that by somehow forcing this binding to exist only for swnodes when running on ACPI systems then we'd still have the problems with creating something with worse tooling than what's there already.

Quoted 5 lines

Like I said in the other mail fwnode is a nice hack for systems that are using ACPI but have hardware that's doing something totally outside the ACPI model to allow them to reuse work that's been done for DT, it's not a universal solution to the lack of appropriate support for describing modern systems in ACPI.

fwnode, as an abstraction of ACPI and OF, is quite useful for camera sensor drivers for instance. They need to read firmware properties (for instance to identify whether a camera is located on the front or back of the device, or to what port of the SoC it's connected), and being able to do so without duplicating OF and ACPI code in drivers is useful.

swnode, on the other hand, is indeed more of a workaround for a more-often-than-not broken ACPI implementation. It's ironic to think that x86 ACPI-based systems, touted as being superior to ARM, are now in a worst state than OF-based systems.

Signature · 3 lines
Regards,

Laurent Pinchart
maintainer
#28 lore raw
Quoted 8 lines · Laurent Pinchart
Quoted 5 lines · Mark Brown

Like I said in the other mail fwnode is a nice hack for systems that are using ACPI but have hardware that's doing something totally outside the ACPI model to allow them to reuse work that's been done for DT, it's not a universal solution to the lack of appropriate support for describing modern systems in ACPI.

Quoted 5 lines

fwnode, as an abstraction of ACPI and OF, is quite useful for camera sensor drivers for instance. They need to read firmware properties (for instance to identify whether a camera is located on the front or back of the device, or to what port of the SoC it's connected), and being able to do so without duplicating OF and ACPI code in drivers is useful.

I'd still say that's a bit of a hack, it's the sort of area where ACPI just has absolutely no handling at all and so picking up the DT bindings will work effectively although it results in something that's really not at all idiomatic for ACPI since idiomatic DT and idiomatic ACPI don't really look like each other and AIUI this stuff isn't getting adopted for actual firmware (as opposed to swnodes) outside of the embedded x86 space.

Quoted 4 lines

swnode, on the other hand, is indeed more of a workaround for a more-often-than-not broken ACPI implementation. It's ironic to think that x86 ACPI-based systems, touted as being superior to ARM, are now in a worst state than OF-based systems.

The unfortunate thing is that ACPI is super limited in what systems it models, making assumptions that only really work for fairly simple server class systems. Outside of that the models it's offering just can't cope with actual hardware yet people still insist on building those systems with ACPI system descriptions so you end up with huge piles of platform quirks. Audio support for modern x86 laptops is just an endless procession of quirks :(

#29 lore raw
Quoted 15 lines · Mark Brown
Quoted 8 lines · Laurent Pinchart
Quoted 5 lines · Mark Brown

Like I said in the other mail fwnode is a nice hack for systems that are using ACPI but have hardware that's doing something totally outside the ACPI model to allow them to reuse work that's been done for DT, it's not a universal solution to the lack of appropriate support for describing modern systems in ACPI.

Quoted 5 lines

fwnode, as an abstraction of ACPI and OF, is quite useful for camera sensor drivers for instance. They need to read firmware properties (for instance to identify whether a camera is located on the front or back of the device, or to what port of the SoC it's connected), and being able to do so without duplicating OF and ACPI code in drivers is useful.

Quoted 7 lines

I'd still say that's a bit of a hack, it's the sort of area where ACPI just has absolutely no handling at all and so picking up the DT bindings will work effectively although it results in something that's really not at all idiomatic for ACPI since idiomatic DT and idiomatic ACPI don't really look like each other and AIUI this stuff isn't getting adopted for actual firmware (as opposed to swnodes) outside of the embedded x86 space.

It's only one data point, but we're seeing adoption of the ACPI DT-in-DSD for camera. It's still not pretty of course.

Quoted 5 lines
Quoted 4 lines

swnode, on the other hand, is indeed more of a workaround for a more-often-than-not broken ACPI implementation. It's ironic to think that x86 ACPI-based systems, touted as being superior to ARM, are now in a worst state than OF-based systems.

Quoted 7 lines

The unfortunate thing is that ACPI is super limited in what systems it models, making assumptions that only really work for fairly simple server class systems. Outside of that the models it's offering just can't cope with actual hardware yet people still insist on building those systems with ACPI system descriptions so you end up with huge piles of platform quirks. Audio support for modern x86 laptops is just an endless procession of quirks :(

I feel your pain. On the camera side, we have a case of an I2C controller that has a PCI driver in the kernel used when dealing with the camera sensor, and an AML "driver" used by an I2C GPIO expander, completely modelled in the DSDT. Both poke the same PCI registers of the I2C controller. I tried to get information from Intel on how this was meant to be handled, but I think the people responsible for the design have been exfiltrated to Guantanamo, or are expiating their sins in a monastery lost in a mountain.

Once travel will be easier again, we'll plot a take over of the world in a bar. Dealing with ACPI requires lots of whisky :-)

Signature · 3 lines
Regards,

Laurent Pinchart
maintainer
#30 lore raw
Quoted 8 lines · Laurent Pinchart
Quoted 3 lines · Mark Brown

really look like each other and AIUI this stuff isn't getting adopted for actual firmware (as opposed to swnodes) outside of the embedded x86 space.

It's only one data point, but we're seeing adoption of the ACPI DT-in-DSD for camera. It's still not pretty of course.

By non-Linux system vendors? My understanding has been that for audio people are just unwilling to provide the level of firmware description required to avoid quirks, there was some limited stuff with the NHLT table but it still required system software to quirk things. If there's progress elsewhere perhaps the relevant people can be persuaded to have another go...

Quoted 2 lines

Once travel will be easier again, we'll plot a take over of the world in a bar. Dealing with ACPI requires lots of whisky :-)

Indeed!

#31 lore raw
Quoted 11 lines · Mark Brown
Quoted 8 lines · Laurent Pinchart
Quoted 3 lines · Mark Brown

really look like each other and AIUI this stuff isn't getting adopted for actual firmware (as opposed to swnodes) outside of the embedded x86 space.

It's only one data point, but we're seeing adoption of the ACPI DT-in-DSD for camera. It's still not pretty of course.

By non-Linux system vendors?

For Windows-based machines, yes. It's fairly new, and the information I have is that those machines may ship DSDT containing both Windows-style (read: crap) data and Linux-style data for the same nodes. My fear is that only the former will be properly tested and the latter will thus be incorrect. The future will tell (I'm as usual very hopeful).

Quoted 10 lines

My understanding has been that for audio people are just unwilling to provide the level of firmware description required to avoid quirks, there was some limited stuff with the NHLT table but it still required system software to quirk things. If there's progress elsewhere perhaps the relevant people can be persuaded to have another go...

Quoted 2 lines

Once travel will be easier again, we'll plot a take over of the world in a bar. Dealing with ACPI requires lots of whisky :-)

Indeed!

Signature · 3 lines
Regards,

Laurent Pinchart
maintainer
#32 lore raw
Quoted 6 lines · Laurent Pinchart
Quoted 4 lines · Mark Brown
Quoted 2 lines · Laurent Pinchart

It's only one data point, but we're seeing adoption of the ACPI DT-in-DSD for camera. It's still not pretty of course.

Quoted 7 lines
Quoted 1 line

By non-Linux system vendors?

For Windows-based machines, yes. It's fairly new, and the information I have is that those machines may ship DSDT containing both Windows-style (read: crap) data and Linux-style data for the same nodes. My fear is that only the former will be properly tested and the latter will thus be incorrect. The future will tell (I'm as usual very hopeful).

Adding the Intel audio people - it'd be good if we could get some similar stuff started for the audio things. Sadly in these sorts of cases AIUI the Windows thing is broadly to match DMI data and supply platform data so it's more a case of just not having essential information in firmware, a bad format would be better TBH (assuming it's accurate which also requires loads of quirks...).

#33 lore raw
Quoted 14 lines · Mark Brown
Quoted 5 lines · Laurent Pinchart
Quoted 4 lines · Mark Brown
Quoted 2 lines · Laurent Pinchart

It's only one data point, but we're seeing adoption of the ACPI DT-in-DSD for camera. It's still not pretty of course.

Quoted 7 lines
Quoted 1 line

By non-Linux system vendors?

For Windows-based machines, yes. It's fairly new, and the information I have is that those machines may ship DSDT containing both Windows-style (read: crap) data and Linux-style data for the same nodes. My fear is that only the former will be properly tested and the latter will thus be incorrect. The future will tell (I'm as usual very hopeful).

Quoted 6 lines

Adding the Intel audio people - it'd be good if we could get some similar stuff started for the audio things. Sadly in these sorts of cases AIUI the Windows thing is broadly to match DMI data and supply platform data so it's more a case of just not having essential information in firmware, a bad format would be better TBH (assuming it's accurate which also requires loads of quirks...).

On the camera side, the Windows-based machines I've worked with (Skylake and Kabylak) have data in the DSDT. There's data we can use directly, and there's a lot that is hardcoded in the Windows driver (including what voltage to program on the different outputs of an I2C-controlled regulator - you get that wrong, you fry your camera). I believe Intel provides a small set of reference designs with several options to the OEMs, and I wouldn't be surprised if some of the data present in ACPI that we don't know how to interpret would identify these options. I don't think the Windows driver has DMI-based quirks, the driver isn't machine-specific as far as I can tell.

For newer devices, ACPI should contain Windows data in a format that the Windows team decides on its own, and data that is actually usable in the _DSD for Linux. I've also heard that the power management would be saner, with PM actually implemented in the DSDT. I haven't seen those DSDT yet though.

Signature · 3 lines
Regards,

Laurent Pinchart
#34 lore raw
In reply to Mark Brown

Hi Mark

Quoted 11 lines · Mark Brown
Quoted 9 lines · Daniel Scally

I do think it can simplify driver code too; a lot of them aren't written to parse platform data to get the init data, as they're just relying on reading it from devicetree so in the event that we get more cases like this, we need to modify those drivers to look for platform data too. On the other hand, even the drivers that don't directly call of_get_regulator_init_data() still do that lookup during the regulator_of_get_init_data() call in regulator_register(), so the ones that do parse platform data for init_data structs will check DT as part of regulator_register() anyway. Imitating that seems simpler to me.

Quoted 5 lines

The driver code is trivial boilerplate, assuming someone doesn't go and implement a helper to register stuff separately like I suggested. The proposed swnode stuff would involve duplicating the DT parsing code. This seems like a whole lot of effort for something that provides a worse result than either of the existing things.

Alright - let me look at adding a helper to register them instead then.

Quoted 4 lines
Quoted 3 lines

It also creates some problems to suppress the enumeration of the i2c device via ACPI (which we'll have to do in a machine specific fashion, because some laptops have this chip with properly configured ACPI and

To be clear I think that's a terrible idea.

Me too. I thought you were suggesting that I do that - sorry to have misunderstood there. The problem we're trying to resolve here is kinda exacerbated by a lot non-standard stuff within the ACPI for these devices, so for example, on top of not having any power management AML (which is what I'm trying to fix up here), the ACPI device can actually represent a bunch of different things that might be a TPS68470 PMIC, a different PMIC entirely or even not a physical PMIC at all, but rather just a convenient dummy device to collect a bunch of GPIOs under. Which one it is is revealed by parsing a buffer out of the device's ACPI, so we need the ACPI enumeration to be able to use that properly.

Part of the reasons I went with addressing this with software nodes is that we've used them to correct other deficiencies in the ACPI on the same devices, like the references between the cameras and the image signal processor ought to be described in _DSD packages [1], but are again just hidden inside a buffer that we need to parse to figure out the right way to make the connection, and then we used software nodes to represent that. The difference there is that that's implementing something that should have been there in the first place, whereas the regulators wouldn't ordinarily be described in this way.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

down to being another data table, I imagine you could write a helper for it, or probably even come up with some generic thing that let you register a platform data/DMI combo independently of the driver to get it out of the driver code (looking more like the existing GPIO code which is already being used in another bit of this quirking).

Quoted 7 lines
Quoted 5 lines

The advantage of the GPIO lookups is there's no need to have the pointer to the registered devices to register the lookup table; we could imitate that, by adding entries to a list with the lookup values being device and regulator name (with the init data as the thing that's "looked up") and check for those during regulator_register() maybe?

Like I keep saying I think that's a much better approach than trying to use swnodes, they just seem like a terrible fit for the problem.

Okedokey; I'm happy to take another look at it from this angle then - thanks for the feedback.

[1]
https://www.kernel.org/doc/html/latest/firmware-guide/acpi/dsd/graph.html

#35 lore raw
In reply to Daniel Scally

Hi Dan,

Quoted 28 lines · Daniel Scally

Hello all

See previous series for some background context [1]

Some x86 laptops with ACPI tables designed for Windows have a TPS68470 PMIC providing regulators and clocks to camera modules. The DSDT tables for those cameras lack any power control methods, declaring only a dependency on the ACPI device representing the TPS68470. This leaves the regulator framework with no means of determining appropriate voltages for the regulators provided by the PMIC, or of determining which regulators relate to which of the sensor's requested supplies.

This series is a prototype of an emulation of the device tree regulator initialisation and lookup functions, using software nodes. Software nodes relating to each regulator are registered as children of the TPS68470's ACPI firmware node. Those regulators have properties describing their constraints (for example "regulator-min-microvolt"). Similarly, software nodes are registered and assigned as secondary to the Camera's firmware node - these software nodes have reference properties named after the supply in the same way as device tree's phandles, for example "avdd-supply", and linking to the software node assigned to the appropriate regulator. We can then use those constraints to specify the appropriate voltages and the references to allow the camera drivers to look up the correct regulator device.

Although not included in this series, I would plan to use a similar method for linking the clocks provided by the TPS68470 to the sensor so that it can be discovered too.

Quoted 7 lines

I'm posting this to see if people agree it's a good approach for tackling the problem; I may be overthinking this and there's a much easier way that I should be looking at instead. It will have knock-ons in the cio2-bridge code [2], as that is adding software nodes to the same sensors to connect them to the media graph. Similarly, is the board file an acceptable solution, or should we just define the configuration for these devices (there's three orf our laptop models in scope) in int3472-tps68470 instead?

I may have missed something, but if you load the SGo2 board file, won't it create the regulator software nodes if it finds an INT3472, regardless of whether the device is an SGo2 ? If you happen to do so on a machine that requires different voltages, that sounds dangerous.

Given that INT3472 models the virtual "Intel Skylake and Kabylake camera PMIC", I think moving device-specific information to the int3472 driver may make sense. I'm unsure what option is best though, having all the data (regulators, clocks, but also data currently stored in the cio2-bridge driver) in a single file (or a single file per machine) is tempting.

Quoted 21 lines

[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://elixir.bootlin.com/linux/latest/source/drivers/media/pci/intel/ipu3/cio2-bridge.c#L166

Daniel Scally (2):
regulator: Add support for software node connections platform/surface: Add Surface Go 2 board file

 MAINTAINERS                                |   6 +
 drivers/platform/surface/Kconfig           |  10 ++
 drivers/platform/surface/Makefile          |   1 +
 drivers/platform/surface/surface_go_2.c    | 135 +++++++++++++++++++++
 drivers/regulator/Kconfig                  |   6 +
 drivers/regulator/Makefile                 |   1 +
 drivers/regulator/core.c                   |  23 ++++
 drivers/regulator/swnode_regulator.c       | 111 +++++++++++++++++
 include/linux/regulator/swnode_regulator.h |  33 +++++
 9 files changed, 326 insertions(+)
 create mode 100644 drivers/platform/surface/surface_go_2.c
 create mode 100644 drivers/regulator/swnode_regulator.c
 create mode 100644 include/linux/regulator/swnode_regulator.h
Signature · 3 lines
Regards,

Laurent Pinchart
#36 lore raw

Hi Laurent

Quoted 38 lines · Laurent Pinchart

Hi Dan,

Quoted 28 lines · Daniel Scally

Hello all

See previous series for some background context [1]

Some x86 laptops with ACPI tables designed for Windows have a TPS68470 PMIC providing regulators and clocks to camera modules. The DSDT tables for those cameras lack any power control methods, declaring only a dependency on the ACPI device representing the TPS68470. This leaves the regulator framework with no means of determining appropriate voltages for the regulators provided by the PMIC, or of determining which regulators relate to which of the sensor's requested supplies.

This series is a prototype of an emulation of the device tree regulator initialisation and lookup functions, using software nodes. Software nodes relating to each regulator are registered as children of the TPS68470's ACPI firmware node. Those regulators have properties describing their constraints (for example "regulator-min-microvolt"). Similarly, software nodes are registered and assigned as secondary to the Camera's firmware node - these software nodes have reference properties named after the supply in the same way as device tree's phandles, for example "avdd-supply", and linking to the software node assigned to the appropriate regulator. We can then use those constraints to specify the appropriate voltages and the references to allow the camera drivers to look up the correct regulator device.

Although not included in this series, I would plan to use a similar method for linking the clocks provided by the TPS68470 to the sensor so that it can be discovered too.

Quoted 7 lines

I'm posting this to see if people agree it's a good approach for tackling the problem; I may be overthinking this and there's a much easier way that I should be looking at instead. It will have knock-ons in the cio2-bridge code [2], as that is adding software nodes to the same sensors to connect them to the media graph. Similarly, is the board file an acceptable solution, or should we just define the configuration for these devices (there's three orf our laptop models in scope) in int3472-tps68470 instead?

Quoted 4 lines

I may have missed something, but if you load the SGo2 board file, won't it create the regulator software nodes if it finds an INT3472, regardless of whether the device is an SGo2 ? If you happen to do so on a machine that requires different voltages, that sounds dangerous.

Ah, yes - hadn't thought of that. If a driver registered regulators with those names, it would try to apply those voltages during registration. Good point.

Quoted 6 lines

Given that INT3472 models the virtual "Intel Skylake and Kabylake camera PMIC", I think moving device-specific information to the int3472 driver may make sense. I'm unsure what option is best though, having all the data (regulators, clocks, but also data currently stored in the cio2-bridge driver) in a single file (or a single file per machine) is tempting.

It is tempting, particularly because (assuming we do end up using this approach) setting the references to the supplies in a board file like this complicated the cio2-bridge code quite a bit, since it then needs to extend the properties array against an already-existing software node rather than registering a new one. But then, I don't particularly want to handle that aspect of the problem in two separate places.

Quoted 21 lines
Quoted 21 lines

[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://elixir.bootlin.com/linux/latest/source/drivers/media/pci/intel/ipu3/cio2-bridge.c#L166

Daniel Scally (2):
regulator: Add support for software node connections platform/surface: Add Surface Go 2 board file

 MAINTAINERS                                |   6 +
 drivers/platform/surface/Kconfig           |  10 ++
 drivers/platform/surface/Makefile          |   1 +
 drivers/platform/surface/surface_go_2.c    | 135 +++++++++++++++++++++
 drivers/regulator/Kconfig                  |   6 +
 drivers/regulator/Makefile                 |   1 +
 drivers/regulator/core.c                   |  23 ++++
 drivers/regulator/swnode_regulator.c       | 111 +++++++++++++++++
 include/linux/regulator/swnode_regulator.h |  33 +++++
 9 files changed, 326 insertions(+)
 create mode 100644 drivers/platform/surface/surface_go_2.c
 create mode 100644 drivers/regulator/swnode_regulator.c
 create mode 100644 include/linux/regulator/swnode_regulator.h
#37 lore raw

Hi Dan,

Quoted 54 lines · Daniel Scally
Quoted 37 lines · Laurent Pinchart
Quoted 28 lines · Daniel Scally

Hello all

See previous series for some background context [1]

Some x86 laptops with ACPI tables designed for Windows have a TPS68470 PMIC providing regulators and clocks to camera modules. The DSDT tables for those cameras lack any power control methods, declaring only a dependency on the ACPI device representing the TPS68470. This leaves the regulator framework with no means of determining appropriate voltages for the regulators provided by the PMIC, or of determining which regulators relate to which of the sensor's requested supplies.

This series is a prototype of an emulation of the device tree regulator initialisation and lookup functions, using software nodes. Software nodes relating to each regulator are registered as children of the TPS68470's ACPI firmware node. Those regulators have properties describing their constraints (for example "regulator-min-microvolt"). Similarly, software nodes are registered and assigned as secondary to the Camera's firmware node - these software nodes have reference properties named after the supply in the same way as device tree's phandles, for example "avdd-supply", and linking to the software node assigned to the appropriate regulator. We can then use those constraints to specify the appropriate voltages and the references to allow the camera drivers to look up the correct regulator device.

Although not included in this series, I would plan to use a similar method for linking the clocks provided by the TPS68470 to the sensor so that it can be discovered too.

Quoted 7 lines

I'm posting this to see if people agree it's a good approach for tackling the problem; I may be overthinking this and there's a much easier way that I should be looking at instead. It will have knock-ons in the cio2-bridge code [2], as that is adding software nodes to the same sensors to connect them to the media graph. Similarly, is the board file an acceptable solution, or should we just define the configuration for these devices (there's three orf our laptop models in scope) in int3472-tps68470 instead?

Quoted 4 lines

I may have missed something, but if you load the SGo2 board file, won't it create the regulator software nodes if it finds an INT3472, regardless of whether the device is an SGo2 ? If you happen to do so on a machine that requires different voltages, that sounds dangerous.

Ah, yes - hadn't thought of that. If a driver registered regulators with those names, it would try to apply those voltages during registration. Good point.

Quoted 6 lines

Given that INT3472 models the virtual "Intel Skylake and Kabylake camera PMIC", I think moving device-specific information to the int3472 driver may make sense. I'm unsure what option is best though, having all the data (regulators, clocks, but also data currently stored in the cio2-bridge driver) in a single file (or a single file per machine) is tempting.

Quoted 6 lines

It is tempting, particularly because (assuming we do end up using this approach) setting the references to the supplies in a board file like this complicated the cio2-bridge code quite a bit, since it then needs to extend the properties array against an already-existing software node rather than registering a new one. But then, I don't particularly want to handle that aspect of the problem in two separate places.

If technically feasible, gathering all the data in a single place would be my preference. Whether that should take the form of software nodes in all cases, or be modelled as custom data that the int3472 driver would interpret to create the regulators and clocks is a different (but related) question.

The very important part is to ensure that the correct board data will be used, as otherwise we could damage the hardware.

Quoted 21 lines
Quoted 21 lines
Quoted 21 lines

[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://elixir.bootlin.com/linux/latest/source/drivers/media/pci/intel/ipu3/cio2-bridge.c#L166

Daniel Scally (2):
regulator: Add support for software node connections platform/surface: Add Surface Go 2 board file

 MAINTAINERS                                |   6 +
 drivers/platform/surface/Kconfig           |  10 ++
 drivers/platform/surface/Makefile          |   1 +
 drivers/platform/surface/surface_go_2.c    | 135 +++++++++++++++++++++
 drivers/regulator/Kconfig                  |   6 +
 drivers/regulator/Makefile                 |   1 +
 drivers/regulator/core.c                   |  23 ++++
 drivers/regulator/swnode_regulator.c       | 111 +++++++++++++++++
 include/linux/regulator/swnode_regulator.h |  33 +++++
 9 files changed, 326 insertions(+)
 create mode 100644 drivers/platform/surface/surface_go_2.c
 create mode 100644 drivers/regulator/swnode_regulator.c
 create mode 100644 include/linux/regulator/swnode_regulator.h
Signature · 3 lines
Regards,

Laurent Pinchart
#38 lore raw

Hi Laurent

Quoted 60 lines · Laurent Pinchart

Hi Dan,

Quoted 51 lines · Daniel Scally
Quoted 36 lines · Laurent Pinchart
Quoted 28 lines · Daniel Scally

Hello all

See previous series for some background context [1]

Some x86 laptops with ACPI tables designed for Windows have a TPS68470 PMIC providing regulators and clocks to camera modules. The DSDT tables for those cameras lack any power control methods, declaring only a dependency on the ACPI device representing the TPS68470. This leaves the regulator framework with no means of determining appropriate voltages for the regulators provided by the PMIC, or of determining which regulators relate to which of the sensor's requested supplies.

This series is a prototype of an emulation of the device tree regulator initialisation and lookup functions, using software nodes. Software nodes relating to each regulator are registered as children of the TPS68470's ACPI firmware node. Those regulators have properties describing their constraints (for example "regulator-min-microvolt"). Similarly, software nodes are registered and assigned as secondary to the Camera's firmware node - these software nodes have reference properties named after the supply in the same way as device tree's phandles, for example "avdd-supply", and linking to the software node assigned to the appropriate regulator. We can then use those constraints to specify the appropriate voltages and the references to allow the camera drivers to look up the correct regulator device.

Although not included in this series, I would plan to use a similar method for linking the clocks provided by the TPS68470 to the sensor so that it can be discovered too.

Quoted 7 lines

I'm posting this to see if people agree it's a good approach for tackling the problem; I may be overthinking this and there's a much easier way that I should be looking at instead. It will have knock-ons in the cio2-bridge code [2], as that is adding software nodes to the same sensors to connect them to the media graph. Similarly, is the board file an acceptable solution, or should we just define the configuration for these devices (there's three orf our laptop models in scope) in int3472-tps68470 instead?

Quoted 4 lines

I may have missed something, but if you load the SGo2 board file, won't it create the regulator software nodes if it finds an INT3472, regardless of whether the device is an SGo2 ? If you happen to do so on a machine that requires different voltages, that sounds dangerous.

Ah, yes - hadn't thought of that. If a driver registered regulators with those names, it would try to apply those voltages during registration. Good point.

Quoted 6 lines

Given that INT3472 models the virtual "Intel Skylake and Kabylake camera PMIC", I think moving device-specific information to the int3472 driver may make sense. I'm unsure what option is best though, having all the data (regulators, clocks, but also data currently stored in the cio2-bridge driver) in a single file (or a single file per machine) is tempting.

Quoted 6 lines

It is tempting, particularly because (assuming we do end up using this approach) setting the references to the supplies in a board file like this complicated the cio2-bridge code quite a bit, since it then needs to extend the properties array against an already-existing software node rather than registering a new one. But then, I don't particularly want to handle that aspect of the problem in two separate places.

Quoted 5 lines

If technically feasible, gathering all the data in a single place would be my preference. Whether that should take the form of software nodes in all cases, or be modelled as custom data that the int3472 driver would interpret to create the regulators and clocks is a different (but related) question.

I'll have to think on that one then; the problem there is that the cio2-bridge is just given ACPI HIDs for the sensors as "ok to parse this", and of course the INT347A that is being dealt with here should already be supported on most Surface platforms via the intel-skl-int3472 stuff, so once the ov8865 edits are (posted and) accepted and that driver is supported my plan would be to add it into the bridge. So we'd need a way to exclude Go2 from that if we wanted to define all the software nodes parts in a single board file instead.

Quoted 3 lines

The very important part is to ensure that the correct board data will be used, as otherwise we could damage the hardware.

Not sure how this is usually guarded against; we could do a DMI match at the start of the init function to confirm it's running on a Go2 and exit if not?

Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines

[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://elixir.bootlin.com/linux/latest/source/drivers/media/pci/intel/ipu3/cio2-bridge.c#L166

Daniel Scally (2):
regulator: Add support for software node connections platform/surface: Add Surface Go 2 board file

 MAINTAINERS                                |   6 +
 drivers/platform/surface/Kconfig           |  10 ++
 drivers/platform/surface/Makefile          |   1 +
 drivers/platform/surface/surface_go_2.c    | 135 +++++++++++++++++++++
 drivers/regulator/Kconfig                  |   6 +
 drivers/regulator/Makefile                 |   1 +
 drivers/regulator/core.c                   |  23 ++++
 drivers/regulator/swnode_regulator.c       | 111 +++++++++++++++++
 include/linux/regulator/swnode_regulator.h |  33 +++++
 9 files changed, 326 insertions(+)
 create mode 100644 drivers/platform/surface/surface_go_2.c
 create mode 100644 drivers/regulator/swnode_regulator.c
 create mode 100644 include/linux/regulator/swnode_regulator.h
#39 lore raw

Hi Dan,

Quoted 78 lines · Daniel Scally
Quoted 62 lines · Laurent Pinchart
Quoted 54 lines · Daniel Scally
Quoted 37 lines · Laurent Pinchart
Quoted 28 lines · Daniel Scally

Hello all

See previous series for some background context [1]

Some x86 laptops with ACPI tables designed for Windows have a TPS68470 PMIC providing regulators and clocks to camera modules. The DSDT tables for those cameras lack any power control methods, declaring only a dependency on the ACPI device representing the TPS68470. This leaves the regulator framework with no means of determining appropriate voltages for the regulators provided by the PMIC, or of determining which regulators relate to which of the sensor's requested supplies.

This series is a prototype of an emulation of the device tree regulator initialisation and lookup functions, using software nodes. Software nodes relating to each regulator are registered as children of the TPS68470's ACPI firmware node. Those regulators have properties describing their constraints (for example "regulator-min-microvolt"). Similarly, software nodes are registered and assigned as secondary to the Camera's firmware node - these software nodes have reference properties named after the supply in the same way as device tree's phandles, for example "avdd-supply", and linking to the software node assigned to the appropriate regulator. We can then use those constraints to specify the appropriate voltages and the references to allow the camera drivers to look up the correct regulator device.

Although not included in this series, I would plan to use a similar method for linking the clocks provided by the TPS68470 to the sensor so that it can be discovered too.

Quoted 7 lines

I'm posting this to see if people agree it's a good approach for tackling the problem; I may be overthinking this and there's a much easier way that I should be looking at instead. It will have knock-ons in the cio2-bridge code [2], as that is adding software nodes to the same sensors to connect them to the media graph. Similarly, is the board file an acceptable solution, or should we just define the configuration for these devices (there's three orf our laptop models in scope) in int3472-tps68470 instead?

Quoted 4 lines

I may have missed something, but if you load the SGo2 board file, won't it create the regulator software nodes if it finds an INT3472, regardless of whether the device is an SGo2 ? If you happen to do so on a machine that requires different voltages, that sounds dangerous.

Ah, yes - hadn't thought of that. If a driver registered regulators with those names, it would try to apply those voltages during registration. Good point.

Quoted 6 lines

Given that INT3472 models the virtual "Intel Skylake and Kabylake camera PMIC", I think moving device-specific information to the int3472 driver may make sense. I'm unsure what option is best though, having all the data (regulators, clocks, but also data currently stored in the cio2-bridge driver) in a single file (or a single file per machine) is tempting.

Quoted 6 lines

It is tempting, particularly because (assuming we do end up using this approach) setting the references to the supplies in a board file like this complicated the cio2-bridge code quite a bit, since it then needs to extend the properties array against an already-existing software node rather than registering a new one. But then, I don't particularly want to handle that aspect of the problem in two separate places.

Quoted 5 lines

If technically feasible, gathering all the data in a single place would be my preference. Whether that should take the form of software nodes in all cases, or be modelled as custom data that the int3472 driver would interpret to create the regulators and clocks is a different (but related) question.

I'll have to think on that one then; the problem there is that the cio2-bridge is just given ACPI HIDs for the sensors as "ok to parse this", and of course the INT347A that is being dealt with here should already be supported on most Surface platforms via the intel-skl-int3472 stuff, so once the ov8865 edits are (posted and) accepted and that driver is supported my plan would be to add it into the bridge. So we'd need a way to exclude Go2 from that if we wanted to define all the software nodes parts in a single board file instead.

Quoted 6 lines
Quoted 2 lines

The very important part is to ensure that the correct board data will be used, as otherwise we could damage the hardware.

Not sure how this is usually guarded against; we could do a DMI match at the start of the init function to confirm it's running on a Go2 and exit if not?

Unless the information is available in ACPI properties that the CIO2 bridge driver can access (and I wouldn't be surprised if it was the case in some way, there's are different IDs that we're not sure how to use, the Windows driver may very well map them to a set of reference designs), then a DMI match is likely the best option.

Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines

[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://elixir.bootlin.com/linux/latest/source/drivers/media/pci/intel/ipu3/cio2-bridge.c#L166

Daniel Scally (2):
regulator: Add support for software node connections platform/surface: Add Surface Go 2 board file

 MAINTAINERS                                |   6 +
 drivers/platform/surface/Kconfig           |  10 ++
 drivers/platform/surface/Makefile          |   1 +
 drivers/platform/surface/surface_go_2.c    | 135 +++++++++++++++++++++
 drivers/regulator/Kconfig                  |   6 +
 drivers/regulator/Makefile                 |   1 +
 drivers/regulator/core.c                   |  23 ++++
 drivers/regulator/swnode_regulator.c       | 111 +++++++++++++++++
 include/linux/regulator/swnode_regulator.h |  33 +++++
 9 files changed, 326 insertions(+)
 create mode 100644 drivers/platform/surface/surface_go_2.c
 create mode 100644 drivers/regulator/swnode_regulator.c
 create mode 100644 include/linux/regulator/swnode_regulator.h
Signature · 3 lines
Regards,

Laurent Pinchart
maintainer
#40 lore raw
In reply to Daniel Scally
Quoted 8 lines · Daniel Scally
Quoted 5 lines · Laurent Pinchart

If technically feasible, gathering all the data in a single place would be my preference. Whether that should take the form of software nodes in all cases, or be modelled as custom data that the int3472 driver would interpret to create the regulators and clocks is a different (but related) question.

Quoted 8 lines

I'll have to think on that one then; the problem there is that the cio2-bridge is just given ACPI HIDs for the sensors as "ok to parse this", and of course the INT347A that is being dealt with here should already be supported on most Surface platforms via the intel-skl-int3472 stuff, so once the ov8865 edits are (posted and) accepted and that driver is supported my plan would be to add it into the bridge. So we'd need a way to exclude Go2 from that if we wanted to define all the software nodes parts in a single board file instead.

Why not just do what things like rt5670 do and have the driver probe for the PMIC use DMI information to set up platform data? That seems a lot more straightforward.

So long as people keep building systems that don't fit the ACPI model using ACPI, and indeed with no firmware description at all for important bits of the system, it's just a question of which particular kind of mess we end up with cleaning up after them. These vendors really should adopt a standards based approach rather than relying on these DMI hacks.