dhd_custom_gpio.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /*
  2. * Customer code to add GPIO control during WLAN start/stop
  3. * Copyright (C) 1999-2010, 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,v 1.1.4.8.4.4 2011/01/20 20:23:09 Exp $
  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 <wlioctl.h>
  32. #include <wl_iw.h>
  33. #define WL_ERROR(x) printf x
  34. #define WL_TRACE(x)
  35. #ifdef CUSTOMER_HW
  36. extern void bcm_wlan_power_off(int);
  37. extern void bcm_wlan_power_on(int);
  38. #endif /* CUSTOMER_HW */
  39. #ifdef CUSTOMER_HW2
  40. int wifi_set_carddetect(int on);
  41. int wifi_set_power(int on, unsigned long msec);
  42. int wifi_get_irq_number(unsigned long *irq_flags_ptr);
  43. int wifi_get_mac_addr(unsigned char *buf);
  44. void *wifi_get_country_code(char *ccode);
  45. #endif
  46. #if defined(OOB_INTR_ONLY)
  47. #if defined(BCMLXSDMMC)
  48. extern int sdioh_mmc_irq(int irq);
  49. #endif /* (BCMLXSDMMC) */
  50. #ifdef CUSTOMER_HW3
  51. #include <mach/gpio.h>
  52. #endif
  53. /* Customer specific Host GPIO defintion */
  54. static int dhd_oob_gpio_num = -1; /* GG 19 */
  55. module_param(dhd_oob_gpio_num, int, 0644);
  56. MODULE_PARM_DESC(dhd_oob_gpio_num, "DHD oob gpio number");
  57. int dhd_customer_oob_irq_map(unsigned long *irq_flags_ptr)
  58. {
  59. int host_oob_irq = 0;
  60. #ifdef CUSTOMER_HW2
  61. host_oob_irq = wifi_get_irq_number(irq_flags_ptr);
  62. #else /* for NOT CUSTOMER_HW2 */
  63. #if defined(CUSTOM_OOB_GPIO_NUM)
  64. if (dhd_oob_gpio_num < 0) {
  65. dhd_oob_gpio_num = CUSTOM_OOB_GPIO_NUM;
  66. }
  67. #endif
  68. if (dhd_oob_gpio_num < 0) {
  69. WL_ERROR(("%s: ERROR customer specific Host GPIO is NOT defined \n",
  70. __FUNCTION__));
  71. return (dhd_oob_gpio_num);
  72. }
  73. WL_ERROR(("%s: customer specific Host GPIO number is (%d)\n",
  74. __FUNCTION__, dhd_oob_gpio_num));
  75. #if defined CUSTOMER_HW
  76. host_oob_irq = MSM_GPIO_TO_INT(dhd_oob_gpio_num);
  77. #elif defined CUSTOMER_HW3
  78. gpio_request(dhd_oob_gpio_num, "oob irq");
  79. host_oob_irq = gpio_to_irq(dhd_oob_gpio_num);
  80. gpio_direction_input(dhd_oob_gpio_num);
  81. #endif /* CUSTOMER_HW */
  82. #endif /* CUSTOMER_HW2 */
  83. return (host_oob_irq);
  84. }
  85. #endif /* defined(OOB_INTR_ONLY) */
  86. /* Customer function to control hw specific wlan gpios */
  87. void
  88. dhd_customer_gpio_wlan_ctrl(int onoff)
  89. {
  90. switch (onoff) {
  91. case WLAN_RESET_OFF:
  92. WL_TRACE(("%s: call customer specific GPIO to insert WLAN RESET\n",
  93. __FUNCTION__));
  94. #ifdef CUSTOMER_HW
  95. bcm_wlan_power_off(2);
  96. #endif /* CUSTOMER_HW */
  97. #ifdef CUSTOMER_HW2
  98. wifi_set_power(0, 0);
  99. #endif
  100. WL_ERROR(("=========== WLAN placed in RESET ========\n"));
  101. break;
  102. case WLAN_RESET_ON:
  103. WL_TRACE(("%s: callc customer specific GPIO to remove WLAN RESET\n",
  104. __FUNCTION__));
  105. #ifdef CUSTOMER_HW
  106. bcm_wlan_power_on(2);
  107. #endif /* CUSTOMER_HW */
  108. #ifdef CUSTOMER_HW2
  109. wifi_set_power(1, 0);
  110. #endif
  111. WL_ERROR(("=========== WLAN going back to live ========\n"));
  112. break;
  113. case WLAN_POWER_OFF:
  114. WL_TRACE(("%s: call customer specific GPIO to turn off WL_REG_ON\n",
  115. __FUNCTION__));
  116. #ifdef CUSTOMER_HW
  117. bcm_wlan_power_off(1);
  118. #endif /* CUSTOMER_HW */
  119. break;
  120. case WLAN_POWER_ON:
  121. WL_TRACE(("%s: call customer specific GPIO to turn on WL_REG_ON\n",
  122. __FUNCTION__));
  123. #ifdef CUSTOMER_HW
  124. bcm_wlan_power_on(1);
  125. /* Lets customer power to get stable */
  126. OSL_DELAY(50);
  127. #endif /* CUSTOMER_HW */
  128. break;
  129. }
  130. }
  131. #ifdef GET_CUSTOM_MAC_ENABLE
  132. /* Function to get custom MAC address */
  133. int
  134. dhd_custom_get_mac_address(unsigned char *buf)
  135. {
  136. int ret = 0;
  137. WL_TRACE(("%s Enter\n", __FUNCTION__));
  138. if (!buf)
  139. return -EINVAL;
  140. /* Customer access to MAC address stored outside of DHD driver */
  141. #ifdef CUSTOMER_HW2
  142. ret = wifi_get_mac_addr(buf);
  143. #endif
  144. #ifdef EXAMPLE_GET_MAC
  145. /* EXAMPLE code */
  146. {
  147. struct ether_addr ea_example = {{0x00, 0x11, 0x22, 0x33, 0x44, 0xFF}};
  148. bcopy((char *)&ea_example, buf, sizeof(struct ether_addr));
  149. }
  150. #endif /* EXAMPLE_GET_MAC */
  151. return ret;
  152. }
  153. #endif /* GET_CUSTOM_MAC_ENABLE */
  154. /* Customized Locale table : OPTIONAL feature */
  155. const struct cntry_locales_custom translate_custom_table[] = {
  156. /* Table should be filled out based on custom platform regulatory requirement */
  157. #ifdef EXAMPLE_TABLE
  158. {"", "XY", 4}, /* universal */
  159. {"US", "US", 69}, /* input ISO "US" to : US regrev 69 */
  160. {"CA", "US", 69}, /* input ISO "CA" to : US regrev 69 */
  161. {"EU", "EU", 5}, /* European union countries */
  162. {"AT", "EU", 5},
  163. {"BE", "EU", 5},
  164. {"BG", "EU", 5},
  165. {"CY", "EU", 5},
  166. {"CZ", "EU", 5},
  167. {"DK", "EU", 5},
  168. {"EE", "EU", 5},
  169. {"FI", "EU", 5},
  170. {"FR", "EU", 5},
  171. {"DE", "EU", 5},
  172. {"GR", "EU", 5},
  173. {"HU", "EU", 5},
  174. {"IE", "EU", 5},
  175. {"IT", "EU", 5},
  176. {"LV", "EU", 5},
  177. {"LI", "EU", 5},
  178. {"LT", "EU", 5},
  179. {"LU", "EU", 5},
  180. {"MT", "EU", 5},
  181. {"NL", "EU", 5},
  182. {"PL", "EU", 5},
  183. {"PT", "EU", 5},
  184. {"RO", "EU", 5},
  185. {"SK", "EU", 5},
  186. {"SI", "EU", 5},
  187. {"ES", "EU", 5},
  188. {"SE", "EU", 5},
  189. {"GB", "EU", 5}, /* input ISO "GB" to : EU regrev 05 */
  190. {"IL", "IL", 0},
  191. {"CH", "CH", 0},
  192. {"TR", "TR", 0},
  193. {"NO", "NO", 0},
  194. {"KR", "XY", 3},
  195. {"AU", "XY", 3},
  196. {"CN", "XY", 3}, /* input ISO "CN" to : XY regrev 03 */
  197. {"TW", "XY", 3},
  198. {"AR", "XY", 3},
  199. {"MX", "XY", 3}
  200. #endif /* EXAMPLE_TABLE */
  201. };
  202. /* Customized Locale convertor
  203. * input : ISO 3166-1 country abbreviation
  204. * output: customized cspec
  205. */
  206. void get_customized_country_code(char *country_iso_code, wl_country_t *cspec)
  207. {
  208. #ifdef CUSTOMER_HW2
  209. struct cntry_locales_custom *cloc_ptr;
  210. if (!cspec)
  211. return;
  212. cloc_ptr = wifi_get_country_code(country_iso_code);
  213. if (cloc_ptr) {
  214. strlcpy(cspec->ccode, cloc_ptr->custom_locale, WLC_CNTRY_BUF_SZ);
  215. cspec->rev = cloc_ptr->custom_locale_rev;
  216. }
  217. return;
  218. #else
  219. int size, i;
  220. size = ARRAYSIZE(translate_custom_table);
  221. if (cspec == 0)
  222. return;
  223. if (size == 0)
  224. return;
  225. for (i = 0; i < size; i++) {
  226. if (strcmp(country_iso_code, translate_custom_table[i].iso_abbrev) == 0) {
  227. memcpy(cspec->ccode, translate_custom_table[i].custom_locale, WLC_CNTRY_BUF_SZ);
  228. cspec->rev = translate_custom_table[i].custom_locale_rev;
  229. return;
  230. }
  231. }
  232. memcpy(cspec->ccode, translate_custom_table[0].custom_locale, WLC_CNTRY_BUF_SZ);
  233. cspec->rev = translate_custom_table[0].custom_locale_rev;
  234. return;
  235. #endif
  236. }