aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/rt2x00/rt61pci.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/wireless/rt2x00/rt61pci.c')
-rw-r--r--drivers/net/wireless/rt2x00/rt61pci.c180
1 files changed, 82 insertions, 98 deletions
diff --git a/drivers/net/wireless/rt2x00/rt61pci.c b/drivers/net/wireless/rt2x00/rt61pci.c
index 1dd30510ed1e..a049ff62e791 100644
--- a/drivers/net/wireless/rt2x00/rt61pci.c
+++ b/drivers/net/wireless/rt2x00/rt61pci.c
@@ -155,6 +155,12 @@ rf_write:
155 rt2x00_rf_write(rt2x00dev, word, value); 155 rt2x00_rf_write(rt2x00dev, word, value);
156} 156}
157 157
158#ifdef CONFIG_RT61PCI_LEDS
159/*
160 * This function is only called from rt61pci_led_brightness()
161 * make gcc happy by placing this function inside the
162 * same ifdef statement as the caller.
163 */
158static void rt61pci_mcu_request(struct rt2x00_dev *rt2x00dev, 164static void rt61pci_mcu_request(struct rt2x00_dev *rt2x00dev,
159 const u8 command, const u8 token, 165 const u8 command, const u8 token,
160 const u8 arg0, const u8 arg1) 166 const u8 arg0, const u8 arg1)
@@ -181,6 +187,7 @@ static void rt61pci_mcu_request(struct rt2x00_dev *rt2x00dev,
181 rt2x00_set_field32(&reg, HOST_CMD_CSR_INTERRUPT_MCU, 1); 187 rt2x00_set_field32(&reg, HOST_CMD_CSR_INTERRUPT_MCU, 1);
182 rt2x00pci_register_write(rt2x00dev, HOST_CMD_CSR, reg); 188 rt2x00pci_register_write(rt2x00dev, HOST_CMD_CSR, reg);
183} 189}
190#endif /* CONFIG_RT61PCI_LEDS */
184 191
185static void rt61pci_eepromregister_read(struct eeprom_93cx6 *eeprom) 192static void rt61pci_eepromregister_read(struct eeprom_93cx6 *eeprom)
186{ 193{
@@ -268,6 +275,48 @@ static int rt61pci_rfkill_poll(struct rt2x00_dev *rt2x00dev)
268#define rt61pci_rfkill_poll NULL 275#define rt61pci_rfkill_poll NULL
269#endif /* CONFIG_RT61PCI_RFKILL */ 276#endif /* CONFIG_RT61PCI_RFKILL */
270 277
278#ifdef CONFIG_RT61PCI_LEDS
279static void rt61pci_led_brightness(struct led_classdev *led_cdev,
280 enum led_brightness brightness)
281{
282 struct rt2x00_led *led =
283 container_of(led_cdev, struct rt2x00_led, led_dev);
284 unsigned int enabled = brightness != LED_OFF;
285 unsigned int a_mode =
286 (enabled && led->rt2x00dev->curr_band == IEEE80211_BAND_5GHZ);
287 unsigned int bg_mode =
288 (enabled && led->rt2x00dev->curr_band == IEEE80211_BAND_2GHZ);
289
290 if (led->type == LED_TYPE_RADIO) {
291 rt2x00_set_field16(&led->rt2x00dev->led_mcu_reg,
292 MCU_LEDCS_RADIO_STATUS, enabled);
293
294 rt61pci_mcu_request(led->rt2x00dev, MCU_LED, 0xff,
295 (led->rt2x00dev->led_mcu_reg & 0xff),
296 ((led->rt2x00dev->led_mcu_reg >> 8)));
297 } else if (led->type == LED_TYPE_ASSOC) {
298 rt2x00_set_field16(&led->rt2x00dev->led_mcu_reg,
299 MCU_LEDCS_LINK_BG_STATUS, bg_mode);
300 rt2x00_set_field16(&led->rt2x00dev->led_mcu_reg,
301 MCU_LEDCS_LINK_A_STATUS, a_mode);
302
303 rt61pci_mcu_request(led->rt2x00dev, MCU_LED, 0xff,
304 (led->rt2x00dev->led_mcu_reg & 0xff),
305 ((led->rt2x00dev->led_mcu_reg >> 8)));
306 } else if (led->type == LED_TYPE_QUALITY) {
307 /*
308 * The brightness is divided into 6 levels (0 - 5),
309 * this means we need to convert the brightness
310 * argument into the matching level within that range.
311 */
312 rt61pci_mcu_request(led->rt2x00dev, MCU_LED_STRENGTH, 0xff,
313 brightness / (LED_FULL / 6), 0);
314 }
315}
316#else
317#define rt61pci_led_brightness NULL
318#endif /* CONFIG_RT61PCI_LEDS */
319
271/* 320/*
272 * Configuration handlers. 321 * Configuration handlers.
273 */ 322 */
@@ -682,78 +731,6 @@ static void rt61pci_config(struct rt2x00_dev *rt2x00dev,
682} 731}
683 732
684/* 733/*
685 * LED functions.
686 */
687static void rt61pci_enable_led(struct rt2x00_dev *rt2x00dev)
688{
689 u32 reg;
690 u8 arg0;
691 u8 arg1;
692
693 rt2x00pci_register_read(rt2x00dev, MAC_CSR14, &reg);
694 rt2x00_set_field32(&reg, MAC_CSR14_ON_PERIOD, 70);
695 rt2x00_set_field32(&reg, MAC_CSR14_OFF_PERIOD, 30);
696 rt2x00pci_register_write(rt2x00dev, MAC_CSR14, reg);
697
698 rt2x00_set_field16(&rt2x00dev->led_reg, MCU_LEDCS_RADIO_STATUS, 1);
699 rt2x00_set_field16(&rt2x00dev->led_reg, MCU_LEDCS_LINK_A_STATUS,
700 rt2x00dev->rx_status.band == IEEE80211_BAND_5GHZ);
701 rt2x00_set_field16(&rt2x00dev->led_reg, MCU_LEDCS_LINK_BG_STATUS,
702 rt2x00dev->rx_status.band != IEEE80211_BAND_5GHZ);
703
704 arg0 = rt2x00dev->led_reg & 0xff;
705 arg1 = (rt2x00dev->led_reg >> 8) & 0xff;
706
707 rt61pci_mcu_request(rt2x00dev, MCU_LED, 0xff, arg0, arg1);
708}
709
710static void rt61pci_disable_led(struct rt2x00_dev *rt2x00dev)
711{
712 u16 led_reg;
713 u8 arg0;
714 u8 arg1;
715
716 led_reg = rt2x00dev->led_reg;
717 rt2x00_set_field16(&led_reg, MCU_LEDCS_RADIO_STATUS, 0);
718 rt2x00_set_field16(&led_reg, MCU_LEDCS_LINK_BG_STATUS, 0);
719 rt2x00_set_field16(&led_reg, MCU_LEDCS_LINK_A_STATUS, 0);
720
721 arg0 = led_reg & 0xff;
722 arg1 = (led_reg >> 8) & 0xff;
723
724 rt61pci_mcu_request(rt2x00dev, MCU_LED, 0xff, arg0, arg1);
725}
726
727static void rt61pci_activity_led(struct rt2x00_dev *rt2x00dev, int rssi)
728{
729 u8 led;
730
731 if (rt2x00dev->led_mode != LED_MODE_SIGNAL_STRENGTH)
732 return;
733
734 /*
735 * Led handling requires a positive value for the rssi,
736 * to do that correctly we need to add the correction.
737 */
738 rssi += rt2x00dev->rssi_offset;
739
740 if (rssi <= 30)
741 led = 0;
742 else if (rssi <= 39)
743 led = 1;
744 else if (rssi <= 49)
745 led = 2;
746 else if (rssi <= 53)
747 led = 3;
748 else if (rssi <= 63)
749 led = 4;
750 else
751 led = 5;
752
753 rt61pci_mcu_request(rt2x00dev, MCU_LED_STRENGTH, 0xff, led, 0);
754}
755
756/*
757 * Link tuning 734 * Link tuning
758 */ 735 */
759static void rt61pci_link_stats(struct rt2x00_dev *rt2x00dev, 736static void rt61pci_link_stats(struct rt2x00_dev *rt2x00dev,
@@ -787,11 +764,6 @@ static void rt61pci_link_tuner(struct rt2x00_dev *rt2x00dev)
787 u8 up_bound; 764 u8 up_bound;
788 u8 low_bound; 765 u8 low_bound;
789 766
790 /*
791 * Update Led strength
792 */
793 rt61pci_activity_led(rt2x00dev, rssi);
794
795 rt61pci_bbp_read(rt2x00dev, 17, &r17); 767 rt61pci_bbp_read(rt2x00dev, 17, &r17);
796 768
797 /* 769 /*
@@ -1192,6 +1164,11 @@ static int rt61pci_init_registers(struct rt2x00_dev *rt2x00dev)
1192 1164
1193 rt2x00pci_register_write(rt2x00dev, MAC_CSR13, 0x0000e000); 1165 rt2x00pci_register_write(rt2x00dev, MAC_CSR13, 0x0000e000);
1194 1166
1167 rt2x00pci_register_read(rt2x00dev, MAC_CSR14, &reg);
1168 rt2x00_set_field32(&reg, MAC_CSR14_ON_PERIOD, 70);
1169 rt2x00_set_field32(&reg, MAC_CSR14_OFF_PERIOD, 30);
1170 rt2x00pci_register_write(rt2x00dev, MAC_CSR14, reg);
1171
1195 /* 1172 /*
1196 * Invalidate all Shared Keys (SEC_CSR0), 1173 * Invalidate all Shared Keys (SEC_CSR0),
1197 * and clear the Shared key Cipher algorithms (SEC_CSR1 & SEC_CSR5) 1174 * and clear the Shared key Cipher algorithms (SEC_CSR1 & SEC_CSR5)
@@ -1403,11 +1380,6 @@ static int rt61pci_enable_radio(struct rt2x00_dev *rt2x00dev)
1403 rt2x00_set_field32(&reg, RX_CNTL_CSR_ENABLE_RX_DMA, 1); 1380 rt2x00_set_field32(&reg, RX_CNTL_CSR_ENABLE_RX_DMA, 1);
1404 rt2x00pci_register_write(rt2x00dev, RX_CNTL_CSR, reg); 1381 rt2x00pci_register_write(rt2x00dev, RX_CNTL_CSR, reg);
1405 1382
1406 /*
1407 * Enable LED
1408 */
1409 rt61pci_enable_led(rt2x00dev);
1410
1411 return 0; 1383 return 0;
1412} 1384}
1413 1385
@@ -1415,11 +1387,6 @@ static void rt61pci_disable_radio(struct rt2x00_dev *rt2x00dev)
1415{ 1387{
1416 u32 reg; 1388 u32 reg;
1417 1389
1418 /*
1419 * Disable LED
1420 */
1421 rt61pci_disable_led(rt2x00dev);
1422
1423 rt2x00pci_register_write(rt2x00dev, MAC_CSR10, 0x00001818); 1390 rt2x00pci_register_write(rt2x00dev, MAC_CSR10, 0x00001818);
1424 1391
1425 /* 1392 /*
@@ -2048,35 +2015,51 @@ static int rt61pci_init_eeprom(struct rt2x00_dev *rt2x00dev)
2048 * If the eeprom value is invalid, 2015 * If the eeprom value is invalid,
2049 * switch to default led mode. 2016 * switch to default led mode.
2050 */ 2017 */
2018#ifdef CONFIG_RT61PCI_LEDS
2051 rt2x00_eeprom_read(rt2x00dev, EEPROM_LED, &eeprom); 2019 rt2x00_eeprom_read(rt2x00dev, EEPROM_LED, &eeprom);
2052 2020
2053 rt2x00dev->led_mode = rt2x00_get_field16(eeprom, EEPROM_LED_LED_MODE); 2021 value = rt2x00_get_field16(eeprom, EEPROM_LED_LED_MODE);
2022
2023 switch (value) {
2024 case LED_MODE_TXRX_ACTIVITY:
2025 case LED_MODE_ASUS:
2026 case LED_MODE_ALPHA:
2027 case LED_MODE_DEFAULT:
2028 rt2x00dev->led_flags =
2029 LED_SUPPORT_RADIO | LED_SUPPORT_ASSOC;
2030 break;
2031 case LED_MODE_SIGNAL_STRENGTH:
2032 rt2x00dev->led_flags =
2033 LED_SUPPORT_RADIO | LED_SUPPORT_ASSOC |
2034 LED_SUPPORT_QUALITY;
2035 break;
2036 }
2054 2037
2055 rt2x00_set_field16(&rt2x00dev->led_reg, MCU_LEDCS_LED_MODE, 2038 rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_LED_MODE, value);
2056 rt2x00dev->led_mode); 2039 rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_GPIO_0,
2057 rt2x00_set_field16(&rt2x00dev->led_reg, MCU_LEDCS_POLARITY_GPIO_0,
2058 rt2x00_get_field16(eeprom, 2040 rt2x00_get_field16(eeprom,
2059 EEPROM_LED_POLARITY_GPIO_0)); 2041 EEPROM_LED_POLARITY_GPIO_0));
2060 rt2x00_set_field16(&rt2x00dev->led_reg, MCU_LEDCS_POLARITY_GPIO_1, 2042 rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_GPIO_1,
2061 rt2x00_get_field16(eeprom, 2043 rt2x00_get_field16(eeprom,
2062 EEPROM_LED_POLARITY_GPIO_1)); 2044 EEPROM_LED_POLARITY_GPIO_1));
2063 rt2x00_set_field16(&rt2x00dev->led_reg, MCU_LEDCS_POLARITY_GPIO_2, 2045 rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_GPIO_2,
2064 rt2x00_get_field16(eeprom, 2046 rt2x00_get_field16(eeprom,
2065 EEPROM_LED_POLARITY_GPIO_2)); 2047 EEPROM_LED_POLARITY_GPIO_2));
2066 rt2x00_set_field16(&rt2x00dev->led_reg, MCU_LEDCS_POLARITY_GPIO_3, 2048 rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_GPIO_3,
2067 rt2x00_get_field16(eeprom, 2049 rt2x00_get_field16(eeprom,
2068 EEPROM_LED_POLARITY_GPIO_3)); 2050 EEPROM_LED_POLARITY_GPIO_3));
2069 rt2x00_set_field16(&rt2x00dev->led_reg, MCU_LEDCS_POLARITY_GPIO_4, 2051 rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_GPIO_4,
2070 rt2x00_get_field16(eeprom, 2052 rt2x00_get_field16(eeprom,
2071 EEPROM_LED_POLARITY_GPIO_4)); 2053 EEPROM_LED_POLARITY_GPIO_4));
2072 rt2x00_set_field16(&rt2x00dev->led_reg, MCU_LEDCS_POLARITY_ACT, 2054 rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_ACT,
2073 rt2x00_get_field16(eeprom, EEPROM_LED_POLARITY_ACT)); 2055 rt2x00_get_field16(eeprom, EEPROM_LED_POLARITY_ACT));
2074 rt2x00_set_field16(&rt2x00dev->led_reg, MCU_LEDCS_POLARITY_READY_BG, 2056 rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_READY_BG,
2075 rt2x00_get_field16(eeprom, 2057 rt2x00_get_field16(eeprom,
2076 EEPROM_LED_POLARITY_RDY_G)); 2058 EEPROM_LED_POLARITY_RDY_G));
2077 rt2x00_set_field16(&rt2x00dev->led_reg, MCU_LEDCS_POLARITY_READY_A, 2059 rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_READY_A,
2078 rt2x00_get_field16(eeprom, 2060 rt2x00_get_field16(eeprom,
2079 EEPROM_LED_POLARITY_RDY_A)); 2061 EEPROM_LED_POLARITY_RDY_A));
2062#endif /* CONFIG_RT61PCI_LEDS */
2080 2063
2081 return 0; 2064 return 0;
2082} 2065}
@@ -2484,6 +2467,7 @@ static const struct rt2x00lib_ops rt61pci_rt2x00_ops = {
2484 .link_stats = rt61pci_link_stats, 2467 .link_stats = rt61pci_link_stats,
2485 .reset_tuner = rt61pci_reset_tuner, 2468 .reset_tuner = rt61pci_reset_tuner,
2486 .link_tuner = rt61pci_link_tuner, 2469 .link_tuner = rt61pci_link_tuner,
2470 .led_brightness = rt61pci_led_brightness,
2487 .write_tx_desc = rt61pci_write_tx_desc, 2471 .write_tx_desc = rt61pci_write_tx_desc,
2488 .write_tx_data = rt2x00pci_write_tx_data, 2472 .write_tx_data = rt2x00pci_write_tx_data,
2489 .kick_tx_queue = rt61pci_kick_tx_queue, 2473 .kick_tx_queue = rt61pci_kick_tx_queue,