Input: qt2160 - switch to using brightness_set_blocking()
Now that LEDs core allows "blocking" flavor of "set brightness" method we can use it and get rid of private work items. Reviewed-by: Sven Van Asbroeck <TheSven73@gmail.com> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
This commit is contained in:
parent
a342083abe
commit
83cd203084
|
@ -58,10 +58,9 @@ static unsigned char qt2160_key2code[] = {
|
||||||
struct qt2160_led {
|
struct qt2160_led {
|
||||||
struct qt2160_data *qt2160;
|
struct qt2160_data *qt2160;
|
||||||
struct led_classdev cdev;
|
struct led_classdev cdev;
|
||||||
struct work_struct work;
|
|
||||||
char name[32];
|
char name[32];
|
||||||
int id;
|
int id;
|
||||||
enum led_brightness new_brightness;
|
enum led_brightness brightness;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -74,7 +73,6 @@ struct qt2160_data {
|
||||||
u16 key_matrix;
|
u16 key_matrix;
|
||||||
#ifdef CONFIG_LEDS_CLASS
|
#ifdef CONFIG_LEDS_CLASS
|
||||||
struct qt2160_led leds[QT2160_NUM_LEDS_X];
|
struct qt2160_led leds[QT2160_NUM_LEDS_X];
|
||||||
struct mutex led_lock;
|
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -83,46 +81,39 @@ static int qt2160_write(struct i2c_client *client, u8 reg, u8 data);
|
||||||
|
|
||||||
#ifdef CONFIG_LEDS_CLASS
|
#ifdef CONFIG_LEDS_CLASS
|
||||||
|
|
||||||
static void qt2160_led_work(struct work_struct *work)
|
static int qt2160_led_set(struct led_classdev *cdev,
|
||||||
{
|
enum led_brightness value)
|
||||||
struct qt2160_led *led = container_of(work, struct qt2160_led, work);
|
|
||||||
struct qt2160_data *qt2160 = led->qt2160;
|
|
||||||
struct i2c_client *client = qt2160->client;
|
|
||||||
int value = led->new_brightness;
|
|
||||||
u32 drive, pwmen;
|
|
||||||
|
|
||||||
mutex_lock(&qt2160->led_lock);
|
|
||||||
|
|
||||||
drive = qt2160_read(client, QT2160_CMD_DRIVE_X);
|
|
||||||
pwmen = qt2160_read(client, QT2160_CMD_PWMEN_X);
|
|
||||||
if (value != LED_OFF) {
|
|
||||||
drive |= (1 << led->id);
|
|
||||||
pwmen |= (1 << led->id);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
drive &= ~(1 << led->id);
|
|
||||||
pwmen &= ~(1 << led->id);
|
|
||||||
}
|
|
||||||
qt2160_write(client, QT2160_CMD_DRIVE_X, drive);
|
|
||||||
qt2160_write(client, QT2160_CMD_PWMEN_X, pwmen);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Changing this register will change the brightness
|
|
||||||
* of every LED in the qt2160. It's a HW limitation.
|
|
||||||
*/
|
|
||||||
if (value != LED_OFF)
|
|
||||||
qt2160_write(client, QT2160_CMD_PWM_DUTY, value);
|
|
||||||
|
|
||||||
mutex_unlock(&qt2160->led_lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void qt2160_led_set(struct led_classdev *cdev,
|
|
||||||
enum led_brightness value)
|
|
||||||
{
|
{
|
||||||
struct qt2160_led *led = container_of(cdev, struct qt2160_led, cdev);
|
struct qt2160_led *led = container_of(cdev, struct qt2160_led, cdev);
|
||||||
|
struct qt2160_data *qt2160 = led->qt2160;
|
||||||
|
struct i2c_client *client = qt2160->client;
|
||||||
|
u32 drive, pwmen;
|
||||||
|
|
||||||
led->new_brightness = value;
|
if (value != led->brightness) {
|
||||||
schedule_work(&led->work);
|
drive = qt2160_read(client, QT2160_CMD_DRIVE_X);
|
||||||
|
pwmen = qt2160_read(client, QT2160_CMD_PWMEN_X);
|
||||||
|
if (value != LED_OFF) {
|
||||||
|
drive |= BIT(led->id);
|
||||||
|
pwmen |= BIT(led->id);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
drive &= ~BIT(led->id);
|
||||||
|
pwmen &= ~BIT(led->id);
|
||||||
|
}
|
||||||
|
qt2160_write(client, QT2160_CMD_DRIVE_X, drive);
|
||||||
|
qt2160_write(client, QT2160_CMD_PWMEN_X, pwmen);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Changing this register will change the brightness
|
||||||
|
* of every LED in the qt2160. It's a HW limitation.
|
||||||
|
*/
|
||||||
|
if (value != LED_OFF)
|
||||||
|
qt2160_write(client, QT2160_CMD_PWM_DUTY, value);
|
||||||
|
|
||||||
|
led->brightness = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CONFIG_LEDS_CLASS */
|
#endif /* CONFIG_LEDS_CLASS */
|
||||||
|
@ -293,20 +284,16 @@ static int qt2160_register_leds(struct qt2160_data *qt2160)
|
||||||
int ret;
|
int ret;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
mutex_init(&qt2160->led_lock);
|
|
||||||
|
|
||||||
for (i = 0; i < QT2160_NUM_LEDS_X; i++) {
|
for (i = 0; i < QT2160_NUM_LEDS_X; i++) {
|
||||||
struct qt2160_led *led = &qt2160->leds[i];
|
struct qt2160_led *led = &qt2160->leds[i];
|
||||||
|
|
||||||
snprintf(led->name, sizeof(led->name), "qt2160:x%d", i);
|
snprintf(led->name, sizeof(led->name), "qt2160:x%d", i);
|
||||||
led->cdev.name = led->name;
|
led->cdev.name = led->name;
|
||||||
led->cdev.brightness_set = qt2160_led_set;
|
led->cdev.brightness_set_blocking = qt2160_led_set;
|
||||||
led->cdev.brightness = LED_OFF;
|
led->cdev.brightness = LED_OFF;
|
||||||
led->id = i;
|
led->id = i;
|
||||||
led->qt2160 = qt2160;
|
led->qt2160 = qt2160;
|
||||||
|
|
||||||
INIT_WORK(&led->work, qt2160_led_work);
|
|
||||||
|
|
||||||
ret = led_classdev_register(&client->dev, &led->cdev);
|
ret = led_classdev_register(&client->dev, &led->cdev);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -324,10 +311,8 @@ static void qt2160_unregister_leds(struct qt2160_data *qt2160)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < QT2160_NUM_LEDS_X; i++) {
|
for (i = 0; i < QT2160_NUM_LEDS_X; i++)
|
||||||
led_classdev_unregister(&qt2160->leds[i].cdev);
|
led_classdev_unregister(&qt2160->leds[i].cdev);
|
||||||
cancel_work_sync(&qt2160->leds[i].work);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
Loading…
Reference in New Issue