add diag support for the Buffalo WZR-G300N
[openwrt.git] / package / broadcom-diag / src / gpio.h
1 #ifndef __DIAG_GPIO_H
2 #define __DIAG_GPIO_H
3
4 #include <typedefs.h>
5 #include <osl.h>
6 #include <bcmdevs.h>
7 #include <sbutils.h>
8 #include <sbconfig.h>
9 #include <sbchipc.h>
10 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
11 #include <sbmips.h>
12 #else
13 #include <hndcpu.h>
14 #endif
15
16 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
17 #define sbh bcm947xx_sbh
18 #define sbh_lock bcm947xx_sbh_lock
19 #endif
20
21 #define EXTIF_ADDR 0x1f000000
22 #define EXTIF_UART (EXTIF_ADDR + 0x00800000)
23
24 #define GPIO_TYPE_NORMAL (0x0 << 24)
25 #define GPIO_TYPE_EXTIF (0x1 << 24)
26 #define GPIO_TYPE_MASK (0xf << 24)
27
28 extern void *sbh;
29 extern spinlock_t sbh_lock;
30
31 #define gpio_in() sb_gpioin(sbh)
32 #define gpio_out(mask, value) sb_gpioout(sbh, mask, ((value) & (mask)), GPIO_DRV_PRIORITY)
33 #define gpio_outen(mask, value) sb_gpioouten(sbh, mask, value, GPIO_DRV_PRIORITY)
34 #define gpio_control(mask, value) sb_gpiocontrol(sbh, mask, value, GPIO_DRV_PRIORITY)
35 #define gpio_intmask(mask, value) sb_gpiointmask(sbh, mask, value, GPIO_DRV_PRIORITY)
36 #define gpio_intpolarity(mask, value) sb_gpiointpolarity(sbh, mask, value, GPIO_DRV_PRIORITY)
37
38 static void gpio_set_irqenable(int enabled, irqreturn_t (*handler)(int, void *, struct pt_regs *))
39 {
40 unsigned int coreidx;
41 unsigned long flags;
42 chipcregs_t *cc;
43 int irq;
44
45 spin_lock_irqsave(sbh_lock, flags);
46 coreidx = sb_coreidx(sbh);
47
48 irq = sb_irq(sbh) + 2;
49 if (enabled)
50 request_irq(irq, handler, SA_SHIRQ | SA_SAMPLE_RANDOM, "gpio", handler);
51 else
52 free_irq(irq, handler);
53
54 if ((cc = sb_setcore(sbh, SB_CC, 0))) {
55 int intmask;
56
57 intmask = readl(&cc->intmask);
58 if (enabled)
59 intmask |= CI_GPIO;
60 else
61 intmask &= ~CI_GPIO;
62 writel(intmask, &cc->intmask);
63 }
64 sb_setcoreidx(sbh, coreidx);
65 spin_unlock_irqrestore(sbh_lock, flags);
66 }
67
68 static inline void gpio_set_extif(int gpio, int value)
69 {
70 volatile u8 *addr = (volatile u8 *) KSEG1ADDR(EXTIF_UART) + (gpio & ~GPIO_TYPE_MASK);
71 if (value)
72 *addr = 0xFF;
73 else
74 *addr;
75 }
76
77
78 #endif
This page took 0.058254 seconds and 5 git commands to generate.