1b44febedSLarry Finger // SPDX-License-Identifier: GPL-2.0 2b44febedSLarry Finger /* Copyright(c) 2009-2012 Realtek Corporation.*/ 3f1d2b4d3SLarry Finger 4f1d2b4d3SLarry Finger #include "../wifi.h" 5f1d2b4d3SLarry Finger #include "../usb.h" 6f1d2b4d3SLarry Finger #include "reg.h" 7f1d2b4d3SLarry Finger #include "led.h" 8f1d2b4d3SLarry Finger 9f1d2b4d3SLarry Finger static void _rtl92cu_init_led(struct ieee80211_hw *hw, 10f1d2b4d3SLarry Finger struct rtl_led *pled, enum rtl_led_pin ledpin) 11f1d2b4d3SLarry Finger { 12f1d2b4d3SLarry Finger pled->hw = hw; 13f1d2b4d3SLarry Finger pled->ledpin = ledpin; 14f1d2b4d3SLarry Finger pled->ledon = false; 15f1d2b4d3SLarry Finger } 16f1d2b4d3SLarry Finger 17ff970453SLarry Finger static void rtl92cu_deinit_led(struct rtl_led *pled) 18f1d2b4d3SLarry Finger { 19f1d2b4d3SLarry Finger } 20f1d2b4d3SLarry Finger 21f1d2b4d3SLarry Finger void rtl92cu_sw_led_on(struct ieee80211_hw *hw, struct rtl_led *pled) 22f1d2b4d3SLarry Finger { 23f1d2b4d3SLarry Finger u8 ledcfg; 24f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 25f1d2b4d3SLarry Finger 26*34d7f007SLarry Finger rtl_dbg(rtlpriv, COMP_LED, DBG_LOUD, "LedAddr:%X ledpin=%d\n", 27f1d2b4d3SLarry Finger REG_LEDCFG2, pled->ledpin); 28f1d2b4d3SLarry Finger ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG2); 29f1d2b4d3SLarry Finger switch (pled->ledpin) { 30f1d2b4d3SLarry Finger case LED_PIN_GPIO0: 31f1d2b4d3SLarry Finger break; 32f1d2b4d3SLarry Finger case LED_PIN_LED0: 33f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, 34f1d2b4d3SLarry Finger REG_LEDCFG2, (ledcfg & 0xf0) | BIT(5) | BIT(6)); 35f1d2b4d3SLarry Finger break; 36f1d2b4d3SLarry Finger case LED_PIN_LED1: 37f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg & 0x0f) | BIT(5)); 38f1d2b4d3SLarry Finger break; 39f1d2b4d3SLarry Finger default: 40c38af3f0SLarry Finger pr_err("switch case %#x not processed\n", 41c38af3f0SLarry Finger pled->ledpin); 42f1d2b4d3SLarry Finger break; 43f1d2b4d3SLarry Finger } 44f1d2b4d3SLarry Finger pled->ledon = true; 45f1d2b4d3SLarry Finger } 46f1d2b4d3SLarry Finger 47f1d2b4d3SLarry Finger void rtl92cu_sw_led_off(struct ieee80211_hw *hw, struct rtl_led *pled) 48f1d2b4d3SLarry Finger { 49f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 50f1d2b4d3SLarry Finger u8 ledcfg; 51f1d2b4d3SLarry Finger 52*34d7f007SLarry Finger rtl_dbg(rtlpriv, COMP_LED, DBG_LOUD, "LedAddr:%X ledpin=%d\n", 53f1d2b4d3SLarry Finger REG_LEDCFG2, pled->ledpin); 54f1d2b4d3SLarry Finger ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG2); 55f1d2b4d3SLarry Finger switch (pled->ledpin) { 56f1d2b4d3SLarry Finger case LED_PIN_GPIO0: 57f1d2b4d3SLarry Finger break; 58f1d2b4d3SLarry Finger case LED_PIN_LED0: 59f1d2b4d3SLarry Finger ledcfg &= 0xf0; 60d5efe153SLarry Finger if (rtlpriv->ledctl.led_opendrain) 61f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_LEDCFG2, 62f1d2b4d3SLarry Finger (ledcfg | BIT(1) | BIT(5) | BIT(6))); 63f1d2b4d3SLarry Finger else 64f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_LEDCFG2, 65f1d2b4d3SLarry Finger (ledcfg | BIT(3) | BIT(5) | BIT(6))); 66f1d2b4d3SLarry Finger break; 67f1d2b4d3SLarry Finger case LED_PIN_LED1: 68f1d2b4d3SLarry Finger ledcfg &= 0x0f; 69f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg | BIT(3))); 70f1d2b4d3SLarry Finger break; 71f1d2b4d3SLarry Finger default: 72c38af3f0SLarry Finger pr_err("switch case %#x not processed\n", 73c38af3f0SLarry Finger pled->ledpin); 74f1d2b4d3SLarry Finger break; 75f1d2b4d3SLarry Finger } 76f1d2b4d3SLarry Finger pled->ledon = false; 77f1d2b4d3SLarry Finger } 78f1d2b4d3SLarry Finger 79f1d2b4d3SLarry Finger void rtl92cu_init_sw_leds(struct ieee80211_hw *hw) 80f1d2b4d3SLarry Finger { 81d5efe153SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 82d5efe153SLarry Finger 83d5efe153SLarry Finger _rtl92cu_init_led(hw, &rtlpriv->ledctl.sw_led0, LED_PIN_LED0); 84d5efe153SLarry Finger _rtl92cu_init_led(hw, &rtlpriv->ledctl.sw_led1, LED_PIN_LED1); 85f1d2b4d3SLarry Finger } 86f1d2b4d3SLarry Finger 87f1d2b4d3SLarry Finger void rtl92cu_deinit_sw_leds(struct ieee80211_hw *hw) 88f1d2b4d3SLarry Finger { 89d5efe153SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 90d5efe153SLarry Finger 91ff970453SLarry Finger rtl92cu_deinit_led(&rtlpriv->ledctl.sw_led0); 92ff970453SLarry Finger rtl92cu_deinit_led(&rtlpriv->ledctl.sw_led1); 93f1d2b4d3SLarry Finger } 94f1d2b4d3SLarry Finger 95f1d2b4d3SLarry Finger static void _rtl92cu_sw_led_control(struct ieee80211_hw *hw, 96f1d2b4d3SLarry Finger enum led_ctl_mode ledaction) 97f1d2b4d3SLarry Finger { 98f1d2b4d3SLarry Finger } 99f1d2b4d3SLarry Finger 100f1d2b4d3SLarry Finger void rtl92cu_led_control(struct ieee80211_hw *hw, 101f1d2b4d3SLarry Finger enum led_ctl_mode ledaction) 102f1d2b4d3SLarry Finger { 103f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 104f1d2b4d3SLarry Finger struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); 105f1d2b4d3SLarry Finger 106f1d2b4d3SLarry Finger if ((ppsc->rfoff_reason > RF_CHANGE_BY_PS) && 107f1d2b4d3SLarry Finger (ledaction == LED_CTL_TX || 108f1d2b4d3SLarry Finger ledaction == LED_CTL_RX || 109f1d2b4d3SLarry Finger ledaction == LED_CTL_SITE_SURVEY || 110f1d2b4d3SLarry Finger ledaction == LED_CTL_LINK || 111f1d2b4d3SLarry Finger ledaction == LED_CTL_NO_LINK || 112f1d2b4d3SLarry Finger ledaction == LED_CTL_START_TO_LINK || 113f1d2b4d3SLarry Finger ledaction == LED_CTL_POWER_ON)) { 114f1d2b4d3SLarry Finger return; 115f1d2b4d3SLarry Finger } 116*34d7f007SLarry Finger rtl_dbg(rtlpriv, COMP_LED, DBG_LOUD, "ledaction %d\n", ledaction); 117f1d2b4d3SLarry Finger _rtl92cu_sw_led_control(hw, ledaction); 118f1d2b4d3SLarry Finger } 119