revert bluetooth kconfig change - it doesn't work that way
[openwrt.git] / package / broadcom-diag / src / gpio.h
1 #ifndef __DIAG_GPIO_H
2 #define __DIAG_GPIO_H
3 #include <linux/interrupt.h>
4
5 #ifndef BCMDRIVER
6 #include <linux/ssb/ssb.h>
7 #include <linux/ssb/ssb_driver_chipcommon.h>
8 #include <linux/ssb/ssb_driver_extif.h>
9
10 extern struct ssb_bus ssb;
11
12 #define gpio_op(op, param...) \
13 do { \
14 if (ssb.chipco.dev) \
15 return ssb_chipco_gpio_##op(&ssb.chipco, param); \
16 else if (ssb.extif.dev) \
17 return ssb_extif_gpio_##op(&ssb.extif, param); \
18 else \
19 return 0; \
20 } while (0);
21
22
23 static inline u32 gpio_in(void)
24 {
25 gpio_op(in, ~0);
26 }
27
28 static inline u32 gpio_out(u32 mask, u32 value)
29 {
30 gpio_op(out, mask, value);
31 }
32
33 static inline u32 gpio_outen(u32 mask, u32 value)
34 {
35 gpio_op(outen, mask, value);
36 }
37
38 static inline u32 gpio_control(u32 mask, u32 value)
39 {
40 if (ssb.chipco.dev)
41 return ssb_chipco_gpio_control(&ssb.chipco, mask, value);
42 else
43 return 0;
44 }
45
46 static inline u32 gpio_intmask(u32 mask, u32 value)
47 {
48 gpio_op(intmask, mask, value);
49 }
50
51 static inline u32 gpio_intpolarity(u32 mask, u32 value)
52 {
53 gpio_op(polarity, mask, value);
54 }
55
56 static void gpio_set_irqenable(int enabled, irqreturn_t (*handler)(int, void *, struct pt_regs *))
57 {
58 int irq;
59
60 if (ssb.chipco.dev)
61 irq = ssb_mips_irq(ssb.chipco.dev) + 2;
62 else if (ssb.extif.dev)
63 irq = ssb_mips_irq(ssb.extif.dev) + 2;
64 else return;
65
66 if (enabled)
67 request_irq(irq, handler, SA_SHIRQ | SA_SAMPLE_RANDOM, "gpio", handler);
68 else
69 free_irq(irq, handler);
70
71 gpio_intmask(1, (enabled ? 1 : 0));
72 }
73
74 #else
75
76 #include <typedefs.h>
77 #include <osl.h>
78 #include <bcmdevs.h>
79 #include <sbutils.h>
80 #include <sbconfig.h>
81 #include <sbchipc.h>
82 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
83 #include <sbmips.h>
84 #else
85 #include <hndcpu.h>
86 #endif
87
88 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
89 #define sbh bcm947xx_sbh
90 #define sbh_lock bcm947xx_sbh_lock
91 #endif
92
93 extern void *sbh;
94 extern spinlock_t sbh_lock;
95
96 #define gpio_in() sb_gpioin(sbh)
97 #define gpio_out(mask, value) sb_gpioout(sbh, mask, ((value) & (mask)), GPIO_DRV_PRIORITY)
98 #define gpio_outen(mask, value) sb_gpioouten(sbh, mask, value, GPIO_DRV_PRIORITY)
99 #define gpio_control(mask, value) sb_gpiocontrol(sbh, mask, value, GPIO_DRV_PRIORITY)
100 #define gpio_intmask(mask, value) sb_gpiointmask(sbh, mask, value, GPIO_DRV_PRIORITY)
101 #define gpio_intpolarity(mask, value) sb_gpiointpolarity(sbh, mask, value, GPIO_DRV_PRIORITY)
102
103 static void gpio_set_irqenable(int enabled, irqreturn_t (*handler)(int, void *, struct pt_regs *))
104 {
105 unsigned int coreidx;
106 unsigned long flags;
107 chipcregs_t *cc;
108 int irq;
109
110 spin_lock_irqsave(sbh_lock, flags);
111 coreidx = sb_coreidx(sbh);
112
113 irq = sb_irq(sbh) + 2;
114 if (enabled)
115 request_irq(irq, handler, SA_SHIRQ | SA_SAMPLE_RANDOM, "gpio", handler);
116 else
117 free_irq(irq, handler);
118
119 if ((cc = sb_setcore(sbh, SB_CC, 0))) {
120 int intmask;
121
122 intmask = readl(&cc->intmask);
123 if (enabled)
124 intmask |= CI_GPIO;
125 else
126 intmask &= ~CI_GPIO;
127 writel(intmask, &cc->intmask);
128 }
129 sb_setcoreidx(sbh, coreidx);
130 spin_unlock_irqrestore(sbh_lock, flags);
131 }
132
133 #endif /* BCMDRIVER */
134
135 #define EXTIF_ADDR 0x1f000000
136 #define EXTIF_UART (EXTIF_ADDR + 0x00800000)
137
138 #define GPIO_TYPE_NORMAL (0x0 << 24)
139 #define GPIO_TYPE_EXTIF (0x1 << 24)
140 #define GPIO_TYPE_MASK (0xf << 24)
141
142 static inline void gpio_set_extif(int gpio, int value)
143 {
144 volatile u8 *addr = (volatile u8 *) KSEG1ADDR(EXTIF_UART) + (gpio & ~GPIO_TYPE_MASK);
145 if (value)
146 *addr = 0xFF;
147 else
148 *addr;
149 }
150
151 #endif /* __DIAG_GPIO_H */
This page took 0.051018 seconds and 5 git commands to generate.