Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 149870
b: refs/heads/master
c: dce0725
h: refs/heads/master
v: v3
  • Loading branch information
Christian Lamparter authored and John W. Linville committed Apr 22, 2009
1 parent 0891bfc commit 8c6dae3
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 24 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: cf3a9579f61c643c15c172da0baf5429578b0ba3
refs/heads/master: dce072580e095d1fb7be59a1be30dc0e8307821b
9 changes: 5 additions & 4 deletions trunk/drivers/net/wireless/p54/p54.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ struct p54_led_dev {
struct led_classdev led_dev;
char name[P54_LED_MAX_NAME_LEN + 1];

unsigned int toggled;
unsigned int index;
unsigned int registered;
};
Expand Down Expand Up @@ -186,10 +187,10 @@ struct p54_common {
u8 rx_keycache_size;

/* LED management */
#ifdef CONFIG_P54_LEDS
struct p54_led_dev assoc_led;
struct p54_led_dev tx_led;
#endif /* CONFIG_P54_LEDS */
#ifdef CONFIG_MAC80211_LEDS
struct p54_led_dev leds[4];
struct delayed_work led_work;
#endif /* CONFIG_MAC80211_LEDS */
u16 softled_state; /* bit field of glowing LEDs */

/* statistics */
Expand Down
84 changes: 65 additions & 19 deletions trunk/drivers/net/wireless/p54/p54common.c
Original file line number Diff line number Diff line change
Expand Up @@ -2088,6 +2088,9 @@ static void p54_stop(struct ieee80211_hw *dev)
priv->softled_state = 0;
p54_set_leds(dev);

#ifdef CONFIG_P54_LEDS
cancel_delayed_work_sync(&priv->led_work);
#endif /* CONFIG_P54_LEDS */
cancel_delayed_work_sync(&priv->work);
if (priv->cached_beacon)
p54_tx_cancel(dev, priv->cached_beacon);
Expand Down Expand Up @@ -2421,35 +2424,67 @@ static int p54_set_key(struct ieee80211_hw *dev, enum set_key_cmd cmd,
}

#ifdef CONFIG_P54_LEDS
static void p54_update_leds(struct work_struct *work)
{
struct p54_common *priv = container_of(work, struct p54_common,
led_work.work);
int err, i, tmp, blink_delay = 400;
bool rerun = false;

/* Don't toggle the LED, when the device is down. */
if (priv->mode == NL80211_IFTYPE_UNSPECIFIED)
return ;

for (i = 0; i < ARRAY_SIZE(priv->leds); i++)
if (priv->leds[i].toggled) {
priv->softled_state |= BIT(i);

tmp = 70 + 200 / (priv->leds[i].toggled);
if (tmp < blink_delay)
blink_delay = tmp;

if (priv->leds[i].led_dev.brightness == LED_OFF)
rerun = true;

priv->leds[i].toggled =
!!priv->leds[i].led_dev.brightness;
} else
priv->softled_state &= ~BIT(i);

err = p54_set_leds(priv->hw);
if (err && net_ratelimit())
printk(KERN_ERR "%s: failed to update LEDs.\n",
wiphy_name(priv->hw->wiphy));

if (rerun)
queue_delayed_work(priv->hw->workqueue, &priv->led_work,
msecs_to_jiffies(blink_delay));
}

static void p54_led_brightness_set(struct led_classdev *led_dev,
enum led_brightness brightness)
{
struct p54_led_dev *led = container_of(led_dev, struct p54_led_dev,
led_dev);
struct ieee80211_hw *dev = led->hw_dev;
struct p54_common *priv = dev->priv;
int err;

/* Don't toggle the LED, when the device is down. */
if (priv->mode == NL80211_IFTYPE_UNSPECIFIED)
return ;

if (brightness != LED_OFF)
priv->softled_state |= BIT(led->index);
else
priv->softled_state &= ~BIT(led->index);

err = p54_set_leds(dev);
if (err && net_ratelimit())
printk(KERN_ERR "%s: failed to update %s LED.\n",
wiphy_name(dev->wiphy), led_dev->name);
if (brightness) {
led->toggled++;
queue_delayed_work(priv->hw->workqueue, &priv->led_work,
HZ/10);
}
}

static int p54_register_led(struct ieee80211_hw *dev,
struct p54_led_dev *led,
unsigned int led_index,
char *name, char *trigger)
{
struct p54_common *priv = dev->priv;
struct p54_led_dev *led = &priv->leds[led_index];
int err;

if (led->registered)
Expand Down Expand Up @@ -2482,31 +2517,42 @@ static int p54_init_leds(struct ieee80211_hw *dev)
* TODO:
* Figure out if the EEPROM contains some hints about the number
* of available/programmable LEDs of the device.
* But for now, we can assume that we have two programmable LEDs.
*/

err = p54_register_led(dev, &priv->assoc_led, 0, "assoc",
INIT_DELAYED_WORK(&priv->led_work, p54_update_leds);

err = p54_register_led(dev, 0, "assoc",
ieee80211_get_assoc_led_name(dev));
if (err)
return err;

err = p54_register_led(dev, &priv->tx_led, 1, "tx",
err = p54_register_led(dev, 1, "tx",
ieee80211_get_tx_led_name(dev));
if (err)
return err;

err = p54_register_led(dev, 2, "rx",
ieee80211_get_rx_led_name(dev));
if (err)
return err;

err = p54_register_led(dev, 3, "radio",
ieee80211_get_radio_led_name(dev));
if (err)
return err;

err = p54_set_leds(dev);
return err;
}

static void p54_unregister_leds(struct ieee80211_hw *dev)
{
struct p54_common *priv = dev->priv;
int i;

if (priv->tx_led.registered)
led_classdev_unregister(&priv->tx_led.led_dev);
if (priv->assoc_led.registered)
led_classdev_unregister(&priv->assoc_led.led_dev);
for (i = 0; i < ARRAY_SIZE(priv->leds); i++)
if (priv->leds[i].registered)
led_classdev_unregister(&priv->leds[i].led_dev);
}
#endif /* CONFIG_P54_LEDS */

Expand Down

0 comments on commit 8c6dae3

Please sign in to comment.