Commit a6e4679a authored by Milo(Woogyom) Kim's avatar Milo(Woogyom) Kim Committed by Bryan Wu

leds-lp55xx: use lp55xx_set_brightness()

 lp5521_set_brightness() and lp5523_set_brightness() are replaced with
 common function, lp55xx_set_brightness().
 This function is invoked when the brightness of each LED channel is updated.
 LP5521 and LP5523 have different register address for the brightness control,
 so this work is done by chip specific brightness_work_fn().

 lp5521/5523_led_brightness_work():
 use lp55xx_led and lp55xx_chip data structure.
 use lp55xx write function.
Signed-off-by: default avatarMilo(Woogyom) Kim <milo.kim@ti.com>
Signed-off-by: default avatarBryan Wu <cooloney@gmail.com>
parent 0e202346
...@@ -151,8 +151,6 @@ static inline struct lp5521_chip *led_to_lp5521(struct lp5521_led *led) ...@@ -151,8 +151,6 @@ static inline struct lp5521_chip *led_to_lp5521(struct lp5521_led *led)
leds[led->id]); leds[led->id]);
} }
static void lp5521_led_brightness_work(struct work_struct *work);
static inline int lp5521_write(struct i2c_client *client, u8 reg, u8 value) static inline int lp5521_write(struct i2c_client *client, u8 reg, u8 value)
{ {
return i2c_smbus_write_byte_data(client, reg, value); return i2c_smbus_write_byte_data(client, reg, value);
...@@ -303,24 +301,14 @@ static int lp5521_run_selftest(struct lp5521_chip *chip, char *buf) ...@@ -303,24 +301,14 @@ static int lp5521_run_selftest(struct lp5521_chip *chip, char *buf)
return 0; return 0;
} }
static void lp5521_set_brightness(struct led_classdev *cdev,
enum led_brightness brightness)
{
struct lp5521_led *led = cdev_to_led(cdev);
led->brightness = (u8)brightness;
schedule_work(&led->brightness_work);
}
static void lp5521_led_brightness_work(struct work_struct *work) static void lp5521_led_brightness_work(struct work_struct *work)
{ {
struct lp5521_led *led = container_of(work, struct lp55xx_led *led = container_of(work, struct lp55xx_led,
struct lp5521_led,
brightness_work); brightness_work);
struct lp5521_chip *chip = led_to_lp5521(led); struct lp55xx_chip *chip = led->chip;
struct i2c_client *client = chip->client;
mutex_lock(&chip->lock); mutex_lock(&chip->lock);
lp5521_write(client, LP5521_REG_LED_PWM_BASE + led->chan_nr, lp55xx_write(chip, LP5521_REG_LED_PWM_BASE + led->chan_nr,
led->brightness); led->brightness);
mutex_unlock(&chip->lock); mutex_unlock(&chip->lock);
} }
...@@ -711,6 +699,7 @@ static struct lp55xx_device_config lp5521_cfg = { ...@@ -711,6 +699,7 @@ static struct lp55xx_device_config lp5521_cfg = {
}, },
.max_channel = LP5521_MAX_LEDS, .max_channel = LP5521_MAX_LEDS,
.post_init_device = lp5521_post_init_device, .post_init_device = lp5521_post_init_device,
.brightness_work_fn = lp5521_led_brightness_work,
}; };
static int lp5521_probe(struct i2c_client *client, static int lp5521_probe(struct i2c_client *client,
......
...@@ -163,8 +163,6 @@ static void lp5523_set_mode(struct lp5523_engine *engine, u8 mode); ...@@ -163,8 +163,6 @@ static void lp5523_set_mode(struct lp5523_engine *engine, u8 mode);
static int lp5523_set_engine_mode(struct lp5523_engine *engine, u8 mode); static int lp5523_set_engine_mode(struct lp5523_engine *engine, u8 mode);
static int lp5523_load_program(struct lp5523_engine *engine, const u8 *pattern); static int lp5523_load_program(struct lp5523_engine *engine, const u8 *pattern);
static void lp5523_led_brightness_work(struct work_struct *work);
static int lp5523_write(struct i2c_client *client, u8 reg, u8 value) static int lp5523_write(struct i2c_client *client, u8 reg, u8 value)
{ {
return i2c_smbus_write_byte_data(client, reg, value); return i2c_smbus_write_byte_data(client, reg, value);
...@@ -468,29 +466,15 @@ static ssize_t lp5523_selftest(struct device *dev, ...@@ -468,29 +466,15 @@ static ssize_t lp5523_selftest(struct device *dev,
return pos; return pos;
} }
static void lp5523_set_brightness(struct led_classdev *cdev,
enum led_brightness brightness)
{
struct lp5523_led *led = cdev_to_led(cdev);
led->brightness = (u8)brightness;
schedule_work(&led->brightness_work);
}
static void lp5523_led_brightness_work(struct work_struct *work) static void lp5523_led_brightness_work(struct work_struct *work)
{ {
struct lp5523_led *led = container_of(work, struct lp55xx_led *led = container_of(work, struct lp55xx_led,
struct lp5523_led,
brightness_work); brightness_work);
struct lp5523_chip *chip = led_to_lp5523(led); struct lp55xx_chip *chip = led->chip;
struct i2c_client *client = chip->client;
mutex_lock(&chip->lock); mutex_lock(&chip->lock);
lp55xx_write(chip, LP5523_REG_LED_PWM_BASE + led->chan_nr,
lp5523_write(client, LP5523_REG_LED_PWM_BASE + led->chan_nr,
led->brightness); led->brightness);
mutex_unlock(&chip->lock); mutex_unlock(&chip->lock);
} }
...@@ -795,6 +779,7 @@ static struct lp55xx_device_config lp5523_cfg = { ...@@ -795,6 +779,7 @@ static struct lp55xx_device_config lp5523_cfg = {
}, },
.max_channel = LP5523_MAX_LEDS, .max_channel = LP5523_MAX_LEDS,
.post_init_device = lp5523_post_init_device, .post_init_device = lp5523_post_init_device,
.brightness_work_fn = lp5523_led_brightness_work,
}; };
static int lp5523_probe(struct i2c_client *client, static int lp5523_probe(struct i2c_client *client,
......
...@@ -20,6 +20,11 @@ ...@@ -20,6 +20,11 @@
#include "leds-lp55xx-common.h" #include "leds-lp55xx-common.h"
static struct lp55xx_led *cdev_to_lp55xx_led(struct led_classdev *cdev)
{
return container_of(cdev, struct lp55xx_led, cdev);
}
static void lp55xx_reset_device(struct lp55xx_chip *chip) static void lp55xx_reset_device(struct lp55xx_chip *chip)
{ {
struct lp55xx_device_config *cfg = chip->cfg; struct lp55xx_device_config *cfg = chip->cfg;
...@@ -74,6 +79,10 @@ static struct attribute_group lp55xx_led_attr_group = { ...@@ -74,6 +79,10 @@ static struct attribute_group lp55xx_led_attr_group = {
static void lp55xx_set_brightness(struct led_classdev *cdev, static void lp55xx_set_brightness(struct led_classdev *cdev,
enum led_brightness brightness) enum led_brightness brightness)
{ {
struct lp55xx_led *led = cdev_to_lp55xx_led(cdev);
led->brightness = (u8)brightness;
schedule_work(&led->brightness_work);
} }
static int lp55xx_init_led(struct lp55xx_led *led, static int lp55xx_init_led(struct lp55xx_led *led,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment