GPIO: Add support for GPIO on CLPS711X-target platform
Subsystems (3)
PATCH 1/1 GPIO: Add support for GPIO on CLPS711X-target platform
The CLPS711X CPUs provide some GPIOs for use in the system. This driver provides support for these via gpiolib. Due to platform limitations, driver does not support interrupts, only inputs and outputs.
--- arch/arm/Kconfig | 1 + arch/arm/mach-clps711x/include/mach/gpio.h | 13 ++ drivers/gpio/Kconfig | 4 + drivers/gpio/Makefile | 1 + drivers/gpio/gpio-clps711x.c | 178 ++++++++++++++++++++++++++++ 5 files changed, 197 insertions(+), 0 deletions(-) create mode 100644 arch/arm/mach-clps711x/include/mach/gpio.h create mode 100644 drivers/gpio/gpio-clps711x.c
arch/arm/Kconfig +1 -0
@@ -384,6 +384,7 @@ config ARCH_CLPS711X bool "Cirrus Logic CLPS711x/EP721x/EP731x-based" select CPU_ARM720T select ARCH_USES_GETTIMEOFFSET + select ARCH_REQUIRE_GPIOLIB select NEED_MACH_MEMORY_H help Support for Cirrus Logic 711x/721x/731x based boards.
arch/arm/mach-clps711x/include/mach/gpio.h new file +13 -0
@@ -0,0 +1,13 @@ +/* +* This file contains the CLPS711X GPIO definitions. +* +* Copyright (C) 2012 Alexander Shiyan <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +*/ + +/* Simple helper for convert port & pin to GPIO number */ +#define CLPS711X_GPIO (port, bit) ((port) * 8 + (bit))
drivers/gpio/Kconfig +4 -0
@@ -91,6 +91,10 @@ config GPIO_MAX730X comment "Memory mapped GPIO drivers:" +config GPIO_CLPS711X + def_bool y + depends on ARCH_CLPS711X + config GPIO_GENERIC_PLATFORM tristate "Generic memory-mapped GPIO controller support (MMIO platform device)" select GPIO_GENERIC
drivers/gpio/Makefile +1 -0
@@ -15,6 +15,7 @@ obj-$(CONFIG_GPIO_ADP5588) += gpio-adp5588.o obj-$(CONFIG_GPIO_AMD8111) += gpio-amd8111.o obj-$(CONFIG_GPIO_ARIZONA) += gpio-arizona.o obj-$(CONFIG_GPIO_BT8XX) += gpio-bt8xx.o +obj-$(CONFIG_GPIO_CLPS711X) += gpio-clps711x.o obj-$(CONFIG_GPIO_CS5535) += gpio-cs5535.o obj-$(CONFIG_GPIO_DA9052) += gpio-da9052.o obj-$(CONFIG_ARCH_DAVINCI) += gpio-davinci.o
drivers/gpio/gpio-clps711x.c new file +178 -0
178 lines not on this page · raw message
Signature · 1 line
1.7.3.4
PATCH 1/1 GPIO: Add support for GPIO on CLPS711X-target platform
Quoted 4 lines · Alexander Shiyan
The CLPS711X CPUs provide some GPIOs for use in the system. This driver provides support for these via gpiolib. Due to platform limitations, driver does not support interrupts, only inputs and outputs.
OK...
(...)
drivers/gpio/gpio-clps711x.c line 25
Quoted 6 lines
drivers/gpio/gpio-clps711x.c new file +5
-0+#include <mach/hardware.h> +struct clps711x_gpio { +struct gpio_chip chip[CLPS711X_GPIO_PORTS ]; +struct mutex lock; +};
That lock is just protecting a few register reads/writes. Use a spinlock instead, it's more apropriate.
(...)
drivers/gpio/gpio-clps711x.c line 69
Quoted 11 lines
drivers/gpio/gpio-clps711x.c new file +11
-0+static int gpio_clps711x_get (struct gpio_chip *chip,unsigned offset) +{ +int ret; +struct clps711x_gpio *gpio =dev_get_drvdata (chip->dev); + +mutex_lock (&gpio->lock); + ret =clps_readb (gpio_clps711x_port_dataaddr (chip)) & (1 << offset); +mutex_unlock (&gpio->lock); + +return !!ret; +}
Please get rid of this clps_readb() business. I can see it's just this:
#define clps_readb(off) readb(CLPS711X_VIRT_BASE + (off))
This makes stuff hard to understand, please pass the virtual base as a memory resource to the platform device, store it in the state holder and just use readb() in the driver from that offset.
(...)
Quoted 1 line
+static int
__devinitgpio_clps711x_probe(struct platform_device *pdev)
This should just be __init, you have made it very certain that this cannot be loaded and unloaded at runtime. (No remove function!) and its a bool in the Kconfig.
Yours,
Linus Walleij
PATCH 1/1 GPIO: Add support for GPIO on CLPS711X-target platform
Hello.
On Fri, 24 Aug 2012 00:08:45 +0200
Linus Walleij <[email protected]> wrote:
...
Quoted 15 lines
drivers/gpio/gpio-clps711x.c line 69
Quoted 11 lines
drivers/gpio/gpio-clps711x.c new file +11
-0+static int gpio_clps711x_get (struct gpio_chip *chip,unsigned offset) +{ +int ret; +struct clps711x_gpio *gpio =dev_get_drvdata (chip->dev); + +mutex_lock (&gpio->lock); + ret =clps_readb (gpio_clps711x_port_dataaddr (chip)) & (1 << offset); +mutex_unlock (&gpio->lock); + +return !!ret; +}Please get rid of this
clps_readb()business. I can see it's just this:
#defineclps_readb(off)readb(CLPS711X_VIRT_BASE + (off))
Quoted 3 lines
This makes stuff hard to understand, please pass the virtual base as a memory resource to the platform device, store it in the state holder and just use
readb()in the driver from that offset.
This will break the whole concept of this platform. All the CPU registers are in one particular area, and therefore access to the registers of all the drivers performed using the macro.
Maybe just add a short comment?
Signature · 1 line
Alexander Shiyan <[email protected]>
PATCH 1/1 GPIO: Add support for GPIO on CLPS711X-target platform
Quoted 19 lines · Alexander Shiyan
On Fri, 24 Aug 2012 00:08:45 +0200
Linus Walleij <[email protected]> wrote:...
Quoted 15 lines
drivers/gpio/gpio-clps711x.c line 69
Quoted 11 lines
drivers/gpio/gpio-clps711x.c new file +11
-0+static int gpio_clps711x_get (struct gpio_chip *chip,unsigned offset) +{ +int ret; +struct clps711x_gpio *gpio =dev_get_drvdata (chip->dev); + +mutex_lock (&gpio->lock); + ret =clps_readb (gpio_clps711x_port_dataaddr (chip)) & (1 << offset); +mutex_unlock (&gpio->lock); + +return !!ret; +}Please get rid of this
clps_readb()business. I can see it's just this:
#defineclps_readb(off)readb(CLPS711X_VIRT_BASE + (off))
Quoted 8 lines
Quoted 3 lines
This makes stuff hard to understand, please pass the virtual base as a memory resource to the platform device, store it in the state holder and just use
readb()in the driver from that offset.This will break the whole concept of this platform. All the CPU registers are in one particular area, and therefore access to the registers of all the drivers performed using the macro.
Maybe just add a short comment?
It does not break if you pass the offset CLPS711X_VIRT_BASE as a memory resource and reference from that, e.g.:
Add a base:
struct clps711x_gpio {
struct gpio_chip chip[CLPS711X_GPIO_PORTS];
struct mutex lock;+ void __iomem *base;
};
Fish out the base from the platform device (provided it's added to the platform device) in .probe:
res = platform_get_resource(dev, IORESOURCE_MEM, 0);
if (!res) {
ret = -ENOENT;
goto out;
}gpio->base = res->start;
The access registers like this:
foo = readb(gpio->base + gpio_clps711x_port_diraddr(chip));
It's no big change, just that the offset is included in every access instead of using custom accessor functions which are in an obscure <mach/*> header, and we want to get rid of all such headers.
If you do this, you should no longer need to include <mach/hardware.h> (or something more is wrong...)
BTW I cannot see where this patch adds the platform device named "gpio-clps711x"? Are you intending to do this later?
Yours,
Linus Walleij
PATCH 1/1 GPIO: Add support for GPIO on CLPS711X-target platform
Quoted 12 lines · On Sat, 1 Sep 2012 00:44:10 +0200 Linus Walleij <[email protected]>…
Quoted 12 lines
...
Quoted 11 lines
Quoted 11 lines
drivers/gpio/gpio-clps711x.c new file +11
-0+static int gpio_clps711x_get (struct gpio_chip *chip,unsigned offset) +{ +int ret; +struct clps711x_gpio *gpio =dev_get_drvdata (chip->dev); + +mutex_lock (&gpio->lock); + ret =clps_readb (gpio_clps711x_port_dataaddr (chip)) & (1 << offset); +mutex_unlock (&gpio->lock); + +return !!ret; +}
...
Quoted 6 lines
Quoted 4 lines
This will break the whole concept of this platform. All the CPU registers are in one particular area, and therefore access to the registers of all the drivers performed using the macro.
Maybe just add a short comment?It does not break if you pass the offset
CLPS711X_VIRT_BASEas a memory resource and reference from that, e.g.:
...
Quoted 2 lines
If you do this, you should no longer need to include <
mach/hardware.h> (or something more is wrong...)
I plan in the future to remove the macros clps_read/write, and while the time to do an override for ports in the header mach/gpio.h.
Passing of resources to the driver still seems superfluous, in any case I changed the code, so please comment on the new version, which will post today.
Quoted 2 lines
BTW I cannot see where this patch adds the platform device named "gpio-clps711x"? Are you intending to do this later?
Yes, I forgot about it in the previous version. The new version of the code is different and it is no longer necessary.
Signature · 1 line
Alexander Shiyan <[email protected]>