summaryrefslogtreecommitdiff
path: root/target/linux/atheros/patches-2.6.37/300-sysfs_for_gpio.patch
blob: 0cf2a8f7d4d152c4d8a59f4ccd4a473d63221a69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -111,7 +111,7 @@ config ATHEROS_AR231X
 	select SYS_HAS_CPU_MIPS32_R1
 	select SYS_SUPPORTS_BIG_ENDIAN
 	select SYS_SUPPORTS_32BIT_KERNEL
-	select GENERIC_GPIO
+	select ARCH_REQUIRE_GPIOLIB
 	select SYS_HAS_EARLY_PRINTK
 	help
 	  Support for AR231x and AR531x based boards
--- a/arch/mips/ar231x/Kconfig
+++ b/arch/mips/ar231x/Kconfig
@@ -13,7 +13,6 @@ config ATHEROS_AR2315
 	select SYS_HAS_CPU_MIPS32_R1
 	select SYS_SUPPORTS_32BIT_KERNEL
 	select SYS_SUPPORTS_BIG_ENDIAN
-	select GENERIC_GPIO
 	default y
 
 config ATHEROS_AR2315_PCI
--- a/arch/mips/ar231x/ar2315.c
+++ b/arch/mips/ar231x/ar2315.c
@@ -23,12 +23,12 @@
 #include <linux/reboot.h>
 #include <linux/delay.h>
 #include <linux/leds.h>
+#include <linux/gpio.h>
 #include <asm/bootinfo.h>
 #include <asm/reboot.h>
 #include <asm/time.h>
 #include <asm/irq.h>
 #include <asm/io.h>
-#include <asm/gpio.h>
 
 #include <ar231x_platform.h>
 #include <ar2315_regs.h>
@@ -312,17 +312,6 @@ ar2315_irq_init(void)
 	setup_irq(AR2315_IRQ_MISC_INTRS, &cascade);
 }
 
-const struct ar231x_gpiodev ar2315_gpiodev;
-
-static u32
-ar2315_gpio_get_output(void)
-{
-	u32 reg;
-	reg = ar231x_read_reg(AR2315_GPIO_CR);
-	reg &= ar2315_gpiodev.valid_mask;
-	return reg;
-}
-
 static u32
 ar2315_gpio_set_output(u32 mask, u32 val)
 {
@@ -336,11 +325,11 @@ ar2315_gpio_set_output(u32 mask, u32 val
 }
 
 static u32
-ar2315_gpio_get(void)
+ar2315_gpio_get(u32 valid_mask)
 {
 	u32 reg;
 	reg = ar231x_read_reg(AR2315_GPIO_DI);
-	reg &= ar2315_gpiodev.valid_mask;
+	reg &= valid_mask;
 	return reg;
 }
 
@@ -355,14 +344,75 @@ ar2315_gpio_set(u32 mask, u32 value)
 	return reg;
 }
 
-const struct ar231x_gpiodev ar2315_gpiodev = {
+/*
+ * gpiolib implementation.  Original legacy mask based methods
+ * preserved for now.
+ */
+static int
+ar2315_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
+{
+	struct ar231x_gpio_chip *gpch =
+		container_of(chip, struct ar231x_gpio_chip, chip);
+	u32 mask = 1 << gpio;
+	u32 rett;
+	if (!(gpch->valid_mask & mask))
+		return 0;
+	rett = ar2315_gpio_get(gpch->valid_mask);  // legacy code
+	return !!(rett & mask);
+}
+
+static void
+ar2315_gpio_set_value(struct gpio_chip *chip, unsigned gpio, int value)
+{
+	struct ar231x_gpio_chip *gpch =
+		container_of(chip, struct ar231x_gpio_chip, chip);
+	u32 mask = 1 << gpio;
+	if (!(gpch->valid_mask & mask))
+		return;
+	ar2315_gpio_set(mask, (!!value) * mask);  // legacy
+}
+
+static int
+ar2315_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
+{
+	struct ar231x_gpio_chip *gpch =
+		container_of(chip, struct ar231x_gpio_chip, chip);
+	u32 mask = 1 << gpio;
+	if (!(gpch->valid_mask & mask))
+		return -ENXIO;
+	ar2315_gpio_set_output(mask, 0);  // legacy
+	return 0;
+}
+
+static int
+ar2315_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, int value)
+{
+	struct ar231x_gpio_chip *gpch =
+		container_of(chip, struct ar231x_gpio_chip, chip);
+	u32 mask = 1 << gpio;
+	if (!(gpch->valid_mask & mask))
+		return -ENXIO;
+	ar2315_gpio_set_output(mask, mask);  // both legacy
+	ar2315_gpio_set(mask, (!!value) * mask);
+	return 0;
+}
+
+static struct ar231x_gpio_chip ar2315_gpio_chip = {
 	.valid_mask = (1 << 22) - 1,
-	.get_output = ar2315_gpio_get_output,
-	.set_output = ar2315_gpio_set_output,
-	.get = ar2315_gpio_get,
-	.set = ar2315_gpio_set,
+	.chip = {
+		.label                  = "ar2315-gpio",
+		.direction_input        = ar2315_gpio_direction_input,
+		.direction_output       = ar2315_gpio_direction_output,
+		.set                    = ar2315_gpio_set_value,
+		.get                    = ar2315_gpio_get_value,
+		.base                   = 0,
+		.ngpio                  = AR531X_GPIO_IRQ_COUNT, // 22
+	}
 };
 
+// end of gpiolib
+
+
 static struct ar231x_eth ar2315_eth_data = {
 	.reset_base = AR2315_RESET,
 	.reset_mac = AR2315_RESET_ENET0,
@@ -496,7 +546,7 @@ static struct platform_device ar2315_gpi
 };
 
 static void __init
-ar2315_init_gpio(void)
+ar2315_init_gpio_leds(void)
 {
 	static char led_names[6][6];
 	int i, led = 0;
@@ -522,7 +572,7 @@ ar2315_init_gpio(void)
 	platform_device_register(&ar2315_gpio_leds);
 }
 #else
-static inline void ar2315_init_gpio(void)
+static inline void ar2315_init_gpio_leds(void)
 {
 }
 #endif
@@ -537,7 +587,7 @@ ar2315_init_devices(void)
 	ar231x_find_config(ar2315_flash_limit());
 	ar2315_eth_data.macaddr = ar231x_board.config->enet0_mac;
 
-	ar2315_init_gpio();
+	ar2315_init_gpio_leds();
 	platform_device_register(&ar2315_wdt);
 	platform_device_register(&ar2315_spiflash);
 	ar231x_add_ethernet(0, KSEG1ADDR(AR2315_ENET0), AR2315_IRQ_ENET0_INTRS,
@@ -633,6 +683,25 @@ ar2315_time_init(void)
 	mips_hpt_frequency = ar2315_cpu_frequency() / 2;
 }
 
+int __init
+ar2315_gpio_init(void)
+{
+	int ret;
+	struct ar231x_gpio_chip *gpch;
+	gpch = &ar2315_gpio_chip;
+	ret = gpiochip_add(&gpch->chip);
+	if (ret) {
+		printk(KERN_ERR "%s: failed to add gpiochip\n",
+			gpch->chip.label);
+		return ret;
+	}
+	printk(KERN_INFO "%s: registered %d GPIOs\n",
+		gpch->chip.label, gpch->chip.ngpio);
+	return ret;
+}
+
+
+
 void __init
 ar2315_prom_init(void)
 {
@@ -659,7 +728,7 @@ ar2315_prom_init(void)
 			ar231x_devtype = DEV_TYPE_AR2315;
 			break;
 	}
-	ar231x_gpiodev = &ar2315_gpiodev;
+	ar2315_gpio_init();
 	ar231x_board.devid = devid;
 }
 
--- a/arch/mips/ar231x/ar5312.c
+++ b/arch/mips/ar231x/ar5312.c
@@ -23,12 +23,12 @@
 #include <linux/kernel.h>
 #include <linux/reboot.h>
 #include <linux/leds.h>
+#include <linux/gpio.h>
 #include <asm/bootinfo.h>
 #include <asm/reboot.h>
 #include <asm/time.h>
 #include <asm/irq.h>
 #include <asm/io.h>
-#include <gpio.h>
 
 #include <ar231x_platform.h>
 #include <ar5312_regs.h>
@@ -160,17 +160,6 @@ void __init ar5312_irq_init(void)
 	setup_irq(AR5312_IRQ_MISC_INTRS, &cascade);
 }
 
-const struct ar231x_gpiodev ar5312_gpiodev;
-
-static u32
-ar5312_gpio_get_output(void)
-{
-	u32 reg;
-	reg = ~(ar231x_read_reg(AR531X_GPIO_CR));
-	reg &= ar5312_gpiodev.valid_mask;
-	return reg;
-}
-
 static u32
 ar5312_gpio_set_output(u32 mask, u32 val)
 {
@@ -184,11 +173,11 @@ ar5312_gpio_set_output(u32 mask, u32 val
 }
 
 static u32
-ar5312_gpio_get(void)
+ar5312_gpio_get(u32 valid_mask)
 {
 	u32 reg;
 	reg = ar231x_read_reg(AR531X_GPIO_DI);
-	reg &= ar5312_gpiodev.valid_mask;
+	reg &= valid_mask;
 	return reg;
 }
 
@@ -203,14 +192,72 @@ ar5312_gpio_set(u32 mask, u32 value)
 	return reg;
 }
 
-const struct ar231x_gpiodev ar5312_gpiodev = {
-	.valid_mask = (1 << 8) - 1,
-	.get_output = ar5312_gpio_get_output,
-	.set_output = ar5312_gpio_set_output,
-	.get = ar5312_gpio_get,
-	.set = ar5312_gpio_set,
+/*
+ * gpiolib implementations. Original mask based methods preserved
+ */
+static int
+ar5312_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
+{
+	struct ar231x_gpio_chip *gpch =
+		container_of(chip, struct ar231x_gpio_chip, chip);
+	u32 mask = 1 << gpio;
+	u32 rett;
+	if (!(gpch->valid_mask & mask))
+		return 0;
+	rett = ar5312_gpio_get(gpch->valid_mask);
+	return !!(rett & mask);
+}
+
+static void
+ar5312_gpio_set_value(struct gpio_chip *chip, unsigned gpio, int value)
+{
+	struct ar231x_gpio_chip *gpch =
+		container_of(chip, struct ar231x_gpio_chip, chip);
+	u32 mask = 1 << gpio;
+	if (!(gpch->valid_mask & mask))
+		return;
+	ar5312_gpio_set(mask, (!!value) * mask);
+}
+
+static int
+ar5312_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
+{
+	struct ar231x_gpio_chip *gpch =
+		container_of(chip, struct ar231x_gpio_chip, chip);
+	u32 mask = 1 << gpio;
+	if (!(gpch->valid_mask & mask))
+		return -ENXIO;
+	ar5312_gpio_set_output(mask, 0);
+	return 0;
+}
+static int
+ar5312_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, int value)
+{
+	struct ar231x_gpio_chip *gpch =
+		container_of(chip, struct ar231x_gpio_chip, chip);
+	u32 mask = 1 << gpio;
+	if (!(gpch->valid_mask & mask))
+		return -ENXIO;
+	ar5312_gpio_set_output(mask, mask);
+	ar5312_gpio_set(mask, (!!value) * mask);
+	return 0;
+}
+
+static struct ar231x_gpio_chip ar5312_gpio_chip = {
+	.valid_mask = (1 << 22) - 1,
+	.chip = {
+		.label                  = "ar5312-gpio",
+		.direction_input        = ar5312_gpio_direction_input,
+		.direction_output       = ar5312_gpio_direction_output,
+		.set                    = ar5312_gpio_set_value,
+		.get                    = ar5312_gpio_get_value,
+		.base                   = 0,
+		.ngpio                  = AR531X_GPIO_IRQ_COUNT, // 22
+	}
 };
 
+// end of gpiolib
+
 static struct physmap_flash_data ar5312_flash_data = {
 	.width = 2,
 };
@@ -486,6 +533,22 @@ ar5312_time_init(void)
 	mips_hpt_frequency = ar5312_cpu_frequency() / 2;
 }
 
+int __init
+ar5312_gpio_init(void)
+{
+	int ret;
+	struct ar231x_gpio_chip *gpch;
+	gpch = &ar5312_gpio_chip;
+	ret = gpiochip_add(&gpch->chip);
+	if (ret) {
+		printk(KERN_ERR "%s: failed to add gpiochip\n",
+			gpch->chip.label);
+		return ret;
+	}
+	printk(KERN_INFO "%s: registered %d GPIOs\n",
+		gpch->chip.label, gpch->chip.ngpio);
+	return ret;
+}
 
 void __init
 ar5312_prom_init(void)
@@ -509,7 +572,7 @@ ar5312_prom_init(void)
 	devid >>= AR531X_REV_WMAC_MIN_S;
 	devid &= AR531X_REV_CHIP;
 	ar231x_board.devid = (u16) devid;
-	ar231x_gpiodev = &ar5312_gpiodev;
+	ar5312_gpio_init();
 }
 
 void __init
--- a/arch/mips/ar231x/devices.c
+++ b/arch/mips/ar231x/devices.c
@@ -12,8 +12,6 @@
 
 struct ar231x_board_config ar231x_board;
 int ar231x_devtype = DEV_TYPE_UNKNOWN;
-const struct ar231x_gpiodev *ar231x_gpiodev;
-EXPORT_SYMBOL(ar231x_gpiodev);
 
 static struct resource ar231x_eth0_res[] = {
 	{
--- a/arch/mips/ar231x/devices.h
+++ b/arch/mips/ar231x/devices.h
@@ -1,5 +1,6 @@
 #ifndef __AR231X_DEVICES_H
 #define __AR231X_DEVICES_H
+#include <linux/gpio.h>
 
 enum {
 	/* handled by ar5312.c */
@@ -34,4 +35,8 @@ static inline bool is_5312(void)
 	return !is_2315();
 }
 
+struct ar231x_gpio_chip {
+	u32 valid_mask;
+	struct gpio_chip chip;
+};
 #endif
--- a/arch/mips/ar231x/reset.c
+++ b/arch/mips/ar231x/reset.c
@@ -6,11 +6,11 @@
 #include <linux/workqueue.h>
 #include <linux/skbuff.h>
 #include <linux/netlink.h>
+#include <linux/gpio.h>
 #include <net/sock.h>
 #include <asm/uaccess.h>
 #include <ar231x_platform.h>
 #include <ar231x.h>
-#include <gpio.h>
 #include "devices.h"
 
 #define AR531X_RESET_GPIO_IRQ	(AR531X_GPIO_IRQ(ar231x_board.config->resetConfigGpio))
@@ -85,13 +85,12 @@ static void
 reset_button_poll(unsigned long unused)
 {
 	struct event_t *event;
-	int gpio = ~0;
+	int gpio = 0;
 
 	if(!no_release_workaround)
 		return;
 
-	gpio = ar231x_gpiodev->get();
-	gpio &= (1 << (AR531X_RESET_GPIO_IRQ - AR531X_GPIO_IRQ_BASE));
+	gpio = gpio_get_value(AR531X_RESET_GPIO_IRQ - AR531X_GPIO_IRQ_BASE);
 	if(gpio) {
 		rst_button_timer.expires = jiffies + (HZ / 4);
 		add_timer(&rst_button_timer);
@@ -113,7 +112,7 @@ button_handler(int irq, void *dev_id)
 {
 	static int pressed = 0;
 	struct event_t *event;
-	u32 gpio = ~0;
+	u32 gpio = 0;
 
 	event = (struct event_t *) kzalloc(sizeof(struct event_t), GFP_ATOMIC);
 	if (!event)
@@ -121,7 +120,7 @@ button_handler(int irq, void *dev_id)
 
 	pressed = !pressed;
 
-	gpio = ar231x_gpiodev->get() & (1 << (irq - AR531X_GPIO_IRQ_BASE));
+	gpio = gpio_get_value(irq - AR531X_GPIO_IRQ_BASE);
 
 	event->set = gpio;
 	if(!event->set)
--- a/arch/mips/include/asm/mach-ar231x/gpio.h
+++ b/arch/mips/include/asm/mach-ar231x/gpio.h
@@ -3,66 +3,15 @@
 
 #include <ar231x.h>
 
-struct ar231x_gpiodev {
-	u32 valid_mask;
-	u32 (*get_output)(void);
-	u32 (*set_output)(u32 mask, u32 val);
-	u32 (*get)(void);
-	u32 (*set)(u32 mask, u32 val);
-};
-
-extern const struct ar231x_gpiodev *ar231x_gpiodev;
+#define gpio_get_value __gpio_get_value
+#define gpio_set_value __gpio_set_value
+#define gpio_cansleep __gpio_cansleep
 
 /*
  * Wrappers for the generic GPIO layer
  */
 
-static inline int gpio_direction_input(unsigned gpio) {
-	u32 mask = 1 << gpio;
-
-	if (!(ar231x_gpiodev->valid_mask & mask))
-		return -ENXIO;
-
-	ar231x_gpiodev->set_output(mask, 0);
-	return 0;
-}
-
-static inline void gpio_set_value(unsigned gpio, int value) {
-	u32 mask = 1 << gpio;
-
-	if (!(ar231x_gpiodev->valid_mask & mask))
-		return;
-
-	ar231x_gpiodev->set(mask, (!!value) * mask);
-}
-
-static inline int gpio_direction_output(unsigned gpio, int value) {
-	u32 mask = 1 << gpio;
-
-	if (!(ar231x_gpiodev->valid_mask & mask))
-		return -ENXIO;
-
-	ar231x_gpiodev->set_output(mask, mask);
-	ar231x_gpiodev->set(mask, (!!value) * mask);
-	return 0;
-}
-
-/* Reads the gpio pin.  Unchecked function */
-static inline int gpio_get_value(unsigned gpio) {
-	u32 mask = 1 << gpio;
-
-	if (!(ar231x_gpiodev->valid_mask & mask))
-		return 0;
-
-	return !!(ar231x_gpiodev->get() & mask);
-}
-
-static inline int gpio_request(unsigned gpio, const char *label) {
-	return 0;
-}
-
-static inline void gpio_free(unsigned gpio) {
-}
+/* not sure if these are used? */
 
 /* Returns IRQ to attach for gpio.  Unchecked function */
 static inline int gpio_to_irq(unsigned gpio) {
@@ -74,11 +23,6 @@ static inline int irq_to_gpio(unsigned i
 	return (irq - (AR531X_GPIO_IRQ(0)));
 }
 
-static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
-{
-	return -ENOSYS;
-}
-
 #include <asm-generic/gpio.h> /* cansleep wrappers */
 
 #endif