custom_gpio_linux.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. /******************************************************************************
  2. * Customer code to add GPIO control during WLAN start/stop
  3. *
  4. * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of version 2 of the GNU General Public License as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with
  16. * this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  18. *
  19. *
  20. ******************************************************************************/
  21. #include "drv_types.h"
  22. #ifdef CONFIG_PLATFORM_SPRD
  23. //gspi func & GPIO define
  24. #include <mach/gpio.h>//0915
  25. #include <mach/board.h>
  26. #if !(defined ANDROID_2X)
  27. #ifdef CONFIG_RTL8188E
  28. #include <mach/regulator.h>
  29. #include <linux/regulator/consumer.h>
  30. #endif // CONFIG_RTL8188E
  31. #ifndef GPIO_WIFI_POWER
  32. #define GPIO_WIFI_POWER -1
  33. #endif // !GPIO_WIFI_POWER
  34. #ifndef GPIO_WIFI_RESET
  35. #define GPIO_WIFI_RESET -1
  36. #endif // !GPIO_WIFI_RESET
  37. #ifndef GPIO_WIFI_PWDN
  38. #define GPIO_WIFI_PWDN -1
  39. #endif // !GPIO_WIFI_RESET
  40. #ifdef CONFIG_GSPI_HCI
  41. extern unsigned int oob_irq;
  42. #endif // CONFIG_GSPI_HCI
  43. #ifdef CONFIG_SDIO_HCI
  44. extern int rtw_mp_mode;
  45. #else // !CONFIG_SDIO_HCI
  46. #endif // !CONFIG_SDIO_HCI
  47. int rtw_wifi_gpio_init(void)
  48. {
  49. #ifdef CONFIG_GSPI_HCI
  50. if (GPIO_WIFI_IRQ > 0) {
  51. gpio_request(GPIO_WIFI_IRQ, "oob_irq");
  52. gpio_direction_input(GPIO_WIFI_IRQ);
  53. oob_irq = gpio_to_irq(GPIO_WIFI_IRQ);
  54. DBG_8192C("%s oob_irq:%d\n", __func__, oob_irq);
  55. }
  56. #endif
  57. if (GPIO_WIFI_RESET > 0)
  58. gpio_request(GPIO_WIFI_RESET , "wifi_rst");
  59. if (GPIO_WIFI_POWER > 0)
  60. gpio_request(GPIO_WIFI_POWER, "wifi_power");
  61. #ifdef CONFIG_SDIO_HCI
  62. #if (defined(CONFIG_RTL8723A) || defined(CONFIG_RTL8723B)) && (MP_DRIVER == 1)
  63. if(rtw_mp_mode==1){
  64. DBG_871X("%s GPIO_BT_RESET pin special for mp_test\n", __func__);
  65. if (GPIO_BT_RESET > 0)
  66. gpio_request(GPIO_BT_RESET , "bt_rst");
  67. }
  68. #endif
  69. #endif
  70. return 0;
  71. }
  72. int rtw_wifi_gpio_deinit(void)
  73. {
  74. #ifdef CONFIG_GSPI_HCI
  75. if (GPIO_WIFI_IRQ > 0)
  76. gpio_free(GPIO_WIFI_IRQ);
  77. #endif
  78. if (GPIO_WIFI_RESET > 0)
  79. gpio_free(GPIO_WIFI_RESET );
  80. if (GPIO_WIFI_POWER > 0)
  81. gpio_free(GPIO_WIFI_POWER);
  82. #ifdef CONFIG_SDIO_HCI
  83. #if (defined(CONFIG_RTL8723A) || defined(CONFIG_RTL8723B)) && (MP_DRIVER == 1)
  84. if(rtw_mp_mode==1){
  85. DBG_871X("%s GPIO_BT_RESET pin special for mp_test\n", __func__);
  86. if (GPIO_BT_RESET > 0)
  87. gpio_free(GPIO_BT_RESET);
  88. }
  89. #endif
  90. #endif
  91. return 0;
  92. }
  93. /* Customer function to control hw specific wlan gpios */
  94. void rtw_wifi_gpio_wlan_ctrl(int onoff)
  95. {
  96. switch (onoff)
  97. {
  98. case WLAN_PWDN_OFF:
  99. DBG_8192C("%s: call customer specific GPIO(%d) to set wifi power down pin to 0\n",
  100. __FUNCTION__, GPIO_WIFI_RESET);
  101. #ifndef CONFIG_DONT_BUS_SCAN
  102. if (GPIO_WIFI_RESET > 0)
  103. gpio_direction_output(GPIO_WIFI_RESET , 0);
  104. #endif
  105. break;
  106. case WLAN_PWDN_ON:
  107. DBG_8192C("%s: callc customer specific GPIO(%d) to set wifi power down pin to 1\n",
  108. __FUNCTION__, GPIO_WIFI_RESET);
  109. if (GPIO_WIFI_RESET > 0)
  110. gpio_direction_output(GPIO_WIFI_RESET , 1);
  111. break;
  112. case WLAN_POWER_OFF:
  113. break;
  114. case WLAN_POWER_ON:
  115. break;
  116. #ifdef CONFIG_SDIO_HCI
  117. #if (defined(CONFIG_RTL8723A) || defined(CONFIG_RTL8723B)) && (MP_DRIVER == 1)
  118. case WLAN_BT_PWDN_OFF:
  119. if(rtw_mp_mode==1)
  120. {
  121. DBG_871X("%s: call customer specific GPIO to set wifi power down pin to 0\n",
  122. __FUNCTION__);
  123. if (GPIO_BT_RESET > 0)
  124. gpio_direction_output(GPIO_BT_RESET , 0);
  125. }
  126. break;
  127. case WLAN_BT_PWDN_ON:
  128. if(rtw_mp_mode==1)
  129. {
  130. DBG_871X("%s: callc customer specific GPIO to set wifi power down pin to 1 %x\n",
  131. __FUNCTION__, GPIO_BT_RESET);
  132. if (GPIO_BT_RESET > 0)
  133. gpio_direction_output(GPIO_BT_RESET , 1);
  134. }
  135. break;
  136. #endif
  137. #endif
  138. }
  139. }
  140. #else //ANDROID_2X
  141. #include <mach/ldo.h>
  142. #ifdef CONFIG_RTL8188E
  143. extern int sprd_3rdparty_gpio_wifi_power;
  144. #endif
  145. extern int sprd_3rdparty_gpio_wifi_pwd;
  146. #if (defined(CONFIG_RTL8723A) || defined(CONFIG_RTL8723B))
  147. extern int sprd_3rdparty_gpio_bt_reset;
  148. #endif
  149. int rtw_wifi_gpio_init(void)
  150. {
  151. #if (defined(CONFIG_RTL8723A) || defined(CONFIG_RTL8723B))
  152. if (sprd_3rdparty_gpio_bt_reset > 0)
  153. gpio_direction_output(sprd_3rdparty_gpio_bt_reset, 1);
  154. #endif
  155. return 0;
  156. }
  157. int rtw_wifi_gpio_deinit(void)
  158. {
  159. return 0;
  160. }
  161. /* Customer function to control hw specific wlan gpios */
  162. void rtw_wifi_gpio_wlan_ctrl(int onoff)
  163. {
  164. switch (onoff)
  165. {
  166. case WLAN_PWDN_OFF:
  167. DBG_8192C("%s: call customer specific GPIO to set wifi power down pin to 0\n",
  168. __FUNCTION__);
  169. if (sprd_3rdparty_gpio_wifi_pwd > 0)
  170. {
  171. gpio_set_value(sprd_3rdparty_gpio_wifi_pwd, 0);
  172. }
  173. if (sprd_3rdparty_gpio_wifi_pwd == 60) {
  174. DBG_8192C("%s: turn off VSIM2 2.8V\n", __func__);
  175. LDO_TurnOffLDO(LDO_LDO_SIM2);
  176. }
  177. break;
  178. case WLAN_PWDN_ON:
  179. DBG_8192C("%s: callc customer specific GPIO to set wifi power down pin to 1\n",
  180. __FUNCTION__);
  181. if (sprd_3rdparty_gpio_wifi_pwd == 60) {
  182. DBG_8192C("%s: turn on VSIM2 2.8V\n", __func__);
  183. LDO_SetVoltLevel(LDO_LDO_SIM2, LDO_VOLT_LEVEL0);
  184. LDO_TurnOnLDO(LDO_LDO_SIM2);
  185. }
  186. if (sprd_3rdparty_gpio_wifi_pwd > 0)
  187. {
  188. gpio_set_value(sprd_3rdparty_gpio_wifi_pwd, 1);
  189. }
  190. break;
  191. case WLAN_POWER_OFF:
  192. #ifdef CONFIG_RTL8188E
  193. #ifdef CONFIG_WIF1_LDO
  194. DBG_8192C("%s: turn off VDD-WIFI0 1.2V\n", __FUNCTION__);
  195. LDO_TurnOffLDO(LDO_LDO_WIF1);
  196. #endif //CONFIG_WIF1_LDO
  197. DBG_8192C("%s: turn off VDD-WIFI0 3.3V\n", __FUNCTION__);
  198. LDO_TurnOffLDO(LDO_LDO_WIF0);
  199. DBG_8192C("%s: call customer specific GPIO(%d) to turn off wifi power\n",
  200. __FUNCTION__, sprd_3rdparty_gpio_wifi_power);
  201. if (sprd_3rdparty_gpio_wifi_power != 65535)
  202. gpio_set_value(sprd_3rdparty_gpio_wifi_power, 0);
  203. #endif
  204. break;
  205. case WLAN_POWER_ON:
  206. #ifdef CONFIG_RTL8188E
  207. DBG_8192C("%s: call customer specific GPIO(%d) to turn on wifi power\n",
  208. __FUNCTION__, sprd_3rdparty_gpio_wifi_power);
  209. if (sprd_3rdparty_gpio_wifi_power != 65535)
  210. gpio_set_value(sprd_3rdparty_gpio_wifi_power, 1);
  211. DBG_8192C("%s: turn on VDD-WIFI0 3.3V\n", __FUNCTION__);
  212. LDO_TurnOnLDO(LDO_LDO_WIF0);
  213. LDO_SetVoltLevel(LDO_LDO_WIF0,LDO_VOLT_LEVEL1);
  214. #ifdef CONFIG_WIF1_LDO
  215. DBG_8192C("%s: turn on VDD-WIFI1 1.2V\n", __func__);
  216. LDO_TurnOnLDO(LDO_LDO_WIF1);
  217. LDO_SetVoltLevel(LDO_LDO_WIF1,LDO_VOLT_LEVEL3);
  218. #endif //CONFIG_WIF1_LDO
  219. #endif
  220. break;
  221. case WLAN_BT_PWDN_OFF:
  222. DBG_8192C("%s: call customer specific GPIO to set bt power down pin to 0\n",
  223. __FUNCTION__);
  224. #if (defined(CONFIG_RTL8723A) || defined(CONFIG_RTL8723B))
  225. if (sprd_3rdparty_gpio_bt_reset > 0)
  226. gpio_set_value(sprd_3rdparty_gpio_bt_reset, 0);
  227. #endif
  228. break;
  229. case WLAN_BT_PWDN_ON:
  230. DBG_8192C("%s: callc customer specific GPIO to set bt power down pin to 1\n",
  231. __FUNCTION__);
  232. #if (defined(CONFIG_RTL8723A) || defined(CONFIG_RTL8723B))
  233. if (sprd_3rdparty_gpio_bt_reset > 0)
  234. gpio_set_value(sprd_3rdparty_gpio_bt_reset, 1);
  235. #endif
  236. break;
  237. }
  238. }
  239. #endif //ANDROID_2X
  240. #else // !CONFIG_PLATFORM_SPRD
  241. int rtw_wifi_gpio_init(void)
  242. {
  243. return 0;
  244. }
  245. void rtw_wifi_gpio_wlan_ctrl(int onoff)
  246. {
  247. }
  248. #endif //CONFIG_PLATFORM_SPRD