Merge tag 'lsk-v4.4-16.06-android'
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rkwifi / bcmdhd / dhd_gpio.c
1
2 #include <osl.h>
3 #include <dhd_linux.h>
4 #include <linux/rfkill-wlan.h>
5
6 #ifdef CONFIG_MACH_ODROID_4210
7 #include <mach/gpio.h>
8 #include <mach/regs-gpio.h>
9 #include <plat/gpio-cfg.h>
10 #include <plat/sdhci.h>
11 #include <plat/devs.h>
12 #define sdmmc_channel   s3c_device_hsmmc0
13 #endif
14
15 struct wifi_platform_data dhd_wlan_control = {0};
16
17 #ifdef CUSTOMER_OOB
18 uint bcm_wlan_get_oob_irq(void)
19 {
20         uint host_oob_irq = 0;
21
22         host_oob_irq = rockchip_wifi_get_oob_irq();
23
24         printk("host_oob_irq: %d\n", host_oob_irq);
25
26         return host_oob_irq;
27 }
28
29 uint bcm_wlan_get_oob_irq_flags(void)
30 {
31         uint host_oob_irq_flags = 0;
32
33         host_oob_irq_flags = (IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL | IORESOURCE_IRQ_SHAREABLE) & IRQF_TRIGGER_MASK;
34         printk("host_oob_irq_flags=0x%X\n", host_oob_irq_flags);
35
36         return host_oob_irq_flags;
37 }
38 #endif
39
40 int bcm_wlan_set_power(bool on)
41 {
42         int err = 0;
43
44         if (on) {
45                 printk("======== PULL WL_REG_ON HIGH! ========\n");
46                 rockchip_wifi_power(1);
47         } else {
48                 printk("======== PULL WL_REG_ON LOW! ========\n");
49                 rockchip_wifi_power(0);
50         }
51
52         return err;
53 }
54
55 int bcm_wlan_set_carddetect(bool present)
56 {
57         int err = 0;
58
59         if (present) {
60                 printk("======== Card detection to detect SDIO card! ========\n");
61                 rockchip_wifi_set_carddetect(1);
62         } else {
63                 printk("======== Card detection to remove SDIO card! ========\n");
64                 rockchip_wifi_set_carddetect(0);
65         }
66
67         return err;
68 }
69
70 int bcm_wlan_get_mac_address(unsigned char *buf)
71 {
72         int err = 0;
73
74         printk("======== %s ========\n", __FUNCTION__);
75 #ifdef EXAMPLE_GET_MAC
76         /* EXAMPLE code */
77         {
78                 struct ether_addr ea_example = {{0x00, 0x11, 0x22, 0x33, 0x44, 0xFF}};
79                 bcopy((char *)&ea_example, buf, sizeof(struct ether_addr));
80         }
81 #endif /* EXAMPLE_GET_MAC */
82         err = rockchip_wifi_mac_addr(buf);
83
84         return err;
85 }
86
87 #ifdef CONFIG_DHD_USE_STATIC_BUF
88 extern void *bcmdhd_mem_prealloc(int section, unsigned long size);
89 void* bcm_wlan_prealloc(int section, unsigned long size)
90 {
91         void *alloc_ptr = NULL;
92         alloc_ptr = bcmdhd_mem_prealloc(section, size);
93         if (alloc_ptr) {
94                 printf("success alloc section %d, size %ld\n", section, size);
95                 if (size != 0L)
96                         bzero(alloc_ptr, size);
97                 return alloc_ptr;
98         }
99         printf("can't alloc section %d\n", section);
100         return NULL;
101 }
102 #endif
103
104 #if !defined(WL_WIRELESS_EXT)
105 struct cntry_locales_custom {
106         char iso_abbrev[WLC_CNTRY_BUF_SZ];      /* ISO 3166-1 country abbreviation */
107         char custom_locale[WLC_CNTRY_BUF_SZ];   /* Custom firmware locale */
108         int32 custom_locale_rev;                /* Custom local revisin default -1 */
109 };
110 #endif
111
112 static struct cntry_locales_custom brcm_wlan_translate_custom_table[] = {
113         /* Table should be filled out based on custom platform regulatory requirement */
114         {"",   "XT", 49},  /* Universal if Country code is unknown or empty */
115         {"US", "US", 0},
116 };
117
118 #ifdef CUSTOM_FORCE_NODFS_FLAG
119 struct cntry_locales_custom brcm_wlan_translate_nodfs_table[] = {
120         {"",   "XT", 50},  /* Universal if Country code is unknown or empty */
121         {"US", "US", 0},
122 };
123 #endif
124
125 static void *bcm_wlan_get_country_code(char *ccode
126 #ifdef CUSTOM_FORCE_NODFS_FLAG
127         , u32 flags
128 #endif
129 )
130 {
131         struct cntry_locales_custom *locales;
132         int size;
133         int i;
134
135         if (!ccode)
136                 return NULL;
137
138 #ifdef CUSTOM_FORCE_NODFS_FLAG
139         if (flags & WLAN_PLAT_NODFS_FLAG) {
140                 locales = brcm_wlan_translate_nodfs_table;
141                 size = ARRAY_SIZE(brcm_wlan_translate_nodfs_table);
142         } else {
143 #endif
144                 locales = brcm_wlan_translate_custom_table;
145                 size = ARRAY_SIZE(brcm_wlan_translate_custom_table);
146 #ifdef CUSTOM_FORCE_NODFS_FLAG
147         }
148 #endif
149
150         for (i = 0; i < size; i++)
151                 if (strcmp(ccode, locales[i].iso_abbrev) == 0)
152                         return &locales[i];
153         return NULL;
154 }
155
156 int bcm_wlan_set_plat_data(void) {
157         printf("======== %s ========\n", __FUNCTION__);
158         dhd_wlan_control.set_power = bcm_wlan_set_power;
159         dhd_wlan_control.set_carddetect = bcm_wlan_set_carddetect;
160         dhd_wlan_control.get_mac_addr = bcm_wlan_get_mac_address;
161 #ifdef CONFIG_DHD_USE_STATIC_BUF
162         dhd_wlan_control.mem_prealloc = bcm_wlan_prealloc;
163 #endif
164         dhd_wlan_control.get_country_code = bcm_wlan_get_country_code;
165         return 0;
166 }
167