Chaoming Li | f53d5a7 | 2011-06-10 15:10:10 -0500 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Larry Finger | 6a57b08 | 2012-01-07 20:46:46 -0600 | [diff] [blame] | 3 | * Copyright(c) 2009-2012 Realtek Corporation. |
Chaoming Li | f53d5a7 | 2011-06-10 15:10:10 -0500 | [diff] [blame] | 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 | * |
Chaoming Li | f53d5a7 | 2011-06-10 15:10:10 -0500 | [diff] [blame] | 14 | * 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 | * Larry Finger <Larry.Finger@lwfinger.net> |
| 23 | * |
| 24 | *****************************************************************************/ |
| 25 | |
| 26 | #include "../wifi.h" |
| 27 | #include "../pci.h" |
| 28 | #include "reg.h" |
| 29 | #include "led.h" |
| 30 | |
| 31 | static void _rtl92ce_init_led(struct ieee80211_hw *hw, |
| 32 | struct rtl_led *pled, enum rtl_led_pin ledpin) |
| 33 | { |
| 34 | pled->hw = hw; |
| 35 | pled->ledpin = ledpin; |
| 36 | pled->ledon = false; |
| 37 | } |
| 38 | |
Larry Finger | ab049fb | 2011-06-28 18:55:50 -0500 | [diff] [blame] | 39 | void rtl92de_sw_led_on(struct ieee80211_hw *hw, struct rtl_led *pled) |
Chaoming Li | f53d5a7 | 2011-06-10 15:10:10 -0500 | [diff] [blame] | 40 | { |
| 41 | u8 ledcfg; |
| 42 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 43 | |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 44 | RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, "LedAddr:%X ledpin=%d\n", |
| 45 | REG_LEDCFG2, pled->ledpin); |
Chaoming Li | f53d5a7 | 2011-06-10 15:10:10 -0500 | [diff] [blame] | 46 | |
| 47 | switch (pled->ledpin) { |
| 48 | case LED_PIN_GPIO0: |
| 49 | break; |
| 50 | case LED_PIN_LED0: |
| 51 | ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG2); |
| 52 | |
| 53 | if ((rtlpriv->efuse.eeprom_did == 0x8176) || |
| 54 | (rtlpriv->efuse.eeprom_did == 0x8193)) |
| 55 | /* BIT7 of REG_LEDCFG2 should be set to |
| 56 | * make sure we could emit the led2. */ |
| 57 | rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg & 0xf0) | |
| 58 | BIT(7) | BIT(5) | BIT(6)); |
| 59 | else |
| 60 | rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg & 0xf0) | |
| 61 | BIT(7) | BIT(5)); |
| 62 | break; |
| 63 | case LED_PIN_LED1: |
| 64 | ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG1); |
| 65 | |
| 66 | rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg & 0x0f) | BIT(5)); |
| 67 | break; |
| 68 | default: |
Larry Finger | b8c79f4 | 2016-12-15 12:23:05 -0600 | [diff] [blame] | 69 | pr_err("switch case %#x not processed\n", |
| 70 | pled->ledpin); |
Chaoming Li | f53d5a7 | 2011-06-10 15:10:10 -0500 | [diff] [blame] | 71 | break; |
| 72 | } |
| 73 | pled->ledon = true; |
| 74 | } |
| 75 | |
Larry Finger | ab049fb | 2011-06-28 18:55:50 -0500 | [diff] [blame] | 76 | void rtl92de_sw_led_off(struct ieee80211_hw *hw, struct rtl_led *pled) |
Chaoming Li | f53d5a7 | 2011-06-10 15:10:10 -0500 | [diff] [blame] | 77 | { |
| 78 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 79 | struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw); |
| 80 | u8 ledcfg; |
| 81 | |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 82 | RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, "LedAddr:%X ledpin=%d\n", |
| 83 | REG_LEDCFG2, pled->ledpin); |
Chaoming Li | f53d5a7 | 2011-06-10 15:10:10 -0500 | [diff] [blame] | 84 | |
| 85 | ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG2); |
| 86 | |
| 87 | switch (pled->ledpin) { |
| 88 | case LED_PIN_GPIO0: |
| 89 | break; |
| 90 | case LED_PIN_LED0: |
| 91 | ledcfg &= 0xf0; |
Larry Finger | 9928c7d | 2011-06-30 16:47:11 -0500 | [diff] [blame] | 92 | if (pcipriv->ledctl.led_opendrain) |
Chaoming Li | f53d5a7 | 2011-06-10 15:10:10 -0500 | [diff] [blame] | 93 | rtl_write_byte(rtlpriv, REG_LEDCFG2, |
| 94 | (ledcfg | BIT(1) | BIT(5) | BIT(6))); |
| 95 | else |
| 96 | rtl_write_byte(rtlpriv, REG_LEDCFG2, |
| 97 | (ledcfg | BIT(3) | BIT(5) | BIT(6))); |
| 98 | break; |
| 99 | case LED_PIN_LED1: |
| 100 | ledcfg &= 0x0f; |
| 101 | rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg | BIT(3))); |
| 102 | break; |
| 103 | default: |
Larry Finger | b8c79f4 | 2016-12-15 12:23:05 -0600 | [diff] [blame] | 104 | pr_err("switch case %#x not processed\n", |
| 105 | pled->ledpin); |
Chaoming Li | f53d5a7 | 2011-06-10 15:10:10 -0500 | [diff] [blame] | 106 | break; |
| 107 | } |
| 108 | pled->ledon = false; |
| 109 | } |
| 110 | |
| 111 | void rtl92de_init_sw_leds(struct ieee80211_hw *hw) |
| 112 | { |
| 113 | struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw); |
| 114 | _rtl92ce_init_led(hw, &(pcipriv->ledctl.sw_led0), LED_PIN_LED0); |
| 115 | _rtl92ce_init_led(hw, &(pcipriv->ledctl.sw_led1), LED_PIN_LED1); |
| 116 | } |
| 117 | |
| 118 | static void _rtl92ce_sw_led_control(struct ieee80211_hw *hw, |
| 119 | enum led_ctl_mode ledaction) |
| 120 | { |
| 121 | struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw); |
| 122 | struct rtl_led *pLed0 = &(pcipriv->ledctl.sw_led0); |
| 123 | switch (ledaction) { |
| 124 | case LED_CTL_POWER_ON: |
| 125 | case LED_CTL_LINK: |
| 126 | case LED_CTL_NO_LINK: |
Larry Finger | ab049fb | 2011-06-28 18:55:50 -0500 | [diff] [blame] | 127 | rtl92de_sw_led_on(hw, pLed0); |
Chaoming Li | f53d5a7 | 2011-06-10 15:10:10 -0500 | [diff] [blame] | 128 | break; |
| 129 | case LED_CTL_POWER_OFF: |
Larry Finger | ab049fb | 2011-06-28 18:55:50 -0500 | [diff] [blame] | 130 | rtl92de_sw_led_off(hw, pLed0); |
Chaoming Li | f53d5a7 | 2011-06-10 15:10:10 -0500 | [diff] [blame] | 131 | break; |
| 132 | default: |
| 133 | break; |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | void rtl92de_led_control(struct ieee80211_hw *hw, enum led_ctl_mode ledaction) |
| 138 | { |
| 139 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 140 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); |
| 141 | |
| 142 | if ((ppsc->rfoff_reason > RF_CHANGE_BY_PS) && |
| 143 | (ledaction == LED_CTL_TX || |
| 144 | ledaction == LED_CTL_RX || |
| 145 | ledaction == LED_CTL_SITE_SURVEY || |
| 146 | ledaction == LED_CTL_LINK || |
| 147 | ledaction == LED_CTL_NO_LINK || |
| 148 | ledaction == LED_CTL_START_TO_LINK || |
| 149 | ledaction == LED_CTL_POWER_ON)) { |
| 150 | return; |
| 151 | } |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 152 | RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, "ledaction %d,\n", ledaction); |
Chaoming Li | f53d5a7 | 2011-06-10 15:10:10 -0500 | [diff] [blame] | 153 | |
| 154 | _rtl92ce_sw_led_control(hw, ledaction); |
| 155 | } |