bcmsdh.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866
  1. /*
  2. * BCMSDH interface glue
  3. * implement bcmsdh API for SDIOH driver
  4. *
  5. * Portions of this code are copyright (c) 2020 Cypress Semiconductor Corporation
  6. *
  7. * Copyright (C) 1999-2020, Broadcom Corporation
  8. *
  9. * Unless you and Broadcom execute a separate written software license
  10. * agreement governing use of this software, this software is licensed to you
  11. * under the terms of the GNU General Public License version 2 (the "GPL"),
  12. * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  13. * following added to such license:
  14. *
  15. * As a special exception, the copyright holders of this software give you
  16. * permission to link this software with independent modules, and to copy and
  17. * distribute the resulting executable under terms of your choice, provided that
  18. * you also meet, for each linked independent module, the terms and conditions of
  19. * the license of that module. An independent module is a module which is not
  20. * derived from this software. The special exception does not apply to any
  21. * modifications of the software.
  22. *
  23. * Notwithstanding the above, under no circumstances may you combine this
  24. * software in any way with any other Broadcom software provided under a license
  25. * other than the GPL, without Broadcom's express prior written consent.
  26. *
  27. *
  28. * <<Broadcom-WL-IPTag/Open:>>
  29. *
  30. * $Id: bcmsdh.c 700323 2017-05-18 16:12:11Z $
  31. */
  32. /**
  33. * @file bcmsdh.c
  34. */
  35. /* ****************** BCMSDH Interface Functions *************************** */
  36. #include <typedefs.h>
  37. #include <bcmdevs.h>
  38. #include <bcmendian.h>
  39. #include <bcmutils.h>
  40. #include <hndsoc.h>
  41. #include <siutils.h>
  42. #include <osl.h>
  43. #include <bcmsdh.h> /* BRCM API for SDIO clients (such as wl, dhd) */
  44. #include <bcmsdbus.h> /* common SDIO/controller interface */
  45. #include <sbsdio.h> /* SDIO device core hardware definitions. */
  46. #include <sdio.h> /* SDIO Device and Protocol Specs */
  47. #if defined(BT_OVER_SDIO)
  48. #include <dhd_bt_interface.h>
  49. #endif /* defined (BT_OVER_SDIO) */
  50. #define SDIOH_API_ACCESS_RETRY_LIMIT 2
  51. const uint bcmsdh_msglevel = BCMSDH_ERROR_VAL;
  52. /* local copy of bcm sd handler */
  53. bcmsdh_info_t * l_bcmsdh = NULL;
  54. #if defined(BT_OVER_SDIO)
  55. struct sdio_func *func_f3 = NULL;
  56. static f3intr_handler processf3intr = NULL;
  57. static dhd_hang_notification process_dhd_hang_notification = NULL;
  58. static dhd_hang_state_t g_dhd_hang_state = NO_HANG_STATE;
  59. #endif /* defined (BT_OVER_SDIO) */
  60. #if defined(OOB_INTR_ONLY) && defined(HW_OOB)
  61. extern int
  62. sdioh_enable_hw_oob_intr(void *sdioh, bool enable);
  63. void
  64. bcmsdh_enable_hw_oob_intr(bcmsdh_info_t *sdh, bool enable)
  65. {
  66. sdioh_enable_hw_oob_intr(sdh->sdioh, enable);
  67. }
  68. #endif // endif
  69. #if defined(BT_OVER_SDIO)
  70. void bcmsdh_btsdio_process_hang_state(dhd_hang_state_t new_state)
  71. {
  72. bool state_change = false;
  73. BCMSDH_ERROR(("%s: DHD hang state changed - [%d] -> [%d]\n",
  74. __FUNCTION__, g_dhd_hang_state, new_state));
  75. if (g_dhd_hang_state == new_state)
  76. return;
  77. switch (g_dhd_hang_state) {
  78. case NO_HANG_STATE:
  79. if (HANG_START_STATE == new_state)
  80. state_change = true;
  81. break;
  82. case HANG_START_STATE:
  83. if (HANG_RECOVERY_STATE == new_state ||
  84. NO_HANG_STATE == new_state)
  85. state_change = true;
  86. break;
  87. case HANG_RECOVERY_STATE:
  88. if (NO_HANG_STATE == new_state)
  89. state_change = true;
  90. break;
  91. default:
  92. BCMSDH_ERROR(("%s: Unhandled Hang state\n", __FUNCTION__));
  93. break;
  94. }
  95. if (!state_change) {
  96. BCMSDH_ERROR(("%s: Hang state cannot be changed\n", __FUNCTION__));
  97. return;
  98. }
  99. g_dhd_hang_state = new_state;
  100. }
  101. void bcmsdh_btsdio_process_f3_intr(void)
  102. {
  103. if (processf3intr && (g_dhd_hang_state == NO_HANG_STATE))
  104. processf3intr(func_f3);
  105. }
  106. void bcmsdh_btsdio_process_dhd_hang_notification(bool wifi_recovery_completed)
  107. {
  108. bcmsdh_btsdio_process_hang_state(HANG_START_STATE);
  109. if (process_dhd_hang_notification)
  110. process_dhd_hang_notification(func_f3, wifi_recovery_completed);
  111. /* WiFi was off, so HANG_RECOVERY_STATE is not needed */
  112. if (wifi_recovery_completed)
  113. bcmsdh_btsdio_process_hang_state(NO_HANG_STATE);
  114. else {
  115. bcmsdh_btsdio_process_hang_state(HANG_RECOVERY_STATE);
  116. }
  117. }
  118. void bcmsdh_btsdio_interface_init(struct sdio_func *func,
  119. f3intr_handler f3intr_fun, dhd_hang_notification hang_notification)
  120. {
  121. bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)l_bcmsdh;
  122. BCMSDH_INFO(("%s: func %p \n", __FUNCTION__, func));
  123. func_f3 = func;
  124. processf3intr = f3intr_fun;
  125. sdioh_sdmmc_card_enable_func_f3(bcmsdh->sdioh, func);
  126. process_dhd_hang_notification = hang_notification;
  127. } EXPORT_SYMBOL(bcmsdh_btsdio_interface_init);
  128. #endif /* defined (BT_OVER_SDIO) */
  129. /* Attach BCMSDH layer to SDIO Host Controller Driver
  130. *
  131. * @param osh OSL Handle.
  132. * @param cfghdl Configuration Handle.
  133. * @param regsva Virtual address of controller registers.
  134. * @param irq Interrupt number of SDIO controller.
  135. *
  136. * @return bcmsdh_info_t Handle to BCMSDH context.
  137. */
  138. bcmsdh_info_t *
  139. bcmsdh_attach(osl_t *osh, void *sdioh, ulong *regsva)
  140. {
  141. bcmsdh_info_t *bcmsdh;
  142. if ((bcmsdh = (bcmsdh_info_t *)MALLOC(osh, sizeof(bcmsdh_info_t))) == NULL) {
  143. BCMSDH_ERROR(("bcmsdh_attach: out of memory, malloced %d bytes\n", MALLOCED(osh)));
  144. return NULL;
  145. }
  146. bzero((char *)bcmsdh, sizeof(bcmsdh_info_t));
  147. bcmsdh->sdioh = sdioh;
  148. bcmsdh->osh = osh;
  149. bcmsdh->init_success = TRUE;
  150. *regsva = si_enum_base(0);
  151. bcmsdh_force_sbwad_calc(bcmsdh, FALSE);
  152. /* Report the BAR, to fix if needed */
  153. bcmsdh->sbwad = si_enum_base(0);
  154. /* save the handler locally */
  155. l_bcmsdh = bcmsdh;
  156. return bcmsdh;
  157. }
  158. int
  159. bcmsdh_detach(osl_t *osh, void *sdh)
  160. {
  161. bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
  162. if (bcmsdh != NULL) {
  163. MFREE(osh, bcmsdh, sizeof(bcmsdh_info_t));
  164. }
  165. l_bcmsdh = NULL;
  166. return 0;
  167. }
  168. int
  169. bcmsdh_iovar_op(void *sdh, const char *name,
  170. void *params, uint plen, void *arg, uint len, bool set)
  171. {
  172. bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
  173. // return sdioh_iovar_op(bcmsdh->sdioh, name, params, plen, arg, len, set);//add 20210511
  174. }
  175. bool
  176. bcmsdh_intr_query(void *sdh)
  177. {
  178. bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
  179. SDIOH_API_RC status;
  180. bool on;
  181. ASSERT(bcmsdh);
  182. // status = sdioh_interrupt_query(bcmsdh->sdioh, &on);//add 20210511
  183. if (SDIOH_API_SUCCESS(status))
  184. return FALSE;
  185. else
  186. return on;
  187. }
  188. int
  189. bcmsdh_intr_enable(void *sdh)
  190. {
  191. bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
  192. SDIOH_API_RC status;
  193. #ifdef BCMSPI_ANDROID
  194. uint32 data;
  195. #endif /* BCMSPI_ANDROID */
  196. ASSERT(bcmsdh);
  197. // status = sdioh_interrupt_set(bcmsdh->sdioh, TRUE);//add 20210511
  198. #ifdef BCMSPI_ANDROID
  199. data = bcmsdh_cfg_read_word(sdh, 0, 4, NULL);
  200. data |= 0xE0E70000;
  201. bcmsdh_cfg_write_word(sdh, 0, 4, data, NULL);
  202. #endif /* BCMSPI_ANDROID */
  203. return (SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR);
  204. }
  205. int
  206. bcmsdh_intr_disable(void *sdh)
  207. {
  208. bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
  209. SDIOH_API_RC status;
  210. #ifdef BCMSPI_ANDROID
  211. uint32 data;
  212. #endif /* BCMSPI_ANDROID */
  213. ASSERT(bcmsdh);
  214. // status = sdioh_interrupt_set(bcmsdh->sdioh, FALSE);//add 20210511
  215. #ifdef BCMSPI_ANDROID
  216. data = bcmsdh_cfg_read_word(sdh, 0, 4, NULL);
  217. data &= ~0xE0E70000;
  218. bcmsdh_cfg_write_word(sdh, 0, 4, data, NULL);
  219. #endif /* BCMSPI_ANDROID */
  220. return (SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR);
  221. }
  222. int
  223. bcmsdh_intr_reg(void *sdh, bcmsdh_cb_fn_t fn, void *argh)
  224. {
  225. bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
  226. SDIOH_API_RC status;
  227. if (!bcmsdh)
  228. bcmsdh = l_bcmsdh;
  229. ASSERT(bcmsdh);
  230. // status = sdioh_interrupt_register(bcmsdh->sdioh, fn, argh);//add 20210511
  231. return (SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR);
  232. }
  233. int
  234. bcmsdh_intr_dereg(void *sdh)
  235. {
  236. bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
  237. SDIOH_API_RC status;
  238. if (!bcmsdh)
  239. bcmsdh = l_bcmsdh;
  240. ASSERT(bcmsdh);
  241. // status = sdioh_interrupt_deregister(bcmsdh->sdioh);//add 20210511
  242. return (SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR);
  243. }
  244. #if defined(DHD_DEBUG)
  245. bool
  246. bcmsdh_intr_pending(void *sdh)
  247. {
  248. bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
  249. ASSERT(sdh);
  250. //return sdioh_interrupt_pending(bcmsdh->sdioh);
  251. return 0;//add 20210511
  252. }
  253. #endif // endif
  254. int
  255. bcmsdh_devremove_reg(void *sdh, bcmsdh_cb_fn_t fn, void *argh)
  256. {
  257. ASSERT(sdh);
  258. /* don't support yet */
  259. return BCME_UNSUPPORTED;
  260. }
  261. /**
  262. * Read from SDIO Configuration Space
  263. * @param sdh SDIO Host context.
  264. * @param func_num Function number to read from.
  265. * @param addr Address to read from.
  266. * @param err Error return.
  267. * @return value read from SDIO configuration space.
  268. */
  269. uint8
  270. bcmsdh_cfg_read(void *sdh, uint fnc_num, uint32 addr, int *err)
  271. {
  272. bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
  273. SDIOH_API_RC status;
  274. #ifdef SDIOH_API_ACCESS_RETRY_LIMIT
  275. int32 retry = 0;
  276. #endif // endif
  277. uint8 data = 0;
  278. if (!bcmsdh)
  279. bcmsdh = l_bcmsdh;
  280. ASSERT(bcmsdh->init_success);
  281. #ifdef SDIOH_API_ACCESS_RETRY_LIMIT
  282. do {
  283. if (retry) /* wait for 1 ms till bus get settled down */
  284. OSL_DELAY(1000);
  285. #endif // endif
  286. // status = sdioh_cfg_read(bcmsdh->sdioh, fnc_num, addr, (uint8 *)&data);//add 20210511
  287. #ifdef SDIOH_API_ACCESS_RETRY_LIMIT
  288. } while (!SDIOH_API_SUCCESS(status) && (retry++ < SDIOH_API_ACCESS_RETRY_LIMIT));
  289. #endif // endif
  290. if (err)
  291. *err = (SDIOH_API_SUCCESS(status) ? 0 : BCME_SDIO_ERROR);
  292. BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, uint8data = 0x%x\n", __FUNCTION__,
  293. fnc_num, addr, data));
  294. return data;
  295. } EXPORT_SYMBOL(bcmsdh_cfg_read);
  296. void
  297. bcmsdh_cfg_write(void *sdh, uint fnc_num, uint32 addr, uint8 data, int *err)
  298. {
  299. bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
  300. SDIOH_API_RC status;
  301. #ifdef SDIOH_API_ACCESS_RETRY_LIMIT
  302. int32 retry = 0;
  303. #endif // endif
  304. if (!bcmsdh)
  305. bcmsdh = l_bcmsdh;
  306. ASSERT(bcmsdh->init_success);
  307. #ifdef SDIOH_API_ACCESS_RETRY_LIMIT
  308. do {
  309. if (retry) /* wait for 1 ms till bus get settled down */
  310. OSL_DELAY(1000);
  311. #endif // endif
  312. // status = sdioh_cfg_write(bcmsdh->sdioh, fnc_num, addr, (uint8 *)&data);//add 20210511
  313. #ifdef SDIOH_API_ACCESS_RETRY_LIMIT
  314. } while (!SDIOH_API_SUCCESS(status) && (retry++ < SDIOH_API_ACCESS_RETRY_LIMIT));
  315. #endif // endif
  316. if (err)
  317. *err = SDIOH_API_SUCCESS(status) ? 0 : BCME_SDIO_ERROR;
  318. BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, uint8data = 0x%x\n", __FUNCTION__,
  319. fnc_num, addr, data));
  320. } EXPORT_SYMBOL(bcmsdh_cfg_write);
  321. uint32
  322. bcmsdh_cfg_read_word(void *sdh, uint fnc_num, uint32 addr, int *err)
  323. {
  324. bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
  325. SDIOH_API_RC status;
  326. uint32 data = 0;
  327. if (!bcmsdh)
  328. bcmsdh = l_bcmsdh;
  329. ASSERT(bcmsdh->init_success);
  330. // status = sdioh_request_word(bcmsdh->sdioh, SDIOH_CMD_TYPE_NORMAL, SDIOH_READ, fnc_num,
  331. // addr, &data, 4);//add 20210511
  332. if (err)
  333. *err = (SDIOH_API_SUCCESS(status) ? 0 : BCME_SDIO_ERROR);
  334. BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, uint32data = 0x%x\n", __FUNCTION__,
  335. fnc_num, addr, data));
  336. return data;
  337. }
  338. void
  339. bcmsdh_cfg_write_word(void *sdh, uint fnc_num, uint32 addr, uint32 data, int *err)
  340. {
  341. bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
  342. SDIOH_API_RC status;
  343. if (!bcmsdh)
  344. bcmsdh = l_bcmsdh;
  345. ASSERT(bcmsdh->init_success);
  346. // status = sdioh_request_word(bcmsdh->sdioh, SDIOH_CMD_TYPE_NORMAL, SDIOH_WRITE, fnc_num,
  347. // addr, &data, 4);//add 20210511
  348. if (err)
  349. *err = (SDIOH_API_SUCCESS(status) ? 0 : BCME_SDIO_ERROR);
  350. BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, uint32data = 0x%x\n", __FUNCTION__, fnc_num,
  351. addr, data));
  352. }
  353. int
  354. bcmsdh_cis_read(void *sdh, uint func, uint8 *cis, uint length)
  355. {
  356. bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
  357. SDIOH_API_RC status;
  358. uint8 *tmp_buf, *tmp_ptr;
  359. uint8 *ptr;
  360. bool ascii = func & ~0xf;
  361. func &= 0x7;
  362. if (!bcmsdh)
  363. bcmsdh = l_bcmsdh;
  364. ASSERT(bcmsdh->init_success);
  365. ASSERT(cis);
  366. ASSERT(length <= SBSDIO_CIS_SIZE_LIMIT);
  367. // status = sdioh_cis_read(bcmsdh->sdioh, func, cis, length);//add 20210511
  368. if (ascii) {
  369. /* Move binary bits to tmp and format them into the provided buffer. */
  370. if ((tmp_buf = (uint8 *)MALLOC(bcmsdh->osh, length)) == NULL) {
  371. BCMSDH_ERROR(("%s: out of memory\n", __FUNCTION__));
  372. return BCME_NOMEM;
  373. }
  374. bcopy(cis, tmp_buf, length);
  375. for (tmp_ptr = tmp_buf, ptr = cis; ptr < (cis + length - 4); tmp_ptr++) {
  376. ptr += snprintf((char*)ptr, (cis + length - ptr - 4),
  377. "%.2x ", *tmp_ptr & 0xff);
  378. if ((((tmp_ptr - tmp_buf) + 1) & 0xf) == 0)
  379. ptr += snprintf((char *)ptr, (cis + length - ptr -4), "\n");
  380. }
  381. MFREE(bcmsdh->osh, tmp_buf, length);
  382. }
  383. return (SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR);
  384. }
  385. int
  386. bcmsdhsdio_set_sbaddr_window(void *sdh, uint32 address, bool force_set)
  387. {
  388. int err = 0;
  389. uint bar0 = address & ~SBSDIO_SB_OFT_ADDR_MASK;
  390. bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
  391. if (bar0 != bcmsdh->sbwad || force_set) {
  392. bcmsdh_cfg_write(bcmsdh, SDIO_FUNC_1, SBSDIO_FUNC1_SBADDRLOW,
  393. (address >> 8) & SBSDIO_SBADDRLOW_MASK, &err);
  394. if (!err)
  395. bcmsdh_cfg_write(bcmsdh, SDIO_FUNC_1, SBSDIO_FUNC1_SBADDRMID,
  396. (address >> 16) & SBSDIO_SBADDRMID_MASK, &err);
  397. if (!err)
  398. bcmsdh_cfg_write(bcmsdh, SDIO_FUNC_1, SBSDIO_FUNC1_SBADDRHIGH,
  399. (address >> 24) & SBSDIO_SBADDRHIGH_MASK, &err);
  400. if (!err)
  401. bcmsdh->sbwad = bar0;
  402. else
  403. /* invalidate cached window var */
  404. bcmsdh->sbwad = 0;
  405. }
  406. return err;
  407. }
  408. uint32
  409. bcmsdh_reg_read(void *sdh, uintptr addr, uint size)
  410. {
  411. bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
  412. SDIOH_API_RC status;
  413. uint32 word = 0;
  414. BCMSDH_INFO(("%s:fun = 1, addr = 0x%x, ",
  415. __FUNCTION__, (unsigned int)addr));
  416. if (!bcmsdh)
  417. bcmsdh = l_bcmsdh;
  418. ASSERT(bcmsdh->init_success);
  419. if (bcmsdhsdio_set_sbaddr_window(bcmsdh, addr, bcmsdh->force_sbwad_calc))
  420. return 0xFFFFFFFF;
  421. addr &= SBSDIO_SB_OFT_ADDR_MASK;
  422. if (size == 4)
  423. addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
  424. // status = sdioh_request_word(bcmsdh->sdioh, SDIOH_CMD_TYPE_NORMAL,
  425. // SDIOH_READ, SDIO_FUNC_1, addr, &word, size);//add 20210511
  426. bcmsdh->regfail = !(SDIOH_API_SUCCESS(status));
  427. BCMSDH_INFO(("uint32data = 0x%x\n", word));
  428. /* if ok, return appropriately masked word */
  429. if (SDIOH_API_SUCCESS(status)) {
  430. switch (size) {
  431. case sizeof(uint8):
  432. return (word & 0xff);
  433. case sizeof(uint16):
  434. return (word & 0xffff);
  435. case sizeof(uint32):
  436. return word;
  437. default:
  438. bcmsdh->regfail = TRUE;
  439. }
  440. }
  441. /* otherwise, bad sdio access or invalid size */
  442. BCMSDH_ERROR(("%s: error reading addr 0x%x size %d\n",
  443. __FUNCTION__, (unsigned int)addr, size));
  444. return 0xFFFFFFFF;
  445. }
  446. uint32
  447. bcmsdh_reg_write(void *sdh, uintptr addr, uint size, uint32 data)
  448. {
  449. bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
  450. SDIOH_API_RC status;
  451. int err = 0;
  452. BCMSDH_INFO(("%s:fun = 1, addr = 0x%x, uint%ddata = 0x%x\n",
  453. __FUNCTION__, (unsigned int)addr, size*8, data));
  454. if (!bcmsdh)
  455. bcmsdh = l_bcmsdh;
  456. ASSERT(bcmsdh->init_success);
  457. if ((err = bcmsdhsdio_set_sbaddr_window(bcmsdh, addr, bcmsdh->force_sbwad_calc)))
  458. return err;
  459. addr &= SBSDIO_SB_OFT_ADDR_MASK;
  460. if (size == 4)
  461. addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
  462. // status = sdioh_request_word(bcmsdh->sdioh, SDIOH_CMD_TYPE_NORMAL, SDIOH_WRITE, SDIO_FUNC_1,
  463. // addr, &data, size);//add 20210511
  464. bcmsdh->regfail = !(SDIOH_API_SUCCESS(status));
  465. if (SDIOH_API_SUCCESS(status))
  466. return 0;
  467. BCMSDH_ERROR(("%s: error writing 0x%08x to addr 0x%04x size %d\n",
  468. __FUNCTION__, data, (unsigned int)addr, size));
  469. return 0xFFFFFFFF;
  470. }
  471. bool
  472. bcmsdh_regfail(void *sdh)
  473. {
  474. return ((bcmsdh_info_t *)sdh)->regfail;
  475. }
  476. int
  477. bcmsdh_recv_buf(void *sdh, uint32 addr, uint fn, uint flags,
  478. uint8 *buf, uint nbytes, void *pkt,
  479. bcmsdh_cmplt_fn_t complete_fn, void *handle)
  480. {
  481. bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
  482. SDIOH_API_RC status;
  483. uint incr_fix;
  484. uint width;
  485. int err = 0;
  486. ASSERT(bcmsdh);
  487. ASSERT(bcmsdh->init_success);
  488. BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, size = %d\n",
  489. __FUNCTION__, fn, addr, nbytes));
  490. /* Async not implemented yet */
  491. ASSERT(!(flags & SDIO_REQ_ASYNC));
  492. if (flags & SDIO_REQ_ASYNC)
  493. return BCME_UNSUPPORTED;
  494. if ((err = bcmsdhsdio_set_sbaddr_window(bcmsdh, addr, FALSE)))
  495. return err;
  496. addr &= SBSDIO_SB_OFT_ADDR_MASK;
  497. incr_fix = (flags & SDIO_REQ_FIXED) ? SDIOH_DATA_FIX : SDIOH_DATA_INC;
  498. width = (flags & SDIO_REQ_4BYTE) ? 4 : 2;
  499. if (width == 4)
  500. addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
  501. // status = sdioh_request_buffer(bcmsdh->sdioh, SDIOH_DATA_PIO, incr_fix,
  502. // SDIOH_READ, fn, addr, width, nbytes, buf, pkt);//add 20210511
  503. return (SDIOH_API_SUCCESS(status) ? 0 : BCME_SDIO_ERROR);
  504. }
  505. int
  506. bcmsdh_send_buf(void *sdh, uint32 addr, uint fn, uint flags,
  507. uint8 *buf, uint nbytes, void *pkt,
  508. bcmsdh_cmplt_fn_t complete_fn, void *handle)
  509. {
  510. bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
  511. SDIOH_API_RC status;
  512. uint incr_fix;
  513. uint width;
  514. int err = 0;
  515. ASSERT(bcmsdh);
  516. ASSERT(bcmsdh->init_success);
  517. BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, size = %d\n",
  518. __FUNCTION__, fn, addr, nbytes));
  519. /* Async not implemented yet */
  520. ASSERT(!(flags & SDIO_REQ_ASYNC));
  521. if (flags & SDIO_REQ_ASYNC)
  522. return BCME_UNSUPPORTED;
  523. if ((err = bcmsdhsdio_set_sbaddr_window(bcmsdh, addr, FALSE)))
  524. return err;
  525. addr &= SBSDIO_SB_OFT_ADDR_MASK;
  526. incr_fix = (flags & SDIO_REQ_FIXED) ? SDIOH_DATA_FIX : SDIOH_DATA_INC;
  527. width = (flags & SDIO_REQ_4BYTE) ? 4 : 2;
  528. if (width == 4)
  529. addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
  530. // status = sdioh_request_buffer(bcmsdh->sdioh, SDIOH_DATA_PIO, incr_fix,
  531. // SDIOH_WRITE, fn, addr, width, nbytes, buf, pkt);//add 20210511
  532. return (SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR);
  533. }
  534. int
  535. bcmsdh_rwdata(void *sdh, uint rw, uint32 addr, uint8 *buf, uint nbytes)
  536. {
  537. bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
  538. SDIOH_API_RC status;
  539. ASSERT(bcmsdh);
  540. ASSERT(bcmsdh->init_success);
  541. ASSERT((addr & SBSDIO_SBWINDOW_MASK) == 0);
  542. addr &= SBSDIO_SB_OFT_ADDR_MASK;
  543. addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
  544. // status = sdioh_request_buffer(bcmsdh->sdioh, SDIOH_DATA_PIO, SDIOH_DATA_INC,
  545. // (rw ? SDIOH_WRITE : SDIOH_READ), SDIO_FUNC_1,
  546. // addr, 4, nbytes, buf, NULL);//add 20210511
  547. return (SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR);
  548. }
  549. int
  550. bcmsdh_abort(void *sdh, uint fn)
  551. {
  552. bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
  553. //return sdioh_abort(bcmsdh->sdioh, fn);
  554. return 0;//add 20210511
  555. }
  556. int
  557. bcmsdh_start(void *sdh, int stage)
  558. {
  559. bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
  560. //return sdioh_start(bcmsdh->sdioh, stage);
  561. return 0;//add 20210511
  562. }
  563. int
  564. bcmsdh_stop(void *sdh)
  565. {
  566. bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
  567. //return sdioh_stop(bcmsdh->sdioh);
  568. return 0;//add 20210511
  569. }
  570. int
  571. bcmsdh_waitlockfree(void *sdh)
  572. {
  573. bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
  574. //return sdioh_waitlockfree(bcmsdh->sdioh);
  575. return 0;//add 20210511
  576. }
  577. int
  578. bcmsdh_query_device(void *sdh)
  579. {
  580. bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
  581. bcmsdh->vendevid = (VENDOR_BROADCOM << 16) | 0;
  582. return (bcmsdh->vendevid);
  583. }
  584. uint
  585. bcmsdh_query_iofnum(void *sdh)
  586. {
  587. bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
  588. if (!bcmsdh)
  589. bcmsdh = l_bcmsdh;
  590. //return (sdioh_query_iofnum(bcmsdh->sdioh));
  591. return 0;//add 20210511
  592. }
  593. int
  594. bcmsdh_reset(bcmsdh_info_t *sdh)
  595. {
  596. bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
  597. //return sdioh_sdio_reset(bcmsdh->sdioh);
  598. return 0;//add 20210511
  599. }
  600. void *bcmsdh_get_sdioh(bcmsdh_info_t *sdh)
  601. {
  602. ASSERT(sdh);
  603. return sdh->sdioh;
  604. }
  605. /* Function to pass device-status bits to DHD. */
  606. uint32
  607. bcmsdh_get_dstatus(void *sdh)
  608. {
  609. #ifdef BCMSPI
  610. bcmsdh_info_t *p = (bcmsdh_info_t *)sdh;
  611. sdioh_info_t *sd = (sdioh_info_t *)(p->sdioh);
  612. return sdioh_get_dstatus(sd);
  613. #else
  614. return 0;
  615. #endif /* BCMSPI */
  616. }
  617. uint32
  618. bcmsdh_cur_sbwad(void *sdh)
  619. {
  620. bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
  621. if (!bcmsdh)
  622. bcmsdh = l_bcmsdh;
  623. return (bcmsdh->sbwad);
  624. }
  625. /* example usage: if force is TRUE, forces the bcmsdhsdio_set_sbaddr_window to
  626. * calculate sbwad always instead of caching.
  627. */
  628. void
  629. bcmsdh_force_sbwad_calc(void *sdh, bool force)
  630. {
  631. bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
  632. if (!bcmsdh)
  633. bcmsdh = l_bcmsdh;
  634. bcmsdh->force_sbwad_calc = force;
  635. }
  636. void
  637. bcmsdh_chipinfo(void *sdh, uint32 chip, uint32 chiprev)
  638. {
  639. #ifdef BCMSPI
  640. bcmsdh_info_t *p = (bcmsdh_info_t *)sdh;
  641. sdioh_info_t *sd = (sdioh_info_t *)(p->sdioh);
  642. sdioh_chipinfo(sd, chip, chiprev);
  643. #else
  644. return;
  645. #endif /* BCMSPI */
  646. }
  647. #ifdef BCMSPI
  648. void
  649. bcmsdh_dwordmode(void *sdh, bool set)
  650. {
  651. bcmsdh_info_t *p = (bcmsdh_info_t *)sdh;
  652. sdioh_info_t *sd = (sdioh_info_t *)(p->sdioh);
  653. sdioh_dwordmode(sd, set);
  654. return;
  655. }
  656. #endif /* BCMSPI */
  657. int
  658. bcmsdh_sleep(void *sdh, bool enab)
  659. {
  660. #ifdef SDIOH_SLEEP_ENABLED
  661. bcmsdh_info_t *p = (bcmsdh_info_t *)sdh;
  662. sdioh_info_t *sd = (sdioh_info_t *)(p->sdioh);
  663. return sdioh_sleep(sd, enab);
  664. #else
  665. return BCME_UNSUPPORTED;
  666. #endif // endif
  667. }
  668. int
  669. bcmsdh_gpio_init(void *sdh)
  670. {
  671. bcmsdh_info_t *p = (bcmsdh_info_t *)sdh;
  672. sdioh_info_t *sd = (sdioh_info_t *)(p->sdioh);
  673. //return sdioh_gpio_init(sd);
  674. return 0;//add 20210511
  675. }
  676. bool
  677. bcmsdh_gpioin(void *sdh, uint32 gpio)
  678. {
  679. bcmsdh_info_t *p = (bcmsdh_info_t *)sdh;
  680. sdioh_info_t *sd = (sdioh_info_t *)(p->sdioh);
  681. //return sdioh_gpioin(sd, gpio);
  682. return TRUE;//add 20210511
  683. }
  684. int
  685. bcmsdh_gpioouten(void *sdh, uint32 gpio)
  686. {
  687. bcmsdh_info_t *p = (bcmsdh_info_t *)sdh;
  688. sdioh_info_t *sd = (sdioh_info_t *)(p->sdioh);
  689. //return sdioh_gpioouten(sd, gpio);
  690. return 0;//add 20210511
  691. }
  692. int
  693. bcmsdh_gpioout(void *sdh, uint32 gpio, bool enab)
  694. {
  695. bcmsdh_info_t *p = (bcmsdh_info_t *)sdh;
  696. sdioh_info_t *sd = (sdioh_info_t *)(p->sdioh);
  697. //return sdioh_gpioout(sd, gpio, enab);
  698. return 0;//add 20210511
  699. }