leds: regulator: Remove work queue

Now the core implements the work queue, remove it from the drivers,
and switch to using brightness_set_blocking op.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Acked-by: Antonio Ospite <ao2@ao2.it>
Signed-off-by: Jacek Anaszewski <j.anaszewski@samsung.com>
This commit is contained in:
Andrew Lunn 2015-08-20 12:55:39 +02:00 committed by Jacek Anaszewski
parent 4330f2f26e
commit 77e8503638

View File

@ -14,7 +14,6 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/workqueue.h>
#include <linux/leds.h> #include <linux/leds.h>
#include <linux/leds-regulator.h> #include <linux/leds-regulator.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
@ -25,10 +24,8 @@
struct regulator_led { struct regulator_led {
struct led_classdev cdev; struct led_classdev cdev;
enum led_brightness value;
int enabled; int enabled;
struct mutex mutex; struct mutex mutex;
struct work_struct work;
struct regulator *vcc; struct regulator *vcc;
}; };
@ -94,22 +91,24 @@ static void regulator_led_disable(struct regulator_led *led)
led->enabled = 0; led->enabled = 0;
} }
static void regulator_led_set_value(struct regulator_led *led) static int regulator_led_brightness_set(struct led_classdev *led_cdev,
enum led_brightness value)
{ {
struct regulator_led *led = to_regulator_led(led_cdev);
int voltage; int voltage;
int ret; int ret = 0;
mutex_lock(&led->mutex); mutex_lock(&led->mutex);
if (led->value == LED_OFF) { if (value == LED_OFF) {
regulator_led_disable(led); regulator_led_disable(led);
goto out; goto out;
} }
if (led->cdev.max_brightness > 1) { if (led->cdev.max_brightness > 1) {
voltage = led_regulator_get_voltage(led->vcc, led->value); voltage = led_regulator_get_voltage(led->vcc, value);
dev_dbg(led->cdev.dev, "brightness: %d voltage: %d\n", dev_dbg(led->cdev.dev, "brightness: %d voltage: %d\n",
led->value, voltage); value, voltage);
ret = regulator_set_voltage(led->vcc, voltage, voltage); ret = regulator_set_voltage(led->vcc, voltage, voltage);
if (ret != 0) if (ret != 0)
@ -121,23 +120,7 @@ static void regulator_led_set_value(struct regulator_led *led)
out: out:
mutex_unlock(&led->mutex); mutex_unlock(&led->mutex);
} return ret;
static void led_work(struct work_struct *work)
{
struct regulator_led *led;
led = container_of(work, struct regulator_led, work);
regulator_led_set_value(led);
}
static void regulator_led_brightness_set(struct led_classdev *led_cdev,
enum led_brightness value)
{
struct regulator_led *led = to_regulator_led(led_cdev);
led->value = value;
schedule_work(&led->work);
} }
static int regulator_led_probe(struct platform_device *pdev) static int regulator_led_probe(struct platform_device *pdev)
@ -169,9 +152,8 @@ static int regulator_led_probe(struct platform_device *pdev)
pdata->brightness); pdata->brightness);
return -EINVAL; return -EINVAL;
} }
led->value = pdata->brightness;
led->cdev.brightness_set = regulator_led_brightness_set; led->cdev.brightness_set_blocking = regulator_led_brightness_set;
led->cdev.name = pdata->name; led->cdev.name = pdata->name;
led->cdev.flags |= LED_CORE_SUSPENDRESUME; led->cdev.flags |= LED_CORE_SUSPENDRESUME;
led->vcc = vcc; led->vcc = vcc;
@ -181,21 +163,18 @@ static int regulator_led_probe(struct platform_device *pdev)
led->enabled = 1; led->enabled = 1;
mutex_init(&led->mutex); mutex_init(&led->mutex);
INIT_WORK(&led->work, led_work);
platform_set_drvdata(pdev, led); platform_set_drvdata(pdev, led);
ret = led_classdev_register(&pdev->dev, &led->cdev); ret = led_classdev_register(&pdev->dev, &led->cdev);
if (ret < 0) { if (ret < 0)
cancel_work_sync(&led->work);
return ret; return ret;
}
/* to expose the default value to userspace */ /* to expose the default value to userspace */
led->cdev.brightness = led->value; led->cdev.brightness = pdata->brightness;
/* Set the default led status */ /* Set the default led status */
regulator_led_set_value(led); regulator_led_brightness_set(&led->cdev, led->cdev.brightness);
return 0; return 0;
} }
@ -205,7 +184,6 @@ static int regulator_led_remove(struct platform_device *pdev)
struct regulator_led *led = platform_get_drvdata(pdev); struct regulator_led *led = platform_get_drvdata(pdev);
led_classdev_unregister(&led->cdev); led_classdev_unregister(&led->cdev);
cancel_work_sync(&led->work);
regulator_led_disable(led); regulator_led_disable(led);
return 0; return 0;
} }