dhd_custom_gpio.c 8.5 KB

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