1 --- a/arch/mips/ath25/Kconfig
2 +++ b/arch/mips/ath25/Kconfig
3 @@ -7,6 +7,7 @@ config SOC_AR5312
5 bool "Atheros 2315+ support"
11 --- a/arch/mips/ath25/ar2315.c
12 +++ b/arch/mips/ath25/ar2315.c
13 @@ -240,6 +240,32 @@ static struct platform_device ar2315_wdt
14 .num_resources = ARRAY_SIZE(ar2315_wdt_res)
17 +static struct resource ar2315_gpio_res[] = {
19 + .name = "ar2315-gpio",
20 + .flags = IORESOURCE_MEM,
21 + .start = AR2315_RST_BASE + AR2315_GPIO,
22 + .end = AR2315_RST_BASE + AR2315_GPIO + 0x10 - 1,
25 + .name = "ar2315-gpio",
26 + .flags = IORESOURCE_IRQ,
29 + .name = "ar2315-gpio-irq-base",
30 + .flags = IORESOURCE_IRQ,
31 + .start = AR231X_GPIO_IRQ_BASE,
32 + .end = AR231X_GPIO_IRQ_BASE,
36 +static struct platform_device ar2315_gpio = {
38 + .name = "ar2315-gpio",
39 + .resource = ar2315_gpio_res,
40 + .num_resources = ARRAY_SIZE(ar2315_gpio_res)
43 #ifdef CONFIG_LEDS_GPIO
44 static struct gpio_led ar2315_leds[6];
45 static struct gpio_led_platform_data ar2315_led_data = {
46 @@ -290,6 +316,11 @@ void __init ar2315_init_devices(void)
47 ath25_find_config(AR2315_SPI_READ_BASE, AR2315_SPI_READ_SIZE);
48 ar2315_eth_data.macaddr = ath25_board.config->enet0_mac;
50 + ar2315_gpio_res[1].start = irq_create_mapping(ar2315_misc_irq_domain,
51 + AR2315_MISC_IRQ_GPIO);
52 + ar2315_gpio_res[1].end = ar2315_gpio_res[1].start;
53 + platform_device_register(&ar2315_gpio);
55 ar2315_init_gpio_leds();
57 ar2315_wdt_res[1].start = irq_create_mapping(ar2315_misc_irq_domain,
58 --- a/drivers/gpio/Kconfig
59 +++ b/drivers/gpio/Kconfig
60 @@ -112,6 +112,13 @@ config GPIO_MAX730X
62 comment "Memory mapped GPIO drivers:"
65 + bool "AR2315 SoC GPIO support"
66 + default y if SOC_AR2315
67 + depends on SOC_AR2315
69 + Say yes here to enable GPIO support for Atheros AR2315+ SoCs.
72 bool "AR5312 SoC GPIO support"
73 default y if SOC_AR5312
74 --- a/drivers/gpio/Makefile
75 +++ b/drivers/gpio/Makefile
76 @@ -17,6 +17,7 @@ obj-$(CONFIG_GPIO_ADNP) += gpio-adnp.o
77 obj-$(CONFIG_GPIO_ADP5520) += gpio-adp5520.o
78 obj-$(CONFIG_GPIO_ADP5588) += gpio-adp5588.o
79 obj-$(CONFIG_GPIO_AMD8111) += gpio-amd8111.o
80 +obj-$(CONFIG_GPIO_AR2315) += gpio-ar2315.o
81 obj-$(CONFIG_GPIO_AR5312) += gpio-ar5312.o
82 obj-$(CONFIG_GPIO_ARIZONA) += gpio-arizona.o
83 obj-$(CONFIG_GPIO_BCM_KONA) += gpio-bcm-kona.o
85 +++ b/drivers/gpio/gpio-ar2315.c
88 + * This file is subject to the terms and conditions of the GNU General Public
89 + * License. See the file "COPYING" in the main directory of this archive
92 + * Copyright (C) 2003 Atheros Communications, Inc., All Rights Reserved.
93 + * Copyright (C) 2006 FON Technology, SL.
94 + * Copyright (C) 2006 Imre Kaloz <kaloz@openwrt.org>
95 + * Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
96 + * Copyright (C) 2012 Alexandros C. Couloumbis <alex@ozo.com>
99 +#include <linux/kernel.h>
100 +#include <linux/init.h>
101 +#include <linux/platform_device.h>
102 +#include <linux/gpio.h>
103 +#include <linux/irq.h>
105 +#define DRIVER_NAME "ar2315-gpio"
107 +#define AR2315_GPIO_DI 0x0000
108 +#define AR2315_GPIO_DO 0x0008
109 +#define AR2315_GPIO_DIR 0x0010
110 +#define AR2315_GPIO_INT 0x0018
112 +#define AR2315_GPIO_DIR_M(x) (1 << (x)) /* mask for i/o */
113 +#define AR2315_GPIO_DIR_O(x) (1 << (x)) /* output */
114 +#define AR2315_GPIO_DIR_I(x) (0) /* input */
116 +#define AR2315_GPIO_INT_NUM_M 0x3F /* mask for GPIO num */
117 +#define AR2315_GPIO_INT_TRIG(x) ((x) << 6) /* interrupt trigger */
118 +#define AR2315_GPIO_INT_TRIG_M (0x3 << 6) /* mask for int trig */
120 +#define AR2315_GPIO_INT_TRIG_OFF 0 /* Triggerring off */
121 +#define AR2315_GPIO_INT_TRIG_LOW 1 /* Low Level Triggered */
122 +#define AR2315_GPIO_INT_TRIG_HIGH 2 /* High Level Triggered */
123 +#define AR2315_GPIO_INT_TRIG_EDGE 3 /* Edge Triggered */
125 +#define AR2315_GPIO_NUM 22
127 +static u32 ar2315_gpio_intmask;
128 +static u32 ar2315_gpio_intval;
129 +static unsigned ar2315_gpio_irq_base;
130 +static void __iomem *ar2315_mem;
132 +static inline u32 ar2315_gpio_reg_read(unsigned reg)
134 + return __raw_readl(ar2315_mem + reg);
137 +static inline void ar2315_gpio_reg_write(unsigned reg, u32 val)
139 + __raw_writel(val, ar2315_mem + reg);
142 +static inline void ar2315_gpio_reg_mask(unsigned reg, u32 mask, u32 val)
144 + ar2315_gpio_reg_write(reg, (ar2315_gpio_reg_read(reg) & ~mask) | val);
147 +static void ar2315_gpio_irq_handler(unsigned irq, struct irq_desc *desc)
152 + /* only do one gpio interrupt at a time */
153 + pend = ar2315_gpio_reg_read(AR2315_GPIO_DI);
154 + pend ^= ar2315_gpio_intval;
155 + pend &= ar2315_gpio_intmask;
158 + bit = fls(pend) - 1;
159 + pend &= ~(1 << bit);
160 + ar2315_gpio_intval ^= (1 << bit);
163 + /* Enable interrupt with edge detection */
164 + if ((ar2315_gpio_reg_read(AR2315_GPIO_DIR) & AR2315_GPIO_DIR_M(bit)) !=
165 + AR2315_GPIO_DIR_I(bit))
169 + generic_handle_irq(ar2315_gpio_irq_base + bit);
172 +static void ar2315_gpio_int_setup(unsigned gpio, int trig)
174 + u32 reg = ar2315_gpio_reg_read(AR2315_GPIO_INT);
176 + reg &= ~(AR2315_GPIO_INT_NUM_M | AR2315_GPIO_INT_TRIG_M);
177 + reg |= gpio | AR2315_GPIO_INT_TRIG(trig);
178 + ar2315_gpio_reg_write(AR2315_GPIO_INT, reg);
181 +static void ar2315_gpio_irq_unmask(struct irq_data *d)
183 + unsigned gpio = d->irq - ar2315_gpio_irq_base;
184 + u32 dir = ar2315_gpio_reg_read(AR2315_GPIO_DIR);
186 + /* Enable interrupt with edge detection */
187 + if ((dir & AR2315_GPIO_DIR_M(gpio)) != AR2315_GPIO_DIR_I(gpio))
190 + ar2315_gpio_intmask |= (1 << gpio);
191 + ar2315_gpio_int_setup(gpio, AR2315_GPIO_INT_TRIG_EDGE);
194 +static void ar2315_gpio_irq_mask(struct irq_data *d)
196 + unsigned gpio = d->irq - ar2315_gpio_irq_base;
198 + /* Disable interrupt */
199 + ar2315_gpio_intmask &= ~(1 << gpio);
200 + ar2315_gpio_int_setup(gpio, AR2315_GPIO_INT_TRIG_OFF);
203 +static struct irq_chip ar2315_gpio_irq_chip = {
204 + .name = DRIVER_NAME,
205 + .irq_unmask = ar2315_gpio_irq_unmask,
206 + .irq_mask = ar2315_gpio_irq_mask,
209 +static void ar2315_gpio_irq_init(unsigned irq)
213 + ar2315_gpio_intval = ar2315_gpio_reg_read(AR2315_GPIO_DI);
214 + for (i = 0; i < AR2315_GPIO_NUM; i++) {
215 + unsigned _irq = ar2315_gpio_irq_base + i;
217 + irq_set_chip_and_handler(_irq, &ar2315_gpio_irq_chip,
220 + irq_set_chained_handler(irq, ar2315_gpio_irq_handler);
223 +static int ar2315_gpio_get_val(struct gpio_chip *chip, unsigned gpio)
225 + return (ar2315_gpio_reg_read(AR2315_GPIO_DI) >> gpio) & 1;
228 +static void ar2315_gpio_set_val(struct gpio_chip *chip, unsigned gpio, int val)
230 + u32 reg = ar2315_gpio_reg_read(AR2315_GPIO_DO);
232 + reg = val ? reg | (1 << gpio) : reg & ~(1 << gpio);
233 + ar2315_gpio_reg_write(AR2315_GPIO_DO, reg);
236 +static int ar2315_gpio_dir_in(struct gpio_chip *chip, unsigned gpio)
238 + ar2315_gpio_reg_mask(AR2315_GPIO_DIR, 1 << gpio, 0);
242 +static int ar2315_gpio_dir_out(struct gpio_chip *chip, unsigned gpio, int val)
244 + ar2315_gpio_reg_mask(AR2315_GPIO_DIR, 0, 1 << gpio);
245 + ar2315_gpio_set_val(chip, gpio, val);
249 +static int ar2315_gpio_to_irq(struct gpio_chip *chip, unsigned gpio)
251 + return ar2315_gpio_irq_base + gpio;
254 +static struct gpio_chip ar2315_gpio_chip = {
255 + .label = DRIVER_NAME,
256 + .direction_input = ar2315_gpio_dir_in,
257 + .direction_output = ar2315_gpio_dir_out,
258 + .set = ar2315_gpio_set_val,
259 + .get = ar2315_gpio_get_val,
260 + .to_irq = ar2315_gpio_to_irq,
262 + .ngpio = AR2315_GPIO_NUM,
265 +static int ar2315_gpio_probe(struct platform_device *pdev)
267 + struct device *dev = &pdev->dev;
268 + struct resource *res;
275 + res = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
276 + "ar2315-gpio-irq-base");
278 + dev_err(dev, "not found GPIO IRQ base\n");
281 + ar2315_gpio_irq_base = res->start;
283 + res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, DRIVER_NAME);
285 + dev_err(dev, "not found IRQ number\n");
290 + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, DRIVER_NAME);
291 + ar2315_mem = devm_ioremap_resource(dev, res);
292 + if (IS_ERR(ar2315_mem))
293 + return PTR_ERR(ar2315_mem);
295 + ar2315_gpio_chip.dev = dev;
296 + ret = gpiochip_add(&ar2315_gpio_chip);
298 + dev_err(dev, "failed to add gpiochip\n");
302 + ar2315_gpio_irq_init(irq);
307 +static struct platform_driver ar2315_gpio_driver = {
308 + .probe = ar2315_gpio_probe,
310 + .name = DRIVER_NAME,
311 + .owner = THIS_MODULE,
315 +static int __init ar2315_gpio_init(void)
317 + return platform_driver_register(&ar2315_gpio_driver);
319 +subsys_initcall(ar2315_gpio_init);