halmac_api.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2016 - 2018 Realtek Corporation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. ******************************************************************************/
  15. #include "halmac_type.h"
  16. #include "halmac_api.h"
  17. #if (HALMAC_PLATFORM_WINDOWS)
  18. #if HALMAC_8822B_SUPPORT
  19. #include "halmac_88xx/halmac_init_win8822b.h"
  20. #endif
  21. #if HALMAC_8821C_SUPPORT
  22. #include "halmac_88xx/halmac_init_win8821c.h"
  23. #endif
  24. #if HALMAC_8814B_SUPPORT
  25. #include "halmac_88xx_v1/halmac_init_win8814b_v1.h"
  26. #endif
  27. #if HALMAC_8822C_SUPPORT
  28. #include "halmac_88xx/halmac_init_win8822c.h"
  29. #endif
  30. #else
  31. #if HALMAC_88XX_SUPPORT
  32. #include "halmac_88xx/halmac_init_88xx.h"
  33. #endif
  34. #if HALMAC_88XX_V1_SUPPORT
  35. #include "halmac_88xx_v1/halmac_init_88xx_v1.h"
  36. #if defined(HALMAC_DATA_CPU_EN)
  37. #include "halmac_88xxd_v1/halmac_init_88xxd_v1.h"
  38. #endif
  39. #endif
  40. #endif
  41. enum chip_id_hw_def {
  42. CHIP_ID_HW_DEF_8723A = 0x01,
  43. CHIP_ID_HW_DEF_8188E = 0x02,
  44. CHIP_ID_HW_DEF_8881A = 0x03,
  45. CHIP_ID_HW_DEF_8812A = 0x04,
  46. CHIP_ID_HW_DEF_8821A = 0x05,
  47. CHIP_ID_HW_DEF_8723B = 0x06,
  48. CHIP_ID_HW_DEF_8192E = 0x07,
  49. CHIP_ID_HW_DEF_8814A = 0x08,
  50. CHIP_ID_HW_DEF_8821C = 0x09,
  51. CHIP_ID_HW_DEF_8822B = 0x0A,
  52. CHIP_ID_HW_DEF_8703B = 0x0B,
  53. CHIP_ID_HW_DEF_8188F = 0x0C,
  54. CHIP_ID_HW_DEF_8192F = 0x0D,
  55. CHIP_ID_HW_DEF_8197F = 0x0E,
  56. CHIP_ID_HW_DEF_8723D = 0x0F,
  57. CHIP_ID_HW_DEF_8814B = 0x11,
  58. CHIP_ID_HW_DEF_8822C = 0x13,
  59. CHIP_ID_HW_DEF_8812F = 0x14,
  60. CHIP_ID_HW_DEF_UNDEFINE = 0x7F,
  61. CHIP_ID_HW_DEF_PS = 0xEA,
  62. };
  63. static enum halmac_ret_status
  64. chk_pltfm_api(void *drv_adapter, enum halmac_interface intf,
  65. struct halmac_platform_api *pltfm_api);
  66. static enum halmac_ret_status
  67. get_chip_info(void *drv_adapter, struct halmac_platform_api *pltfm_api,
  68. enum halmac_interface intf, struct halmac_adapter *adapter);
  69. static u8
  70. pltfm_reg_r8_sdio(void *drv_adapter, struct halmac_platform_api *pltfm_api,
  71. u32 offset);
  72. static enum halmac_ret_status
  73. pltfm_reg_w8_sdio(void *drv_adapter, struct halmac_platform_api *pltfm_api,
  74. u32 offset, u8 data);
  75. static u8
  76. pltfm_reg_r_indir_sdio(void *drv_adapter, struct halmac_platform_api *pltfm_api,
  77. u32 offset);
  78. static enum halmac_ret_status
  79. cnv_to_sdio_bus_offset(u32 *offset);
  80. /**
  81. * halmac_init_adapter() - init halmac_adapter
  82. * @drv_adapter : the adapter of caller
  83. * @pltfm_api : the platform APIs which is used in halmac
  84. * @intf : bus interface
  85. * @halmac_adapter : the adapter of halmac
  86. * @halmac_api : the function pointer of APIs
  87. * Author : KaiYuan Chang / Ivan Lin
  88. * Return : enum halmac_ret_status
  89. * More details of status code can be found in prototype document
  90. */
  91. enum halmac_ret_status
  92. halmac_init_adapter(void *drv_adapter, struct halmac_platform_api *pltfm_api,
  93. enum halmac_interface intf,
  94. struct halmac_adapter **halmac_adapter,
  95. struct halmac_api **halmac_api)
  96. {
  97. struct halmac_adapter *adapter = NULL;
  98. enum halmac_ret_status status = HALMAC_RET_SUCCESS;
  99. u8 *buf = NULL;
  100. union {
  101. u32 i;
  102. u8 x[4];
  103. } ENDIAN_CHECK = { 0x01000000 };
  104. status = chk_pltfm_api(drv_adapter, intf, pltfm_api);
  105. if (status != HALMAC_RET_SUCCESS)
  106. return status;
  107. pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT, HALMAC_DBG_ALWAYS,
  108. HALMAC_SVN_VER "\n"
  109. "HALMAC_MAJOR_VER = %x\n"
  110. "HALMAC_PROTOTYPE_VER = %x\n"
  111. "HALMAC_MINOR_VER = %x\n"
  112. "HALMAC_PATCH_VER = %x\n",
  113. HALMAC_MAJOR_VER, HALMAC_PROTOTYPE_VER,
  114. HALMAC_MINOR_VER, HALMAC_PATCH_VER);
  115. if (ENDIAN_CHECK.x[0] == HALMAC_SYSTEM_ENDIAN) {
  116. pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
  117. HALMAC_DBG_ERR,
  118. "[ERR]Endian setting err!!\n");
  119. return HALMAC_RET_ENDIAN_ERR;
  120. }
  121. buf = (u8 *)pltfm_api->RTL_MALLOC(drv_adapter, sizeof(*adapter));
  122. if (!buf) {
  123. pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
  124. HALMAC_DBG_ERR,
  125. "[ERR]Malloc HAL adapter err!!\n");
  126. return HALMAC_RET_MALLOC_FAIL;
  127. }
  128. pltfm_api->RTL_MEMSET(drv_adapter, buf, 0x00, sizeof(*adapter));
  129. adapter = (struct halmac_adapter *)buf;
  130. *halmac_adapter = adapter;
  131. adapter->pltfm_api = pltfm_api;
  132. adapter->drv_adapter = drv_adapter;
  133. intf = (intf == HALMAC_INTERFACE_AXI) ? HALMAC_INTERFACE_PCIE : intf;
  134. adapter->intf = intf;
  135. if (get_chip_info(drv_adapter, pltfm_api, intf, adapter)
  136. != HALMAC_RET_SUCCESS) {
  137. PLTFM_FREE(*halmac_adapter, sizeof(**halmac_adapter));
  138. *halmac_adapter = NULL;
  139. return HALMAC_RET_CHIP_NOT_SUPPORT;
  140. }
  141. PLTFM_MUTEX_INIT(&adapter->efuse_mutex);
  142. PLTFM_MUTEX_INIT(&adapter->h2c_seq_mutex);
  143. PLTFM_MUTEX_INIT(&adapter->sdio_indir_mutex);
  144. #if (HALMAC_PLATFORM_WINDOWS == 0)
  145. #if HALMAC_88XX_SUPPORT
  146. if (adapter->chip_id == HALMAC_CHIP_ID_8822B ||
  147. adapter->chip_id == HALMAC_CHIP_ID_8821C ||
  148. adapter->chip_id == HALMAC_CHIP_ID_8822C ||
  149. adapter->chip_id == HALMAC_CHIP_ID_8812F) {
  150. init_adapter_param_88xx(adapter);
  151. status = mount_api_88xx(adapter);
  152. }
  153. #endif
  154. #if HALMAC_88XX_V1_SUPPORT
  155. if (adapter->chip_id == HALMAC_CHIP_ID_8814B) {
  156. init_adapter_param_88xx_v1(adapter);
  157. status = mount_api_88xx_v1(adapter);
  158. }
  159. #if defined(HALMAC_DATA_CPU_EN)
  160. if (adapter->chip_id == HALMAC_CHIP_ID_8814B) {
  161. init_adapter_param_88xxd_v1(adapter);
  162. status = mount_api_88xxd_v1(adapter);
  163. }
  164. #endif
  165. #endif
  166. #else
  167. #if HALMAC_8822B_SUPPORT
  168. if (adapter->chip_id == HALMAC_CHIP_ID_8822B) {
  169. init_adapter_param_win8822b(adapter);
  170. status = mount_api_win8822b(adapter);
  171. }
  172. #endif
  173. #if HALMAC_8821C_SUPPORT
  174. if (adapter->chip_id == HALMAC_CHIP_ID_8821C) {
  175. init_adapter_param_win8821c(adapter);
  176. status = mount_api_win8821c(adapter);
  177. }
  178. #endif
  179. #if HALMAC_8814B_SUPPORT
  180. if (adapter->chip_id == HALMAC_CHIP_ID_8814B) {
  181. init_adapter_param_win8814b_v1(adapter);
  182. status = mount_api_win8814b_v1(adapter);
  183. }
  184. #endif
  185. #if HALMAC_8822C_SUPPORT
  186. if (adapter->chip_id == HALMAC_CHIP_ID_8822C) {
  187. init_adapter_param_win8822c(adapter);
  188. status = mount_api_win8822c(adapter);
  189. }
  190. #endif
  191. #if HALMAC_8812F_SUPPORT
  192. if (adapter->chip_id == HALMAC_CHIP_ID_8812F) {
  193. init_adapter_param_win8812f(adapter);
  194. status = mount_api_win8812f(adapter);
  195. }
  196. #endif
  197. #endif
  198. *halmac_api = (struct halmac_api *)adapter->halmac_api;
  199. PLTFM_MSG_TRACE("[TRACE]%s <===\n", __func__);
  200. return status;
  201. }
  202. /**
  203. * halmac_halt_api() - stop halmac_api action
  204. * @adapter : the adapter of halmac
  205. * Author : Ivan Lin
  206. * Return : enum halmac_ret_status
  207. * More details of status code can be found in prototype document
  208. */
  209. enum halmac_ret_status
  210. halmac_halt_api(struct halmac_adapter *adapter)
  211. {
  212. PLTFM_MSG_TRACE("[TRACE]%s ===>\n", __func__);
  213. adapter->halmac_state.api_state = HALMAC_API_STATE_HALT;
  214. PLTFM_MSG_TRACE("[TRACE]%s <===\n", __func__);
  215. return HALMAC_RET_SUCCESS;
  216. }
  217. /**
  218. * halmac_deinit_adapter() - deinit halmac adapter
  219. * @adapter : the adapter of halmac
  220. * Author : KaiYuan Chang / Ivan Lin
  221. * Return : enum halmac_ret_status
  222. * More details of status code can be found in prototype document
  223. */
  224. enum halmac_ret_status
  225. halmac_deinit_adapter(struct halmac_adapter *adapter)
  226. {
  227. PLTFM_MSG_TRACE("[TRACE]%s ===>\n", __func__);
  228. PLTFM_MUTEX_DEINIT(&adapter->efuse_mutex);
  229. PLTFM_MUTEX_DEINIT(&adapter->h2c_seq_mutex);
  230. PLTFM_MUTEX_DEINIT(&adapter->sdio_indir_mutex);
  231. if (adapter->efuse_map) {
  232. PLTFM_FREE(adapter->efuse_map, adapter->hw_cfg_info.efuse_size);
  233. adapter->efuse_map = (u8 *)NULL;
  234. }
  235. if (adapter->sdio_fs.macid_map) {
  236. PLTFM_FREE(adapter->sdio_fs.macid_map,
  237. adapter->sdio_fs.macid_map_size);
  238. adapter->sdio_fs.macid_map = (u8 *)NULL;
  239. }
  240. if (adapter->halmac_state.psd_state.data) {
  241. PLTFM_FREE(adapter->halmac_state.psd_state.data,
  242. adapter->halmac_state.psd_state.data_size);
  243. adapter->halmac_state.psd_state.data = (u8 *)NULL;
  244. }
  245. if (adapter->halmac_api) {
  246. PLTFM_FREE(adapter->halmac_api, sizeof(struct halmac_api));
  247. adapter->halmac_api = NULL;
  248. }
  249. PLTFM_FREE(adapter, sizeof(*adapter));
  250. return HALMAC_RET_SUCCESS;
  251. }
  252. static enum halmac_ret_status
  253. chk_pltfm_api(void *drv_adapter, enum halmac_interface intf,
  254. struct halmac_platform_api *pltfm_api)
  255. {
  256. if (!pltfm_api)
  257. return HALMAC_RET_PLATFORM_API_NULL;
  258. if (!pltfm_api->MSG_PRINT)
  259. return HALMAC_RET_PLATFORM_API_NULL;
  260. if (intf == HALMAC_INTERFACE_SDIO) {
  261. if (!pltfm_api->SDIO_CMD52_READ) {
  262. pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
  263. HALMAC_DBG_ERR, "[ERR]sdio-r\n");
  264. return HALMAC_RET_PLATFORM_API_NULL;
  265. }
  266. if (!pltfm_api->SDIO_CMD53_READ_8) {
  267. pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
  268. HALMAC_DBG_ERR, "[ERR]sdio-r8\n");
  269. return HALMAC_RET_PLATFORM_API_NULL;
  270. }
  271. if (!pltfm_api->SDIO_CMD53_READ_16) {
  272. pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
  273. HALMAC_DBG_ERR, "[ERR]sdio-r16\n");
  274. return HALMAC_RET_PLATFORM_API_NULL;
  275. }
  276. if (!pltfm_api->SDIO_CMD53_READ_32) {
  277. pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
  278. HALMAC_DBG_ERR, "[ERR]sdio-r32\n");
  279. return HALMAC_RET_PLATFORM_API_NULL;
  280. }
  281. if (!pltfm_api->SDIO_CMD53_READ_N) {
  282. pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
  283. HALMAC_DBG_ERR, "[ERR]sdio-rn\n");
  284. return HALMAC_RET_PLATFORM_API_NULL;
  285. }
  286. if (!pltfm_api->SDIO_CMD52_WRITE) {
  287. pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
  288. HALMAC_DBG_ERR, "[ERR]sdio-w\n");
  289. return HALMAC_RET_PLATFORM_API_NULL;
  290. }
  291. if (!pltfm_api->SDIO_CMD53_WRITE_8) {
  292. pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
  293. HALMAC_DBG_ERR, "[ERR]sdio-w8\n");
  294. return HALMAC_RET_PLATFORM_API_NULL;
  295. }
  296. if (!pltfm_api->SDIO_CMD53_WRITE_16) {
  297. pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
  298. HALMAC_DBG_ERR, "[ERR]sdio-w16\n");
  299. return HALMAC_RET_PLATFORM_API_NULL;
  300. }
  301. if (!pltfm_api->SDIO_CMD53_WRITE_32) {
  302. pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
  303. HALMAC_DBG_ERR, "[ERR]sdio-w32\n");
  304. return HALMAC_RET_PLATFORM_API_NULL;
  305. }
  306. if (!pltfm_api->SDIO_CMD52_CIA_READ) {
  307. pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
  308. HALMAC_DBG_ERR, "[ERR]sdio-cia\n");
  309. return HALMAC_RET_PLATFORM_API_NULL;
  310. }
  311. }
  312. if (intf == HALMAC_INTERFACE_USB || intf == HALMAC_INTERFACE_PCIE) {
  313. if (!pltfm_api->REG_READ_8) {
  314. pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
  315. HALMAC_DBG_ERR, "[ERR]reg-r8\n");
  316. return HALMAC_RET_PLATFORM_API_NULL;
  317. }
  318. if (!pltfm_api->REG_READ_16) {
  319. pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
  320. HALMAC_DBG_ERR, "[ERR]reg-r16\n");
  321. return HALMAC_RET_PLATFORM_API_NULL;
  322. }
  323. if (!pltfm_api->REG_READ_32) {
  324. pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
  325. HALMAC_DBG_ERR, "[ERR]reg-r32\n");
  326. return HALMAC_RET_PLATFORM_API_NULL;
  327. }
  328. if (!pltfm_api->REG_WRITE_8) {
  329. pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
  330. HALMAC_DBG_ERR, "[ERR]reg-w8\n");
  331. return HALMAC_RET_PLATFORM_API_NULL;
  332. }
  333. if (!pltfm_api->REG_WRITE_16) {
  334. pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
  335. HALMAC_DBG_ERR, "[ERR]reg-w16\n");
  336. return HALMAC_RET_PLATFORM_API_NULL;
  337. }
  338. if (!pltfm_api->REG_WRITE_32) {
  339. pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
  340. HALMAC_DBG_ERR, "[ERR]reg-w32\n");
  341. return HALMAC_RET_PLATFORM_API_NULL;
  342. }
  343. }
  344. if (!pltfm_api->RTL_FREE) {
  345. pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
  346. HALMAC_DBG_ERR, "[ERR]mem-free\n");
  347. return HALMAC_RET_PLATFORM_API_NULL;
  348. }
  349. if (!pltfm_api->RTL_MALLOC) {
  350. pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
  351. HALMAC_DBG_ERR, "[ERR]mem-malloc\n");
  352. return HALMAC_RET_PLATFORM_API_NULL;
  353. }
  354. if (!pltfm_api->RTL_MEMCPY) {
  355. pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
  356. HALMAC_DBG_ERR, "[ERR]mem-cpy\n");
  357. return HALMAC_RET_PLATFORM_API_NULL;
  358. }
  359. if (!pltfm_api->RTL_MEMSET) {
  360. pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
  361. HALMAC_DBG_ERR, "[ERR]mem-set\n");
  362. return HALMAC_RET_PLATFORM_API_NULL;
  363. }
  364. if (!pltfm_api->RTL_DELAY_US) {
  365. pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
  366. HALMAC_DBG_ERR, "[ERR]time-delay\n");
  367. return HALMAC_RET_PLATFORM_API_NULL;
  368. }
  369. if (!pltfm_api->MUTEX_INIT) {
  370. pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
  371. HALMAC_DBG_ERR, "[ERR]mutex-init\n");
  372. return HALMAC_RET_PLATFORM_API_NULL;
  373. }
  374. if (!pltfm_api->MUTEX_DEINIT) {
  375. pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
  376. HALMAC_DBG_ERR, "[ERR]mutex-deinit\n");
  377. return HALMAC_RET_PLATFORM_API_NULL;
  378. }
  379. if (!pltfm_api->MUTEX_LOCK) {
  380. pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
  381. HALMAC_DBG_ERR, "[ERR]mutex-lock\n");
  382. return HALMAC_RET_PLATFORM_API_NULL;
  383. }
  384. if (!pltfm_api->MUTEX_UNLOCK) {
  385. pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
  386. HALMAC_DBG_ERR, "[ERR]mutex-unlock\n");
  387. return HALMAC_RET_PLATFORM_API_NULL;
  388. }
  389. if (!pltfm_api->EVENT_INDICATION) {
  390. pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
  391. HALMAC_DBG_ERR, "[ERR]event-indication\n");
  392. return HALMAC_RET_PLATFORM_API_NULL;
  393. }
  394. return HALMAC_RET_SUCCESS;
  395. }
  396. /**
  397. * halmac_get_version() - get HALMAC version
  398. * @version : return version of major, prototype and minor information
  399. * Author : KaiYuan Chang / Ivan Lin
  400. * Return : enum halmac_ret_status
  401. * More details of status code can be found in prototype document
  402. */
  403. enum halmac_ret_status
  404. halmac_get_version(struct halmac_ver *version)
  405. {
  406. version->major_ver = (u8)HALMAC_MAJOR_VER;
  407. version->prototype_ver = (u8)HALMAC_PROTOTYPE_VER;
  408. version->minor_ver = (u8)HALMAC_MINOR_VER;
  409. return HALMAC_RET_SUCCESS;
  410. }
  411. static enum halmac_ret_status
  412. get_chip_info(void *drv_adapter, struct halmac_platform_api *pltfm_api,
  413. enum halmac_interface intf, struct halmac_adapter *adapter)
  414. {
  415. u8 chip_id;
  416. u8 chip_ver;
  417. u32 cnt;
  418. if (adapter->intf == HALMAC_INTERFACE_SDIO) {
  419. pltfm_reg_w8_sdio(drv_adapter, pltfm_api, REG_SDIO_HSUS_CTRL,
  420. pltfm_reg_r8_sdio(drv_adapter, pltfm_api,
  421. REG_SDIO_HSUS_CTRL) &
  422. ~(BIT(0)));
  423. cnt = 10000;
  424. while (!(pltfm_reg_r8_sdio(drv_adapter, pltfm_api,
  425. REG_SDIO_HSUS_CTRL) & BIT(1))) {
  426. cnt--;
  427. if (cnt == 0)
  428. return HALMAC_RET_SDIO_LEAVE_SUSPEND_FAIL;
  429. }
  430. chip_id = pltfm_reg_r_indir_sdio(drv_adapter, pltfm_api,
  431. REG_SYS_CFG2);
  432. chip_ver = pltfm_reg_r_indir_sdio(drv_adapter, pltfm_api,
  433. REG_SYS_CFG1 + 1) >> 4;
  434. } else {
  435. chip_id = pltfm_api->REG_READ_8(drv_adapter, REG_SYS_CFG2);
  436. chip_ver = pltfm_api->REG_READ_8(drv_adapter,
  437. REG_SYS_CFG1 + 1) >> 4;
  438. }
  439. adapter->chip_ver = (enum halmac_chip_ver)chip_ver;
  440. if (chip_id == CHIP_ID_HW_DEF_8822B) {
  441. adapter->chip_id = HALMAC_CHIP_ID_8822B;
  442. } else if (chip_id == CHIP_ID_HW_DEF_8821C) {
  443. adapter->chip_id = HALMAC_CHIP_ID_8821C;
  444. } else if (chip_id == CHIP_ID_HW_DEF_8814B) {
  445. adapter->chip_id = HALMAC_CHIP_ID_8814B;
  446. } else if (chip_id == CHIP_ID_HW_DEF_8197F) {
  447. adapter->chip_id = HALMAC_CHIP_ID_8197F;
  448. } else if (chip_id == CHIP_ID_HW_DEF_8822C) {
  449. adapter->chip_id = HALMAC_CHIP_ID_8822C;
  450. } else if (chip_id == CHIP_ID_HW_DEF_8812F) {
  451. adapter->chip_id = HALMAC_CHIP_ID_8812F;
  452. } else {
  453. adapter->chip_id = HALMAC_CHIP_ID_UNDEFINE;
  454. PLTFM_MSG_ERR("[ERR]Chip id is undefined\n");
  455. return HALMAC_RET_CHIP_NOT_SUPPORT;
  456. }
  457. return HALMAC_RET_SUCCESS;
  458. }
  459. static u8
  460. pltfm_reg_r8_sdio(void *drv_adapter, struct halmac_platform_api *pltfm_api,
  461. u32 offset)
  462. {
  463. u8 value8;
  464. enum halmac_ret_status status = HALMAC_RET_SUCCESS;
  465. if (0 == (offset & 0xFFFF0000))
  466. offset |= WLAN_IOREG_OFFSET;
  467. status = cnv_to_sdio_bus_offset(&offset);
  468. if (status != HALMAC_RET_SUCCESS)
  469. return status;
  470. value8 = pltfm_api->SDIO_CMD52_READ(drv_adapter, offset);
  471. return value8;
  472. }
  473. static enum halmac_ret_status
  474. pltfm_reg_w8_sdio(void *drv_adapter, struct halmac_platform_api *pltfm_api,
  475. u32 offset, u8 data)
  476. {
  477. enum halmac_ret_status status = HALMAC_RET_SUCCESS;
  478. if (0 == (offset & 0xFFFF0000))
  479. offset |= WLAN_IOREG_OFFSET;
  480. status = cnv_to_sdio_bus_offset(&offset);
  481. if (status != HALMAC_RET_SUCCESS)
  482. return status;
  483. pltfm_api->SDIO_CMD52_WRITE(drv_adapter, offset, data);
  484. return HALMAC_RET_SUCCESS;
  485. }
  486. static u8
  487. pltfm_reg_r_indir_sdio(void *drv_adapter, struct halmac_platform_api *pltfm_api,
  488. u32 offset)
  489. {
  490. u8 value8, tmp, cnt = 50;
  491. u32 reg_cfg = REG_SDIO_INDIRECT_REG_CFG;
  492. u32 reg_data = REG_SDIO_INDIRECT_REG_DATA;
  493. enum halmac_ret_status status = HALMAC_RET_SUCCESS;
  494. status = cnv_to_sdio_bus_offset(&reg_cfg);
  495. if (status != HALMAC_RET_SUCCESS)
  496. return status;
  497. status = cnv_to_sdio_bus_offset(&reg_data);
  498. if (status != HALMAC_RET_SUCCESS)
  499. return status;
  500. pltfm_api->SDIO_CMD52_WRITE(drv_adapter, reg_cfg, (u8)offset);
  501. pltfm_api->SDIO_CMD52_WRITE(drv_adapter, reg_cfg + 1,
  502. (u8)(offset >> 8));
  503. pltfm_api->SDIO_CMD52_WRITE(drv_adapter, reg_cfg + 2,
  504. (u8)(BIT(3) | BIT(4)));
  505. do {
  506. tmp = pltfm_api->SDIO_CMD52_READ(drv_adapter, reg_cfg + 2);
  507. cnt--;
  508. } while (((tmp & BIT(4)) == 0) && (cnt > 0));
  509. if (((cnt & BIT(4)) == 0) && cnt == 0)
  510. pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
  511. HALMAC_DBG_ERR, "[ERR]sdio indir read\n");
  512. value8 = pltfm_api->SDIO_CMD52_READ(drv_adapter, reg_data);
  513. return value8;
  514. }
  515. /*Note: copy from cnv_to_sdio_bus_offset_88xx*/
  516. static enum halmac_ret_status
  517. cnv_to_sdio_bus_offset(u32 *offset)
  518. {
  519. switch ((*offset) & 0xFFFF0000) {
  520. case WLAN_IOREG_OFFSET:
  521. *offset &= HALMAC_WLAN_MAC_REG_MSK;
  522. *offset |= HALMAC_SDIO_CMD_ADDR_MAC_REG << 13;
  523. break;
  524. case SDIO_LOCAL_OFFSET:
  525. *offset &= HALMAC_SDIO_LOCAL_MSK;
  526. *offset |= HALMAC_SDIO_CMD_ADDR_SDIO_REG << 13;
  527. break;
  528. default:
  529. *offset = 0xFFFFFFFF;
  530. return HALMAC_RET_CONVERT_SDIO_OFFSET_FAIL;
  531. }
  532. return HALMAC_RET_SUCCESS;
  533. }