/drivers/net/wireless/bcmdhd/dhd_custom_gpio.c

https://bitbucket.org/cyanogenmod/android_kernel_asus_tf300t · C · 302 lines · 218 code · 35 blank · 49 comment · 14 complexity · 50b3ad0b7c54a63067255e15333d9b2c MD5 · raw file

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