dhd_custom_gpio.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. /*
  2. * Customer code to add GPIO control during WLAN start/stop
  3. * Copyright (C) 1999-2014, 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. #include <wl_iw.h>
  34. #define WL_ERROR(x) printf x
  35. #define WL_TRACE(x)
  36. #if defined(CUSTOMER_HW2) || defined(CUSTOMER_HW4)
  37. #if defined(PLATFORM_MPS)
  38. int __attribute__ ((weak)) wifi_get_fw_nv_path(char *fw, char *nv) { return 0;};
  39. #endif
  40. #endif /* CUSTOMER_HW2 || CUSTOMER_HW4 */
  41. #if defined(OOB_INTR_ONLY) || defined(BCMSPI_ANDROID)
  42. #if defined(BCMLXSDMMC)
  43. extern int sdioh_mmc_irq(int irq);
  44. #endif /* (BCMLXSDMMC) */
  45. #if defined(CUSTOMER_HW3)
  46. #include <mach/gpio.h>
  47. #endif
  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(CUSTOMER_HW4)
  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. #if defined(CUSTOMER_HW3)
  82. gpio_request(dhd_oob_gpio_num, "oob irq");
  83. host_oob_irq = gpio_to_irq(dhd_oob_gpio_num);
  84. gpio_direction_input(dhd_oob_gpio_num);
  85. #endif /* defined CUSTOMER_HW3 */
  86. #endif /* CUSTOMER_HW2 || CUSTOMER_HW4 */
  87. return (host_oob_irq);
  88. }
  89. #endif /* defined(OOB_INTR_ONLY) || defined(BCMSPI_ANDROID) */
  90. /* Customer function to control hw specific wlan gpios */
  91. int
  92. dhd_customer_gpio_wlan_ctrl(void *adapter, int onoff)
  93. {
  94. int err = 0;
  95. return err;
  96. }
  97. #ifdef GET_CUSTOM_MAC_ENABLE
  98. /* Function to get custom MAC address */
  99. int
  100. dhd_custom_get_mac_address(void *adapter, unsigned char *buf)
  101. {
  102. int ret = 0;
  103. WL_TRACE(("%s Enter\n", __FUNCTION__));
  104. if (!buf)
  105. return -EINVAL;
  106. /* Customer access to MAC address stored outside of DHD driver */
  107. #if defined(CUSTOMER_HW2) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35))
  108. ret = wifi_platform_get_mac_addr(adapter, buf);
  109. #endif
  110. #ifdef EXAMPLE_GET_MAC
  111. /* EXAMPLE code */
  112. {
  113. struct ether_addr ea_example = {{0x00, 0x11, 0x22, 0x33, 0x44, 0xFF}};
  114. bcopy((char *)&ea_example, buf, sizeof(struct ether_addr));
  115. }
  116. #endif /* EXAMPLE_GET_MAC */
  117. return ret;
  118. }
  119. #endif /* GET_CUSTOM_MAC_ENABLE */
  120. #if !defined(CUSTOMER_HW4) || defined(PLATFORM_MPS)
  121. /* Customized Locale table : OPTIONAL feature */
  122. const struct cntry_locales_custom translate_custom_table[] = {
  123. /* Table should be filled out based on custom platform regulatory requirement */
  124. #ifdef EXAMPLE_TABLE
  125. {"", "XY", 4}, /* Universal if Country code is unknown or empty */
  126. {"US", "US", 69}, /* input ISO "US" to : US regrev 69 */
  127. {"CA", "US", 69}, /* input ISO "CA" to : US regrev 69 */
  128. {"EU", "EU", 5}, /* European union countries to : EU regrev 05 */
  129. {"AT", "EU", 5},
  130. {"BE", "EU", 5},
  131. {"BG", "EU", 5},
  132. {"CY", "EU", 5},
  133. {"CZ", "EU", 5},
  134. {"DK", "EU", 5},
  135. {"EE", "EU", 5},
  136. {"FI", "EU", 5},
  137. {"FR", "EU", 5},
  138. {"DE", "EU", 5},
  139. {"GR", "EU", 5},
  140. {"HU", "EU", 5},
  141. {"IE", "EU", 5},
  142. {"IT", "EU", 5},
  143. {"LV", "EU", 5},
  144. {"LI", "EU", 5},
  145. {"LT", "EU", 5},
  146. {"LU", "EU", 5},
  147. {"MT", "EU", 5},
  148. {"NL", "EU", 5},
  149. {"PL", "EU", 5},
  150. {"PT", "EU", 5},
  151. {"RO", "EU", 5},
  152. {"SK", "EU", 5},
  153. {"SI", "EU", 5},
  154. {"ES", "EU", 5},
  155. {"SE", "EU", 5},
  156. {"GB", "EU", 5},
  157. {"KR", "XY", 3},
  158. {"AU", "XY", 3},
  159. {"CN", "XY", 3}, /* input ISO "CN" to : XY regrev 03 */
  160. {"TW", "XY", 3},
  161. {"AR", "XY", 3},
  162. {"MX", "XY", 3},
  163. {"IL", "IL", 0},
  164. {"CH", "CH", 0},
  165. {"TR", "TR", 0},
  166. {"NO", "NO", 0},
  167. #endif /* EXMAPLE_TABLE */
  168. #if defined(CUSTOMER_HW2)
  169. #if defined(BCM4334_CHIP) || defined(BCM4335_CHIP)
  170. {"", "XZ", 11}, /* Universal if Country code is unknown or empty */
  171. #endif
  172. {"AE", "AE", 1},
  173. {"AR", "AR", 1},
  174. {"AT", "AT", 1},
  175. {"AU", "AU", 2},
  176. {"BE", "BE", 1},
  177. {"BG", "BG", 1},
  178. {"BN", "BN", 1},
  179. {"CA", "CA", 2},
  180. {"CH", "CH", 1},
  181. {"CY", "CY", 1},
  182. {"CZ", "CZ", 1},
  183. {"DE", "DE", 3},
  184. {"DK", "DK", 1},
  185. {"EE", "EE", 1},
  186. {"ES", "ES", 1},
  187. {"FI", "FI", 1},
  188. {"FR", "FR", 1},
  189. {"GB", "GB", 1},
  190. {"GR", "GR", 1},
  191. {"HR", "HR", 1},
  192. {"HU", "HU", 1},
  193. {"IE", "IE", 1},
  194. {"IS", "IS", 1},
  195. {"IT", "IT", 1},
  196. {"ID", "ID", 1},
  197. {"JP", "JP", 8},
  198. {"KR", "KR", 24},
  199. {"KW", "KW", 1},
  200. {"LI", "LI", 1},
  201. {"LT", "LT", 1},
  202. {"LU", "LU", 1},
  203. {"LV", "LV", 1},
  204. {"MA", "MA", 1},
  205. {"MT", "MT", 1},
  206. {"MX", "MX", 1},
  207. {"NL", "NL", 1},
  208. {"NO", "NO", 1},
  209. {"PL", "PL", 1},
  210. {"PT", "PT", 1},
  211. {"PY", "PY", 1},
  212. {"RO", "RO", 1},
  213. {"SE", "SE", 1},
  214. {"SI", "SI", 1},
  215. {"SK", "SK", 1},
  216. {"TR", "TR", 7},
  217. {"TW", "TW", 1},
  218. {"IR", "XZ", 11}, /* Universal if Country code is IRAN, (ISLAMIC REPUBLIC OF) */
  219. {"SD", "XZ", 11}, /* Universal if Country code is SUDAN */
  220. {"SY", "XZ", 11}, /* Universal if Country code is SYRIAN ARAB REPUBLIC */
  221. {"GL", "XZ", 11}, /* Universal if Country code is GREENLAND */
  222. {"PS", "XZ", 11}, /* Universal if Country code is PALESTINIAN TERRITORY, OCCUPIED */
  223. {"TL", "XZ", 11}, /* Universal if Country code is TIMOR-LESTE (EAST TIMOR) */
  224. {"MH", "XZ", 11}, /* Universal if Country code is MARSHALL ISLANDS */
  225. #ifdef BCM4334_CHIP
  226. {"US", "US", 0}
  227. {"RU", "RU", 5},
  228. {"SG", "SG", 4},
  229. {"US", "US", 46}
  230. #endif
  231. #ifdef BCM4330_CHIP
  232. {"RU", "RU", 1},
  233. {"US", "US", 5}
  234. #endif
  235. #endif /* CUSTOMER_HW2 */
  236. };
  237. /* Customized Locale convertor
  238. * input : ISO 3166-1 country abbreviation
  239. * output: customized cspec
  240. */
  241. void get_customized_country_code(void *adapter, char *country_iso_code, wl_country_t *cspec)
  242. {
  243. #if defined(CUSTOMER_HW2) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 39))
  244. struct cntry_locales_custom *cloc_ptr;
  245. if (!cspec)
  246. return;
  247. cloc_ptr = wifi_platform_get_country_code(adapter, country_iso_code);
  248. if (cloc_ptr) {
  249. strlcpy(cspec->ccode, cloc_ptr->custom_locale, WLC_CNTRY_BUF_SZ);
  250. cspec->rev = cloc_ptr->custom_locale_rev;
  251. }
  252. return;
  253. #else
  254. int size, i;
  255. size = ARRAYSIZE(translate_custom_table);
  256. if (cspec == 0)
  257. return;
  258. if (size == 0)
  259. return;
  260. for (i = 0; i < size; i++) {
  261. if (strcmp(country_iso_code, translate_custom_table[i].iso_abbrev) == 0) {
  262. memcpy(cspec->ccode,
  263. translate_custom_table[i].custom_locale, WLC_CNTRY_BUF_SZ);
  264. cspec->rev = translate_custom_table[i].custom_locale_rev;
  265. return;
  266. }
  267. }
  268. #ifdef EXAMPLE_TABLE
  269. /* if no country code matched return first universal code from translate_custom_table */
  270. memcpy(cspec->ccode, translate_custom_table[0].custom_locale, WLC_CNTRY_BUF_SZ);
  271. cspec->rev = translate_custom_table[0].custom_locale_rev;
  272. #endif /* EXMAPLE_TABLE */
  273. return;
  274. #endif /* defined(CUSTOMER_HW2) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 36)) */
  275. }
  276. #endif /* !CUSTOMER_HW4 */