gpio: Driver for SYSCON-based GPIOs
RFC PATCH 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. This is RFC only yet, so I did not add DT bindings for this driver.
--- drivers/gpio/Kconfig | 6 ++ drivers/gpio/Makefile | 1 + drivers/gpio/gpio-syscon.c | 141 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 148 insertions(+) create mode 100644 drivers/gpio/gpio-syscon.c
drivers/gpio/Kconfig +6 -0
@@ -252,6 +252,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
@@ -73,6 +73,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 +141 -0
141 lines not on this page · raw message
Signature · 1 line
1.8.1.5
Hi Alexander,
Quoted 16 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. This is RFC only yet, so I did not add DT bindings for this driver.
Signed-off-by Alexander Shiyan <[email protected]>--- drivers/gpio/Kconfig | 6 ++ drivers/gpio/Makefile | 1 + drivers/gpio/gpio-syscon.c | 141 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 148 insertions(+)create mode 100644
drivers/gpio/gpio-syscon.c
[snip]
drivers/gpio/gpio-syscon.c line 99
Quoted 2 lines
drivers/gpio/gpio-syscon.c new file +2
-0+if (of_property_read_u32 (np,"gpio-syscon,offset" , &priv->bit_offset)) +return -EINVAL ;
Any reason for dropping the error code from of_property_read_u32() in favor of fixed -EINVAL?
Br, David Cohen
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. This is RFC only yet, so I did not add DT bindings for this driver.
Signed-off-by Alexander Shiyan <[email protected]>
Good idea. I like the general concept.
drivers/gpio/gpio-syscon.c line 27
Quoted 4 lines
drivers/gpio/gpio-syscon.c new file +4
-0+struct syscon_gpio_priv { +struct gpio_chip chip; +struct regmap *syscon; +u32 bit_offset;
Use a simple unsigned int for bit offset please.
drivers/gpio/gpio-syscon.c line 46
Quoted 12 lines
drivers/gpio/gpio-syscon.c new file +12
-0+static int syscon_gpio_get (struct gpio_chip *chip,unsigned offset) +{ +struct syscon_gpio_priv *priv =to_syscon_gpio (chip); +unsigned int val; +int ret; + + ret =regmap_read (priv->syscon, priv->bit_offset /32 , &val); +if (ret <0 ) +return ret; + +return !!(val & (priv->bit_offset %32 )); +}
Grrr OK drivers/mfd/syscon has its regmap constrained like that:
static struct regmap_config syscon_regmap_config = {
.reg_bits = 32,
.val_bits = 32,
.reg_stride = 4,
};Assuming just like the people causing the y2k problem that "32 bits ought to fit everyone".
This is not your fault, but I'd like you to insert a big comment explaining that the syscon driver semantics hammer down the 32 bit register width and there is nothing you can do about it.
Yours,
Linus Walleij
Quoted 11 lines · Alexander Shiyan
Quoted 10 lines
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. This is RFC only yet, so I did not add DT bindings for this driver.
Signed-off-by Alexander Shiyan <[email protected]>
...
Quoted 21 lines
drivers/gpio/gpio-syscon.c line 46
Quoted 12 lines
drivers/gpio/gpio-syscon.c new file +12
-0+static int syscon_gpio_get (struct gpio_chip *chip,unsigned offset) +{ +struct syscon_gpio_priv *priv =to_syscon_gpio (chip); +unsigned int val; +int ret; + + ret =regmap_read (priv->syscon, priv->bit_offset /32 , &val); +if (ret <0 ) +return ret; + +return !!(val & (priv->bit_offset %32 )); +}Grrr OK
drivers/mfd/sysconhas its regmap constrained like that:static struct regmap_config syscon_regmap_config = { .reg_bits = 32, .val_bits = 32, .reg_stride = 4, };
Quoted 6 lines
Assuming just like the people causing the y2k problem that "32 bits ought to fit everyone".
This is not your fault, but I'd like you to insert a big comment explaining that the syscon driver semantics hammer down the 32 bit register width and there is nothing you can do about it.
You mean the comment in the source code or in the DT bindings? Thanks.
---
Quoted 11 lines · Alexander Shiyan
Quoted 8 lines · Alexander Shiyan
Assuming just like the people causing the y2k problem that "32 bits ought to fit everyone".
This is not your fault, but I'd like you to insert a big comment explaining that the syscon driver semantics hammer down the 32 bit register width and there is nothing you can do about it.
You mean the comment in the source code or in the DT bindings? Thanks.
In the source code right where you hardwire /32 and %32 etc.
Might as well use some
#define SYSCON_REG_WIDTH 32
Yours,
Linus Walleij