Skip to contentSkip to conversation

gpio: Driver for SYSCON-based GPIOs

PATCH Superseded Alexander Shiyan 4 participants 4 messages Dec 17, 2013 – Jan 8, 2014

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 gpio: Driver for SYSCON-based GPIOs

SYSCON driver was designed for using memory areas (registers) that are used in several subsystems. There are systems (CPUs) which use bits in one register for various purposes and thus should be handled by various kernel subsystems. This driver allows you to use the individual SYSCON bits as GPIOs. ARM CLPS711X SYSFLG1 input lines has been added as first user of this driver.

---
 .../devicetree/bindings/gpio/gpio-syscon.txt       |  19 +++
 drivers/gpio/Kconfig                               |   6 +
 drivers/gpio/Makefile                              |   1 +
 drivers/gpio/gpio-syscon.c                         | 151 +++++++++++++++++++++
 4 files changed, 177 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/gpio/gpio-syscon.txt
 create mode 100644 drivers/gpio/gpio-syscon.c
Documentation/devicetree/bindings/gpio/gpio-syscon.txt new file +19 -0
new file mode 100644
index 0000000..47c4fda
@@ -0,0 +1,19 @@
+* SYSCON-based GPIO driver
+
+Required properties:
+- compatible: Should contain one of the following:
+  - "clps711x,syscon-gpio-mctrl": For ARM CLPS711X SYSFLG1 MCTRL GPIOs.
+- syscon: Phandle to syscon device node.
+- gpio-controller: Marks the device node as a gpio controller.
+- #gpio-cells: Should be two. The first cell is the pin number and
+  the second cell is used to specify the gpio polarity:
+    0 = Active high,
+    1 = Active low.
+
+Example:
+	sysgpio: sysgpio {
+		compatible = "clps711x,syscon-gpio-mctrl";
+		syscon = <&syscon1>;
+		gpio-controller;
+		#gpio-cells = <2>;
+	};
drivers/gpio/Kconfig +6 -0
index dfe1704..652a688 100644
@@ -259,6 +259,12 @@ config GPIO_STA2X11
 	  Say yes here to support the STA2x11/ConneXt GPIO device.
 	  The GPIO module has 128 GPIO pins with alternate functions.
 
+config GPIO_SYSCON
+	tristate "GPIO based on SYSCON"
+	depends on MFD_SYSCON && OF
+	help
+	  Say yes here to support GPIO functionality though SYSCON driver.
+
 config GPIO_TS5500
 	tristate "TS-5500 DIO blocks and compatibles"
 	help
drivers/gpio/Makefile +1 -0
index 6ae8402..bf2cef4 100644
@@ -75,6 +75,7 @@ obj-$(CONFIG_GPIO_STA2X11)	+= gpio-sta2x11.o
 obj-$(CONFIG_GPIO_STMPE)	+= gpio-stmpe.o
 obj-$(CONFIG_GPIO_STP_XWAY)	+= gpio-stp-xway.o
 obj-$(CONFIG_GPIO_SX150X)	+= gpio-sx150x.o
+obj-$(CONFIG_GPIO_SYSCON)	+= gpio-syscon.o
 obj-$(CONFIG_GPIO_TB10X)	+= gpio-tb10x.o
 obj-$(CONFIG_GPIO_TC3589X)	+= gpio-tc3589x.o
 obj-$(CONFIG_ARCH_TEGRA)	+= gpio-tegra.o
drivers/gpio/gpio-syscon.c new file +151 -0

151 lines not on this page · raw message

Signature · 6 lines
1.8.3.2

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#1 lore raw
Quoted 10 lines · On Tue, 17 Dec 2013 23:19:44 +0400 Alexander Shiyan <[email protected]> wrote:

SYSCON driver was designed for using memory areas (registers) that are used in several subsystems. There are systems (CPUs) which use bits in one register for various purposes and thus should be handled by various kernel subsystems. This driver allows you to use the individual SYSCON bits as GPIOs. ARM CLPS711X SYSFLG1 input lines has been added as first user of this driver.

---

Ping.

Signature · 1 line
Alexander Shiyan <[email protected]>
Acked-by on v2 1/1
#2 lore raw
In reply to Alexander Shiyan
Quoted 9 lines · Alexander Shiyan

SYSCON driver was designed for using memory areas (registers) that are used in several subsystems. There are systems (CPUs) which use bits in one register for various purposes and thus should be handled by various kernel subsystems. This driver allows you to use the individual SYSCON bits as GPIOs. ARM CLPS711X SYSFLG1 input lines has been added as first user of this driver.

Looks good to me.

#3 lore raw
In reply to Alexander Shiyan
Quoted 9 lines · Alexander Shiyan

SYSCON driver was designed for using memory areas (registers) that are used in several subsystems. There are systems (CPUs) which use bits in one register for various purposes and thus should be handled by various kernel subsystems. This driver allows you to use the individual SYSCON bits as GPIOs. ARM CLPS711X SYSFLG1 input lines has been added as first user of this driver.

Hm, this is nice in some ways but I'm reluctant still.
I really need input from the device tree maintainers on the bindings.

Won't be for v3.14 in any case. Let's get some more input on this thing.

Quoted 1 line

+++ b/drivers/gpio/gpio-syscon.c

(...)

drivers/gpio/gpio-syscon.c line 26

Quoted 6 lines
drivers/gpio/gpio-syscon.c new file +6 -0
+#define GPIO_SYSCON_INPUT      (1 << 0)
+#define GPIO_SYSCON_OUTPUT     (1 << 1)
+
+/* SYSCON driver is designed to use 32-bit wide registers */
+#define SYSCON_REG_SIZE                (4)
+#define SYSCON_REG_BITS                (SYSCON_REG_SIZE * 8)

This is nice.

Add kerneldoc to the following structs as this will be a very generic driver.

drivers/gpio/gpio-syscon.c line 30

Quoted 3 lines
drivers/gpio/gpio-syscon.c new file +3 -0
+struct syscon_gpio_data {
+       unsigned int    flags;
+       unsigned int    bit_offset;

Call it line_bit_offset

And I would add (per comment below) an optional dir_bit_offset as well.

Quoted 10 lines
drivers/gpio/gpio-syscon.c new file +9 -0
+       unsigned int    bit_count;
+};
+
+struct syscon_gpio_priv {
+       struct gpio_chip                chip;
+       struct regmap                   *syscon;
+       const struct syscon_gpio_data   *data;
+};
 
+static int syscon_gpio_dir_in(struct gpio_chip *chip, unsigned offset)

drivers/gpio/gpio-syscon.c line 80

Quoted 10 lines
drivers/gpio/gpio-syscon.c new file +10 -0
+{
+       return 0;
+}
+
+static int syscon_gpio_dir_out(struct gpio_chip *chip, unsigned offset, int val)
+{
+       syscon_gpio_set(chip, offset, val);
+
+       return 0;
+}

Should this not be supported by such a generic driver?

Atleast add a big fat TODO comment stating that the next user need to implement this.

Also struct syscon_gpio_data then should contain an dir_bit_offset for the direction bits.

Quoted 5 lines
drivers/gpio/gpio-syscon.c new file +5 -0
+static const struct syscon_gpio_data clps711x_mctrl_gpio = {
+       /* ARM CLPS711X SYSFLG1 Bits 8-10 */
+       .flags          = GPIO_SYSCON_INPUT,
+       .bit_offset     = 0x40 * 8 + 8,
+       .bit_count      = 3,

drivers/gpio/gpio-syscon.c line 96

Quoted 10 lines
drivers/gpio/gpio-syscon.c new file +10 -0
+};
+
+static const struct of_device_id syscon_gpio_ids[] = {
+       {
+               .compatible     = "clps711x,syscon-gpio-mctrl",
+               .data           = &clps711x_mctrl_gpio,
+       },
+       { }
+};
+MODULE_DEVICE_TABLE(of, syscon_gpio_ids);

Oh you're doing it like that :-)

That is actually helpful. Hm.

Yours,
Linus Walleij