1 --- a/arch/mips/ath25/Kconfig
2 +++ b/arch/mips/ath25/Kconfig
5 bool "Atheros 5312/2312+ support"
11 --- a/arch/mips/ath25/ar5312.c
12 +++ b/arch/mips/ath25/ar5312.c
13 @@ -192,6 +192,22 @@ static struct platform_device ar5312_phy
17 +static struct resource ar5312_gpio_res[] = {
19 + .name = "ar5312-gpio",
20 + .flags = IORESOURCE_MEM,
21 + .start = AR5312_GPIO,
22 + .end = AR5312_GPIO + 0x0c - 1,
26 +static struct platform_device ar5312_gpio = {
27 + .name = "ar5312-gpio",
29 + .resource = ar5312_gpio_res,
30 + .num_resources = ARRAY_SIZE(ar5312_gpio_res),
33 #ifdef CONFIG_LEDS_GPIO
34 static struct gpio_led ar5312_leds[] = {
35 { .name = "wlan", .gpio = 0, .active_low = 1, },
36 @@ -282,6 +298,8 @@ int __init ar5312_init_devices(void)
38 platform_device_register(&ar5312_physmap_flash);
40 + platform_device_register(&ar5312_gpio);
42 #ifdef CONFIG_LEDS_GPIO
43 ar5312_leds[0].gpio = config->sys_led_gpio;
44 platform_device_register(&ar5312_gpio_leds);
45 --- a/drivers/gpio/Kconfig
46 +++ b/drivers/gpio/Kconfig
47 @@ -112,6 +112,13 @@ config GPIO_MAX730X
49 comment "Memory mapped GPIO drivers:"
52 + bool "AR5312 SoC GPIO support"
53 + default y if SOC_AR5312
54 + depends on SOC_AR5312
56 + Say yes here to enable GPIO support for Atheros AR5312/AR2312+ SoCs.
59 tristate "CLPS711X GPIO support"
60 depends on ARCH_CLPS711X || COMPILE_TEST
61 --- a/drivers/gpio/Makefile
62 +++ b/drivers/gpio/Makefile
63 @@ -17,6 +17,7 @@ obj-$(CONFIG_GPIO_ADNP) += gpio-adnp.o
64 obj-$(CONFIG_GPIO_ADP5520) += gpio-adp5520.o
65 obj-$(CONFIG_GPIO_ADP5588) += gpio-adp5588.o
66 obj-$(CONFIG_GPIO_AMD8111) += gpio-amd8111.o
67 +obj-$(CONFIG_GPIO_AR5312) += gpio-ar5312.o
68 obj-$(CONFIG_GPIO_ARIZONA) += gpio-arizona.o
69 obj-$(CONFIG_GPIO_BCM_KONA) += gpio-bcm-kona.o
70 obj-$(CONFIG_GPIO_BT8XX) += gpio-bt8xx.o
72 +++ b/drivers/gpio/gpio-ar5312.c
75 + * This file is subject to the terms and conditions of the GNU General Public
76 + * License. See the file "COPYING" in the main directory of this archive
79 + * Copyright (C) 2003 Atheros Communications, Inc., All Rights Reserved.
80 + * Copyright (C) 2006 FON Technology, SL.
81 + * Copyright (C) 2006 Imre Kaloz <kaloz@openwrt.org>
82 + * Copyright (C) 2006-2009 Felix Fietkau <nbd@openwrt.org>
83 + * Copyright (C) 2012 Alexandros C. Couloumbis <alex@ozo.com>
86 +#include <linux/kernel.h>
87 +#include <linux/init.h>
88 +#include <linux/platform_device.h>
89 +#include <linux/gpio.h>
91 +#define DRIVER_NAME "ar5312-gpio"
93 +#define AR5312_GPIO_DO 0x00 /* output register */
94 +#define AR5312_GPIO_DI 0x04 /* intput register */
95 +#define AR5312_GPIO_CR 0x08 /* control register */
97 +#define AR5312_GPIO_CR_M(x) (1 << (x)) /* mask for i/o */
98 +#define AR5312_GPIO_CR_O(x) (0 << (x)) /* mask for output */
99 +#define AR5312_GPIO_CR_I(x) (1 << (x)) /* mask for input */
100 +#define AR5312_GPIO_CR_INT(x) (1 << ((x)+8)) /* mask for interrupt */
101 +#define AR5312_GPIO_CR_UART(x) (1 << ((x)+16)) /* uart multiplex */
103 +#define AR5312_GPIO_NUM 8
105 +static void __iomem *ar5312_mem;
107 +static inline u32 ar5312_gpio_reg_read(unsigned reg)
109 + return __raw_readl(ar5312_mem + reg);
112 +static inline void ar5312_gpio_reg_write(unsigned reg, u32 val)
114 + __raw_writel(val, ar5312_mem + reg);
117 +static inline void ar5312_gpio_reg_mask(unsigned reg, u32 mask, u32 val)
119 + ar5312_gpio_reg_write(reg, (ar5312_gpio_reg_read(reg) & ~mask) | val);
122 +static int ar5312_gpio_get_val(struct gpio_chip *chip, unsigned gpio)
124 + return (ar5312_gpio_reg_read(AR5312_GPIO_DI) >> gpio) & 1;
127 +static void ar5312_gpio_set_val(struct gpio_chip *chip, unsigned gpio, int val)
129 + u32 reg = ar5312_gpio_reg_read(AR5312_GPIO_DO);
131 + reg = val ? reg | (1 << gpio) : reg & ~(1 << gpio);
132 + ar5312_gpio_reg_write(AR5312_GPIO_DO, reg);
135 +static int ar5312_gpio_dir_in(struct gpio_chip *chip, unsigned gpio)
137 + ar5312_gpio_reg_mask(AR5312_GPIO_CR, 0, 1 << gpio);
141 +static int ar5312_gpio_dir_out(struct gpio_chip *chip, unsigned gpio, int val)
143 + ar5312_gpio_reg_mask(AR5312_GPIO_CR, 1 << gpio, 0);
144 + ar5312_gpio_set_val(chip, gpio, val);
148 +static struct gpio_chip ar5312_gpio_chip = {
149 + .label = DRIVER_NAME,
150 + .direction_input = ar5312_gpio_dir_in,
151 + .direction_output = ar5312_gpio_dir_out,
152 + .set = ar5312_gpio_set_val,
153 + .get = ar5312_gpio_get_val,
155 + .ngpio = AR5312_GPIO_NUM,
158 +static int ar5312_gpio_probe(struct platform_device *pdev)
160 + struct device *dev = &pdev->dev;
161 + struct resource *res;
167 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
168 + ar5312_mem = devm_ioremap_resource(dev, res);
169 + if (IS_ERR(ar5312_mem))
170 + return PTR_ERR(ar5312_mem);
172 + ar5312_gpio_chip.dev = dev;
173 + ret = gpiochip_add(&ar5312_gpio_chip);
175 + dev_err(dev, "failed to add gpiochip\n");
182 +static struct platform_driver ar5312_gpio_driver = {
183 + .probe = ar5312_gpio_probe,
185 + .name = DRIVER_NAME,
186 + .owner = THIS_MODULE,
190 +static int __init ar5312_gpio_init(void)
192 + return platform_driver_register(&ar5312_gpio_driver);
194 +subsys_initcall(ar5312_gpio_init);