/drivers/net/wireless/bcm4329/dhd_custom_gpio.c

https://bitbucket.org/cyanogenmod/android_kernel_asus_tf300t · C · 285 lines · 211 code · 36 blank · 38 comment · 13 complexity · 3cfcca556ee71d4e2b7179415f7b9427 MD5 · raw file

  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. #define EXAMPLE_TABLE
  155. /* Customized Locale table : OPTIONAL feature */
  156. const struct cntry_locales_custom translate_custom_table[] = {
  157. /* Table should be filled out based on custom platform regulatory requirement */
  158. #ifdef EXAMPLE_TABLE
  159. {"", "XY", 4}, /* Universal if Country code is unknown or empty */
  160. {"EU", "EU", 5}, /* European union countries to : EU regrev 05 */
  161. {"AT", "EU", 5},
  162. {"BE", "EU", 5},
  163. {"BG", "EU", 5},
  164. {"CY", "EU", 5},
  165. {"CZ", "EU", 5},
  166. {"DK", "EU", 5},
  167. {"EE", "EU", 5},
  168. {"FI", "EU", 5},
  169. {"FR", "EU", 5},
  170. {"DE", "EU", 5},
  171. {"GR", "EU", 5},
  172. {"HU", "EU", 5},
  173. {"IE", "EU", 5},
  174. {"IT", "EU", 5},
  175. {"LV", "EU", 5},
  176. {"LI", "EU", 5},
  177. {"LT", "EU", 5},
  178. {"LU", "EU", 5},
  179. {"MT", "EU", 5},
  180. {"NL", "EU", 5},
  181. {"PL", "EU", 5},
  182. {"PT", "EU", 5},
  183. {"RO", "EU", 5},
  184. {"SK", "EU", 5},
  185. {"SI", "EU", 5},
  186. {"ES", "EU", 5},
  187. {"SE", "EU", 5},
  188. {"GB", "EU", 5},
  189. {"IL", "IL", 0},
  190. {"CH", "CH", 0},
  191. {"TR", "TR", 0},
  192. {"NO", "NO", 0},
  193. {"KR", "XY", 3},
  194. {"AU", "XY", 3},
  195. {"CN", "XY", 3}, /* input ISO "CN" to : XY regrev 03 */
  196. {"AR", "XY", 3},
  197. {"MX", "XY", 3},
  198. {"AS", "US", 69},
  199. {"CA", "US", 69}, /* input ISO "CA" to : US regrev 69 */
  200. {"KY", "US", 69},
  201. {"GU", "US", 69},
  202. {"FM", "US", 69},
  203. {"MP", "US", 69},
  204. {"PR", "US", 69},
  205. {"TW", "US", 69},
  206. {"VI", "US", 69},
  207. {"UM", "US", 69},
  208. {"US", "US", 69} /* input ISO "US" to : US regrev 69 */
  209. #endif /* EXAMPLE_TABLE */
  210. };
  211. /* Customized Locale convertor
  212. * input : ISO 3166-1 country abbreviation
  213. * output: customized cspec
  214. */
  215. void get_customized_country_code(char *country_iso_code, wl_country_t *cspec)
  216. {
  217. //#ifdef CUSTOMER_HW2
  218. #if 0 // Use Broadcom country code table
  219. struct cntry_locales_custom *cloc_ptr;
  220. if (!cspec)
  221. return;
  222. cloc_ptr = wifi_get_country_code(country_iso_code);
  223. if (cloc_ptr) {
  224. strlcpy(cspec->ccode, cloc_ptr->custom_locale, WLC_CNTRY_BUF_SZ);
  225. cspec->rev = cloc_ptr->custom_locale_rev;
  226. }
  227. return;
  228. #else
  229. int size, i;
  230. size = ARRAYSIZE(translate_custom_table);
  231. if (cspec == 0)
  232. return;
  233. if (size == 0)
  234. return;
  235. for (i = 0; i < size; i++) {
  236. if (strcmp(country_iso_code, translate_custom_table[i].iso_abbrev) == 0) {
  237. memcpy(cspec->ccode, translate_custom_table[i].custom_locale, WLC_CNTRY_BUF_SZ);
  238. cspec->rev = translate_custom_table[i].custom_locale_rev;
  239. return;
  240. }
  241. }
  242. #ifdef EXAMPLE_TABLE
  243. /* if no country code matched return first universal code from translate_custom_table */
  244. memcpy(cspec->ccode, translate_custom_table[0].custom_locale, WLC_CNTRY_BUF_SZ);
  245. cspec->rev = translate_custom_table[0].custom_locale_rev;
  246. #endif /* EXAMPLE_TABLE */
  247. return;
  248. #endif
  249. }