Skip to contentSkip to conversation

pinctrl: ralink: add support for rt2880 pinmux

PATCH In review John Crispin 2 participants 7 messages Oct 9, 2014 – Oct 27, 2014

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

cover pinctrl: ralink: add support for rt2880 pinmux

This series adds a pinctrl driver for ralink SoC. as it touches both arch and pinctrl files i would prefer to have this go via the mips tree with the other ralink pathes that i have sent.

John Crispin (4):
MIPS: ralink: cleanup the soc specific pinmux data
pinctrl: ralink: add a pinctrl driver for the rt2880 family of SoCs
pinctrl: ralink: add binding documentation
MIPS: ralink: always enable pinctrl on ralink SoC

 .../bindings/pinctrl/ralink,rt2880-pinmux.txt      |   74 +++
 arch/mips/Kconfig                                  |    2 +
 arch/mips/include/asm/mach-ralink/mt7620.h         |   41 +-
 arch/mips/include/asm/mach-ralink/pinmux.h         |   55 +++
 arch/mips/include/asm/mach-ralink/rt305x.h         |   35 +-
 arch/mips/include/asm/mach-ralink/rt3883.h         |   16 +-
 arch/mips/ralink/common.h                          |   19 -
 arch/mips/ralink/mt7620.c                          |  159 +++----
 arch/mips/ralink/rt288x.c                          |   62 +--
 arch/mips/ralink/rt305x.c                          |  153 +++----
 arch/mips/ralink/rt3883.c                          |  173 ++-----
 drivers/pinctrl/Kconfig                            |    5 +
 drivers/pinctrl/Makefile                           |    1 +
 drivers/pinctrl/pinctrl-rt2880.c                   |  474 ++++++++++++++++++++
 14 files changed, 849 insertions(+), 420 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/pinctrl/ralink,rt2880-pinmux.txt
 create mode 100644 arch/mips/include/asm/mach-ralink/pinmux.h
 create mode 100644 drivers/pinctrl/pinctrl-rt2880.c
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 1/4 MIPS: ralink: cleanup the soc specific pinmux data

Before we had a pinctrl driver we used a custom OF api. This patch converts the soc specific pinmux data to a new set of structs. We also add some new pinmux setings.

---
 arch/mips/include/asm/mach-ralink/mt7620.h |   41 +++++--
 arch/mips/include/asm/mach-ralink/pinmux.h |   55 +++++++++
 arch/mips/include/asm/mach-ralink/rt305x.h |   35 +++---
 arch/mips/include/asm/mach-ralink/rt3883.h |   16 +--
 arch/mips/ralink/common.h                  |   19 ---
 arch/mips/ralink/mt7620.c                  |  159 ++++++++-----------------
 arch/mips/ralink/rt288x.c                  |   62 ++++------
 arch/mips/ralink/rt305x.c                  |  153 +++++++++++-------------
 arch/mips/ralink/rt3883.c                  |  173 +++++++---------------------
 9 files changed, 293 insertions(+), 420 deletions(-)
 create mode 100644 arch/mips/include/asm/mach-ralink/pinmux.h
arch/mips/include/asm/mach-ralink/mt7620.h +30 -11
index 7ff9290..a05c14c2 100644
@@ -82,7 +82,6 @@
 #define MT7620_DDR2_SIZE_MIN		32
 #define MT7620_DDR2_SIZE_MAX		256
 
-#define MT7620_GPIO_MODE_I2C		BIT(0)
 #define MT7620_GPIO_MODE_UART0_SHIFT	2
 #define MT7620_GPIO_MODE_UART0_MASK	0x7
 #define MT7620_GPIO_MODE_UART0(x)	((x) << MT7620_GPIO_MODE_UART0_SHIFT)
@@ -94,16 +93,36 @@
 #define MT7620_GPIO_MODE_GPIO_UARTF	0x5
 #define MT7620_GPIO_MODE_GPIO_I2S	0x6
 #define MT7620_GPIO_MODE_GPIO		0x7
-#define MT7620_GPIO_MODE_UART1		BIT(5)
-#define MT7620_GPIO_MODE_MDIO		BIT(8)
-#define MT7620_GPIO_MODE_RGMII1		BIT(9)
-#define MT7620_GPIO_MODE_RGMII2		BIT(10)
-#define MT7620_GPIO_MODE_SPI		BIT(11)
-#define MT7620_GPIO_MODE_SPI_REF_CLK	BIT(12)
-#define MT7620_GPIO_MODE_WLED		BIT(13)
-#define MT7620_GPIO_MODE_JTAG		BIT(15)
-#define MT7620_GPIO_MODE_EPHY		BIT(15)
-#define MT7620_GPIO_MODE_WDT		BIT(22)
+
+#define MT7620_GPIO_MODE_NAND		0
+#define MT7620_GPIO_MODE_SD		1
+#define MT7620_GPIO_MODE_ND_SD_GPIO	2
+#define MT7620_GPIO_MODE_ND_SD_MASK	0x3
+#define MT7620_GPIO_MODE_ND_SD_SHIFT	18
+
+#define MT7620_GPIO_MODE_PCIE_RST	0
+#define MT7620_GPIO_MODE_PCIE_REF	1
+#define MT7620_GPIO_MODE_PCIE_GPIO	2
+#define MT7620_GPIO_MODE_PCIE_MASK	0x3
+#define MT7620_GPIO_MODE_PCIE_SHIFT	16
+
+#define MT7620_GPIO_MODE_WDT_RST	0
+#define MT7620_GPIO_MODE_WDT_REF	1
+#define MT7620_GPIO_MODE_WDT_GPIO	2
+#define MT7620_GPIO_MODE_WDT_MASK	0x3
+#define MT7620_GPIO_MODE_WDT_SHIFT	21
+
+#define MT7620_GPIO_MODE_I2C		0
+#define MT7620_GPIO_MODE_UART1		5
+#define MT7620_GPIO_MODE_MDIO		8
+#define MT7620_GPIO_MODE_RGMII1		9
+#define MT7620_GPIO_MODE_RGMII2		10
+#define MT7620_GPIO_MODE_SPI		11
+#define MT7620_GPIO_MODE_SPI_REF_CLK	12
+#define MT7620_GPIO_MODE_WLED		13
+#define MT7620_GPIO_MODE_JTAG		15
+#define MT7620_GPIO_MODE_EPHY		15
+#define MT7620_GPIO_MODE_PA		20
 
 static inline int mt7620_get_eco(void)
 {
arch/mips/include/asm/mach-ralink/pinmux.h new file +55 -0

55 lines not on this page · raw message

arch/mips/include/asm/mach-ralink/rt305x.h +20 -15
index 069bf37..96f731b 100644
@@ -125,24 +125,29 @@ static inline int soc_is_rt5350(void)
 #define RT305X_GPIO_GE0_TXD0		40
 #define RT305X_GPIO_GE0_RXCLK		51
 
-#define RT305X_GPIO_MODE_I2C		BIT(0)
-#define RT305X_GPIO_MODE_SPI		BIT(1)
 #define RT305X_GPIO_MODE_UART0_SHIFT	2
 #define RT305X_GPIO_MODE_UART0_MASK	0x7
 #define RT305X_GPIO_MODE_UART0(x)	((x) << RT305X_GPIO_MODE_UART0_SHIFT)
-#define RT305X_GPIO_MODE_UARTF		0x0
-#define RT305X_GPIO_MODE_PCM_UARTF	0x1
-#define RT305X_GPIO_MODE_PCM_I2S	0x2
-#define RT305X_GPIO_MODE_I2S_UARTF	0x3
-#define RT305X_GPIO_MODE_PCM_GPIO	0x4
-#define RT305X_GPIO_MODE_GPIO_UARTF	0x5
-#define RT305X_GPIO_MODE_GPIO_I2S	0x6
-#define RT305X_GPIO_MODE_GPIO		0x7
-#define RT305X_GPIO_MODE_UART1		BIT(5)
-#define RT305X_GPIO_MODE_JTAG		BIT(6)
-#define RT305X_GPIO_MODE_MDIO		BIT(7)
-#define RT305X_GPIO_MODE_SDRAM		BIT(8)
-#define RT305X_GPIO_MODE_RGMII		BIT(9)
+#define RT305X_GPIO_MODE_UARTF		0
+#define RT305X_GPIO_MODE_PCM_UARTF	1
+#define RT305X_GPIO_MODE_PCM_I2S	2
+#define RT305X_GPIO_MODE_I2S_UARTF	3
+#define RT305X_GPIO_MODE_PCM_GPIO	4
+#define RT305X_GPIO_MODE_GPIO_UARTF	5
+#define RT305X_GPIO_MODE_GPIO_I2S	6
+#define RT305X_GPIO_MODE_GPIO		7
+
+#define RT305X_GPIO_MODE_I2C		0
+#define RT305X_GPIO_MODE_SPI		1
+#define RT305X_GPIO_MODE_UART1		5
+#define RT305X_GPIO_MODE_JTAG		6
+#define RT305X_GPIO_MODE_MDIO		7
+#define RT305X_GPIO_MODE_SDRAM		8
+#define RT305X_GPIO_MODE_RGMII		9
+#define RT5350_GPIO_MODE_PHY_LED	14
+#define RT5350_GPIO_MODE_SPI_CS1	21
+#define RT3352_GPIO_MODE_LNA		18
+#define RT3352_GPIO_MODE_PA		20
 
 #define RT3352_SYSC_REG_SYSCFG0		0x010
 #define RT3352_SYSC_REG_SYSCFG1         0x014
arch/mips/include/asm/mach-ralink/rt3883.h +9 -7
index 058382f..0fbe6f9 100644
@@ -112,8 +112,6 @@
 #define RT3883_CLKCFG1_PCI_CLK_EN	BIT(19)
 #define RT3883_CLKCFG1_UPHY0_CLK_EN	BIT(18)
 
-#define RT3883_GPIO_MODE_I2C		BIT(0)
-#define RT3883_GPIO_MODE_SPI		BIT(1)
 #define RT3883_GPIO_MODE_UART0_SHIFT	2
 #define RT3883_GPIO_MODE_UART0_MASK	0x7
 #define RT3883_GPIO_MODE_UART0(x)	((x) << RT3883_GPIO_MODE_UART0_SHIFT)
@@ -125,11 +123,15 @@
 #define RT3883_GPIO_MODE_GPIO_UARTF	0x5
 #define RT3883_GPIO_MODE_GPIO_I2S	0x6
 #define RT3883_GPIO_MODE_GPIO		0x7
-#define RT3883_GPIO_MODE_UART1		BIT(5)
-#define RT3883_GPIO_MODE_JTAG		BIT(6)
-#define RT3883_GPIO_MODE_MDIO		BIT(7)
-#define RT3883_GPIO_MODE_GE1		BIT(9)
-#define RT3883_GPIO_MODE_GE2		BIT(10)
+
+#define RT3883_GPIO_MODE_I2C		0
+#define RT3883_GPIO_MODE_SPI		1
+#define RT3883_GPIO_MODE_UART1		5
+#define RT3883_GPIO_MODE_JTAG		6
+#define RT3883_GPIO_MODE_MDIO		7
+#define RT3883_GPIO_MODE_GE1		9
+#define RT3883_GPIO_MODE_GE2		10
+
 #define RT3883_GPIO_MODE_PCI_SHIFT	11
 #define RT3883_GPIO_MODE_PCI_MASK	0x7
 #define RT3883_GPIO_MODE_PCI		(RT3883_GPIO_MODE_PCI_MASK << RT3883_GPIO_MODE_PCI_SHIFT)
arch/mips/ralink/common.h +0 -19
index 42dfd61..8e7d8e6 100644
@@ -11,25 +11,6 @@
 
 #define RAMIPS_SYS_TYPE_LEN	32
 
-struct ralink_pinmux_grp {
-	const char *name;
-	u32 mask;
-	int gpio_first;
-	int gpio_last;
-};
-
-struct ralink_pinmux {
-	struct ralink_pinmux_grp *mode;
-	struct ralink_pinmux_grp *uart;
-	int uart_shift;
-	u32 uart_mask;
-	void (*wdt_reset)(void);
-	struct ralink_pinmux_grp *pci;
-	int pci_shift;
-	u32 pci_mask;
-};
-extern struct ralink_pinmux rt_gpio_pinmux;
-
 struct ralink_soc_info {
 	unsigned char sys_type[RAMIPS_SYS_TYPE_LEN];
 	unsigned char *compatible;
arch/mips/ralink/mt7620.c +50 -109

174 lines not on this page · raw message

arch/mips/ralink/rt288x.c +20 -42

81 lines not on this page · raw message

arch/mips/ralink/rt305x.c +68 -85

183 lines not on this page · raw message

arch/mips/ralink/rt3883.c +41 -132

194 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#2 lore raw

PATCH 2/4 pinctrl: ralink: add a pinctrl driver for the rt2880 family of SoCs

In reply to John Crispin

These Socs have 1-3 banks of 8-32 gpios. Rather then setting the muxing of each pin individually, these socs have mux groups that when set will effect 1-N pins. Pin groups have a 2, 4 or 8 different muxes.

---
 drivers/pinctrl/Kconfig          |    5 +
 drivers/pinctrl/Makefile         |    1 +
 drivers/pinctrl/pinctrl-rt2880.c |  474 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 480 insertions(+)
 create mode 100644 drivers/pinctrl/pinctrl-rt2880.c
drivers/pinctrl/Kconfig +5 -0
index bfd2c2e..2447088 100644
@@ -192,6 +192,11 @@ config PINCTRL_LANTIQ
 	select PINMUX
 	select PINCONF
 
+config PINCTRL_RT2880
+	bool
+	depends on RALINK
+	select PINMUX
+
 config PINCTRL_FALCON
 	bool
 	depends on SOC_FALCON
drivers/pinctrl/Makefile +1 -0
index 05d2275..6273f86 100644
@@ -36,6 +36,7 @@ obj-$(CONFIG_PINCTRL_IMX25)	+= pinctrl-imx25.o
 obj-$(CONFIG_PINCTRL_IMX28)	+= pinctrl-imx28.o
 obj-$(CONFIG_PINCTRL_PALMAS)	+= pinctrl-palmas.o
 obj-$(CONFIG_PINCTRL_ROCKCHIP)	+= pinctrl-rockchip.o
+obj-$(CONFIG_PINCTRL_RT2880)	+= pinctrl-rt2880.o
 obj-$(CONFIG_PINCTRL_SINGLE)	+= pinctrl-single.o
 obj-$(CONFIG_PINCTRL_SIRF)	+= sirf/
 obj-$(CONFIG_PINCTRL_TEGRA)	+= pinctrl-tegra.o
drivers/pinctrl/pinctrl-rt2880.c new file +474 -0

474 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#4 lore raw

PATCH 3/4 pinctrl: ralink: add binding documentation

In reply to John Crispin
---
 .../bindings/pinctrl/ralink,rt2880-pinmux.txt      |   74 ++++++++++++++++++++
 1 file changed, 74 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pinctrl/ralink,rt2880-pinmux.txt
Documentation/devicetree/bindings/pinctrl/ralink,rt2880-pinmux.txt new file +74 -0
new file mode 100644
index 0000000..20e6cc0
@@ -0,0 +1,74 @@
+Ralink rt2880 pinmux controller
+
+Required properties:
+- compatible: "lantiq,rt2880-pinmux"
+- reg: Should contain the physical address and length of the gpio/pinmux
+  register range
+
+The rt2880 pinmux can only set the muxing of pin groups. muxing indiviual pins
+is not supported. There is no pinconf support.
+
+Definition of mux function groups:
+
+Required subnode-properties:
+- ralink,group : An array of strings. Each string contains the name of a group.
+  Valid values for these names are listed below.
+- ralink,function: A string containing the name of the function to mux to the
+  group. Valid values for function names are listed below.
+
+Valid values for group and function names:
+   mux groups (rt2880):
+    i2c, spi, uartlite, jtag, mdio, sdram, pci
+
+   mux functions (rt2880):
+    gpio, i2c, spi, uartlite, jtag, mdio, sdram, pci
+
+   mux groups (rt3050):
+    i2c, spi, uartf, uartlite, jtag, mdio, rgmii, sdram
+
+   mux functions (rt3050):
+    gpio, i2c, spi, uartf, pcm uartf, pcm i2s, i2s uartf, pcm gpio, gpio uartf,
+    gpio i2s, uartlite, jtag, mdio, sdram
+
+   mux groups (rt3352):
+    i2c, spi, uartf, uartlite, jtag, mdio, rgmii, lna, pna, led
+
+   mux functions (rt3050):
+    gpio, i2c, spi, uartf, pcm uartf, pcm i2s, i2s uartf, pcm gpio, gpio uartf,
+    gpio i2s, uartlite, jtag, mdio, lna, pna, led
+
+   mux groups (rt5350):
+    i2c, spi, uartf, uartlite, jtag, pna, led, spi cs1
+
+   mux functions (rt5350):
+    gpio, i2c, spi, uartf, pcm uartf, pcm i2s, i2s uartf, pcm gpio, gpio uartf,
+    gpio i2s, uartlite, jtag, spi_cs1, wdg
+
+
+Example:
+	pinctrl {
+		compatible = "ralink,rt2880-pinmux";
+
+		pinctrl-names = "default";
+		pinctrl-0 = <&state_default>;
+
+		state_default: pinctrl0 {
+			sdram {
+				ralink,group = "sdram";
+				ralink,function = "sdram";
+			};
+		};
+
+		spi_pins: spi {
+			spi {
+				ralink,group = "spi";
+				ralink,function = "spi";
+			};
+		};
+		uartlite_pins: uartlite {
+			uart {
+				ralink,group = "uartlite";
+				ralink,function = "uartlite";
+			};
+		};
+	};
Signature · 1 line
1.7.10.4
#6 lore raw

PATCH 4/4 MIPS: ralink: always enable pinctrl on ralink SoC

In reply to John Crispin
---
 arch/mips/Kconfig |    2 ++
 1 file changed, 2 insertions(+)
arch/mips/Kconfig +2 -0
index 574c430..2d255e8 100644
@@ -451,6 +451,8 @@ config RALINK
 	select CLKDEV_LOOKUP
 	select ARCH_HAS_RESET_CONTROLLER
 	select RESET_CONTROLLER
+	select PINCTRL
+	select PINCTRL_RT2880
 
 config SGI_IP22
 	bool "SGI IP22 (Indy/Indigo2)"
Signature · 1 line
1.7.10.4
#3 lore raw

Re: [PATCH 2/4] pinctrl: ralink: add a pinctrl driver for the rt2880 family of SoCs

In reply to John Crispin
Quoted 5 lines · John Crispin

These Socs have 1-3 banks of 8-32 gpios. Rather then setting the muxing of each pin individually, these socs have mux groups that when set will effect 1-N pins. Pin groups have a 2, 4 or 8 different muxes.

Overall this looks nice, some minor things....

Quoted 4 lines
drivers/pinctrl/pinctrl-rt2880.c new file +4 -0
+struct rt2880_priv {
+       struct device *dev;
+
+       struct pinctrl_pin_desc *pads;

drivers/pinctrl/pinctrl-rt2880.c line 44

Quoted 10 lines
drivers/pinctrl/pinctrl-rt2880.c new file +10 -0
+       struct pinctrl_desc *desc;
+
+       struct rt2880_pmx_func **func;
+       int func_count;
+
+       struct rt2880_pmx_group *groups;
+       const char **group_names;
+       int group_count;
+
+       uint8_t *gpio;

Just use u8

drivers/pinctrl/pinctrl-rt2880.c line 46

Quoted 2 lines
drivers/pinctrl/pinctrl-rt2880.c new file +2 -0
+       int max_pins;
+};

Some of this would need some kerneldoc, don't you think?

drivers/pinctrl/pinctrl-rt2880.c line 94

Quoted 11 lines
drivers/pinctrl/pinctrl-rt2880.c new file +11 -0
+static void rt2880_pinctrl_dt_free_map(struct pinctrl_dev *pctrldev,
+                                   struct pinctrl_map *map, unsigned num_maps)
+{
+       int i;
+
+       for (i = 0; i < num_maps; i++)
+               if (map[i].type == PIN_MAP_TYPE_CONFIGS_PIN ||
+                   map[i].type == PIN_MAP_TYPE_CONFIGS_GROUP)
+                       kfree(map[i].data.configs.configs);
+       kfree(map);
+}

Can you use pinctrl_utils_dt_free_map()
from
#include "pinctrl-utils.h"
for this?

drivers/pinctrl/pinctrl-rt2880.c line 101

Quoted 6 lines
drivers/pinctrl/pinctrl-rt2880.c new file +6 -0
+static void rt2880_pinctrl_pin_dbg_show(struct pinctrl_dev *pctrldev,
+                                       struct seq_file *s,
+                                       unsigned offset)
+{
+       seq_puts(s, "ralink pio");
+}

Hmmm rather terse debug info don't you think... ;)

drivers/pinctrl/pinctrl-rt2880.c line 109

Quoted 7 lines
drivers/pinctrl/pinctrl-rt2880.c new file +7 -0
+static void rt2880_pinctrl_dt_subnode_to_map(struct pinctrl_dev *pctrldev,
+                               struct device_node *np,
+                               struct pinctrl_map **map)
+{
+       const char *function;
+       int func = of_property_read_string(np, "ralink,function", &function);
+       int grps = of_property_count_strings(np, "ralink,group");

There are now standard bindings for "function" and "group" so please if you can, just use "function" and "group".

See:
Documentation/devicetree/bindings/pinctrl/pinctrl-bindings.txt "Generic pin multiplexing node content"

I also wanted to provide a generic parsing function for it actually, since so many drivers look alike.

Quoted 11 lines
drivers/pinctrl/pinctrl-rt2880.c new file +11 -0
+static int rt2880_pinctrl_dt_node_to_map(struct pinctrl_dev *pctrldev,
+                               struct device_node *np_config,
+                               struct pinctrl_map **map,
+                               unsigned *num_maps)
+{
+       int max_maps = 0;
+       struct pinctrl_map *tmp;
+       struct device_node *np;
+
+       for_each_child_of_node(np_config, np) {
+               int ret = of_property_count_strings(np, "ralink,group");

drivers/pinctrl/pinctrl-rt2880.c line 148

Quoted 10 lines
drivers/pinctrl/pinctrl-rt2880.c new file +10 -0
+
+               if (ret >= 0)
+                       max_maps += ret;
+       }
+
+       if (!max_maps)
+               return max_maps;
+
+       *map = kzalloc(max_maps * sizeof(struct pinctrl_map),
+                                       GFP_KERNEL);

Can you use pinctrl_utils_reserve_map() here?

drivers/pinctrl/pinctrl-rt2880.c line 204

Quoted 3 lines
drivers/pinctrl/pinctrl-rt2880.c new file +3 -0
+static int rt2880_pmx_group_enable(struct pinctrl_dev *pctrldev,
+                               unsigned func,
+                               unsigned group)

We don't have an "enable" callback anymore.
Rename this rt2880_pmx_set_mux().

drivers/pinctrl/pinctrl-rt2880.c line 259

Quoted 5 lines
drivers/pinctrl/pinctrl-rt2880.c new file +5 -0
+static const struct pinmux_ops rt2880_pmx_group_ops = {
+       .get_functions_count    = rt2880_pmx_func_count,
+       .get_function_name      = rt2880_pmx_func_name,
+       .get_function_groups    = rt2880_pmx_group_get_groups,
+       .enable                 = rt2880_pmx_group_enable,

.set_mux rather than .enable

And make sure you test this on say v3.18-rc2.

drivers/pinctrl/pinctrl-rt2880.c line 272

Quoted 3 lines
drivers/pinctrl/pinctrl-rt2880.c new file +3 -0
+static struct rt2880_pmx_func gpio_func = {
+       .name = "gpio",
+};

Hmmmmmm

Quoted 23 lines
drivers/pinctrl/pinctrl-rt2880.c new file +23 -0
+static int rt2880_pinmux_index(struct rt2880_priv *p)
+{
+       struct rt2880_pmx_func **f;
+       struct rt2880_pmx_group *mux = p->groups;
+       int i, j, c = 0;
+
+       /* count the mux functions */
+       while (mux->name) {
+               p->group_count++;
+               mux++;
+       }
+
+       /* allocate the group names array needed by the gpio function */
+       p->group_names = devm_kzalloc(p->dev,
+               sizeof(char *) * p->group_count, GFP_KERNEL);
+       if (!p->group_names)
+               return -1;
+
+       for (i = 0; i < p->group_count; i++) {
+               p->group_names[i] = p->groups[i].name;
+               p->func_count += p->groups[i].func_count;
+       }
+

drivers/pinctrl/pinctrl-rt2880.c line 306

Quoted 10 lines
drivers/pinctrl/pinctrl-rt2880.c new file +10 -0
+       /* we have a dummy function[0] for gpio */
+       p->func_count++;
+
+       /* allocate our function and group mapping index buffers */
+       f = p->func = devm_kzalloc(p->dev,
+               sizeof(struct rt2880_pmx_func) * p->func_count, GFP_KERNEL);
+       gpio_func.groups = devm_kzalloc(p->dev, sizeof(int) * p->group_count,
+               GFP_KERNEL);
+       if (!f || !gpio_func.groups)
+               return -1;

Can you explain what this code is doing a bit more.

Are you avoiding to use gpio ranges by instead providing that "gpio" function on each and every pin?

Quoted 18 lines
drivers/pinctrl/pinctrl-rt2880.c new file +18 -0
+static int rt2880_pinmux_probe(struct platform_device *pdev)
+{
+       struct rt2880_priv *p;
+       struct pinctrl_dev *dev;
+       struct device_node *np;
+
+       if (!rt2880_pinmux_data)
+               return -ENOSYS;
+
+       /* setup the private data */
+       p = devm_kzalloc(&pdev->dev, sizeof(struct rt2880_priv), GFP_KERNEL);
+       if (!p)
+               return -ENOMEM;
+
+       p->dev = &pdev->dev;
+       p->desc = &rt2880_pctrl_desc;
+       p->groups = rt2880_pinmux_data;
+       platform_set_drvdata(pdev, p);

drivers/pinctrl/pinctrl-rt2880.c line 420

Quoted 10 lines
drivers/pinctrl/pinctrl-rt2880.c new file +10 -0
+
+       /* init the device */
+       if (rt2880_pinmux_index(p)) {
+               dev_err(&pdev->dev, "failed to load index\n");
+               return -EINVAL;
+       }
+       if (rt2880_pinmux_pins(p)) {
+               dev_err(&pdev->dev, "failed to load pins\n");
+               return -EINVAL;
+       }

What is this "loading" that is happening here?

Quoted 5 lines
drivers/pinctrl/pinctrl-rt2880.c new file +5 -0
+       dev = pinctrl_register(p->desc, &pdev->dev, p);
+       if (IS_ERR(dev))
+               return PTR_ERR(dev);
+
+       /* finalize by adding gpio ranges for enables gpio controllers */

drivers/pinctrl/pinctrl-rt2880.c line 435

Quoted 10 lines
drivers/pinctrl/pinctrl-rt2880.c new file +10 -0
+       for_each_compatible_node(np, NULL, "ralink,rt2880-gpio") {
+               const __be32 *ngpio, *gpiobase;
+               struct pinctrl_gpio_range *range;
+               char *name;
+
+               if (!of_device_is_available(np))
+                       continue;
+
+               ngpio = of_get_property(np, "ralink,num-gpios", NULL);
+               gpiobase = of_get_property(np, "ralink,gpio-base", NULL);

NO GPIO BASE in the device tree.

We have NACKed this so many times that I don't know it anymore.

The gpiobase is a linux-internal thing and not OS neutral at all.

So it has nothing to do in the device tree.

(If it was allowed it would atleast be linux,gpio-base)

Several other ways to handle this is available, the best being... (see below)

drivers/pinctrl/pinctrl-rt2880.c line 448

Quoted 13 lines
drivers/pinctrl/pinctrl-rt2880.c new file +13 -0
+               if (!ngpio || !gpiobase) {
+                       dev_err(&pdev->dev, "failed to load chip info\n");
+                       return -EINVAL;
+               }
+
+               range = devm_kzalloc(p->dev,
+                       sizeof(struct pinctrl_gpio_range) + 4, GFP_KERNEL);
+               range->name = name = (char *) &range[1];
+               sprintf(name, "pio");
+               range->npins = __be32_to_cpu(*ngpio);
+               range->base = __be32_to_cpu(*gpiobase);
+               range->pin_base = range->base;
+               pinctrl_add_gpio_range(dev, range);

...to NOT do this but instead use gpiochip_add_pin_range() or gpiochip_add_pingroup_range() from the gpiochip side.

The gpiochip has the ability to add ranges completely dynamically as it can get a relative offset from the pin control subsystem. It doesn't work the other way around unfortunately.

So I'd suggest you look at ways to modify your GPIO driver to do this.

Quoted 1 line

+core_initcall_sync(rt2880_pinmux_init);

Do you really need it this early?

Yours,
Linus Walleij

#5 lore raw

Re: [PATCH 3/4] pinctrl: ralink: add binding documentation

In reply to John Crispin
Quoted 1 line · John Crispin

This does not seem complete since it lacks things like the very controversial gpio-base thing.

Quoted 9 lines

+++ b/Documentation/devicetree/bindings/pinctrl/ralink,rt2880-pinmux.txt

Documentation/devicetree/bindings/pinctrl/ralink,rt2880-pinmux.txt new file +7 -0
@@ -0,0 +1,74 @@
+Ralink rt2880 pinmux controller
+
+Required properties:
+- compatible: "lantiq,rt2880-pinmux"
+- reg: Should contain the physical address and length of the gpio/pinmux
+  register range
+

Documentation/devicetree/bindings/pinctrl/ralink,rt2880-pinmux.txt line 17

Quoted 10 lines
Documentation/devicetree/bindings/pinctrl/ralink,rt2880-pinmux.txt new file +10 -0
+The rt2880 pinmux can only set the muxing of pin groups. muxing indiviual pins
+is not supported. There is no pinconf support.
+
+Definition of mux function groups:
+
+Required subnode-properties:
+- ralink,group : An array of strings. Each string contains the name of a group.
+  Valid values for these names are listed below.
+- ralink,function: A string containing the name of the function to mux to the
+  group. Valid values for function names are listed below.

Just use "function" and "group" from the generic bindings.

Yours,
Linus Walleij