Skip to contentSkip to conversation

Update GPIO and pinctrl to upstream

PATCH Superseded Andrew Jeffery 1 participant 7 messages Feb 3, 2017

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

cover Update GPIO and pinctrl to upstream

Hi Joel,

This series gets the GPIO and pinctrl subsystems of dev-4.7 into the same state as upstream. A handful of patches reset things back to mainline, and then patches applied by the GPIO and pinctrl maintainer are cherry-picked in.

The series has three checkpatch warnings, one for "lack" of Kconfig symbol description in 2/14 (which simply resets some state to match mainline), a second for a duplicate S-o-B tag in 5/14 and another regarding commit message line length in 6/14. I've added my S-o-B twice in 5/14 because the patch doesn't backport cleanly and I had to remove some code. The commit message warning in 6/14 is for a link to the upstream patch and isn't appropriate to wrap.

Other than that, it builds with aspeed_g{4,5}_defconfigs and boots in Palmetto and Romulus QEMU machines. The cherry-picked patches have been tested on Palmetto and AST2500EVB hardware.

Please review.

Cheers,

Andrew

Andrew Jeffery (13):
gpio: aspeed: dt: Reset bindings to mainline
gpio: aspeed: Reset to mainline
aspeed: dt: Mark GPIO controller as interrupt-controller
gpio: aspeed: Add banks Y, Z, AA, AB and AC
gpio: aspeed: Remove dependence on GPIOF_* macros
aspeed: g5: dt: Update GPIO pin range to mux banks Y, Z, AA, AB, AC
pinctrl: aspeed: Reset to mainline
pinctrl: aspeed: dt: Fix compatibles for the System Control Unit
pinctrl: aspeed: Read and write bits in LPC and GFX controllers
pinctrl: aspeed-g4: Add mux configuration for all pins
pinctrl: aspeed-g5: Add mux configuration for all pins
pinctrl: aspeed: Fix kerneldoc return descriptions
pinctrl: aspeed: g4: Fix mux configuration for GPIOs AA[4-7], AB[0-7]

Joel Stanley (1):
gpio: aspeed: Make bank names strings

 .../devicetree/bindings/gpio/gpio-aspeed.txt       |  20 +-
 .../devicetree/bindings/pinctrl/pinctrl-aspeed.txt |  91 ++++++-
 arch/arm/boot/dts/aspeed-g4.dtsi                   |   1 +
 arch/arm/boot/dts/aspeed-g5.dtsi                   |   3 +-
 drivers/gpio/Kconfig                               |  13 +-
 drivers/gpio/gpio-aspeed.c                         | 299 ++++++++++++++-------
 drivers/pinctrl/aspeed/pinctrl-aspeed-g4.c         |  63 ++---
 drivers/pinctrl/aspeed/pinctrl-aspeed-g5.c         |  76 ++++--
 drivers/pinctrl/aspeed/pinctrl-aspeed.c            | 216 +++++++--------
 drivers/pinctrl/aspeed/pinctrl-aspeed.h            |  48 ++--
 10 files changed, 507 insertions(+), 323 deletions(-)
Signature · 1 line
2.9.3
#1 lore raw

PATCH 1/14 gpio: aspeed: dt: Reset bindings to mainline

---
 .../devicetree/bindings/gpio/gpio-aspeed.txt         | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)
Documentation/devicetree/bindings/gpio/gpio-aspeed.txt +7 -13
index 1954b288cd49..393bb2ed8a77 100644
@@ -2,28 +2,22 @@ Aspeed GPIO controller Device Tree Bindings
 -------------------------------------------
 
 Required properties:
+- compatible		: Either "aspeed,ast2400-gpio" or "aspeed,ast2500-gpio"
+
 - #gpio-cells 		: Should be two
 			  - First cell is the GPIO line number
 			  - Second cell is used to specify optional
 			    parameters (unused)
 
-- compatible		: Either "aspeed,ast2400-gpio" or "aspeed,ast2500-gpio"
-
 - reg			: Address and length of the register set for the device
 - gpio-controller	: Marks the device node as a GPIO controller.
 - interrupts		: Interrupt specifier (see interrupt bindings for
 			  details)
+- interrupt-controller	: Mark the GPIO controller as an interrupt-controller
 
 Optional properties:
-- interrupt-controller	: Marks the device node as an interrupt controller.
-- interrupt-parent	: The parent interrupt controller, optional if inherited
-- #interrupt-cells 	: Should be 2.  The first cell is the GPIO number.
-			  The second cell bits[3:0] is used to specify trigger
-			  type and level flags:
-			      1 = low-to-high edge triggered.
-			      2 = high-to-low edge triggered.
-			      4 = active high level-sensitive.
-			      8 = active low level-sensitive.
+
+- interrupt-parent     : The parent interrupt controller, optional if inherited
 
 The gpio and interrupt properties are further described in their respective
 bindings documentation:
@@ -34,9 +28,9 @@ bindings documentation:
   Example:
 	gpio@1e780000 {
 		#gpio-cells = <2>;
-		compatible = "aspeed,ast2400-gpio"
+		compatible = "aspeed,ast2400-gpio";
 		gpio-controller;
-		interrupt-parent = <&intc>;
 		interrupts = <20>;
 		reg = <0x1e780000 0x1000>;
+		interrupt-controller;
 	};
Signature · 1 line
2.9.3
#2 lore raw

PATCH 2/14 gpio: aspeed: Reset to mainline

In reply to Andrew Jeffery
---
 drivers/gpio/Kconfig       |  13 +++--
 drivers/gpio/gpio-aspeed.c | 137 ++++++++++++++++++++-------------------------
 2 files changed, 69 insertions(+), 81 deletions(-)
drivers/gpio/Kconfig +7 -6
index a9c816f795ac..094d3a12d9f6 100644
@@ -128,6 +128,13 @@ config GPIO_AMDPT
 	  driver for GPIO functionality on Promontory IOHub
 	  Require ACPI ASL code to enumerate as a platform device.
 
+config GPIO_ASPEED
+	tristate "Aspeed GPIO support"
+	depends on (ARCH_ASPEED || COMPILE_TEST) && OF_GPIO
+	select GPIOLIB_IRQCHIP
+	help
+	  Say Y here to support Aspeed AST2400 and AST2500 GPIO controllers.
+
 config GPIO_ATH79
 	tristate "Atheros AR71XX/AR724X/AR913X GPIO support"
 	default y if ATH79
@@ -138,12 +145,6 @@ config GPIO_ATH79
 	  Select this option to enable GPIO driver for
 	  Atheros AR71XX/AR724X/AR913X SoC devices.
 
-config GPIO_ASPEED
-	bool "Aspeed GPIO support"
-	depends on (ARCH_ASPEED || COMPILE_TEST) && OF
-	select GENERIC_IRQ_CHIP
-	help
-	  Say Y here to support Aspeed AST2400 and AST2500 GPIO controllers.
 
 config GPIO_BCM_KONA
 	bool "Broadcom Kona GPIO"
drivers/gpio/gpio-aspeed.c +62 -75

281 lines not on this page · raw message

Signature · 1 line
2.9.3
#3 lore raw

PATCH 3/14 aspeed: dt: Mark GPIO controller as interrupt-controller

In reply to Andrew Jeffery

This brings the devicetree into line with the mainline bindings.

---
 arch/arm/boot/dts/aspeed-g4.dtsi | 1 +
 arch/arm/boot/dts/aspeed-g5.dtsi | 1 +
 2 files changed, 2 insertions(+)
arch/arm/boot/dts/aspeed-g4.dtsi +1 -0
index 7c78eb1c01ff..28408a2e2ad5 100644
@@ -851,6 +851,7 @@
 				compatible = "aspeed,ast2400-gpio";
 				reg = <0x1e780000 0x1000>;
 				interrupts = <20>;
+				interrupt-controller;
 				gpio-ranges = <&pinctrl 0 0 220>;
 			};
 
arch/arm/boot/dts/aspeed-g5.dtsi +1 -0
index 7b1297b7f3da..14e03d8d35dc 100644
@@ -1016,6 +1016,7 @@
 				compatible = "aspeed,ast2500-gpio";
 				reg = <0x1e780000 0x1000>;
 				interrupts = <20>;
+				interrupt-controller;
 				gpio-ranges = <&pinctrl 0 0 220>;
 			};
 
Signature · 1 line
2.9.3
#4 lore raw

PATCH 4/14 gpio: aspeed: Make bank names strings

In reply to Andrew Jeffery

From: Joel Stanley <[email protected]>

The Aspeed SoCs have more GPIOs than can be represented with A-Z. The documentation uses two letter names such as AA and AB, so make the names a three-character array in the bank struct to accommodate this.

(cherry picked from commit 7153f8ef679d5fcb2d9c69a19613399194600f5b)
---
 drivers/gpio/gpio-aspeed.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/gpio/gpio-aspeed.c +7 -7
index 03a5925a423c..20f6f8ae4671 100644
@@ -28,39 +28,39 @@ struct aspeed_gpio {
 struct aspeed_gpio_bank {
 	uint16_t	val_regs;
 	uint16_t	irq_regs;
-	const char	names[4];
+	const char	names[4][3];
 };
 
 static const struct aspeed_gpio_bank aspeed_gpio_banks[] = {
 	{
 		.val_regs = 0x0000,
 		.irq_regs = 0x0008,
-		.names = { 'A', 'B', 'C', 'D' },
+		.names = { "A", "B", "C", "D" },
 	},
 	{
 		.val_regs = 0x0020,
 		.irq_regs = 0x0028,
-		.names = { 'E', 'F', 'G', 'H' },
+		.names = { "E", "F", "G", "H" },
 	},
 	{
 		.val_regs = 0x0070,
 		.irq_regs = 0x0098,
-		.names = { 'I', 'J', 'K', 'L' },
+		.names = { "I", "J", "K", "L" },
 	},
 	{
 		.val_regs = 0x0078,
 		.irq_regs = 0x00e8,
-		.names = { 'M', 'N', 'O', 'P' },
+		.names = { "M", "N", "O", "P" },
 	},
 	{
 		.val_regs = 0x0080,
 		.irq_regs = 0x0118,
-		.names = { 'Q', 'R', 'S', 'T' },
+		.names = { "Q", "R", "S", "T" },
 	},
 	{
 		.val_regs = 0x0088,
 		.irq_regs = 0x0148,
-		.names = { 'U', 'V', 'W', 'X' },
+		.names = { "U", "V", "W", "X" },
 	},
 	/*
 	 * A bank exists for { 'Y', 'Z', "AA", "AB" }, but is not implemented.
Signature · 1 line
2.9.3
#5 lore raw

PATCH 5/14 gpio: aspeed: Add banks Y, Z, AA, AB and AC

In reply to Andrew Jeffery

This is less straight-forward than one would hope, as some banks only have 4 pins rather than 8, others are output only, yet more (W and X, already supported) are input-only, and in the case of the g4 SoC bank AC doesn't exist.

Add some structs to describe the varying properties of different banks and integrate mechanisms to deny requests for unsupported configurations.

(cherry picked from commit 1736f75d35e47409ad776273133d0f558a4c8253)
[AJ: Drop irq valid code as it's not present in 4.7]
---
 drivers/gpio/gpio-aspeed.c | 149 ++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 135 insertions(+), 14 deletions(-)
drivers/gpio/gpio-aspeed.c +135 -14
index 20f6f8ae4671..cb37783ff857 100644
@@ -15,14 +15,27 @@
 #include <linux/io.h>
 #include <linux/spinlock.h>
 #include <linux/platform_device.h>
+#include <linux/gpio.h>
 #include <linux/gpio/driver.h>
 #include <linux/pinctrl/consumer.h>
 
+struct aspeed_bank_props {
+	unsigned int bank;
+	u32 input;
+	u32 output;
+};
+
+struct aspeed_gpio_config {
+	unsigned int nr_gpios;
+	const struct aspeed_bank_props *props;
+};
+
 struct aspeed_gpio {
 	struct gpio_chip chip;
 	spinlock_t lock;
 	void __iomem *base;
 	int irq;
+	const struct aspeed_gpio_config *config;
 };
 
 struct aspeed_gpio_bank {
@@ -62,11 +75,16 @@ static const struct aspeed_gpio_bank aspeed_gpio_banks[] = {
 		.irq_regs = 0x0148,
 		.names = { "U", "V", "W", "X" },
 	},
-	/*
-	 * A bank exists for { 'Y', 'Z', "AA", "AB" }, but is not implemented.
-	 * Only half of GPIOs Y support interrupt configuration, and none of Z,
-	 * AA or AB do as they are output only.
-	 */
+	{
+		.val_regs = 0x01E0,
+		.irq_regs = 0x0178,
+		.names = { "Y", "Z", "AA", "AB" },
+	},
+	{
+		.val_regs = 0x01E8,
+		.irq_regs = 0x01A8,
+		.names = { "AC", "", "", "" },
+	},
 };
 
 #define GPIO_BANK(x)	((x) >> 5)
@@ -90,6 +108,51 @@ static const struct aspeed_gpio_bank *to_bank(unsigned int offset)
 	return &aspeed_gpio_banks[bank];
 }
 
+static inline bool is_bank_props_sentinel(const struct aspeed_bank_props *props)
+{
+	return !(props->input || props->output);
+}
+
+static inline const struct aspeed_bank_props *find_bank_props(
+		struct aspeed_gpio *gpio, unsigned int offset)
+{
+	const struct aspeed_bank_props *props = gpio->config->props;
+
+	while (!is_bank_props_sentinel(props)) {
+		if (props->bank == GPIO_BANK(offset))
+			return props;
+		props++;
+	}
+
+	return NULL;
+}
+
+static inline bool have_gpio(struct aspeed_gpio *gpio, unsigned int offset)
+{
+	const struct aspeed_bank_props *props = find_bank_props(gpio, offset);
+	const struct aspeed_gpio_bank *bank = to_bank(offset);
+	unsigned int group = GPIO_OFFSET(offset) / 8;
+
+	return bank->names[group][0] != '\0' &&
+		(!props || ((props->input | props->output) & GPIO_BIT(offset)));
+}
+
+static inline bool have_input(struct aspeed_gpio *gpio, unsigned int offset)
+{
+	const struct aspeed_bank_props *props = find_bank_props(gpio, offset);
+
+	return !props || (props->input & GPIO_BIT(offset));
+}
+
+#define have_irq(g, o) have_input((g), (o))
+
+static inline bool have_output(struct aspeed_gpio *gpio, unsigned int offset)
+{
+	const struct aspeed_bank_props *props = find_bank_props(gpio, offset);
+
+	return !props || (props->output & GPIO_BIT(offset));
+}
+
 static void __iomem *bank_val_reg(struct aspeed_gpio *gpio,
 		const struct aspeed_gpio_bank *bank,
 		unsigned int reg)
@@ -152,6 +215,9 @@ static int aspeed_gpio_dir_in(struct gpio_chip *gc, unsigned int offset)
 	unsigned long flags;
 	u32 reg;
 
+	if (!have_input(gpio, offset))
+		return -ENOTSUPP;
+
 	spin_lock_irqsave(&gpio->lock, flags);
 
 	reg = ioread32(bank_val_reg(gpio, bank, GPIO_DIR));
@@ -170,6 +236,9 @@ static int aspeed_gpio_dir_out(struct gpio_chip *gc,
 	unsigned long flags;
 	u32 reg;
 
+	if (!have_output(gpio, offset))
+		return -ENOTSUPP;
+
 	spin_lock_irqsave(&gpio->lock, flags);
 
 	reg = ioread32(bank_val_reg(gpio, bank, GPIO_DIR));
@@ -189,6 +258,12 @@ static int aspeed_gpio_get_direction(struct gpio_chip *gc, unsigned int offset)
 	unsigned long flags;
 	u32 val;
 
+	if (!have_input(gpio, offset))
+		return GPIOF_DIR_OUT;
+
+	if (!have_output(gpio, offset))
+		return GPIOF_DIR_IN;
+
 	spin_lock_irqsave(&gpio->lock, flags);
 
 	val = ioread32(bank_val_reg(gpio, bank, GPIO_DIR)) & GPIO_BIT(offset);
@@ -205,10 +280,17 @@ static inline int irqd_to_aspeed_gpio_data(struct irq_data *d,
 		u32 *bit)
 {
 	int offset;
+	struct aspeed_gpio *internal;
 
 	offset = irqd_to_hwirq(d);
 
-	*gpio = irq_data_get_irq_chip_data(d);
+	internal = irq_data_get_irq_chip_data(d);
+
+	/* This might be a bit of a questionable place to check */
+	if (!have_irq(internal, offset))
+		return -ENOTSUPP;
+
+	*gpio = internal;
 	*bank = to_bank(offset);
 	*bit = GPIO_BIT(offset);
 
@@ -390,6 +472,9 @@ static int aspeed_gpio_setup_irqs(struct aspeed_gpio *gpio,
 
 static int aspeed_gpio_request(struct gpio_chip *chip, unsigned int offset)
 {
+	if (!have_gpio(gpiochip_get_data(chip), offset))
+		return -ENODEV;
+
 	return pinctrl_request_gpio(chip->base + offset);
 }
 
@@ -398,8 +483,46 @@ static void aspeed_gpio_free(struct gpio_chip *chip, unsigned int offset)
 	pinctrl_free_gpio(chip->base + offset);
 }
 
+/*
+ * Any banks not specified in a struct aspeed_bank_props array are assumed to
+ * have the properties:
+ *
+ *     { .input = 0xffffffff, .output = 0xffffffff }
+ */
+
+static const struct aspeed_bank_props ast2400_bank_props[] = {
+	/*     input	  output   */
+	{ 5, 0xffffffff, 0x0000ffff }, /* U/V/W/X */
+	{ 6, 0x0000000f, 0x0fffff0f }, /* Y/Z/AA/AB, two 4-GPIO holes */
+	{ },
+};
+
+static const struct aspeed_gpio_config ast2400_config =
+	/* 220 for simplicity, really 216 with two 4-GPIO holes, four at end */
+	{ .nr_gpios = 220, .props = ast2400_bank_props, };
+
+static const struct aspeed_bank_props ast2500_bank_props[] = {
+	/*     input	  output   */
+	{ 5, 0xffffffff, 0x0000ffff }, /* U/V/W/X */
+	{ 6, 0x0fffffff, 0x0fffffff }, /* Y/Z/AA/AB, 4-GPIO hole */
+	{ 7, 0x000000ff, 0x000000ff }, /* AC */
+	{ },
+};
+
+static const struct aspeed_gpio_config ast2500_config =
+	/* 232 for simplicity, actual number is 228 (4-GPIO hole in GPIOAB) */
+	{ .nr_gpios = 232, .props = ast2500_bank_props, };
+
+static const struct of_device_id aspeed_gpio_of_table[] = {
+	{ .compatible = "aspeed,ast2400-gpio", .data = &ast2400_config, },
+	{ .compatible = "aspeed,ast2500-gpio", .data = &ast2500_config, },
+	{}
+};
+MODULE_DEVICE_TABLE(of, aspeed_gpio_of_table);
+
 static int __init aspeed_gpio_probe(struct platform_device *pdev)
 {
+	const struct of_device_id *gpio_id;
 	struct aspeed_gpio *gpio;
 	struct resource *res;
 	int rc;
@@ -415,8 +538,13 @@ static int __init aspeed_gpio_probe(struct platform_device *pdev)
 
 	spin_lock_init(&gpio->lock);
 
-	gpio->chip.ngpio = ARRAY_SIZE(aspeed_gpio_banks) * 32;
+	gpio_id = of_match_node(aspeed_gpio_of_table, pdev->dev.of_node);
+	if (!gpio_id)
+		return -EINVAL;
 
+	gpio->config = gpio_id->data;
+
+	gpio->chip.ngpio = gpio->config->nr_gpios;
 	gpio->chip.parent = &pdev->dev;
 	gpio->chip.direction_input = aspeed_gpio_dir_in;
 	gpio->chip.direction_output = aspeed_gpio_dir_out;
@@ -435,13 +563,6 @@ static int __init aspeed_gpio_probe(struct platform_device *pdev)
 	return aspeed_gpio_setup_irqs(gpio, pdev);
 }
 
-static const struct of_device_id aspeed_gpio_of_table[] = {
-	{ .compatible = "aspeed,ast2400-gpio" },
-	{ .compatible = "aspeed,ast2500-gpio" },
-	{}
-};
-MODULE_DEVICE_TABLE(of, aspeed_gpio_of_table);
-
 static struct platform_driver aspeed_gpio_driver = {
 	.driver = {
 		.name = KBUILD_MODNAME,
Signature · 1 line
2.9.3
#6 lore raw
In reply to Andrew Jeffery

Hi all,

I've aborted the sending of this series. git send-email will by default Cc people who have tags on the patches, most of which are cherry-picked backports from upstream. This resulted in the backport series being sent to the GPIO/pinctrl maintainer, who is already stressed enough as it is[1].

I'll resend in a moment.

Apologies for the noise.

Andrew

[1] https://lists.ozlabs.org/pipermail/openbmc/2017-February/006366.html

Quoted 54 lines · Andrew Jeffery

Hi Joel,

This series gets the GPIO and pinctrl subsystems of dev-4.7 into the same state as upstream. A handful of patches reset things back to mainline, and then patches applied by the GPIO and pinctrl maintainer are cherry-picked in.

The series has three checkpatch warnings, one for "lack" of Kconfig symbol description in 2/14 (which simply resets some state to match mainline), a second for a duplicate S-o-B tag in 5/14 and another regarding commit message line length in 6/14. I've added my S-o-B twice in 5/14 because the patch doesn't backport cleanly and I had to remove some code. The commit message warning in 6/14 is for a link to the upstream patch and isn't appropriate to wrap.

Other than that, it builds with aspeed_g{4,5}_defconfigs and boots in Palmetto and Romulus QEMU machines. The cherry-picked patches have been tested on Palmetto and AST2500EVB hardware.

Please review.

Cheers,

Andrew

Andrew Jeffery (13):
  gpio: aspeed: dt: Reset bindings to mainline
  gpio: aspeed: Reset to mainline
  aspeed: dt: Mark GPIO controller as interrupt-controller
  gpio: aspeed: Add banks Y, Z, AA, AB and AC
  gpio: aspeed: Remove dependence on GPIOF_* macros
  aspeed: g5: dt: Update GPIO pin range to mux banks Y, Z, AA, AB, AC
  pinctrl: aspeed: Reset to mainline
  pinctrl: aspeed: dt: Fix compatibles for the System Control Unit
  pinctrl: aspeed: Read and write bits in LPC and GFX controllers
  pinctrl: aspeed-g4: Add mux configuration for all pins
  pinctrl: aspeed-g5: Add mux configuration for all pins
  pinctrl: aspeed: Fix kerneldoc return descriptions
  pinctrl: aspeed: g4: Fix mux configuration for GPIOs AA[4-7], AB[0-7]

Joel Stanley (1):
  gpio: aspeed: Make bank names strings

 .../devicetree/bindings/gpio/gpio-aspeed.txt       |  20 +- .../devicetree/bindings/pinctrl/pinctrl-aspeed.txt |  91 ++++++- arch/arm/boot/dts/aspeed-g4.dtsi                   |   1 + arch/arm/boot/dts/aspeed-g5.dtsi                   |   3 +- drivers/gpio/Kconfig                               |  13 +- drivers/gpio/gpio-aspeed.c                         | 299 ++++++++++++++------- drivers/pinctrl/aspeed/pinctrl-aspeed-g4.c         |  63 ++--- drivers/pinctrl/aspeed/pinctrl-aspeed-g5.c         |  76 ++++-- drivers/pinctrl/aspeed/pinctrl-aspeed.c            | 216 +++++++-------- drivers/pinctrl/aspeed/pinctrl-aspeed.h            |  48 ++--

 10 files changed, 507 insertions(+), 323 deletions(-)