rtl8812au_led.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. *
  19. ******************************************************************************/
  20. #define _RTL8812AU_LED_C_
  21. //#include <drv_types.h>
  22. #include <rtl8812a_hal.h>
  23. //================================================================================
  24. // LED object.
  25. //================================================================================
  26. //================================================================================
  27. // Prototype of protected function.
  28. //================================================================================
  29. //================================================================================
  30. // LED_819xUsb routines.
  31. //================================================================================
  32. //
  33. // Description:
  34. // Turn on LED according to LedPin specified.
  35. //
  36. static void
  37. SwLedOn_8812AU(
  38. PADAPTER padapter,
  39. PLED_USB pLed
  40. )
  41. {
  42. u8 LedCfg;
  43. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
  44. if( (padapter->bSurpriseRemoved == _TRUE) || ( padapter->bDriverStopped == _TRUE))
  45. {
  46. return;
  47. }
  48. if( RT_GetInterfaceSelection(padapter) == INTF_SEL2_MINICARD ||
  49. RT_GetInterfaceSelection(padapter) == INTF_SEL3_USB_Solo ||
  50. RT_GetInterfaceSelection(padapter) == INTF_SEL4_USB_Combo)
  51. {
  52. LedCfg = rtw_read8(padapter, REG_LEDCFG2);
  53. RT_TRACE(_module_rtl8712_led_c_,_drv_info_,("In SwLedON,LedAddr:%X LEDPIN=%d\n",REG_LEDCFG2, pLed->LedPin));
  54. switch(pLed->LedPin)
  55. {
  56. case LED_PIN_GPIO0:
  57. break;
  58. case LED_PIN_LED0:
  59. RT_TRACE(_module_rtl8712_led_c_,_drv_info_,("In SwLedOn,LedAddr:%X LEDPIN=%d\n",REG_LEDCFG2, pLed->LedPin));
  60. LedCfg = rtw_read8(padapter, REG_LEDCFG2);
  61. rtw_write8(padapter, REG_LEDCFG2, (LedCfg&0xf0)|BIT5|BIT6); // SW control led0 on.
  62. break;
  63. case LED_PIN_LED1:
  64. rtw_write8(padapter, REG_LEDCFG2, (LedCfg&0x0f)|BIT5); // SW control led1 on.
  65. break;
  66. default:
  67. break;
  68. }
  69. }
  70. else
  71. {
  72. switch(pLed->LedPin)
  73. {
  74. case LED_PIN_GPIO0:
  75. break;
  76. case LED_PIN_LED0:
  77. if(pHalData->AntDivCfg==0)
  78. {
  79. LedCfg = rtw_read8(padapter, REG_LEDCFG0);
  80. rtw_write8(padapter, REG_LEDCFG0, (LedCfg&0x70)|BIT5); // SW control led0 on.
  81. RT_TRACE(_module_rtl8712_led_c_,_drv_info_,("SwLedOn LED0 0x%x\n", rtw_read32(padapter, REG_LEDCFG0)));
  82. }
  83. else
  84. {
  85. LedCfg = rtw_read8(padapter, REG_LEDCFG2);
  86. rtw_write8(padapter, REG_LEDCFG2, (LedCfg&0xe0)|BIT7|BIT6|BIT5); // SW control led0 on.
  87. RT_TRACE(_module_rtl8712_led_c_,_drv_info_,("SwLedOn LED0 Addr 0x%x, 0x%x\n", REG_LEDCFG2, rtw_read32(padapter, REG_LEDCFG2)));
  88. }
  89. break;
  90. case LED_PIN_LED1:
  91. LedCfg = rtw_read8(padapter, (REG_LEDCFG1));
  92. rtw_write8(padapter, (REG_LEDCFG1), (LedCfg&0x70)|BIT5); // SW control led1 on.
  93. RT_TRACE(_module_rtl8712_led_c_,_drv_info_,("SwLedOn LED1 0x%x\n", rtw_read32(padapter, REG_LEDCFG1)));
  94. break;
  95. case LED_PIN_LED2:
  96. LedCfg = rtw_read8(padapter, (REG_LEDCFG2));
  97. rtw_write8(padapter, (REG_LEDCFG2), (LedCfg&0x70)|BIT5); // SW control led1 on.
  98. RT_TRACE(_module_rtl8712_led_c_,_drv_info_,("SwLedOn LED2 0x%x\n", rtw_read32(padapter, REG_LEDCFG2)));
  99. break;
  100. default:
  101. break;
  102. }
  103. }
  104. pLed->bLedOn = _TRUE;
  105. }
  106. //
  107. // Description:
  108. // Turn off LED according to LedPin specified.
  109. //
  110. static void
  111. SwLedOff_8812AU(
  112. PADAPTER padapter,
  113. PLED_USB pLed
  114. )
  115. {
  116. u8 LedCfg;
  117. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
  118. if(padapter->bSurpriseRemoved == _TRUE)
  119. {
  120. return;
  121. }
  122. if( RT_GetInterfaceSelection(padapter) == INTF_SEL2_MINICARD ||
  123. RT_GetInterfaceSelection(padapter) == INTF_SEL3_USB_Solo ||
  124. RT_GetInterfaceSelection(padapter) == INTF_SEL4_USB_Combo)
  125. {
  126. RT_TRACE(_module_rtl8712_led_c_,_drv_info_,("In SwLedOff,LedAddr:%X LEDPIN=%d\n",REG_LEDCFG2, pLed->LedPin));
  127. LedCfg = rtw_read8(padapter, REG_LEDCFG2);
  128. // 2009/10/23 MH Issau eed to move the LED GPIO from bit 0 to bit3.
  129. // 2009/10/26 MH Issau if tyhe device is 8c DID is 0x8176, we need to enable bit6 to
  130. // enable GPIO8 for controlling LED.
  131. // 2010/07/02 Supprt Open-drain arrangement for controlling the LED. Added by Roger.
  132. //
  133. switch(pLed->LedPin)
  134. {
  135. case LED_PIN_GPIO0:
  136. break;
  137. case LED_PIN_LED0:
  138. if(pHalData->bLedOpenDrain == _TRUE)
  139. {
  140. LedCfg &= 0x90; // Set to software control.
  141. rtw_write8(padapter, REG_LEDCFG2, (LedCfg|BIT3));
  142. LedCfg = rtw_read8(padapter, REG_MAC_PINMUX_CFG);
  143. LedCfg &= 0xFE;
  144. rtw_write8(padapter, REG_MAC_PINMUX_CFG, LedCfg);
  145. }
  146. else
  147. {
  148. rtw_write8(padapter, REG_LEDCFG2, (LedCfg|BIT3|BIT5|BIT6));
  149. }
  150. break;
  151. case LED_PIN_LED1:
  152. LedCfg &= 0x0f; // Set to software control.
  153. rtw_write8(padapter, REG_LEDCFG2, (LedCfg|BIT3));
  154. break;
  155. default:
  156. break;
  157. }
  158. }
  159. else
  160. {
  161. switch(pLed->LedPin)
  162. {
  163. case LED_PIN_GPIO0:
  164. break;
  165. case LED_PIN_LED0:
  166. if(pHalData->AntDivCfg==0)
  167. {
  168. LedCfg = rtw_read8(padapter, REG_LEDCFG0);
  169. LedCfg &= 0x70; // Set to software control.
  170. rtw_write8(padapter, REG_LEDCFG0, (LedCfg|BIT3|BIT5));
  171. RT_TRACE(_module_rtl8712_led_c_,_drv_info_,("SwLedOff LED0 0x%x\n", rtw_read32(padapter, REG_LEDCFG0)));
  172. }
  173. else
  174. {
  175. LedCfg = rtw_read8(padapter, REG_LEDCFG2);
  176. LedCfg &= 0xe0; // Set to software control.
  177. if(IS_HARDWARE_TYPE_8723A(padapter))
  178. rtw_write8(padapter, REG_LEDCFG2, (LedCfg|BIT3|BIT7|BIT5));
  179. else
  180. rtw_write8(padapter, REG_LEDCFG2, (LedCfg|BIT3|BIT7|BIT6|BIT5));
  181. RT_TRACE(_module_rtl8712_led_c_,_drv_info_,("SwLedOff LED0 0x%x\n", rtw_read32(padapter, REG_LEDCFG2)));
  182. }
  183. break;
  184. case LED_PIN_LED1:
  185. LedCfg = rtw_read8(padapter, REG_LEDCFG1);
  186. LedCfg &= 0x70; // Set to software control.
  187. rtw_write8(padapter, REG_LEDCFG1, (LedCfg|BIT3|BIT5));
  188. RT_TRACE(_module_rtl8712_led_c_,_drv_info_,("SwLedOff LED1 0x%x\n", rtw_read32(padapter, REG_LEDCFG1)));
  189. break;
  190. case LED_PIN_LED2:
  191. LedCfg = rtw_read8(padapter, REG_LEDCFG2);
  192. LedCfg &= 0x70; // Set to software control.
  193. rtw_write8(padapter, REG_LEDCFG2, (LedCfg|BIT3|BIT5));
  194. RT_TRACE(_module_rtl8712_led_c_,_drv_info_,("SwLedOff LED1 0x%x\n", rtw_read32(padapter, REG_LEDCFG2)));
  195. break;
  196. default:
  197. break;
  198. }
  199. }
  200. pLed->bLedOn = _FALSE;
  201. }
  202. //
  203. // Description:
  204. // Turn on LED according to LedPin specified.
  205. //
  206. static void
  207. SwLedOn_8821AU(
  208. PADAPTER Adapter,
  209. PLED_USB pLed
  210. )
  211. {
  212. u8 LedCfg;
  213. if( (Adapter->bSurpriseRemoved == _TRUE) || ( Adapter->bDriverStopped == _TRUE))
  214. {
  215. return;
  216. }
  217. if( RT_GetInterfaceSelection(Adapter) == INTF_SEL2_MINICARD ||
  218. RT_GetInterfaceSelection(Adapter) == INTF_SEL3_USB_Solo ||
  219. RT_GetInterfaceSelection(Adapter) == INTF_SEL4_USB_Combo)
  220. {
  221. LedCfg = rtw_read8(Adapter, REG_LEDCFG2);
  222. RT_TRACE(_module_rtl8712_led_c_,_drv_info_,("In SwLedON,LedAddr:%X LEDPIN=%d\n",REG_LEDCFG2, pLed->LedPin));
  223. switch(pLed->LedPin)
  224. {
  225. case LED_PIN_GPIO0:
  226. break;
  227. case LED_PIN_LED0:
  228. RT_TRACE(_module_rtl8712_led_c_,_drv_info_,("In SwLedOn,LedAddr:%X LEDPIN=%d\n",REG_LEDCFG2, pLed->LedPin));
  229. LedCfg = rtw_read8(Adapter, REG_LEDCFG2);
  230. rtw_write8(Adapter, REG_LEDCFG2, (LedCfg&0xf0)|BIT5|BIT6); // SW control led0 on.
  231. break;
  232. case LED_PIN_LED1:
  233. rtw_write8(Adapter, REG_LEDCFG2, (LedCfg&0x0f)|BIT5); // SW control led1 on.
  234. break;
  235. default:
  236. break;
  237. }
  238. }
  239. else
  240. {
  241. switch(pLed->LedPin)
  242. {
  243. case LED_PIN_GPIO0:
  244. break;
  245. case LED_PIN_LED0:
  246. case LED_PIN_LED1:
  247. case LED_PIN_LED2:
  248. if(IS_HARDWARE_TYPE_8821U(Adapter))
  249. {
  250. LedCfg = rtw_read8(Adapter, REG_LEDCFG2);
  251. rtw_write8(Adapter, REG_LEDCFG2, ((LedCfg&0x20) & (~BIT3))|BIT5); // SW control led0 on.
  252. RT_TRACE(_module_rtl8712_led_c_,_drv_info_,("8821 SwLedOn LED2 0x%x\n", rtw_read32(Adapter, REG_LEDCFG0)));
  253. }
  254. break;
  255. default:
  256. break;
  257. }
  258. }
  259. pLed->bLedOn = _TRUE;
  260. }
  261. //
  262. // Description:
  263. // Turn off LED according to LedPin specified.
  264. //
  265. static void
  266. SwLedOff_8821AU(
  267. PADAPTER Adapter,
  268. PLED_USB pLed
  269. )
  270. {
  271. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  272. u8 LedCfg;
  273. if(Adapter->bSurpriseRemoved == _TRUE)
  274. {
  275. return;
  276. }
  277. if( RT_GetInterfaceSelection(Adapter) == INTF_SEL2_MINICARD ||
  278. RT_GetInterfaceSelection(Adapter) == INTF_SEL3_USB_Solo ||
  279. RT_GetInterfaceSelection(Adapter) == INTF_SEL4_USB_Combo)
  280. {
  281. RT_TRACE(_module_rtl8712_led_c_,_drv_info_,("In SwLedOff,LedAddr:%X LEDPIN=%d\n",REG_LEDCFG2, pLed->LedPin));
  282. LedCfg = rtw_read8(Adapter, REG_LEDCFG2);
  283. // 2009/10/23 MH Issau eed to move the LED GPIO from bit 0 to bit3.
  284. // 2009/10/26 MH Issau if tyhe device is 8c DID is 0x8176, we need to enable bit6 to
  285. // enable GPIO8 for controlling LED.
  286. // 2010/07/02 Supprt Open-drain arrangement for controlling the LED. Added by Roger.
  287. //
  288. switch(pLed->LedPin)
  289. {
  290. case LED_PIN_GPIO0:
  291. break;
  292. case LED_PIN_LED0:
  293. if(pHalData->bLedOpenDrain == _TRUE)
  294. {
  295. LedCfg &= 0x90; // Set to software control.
  296. rtw_write8(Adapter, REG_LEDCFG2, (LedCfg|BIT3));
  297. LedCfg = rtw_read8(Adapter, REG_MAC_PINMUX_CFG);
  298. LedCfg &= 0xFE;
  299. rtw_write8(Adapter, REG_MAC_PINMUX_CFG, LedCfg);
  300. }
  301. else
  302. {
  303. rtw_write8(Adapter, REG_LEDCFG2, (LedCfg|BIT3|BIT5|BIT6));
  304. }
  305. break;
  306. case LED_PIN_LED1:
  307. LedCfg &= 0x0f; // Set to software control.
  308. rtw_write8(Adapter, REG_LEDCFG2, (LedCfg|BIT3));
  309. break;
  310. default:
  311. break;
  312. }
  313. }
  314. else
  315. {
  316. switch(pLed->LedPin)
  317. {
  318. case LED_PIN_GPIO0:
  319. break;
  320. case LED_PIN_LED0:
  321. case LED_PIN_LED1:
  322. case LED_PIN_LED2:
  323. if(IS_HARDWARE_TYPE_8821U(Adapter))
  324. {
  325. LedCfg = rtw_read8(Adapter, REG_LEDCFG2);
  326. LedCfg &= 0x20; // Set to software control.
  327. rtw_write8(Adapter, REG_LEDCFG2, (LedCfg|BIT3|BIT5));
  328. RT_TRACE(_module_rtl8712_led_c_,_drv_info_,("8821 SwLedOff LED2 0x%x\n", rtw_read32(Adapter, REG_LEDCFG0)));
  329. }
  330. break;
  331. default:
  332. break;
  333. }
  334. }
  335. pLed->bLedOn = _FALSE;
  336. }
  337. //================================================================================
  338. // Interface to manipulate LED objects.
  339. //================================================================================
  340. //================================================================================
  341. // Default LED behavior.
  342. //================================================================================
  343. //
  344. // Description:
  345. // Initialize all LED_871x objects.
  346. //
  347. void
  348. rtl8812au_InitSwLeds(
  349. _adapter *padapter
  350. )
  351. {
  352. struct led_priv *pledpriv = &(padapter->ledpriv);
  353. pledpriv->LedControlHandler = LedControlUSB;
  354. if(IS_HARDWARE_TYPE_8812(padapter)) {
  355. pledpriv->SwLedOn = SwLedOn_8812AU;
  356. pledpriv->SwLedOff = SwLedOff_8812AU;
  357. } else {
  358. pledpriv->SwLedOn = SwLedOn_8821AU;
  359. pledpriv->SwLedOff = SwLedOff_8821AU;
  360. }
  361. InitLed(padapter, &(pledpriv->SwLed0), LED_PIN_LED0);
  362. InitLed(padapter, &(pledpriv->SwLed1), LED_PIN_LED1);
  363. InitLed(padapter, &(pledpriv->SwLed2), LED_PIN_LED2);
  364. }
  365. //
  366. // Description:
  367. // DeInitialize all LED_819xUsb objects.
  368. //
  369. void
  370. rtl8812au_DeInitSwLeds(
  371. _adapter *padapter
  372. )
  373. {
  374. struct led_priv *ledpriv = &(padapter->ledpriv);
  375. DeInitLed( &(ledpriv->SwLed0) );
  376. DeInitLed( &(ledpriv->SwLed1) );
  377. DeInitLed( &(ledpriv->SwLed2) );
  378. }