Merge branch 'chromeos-wifi-3.4' into chromeos-3.4
[cascardo/linux.git] / drivers / staging / gdm72xx / gdm_sdio.c
1 /*
2  * Copyright (c) 2012 GCT Semiconductor, Inc. All rights reserved.
3  *
4  * This software is licensed under the terms of the GNU General Public
5  * License version 2, as published by the Free Software Foundation, and
6  * may be copied, distributed, and modified under those terms.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  */
13
14 #include <linux/module.h>
15 #include <linux/init.h>
16 #include <linux/kernel.h>
17 #include <linux/version.h>
18
19 #include <linux/mmc/core.h>
20 #include <linux/mmc/card.h>
21 #include <linux/mmc/sdio_func.h>
22 #include <linux/mmc/sdio_ids.h>
23
24 #include "gdm_sdio.h"
25 #include "gdm_wimax.h"
26 #include "sdio_boot.h"
27 #include "hci.h"
28
29 #define TYPE_A_HEADER_SIZE      4
30 #define TYPE_A_LOOKAHEAD_SIZE   16
31
32 #define MAX_NR_RX_BUF   4
33
34 #define SDU_TX_BUF_SIZE 2048
35 #define TX_BUF_SIZE             2048
36 #define TX_CHUNK_SIZE   (2048 - TYPE_A_HEADER_SIZE)
37 #define RX_BUF_SIZE             (25*1024)
38
39 #define TX_HZ   2000
40 #define TX_INTERVAL     (1000000/TX_HZ)
41
42 /*#define DEBUG*/
43
44 static int init_sdio(struct sdiowm_dev *sdev);
45 static void release_sdio(struct sdiowm_dev *sdev);
46
47 #ifdef DEBUG
48 static void hexdump(char *title, u8 *data, int len)
49 {
50         int i;
51
52         printk(KERN_DEBUG "%s: length = %d\n", title, len);
53         for (i = 0; i < len; i++) {
54                 printk(KERN_DEBUG "%02x ", data[i]);
55                 if ((i & 0xf) == 0xf)
56                         printk(KERN_DEBUG "\n");
57         }
58         printk(KERN_DEBUG "\n");
59 }
60 #endif
61
62 static struct sdio_tx *alloc_tx_struct(struct tx_cxt *tx)
63 {
64         struct sdio_tx *t = NULL;
65
66         t = kmalloc(sizeof(*t), GFP_ATOMIC);
67         if (t == NULL)
68                 goto out;
69
70         memset(t, 0, sizeof(*t));
71
72         t->buf = kmalloc(TX_BUF_SIZE, GFP_ATOMIC);
73         if (t->buf == NULL)
74                 goto out;
75
76         t->tx_cxt = tx;
77
78         return t;
79 out:
80         if (t) {
81                 kfree(t->buf);
82                 kfree(t);
83         }
84         return NULL;
85 }
86
87 static void free_tx_struct(struct sdio_tx *t)
88 {
89         if (t) {
90                 kfree(t->buf);
91                 kfree(t);
92         }
93 }
94
95 static struct sdio_rx *alloc_rx_struct(struct rx_cxt *rx)
96 {
97         struct sdio_rx *r = NULL;
98
99         r = kmalloc(sizeof(*r), GFP_ATOMIC);
100         if (r == NULL)
101                 goto out;
102
103         memset(r, 0, sizeof(*r));
104
105         r->rx_cxt = rx;
106
107         return r;
108 out:
109         kfree(r);
110         return NULL;
111 }
112
113 static void free_rx_struct(struct sdio_rx *r)
114 {
115         kfree(r);
116 }
117
118 /* Before this function is called, spin lock should be locked. */
119 static struct sdio_tx *get_tx_struct(struct tx_cxt *tx, int *no_spc)
120 {
121         struct sdio_tx *t;
122
123         if (list_empty(&tx->free_list))
124                 return NULL;
125
126         t = list_entry(tx->free_list.prev, struct sdio_tx, list);
127         list_del(&t->list);
128
129         *no_spc = list_empty(&tx->free_list) ? 1 : 0;
130
131         return t;
132 }
133
134 /* Before this function is called, spin lock should be locked. */
135 static void put_tx_struct(struct tx_cxt *tx, struct sdio_tx *t)
136 {
137         list_add_tail(&t->list, &tx->free_list);
138 }
139
140 /* Before this function is called, spin lock should be locked. */
141 static struct sdio_rx *get_rx_struct(struct rx_cxt *rx)
142 {
143         struct sdio_rx *r;
144
145         if (list_empty(&rx->free_list))
146                 return NULL;
147
148         r = list_entry(rx->free_list.prev, struct sdio_rx, list);
149         list_del(&r->list);
150
151         return r;
152 }
153
154 /* Before this function is called, spin lock should be locked. */
155 static void put_rx_struct(struct rx_cxt *rx, struct sdio_rx *r)
156 {
157         list_add_tail(&r->list, &rx->free_list);
158 }
159
160 static int init_sdio(struct sdiowm_dev *sdev)
161 {
162         int ret = 0, i;
163         struct tx_cxt   *tx = &sdev->tx;
164         struct rx_cxt   *rx = &sdev->rx;
165         struct sdio_tx  *t;
166         struct sdio_rx  *r;
167
168         INIT_LIST_HEAD(&tx->free_list);
169         INIT_LIST_HEAD(&tx->sdu_list);
170         INIT_LIST_HEAD(&tx->hci_list);
171
172         spin_lock_init(&tx->lock);
173
174         tx->sdu_buf = kmalloc(SDU_TX_BUF_SIZE, GFP_KERNEL);
175         if (tx->sdu_buf == NULL) {
176                 printk(KERN_ERR "Failed to allocate SDU tx buffer.\n");
177                 goto fail;
178         }
179
180         for (i = 0; i < MAX_NR_SDU_BUF; i++) {
181                 t = alloc_tx_struct(tx);
182                 if (t == NULL) {
183                         ret = -ENOMEM;
184                         goto fail;
185                 }
186                 list_add(&t->list, &tx->free_list);
187         }
188
189         INIT_LIST_HEAD(&rx->free_list);
190         INIT_LIST_HEAD(&rx->req_list);
191
192         spin_lock_init(&rx->lock);
193
194         for (i = 0; i < MAX_NR_RX_BUF; i++) {
195                 r = alloc_rx_struct(rx);
196                 if (r == NULL) {
197                         ret = -ENOMEM;
198                         goto fail;
199                 }
200                 list_add(&r->list, &rx->free_list);
201         }
202
203         rx->rx_buf = kmalloc(RX_BUF_SIZE, GFP_KERNEL);
204         if (rx->rx_buf == NULL) {
205                 printk(KERN_ERR "Failed to allocate rx buffer.\n");
206                 goto fail;
207         }
208
209         return 0;
210
211 fail:
212         release_sdio(sdev);
213         return ret;
214 }
215
216 static void release_sdio(struct sdiowm_dev *sdev)
217 {
218         struct tx_cxt   *tx = &sdev->tx;
219         struct rx_cxt   *rx = &sdev->rx;
220         struct sdio_tx  *t, *t_next;
221         struct sdio_rx  *r, *r_next;
222
223         kfree(tx->sdu_buf);
224
225         list_for_each_entry_safe(t, t_next, &tx->free_list, list) {
226                 list_del(&t->list);
227                 free_tx_struct(t);
228         }
229
230         list_for_each_entry_safe(t, t_next, &tx->sdu_list, list) {
231                 list_del(&t->list);
232                 free_tx_struct(t);
233         }
234
235         list_for_each_entry_safe(t, t_next, &tx->hci_list, list) {
236                 list_del(&t->list);
237                 free_tx_struct(t);
238         }
239
240         kfree(rx->rx_buf);
241
242         list_for_each_entry_safe(r, r_next, &rx->free_list, list) {
243                 list_del(&r->list);
244                 free_rx_struct(r);
245         }
246
247         list_for_each_entry_safe(r, r_next, &rx->req_list, list) {
248                 list_del(&r->list);
249                 free_rx_struct(r);
250         }
251 }
252
253 static void send_sdio_pkt(struct sdio_func *func, u8 *data, int len)
254 {
255         int n, blocks, ret, remain;
256
257         sdio_claim_host(func);
258
259         blocks = len / func->cur_blksize;
260         n = blocks * func->cur_blksize;
261         if (blocks) {
262                 ret = sdio_memcpy_toio(func, 0, data, n);
263                 if (ret < 0) {
264                         if (ret != -ENOMEDIUM)
265                                 printk(KERN_ERR "gdmwms: %s error: ret = %d\n",
266                                         __func__, ret);
267                         goto end_io;
268                 }
269         }
270
271         remain = len - n;
272         remain = (remain + 3) & ~3;
273
274         if (remain) {
275                 ret = sdio_memcpy_toio(func, 0, data + n, remain);
276                 if (ret < 0) {
277                         if (ret != -ENOMEDIUM)
278                                 printk(KERN_ERR "gdmwms: %s error: ret = %d\n",
279                                         __func__, ret);
280                         goto end_io;
281                 }
282         }
283
284 end_io:
285         sdio_release_host(func);
286 }
287
288 static void send_sdu(struct sdio_func *func, struct tx_cxt *tx)
289 {
290         struct list_head *l, *next;
291         struct hci_s *hci;
292         struct sdio_tx *t;
293         int pos, len, i, estlen, aggr_num = 0, aggr_len;
294         u8 *buf;
295         unsigned long flags;
296
297         spin_lock_irqsave(&tx->lock, flags);
298
299         pos = TYPE_A_HEADER_SIZE + HCI_HEADER_SIZE;
300         list_for_each_entry(t, &tx->sdu_list, list) {
301                 estlen = ((t->len + 3) & ~3) + 4;
302                 if ((pos + estlen) > SDU_TX_BUF_SIZE)
303                         break;
304
305                 aggr_num++;
306                 memcpy(tx->sdu_buf + pos, t->buf, t->len);
307                 memset(tx->sdu_buf + pos + t->len, 0, estlen - t->len);
308                 pos += estlen;
309         }
310         aggr_len = pos;
311
312         hci = (struct hci_s *)(tx->sdu_buf + TYPE_A_HEADER_SIZE);
313         hci->cmd_evt = H2B(WIMAX_TX_SDU_AGGR);
314         hci->length = H2B(aggr_len - TYPE_A_HEADER_SIZE - HCI_HEADER_SIZE);
315
316         spin_unlock_irqrestore(&tx->lock, flags);
317
318 #ifdef DEBUG
319         hexdump("sdio_send", tx->sdu_buf + TYPE_A_HEADER_SIZE,
320                 aggr_len - TYPE_A_HEADER_SIZE);
321 #endif
322
323         for (pos = TYPE_A_HEADER_SIZE; pos < aggr_len; pos += TX_CHUNK_SIZE) {
324                 len = aggr_len - pos;
325                 len = len > TX_CHUNK_SIZE ? TX_CHUNK_SIZE : len;
326                 buf = tx->sdu_buf + pos - TYPE_A_HEADER_SIZE;
327
328                 buf[0] = len & 0xff;
329                 buf[1] = (len >> 8) & 0xff;
330                 buf[2] = (len >> 16) & 0xff;
331                 buf[3] = (pos + len) >= aggr_len ? 0 : 1;
332                 send_sdio_pkt(func, buf, len + TYPE_A_HEADER_SIZE);
333         }
334
335         spin_lock_irqsave(&tx->lock, flags);
336
337         for (l = tx->sdu_list.next, i = 0; i < aggr_num; i++, l = next) {
338                 next = l->next;
339                 t = list_entry(l, struct sdio_tx, list);
340                 if (t->callback)
341                         t->callback(t->cb_data);
342
343                 list_del(l);
344                 put_tx_struct(t->tx_cxt, t);
345         }
346
347         do_gettimeofday(&tx->sdu_stamp);
348         spin_unlock_irqrestore(&tx->lock, flags);
349 }
350
351 static void send_hci(struct sdio_func *func, struct tx_cxt *tx,
352                         struct sdio_tx *t)
353 {
354         unsigned long flags;
355
356 #ifdef DEBUG
357         hexdump("sdio_send", t->buf + TYPE_A_HEADER_SIZE,
358                 t->len - TYPE_A_HEADER_SIZE);
359 #endif
360         send_sdio_pkt(func, t->buf, t->len);
361
362         spin_lock_irqsave(&tx->lock, flags);
363         if (t->callback)
364                 t->callback(t->cb_data);
365         free_tx_struct(t);
366         spin_unlock_irqrestore(&tx->lock, flags);
367 }
368
369 static void do_tx(struct work_struct *work)
370 {
371         struct sdiowm_dev *sdev = container_of(work, struct sdiowm_dev, ws);
372         struct sdio_func *func = sdev->func;
373         struct tx_cxt *tx = &sdev->tx;
374         struct sdio_tx *t = NULL;
375         struct timeval now, *before;
376         int is_sdu = 0;
377         long diff;
378         unsigned long flags;
379
380         spin_lock_irqsave(&tx->lock, flags);
381         if (!tx->can_send) {
382                 spin_unlock_irqrestore(&tx->lock, flags);
383                 return;
384         }
385
386         if (!list_empty(&tx->hci_list)) {
387                 t = list_entry(tx->hci_list.next, struct sdio_tx, list);
388                 list_del(&t->list);
389                 is_sdu = 0;
390         } else if (!tx->stop_sdu_tx && !list_empty(&tx->sdu_list)) {
391                 do_gettimeofday(&now);
392                 before = &tx->sdu_stamp;
393
394                 diff = (now.tv_sec - before->tv_sec) * 1000000 +
395                         (now.tv_usec - before->tv_usec);
396                 if (diff >= 0 && diff < TX_INTERVAL) {
397                         schedule_work(&sdev->ws);
398                         spin_unlock_irqrestore(&tx->lock, flags);
399                         return;
400                 }
401                 is_sdu = 1;
402         }
403
404         if (!is_sdu && t == NULL) {
405                 spin_unlock_irqrestore(&tx->lock, flags);
406                 return;
407         }
408
409         tx->can_send = 0;
410
411         spin_unlock_irqrestore(&tx->lock, flags);
412
413         if (is_sdu)
414                 send_sdu(func, tx);
415         else
416                 send_hci(func, tx, t);
417 }
418
419 static int gdm_sdio_send(void *priv_dev, void *data, int len,
420                         void (*cb)(void *data), void *cb_data)
421 {
422         struct sdiowm_dev *sdev = priv_dev;
423         struct tx_cxt *tx = &sdev->tx;
424         struct sdio_tx *t;
425         u8 *pkt = data;
426         int no_spc = 0;
427         u16 cmd_evt;
428         unsigned long flags;
429
430         BUG_ON(len > TX_BUF_SIZE - TYPE_A_HEADER_SIZE);
431
432         spin_lock_irqsave(&tx->lock, flags);
433
434         cmd_evt = (pkt[0] << 8) | pkt[1];
435         if (cmd_evt == WIMAX_TX_SDU) {
436                 t = get_tx_struct(tx, &no_spc);
437                 if (t == NULL) {
438                         /* This case must not happen. */
439                         spin_unlock_irqrestore(&tx->lock, flags);
440                         return -ENOSPC;
441                 }
442                 list_add_tail(&t->list, &tx->sdu_list);
443
444                 memcpy(t->buf, data, len);
445
446                 t->len = len;
447                 t->callback = cb;
448                 t->cb_data = cb_data;
449         } else {
450                 t = alloc_tx_struct(tx);
451                 if (t == NULL) {
452                         spin_unlock_irqrestore(&tx->lock, flags);
453                         return -ENOMEM;
454                 }
455                 list_add_tail(&t->list, &tx->hci_list);
456
457                 t->buf[0] = len & 0xff;
458                 t->buf[1] = (len >> 8) & 0xff;
459                 t->buf[2] = (len >> 16) & 0xff;
460                 t->buf[3] = 2;
461                 memcpy(t->buf + TYPE_A_HEADER_SIZE, data, len);
462
463                 t->len = len + TYPE_A_HEADER_SIZE;
464                 t->callback = cb;
465                 t->cb_data = cb_data;
466         }
467
468         if (tx->can_send)
469                 schedule_work(&sdev->ws);
470
471         spin_unlock_irqrestore(&tx->lock, flags);
472
473         if (no_spc)
474                 return -ENOSPC;
475
476         return 0;
477 }
478
479 /*
480  * Handle the HCI, WIMAX_SDU_TX_FLOW.
481  */
482 static int control_sdu_tx_flow(struct sdiowm_dev *sdev, u8 *hci_data, int len)
483 {
484         struct tx_cxt *tx = &sdev->tx;
485         u16 cmd_evt;
486         unsigned long flags;
487
488         spin_lock_irqsave(&tx->lock, flags);
489
490         cmd_evt = (hci_data[0] << 8) | (hci_data[1]);
491         if (cmd_evt != WIMAX_SDU_TX_FLOW)
492                 goto out;
493
494         if (hci_data[4] == 0) {
495 #ifdef DEBUG
496                 printk(KERN_DEBUG "WIMAX ==> STOP SDU TX\n");
497 #endif
498                 tx->stop_sdu_tx = 1;
499         } else if (hci_data[4] == 1) {
500 #ifdef DEBUG
501                 printk(KERN_DEBUG "WIMAX ==> START SDU TX\n");
502 #endif
503                 tx->stop_sdu_tx = 0;
504                 if (tx->can_send)
505                         schedule_work(&sdev->ws);
506                 /*
507                  * If free buffer for sdu tx doesn't exist, then tx queue
508                  * should not be woken. For this reason, don't pass the command,
509                  * START_SDU_TX.
510                  */
511                 if (list_empty(&tx->free_list))
512                         len = 0;
513         }
514
515 out:
516         spin_unlock_irqrestore(&tx->lock, flags);
517         return len;
518 }
519
520 static void gdm_sdio_irq(struct sdio_func *func)
521 {
522         struct phy_dev *phy_dev = sdio_get_drvdata(func);
523         struct sdiowm_dev *sdev = phy_dev->priv_dev;
524         struct tx_cxt *tx = &sdev->tx;
525         struct rx_cxt *rx = &sdev->rx;
526         struct sdio_rx *r;
527         unsigned long flags;
528         u8 val, hdr[TYPE_A_LOOKAHEAD_SIZE], *buf;
529         u32 len, blocks, n;
530         int ret, remain;
531
532         /* Check interrupt */
533         val = sdio_readb(func, 0x13, &ret);
534         if (val & 0x01)
535                 sdio_writeb(func, 0x01, 0x13, &ret);    /* clear interrupt */
536         else
537                 return;
538
539         ret = sdio_memcpy_fromio(func, hdr, 0x0, TYPE_A_LOOKAHEAD_SIZE);
540         if (ret) {
541                 printk(KERN_ERR "Cannot read from function %d\n", func->num);
542                 goto done;
543         }
544
545         len = (hdr[2] << 16) | (hdr[1] << 8) | hdr[0];
546         if (len > (RX_BUF_SIZE - TYPE_A_HEADER_SIZE)) {
547                 printk(KERN_ERR "Too big Type-A size: %d\n", len);
548                 goto done;
549         }
550
551         if (hdr[3] == 1) {      /* Ack */
552 #ifdef DEBUG
553                 u32 *ack_seq = (u32 *)&hdr[4];
554 #endif
555                 spin_lock_irqsave(&tx->lock, flags);
556                 tx->can_send = 1;
557
558                 if (!list_empty(&tx->sdu_list) || !list_empty(&tx->hci_list))
559                         schedule_work(&sdev->ws);
560                 spin_unlock_irqrestore(&tx->lock, flags);
561 #ifdef DEBUG
562                 printk(KERN_DEBUG "Ack... %0x\n", ntohl(*ack_seq));
563 #endif
564                 goto done;
565         }
566
567         memcpy(rx->rx_buf, hdr + TYPE_A_HEADER_SIZE,
568                         TYPE_A_LOOKAHEAD_SIZE - TYPE_A_HEADER_SIZE);
569
570         buf = rx->rx_buf + TYPE_A_LOOKAHEAD_SIZE - TYPE_A_HEADER_SIZE;
571         remain = len - TYPE_A_LOOKAHEAD_SIZE + TYPE_A_HEADER_SIZE;
572         if (remain <= 0)
573                 goto end_io;
574
575         blocks = remain / func->cur_blksize;
576
577         if (blocks) {
578                 n = blocks * func->cur_blksize;
579                 ret = sdio_memcpy_fromio(func, buf, 0x0, n);
580                 if (ret) {
581                         printk(KERN_ERR "Cannot read from function %d\n",
582                                 func->num);
583                         goto done;
584                 }
585                 buf += n;
586                 remain -= n;
587         }
588
589         if (remain) {
590                 ret = sdio_memcpy_fromio(func, buf, 0x0, remain);
591                 if (ret) {
592                         printk(KERN_ERR "Cannot read from function %d\n",
593                                 func->num);
594                         goto done;
595                 }
596         }
597
598 end_io:
599 #ifdef DEBUG
600         hexdump("sdio_receive", rx->rx_buf, len);
601 #endif
602         len = control_sdu_tx_flow(sdev, rx->rx_buf, len);
603
604         spin_lock_irqsave(&rx->lock, flags);
605
606         if (!list_empty(&rx->req_list)) {
607                 r = list_entry(rx->req_list.next, struct sdio_rx, list);
608                 spin_unlock_irqrestore(&rx->lock, flags);
609                 if (r->callback)
610                         r->callback(r->cb_data, rx->rx_buf, len);
611                 spin_lock_irqsave(&rx->lock, flags);
612                 list_del(&r->list);
613                 put_rx_struct(rx, r);
614         }
615
616         spin_unlock_irqrestore(&rx->lock, flags);
617
618 done:
619         sdio_writeb(func, 0x00, 0x10, &ret);    /* PCRRT */
620         if (!phy_dev->netdev)
621                 register_wimax_device(phy_dev, &func->dev);
622 }
623
624 static int gdm_sdio_receive(void *priv_dev,
625                                 void (*cb)(void *cb_data, void *data, int len),
626                                 void *cb_data)
627 {
628         struct sdiowm_dev *sdev = priv_dev;
629         struct rx_cxt *rx = &sdev->rx;
630         struct sdio_rx *r;
631         unsigned long flags;
632
633         spin_lock_irqsave(&rx->lock, flags);
634         r = get_rx_struct(rx);
635         if (r == NULL) {
636                 spin_unlock_irqrestore(&rx->lock, flags);
637                 return -ENOMEM;
638         }
639
640         r->callback = cb;
641         r->cb_data = cb_data;
642
643         list_add_tail(&r->list, &rx->req_list);
644         spin_unlock_irqrestore(&rx->lock, flags);
645
646         return 0;
647 }
648
649 static int sdio_wimax_probe(struct sdio_func *func,
650                                 const struct sdio_device_id *id)
651 {
652         int ret;
653         struct phy_dev *phy_dev = NULL;
654         struct sdiowm_dev *sdev = NULL;
655
656         printk(KERN_INFO "Found GDM SDIO VID = 0x%04x PID = 0x%04x...\n",
657                         func->vendor, func->device);
658         printk(KERN_INFO "GCT WiMax driver version %s\n", DRIVER_VERSION);
659
660         sdio_claim_host(func);
661         sdio_enable_func(func);
662         sdio_claim_irq(func, gdm_sdio_irq);
663
664         ret = sdio_boot(func);
665         if (ret)
666                 return ret;
667
668         phy_dev = kmalloc(sizeof(*phy_dev), GFP_KERNEL);
669         if (phy_dev == NULL) {
670                 ret = -ENOMEM;
671                 goto out;
672         }
673         sdev = kmalloc(sizeof(*sdev), GFP_KERNEL);
674         if (sdev == NULL) {
675                 ret = -ENOMEM;
676                 goto out;
677         }
678
679         memset(phy_dev, 0, sizeof(*phy_dev));
680         memset(sdev, 0, sizeof(*sdev));
681
682         phy_dev->priv_dev = (void *)sdev;
683         phy_dev->send_func = gdm_sdio_send;
684         phy_dev->rcv_func = gdm_sdio_receive;
685
686         ret = init_sdio(sdev);
687         if (sdev < 0)
688                 goto out;
689
690         sdev->func = func;
691
692         sdio_writeb(func, 1, 0x14, &ret);       /* Enable interrupt */
693         sdio_release_host(func);
694
695         INIT_WORK(&sdev->ws, do_tx);
696
697         sdio_set_drvdata(func, phy_dev);
698 out:
699         if (ret) {
700                 kfree(phy_dev);
701                 kfree(sdev);
702         }
703
704         return ret;
705 }
706
707 static void sdio_wimax_remove(struct sdio_func *func)
708 {
709         struct phy_dev *phy_dev = sdio_get_drvdata(func);
710         struct sdiowm_dev *sdev = phy_dev->priv_dev;
711
712         if (phy_dev->netdev)
713                 unregister_wimax_device(phy_dev);
714         sdio_claim_host(func);
715         sdio_release_irq(func);
716         sdio_disable_func(func);
717         sdio_release_host(func);
718         release_sdio(sdev);
719
720         kfree(sdev);
721         kfree(phy_dev);
722 }
723
724 static const struct sdio_device_id sdio_wimax_ids[] = {
725         { SDIO_DEVICE(0x0296, 0x5347) },
726         {0}
727 };
728
729 MODULE_DEVICE_TABLE(sdio, sdio_wimax_ids);
730
731 static struct sdio_driver sdio_wimax_driver = {
732         .probe          = sdio_wimax_probe,
733         .remove         = sdio_wimax_remove,
734         .name           = "sdio_wimax",
735         .id_table       = sdio_wimax_ids,
736 };
737
738 static int __init sdio_gdm_wimax_init(void)
739 {
740         return sdio_register_driver(&sdio_wimax_driver);
741 }
742
743 static void __exit sdio_gdm_wimax_exit(void)
744 {
745         sdio_unregister_driver(&sdio_wimax_driver);
746 }
747
748 module_init(sdio_gdm_wimax_init);
749 module_exit(sdio_gdm_wimax_exit);
750
751 MODULE_VERSION(DRIVER_VERSION);
752 MODULE_DESCRIPTION("GCT WiMax SDIO Device Driver");
753 MODULE_AUTHOR("Ethan Park");
754 MODULE_LICENSE("GPL");