diff options
| author | Linus Walleij <linus.walleij@linaro.org> | 2015-12-04 08:02:58 -0500 |
|---|---|---|
| committer | Linus Walleij <linus.walleij@linaro.org> | 2016-01-05 05:21:00 -0500 |
| commit | 0f4630f3720e7e6e921bf525c8357fea7ef3dbab (patch) | |
| tree | 61c1904593d1ee424464c2d57668ba0fd2fbcbb4 /include/linux/gpio | |
| parent | 3208b0f0c010b26e4d461a3bca59989d03ed9087 (diff) | |
gpio: generic: factor into gpio_chip struct
The separate struct bgpio_chip has been a pain to handle, both
by being confusingly similar in name to struct gpio_chip and
for being contained inside a struct so that struct gpio_chip
is contained in a struct contained in a struct, making several
steps of dereferencing necessary.
Make things simpler: include the fields directly into
<linux/gpio/driver.h>, #ifdef:ed for CONFIG_GENERIC_GPIO, and
get rid of the <linux/basic_mmio_gpio.h> altogether. Prefix
some of the member variables with bgpio_* and add proper
kerneldoc while we're at it.
Modify all users to handle the change and use a struct
gpio_chip directly. And while we're at it: replace all
container_of() dereferencing by gpiochip_get_data() and
registering the gpio_chip with gpiochip_add_data().
Cc: arm@kernel.org
Cc: Alexander Shiyan <shc_work@mail.ru>
Cc: Shawn Guo <shawnguo@kernel.org>
Cc: Sascha Hauer <kernel@pengutronix.de>
Cc: Kukjin Kim <kgene@kernel.org>
Cc: Alexandre Courbot <gnurou@gmail.com>
Cc: Brian Norris <computersforpeace@gmail.com>
Cc: Florian Fainelli <f.fainelli@gmail.com>
Cc: Sudeep Holla <sudeep.holla@arm.com>
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Nicolas Pitre <nicolas.pitre@linaro.org>
Cc: Olof Johansson <olof@lixom.net>
Cc: Vladimir Zapolskiy <vladimir_zapolskiy@mentor.com>
Cc: Rabin Vincent <rabin@rab.in>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-omap@vger.kernel.org
Cc: linux-samsung-soc@vger.kernel.org
Cc: bcm-kernel-feedback-list@broadcom.com
Acked-by: Gregory Fong <gregory.0xf0@gmail.com>
Acked-by: Liviu Dudau <Liviu.Dudau@arm.com>
Acked-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Acked-by: Tony Lindgren <tony@atomide.com>
Acked-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Acked-by: Lee Jones <lee.jones@linaro.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'include/linux/gpio')
| -rw-r--r-- | include/linux/gpio/driver.h | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index b833a5f9629a..e2d05fd0e6e3 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h | |||
| @@ -8,6 +8,7 @@ | |||
| 8 | #include <linux/irqdomain.h> | 8 | #include <linux/irqdomain.h> |
| 9 | #include <linux/lockdep.h> | 9 | #include <linux/lockdep.h> |
| 10 | #include <linux/pinctrl/pinctrl.h> | 10 | #include <linux/pinctrl/pinctrl.h> |
| 11 | #include <linux/kconfig.h> | ||
| 11 | 12 | ||
| 12 | struct device; | 13 | struct device; |
| 13 | struct gpio_desc; | 14 | struct gpio_desc; |
| @@ -65,6 +66,23 @@ struct seq_file; | |||
| 65 | * registers. | 66 | * registers. |
| 66 | * @irq_not_threaded: flag must be set if @can_sleep is set but the | 67 | * @irq_not_threaded: flag must be set if @can_sleep is set but the |
| 67 | * IRQs don't need to be threaded | 68 | * IRQs don't need to be threaded |
| 69 | * @read_reg: reader function for generic GPIO | ||
| 70 | * @write_reg: writer function for generic GPIO | ||
| 71 | * @pin2mask: some generic GPIO controllers work with the big-endian bits | ||
| 72 | * notation, e.g. in a 8-bits register, GPIO7 is the least significant | ||
| 73 | * bit. This callback assigns the right bit mask. | ||
| 74 | * @reg_dat: data (in) register for generic GPIO | ||
| 75 | * @reg_set: output set register (out=high) for generic GPIO | ||
| 76 | * @reg_clk: output clear register (out=low) for generic GPIO | ||
| 77 | * @reg_dir: direction setting register for generic GPIO | ||
| 78 | * @bgpio_bits: number of register bits used for a generic GPIO i.e. | ||
| 79 | * <register width> * 8 | ||
| 80 | * @bgpio_lock: used to lock chip->bgpio_data. Also, this is needed to keep | ||
| 81 | * shadowed and real data registers writes together. | ||
| 82 | * @bgpio_data: shadowed data register for generic GPIO to clear/set bits | ||
| 83 | * safely. | ||
| 84 | * @bgpio_dir: shadowed direction register for generic GPIO to clear/set | ||
| 85 | * direction safely. | ||
| 68 | * @irqchip: GPIO IRQ chip impl, provided by GPIO driver | 86 | * @irqchip: GPIO IRQ chip impl, provided by GPIO driver |
| 69 | * @irqdomain: Interrupt translation domain; responsible for mapping | 87 | * @irqdomain: Interrupt translation domain; responsible for mapping |
| 70 | * between GPIO hwirq number and linux irq number | 88 | * between GPIO hwirq number and linux irq number |
| @@ -128,6 +146,20 @@ struct gpio_chip { | |||
| 128 | bool can_sleep; | 146 | bool can_sleep; |
| 129 | bool irq_not_threaded; | 147 | bool irq_not_threaded; |
| 130 | 148 | ||
| 149 | #if IS_ENABLED(CONFIG_GPIO_GENERIC) | ||
| 150 | unsigned long (*read_reg)(void __iomem *reg); | ||
| 151 | void (*write_reg)(void __iomem *reg, unsigned long data); | ||
| 152 | unsigned long (*pin2mask)(struct gpio_chip *gc, unsigned int pin); | ||
| 153 | void __iomem *reg_dat; | ||
| 154 | void __iomem *reg_set; | ||
| 155 | void __iomem *reg_clr; | ||
| 156 | void __iomem *reg_dir; | ||
| 157 | int bgpio_bits; | ||
| 158 | spinlock_t bgpio_lock; | ||
| 159 | unsigned long bgpio_data; | ||
| 160 | unsigned long bgpio_dir; | ||
| 161 | #endif | ||
| 162 | |||
| 131 | #ifdef CONFIG_GPIOLIB_IRQCHIP | 163 | #ifdef CONFIG_GPIOLIB_IRQCHIP |
| 132 | /* | 164 | /* |
| 133 | * With CONFIG_GPIOLIB_IRQCHIP we get an irqchip inside the gpiolib | 165 | * With CONFIG_GPIOLIB_IRQCHIP we get an irqchip inside the gpiolib |
| @@ -188,6 +220,28 @@ static inline void *gpiochip_get_data(struct gpio_chip *chip) | |||
| 188 | 220 | ||
| 189 | struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc); | 221 | struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc); |
| 190 | 222 | ||
| 223 | #if IS_ENABLED(CONFIG_GPIO_GENERIC) | ||
| 224 | |||
| 225 | struct bgpio_pdata { | ||
| 226 | const char *label; | ||
| 227 | int base; | ||
| 228 | int ngpio; | ||
| 229 | }; | ||
| 230 | |||
| 231 | int bgpio_init(struct gpio_chip *gc, struct device *dev, | ||
| 232 | unsigned long sz, void __iomem *dat, void __iomem *set, | ||
| 233 | void __iomem *clr, void __iomem *dirout, void __iomem *dirin, | ||
| 234 | unsigned long flags); | ||
| 235 | |||
| 236 | #define BGPIOF_BIG_ENDIAN BIT(0) | ||
| 237 | #define BGPIOF_UNREADABLE_REG_SET BIT(1) /* reg_set is unreadable */ | ||
| 238 | #define BGPIOF_UNREADABLE_REG_DIR BIT(2) /* reg_dir is unreadable */ | ||
| 239 | #define BGPIOF_BIG_ENDIAN_BYTE_ORDER BIT(3) | ||
| 240 | #define BGPIOF_READ_OUTPUT_REG_SET BIT(4) /* reg_set stores output value */ | ||
| 241 | #define BGPIOF_NO_OUTPUT BIT(5) /* only input */ | ||
| 242 | |||
| 243 | #endif | ||
| 244 | |||
| 191 | #ifdef CONFIG_GPIOLIB_IRQCHIP | 245 | #ifdef CONFIG_GPIOLIB_IRQCHIP |
| 192 | 246 | ||
| 193 | void gpiochip_set_chained_irqchip(struct gpio_chip *gpiochip, | 247 | void gpiochip_set_chained_irqchip(struct gpio_chip *gpiochip, |
