384ea3ea18df6a1bc64beffda385478d32333bb4
[openwrt.git] / package / switch / src / gpio-bcm947xx.h
1 #ifndef __SWITCH_GPIO_H
2 #define __SWITCH_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 #else
57
58 #include <typedefs.h>
59 #include <osl.h>
60 #include <bcmdevs.h>
61 #include <sbutils.h>
62 #include <sbconfig.h>
63 #include <sbchipc.h>
64 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
65 #include <sbmips.h>
66 #else
67 #include <hndcpu.h>
68 #endif
69
70 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
71 #define sbh bcm947xx_sbh
72 #define sbh_lock bcm947xx_sbh_lock
73 #endif
74
75 extern void *sbh;
76 extern spinlock_t sbh_lock;
77
78 #define gpio_in()       sb_gpioin(sbh)
79 #define gpio_out(mask, value)   sb_gpioout(sbh, mask, ((value) & (mask)), GPIO_DRV_PRIORITY)
80 #define gpio_outen(mask, value)         sb_gpioouten(sbh, mask, value, GPIO_DRV_PRIORITY)
81 #define gpio_control(mask, value)       sb_gpiocontrol(sbh, mask, value, GPIO_DRV_PRIORITY)
82 #define gpio_intmask(mask, value)       sb_gpiointmask(sbh, mask, value, GPIO_DRV_PRIORITY)
83 #define gpio_intpolarity(mask, value)   sb_gpiointpolarity(sbh, mask, value, GPIO_DRV_PRIORITY)
84
85 #endif /* BCMDRIVER */
86 #endif /* __SWITCH_GPIO_H */