dhd_custom_gpio.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. /*
  2. * Customer code to add GPIO control during WLAN start/stop
  3. *
  4. * Portions of this code are copyright (c) 2020 Cypress Semiconductor Corporation
  5. *
  6. * Copyright (C) 1999-2020, Broadcom Corporation
  7. *
  8. * Unless you and Broadcom execute a separate written software license
  9. * agreement governing use of this software, this software is licensed to you
  10. * under the terms of the GNU General Public License version 2 (the "GPL"),
  11. * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  12. * following added to such license:
  13. *
  14. * As a special exception, the copyright holders of this software give you
  15. * permission to link this software with independent modules, and to copy and
  16. * distribute the resulting executable under terms of your choice, provided that
  17. * you also meet, for each linked independent module, the terms and conditions of
  18. * the license of that module. An independent module is a module which is not
  19. * derived from this software. The special exception does not apply to any
  20. * modifications of the software.
  21. *
  22. * Notwithstanding the above, under no circumstances may you combine this
  23. * software in any way with any other Broadcom software provided under a license
  24. * other than the GPL, without Broadcom's express prior written consent.
  25. *
  26. *
  27. * <<Broadcom-WL-IPTag/Open:>>
  28. *
  29. * $Id: dhd_custom_gpio.c 691191 2017-03-21 07:09:04Z $
  30. */
  31. #include <typedefs.h>
  32. #include <linuxver.h>
  33. #include <osl.h>
  34. #include <bcmutils.h>
  35. #include <dngl_stats.h>
  36. #include <dhd.h>
  37. #include <dhd_linux.h>
  38. #include <wlioctl.h>
  39. #if defined(WL_WIRELESS_EXT)
  40. #include <wl_iw.h>
  41. #endif // endif
  42. #define WL_ERROR(x) printf x
  43. #define WL_TRACE(x)
  44. #if defined(OOB_INTR_ONLY) || defined(BCMSPI_ANDROID)
  45. #if defined(BCMLXSDMMC)
  46. extern int sdioh_mmc_irq(int irq);
  47. #endif /* (BCMLXSDMMC) */
  48. /* Customer specific Host GPIO defintion */
  49. static int dhd_oob_gpio_num = -1;
  50. module_param(dhd_oob_gpio_num, int, 0644);
  51. MODULE_PARM_DESC(dhd_oob_gpio_num, "DHD oob gpio number");
  52. /* This function will return:
  53. * 1) return : Host gpio interrupt number per customer platform
  54. * 2) irq_flags_ptr : Type of Host interrupt as Level or Edge
  55. *
  56. * NOTE :
  57. * Customer should check his platform definitions
  58. * and his Host Interrupt spec
  59. * to figure out the proper setting for his platform.
  60. * Broadcom provides just reference settings as example.
  61. *
  62. */
  63. int dhd_customer_oob_irq_map(void *adapter, unsigned long *irq_flags_ptr)
  64. {
  65. int host_oob_irq = 0;
  66. #if defined(CUSTOMER_HW2) || defined(BOARD_HIKEY)
  67. host_oob_irq = wifi_platform_get_irq_number(adapter, irq_flags_ptr);
  68. #else
  69. #if defined(CUSTOM_OOB_GPIO_NUM)
  70. if (dhd_oob_gpio_num < 0) {
  71. dhd_oob_gpio_num = CUSTOM_OOB_GPIO_NUM;
  72. }
  73. #endif /* CUSTOMER_OOB_GPIO_NUM */
  74. if (dhd_oob_gpio_num < 0) {
  75. WL_ERROR(("%s: ERROR customer specific Host GPIO is NOT defined \n",
  76. __FUNCTION__));
  77. return (dhd_oob_gpio_num);
  78. }
  79. WL_ERROR(("%s: customer specific Host GPIO number is (%d)\n",
  80. __FUNCTION__, dhd_oob_gpio_num));
  81. #endif // endif
  82. return (host_oob_irq);
  83. }
  84. #endif /* defined(OOB_INTR_ONLY) || defined(BCMSPI_ANDROID) */
  85. /* Customer function to control hw specific wlan gpios */
  86. int
  87. dhd_customer_gpio_wlan_ctrl(void *adapter, int onoff)
  88. {
  89. int err = 0;
  90. return err;
  91. }
  92. #ifdef GET_CUSTOM_MAC_ENABLE
  93. /* Function to get custom MAC address */
  94. int
  95. dhd_custom_get_mac_address(void *adapter, unsigned char *buf)
  96. {
  97. int ret = 0;
  98. WL_TRACE(("%s Enter\n", __FUNCTION__));
  99. if (!buf)
  100. return -EINVAL;
  101. /* Customer access to MAC address stored outside of DHD driver */
  102. #if (defined(CUSTOMER_HW2) || defined(BOARD_HIKEY)) && (LINUX_VERSION_CODE >= \
  103. KERNEL_VERSION(2, 6, 35))
  104. ret = wifi_platform_get_mac_addr(adapter, buf);
  105. #endif // endif
  106. #ifdef EXAMPLE_GET_MAC
  107. /* EXAMPLE code */
  108. {
  109. struct ether_addr ea_example = {{0x00, 0x11, 0x22, 0x33, 0x44, 0xFF}};
  110. bcopy((char *)&ea_example, buf, sizeof(struct ether_addr));
  111. }
  112. #endif /* EXAMPLE_GET_MAC */
  113. return ret;
  114. }
  115. #endif /* GET_CUSTOM_MAC_ENABLE */
  116. /* Customized Locale table : OPTIONAL feature */
  117. const struct cntry_locales_custom translate_custom_table[] = {
  118. /* Table should be filled out based on custom platform regulatory requirement */
  119. #ifdef EXAMPLE_TABLE
  120. {"", "XY", 4}, /* Universal if Country code is unknown or empty */
  121. {"US", "US", 69}, /* input ISO "US" to : US regrev 69 */
  122. {"CA", "US", 69}, /* input ISO "CA" to : US regrev 69 */
  123. {"EU", "EU", 5}, /* European union countries to : EU regrev 05 */
  124. {"AT", "EU", 5},
  125. {"BE", "EU", 5},
  126. {"BG", "EU", 5},
  127. {"CY", "EU", 5},
  128. {"CZ", "EU", 5},
  129. {"DK", "EU", 5},
  130. {"EE", "EU", 5},
  131. {"FI", "EU", 5},
  132. {"FR", "EU", 5},
  133. {"DE", "EU", 5},
  134. {"GR", "EU", 5},
  135. {"HU", "EU", 5},
  136. {"IE", "EU", 5},
  137. {"IT", "EU", 5},
  138. {"LV", "EU", 5},
  139. {"LI", "EU", 5},
  140. {"LT", "EU", 5},
  141. {"LU", "EU", 5},
  142. {"MT", "EU", 5},
  143. {"NL", "EU", 5},
  144. {"PL", "EU", 5},
  145. {"PT", "EU", 5},
  146. {"RO", "EU", 5},
  147. {"SK", "EU", 5},
  148. {"SI", "EU", 5},
  149. {"ES", "EU", 5},
  150. {"SE", "EU", 5},
  151. {"GB", "EU", 5},
  152. {"KR", "XY", 3},
  153. {"AU", "XY", 3},
  154. {"CN", "XY", 3}, /* input ISO "CN" to : XY regrev 03 */
  155. {"TW", "XY", 3},
  156. {"AR", "XY", 3},
  157. {"MX", "XY", 3},
  158. {"IL", "IL", 0},
  159. {"CH", "CH", 0},
  160. {"TR", "TR", 0},
  161. {"NO", "NO", 0},
  162. #endif /* EXMAPLE_TABLE */
  163. #if (defined(CUSTOMER_HW2) || defined(BOARD_HIKEY))
  164. #if defined(BCM4335_CHIP)
  165. {"", "XZ", 11}, /* Universal if Country code is unknown or empty */
  166. #endif // endif
  167. {"AE", "AE", 1},
  168. {"AR", "AR", 1},
  169. {"AT", "AT", 1},
  170. {"AU", "AU", 2},
  171. {"BE", "BE", 1},
  172. {"BG", "BG", 1},
  173. {"BN", "BN", 1},
  174. {"CA", "CA", 2},
  175. {"CH", "CH", 1},
  176. {"CY", "CY", 1},
  177. {"CZ", "CZ", 1},
  178. {"DE", "DE", 3},
  179. {"DK", "DK", 1},
  180. {"EE", "EE", 1},
  181. {"ES", "ES", 1},
  182. {"FI", "FI", 1},
  183. {"FR", "FR", 1},
  184. {"GB", "GB", 1},
  185. {"GR", "GR", 1},
  186. {"HR", "HR", 1},
  187. {"HU", "HU", 1},
  188. {"IE", "IE", 1},
  189. {"IS", "IS", 1},
  190. {"IT", "IT", 1},
  191. {"ID", "ID", 1},
  192. {"JP", "JP", 8},
  193. {"KR", "KR", 24},
  194. {"KW", "KW", 1},
  195. {"LI", "LI", 1},
  196. {"LT", "LT", 1},
  197. {"LU", "LU", 1},
  198. {"LV", "LV", 1},
  199. {"MA", "MA", 1},
  200. {"MT", "MT", 1},
  201. {"MX", "MX", 1},
  202. {"NL", "NL", 1},
  203. {"NO", "NO", 1},
  204. {"PL", "PL", 1},
  205. {"PT", "PT", 1},
  206. {"PY", "PY", 1},
  207. {"RO", "RO", 1},
  208. {"SE", "SE", 1},
  209. {"SI", "SI", 1},
  210. {"SK", "SK", 1},
  211. {"TR", "TR", 7},
  212. {"TW", "TW", 1},
  213. {"IR", "XZ", 11}, /* Universal if Country code is IRAN, (ISLAMIC REPUBLIC OF) */
  214. {"SD", "XZ", 11}, /* Universal if Country code is SUDAN */
  215. {"SY", "XZ", 11}, /* Universal if Country code is SYRIAN ARAB REPUBLIC */
  216. {"GL", "XZ", 11}, /* Universal if Country code is GREENLAND */
  217. {"PS", "XZ", 11}, /* Universal if Country code is PALESTINIAN TERRITORY, OCCUPIED */
  218. {"TL", "XZ", 11}, /* Universal if Country code is TIMOR-LESTE (EAST TIMOR) */
  219. {"MH", "XZ", 11}, /* Universal if Country code is MARSHALL ISLANDS */
  220. #endif // endif
  221. };
  222. /* Customized Locale convertor
  223. * input : ISO 3166-1 country abbreviation
  224. * output: customized cspec
  225. */
  226. #ifdef CUSTOM_COUNTRY_CODE
  227. void get_customized_country_code(void *adapter, char *country_iso_code,
  228. wl_country_t *cspec, u32 flags)
  229. #else
  230. void get_customized_country_code(void *adapter, char *country_iso_code, wl_country_t *cspec)
  231. #endif /* CUSTOM_COUNTRY_CODE */
  232. {
  233. #if defined(OEM_ANDROID)
  234. #if (defined(CUSTOMER_HW2) || defined(BOARD_HIKEY)) && (LINUX_VERSION_CODE >= \
  235. KERNEL_VERSION(2, 6, 39))
  236. struct cntry_locales_custom *cloc_ptr;
  237. if (!cspec)
  238. return;
  239. #ifdef CUSTOM_COUNTRY_CODE
  240. cloc_ptr = wifi_platform_get_country_code(adapter, country_iso_code, flags);
  241. #else
  242. cloc_ptr = wifi_platform_get_country_code(adapter, country_iso_code);
  243. #endif /* CUSTOM_COUNTRY_CODE */
  244. if (cloc_ptr) {
  245. strlcpy(cspec->ccode, cloc_ptr->custom_locale, WLC_CNTRY_BUF_SZ);
  246. cspec->rev = cloc_ptr->custom_locale_rev;
  247. }
  248. return;
  249. #else
  250. int size, i;
  251. size = ARRAYSIZE(translate_custom_table);
  252. if (cspec == 0)
  253. return;
  254. if (size == 0)
  255. return;
  256. for (i = 0; i < size; i++) {
  257. if (strcmp(country_iso_code, translate_custom_table[i].iso_abbrev) == 0) {
  258. memcpy(cspec->ccode,
  259. translate_custom_table[i].custom_locale, WLC_CNTRY_BUF_SZ);
  260. cspec->rev = translate_custom_table[i].custom_locale_rev;
  261. return;
  262. }
  263. }
  264. #ifdef EXAMPLE_TABLE
  265. /* if no country code matched return first universal code from translate_custom_table */
  266. memcpy(cspec->ccode, translate_custom_table[0].custom_locale, WLC_CNTRY_BUF_SZ);
  267. cspec->rev = translate_custom_table[0].custom_locale_rev;
  268. #endif /* EXMAPLE_TABLE */
  269. return;
  270. #endif /* (defined(CUSTOMER_HW2) || defined(BOARD_HIKEY)) &&
  271. * (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 36))
  272. */
  273. #endif /* OEM_ANDROID */
  274. }