dhd_linux_platdev.c 18 KB

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