blob: 70ea6c5692a5f1fb37ab3e34677711278a940c34 [file] [log] [blame]
George442888c2011-02-19 16:29:17 -06001/******************************************************************************
2 *
Larry Fingerc1d66042012-01-07 20:46:45 -06003 * Copyright(c) 2009-2012 Realtek Corporation. All rights reserved.
George442888c2011-02-19 16:29:17 -06004 *
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 *
George442888c2011-02-19 16:29:17 -060014 * The full GNU General Public License is included in this distribution in the
15 * file called LICENSE.
16 *
17 * Contact Information:
18 * wlanfae <wlanfae@realtek.com>
19 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
20 * Hsinchu 300, Taiwan.
21 *
22 *****************************************************************************/
23
24#include "../wifi.h"
25#include "../usb.h"
26#include "reg.h"
27#include "led.h"
28
29static void _rtl92cu_init_led(struct ieee80211_hw *hw,
30 struct rtl_led *pled, enum rtl_led_pin ledpin)
31{
32 pled->hw = hw;
33 pled->ledpin = ledpin;
34 pled->ledon = false;
35}
36
37static void _rtl92cu_deInit_led(struct rtl_led *pled)
38{
39}
40
41void rtl92cu_sw_led_on(struct ieee80211_hw *hw, struct rtl_led *pled)
42{
43 u8 ledcfg;
44 struct rtl_priv *rtlpriv = rtl_priv(hw);
45
Joe Perchesf30d7502012-01-04 19:40:41 -080046 RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, "LedAddr:%X ledpin=%d\n",
47 REG_LEDCFG2, pled->ledpin);
George442888c2011-02-19 16:29:17 -060048 ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG2);
49 switch (pled->ledpin) {
50 case LED_PIN_GPIO0:
51 break;
52 case LED_PIN_LED0:
53 rtl_write_byte(rtlpriv,
54 REG_LEDCFG2, (ledcfg & 0xf0) | BIT(5) | BIT(6));
55 break;
56 case LED_PIN_LED1:
57 rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg & 0x0f) | BIT(5));
58 break;
59 default:
Larry Fingerc38af3f2016-12-15 12:23:06 -060060 pr_err("switch case %#x not processed\n",
61 pled->ledpin);
George442888c2011-02-19 16:29:17 -060062 break;
63 }
64 pled->ledon = true;
65}
66
67void rtl92cu_sw_led_off(struct ieee80211_hw *hw, struct rtl_led *pled)
68{
69 struct rtl_priv *rtlpriv = rtl_priv(hw);
70 struct rtl_usb_priv *usbpriv = rtl_usbpriv(hw);
71 u8 ledcfg;
72
Joe Perchesf30d7502012-01-04 19:40:41 -080073 RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, "LedAddr:%X ledpin=%d\n",
74 REG_LEDCFG2, pled->ledpin);
George442888c2011-02-19 16:29:17 -060075 ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG2);
76 switch (pled->ledpin) {
77 case LED_PIN_GPIO0:
78 break;
79 case LED_PIN_LED0:
80 ledcfg &= 0xf0;
Mike McCormacke10542c2011-06-20 10:47:51 +090081 if (usbpriv->ledctl.led_opendrain)
George442888c2011-02-19 16:29:17 -060082 rtl_write_byte(rtlpriv, REG_LEDCFG2,
83 (ledcfg | BIT(1) | BIT(5) | BIT(6)));
84 else
85 rtl_write_byte(rtlpriv, REG_LEDCFG2,
86 (ledcfg | BIT(3) | BIT(5) | BIT(6)));
87 break;
88 case LED_PIN_LED1:
89 ledcfg &= 0x0f;
90 rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg | BIT(3)));
91 break;
92 default:
Larry Fingerc38af3f2016-12-15 12:23:06 -060093 pr_err("switch case %#x not processed\n",
94 pled->ledpin);
George442888c2011-02-19 16:29:17 -060095 break;
96 }
97 pled->ledon = false;
98}
99
100void rtl92cu_init_sw_leds(struct ieee80211_hw *hw)
101{
102 struct rtl_usb_priv *usbpriv = rtl_usbpriv(hw);
103 _rtl92cu_init_led(hw, &(usbpriv->ledctl.sw_led0), LED_PIN_LED0);
104 _rtl92cu_init_led(hw, &(usbpriv->ledctl.sw_led1), LED_PIN_LED1);
105}
106
107void rtl92cu_deinit_sw_leds(struct ieee80211_hw *hw)
108{
109 struct rtl_usb_priv *usbpriv = rtl_usbpriv(hw);
110 _rtl92cu_deInit_led(&(usbpriv->ledctl.sw_led0));
111 _rtl92cu_deInit_led(&(usbpriv->ledctl.sw_led1));
112}
113
114static void _rtl92cu_sw_led_control(struct ieee80211_hw *hw,
115 enum led_ctl_mode ledaction)
116{
117}
118
119void rtl92cu_led_control(struct ieee80211_hw *hw,
120 enum led_ctl_mode ledaction)
121{
122 struct rtl_priv *rtlpriv = rtl_priv(hw);
123 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
124
125 if ((ppsc->rfoff_reason > RF_CHANGE_BY_PS) &&
126 (ledaction == LED_CTL_TX ||
127 ledaction == LED_CTL_RX ||
128 ledaction == LED_CTL_SITE_SURVEY ||
129 ledaction == LED_CTL_LINK ||
130 ledaction == LED_CTL_NO_LINK ||
131 ledaction == LED_CTL_START_TO_LINK ||
132 ledaction == LED_CTL_POWER_ON)) {
133 return;
134 }
Joe Perchesf30d7502012-01-04 19:40:41 -0800135 RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, "ledaction %d\n", ledaction);
George442888c2011-02-19 16:29:17 -0600136 _rtl92cu_sw_led_control(hw, ledaction);
137}