Skip to contentSkip to conversation

pinctrl: ralink: pinctrl driver for the rt2880 family

PATCH Superseded Sergio Paracuellos 3 participants 10 messages Dec 7, 2020 – Dec 8, 2020

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover pinctrl: ralink: pinctrl driver for the rt2880 family

This series adds a pinctrl driver for ralink rt2880 SoC.

After last cleanup in staging I was told [0] this driver is ready to be promoted from staging.

This series are rebased on the top of staging-testing.

Thanks in advance for your time.

Best regards,
Sergio Paracuellos

[0]: http://driverdev.linuxdriverproject.org/pipermail/driverdev-devel/2020-December/149178.html
Sergio Paracuellos (3):
dt-bindings: pinctrl: rt2880: add binding document
pinctrl: ralink: add a pinctrl driver for the rt2880 family
staging: mt7621-pinctrl: remove driver from staging

 .../pinctrl/ralink,rt2880-pinmux.yaml         | 82 +++++++++++++++++++
 drivers/pinctrl/Kconfig                       |  6 ++
 drivers/pinctrl/Makefile                      |  1 +
 .../pinctrl-rt2880.c                          |  0
 drivers/staging/Kconfig                       |  2 -
 drivers/staging/Makefile                      |  1 -
 drivers/staging/mt7621-pinctrl/Kconfig        |  6 --
 drivers/staging/mt7621-pinctrl/Makefile       |  4 -
 drivers/staging/mt7621-pinctrl/TODO           |  6 --
 9 files changed, 89 insertions(+), 19 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/pinctrl/ralink,rt2880-pinmux.yaml
 rename drivers/{staging/mt7621-pinctrl => pinctrl}/pinctrl-rt2880.c (100%)
 delete mode 100644 drivers/staging/mt7621-pinctrl/Kconfig
 delete mode 100644 drivers/staging/mt7621-pinctrl/Makefile
 delete mode 100644 drivers/staging/mt7621-pinctrl/TODO
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/3 dt-bindings: pinctrl: rt2880: add binding document

The commit adds rt2880 compatible node in binding document.

---
 .../pinctrl/ralink,rt2880-pinmux.yaml         | 82 +++++++++++++++++++
 1 file changed, 82 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pinctrl/ralink,rt2880-pinmux.yaml
Documentation/devicetree/bindings/pinctrl/ralink,rt2880-pinmux.yaml new file +82 -0
new file mode 100644
index 000000000000..d946219a115c
@@ -0,0 +1,82 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/pinctrl/ralink,rt2880-pinmux.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Ralink rt2880 pinmux controller
+
+maintainers:
+  - Sergio Paracuellos <[email protected]>
+
+description:
+  The rt2880 pinmux can only set the muxing of pin groups. muxing indiviual pins
+  is not supported. There is no pinconf support.
+
+properties:
+  compatible:
+    enum:
+      - ralink,rt2880-pinmux
+
+  pinctrl-0:
+    description:
+      A phandle to the node containing the subnodes containing default
+      configurations.
+
+  pinctrl-names:
+    description:
+      A pinctrl state named "default" must be defined.
+    const: default
+
+required:
+  - compatible
+  - pinctrl-names
+  - pinctrl-0
+
+patternProperties:
+  '^.*$':
+    if:
+      type: object
+      description: |
+        A pinctrl node should contain at least one subnodes representing the
+        pinctrl groups available on the machine.
+      $ref: "pinmux-node.yaml"
+      required:
+        - groups
+        - function
+      additionalProperties: false
+    then:
+      properties:
+        groups:
+          description:
+            Name of the pin group to use for the functions.
+          $ref: "/schemas/types.yaml#/definitions/string"
+          enum: [i2c, spi, uart1, uart2, uart3, rgmii1, rgmii2, mdio,
+                 pcie, sdhci]
+        function:
+          description:
+            The mux function to select
+          $ref: "/schemas/types.yaml#/definitions/string"
+          enum: [gpio, i2c, spi, uart1, uart2, uart3, rgmii1, rgmii2,
+                 mdio, nand1, nand2, sdhci]
+
+additionalProperties: false
+
+examples:
+  # Pinmux controller node
+  - |
+    pinctrl {
+      compatible = "ralink,rt2880-pinmux";
+      pinctrl-names = "default";
+      pinctrl-0 = <&state_default>;
+
+      state_default: pinctrl0 {
+      };
+
+      i2c_pins: i2c0 {
+        i2c0 {
+          groups = "i2c";
+          function = "i2c";
+        };
+      };
+    };
Signature · 1 line
2.25.1
#4 lore raw

PATCH 2/3 pinctrl: ralink: add a pinctrl driver for the rt2880 family

In reply to Sergio Paracuellos

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          |   6 +
 drivers/pinctrl/Makefile         |   1 +
 drivers/pinctrl/pinctrl-rt2880.c | 370 +++++++++++++++++++++++++++++++
 3 files changed, 377 insertions(+)
 create mode 100644 drivers/pinctrl/pinctrl-rt2880.c
drivers/pinctrl/Kconfig +6 -0
index 815095326e2d..e97970ec1210 100644
@@ -215,6 +215,12 @@ config PINCTRL_ROCKCHIP
 	select MFD_SYSCON
 	select OF_GPIO
 
+config PINCTRL_RT2880
+        bool "RT2880 pinctrl driver for RALINK/Mediatek SOCs"
+        depends on RALINK
+        select PINMUX
+        select GENERIC_PINCONF
+
 config PINCTRL_SINGLE
 	tristate "One-register-per-pin type device tree based pinctrl driver"
 	depends on OF
drivers/pinctrl/Makefile +1 -0
index f53933b2ff02..0ebc24dad259 100644
@@ -45,6 +45,7 @@ obj-$(CONFIG_PINCTRL_STMFX) 	+= pinctrl-stmfx.o
 obj-$(CONFIG_PINCTRL_ZYNQ)	+= pinctrl-zynq.o
 obj-$(CONFIG_PINCTRL_INGENIC)	+= pinctrl-ingenic.o
 obj-$(CONFIG_PINCTRL_RK805)	+= pinctrl-rk805.o
+obj-$(CONFIG_PINCTRL_RT2880)   += pinctrl-rt2880.o
 obj-$(CONFIG_PINCTRL_OCELOT)	+= pinctrl-ocelot.o
 obj-$(CONFIG_PINCTRL_EQUILIBRIUM)   += pinctrl-equilibrium.o
 
drivers/pinctrl/pinctrl-rt2880.c new file +370 -0

370 lines not on this page · raw message

Signature · 1 line
2.25.1
#9 lore raw

PATCH 3/3 staging: mt7621-pinctrl: remove driver from staging

In reply to Sergio Paracuellos

Remove this driver from staging because it has been moved into its properly place in the kernel.

---
 drivers/staging/Kconfig                       |   2 -
 drivers/staging/Makefile                      |   1 -
 drivers/staging/mt7621-pinctrl/Kconfig        |   6 -
 drivers/staging/mt7621-pinctrl/Makefile       |   4 -
 drivers/staging/mt7621-pinctrl/TODO           |   6 -
 .../staging/mt7621-pinctrl/pinctrl-rt2880.c   | 370 ------------------
 6 files changed, 389 deletions(-)
 delete mode 100644 drivers/staging/mt7621-pinctrl/Kconfig
 delete mode 100644 drivers/staging/mt7621-pinctrl/Makefile
 delete mode 100644 drivers/staging/mt7621-pinctrl/TODO
 delete mode 100644 drivers/staging/mt7621-pinctrl/pinctrl-rt2880.c
drivers/staging/Kconfig +0 -2
index 9b7cb7c5766a..c42708e60afc 100644
@@ -94,8 +94,6 @@ source "drivers/staging/mt7621-pci/Kconfig"
 
 source "drivers/staging/mt7621-pci-phy/Kconfig"
 
-source "drivers/staging/mt7621-pinctrl/Kconfig"
-
 source "drivers/staging/mt7621-dma/Kconfig"
 
 source "drivers/staging/ralink-gdma/Kconfig"
drivers/staging/Makefile +0 -1
index 38226737c9f3..ebcc646d7b51 100644
@@ -37,7 +37,6 @@ obj-$(CONFIG_BCM2835_VCHIQ)	+= vc04_services/
 obj-$(CONFIG_PI433)		+= pi433/
 obj-$(CONFIG_PCI_MT7621)	+= mt7621-pci/
 obj-$(CONFIG_PCI_MT7621_PHY)	+= mt7621-pci-phy/
-obj-$(CONFIG_PINCTRL_RT2880)	+= mt7621-pinctrl/
 obj-$(CONFIG_SOC_MT7621)	+= mt7621-dma/
 obj-$(CONFIG_DMA_RALINK)	+= ralink-gdma/
 obj-$(CONFIG_SOC_MT7621)	+= mt7621-dts/
drivers/staging/mt7621-pinctrl/Kconfig deleted +0 -6
deleted file mode 100644
index f42974026480..000000000000
@@ -1,6 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0
-config PINCTRL_RT2880
-	bool "RT2800 pinctrl driver for RALINK/Mediatek SOCs"
-	depends on RALINK
-	select PINMUX
-	select GENERIC_PINCONF
drivers/staging/mt7621-pinctrl/Makefile deleted +0 -4
deleted file mode 100644
index 49445f40c3cd..000000000000
@@ -1,4 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0
-obj-$(CONFIG_PINCTRL_RT2880)   += pinctrl-rt2880.o
-
-ccflags-y += -I$(srctree)/drivers/pinctrl
drivers/staging/mt7621-pinctrl/TODO deleted +0 -6
deleted file mode 100644
index b2c235a16d5c..000000000000
@@ -1,6 +0,0 @@
-
-- general code review and cleanup
-- should probably be always selected by 'config RALINK'
-- ensure device-tree requirements are documented
-
-Cc: NeilBrown <[email protected]>
drivers/staging/mt7621-pinctrl/pinctrl-rt2880.c deleted +0 -370

370 lines not on this page · raw message

Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH 1/3] dt-bindings: pinctrl: rt2880: add binding document

In reply to Sergio Paracuellos

Hi Sergio,

thanks for driving this!

Quoted 3 lines · Sergio Paracuellos

The commit adds rt2880 compatible node in binding document.

(...)

Documentation/devicetree/bindings/pinctrl/ralink,rt2880-pinmux.yaml line 14

Quoted 3 lines
Documentation/devicetree/bindings/pinctrl/ralink,rt2880-pinmux.yaml new file +3 -0
+description:
+  The rt2880 pinmux can only set the muxing of pin groups. muxing indiviual pins
+  is not supported. There is no pinconf support.

OK!

Documentation/devicetree/bindings/pinctrl/ralink,rt2880-pinmux.yaml line 24

Quoted 9 lines
Documentation/devicetree/bindings/pinctrl/ralink,rt2880-pinmux.yaml new file +9 -0
+properties:
+  compatible:
+    enum:
+      - ralink,rt2880-pinmux
+
+  pinctrl-0:
+    description:
+      A phandle to the node containing the subnodes containing default
+      configurations.

As it is a node on the pin controller itself, this is a hog so write something about that this is for pinctrl hogs.

Documentation/devicetree/bindings/pinctrl/ralink,rt2880-pinmux.yaml line 29

Quoted 4 lines
Documentation/devicetree/bindings/pinctrl/ralink,rt2880-pinmux.yaml new file +4 -0
+  pinctrl-names:
+    description:
+      A pinctrl state named "default" must be defined.
+    const: default

Is it really compulsory?

Documentation/devicetree/bindings/pinctrl/ralink,rt2880-pinmux.yaml line 34

Quoted 4 lines
Documentation/devicetree/bindings/pinctrl/ralink,rt2880-pinmux.yaml new file +4 -0
+required:
+  - compatible
+  - pinctrl-names
+  - pinctrl-0

I wonder if the hogs are really compulsory.

Documentation/devicetree/bindings/pinctrl/ralink,rt2880-pinmux.yaml line 37

Quoted 2 lines
Documentation/devicetree/bindings/pinctrl/ralink,rt2880-pinmux.yaml new file +2 -0
+patternProperties:
+  '^.*$':

That's liberal node naming!
What about [a-z0-9_-]+ or something?

Quoted 14 lines
Documentation/devicetree/bindings/pinctrl/ralink,rt2880-pinmux.yaml new file +14 -0
+    if:
+      type: object
+      description: |
+        A pinctrl node should contain at least one subnodes representing the
+        pinctrl groups available on the machine.
+      $ref: "pinmux-node.yaml"
+      required:
+        - groups
+        - function
+      additionalProperties: false
+    then:
+      properties:
+        groups:
+          description:

Documentation/devicetree/bindings/pinctrl/ralink,rt2880-pinmux.yaml line 61

Quoted 10 lines
Documentation/devicetree/bindings/pinctrl/ralink,rt2880-pinmux.yaml new file +10 -0
+            Name of the pin group to use for the functions.
+          $ref: "/schemas/types.yaml#/definitions/string"
+          enum: [i2c, spi, uart1, uart2, uart3, rgmii1, rgmii2, mdio,
+                 pcie, sdhci]
+        function:
+          description:
+            The mux function to select
+          $ref: "/schemas/types.yaml#/definitions/string"
+          enum: [gpio, i2c, spi, uart1, uart2, uart3, rgmii1, rgmii2,
+                 mdio, nand1, nand2, sdhci]

Why do we have this complex if: clause?
$ref: "pinmux-node.yaml" should bring in the groups and function properties. Then you can add some further restrictions on top of that, right?

I would just do:

patternProperties:
'^[a-z0-9_]+$':
type: object
description: node for pinctrl
$ref "pinmux-node.yaml"

properties:
groups:
description: groups...
enum: [i2c, spi, uart1, uart2, uart3, rgmii1, rgmii2, mdio,
pcie, sdhci]

        function:
          description: function...
          enum: [gpio, i2c, spi, uart1, uart2, uart3, rgmii1, rgmii2,

mdio, nand1, nand2, sdhci]

Note: the function names are fine but the group names are a bit confusion since often a group can be used for more than one function, and e.g.

function = "i2c";
group = "uart1";

to use the uart1 pins for an i2c is gonna look mildly confusing.

But if this is what the hardware calls it I suppose it is fine.

Yours,
Linus Walleij

Acked-by on v1 2/3
#5 lore raw

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

In reply to Sergio Paracuellos

Hi Serigio,

I dug around some to try to understand the patch I think I get it now :)

Squash this with the third patch so it becomes a "move" of this file, preserving history. With that:

I have ideas, but it is better to move the driver out of staging and improve it in pinctrl.

Since there might be many sub-SoCs for this pin controller, what about creating drivers/pinctrl/ralink/* for this at the same time?

Quoted 6 lines · Sergio Paracuellos

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/pinctrl-rt2880.c line 21

Quoted 3 lines
drivers/pinctrl/pinctrl-rt2880.c new file +3 -0
+#include <asm/mach-ralink/ralink_regs.h>
+#include <asm/mach-ralink/pinmux.h>
+#include <asm/mach-ralink/mt7620.h>

I think in the next step we should move the contents of rt2880_pinmux_data into this driver, then we can drop these mach-headers and show the way for the rest of the ralink chips to push their data down into this driver (or subdrivers) and depopulate mach-ralink a bit.

Quoted 1 line

+ p->groups = rt2880_pinmux_data;

So this is where the driver actually gets a pointer to all groups and functions, and these groups and functions all come from arch/mips/ralink/mt7621.c right?

I think after this first step we should move mt7621.c to pinctrl and become a subdriver for this pin controller and then we can hopefully move the rest as well once you set the pattern for how we do this.

Yours,
Linus Walleij

#3 lore raw

Re: [PATCH 1/3] dt-bindings: pinctrl: rt2880: add binding document

In reply to Linus Walleij

Hi Linus,

Thanks for the review. There weren't too many yaml samples for this so as you had seen this was a bit messy and I really needed this review, especially in the 'if' clause part :).

Quoted 18 lines · Linus Walleij

Hi Sergio,

thanks for driving this!

Quoted 3 lines · Sergio Paracuellos

The commit adds rt2880 compatible node in binding document.

(...)

Documentation/devicetree/bindings/pinctrl/ralink,rt2880-pinmux.yaml line 14

Quoted 3 lines
Documentation/devicetree/bindings/pinctrl/ralink,rt2880-pinmux.yaml new file +3 -0
+description:
+  The rt2880 pinmux can only set the muxing of pin groups. muxing indiviual pins
+  is not supported. There is no pinconf support.

OK!

Quoted 12 lines

Documentation/devicetree/bindings/pinctrl/ralink,rt2880-pinmux.yaml line 24

Quoted 9 lines
Documentation/devicetree/bindings/pinctrl/ralink,rt2880-pinmux.yaml new file +9 -0
+properties:
+  compatible:
+    enum:
+      - ralink,rt2880-pinmux
+
+  pinctrl-0:
+    description:
+      A phandle to the node containing the subnodes containing default
+      configurations.

As it is a node on the pin controller itself, this is a hog so write something about that this is for pinctrl hogs.

Ok, will do.

Quoted 7 lines

Documentation/devicetree/bindings/pinctrl/ralink,rt2880-pinmux.yaml line 29

Quoted 5 lines
Documentation/devicetree/bindings/pinctrl/ralink,rt2880-pinmux.yaml new file +4 -0
+  pinctrl-names:
+    description:
+      A pinctrl state named "default" must be defined.
+    const: default

Is it really compulsory?

Not really, I guess. The current device tree contains one so I added here because of this.

Quoted 7 lines

Documentation/devicetree/bindings/pinctrl/ralink,rt2880-pinmux.yaml line 34

Quoted 5 lines
Documentation/devicetree/bindings/pinctrl/ralink,rt2880-pinmux.yaml new file +4 -0
+required:
+  - compatible
+  - pinctrl-names
+  - pinctrl-0

I wonder if the hogs are really compulsory.

Ok, so I guess I should remove both 'pinctrl-names' and ' pinctrl-0' from the required but maintain its desciption.

Quoted 6 lines

Documentation/devicetree/bindings/pinctrl/ralink,rt2880-pinmux.yaml line 37

Quoted 3 lines
Documentation/devicetree/bindings/pinctrl/ralink,rt2880-pinmux.yaml new file +2 -0
+patternProperties:
+  '^.*$':

That's liberal node naming!
What about [a-z0-9_-]+ or something?

hahaha. Yeah, I like freedom :), but yes, you are right, I will change the pattern using the one proposed here.

Quoted 26 lines
Quoted 15 lines
Documentation/devicetree/bindings/pinctrl/ralink,rt2880-pinmux.yaml new file +14 -0
+    if:
+      type: object
+      description: |
+        A pinctrl node should contain at least one subnodes representing the
+        pinctrl groups available on the machine.
+      $ref: "pinmux-node.yaml"
+      required:
+        - groups
+        - function
+      additionalProperties: false
+    then:
+      properties:
+        groups:
+          description:

Documentation/devicetree/bindings/pinctrl/ralink,rt2880-pinmux.yaml line 61

Quoted 10 lines
Documentation/devicetree/bindings/pinctrl/ralink,rt2880-pinmux.yaml new file +10 -0
+            Name of the pin group to use for the functions.
+          $ref: "/schemas/types.yaml#/definitions/string"
+          enum: [i2c, spi, uart1, uart2, uart3, rgmii1, rgmii2, mdio,
+                 pcie, sdhci]
+        function:
+          description:
+            The mux function to select
+          $ref: "/schemas/types.yaml#/definitions/string"
+          enum: [gpio, i2c, spi, uart1, uart2, uart3, rgmii1, rgmii2,
+                 mdio, nand1, nand2, sdhci]
Quoted 1 line

Why do we have this complex if: clause?

To be honest to avoid problems with other pinctrl root nodes because they are not type 'object' and not having real idea in what way this should be achieved :).

Quoted 26 lines

$ref: "pinmux-node.yaml" should bring in the groups and function properties. Then you can add some further restrictions on top of that, right?

I would just do:

patternProperties:
'^[a-z0-9_]+$':
type: object
description: node for pinctrl
$ref "pinmux-node.yaml"

properties:
groups:
description: groups...
enum: [i2c, spi, uart1, uart2, uart3, rgmii1, rgmii2, mdio,
pcie, sdhci]

        function:
          description: function...
          enum: [gpio, i2c, spi, uart1, uart2, uart3, rgmii1, rgmii2,

mdio, nand1, nand2, sdhci]

Note: the function names are fine but the group names are a bit confusion since often a group can be used for more than one function, and e.g.

Quoted 7 lines

function = "i2c";
group = "uart1";

to use the uart1 pins for an i2c is gonna look mildly confusing.

But if this is what the hardware calls it I suppose it is fine.

This is the way is currently being used in the device tree.

Quoted 3 lines

Yours,
Linus Walleij

Thanks again. I will change this and send v2.

Best regards,
Sergio Paracuellos

#6 lore raw

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

In reply to Linus Walleij

Hi Linus,

Quoted 9 lines · Linus Walleij

Hi Serigio,

I dug around some to try to understand the patch I think I get it now :)

Squash this with the third patch so it becomes a "move" of this file, preserving history. With that:

Ok, will squash those two if you prefer that way with your 'Acked-by'.

Quoted 7 lines

I have ideas, but it is better to move the driver out of staging and improve it in pinctrl.

Since there might be many sub-SoCs for this pin controller, what about creating drivers/pinctrl/ralink/* for this at the same time?

Ok, I will put this inside a ralink subdirectory in pinctrl.

Quoted 10 lines
Quoted 6 lines · Sergio Paracuellos

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.

(...)

Quoted 9 lines

drivers/pinctrl/pinctrl-rt2880.c line 21

Quoted 3 lines
drivers/pinctrl/pinctrl-rt2880.c new file +3 -0
+#include <asm/mach-ralink/ralink_regs.h>
+#include <asm/mach-ralink/pinmux.h>
+#include <asm/mach-ralink/mt7620.h>

I think in the next step we should move the contents of rt2880_pinmux_data into this driver, then we can drop these mach-headers and show the way for the rest of the ralink chips to push their data down into this driver (or subdrivers) and depopulate mach-ralink a bit.

Agree. Doing that no arch dependencies are included and we can cleanly enable the driver also for COMPILE_TEST without adding special flags in pinctrl Makefile.

Quoted 6 lines
Quoted 2 lines

+ p->groups = rt2880_pinmux_data;

So this is where the driver actually gets a pointer to all groups and functions, and these groups and functions all come from arch/mips/ralink/mt7621.c right?

Yes, all of that is defined there.

Quoted 5 lines

I think after this first step we should move mt7621.c to pinctrl and become a subdriver for this pin controller and then we can hopefully move the rest as well once you set the pattern for how we do this.

I see. Thanks for advices.

Quoted 3 lines

Yours,
Linus Walleij

Best regards,
Sergio Paracuellos

#7 lore raw

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

In reply to Sergio Paracuellos

drivers/pinctrl/pinctrl-rt2880.c line 194

Quoted 12 lines · Sergio Paracuellos
drivers/pinctrl/pinctrl-rt2880.c new file +12 -0
+static struct pinctrl_desc rt2880_pctrl_desc = {
+	.owner		= THIS_MODULE,
+	.name		= "rt2880-pinmux",
+	.pctlops	= &rt2880_pctrl_ops,
+	.pmxops		= &rt2880_pmx_group_ops,
+};
+
+static struct rt2880_pmx_func gpio_func = {
+	.name = "gpio",
+};
+
+static int rt2880_pinmux_index(struct rt2880_priv *p)

This function name is not great. I assumed that it would return the index.

Review

Quoted 2 lines
(quoted diff) +2 -0
+{
+	struct rt2880_pmx_func **f;

Get rid of this "f" variable and use "p->func" instead.

Quoted 4 lines
drivers/pinctrl/pinctrl-rt2880.c new file +4 -0
+	struct rt2880_pmx_group *mux = p->groups;
+	int i, j, c = 0;
+
+	/* count the mux functions */

drivers/pinctrl/pinctrl-rt2880.c line 210

Quoted 10 lines
drivers/pinctrl/pinctrl-rt2880.c new file +10 -0
+	while (mux->name) {
+		p->group_count++;
+		mux++;
+	}
+
+	/* allocate the group names array needed by the gpio function */
+	p->group_names = devm_kcalloc(p->dev, p->group_count,
+				      sizeof(char *), GFP_KERNEL);
+	if (!p->group_names)
+		return -1;

Return proper error codes in this function. s/-1/-ENOMEM/

Quoted 23 lines
drivers/pinctrl/pinctrl-rt2880.c new file +23 -0
+
+	for (i = 0; i < p->group_count; i++) {
+		p->group_names[i] = p->groups[i].name;
+		p->func_count += p->groups[i].func_count;
+	}
+
+	/* we have a dummy function[0] for gpio */
+	p->func_count++;
+
+	/* allocate our function and group mapping index buffers */
+	f = p->func = devm_kcalloc(p->dev,
+				   p->func_count,
+				   sizeof(*p->func),
+				   GFP_KERNEL);
+	gpio_func.groups = devm_kcalloc(p->dev, p->group_count, sizeof(int),
+					GFP_KERNEL);
+	if (!f || !gpio_func.groups)
+		return -1;
+
+	/* add a backpointer to the function so it knows its group */
+	gpio_func.group_count = p->group_count;
+	for (i = 0; i < gpio_func.group_count; i++)
+		gpio_func.groups[i] = i;

drivers/pinctrl/pinctrl-rt2880.c line 243

Quoted 10 lines
drivers/pinctrl/pinctrl-rt2880.c new file +10 -0
+
+	f[c] = &gpio_func;
+	c++;
+
+	/* add remaining functions */
+	for (i = 0; i < p->group_count; i++) {
+		for (j = 0; j < p->groups[i].func_count; j++) {
+			f[c] = &p->groups[i].func[j];
+			f[c]->groups = devm_kzalloc(p->dev, sizeof(int),
+						    GFP_KERNEL);

Add a NULL check.

Quoted 16 lines
drivers/pinctrl/pinctrl-rt2880.c new file +16 -0
+			f[c]->groups[0] = i;
+			f[c]->group_count = 1;
+			c++;
+		}
+	}
+	return 0;
+}
+
+static int rt2880_pinmux_pins(struct rt2880_priv *p)
+{
+	int i, j;
+
+	/*
+	 * loop over the functions and initialize the pins array.
+	 * also work out the highest pin used.
+	 */

drivers/pinctrl/pinctrl-rt2880.c line 269

Quoted 10 lines
drivers/pinctrl/pinctrl-rt2880.c new file +10 -0
+	for (i = 0; i < p->func_count; i++) {
+		int pin;
+
+		if (!p->func[i]->pin_count)
+			continue;
+
+		p->func[i]->pins = devm_kcalloc(p->dev,
+						p->func[i]->pin_count,
+						sizeof(int),
+						GFP_KERNEL);

This can fit on two lines.

		p->func[i]->pins = devm_kcalloc(p->dev, p->func[i]->pin_count,
						sizeof(int), GFP_KERNEL);
Quoted 5 lines
drivers/pinctrl/pinctrl-rt2880.c new file +5 -0
+		for (j = 0; j < p->func[i]->pin_count; j++)
+			p->func[i]->pins[j] = p->func[i]->pin_first + j;
+
+		pin = p->func[i]->pin_first + p->func[i]->pin_count;
+		if (pin > p->max_pins)

drivers/pinctrl/pinctrl-rt2880.c line 284

Quoted 10 lines
drivers/pinctrl/pinctrl-rt2880.c new file +10 -0
+			p->max_pins = pin;
+	}
+
+	/* the buffer that tells us which pins are gpio */
+	p->gpio = devm_kcalloc(p->dev, p->max_pins, sizeof(u8), GFP_KERNEL);
+	/* the pads needed to tell pinctrl about our pins */
+	p->pads = devm_kcalloc(p->dev, p->max_pins,
+			       sizeof(struct pinctrl_pin_desc), GFP_KERNEL);
+	if (!p->pads || !p->gpio) {
+		dev_err(p->dev, "Failed to allocate gpio data\n");

Delete this error message. #checkpatch.pl

Quoted 10 lines
drivers/pinctrl/pinctrl-rt2880.c new file +10 -0
+		return -ENOMEM;
+	}
+
+	memset(p->gpio, 1, sizeof(u8) * p->max_pins);
+	for (i = 0; i < p->func_count; i++) {
+		if (!p->func[i]->pin_count)
+			continue;
+
+		for (j = 0; j < p->func[i]->pin_count; j++)
+			p->gpio[p->func[i]->pins[j]] = 0;

drivers/pinctrl/pinctrl-rt2880.c line 304

Quoted 10 lines
drivers/pinctrl/pinctrl-rt2880.c new file +10 -0
+	}
+
+	/* pin 0 is always a gpio */
+	p->gpio[0] = 1;
+
+	/* set the pads */
+	for (i = 0; i < p->max_pins; i++) {
+		/* strlen("ioXY") + 1 = 5 */
+		char *name = devm_kzalloc(p->dev, 5, GFP_KERNEL);
+
		char *name;

		name = kasprintf(GFP_KERNEL, "io%d", i);
Quoted 24 lines
drivers/pinctrl/pinctrl-rt2880.c new file +24 -0
+		if (!name)
+			return -ENOMEM;
+		snprintf(name, 5, "io%d", i);
+		p->pads[i].number = i;
+		p->pads[i].name = name;
+	}
+	p->desc->pins = p->pads;
+	p->desc->npins = p->max_pins;
+
+	return 0;
+}
+
+static int rt2880_pinmux_probe(struct platform_device *pdev)
+{
+	struct rt2880_priv *p;
+	struct pinctrl_dev *dev;
+
+	if (!rt2880_pinmux_data)
+		return -ENOTSUPP;
+
+	/* setup the private data */
+	p = devm_kzalloc(&pdev->dev, sizeof(struct rt2880_priv), GFP_KERNEL);
+	if (!p)
+		return -ENOMEM;

drivers/pinctrl/pinctrl-rt2880.c line 338

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

Preserve the error code:

	err = rt2880_pinmux_index(p);
	if (err) {
		dev_err(&pdev->dev, "failed to load index\n");
		return err;
	}

drivers/pinctrl/pinctrl-rt2880.c line 342

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

Same.

drivers/pinctrl/pinctrl-rt2880.c line 349

Quoted 7 lines
drivers/pinctrl/pinctrl-rt2880.c new file +7 -0
+	}
+	dev = pinctrl_register(p->desc, &pdev->dev, p);
+	if (IS_ERR(dev))
+		return PTR_ERR(dev);
+
+	return 0;
+}

regards,
dan carpenter

#8 lore raw

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

Hi Dan,

Thanks for the review.

Quoted 204 lines · Dan Carpenter

drivers/pinctrl/pinctrl-rt2880.c line 194

Quoted 12 lines · Sergio Paracuellos
drivers/pinctrl/pinctrl-rt2880.c new file +12 -0
+static struct pinctrl_desc rt2880_pctrl_desc = {
+     .owner          = THIS_MODULE,
+     .name           = "rt2880-pinmux",
+     .pctlops        = &rt2880_pctrl_ops,
+     .pmxops         = &rt2880_pmx_group_ops,
+};
+
+static struct rt2880_pmx_func gpio_func = {
+     .name = "gpio",
+};
+
+static int rt2880_pinmux_index(struct rt2880_priv *p)

This function name is not great. I assumed that it would return the index.

Review

Quoted 2 lines
(quoted diff) +2 -0
+{
+     struct rt2880_pmx_func **f;

Get rid of this "f" variable and use "p->func" instead.

Quoted 4 lines
drivers/pinctrl/pinctrl-rt2880.c new file +4 -0
+     struct rt2880_pmx_group *mux = p->groups;
+     int i, j, c = 0;
+
+     /* count the mux functions */

drivers/pinctrl/pinctrl-rt2880.c line 210

Quoted 10 lines
drivers/pinctrl/pinctrl-rt2880.c new file +10 -0
+     while (mux->name) {
+             p->group_count++;
+             mux++;
+     }
+
+     /* allocate the group names array needed by the gpio function */
+     p->group_names = devm_kcalloc(p->dev, p->group_count,
+                                   sizeof(char *), GFP_KERNEL);
+     if (!p->group_names)
+             return -1;

Return proper error codes in this function. s/-1/-ENOMEM/

Quoted 23 lines
drivers/pinctrl/pinctrl-rt2880.c new file +23 -0
+
+     for (i = 0; i < p->group_count; i++) {
+             p->group_names[i] = p->groups[i].name;
+             p->func_count += p->groups[i].func_count;
+     }
+
+     /* we have a dummy function[0] for gpio */
+     p->func_count++;
+
+     /* allocate our function and group mapping index buffers */
+     f = p->func = devm_kcalloc(p->dev,
+                                p->func_count,
+                                sizeof(*p->func),
+                                GFP_KERNEL);
+     gpio_func.groups = devm_kcalloc(p->dev, p->group_count, sizeof(int),
+                                     GFP_KERNEL);
+     if (!f || !gpio_func.groups)
+             return -1;
+
+     /* add a backpointer to the function so it knows its group */
+     gpio_func.group_count = p->group_count;
+     for (i = 0; i < gpio_func.group_count; i++)
+             gpio_func.groups[i] = i;

drivers/pinctrl/pinctrl-rt2880.c line 243

Quoted 10 lines
drivers/pinctrl/pinctrl-rt2880.c new file +10 -0
+
+     f[c] = &gpio_func;
+     c++;
+
+     /* add remaining functions */
+     for (i = 0; i < p->group_count; i++) {
+             for (j = 0; j < p->groups[i].func_count; j++) {
+                     f[c] = &p->groups[i].func[j];
+                     f[c]->groups = devm_kzalloc(p->dev, sizeof(int),
+                                                 GFP_KERNEL);

Add a NULL check.

Quoted 16 lines
drivers/pinctrl/pinctrl-rt2880.c new file +16 -0
+                     f[c]->groups[0] = i;
+                     f[c]->group_count = 1;
+                     c++;
+             }
+     }
+     return 0;
+}
+
+static int rt2880_pinmux_pins(struct rt2880_priv *p)
+{
+     int i, j;
+
+     /*
+      * loop over the functions and initialize the pins array.
+      * also work out the highest pin used.
+      */

drivers/pinctrl/pinctrl-rt2880.c line 269

Quoted 10 lines
drivers/pinctrl/pinctrl-rt2880.c new file +10 -0
+     for (i = 0; i < p->func_count; i++) {
+             int pin;
+
+             if (!p->func[i]->pin_count)
+                     continue;
+
+             p->func[i]->pins = devm_kcalloc(p->dev,
+                                             p->func[i]->pin_count,
+                                             sizeof(int),
+                                             GFP_KERNEL);

This can fit on two lines.

                p->func[i]->pins = devm_kcalloc(p->dev, p->func[i]->pin_count,
                                                sizeof(int), GFP_KERNEL);
Quoted 5 lines
drivers/pinctrl/pinctrl-rt2880.c new file +5 -0
+             for (j = 0; j < p->func[i]->pin_count; j++)
+                     p->func[i]->pins[j] = p->func[i]->pin_first + j;
+
+             pin = p->func[i]->pin_first + p->func[i]->pin_count;
+             if (pin > p->max_pins)

drivers/pinctrl/pinctrl-rt2880.c line 284

Quoted 10 lines
drivers/pinctrl/pinctrl-rt2880.c new file +10 -0
+                     p->max_pins = pin;
+     }
+
+     /* the buffer that tells us which pins are gpio */
+     p->gpio = devm_kcalloc(p->dev, p->max_pins, sizeof(u8), GFP_KERNEL);
+     /* the pads needed to tell pinctrl about our pins */
+     p->pads = devm_kcalloc(p->dev, p->max_pins,
+                            sizeof(struct pinctrl_pin_desc), GFP_KERNEL);
+     if (!p->pads || !p->gpio) {
+             dev_err(p->dev, "Failed to allocate gpio data\n");

Delete this error message. #checkpatch.pl

Quoted 10 lines
drivers/pinctrl/pinctrl-rt2880.c new file +10 -0
+             return -ENOMEM;
+     }
+
+     memset(p->gpio, 1, sizeof(u8) * p->max_pins);
+     for (i = 0; i < p->func_count; i++) {
+             if (!p->func[i]->pin_count)
+                     continue;
+
+             for (j = 0; j < p->func[i]->pin_count; j++)
+                     p->gpio[p->func[i]->pins[j]] = 0;

drivers/pinctrl/pinctrl-rt2880.c line 304

Quoted 10 lines
drivers/pinctrl/pinctrl-rt2880.c new file +10 -0
+     }
+
+     /* pin 0 is always a gpio */
+     p->gpio[0] = 1;
+
+     /* set the pads */
+     for (i = 0; i < p->max_pins; i++) {
+             /* strlen("ioXY") + 1 = 5 */
+             char *name = devm_kzalloc(p->dev, 5, GFP_KERNEL);
+
                char *name;

                name = kasprintf(GFP_KERNEL, "io%d", i);
Quoted 24 lines
drivers/pinctrl/pinctrl-rt2880.c new file +24 -0
+             if (!name)
+                     return -ENOMEM;
+             snprintf(name, 5, "io%d", i);
+             p->pads[i].number = i;
+             p->pads[i].name = name;
+     }
+     p->desc->pins = p->pads;
+     p->desc->npins = p->max_pins;
+
+     return 0;
+}
+
+static int rt2880_pinmux_probe(struct platform_device *pdev)
+{
+     struct rt2880_priv *p;
+     struct pinctrl_dev *dev;
+
+     if (!rt2880_pinmux_data)
+             return -ENOTSUPP;
+
+     /* setup the private data */
+     p = devm_kzalloc(&pdev->dev, sizeof(struct rt2880_priv), GFP_KERNEL);
+     if (!p)
+             return -ENOMEM;

drivers/pinctrl/pinctrl-rt2880.c line 338

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

Preserve the error code:

        err = rt2880_pinmux_index(p);
        if (err) {
                dev_err(&pdev->dev, "failed to load index\n");
                return err;
        }

drivers/pinctrl/pinctrl-rt2880.c line 342

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

Same.

Quoted 7 lines

drivers/pinctrl/pinctrl-rt2880.c line 349

Quoted 7 lines
drivers/pinctrl/pinctrl-rt2880.c new file +7 -0
+     }
+     dev = pinctrl_register(p->desc, &pdev->dev, p);
+     if (IS_ERR(dev))
+             return PTR_ERR(dev);
+
+     return 0;
+}

This is already applied but needs more work in its correct place afterwards. So I will take into account all of these comments and will send patches to properly address all of them.

Quoted 3 lines

regards,
dan carpenter

Thanks again.

Best regards,
Sergio Paracuellos