Skip to contentSkip to conversation

Align sama5 and sama7 DT's with Linux

PATCH In review Sergiu Moga 2 participants 6 messages Sep 1, 2022 – Sep 19, 2022

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

cover Align sama5 and sama7 DT's with Linux

This has been done in order to align the DT of U-Boot with the DT of Linux. In Linux, a phandle from a '-gpio' DT property is linked to the pinctrl driver, a single driver that handles both pinctrl settings and offers GPIO API to callers. On the other hand, U-Boot redirects such phandle to a corresponding UCLASS_GPIO driver, because U-Boot offers two different types of drivers in this case: UCLASS_PINCTRL which handles pin functions and UCLASS_GPIO which handles gpio requests as a gpio provider. Due to this, we have two drivers in Uboot, but the Devicetree has a single node. Thus, just one of the drivers can be probed for the DT node during platform initialization, before relocation.

Our previous solution in U-Boot was to have a different devicetree:
the gpio node has a subnode for the pinctrl driver, which is not compliant with Linux ABI. Furthermore, our documentation for this type of nodes mentions no such gpio compatible.

After this patch, we can no longer add nodes with a gpio compatible in the DT. Thus, in order to link the pinctrl driver to the gpio one, a hook to the bind method of the former in U-Boot has been added and the GPIO related compatibles have been removed to avoid conflict when compatibles are enumerated and bound to drivers during platform start before relocation. The bind method will attach the GPIO driver to the pinctrl DT node so that every phandle coming from '-gpio' DT properties will be redirected to a valid driver attached to the pinctrl DT node.

Furthermore, this fixes a GPIO request issue existent on sama7g5, which was caused by the fact that there was no UCLASS_GPIO driver bound to the pioA node label.

To make the two Devicetrees even more similar (the one from Linux and the one from U-Boot), make the pinctrl driver's node support multiple subnodes for its subnode.

Sergiu Moga (4):
ARM: dts: at91: sama5: Align with Linux Devicetree
ARM: dts: at91: sama7: Align with Linux Devicetree
pinctrl: at91-pio4: Bind GPIO driver to the pinctrl DT node
pinctrl: at91-pio4: Add support for pinctrl config subnodes

 arch/arm/dts/at91-sama5d27_giantboard.dts     |  59 +++--
 arch/arm/dts/at91-sama5d27_som1_ek.dts        |  80 +++----
 .../dts/at91-sama5d27_wlsom1_ek-u-boot.dtsi   |   6 +-
 arch/arm/dts/at91-sama5d27_wlsom1_ek.dts      |  92 ++++----
 arch/arm/dts/at91-sama5d2_icp.dts             | 134 ++++++------
 arch/arm/dts/at91-sama5d2_ptc_ek.dts          |  98 ++++-----
 arch/arm/dts/at91-sama5d2_xplained.dts        | 204 +++++++++---------
 arch/arm/dts/at91-sama7g5ek-u-boot.dtsi       |   2 +-
 arch/arm/dts/at91-sama7g5ek.dts               |  85 +++++---
 arch/arm/dts/sama5d2.dtsi                     |   9 +-
 arch/arm/dts/sama5d27_som1.dtsi               |  94 ++++----
 arch/arm/dts/sama5d27_wlsom1.dtsi             |  54 +++--
 arch/arm/dts/sama7g5.dtsi                     |  16 +-
 drivers/gpio/atmel_pio4.c                     |   2 -
 drivers/pinctrl/pinctrl-at91-pio4.c           | 138 ++++++++++--
 15 files changed, 592 insertions(+), 481 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/4 ARM: dts: at91: sama5: Align with Linux Devicetree

This patch makes sure that the Devicetree for the sama5 boards are aligned with the Devicetree from Linux. This implies removing the GPIO compatible and replacing it with the PINCTRL one, as well as unifying the SDMMC pinctrl related subnodes under one single subnode.

---
 arch/arm/dts/at91-sama5d27_giantboard.dts     |  59 +++--
 arch/arm/dts/at91-sama5d27_som1_ek.dts        |  80 +++----
 .../dts/at91-sama5d27_wlsom1_ek-u-boot.dtsi   |   6 +-
 arch/arm/dts/at91-sama5d27_wlsom1_ek.dts      |  92 ++++----
 arch/arm/dts/at91-sama5d2_icp.dts             | 134 ++++++------
 arch/arm/dts/at91-sama5d2_ptc_ek.dts          |  98 ++++-----
 arch/arm/dts/at91-sama5d2_xplained.dts        | 204 +++++++++---------
 arch/arm/dts/sama5d2.dtsi                     |   9 +-
 arch/arm/dts/sama5d27_som1.dtsi               |  94 ++++----
 arch/arm/dts/sama5d27_wlsom1.dtsi             |  54 +++--
 10 files changed, 411 insertions(+), 419 deletions(-)
arch/arm/dts/at91-sama5d27_giantboard.dts +29 -30
index e81ca60ca0..2625f81c8b 100644
@@ -30,7 +30,7 @@
 		sdmmc1: sdio-host@b0000000 {
 			bus-width = <4>;
 			pinctrl-names = "default";
-			pinctrl-0 = <&pinctrl_sdmmc1_cmd_dat_default &pinctrl_sdmmc1_ck_cd_default>;
+			pinctrl-0 = <&pinctrl_sdmmc1_default>;
 			status = "okay";
 			u-boot,dm-pre-reloc;
 		};
@@ -73,10 +73,9 @@
 				u-boot,dm-pre-reloc;
 			};
 
-			pioA: gpio@fc038000 {
-				pinctrl {
-
-					pinctrl_sdmmc1_cmd_dat_default: sdmmc1_cmd_dat_default {
+			pioA: pinctrl@fc038000 {
+				pinctrl_sdmmc1_default: sdmmc1_default {
+					cmd_data {
 						pinmux = <PIN_PA28__SDMMC1_CMD>,
 							 <PIN_PA18__SDMMC1_DAT0>,
 							 <PIN_PA19__SDMMC1_DAT1>,
@@ -86,41 +85,41 @@
 						u-boot,dm-pre-reloc;
 					};
 
-					pinctrl_sdmmc1_ck_cd_default: sdmmc1_ck_cd_default {
+					ck_cd {
 						pinmux = <PIN_PA22__SDMMC1_CK>,
 							 <PIN_PA30__SDMMC1_CD>;
 						bias-disable;
 						u-boot,dm-pre-reloc;
 					};
+				};
 
-					pinctrl_uart1_default: uart1_default {
-						pinmux = <PIN_PD2__URXD1>,
-							 <PIN_PD3__UTXD1>;
-						bias-disable;
-						u-boot,dm-pre-reloc;
-					};
+				pinctrl_uart1_default: uart1_default {
+					pinmux = <PIN_PD2__URXD1>,
+						 <PIN_PD3__UTXD1>;
+					bias-disable;
+					u-boot,dm-pre-reloc;
+				};
 
-					pinctrl_i2c0_default: i2c0_default {
-						pinmux = <PIN_PD21__TWD0>,
-							 <PIN_PD22__TWCK0>;
-						bias-disable;
-					};
+				pinctrl_i2c0_default: i2c0_default {
+					pinmux = <PIN_PD21__TWD0>,
+						 <PIN_PD22__TWCK0>;
+					bias-disable;
+				};
 
-					pinctrl_i2c1_default: i2c1_default {
-						pinmux = <PIN_PD4__TWD1>,
-							 <PIN_PD5__TWCK1>;
-						bias-disable;
-					};
+				pinctrl_i2c1_default: i2c1_default {
+					pinmux = <PIN_PD4__TWD1>,
+						 <PIN_PD5__TWCK1>;
+					bias-disable;
+				};
 
-					pinctrl_usb_default: usb_default {
-						pinmux = <PIN_PB10__GPIO>;
-						bias-disable;
-					};
+				pinctrl_usb_default: usb_default {
+					pinmux = <PIN_PB10__GPIO>;
+					bias-disable;
+				};
 
-					pinctrl_usba_vbus: usba_vbus {
-						pinmux = <PIN_PA31__GPIO>;
-						bias-disable;
-					};
+				pinctrl_usba_vbus: usba_vbus {
+					pinmux = <PIN_PA31__GPIO>;
+					bias-disable;
 				};
 			};
 		};
arch/arm/dts/at91-sama5d27_som1_ek.dts +42 -38

106 lines not on this page · raw message

arch/arm/dts/at91-sama5d27_wlsom1_ek-u-boot.dtsi +1 -5
index 8c84dd08fd..41cf9061a1 100644
@@ -37,11 +37,7 @@
 	u-boot,dm-pre-reloc;
 };
 
-&pinctrl_sdmmc0_cmd_dat_default {
-	u-boot,dm-pre-reloc;
-};
-
-&pinctrl_sdmmc0_ck_cd_default {
+&pinctrl_sdmmc0_default {
 	u-boot,dm-pre-reloc;
 };
 
arch/arm/dts/at91-sama5d27_wlsom1_ek.dts +46 -46

121 lines not on this page · raw message

arch/arm/dts/at91-sama5d2_icp.dts +66 -68

141 lines not on this page · raw message

arch/arm/dts/at91-sama5d2_ptc_ek.dts +50 -48

147 lines not on this page · raw message

arch/arm/dts/at91-sama5d2_xplained.dts +103 -101

259 lines not on this page · raw message

arch/arm/dts/sama5d2.dtsi +2 -7
index d92bdd5588..790b746ed1 100644
@@ -799,18 +799,13 @@
 				status = "disabled";
 			};
 
-			pioA: gpio@fc038000 {
-				compatible = "atmel,sama5d2-gpio";
+			pioA: pinctrl@fc038000 {
+				compatible = "atmel,sama5d2-pinctrl";
 				reg = <0xfc038000 0x600>;
 				clocks = <&pioA_clk>;
 				gpio-controller;
 				#gpio-cells = <2>;
 				u-boot,dm-pre-reloc;
-
-				pinctrl {
-					compatible = "atmel,sama5d2-pinctrl";
-					u-boot,dm-pre-reloc;
-				};
 			};
 		};
 	};
arch/arm/dts/sama5d27_som1.dtsi +46 -48

100 lines not on this page · raw message

arch/arm/dts/sama5d27_wlsom1.dtsi +26 -28

62 lines not on this page · raw message

Signature · 1 line
2.25.1
#2 lore raw

PATCH 2/4 ARM: dts: at91: sama7: Align with Linux Devicetree

In reply to Sergiu Moga

This patch makes sure that the Devicetree for the sama7 boards are aligned with the Devicetree from Linux. This implies removing the GPIO compatible and replacing it with the PINCTRL one, as well as unifying the SDMMC pinctrl related subnodes under one single subnode.

---
 arch/arm/dts/at91-sama7g5ek-u-boot.dtsi |  2 +-
 arch/arm/dts/at91-sama7g5ek.dts         | 85 +++++++++++++++----------
 arch/arm/dts/sama7g5.dtsi               | 16 ++---
 3 files changed, 60 insertions(+), 43 deletions(-)
arch/arm/dts/at91-sama7g5ek-u-boot.dtsi +1 -1
index 601386788f..d294ddb54a 100644
@@ -28,7 +28,7 @@
 	u-boot,dm-pre-reloc;
 };
 
-&pinctrl {
+&pioA {
 	u-boot,dm-pre-reloc;
 };
 
arch/arm/dts/at91-sama7g5ek.dts +53 -32

99 lines not on this page · raw message

arch/arm/dts/sama7g5.dtsi +6 -10
index 97400dc18e..d38090d7dd 100644
@@ -187,8 +187,8 @@
 			reg = <0xe0008000 0x20>;
 		};
 
-		pinctrl: pinctrl@e0014000 {
-			compatible = "microchip,sama7g5-gpio";
+		pioA: pinctrl@e0014000 {
+			compatible = "microchip,sama7g5-pinctrl";
 			reg = <0xe0014000 0x800>;
 			interrupts = <GIC_SPI 11 IRQ_TYPE_LEVEL_HIGH>,
 				<GIC_SPI 12 IRQ_TYPE_LEVEL_HIGH>,
@@ -196,14 +196,10 @@
 				<GIC_SPI 14 IRQ_TYPE_LEVEL_HIGH>,
 				<GIC_SPI 15 IRQ_TYPE_LEVEL_HIGH>;
 			clocks = <&pmc PMC_TYPE_PERIPHERAL 11>;
-
-			pioA: pinctrl_default {
-				interrupt-controller;
-				#interrupt-cells = <2>;
-				gpio-controller;
-				#gpio-cells = <2>;
-				compatible = "microchip,sama7g5-pinctrl";
-			};
+			interrupt-controller;
+			#interrupt-cells = <2>;
+			gpio-controller;
+			#gpio-cells = <2>;
 		};
 
 		pmc: pmc@e0018000 {
Signature · 1 line
2.25.1
#3 lore raw

PATCH 3/4 pinctrl: at91-pio4: Bind GPIO driver to the pinctrl DT node

In reply to Sergiu Moga

This has been done in order to align the DT of U-Boot with the DT of Linux. In Linux, a phandle from a '-gpio' DT property is linked to the pinctrl driver, a single driver that handles both pinctrl settings and offers GPIO API to callers. On the other hand, U-Boot redirects such phandle to a corresponding UCLASS_GPIO driver, because U-Boot offers two different types of drivers in this case: UCLASS_PINCTRL which handles pin functions and UCLASS_GPIO which handles gpio requests as a gpio provider. Due to this, we have two drivers in Uboot, but the Devicetree has a single node. Thus, just one of the drivers can be probed for the DT node during platform initialization, before relocation.

Our previous solution in U-Boot was to have a different devicetree:
the gpio node has a subnode for the pinctrl driver, which is not compliant with Linux ABI. Furthermore, our documentation for this type of nodes mentions no such gpio compatible.

After this patch, we can no longer add nodes with a gpio compatible in the DT. Thus, in order to link the pinctrl driver to the gpio one, a hook to the bind method of the former in U-Boot has been added and the GPIO related compatibles have been removed to avoid conflict when compatibles are enumerated and bound to drivers during platform start before relocation. The bind method will attach the GPIO driver to the pinctrl DT node so that every phandle coming from '-gpio' DT properties will be redirected to a valid driver attached to the pinctrl DT node.

---
 drivers/gpio/atmel_pio4.c           |  2 -
 drivers/pinctrl/pinctrl-at91-pio4.c | 65 ++++++++++++++++++++++++++---
 2 files changed, 60 insertions(+), 7 deletions(-)
drivers/gpio/atmel_pio4.c +0 -2
index 77a76c1d50..47ed297981 100644
@@ -350,10 +350,8 @@ static const struct atmel_pioctrl_data microchip_sama7g5_pioctrl_data = {
 
 static const struct udevice_id atmel_pio4_ids[] = {
 	{
-		.compatible = "atmel,sama5d2-gpio",
 		.data = (ulong)&atmel_sama5d2_pioctrl_data,
 	}, {
-		.compatible = "microchip,sama7g5-gpio",
 		.data = (ulong)&microchip_sama7g5_pioctrl_data,
 	},
 	{}
drivers/pinctrl/pinctrl-at91-pio4.c +60 -5

102 lines not on this page · raw message

Signature · 1 line
2.25.1
#4 lore raw

PATCH 4/4 pinctrl: at91-pio4: Add support for pinctrl config subnodes

In reply to Sergiu Moga

Previously, in order for the pinctrl-* DT node properties to be properly processed, the pinctrl's subnodes were limited to only having the pinmux property as well as other additional properties (slew-rate, bias-disable, etc.). Now, with this patch the pinctrl driver is made to work similarly to the one from Linux. It can now distinguish between one subnode and a subnode with multiple subnodes.

---
 drivers/pinctrl/pinctrl-at91-pio4.c | 73 ++++++++++++++++++++++++-----
 1 file changed, 61 insertions(+), 12 deletions(-)
drivers/pinctrl/pinctrl-at91-pio4.c +61 -12
index e434a38f1f..50e3dd449a 100644
@@ -15,6 +15,7 @@
 #include <linux/bitops.h>
 #include <linux/io.h>
 #include <linux/err.h>
+#include <dm/uclass-internal.h>
 #include <mach/atmel_pio4.h>
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -151,12 +152,11 @@ static inline struct atmel_pio4_port *atmel_pio4_bank_base(struct udevice *dev,
 
 #define MAX_PINMUX_ENTRIES	40
 
-static int atmel_pinctrl_set_state(struct udevice *dev, struct udevice *config)
+static int atmel_process_config_dev(struct udevice *dev, struct udevice *config)
 {
 	struct atmel_pio4_plat *plat = dev_get_plat(dev);
-	struct atmel_pio4_port *bank_base;
-	const void *blob = gd->fdt_blob;
 	int node = dev_of_offset(config);
+	struct atmel_pio4_port *bank_base;
 	u32 offset, func, bank, line;
 	u32 cells[MAX_PINMUX_ENTRIES];
 	u32 i, conf;
@@ -164,18 +164,17 @@ static int atmel_pinctrl_set_state(struct udevice *dev, struct udevice *config)
 
 	conf = atmel_pinctrl_get_pinconf(config, plat);
 
-	count = fdtdec_get_int_array_count(blob, node, "pinmux",
+	/*
+	 * The only case where this function returns a negative error value
+	 * is when there is no "pinmux" property attached to this node
+	 */
+	count = fdtdec_get_int_array_count(gd->fdt_blob, node, "pinmux",
 					   cells, ARRAY_SIZE(cells));
-	if (count < 0) {
-		printf("%s: bad pinmux array %d\n", __func__, count);
-		return -EINVAL;
-	}
+	if (count < 0)
+		return count;
 
-	if (count > MAX_PINMUX_ENTRIES) {
-		printf("%s: unsupported pinmux array count %d\n",
-		       __func__, count);
+	if (count > MAX_PINMUX_ENTRIES)
 		return -EINVAL;
-	}
 
 	for (i = 0 ; i < count; i++) {
 		offset = ATMEL_GET_PIN_NO(cells[i]);
@@ -195,6 +194,56 @@ static int atmel_pinctrl_set_state(struct udevice *dev, struct udevice *config)
 	return 0;
 }
 
+static int atmel_pinctrl_set_state(struct udevice *dev, struct udevice *config)
+{
+	int node = dev_of_offset(config);
+	struct udevice *subconfig;
+	int subnode, subnode_count = 0, ret;
+
+	/*
+	 * If this function returns a negative error code then that means
+	 * that either the "pinmux" property of the node is missing, which is
+	 * the case for pinctrl nodes that do not have all the pins with the
+	 * same configuration and are split in multiple subnodes, or something
+	 * else went wrong and we have to stop. For the latter case, it would
+	 * mean that the node failed even though it has no subnodes.
+	 */
+	ret = atmel_process_config_dev(dev, config);
+	if (!ret)
+		return ret;
+
+	/*
+	 * If we reach here, it means that the subnode pinctrl's DT has multiple
+	 * subnodes. If it does not, then something else went wrong in the
+	 * previous call to atmel_process_config_dev.
+	 */
+	fdt_for_each_subnode(subnode, gd->fdt_blob, node) {
+		/* Get subnode as an udevice */
+		ret = uclass_find_device_by_of_offset(UCLASS_PINCONFIG, subnode,
+						      &subconfig);
+		if (ret)
+			return ret;
+
+		/*
+		 * If this time the function returns an error code on a subnode
+		 * then something is totally wrong so abort.
+		 */
+		ret = atmel_process_config_dev(dev, subconfig);
+		if (ret)
+			return ret;
+
+		subnode_count++;
+	}
+
+	/*
+	 * If we somehow got here and we do not have any subnodes, abort.
+	 */
+	if (!subnode_count)
+		return -EINVAL;
+
+	return 0;
+}
+
 const struct pinctrl_ops atmel_pinctrl_ops  = {
 	.set_state = atmel_pinctrl_set_state,
 };
Signature · 1 line
2.25.1
#5 lore raw
In reply to Sergiu Moga
Quoted 41 lines · Sergiu Moga

This has been done in order to align the DT of U-Boot with the DT of Linux. In Linux, a phandle from a '-gpio' DT property is linked to the pinctrl driver, a single driver that handles both pinctrl settings and offers GPIO API to callers. On the other hand, U-Boot redirects such phandle to a corresponding UCLASS_GPIO driver, because U-Boot offers two different types of drivers in this case: UCLASS_PINCTRL which handles pin functions and UCLASS_GPIO which handles gpio requests as a gpio provider. Due to this, we have two drivers in Uboot, but the Devicetree has a single node. Thus, just one of the drivers can be probed for the DT node during platform initialization, before relocation.

Our previous solution in U-Boot was to have a different devicetree:
the gpio node has a subnode for the pinctrl driver, which is not compliant with Linux ABI. Furthermore, our documentation for this type of nodes mentions no such gpio compatible.

After this patch, we can no longer add nodes with a gpio compatible in the DT. Thus, in order to link the pinctrl driver to the gpio one, a hook to the bind method of the former in U-Boot has been added and the GPIO related compatibles have been removed to avoid conflict when compatibles are enumerated and bound to drivers during platform start before relocation. The bind method will attach the GPIO driver to the pinctrl DT node so that every phandle coming from '-gpio' DT properties will be redirected to a valid driver attached to the pinctrl DT node.

Furthermore, this fixes a GPIO request issue existent on sama7g5, which was caused by the fact that there was no UCLASS_GPIO driver bound to the pioA node label.

To make the two Devicetrees even more similar (the one from Linux and the one from U-Boot), make the pinctrl driver's node support multiple subnodes for its subnode.

Sergiu Moga (4):
ARM: dts: at91: sama5: Align with Linux Devicetree
ARM: dts: at91: sama7: Align with Linux Devicetree
pinctrl: at91-pio4: Bind GPIO driver to the pinctrl DT node
pinctrl: at91-pio4: Add support for pinctrl config subnodes

Quoted 17 lines
  arch/arm/dts/at91-sama5d27_giantboard.dts     |  59 +++--
  arch/arm/dts/at91-sama5d27_som1_ek.dts        |  80 +++----
  .../dts/at91-sama5d27_wlsom1_ek-u-boot.dtsi   |   6 +-
  arch/arm/dts/at91-sama5d27_wlsom1_ek.dts      |  92 ++++----
  arch/arm/dts/at91-sama5d2_icp.dts             | 134 ++++++------
  arch/arm/dts/at91-sama5d2_ptc_ek.dts          |  98 ++++-----
  arch/arm/dts/at91-sama5d2_xplained.dts        | 204 +++++++++---------
  arch/arm/dts/at91-sama7g5ek-u-boot.dtsi       |   2 +-
  arch/arm/dts/at91-sama7g5ek.dts               |  85 +++++---
  arch/arm/dts/sama5d2.dtsi                     |   9 +-
  arch/arm/dts/sama5d27_som1.dtsi               |  94 ++++----
  arch/arm/dts/sama5d27_wlsom1.dtsi             |  54 +++--
  arch/arm/dts/sama7g5.dtsi                     |  16 +-
  drivers/gpio/atmel_pio4.c                     |   2 -
  drivers/pinctrl/pinctrl-at91-pio4.c           | 138 ++++++++++--
  15 files changed, 592 insertions(+), 481 deletions(-)

Applied to u-boot-at91/next , thanks !