Skip to content

Commit

Permalink
mt76: add led support using mac80211 led framework
Browse files Browse the repository at this point in the history
use tpt-trigger as default trigger

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
  • Loading branch information
LorenzoBianconi authored and nbd168 committed Oct 31, 2017
1 parent f6a021d commit c9bdcd8
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
45 changes: 45 additions & 0 deletions mac80211.c
Expand Up @@ -76,6 +76,47 @@ static const struct ieee80211_channel mt76_channels_5ghz[] = {
CHAN5G(165, 5825),
};

static const struct ieee80211_tpt_blink mt76_tpt_blink[] = {
{ .throughput = 0 * 1024, .blink_time = 334 },
{ .throughput = 1 * 1024, .blink_time = 260 },
{ .throughput = 5 * 1024, .blink_time = 220 },
{ .throughput = 10 * 1024, .blink_time = 190 },
{ .throughput = 20 * 1024, .blink_time = 170 },
{ .throughput = 50 * 1024, .blink_time = 150 },
{ .throughput = 70 * 1024, .blink_time = 130 },
{ .throughput = 100 * 1024, .blink_time = 110 },
{ .throughput = 200 * 1024, .blink_time = 80 },
{ .throughput = 300 * 1024, .blink_time = 50 },
};

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

if (!dev->led_cdev.brightness_set && !dev->led_cdev.blink_set)
return 0;

snprintf(dev->led_name, sizeof(dev->led_name),
"mt76-%s", wiphy_name(hw->wiphy));

dev->led_cdev.name = dev->led_name;
dev->led_cdev.default_trigger =
ieee80211_create_tpt_led_trigger(hw,
IEEE80211_TPT_LEDTRIG_FL_RADIO,
mt76_tpt_blink,
ARRAY_SIZE(mt76_tpt_blink));

if (np) {
if (!of_property_read_u32(np, "led-sources", &led_pin))
dev->led_pin = led_pin;
dev->led_al = of_property_read_bool(np, "led-active-low");
}

return devm_led_classdev_register(dev->dev, &dev->led_cdev);
}

static int
mt76_init_sband(struct mt76_dev *dev, struct mt76_sband *msband,
const struct ieee80211_channel *chan, int n_chan,
Expand Down Expand Up @@ -252,6 +293,10 @@ int mt76_register_device(struct mt76_dev *dev, bool vht,
mt76_check_sband(dev, NL80211_BAND_2GHZ);
mt76_check_sband(dev, NL80211_BAND_5GHZ);

ret = mt76_led_init(dev);
if (ret)
return ret;

return ieee80211_register_hw(hw);
}
EXPORT_SYMBOL_GPL(mt76_register_device);
Expand Down
6 changes: 6 additions & 0 deletions mt76.h
Expand Up @@ -21,6 +21,7 @@
#include <linux/io.h>
#include <linux/spinlock.h>
#include <linux/skbuff.h>
#include <linux/leds.h>
#include <net/mac80211.h>
#include "util.h"

Expand Down Expand Up @@ -222,6 +223,11 @@ struct mt76_dev {
struct mt76_hw_cap cap;

u32 debugfs_reg;

struct led_classdev led_cdev;
char led_name[32];
bool led_al;
u8 led_pin;
};

enum mt76_phy_type {
Expand Down

0 comments on commit c9bdcd8

Please sign in to comment.