atheros: add v3.18 support
[openwrt/svn-archive/archive.git] / target / linux / atheros / patches-3.18 / 102-ar5312_gpio.patch
1 --- a/arch/mips/ar231x/Kconfig
2 +++ b/arch/mips/ar231x/Kconfig
3 @@ -1,6 +1,7 @@
4 config SOC_AR5312
5 bool "Atheros 5312/2312+ support"
6 depends on ATHEROS_AR231X
7 + select GPIO_AR5312
8 default y
9
10 config SOC_AR2315
11 --- a/arch/mips/ar231x/ar5312.c
12 +++ b/arch/mips/ar231x/ar5312.c
13 @@ -192,6 +192,22 @@ static struct platform_device ar5312_phy
14 .num_resources = 1,
15 };
16
17 +static struct resource ar5312_gpio_res[] = {
18 + {
19 + .name = "ar5312-gpio",
20 + .flags = IORESOURCE_MEM,
21 + .start = AR5312_GPIO,
22 + .end = AR5312_GPIO + 0x0c - 1,
23 + },
24 +};
25 +
26 +static struct platform_device ar5312_gpio = {
27 + .name = "ar5312-gpio",
28 + .id = -1,
29 + .resource = ar5312_gpio_res,
30 + .num_resources = ARRAY_SIZE(ar5312_gpio_res),
31 +};
32 +
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)
37
38 platform_device_register(&ar5312_physmap_flash);
39
40 + platform_device_register(&ar5312_gpio);
41 +
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
48
49 comment "Memory mapped GPIO drivers:"
50
51 +config GPIO_AR5312
52 + bool "AR5312 SoC GPIO support"
53 + default y if SOC_AR5312
54 + depends on SOC_AR5312
55 + help
56 + Say yes here to enable GPIO support for Atheros AR5312/AR2312+ SoCs.
57 +
58 config GPIO_CLPS711X
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
71 --- /dev/null
72 +++ b/drivers/gpio/gpio-ar5312.c
73 @@ -0,0 +1,121 @@
74 +/*
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
77 + * for more details.
78 + *
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>
84 + */
85 +
86 +#include <linux/kernel.h>
87 +#include <linux/init.h>
88 +#include <linux/platform_device.h>
89 +#include <linux/gpio.h>
90 +
91 +#define DRIVER_NAME "ar5312-gpio"
92 +
93 +#define AR5312_GPIO_DO 0x00 /* output register */
94 +#define AR5312_GPIO_DI 0x04 /* intput register */
95 +#define AR5312_GPIO_CR 0x08 /* control register */
96 +
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 */
102 +
103 +#define AR5312_GPIO_NUM 8
104 +
105 +static void __iomem *ar5312_mem;
106 +
107 +static inline u32 ar5312_gpio_reg_read(unsigned reg)
108 +{
109 + return __raw_readl(ar5312_mem + reg);
110 +}
111 +
112 +static inline void ar5312_gpio_reg_write(unsigned reg, u32 val)
113 +{
114 + __raw_writel(val, ar5312_mem + reg);
115 +}
116 +
117 +static inline void ar5312_gpio_reg_mask(unsigned reg, u32 mask, u32 val)
118 +{
119 + ar5312_gpio_reg_write(reg, (ar5312_gpio_reg_read(reg) & ~mask) | val);
120 +}
121 +
122 +static int ar5312_gpio_get_val(struct gpio_chip *chip, unsigned gpio)
123 +{
124 + return (ar5312_gpio_reg_read(AR5312_GPIO_DI) >> gpio) & 1;
125 +}
126 +
127 +static void ar5312_gpio_set_val(struct gpio_chip *chip, unsigned gpio, int val)
128 +{
129 + u32 reg = ar5312_gpio_reg_read(AR5312_GPIO_DO);
130 +
131 + reg = val ? reg | (1 << gpio) : reg & ~(1 << gpio);
132 + ar5312_gpio_reg_write(AR5312_GPIO_DO, reg);
133 +}
134 +
135 +static int ar5312_gpio_dir_in(struct gpio_chip *chip, unsigned gpio)
136 +{
137 + ar5312_gpio_reg_mask(AR5312_GPIO_CR, 0, 1 << gpio);
138 + return 0;
139 +}
140 +
141 +static int ar5312_gpio_dir_out(struct gpio_chip *chip, unsigned gpio, int val)
142 +{
143 + ar5312_gpio_reg_mask(AR5312_GPIO_CR, 1 << gpio, 0);
144 + ar5312_gpio_set_val(chip, gpio, val);
145 + return 0;
146 +}
147 +
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,
154 + .base = 0,
155 + .ngpio = AR5312_GPIO_NUM,
156 +};
157 +
158 +static int ar5312_gpio_probe(struct platform_device *pdev)
159 +{
160 + struct device *dev = &pdev->dev;
161 + struct resource *res;
162 + int ret;
163 +
164 + if (ar5312_mem)
165 + return -EBUSY;
166 +
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);
171 +
172 + ar5312_gpio_chip.dev = dev;
173 + ret = gpiochip_add(&ar5312_gpio_chip);
174 + if (ret) {
175 + dev_err(dev, "failed to add gpiochip\n");
176 + return ret;
177 + }
178 +
179 + return 0;
180 +}
181 +
182 +static struct platform_driver ar5312_gpio_driver = {
183 + .probe = ar5312_gpio_probe,
184 + .driver = {
185 + .name = DRIVER_NAME,
186 + .owner = THIS_MODULE,
187 + }
188 +};
189 +
190 +static int __init ar5312_gpio_init(void)
191 +{
192 + return platform_driver_register(&ar5312_gpio_driver);
193 +}
194 +subsys_initcall(ar5312_gpio_init);