Skip to contentSkip to conversation

Pinctrl driver for Amlogic Meson SoCs

PATCH Superseded Beniamino Galvani 2 participants 6 messages Oct 14, 2014 – Oct 28, 2014

Subsystems (6)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover Pinctrl driver for Amlogic Meson SoCs

Hi,

this series introduces a driver for Amlogic Meson pinctrl and GPIOs, adding the basic infrastructure for all the SoCs of the Meson family and configuration data specific for Meson8.

I tested the pinmux and GPIO functionalities on a Tronsmart Vega S89e TV box and everything seems to work, however I'm not so familiar with the pinctrl subsystem and thus any feedback is very welcome.

Changes since v1 [https://lkml.org/lkml/2014/10/7/712]
- added missing checks of return values
- indentation fixes
- added missing definitions of groups and functions for Meson8

Beniamino Galvani (3):
pinctrl: add driver for Amlogic Meson SoCs
pinctrl: meson: add device tree bindings documentation
ARM: dts: meson8: add pinctrl and gpio nodes

 .../devicetree/bindings/pinctrl/meson,pinctrl.txt  |  79 ++
 arch/arm/boot/dts/meson8-vega-s89e.dts             |  16 +-
 arch/arm/boot/dts/meson8.dtsi                      |  35 +
 arch/arm/mach-meson/Kconfig                        |   3 +
 drivers/pinctrl/Kconfig                            |   8 +
 drivers/pinctrl/Makefile                           |   1 +
 drivers/pinctrl/meson/Makefile                     |   2 +
 drivers/pinctrl/meson/pinctrl-meson.c              | 824 +++++++++++++++++++++
 drivers/pinctrl/meson/pinctrl-meson.h              | 217 ++++++
 drivers/pinctrl/meson/pinctrl-meson8.c             | 534 +++++++++++++
 include/dt-bindings/gpio/meson8-gpio.h             | 155 ++++
 11 files changed, 1873 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/pinctrl/meson,pinctrl.txt
 create mode 100644 drivers/pinctrl/meson/Makefile
 create mode 100644 drivers/pinctrl/meson/pinctrl-meson.c
 create mode 100644 drivers/pinctrl/meson/pinctrl-meson.h
 create mode 100644 drivers/pinctrl/meson/pinctrl-meson8.c
 create mode 100644 include/dt-bindings/gpio/meson8-gpio.h
Signature · 1 line
1.9.1
#1 lore raw

PATCH v2 1/3 pinctrl: add driver for Amlogic Meson SoCs

This is a driver for the pinmux and GPIO controller available in Amlogic Meson SoCs. At the moment it only supports Meson8 devices, however other SoC families like Meson6 and Meson8b (the Cortex-A5 variant) appear to be similar, with just different sets of banks and registers.

GPIO interrupts are not supported at the moment due to lack of documentation.

---
 arch/arm/mach-meson/Kconfig            |   3 +
 drivers/pinctrl/Kconfig                |   8 +
 drivers/pinctrl/Makefile               |   1 +
 drivers/pinctrl/meson/Makefile         |   2 +
 drivers/pinctrl/meson/pinctrl-meson.c  | 824 +++++++++++++++++++++++++++++++++
 drivers/pinctrl/meson/pinctrl-meson.h  | 217 +++++++++
 drivers/pinctrl/meson/pinctrl-meson8.c | 534 +++++++++++++++++++++
 include/dt-bindings/gpio/meson8-gpio.h | 155 +++++++
 8 files changed, 1744 insertions(+)
 create mode 100644 drivers/pinctrl/meson/Makefile
 create mode 100644 drivers/pinctrl/meson/pinctrl-meson.c
 create mode 100644 drivers/pinctrl/meson/pinctrl-meson.h
 create mode 100644 drivers/pinctrl/meson/pinctrl-meson8.c
 create mode 100644 include/dt-bindings/gpio/meson8-gpio.h
arch/arm/mach-meson/Kconfig +3 -0
index b289e8e..7c2988d 100644
@@ -2,6 +2,9 @@ menuconfig ARCH_MESON
 	bool "Amlogic Meson SoCs" if ARCH_MULTI_V7
 	select GENERIC_IRQ_CHIP
 	select ARM_GIC
+	select PINCTRL
+	select PINCTRL_MESON
+	select ARCH_REQUIRE_GPIOLIB
 
 if ARCH_MESON
 
drivers/pinctrl/Kconfig +8 -0
index c6a66de..22b05e1 100644
@@ -108,6 +108,14 @@ config PINCTRL_FALCON
 	depends on SOC_FALCON
 	depends on PINCTRL_LANTIQ
 
+config PINCTRL_MESON
+	bool "Amlogic Meson pin controller driver"
+	depends on ARCH_MESON
+	select PINMUX
+	select PINCONF
+	select GENERIC_PINCONF
+	select OF_GPIO
+
 config PINCTRL_ROCKCHIP
 	bool
 	select PINMUX
drivers/pinctrl/Makefile +1 -0
index 51f52d3..7b22f89 100644
@@ -18,6 +18,7 @@ obj-$(CONFIG_PINCTRL_BCM2835)	+= pinctrl-bcm2835.o
 obj-$(CONFIG_PINCTRL_BAYTRAIL)	+= pinctrl-baytrail.o
 obj-$(CONFIG_PINCTRL_BCM281XX)	+= pinctrl-bcm281xx.o
 obj-$(CONFIG_PINCTRL_FALCON)	+= pinctrl-falcon.o
+obj-$(CONFIG_PINCTRL_MESON)	+= meson/
 obj-$(CONFIG_PINCTRL_PALMAS)	+= pinctrl-palmas.o
 obj-$(CONFIG_PINCTRL_ROCKCHIP)	+= pinctrl-rockchip.o
 obj-$(CONFIG_PINCTRL_SINGLE)	+= pinctrl-single.o
drivers/pinctrl/meson/Makefile new file +2 -0
new file mode 100644
index 0000000..03a90b4
@@ -0,0 +1,2 @@
+obj-y	+= pinctrl-meson.o
+obj-y	+= pinctrl-meson8.o
drivers/pinctrl/meson/pinctrl-meson.c new file +824 -0

824 lines not on this page · raw message

drivers/pinctrl/meson/pinctrl-meson.h new file +217 -0

217 lines not on this page · raw message

drivers/pinctrl/meson/pinctrl-meson8.c new file +534 -0

534 lines not on this page · raw message

include/dt-bindings/gpio/meson8-gpio.h new file +155 -0

155 lines not on this page · raw message

Signature · 1 line
1.9.1
#2 lore raw

Re: [PATCH v2 1/3] pinctrl: add driver for Amlogic Meson SoCs

Quoted 10 lines · Beniamino Galvani

This is a driver for the pinmux and GPIO controller available in Amlogic Meson SoCs. At the moment it only supports Meson8 devices, however other SoC families like Meson6 and Meson8b (the Cortex-A5 variant) appear to be similar, with just different sets of banks and registers.

GPIO interrupts are not supported at the moment due to lack of documentation.

(...)

Quoted 1 line
 arch/arm/mach-meson/Kconfig            |   3 +

Still not split off from the main patch.

drivers/pinctrl/meson/pinctrl-meson.c line 35

Quoted 3 lines
drivers/pinctrl/meson/pinctrl-meson.c new file +3 -0
+static void meson_domain_set_bit(struct meson_domain *domain,
+                                void __iomem *addr, unsigned int bit,
+                                unsigned int value)

Still not migrated to regmap MMIO.

drivers/pinctrl/meson/pinctrl-meson.c line 585

Quoted 7 lines
drivers/pinctrl/meson/pinctrl-meson.c new file +7 -0
+       /* Copy group and function definitions from domains to pinctrl */
+       pc->groups = devm_kzalloc(pc->dev, pc->num_groups *
+                                 sizeof(struct meson_pmx_group), GFP_KERNEL);
+       pc->funcs = devm_kzalloc(pc->dev, pc->num_funcs *
+                                 sizeof(struct meson_pmx_func), GFP_KERNEL);
+       if (!pc->groups || !pc->funcs)
+               return -ENOMEM;

Still lots of copying of data.

drivers/pinctrl/meson/pinctrl-meson.c line 713

Quoted 4 lines
drivers/pinctrl/meson/pinctrl-meson.c new file +4 -0
+static int meson_gpiolib_register(struct meson_pinctrl *pc)
+{
+       struct meson_domain *domain;
+       unsigned int base = 0;

No.

Quoted 4 lines
drivers/pinctrl/meson/pinctrl-meson.c new file +4 -0
+       int i, ret;
+
+       for (i = 0; i < pc->num_domains; i++) {
+               domain = &pc->domains[i];

drivers/pinctrl/meson/pinctrl-meson.c line 727

Quoted 10 lines
drivers/pinctrl/meson/pinctrl-meson.c new file +10 -0
+
+               domain->chip.label = domain->data->name;
+               domain->chip.dev = pc->dev;
+               domain->chip.request = meson_gpio_request;
+               domain->chip.free = meson_gpio_free;
+               domain->chip.direction_input = meson_gpio_direction_input;
+               domain->chip.direction_output = meson_gpio_direction_output;
+               domain->chip.get = meson_gpio_get;
+               domain->chip.set = meson_gpio_set;
+               domain->chip.base = base;

No. Set it to -1 and let the gpiolib assign some random GPIO numbers.

drivers/pinctrl/meson/pinctrl-meson.c line 733

Quoted 6 lines
drivers/pinctrl/meson/pinctrl-meson.c new file +6 -0
+               domain->chip.ngpio = domain->data->num_pins;
+               domain->chip.names = domain->data->pin_names;
+               domain->chip.can_sleep = false;
+               domain->chip.of_node = domain->of_node;
+               domain->chip.of_gpio_n_cells = 2;
+               domain->chip.of_xlate = meson_gpio_of_xlate;

Go for the generic xlate function instead.

drivers/pinctrl/meson/pinctrl-meson.c line 749

Quoted 8 lines
drivers/pinctrl/meson/pinctrl-meson.c new file +8 -0
+               domain->gpio_range.name = domain->data->name;
+               domain->gpio_range.id = i;
+               domain->gpio_range.base = base;
+               domain->gpio_range.pin_base = base;
+               domain->gpio_range.npins = domain->data->num_pins;
+               domain->gpio_range.gc = &domain->chip;
+
+               pinctrl_add_gpio_range(pc->pcdev, &domain->gpio_range);

Don't add the gpio range from the pinctrl side, add it from the gpiolib side using gpiochip_add_pin_range() instead.

drivers/pinctrl/meson/pinctrl-meson.c line 820

Quoted 5 lines
drivers/pinctrl/meson/pinctrl-meson.c new file +5 -0
+static int __init meson_pinctrl_drv_register(void)
+{
+       return platform_driver_register(&meson_pinctrl_driver);
+}
+postcore_initcall(meson_pinctrl_drv_register);

Does it have to be this early?

Quoted 14 lines

+/**
+ * struct meson_domain
+ *
+ * @reg_mux: registers for mux settings
+ * @reg_pullen: registers for pull-enable settings

+ * @reg_pull:  registers for pull settings
+ * @reg_gpio:  registers for gpio settings
+ * @mux_size:  size of mux register range (in words)
+ * @pullen_size:size of pull-enable register range
+ * @pull_size: size of pull register range
+ * @gpio_size: size of gpio register range
+ * @chip:      gpio chip associated with the domain
+ * @data;      platform data for the domain
+ * @node:      device tree node for the domain
Quoted 7 lines

+ * @gpio_range: gpio range that maps domain gpios to the pin controller
+ * @lock: spinlock for accessing domain registers
+ *
+ * A domain represents a set of banks controlled by the same set of
+ * registers. Typically there is a domain for the normal banks and
+ * another one for the Always-On bus.
+ */

Insert all the info from your previous mail.

Yours,
Linus Walleij

#3 lore raw

PATCH v2 2/3 pinctrl: meson: add device tree bindings documentation

In reply to Beniamino Galvani

Add device tree bindings documentation for Amlogic Meson pinmux and GPIO controller.

---
 .../devicetree/bindings/pinctrl/meson,pinctrl.txt  | 79 ++++++++++++++++++++++
 1 file changed, 79 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pinctrl/meson,pinctrl.txt
Documentation/devicetree/bindings/pinctrl/meson,pinctrl.txt new file +79 -0
new file mode 100644
index 0000000..6645fa6
@@ -0,0 +1,79 @@
+* Amlogic Meson pinmux controller
+
+Pins are organized in banks; all banks except AO are controlled by the
+same set of registers, while the AO bank uses a dedicated register
+range. The device tree uses sub-nodes to represent set of banks which
+share the same address space.
+
+Required properties for the root node:
+ - compatible: "amlogic,meson8-pinctrl"
+ - reg: address and size of the common registers controlling gpio irq
+   functionality
+
+Required properties for gpio sub-nodes:
+ - reg: should contain address and size for mux, pull-enable, pull and
+   gpio register sets
+ - reg-names: an array of strings describing the "reg" entries. Must
+   contain "mux", "pull" and "gpio". "pull-enable" is optional and
+   when it is missing the "pull" registers are used instead
+ - gpio-controller: identifies the node as a gpio controller
+ - #gpio-cells: must be 2
+
+Valid gpio sub-nodes name are:
+ - "banks" for the standard banks
+ - "ao-bank" for the AO bank which belong to the special always-on
+   power domain
+
+Required properties for configuration nodes:
+ - pins: the name of a pin group. The list of all available groups can
+   be found in driver sources.
+ - function: the name of a function to activate for the specified set
+   of groups. The list of all available functions can be found in
+   driver sources.
+
+Example:
+
+	pinctrl: pinctrl at c1109880 {
+		compatible = "amlogic,meson8-pinctrl";
+		reg = <0xc1109880 0x10>;
+		#address-cells = <1>;
+		#size-cells = <1>;
+		ranges;
+
+		gpio: banks at c11080b0 {
+			reg = <0xc11080b0 0x28>,
+			      <0xc11080e4 0x18>,
+			      <0xc1108120 0x18>,
+			      <0xc1108030 0x30>;
+			reg-names = "mux", "pull-enable", "pull", "gpio";
+			gpio-controller;
+			#gpio-cells = <2>;
+               };
+
+		gpio_ao: ao-bank at c1108030 {
+			reg = <0xc8100014 0x4>,
+			      <0xc810002c 0x4>,
+			      <0xc8100024 0x8>;
+			reg-names = "mux", "pull", "gpio";
+			gpio-controller;
+			#gpio-cells = <2>;
+		};
+
+		nand {
+			nand {
+				pins = "nand_io", "nand_io_ce0", "nand_io_ce1",
+				       "nand_io_rb0", "nand_ale", "nand_cle",
+				       "nand_wen_clk", "nand_ren_clk", "nand_dqs",
+				       "nand_ce2", "nand_ce3";
+				function = "nand";
+			};
+		};
+
+		uart_ao_a: uart_ao_a {
+			uart_ao_a {
+				pins = "uart_tx_ao_a", "uart_rx_ao_a";
+				       "uart_cts_ao_a", "uart_rts_ao_a";
+				function = "uart_ao";
+			};
+		};
+	};
Signature · 1 line
1.9.1
#4 lore raw

Re: [PATCH v2 2/3] pinctrl: meson: add device tree bindings documentation

Quoted 4 lines · Beniamino Galvani

Add device tree bindings documentation for Amlogic Meson pinmux and GPIO controller.

(...)

Documentation/devicetree/bindings/pinctrl/meson,pinctrl.txt line 56

Quoted 4 lines
Documentation/devicetree/bindings/pinctrl/meson,pinctrl.txt new file +4 -0
+               gpio_ao: ao-bank at c1108030 {
+                       reg = <0xc8100014 0x4>,
+                             <0xc810002c 0x4>,
+                             <0xc8100024 0x8>;

This still has the same problem as in the previous review.

It seems for both patches you posted v2 before I got to review v1, so sorry for the confusion.

Please take the combined result of my review letters and fix everything...

Yours,
Linus Walleij

#5 lore raw

PATCH v2 3/3 ARM: dts: meson8: add pinctrl and gpio nodes

In reply to Beniamino Galvani

Add pinctrl node to meson8.dtsi and gpio-leds node to meson8-vega-s89e.dts

---
 arch/arm/boot/dts/meson8-vega-s89e.dts | 16 +++++++++++++++-
 arch/arm/boot/dts/meson8.dtsi          | 35 ++++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+), 1 deletion(-)
arch/arm/boot/dts/meson8-vega-s89e.dts +15 -1
index 950998f..70a05c1 100644
@@ -45,7 +45,9 @@
 
 
 /dts-v1/;
-/include/ "meson8.dtsi"
+#include "meson8.dtsi"
+#include <dt-bindings/gpio/gpio.h>
+#include <dt-bindings/gpio/meson8-gpio.h>
 
 / {
 	model = "Tronsmart Vega S89 Elite";
@@ -58,8 +60,20 @@
 	memory {
 		reg = <0x40000000 0x80000000>;
 	};
+
+	gpio-leds {
+		compatible = "gpio-leds";
+
+		power {
+			gpios = <&gpio_ao GPIO_TEST_N GPIO_ACTIVE_LOW>;
+			linux,default-trigger = "none";
+		};
+	};
+
 };
 
 &uart_AO {
 	status = "okay";
+	pinctrl-names = "default";
+	pinctrl-0 = <&uart_ao_a>;
 };
arch/arm/boot/dts/meson8.dtsi +35 -0
index 42e4026..c82f597 100644
@@ -85,4 +85,39 @@
 		compatible = "fixed-clock";
 		clock-frequency = <141666666>;
 	};
+
+	pinctrl: pinctrl at c1109880 {
+		compatible = "amlogic,meson8-pinctrl";
+		reg = <0xc1109880 0x10>;
+		#address-cells = <1>;
+		#size-cells = <1>;
+		ranges;
+
+		gpio: banks at c11080b0 {
+			reg = <0xc11080b0 0x28>,
+			      <0xc11080e4 0x18>,
+			      <0xc1108120 0x18>,
+			      <0xc1108030 0x30>;
+			reg-names = "mux", "pull-enable", "pull", "gpio";
+			gpio-controller;
+			#gpio-cells = <2>;
+		};
+
+		gpio_ao: ao-bank at c1108030 {
+			reg = <0xc8100014 0x4>,
+			      <0xc810002c 0x4>,
+			      <0xc8100024 0x8>;
+			reg-names = "mux", "pull", "gpio";
+			gpio-controller;
+			#gpio-cells = <2>;
+		};
+
+		uart_ao_a: uart_ao_a {
+			uart_ao_a {
+				pins = "uart_tx_ao_a", "uart_rx_ao_a";
+				function = "uart_ao";
+			};
+		};
+	};
+
 }; /* end of / */
Signature · 1 line
1.9.1