Skip to contentSkip to conversation

pinctrl: ADI PIN control driver for the GPIO controller on bf54x and bf60x.

PATCH Superseded Sonic Zhang 3 participants 20 messages Aug 21, 2013 – Aug 30, 2013 Pin control

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/3 pinctrl: ADI PIN control driver for the GPIO controller on bf54x and bf60x.

From: Sonic Zhang <[email protected]>

The new ADI GPIO2 controller was introduced since the BF548 and BF60x processors. It differs a lot from the old one on BF5xx processors. So, create a pinctrl driver under the pinctrl framework.

- Define gpio ports and pin interrupt controllers as individual platform devices.
- Register a pinctrl driver for the whole GPIO ports and pin interrupt devices.
- Probe pint devices before port devices. Put device instances into the global gpio and pint lists.
- Define peripheral, irq and gpio reservation bit masks for each gpio port as runtime resources.
- Save and restore gpio port and pint status MMRs in syscore PM functions.
- Create the plug-in subdrivers to hold the pinctrl soc data for bf54x and bf60x. Add soc data into struct adi_pinctrl. Initialize the soc data in pin controller probe function. Get the pin groups and functions via the soc data reference.
- Call gpiochip_add_pin_range() in gpio device probe function to register range cross reference between gpio device and pin control device.
- Get range by pinctrl_find_gpio_range_from_pin(), find gpio_port object by container_of() and find adi_pinctrl by pin control device name.
- Handle peripheral and gpio requests in pinctrl operation functions.
- Demux gpio IRQs via the irq_domain created by each GPIO port.

---
v2-changes:
- Remove unlinke() directive.

v3-changes:
- Rename struct adi_pmx to adi_pinctrl.
- Fix the comments of struct gpio_pint.
- Remove unused pin_base in struct gpio_port.
- Change pint_assign into bool type.
- Add comments about the relationship between pint device and port device to the driver header.
- Use BIT macro to shift bit.
- Remove all bitmap reservation help functions. Inline reservation functions into the actual code.
- Remove gpio and offset mutual reference help functions.
- Remove all help functions to find gpio_port and adi_pinctrl structs. Get range by pinctrl_find_gpio_range_from_pin(), find gpio_port object by container_of() and find adi_pinctrl by pin control device name.
- Pass bool type usage variable to port_setup help function.
- Separate long bit operations into several lines and add comments.
- Use debugfs to output all GPIO request information.
- Avoid to set drvdata to NULL
- Add explanation to function adi_gpio_init_int()
- Call gpiochip_add_pin_range() in gpio device probe function to register range cross reference between gpio device and pin control device.
- Remove the reference to pin control device from the gpio_port struct. Remove the reference list to gpio device from the adi_pinctrl struct. Replace the global adi_pinctrl list with adi_gpio_port_list. Walk through the gpio list to do power suspend and resume operations.
- Remove the global GPIO base from struct adi_pinctrl, define pin base in the platform data for each GPIO port device.
- Initialize adi_pinctrl_setup in arch_initcall().
- print the status of triggers, whether it is in GPIO mode, if it is flagged to be used as IRQ, etc in adi_pin_dbg_show().
- Create the plug-in subdrivers to hold the pinctrl soc data for bf54x and bf60x. Add soc data into struct adi_pinctrl. Initialize the soc data in pin controller probe function. Get the pin groups and functions via the soc data reference.

---
 drivers/pinctrl/Kconfig                    |   17 +
 drivers/pinctrl/Makefile                   |    3 +
 drivers/pinctrl/pinctrl-adi2-bf54x.c       |  572 +++++++++++
 drivers/pinctrl/pinctrl-adi2-bf60x.c       |  454 +++++++++
 drivers/pinctrl/pinctrl-adi2.c             | 1501 ++++++++++++++++++++++++++++
 drivers/pinctrl/pinctrl-adi2.h             |   75 ++
 include/linux/platform_data/pinctrl-adi2.h |   40 +
 7 files changed, 2662 insertions(+)
 create mode 100644 drivers/pinctrl/pinctrl-adi2-bf54x.c
 create mode 100644 drivers/pinctrl/pinctrl-adi2-bf60x.c
 create mode 100644 drivers/pinctrl/pinctrl-adi2.c
 create mode 100644 drivers/pinctrl/pinctrl-adi2.h
 create mode 100644 include/linux/platform_data/pinctrl-adi2.h
drivers/pinctrl/Kconfig +17 -0
index 8f66924..08b8337 100644
@@ -49,6 +49,23 @@ config PINCTRL_AB8505
 	bool "AB8505 pin controller driver"
 	depends on PINCTRL_ABX500 && ARCH_U8500
 
+config PINCTRL_ADI2
+	bool "ADI pin controller driver"
+	select PINMUX
+	select IRQ_DOMAIN
+	help
+	  This is the pin controller and gpio driver for ADI BF54x, BF60x and
+	  future processors. This option is selected automatically when specific
+	  machine and arch are selected to build.
+
+config PINCTRL_BF54x
+	def_bool y if BF54x
+	select PINCTRL_ADI2
+
+config PINCTRL_BF60x
+	def_bool y if BF60x
+	select PINCTRL_ADI2
+
 config PINCTRL_AT91
 	bool "AT91 pinctrl driver"
 	depends on OF
drivers/pinctrl/Makefile +3 -0
index 9bdaeb8..4701180 100644
@@ -14,6 +14,9 @@ obj-$(CONFIG_PINCTRL_AB8500)	+= pinctrl-ab8500.o
 obj-$(CONFIG_PINCTRL_AB8540)	+= pinctrl-ab8540.o
 obj-$(CONFIG_PINCTRL_AB9540)	+= pinctrl-ab9540.o
 obj-$(CONFIG_PINCTRL_AB8505)	+= pinctrl-ab8505.o
+obj-$(CONFIG_PINCTRL_ADI2)	+= pinctrl-adi2.o
+obj-$(CONFIG_PINCTRL_BF54x)	+= pinctrl-adi2-bf54x.o
+obj-$(CONFIG_PINCTRL_BF60x)	+= pinctrl-adi2-bf60x.o
 obj-$(CONFIG_PINCTRL_AT91)	+= pinctrl-at91.o
 obj-$(CONFIG_PINCTRL_BCM2835)	+= pinctrl-bcm2835.o
 obj-$(CONFIG_PINCTRL_IMX)	+= pinctrl-imx.o
drivers/pinctrl/pinctrl-adi2-bf54x.c new file +572 -0

572 lines not on this page · raw message

drivers/pinctrl/pinctrl-adi2-bf60x.c new file +454 -0

454 lines not on this page · raw message

drivers/pinctrl/pinctrl-adi2.c new file +1501 -0

1,501 lines not on this page · raw message

drivers/pinctrl/pinctrl-adi2.h new file +75 -0

75 lines not on this page · raw message

include/linux/platform_data/pinctrl-adi2.h new file +40 -0
new file mode 100644
index 0000000..8f91300
@@ -0,0 +1,40 @@
+/*
+ * Pinctrl Driver for ADI GPIO2 controller
+ *
+ * Copyright 2007-2013 Analog Devices Inc.
+ *
+ * Licensed under the GPLv2 or later
+ */
+
+
+#ifndef PINCTRL_ADI2_H
+#define PINCTRL_ADI2_H
+
+#include <linux/io.h>
+#include <linux/platform_device.h>
+
+/**
+ * struct adi_pinctrl_gpio_platform_data - Pinctrl gpio platform data
+ * for ADI GPIO2 device.
+ *
+ * @port_gpio_base: Optional global GPIO index of the GPIO bank.
+ *                 0 means driver decides.
+ * @port_pin_base: Pin index of the pin controller device.
+ * @port_width: PIN number of the GPIO bank device
+ * @pint_id: GPIO PINT device id that this GPIO bank should map to.
+ * @pint_assign: The 32-bit GPIO PINT registers can be divided into 2 parts. A
+ *               GPIO bank can be mapped into either low 16 bits[0] or high 16
+ *               bits[1] of each PINT register.
+ * @pint_map: GIOP bank mapping code in PINT device
+ */
+struct adi_pinctrl_gpio_platform_data {
+	unsigned int port_gpio_base;
+	unsigned int port_pin_base;
+	unsigned int port_width;
+	u8 pinctrl_id;
+	u8 pint_id;
+	bool pint_assign;
+	u8 pint_map;
+};
+
+#endif
Signature · 1 line
1.8.2.3
#1 lore raw

PATCH v3 2/3 blackfin: gpio: Remove none gpio lib code.

From: Sonic Zhang <[email protected]>

- Remove non gpio lib code from blackfin architecture.
- Limit the lagecy blackfin gpio driver to bf5xx processors only.
- Remove unused definition of the pint power functions.

---
 arch/blackfin/Kconfig            |   7 ++
 arch/blackfin/include/asm/gpio.h | 157 +++++----------------------------------
 arch/blackfin/kernel/Makefile    |   3 +-
 3 files changed, 29 insertions(+), 138 deletions(-)
arch/blackfin/Kconfig +7 -0
index a117652..9eff25b 100644
@@ -52,6 +52,9 @@ config GENERIC_BUG
 config ZONE_DMA
 	def_bool y
 
+config GENERIC_GPIO
+	def_bool y
+
 config FORCE_MAX_ZONEORDER
 	int
 	default "14"
@@ -317,6 +320,10 @@ config BF53x
 	depends on (BF531 || BF532 || BF533 || BF534 || BF536 || BF537)
 	default y
 
+config GPIO_ADI
+	def_bool y
+	depends on (BF51x || BF52x || BF53x || BF538 || BF539 || BF561)
+
 config MEM_MT48LC64M4A2FB_7E
 	bool
 	depends on (BFIN533_STAMP)
arch/blackfin/include/asm/gpio.h +20 -137

223 lines not on this page · raw message

arch/blackfin/kernel/Makefile +2 -1
index 735f24e..703dc7c 100644
@@ -7,7 +7,7 @@ extra-y := vmlinux.lds
 obj-y := \
 	entry.o process.o bfin_ksyms.o ptrace.o setup.o signal.o \
 	sys_bfin.o traps.o irqchip.o dma-mapping.o flat.o \
-	fixed_code.o reboot.o bfin_gpio.o bfin_dma.o \
+	fixed_code.o reboot.o bfin_dma.o \
 	exception.o dumpstack.o
 
 ifeq ($(CONFIG_GENERIC_CLOCKEVENTS),y)
@@ -16,6 +16,7 @@ else
     obj-y += time.o
 endif
 
+obj-$(CONFIG_GPIO_ADI)               += bfin_gpio.o
 obj-$(CONFIG_DYNAMIC_FTRACE)         += ftrace.o
 obj-$(CONFIG_FUNCTION_TRACER)        += ftrace-entry.o
 obj-$(CONFIG_FUNCTION_GRAPH_TRACER)  += ftrace.o
Signature · 1 line
1.8.2.3
#2 lore raw

PATCH v3 3/3 blackfin: pinctrl-adi2: Enable PINCTRL framework for BF54x and BF60x.

In reply to Sonic Zhang

From: Sonic Zhang <[email protected]>

- Remove unused macro MAX_RESOURCES
- Override blackfin legacy peripheral pinmux request and free APIs by devm_pinctrl_get_select_default() to init the peripheral portmux setting.

v2-chagnes:
- Move pinctrl soc data out of blackfin arch folder.

---
 arch/blackfin/Kconfig                           |  4 ++++
 arch/blackfin/include/asm/portmux.h             | 19 +++++++++++++++++--
 arch/blackfin/mach-bf548/include/mach/portmux.h |  2 --
 arch/blackfin/mach-bf609/include/mach/portmux.h |  2 --
 4 files changed, 21 insertions(+), 6 deletions(-)
arch/blackfin/Kconfig +4 -0
index 9eff25b..ed7157f 100644
@@ -324,6 +324,10 @@ config GPIO_ADI
 	def_bool y
 	depends on (BF51x || BF52x || BF53x || BF538 || BF539 || BF561)
 
+config PINCTRL
+	def_bool y
+	depends on BF54x || BF60x
+
 config MEM_MT48LC64M4A2FB_7E
 	bool
 	depends on (BFIN533_STAMP)
arch/blackfin/include/asm/portmux.h +17 -2
index 9b1e2c3..7aa2043 100644
@@ -17,14 +17,29 @@
 #define P_MAYSHARE	0x2000
 #define P_DONTCARE	0x1000
 
-
+#ifdef CONFIG_PINCTRL
+#include <asm/irq_handler.h>
+
+#define gpio_pint_regs bfin_pint_regs
+#define adi_internal_set_wake bfin_internal_set_wake
+
+#define peripheral_request(per, label) 0
+#define peripheral_free(per)
+#define peripheral_request_list(per, label) \
+	(pdev ? (IS_ERR(devm_pinctrl_get_select_default(&pdev->dev)) \
+	? -EINVAL : 0) : 0)
+#define peripheral_free_list(per)
+#else
 int peripheral_request(unsigned short per, const char *label);
 void peripheral_free(unsigned short per);
 int peripheral_request_list(const unsigned short per[], const char *label);
 void peripheral_free_list(const unsigned short per[]);
+#endif
 
-#include <asm/gpio.h>
+#include <linux/err.h>
+#include <linux/pinctrl/pinctrl.h>
 #include <mach/portmux.h>
+#include <linux/gpio.h>
 
 #ifndef P_SPORT2_TFS
 #define P_SPORT2_TFS P_UNDEF
arch/blackfin/mach-bf548/include/mach/portmux.h +0 -2
index e222462..d9f8632 100644
@@ -7,8 +7,6 @@
 #ifndef _MACH_PORTMUX_H_
 #define _MACH_PORTMUX_H_
 
-#define MAX_RESOURCES	MAX_BLACKFIN_GPIOS
-
 #define P_SPORT2_TFS	(P_DEFINED | P_IDENT(GPIO_PA0) | P_FUNCT(0))
 #define P_SPORT2_DTSEC	(P_DEFINED | P_IDENT(GPIO_PA1) | P_FUNCT(0))
 #define P_SPORT2_DTPRI	(P_DEFINED | P_IDENT(GPIO_PA2) | P_FUNCT(0))
arch/blackfin/mach-bf609/include/mach/portmux.h +0 -2
index 2e1a51c..fe34191 100644
@@ -7,8 +7,6 @@
 #ifndef _MACH_PORTMUX_H_
 #define _MACH_PORTMUX_H_
 
-#define MAX_RESOURCES	MAX_BLACKFIN_GPIOS
-
 /* EMAC RMII Port Mux */
 #define P_MII0_MDC	(P_DEFINED | P_IDENT(GPIO_PC6) | P_FUNCT(0))
 #define P_MII0_MDIO	(P_DEFINED | P_IDENT(GPIO_PC7) | P_FUNCT(0))
Signature · 1 line
1.8.2.3
#3 lore raw
In reply to Sonic Zhang
Quoted 10 lines · Sonic Zhang

From: Sonic Zhang <[email protected]>

The new ADI GPIO2 controller was introduced since the BF548 and BF60x processors. It differs a lot from the old one on BF5xx processors. So, create a pinctrl driver under the pinctrl framework.

 drivers/pinctrl/Kconfig                    |   17 +
 drivers/pinctrl/Makefile                   |    3 +
 drivers/pinctrl/pinctrl-adi2-bf54x.c       |  572 +++++++++++
 drivers/pinctrl/pinctrl-adi2-bf60x.c       |  454 +++++++++

Those files look reasonable.

Quoted 11 lines
 drivers/pinctrl/pinctrl-adi2.c             | 1501 ++++++++++++++++++++++++++++
 drivers/pinctrl/pinctrl-adi2.h             |   75 ++
 include/linux/platform_data/pinctrl-adi2.h |   40 +
drivers/pinctrl/pinctrl-adi2.c +5 -0
 
+/**
+ * struct gpio_reserve_map - a GPIO map structure containing the
+ * reservation status of each PIN.
+ *
+ * @owner: who request the reservation

drivers/pinctrl/pinctrl-adi2.c line 89

Quoted 10 lines
drivers/pinctrl/pinctrl-adi2.c +10 -0
+ * @rsv_gpio: if this pin is reserved as GPIO
+ * @rsv_int: if this pin is reserved as interrupt
+ * @rsv_peri: if this pin is reserved as part of a peripheral device
+ */
+struct gpio_reserve_map {
+	unsigned char owner[RESOURCE_LABEL_SIZE];
+	bool rsv_gpio;
+	bool rsv_int;
+	bool rsv_peri;
+};

Why is that needed; don't the pinctrl/GPIO cores already know which pinctrl pins and which GPIOs are used, and for what?

drivers/pinctrl/pinctrl-adi2.c line 654

Quoted 3 lines
drivers/pinctrl/pinctrl-adi2.c +2 -0
+#if defined(CONFIG_DEBUG_FS)
+static inline unsigned short get_gpio_dir(struct gpio_port *port,
...

Why aren't the existing GPIO/pinctrl subsystem debugfs files enough?

Quoted 1 line

+static int adi_pinmux_request(struct pinctrl_dev *pctldev, unsigned pin)

...

drivers/pinctrl/pinctrl-adi2.c line 797

Quoted 12 lines
drivers/pinctrl/pinctrl-adi2.c +12 -0
+	/* If a pin can be muxed as either GPIO or peripheral, make
+	 * sure it is not already a GPIO pin when we request it.
+	 */
+	if (port->rsvmap[offset].rsv_gpio) {
+		if (system_state == SYSTEM_BOOTING)
+			dump_stack();
+		dev_err(pctldev->dev,
+		       "%s: Peripheral PIN %d is already reserved as GPIO by %s!\n",
+		       __func__, pin, get_label(port, offset));
+		spin_unlock_irqrestore(&port->lock, flags);
+		return -EBUSY;
+	}

Yes, this definitely warrants some more explanation. It looks odd. What is "system_state"?

Quoted 1 line

+static int adi_gpio_probe(struct platform_device *pdev)

...

drivers/pinctrl/pinctrl-adi2.c line 1371

Quoted 6 lines
drivers/pinctrl/pinctrl-adi2.c +6 -0
+	/* Add gpio pin range */
+	snprintf(pinctrl_devname, RESOURCE_LABEL_SIZE, "pinctrl-adi2.%d",
+		pdata->pinctrl_id);
+	pinctrl_devname[RESOURCE_LABEL_SIZE - 1] = 0;
+	ret = gpiochip_add_pin_range(&port->chip, pinctrl_devname,
+		0, pdata->port_pin_base, port->width);

This looks like platform data is providing the GPIO <-> pinctrl pin ID mapping, or at least part of it. Surely that mapping is fixed by the HW design, and hence isn't something platform data should influence. Do the files pinctrl-adi2-bf*.c not contain complete information about each HW configuration for some reason?

Quoted 13 lines
drivers/pinctrl/pinctrl-adi2.c +13 -0
+static struct platform_driver adi_pinctrl_driver = {
+	.probe		= adi_pinctrl_probe,
+	.remove		= adi_pinctrl_remove,
+	.driver		= {
+		.name	= DRIVER_NAME,
+	},
+};
+
+static struct platform_driver adi_gpio_pint_driver = {
+	.probe		= adi_gpio_pint_probe,
+	.remove		= adi_gpio_pint_remove,
+	.driver		= {
+		.name	= "adi-gpio-pint",

drivers/pinctrl/pinctrl-adi2.c line 1468

Quoted 10 lines
drivers/pinctrl/pinctrl-adi2.c +10 -0
+	},
+};
+
+static struct platform_driver adi_gpio_driver = {
+	.probe		= adi_gpio_probe,
+	.remove		= adi_gpio_remove,
+	.driver		= {
+		.name	= "adi-gpio",
+	},
+};

Hmmm. Is there one HW block that controls GPIOs and pinctrl, or are there separate HW blocks?

If there's one HW block, why not have just one driver?

If there are separate HW blocks, then having separate GPIO and pinctrl drivers seems like it would make sense.

#4 lore raw

Hi Stephen,

Quoted 30 lines · Stephen Warren
Quoted 10 lines · Sonic Zhang

From: Sonic Zhang <[email protected]>

The new ADI GPIO2 controller was introduced since the BF548 and BF60x processors. It differs a lot from the old one on BF5xx processors. So, create a pinctrl driver under the pinctrl framework.

 drivers/pinctrl/Kconfig                    |   17 +
 drivers/pinctrl/Makefile                   |    3 +
 drivers/pinctrl/pinctrl-adi2-bf54x.c       |  572 +++++++++++
 drivers/pinctrl/pinctrl-adi2-bf60x.c       |  454 +++++++++

Those files look reasonable.

Quoted 16 lines
 drivers/pinctrl/pinctrl-adi2.c             | 1501 ++++++++++++++++++++++++++++
 drivers/pinctrl/pinctrl-adi2.h             |   75 ++
 include/linux/platform_data/pinctrl-adi2.h |   40 +
drivers/pinctrl/pinctrl-adi2.c +10 -0
 
+/**
+ * struct gpio_reserve_map - a GPIO map structure containing the
+ * reservation status of each PIN.
+ *
+ * @owner: who request the reservation
+ * @rsv_gpio: if this pin is reserved as GPIO
+ * @rsv_int: if this pin is reserved as interrupt
+ * @rsv_peri: if this pin is reserved as part of a peripheral device
+ */
+struct gpio_reserve_map {
Quoted 8 lines

drivers/pinctrl/pinctrl-adi2.c line 89

Quoted 5 lines
drivers/pinctrl/pinctrl-adi2.c +5 -0
+     unsigned char owner[RESOURCE_LABEL_SIZE];
+     bool rsv_gpio;
+     bool rsv_int;
+     bool rsv_peri;
+};

Why is that needed; don't the pinctrl/GPIO cores already know which pinctrl pins and which GPIOs are used, and for what?

The interrupt pin is requested and reserved in irq_chip operation irq_set_type() other than gpio_request(). In Blackfin, one gpio pin is allowed to be set up as both gpio interrupt and gpio input concurrently. So, we need bits to differentiate them.

Quoted 7 lines

drivers/pinctrl/pinctrl-adi2.c line 654

Quoted 4 lines
drivers/pinctrl/pinctrl-adi2.c +2 -0
+#if defined(CONFIG_DEBUG_FS)
+static inline unsigned short get_gpio_dir(struct gpio_port *port,
...

Why aren't the existing GPIO/pinctrl subsystem debugfs files enough?

Yes, I do use the existing subsystem debugfs file.

port->chip.dbg_show = adi_gpio_dbg_show;

root:/> cat /sys/kernel/debug/gpio
GPIOs 0-15, adi-gpio:

GPIO_0:         physmap-flash.0                 Peripheral
GPIO_1:         physmap-flash.0                 Peripheral
GPIO_2:         physmap-flash.0                 Peripheral
GPIO_3:         physmap-flash.0                 Peripheral
GPIO_4:         physmap-flash.0                 Peripheral

......

Quoted 15 lines
Quoted 1 line

+static int adi_pinmux_request(struct pinctrl_dev *pctldev, unsigned pin)

...

drivers/pinctrl/pinctrl-adi2.c line 797

Quoted 12 lines
drivers/pinctrl/pinctrl-adi2.c +12 -0
+     /* If a pin can be muxed as either GPIO or peripheral, make
+      * sure it is not already a GPIO pin when we request it.
+      */
+     if (port->rsvmap[offset].rsv_gpio) {
+             if (system_state == SYSTEM_BOOTING)
+                     dump_stack();
+             dev_err(pctldev->dev,
+                    "%s: Peripheral PIN %d is already reserved as GPIO by %s!\n",
+                    __func__, pin, get_label(port, offset));
+             spin_unlock_irqrestore(&port->lock, flags);
+             return -EBUSY;
+     }
Quoted 3 lines

Yes, this definitely warrants some more explanation. It looks odd. What is "system_state"?

The system_state checking, which is from the legacy bf5xx gpio driver, is to warn if any peripheral pin is requested before the kernel_init is executed. It seems this is not necessary under the pinctrl framework. I will remove all these checking.

Quoted 9 lines
Quoted 1 line

+static int adi_gpio_probe(struct platform_device *pdev)

...

drivers/pinctrl/pinctrl-adi2.c line 1371

Quoted 6 lines
drivers/pinctrl/pinctrl-adi2.c +6 -0
+     /* Add gpio pin range */
+     snprintf(pinctrl_devname, RESOURCE_LABEL_SIZE, "pinctrl-adi2.%d",
+             pdata->pinctrl_id);
+     pinctrl_devname[RESOURCE_LABEL_SIZE - 1] = 0;
+     ret = gpiochip_add_pin_range(&port->chip, pinctrl_devname,
+             0, pdata->port_pin_base, port->width);
Quoted 5 lines

This looks like platform data is providing the GPIO <-> pinctrl pin ID mapping, or at least part of it. Surely that mapping is fixed by the HW design, and hence isn't something platform data should influence. Do the files pinctrl-adi2-bf*.c not contain complete information about each HW configuration for some reason?

Is it possible that 2 and more pinctrl devices are on the same SoC? Or do we always assume there is only one pinctrl device on one SoC? The pinctrl_id field in platform data is to make the driver flexible for future SoCs. If the later case is true, I can just fix the pinctrl device name to "pinctrl-adi2.0".

The GPIO device's HW regsiter base, pin base, pin number and the relationship with the PINT device are defined in the platform data.

Quoted 28 lines
Quoted 14 lines
drivers/pinctrl/pinctrl-adi2.c +13 -0
+static struct platform_driver adi_pinctrl_driver = {
+     .probe          = adi_pinctrl_probe,
+     .remove         = adi_pinctrl_remove,
+     .driver         = {
+             .name   = DRIVER_NAME,
+     },
+};
+
+static struct platform_driver adi_gpio_pint_driver = {
+     .probe          = adi_gpio_pint_probe,
+     .remove         = adi_gpio_pint_remove,
+     .driver         = {
+             .name   = "adi-gpio-pint",

drivers/pinctrl/pinctrl-adi2.c line 1468

Quoted 10 lines
drivers/pinctrl/pinctrl-adi2.c +10 -0
+     },
+};
+
+static struct platform_driver adi_gpio_driver = {
+     .probe          = adi_gpio_probe,
+     .remove         = adi_gpio_remove,
+     .driver         = {
+             .name   = "adi-gpio",
+     },
+};

Hmmm. Is there one HW block that controls GPIOs and pinctrl, or are there separate HW blocks?

Quoted 4 lines

If there's one HW block, why not have just one driver?

If there are separate HW blocks, then having separate GPIO and pinctrl drivers seems like it would make sense.

There are 6 to 9 GPIO HW blocks in one Blackfin SoC. Function pinmux_enable_setting() in current pinctrl framework assumes the function mux setting of one peripheral pin group is configured in one pinctrl device. But, the function mux setting of one blackfin peripheral may be done among different GPIO HW blocks. So, I have to separate the pinctrl driver from the GPIO block driver add the ranges of all GPIO blocks into one pinctrl device for Blackfin.

Regards,

Sonic

#5 lore raw
Quoted 42 lines · Sonic Zhang

Hi Stephen,

Quoted 30 lines · Stephen Warren
Quoted 10 lines · Sonic Zhang

From: Sonic Zhang <[email protected]>

The new ADI GPIO2 controller was introduced since the BF548 and BF60x processors. It differs a lot from the old one on BF5xx processors. So, create a pinctrl driver under the pinctrl framework.

 drivers/pinctrl/Kconfig                    |   17 +
 drivers/pinctrl/Makefile                   |    3 +
 drivers/pinctrl/pinctrl-adi2-bf54x.c       |  572 +++++++++++
 drivers/pinctrl/pinctrl-adi2-bf60x.c       |  454 +++++++++

Those files look reasonable.

Quoted 16 lines
 drivers/pinctrl/pinctrl-adi2.c             | 1501 ++++++++++++++++++++++++++++
 drivers/pinctrl/pinctrl-adi2.h             |   75 ++
 include/linux/platform_data/pinctrl-adi2.h |   40 +
drivers/pinctrl/pinctrl-adi2.c +10 -0
 
+/**
+ * struct gpio_reserve_map - a GPIO map structure containing the
+ * reservation status of each PIN.
+ *
+ * @owner: who request the reservation
+ * @rsv_gpio: if this pin is reserved as GPIO
+ * @rsv_int: if this pin is reserved as interrupt
+ * @rsv_peri: if this pin is reserved as part of a peripheral device
+ */
+struct gpio_reserve_map {
Quoted 8 lines

drivers/pinctrl/pinctrl-adi2.c line 89

Quoted 5 lines
drivers/pinctrl/pinctrl-adi2.c +5 -0
+     unsigned char owner[RESOURCE_LABEL_SIZE];
+     bool rsv_gpio;
+     bool rsv_int;
+     bool rsv_peri;
+};

Why is that needed; don't the pinctrl/GPIO cores already know which pinctrl pins and which GPIOs are used, and for what?

Quoted 4 lines

The interrupt pin is requested and reserved in irq_chip operation irq_set_type() other than gpio_request(). In Blackfin, one gpio pin is allowed to be set up as both gpio interrupt and gpio input concurrently. So, we need bits to differentiate them.

Does the HW need to be programmed differently in those cases?

If not, I still don't see why the driver cares; if the HW allows both usages concurrently, there's nothing to check and hence no need to record any state.

If the HW must be programmed differently, can't you read the current state out of the HW?

Quoted 9 lines
Quoted 9 lines
Quoted 1 line

+static int adi_gpio_probe(struct platform_device *pdev)

...

Quoted 6 lines
drivers/pinctrl/pinctrl-adi2.c +6 -0
+     /* Add gpio pin range */
+     snprintf(pinctrl_devname, RESOURCE_LABEL_SIZE, "pinctrl-adi2.%d",
+             pdata->pinctrl_id);
+     pinctrl_devname[RESOURCE_LABEL_SIZE - 1] = 0;
+     ret = gpiochip_add_pin_range(&port->chip, pinctrl_devname,
+             0, pdata->port_pin_base, port->width);
Quoted 7 lines
Quoted 5 lines

This looks like platform data is providing the GPIO <-> pinctrl pin ID mapping, or at least part of it. Surely that mapping is fixed by the HW design, and hence isn't something platform data should influence. Do the files pinctrl-adi2-bf*.c not contain complete information about each HW configuration for some reason?

Is it possible that 2 and more pinctrl devices are on the same SoC?

Yes.

Quoted 1 line

Or do we always assume there is only one pinctrl device on one SoC

No.

Quoted 4 lines

The
pinctrl_id field in platform data is to make the driver flexible for future SoCs. If the later case is true, I can just fix the pinctrl device name to "pinctrl-adi2.0".

I was talking about pdata->port_pin_base being passed to gpiochip_add_pin_range(), not the device name.

Quoted 2 lines

The GPIO device's HW regsiter base, pin base, pin number and the relationship with the PINT device are defined in the platform data.

Hmmm. I suppose with a platform-data-based driver, there isn't a good opportunity to encode which HW the code is running on, and then derive those parameters from the SoC type and/or put that information into device tree. Perhaps platform data is the only way, although isn't there some kind of "device ID -> data" mapping table option, so that probe() can be told which SoC is in use based on the device name, and use that to look up SoC-specific data?

Quoted 32 lines
Quoted 27 lines
Quoted 13 lines
drivers/pinctrl/pinctrl-adi2.c +13 -0
+static struct platform_driver adi_pinctrl_driver = {
+     .probe          = adi_pinctrl_probe,
+     .remove         = adi_pinctrl_remove,
+     .driver         = {
+             .name   = DRIVER_NAME,
+     },
+};
+
+static struct platform_driver adi_gpio_pint_driver = {
+     .probe          = adi_gpio_pint_probe,
+     .remove         = adi_gpio_pint_remove,
+     .driver         = {
+             .name   = "adi-gpio-pint",

drivers/pinctrl/pinctrl-adi2.c line 1468

Quoted 10 lines
drivers/pinctrl/pinctrl-adi2.c +10 -0
+     },
+};
+
+static struct platform_driver adi_gpio_driver = {
+     .probe          = adi_gpio_probe,
+     .remove         = adi_gpio_remove,
+     .driver         = {
+             .name   = "adi-gpio",
+     },
+};

Hmmm. Is there one HW block that controls GPIOs and pinctrl, or are there separate HW blocks?

Quoted 4 lines

If there's one HW block, why not have just one driver?

If there are separate HW blocks, then having separate GPIO and pinctrl drivers seems like it would make sense.

Quoted 7 lines

There are 6 to 9 GPIO HW blocks in one Blackfin SoC. Function pinmux_enable_setting() in current pinctrl framework assumes the function mux setting of one peripheral pin group is configured in one pinctrl device. But, the function mux setting of one blackfin peripheral may be done among different GPIO HW blocks. So, I have to separate the pinctrl driver from the GPIO block driver add the ranges of all GPIO blocks into one pinctrl device for Blackfin.

I don't think you need separate device; the pin control mapping table entries for a particular state simply needs to include entries for multiple pin controllers.

#6 lore raw

Hi Stephen,

Quoted 48 lines · Stephen Warren
Quoted 42 lines · Sonic Zhang

Hi Stephen,

Quoted 30 lines · Stephen Warren
Quoted 10 lines · Sonic Zhang

From: Sonic Zhang <[email protected]>

The new ADI GPIO2 controller was introduced since the BF548 and BF60x processors. It differs a lot from the old one on BF5xx processors. So, create a pinctrl driver under the pinctrl framework.

 drivers/pinctrl/Kconfig                    |   17 +
 drivers/pinctrl/Makefile                   |    3 +
 drivers/pinctrl/pinctrl-adi2-bf54x.c       |  572 +++++++++++
 drivers/pinctrl/pinctrl-adi2-bf60x.c       |  454 +++++++++

Those files look reasonable.

Quoted 16 lines
 drivers/pinctrl/pinctrl-adi2.c             | 1501 ++++++++++++++++++++++++++++
 drivers/pinctrl/pinctrl-adi2.h             |   75 ++
 include/linux/platform_data/pinctrl-adi2.h |   40 +
drivers/pinctrl/pinctrl-adi2.c +10 -0
 
+/**
+ * struct gpio_reserve_map - a GPIO map structure containing the
+ * reservation status of each PIN.
+ *
+ * @owner: who request the reservation
+ * @rsv_gpio: if this pin is reserved as GPIO
+ * @rsv_int: if this pin is reserved as interrupt
+ * @rsv_peri: if this pin is reserved as part of a peripheral device
+ */
+struct gpio_reserve_map {
Quoted 8 lines

drivers/pinctrl/pinctrl-adi2.c line 89

Quoted 5 lines
drivers/pinctrl/pinctrl-adi2.c +5 -0
+     unsigned char owner[RESOURCE_LABEL_SIZE];
+     bool rsv_gpio;
+     bool rsv_int;
+     bool rsv_peri;
+};

Why is that needed; don't the pinctrl/GPIO cores already know which pinctrl pins and which GPIOs are used, and for what?

Quoted 4 lines

The interrupt pin is requested and reserved in irq_chip operation irq_set_type() other than gpio_request(). In Blackfin, one gpio pin is allowed to be set up as both gpio interrupt and gpio input concurrently. So, we need bits to differentiate them.

Quoted 8 lines

Does the HW need to be programmed differently in those cases?

If not, I still don't see why the driver cares; if the HW allows both usages concurrently, there's nothing to check and hence no need to record any state.

If the HW must be programmed differently, can't you read the current state out of the HW?

After checking the blackfin HRM again, I think the GPIO interrupt mode is not mutually exclusive with the peripheral mode as well as the gpio mode. So, it is not necessary to check the reservation mode of the requested pin in IRQ chip operation. I will remove the reservation map.

Quoted 35 lines
Quoted 10 lines
Quoted 10 lines
Quoted 2 lines

+static int adi_gpio_probe(struct platform_device *pdev)

...

Quoted 6 lines
drivers/pinctrl/pinctrl-adi2.c +6 -0
+     /* Add gpio pin range */
+     snprintf(pinctrl_devname, RESOURCE_LABEL_SIZE, "pinctrl-adi2.%d",
+             pdata->pinctrl_id);
+     pinctrl_devname[RESOURCE_LABEL_SIZE - 1] = 0;
+     ret = gpiochip_add_pin_range(&port->chip, pinctrl_devname,
+             0, pdata->port_pin_base, port->width);
Quoted 7 lines
Quoted 5 lines

This looks like platform data is providing the GPIO <-> pinctrl pin ID mapping, or at least part of it. Surely that mapping is fixed by the HW design, and hence isn't something platform data should influence. Do the files pinctrl-adi2-bf*.c not contain complete information about each HW configuration for some reason?

Is it possible that 2 and more pinctrl devices are on the same SoC?

Yes.

Quoted 1 line

Or do we always assume there is only one pinctrl device on one SoC

No.

Quoted 4 lines

The
pinctrl_id field in platform data is to make the driver flexible for future SoCs. If the later case is true, I can just fix the pinctrl device name to "pinctrl-adi2.0".

I was talking about pdata->port_pin_base being passed to gpiochip_add_pin_range(), not the device name.

Quoted 2 lines

The GPIO device's HW regsiter base, pin base, pin number and the relationship with the PINT device are defined in the platform data.

Quoted 7 lines

Hmmm. I suppose with a platform-data-based driver, there isn't a good opportunity to encode which HW the code is running on, and then derive those parameters from the SoC type and/or put that information into device tree. Perhaps platform data is the only way, although isn't there some kind of "device ID -> data" mapping table option, so that probe() can be told which SoC is in use based on the device name, and use that to look up SoC-specific data?

The soc data driver is use to describe the pin group and function information of peripherals managed by a pin controller. It is more traditional and simpler to put the device specific parameters into the platform data.

Quoted 41 lines
Quoted 33 lines
Quoted 28 lines
Quoted 14 lines
drivers/pinctrl/pinctrl-adi2.c +13 -0
+static struct platform_driver adi_pinctrl_driver = {
+     .probe          = adi_pinctrl_probe,
+     .remove         = adi_pinctrl_remove,
+     .driver         = {
+             .name   = DRIVER_NAME,
+     },
+};
+
+static struct platform_driver adi_gpio_pint_driver = {
+     .probe          = adi_gpio_pint_probe,
+     .remove         = adi_gpio_pint_remove,
+     .driver         = {
+             .name   = "adi-gpio-pint",

drivers/pinctrl/pinctrl-adi2.c line 1468

Quoted 10 lines
drivers/pinctrl/pinctrl-adi2.c +10 -0
+     },
+};
+
+static struct platform_driver adi_gpio_driver = {
+     .probe          = adi_gpio_probe,
+     .remove         = adi_gpio_remove,
+     .driver         = {
+             .name   = "adi-gpio",
+     },
+};

Hmmm. Is there one HW block that controls GPIOs and pinctrl, or are there separate HW blocks?

Quoted 4 lines

If there's one HW block, why not have just one driver?

If there are separate HW blocks, then having separate GPIO and pinctrl drivers seems like it would make sense.

Quoted 7 lines

There are 6 to 9 GPIO HW blocks in one Blackfin SoC. Function pinmux_enable_setting() in current pinctrl framework assumes the function mux setting of one peripheral pin group is configured in one pinctrl device. But, the function mux setting of one blackfin peripheral may be done among different GPIO HW blocks. So, I have to separate the pinctrl driver from the GPIO block driver add the ranges of all GPIO blocks into one pinctrl device for Blackfin.

Quoted 4 lines

I don't think you need separate device; the pin control mapping table entries for a particular state simply needs to include entries for multiple pin controllers.

Calling pinctrl_select_state() multiple times with different pin controllers is not an atomic operation. If the second call fails, the pins requested successfully in the first call won't be freed automatically.

And it is more complicated for peripheral driver to handle pin group and function in multiple pin controllers. The peripheral driver has to know explicit which pinctrl devices to select other than calling the default devm_pinctrl_get_select_default().

So, I think if multiple gpio devices should be set up together for one peripheral, having one pin controller device to handle all of them is a more reasonable and clear solution.

Thanks

Sonic

#7 lore raw
Quoted 33 lines · Sonic Zhang

Hi Stephen,

Quoted 22 lines · Stephen Warren
Quoted 6 lines · Sonic Zhang

Hi Stephen,

Quoted 3 lines · Stephen Warren
Quoted 2 lines · Sonic Zhang

From: Sonic Zhang <[email protected]>

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

The new ADI GPIO2 controller was introduced since the BF548 and BF60x processors. It differs a lot from the old one on BF5xx processors. So, create a pinctrl driver under the pinctrl framework.

The
pinctrl_id field in platform data is to make the driver flexible for future SoCs. If the later case is true, I can just fix the pinctrl device name to "pinctrl-adi2.0".

I was talking about pdata->port_pin_base being passed to gpiochip_add_pin_range(), not the device name.

Quoted 2 lines

The GPIO device's HW regsiter base, pin base, pin number and the relationship with the PINT device are defined in the platform data.

Quoted 7 lines

Hmmm. I suppose with a platform-data-based driver, there isn't a good opportunity to encode which HW the code is running on, and then derive those parameters from the SoC type and/or put that information into device tree. Perhaps platform data is the only way, although isn't there some kind of "device ID -> data" mapping table option, so that probe() can be told which SoC is in use based on the device name, and use that to look up SoC-specific data?

Quoted 4 lines

The soc data driver is use to describe the pin group and function information of peripherals managed by a pin controller. It is more traditional and simpler to put the device specific parameters into the platform data.

Sure, that's the way things have been done historically. However, if there's a better way, one may as well use it.

Quoted 43 lines
Quoted 43 lines
Quoted 42 lines
Quoted 30 lines
Quoted 16 lines
drivers/pinctrl/pinctrl-adi2.c new file +13 -0
+static struct platform_driver adi_pinctrl_driver = {
+     .probe          = adi_pinctrl_probe,
+     .remove         = adi_pinctrl_remove,
+     .driver         = {
+             .name   = DRIVER_NAME,
+     },
+};
+
+static struct platform_driver adi_gpio_pint_driver = {
+     .probe          = adi_gpio_pint_probe,
+     .remove         = adi_gpio_pint_remove,
+     .driver         = {
+             .name   = "adi-gpio-pint",

drivers/pinctrl/pinctrl-adi2.c line 1468

Quoted 10 lines
drivers/pinctrl/pinctrl-adi2.c new file +10 -0
+     },
+};
+
+static struct platform_driver adi_gpio_driver = {
+     .probe          = adi_gpio_probe,
+     .remove         = adi_gpio_remove,
+     .driver         = {
+             .name   = "adi-gpio",
+     },
+};

Hmmm. Is there one HW block that controls GPIOs and pinctrl, or are there separate HW blocks?

Quoted 4 lines

If there's one HW block, why not have just one driver?

If there are separate HW blocks, then having separate GPIO and pinctrl drivers seems like it would make sense.

There are 6 to 9 GPIO HW blocks in one Blackfin SoC. Function pinmux_enable_setting() in current pinctrl framework assumes the function mux setting of one peripheral pin group is configured in one pinctrl device. But, the function mux setting of one blackfin peripheral may be done among different GPIO HW blocks. So, I have to separate the pinctrl driver from the GPIO block driver add the ranges of all GPIO blocks into one pinctrl device for Blackfin.

Quoted 8 lines
Quoted 3 lines

I don't think you need separate device; the pin control mapping table entries for a particular state simply needs to include entries for multiple pin controllers.

Calling pinctrl_select_state() multiple times with different pin controllers is not an atomic operation. If the second call fails, the pins requested successfully in the first call won't be freed automatically.

Drivers should only call pinctrl_select_state() once. The state that gets selected can affect multiple pin controllers at once. This should be an atomic operation as far as the client driver is concerned. If any of that isn't true, it's a bug in pinctrl.

Quoted 4 lines

And it is more complicated for peripheral driver to handle pin group and function in multiple pin controllers. The peripheral driver has to know explicit which pinctrl devices to select other than calling the default devm_pinctrl_get_select_default().

No; see above.

Quoted 3 lines

So, I think if multiple gpio devices should be set up together for one peripheral, having one pin controller device to handle all of them is a more reasonable and clear solution.

#8 lore raw

Hi Stephen,

Quoted 94 lines · Stephen Warren
Quoted 33 lines · Sonic Zhang

Hi Stephen,

Quoted 22 lines · Stephen Warren
Quoted 6 lines · Sonic Zhang

Hi Stephen,

Quoted 3 lines · Stephen Warren
Quoted 2 lines · Sonic Zhang

From: Sonic Zhang <[email protected]>

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

The new ADI GPIO2 controller was introduced since the BF548 and BF60x processors. It differs a lot from the old one on BF5xx processors. So, create a pinctrl driver under the pinctrl framework.

The
pinctrl_id field in platform data is to make the driver flexible for future SoCs. If the later case is true, I can just fix the pinctrl device name to "pinctrl-adi2.0".

I was talking about pdata->port_pin_base being passed to gpiochip_add_pin_range(), not the device name.

Quoted 2 lines

The GPIO device's HW regsiter base, pin base, pin number and the relationship with the PINT device are defined in the platform data.

Quoted 7 lines

Hmmm. I suppose with a platform-data-based driver, there isn't a good opportunity to encode which HW the code is running on, and then derive those parameters from the SoC type and/or put that information into device tree. Perhaps platform data is the only way, although isn't there some kind of "device ID -> data" mapping table option, so that probe() can be told which SoC is in use based on the device name, and use that to look up SoC-specific data?

Quoted 4 lines

The soc data driver is use to describe the pin group and function information of peripherals managed by a pin controller. It is more traditional and simpler to put the device specific parameters into the platform data.

Sure, that's the way things have been done historically. However, if there's a better way, one may as well use it.

Quoted 43 lines
Quoted 43 lines
Quoted 42 lines
Quoted 30 lines
Quoted 16 lines
drivers/pinctrl/pinctrl-adi2.c new file +13 -0
+static struct platform_driver adi_pinctrl_driver = {
+     .probe          = adi_pinctrl_probe,
+     .remove         = adi_pinctrl_remove,
+     .driver         = {
+             .name   = DRIVER_NAME,
+     },
+};
+
+static struct platform_driver adi_gpio_pint_driver = {
+     .probe          = adi_gpio_pint_probe,
+     .remove         = adi_gpio_pint_remove,
+     .driver         = {
+             .name   = "adi-gpio-pint",

drivers/pinctrl/pinctrl-adi2.c line 1468

Quoted 10 lines
drivers/pinctrl/pinctrl-adi2.c new file +10 -0
+     },
+};
+
+static struct platform_driver adi_gpio_driver = {
+     .probe          = adi_gpio_probe,
+     .remove         = adi_gpio_remove,
+     .driver         = {
+             .name   = "adi-gpio",
+     },
+};

Hmmm. Is there one HW block that controls GPIOs and pinctrl, or are there separate HW blocks?

Quoted 4 lines

If there's one HW block, why not have just one driver?

If there are separate HW blocks, then having separate GPIO and pinctrl drivers seems like it would make sense.

There are 6 to 9 GPIO HW blocks in one Blackfin SoC. Function pinmux_enable_setting() in current pinctrl framework assumes the function mux setting of one peripheral pin group is configured in one pinctrl device. But, the function mux setting of one blackfin peripheral may be done among different GPIO HW blocks. So, I have to separate the pinctrl driver from the GPIO block driver add the ranges of all GPIO blocks into one pinctrl device for Blackfin.

Quoted 8 lines
Quoted 3 lines

I don't think you need separate device; the pin control mapping table entries for a particular state simply needs to include entries for multiple pin controllers.

Calling pinctrl_select_state() multiple times with different pin controllers is not an atomic operation. If the second call fails, the pins requested successfully in the first call won't be freed automatically.

Quoted 4 lines

Drivers should only call pinctrl_select_state() once. The state that gets selected can affect multiple pin controllers at once. This should be an atomic operation as far as the client driver is concerned. If any of that isn't true, it's a bug in pinctrl.

/**
* pinctrl_select_state() - select/activate/program a pinctrl state to HW
* @p: the pinctrl handle for the device that requests configuration
* @state: the state handle to select/activate/program
*/
int pinctrl_select_state(struct pinctrl *p, struct pinctrl_state *state)

If drivers should still call pinctrl_select_state() once in case of multiple pin controllers, the first parameter of pinctrl_select_state() is wrong. Which pinctrl device among all affected pin controllers should the driver use? Or whatever pinctrl device?

To separate the pinctrl_settings of one peripheral to multiple pinctrl devices, multiple pinctrl group arrays and function arrays should be defined in the soc data file. This change increases the code size of the soc data file a lot without get any real benefits. The pin controller device can be defined as a logic device to cover all gpio devices, which are mapped into one peripheral pin id space without collision. All overhead in the soc data file can be removed in this way.

GPIO devices with peripheral pin id collision have to put into different pin controller logic devices.

So, I think it is fine to either binding pinctrl device to gpio device or leave it as a logic device.

Regards,

Sonic

Quoted 11 lines
Quoted 5 lines

And it is more complicated for peripheral driver to handle pin group and function in multiple pin controllers. The peripheral driver has to know explicit which pinctrl devices to select other than calling the default devm_pinctrl_get_select_default().

No; see above.

Quoted 3 lines

So, I think if multiple gpio devices should be set up together for one peripheral, having one pin controller device to handle all of them is a more reasonable and clear solution.

#9 lore raw
Quoted 109 lines · Sonic Zhang

Hi Stephen,

Quoted 94 lines · Stephen Warren
Quoted 33 lines · Sonic Zhang

Hi Stephen,

Quoted 22 lines · Stephen Warren
Quoted 6 lines · Sonic Zhang

Hi Stephen,

Quoted 3 lines · Stephen Warren
Quoted 2 lines · Sonic Zhang

From: Sonic Zhang <[email protected]>

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

The new ADI GPIO2 controller was introduced since the BF548 and BF60x processors. It differs a lot from the old one on BF5xx processors. So, create a pinctrl driver under the pinctrl framework.

The
pinctrl_id field in platform data is to make the driver flexible for future SoCs. If the later case is true, I can just fix the pinctrl device name to "pinctrl-adi2.0".

I was talking about pdata->port_pin_base being passed to gpiochip_add_pin_range(), not the device name.

Quoted 2 lines

The GPIO device's HW regsiter base, pin base, pin number and the relationship with the PINT device are defined in the platform data.

Quoted 7 lines

Hmmm. I suppose with a platform-data-based driver, there isn't a good opportunity to encode which HW the code is running on, and then derive those parameters from the SoC type and/or put that information into device tree. Perhaps platform data is the only way, although isn't there some kind of "device ID -> data" mapping table option, so that probe() can be told which SoC is in use based on the device name, and use that to look up SoC-specific data?

Quoted 4 lines

The soc data driver is use to describe the pin group and function information of peripherals managed by a pin controller. It is more traditional and simpler to put the device specific parameters into the platform data.

Sure, that's the way things have been done historically. However, if there's a better way, one may as well use it.

Quoted 43 lines
Quoted 43 lines
Quoted 42 lines
Quoted 30 lines
Quoted 16 lines
(quoted diff) +13 -0
+static struct platform_driver adi_pinctrl_driver = {
+     .probe          = adi_pinctrl_probe,
+     .remove         = adi_pinctrl_remove,
+     .driver         = {
+             .name   = DRIVER_NAME,
+     },
+};
+
+static struct platform_driver adi_gpio_pint_driver = {
+     .probe          = adi_gpio_pint_probe,
+     .remove         = adi_gpio_pint_remove,
+     .driver         = {
+             .name   = "adi-gpio-pint",

Review

Quoted 10 lines
(quoted diff) +10 -0
+     },
+};
+
+static struct platform_driver adi_gpio_driver = {
+     .probe          = adi_gpio_probe,
+     .remove         = adi_gpio_remove,
+     .driver         = {
+             .name   = "adi-gpio",
+     },
+};

Hmmm. Is there one HW block that controls GPIOs and pinctrl, or are there separate HW blocks?

Quoted 4 lines

If there's one HW block, why not have just one driver?

If there are separate HW blocks, then having separate GPIO and pinctrl drivers seems like it would make sense.

There are 6 to 9 GPIO HW blocks in one Blackfin SoC. Function pinmux_enable_setting() in current pinctrl framework assumes the function mux setting of one peripheral pin group is configured in one pinctrl device. But, the function mux setting of one blackfin peripheral may be done among different GPIO HW blocks. So, I have to separate the pinctrl driver from the GPIO block driver add the ranges of all GPIO blocks into one pinctrl device for Blackfin.

Quoted 8 lines
Quoted 3 lines

I don't think you need separate device; the pin control mapping table entries for a particular state simply needs to include entries for multiple pin controllers.

Calling pinctrl_select_state() multiple times with different pin controllers is not an atomic operation. If the second call fails, the pins requested successfully in the first call won't be freed automatically.

Quoted 4 lines

Drivers should only call pinctrl_select_state() once. The state that gets selected can affect multiple pin controllers at once. This should be an atomic operation as far as the client driver is concerned. If any of that isn't true, it's a bug in pinctrl.

/**
* pinctrl_select_state() - select/activate/program a pinctrl state to HW
* @p: the pinctrl handle for the device that requests configuration
* @state: the state handle to select/activate/program
*/
int pinctrl_select_state(struct pinctrl *p, struct pinctrl_state *state)

Quoted 5 lines

If drivers should still call pinctrl_select_state() once in case of multiple pin controllers, the first parameter of pinctrl_select_state() is wrong. Which pinctrl device among all affected pin controllers should the driver use? Or whatever pinctrl device?

The function prototype is not wrong. "struct pinctrl *p" is not a pinctrl device, but rather it's the result of calling pinctrl_get(). This value encompasses all information required to program all pinctrl HW devices that need to be programmed.

Quoted 8 lines

To separate the pinctrl_settings of one peripheral to multiple pinctrl devices, multiple pinctrl group arrays and function arrays should be defined in the soc data file. This change increases the code size of the soc data file a lot without get any real benefits. The pin controller device can be defined as a logic device to cover all gpio devices, which are mapped into one peripheral pin id space without collision. All overhead in the soc data file can be removed in this way.

It's possible to debate how to construct the pinctrl drivers themselves, but this has no impact at all on how a client driver calls the pinctrl APIs.

#10 lore raw

Hi Stephen,

Quoted 116 lines · Stephen Warren
Quoted 109 lines · Sonic Zhang

Hi Stephen,

Quoted 94 lines · Stephen Warren
Quoted 33 lines · Sonic Zhang

Hi Stephen,

Quoted 22 lines · Stephen Warren
Quoted 6 lines · Sonic Zhang

Hi Stephen,

Quoted 3 lines · Stephen Warren
Quoted 2 lines · Sonic Zhang

From: Sonic Zhang <[email protected]>

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

The new ADI GPIO2 controller was introduced since the BF548 and BF60x processors. It differs a lot from the old one on BF5xx processors. So, create a pinctrl driver under the pinctrl framework.

The
pinctrl_id field in platform data is to make the driver flexible for future SoCs. If the later case is true, I can just fix the pinctrl device name to "pinctrl-adi2.0".

I was talking about pdata->port_pin_base being passed to gpiochip_add_pin_range(), not the device name.

Quoted 2 lines

The GPIO device's HW regsiter base, pin base, pin number and the relationship with the PINT device are defined in the platform data.

Quoted 7 lines

Hmmm. I suppose with a platform-data-based driver, there isn't a good opportunity to encode which HW the code is running on, and then derive those parameters from the SoC type and/or put that information into device tree. Perhaps platform data is the only way, although isn't there some kind of "device ID -> data" mapping table option, so that probe() can be told which SoC is in use based on the device name, and use that to look up SoC-specific data?

Quoted 4 lines

The soc data driver is use to describe the pin group and function information of peripherals managed by a pin controller. It is more traditional and simpler to put the device specific parameters into the platform data.

Sure, that's the way things have been done historically. However, if there's a better way, one may as well use it.

Quoted 43 lines
Quoted 43 lines
Quoted 42 lines
Quoted 30 lines
Quoted 16 lines
(quoted diff) +13 -0
+static struct platform_driver adi_pinctrl_driver = {
+     .probe          = adi_pinctrl_probe,
+     .remove         = adi_pinctrl_remove,
+     .driver         = {
+             .name   = DRIVER_NAME,
+     },
+};
+
+static struct platform_driver adi_gpio_pint_driver = {
+     .probe          = adi_gpio_pint_probe,
+     .remove         = adi_gpio_pint_remove,
+     .driver         = {
+             .name   = "adi-gpio-pint",

Review

Quoted 10 lines
(quoted diff) +10 -0
+     },
+};
+
+static struct platform_driver adi_gpio_driver = {
+     .probe          = adi_gpio_probe,
+     .remove         = adi_gpio_remove,
+     .driver         = {
+             .name   = "adi-gpio",
+     },
+};

Hmmm. Is there one HW block that controls GPIOs and pinctrl, or are there separate HW blocks?

Quoted 4 lines

If there's one HW block, why not have just one driver?

If there are separate HW blocks, then having separate GPIO and pinctrl drivers seems like it would make sense.

There are 6 to 9 GPIO HW blocks in one Blackfin SoC. Function pinmux_enable_setting() in current pinctrl framework assumes the function mux setting of one peripheral pin group is configured in one pinctrl device. But, the function mux setting of one blackfin peripheral may be done among different GPIO HW blocks. So, I have to separate the pinctrl driver from the GPIO block driver add the ranges of all GPIO blocks into one pinctrl device for Blackfin.

Quoted 8 lines
Quoted 3 lines

I don't think you need separate device; the pin control mapping table entries for a particular state simply needs to include entries for multiple pin controllers.

Calling pinctrl_select_state() multiple times with different pin controllers is not an atomic operation. If the second call fails, the pins requested successfully in the first call won't be freed automatically.

Quoted 4 lines

Drivers should only call pinctrl_select_state() once. The state that gets selected can affect multiple pin controllers at once. This should be an atomic operation as far as the client driver is concerned. If any of that isn't true, it's a bug in pinctrl.

/**
* pinctrl_select_state() - select/activate/program a pinctrl state to HW
* @p: the pinctrl handle for the device that requests configuration
* @state: the state handle to select/activate/program
*/
int pinctrl_select_state(struct pinctrl *p, struct pinctrl_state *state)

Quoted 5 lines

If drivers should still call pinctrl_select_state() once in case of multiple pin controllers, the first parameter of pinctrl_select_state() is wrong. Which pinctrl device among all affected pin controllers should the driver use? Or whatever pinctrl device?

Quoted 4 lines

The function prototype is not wrong. "struct pinctrl *p" is not a pinctrl device, but rather it's the result of calling pinctrl_get(). This value encompasses all information required to program all pinctrl HW devices that need to be programmed.

Thanks to explain. I didn't dig into struct pinctrl much.

Regards,

Sonic

Quoted 13 lines
Quoted 9 lines

To separate the pinctrl_settings of one peripheral to multiple pinctrl devices, multiple pinctrl group arrays and function arrays should be defined in the soc data file. This change increases the code size of the soc data file a lot without get any real benefits. The pin controller device can be defined as a logic device to cover all gpio devices, which are mapped into one peripheral pin id space without collision. All overhead in the soc data file can be removed in this way.

It's possible to debate how to construct the pinctrl drivers themselves, but this has no impact at all on how a client driver calls the pinctrl APIs.

#11 lore raw
In reply to Stephen Warren
Quoted 10 lines · Stephen Warren
Quoted 8 lines · Sonic Zhang

There are 6 to 9 GPIO HW blocks in one Blackfin SoC. Function pinmux_enable_setting() in current pinctrl framework assumes the function mux setting of one peripheral pin group is configured in one pinctrl device. But, the function mux setting of one blackfin peripheral may be done among different GPIO HW blocks. So, I have to separate the pinctrl driver from the GPIO block driver add the ranges of all GPIO blocks into one pinctrl device for Blackfin.

Quoted 3 lines

I don't think you need separate device; the pin control mapping table entries for a particular state simply needs to include entries for multiple pin controllers.

So splitting each block into a separate pin control device is definately one way to skin the cat.

The ux500 would then have 9 pin controller instances (after a big fat refactoring, but whatever) instead of 9 GPIO instances and one pinctrl instance referencing them. Also this solves the problem of registering GPIO ranges from the wrong end of the pin controller.

Hm, I should try this and see where it goes... What do you think about this Sonic?

Yours,
Linus Walleij

#12 lore raw

Hi Linus,

Quoted 18 lines · Linus Walleij
Quoted 10 lines · Stephen Warren
Quoted 8 lines · Sonic Zhang

There are 6 to 9 GPIO HW blocks in one Blackfin SoC. Function pinmux_enable_setting() in current pinctrl framework assumes the function mux setting of one peripheral pin group is configured in one pinctrl device. But, the function mux setting of one blackfin peripheral may be done among different GPIO HW blocks. So, I have to separate the pinctrl driver from the GPIO block driver add the ranges of all GPIO blocks into one pinctrl device for Blackfin.

Quoted 3 lines

I don't think you need separate device; the pin control mapping table entries for a particular state simply needs to include entries for multiple pin controllers.

So splitting each block into a separate pin control device is definately one way to skin the cat.

Quoted 8 lines

The ux500 would then have 9 pin controller instances (after a big fat refactoring, but whatever) instead of 9 GPIO instances and one pinctrl instance referencing them. Also this solves the problem of registering GPIO ranges from the wrong end of the pin controller.

Hm, I should try this and see where it goes... What do you think about this Sonic?

As I discussed with Stephen:

To separate the pinctrl_settings of one peripheral to multiple pinctrl devices, multiple pinctrl group arrays and function arrays should be defined in the soc data file. This change increases the code size of the soc data file a lot without get any real benefits.

The pin controller device can be defined as a logic device to cover many gpio devices, which are mapped into the same pin id space without collision. All overhead in the soc data file can be removed in this way. GPIO devices with pin id region collision should be put into different pin controller devices.

So, I think it is fine to either binding pinctrl device to gpio device or leave it as a logic device.

Regards,

Sonic

#13 lore raw
Quoted 10 lines · Sonic Zhang
Quoted 8 lines · Linus Walleij

So splitting each block into a separate pin control device is definately one way to skin the cat.

The ux500 would then have 9 pin controller instances (after a big fat refactoring, but whatever) instead of 9 GPIO instances and one pinctrl instance referencing them. Also this solves the problem of registering GPIO ranges from the wrong end of the pin controller.

(...)

Quoted 5 lines

The pin controller device can be defined as a logic device to cover many gpio devices, which are mapped into the same pin id space without collision. All overhead in the soc data file can be removed in this way. GPIO devices with pin id region collision should be put into different pin controller devices.

This is true for your device and if that works for you then go ahead with this.

In the Nomadik case the registers for GPIO and pin control are mingled in the same memory range so things are more complex.

Yours,
Linus Walleij

#14 lore raw
In reply to Sonic Zhang
Quoted 2 lines · Sonic Zhang

Is it possible that 2 and more pinctrl devices are on the same SoC? Or do we always assume there is only one pinctrl device on one SoC?

It is possible to have N pinctrl devices on the same SoC, not to mention the whole system. The subsystem does not care, just line them up.

Yours,
Linus Walleij

#15 lore raw
In reply to Sonic Zhang
Quoted 7 lines · Sonic Zhang

There are 6 to 9 GPIO HW blocks in one Blackfin SoC. Function pinmux_enable_setting() in current pinctrl framework assumes the function mux setting of one peripheral pin group is configured in one pinctrl device. But, the function mux setting of one blackfin peripheral may be done among different GPIO HW blocks. So, I have to separate the pinctrl driver from the GPIO block driver add the ranges of all GPIO blocks into one pinctrl device for Blackfin.

This is similar to the situation in the pinctrl-nomadik.c driver, where the pinctrl portions wait for the GPIO devices to instantiate before proceeding to probe "on top" of the GPIO blocks, using the latter to get to the registers.

I am not sure we have found the best way to sort out this type of system, let's see what we can come up with.

One way I was contemplating was to have just one fat node in the device tree containing all the register ranges, and one fat probe function, so all these ranges associated with a single struct device, but that does not well work with clocking and interrupts (the GPIO ranges needed one clock and interrupt each) so I gave up on that idea.

My latest idea was to to to break the subsystems apart a bit by letting GPIO devices probe without the underlying pin controller being in place, so I queued up the operations until the pin controller arrived, but unfortunately this creates other problems :-(

Still this creates a fuzz when trying to refactor stuff so we need to find a solution.

Yours,
Linus Walleij

#16 lore raw

Hi Linus,

Quoted 10 lines · Linus Walleij
Quoted 7 lines · Sonic Zhang

There are 6 to 9 GPIO HW blocks in one Blackfin SoC. Function pinmux_enable_setting() in current pinctrl framework assumes the function mux setting of one peripheral pin group is configured in one pinctrl device. But, the function mux setting of one blackfin peripheral may be done among different GPIO HW blocks. So, I have to separate the pinctrl driver from the GPIO block driver add the ranges of all GPIO blocks into one pinctrl device for Blackfin.

Quoted 7 lines

This is similar to the situation in the pinctrl-nomadik.c driver, where the pinctrl portions wait for the GPIO devices to instantiate before proceeding to probe "on top" of the GPIO blocks, using the latter to get to the registers.

I am not sure we have found the best way to sort out this type of system, let's see what we can come up with.

In the blackfin pinctrol-adi2 driver, I probe all gpio devices independently after all logic pinctrl devices. When one gpio device is probed, it can get its pinctrl device name from its platform data and add its gpio range into the pinctrl device via gpiochip_add_pin_range(). The gpio device don't need to know anything else about its pinctrl device.

Regards,

Sonic

Quoted 19 lines

One way I was contemplating was to have just one fat node in the device tree containing all the register ranges, and one fat probe function, so all these ranges associated with a single struct device, but that does not well work with clocking and interrupts (the GPIO ranges needed one clock and interrupt each) so I gave up on that idea.

My latest idea was to to to break the subsystems apart a bit by letting GPIO devices probe without the underlying pin controller being in place, so I queued up the operations until the pin controller arrived, but unfortunately this creates other problems :-(

Still this creates a fuzz when trying to refactor stuff so we need to find a solution.

Yours,
Linus Walleij

#17 lore raw
Quoted 10 lines · Sonic Zhang
Quoted 7 lines · Linus Walleij

This is similar to the situation in the pinctrl-nomadik.c driver, where the pinctrl portions wait for the GPIO devices to instantiate before proceeding to probe "on top" of the GPIO blocks, using the latter to get to the registers.

I am not sure we have found the best way to sort out this type of system, let's see what we can come up with.

Quoted 6 lines

In the blackfin pinctrol-adi2 driver, I probe all gpio devices independently after all logic pinctrl devices. When one gpio device is probed, it can get its pinctrl device name from its platform data and add its gpio range into the pinctrl device via gpiochip_add_pin_range(). The gpio device don't need to know anything else about its pinctrl device.

This is ideal in the situation when there is a clear separation between the GPIO and pin control (muxing, biasing) registers. So you're doing the right thing.

Yours,
Linus Walleij

#18 lore raw
In reply to Sonic Zhang
Quoted 5 lines · Sonic Zhang

From: Sonic Zhang <[email protected]>

The new ADI GPIO2 controller was introduced since the BF548 and BF60x processors. It differs a lot from the old one on BF5xx processors. So, create a pinctrl driver under the pinctrl framework.

(...)

The v3 is a huge improvement! Keep going.

I will not repeat any of Stephens review comments, I just saw this:

Quoted 5 lines
drivers/pinctrl/pinctrl-adi2-bf54x.c new file +5 -0
+static const unsigned uart1_pins[] = {
+       GPIO_PH0, GPIO_PH1,
+#ifdef CONFIG_BFIN_UART1_CTSRTS
+       GPIO_PE9, GPIO_PE10,
+#endif

(...)

Quoted 9 lines
drivers/pinctrl/pinctrl-adi2-bf54x.c new file +9 -0
+static const unsigned atapi_pins[] = {
+       GPIO_PH2, GPIO_PJ3, GPIO_PJ4, GPIO_PJ5, GPIO_PJ6,
+       GPIO_PJ7, GPIO_PJ8, GPIO_PJ9, GPIO_PJ10,
+       GPIO_PG5, GPIO_PG6, GPIO_PG7,
+#ifdef CONFIG_BF548_ATAPI_ALTERNATIVE_PORT
+       GPIO_PF0, GPIO_PF1, GPIO_PF2, GPIO_PF3, GPIO_PF4, GPIO_PF5, GPIO_PF6,
+       GPIO_PF7, GPIO_PF8, GPIO_PF9, GPIO_PF10, GPIO_PF11, GPIO_PF12,
+       GPIO_PF13, GPIO_PF14, GPIO_PF15, GPIO_PG2, GPIO_PG3, GPIO_PG4,
+#endif

(...)

Quoted 1 line

+static const struct adi_pin_group adi_pin_groups[] = {

(...)

Quoted 1 line

+ ADI_PIN_GROUP("uart1grp", uart1_pins),

(...)

Review

Quoted 2 lines
(quoted diff) +2 -0
+       ADI_PIN_GROUP("atapigrp", atapi_pins),
+};

This is not how we do it. Do not use Kconfig to spefify how the SoC is utilized. This shall be done at runtime.

What you want to do for UART0 is specify one group for the TX/RX pair and another group for the CTS/RTS pair like this:

static const unsigned uart1_rxtx_pins[] = {
       GPIO_PH0, GPIO_PH1,
};
static const unsigned uart1_rtscts_pins[] = {
       GPIO_PE9, GPIO_PE10,
};

static const struct adi_pin_group adi_pin_groups[] = { (...)

        ADI_PIN_GROUP("uart1txrxgrp", uart1_rxtx_pins),
        ADI_PIN_GROUP("uart1rtsctsgrp", uart1_ctsrts_pins),
       (...)
};

(And vice versa for the atapi pins, create two groups.)

If you want to use all four pins on UART1 in a system, you specify this in you map (in platform data or DTS), so that e.g. the state "default" will be activate *both* uart1txrxgrp and uart1rtscts groups.

This is typically done with two entries in the map.

Yours,
Linus Walleij

#19 lore raw

Hi Linus,

Quoted 59 lines · Linus Walleij
Quoted 5 lines · Sonic Zhang

From: Sonic Zhang <[email protected]>

The new ADI GPIO2 controller was introduced since the BF548 and BF60x processors. It differs a lot from the old one on BF5xx processors. So, create a pinctrl driver under the pinctrl framework.

(...)

The v3 is a huge improvement! Keep going.

I will not repeat any of Stephens review comments, I just saw this:

Quoted 5 lines
drivers/pinctrl/pinctrl-adi2-bf54x.c new file +5 -0
+static const unsigned uart1_pins[] = {
+       GPIO_PH0, GPIO_PH1,
+#ifdef CONFIG_BFIN_UART1_CTSRTS
+       GPIO_PE9, GPIO_PE10,
+#endif

(...)

Quoted 9 lines
drivers/pinctrl/pinctrl-adi2-bf54x.c new file +9 -0
+static const unsigned atapi_pins[] = {
+       GPIO_PH2, GPIO_PJ3, GPIO_PJ4, GPIO_PJ5, GPIO_PJ6,
+       GPIO_PJ7, GPIO_PJ8, GPIO_PJ9, GPIO_PJ10,
+       GPIO_PG5, GPIO_PG6, GPIO_PG7,
+#ifdef CONFIG_BF548_ATAPI_ALTERNATIVE_PORT
+       GPIO_PF0, GPIO_PF1, GPIO_PF2, GPIO_PF3, GPIO_PF4, GPIO_PF5, GPIO_PF6,
+       GPIO_PF7, GPIO_PF8, GPIO_PF9, GPIO_PF10, GPIO_PF11, GPIO_PF12,
+       GPIO_PF13, GPIO_PF14, GPIO_PF15, GPIO_PG2, GPIO_PG3, GPIO_PG4,
+#endif

(...)

Quoted 1 line

+static const struct adi_pin_group adi_pin_groups[] = {

(...)

Quoted 1 line

+ ADI_PIN_GROUP("uart1grp", uart1_pins),

(...)

Review

Quoted 2 lines
(quoted diff) +2 -0
+       ADI_PIN_GROUP("atapigrp", atapi_pins),
+};

This is not how we do it. Do not use Kconfig to spefify how the SoC is utilized. This shall be done at runtime.

What you want to do for UART0 is specify one group for the TX/RX pair and another group for the CTS/RTS pair like this:

static const unsigned uart1_rxtx_pins[] = {
       GPIO_PH0, GPIO_PH1,
};
static const unsigned uart1_rtscts_pins[] = {
       GPIO_PE9, GPIO_PE10,
};

static const struct adi_pin_group adi_pin_groups[] = { (...)

        ADI_PIN_GROUP("uart1txrxgrp", uart1_rxtx_pins),
        ADI_PIN_GROUP("uart1rtsctsgrp", uart1_ctsrts_pins),
       (...)
};
Quoted 8 lines

(And vice versa for the atapi pins, create two groups.)

If you want to use all four pins on UART1 in a system, you specify this in you map (in platform data or DTS), so that e.g. the state "default" will be activate *both* uart1txrxgrp and uart1rtscts groups.

This is typically done with two entries in the map.

OK. I will separate the pins into 2 groups.

Regards,

Sonic