dhd_linux_platdev.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. /*
  2. * Linux platform device for DHD WLAN adapter
  3. *
  4. * Copyright (C) 1999-2014, 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. #if !defined(CONFIG_WIFI_CONTROL_FUNC)
  43. struct wifi_platform_data {
  44. int (*set_power)(int val);
  45. int (*set_reset)(int val);
  46. int (*set_carddetect)(int val);
  47. void *(*mem_prealloc)(int section, unsigned long size);
  48. int (*get_mac_addr)(unsigned char *buf);
  49. void *(*get_country_code)(char *ccode);
  50. };
  51. #endif /* CONFIG_WIFI_CONTROL_FUNC */
  52. #define WIFI_PLAT_NAME "bcmdhd_wlan"
  53. #define WIFI_PLAT_NAME2 "bcm4329_wlan"
  54. #define WIFI_PLAT_EXT "bcmdhd_wifi_platform"
  55. bool cfg_multichip = FALSE;
  56. bcmdhd_wifi_platdata_t *dhd_wifi_platdata = NULL;
  57. static int wifi_plat_dev_probe_ret = 0;
  58. static bool is_power_on = FALSE;
  59. #ifdef DHD_OF_SUPPORT
  60. static bool dts_enabled = TRUE;
  61. extern struct resource dhd_wlan_resources;
  62. extern struct wifi_platform_data dhd_wlan_control;
  63. #else
  64. static bool dts_enabled = FALSE;
  65. struct resource dhd_wlan_resources = {0};
  66. struct wifi_platform_data dhd_wlan_control = {0};
  67. #endif /* CONFIG_OF && !defined(CONFIG_ARCH_MSM) */
  68. static int dhd_wifi_platform_load(void);
  69. extern void* wl_cfg80211_get_dhdp(void);
  70. #ifdef ENABLE_4335BT_WAR
  71. extern int bcm_bt_lock(int cookie);
  72. extern void bcm_bt_unlock(int cookie);
  73. static int lock_cookie_wifi = 'W' | 'i'<<8 | 'F'<<16 | 'i'<<24; /* cookie is "WiFi" */
  74. #endif /* ENABLE_4335BT_WAR */
  75. wifi_adapter_info_t* dhd_wifi_platform_get_adapter(uint32 bus_type, uint32 bus_num, uint32 slot_num)
  76. {
  77. int i;
  78. if (dhd_wifi_platdata == NULL)
  79. return NULL;
  80. for (i = 0; i < dhd_wifi_platdata->num_adapters; i++) {
  81. wifi_adapter_info_t *adapter = &dhd_wifi_platdata->adapters[i];
  82. if ((adapter->bus_type == -1 || adapter->bus_type == bus_type) &&
  83. (adapter->bus_num == -1 || adapter->bus_num == bus_num) &&
  84. (adapter->slot_num == -1 || adapter->slot_num == slot_num)) {
  85. DHD_TRACE(("found adapter info '%s'\n", adapter->name));
  86. return adapter;
  87. }
  88. }
  89. return NULL;
  90. }
  91. void* wifi_platform_prealloc(wifi_adapter_info_t *adapter, int section, unsigned long size)
  92. {
  93. void *alloc_ptr = NULL;
  94. struct wifi_platform_data *plat_data;
  95. if (!adapter || !adapter->wifi_plat_data)
  96. return NULL;
  97. plat_data = adapter->wifi_plat_data;
  98. if (plat_data->mem_prealloc) {
  99. alloc_ptr = plat_data->mem_prealloc(section, size);
  100. if (alloc_ptr) {
  101. DHD_INFO(("success alloc section %d\n", section));
  102. if (size != 0L)
  103. bzero(alloc_ptr, size);
  104. return alloc_ptr;
  105. }
  106. }
  107. DHD_ERROR(("%s: failed to alloc static mem section %d\n", __FUNCTION__, section));
  108. return NULL;
  109. }
  110. void* wifi_platform_get_prealloc_func_ptr(wifi_adapter_info_t *adapter)
  111. {
  112. struct wifi_platform_data *plat_data;
  113. if (!adapter || !adapter->wifi_plat_data)
  114. return NULL;
  115. plat_data = adapter->wifi_plat_data;
  116. return plat_data->mem_prealloc;
  117. }
  118. int wifi_platform_get_irq_number(wifi_adapter_info_t *adapter, unsigned long *irq_flags_ptr)
  119. {
  120. if (adapter == NULL)
  121. return -1;
  122. if (irq_flags_ptr)
  123. *irq_flags_ptr = adapter->intr_flags;
  124. return adapter->irq_num;
  125. }
  126. #ifdef ENABLE_4335BT_WAR
  127. bool check_bcm4335_rev(void)
  128. {
  129. int ret = -1;
  130. struct file *fp = NULL;
  131. char *filepath = "/data/.rev";
  132. char chip_rev[10]={0,};
  133. bool is_revb0 = true;
  134. printk("check BCM4335, check_bcm4335_rev \n");
  135. fp = filp_open(filepath, O_RDONLY, 0);
  136. if (IS_ERR(fp)) {
  137. printk("/data/.rev file open error\n");
  138. is_revb0 = true;
  139. } else {
  140. printk("/data/.rev file Found\n");
  141. ret = kernel_read(fp, 0, (char *)chip_rev, 9);
  142. if(ret != -1 && NULL != strstr(chip_rev,"BCM4335B0")) {
  143. printk("Found BCM4335B0\n");
  144. is_revb0 = true;
  145. } else {
  146. is_revb0 = false;
  147. }
  148. filp_close(fp, NULL);
  149. }
  150. return is_revb0;
  151. }
  152. #endif
  153. int wifi_platform_set_power(wifi_adapter_info_t *adapter, bool on, unsigned long msec)
  154. {
  155. int err = 0;
  156. struct wifi_platform_data *plat_data;
  157. #ifdef ENABLE_4335BT_WAR
  158. bool is4335_revb0 = true;
  159. #endif
  160. if (!adapter || !adapter->wifi_plat_data)
  161. return -EINVAL;
  162. plat_data = adapter->wifi_plat_data;
  163. DHD_ERROR(("%s = %d\n", __FUNCTION__, on));
  164. if (plat_data->set_power) {
  165. #ifdef ENABLE_4335BT_WAR
  166. if (on) {
  167. printk("WiFi: trying to acquire BT lock\n");
  168. if (bcm_bt_lock(lock_cookie_wifi) != 0)
  169. printk("** WiFi: timeout in acquiring bt lock**\n");
  170. printk("%s: btlock acquired\n", __FUNCTION__);
  171. }
  172. else {
  173. /* For a exceptional case, release btlock */
  174. bcm_bt_unlock(lock_cookie_wifi);
  175. }
  176. #endif /* ENABLE_4335BT_WAR */
  177. #ifdef ENABLE_4335BT_WAR
  178. is4335_revb0 = check_bcm4335_rev();
  179. err = plat_data->set_power(on,is4335_revb0);
  180. #else
  181. err = plat_data->set_power(on);
  182. #endif
  183. }
  184. if (msec && !err)
  185. OSL_SLEEP(msec);
  186. if (on && !err)
  187. is_power_on = TRUE;
  188. else
  189. is_power_on = FALSE;
  190. return err;
  191. }
  192. int wifi_platform_bus_enumerate(wifi_adapter_info_t *adapter, bool device_present)
  193. {
  194. int err = 0;
  195. struct wifi_platform_data *plat_data;
  196. if (!adapter || !adapter->wifi_plat_data)
  197. return -EINVAL;
  198. plat_data = adapter->wifi_plat_data;
  199. DHD_ERROR(("%s device present %d\n", __FUNCTION__, device_present));
  200. if (plat_data->set_carddetect) {
  201. err = plat_data->set_carddetect(device_present);
  202. }
  203. return err;
  204. }
  205. int wifi_platform_get_mac_addr(wifi_adapter_info_t *adapter, unsigned char *buf)
  206. {
  207. struct wifi_platform_data *plat_data;
  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. void *wifi_platform_get_country_code(wifi_adapter_info_t *adapter, char *ccode)
  218. {
  219. /* get_country_code was added after 2.6.39 */
  220. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 39))
  221. struct wifi_platform_data *plat_data;
  222. if (!ccode || !adapter || !adapter->wifi_plat_data)
  223. return NULL;
  224. plat_data = adapter->wifi_plat_data;
  225. DHD_TRACE(("%s\n", __FUNCTION__));
  226. if (plat_data->get_country_code) {
  227. return plat_data->get_country_code(ccode);
  228. }
  229. #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 39)) */
  230. return NULL;
  231. }
  232. static int wifi_plat_dev_drv_probe(struct platform_device *pdev)
  233. {
  234. struct resource *resource;
  235. wifi_adapter_info_t *adapter;
  236. /* Android style wifi platform data device ("bcmdhd_wlan" or "bcm4329_wlan")
  237. * is kept for backward compatibility and supports only 1 adapter
  238. */
  239. ASSERT(dhd_wifi_platdata != NULL);
  240. ASSERT(dhd_wifi_platdata->num_adapters == 1);
  241. adapter = &dhd_wifi_platdata->adapters[0];
  242. adapter->wifi_plat_data = (struct wifi_platform_data *)(pdev->dev.platform_data);
  243. resource = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "bcmdhd_wlan_irq");
  244. if (resource == NULL)
  245. resource = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "bcm4329_wlan_irq");
  246. if (resource) {
  247. adapter->irq_num = resource->start;
  248. adapter->intr_flags = resource->flags;
  249. }
  250. wifi_plat_dev_probe_ret = dhd_wifi_platform_load();
  251. return wifi_plat_dev_probe_ret;
  252. }
  253. static int wifi_plat_dev_drv_remove(struct platform_device *pdev)
  254. {
  255. wifi_adapter_info_t *adapter;
  256. /* Android style wifi platform data device ("bcmdhd_wlan" or "bcm4329_wlan")
  257. * is kept for backward compatibility and supports only 1 adapter
  258. */
  259. ASSERT(dhd_wifi_platdata != NULL);
  260. ASSERT(dhd_wifi_platdata->num_adapters == 1);
  261. adapter = &dhd_wifi_platdata->adapters[0];
  262. if (is_power_on) {
  263. wifi_platform_set_power(adapter, FALSE, WIFI_TURNOFF_DELAY);
  264. wifi_platform_bus_enumerate(adapter, FALSE);
  265. }
  266. return 0;
  267. }
  268. static int wifi_plat_dev_drv_suspend(struct platform_device *pdev, pm_message_t state)
  269. {
  270. DHD_TRACE(("##> %s\n", __FUNCTION__));
  271. #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 39)) && defined(OOB_INTR_ONLY)
  272. bcmsdh_oob_intr_set(0);
  273. #endif /* (OOB_INTR_ONLY) */
  274. return 0;
  275. }
  276. static int wifi_plat_dev_drv_resume(struct platform_device *pdev)
  277. {
  278. DHD_TRACE(("##> %s\n", __FUNCTION__));
  279. #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 39)) && defined(OOB_INTR_ONLY)
  280. if (dhd_os_check_if_up(wl_cfg80211_get_dhdp()))
  281. bcmsdh_oob_intr_set(1);
  282. #endif /* (OOB_INTR_ONLY) */
  283. return 0;
  284. }
  285. static struct platform_driver wifi_platform_dev_driver = {
  286. .probe = wifi_plat_dev_drv_probe,
  287. .remove = wifi_plat_dev_drv_remove,
  288. .suspend = wifi_plat_dev_drv_suspend,
  289. .resume = wifi_plat_dev_drv_resume,
  290. .driver = {
  291. .name = WIFI_PLAT_NAME,
  292. }
  293. };
  294. static struct platform_driver wifi_platform_dev_driver_legacy = {
  295. .probe = wifi_plat_dev_drv_probe,
  296. .remove = wifi_plat_dev_drv_remove,
  297. .suspend = wifi_plat_dev_drv_suspend,
  298. .resume = wifi_plat_dev_drv_resume,
  299. .driver = {
  300. .name = WIFI_PLAT_NAME2,
  301. }
  302. };
  303. static int wifi_platdev_match(struct device *dev, void *data)
  304. {
  305. char *name = (char*)data;
  306. struct platform_device *pdev = to_platform_device(dev);
  307. if (strcmp(pdev->name, name) == 0) {
  308. DHD_ERROR(("found wifi platform device %s\n", name));
  309. return TRUE;
  310. }
  311. return FALSE;
  312. }
  313. static int wifi_ctrlfunc_register_drv(void)
  314. {
  315. int err = 0;
  316. struct device *dev1, *dev2;
  317. wifi_adapter_info_t *adapter;
  318. dev1 = bus_find_device(&platform_bus_type, NULL, WIFI_PLAT_NAME, wifi_platdev_match);
  319. dev2 = bus_find_device(&platform_bus_type, NULL, WIFI_PLAT_NAME2, wifi_platdev_match);
  320. if (!dts_enabled) {
  321. if (dev1 == NULL && dev2 == NULL) {
  322. DHD_ERROR(("no wifi platform data, skip\n"));
  323. return -ENXIO;
  324. }
  325. }
  326. /* multi-chip support not enabled, build one adapter information for
  327. * DHD (either SDIO, USB or PCIe)
  328. */
  329. adapter = kzalloc(sizeof(wifi_adapter_info_t), GFP_KERNEL);
  330. adapter->name = "DHD generic adapter";
  331. adapter->bus_type = -1;
  332. adapter->bus_num = -1;
  333. adapter->slot_num = -1;
  334. adapter->irq_num = -1;
  335. is_power_on = FALSE;
  336. wifi_plat_dev_probe_ret = 0;
  337. dhd_wifi_platdata = kzalloc(sizeof(bcmdhd_wifi_platdata_t), GFP_KERNEL);
  338. dhd_wifi_platdata->num_adapters = 1;
  339. dhd_wifi_platdata->adapters = adapter;
  340. if (dev1) {
  341. err = platform_driver_register(&wifi_platform_dev_driver);
  342. if (err) {
  343. DHD_ERROR(("%s: failed to register wifi ctrl func driver\n",
  344. __FUNCTION__));
  345. return err;
  346. }
  347. }
  348. if (dev2) {
  349. err = platform_driver_register(&wifi_platform_dev_driver_legacy);
  350. if (err) {
  351. DHD_ERROR(("%s: failed to register wifi ctrl func legacy driver\n",
  352. __FUNCTION__));
  353. return err;
  354. }
  355. }
  356. if (dts_enabled) {
  357. struct resource *resource;
  358. adapter->wifi_plat_data = (void *)&dhd_wlan_control;
  359. resource = &dhd_wlan_resources;
  360. adapter->irq_num = resource->start;
  361. adapter->intr_flags = resource->flags;
  362. wifi_plat_dev_probe_ret = dhd_wifi_platform_load();
  363. }
  364. /* return probe function's return value if registeration succeeded */
  365. return wifi_plat_dev_probe_ret;
  366. }
  367. void wifi_ctrlfunc_unregister_drv(void)
  368. {
  369. struct device *dev1, *dev2;
  370. dev1 = bus_find_device(&platform_bus_type, NULL, WIFI_PLAT_NAME, wifi_platdev_match);
  371. dev2 = bus_find_device(&platform_bus_type, NULL, WIFI_PLAT_NAME2, wifi_platdev_match);
  372. if (!dts_enabled)
  373. if (dev1 == NULL && dev2 == NULL)
  374. return;
  375. DHD_ERROR(("unregister wifi platform drivers\n"));
  376. if (dev1)
  377. platform_driver_unregister(&wifi_platform_dev_driver);
  378. if (dev2)
  379. platform_driver_unregister(&wifi_platform_dev_driver_legacy);
  380. if (dts_enabled) {
  381. wifi_adapter_info_t *adapter;
  382. adapter = &dhd_wifi_platdata->adapters[0];
  383. if (is_power_on) {
  384. wifi_platform_set_power(adapter, FALSE, WIFI_TURNOFF_DELAY);
  385. wifi_platform_bus_enumerate(adapter, FALSE);
  386. }
  387. }
  388. kfree(dhd_wifi_platdata->adapters);
  389. dhd_wifi_platdata->adapters = NULL;
  390. dhd_wifi_platdata->num_adapters = 0;
  391. kfree(dhd_wifi_platdata);
  392. dhd_wifi_platdata = NULL;
  393. }
  394. static int bcmdhd_wifi_plat_dev_drv_probe(struct platform_device *pdev)
  395. {
  396. dhd_wifi_platdata = (bcmdhd_wifi_platdata_t *)(pdev->dev.platform_data);
  397. return dhd_wifi_platform_load();
  398. }
  399. static int bcmdhd_wifi_plat_dev_drv_remove(struct platform_device *pdev)
  400. {
  401. int i;
  402. wifi_adapter_info_t *adapter;
  403. ASSERT(dhd_wifi_platdata != NULL);
  404. /* power down all adapters */
  405. for (i = 0; i < dhd_wifi_platdata->num_adapters; i++) {
  406. adapter = &dhd_wifi_platdata->adapters[i];
  407. wifi_platform_set_power(adapter, FALSE, WIFI_TURNOFF_DELAY);
  408. wifi_platform_bus_enumerate(adapter, FALSE);
  409. }
  410. return 0;
  411. }
  412. static struct platform_driver dhd_wifi_platform_dev_driver = {
  413. .probe = bcmdhd_wifi_plat_dev_drv_probe,
  414. .remove = bcmdhd_wifi_plat_dev_drv_remove,
  415. .driver = {
  416. .name = WIFI_PLAT_EXT,
  417. }
  418. };
  419. int dhd_wifi_platform_register_drv(void)
  420. {
  421. int err = 0;
  422. struct device *dev;
  423. /* register Broadcom wifi platform data driver if multi-chip is enabled,
  424. * otherwise use Android style wifi platform data (aka wifi control function)
  425. * if it exists
  426. *
  427. * to support multi-chip DHD, Broadcom wifi platform data device must
  428. * be added in kernel early boot (e.g. board config file).
  429. */
  430. if (cfg_multichip) {
  431. dev = bus_find_device(&platform_bus_type, NULL, WIFI_PLAT_EXT, wifi_platdev_match);
  432. if (dev == NULL) {
  433. DHD_ERROR(("bcmdhd wifi platform data device not found!!\n"));
  434. return -ENXIO;
  435. }
  436. err = platform_driver_register(&dhd_wifi_platform_dev_driver);
  437. } else {
  438. err = wifi_ctrlfunc_register_drv();
  439. /* no wifi ctrl func either, load bus directly and ignore this error */
  440. if (err) {
  441. if (err == -ENXIO) {
  442. /* wifi ctrl function does not exist */
  443. err = dhd_wifi_platform_load();
  444. } else {
  445. /* unregister driver due to initialization failure */
  446. wifi_ctrlfunc_unregister_drv();
  447. }
  448. }
  449. }
  450. return err;
  451. }
  452. #ifdef BCMPCIE
  453. static int dhd_wifi_platform_load_pcie(void)
  454. {
  455. int err = 0;
  456. err = dhd_bus_register();
  457. return err;
  458. }
  459. #else
  460. static int dhd_wifi_platform_load_pcie(void)
  461. {
  462. return 0;
  463. }
  464. #endif /* BCMPCIE */
  465. void dhd_wifi_platform_unregister_drv(void)
  466. {
  467. if (cfg_multichip)
  468. platform_driver_unregister(&dhd_wifi_platform_dev_driver);
  469. else
  470. wifi_ctrlfunc_unregister_drv();
  471. }
  472. extern int dhd_watchdog_prio;
  473. extern int dhd_dpc_prio;
  474. extern uint dhd_deferred_tx;
  475. #if defined(BCMLXSDMMC)
  476. extern struct semaphore dhd_registration_sem;
  477. #endif
  478. static int dhd_wifi_platform_load_sdio(void)
  479. {
  480. int i;
  481. int err = 0;
  482. wifi_adapter_info_t *adapter;
  483. BCM_REFERENCE(i);
  484. BCM_REFERENCE(adapter);
  485. /* Sanity check on the module parameters
  486. * - Both watchdog and DPC as tasklets are ok
  487. * - If both watchdog and DPC are threads, TX must be deferred
  488. */
  489. if (!(dhd_watchdog_prio < 0 && dhd_dpc_prio < 0) &&
  490. !(dhd_watchdog_prio >= 0 && dhd_dpc_prio >= 0 && dhd_deferred_tx))
  491. return -EINVAL;
  492. #if defined(BCMLXSDMMC)
  493. if (dhd_wifi_platdata == NULL) {
  494. DHD_ERROR(("DHD wifi platform data is required for Android build\n"));
  495. return -EINVAL;
  496. }
  497. sema_init(&dhd_registration_sem, 0);
  498. /* power up all adapters */
  499. for (i = 0; i < dhd_wifi_platdata->num_adapters; i++) {
  500. bool chip_up = FALSE;
  501. int retry = POWERUP_MAX_RETRY;
  502. struct semaphore dhd_chipup_sem;
  503. adapter = &dhd_wifi_platdata->adapters[i];
  504. DHD_ERROR(("Power-up adapter '%s'\n", adapter->name));
  505. DHD_INFO((" - irq %d [flags %d], firmware: %s, nvram: %s\n",
  506. adapter->irq_num, adapter->intr_flags, adapter->fw_path, adapter->nv_path));
  507. DHD_INFO((" - bus type %d, bus num %d, slot num %d\n\n",
  508. adapter->bus_type, adapter->bus_num, adapter->slot_num));
  509. do {
  510. sema_init(&dhd_chipup_sem, 0);
  511. err = dhd_bus_reg_sdio_notify(&dhd_chipup_sem);
  512. if (err) {
  513. DHD_ERROR(("%s dhd_bus_reg_sdio_notify fail(%d)\n\n",
  514. __FUNCTION__, err));
  515. return err;
  516. }
  517. err = wifi_platform_set_power(adapter, TRUE, WIFI_TURNON_DELAY);
  518. if (err) {
  519. DHD_ERROR(("failed to set WIFI_REG_ON\n"));
  520. } else {
  521. wifi_platform_bus_enumerate(adapter, TRUE);
  522. err = 0;
  523. }
  524. if (down_timeout(&dhd_chipup_sem, msecs_to_jiffies(POWERUP_WAIT_MS)) == 0) {
  525. dhd_bus_unreg_sdio_notify();
  526. chip_up = TRUE;
  527. break;
  528. }
  529. DHD_ERROR(("failed to power up %s, %d retry left\n", adapter->name, retry));
  530. dhd_bus_unreg_sdio_notify();
  531. wifi_platform_set_power(adapter, FALSE, WIFI_TURNOFF_DELAY);
  532. wifi_platform_bus_enumerate(adapter, FALSE);
  533. } while (retry--);
  534. if (!chip_up) {
  535. DHD_ERROR(("failed to power up %s, max retry reached**\n", adapter->name));
  536. return -ENODEV;
  537. }
  538. }
  539. err = dhd_bus_register();
  540. if (err) {
  541. DHD_ERROR(("%s: sdio_register_driver failed\n", __FUNCTION__));
  542. goto fail;
  543. }
  544. /*
  545. * Wait till MMC sdio_register_driver callback called and made driver attach.
  546. * It's needed to make sync up exit from dhd insmod and
  547. * Kernel MMC sdio device callback registration
  548. */
  549. err = down_timeout(&dhd_registration_sem, msecs_to_jiffies(DHD_REGISTRATION_TIMEOUT));
  550. if (err) {
  551. DHD_ERROR(("%s: sdio_register_driver timeout or error \n", __FUNCTION__));
  552. dhd_bus_unregister();
  553. goto fail;
  554. }
  555. return err;
  556. fail:
  557. /* power down all adapters */
  558. for (i = 0; i < dhd_wifi_platdata->num_adapters; i++) {
  559. adapter = &dhd_wifi_platdata->adapters[i];
  560. wifi_platform_set_power(adapter, FALSE, WIFI_TURNOFF_DELAY);
  561. wifi_platform_bus_enumerate(adapter, FALSE);
  562. }
  563. #else
  564. /* x86 bring-up PC needs no power-up operations */
  565. err = dhd_bus_register();
  566. #endif
  567. return err;
  568. }
  569. static int dhd_wifi_platform_load_usb(void)
  570. {
  571. return 0;
  572. }
  573. static int dhd_wifi_platform_load()
  574. {
  575. int err = 0;
  576. wl_android_init();
  577. if ((err = dhd_wifi_platform_load_usb()))
  578. goto end;
  579. else if ((err = dhd_wifi_platform_load_sdio()))
  580. goto end;
  581. else
  582. err = dhd_wifi_platform_load_pcie();
  583. end:
  584. if (err)
  585. wl_android_exit();
  586. else
  587. wl_android_post_init();
  588. return err;
  589. }