1 --- a/arch/mips/ath25/Kconfig
2 +++ b/arch/mips/ath25/Kconfig
3 @@ -7,4 +7,5 @@ config SOC_AR5312
5 bool "Atheros 2315+ support"
9 --- a/arch/mips/ath25/ar2315.c
10 +++ b/arch/mips/ath25/ar2315.c
11 @@ -236,6 +236,32 @@ static struct platform_device ar2315_wdt
12 .num_resources = ARRAY_SIZE(ar2315_wdt_res)
15 +static struct resource ar2315_gpio_res[] = {
17 + .name = "ar2315-gpio",
18 + .flags = IORESOURCE_MEM,
19 + .start = AR2315_RST_BASE + AR2315_GPIO,
20 + .end = AR2315_RST_BASE + AR2315_GPIO + 0x10 - 1,
23 + .name = "ar2315-gpio",
24 + .flags = IORESOURCE_IRQ,
27 + .name = "ar2315-gpio-irq-base",
28 + .flags = IORESOURCE_IRQ,
29 + .start = AR231X_GPIO_IRQ_BASE,
30 + .end = AR231X_GPIO_IRQ_BASE,
34 +static struct platform_device ar2315_gpio = {
36 + .name = "ar2315-gpio",
37 + .resource = ar2315_gpio_res,
38 + .num_resources = ARRAY_SIZE(ar2315_gpio_res)
41 #ifdef CONFIG_LEDS_GPIO
42 static struct gpio_led ar2315_leds[6];
43 static struct gpio_led_platform_data ar2315_led_data = {
44 @@ -286,6 +312,11 @@ void __init ar2315_init_devices(void)
45 ath25_find_config(AR2315_SPI_READ_BASE, AR2315_SPI_READ_SIZE);
46 ar2315_eth_data.macaddr = ath25_board.config->enet0_mac;
48 + ar2315_gpio_res[1].start = irq_create_mapping(ar2315_misc_irq_domain,
49 + AR2315_MISC_IRQ_GPIO);
50 + ar2315_gpio_res[1].end = ar2315_gpio_res[1].start;
51 + platform_device_register(&ar2315_gpio);
53 ar2315_init_gpio_leds();
55 ar2315_wdt_res[1].start = irq_create_mapping(ar2315_misc_irq_domain,
56 --- a/drivers/gpio/Kconfig
57 +++ b/drivers/gpio/Kconfig
58 @@ -112,6 +112,13 @@ config GPIO_MAX730X
60 comment "Memory mapped GPIO drivers:"
63 + bool "AR2315 SoC GPIO support"
64 + default y if SOC_AR2315
65 + depends on SOC_AR2315
67 + Say yes here to enable GPIO support for Atheros AR2315+ SoCs.
70 bool "AR5312 SoC GPIO support"
71 default y if SOC_AR5312
72 --- a/drivers/gpio/Makefile
73 +++ b/drivers/gpio/Makefile
74 @@ -17,6 +17,7 @@ obj-$(CONFIG_GPIO_ADNP) += gpio-adnp.o
75 obj-$(CONFIG_GPIO_ADP5520) += gpio-adp5520.o
76 obj-$(CONFIG_GPIO_ADP5588) += gpio-adp5588.o
77 obj-$(CONFIG_GPIO_AMD8111) += gpio-amd8111.o
78 +obj-$(CONFIG_GPIO_AR2315) += gpio-ar2315.o
79 obj-$(CONFIG_GPIO_AR5312) += gpio-ar5312.o
80 obj-$(CONFIG_GPIO_ARIZONA) += gpio-arizona.o
81 obj-$(CONFIG_GPIO_BCM_KONA) += gpio-bcm-kona.o
83 +++ b/drivers/gpio/gpio-ar2315.c
86 + * This file is subject to the terms and conditions of the GNU General Public
87 + * License. See the file "COPYING" in the main directory of this archive
90 + * Copyright (C) 2003 Atheros Communications, Inc., All Rights Reserved.
91 + * Copyright (C) 2006 FON Technology, SL.
92 + * Copyright (C) 2006 Imre Kaloz <kaloz@openwrt.org>
93 + * Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
94 + * Copyright (C) 2012 Alexandros C. Couloumbis <alex@ozo.com>
97 +#include <linux/kernel.h>
98 +#include <linux/init.h>
99 +#include <linux/platform_device.h>
100 +#include <linux/gpio.h>
101 +#include <linux/irq.h>
103 +#define DRIVER_NAME "ar2315-gpio"
105 +#define AR2315_GPIO_DI 0x0000
106 +#define AR2315_GPIO_DO 0x0008
107 +#define AR2315_GPIO_DIR 0x0010
108 +#define AR2315_GPIO_INT 0x0018
110 +#define AR2315_GPIO_DIR_M(x) (1 << (x)) /* mask for i/o */
111 +#define AR2315_GPIO_DIR_O(x) (1 << (x)) /* output */
112 +#define AR2315_GPIO_DIR_I(x) (0) /* input */
114 +#define AR2315_GPIO_INT_NUM_M 0x3F /* mask for GPIO num */
115 +#define AR2315_GPIO_INT_TRIG(x) ((x) << 6) /* interrupt trigger */
116 +#define AR2315_GPIO_INT_TRIG_M (0x3 << 6) /* mask for int trig */
118 +#define AR2315_GPIO_INT_TRIG_OFF 0 /* Triggerring off */
119 +#define AR2315_GPIO_INT_TRIG_LOW 1 /* Low Level Triggered */
120 +#define AR2315_GPIO_INT_TRIG_HIGH 2 /* High Level Triggered */
121 +#define AR2315_GPIO_INT_TRIG_EDGE 3 /* Edge Triggered */
123 +#define AR2315_GPIO_NUM 22
125 +static u32 ar2315_gpio_intmask;
126 +static u32 ar2315_gpio_intval;
127 +static unsigned ar2315_gpio_irq_base;
128 +static void __iomem *ar2315_mem;
130 +static inline u32 ar2315_gpio_reg_read(unsigned reg)
132 + return __raw_readl(ar2315_mem + reg);
135 +static inline void ar2315_gpio_reg_write(unsigned reg, u32 val)
137 + __raw_writel(val, ar2315_mem + reg);
140 +static inline void ar2315_gpio_reg_mask(unsigned reg, u32 mask, u32 val)
142 + ar2315_gpio_reg_write(reg, (ar2315_gpio_reg_read(reg) & ~mask) | val);
145 +static void ar2315_gpio_irq_handler(unsigned irq, struct irq_desc *desc)
150 + /* only do one gpio interrupt at a time */
151 + pend = ar2315_gpio_reg_read(AR2315_GPIO_DI);
152 + pend ^= ar2315_gpio_intval;
153 + pend &= ar2315_gpio_intmask;
156 + bit = fls(pend) - 1;
157 + pend &= ~(1 << bit);
158 + ar2315_gpio_intval ^= (1 << bit);
161 + /* Enable interrupt with edge detection */
162 + if ((ar2315_gpio_reg_read(AR2315_GPIO_DIR) & AR2315_GPIO_DIR_M(bit)) !=
163 + AR2315_GPIO_DIR_I(bit))
167 + generic_handle_irq(ar2315_gpio_irq_base + bit);
170 +static void ar2315_gpio_int_setup(unsigned gpio, int trig)
172 + u32 reg = ar2315_gpio_reg_read(AR2315_GPIO_INT);
174 + reg &= ~(AR2315_GPIO_INT_NUM_M | AR2315_GPIO_INT_TRIG_M);
175 + reg |= gpio | AR2315_GPIO_INT_TRIG(trig);
176 + ar2315_gpio_reg_write(AR2315_GPIO_INT, reg);
179 +static void ar2315_gpio_irq_unmask(struct irq_data *d)
181 + unsigned gpio = d->irq - ar2315_gpio_irq_base;
182 + u32 dir = ar2315_gpio_reg_read(AR2315_GPIO_DIR);
184 + /* Enable interrupt with edge detection */
185 + if ((dir & AR2315_GPIO_DIR_M(gpio)) != AR2315_GPIO_DIR_I(gpio))
188 + ar2315_gpio_intmask |= (1 << gpio);
189 + ar2315_gpio_int_setup(gpio, AR2315_GPIO_INT_TRIG_EDGE);
192 +static void ar2315_gpio_irq_mask(struct irq_data *d)
194 + unsigned gpio = d->irq - ar2315_gpio_irq_base;
196 + /* Disable interrupt */
197 + ar2315_gpio_intmask &= ~(1 << gpio);
198 + ar2315_gpio_int_setup(gpio, AR2315_GPIO_INT_TRIG_OFF);
201 +static struct irq_chip ar2315_gpio_irq_chip = {
202 + .name = DRIVER_NAME,
203 + .irq_unmask = ar2315_gpio_irq_unmask,
204 + .irq_mask = ar2315_gpio_irq_mask,
207 +static void ar2315_gpio_irq_init(unsigned irq)
211 + ar2315_gpio_intval = ar2315_gpio_reg_read(AR2315_GPIO_DI);
212 + for (i = 0; i < AR2315_GPIO_NUM; i++) {
213 + unsigned _irq = ar2315_gpio_irq_base + i;
215 + irq_set_chip_and_handler(_irq, &ar2315_gpio_irq_chip,
218 + irq_set_chained_handler(irq, ar2315_gpio_irq_handler);
221 +static int ar2315_gpio_get_val(struct gpio_chip *chip, unsigned gpio)
223 + return (ar2315_gpio_reg_read(AR2315_GPIO_DI) >> gpio) & 1;
226 +static void ar2315_gpio_set_val(struct gpio_chip *chip, unsigned gpio, int val)
228 + u32 reg = ar2315_gpio_reg_read(AR2315_GPIO_DO);
230 + reg = val ? reg | (1 << gpio) : reg & ~(1 << gpio);
231 + ar2315_gpio_reg_write(AR2315_GPIO_DO, reg);
234 +static int ar2315_gpio_dir_in(struct gpio_chip *chip, unsigned gpio)
236 + ar2315_gpio_reg_mask(AR2315_GPIO_DIR, 1 << gpio, 0);
240 +static int ar2315_gpio_dir_out(struct gpio_chip *chip, unsigned gpio, int val)
242 + ar2315_gpio_reg_mask(AR2315_GPIO_DIR, 0, 1 << gpio);
243 + ar2315_gpio_set_val(chip, gpio, val);
247 +static int ar2315_gpio_to_irq(struct gpio_chip *chip, unsigned gpio)
249 + return ar2315_gpio_irq_base + gpio;
252 +static struct gpio_chip ar2315_gpio_chip = {
253 + .label = DRIVER_NAME,
254 + .direction_input = ar2315_gpio_dir_in,
255 + .direction_output = ar2315_gpio_dir_out,
256 + .set = ar2315_gpio_set_val,
257 + .get = ar2315_gpio_get_val,
258 + .to_irq = ar2315_gpio_to_irq,
260 + .ngpio = AR2315_GPIO_NUM,
263 +static int ar2315_gpio_probe(struct platform_device *pdev)
265 + struct device *dev = &pdev->dev;
266 + struct resource *res;
273 + res = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
274 + "ar2315-gpio-irq-base");
276 + dev_err(dev, "not found GPIO IRQ base\n");
279 + ar2315_gpio_irq_base = res->start;
281 + res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, DRIVER_NAME);
283 + dev_err(dev, "not found IRQ number\n");
288 + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, DRIVER_NAME);
289 + ar2315_mem = devm_ioremap_resource(dev, res);
290 + if (IS_ERR(ar2315_mem))
291 + return PTR_ERR(ar2315_mem);
293 + ar2315_gpio_chip.dev = dev;
294 + ret = gpiochip_add(&ar2315_gpio_chip);
296 + dev_err(dev, "failed to add gpiochip\n");
300 + ar2315_gpio_irq_init(irq);
305 +static struct platform_driver ar2315_gpio_driver = {
306 + .probe = ar2315_gpio_probe,
308 + .name = DRIVER_NAME,
309 + .owner = THIS_MODULE,
313 +static int __init ar2315_gpio_init(void)
315 + return platform_driver_register(&ar2315_gpio_driver);
317 +subsys_initcall(ar2315_gpio_init);