Skip to contentSkip to conversation

add support for fwnode in i2c mux system and sfp

RFC In review Clément Léger 11 participants 73 messages Feb 21, 2022 – Mar 8, 2022

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

cover add support for fwnode in i2c mux system and sfp

The purpose of this work is to allow i2c muxes and adapters to be usable with devices that are described with software_node. A solution for this is to use the fwnode API which works with both device-tree, ACPI and software node. In this series, functions are added to retrieve i2c_adapter from fwnode and to create new mux adapters from fwnode.

This series is part of a larger changeset that touches multiple subsystems. series will be sent separately for each subsystems since the amount of modified file is quite large. The following cover letter gives an overview of this work:

---

The LAN966X SoC can either run it's own Linux system or be plugged in a PCIe slot as a PCIe switch. When running with a Linux system, a device-tree description is used to describe the system. However, when plugged in a PCIe slot (on a x86), there is no device-tree support and the peripherals that are present must be described in some other way.

Reusing the existing drivers is of course mandatory and they should also be able to work without device-tree description. We decided to describe this card using software nodes and a MFD device. Indeed, the MFD subsystem allows to describe such systems using struct mfd_cells and mfd_add_devices(). This support also allows to attach a software_node description which might be used by fwnode API in drivers and subsystems.

We thought about adding CONFIG_OF to x86 and potentially describe this card using device-tree overlays but it introduce other problems that also seems difficult to solve (overlay loading without base device-tree, fixup of IRQs, adresses, and so on) and CONFIG_OF is not often enabled on x86 to say the least.

TLDR: I know the series touches a lot of different files and has big implications, but it turns out software_nodes looks the "best" way of achieving this goal and has the advantage of converting some subsystems to be node agnostics, also allowing some ACPI factorization. Criticism is of course welcome as I might have overlooked something way simpler !

---

This series introduce a number of changes in multiple subsystems to allow registering and using devices that are described with a software_node description attached to a mfd_cell, making them usable with the fwnode API. It was needed to modify many subsystem where CONFIG_OF was tightly integrated through the use of of_xlate() functions and other of_* calls. New calls have been added to use fwnode API and thus be usable with a wider range of nodes. Functions that are used to get the devices (pinctrl_get, clk_get and so on) also needed to be changed to use the fwnode API internally.

For instance, the clk framework has been modified to add a fwnode_xlate() callback and a new named fwnode_clk_add_hw_provider() has been added. This function will register a clock using fwnode_xlate() callback. Note that since the fwnode API is compatible with devices that have a of_node member set, it will still be possible to use the driver and get the clocks with CONFIG_OF enabled configurations.

In some subsystems, it was possible to keep OF related function by wrapping the fwnode ones. It is not yet sure if both support (device-tree and fwnode) should still continue to coexists. For instance if fwnode_xlate() and of_xlate() should remain since the fwnode version also supports device-tree. Removing of_xlate() would of course require to modify all drivers that uses it.

Here is an excerpt of the lan966x description when used as a PCIe card. The complete description is visible at [2]. This part only describe the flexcom controller and the fixed-clock that is used as an input clock.

static const struct property_entry ddr_clk_props[] = {
        PROPERTY_ENTRY_U32("clock-frequency", 30000000),
        PROPERTY_ENTRY_U32("#clock-cells", 0),
        {}
};

static const struct software_node ddr_clk_node = {
.name = "ddr_clk",
.properties = ddr_clk_props,
};

static const struct property_entry lan966x_flexcom_props[] = {
        PROPERTY_ENTRY_U32("atmel,flexcom-mode", ATMEL_FLEXCOM_MODE_TWI),
        PROPERTY_ENTRY_REF("clocks", &ddr_clk_node),
        {}
};

static const struct software_node lan966x_flexcom_node = {
.name = "lan966x-flexcom",
.properties = lan966x_flexcom_props,
};

...

static struct resource lan966x_flexcom_res[] = {
        [0] = {
                .flags = IORESOURCE_MEM,
                .start = LAN966X_DEV_ADDR(FLEXCOM_0_FLEXCOM_REG),
                .end = LAN966X_DEV_ADDR(FLEXCOM_0_FLEXCOM_REG),
        },
};

...

static struct mfd_cell lan966x_pci_mfd_cells[] = {
        ...
        [LAN966X_DEV_DDR_CLK] = {
                .name = "of_fixed_clk",
                .swnode = &ddr_clk_node,
        },
        [LAN966X_DEV_FLEXCOM] = {
                .name = "atmel_flexcom",
                .num_resources = ARRAY_SIZE(lan966x_flexcom_res),
                .resources = lan966x_flexcom_res,
                .swnode = &lan966x_flexcom_node,
        },
        ...
},

And finally registered using:

ret = devm_mfd_add_devices(dev, PLATFORM_DEVID_AUTO,

                           lan966x_pci_mfd_cells,
                           ARRAY_SIZE(lan966x_pci_mfd_cells), pci_base, irq_base,
                           irq_domain);

With the modifications that have been made on this tree, it is now possible to probe such description using existing platform drivers, providing that they have been modified a bit to retrieve properties using fwnode API and using the fwnode_xlate() callback instead of of_xlate().

This series has been tested on a x86 kernel build without CONFIG_OF. Another kernel was also built with COMPILE_TEST and CONFIG_OF support to build as most drivers as possible. It was also tested on a sparx5 arm64 with CONFIG_OF. However, it was not tested with an ACPI description evolved enough to validate all the changes.

A branch containing all theses modifications can be seen at [1] along with a PCIe driver [2] which describes the card using software nodes. Modifications that are on this branch are not completely finished (ie, subsystems modifications for fwnode have not been factorized with OF for all of them) in absence of feedback on the beginning of this work from the community.

[1] https://github.com/clementleger/linux/tree/fwnode_support
[2] https://github.com/clementleger/linux/blob/fwnode_support/drivers/mfd/lan966x_pci_mfd.c

Clément Léger (10):
property: add fwnode_match_node()
property: add fwnode_get_match_data()
base: swnode: use fwnode_get_match_data()
property: add a callback parameter to fwnode_property_match_string()
property: add fwnode_property_read_string_index()
i2c: fwnode: add fwnode_find_i2c_adapter_by_node()
i2c: of: use fwnode_get_i2c_adapter_by_node()
i2c: mux: pinctrl: remove CONFIG_OF dependency and use fwnode API
i2c: mux: add support for fwnode
net: sfp: add support for fwnode

 drivers/base/property.c             | 133 ++++++++++++++++++++++++++--
 drivers/base/swnode.c               |   1 +
 drivers/i2c/Makefile                |   1 +
 drivers/i2c/i2c-core-fwnode.c       |  40 +++++++++
 drivers/i2c/i2c-core-of.c           |  30 -------
 drivers/i2c/i2c-mux.c               |  39 ++++----
 drivers/i2c/muxes/Kconfig           |   1 -
 drivers/i2c/muxes/i2c-mux-pinctrl.c |  21 ++---
 drivers/net/phy/sfp.c               |  44 +++------
 include/linux/i2c.h                 |   7 +-
 include/linux/property.h            |   9 ++
 11 files changed, 225 insertions(+), 101 deletions(-)
 create mode 100644 drivers/i2c/i2c-core-fwnode.c
Signature · 1 line
2.34.1
#1 lore raw

RFC 1/10 property: add fwnode_match_node()

Add a function equivalent to of_match_node() which is usable for fwnode support. Matching is based on the compatible property and it returns the best matches for the node according to the compatible list ordering.

---
 drivers/base/property.c  | 23 +++++++++++++++++++++++
 include/linux/property.h |  3 +++
 2 files changed, 26 insertions(+)
drivers/base/property.c +23 -0
index e6497f6877ee..434c2713fd99 100644
@@ -1158,6 +1158,29 @@ int fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode,
 }
 EXPORT_SYMBOL(fwnode_graph_parse_endpoint);
 
+const struct of_device_id *fwnode_match_node(const struct fwnode_handle *fwnode,
+					     const struct of_device_id *matches)
+{
+	int index;
+	const struct of_device_id *best_match = NULL;
+	int best_index = INT_MAX;
+
+	if (!matches)
+		return NULL;
+
+	for (; matches->name[0] || matches->type[0] || matches->compatible[0]; matches++) {
+		index = fwnode_property_match_string(fwnode, "compatible",
+						     matches->compatible);
+		if (index >= 0 && index < best_index) {
+			best_match = matches;
+			best_index = index;
+		}
+	}
+
+	return best_match;
+}
+EXPORT_SYMBOL(fwnode_match_node);
+
 const void *device_get_match_data(struct device *dev)
 {
 	return fwnode_call_ptr_op(dev_fwnode(dev), device_get_match_data, dev);
include/linux/property.h +3 -0
index 7399a0b45f98..978ecf6be34e 100644
@@ -446,6 +446,9 @@ static inline void *device_connection_find_match(struct device *dev,
 	return fwnode_connection_find_match(dev_fwnode(dev), con_id, data, match);
 }
 
+const struct of_device_id *fwnode_match_node(const struct fwnode_handle *fwnode,
+					     const struct of_device_id *matches);
+
 /* -------------------------------------------------------------------------- */
 /* Software fwnode support - when HW description is incomplete or missing */
 
Signature · 1 line
2.34.1
#2 lore raw

Re: [RFC 01/10] property: add fwnode_match_node()

Quoted 4 lines · Clément Léger

Add a function equivalent to of_match_node() which is usable for fwnode support. Matching is based on the compatible property and it returns the best matches for the node according to the compatible list ordering.

Not sure I understand the purpose of this API.
We have device_get_match_data(), maybe you want similar for fwnode?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw

Re: [RFC 01/10] property: add fwnode_match_node()

Quoted 9 lines · Andy Shevchenko
Quoted 4 lines · Clément Léger

Add a function equivalent to of_match_node() which is usable for fwnode support. Matching is based on the compatible property and it returns the best matches for the node according to the compatible list ordering.

Not sure I understand the purpose of this API.
We have device_get_match_data(), maybe you want similar for fwnode?

Hi Andy,

Actually device_get_match_data() is calling the .device_get_match_data callback of the dev fwnode. This function is meant to be used by the next patch (fwnode_get_match_data()) to be used as a generic fwnode operation and thus be usable with software_node.

Signature · 3 lines
Clément Léger,
Embedded Linux and Kernel engineer at Bootlin
https://bootlin.com
#4 lore raw

RFC 2/10 property: add fwnode_get_match_data()

In reply to Clément Léger

Add fwnode_get_match_data() which is meant to be used as device_get_match_data for fwnode_operations.

---
 drivers/base/property.c  | 12 ++++++++++++
 include/linux/property.h |  3 +++
 2 files changed, 15 insertions(+)
drivers/base/property.c +12 -0
index 434c2713fd99..6ffb3ac4509c 100644
@@ -1181,6 +1181,18 @@ const struct of_device_id *fwnode_match_node(const struct fwnode_handle *fwnode,
 }
 EXPORT_SYMBOL(fwnode_match_node);
 
+const void *fwnode_get_match_data(const struct fwnode_handle *fwnode,
+				  const struct device *dev)
+{
+	const struct of_device_id *match;
+
+	match = fwnode_match_node(fwnode, dev->driver->of_match_table);
+	if (!match)
+		return NULL;
+
+	return match->data;
+}
+
 const void *device_get_match_data(struct device *dev)
 {
 	return fwnode_call_ptr_op(dev_fwnode(dev), device_get_match_data, dev);
include/linux/property.h +3 -0
index 978ecf6be34e..7f727c492602 100644
@@ -449,6 +449,9 @@ static inline void *device_connection_find_match(struct device *dev,
 const struct of_device_id *fwnode_match_node(const struct fwnode_handle *fwnode,
 					     const struct of_device_id *matches);
 
+const void *fwnode_get_match_data(const struct fwnode_handle *fwnode,
+				  const struct device *dev);
+
 /* -------------------------------------------------------------------------- */
 /* Software fwnode support - when HW description is incomplete or missing */
 
Signature · 1 line
2.34.1
#5 lore raw

Re: [RFC 02/10] property: add fwnode_get_match_data()

Quoted 2 lines · Clément Léger

Add fwnode_get_match_data() which is meant to be used as device_get_match_data for fwnode_operations.

...

drivers/base/property.c const struct of_device_id *fwnode_match_node(const struct fwnode_handle *fwnode, · line 1194

Quoted 11 lines
drivers/base/property.c +11 -0
+const void *fwnode_get_match_data(const struct fwnode_handle *fwnode,
+				  const struct device *dev)
+{
+	const struct of_device_id *match;
+
+	match = fwnode_match_node(fwnode, dev->driver->of_match_table);
+	if (!match)
+		return NULL;
+
+	return match->data;
+}

It's OF-centric API, why it has fwnode prefix? Can it leave in drivers/of instead?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#6 lore raw

Re: [RFC 02/10] property: add fwnode_get_match_data()

Quoted 6 lines · Andy Shevchenko
Quoted 2 lines · Clément Léger

Add fwnode_get_match_data() which is meant to be used as device_get_match_data for fwnode_operations.

...

Quoted 15 lines

drivers/base/property.c const struct of_device_id *fwnode_match_node(const struct fwnode_handle *fwnode, · line 1194

Quoted 11 lines
drivers/base/property.c +11 -0
+const void *fwnode_get_match_data(const struct fwnode_handle *fwnode,
+				  const struct device *dev)
+{
+	const struct of_device_id *match;
+
+	match = fwnode_match_node(fwnode, dev->driver->of_match_table);
+	if (!match)
+		return NULL;
+
+	return match->data;
+}  

It's OF-centric API, why it has fwnode prefix? Can it leave in drivers/of instead?

The idea is to allow device with a software_node description to match with the content of the of_match_table. Without this, we would need a new type of match table that would probably duplicates part of the of_match_table to be able to match software_node against a driver. I did not found an other way to do it without modifying drivers individually to support software_nodes.

Signature · 3 lines
Clément Léger,
Embedded Linux and Kernel engineer at Bootlin
https://bootlin.com
#7 lore raw

Re: [RFC 02/10] property: add fwnode_get_match_data()

Quoted 3 lines · Clément Léger
Quoted 1 line · Andy Shevchenko

On Mon, Feb 21, 2022 at 05:26:44PM +0100, Clément Léger wrote:

...

Quoted 8 lines
Quoted 1 line

It's OF-centric API, why it has fwnode prefix? Can it leave in drivers/of instead?

The idea is to allow device with a software_node description to match with the content of the of_match_table. Without this, we would need a new type of match table that would probably duplicates part of the of_match_table to be able to match software_node against a driver. I did not found an other way to do it without modifying drivers individually to support software_nodes.

software nodes should not be used as a replacement of the real firmware nodes. The idea behind is to fill the gaps in the cases when firmware doesn't provide enough information to the OS. I think Heikki can confirm or correct me.

If you want to use the device on an ACPI based platform, you need to describe it in ACPI as much as possible. The rest we may discuss.

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

Re: [RFC 02/10] property: add fwnode_get_match_data()

Quoted 16 lines · Andy Shevchenko
Quoted 3 lines · Clément Léger
Quoted 1 line · Andy Shevchenko

On Mon, Feb 21, 2022 at 05:26:44PM +0100, Clément Léger wrote:

...

Quoted 8 lines
Quoted 1 line

It's OF-centric API, why it has fwnode prefix? Can it leave in drivers/of instead?

The idea is to allow device with a software_node description to match with the content of the of_match_table. Without this, we would need a new type of match table that would probably duplicates part of the of_match_table to be able to match software_node against a driver. I did not found an other way to do it without modifying drivers individually to support software_nodes.

Quoted 4 lines

software nodes should not be used as a replacement of the real firmware nodes. The idea behind is to fill the gaps in the cases when firmware doesn't provide enough information to the OS. I think Heikki can confirm or correct me.

Yes, the documentation states that:

NOTE! The primary hardware description should always come from either ACPI tables or DT. Describing an entire system with software nodes, though possible, is not acceptable! The software nodes should only complement the primary hardware description.

Quoted 4 lines

If you want to use the device on an ACPI based platform, you need to describe it in ACPI as much as possible. The rest we may discuss.

Agreed but the PCIe card might also be plugged in a system using a device-tree description (ARM for instance). I should I do that without duplicating the description both in DT and ACPI ?

Signature · 3 lines
Clément Léger,
Embedded Linux and Kernel engineer at Bootlin
https://bootlin.com
#9 lore raw

Re: [RFC 02/10] property: add fwnode_get_match_data()

Quoted 5 lines · Clément Léger
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Clément Léger

Le Mon, 21 Feb 2022 19:46:12 +0200,
Andy Shevchenko <[email protected]> a écrit :

...

Quoted 19 lines
Quoted 11 lines
Quoted 6 lines

The idea is to allow device with a software_node description to match with the content of the of_match_table. Without this, we would need a new type of match table that would probably duplicates part of the of_match_table to be able to match software_node against a driver. I did not found an other way to do it without modifying drivers individually to support software_nodes.

software nodes should not be used as a replacement of the real firmware nodes. The idea behind is to fill the gaps in the cases when firmware doesn't provide enough information to the OS. I think Heikki can confirm or correct me.

Yes, the documentation states that:

NOTE! The primary hardware description should always come from either ACPI tables or DT. Describing an entire system with software nodes, though possible, is not acceptable! The software nodes should only complement the primary hardware description.

Quoted 6 lines
Quoted 2 lines

If you want to use the device on an ACPI based platform, you need to describe it in ACPI as much as possible. The rest we may discuss.

Agreed but the PCIe card might also be plugged in a system using a device-tree description (ARM for instance). I should I do that without duplicating the description both in DT and ACPI ?

Why is it (duplication) a problem?
Each platform has its own kind of description, so one needs to provide it in the format the platform accepts.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#10 lore raw

Re: [RFC 02/10] property: add fwnode_get_match_data()

Quoted 11 lines · Andy Shevchenko
Quoted 6 lines
Quoted 2 lines

If you want to use the device on an ACPI based platform, you need to describe it in ACPI as much as possible. The rest we may discuss.

Agreed but the PCIe card might also be plugged in a system using a device-tree description (ARM for instance). I should I do that without duplicating the description both in DT and ACPI ?

Why is it (duplication) a problem?
Each platform has its own kind of description, so one needs to provide it in the format the platform accepts.

The problem that I see is not only duplication but also that the PCIe card won't work out of the box and will need a specific SSDT overlays each time it is used. According to your document about SSDT overlays, there is no way to load this from the driver. This means that the user will have to compile a platform specific .aml file to match its platform configuration. If the user wants to change the PCIe port, than I guess it will have to load another .aml file. I do not think a user expect to do so when plugging a PCIe card.

Moreover, the APCI documentation [1] says the following:

"PCI devices, which are below the host bridge, generally do not need to be described via ACPI. The OS can discover them via the standard PCI enumeration mechanism, using config accesses to discover and identify devices and read and size their BARs. However, ACPI may describe PCI devices if it provides power management or hotplug functionality for them or if the device has INTx interrupts connected by platform interrupt controllers and a _PRT is needed to describe those connections."

The device I want to use (a PCIe switch) does not fall into these categories so there should be no need to describe it using ACPI. Regarding the use of software nodes, the documentation also says that:

"The software nodes can be used to complement fwnodes representing real firmware nodes when they are incomplete, for example missing device properties, *and to supply the primary fwnode when the firmware lacks hardware description for a device completely.*"

I think my device falls into this last category but I might be wrong. I understand that using software_node is probably not the best idea to do so but I did not found any other convenient way to do it and SSDT overlays do not really seems to be ideal. I would be glad if you could provide me with an example of such usage to check if it's really usable.

Thanks,

[1] https://www.kernel.org/doc/html/latest/PCI/acpi-info.html

Signature · 3 lines
Clément Léger,
Embedded Linux and Kernel engineer at Bootlin
https://bootlin.com
#11 lore raw

Re: [RFC 02/10] property: add fwnode_get_match_data()

Quoted 35 lines · Clément Léger
Quoted 11 lines · Andy Shevchenko
Quoted 6 lines
Quoted 2 lines

If you want to use the device on an ACPI based platform, you need to describe it in ACPI as much as possible. The rest we may discuss.

Agreed but the PCIe card might also be plugged in a system using a device-tree description (ARM for instance). I should I do that without duplicating the description both in DT and ACPI ?

Why is it (duplication) a problem?
Each platform has its own kind of description, so one needs to provide it in the format the platform accepts.

The problem that I see is not only duplication but also that the PCIe card won't work out of the box and will need a specific SSDT overlays each time it is used. According to your document about SSDT overlays, there is no way to load this from the driver. This means that the user will have to compile a platform specific .aml file to match its platform configuration. If the user wants to change the PCIe port, than I guess it will have to load another .aml file. I do not think a user expect to do so when plugging a PCIe card.

Moreover, the APCI documentation [1] says the following:

"PCI devices, which are below the host bridge, generally do not need to be described via ACPI. The OS can discover them via the standard PCI enumeration mechanism, using config accesses to discover and identify devices and read and size their BARs. However, ACPI may describe PCI devices if it provides power management or hotplug functionality for them or if the device has INTx interrupts connected by platform interrupt controllers and a _PRT is needed to describe those connections."

Quoted 2 lines

The device I want to use (a PCIe switch) does not fall into these categories so there should be no need to describe it using ACPI.

There should not be any need to describe it in any way, the device should provide all of the needed information. PCIe devices do not need a DT entry, as that does not make sense.

thanks,

greg k-h

#12 lore raw

Re: [RFC 02/10] property: add fwnode_get_match_data()

Quoted 24 lines · Greg Kroah-Hartman
Quoted 21 lines

The problem that I see is not only duplication but also that the PCIe card won't work out of the box and will need a specific SSDT overlays each time it is used. According to your document about SSDT overlays, there is no way to load this from the driver. This means that the user will have to compile a platform specific .aml file to match its platform configuration. If the user wants to change the PCIe port, than I guess it will have to load another .aml file. I do not think a user expect to do so when plugging a PCIe card.

Moreover, the APCI documentation [1] says the following:

"PCI devices, which are below the host bridge, generally do not need to be described via ACPI. The OS can discover them via the standard PCI enumeration mechanism, using config accesses to discover and identify devices and read and size their BARs. However, ACPI may describe PCI devices if it provides power management or hotplug functionality for them or if the device has INTx interrupts connected by platform interrupt controllers and a _PRT is needed to describe those connections."

Quoted 2 lines

The device I want to use (a PCIe switch) does not fall into these categories so there should be no need to describe it using ACPI.

Quoted 7 lines

There should not be any need to describe it in any way, the device should provide all of the needed information. PCIe devices do not need a DT entry, as that does not make sense.

thanks,

greg k-h

In my opinion, yes, there should be no need for an "external" description. Loading any kind of description (either with ACPI or DT) defeat the purpose of the PCI since the card won't be able to be plug-and-play anymore on multiple platform.

The driver however should be self-contained and contain its own "description" of the hardware, no matter the platform on which the card is plugged. The PCIe card is independent of the platform, I do not think describing it with a platform specific description language is maintainable nor user acceptable for the user.

Signature · 3 lines
Clément Léger,
Embedded Linux and Kernel engineer at Bootlin
https://bootlin.com
#13 lore raw

RFC 3/10 base: swnode: use fwnode_get_match_data()

In reply to Clément Léger

In order to allow matching devices with software node with device_get_match_data(), use fwnode_get_match_data() for .device_get_match_data operation.

---
 drivers/base/swnode.c | 1 +
 1 file changed, 1 insertion(+)
drivers/base/swnode.c +1 -0
index 0a482212c7e8..783ad18f49af 100644
@@ -662,6 +662,7 @@ software_node_graph_parse_endpoint(const struct fwnode_handle *fwnode,
 static const struct fwnode_operations software_node_ops = {
 	.get = software_node_get,
 	.put = software_node_put,
+	.device_get_match_data = fwnode_get_match_data,
 	.property_present = software_node_property_present,
 	.property_read_int_array = software_node_read_int_array,
 	.property_read_string_array = software_node_read_string_array,
Signature · 1 line
2.34.1
#14 lore raw

Re: [RFC 03/10] base: swnode: use fwnode_get_match_data()

Quoted 3 lines · Clément Léger

In order to allow matching devices with software node with device_get_match_data(), use fwnode_get_match_data() for .device_get_match_data operation.

...

drivers/base/swnode.c software_node_graph_parse_endpoint(const struct fwnode_handle *fwnode, · line 665

Quoted 1 line
drivers/base/swnode.c +1 -0
+	.device_get_match_data = fwnode_get_match_data,

Huh? It should be other way around, no?
I mean that each of the resource providers may (or may not) provide a method for the specific fwnode abstraction.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#15 lore raw

Re: [RFC 03/10] base: swnode: use fwnode_get_match_data()

Quoted 5 lines · Andy Shevchenko
Quoted 3 lines · Clément Léger

In order to allow matching devices with software node with device_get_match_data(), use fwnode_get_match_data() for .device_get_match_data operation.

Quoted 8 lines

...

drivers/base/swnode.c software_node_graph_parse_endpoint(const struct fwnode_handle *fwnode, · line 665

Quoted 1 line
drivers/base/swnode.c +1 -0
+	.device_get_match_data = fwnode_get_match_data,  

Huh? It should be other way around, no?
I mean that each of the resource providers may (or may not) provide a method for the specific fwnode abstraction.

Indeed, it should be the other way. But since this function is generic and uses only fwnode API I guessed it would be more convenient to define it in the fwnode generic part and use it for specific implementation. I could have modified device_get_match_data to call it if there was no .device_get_match_data operation like this:

const void *device_get_match_data(struct device *dev)

{
	if (!fwnode_has_op(fwnode, device_get_match_data)
		return fwnode_get_match_data(dev);
	return fwnode_call_ptr_op(dev_fwnode(dev),device_get_match_data, dev);
}

But I thought it was more convenient to do it by setting the .device_get_match_data field of software_node operations.

Signature · 3 lines
Clément Léger,
Embedded Linux and Kernel engineer at Bootlin
https://bootlin.com
reviewer
#16 lore raw

Re: [RFC 03/10] base: swnode: use fwnode_get_match_data()

Hi Clément,

Quoted 24 lines · Clément Léger
Quoted 5 lines · Andy Shevchenko
Quoted 3 lines · Clément Léger

In order to allow matching devices with software node with device_get_match_data(), use fwnode_get_match_data() for .device_get_match_data operation.

Quoted 8 lines

...

drivers/base/swnode.c software_node_graph_parse_endpoint(const struct fwnode_handle *fwnode, · line 665

Quoted 1 line
drivers/base/swnode.c +1 -0
+	.device_get_match_data = fwnode_get_match_data,  

Huh? It should be other way around, no?
I mean that each of the resource providers may (or may not) provide a method for the specific fwnode abstraction.

Indeed, it should be the other way. But since this function is generic and uses only fwnode API I guessed it would be more convenient to define it in the fwnode generic part and use it for specific implementation. I could have modified device_get_match_data to call it if there was no .device_get_match_data operation like this:

const void *device_get_match_data(struct device *dev)

Quoted 8 lines
{
	if (!fwnode_has_op(fwnode, device_get_match_data)
		return fwnode_get_match_data(dev);
	return fwnode_call_ptr_op(dev_fwnode(dev),device_get_match_data, dev);
}

But I thought it was more convenient to do it by setting the .device_get_match_data field of software_node operations.

Should this function be called e.g. software_node_get_match_data() instead, as it seems to be specific to software nodes?

Signature · 3 lines
Regards,

Sakari Ailus
#17 lore raw

Re: [RFC 03/10] base: swnode: use fwnode_get_match_data()

Quoted 7 lines · Sakari Ailus
Quoted 7 lines

const void *device_get_match_data(struct device *dev)

{
	if (!fwnode_has_op(fwnode, device_get_match_data)
		return fwnode_get_match_data(dev);
	return fwnode_call_ptr_op(dev_fwnode(dev),device_get_match_data, dev);
}
Quoted 5 lines
Quoted 2 lines

But I thought it was more convenient to do it by setting the .device_get_match_data field of software_node operations.

Should this function be called e.g. software_node_get_match_data() instead, as it seems to be specific to software nodes?

Hi Sakari,

You are right, since the only user of this function currently is the software_node operations, then I should rename it and move it to swnode.c maybe.

Signature · 3 lines
Clément Léger,
Embedded Linux and Kernel engineer at Bootlin
https://bootlin.com
reviewer
#18 lore raw

Re: [RFC 03/10] base: swnode: use fwnode_get_match_data()

Quoted 13 lines · Clément Léger
Quoted 10 lines · Sakari Ailus
Quoted 9 lines

const void *device_get_match_data(struct device *dev)

{
	if (!fwnode_has_op(fwnode, device_get_match_data)
		return fwnode_get_match_data(dev);
	return fwnode_call_ptr_op(dev_fwnode(dev),device_get_match_data, dev);
}

But I thought it was more convenient to do it by setting the .device_get_match_data field of software_node operations.

Quoted 8 lines
Quoted 2 lines

Should this function be called e.g. software_node_get_match_data() instead, as it seems to be specific to software nodes?

Hi Sakari,

You are right, since the only user of this function currently is the software_node operations, then I should rename it and move it to swnode.c maybe.

It might be also fit to be used in OF, based on how it looks like.

But currently the original naming makes it seem an fwnode property API function and that is misleading. I'd move this to swnode.c now with a new software node specific name, and rethink the naming matter if there would seem to be possibilities for code re-use.

Signature · 1 line
Sakari Ailus
#19 lore raw

RFC 4/10 property: add a callback parameter to fwnode_property_match_string()

In reply to Clément Léger

This function will be modified to be reused for fwnode_property_read_string_index(). In order to avoid copy/paste of existing code, split the existing function and pass a callback that will be executed once the string array has been retrieved.

In order to reuse this function with other actions.

---
 drivers/base/property.c | 50 +++++++++++++++++++++++++++++++++++------
 1 file changed, 43 insertions(+), 7 deletions(-)
drivers/base/property.c +43 -7
index 6ffb3ac4509c..cd1c30999fd9 100644
@@ -410,10 +410,11 @@ EXPORT_SYMBOL_GPL(fwnode_property_read_string);
  * fwnode_property_match_string - find a string in an array and return index
  * @fwnode: Firmware node to get the property of
  * @propname: Name of the property holding the array
- * @string: String to look for
+ * @cb: callback to execute on the string array
+ * @data: data to be passed to the callback
  *
- * Find a given string in a string array and if it is found return the
- * index back.
+ * Execute a given callback on a string array values and returns the callback
+ * return value.
  *
  * Return: %0 if the property was found (success),
  *	   %-EINVAL if given arguments are not valid,
@@ -421,8 +422,10 @@ EXPORT_SYMBOL_GPL(fwnode_property_read_string);
  *	   %-EPROTO if the property is not an array of strings,
  *	   %-ENXIO if no suitable firmware interface is present.
  */
-int fwnode_property_match_string(const struct fwnode_handle *fwnode,
-	const char *propname, const char *string)
+static int fwnode_property_string_match(const struct fwnode_handle *fwnode,
+					const char *propname,
+					int (*cb)(const char **, int, void *),
+					void *data)
 {
 	const char **values;
 	int nval, ret;
@@ -442,13 +445,46 @@ int fwnode_property_match_string(const struct fwnode_handle *fwnode,
 	if (ret < 0)
 		goto out;
 
+	ret = cb(values, nval, data);
+out:
+	kfree(values);
+	return ret;
+}
+
+static int match_string_callback(const char **values, int nval, void *data)
+{
+	int ret;
+	const char *string = data;
+
 	ret = match_string(values, nval, string);
 	if (ret < 0)
 		ret = -ENODATA;
-out:
-	kfree(values);
+
 	return ret;
 }
+
+/**
+ * fwnode_property_match_string - find a string in an array and return index
+ * @fwnode: Firmware node to get the property of
+ * @propname: Name of the property holding the array
+ * @string: String to look for
+ *
+ * Find a given string in a string array and if it is found return the
+ * index back.
+ *
+ * Return: %0 if the property was found (success),
+ *	   %-EINVAL if given arguments are not valid,
+ *	   %-ENODATA if the property does not have a value,
+ *	   %-EPROTO if the property is not an array of strings,
+ *	   %-ENXIO if no suitable firmware interface is present.
+ */
+int fwnode_property_match_string(const struct fwnode_handle *fwnode,
+				 const char *propname, const char *string)
+{
+	return fwnode_property_string_match(fwnode, propname,
+					    match_string_callback,
+					    (void *)string);
+}
 EXPORT_SYMBOL_GPL(fwnode_property_match_string);
 
 /**
Signature · 1 line
2.34.1
#20 lore raw

Re: [RFC 04/10] property: add a callback parameter to fwnode_property_match_string()

Quoted 6 lines · Clément Léger

This function will be modified to be reused for fwnode_property_read_string_index(). In order to avoid copy/paste of existing code, split the existing function and pass a callback that will be executed once the string array has been retrieved.

In order to reuse this function with other actions.

...

drivers/base/property.c int fwnode_property_match_string(const struct fwnode_handle *fwnode,

Quoted 7 lines
drivers/base/property.c +6 -0
+int fwnode_property_match_string(const struct fwnode_handle *fwnode,
+				 const char *propname, const char *string)
+{
+	return fwnode_property_string_match(fwnode, propname,
+					    match_string_callback,
 
+					    (void *)string);

We want to keep const qualifier.

Quoted 1 line

+}

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#21 lore raw

RFC 5/10 property: add fwnode_property_read_string_index()

In reply to Clément Léger

Add fwnode_property_read_string_index() function which allows to retrieve a string from an array by its index. This function is the equivalent of of_property_read_string_index() but for fwnode support.

---
 drivers/base/property.c  | 48 ++++++++++++++++++++++++++++++++++++++++
 include/linux/property.h |  3 +++
 2 files changed, 51 insertions(+)
drivers/base/property.c +48 -0
index cd1c30999fd9..00d9f171329c 100644
@@ -487,6 +487,54 @@ int fwnode_property_match_string(const struct fwnode_handle *fwnode,
 }
 EXPORT_SYMBOL_GPL(fwnode_property_match_string);
 
+struct read_index_data {
+	const char **string;
+	int index;
+};
+
+static int read_string_index(const char **values, int nval, void *data)
+{
+	struct read_index_data *cb_data = data;
+
+	if (cb_data->index >= nval)
+		return -EINVAL;
+
+	*cb_data->string = values[cb_data->index];
+
+	return 0;
+}
+
+/**
+ * fwnode_property_read_string_index - read a string in an array using an index
+ * and return a pointer to the string
+ * @fwnode: Firmware node to get the property of
+ * @propname: Name of the property holding the array
+ * @index: Index of the string to look for
+ * @string: Pointer to the string if found
+ *
+ * Find a string by a given index in a string array and if it is found return
+ * the string value in @string.
+ *
+ * Return: %0 if the property was found (success),
+ *	   %-EINVAL if given arguments are not valid,
+ *	   %-ENODATA if the property does not have a value,
+ *	   %-EPROTO if the property is not an array of strings,
+ *	   %-ENXIO if no suitable firmware interface is present.
+ */
+int fwnode_property_read_string_index(const struct fwnode_handle *fwnode,
+				      const char *propname, int index,
+				      const char **string)
+{
+	struct read_index_data cb_data;
+
+	cb_data.index = index;
+	cb_data.string = string;
+
+	return fwnode_property_string_match(fwnode, propname, read_string_index,
+					    &cb_data);
+}
+EXPORT_SYMBOL_GPL(fwnode_property_read_string_index);
+
 /**
  * fwnode_property_get_reference_args() - Find a reference with arguments
  * @fwnode:	Firmware node where to look for the reference
include/linux/property.h +3 -0
index 7f727c492602..f6ede3840c40 100644
@@ -70,6 +70,9 @@ int fwnode_property_read_string_array(const struct fwnode_handle *fwnode,
 				      size_t nval);
 int fwnode_property_read_string(const struct fwnode_handle *fwnode,
 				const char *propname, const char **val);
+int fwnode_property_read_string_index(const struct fwnode_handle *fwnode,
+				      const char *propname, int index,
+				      const char **string);
 int fwnode_property_match_string(const struct fwnode_handle *fwnode,
 				 const char *propname, const char *string);
 int fwnode_property_get_reference_args(const struct fwnode_handle *fwnode,
Signature · 1 line
2.34.1
#22 lore raw

RFC 6/10 i2c: fwnode: add fwnode_find_i2c_adapter_by_node()

In reply to Clément Léger

Add fwnode_find_i2c_adapter_by_node() which allows to retrieve a i2c adapter using a fwnode. Since dev_fwnode() uses the fwnode provided by the of_node member of the device, this will also work for devices were the of_node has been set and not the fwnode field.

---
 drivers/i2c/Makefile          |  1 +
 drivers/i2c/i2c-core-fwnode.c | 40 +++++++++++++++++++++++++++++++++++
 include/linux/i2c.h           |  2 ++
 3 files changed, 43 insertions(+)
 create mode 100644 drivers/i2c/i2c-core-fwnode.c
drivers/i2c/Makefile +1 -0
index c1d493dc9bac..c9c97675163e 100644
@@ -6,6 +6,7 @@
 obj-$(CONFIG_I2C_BOARDINFO)	+= i2c-boardinfo.o
 obj-$(CONFIG_I2C)		+= i2c-core.o
 i2c-core-objs 			:= i2c-core-base.o i2c-core-smbus.o
+i2c-core-objs			+= i2c-core-fwnode.o
 i2c-core-$(CONFIG_ACPI)		+= i2c-core-acpi.o
 i2c-core-$(CONFIG_I2C_SLAVE) 	+= i2c-core-slave.o
 i2c-core-$(CONFIG_OF) 		+= i2c-core-of.o
drivers/i2c/i2c-core-fwnode.c new file +40 -0
new file mode 100644
index 000000000000..d116aca3e2ec
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Linux I2C core fwnode support code
+ *
+ * Copyright (C) 2022 Microchip
+ */
+
+#include <linux/device.h>
+#include <linux/i2c.h>
+
+#include "i2c-core.h"
+
+static int fwnode_dev_or_parent_node_match(struct device *dev, const void *data)
+{
+	if (dev_fwnode(dev) == data)
+		return 1;
+
+	if (dev->parent)
+		return dev_fwnode(dev->parent) == data;
+
+	return 0;
+}
+
+struct i2c_adapter *fwnode_find_i2c_adapter_by_node(struct fwnode_handle *node)
+{
+	struct device *dev;
+	struct i2c_adapter *adapter;
+
+	dev = bus_find_device(&i2c_bus_type, NULL, node,
+			      fwnode_dev_or_parent_node_match);
+	if (!dev)
+		return NULL;
+
+	adapter = i2c_verify_adapter(dev);
+	if (!adapter)
+		put_device(dev);
+
+	return adapter;
+}
+EXPORT_SYMBOL(fwnode_find_i2c_adapter_by_node);
include/linux/i2c.h +2 -0
index 7d4f52ceb7b5..9b480a8b0a76 100644
@@ -967,6 +967,8 @@ int i2c_handle_smbus_host_notify(struct i2c_adapter *adap, unsigned short addr);
 
 #endif /* I2C */
 
+struct i2c_adapter *fwnode_find_i2c_adapter_by_node(struct fwnode_handle *node);
+
 #if IS_ENABLED(CONFIG_OF)
 /* must call put_device() when done with returned i2c_client device */
 struct i2c_client *of_find_i2c_device_by_node(struct device_node *node);
Signature · 1 line
2.34.1
#23 lore raw

Re: [RFC 06/10] i2c: fwnode: add fwnode_find_i2c_adapter_by_node()

Quoted 4 lines · Clément Léger

Add fwnode_find_i2c_adapter_by_node() which allows to retrieve a i2c adapter using a fwnode. Since dev_fwnode() uses the fwnode provided by the of_node member of the device, this will also work for devices were the of_node has been set and not the fwnode field.

...

drivers/i2c/i2c-core-fwnode.c line 16

Quoted 5 lines
drivers/i2c/i2c-core-fwnode.c new file +4 -0
+static int fwnode_dev_or_parent_node_match(struct device *dev, const void *data)
+{
 
+	if (dev_fwnode(dev) == data)
+		return 1;

This can use corresponding match function from bus.h.

drivers/i2c/i2c-core-fwnode.c line 21

Quoted 4 lines
drivers/i2c/i2c-core-fwnode.c new file +4 -0
+	if (dev->parent)
+		return dev_fwnode(dev->parent) == data;
+
+	return 0;

The same.

Quoted 1 line

+}

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#24 lore raw

RFC 7/10 i2c: of: use fwnode_get_i2c_adapter_by_node()

In reply to Clément Léger

Since the new fwnode function does the same check that was done by of_get_i2c_adapter_by_node(), call this one to avoid code duplication.

---
 drivers/i2c/i2c-core-of.c | 30 ------------------------------
 include/linux/i2c.h       |  5 ++++-
 2 files changed, 4 insertions(+), 31 deletions(-)
drivers/i2c/i2c-core-of.c +0 -30
index 3ed74aa4b44b..be7d66aa0f49 100644
@@ -113,17 +113,6 @@ void of_i2c_register_devices(struct i2c_adapter *adap)
 	of_node_put(bus);
 }
 
-static int of_dev_or_parent_node_match(struct device *dev, const void *data)
-{
-	if (dev->of_node == data)
-		return 1;
-
-	if (dev->parent)
-		return dev->parent->of_node == data;
-
-	return 0;
-}
-
 /* must call put_device() when done with returned i2c_client device */
 struct i2c_client *of_find_i2c_device_by_node(struct device_node *node)
 {
@@ -142,25 +131,6 @@ struct i2c_client *of_find_i2c_device_by_node(struct device_node *node)
 }
 EXPORT_SYMBOL(of_find_i2c_device_by_node);
 
-/* must call put_device() when done with returned i2c_adapter device */
-struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node)
-{
-	struct device *dev;
-	struct i2c_adapter *adapter;
-
-	dev = bus_find_device(&i2c_bus_type, NULL, node,
-			      of_dev_or_parent_node_match);
-	if (!dev)
-		return NULL;
-
-	adapter = i2c_verify_adapter(dev);
-	if (!adapter)
-		put_device(dev);
-
-	return adapter;
-}
-EXPORT_SYMBOL(of_find_i2c_adapter_by_node);
-
 /* must call i2c_put_adapter() when done with returned i2c_adapter device */
 struct i2c_adapter *of_get_i2c_adapter_by_node(struct device_node *node)
 {
include/linux/i2c.h +4 -1
index 9b480a8b0a76..d1f384b805ad 100644
@@ -974,7 +974,10 @@ struct i2c_adapter *fwnode_find_i2c_adapter_by_node(struct fwnode_handle *node);
 struct i2c_client *of_find_i2c_device_by_node(struct device_node *node);
 
 /* must call put_device() when done with returned i2c_adapter device */
-struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node);
+static inline struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node)
+{
+	return fwnode_find_i2c_adapter_by_node(of_fwnode_handle(node));
+}
 
 /* must call i2c_put_adapter() when done with returned i2c_adapter device */
 struct i2c_adapter *of_get_i2c_adapter_by_node(struct device_node *node);
Signature · 1 line
2.34.1
#25 lore raw

RFC 8/10 i2c: mux: pinctrl: remove CONFIG_OF dependency and use fwnode API

In reply to Clément Léger

In order to use i2c muxes with software_node when added with a struct mfd_cell, switch to fwnode API. The fwnode layer will allow to use this with both device_node and software_node.

---
 drivers/i2c/muxes/Kconfig           |  1 -
 drivers/i2c/muxes/i2c-mux-pinctrl.c | 21 +++++++++++----------
 2 files changed, 11 insertions(+), 11 deletions(-)
drivers/i2c/muxes/Kconfig +0 -1
index 1708b1a82da2..d9cb15cfba3e 100644
@@ -77,7 +77,6 @@ config I2C_MUX_PCA954x
 config I2C_MUX_PINCTRL
 	tristate "pinctrl-based I2C multiplexer"
 	depends on PINCTRL
-	depends on OF || COMPILE_TEST
 	help
 	  If you say yes to this option, support will be included for an I2C
 	  multiplexer that uses the pinctrl subsystem, i.e. pin multiplexing.
drivers/i2c/muxes/i2c-mux-pinctrl.c +11 -10
index f1bb00a11ad6..200890d7a625 100644
@@ -53,19 +53,20 @@ static struct i2c_adapter *i2c_mux_pinctrl_root_adapter(
 
 static struct i2c_adapter *i2c_mux_pinctrl_parent_adapter(struct device *dev)
 {
-	struct device_node *np = dev->of_node;
-	struct device_node *parent_np;
+	struct fwnode_handle *fwnode = dev_fwnode(dev);
+	struct fwnode_handle *parent_np;
 	struct i2c_adapter *parent;
 
-	parent_np = of_parse_phandle(np, "i2c-parent", 0);
+	parent_np = fwnode_find_reference(fwnode, "i2c-parent", 0);
 	if (!parent_np) {
 		dev_err(dev, "Cannot parse i2c-parent\n");
 		return ERR_PTR(-ENODEV);
 	}
-	parent = of_find_i2c_adapter_by_node(parent_np);
-	of_node_put(parent_np);
-	if (!parent)
+	parent = fwnode_find_i2c_adapter_by_node(parent_np);
+	if (!parent) {
+		dev_err(dev, "Cannot find i2c-parent\n");
 		return ERR_PTR(-EPROBE_DEFER);
+	}
 
 	return parent;
 }
@@ -73,7 +74,7 @@ static struct i2c_adapter *i2c_mux_pinctrl_parent_adapter(struct device *dev)
 static int i2c_mux_pinctrl_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
-	struct device_node *np = dev->of_node;
+	struct fwnode_handle *np = dev_fwnode(dev);
 	struct i2c_mux_core *muxc;
 	struct i2c_mux_pinctrl *mux;
 	struct i2c_adapter *parent;
@@ -81,7 +82,7 @@ static int i2c_mux_pinctrl_probe(struct platform_device *pdev)
 	int num_names, i, ret;
 	const char *name;
 
-	num_names = of_property_count_strings(np, "pinctrl-names");
+	num_names = fwnode_property_string_array_count(np, "pinctrl-names");
 	if (num_names < 0) {
 		dev_err(dev, "Cannot parse pinctrl-names: %d\n",
 			num_names);
@@ -111,8 +112,8 @@ static int i2c_mux_pinctrl_probe(struct platform_device *pdev)
 	}
 
 	for (i = 0; i < num_names; i++) {
-		ret = of_property_read_string_index(np, "pinctrl-names", i,
-						    &name);
+		ret = fwnode_property_read_string_index(np, "pinctrl-names", i,
+							&name);
 		if (ret < 0) {
 			dev_err(dev, "Cannot parse pinctrl-names: %d\n", ret);
 			goto err_put_parent;
Signature · 1 line
2.34.1
#26 lore raw

RFC 9/10 i2c: mux: add support for fwnode

In reply to Clément Léger

Modify i2c_mux_add_adapter() to use with fwnode API to allow creating mux adapters with fwnode based devices. This allows to have a node independent support for i2c muxes.

---
 drivers/i2c/i2c-mux.c | 39 ++++++++++++++++++---------------------
 1 file changed, 18 insertions(+), 21 deletions(-)
drivers/i2c/i2c-mux.c +18 -21
index 774507b54b57..93c916220da5 100644
@@ -24,7 +24,7 @@
 #include <linux/i2c-mux.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
-#include <linux/of.h>
+#include <linux/property.h>
 #include <linux/slab.h>
 #include <linux/sysfs.h>
 
@@ -347,38 +347,35 @@ int i2c_mux_add_adapter(struct i2c_mux_core *muxc,
 	else
 		priv->adap.class = class;
 
-	/*
-	 * Try to populate the mux adapter's of_node, expands to
-	 * nothing if !CONFIG_OF.
-	 */
-	if (muxc->dev->of_node) {
-		struct device_node *dev_node = muxc->dev->of_node;
-		struct device_node *mux_node, *child = NULL;
+	/* Try to populate the mux adapter's device node */
+	if (dev_fwnode(muxc->dev) && !has_acpi_companion(muxc->dev)) {
+		struct fwnode_handle *dev_node = dev_fwnode(muxc->dev);
+		struct fwnode_handle *mux_node, *child = NULL;
 		u32 reg;
 
 		if (muxc->arbitrator)
-			mux_node = of_get_child_by_name(dev_node, "i2c-arb");
+			mux_node = fwnode_get_named_child_node(dev_node, "i2c-arb");
 		else if (muxc->gate)
-			mux_node = of_get_child_by_name(dev_node, "i2c-gate");
+			mux_node = fwnode_get_named_child_node(dev_node, "i2c-gate");
 		else
-			mux_node = of_get_child_by_name(dev_node, "i2c-mux");
+			mux_node = fwnode_get_named_child_node(dev_node, "i2c-mux");
 
 		if (mux_node) {
 			/* A "reg" property indicates an old-style DT entry */
-			if (!of_property_read_u32(mux_node, "reg", &reg)) {
-				of_node_put(mux_node);
+			if (!fwnode_property_read_u32(mux_node, "reg", &reg)) {
+				fwnode_handle_put(mux_node);
 				mux_node = NULL;
 			}
 		}
 
 		if (!mux_node)
-			mux_node = of_node_get(dev_node);
+			mux_node = fwnode_handle_get(dev_node);
 		else if (muxc->arbitrator || muxc->gate)
-			child = of_node_get(mux_node);
+			child = fwnode_handle_get(mux_node);
 
 		if (!child) {
-			for_each_child_of_node(mux_node, child) {
-				ret = of_property_read_u32(child, "reg", &reg);
+			fwnode_for_each_child_node(mux_node, child) {
+				ret = fwnode_property_read_u32(child, "reg", &reg);
 				if (ret)
 					continue;
 				if (chan_id == reg)
@@ -386,8 +383,8 @@ int i2c_mux_add_adapter(struct i2c_mux_core *muxc,
 			}
 		}
 
-		priv->adap.dev.of_node = child;
-		of_node_put(mux_node);
+		device_set_node(&priv->adap.dev, child);
+		fwnode_handle_put(mux_node);
 	}
 
 	/*
@@ -444,7 +441,7 @@ void i2c_mux_del_adapters(struct i2c_mux_core *muxc)
 	while (muxc->num_adapters) {
 		struct i2c_adapter *adap = muxc->adapter[--muxc->num_adapters];
 		struct i2c_mux_priv *priv = adap->algo_data;
-		struct device_node *np = adap->dev.of_node;
+		struct fwnode_handle *np = dev_fwnode(&adap->dev);
 
 		muxc->adapter[muxc->num_adapters] = NULL;
 
@@ -454,7 +451,7 @@ void i2c_mux_del_adapters(struct i2c_mux_core *muxc)
 
 		sysfs_remove_link(&priv->adap.dev.kobj, "mux_device");
 		i2c_del_adapter(adap);
-		of_node_put(np);
+		fwnode_handle_put(np);
 		kfree(priv);
 	}
 }
Signature · 1 line
2.34.1
#27 lore raw

Re: [RFC 09/10] i2c: mux: add support for fwnode

Quoted 3 lines · Clément Léger

Modify i2c_mux_add_adapter() to use with fwnode API to allow creating mux adapters with fwnode based devices. This allows to have a node independent support for i2c muxes.

I^2C muxes have their own description for DT and ACPI platforms, I'm not sure swnode should be used here at all. Just upload a corresponding SSDT overlay or DT overlay depending on the platform. Can it be achieved?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#28 lore raw

Re: [RFC 09/10] i2c: mux: add support for fwnode

Quoted 9 lines · Andy Shevchenko
Quoted 3 lines · Clément Léger

Modify i2c_mux_add_adapter() to use with fwnode API to allow creating mux adapters with fwnode based devices. This allows to have a node independent support for i2c muxes.

I^2C muxes have their own description for DT and ACPI platforms, I'm not sure swnode should be used here at all. Just upload a corresponding SSDT overlay or DT overlay depending on the platform. Can it be achieved?

Problem is that this PCIe card can be plugged either in a X86 platform using ACPI or on a ARM one with device-tree. So it means I should have two "identical" descriptions for each platforms.

Signature · 3 lines
Clément Léger,
Embedded Linux and Kernel engineer at Bootlin
https://bootlin.com
maintainer
#29 lore raw

Re: [RFC 09/10] i2c: mux: add support for fwnode

Quoted 8 lines · Clément Léger
Quoted 5 lines · Andy Shevchenko
Quoted 3 lines · Clément Léger

Modify i2c_mux_add_adapter() to use with fwnode API to allow creating mux adapters with fwnode based devices. This allows to have a node independent support for i2c muxes.

Quoted 8 lines
Quoted 4 lines

I^2C muxes have their own description for DT and ACPI platforms, I'm not sure swnode should be used here at all. Just upload a corresponding SSDT overlay or DT overlay depending on the platform. Can it be achieved?

Problem is that this PCIe card can be plugged either in a X86 platform using ACPI or on a ARM one with device-tree. So it means I should have two "identical" descriptions for each platforms.

ACPI != DT.

I know people like stuffing DT properties into ACPI tables, when ACPI does not have a binding. But in this case, there is a well defined ACPI mechanism for I2C muxes. You cannot ignore it because it is different to DT. So you need to handle the muxes in both the ACPI way and the DT way.

For other parts of what you are doing, you might be able to get away by just stuffing DT properties into ACPI tables. But that is not for me to decide, that is up to the ACPI maintainers.

Andrew

#30 lore raw

Re: [RFC 09/10] i2c: mux: add support for fwnode

Quoted 26 lines · Andrew Lunn
Quoted 8 lines · Clément Léger
Quoted 5 lines · Andy Shevchenko
Quoted 3 lines · Clément Léger

Modify i2c_mux_add_adapter() to use with fwnode API to allow creating mux adapters with fwnode based devices. This allows to have a node independent support for i2c muxes.

Quoted 8 lines
Quoted 4 lines

I^2C muxes have their own description for DT and ACPI platforms, I'm not sure swnode should be used here at all. Just upload a corresponding SSDT overlay or DT overlay depending on the platform. Can it be achieved?

Problem is that this PCIe card can be plugged either in a X86 platform using ACPI or on a ARM one with device-tree. So it means I should have two "identical" descriptions for each platforms.

ACPI != DT.

I know people like stuffing DT properties into ACPI tables, when ACPI does not have a binding. But in this case, there is a well defined ACPI mechanism for I2C muxes. You cannot ignore it because it is different to DT. So you need to handle the muxes in both the ACPI way and the DT way.

Quoted 4 lines

For other parts of what you are doing, you might be able to get away by just stuffing DT properties into ACPI tables. But that is not for me to decide, that is up to the ACPI maintainers.

What I'm wondering is why you would have to stuff anything in ACPI when plugging any PCIe card in a PC. Wouldn't that be a first?

I don't have to do so when plugging an Intel network card, I don't expect to have to do it when plugging any other network card...

Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#31 lore raw

RFC 10/10 net: sfp: add support for fwnode

In reply to Clément Léger

Add support to retrieve a i2c bus in sfp with a fwnode. This support is using the fwnode API which also works with device-tree and ACPI. For this purpose, the device-tree and ACPI code handling the i2c adapter retrieval was factorized with the new code. This also allows i2c devices using a software_node description to be used by sfp code.

---
 drivers/net/phy/sfp.c | 44 +++++++++++++------------------------------
 1 file changed, 13 insertions(+), 31 deletions(-)
drivers/net/phy/sfp.c +13 -31
index 4720b24ca51b..9d9e3d209408 100644
@@ -2499,43 +2499,25 @@ static int sfp_probe(struct platform_device *pdev)
 		return err;
 
 	sff = sfp->type = &sfp_data;
+	if (dev_fwnode(&pdev->dev)) {
+		struct fwnode_handle *fwnode = dev_fwnode(&pdev->dev);
+		struct fwnode_handle *np;
 
-	if (pdev->dev.of_node) {
-		struct device_node *node = pdev->dev.of_node;
-		const struct of_device_id *id;
-		struct device_node *np;
+		if (!is_acpi_device_node(fwnode)) {
+			sff = device_get_match_data(&pdev->dev);
+			if (WARN_ON(!sff))
+				return -EINVAL;
 
-		id = of_match_node(sfp_of_match, node);
-		if (WARN_ON(!id))
-			return -EINVAL;
-
-		sff = sfp->type = id->data;
-
-		np = of_parse_phandle(node, "i2c-bus", 0);
-		if (!np) {
-			dev_err(sfp->dev, "missing 'i2c-bus' property\n");
-			return -ENODEV;
+			sfp->type = sff;
 		}
 
-		i2c = of_find_i2c_adapter_by_node(np);
-		of_node_put(np);
-	} else if (has_acpi_companion(&pdev->dev)) {
-		struct acpi_device *adev = ACPI_COMPANION(&pdev->dev);
-		struct fwnode_handle *fw = acpi_fwnode_handle(adev);
-		struct fwnode_reference_args args;
-		struct acpi_handle *acpi_handle;
-		int ret;
-
-		ret = acpi_node_get_property_reference(fw, "i2c-bus", 0, &args);
-		if (ret || !is_acpi_device_node(args.fwnode)) {
-			dev_err(&pdev->dev, "missing 'i2c-bus' property\n");
+		np = fwnode_find_reference(fwnode, "i2c-bus", 0);
+		if (!np) {
+			dev_err(&pdev->dev, "Cannot parse i2c-bus\n");
 			return -ENODEV;
 		}
-
-		acpi_handle = ACPI_HANDLE_FWNODE(args.fwnode);
-		i2c = i2c_acpi_find_adapter_by_handle(acpi_handle);
-	} else {
-		return -EINVAL;
+		i2c = fwnode_find_i2c_adapter_by_node(np);
+		fwnode_handle_put(np);
 	}
 
 	if (!i2c)
Signature · 1 line
2.34.1
maintainer Reviewed-by on v1 10/10
#32 lore raw

Re: [RFC 10/10] net: sfp: add support for fwnode

Quoted 7 lines · Clément Léger

Add support to retrieve a i2c bus in sfp with a fwnode. This support is using the fwnode API which also works with device-tree and ACPI. For this purpose, the device-tree and ACPI code handling the i2c adapter retrieval was factorized with the new code. This also allows i2c devices using a software_node description to be used by sfp code.

I think this looks fine.

Thanks.

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
#33 lore raw

Re: [RFC 10/10] net: sfp: add support for fwnode

In reply to Clément Léger
Quoted 5 lines · Clément Léger

Add support to retrieve a i2c bus in sfp with a fwnode. This support is using the fwnode API which also works with device-tree and ACPI. For this purpose, the device-tree and ACPI code handling the i2c adapter retrieval was factorized with the new code. This also allows i2c devices using a software_node description to be used by sfp code.

If I'm not mistaken this patch can even go separately right now, since all used APIs are already available.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#34 lore raw

Re: [RFC 10/10] net: sfp: add support for fwnode

Quoted 10 lines · Andy Shevchenko
Quoted 5 lines · Clément Léger

Add support to retrieve a i2c bus in sfp with a fwnode. This support is using the fwnode API which also works with device-tree and ACPI. For this purpose, the device-tree and ACPI code handling the i2c adapter retrieval was factorized with the new code. This also allows i2c devices using a software_node description to be used by sfp code.

If I'm not mistaken this patch can even go separately right now, since all used APIs are already available.

This patches uses fwnode_find_i2c_adapter_by_node() which is introduced by "i2c: fwnode: add fwnode_find_i2c_adapter_by_node()" but they can probably be contributed both in a separate series.

Signature · 3 lines
Clément Léger,
Embedded Linux and Kernel engineer at Bootlin
https://bootlin.com
#35 lore raw

Re: [RFC 10/10] net: sfp: add support for fwnode

Quoted 10 lines · Clément Léger
Quoted 7 lines · Andy Shevchenko
Quoted 5 lines · Clément Léger

Add support to retrieve a i2c bus in sfp with a fwnode. This support is using the fwnode API which also works with device-tree and ACPI. For this purpose, the device-tree and ACPI code handling the i2c adapter retrieval was factorized with the new code. This also allows i2c devices using a software_node description to be used by sfp code.

Quoted 6 lines
Quoted 2 lines

If I'm not mistaken this patch can even go separately right now, since all used APIs are already available.

This patches uses fwnode_find_i2c_adapter_by_node() which is introduced by "i2c: fwnode: add fwnode_find_i2c_adapter_by_node()" but they can probably be contributed both in a separate series.

I summon Hans into the discussion since I remember he recently refactored a bit I2C (ACPI/fwnode) APIs. Also he might have an idea about entire big picture approach with this series based on his ACPI experience.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#36 lore raw

Re: [RFC 10/10] net: sfp: add support for fwnode

Hi,

Quoted 14 lines · Andy Shevchenko
Quoted 13 lines · Clément Léger
Quoted 9 lines · Andy Shevchenko
Quoted 5 lines · Clément Léger

Add support to retrieve a i2c bus in sfp with a fwnode. This support is using the fwnode API which also works with device-tree and ACPI. For this purpose, the device-tree and ACPI code handling the i2c adapter retrieval was factorized with the new code. This also allows i2c devices using a software_node description to be used by sfp code.

If I'm not mistaken this patch can even go separately right now, since all used APIs are already available.

Quoted 7 lines
Quoted 3 lines

This patches uses fwnode_find_i2c_adapter_by_node() which is introduced by "i2c: fwnode: add fwnode_find_i2c_adapter_by_node()" but they can probably be contributed both in a separate series.

I summon Hans into the discussion since I remember he recently refactored a bit I2C (ACPI/fwnode) APIs. Also he might have an idea about entire big picture approach with this series based on his ACPI experience.

If I understand this series correctly then this is about a PCI-E card which has an I2C controller on the card and behind that I2C-controller there are a couple if I2C muxes + I2C clients.

And the goal of the series is to describe those I2C muxes + I2C clients with software nodes so that the existing I2C enumeration code can be used (after porting the existing I2C enumeration code from OF functions to generic fwnode functions).

Did I understand this bit correctly? I believe that a lot of the discussion here is caused by the initial problem / hw-setup this series tries to address / support is not described very well ?

Assuming I did understand the above correctly. One alternative would be to simply manually instantiate the I2C muxes + clients using i2c_new_client_device(). But I'm not sure if i2c_new_client_device() will work for the muxes without adding some software_nodes which brings us back to something like this patch-set.

In general I believe that porting things away from OF specific parsing to the generic fwnode APIs is a good thing.

Making device_get_match_data() for devices with only a software fwnode use of_device_id matching feels a bit weird. But it also makes sense since that requires just adding a compatible string to the software fwnode properties which is easy and it allows re-uses existing matching code in the drivers.

I understand various people falling over this weirdness but AFAICT the alternative would be adding some special swnode_id type + matching code for devices where the primary fwnode is a software fwnode, which would just be a whole bunch of extra code ending up with something similar.

So re-using of_device_id-s for matching of devices where the primary fwnode is a software fwnode seems like a good idea. *But* this all needs to be explained in the commit message a lot better. It really needs to be spelled out that this is:

a) Only for matching devices where the primary fwnode is a software fwnode

b) Really has nothing to do with of/dt but of_device_id matching is used here to avoid having to introduce a new matching mechanism just for devices where the primary fwnode is a software fwnode

c) That introducing a new software fwnode matching mechanism would be a bad idea since this will require adding new swnode_match tables to many drivers, where as re-using of_device_id will make drivers which already have an of_match_table just work.

And this should be spelled out in both the commit message as well as in some documentation / kdoc comments. Because although a useful trick, reusing the of_match_id-s is also confusing which I believe is what has led to a lot of the discussion on this patch-set so far.

Note the above all relies on my interpretation of this patch set, which may be wrong, since as said the patch-set does seem to be lacking when it comes to documentation / motivation of the patches.

Regards,

Hans

maintainer
#37 lore raw

Re: [RFC 10/10] net: sfp: add support for fwnode

Quoted 3 lines

If I understand this series correctly then this is about a PCI-E card which has an I2C controller on the card and behind that I2C-controller there are a couple if I2C muxes + I2C clients.

They are not i2c clients in the normal sense. The i2c bus connects to an SFP cage. You can hot plug different sort of network modules into the cage. So for example fibre optic modules or copper modules. The modules have an 'at24' like block of memory, which is a mix of EEPROM and status values. For copper modules, there is an MDIO over I2C protocol which allows access to the Copper Ethernet PHY inside the module.

The current device tree binding is that you have a node for the SFP cage, which includes a phandle to the i2c bus, plus a list of GPIOs connected to pins on the SFP cage. The SFP driver will then directly access the memory, maybe instantiate an mdio-over-i2c device if needed, and control the GPIOs. The Ethernet driver then has an OF node with a phandle pointing to the SFP device.

The whole design of this is based around the hardware being a collection of standard parts, i2c bus, i2c mux, gpio controller, ethernet controller, each with their own driver as part of a linux subsystem, and then having some glue to put all the parts together. And at the moment, that glue is DT.

Quoted 3 lines

Note the above all relies on my interpretation of this patch set, which may be wrong, since as said the patch-set does seem to be lacking when it comes to documentation / motivation of the patches.

I think some examples from DT will help with this.

Andrew

#38 lore raw

Re: [RFC 10/10] net: sfp: add support for fwnode

In reply to Hans de Goede
Quoted 21 lines · Hans de Goede

Hi,

Quoted 18 lines · Andy Shevchenko
Quoted 16 lines · Clément Léger
Quoted 9 lines · Andy Shevchenko
Quoted 5 lines · Clément Léger

Add support to retrieve a i2c bus in sfp with a fwnode. This support is using the fwnode API which also works with device-tree and ACPI. For this purpose, the device-tree and ACPI code handling the i2c adapter retrieval was factorized with the new code. This also allows i2c devices using a software_node description to be used by sfp code.

If I'm not mistaken this patch can even go separately right now, since all used APIs are already available.

This patches uses fwnode_find_i2c_adapter_by_node() which is introduced by "i2c: fwnode: add fwnode_find_i2c_adapter_by_node()" but they can probably be contributed both in a separate series.

Quoted 7 lines
Quoted 3 lines

I summon Hans into the discussion since I remember he recently refactored a bit I2C (ACPI/fwnode) APIs. Also he might have an idea about entire big picture approach with this series based on his ACPI experience.

If I understand this series correctly then this is about a PCI-E card which has an I2C controller on the card and behind that I2C-controller there are a couple if I2C muxes + I2C clients.

That is what I gathered as well.

Quoted 5 lines

Assuming I did understand the above correctly. One alternative would be to simply manually instantiate the I2C muxes + clients using i2c_new_client_device(). But I'm not sure if i2c_new_client_device() will work for the muxes without adding some software_nodes which brings us back to something like this patch-set.

That assumes that an I2C device is always present, which is not always the case - there are hot-pluggable devices on I2C buses.

Specifically, this series includes pluggable SFP modules, which fall into this category of "hot-pluggable I2C devices" - spanning several bus addresses (0x50, 0x51, 0x56). 0x50 is EEPROM like, but not quite as the top 128 bytes is paged and sometimes buggy in terms of access behaviour. 0x51 contains a bunch of monitoring and other controls for the module which again can be paged. At 0x56, there may possibly be some kind of device that translates I2C accesses to MDIO accesses to access a PHY onboard.

Consequently, the SFP driver and MDIO translation layer wants access to the I2C bus, rather than a device.

Now, before ARM was converted to DT, we had ways to cope with non-firmware described setups like this by using platform devices and platform data. Much of that ended up deprecated, because - hey - DT is great and more modern and the old way is disgusting and we want to get rid of it.

However, that approach locks us into describing stuff in firmware, which is unsuitable when something like this comes along.

I think what we need is both approaches. We need a way for the SFP driver (which is a platform_driver) to be used _without_ needing descriptions in firmware. I think we have that for GPIOs, but for an I2C bus, We have i2c_get_adapter() for I2C buses, but that needs the bus number - we could either pass the i2c_adapter or the adapter number through platform data to the SFP driver.

Or is there another solution to being able to reuse multi-driver based infrastructure that we have developed based on DT descriptions in situations such as an add-in PCI card?

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
#39 lore raw

Re: [RFC 10/10] net: sfp: add support for fwnode

Hi,

Quoted 69 lines · Russell King (Oracle)
Quoted 21 lines · Hans de Goede

Hi,

Quoted 18 lines · Andy Shevchenko
Quoted 16 lines · Clément Léger
Quoted 9 lines · Andy Shevchenko
Quoted 5 lines · Clément Léger

Add support to retrieve a i2c bus in sfp with a fwnode. This support is using the fwnode API which also works with device-tree and ACPI. For this purpose, the device-tree and ACPI code handling the i2c adapter retrieval was factorized with the new code. This also allows i2c devices using a software_node description to be used by sfp code.

If I'm not mistaken this patch can even go separately right now, since all used APIs are already available.

This patches uses fwnode_find_i2c_adapter_by_node() which is introduced by "i2c: fwnode: add fwnode_find_i2c_adapter_by_node()" but they can probably be contributed both in a separate series.

Quoted 7 lines
Quoted 3 lines

I summon Hans into the discussion since I remember he recently refactored a bit I2C (ACPI/fwnode) APIs. Also he might have an idea about entire big picture approach with this series based on his ACPI experience.

If I understand this series correctly then this is about a PCI-E card which has an I2C controller on the card and behind that I2C-controller there are a couple if I2C muxes + I2C clients.

That is what I gathered as well.

Quoted 5 lines

Assuming I did understand the above correctly. One alternative would be to simply manually instantiate the I2C muxes + clients using i2c_new_client_device(). But I'm not sure if i2c_new_client_device() will work for the muxes without adding some software_nodes which brings us back to something like this patch-set.

That assumes that an I2C device is always present, which is not always the case - there are hot-pluggable devices on I2C buses.

Specifically, this series includes pluggable SFP modules, which fall into this category of "hot-pluggable I2C devices" - spanning several bus addresses (0x50, 0x51, 0x56). 0x50 is EEPROM like, but not quite as the top 128 bytes is paged and sometimes buggy in terms of access behaviour. 0x51 contains a bunch of monitoring and other controls for the module which again can be paged. At 0x56, there may possibly be some kind of device that translates I2C accesses to MDIO accesses to access a PHY onboard.

Consequently, the SFP driver and MDIO translation layer wants access to the I2C bus, rather than a device.

Now, before ARM was converted to DT, we had ways to cope with non-firmware described setups like this by using platform devices and platform data. Much of that ended up deprecated, because - hey - DT is great and more modern and the old way is disgusting and we want to get rid of it.

However, that approach locks us into describing stuff in firmware, which is unsuitable when something like this comes along.

I think what we need is both approaches. We need a way for the SFP driver (which is a platform_driver) to be used _without_ needing descriptions in firmware. I think we have that for GPIOs, but for an I2C bus, We have i2c_get_adapter() for I2C buses, but that needs the bus number - we could either pass the i2c_adapter or the adapter number through platform data to the SFP driver.

Quoted 3 lines

Or is there another solution to being able to reuse multi-driver based infrastructure that we have developed based on DT descriptions in situations such as an add-in PCI card?

The use of software fwnode-s as proposed in this patch-set is another way to deal with this. There has been work to abstract ACPI vs of/dt firmware-nodes into a generic fwnode concept and software-nodes are a third way to define fwnode-s for "struct device" devices.

Software nodes currently are mainly used as so called secondary fwnodes which means they can e.g. add extra properties to cover for the firmware description missing some info (which at least on ACPI happens more often then we would like).

But a software-node can also be used as the primary fwnode for a device. So what this patch-set does is move the i2c of/dt enumeration code over to the fwnode abstraction (1). This allows the driver for the SPF card to attach a software fwnode to the device for the i2c-controller which describes the hotplug pins + any other always present hw in the same way as it would be done in a devicetree fwnode and then the existing of/dt based SPF code can be re-used as is.

At least that is my understanding of this patch-set.

Regards,

Hans

1) This should result in no functional changes for existing devicetree use cases.

#40 lore raw

Re: [RFC 10/10] net: sfp: add support for fwnode

Quoted 30 lines · Hans de Goede
Quoted 10 lines

I think what we need is both approaches. We need a way for the SFP driver (which is a platform_driver) to be used _without_ needing descriptions in firmware. I think we have that for GPIOs, but for an I2C bus, We have i2c_get_adapter() for I2C buses, but that needs the bus number - we could either pass the i2c_adapter or the adapter number through platform data to the SFP driver.

Or is there another solution to being able to reuse multi-driver based infrastructure that we have developed based on DT descriptions in situations such as an add-in PCI card?

The use of software fwnode-s as proposed in this patch-set is another way to deal with this. There has been work to abstract ACPI vs of/dt firmware-nodes into a generic fwnode concept and software-nodes are a third way to define fwnode-s for "struct device" devices.

Software nodes currently are mainly used as so called secondary fwnodes which means they can e.g. add extra properties to cover for the firmware description missing some info (which at least on ACPI happens more often then we would like).

But a software-node can also be used as the primary fwnode for a device. So what this patch-set does is move the i2c of/dt enumeration code over to the fwnode abstraction (1). This allows the driver for the SPF card to attach a software fwnode to the device for the i2c-controller which describes the hotplug pins + any other always present hw in the same way as it would be done in a devicetree fwnode and then the existing of/dt based SPF code can be re-used as is.

Quoted 5 lines

At least that is my understanding of this patch-set.

Regards,

Hans

Hello Hans, your understanding is totally correct.

This PCIe device actually embeds much more than just a I2C controller. I should have made that clearer in the cover letter, sorry for the confusion. The PCIe card is actually using a lan9662x SoC which is meant to be used as an ethernet switch with 4 ports (2 RJ45 and two SFPS). In order to use this switch, the following drivers can be reused:
- lan966x-switch
- reset-microchip-sparx5
- lan966x_serdes
- reset-microchip-lan966x-phy
- mdio-mscc-miim
- pinctrl-lan966x
- atmel-flexcom
- i2c-at91
- i2c-mux
- i2c-mux-pinctrl
- sfp
- clk-lan966x
- lan966x-pci-mfd

All theses drivers are using of_* API and as such only works with a DT description. One solution that did seems acceptable to me (although not great)was to use mfd_cells and software_node description as primary node.

Since I wanted to convert these to be software_node compatible, I had to modify many subsystems (pinctrl, gpio, i2c, clocks, reset, etc). This is why I stated in the cover letter that "This series is part of a larger changeset that touches multiple subsystems". But clearly, it lacks more context and namely the list of subsystems that needed to be modify as well as the PCIe card type. I will modify this cover-letter to add more informations.

So indeed, this series is targetting at using devices which uses a software_node as a primary node and modifying subsystems to use the fwnode API in order to make that compatible with these software nodes. As you said, in order to avoid redefining the match tables and allow device_get_match_data to work with software_node, the trick was to reuse the of_table_id

However, I'm not totally happy with that as it seems we are doing what was done with the "old" platform_data (a bit cleaner maybe since it allows to reuse the driver with the fwnode API).

As Russell asked, I'm also really interested if someone has a solution to reuse device-tree description (overlays ?) to describe such hardware. However, the fact that CONFIG_OF isn't enabled on x86 config seems a bit complicated on this side. This also requires to load a device-tree overlay from the filesystem to describe the card, but that might be something that could be made generic to allow other uses-cases.

Signature · 3 lines
Clément Léger,
Embedded Linux and Kernel engineer at Bootlin
https://bootlin.com
maintainer
#41 lore raw

Re: [RFC 10/10] net: sfp: add support for fwnode

Quoted 4 lines

As Russell asked, I'm also really interested if someone has a solution to reuse device-tree description (overlays ?) to describe such hardware. However, the fact that CONFIG_OF isn't enabled on x86 config seems a bit complicated on this side.

It does work, intel even used it for one of there tiny x86 SoCs. Maybe it was Newton? If you search around you can find maybe a Linux Plumbers presentation about DT and x86.

You can probably use a udev rule, triggered by the PCIe device ID to load the DT overlay.

Do you actually need anything from the host other than PCIe? It sounds like this card is pretty self contained, so you won't need phandles pointing to the host i2c bus, or the hosts GPIOs? You only need phandles to your own i2c bus, your own GPIOs? That will make the overlay much simpler.

Andrew

#42 lore raw

Re: [RFC 10/10] net: sfp: add support for fwnode

Hi,

Quoted 7 lines · Andrew Lunn
Quoted 4 lines

As Russell asked, I'm also really interested if someone has a solution to reuse device-tree description (overlays ?) to describe such hardware. However, the fact that CONFIG_OF isn't enabled on x86 config seems a bit complicated on this side.

It does work, intel even used it for one of there tiny x86 SoCs. Maybe it was Newton?

IIRC those SoCs did not use standard EFI/ACPI though, but rather some other special firmware, I think it was SFI ? This is not so much about the CPU architecture as it is about the firmware/bootloader <-> OS interface.

Note I'm not saying this can not be done with EFI/ACPI systems, but I think it has never been tried.

Regards,

Hans

#43 lore raw

Re: [RFC 10/10] net: sfp: add support for fwnode

In reply to Andrew Lunn

Hi,

Quoted 7 lines · Andrew Lunn
Quoted 4 lines

As Russell asked, I'm also really interested if someone has a solution to reuse device-tree description (overlays ?) to describe such hardware. However, the fact that CONFIG_OF isn't enabled on x86 config seems a bit complicated on this side.

It does work, intel even used it for one of there tiny x86 SoCs. Maybe it was Newton?

IIRC those SoCs did not use standard EFI/ACPI though, but rather some other special firmware, I think it was SFI ? This is not so much about the CPU architecture as it is about the firmware/bootloader <-> OS interface.

Note I'm not saying this can not be done with EFI/ACPI systems, but I think it has never been tried.

Regards,

Hans

#44 lore raw

Re: [RFC 10/10] net: sfp: add support for fwnode

Quoted 6 lines · Hans de Goede
Quoted 5 lines · Andrew Lunn
Quoted 4 lines

As Russell asked, I'm also really interested if someone has a solution to reuse device-tree description (overlays ?) to describe such hardware. However, the fact that CONFIG_OF isn't enabled on x86 config seems a bit complicated on this side.

Quoted 7 lines
Quoted 2 lines

It does work, intel even used it for one of there tiny x86 SoCs. Maybe it was Newton?

IIRC those SoCs did not use standard EFI/ACPI though, but rather some other special firmware, I think it was SFI ? This is not so much about the CPU architecture as it is about the firmware/bootloader <-> OS interface.

I think Andrew refers to Intel SoCs that are using OF. Those so far are CE4xxx and SoFIA SoCs.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#45 lore raw

Re: [RFC 10/10] net: sfp: add support for fwnode

In reply to Andrew Lunn
Quoted 8 lines · Andrew Lunn
Quoted 4 lines

As Russell asked, I'm also really interested if someone has a solution to reuse device-tree description (overlays ?) to describe such hardware. However, the fact that CONFIG_OF isn't enabled on x86 config seems a bit complicated on this side.

It does work, intel even used it for one of there tiny x86 SoCs. Maybe it was Newton? If you search around you can find maybe a Linux Plumbers presentation about DT and x86.

Oh yes, I know it works and I tried loading an overlay using CONFIG_OF on a x86. Currently it does not works and generate a oops due to the fact that the lack of "/" node is not handled and that the error path has probably not been thoroughly tested. Adress remapping for PCI and lack of PCI bus description might also be a bit cumbersome but maybe this is the way to go.

I was saying a "bit complicated" as it is not often used and it would require enabling CONFIG_OF to support this feature as well as allowing loading overlays without any root node. But this is probably something that is also achievable.

Quoted 3 lines

You can probably use a udev rule, triggered by the PCIe device ID to load the DT overlay.

Or maybe load the overlay from the PCIe driver ? This would also allow to introduce some remapping of addresses (see below) inside the driver maybe.

Quoted 6 lines

Do you actually need anything from the host other than PCIe? It sounds like this card is pretty self contained, so you won't need phandles pointing to the host i2c bus, or the hosts GPIOs? You only need phandles to your own i2c bus, your own GPIOs? That will make the overlay much simpler.

Yes, the device is almost self contained, only the IRQ needs to be chained with the MSI.

Quoted 2 lines

Andrew

Signature · 3 lines
Clément Léger,
Embedded Linux and Kernel engineer at Bootlin
https://bootlin.com
#46 lore raw

Re: [RFC 10/10] net: sfp: add support for fwnode

In reply to Russell King (Oracle)
Quoted 50 lines · Russell King (Oracle)
Quoted 18 lines · Hans de Goede
Quoted 17 lines · Andy Shevchenko
Quoted 15 lines · Clément Léger
Quoted 9 lines · Andy Shevchenko
Quoted 5 lines · Clément Léger

Add support to retrieve a i2c bus in sfp with a fwnode. This support is using the fwnode API which also works with device-tree and ACPI. For this purpose, the device-tree and ACPI code handling the i2c adapter retrieval was factorized with the new code. This also allows i2c devices using a software_node description to be used by sfp code.

If I'm not mistaken this patch can even go separately right now, since all used APIs are already available.

This patches uses fwnode_find_i2c_adapter_by_node() which is introduced by "i2c: fwnode: add fwnode_find_i2c_adapter_by_node()" but they can probably be contributed both in a separate series.

Quoted 7 lines
Quoted 3 lines

I summon Hans into the discussion since I remember he recently refactored a bit I2C (ACPI/fwnode) APIs. Also he might have an idea about entire big picture approach with this series based on his ACPI experience.

If I understand this series correctly then this is about a PCI-E card which has an I2C controller on the card and behind that I2C-controller there are a couple if I2C muxes + I2C clients.

That is what I gathered as well.

Quoted 5 lines

Assuming I did understand the above correctly. One alternative would be to simply manually instantiate the I2C muxes + clients using i2c_new_client_device(). But I'm not sure if i2c_new_client_device() will work for the muxes without adding some software_nodes which brings us back to something like this patch-set.

That assumes that an I2C device is always present, which is not always the case - there are hot-pluggable devices on I2C buses.

Specifically, this series includes pluggable SFP modules, which fall into this category of "hot-pluggable I2C devices" - spanning several bus addresses (0x50, 0x51, 0x56). 0x50 is EEPROM like, but not quite as the top 128 bytes is paged and sometimes buggy in terms of access behaviour. 0x51 contains a bunch of monitoring and other controls for the module which again can be paged. At 0x56, there may possibly be some kind of device that translates I2C accesses to MDIO accesses to access a PHY onboard.

Consequently, the SFP driver and MDIO translation layer wants access to the I2C bus, rather than a device.

Quoted 8 lines

Now, before ARM was converted to DT, we had ways to cope with non-firmware described setups like this by using platform devices and platform data. Much of that ended up deprecated, because - hey - DT is great and more modern and the old way is disgusting and we want to get rid of it.

However, that approach locks us into describing stuff in firmware, which is unsuitable when something like this comes along.

Looks like this is a way to reinvent what FPGA should cope with already. And if I remember correctly the discussions about PCIe FPGAs (from 2016, though) the idea is that FPGA should have provided a firmware description with itself. I.o.w. If we are talking about "run-time configurable" devices they should provide a way to bring their description to the system.

The currently available way to do it is to get this from EEPROM / ROM specified on the hardware side in form of DT and ACPI blobs (representing overlays). Then the only part that is missed (at least for ACPI case) is to dynamically insert that based on the PCI BDF of the corresponding PCI bridge.

TL;DR: In my opinion such hardware must bring the description with itself in case it uses non-enumerable busses, such as SPI, I²C.

I dunno what was the last development in this area for FPGAs cases.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#47 lore raw

Re: [RFC 10/10] net: sfp: add support for fwnode

In reply to Clément Léger
[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 "Clément,

[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on wsa/i2c/for-next]
[also build test WARNING on driver-core/driver-core-testing linus/master v5.17-rc5 next-20220217] [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/Cl-ment-L-ger/add-support-for-fwnode-in-i2c-mux-system-and-sfp/20220222-004129
base:   https://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git i2c/for-next
config: arm-randconfig-r034-20220221 (https://download.01.org/0day-ci/archive/20220222/[email protected]/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project d271fc04d5b97b12e6b797c6067d3c96a8d7470e)

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
# install arm cross compiling tool for clang build
# apt-get install binutils-arm-linux-gnueabi
# https://github.com/0day-ci/linux/commit/88ff2fe34392c6bdae43f555e0d1373fecab434f
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Cl-ment-L-ger/add-support-for-fwnode-in-i2c-mux-system-and-sfp/20220222-004129 git checkout 88ff2fe34392c6bdae43f555e0d1373fecab434f
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=arm SHELL=/bin/bash drivers/net/phy/

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

All warnings (new ones prefixed by >>):

>> drivers/net/phy/sfp.c:2502:6: warning: variable 'i2c' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
           if (dev_fwnode(&pdev->dev)) {
               ^~~~~~~~~~~~~~~~~~~~~~
   drivers/net/phy/sfp.c:2523:7: note: uninitialized use occurs here
           if (!i2c)
                ^~~
   drivers/net/phy/sfp.c:2502:2: note: remove the 'if' if its condition is always true
           if (dev_fwnode(&pdev->dev)) {
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/net/phy/sfp.c:2486:25: note: initialize the variable 'i2c' to silence this warning
           struct i2c_adapter *i2c;
                                  ^
                                   = NULL

1 warning generated.

vim +2502 drivers/net/phy/sfp.c

2482
2483 static int sfp_probe(struct platform_device *pdev)
2484 {
2485 const struct sff_data *sff;
2486 struct i2c_adapter *i2c;
2487 char *sfp_irq_name;
2488 struct sfp *sfp;
2489 int err, i;
2490
2491 sfp = sfp_alloc(&pdev->dev);
2492 if (IS_ERR(sfp))
2493 return PTR_ERR(sfp);
2494
2495 platform_set_drvdata(pdev, sfp);
2496
2497 err = devm_add_action(sfp->dev, sfp_cleanup, sfp);
2498 if (err < 0)
2499 return err;
2500
2501 sff = sfp->type = &sfp_data;

> 2502		if (dev_fwnode(&pdev->dev)) {

2503 struct fwnode_handle *fwnode = dev_fwnode(&pdev->dev);
2504 struct fwnode_handle *np;
2505
2506 if (!is_acpi_device_node(fwnode)) {
2507 sff = device_get_match_data(&pdev->dev);
2508 if (WARN_ON(!sff))
2509 return -EINVAL;
2510
2511 sfp->type = sff;
2512 }
2513
2514 np = fwnode_find_reference(fwnode, "i2c-bus", 0);
2515 if (!np) {
2516 dev_err(&pdev->dev, "Cannot parse i2c-bus\n");
2517 return -ENODEV;
2518 }
2519 i2c = fwnode_find_i2c_adapter_by_node(np);
2520 fwnode_handle_put(np);
2521 }
2522
2523 if (!i2c)
2524 return -EPROBE_DEFER;
2525
2526 err = sfp_i2c_configure(sfp, i2c);
2527 if (err < 0) {
2528 i2c_put_adapter(i2c);
2529 return err;
2530 }
2531
2532 for (i = 0; i < GPIO_MAX; i++)
2533 if (sff->gpios & BIT(i)) {
2534 sfp->gpio[i] = devm_gpiod_get_optional(sfp->dev,
2535 gpio_of_names[i], gpio_flags[i]);
2536 if (IS_ERR(sfp->gpio[i]))
2537 return PTR_ERR(sfp->gpio[i]);
2538 }
2539
2540 sfp->get_state = sfp_gpio_get_state;
2541 sfp->set_state = sfp_gpio_set_state;
2542
2543 /* Modules that have no detect signal are always present */
2544 if (!(sfp->gpio[GPIO_MODDEF0]))
2545 sfp->get_state = sff_gpio_get_state;
2546
2547 device_property_read_u32(&pdev->dev, "maximum-power-milliwatt",
2548 &sfp->max_power_mW);
2549 if (!sfp->max_power_mW)
2550 sfp->max_power_mW = 1000;
2551
2552 dev_info(sfp->dev, "Host maximum power %u.%uW\n",
2553 sfp->max_power_mW / 1000, (sfp->max_power_mW / 100) % 10);
2554
2555 /* Get the initial state, and always signal TX disable,
2556 * since the network interface will not be up.
2557 */
2558 sfp->state = sfp_get_state(sfp) | SFP_F_TX_DISABLE;
2559
2560 if (sfp->gpio[GPIO_RATE_SELECT] &&
2561 gpiod_get_value_cansleep(sfp->gpio[GPIO_RATE_SELECT]))
2562 sfp->state |= SFP_F_RATE_SELECT;
2563 sfp_set_state(sfp, sfp->state);
2564 sfp_module_tx_disable(sfp);
2565 if (sfp->state & SFP_F_PRESENT) {
2566 rtnl_lock();
2567 sfp_sm_event(sfp, SFP_E_INSERT);
2568 rtnl_unlock();
2569 }
2570
2571 for (i = 0; i < GPIO_MAX; i++) {
2572 if (gpio_flags[i] != GPIOD_IN || !sfp->gpio[i])
2573 continue;
2574
2575 sfp->gpio_irq[i] = gpiod_to_irq(sfp->gpio[i]);
2576 if (sfp->gpio_irq[i] < 0) {
2577 sfp->gpio_irq[i] = 0;
2578 sfp->need_poll = true;
2579 continue;
2580 }
2581
2582 sfp_irq_name = devm_kasprintf(sfp->dev, GFP_KERNEL,
2583 "%s-%s", dev_name(sfp->dev),
2584 gpio_of_names[i]);
2585
2586 if (!sfp_irq_name)
2587 return -ENOMEM;
2588
2589 err = devm_request_threaded_irq(sfp->dev, sfp->gpio_irq[i],
2590 NULL, sfp_irq,
2591 IRQF_ONESHOT |
2592 IRQF_TRIGGER_RISING |
2593 IRQF_TRIGGER_FALLING,
2594 sfp_irq_name, sfp);
2595 if (err) {
2596 sfp->gpio_irq[i] = 0;
2597 sfp->need_poll = true;
2598 }
2599 }
2600
2601 if (sfp->need_poll)
2602 mod_delayed_work(system_wq, &sfp->poll, poll_jiffies);
2603
2604 /* We could have an issue in cases no Tx disable pin is available or
2605 * wired as modules using a laser as their light source will continue to
2606 * be active when the fiber is removed. This could be a safety issue and
2607 * we should at least warn the user about that.
2608 */
2609 if (!sfp->gpio[GPIO_TX_DISABLE])
2610 dev_warn(sfp->dev,
2611 "No tx_disable pin: SFP modules will always be emitting.\n");
2612
2613 sfp->sfp_bus = sfp_register_socket(sfp->dev, sfp, &sfp_module_ops);
2614 if (!sfp->sfp_bus)
2615 return -ENOMEM;
2616
2617 sfp_debugfs_init(sfp);
2618
2619 return 0;
2620 }
2621

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]

#48 lore raw
In reply to Clément Léger
Quoted 27 lines · Clément Léger

The purpose of this work is to allow i2c muxes and adapters to be usable with devices that are described with software_node. A solution for this is to use the fwnode API which works with both device-tree, ACPI and software node. In this series, functions are added to retrieve i2c_adapter from fwnode and to create new mux adapters from fwnode.

This series is part of a larger changeset that touches multiple subsystems. series will be sent separately for each subsystems since the amount of modified file is quite large. The following cover letter gives an overview of this work:

---

The LAN966X SoC can either run it's own Linux system or be plugged in a PCIe slot as a PCIe switch. When running with a Linux system, a device-tree description is used to describe the system. However, when plugged in a PCIe slot (on a x86), there is no device-tree support and the peripherals that are present must be described in some other way.

Reusing the existing drivers is of course mandatory and they should also be able to work without device-tree description. We decided to describe this card using software nodes and a MFD device. Indeed, the MFD subsystem allows to describe such systems using struct mfd_cells and mfd_add_devices(). This support also allows to attach a software_node description which might be used by fwnode API in drivers and subsystems.

Quoted 5 lines

We thought about adding CONFIG_OF to x86 and potentially describe this card using device-tree overlays but it introduce other problems that also seems difficult to solve (overlay loading without base device-tree, fixup of IRQs, adresses, and so on) and CONFIG_OF is not often enabled on x86 to say the least.

Why it can't be described by SSDT overlay (if the x86 platform in question is ACPI based)?

Quoted 18 lines

TLDR: I know the series touches a lot of different files and has big implications, but it turns out software_nodes looks the "best" way of achieving this goal and has the advantage of converting some subsystems to be node agnostics, also allowing some ACPI factorization. Criticism is of course welcome as I might have overlooked something way simpler !

---

This series introduce a number of changes in multiple subsystems to allow registering and using devices that are described with a software_node description attached to a mfd_cell, making them usable with the fwnode API. It was needed to modify many subsystem where CONFIG_OF was tightly integrated through the use of of_xlate() functions and other of_* calls. New calls have been added to use fwnode API and thus be usable with a wider range of nodes. Functions that are used to get the devices (pinctrl_get, clk_get and so on) also needed to be changed to use the fwnode API internally.

Quoted 7 lines

For instance, the clk framework has been modified to add a fwnode_xlate() callback and a new named fwnode_clk_add_hw_provider() has been added. This function will register a clock using fwnode_xlate() callback. Note that since the fwnode API is compatible with devices that have a of_node member set, it will still be possible to use the driver and get the clocks with CONFIG_OF enabled configurations.

How does this all is compatible with ACPI approaches? I mean we usually do not reintroduce 1:1 DT schemas in ACPI.

I think the CCF should be converted to use fwnode APIs and meanwhile we may discuss how to deal with clocks on ACPI platforms, because it may be a part of the power management methods.

Quoted 7 lines

In some subsystems, it was possible to keep OF related function by wrapping the fwnode ones. It is not yet sure if both support (device-tree and fwnode) should still continue to coexists. For instance if fwnode_xlate() and of_xlate() should remain since the fwnode version also supports device-tree. Removing of_xlate() would of course require to modify all drivers that uses it.

Quoted 8 lines

Here is an excerpt of the lan966x description when used as a PCIe card. The complete description is visible at [2]. This part only describe the flexcom controller and the fixed-clock that is used as an input clock.

static const struct property_entry ddr_clk_props[] = {
        PROPERTY_ENTRY_U32("clock-frequency", 30000000),

        PROPERTY_ENTRY_U32("#clock-cells", 0),

Why this is used?

Quoted 104 lines
        {}
};

static const struct software_node ddr_clk_node = {
.name = "ddr_clk",
.properties = ddr_clk_props,
};

static const struct property_entry lan966x_flexcom_props[] = {
        PROPERTY_ENTRY_U32("atmel,flexcom-mode", ATMEL_FLEXCOM_MODE_TWI),
        PROPERTY_ENTRY_REF("clocks", &ddr_clk_node),
        {}
};

static const struct software_node lan966x_flexcom_node = {
.name = "lan966x-flexcom",
.properties = lan966x_flexcom_props,
};

...

static struct resource lan966x_flexcom_res[] = {
        [0] = {
                .flags = IORESOURCE_MEM,
                .start = LAN966X_DEV_ADDR(FLEXCOM_0_FLEXCOM_REG),
                .end = LAN966X_DEV_ADDR(FLEXCOM_0_FLEXCOM_REG),
        },
};

...

static struct mfd_cell lan966x_pci_mfd_cells[] = {
        ...
        [LAN966X_DEV_DDR_CLK] = {
                .name = "of_fixed_clk",
                .swnode = &ddr_clk_node,
        },
        [LAN966X_DEV_FLEXCOM] = {
                .name = "atmel_flexcom",
                .num_resources = ARRAY_SIZE(lan966x_flexcom_res),
                .resources = lan966x_flexcom_res,
                .swnode = &lan966x_flexcom_node,
        },
        ...
},

And finally registered using:

ret = devm_mfd_add_devices(dev, PLATFORM_DEVID_AUTO,

                           lan966x_pci_mfd_cells,
                           ARRAY_SIZE(lan966x_pci_mfd_cells), pci_base, irq_base,
                           irq_domain);

With the modifications that have been made on this tree, it is now possible to probe such description using existing platform drivers, providing that they have been modified a bit to retrieve properties using fwnode API and using the fwnode_xlate() callback instead of of_xlate().

This series has been tested on a x86 kernel build without CONFIG_OF. Another kernel was also built with COMPILE_TEST and CONFIG_OF support to build as most drivers as possible. It was also tested on a sparx5 arm64 with CONFIG_OF. However, it was not tested with an ACPI description evolved enough to validate all the changes.

A branch containing all theses modifications can be seen at [1] along with a PCIe driver [2] which describes the card using software nodes. Modifications that are on this branch are not completely finished (ie, subsystems modifications for fwnode have not been factorized with OF for all of them) in absence of feedback on the beginning of this work from the community.

[1] https://github.com/clementleger/linux/tree/fwnode_support
[2] https://github.com/clementleger/linux/blob/fwnode_support/drivers/mfd/lan966x_pci_mfd.c

Clément Léger (10):
property: add fwnode_match_node()
property: add fwnode_get_match_data()
base: swnode: use fwnode_get_match_data()
property: add a callback parameter to fwnode_property_match_string()
property: add fwnode_property_read_string_index()
i2c: fwnode: add fwnode_find_i2c_adapter_by_node()
i2c: of: use fwnode_get_i2c_adapter_by_node()
i2c: mux: pinctrl: remove CONFIG_OF dependency and use fwnode API
i2c: mux: add support for fwnode
net: sfp: add support for fwnode

 drivers/base/property.c             | 133 ++++++++++++++++++++++++++--
 drivers/base/swnode.c               |   1 +
 drivers/i2c/Makefile                |   1 +
 drivers/i2c/i2c-core-fwnode.c       |  40 +++++++++
 drivers/i2c/i2c-core-of.c           |  30 -------
 drivers/i2c/i2c-mux.c               |  39 ++++----
 drivers/i2c/muxes/Kconfig           |   1 -
 drivers/i2c/muxes/i2c-mux-pinctrl.c |  21 ++---
 drivers/net/phy/sfp.c               |  44 +++------
 include/linux/i2c.h                 |   7 +-
 include/linux/property.h            |   9 ++
 11 files changed, 225 insertions(+), 101 deletions(-)
 create mode 100644 drivers/i2c/i2c-core-fwnode.c
Signature · 1 line
2.34.1
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#49 lore raw
Quoted 9 lines · Andy Shevchenko
Quoted 6 lines

We thought about adding CONFIG_OF to x86 and potentially describe this card using device-tree overlays but it introduce other problems that also seems difficult to solve (overlay loading without base device-tree, fixup of IRQs, adresses, and so on) and CONFIG_OF is not often enabled on x86 to say the least.

Why it can't be described by SSDT overlay (if the x86 platform in question is ACPI based)?

This devices uses a SoC for which drivers are already available but are meant to be used by a device-tree description. These drivers uses the following subsystems:
- reset (no ACPI support ?)
- clk (no ACPI support ?)
- pinctrl (no ACPI support ?)
- syscon (no ACPI support ?)
- gpio
- phy
- mdio

Converting existing OF support to fwnode support and thus allowing drivers and subsystems to be compatible with software nodes seemed like the easiest way to do what I needed by keeping all existing drivers. With this support, the driver is completely self-contained and does allow the card to be plugged on whatever platform the user may have.

Again, the PCI card is independent of the platform, I do not really see why it should be described using platform description language.

Quoted 19 lines
Quoted 11 lines

This series introduce a number of changes in multiple subsystems to allow registering and using devices that are described with a software_node description attached to a mfd_cell, making them usable with the fwnode API. It was needed to modify many subsystem where CONFIG_OF was tightly integrated through the use of of_xlate() functions and other of_* calls. New calls have been added to use fwnode API and thus be usable with a wider range of nodes. Functions that are used to get the devices (pinctrl_get, clk_get and so on) also needed to be changed to use the fwnode API internally.

Quoted 7 lines

For instance, the clk framework has been modified to add a fwnode_xlate() callback and a new named fwnode_clk_add_hw_provider() has been added. This function will register a clock using fwnode_xlate() callback. Note that since the fwnode API is compatible with devices that have a of_node member set, it will still be possible to use the driver and get the clocks with CONFIG_OF enabled configurations.

Quoted 2 lines

How does this all is compatible with ACPI approaches? I mean we usually do not reintroduce 1:1 DT schemas in ACPI.

For the moment, I only added fwnode API support as an alternative to support both OF and software nodes. ACPI is not meant to be handled by this code "as-is". There is for sure some modifications to be made and I do not know how clocks are handled when using ACPI. Based on some thread dating back to 2018 [1], it seem it was even not supported at all.

To be clear, I added the equivalent of the OF support but using fwnode API because I was interested primarly in using it with software nodes and still wanted OF support to work. I did not planned it to be "ACPI compliant" right now since I do not have any knowledge in that field.

Quoted 4 lines

I think the CCF should be converted to use fwnode APIs and meanwhile we may discuss how to deal with clocks on ACPI platforms, because it may be a part of the power management methods.

Ok, before going down that way, should the fwnode support be the "only" one, ie remove of_clk_register and others and convert them to fwnode_clk_register for instance or should it be left to avoid modifying all clock drivers ?

Quoted 12 lines
Quoted 12 lines

In some subsystems, it was possible to keep OF related function by wrapping the fwnode ones. It is not yet sure if both support (device-tree and fwnode) should still continue to coexists. For instance if fwnode_xlate() and of_xlate() should remain since the fwnode version also supports device-tree. Removing of_xlate() would of course require to modify all drivers that uses it.

Here is an excerpt of the lan966x description when used as a PCIe card. The complete description is visible at [2]. This part only describe the flexcom controller and the fixed-clock that is used as an input clock.

Quoted 7 lines
Quoted 4 lines
static const struct property_entry ddr_clk_props[] = {
        PROPERTY_ENTRY_U32("clock-frequency", 30000000),  

        PROPERTY_ENTRY_U32("#clock-cells", 0),  

Why this is used?

These props actually describes a fixed-clock properties. When adding fwnode support to clk framework, it was needed to add the equivalent of of_xlate() for fwnode (fwnode_xlate()). The number of cells used to describe a reference is still needed to do the translation using fwnode_property_get_reference_args() and give the correct arguments to fwnode_xlate().

[1]
https://lore.kernel.org/lkml/[email protected]/T/

Signature · 3 lines
Clément Léger,
Embedded Linux and Kernel engineer at Bootlin
https://bootlin.com
#50 lore raw
Quoted 23 lines · Clément Léger
Quoted 8 lines · Andy Shevchenko
Quoted 5 lines

We thought about adding CONFIG_OF to x86 and potentially describe this card using device-tree overlays but it introduce other problems that also seems difficult to solve (overlay loading without base device-tree, fixup of IRQs, adresses, and so on) and CONFIG_OF is not often enabled on x86 to say the least.

Why it can't be described by SSDT overlay (if the x86 platform in question is ACPI based)?

This devices uses a SoC for which drivers are already available but are meant to be used by a device-tree description. These drivers uses the following subsystems:
- reset (no ACPI support ?)
- clk (no ACPI support ?)
- pinctrl (no ACPI support ?)
- syscon (no ACPI support ?)
- gpio
- phy
- mdio

Quoted 5 lines

Converting existing OF support to fwnode support and thus allowing drivers and subsystems to be compatible with software nodes seemed like the easiest way to do what I needed by keeping all existing drivers. With this support, the driver is completely self-contained and does allow the card to be plugged on whatever platform the user may have.

I agree with Hans on the point that converting to / supporting fwnode is a good thing by its own.

Quoted 2 lines

Again, the PCI card is independent of the platform, I do not really see why it should be described using platform description language.

Yep, and that why it should cope with the platforms it's designed to be used with.

Quoted 28 lines
Quoted 18 lines
Quoted 10 lines

This series introduce a number of changes in multiple subsystems to allow registering and using devices that are described with a software_node description attached to a mfd_cell, making them usable with the fwnode API. It was needed to modify many subsystem where CONFIG_OF was tightly integrated through the use of of_xlate() functions and other of_* calls. New calls have been added to use fwnode API and thus be usable with a wider range of nodes. Functions that are used to get the devices (pinctrl_get, clk_get and so on) also needed to be changed to use the fwnode API internally.

Quoted 7 lines

For instance, the clk framework has been modified to add a fwnode_xlate() callback and a new named fwnode_clk_add_hw_provider() has been added. This function will register a clock using fwnode_xlate() callback. Note that since the fwnode API is compatible with devices that have a of_node member set, it will still be possible to use the driver and get the clocks with CONFIG_OF enabled configurations.

Quoted 2 lines

How does this all is compatible with ACPI approaches? I mean we usually do not reintroduce 1:1 DT schemas in ACPI.

For the moment, I only added fwnode API support as an alternative to support both OF and software nodes. ACPI is not meant to be handled by this code "as-is". There is for sure some modifications to be made and I do not know how clocks are handled when using ACPI. Based on some thread dating back to 2018 [1], it seem it was even not supported at all.

Quoted 5 lines

To be clear, I added the equivalent of the OF support but using fwnode API because I was interested primarly in using it with software nodes and still wanted OF support to work. I did not planned it to be "ACPI compliant" right now since I do not have any knowledge in that field.

And here is the problem. We have a few different resource providers (a.k.a. firmware interfaces) which we need to cope with.

What is going on in this series seems to me quite a violation of the layers and technologies. But I guess you may find a supporter of your ideas (I mean Enrico). However, I'm on the other side and do not like this approach.

Quoted 8 lines
Quoted 3 lines

I think the CCF should be converted to use fwnode APIs and meanwhile we may discuss how to deal with clocks on ACPI platforms, because it may be a part of the power management methods.

Ok, before going down that way, should the fwnode support be the "only" one, ie remove of_clk_register and others and convert them to fwnode_clk_register for instance or should it be left to avoid modifying all clock drivers ?

IRQ domain framework decided to cohabit both, while deprecating the OF one. (see "add" vs. "create" APIs there). I think it's a sane choice.

Quoted 16 lines
Quoted 16 lines
Quoted 15 lines

In some subsystems, it was possible to keep OF related function by wrapping the fwnode ones. It is not yet sure if both support (device-tree and fwnode) should still continue to coexists. For instance if fwnode_xlate() and of_xlate() should remain since the fwnode version also supports device-tree. Removing of_xlate() would of course require to modify all drivers that uses it.

Here is an excerpt of the lan966x description when used as a PCIe card. The complete description is visible at [2]. This part only describe the flexcom controller and the fixed-clock that is used as an input clock.

static const struct property_entry ddr_clk_props[] = {
        PROPERTY_ENTRY_U32("clock-frequency", 30000000),  

        PROPERTY_ENTRY_U32("#clock-cells", 0),  
Quoted 8 lines
Quoted 1 line

Why this is used?

These props actually describes a fixed-clock properties. When adding fwnode support to clk framework, it was needed to add the equivalent of of_xlate() for fwnode (fwnode_xlate()). The number of cells used to describe a reference is still needed to do the translation using fwnode_property_get_reference_args() and give the correct arguments to fwnode_xlate().

What you described is the programming (overkilled) point. But does hardware needs this? I.o.w. does it make sense in the _hardware_ description?

Quoted 2 lines

[1]
https://lore.kernel.org/lkml/[email protected]/T/

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#51 lore raw

Le Wed, 23 Feb 2022 16:46:45 +0200,
Andy Shevchenko <[email protected]> a écrit :

[...]

Quoted 7 lines
Quoted 6 lines

Converting existing OF support to fwnode support and thus allowing drivers and subsystems to be compatible with software nodes seemed like the easiest way to do what I needed by keeping all existing drivers. With this support, the driver is completely self-contained and does allow the card to be plugged on whatever platform the user may have.

Quoted 8 lines

I agree with Hans on the point that converting to / supporting fwnode is a good thing by its own.

Quoted 2 lines

Again, the PCI card is independent of the platform, I do not really see why it should be described using platform description language.

Yep, and that why it should cope with the platforms it's designed to be used with.

I don't think PCIe card manufacturer expect them to be used solely on a x86 platform with ACPI. So why should I used ACPI to describe it (or DT by the way), that's my point.

[...]

Quoted 8 lines
Quoted 8 lines

For the moment, I only added fwnode API support as an alternative to support both OF and software nodes. ACPI is not meant to be handled by this code "as-is". There is for sure some modifications to be made and I do not know how clocks are handled when using ACPI. Based on some thread dating back to 2018 [1], it seem it was even not supported at all.

Quoted 8 lines
Quoted 5 lines

To be clear, I added the equivalent of the OF support but using fwnode API because I was interested primarly in using it with software nodes and still wanted OF support to work. I did not planned it to be "ACPI compliant" right now since I do not have any knowledge in that field.

And here is the problem. We have a few different resource providers (a.k.a. firmware interfaces) which we need to cope with.

Understood that but does adding fwnode support means it should work as-is with both DT and ACPI ? ACPI code is still in place and only the of part was converted. But maybe you expect the fwnode prot to be conformant with ACPI.

Quoted 5 lines

What is going on in this series seems to me quite a violation of the layers and technologies. But I guess you may find a supporter of your ideas (I mean Enrico). However, I'm on the other side and do not like this approach.

As I said in the cover-letter, this approach is the only one that I did found acceptable without being tied to some firmware description. If you have another more portable approach, I'm ok with that. But this solution should ideally work with pinctrl, gpio, clk, reset, phy, i2c, i2c-mux without rewriting half of the code. And also allows to easily swap the PCIe card to other slots/computer without having to modify the description.

Quoted 9 lines
Quoted 6 lines

Ok, before going down that way, should the fwnode support be the "only" one, ie remove of_clk_register and others and convert them to fwnode_clk_register for instance or should it be left to avoid modifying all clock drivers ?

IRQ domain framework decided to cohabit both, while deprecating the OF one. (see "add" vs. "create" APIs there). I think it's a sane choice.

Ok, thanks for the info.

[...]

Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
static const struct property_entry ddr_clk_props[] = {
        PROPERTY_ENTRY_U32("clock-frequency", 30000000),    
  
        PROPERTY_ENTRY_U32("#clock-cells", 0),    
Quoted 8 lines
Quoted 1 line

Why this is used?

These props actually describes a fixed-clock properties. When adding fwnode support to clk framework, it was needed to add the equivalent of of_xlate() for fwnode (fwnode_xlate()). The number of cells used to describe a reference is still needed to do the translation using fwnode_property_get_reference_args() and give the correct arguments to fwnode_xlate().

Quoted 2 lines

What you described is the programming (overkilled) point. But does hardware needs this? I.o.w. does it make sense in the _hardware_ description?

This does not makes sense for the hardware of course. It also does not makes sense for the hardware to provide that in the device-tree though. I actually think this should be only provided by the drivers but it might be difficult to parse the descriptions then (either DT or software_node), at least that's how it works right now.

Signature · 3 lines
Clément Léger,
Embedded Linux and Kernel engineer at Bootlin
https://bootlin.com
#52 lore raw
Quoted 2 lines · Clément Léger

Le Wed, 23 Feb 2022 16:46:45 +0200,
Andy Shevchenko <[email protected]> a écrit :

...

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

Again, the PCI card is independent of the platform, I do not really see why it should be described using platform description language.

Yep, and that why it should cope with the platforms it's designed to be used with.

I don't think PCIe card manufacturer expect them to be used solely on a x86 platform with ACPI. So why should I used ACPI to describe it (or DT by the way), that's my point.

Because you want it to be used on x86 platforms. On the rest it needs DT or whatever is required by those platforms (I dunno about Zephyr RTOS, or VxWorks, or *BSDs).

...

Quoted 13 lines
Quoted 13 lines
Quoted 12 lines

For the moment, I only added fwnode API support as an alternative to support both OF and software nodes. ACPI is not meant to be handled by this code "as-is". There is for sure some modifications to be made and I do not know how clocks are handled when using ACPI. Based on some thread dating back to 2018 [1], it seem it was even not supported at all.

To be clear, I added the equivalent of the OF support but using fwnode API because I was interested primarly in using it with software nodes and still wanted OF support to work. I did not planned it to be "ACPI compliant" right now since I do not have any knowledge in that field.

Quoted 7 lines
Quoted 2 lines

And here is the problem. We have a few different resource providers (a.k.a. firmware interfaces) which we need to cope with.

Understood that but does adding fwnode support means it should work as-is with both DT and ACPI ? ACPI code is still in place and only the of part was converted. But maybe you expect the fwnode prot to be conformant with ACPI.

Not only me, I believe Mark also was against using pure DT approach on ACPI enabled platforms.

...

Quoted 5 lines
Quoted 4 lines

What is going on in this series seems to me quite a violation of the layers and technologies. But I guess you may find a supporter of your ideas (I mean Enrico). However, I'm on the other side and do not like this approach.

Quoted 7 lines

As I said in the cover-letter, this approach is the only one that I did found acceptable without being tied to some firmware description. If you have another more portable approach, I'm ok with that. But this solution should ideally work with pinctrl, gpio, clk, reset, phy, i2c, i2c-mux without rewriting half of the code. And also allows to easily swap the PCIe card to other slots/computer without having to modify the description.

My proposal is to use overlays that card provides with itself. These are supported mechanisms by Linux kernel.

...

Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 6 lines
Quoted 4 lines
static const struct property_entry ddr_clk_props[] = {
        PROPERTY_ENTRY_U32("clock-frequency", 30000000),    
  
        PROPERTY_ENTRY_U32("#clock-cells", 0),    

Why this is used?

These props actually describes a fixed-clock properties. When adding fwnode support to clk framework, it was needed to add the equivalent of of_xlate() for fwnode (fwnode_xlate()). The number of cells used to describe a reference is still needed to do the translation using fwnode_property_get_reference_args() and give the correct arguments to fwnode_xlate().

Quoted 5 lines
Quoted 2 lines

What you described is the programming (overkilled) point. But does hardware needs this? I.o.w. does it make sense in the _hardware_ description?

This does not makes sense for the hardware of course. It also does not makes sense for the hardware to provide that in the device-tree though.

How it can be discovered and enumerated without a hint? And under hint we may understand, in particular, the overlay blob.

Quoted 3 lines

I actually think this should be only provided by the drivers but it might be difficult to parse the descriptions then (either DT or software_node), at least that's how it works right now.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#53 lore raw
Quoted 7 lines · Andy Shevchenko
Quoted 5 lines · Clément Léger
Quoted 2 lines · Andy Shevchenko

And here is the problem. We have a few different resource providers (a.k.a. firmware interfaces) which we need to cope with.

Quoted 7 lines
Quoted 4 lines

Understood that but does adding fwnode support means it should work as-is with both DT and ACPI ? ACPI code is still in place and only the of part was converted. But maybe you expect the fwnode prot to be conformant with ACPI.

Not only me, I believe Mark also was against using pure DT approach on ACPI enabled platforms.

I'm not 100% clear on the context here (I did dig about a bit in the thread on lore but it looks like there's some extra context here) but in general I don't think there's any enthusiasm for trying to mix different firmware interfaces on a single system. Certainly in the case of ACPI and DT they have substantial differences in system model and trying to paper over those cracks and integrate the two is a route to trouble. This doesn't look like it's trying to use a DT on an ACPI system though?

There's been some discussion on how to handle loadable descriptions for things like FPGA but I don't recall it ever having got anywhere concrete
- I could have missed something. Those are dynamic cases which are more trouble though. For something that's a PCI card it's not clear that we can't just statically instanitate the devices from kernel code, that was how the MFD subsystem started off although it's now primarily applied to other applications. That looks to be what's going on here?

There were separately some issues with people trying to create completely swnode based enumeration mechanisms for things that required totally independent code for handling swnodes which seemed very concerning but it's not clear to me if that's what's going on here.

Quoted 10 lines
Quoted 7 lines

As I said in the cover-letter, this approach is the only one that I did found acceptable without being tied to some firmware description. If you have another more portable approach, I'm ok with that. But this solution should ideally work with pinctrl, gpio, clk, reset, phy, i2c, i2c-mux without rewriting half of the code. And also allows to easily swap the PCIe card to other slots/computer without having to modify the description.

My proposal is to use overlays that card provides with itself. These are supported mechanisms by Linux kernel.

We have code for DT overlays in the kernel but it's not generically available. There's issues with binding onto the platform device tree, though they're less of a problem with something like this where it seems to be a separate card with no cross links.

#54 lore raw
Quoted 16 lines · Mark Brown
Quoted 7 lines · Andy Shevchenko
Quoted 5 lines · Clément Léger
Quoted 2 lines · Andy Shevchenko

And here is the problem. We have a few different resource providers (a.k.a. firmware interfaces) which we need to cope with.

Quoted 7 lines
Quoted 4 lines

Understood that but does adding fwnode support means it should work as-is with both DT and ACPI ? ACPI code is still in place and only the of part was converted. But maybe you expect the fwnode prot to be conformant with ACPI.

Not only me, I believe Mark also was against using pure DT approach on ACPI enabled platforms.

Quoted 7 lines

I'm not 100% clear on the context here (I did dig about a bit in the thread on lore but it looks like there's some extra context here) but in general I don't think there's any enthusiasm for trying to mix different firmware interfaces on a single system. Certainly in the case of ACPI and DT they have substantial differences in system model and trying to paper over those cracks and integrate the two is a route to trouble. This doesn't look like it's trying to use a DT on an ACPI system though?

Ideally no, but it is a possibility mentionned by Andrew, use DT overlays on an ACPI system. This series did not took this way (yet). Andrew mentionned that it could potentially be done but judging by your comment, i'm not sure you agree with that.

Quoted 8 lines

There's been some discussion on how to handle loadable descriptions for things like FPGA but I don't recall it ever having got anywhere concrete
- I could have missed something. Those are dynamic cases which are more trouble though. For something that's a PCI card it's not clear that we can't just statically instanitate the devices from kernel code, that was how the MFD subsystem started off although it's now primarily applied to other applications. That looks to be what's going on here?

Yes, in this series, I used the MFD susbsytems with mfd_cells. These cells are attached with a swnode. Then, needed subsystems are modified to use the fwnode API to be able to use them with devices that have a swnode as a primary node.

Quoted 5 lines

There were separately some issues with people trying to create completely swnode based enumeration mechanisms for things that required totally independent code for handling swnodes which seemed very concerning but it's not clear to me if that's what's going on here.

The card is described entirely using swnode that in a MFD PCI driver, everything is described statically. The "enumeration" is static since all the devices are described in the driver and registered using mfd_add_device() at probe time. Thus, I don't think it adds an enumeration mechanism like you mention but I may be wrong.

Quoted 9 lines
Quoted 8 lines
Quoted 8 lines

As I said in the cover-letter, this approach is the only one that I did found acceptable without being tied to some firmware description. If you have another more portable approach, I'm ok with that. But this solution should ideally work with pinctrl, gpio, clk, reset, phy, i2c, i2c-mux without rewriting half of the code. And also allows to easily swap the PCIe card to other slots/computer without having to modify the description.

Quoted 7 lines
Quoted 2 lines

My proposal is to use overlays that card provides with itself. These are supported mechanisms by Linux kernel.

We have code for DT overlays in the kernel but it's not generically available. There's issues with binding onto the platform device tree, though they're less of a problem with something like this where it seems to be a separate card with no cross links.

Indeed, the card does not have crosslinks with other devices and thus it might be a solution to use a device-tree overlay (loaded from the filesystem). But I'm not sure if it's a good idea to do that on a ACPI enabled platform.

Signature · 3 lines
Clément Léger,
Embedded Linux and Kernel engineer at Bootlin
https://bootlin.com
#55 lore raw
Quoted 8 lines · Clément Léger
Quoted 1 line · Mark Brown

This doesn't look like it's trying to use a DT on an ACPI system though?

Ideally no, but it is a possibility mentionned by Andrew, use DT overlays on an ACPI system. This series did not took this way (yet). Andrew mentionned that it could potentially be done but judging by your comment, i'm not sure you agree with that.

That seems like it's opening a can of worms that might be best left closed.

Quoted 8 lines
Quoted 7 lines

There's been some discussion on how to handle loadable descriptions for things like FPGA but I don't recall it ever having got anywhere concrete
- I could have missed something. Those are dynamic cases which are more trouble though. For something that's a PCI card it's not clear that we can't just statically instanitate the devices from kernel code, that was how the MFD subsystem started off although it's now primarily applied to other applications. That looks to be what's going on here?

Quoted 4 lines

Yes, in this series, I used the MFD susbsytems with mfd_cells. These cells are attached with a swnode. Then, needed subsystems are modified to use the fwnode API to be able to use them with devices that have a swnode as a primary node.

Note that not all subsystems are going to be a good fit for fwnode, it's concerning for the areas where ACPI and DT have substantially different models like regulators.

Quoted 10 lines
Quoted 4 lines

There were separately some issues with people trying to create completely swnode based enumeration mechanisms for things that required totally independent code for handling swnodes which seemed very concerning but it's not clear to me if that's what's going on here.

The card is described entirely using swnode that in a MFD PCI driver, everything is described statically. The "enumeration" is static since all the devices are described in the driver and registered using mfd_add_device() at probe time. Thus, I don't think it adds an enumeration mechanism like you mention but I may be wrong.

This was all on the side parsing the swnodes rather than injecting the data.

#56 lore raw
In reply to Mark Brown
Quoted 1 line · Mark Brown

On Wed, Feb 23, 2022 at 05:24:37PM +0200, Andy Shevchenko wrote:

...

Quoted 4 lines

There were separately some issues with people trying to create completely swnode based enumeration mechanisms for things that required totally independent code for handling swnodes which seemed very concerning but it's not clear to me if that's what's going on here.

This is the case IIUC.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#57 lore raw
In reply to Clément Léger
Quoted 5 lines

This series has been tested on a x86 kernel build without CONFIG_OF. Another kernel was also built with COMPILE_TEST and CONFIG_OF support to build as most drivers as possible. It was also tested on a sparx5 arm64 with CONFIG_OF. However, it was not tested with an ACPI description evolved enough to validate all the changes.

By that, do you mean a DSD description?

In the DT world, we avoid snow flakes. Once you define a binding, it is expected every following board will use it. So what i believe you are doing here is defining how i2c muxes are described in APCI. How SFP devices are described in ACPI. Until the ACPI standards committee says otherwise, this is it. So you need to clearly document this. Please add to Documentation/firmware-guide/acpi/dsd.

Andrew

#58 lore raw
Quoted 7 lines · Andrew Lunn
Quoted 6 lines

This series has been tested on a x86 kernel build without CONFIG_OF. Another kernel was also built with COMPILE_TEST and CONFIG_OF support to build as most drivers as possible. It was also tested on a sparx5 arm64 with CONFIG_OF. However, it was not tested with an ACPI description evolved enough to validate all the changes.

Quoted 5 lines

By that, do you mean a DSD description?

In the DT world, we avoid snow flakes. Once you define a binding, it is expected every following board will use it. So what i believe you are doing here is defining how i2c muxes are described in APCI.

Linux kernel has already established description of I2C muxes in ACPI:
https://www.kernel.org/doc/html/latest/firmware-guide/acpi/i2c-muxes.html

I'm not sure we want another one.

Quoted 4 lines

How
SFP devices are described in ACPI. Until the ACPI standards committee says otherwise, this is it. So you need to clearly document this. Please add to Documentation/firmware-guide/acpi/dsd.

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

In the DT world, we avoid snow flakes. Once you define a binding, it is expected every following board will use it. So what i believe you are doing here is defining how i2c muxes are described in APCI.

Linux kernel has already established description of I2C muxes in ACPI:
https://www.kernel.org/doc/html/latest/firmware-guide/acpi/i2c-muxes.html

I'm not sure we want another one.

Agreed. This implementation needs to make use of that. Thanks for pointing it out. I don't know the ACPI world, are there any other overlaps with existing ACPI bindings?

Andrew

#60 lore raw
Quoted 5 lines · Andrew Lunn
Quoted 5 lines
Quoted 4 lines

In the DT world, we avoid snow flakes. Once you define a binding, it is expected every following board will use it. So what i believe you are doing here is defining how i2c muxes are described in APCI.

Quoted 8 lines
Quoted 4 lines

Linux kernel has already established description of I2C muxes in ACPI:
https://www.kernel.org/doc/html/latest/firmware-guide/acpi/i2c-muxes.html

I'm not sure we want another one.

Agreed. This implementation needs to make use of that. Thanks for pointing it out. I don't know the ACPI world, are there any other overlaps with existing ACPI bindings?

Besides ACPI specification, which defines _CRS resources, such as I2C, SPI, GPIO, and other peripheral connections, in the Linux kernel we have already established these [1]. I hope it's all here, since in the past not everything got documented and there were some documentation patches in time.

On top of that there are some Microsoft documents on enumeration that Linux follows, such as USB embedded devices [2]. There is also a PCI FW specification that defines how PCI bus devices, bridges, etc have to be represented in ACPI, including additional tables, such as MCFG.

[1]: https://www.kernel.org/doc/html/latest/firmware-guide/acpi/enumeration.html
[2]: https://docs.microsoft.com/en-us/windows-hardware/drivers/bringup/other-acpi-namespace-objects#acpi-namespace-hierarchy-and-_adr-for-embedded-usb-devices

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#61 lore raw
In reply to Clément Léger

Hi,

As stated at the beginning of the cover letter, the PCIe card I'm working on uses a lan9662 SoC. This card is meant to be used an ethernet switch with 2 x RJ45 ports and 2 x 10G SFPs. The lan966x SoCs can be used in two different ways:

- It can run Linux by itself, on ARM64 cores included in the SoC. This use-case of the lan966x is currently being upstreamed, using a traditional Device Tree representation of the lan996x HW blocks [1] A number of drivers for the different IPs of the SoC have already been merged in upstream Linux.

- It can be used as a PCIe endpoint, connected to a separate platform that acts as the PCIe root complex. In this case, all the devices that are embedded on this SoC are exposed through PCIe BARs and the ARM64 cores of the SoC are not used. Since this is a PCIe card, it can be plugged on any platform, of any architecture supporting PCIe.

The goal of this effort is to enable this second use-case, while allowing the re-use of the existing drivers for the different devices part of the SoC.

Following a first round of discussion, here are some clarifications on what problem this series is trying to solve and what are the possible choices to support this use-case.

Here is the list of devices that are exposed and needed to make this card work as an ethernet switch:
- lan966x-switch
- reset-microchip-sparx5
- lan966x_serdes
- reset-microchip-lan966x-phy
- mdio-mscc-miim
- pinctrl-lan966x
- atmel-flexcom
- i2c-at91
- i2c-mux
- i2c-mux-pinctrl
- sfp
- clk-lan966x

All the devices on this card are "self-contained" and do not require cross-links with devices that are on the host (except to demux IRQ but this is something easy to do). These drivers already exists and are using of_* API to register controllers, get properties and so on.

The challenge we're trying to solve is how can the PCI driver for this card re-use the existing drivers, and using which hardware representation to instantiate all those drivers.

Although this series only contained the modifications for the I2C subsystem all the subsystems that are used or needed by the previously listed driver have also been modified to have support for fwnode. This includes the following subsystems:
- reset
- clk
- pinctrl
- syscon
- gpio
- pinctrl
- phy
- mdio
- i2c

The first feedback on this series does not seems to reach a consensus (to say the least) on how to do it cleanly so here is a recap of the possible solutions, either brought by this series or mentioned by contributors:

1) Describe the card statically using swnode

This is the approach that was taken by this series. The devices are described using the MFD subsystem with mfd_cells. These cells are attached with a swnode which will be used as a primary node in place of ACPI or OF description. This means that the device description (properties and references) is conveyed entirely in the swnode. In order to make these swnode usable with existing OF based subsystems, the fwnode API can be used in needed subsystems.

Pros:
- Self-contained in the driver.
- Will work on all platforms no matter the firmware description.
- Makes the subsystems less OF-centric.

Cons:
- Modifications are required in subsystems to support fwnode (mitigated by the fact it makes to subsystems less OF-centric).
- swnode are not meant to be used entirely as primary nodes.
- Specifications for both ACPI and OF must be handled if using fwnode API.

2) Use SSDT overlays

Andy mentioned that SSDT overlays could be used. This overlay should match the exact configuration that is used (ie correct PCIe bus/port etc). It requires the user to write/modify/compile a .asl file and load it using either EFI vars, custom initrd or via configfs. The existing drivers would also need more modifications to work with ACPI. Some of them might even be harder (if not possible) to use since there is no ACPI support for the subsystems they are using .

Pros:
- Can't really find any for this one

Cons:
- Not all needed subsystems have appropriate ACPI bindings/support (reset, clk, pinctrl, syscon).
- Difficult to setup for the user (modify/compile/load .aml file).
- Not portable between machines, as the SSDT overlay need to be different depending on how the PCI device is connected to the platform.

3) Use device-tree overlays

This solution was proposed by Andrew and could potentially allows to keep all the existing device-tree infrastructure and helpers. A device-tree overlay could be loaded by the driver and applied using of_overlay_fdt_apply(). There is some glue to make this work but it could potentially be possible. Mark have raised some warnings about using such device-tree overlays on an ACPI enabled platform.

Pros:
- Reuse all the existing OF infrastructure, no modifications at all on drivers and subsystems.
- Could potentially lead to designing a generic driver for PCI devices that uses a composition of other drivers.

Cons:
- Might not the best idea to mix it with ACPI.
- Needs CONFIG_OF, which typically isn't enabled today on most x86 platforms.
- Loading DT overlays on non-DT platforms is not currently working. It can be addressed, but it's not necessarily immediate.

My preferred solutions would be swnode or device-tree overlays but since there to is no consensus on how to add this support, how can we go on with this series ?

Thanks,

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

Signature · 3 lines
Clément Léger,
Embedded Linux and Kernel engineer at Bootlin
https://bootlin.com
#62 lore raw

Hi Clément,

Quoted 135 lines · Clément Léger

Hi,

As stated at the beginning of the cover letter, the PCIe card I'm working on uses a lan9662 SoC. This card is meant to be used an ethernet switch with 2 x RJ45 ports and 2 x 10G SFPs. The lan966x SoCs can be used in two different ways:

- It can run Linux by itself, on ARM64 cores included in the SoC. This use-case of the lan966x is currently being upstreamed, using a traditional Device Tree representation of the lan996x HW blocks [1] A number of drivers for the different IPs of the SoC have already been merged in upstream Linux.

- It can be used as a PCIe endpoint, connected to a separate platform that acts as the PCIe root complex. In this case, all the devices that are embedded on this SoC are exposed through PCIe BARs and the ARM64 cores of the SoC are not used. Since this is a PCIe card, it can be plugged on any platform, of any architecture supporting PCIe.

The goal of this effort is to enable this second use-case, while allowing the re-use of the existing drivers for the different devices part of the SoC.

Following a first round of discussion, here are some clarifications on what problem this series is trying to solve and what are the possible choices to support this use-case.

Here is the list of devices that are exposed and needed to make this card work as an ethernet switch:
- lan966x-switch
- reset-microchip-sparx5
- lan966x_serdes
- reset-microchip-lan966x-phy
- mdio-mscc-miim
- pinctrl-lan966x
- atmel-flexcom
- i2c-at91
- i2c-mux
- i2c-mux-pinctrl
- sfp
- clk-lan966x

All the devices on this card are "self-contained" and do not require cross-links with devices that are on the host (except to demux IRQ but this is something easy to do). These drivers already exists and are using of_* API to register controllers, get properties and so on.

The challenge we're trying to solve is how can the PCI driver for this card re-use the existing drivers, and using which hardware representation to instantiate all those drivers.

Although this series only contained the modifications for the I2C subsystem all the subsystems that are used or needed by the previously listed driver have also been modified to have support for fwnode. This includes the following subsystems:
- reset
- clk
- pinctrl
- syscon
- gpio
- pinctrl
- phy
- mdio
- i2c

The first feedback on this series does not seems to reach a consensus (to say the least) on how to do it cleanly so here is a recap of the possible solutions, either brought by this series or mentioned by contributors:

1) Describe the card statically using swnode

This is the approach that was taken by this series. The devices are described using the MFD subsystem with mfd_cells. These cells are attached with a swnode which will be used as a primary node in place of ACPI or OF description. This means that the device description (properties and references) is conveyed entirely in the swnode. In order to make these swnode usable with existing OF based subsystems, the fwnode API can be used in needed subsystems.

Pros:
- Self-contained in the driver.
- Will work on all platforms no matter the firmware description.
- Makes the subsystems less OF-centric.

Cons:
- Modifications are required in subsystems to support fwnode (mitigated by the fact it makes to subsystems less OF-centric).
- swnode are not meant to be used entirely as primary nodes.
- Specifications for both ACPI and OF must be handled if using fwnode API.

2) Use SSDT overlays

Andy mentioned that SSDT overlays could be used. This overlay should match the exact configuration that is used (ie correct PCIe bus/port etc). It requires the user to write/modify/compile a .asl file and load it using either EFI vars, custom initrd or via configfs. The existing drivers would also need more modifications to work with ACPI. Some of them might even be harder (if not possible) to use since there is no ACPI support for the subsystems they are using .

Pros:
- Can't really find any for this one

Cons:
- Not all needed subsystems have appropriate ACPI bindings/support (reset, clk, pinctrl, syscon).
- Difficult to setup for the user (modify/compile/load .aml file).
- Not portable between machines, as the SSDT overlay need to be different depending on how the PCI device is connected to the platform.

3) Use device-tree overlays

This solution was proposed by Andrew and could potentially allows to keep all the existing device-tree infrastructure and helpers. A device-tree overlay could be loaded by the driver and applied using of_overlay_fdt_apply(). There is some glue to make this work but it could potentially be possible. Mark have raised some warnings about using such device-tree overlays on an ACPI enabled platform.

Pros:
- Reuse all the existing OF infrastructure, no modifications at all on drivers and subsystems.
- Could potentially lead to designing a generic driver for PCI devices that uses a composition of other drivers.

Cons:
- Might not the best idea to mix it with ACPI.
- Needs CONFIG_OF, which typically isn't enabled today on most x86 platforms.
- Loading DT overlays on non-DT platforms is not currently working. It can be addressed, but it's not necessarily immediate.

Quoted 3 lines

My preferred solutions would be swnode or device-tree overlays but since there to is no consensus on how to add this support, how can we go on with this series ?

FWIW I think that the convert subsystems + drivers to use the fwnode abstraction layer + use swnode-s approach makes sense. For a bunch of x86/ACPI stuff like Type-C muxing/controllers/routing but also MIPI cameras we have already been moving in that direction since sometimes a bunch of info seems to be hardcoded in Windows drivers rather then "spelled out" in the ACPI tables so from the x86 side we are seeing a need to have platform glue code which replaces the hardcoding on the Windows side and we have been using the fwnode abstraction + swnodes for this, so that we can keep using the standard Linux abstractions/subsystems for this.

As Mark already mentioned the regulator subsystem has shown to be a bit problematic here, but you don't seem to need that?

Your i2c subsys patches looked reasonable to me. IMHO an important thing missing to give you some advice whether to try 1. or 3. first is how well / clean the move to the fwnode abstractions would work for the other subsystems.

Have you already converted other subsystems and if yes, can you give us a pointer to a branch somewhere with the conversion for other subsystems ?

Regards,

Hans

#63 lore raw
Quoted 2 lines · Hans de Goede

As Mark already mentioned the regulator subsystem has shown to be a bit problematic here, but you don't seem to need that?

I believe clocks are also potentially problematic for similar reasons (ACPI wants to handle those as part of the device level power management and/or should have native abstractions for them, and I think we also have board file provisions that work well for them and are less error prone than translating into an abstract data structure).

reviewer
#64 lore raw

Hi Mark,

Quoted 10 lines · Mark Brown
Quoted 2 lines · Hans de Goede

As Mark already mentioned the regulator subsystem has shown to be a bit problematic here, but you don't seem to need that?

I believe clocks are also potentially problematic for similar reasons (ACPI wants to handle those as part of the device level power management and/or should have native abstractions for them, and I think we also have board file provisions that work well for them and are less error prone than translating into an abstract data structure).

Per ACPI spec, what corresponds to clocks and regulators in DT is handled through power resources. This is generally how things work in ACPI based systems but there are cases out there where regulators and/or clocks are exposed to software directly. This concerns e.g. camera sensors and lens voice coils on some systems while rest of the devices in the system are powered on and off the usual ACPI way.

So controlling regulators or clocks directly on an ACPI based system wouldn't be exactly something new. All you need to do in that case is to ensure that there's exactly one way regulators and clocks are controlled for a given device. For software nodes this is a non-issue.

This does have the limitation that a clock or a regulator is either controlled through power resources or relevant drivers, but that tends to be the case in practice. But I presume it wouldn't be different with board files.

Signature · 1 line
Sakari Ailus
#65 lore raw
Quoted 26 lines · Sakari Ailus

Hi Mark,

Quoted 10 lines · Mark Brown
Quoted 2 lines · Hans de Goede

As Mark already mentioned the regulator subsystem has shown to be a bit problematic here, but you don't seem to need that?

I believe clocks are also potentially problematic for similar reasons (ACPI wants to handle those as part of the device level power management and/or should have native abstractions for them, and I think we also have board file provisions that work well for them and are less error prone than translating into an abstract data structure).

Per ACPI spec, what corresponds to clocks and regulators in DT is handled through power resources. This is generally how things work in ACPI based systems but there are cases out there where regulators and/or clocks are exposed to software directly. This concerns e.g. camera sensors and lens voice coils on some systems while rest of the devices in the system are powered on and off the usual ACPI way.

So controlling regulators or clocks directly on an ACPI based system wouldn't be exactly something new. All you need to do in that case is to ensure that there's exactly one way regulators and clocks are controlled for a given device. For software nodes this is a non-issue.

Quoted 5 lines

This does have the limitation that a clock or a regulator is either controlled through power resources or relevant drivers, but that tends to be the case in practice. But I presume it wouldn't be different with board files.

In this use case, we don't need anything that is actually described in ACPI as all the clocks we need to control are on the device itself so I don't think this is relevant here.

Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#66 lore raw
Quoted 3 lines · Alexandre Belloni

In this use case, we don't need anything that is actually described in ACPI as all the clocks we need to control are on the device itself so I don't think this is relevant here.

You should be able to support this case, the concern is if it's done in a way that would allow things to be parsed out of the firmware by other systems.

#67 lore raw
In reply to Sakari Ailus
Quoted 8 lines · Sakari Ailus
Quoted 5 lines · Mark Brown

I believe clocks are also potentially problematic for similar reasons (ACPI wants to handle those as part of the device level power management and/or should have native abstractions for them, and I think we also have board file provisions that work well for them and are less error prone than translating into an abstract data structure).

Quoted 6 lines

Per ACPI spec, what corresponds to clocks and regulators in DT is handled through power resources. This is generally how things work in ACPI based systems but there are cases out there where regulators and/or clocks are exposed to software directly. This concerns e.g. camera sensors and lens voice coils on some systems while rest of the devices in the system are powered on and off the usual ACPI way.

But note crucially that when these things are controlled by the OS they are enumerated via some custom mechanism that is *not* _DSD properties - the issue is with the firmware interface, not with using the relevant kernel APIs in the client or provider devices.

#68 lore raw
In reply to Hans de Goede

Le Thu, 24 Feb 2022 15:58:04 +0100,
Hans de Goede <[email protected]> a écrit :

[...]

Quoted 17 lines
Quoted 5 lines

can be addressed, but it's not necessarily immediate.

My preferred solutions would be swnode or device-tree overlays but since there to is no consensus on how to add this support, how can we go on with this series ?

FWIW I think that the convert subsystems + drivers to use the fwnode abstraction layer + use swnode-s approach makes sense. For a bunch of x86/ACPI stuff like Type-C muxing/controllers/routing but also MIPI cameras we have already been moving in that direction since sometimes a bunch of info seems to be hardcoded in Windows drivers rather then "spelled out" in the ACPI tables so from the x86 side we are seeing a need to have platform glue code which replaces the hardcoding on the Windows side and we have been using the fwnode abstraction + swnodes for this, so that we can keep using the standard Linux abstractions/subsystems for this.

Quoted 2 lines

As Mark already mentioned the regulator subsystem has shown to be a bit problematic here, but you don't seem to need that?

Hi Hans,

Indeed, I don't need this subsystem. However, I'm still not clear why this subsystem in particular is problematic. Just so that I can recognize the other subsystems with the same pattern, could you explain me why it is problematic ?

Quoted 5 lines

Your i2c subsys patches looked reasonable to me. IMHO an important thing missing to give you some advice whether to try 1. or 3. first is how well / clean the move to the fwnode abstractions would work for the other subsystems.

Actually, I did the conversion for pinctrl, gpios, i2c, reset, clk, syscon, mdio but did not factorized all the of code on top of fwnode adaptation. I did it completely for mdio and reset subsystems. Porting them to fwnode was rather straightforward, and almost all the of_* API now have a fwnode_* variant.

While porting them to fwnode, I mainly had to modify the "register" and the "get" interface of these subsystems. I did not touched the enumeration part if we can call it like this and thus all the CLK_OF_DECLARE() related stuff is left untouched.

Quoted 4 lines

Have you already converted other subsystems and if yes, can you give us a pointer to a branch somewhere with the conversion for other subsystems ?

All the preliminary work I did is available at the link at [1]. But as I said, I did not converted completely all the subsystems, only reset [2] (for which I tried to convert all the drivers and fatorized OF on top of fwnode functions) and mdio [3] which proved to be easily portable.

I also modified the clk framework [4] but did not went to the complete factorization of it. I converted the fixed-clk driver to see how well it could be done. Biggest difficulty is to keep of_xlate() and fwnode_xlate() (if we want to do so) to avoid modifying all drivers (even though not a lot of them implements custom of_xlate() functions).

If backward compatibility is really needed, it can potentially be done, at the cost of keeping of_xlate() member and by converting the fwnode stuff to OF world (which is easily doable).

Conversion to fwnode API actually proved to be rather straightforward except for some specific subsystem (syscon) which I'm not quite happy with the outcome, but again, I wanted the community feedback before going further in this way so there is room for improvement.

Regards,

[1] https://github.com/clementleger/linux/tree/fwnode_support
[2] https://github.com/clementleger/linux/tree/fwnode_reset
[3] https://github.com/clementleger/linux/tree/fwnode_mdio
[4] https://github.com/clementleger/linux/tree/fwnode_clk

Quoted 4 lines

Regards,

Hans

Signature · 3 lines
Clément Léger,
Embedded Linux and Kernel engineer at Bootlin
https://bootlin.com
#69 lore raw
Quoted 9 lines · Clément Léger
Quoted 2 lines · Hans de Goede

As Mark already mentioned the regulator subsystem has shown to be a bit problematic here, but you don't seem to need that?

Indeed, I don't need this subsystem. However, I'm still not clear why this subsystem in particular is problematic. Just so that I can recognize the other subsystems with the same pattern, could you explain me why it is problematic ?

ACPI has a strong concept of how power supply (and general critical resources) for devices should be described by firmware which is very different to that which DT as it is used in Linux has, confusing that model would make it much harder for generic OSs to work with generic ACPI systems, and makes it much easier to create unfortunate interactions between bits of software expecting ACPI models and bits of software expecting DT models for dealing with a device. Potentially we could even run into issues with new versions of Linux if there's timing or other changes. If Linux starts parsing the core DT bindings for regulators on ACPI systems then that makes it more likely that system integrators who are primarily interested in Linux will produce firmwares that run into these issues, perhaps unintentionally through a "this just happens to work" process.

As a result of this we very much do not want to have the regulator code parsing DT bindings using the fwnode APIs since that makes it much easier for us to end up with a situation where we are interpreting _DSD versions of regulator bindings and ending up with people making systems that rely on that. Instead the regulator API is intentional about which platform description interfaces it is using. We could potentially have something that is specific to swnode and won't work with general fwnode but it's hard to see any advantages for this over the board file based mechanism we have already, swnode offers less error detection (typoing field names is harder to spot) and the data marshalling takes more code.

fwnode is great for things like properties for leaf devices since those are basically a free for all on ACPI systems, it allows us to quickly and simply apply the work done defining bindings for DT to ACPI systems in a way that's compatible with how APCI wants to work. It's also good for cross device bindings that are considered out of scope for ACPI, though a bit of caution is needed determining when that's the case.

#70 lore raw
Quoted 11 lines · Mark Brown
Quoted 9 lines · Clément Léger
Quoted 2 lines · Hans de Goede

As Mark already mentioned the regulator subsystem has shown to be a bit problematic here, but you don't seem to need that?

Indeed, I don't need this subsystem. However, I'm still not clear why this subsystem in particular is problematic. Just so that I can recognize the other subsystems with the same pattern, could you explain me why it is problematic ?

Quoted 13 lines

ACPI has a strong concept of how power supply (and general critical resources) for devices should be described by firmware which is very different to that which DT as it is used in Linux has, confusing that model would make it much harder for generic OSs to work with generic ACPI systems, and makes it much easier to create unfortunate interactions between bits of software expecting ACPI models and bits of software expecting DT models for dealing with a device. Potentially we could even run into issues with new versions of Linux if there's timing or other changes. If Linux starts parsing the core DT bindings for regulators on ACPI systems then that makes it more likely that system integrators who are primarily interested in Linux will produce firmwares that run into these issues, perhaps unintentionally through a "this just happens to work" process.

Ok that's way more clear.

Quoted 11 lines

As a result of this we very much do not want to have the regulator code parsing DT bindings using the fwnode APIs since that makes it much easier for us to end up with a situation where we are interpreting _DSD versions of regulator bindings and ending up with people making systems that rely on that. Instead the regulator API is intentional about which platform description interfaces it is using. We could potentially have something that is specific to swnode and won't work with general fwnode but it's hard to see any advantages for this over the board file based mechanism we have already, swnode offers less error detection (typoing field names is harder to spot) and the data marshalling takes more code.

Instead of making it specific for swnode, could we make it instead non working for acpi nodes ? Thus, the parsing would work only for swnode and device_node, not allowing to use the fwnode support with acpi for such subsystems (not talking about regulators here).

If switching to board file based mechanism, this means that all drivers that are used by the PCIe card will have to be modified to support this mechanism.

Quoted 7 lines

fwnode is great for things like properties for leaf devices since those are basically a free for all on ACPI systems, it allows us to quickly and simply apply the work done defining bindings for DT to ACPI systems in a way that's compatible with how APCI wants to work. It's also good for cross device bindings that are considered out of scope for ACPI, though a bit of caution is needed determining when that's the case.

Ok got it, thanks for the in-depth explanations.

Signature · 3 lines
Clément Léger,
Embedded Linux and Kernel engineer at Bootlin
https://bootlin.com
#71 lore raw
Quoted 4 lines · Clément Léger

Instead of making it specific for swnode, could we make it instead non working for acpi nodes ? Thus, the parsing would work only for swnode and device_node, not allowing to use the fwnode support with acpi for such subsystems (not talking about regulators here).

*Potentially*. I'd need to see the code, it doesn't fill me with great joy and there are disadvantages in terms of input validation but that does address the main issue and perhaps the implementation would be nicer than I'm immediately imagining.

Quoted 3 lines

If switching to board file based mechanism, this means that all drivers that are used by the PCIe card will have to be modified to support this mechanism.

You should be able to mix the use of board file regulator descriptions with other descriptions for other bits of the hardware.

#72 lore raw
In reply to Clément Léger
Quoted 135 lines · Clément Léger

Hi,

As stated at the beginning of the cover letter, the PCIe card I'm working on uses a lan9662 SoC. This card is meant to be used an ethernet switch with 2 x RJ45 ports and 2 x 10G SFPs. The lan966x SoCs can be used in two different ways:

- It can run Linux by itself, on ARM64 cores included in the SoC. This use-case of the lan966x is currently being upstreamed, using a traditional Device Tree representation of the lan996x HW blocks [1] A number of drivers for the different IPs of the SoC have already been merged in upstream Linux.

- It can be used as a PCIe endpoint, connected to a separate platform that acts as the PCIe root complex. In this case, all the devices that are embedded on this SoC are exposed through PCIe BARs and the ARM64 cores of the SoC are not used. Since this is a PCIe card, it can be plugged on any platform, of any architecture supporting PCIe.

The goal of this effort is to enable this second use-case, while allowing the re-use of the existing drivers for the different devices part of the SoC.

Following a first round of discussion, here are some clarifications on what problem this series is trying to solve and what are the possible choices to support this use-case.

Here is the list of devices that are exposed and needed to make this card work as an ethernet switch:
- lan966x-switch
- reset-microchip-sparx5
- lan966x_serdes
- reset-microchip-lan966x-phy
- mdio-mscc-miim
- pinctrl-lan966x
- atmel-flexcom
- i2c-at91
- i2c-mux
- i2c-mux-pinctrl
- sfp
- clk-lan966x

All the devices on this card are "self-contained" and do not require cross-links with devices that are on the host (except to demux IRQ but this is something easy to do). These drivers already exists and are using of_* API to register controllers, get properties and so on.

The challenge we're trying to solve is how can the PCI driver for this card re-use the existing drivers, and using which hardware representation to instantiate all those drivers.

Although this series only contained the modifications for the I2C subsystem all the subsystems that are used or needed by the previously listed driver have also been modified to have support for fwnode. This includes the following subsystems:
- reset
- clk
- pinctrl
- syscon
- gpio
- pinctrl
- phy
- mdio
- i2c

The first feedback on this series does not seems to reach a consensus (to say the least) on how to do it cleanly so here is a recap of the possible solutions, either brought by this series or mentioned by contributors:

1) Describe the card statically using swnode

This is the approach that was taken by this series. The devices are described using the MFD subsystem with mfd_cells. These cells are attached with a swnode which will be used as a primary node in place of ACPI or OF description. This means that the device description (properties and references) is conveyed entirely in the swnode. In order to make these swnode usable with existing OF based subsystems, the fwnode API can be used in needed subsystems.

Pros:
- Self-contained in the driver.
- Will work on all platforms no matter the firmware description.
- Makes the subsystems less OF-centric.

Cons:
- Modifications are required in subsystems to support fwnode (mitigated by the fact it makes to subsystems less OF-centric).
- swnode are not meant to be used entirely as primary nodes.
- Specifications for both ACPI and OF must be handled if using fwnode API.

2) Use SSDT overlays

Andy mentioned that SSDT overlays could be used. This overlay should match the exact configuration that is used (ie correct PCIe bus/port etc). It requires the user to write/modify/compile a .asl file and load it using either EFI vars, custom initrd or via configfs. The existing drivers would also need more modifications to work with ACPI. Some of them might even be harder (if not possible) to use since there is no ACPI support for the subsystems they are using .

Pros:
- Can't really find any for this one

Cons:
- Not all needed subsystems have appropriate ACPI bindings/support (reset, clk, pinctrl, syscon).
- Difficult to setup for the user (modify/compile/load .aml file).
- Not portable between machines, as the SSDT overlay need to be different depending on how the PCI device is connected to the platform.

3) Use device-tree overlays

This solution was proposed by Andrew and could potentially allows to keep all the existing device-tree infrastructure and helpers. A device-tree overlay could be loaded by the driver and applied using of_overlay_fdt_apply(). There is some glue to make this work but it could potentially be possible. Mark have raised some warnings about using such device-tree overlays on an ACPI enabled platform.

Pros:
- Reuse all the existing OF infrastructure, no modifications at all on drivers and subsystems.
- Could potentially lead to designing a generic driver for PCI devices that uses a composition of other drivers.

Cons:
- Might not the best idea to mix it with ACPI.
- Needs CONFIG_OF, which typically isn't enabled today on most x86 platforms.
- Loading DT overlays on non-DT platforms is not currently working. It can be addressed, but it's not necessarily immediate.

Quoted 9 lines

My preferred solutions would be swnode or device-tree overlays but since there to is no consensus on how to add this support, how can we go on with this series ?

Thanks,

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

Does anybody have some other advices or recommendation regarding this RFC ? It would be nice to have more feedback on the solution that might e preferred to support this use-case.

Thanks,

Signature · 3 lines
Clément Léger,
Embedded Linux and Kernel engineer at Bootlin
https://bootlin.com