Commit 3abd46dd authored by Lorenzo Bianconi's avatar Lorenzo Bianconi Committed by Felix Fietkau
Browse files

wifi: mt76: move leds struct in mt76_phy



Move leds struct in mt76_phy in order to have leds associated to phy
(e.g. in dbdc mode) instead of per device.

Tested-by: default avatarFrank Wunderlich <frank-w@public-files.de>
Co-developed-by: default avatarRyder Lee <ryder.Lee@mediatek.com>
Signed-off-by: default avatarRyder Lee <ryder.Lee@mediatek.com>
Signed-off-by: default avatarLorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: default avatarFelix Fietkau <nbd@nbd.name>
parent a00b7910
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -112,7 +112,7 @@ mt76_register_debugfs_fops(struct mt76_phy *phy,
	if (!dir)
		return NULL;

	debugfs_create_u8("led_pin", 0600, dir, &dev->leds.pin);
	debugfs_create_u8("led_pin", 0600, dir, &phy->leds.pin);
	debugfs_create_u32("regidx", 0600, dir, &dev->debugfs_reg);
	debugfs_create_file_unsafe("regval", 0600, dir, dev, fops);
	debugfs_create_file_unsafe("napi_threaded", 0600, dir, dev,
+27 −21
Original line number Diff line number Diff line
@@ -192,42 +192,48 @@ static const struct cfg80211_sar_capa mt76_sar_capa = {
	.freq_ranges = &mt76_sar_freq_ranges[0],
};

static int mt76_led_init(struct mt76_dev *dev)
static int mt76_led_init(struct mt76_phy *phy)
{
	struct device_node *np = dev->dev->of_node;
	struct ieee80211_hw *hw = dev->hw;
	int led_pin;
	struct mt76_dev *dev = phy->dev;
	struct ieee80211_hw *hw = phy->hw;

	if (!dev->leds.cdev.brightness_set && !dev->leds.cdev.blink_set)
	if (!phy->leds.cdev.brightness_set && !phy->leds.cdev.blink_set)
		return 0;

	snprintf(dev->leds.name, sizeof(dev->leds.name),
		 "mt76-%s", wiphy_name(hw->wiphy));
	snprintf(phy->leds.name, sizeof(phy->leds.name), "mt76-%s",
		 wiphy_name(hw->wiphy));

	dev->leds.cdev.name = dev->leds.name;
	dev->leds.cdev.default_trigger =
	phy->leds.cdev.name = phy->leds.name;
	phy->leds.cdev.default_trigger =
		ieee80211_create_tpt_led_trigger(hw,
					IEEE80211_TPT_LEDTRIG_FL_RADIO,
					mt76_tpt_blink,
					ARRAY_SIZE(mt76_tpt_blink));

	if (phy == &dev->phy) {
		struct device_node *np = dev->dev->of_node;

		np = of_get_child_by_name(np, "led");
		if (np) {
			int led_pin;

			if (!of_property_read_u32(np, "led-sources", &led_pin))
			dev->leds.pin = led_pin;
		dev->leds.al = of_property_read_bool(np, "led-active-low");
				phy->leds.pin = led_pin;
			phy->leds.al = of_property_read_bool(np,
							     "led-active-low");
			of_node_put(np);
		}
	}

	return led_classdev_register(dev->dev, &dev->leds.cdev);
	return led_classdev_register(dev->dev, &phy->leds.cdev);
}

static void mt76_led_cleanup(struct mt76_dev *dev)
static void mt76_led_cleanup(struct mt76_phy *phy)
{
	if (!dev->leds.cdev.brightness_set && !dev->leds.cdev.blink_set)
	if (!phy->leds.cdev.brightness_set && !phy->leds.cdev.blink_set)
		return;

	led_classdev_unregister(&dev->leds.cdev);
	led_classdev_unregister(&phy->leds.cdev);
}

static void mt76_init_stream_cap(struct mt76_phy *phy,
@@ -653,7 +659,7 @@ int mt76_register_device(struct mt76_dev *dev, bool vht,
	mt76_check_sband(&dev->phy, &phy->sband_6g, NL80211_BAND_6GHZ);

	if (IS_ENABLED(CONFIG_MT76_LEDS)) {
		ret = mt76_led_init(dev);
		ret = mt76_led_init(phy);
		if (ret)
			return ret;
	}
@@ -674,7 +680,7 @@ void mt76_unregister_device(struct mt76_dev *dev)
	struct ieee80211_hw *hw = dev->hw;

	if (IS_ENABLED(CONFIG_MT76_LEDS))
		mt76_led_cleanup(dev);
		mt76_led_cleanup(&dev->phy);
	mt76_tx_status_check(dev, true);
	ieee80211_unregister_hw(hw);
}
+7 −7
Original line number Diff line number Diff line
@@ -731,6 +731,13 @@ struct mt76_phy {
	} rx_amsdu[__MT_RXQ_MAX];

	struct mt76_freq_range_power *frp;

	struct {
		struct led_classdev cdev;
		char name[32];
		bool al;
		u8 pin;
	} leds;
};

struct mt76_dev {
@@ -830,13 +837,6 @@ struct mt76_dev {
		struct mt76_usb usb;
		struct mt76_sdio sdio;
	};

	struct {
		struct led_classdev cdev;
		char name[32];
		bool al;
		u8 pin;
	} leds;
};

struct mt76_power_limits {
+15 −15
Original line number Diff line number Diff line
@@ -330,10 +330,10 @@ static const struct ieee80211_iface_combination if_comb[] = {
	}
};

static void mt7603_led_set_config(struct mt76_dev *mt76, u8 delay_on,
static void mt7603_led_set_config(struct mt76_phy *mphy, u8 delay_on,
				  u8 delay_off)
{
	struct mt7603_dev *dev = container_of(mt76, struct mt7603_dev,
	struct mt7603_dev *dev = container_of(mphy->dev, struct mt7603_dev,
					      mt76);
	u32 val, addr;

@@ -341,15 +341,15 @@ static void mt7603_led_set_config(struct mt76_dev *mt76, u8 delay_on,
	      FIELD_PREP(MT_LED_STATUS_OFF, delay_off) |
	      FIELD_PREP(MT_LED_STATUS_ON, delay_on);

	addr = mt7603_reg_map(dev, MT_LED_STATUS_0(mt76->leds.pin));
	addr = mt7603_reg_map(dev, MT_LED_STATUS_0(mphy->leds.pin));
	mt76_wr(dev, addr, val);
	addr = mt7603_reg_map(dev, MT_LED_STATUS_1(mt76->leds.pin));
	addr = mt7603_reg_map(dev, MT_LED_STATUS_1(mphy->leds.pin));
	mt76_wr(dev, addr, val);

	val = MT_LED_CTRL_REPLAY(mt76->leds.pin) |
	      MT_LED_CTRL_KICK(mt76->leds.pin);
	if (mt76->leds.al)
		val |= MT_LED_CTRL_POLARITY(mt76->leds.pin);
	val = MT_LED_CTRL_REPLAY(mphy->leds.pin) |
	      MT_LED_CTRL_KICK(mphy->leds.pin);
	if (mphy->leds.al)
		val |= MT_LED_CTRL_POLARITY(mphy->leds.pin);
	addr = mt7603_reg_map(dev, MT_LED_CTRL);
	mt76_wr(dev, addr, val);
}
@@ -358,27 +358,27 @@ static int mt7603_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,
	struct mt76_phy *mphy = container_of(led_cdev, struct mt76_phy,
					     leds.cdev);
	u8 delta_on, delta_off;

	delta_off = max_t(u8, *delay_off / 10, 1);
	delta_on = max_t(u8, *delay_on / 10, 1);

	mt7603_led_set_config(mt76, delta_on, delta_off);
	mt7603_led_set_config(mphy, delta_on, delta_off);
	return 0;
}

static void mt7603_led_set_brightness(struct led_classdev *led_cdev,
				      enum led_brightness brightness)
{
	struct mt76_dev *mt76 = container_of(led_cdev, struct mt76_dev,
	struct mt76_phy *mphy = container_of(led_cdev, struct mt76_phy,
					     leds.cdev);

	if (!brightness)
		mt7603_led_set_config(mt76, 0, 0xff);
		mt7603_led_set_config(mphy, 0, 0xff);
	else
		mt7603_led_set_config(mt76, 0xff, 0);
		mt7603_led_set_config(mphy, 0xff, 0);
}

static u32 __mt7603_reg_addr(struct mt7603_dev *dev, u32 addr)
@@ -535,8 +535,8 @@ int mt7603_register_device(struct mt7603_dev *dev)

	/* init led callbacks */
	if (IS_ENABLED(CONFIG_MT76_LEDS)) {
		dev->mt76.leds.cdev.brightness_set = mt7603_led_set_brightness;
		dev->mt76.leds.cdev.blink_set = mt7603_led_set_blink;
		dev->mphy.leds.cdev.brightness_set = mt7603_led_set_brightness;
		dev->mphy.leds.cdev.blink_set = mt7603_led_set_blink;
	}

	wiphy->reg_notifier = mt7603_regd_notifier;
+13 −13
Original line number Diff line number Diff line
@@ -71,32 +71,32 @@ mt7615_led_set_config(struct led_classdev *led_cdev,
		      u8 delay_on, u8 delay_off)
{
	struct mt7615_dev *dev;
	struct mt76_dev *mt76;
	struct mt76_phy *mphy;
	u32 val, addr;

	mt76 = container_of(led_cdev, struct mt76_dev, leds.cdev);
	dev = container_of(mt76, struct mt7615_dev, mt76);
	mphy = container_of(led_cdev, struct mt76_phy, leds.cdev);
	dev = container_of(mphy->dev, struct mt7615_dev, mt76);

	if (!mt76_connac_pm_ref(&dev->mphy, &dev->pm))
	if (!mt76_connac_pm_ref(mphy, &dev->pm))
		return;

	val = FIELD_PREP(MT_LED_STATUS_DURATION, 0xffff) |
	      FIELD_PREP(MT_LED_STATUS_OFF, delay_off) |
	      FIELD_PREP(MT_LED_STATUS_ON, delay_on);

	addr = mt7615_reg_map(dev, MT_LED_STATUS_0(mt76->leds.pin));
	addr = mt7615_reg_map(dev, MT_LED_STATUS_0(mphy->leds.pin));
	mt76_wr(dev, addr, val);
	addr = mt7615_reg_map(dev, MT_LED_STATUS_1(mt76->leds.pin));
	addr = mt7615_reg_map(dev, MT_LED_STATUS_1(mphy->leds.pin));
	mt76_wr(dev, addr, val);

	val = MT_LED_CTRL_REPLAY(mt76->leds.pin) |
	      MT_LED_CTRL_KICK(mt76->leds.pin);
	if (mt76->leds.al)
		val |= MT_LED_CTRL_POLARITY(mt76->leds.pin);
	val = MT_LED_CTRL_REPLAY(mphy->leds.pin) |
	      MT_LED_CTRL_KICK(mphy->leds.pin);
	if (mphy->leds.al)
		val |= MT_LED_CTRL_POLARITY(mphy->leds.pin);
	addr = mt7615_reg_map(dev, MT_LED_CTRL);
	mt76_wr(dev, addr, val);

	mt76_connac_pm_unref(&dev->mphy, &dev->pm);
	mt76_connac_pm_unref(mphy, &dev->pm);
}

static int
@@ -133,8 +133,8 @@ int mt7615_register_device(struct mt7615_dev *dev)

	/* init led callbacks */
	if (IS_ENABLED(CONFIG_MT76_LEDS)) {
		dev->mt76.leds.cdev.brightness_set = mt7615_led_set_brightness;
		dev->mt76.leds.cdev.blink_set = mt7615_led_set_blink;
		dev->mphy.leds.cdev.brightness_set = mt7615_led_set_brightness;
		dev->mphy.leds.cdev.blink_set = mt7615_led_set_blink;
	}

	ret = mt7622_wmac_init(dev);
Loading