blob: 06e273a180511b842c62aa6d722cf7cd0eababc4 [file] [log] [blame]
developer064da3c2023-06-13 15:57:26 +08001From 030159528eff349db01b6b47b6fff8112b4282a4 Mon Sep 17 00:00:00 2001
2From: mtk25577 <jen-hao.cheng@mediatek.com>
3Date: Tue, 28 Mar 2023 18:23:00 +0800
4Subject: [PATCH 26/39] wifi: mt76: mt7996: add led feature support
5
6Signed-off-by: mtk25577 <jen-hao.cheng@mediatek.com>
7---
8 mt7996/Makefile | 1 +
9 mt7996/init.c | 33 +++++++++++++++++++++------------
10 mt7996/regs.h | 1 +
11 3 files changed, 23 insertions(+), 12 deletions(-)
12
13diff --git a/mt7996/Makefile b/mt7996/Makefile
14index bed9efd..7c2514a 100644
15--- a/mt7996/Makefile
16+++ b/mt7996/Makefile
17@@ -1,4 +1,5 @@
18 # SPDX-License-Identifier: ISC
19+EXTRA_CFLAGS += -DCONFIG_MT76_LEDS
20
21 obj-$(CONFIG_MT7996E) += mt7996e.o
22
23diff --git a/mt7996/init.c b/mt7996/init.c
24index fecd0d3..192af3f 100644
25--- a/mt7996/init.c
26+++ b/mt7996/init.c
27@@ -232,23 +232,31 @@ static void mt7996_led_set_config(struct led_classdev *led_cdev,
28 dev = container_of(mphy->dev, struct mt7996_dev, mt76);
29
30 /* select TX blink mode, 2: only data frames */
31- mt76_rmw_field(dev, MT_TMAC_TCR0(0), MT_TMAC_TCR0_TX_BLINK, 2);
32+ mt76_rmw_field(dev, MT_TMAC_TCR0(mphy->band_idx), MT_TMAC_TCR0_TX_BLINK, 2);
33
34 /* enable LED */
35- mt76_wr(dev, MT_LED_EN(0), 1);
36+ mt76_wr(dev, MT_LED_EN(mphy->band_idx), 1);
37
38 /* set LED Tx blink on/off time */
39 val = FIELD_PREP(MT_LED_TX_BLINK_ON_MASK, delay_on) |
40 FIELD_PREP(MT_LED_TX_BLINK_OFF_MASK, delay_off);
41- mt76_wr(dev, MT_LED_TX_BLINK(0), val);
42+ mt76_wr(dev, MT_LED_TX_BLINK(mphy->band_idx), val);
43+
44+ /* turn LED off */
45+ if (delay_off == 0xff && delay_on == 0x0)
46+ val = MT_LED_CTRL_POLARITY | MT_LED_CTRL_KICK;
47+ else {
48+ /* control LED */
49+ val = MT_LED_CTRL_BLINK_MODE | MT_LED_CTRL_KICK;
50+ if (mphy->band_idx == MT_BAND1)
51+ val |= MT_LED_CTRL_BLINK_BAND_SEL;
52+ }
53
54- /* control LED */
55- val = MT_LED_CTRL_BLINK_MODE | MT_LED_CTRL_KICK;
56 if (mphy->leds.al)
57 val |= MT_LED_CTRL_POLARITY;
58
59- mt76_wr(dev, MT_LED_CTRL(0), val);
60- mt76_clear(dev, MT_LED_CTRL(0), MT_LED_CTRL_KICK);
61+ mt76_wr(dev, MT_LED_CTRL(mphy->band_idx), val);
62+ mt76_clear(dev, MT_LED_CTRL(mphy->band_idx), MT_LED_CTRL_KICK);
63 }
64
65 static int mt7996_led_set_blink(struct led_classdev *led_cdev,
66@@ -400,6 +408,12 @@ mt7996_init_wiphy(struct ieee80211_hw *hw)
67 ieee80211_hw_set(hw, SUPPORTS_VHT_EXT_NSS_BW);
68 }
69
70+ /* init led callbacks */
71+ if (IS_ENABLED(CONFIG_MT76_LEDS)) {
72+ phy->mt76->leds.cdev.brightness_set = mt7996_led_set_brightness;
73+ phy->mt76->leds.cdev.blink_set = mt7996_led_set_blink;
74+ }
75+
76 mt76_set_stream_caps(phy->mt76, true);
77 mt7996_set_stream_vht_txbf_caps(phy);
78 mt7996_set_stream_he_eht_caps(phy);
79@@ -1063,11 +1077,6 @@ int mt7996_register_device(struct mt7996_dev *dev)
80 #ifdef CONFIG_NL80211_TESTMODE
81 dev->mt76.test_ops = &mt7996_testmode_ops;
82 #endif
83- /* init led callbacks */
84- if (IS_ENABLED(CONFIG_MT76_LEDS)) {
85- dev->mphy.leds.cdev.brightness_set = mt7996_led_set_brightness;
86- dev->mphy.leds.cdev.blink_set = mt7996_led_set_blink;
87- }
88
89 ret = mt76_register_device(&dev->mt76, true, mt76_rates,
90 ARRAY_SIZE(mt76_rates));
91diff --git a/mt7996/regs.h b/mt7996/regs.h
92index d1d3d15..86da1bf 100644
93--- a/mt7996/regs.h
94+++ b/mt7996/regs.h
95@@ -509,6 +509,7 @@ enum base_rev {
96
97 #define MT_LED_CTRL(_n) MT_LED_PHYS(0x00 + ((_n) * 4))
98 #define MT_LED_CTRL_KICK BIT(7)
99+#define MT_LED_CTRL_BLINK_BAND_SEL BIT(4)
100 #define MT_LED_CTRL_BLINK_MODE BIT(2)
101 #define MT_LED_CTRL_POLARITY BIT(1)
102
103--
1042.18.0
105