tizen 2.4 release
[profile/mobile/platform/kernel/linux-3.10-sc7730.git] / drivers / net / wireless / bcmdhd / dhd_linux_platdev.c
1 /*
2  * Linux platform device for DHD WLAN adapter
3  *
4  * Copyright (C) 1999-2015, Broadcom Corporation
5  * 
6  *      Unless you and Broadcom execute a separate written software license
7  * agreement governing use of this software, this software is licensed to you
8  * under the terms of the GNU General Public License version 2 (the "GPL"),
9  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
10  * following added to such license:
11  * 
12  *      As a special exception, the copyright holders of this software give you
13  * permission to link this software with independent modules, and to copy and
14  * distribute the resulting executable under terms of your choice, provided that
15  * you also meet, for each linked independent module, the terms and conditions of
16  * the license of that module.  An independent module is a module which is not
17  * derived from this software.  The special exception does not apply to any
18  * modifications of the software.
19  * 
20  *      Notwithstanding the above, under no circumstances may you combine this
21  * software in any way with any other Broadcom software provided under a license
22  * other than the GPL, without Broadcom's express prior written consent.
23  *
24  * $Id: dhd_linux_platdev.c 401742 2013-05-13 15:03:21Z $
25  */
26 #include <typedefs.h>
27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 #include <linux/init.h>
30 #include <linux/platform_device.h>
31 #include <bcmutils.h>
32 #include <linux_osl.h>
33 #include <dhd_dbg.h>
34 #include <dngl_stats.h>
35 #include <dhd.h>
36 #include <dhd_bus.h>
37 #include <dhd_linux.h>
38 #include <wl_android.h>
39 #if defined(CONFIG_WIFI_CONTROL_FUNC)
40 #include <linux/wlan_plat.h>
41 #endif
42
43 #if !defined(CONFIG_WIFI_CONTROL_FUNC)
44 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 58))
45 #define WLAN_PLAT_NODFS_FLAG    0x01
46 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 58) */
47 struct wifi_platform_data {
48         int (*set_power)(int val);
49         int (*set_reset)(int val);
50         int (*set_carddetect)(int val);
51         void *(*mem_prealloc)(int section, unsigned long size);
52         int (*get_mac_addr)(unsigned char *buf);
53 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 58))
54         void *(*get_country_code)(char *ccode, u32 flags);
55 #else
56         void *(*get_country_code)(char *ccode);
57 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 58) */
58 };
59 #endif /* CONFIG_WIFI_CONTROL_FUNC */
60
61 #define WIFI_PLAT_NAME          "bcmdhd_wlan"
62 #define WIFI_PLAT_NAME2         "bcm4329_wlan"
63 #define WIFI_PLAT_EXT           "bcmdhd_wifi_platform"
64
65 bool cfg_multichip = FALSE;
66 bcmdhd_wifi_platdata_t *dhd_wifi_platdata = NULL;
67 static int wifi_plat_dev_probe_ret = 0;
68 static bool is_power_on = FALSE;
69 #ifdef DHD_OF_SUPPORT
70 static bool dts_enabled = TRUE;
71 extern struct resource dhd_wlan_resources;
72 extern struct wifi_platform_data dhd_wlan_control;
73 #else
74 static bool dts_enabled = FALSE;
75 struct resource dhd_wlan_resources = {0};
76 struct wifi_platform_data dhd_wlan_control = {0};
77 #endif /* CONFIG_OF && !defined(CONFIG_ARCH_MSM) */
78
79 static int dhd_wifi_platform_load(void);
80
81 extern void* wl_cfg80211_get_dhdp(void);
82
83 #ifdef ENABLE_4335BT_WAR
84 extern int bcm_bt_lock(int cookie);
85 extern void bcm_bt_unlock(int cookie);
86 static int lock_cookie_wifi = 'W' | 'i'<<8 | 'F'<<16 | 'i'<<24; /* cookie is "WiFi" */
87 #endif /* ENABLE_4335BT_WAR */
88
89 wifi_adapter_info_t* dhd_wifi_platform_get_adapter(uint32 bus_type, uint32 bus_num, uint32 slot_num)
90 {
91         int i;
92
93         if (dhd_wifi_platdata == NULL)
94                 return NULL;
95
96         for (i = 0; i < dhd_wifi_platdata->num_adapters; i++) {
97                 wifi_adapter_info_t *adapter = &dhd_wifi_platdata->adapters[i];
98                 if ((adapter->bus_type == -1 || adapter->bus_type == bus_type) &&
99                         (adapter->bus_num == -1 || adapter->bus_num == bus_num) &&
100                         (adapter->slot_num == -1 || adapter->slot_num == slot_num)) {
101                         DHD_TRACE(("found adapter info '%s'\n", adapter->name));
102                         return adapter;
103                 }
104         }
105         return NULL;
106 }
107
108 void* wifi_platform_prealloc(wifi_adapter_info_t *adapter, int section, unsigned long size)
109 {
110         void *alloc_ptr = NULL;
111         struct wifi_platform_data *plat_data;
112
113         if (!adapter || !adapter->wifi_plat_data)
114                 return NULL;
115         plat_data = adapter->wifi_plat_data;
116         if (plat_data->mem_prealloc) {
117                 alloc_ptr = plat_data->mem_prealloc(section, size);
118                 if (alloc_ptr) {
119                         DHD_INFO(("success alloc section %d\n", section));
120                         if (size != 0L)
121                                 bzero(alloc_ptr, size);
122                         return alloc_ptr;
123                 }
124         }
125
126         DHD_ERROR(("%s: failed to alloc static mem section %d\n", __FUNCTION__, section));
127         return NULL;
128 }
129
130 void* wifi_platform_get_prealloc_func_ptr(wifi_adapter_info_t *adapter)
131 {
132         struct wifi_platform_data *plat_data;
133
134         if (!adapter || !adapter->wifi_plat_data)
135                 return NULL;
136         plat_data = adapter->wifi_plat_data;
137         return plat_data->mem_prealloc;
138 }
139
140 int wifi_platform_get_irq_number(wifi_adapter_info_t *adapter, unsigned long *irq_flags_ptr)
141 {
142         if (adapter == NULL)
143                 return -1;
144         if (irq_flags_ptr)
145                 *irq_flags_ptr = adapter->intr_flags;
146         return adapter->irq_num;
147 }
148
149 int wifi_platform_set_power(wifi_adapter_info_t *adapter, bool on, unsigned long msec)
150 {
151         int err = 0;
152         struct wifi_platform_data *plat_data;
153
154         if (!adapter || !adapter->wifi_plat_data)
155                 return -EINVAL;
156         plat_data = adapter->wifi_plat_data;
157
158         DHD_ERROR(("%s = %d\n", __FUNCTION__, on));
159         if (plat_data->set_power) {
160 #ifdef ENABLE_4335BT_WAR
161                 if (on) {
162                         printk("WiFi: trying to acquire BT lock\n");
163                         if (bcm_bt_lock(lock_cookie_wifi) != 0)
164                                 printk("** WiFi: timeout in acquiring bt lock**\n");
165                         printk("%s: btlock acquired\n", __FUNCTION__);
166                 }
167                 else {
168                         /* For a exceptional case, release btlock */
169                         bcm_bt_unlock(lock_cookie_wifi);
170                 }
171 #endif /* ENABLE_4335BT_WAR */
172
173                 err = plat_data->set_power(on);
174         }
175
176         if (msec && !err)
177                 OSL_SLEEP(msec);
178
179         if (on && !err)
180                 is_power_on = TRUE;
181         else
182                 is_power_on = FALSE;
183
184         return err;
185 }
186
187 int wifi_platform_bus_enumerate(wifi_adapter_info_t *adapter, bool device_present)
188 {
189         int err = 0;
190         struct wifi_platform_data *plat_data;
191
192         if (!adapter || !adapter->wifi_plat_data)
193                 return -EINVAL;
194         plat_data = adapter->wifi_plat_data;
195
196         DHD_ERROR(("%s device present %d\n", __FUNCTION__, device_present));
197         if (plat_data->set_carddetect) {
198                 err = plat_data->set_carddetect(device_present);
199         }
200         return err;
201
202 }
203
204 int wifi_platform_get_mac_addr(wifi_adapter_info_t *adapter, unsigned char *buf)
205 {
206         struct wifi_platform_data *plat_data;
207
208         DHD_ERROR(("%s\n", __FUNCTION__));
209         if (!buf || !adapter || !adapter->wifi_plat_data)
210                 return -EINVAL;
211         plat_data = adapter->wifi_plat_data;
212         if (plat_data->get_mac_addr) {
213                 return plat_data->get_mac_addr(buf);
214         }
215         return -EOPNOTSUPP;
216 }
217
218 void *wifi_platform_get_country_code(wifi_adapter_info_t *adapter, char *ccode)
219 {
220         /* get_country_code was added after 2.6.39 */
221 #if     (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 39))
222         struct wifi_platform_data *plat_data;
223
224         if (!ccode || !adapter || !adapter->wifi_plat_data)
225                 return NULL;
226         plat_data = adapter->wifi_plat_data;
227
228         DHD_TRACE(("%s\n", __FUNCTION__));
229         if (plat_data->get_country_code) {
230 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 58))
231                 return plat_data->get_country_code(ccode, WLAN_PLAT_NODFS_FLAG);
232 #else
233                 return plat_data->get_country_code(ccode);
234 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 58)) */
235         }
236 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 39)) */
237
238         return NULL;
239 }
240
241 static int wifi_plat_dev_drv_probe(struct platform_device *pdev)
242 {
243         struct resource *resource;
244         wifi_adapter_info_t *adapter;
245
246         /* Android style wifi platform data device ("bcmdhd_wlan" or "bcm4329_wlan")
247          * is kept for backward compatibility and supports only 1 adapter
248          */
249         ASSERT(dhd_wifi_platdata != NULL);
250         ASSERT(dhd_wifi_platdata->num_adapters == 1);
251         adapter = &dhd_wifi_platdata->adapters[0];
252         adapter->wifi_plat_data = (struct wifi_platform_data *)(pdev->dev.platform_data);
253
254         resource = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "bcmdhd_wlan_irq");
255         if (resource == NULL)
256                 resource = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "bcm4329_wlan_irq");
257         if (resource) {
258                 adapter->irq_num = resource->start;
259                 adapter->intr_flags = resource->flags;
260         }
261
262         wifi_plat_dev_probe_ret = dhd_wifi_platform_load();
263         return wifi_plat_dev_probe_ret;
264 }
265
266 static int wifi_plat_dev_drv_remove(struct platform_device *pdev)
267 {
268         wifi_adapter_info_t *adapter;
269
270         /* Android style wifi platform data device ("bcmdhd_wlan" or "bcm4329_wlan")
271          * is kept for backward compatibility and supports only 1 adapter
272          */
273         ASSERT(dhd_wifi_platdata != NULL);
274         ASSERT(dhd_wifi_platdata->num_adapters == 1);
275         adapter = &dhd_wifi_platdata->adapters[0];
276         if (is_power_on) {
277                 wifi_platform_set_power(adapter, FALSE, WIFI_TURNOFF_DELAY);
278                 wifi_platform_bus_enumerate(adapter, FALSE);
279         }
280
281         return 0;
282 }
283
284 static int wifi_plat_dev_drv_suspend(struct platform_device *pdev, pm_message_t state)
285 {
286         DHD_TRACE(("##> %s\n", __FUNCTION__));
287 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 39)) && defined(OOB_INTR_ONLY)
288         bcmsdh_oob_intr_set(0);
289 #endif /* (OOB_INTR_ONLY) */
290         return 0;
291 }
292
293 static int wifi_plat_dev_drv_resume(struct platform_device *pdev)
294 {
295         DHD_TRACE(("##> %s\n", __FUNCTION__));
296 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 39)) && defined(OOB_INTR_ONLY)
297         if (dhd_os_check_if_up(wl_cfg80211_get_dhdp()))
298                 bcmsdh_oob_intr_set(1);
299 #endif /* (OOB_INTR_ONLY) */
300         return 0;
301 }
302
303 static struct platform_driver wifi_platform_dev_driver = {
304         .probe          = wifi_plat_dev_drv_probe,
305         .remove         = wifi_plat_dev_drv_remove,
306         .suspend        = wifi_plat_dev_drv_suspend,
307         .resume         = wifi_plat_dev_drv_resume,
308         .driver         = {
309         .name   = WIFI_PLAT_NAME,
310         }
311 };
312
313 static struct platform_driver wifi_platform_dev_driver_legacy = {
314         .probe          = wifi_plat_dev_drv_probe,
315         .remove         = wifi_plat_dev_drv_remove,
316         .suspend        = wifi_plat_dev_drv_suspend,
317         .resume         = wifi_plat_dev_drv_resume,
318         .driver         = {
319         .name   = WIFI_PLAT_NAME2,
320         }
321 };
322
323 static int wifi_platdev_match(struct device *dev, void *data)
324 {
325         char *name = (char*)data;
326         struct platform_device *pdev = to_platform_device(dev);
327
328         if (strcmp(pdev->name, name) == 0) {
329                 DHD_ERROR(("found wifi platform device %s\n", name));
330                 return TRUE;
331         }
332
333         return FALSE;
334 }
335
336 static int wifi_ctrlfunc_register_drv(void)
337 {
338         int err = 0;
339         struct device *dev1, *dev2;
340         wifi_adapter_info_t *adapter;
341
342         dev1 = bus_find_device(&platform_bus_type, NULL, WIFI_PLAT_NAME, wifi_platdev_match);
343         dev2 = bus_find_device(&platform_bus_type, NULL, WIFI_PLAT_NAME2, wifi_platdev_match);
344         if (!dts_enabled) {
345                 if (dev1 == NULL && dev2 == NULL) {
346                         DHD_ERROR(("no wifi platform data, skip\n"));
347                         return -ENXIO;
348                 }
349         }
350
351         /* multi-chip support not enabled, build one adapter information for
352          * DHD (either SDIO, USB or PCIe)
353          */
354         adapter = kzalloc(sizeof(wifi_adapter_info_t), GFP_KERNEL);
355         adapter->name = "DHD generic adapter";
356         adapter->bus_type = -1;
357         adapter->bus_num = -1;
358         adapter->slot_num = -1;
359         adapter->irq_num = -1;
360         is_power_on = FALSE;
361         wifi_plat_dev_probe_ret = 0;
362         dhd_wifi_platdata = kzalloc(sizeof(bcmdhd_wifi_platdata_t), GFP_KERNEL);
363         dhd_wifi_platdata->num_adapters = 1;
364         dhd_wifi_platdata->adapters = adapter;
365
366         if (dev1) {
367                 err = platform_driver_register(&wifi_platform_dev_driver);
368                 if (err) {
369                         DHD_ERROR(("%s: failed to register wifi ctrl func driver\n",
370                                 __FUNCTION__));
371                         return err;
372                 }
373         }
374         if (dev2) {
375                 err = platform_driver_register(&wifi_platform_dev_driver_legacy);
376                 if (err) {
377                         DHD_ERROR(("%s: failed to register wifi ctrl func legacy driver\n",
378                                 __FUNCTION__));
379                         return err;
380                 }
381         }
382
383         if (dts_enabled) {
384                 struct resource *resource;
385                 adapter->wifi_plat_data = (void *)&dhd_wlan_control;
386                 resource = &dhd_wlan_resources;
387                 adapter->irq_num = resource->start;
388                 adapter->intr_flags = resource->flags;
389                 wifi_plat_dev_probe_ret = dhd_wifi_platform_load();
390         }
391
392         /* return probe function's return value if registeration succeeded */
393         return wifi_plat_dev_probe_ret;
394 }
395
396 void wifi_ctrlfunc_unregister_drv(void)
397 {
398         struct device *dev1, *dev2;
399
400         dev1 = bus_find_device(&platform_bus_type, NULL, WIFI_PLAT_NAME, wifi_platdev_match);
401         dev2 = bus_find_device(&platform_bus_type, NULL, WIFI_PLAT_NAME2, wifi_platdev_match);
402         if (!dts_enabled)
403                 if (dev1 == NULL && dev2 == NULL)
404                         return;
405
406         DHD_ERROR(("unregister wifi platform drivers\n"));
407         if (dev1)
408                 platform_driver_unregister(&wifi_platform_dev_driver);
409         if (dev2)
410                 platform_driver_unregister(&wifi_platform_dev_driver_legacy);
411         if (dts_enabled) {
412                 wifi_adapter_info_t *adapter;
413                 adapter = &dhd_wifi_platdata->adapters[0];
414                 if (is_power_on) {
415                         wifi_platform_set_power(adapter, FALSE, WIFI_TURNOFF_DELAY);
416                         wifi_platform_bus_enumerate(adapter, FALSE);
417                 }
418         }
419         kfree(dhd_wifi_platdata->adapters);
420         dhd_wifi_platdata->adapters = NULL;
421         dhd_wifi_platdata->num_adapters = 0;
422         kfree(dhd_wifi_platdata);
423         dhd_wifi_platdata = NULL;
424 }
425
426 static int bcmdhd_wifi_plat_dev_drv_probe(struct platform_device *pdev)
427 {
428         dhd_wifi_platdata = (bcmdhd_wifi_platdata_t *)(pdev->dev.platform_data);
429
430         return dhd_wifi_platform_load();
431 }
432
433 static int bcmdhd_wifi_plat_dev_drv_remove(struct platform_device *pdev)
434 {
435         int i;
436         wifi_adapter_info_t *adapter;
437         ASSERT(dhd_wifi_platdata != NULL);
438
439         /* power down all adapters */
440         for (i = 0; i < dhd_wifi_platdata->num_adapters; i++) {
441                 adapter = &dhd_wifi_platdata->adapters[i];
442                 wifi_platform_set_power(adapter, FALSE, WIFI_TURNOFF_DELAY);
443                 wifi_platform_bus_enumerate(adapter, FALSE);
444         }
445         return 0;
446 }
447
448 static struct platform_driver dhd_wifi_platform_dev_driver = {
449         .probe          = bcmdhd_wifi_plat_dev_drv_probe,
450         .remove         = bcmdhd_wifi_plat_dev_drv_remove,
451         .driver         = {
452         .name   = WIFI_PLAT_EXT,
453         }
454 };
455
456 int dhd_wifi_platform_register_drv(void)
457 {
458         int err = 0;
459         struct device *dev;
460
461         /* register Broadcom wifi platform data driver if multi-chip is enabled,
462          * otherwise use Android style wifi platform data (aka wifi control function)
463          * if it exists
464          *
465          * to support multi-chip DHD, Broadcom wifi platform data device must
466          * be added in kernel early boot (e.g. board config file).
467          */
468         if (cfg_multichip) {
469                 dev = bus_find_device(&platform_bus_type, NULL, WIFI_PLAT_EXT, wifi_platdev_match);
470                 if (dev == NULL) {
471                         DHD_ERROR(("bcmdhd wifi platform data device not found!!\n"));
472                         return -ENXIO;
473                 }
474                 err = platform_driver_register(&dhd_wifi_platform_dev_driver);
475         } else {
476                 err = wifi_ctrlfunc_register_drv();
477
478                 /* no wifi ctrl func either, load bus directly and ignore this error */
479                 if (err) {
480                         if (err == -ENXIO) {
481                                 /* wifi ctrl function does not exist */
482                                 err = dhd_wifi_platform_load();
483                         } else {
484                                 /* unregister driver due to initialization failure */
485                                 wifi_ctrlfunc_unregister_drv();
486                         }
487                 }
488         }
489
490         return err;
491 }
492
493 #ifdef BCMPCIE
494 static int dhd_wifi_platform_load_pcie(void)
495 {
496         int err = 0;
497         err = dhd_bus_register();
498         return err;
499 }
500 #else
501 static int dhd_wifi_platform_load_pcie(void)
502 {
503         return 0;
504 }
505 #endif /* BCMPCIE  */
506
507
508 void dhd_wifi_platform_unregister_drv(void)
509 {
510         if (cfg_multichip)
511                 platform_driver_unregister(&dhd_wifi_platform_dev_driver);
512         else
513                 wifi_ctrlfunc_unregister_drv();
514 }
515
516 extern int dhd_watchdog_prio;
517 extern int dhd_dpc_prio;
518 extern uint dhd_deferred_tx;
519 #if defined(BCMLXSDMMC)
520 extern struct semaphore dhd_registration_sem;
521 #endif 
522
523 static int dhd_wifi_platform_load_sdio(void)
524 {
525         int i;
526         int err = 0;
527         wifi_adapter_info_t *adapter;
528
529         BCM_REFERENCE(i);
530         BCM_REFERENCE(adapter);
531         /* Sanity check on the module parameters
532          * - Both watchdog and DPC as tasklets are ok
533          * - If both watchdog and DPC are threads, TX must be deferred
534          */
535         if (!(dhd_watchdog_prio < 0 && dhd_dpc_prio < 0) &&
536                 !(dhd_watchdog_prio >= 0 && dhd_dpc_prio >= 0 && dhd_deferred_tx))
537                 return -EINVAL;
538
539 #if defined(BCMLXSDMMC)
540         if (dhd_wifi_platdata == NULL) {
541                 DHD_ERROR(("DHD wifi platform data is required for Android build\n"));
542                 return -EINVAL;
543         }
544
545         sema_init(&dhd_registration_sem, 0);
546         /* power up all adapters */
547         for (i = 0; i < dhd_wifi_platdata->num_adapters; i++) {
548                 bool chip_up = FALSE;
549                 int retry = POWERUP_MAX_RETRY;
550                 struct semaphore dhd_chipup_sem;
551
552                 adapter = &dhd_wifi_platdata->adapters[i];
553
554                 DHD_ERROR(("Power-up adapter '%s'\n", adapter->name));
555                 DHD_INFO((" - irq %d [flags %d], firmware: %s, nvram: %s\n",
556                         adapter->irq_num, adapter->intr_flags, adapter->fw_path, adapter->nv_path));
557                 DHD_INFO((" - bus type %d, bus num %d, slot num %d\n\n",
558                         adapter->bus_type, adapter->bus_num, adapter->slot_num));
559
560                 do {
561                         sema_init(&dhd_chipup_sem, 0);
562                         err = dhd_bus_reg_sdio_notify(&dhd_chipup_sem);
563                         if (err) {
564                                 DHD_ERROR(("%s dhd_bus_reg_sdio_notify fail(%d)\n\n",
565                                         __FUNCTION__, err));
566                                 return err;
567                         }
568                         err = wifi_platform_set_power(adapter, TRUE, WIFI_TURNON_DELAY);
569                         if (err) {
570                                 /* WL_REG_ON state unknown, Power off forcely */
571                                 wifi_platform_set_power(adapter, FALSE, WIFI_TURNOFF_DELAY);
572                                 continue;
573                         } else {
574                                 wifi_platform_bus_enumerate(adapter, TRUE);
575                                 err = 0;
576                         }
577
578                         if (down_timeout(&dhd_chipup_sem, msecs_to_jiffies(POWERUP_WAIT_MS)) == 0) {
579                                 dhd_bus_unreg_sdio_notify();
580                                 chip_up = TRUE;
581                                 break;
582                         }
583
584                         DHD_ERROR(("failed to power up %s, %d retry left\n", adapter->name, retry));
585                         dhd_bus_unreg_sdio_notify();
586                         wifi_platform_set_power(adapter, FALSE, WIFI_TURNOFF_DELAY);
587                         wifi_platform_bus_enumerate(adapter, FALSE);
588                 } while (retry--);
589
590                 if (!chip_up) {
591                         DHD_ERROR(("failed to power up %s, max retry reached**\n", adapter->name));
592                         return -ENODEV;
593                 }
594
595         }
596
597         err = dhd_bus_register();
598
599         if (err) {
600                 DHD_ERROR(("%s: sdio_register_driver failed\n", __FUNCTION__));
601                 goto fail;
602         }
603
604
605         /*
606          * Wait till MMC sdio_register_driver callback called and made driver attach.
607          * It's needed to make sync up exit from dhd insmod  and
608          * Kernel MMC sdio device callback registration
609          */
610         err = down_timeout(&dhd_registration_sem, msecs_to_jiffies(DHD_REGISTRATION_TIMEOUT));
611         if (err) {
612                 DHD_ERROR(("%s: sdio_register_driver timeout or error \n", __FUNCTION__));
613                 dhd_bus_unregister();
614                 goto fail;
615         }
616
617         return err;
618
619 fail:
620         /* power down all adapters */
621         for (i = 0; i < dhd_wifi_platdata->num_adapters; i++) {
622                 adapter = &dhd_wifi_platdata->adapters[i];
623                 wifi_platform_set_power(adapter, FALSE, WIFI_TURNOFF_DELAY);
624                 wifi_platform_bus_enumerate(adapter, FALSE);
625         }
626 #else
627
628         /* x86 bring-up PC needs no power-up operations */
629         err = dhd_bus_register();
630
631 #endif 
632
633         return err;
634 }
635
636 static int dhd_wifi_platform_load_usb(void)
637 {
638         return 0;
639 }
640
641 static int dhd_wifi_platform_load()
642 {
643         int err = 0;
644
645                 wl_android_init();
646
647         if ((err = dhd_wifi_platform_load_usb()))
648                 goto end;
649         else if ((err = dhd_wifi_platform_load_sdio()))
650                 goto end;
651         else
652                 err = dhd_wifi_platform_load_pcie();
653
654 end:
655         if (err)
656                 wl_android_exit();
657         else
658                 wl_android_post_init();
659
660         return err;
661 }