Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 62617
b: refs/heads/master
c: 0085227
h: refs/heads/master
i:
  62615: b483db0
v: v3
  • Loading branch information
David Brownell authored and Richard Purdie committed Jul 16, 2007
1 parent 30585e9 commit 42d5b0d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 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: 22e03f3b58dfcca30f0c8de185022132459638d1
refs/heads/master: 00852279af5ad26956bc7f4d0e86fdb40192e542
27 changes: 26 additions & 1 deletion trunk/drivers/leds/leds-gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,26 @@
#include <linux/init.h>
#include <linux/platform_device.h>
#include <linux/leds.h>
#include <linux/workqueue.h>

#include <asm/gpio.h>

struct gpio_led_data {
struct led_classdev cdev;
unsigned gpio;
struct work_struct work;
u8 new_level;
u8 can_sleep;
u8 active_low;
};

static void gpio_led_work(struct work_struct *work)
{
struct gpio_led_data *led_dat =
container_of(work, struct gpio_led_data, work);

gpio_set_value_cansleep(led_dat->gpio, led_dat->new_level);
}

static void gpio_led_set(struct led_classdev *led_cdev,
enum led_brightness value)
Expand All @@ -37,7 +49,15 @@ static void gpio_led_set(struct led_classdev *led_cdev,
if (led_dat->active_low)
level = !level;

gpio_set_value(led_dat->gpio, level);
/* setting GPIOs with I2C/etc requires a preemptible task context */
if (led_dat->can_sleep) {
if (preempt_count()) {
led_dat->new_level = level;
schedule_work(&led_dat->work);
} else
gpio_set_value_cansleep(led_dat->gpio, level);
} else
gpio_set_value(led_dat->gpio, level);
}

static int __init gpio_led_probe(struct platform_device *pdev)
Expand All @@ -62,6 +82,7 @@ static int __init gpio_led_probe(struct platform_device *pdev)
led_dat->cdev.name = cur_led->name;
led_dat->cdev.default_trigger = cur_led->default_trigger;
led_dat->gpio = cur_led->gpio;
led_dat->can_sleep = gpio_cansleep(cur_led->gpio);
led_dat->active_low = cur_led->active_low;
led_dat->cdev.brightness_set = gpio_led_set;
led_dat->cdev.brightness = cur_led->active_low ? LED_FULL : LED_OFF;
Expand All @@ -77,6 +98,8 @@ static int __init gpio_led_probe(struct platform_device *pdev)
gpio_free(led_dat->gpio);
goto err;
}

INIT_WORK(&led_dat->work, gpio_led_work);
}

platform_set_drvdata(pdev, leds_data);
Expand All @@ -90,6 +113,8 @@ static int __init gpio_led_probe(struct platform_device *pdev)
gpio_free(leds_data[i].gpio);
}
}

flush_scheduled_work();
kfree(leds_data);

return ret;
Expand Down

0 comments on commit 42d5b0d

Please sign in to comment.