1 #include "wilc_wfi_netdevice.h"
2
3 #include <linux/mmc/sdio_func.h>
4 #include <linux/mmc/card.h>
5 #include <linux/mmc/sdio_ids.h>
6 #include <linux/mmc/sdio.h>
7 #include <linux/mmc/host.h>
8
9
10
11 #define SDIO_MODALIAS "wilc1000_sdio"
12
13 #if defined(CUSTOMER_PLATFORM)
14 /* TODO : User have to stable bus clock as user's environment. */
15 #ifdef MAX_BUS_SPEED
16 #define MAX_SPEED MAX_BUS_SPEED
17 #else
18 #define MAX_SPEED 50000000
19 #endif
20 #else
21 #define MAX_SPEED (6 * 1000000) /* Max 50M */
22 #endif
23
24 struct wilc_sdio {
25 struct sdio_func *func;
26 struct wilc *wilc;
27 };
28
29 struct sdio_func *local_sdio_func;
30
31 static unsigned int sdio_default_speed;
32
33 #define SDIO_VENDOR_ID_WILC 0x0296
34 #define SDIO_DEVICE_ID_WILC 0x5347
35
36 static const struct sdio_device_id wilc_sdio_ids[] = {
37 { SDIO_DEVICE(SDIO_VENDOR_ID_WILC, SDIO_DEVICE_ID_WILC) },
38 { },
39 };
40
41
wilc_sdio_interrupt(struct sdio_func * func)42 static void wilc_sdio_interrupt(struct sdio_func *func)
43 {
44 struct wilc_sdio *wl_sdio;
45
46 wl_sdio = sdio_get_drvdata(func);
47
48 #ifndef WILC_SDIO_IRQ_GPIO
49 sdio_release_host(func);
50 wilc_handle_isr(wl_sdio->wilc);
51 sdio_claim_host(func);
52 #endif
53 }
54
55
linux_sdio_cmd52(sdio_cmd52_t * cmd)56 int linux_sdio_cmd52(sdio_cmd52_t *cmd)
57 {
58 struct sdio_func *func = g_linux_wlan->wilc_sdio_func;
59 int ret;
60 u8 data;
61
62 sdio_claim_host(func);
63
64 func->num = cmd->function;
65 if (cmd->read_write) { /* write */
66 if (cmd->raw) {
67 sdio_writeb(func, cmd->data, cmd->address, &ret);
68 data = sdio_readb(func, cmd->address, &ret);
69 cmd->data = data;
70 } else {
71 sdio_writeb(func, cmd->data, cmd->address, &ret);
72 }
73 } else { /* read */
74 data = sdio_readb(func, cmd->address, &ret);
75 cmd->data = data;
76 }
77
78 sdio_release_host(func);
79
80 if (ret < 0) {
81 PRINT_ER("wilc_sdio_cmd52..failed, err(%d)\n", ret);
82 return 0;
83 }
84 return 1;
85 }
86
87
linux_sdio_cmd53(sdio_cmd53_t * cmd)88 int linux_sdio_cmd53(sdio_cmd53_t *cmd)
89 {
90 struct sdio_func *func = g_linux_wlan->wilc_sdio_func;
91 int size, ret;
92
93 sdio_claim_host(func);
94
95 func->num = cmd->function;
96 func->cur_blksize = cmd->block_size;
97 if (cmd->block_mode)
98 size = cmd->count * cmd->block_size;
99 else
100 size = cmd->count;
101
102 if (cmd->read_write) { /* write */
103 ret = sdio_memcpy_toio(func, cmd->address, (void *)cmd->buffer, size);
104 } else { /* read */
105 ret = sdio_memcpy_fromio(func, (void *)cmd->buffer, cmd->address, size);
106 }
107
108 sdio_release_host(func);
109
110
111 if (ret < 0) {
112 PRINT_ER("wilc_sdio_cmd53..failed, err(%d)\n", ret);
113 return 0;
114 }
115
116 return 1;
117 }
118
linux_sdio_probe(struct sdio_func * func,const struct sdio_device_id * id)119 static int linux_sdio_probe(struct sdio_func *func, const struct sdio_device_id *id)
120 {
121 struct wilc_sdio *wl_sdio;
122 struct wilc *wilc;
123
124 PRINT_D(INIT_DBG, "probe function\n");
125 wl_sdio = kzalloc(sizeof(struct wilc_sdio), GFP_KERNEL);
126 if (!wl_sdio)
127 return -ENOMEM;
128
129 PRINT_D(INIT_DBG, "Initializing netdev\n");
130 local_sdio_func = func;
131 if (wilc_netdev_init(&wilc)) {
132 PRINT_ER("Couldn't initialize netdev\n");
133 kfree(wl_sdio);
134 return -1;
135 }
136 wl_sdio->func = func;
137 wl_sdio->wilc = wilc;
138 sdio_set_drvdata(func, wl_sdio);
139
140 printk("Driver Initializing success\n");
141 return 0;
142 }
143
linux_sdio_remove(struct sdio_func * func)144 static void linux_sdio_remove(struct sdio_func *func)
145 {
146 struct wilc_sdio *wl_sdio;
147
148 wl_sdio = sdio_get_drvdata(func);
149 wl_wlan_cleanup();
150 kfree(wl_sdio);
151 }
152
153 struct sdio_driver wilc_bus = {
154 .name = SDIO_MODALIAS,
155 .id_table = wilc_sdio_ids,
156 .probe = linux_sdio_probe,
157 .remove = linux_sdio_remove,
158 };
159
enable_sdio_interrupt(void)160 int enable_sdio_interrupt(void)
161 {
162 int ret = 0;
163 #ifndef WILC_SDIO_IRQ_GPIO
164
165 sdio_claim_host(local_sdio_func);
166 ret = sdio_claim_irq(local_sdio_func, wilc_sdio_interrupt);
167 sdio_release_host(local_sdio_func);
168
169 if (ret < 0) {
170 PRINT_ER("can't claim sdio_irq, err(%d)\n", ret);
171 ret = -EIO;
172 }
173 #endif
174 return ret;
175 }
176
disable_sdio_interrupt(void)177 void disable_sdio_interrupt(void)
178 {
179
180 #ifndef WILC_SDIO_IRQ_GPIO
181 int ret;
182
183 PRINT_D(INIT_DBG, "disable_sdio_interrupt IN\n");
184
185 sdio_claim_host(local_sdio_func);
186 ret = sdio_release_irq(local_sdio_func);
187 if (ret < 0) {
188 PRINT_ER("can't release sdio_irq, err(%d)\n", ret);
189 }
190 sdio_release_host(local_sdio_func);
191
192 PRINT_D(INIT_DBG, "disable_sdio_interrupt OUT\n");
193 #endif
194 }
195
linux_sdio_set_speed(int speed)196 static int linux_sdio_set_speed(int speed)
197 {
198 struct mmc_ios ios;
199
200 sdio_claim_host(local_sdio_func);
201
202 memcpy((void *)&ios, (void *)&local_sdio_func->card->host->ios, sizeof(struct mmc_ios));
203 local_sdio_func->card->host->ios.clock = speed;
204 ios.clock = speed;
205 local_sdio_func->card->host->ops->set_ios(local_sdio_func->card->host, &ios);
206 sdio_release_host(local_sdio_func);
207 PRINT_INFO(INIT_DBG, "@@@@@@@@@@@@ change SDIO speed to %d @@@@@@@@@\n", speed);
208
209 return 1;
210 }
211
linux_sdio_get_speed(void)212 static int linux_sdio_get_speed(void)
213 {
214 return local_sdio_func->card->host->ios.clock;
215 }
216
linux_sdio_init(void * pv)217 int linux_sdio_init(void *pv)
218 {
219
220 /**
221 * TODO :
222 **/
223
224
225 sdio_default_speed = linux_sdio_get_speed();
226 return 1;
227 }
228
linux_sdio_deinit(void * pv)229 void linux_sdio_deinit(void *pv)
230 {
231
232 /**
233 * TODO :
234 **/
235
236
237 sdio_unregister_driver(&wilc_bus);
238 }
239
linux_sdio_set_max_speed(void)240 int linux_sdio_set_max_speed(void)
241 {
242 return linux_sdio_set_speed(MAX_SPEED);
243 }
244
linux_sdio_set_default_speed(void)245 int linux_sdio_set_default_speed(void)
246 {
247 return linux_sdio_set_speed(sdio_default_speed);
248 }
249
250
251
252