mirror of
https://github.com/torvalds/linux.git
synced 2024-12-25 12:21:37 +00:00
mt76: add led support to mt76x0e driver
Move mt76x02 led support in mt76x02-lib module in order to add tpt led trigger to mt76x0e driver Tested-by: LGA1150 <dqfext@gmail.com> Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com> Signed-off-by: Felix Fietkau <nbd@nbd.name>
This commit is contained in:
parent
3121742915
commit
5c9decdfbb
@ -230,6 +230,29 @@
|
||||
#define MT_COM_REG2 0x0738
|
||||
#define MT_COM_REG3 0x073C
|
||||
|
||||
#define MT_LED_CTRL 0x0770
|
||||
#define MT_LED_CTRL_REPLAY(_n) BIT(0 + (8 * (_n)))
|
||||
#define MT_LED_CTRL_POLARITY(_n) BIT(1 + (8 * (_n)))
|
||||
#define MT_LED_CTRL_TX_BLINK_MODE(_n) BIT(2 + (8 * (_n)))
|
||||
#define MT_LED_CTRL_KICK(_n) BIT(7 + (8 * (_n)))
|
||||
|
||||
#define MT_LED_TX_BLINK_0 0x0774
|
||||
#define MT_LED_TX_BLINK_1 0x0778
|
||||
|
||||
#define MT_LED_S0_BASE 0x077C
|
||||
#define MT_LED_S0(_n) (MT_LED_S0_BASE + 8 * (_n))
|
||||
#define MT_LED_S1_BASE 0x0780
|
||||
#define MT_LED_S1(_n) (MT_LED_S1_BASE + 8 * (_n))
|
||||
#define MT_LED_STATUS_OFF_MASK GENMASK(31, 24)
|
||||
#define MT_LED_STATUS_OFF(_v) (((_v) << __ffs(MT_LED_STATUS_OFF_MASK)) & \
|
||||
MT_LED_STATUS_OFF_MASK)
|
||||
#define MT_LED_STATUS_ON_MASK GENMASK(23, 16)
|
||||
#define MT_LED_STATUS_ON(_v) (((_v) << __ffs(MT_LED_STATUS_ON_MASK)) & \
|
||||
MT_LED_STATUS_ON_MASK)
|
||||
#define MT_LED_STATUS_DURATION_MASK GENMASK(15, 8)
|
||||
#define MT_LED_STATUS_DURATION(_v) (((_v) << __ffs(MT_LED_STATUS_DURATION_MASK)) & \
|
||||
MT_LED_STATUS_DURATION_MASK)
|
||||
|
||||
#define MT_FCE_PSE_CTRL 0x0800
|
||||
#define MT_FCE_PARAMETERS 0x0804
|
||||
#define MT_FCE_CSO 0x0808
|
||||
|
@ -75,6 +75,58 @@ static const struct ieee80211_iface_combination mt76x02_if_comb[] = {
|
||||
}
|
||||
};
|
||||
|
||||
static void
|
||||
mt76x02_led_set_config(struct mt76_dev *mdev, u8 delay_on,
|
||||
u8 delay_off)
|
||||
{
|
||||
struct mt76x02_dev *dev = container_of(mdev, struct mt76x02_dev,
|
||||
mt76);
|
||||
u32 val;
|
||||
|
||||
val = MT_LED_STATUS_DURATION(0xff) |
|
||||
MT_LED_STATUS_OFF(delay_off) |
|
||||
MT_LED_STATUS_ON(delay_on);
|
||||
|
||||
mt76_wr(dev, MT_LED_S0(mdev->led_pin), val);
|
||||
mt76_wr(dev, MT_LED_S1(mdev->led_pin), val);
|
||||
|
||||
val = MT_LED_CTRL_REPLAY(mdev->led_pin) |
|
||||
MT_LED_CTRL_KICK(mdev->led_pin);
|
||||
if (mdev->led_al)
|
||||
val |= MT_LED_CTRL_POLARITY(mdev->led_pin);
|
||||
mt76_wr(dev, MT_LED_CTRL, val);
|
||||
}
|
||||
|
||||
static int
|
||||
mt76x02_led_set_blink(struct led_classdev *led_cdev,
|
||||
unsigned long *delay_on,
|
||||
unsigned long *delay_off)
|
||||
{
|
||||
struct mt76_dev *mdev = container_of(led_cdev, struct mt76_dev,
|
||||
led_cdev);
|
||||
u8 delta_on, delta_off;
|
||||
|
||||
delta_off = max_t(u8, *delay_off / 10, 1);
|
||||
delta_on = max_t(u8, *delay_on / 10, 1);
|
||||
|
||||
mt76x02_led_set_config(mdev, delta_on, delta_off);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
mt76x02_led_set_brightness(struct led_classdev *led_cdev,
|
||||
enum led_brightness brightness)
|
||||
{
|
||||
struct mt76_dev *mdev = container_of(led_cdev, struct mt76_dev,
|
||||
led_cdev);
|
||||
|
||||
if (!brightness)
|
||||
mt76x02_led_set_config(mdev, 0, 0xff);
|
||||
else
|
||||
mt76x02_led_set_config(mdev, 0xff, 0);
|
||||
}
|
||||
|
||||
void mt76x02_init_device(struct mt76x02_dev *dev)
|
||||
{
|
||||
struct ieee80211_hw *hw = mt76_hw(dev);
|
||||
@ -109,6 +161,13 @@ void mt76x02_init_device(struct mt76x02_dev *dev)
|
||||
BIT(NL80211_IFTYPE_ADHOC);
|
||||
|
||||
wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
|
||||
|
||||
/* init led callbacks */
|
||||
if (IS_ENABLED(CONFIG_MT76_LEDS)) {
|
||||
dev->mt76.led_cdev.brightness_set =
|
||||
mt76x02_led_set_brightness;
|
||||
dev->mt76.led_cdev.blink_set = mt76x02_led_set_blink;
|
||||
}
|
||||
}
|
||||
|
||||
hw->sta_data_size = sizeof(struct mt76x02_sta);
|
||||
|
@ -26,29 +26,6 @@
|
||||
#define MT_MCU_PCIE_REMAP_BASE2 0x0744
|
||||
#define MT_MCU_PCIE_REMAP_BASE3 0x0748
|
||||
|
||||
#define MT_LED_CTRL 0x0770
|
||||
#define MT_LED_CTRL_REPLAY(_n) BIT(0 + (8 * (_n)))
|
||||
#define MT_LED_CTRL_POLARITY(_n) BIT(1 + (8 * (_n)))
|
||||
#define MT_LED_CTRL_TX_BLINK_MODE(_n) BIT(2 + (8 * (_n)))
|
||||
#define MT_LED_CTRL_KICK(_n) BIT(7 + (8 * (_n)))
|
||||
|
||||
#define MT_LED_TX_BLINK_0 0x0774
|
||||
#define MT_LED_TX_BLINK_1 0x0778
|
||||
|
||||
#define MT_LED_S0_BASE 0x077C
|
||||
#define MT_LED_S0(_n) (MT_LED_S0_BASE + 8 * (_n))
|
||||
#define MT_LED_S1_BASE 0x0780
|
||||
#define MT_LED_S1(_n) (MT_LED_S1_BASE + 8 * (_n))
|
||||
#define MT_LED_STATUS_OFF_MASK GENMASK(31, 24)
|
||||
#define MT_LED_STATUS_OFF(_v) (((_v) << __ffs(MT_LED_STATUS_OFF_MASK)) & \
|
||||
MT_LED_STATUS_OFF_MASK)
|
||||
#define MT_LED_STATUS_ON_MASK GENMASK(23, 16)
|
||||
#define MT_LED_STATUS_ON(_v) (((_v) << __ffs(MT_LED_STATUS_ON_MASK)) & \
|
||||
MT_LED_STATUS_ON_MASK)
|
||||
#define MT_LED_STATUS_DURATION_MASK GENMASK(15, 8)
|
||||
#define MT_LED_STATUS_DURATION(_v) (((_v) << __ffs(MT_LED_STATUS_DURATION_MASK)) & \
|
||||
MT_LED_STATUS_DURATION_MASK)
|
||||
|
||||
#define MT_MCU_ROM_PATCH_OFFSET 0x80000
|
||||
#define MT_MCU_ROM_PATCH_ADDR 0x90000
|
||||
|
||||
|
@ -342,54 +342,6 @@ struct mt76x02_dev *mt76x2_alloc_device(struct device *pdev)
|
||||
return dev;
|
||||
}
|
||||
|
||||
static void mt76x2_led_set_config(struct mt76_dev *mt76, u8 delay_on,
|
||||
u8 delay_off)
|
||||
{
|
||||
struct mt76x02_dev *dev = container_of(mt76, struct mt76x02_dev,
|
||||
mt76);
|
||||
u32 val;
|
||||
|
||||
val = MT_LED_STATUS_DURATION(0xff) |
|
||||
MT_LED_STATUS_OFF(delay_off) |
|
||||
MT_LED_STATUS_ON(delay_on);
|
||||
|
||||
mt76_wr(dev, MT_LED_S0(mt76->led_pin), val);
|
||||
mt76_wr(dev, MT_LED_S1(mt76->led_pin), val);
|
||||
|
||||
val = MT_LED_CTRL_REPLAY(mt76->led_pin) |
|
||||
MT_LED_CTRL_KICK(mt76->led_pin);
|
||||
if (mt76->led_al)
|
||||
val |= MT_LED_CTRL_POLARITY(mt76->led_pin);
|
||||
mt76_wr(dev, MT_LED_CTRL, val);
|
||||
}
|
||||
|
||||
static int mt76x2_led_set_blink(struct led_classdev *led_cdev,
|
||||
unsigned long *delay_on,
|
||||
unsigned long *delay_off)
|
||||
{
|
||||
struct mt76_dev *mt76 = container_of(led_cdev, struct mt76_dev,
|
||||
led_cdev);
|
||||
u8 delta_on, delta_off;
|
||||
|
||||
delta_off = max_t(u8, *delay_off / 10, 1);
|
||||
delta_on = max_t(u8, *delay_on / 10, 1);
|
||||
|
||||
mt76x2_led_set_config(mt76, delta_on, delta_off);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void mt76x2_led_set_brightness(struct led_classdev *led_cdev,
|
||||
enum led_brightness brightness)
|
||||
{
|
||||
struct mt76_dev *mt76 = container_of(led_cdev, struct mt76_dev,
|
||||
led_cdev);
|
||||
|
||||
if (!brightness)
|
||||
mt76x2_led_set_config(mt76, 0, 0xff);
|
||||
else
|
||||
mt76x2_led_set_config(mt76, 0xff, 0);
|
||||
}
|
||||
|
||||
int mt76x2_register_device(struct mt76x02_dev *dev)
|
||||
{
|
||||
int ret;
|
||||
@ -404,12 +356,6 @@ int mt76x2_register_device(struct mt76x02_dev *dev)
|
||||
|
||||
mt76x02_config_mac_addr_list(dev);
|
||||
|
||||
/* init led callbacks */
|
||||
if (IS_ENABLED(CONFIG_MT76_LEDS)) {
|
||||
dev->mt76.led_cdev.brightness_set = mt76x2_led_set_brightness;
|
||||
dev->mt76.led_cdev.blink_set = mt76x2_led_set_blink;
|
||||
}
|
||||
|
||||
ret = mt76_register_device(&dev->mt76, true, mt76x02_rates,
|
||||
ARRAY_SIZE(mt76x02_rates));
|
||||
if (ret)
|
||||
|
Loading…
Reference in New Issue
Block a user