Commit 83cd2030 authored by Dmitry Torokhov's avatar Dmitry Torokhov

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: default avatarSven Van Asbroeck <TheSven73@gmail.com>
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent a342083a
...@@ -58,10 +58,9 @@ static unsigned char qt2160_key2code[] = { ...@@ -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 { ...@@ -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); ...@@ -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_led *led = container_of(cdev, struct qt2160_led, cdev);
struct qt2160_data *qt2160 = led->qt2160; struct qt2160_data *qt2160 = led->qt2160;
struct i2c_client *client = qt2160->client; struct i2c_client *client = qt2160->client;
int value = led->new_brightness;
u32 drive, pwmen; u32 drive, pwmen;
mutex_lock(&qt2160->led_lock); if (value != led->brightness) {
drive = qt2160_read(client, QT2160_CMD_DRIVE_X);
drive = qt2160_read(client, QT2160_CMD_DRIVE_X); pwmen = qt2160_read(client, QT2160_CMD_PWMEN_X);
pwmen = qt2160_read(client, QT2160_CMD_PWMEN_X); if (value != LED_OFF) {
if (value != LED_OFF) { drive |= BIT(led->id);
drive |= (1 << led->id); pwmen |= BIT(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);
/* } else {
* Changing this register will change the brightness drive &= ~BIT(led->id);
* of every LED in the qt2160. It's a HW limitation. pwmen &= ~BIT(led->id);
*/ }
if (value != LED_OFF) qt2160_write(client, QT2160_CMD_DRIVE_X, drive);
qt2160_write(client, QT2160_CMD_PWM_DUTY, value); qt2160_write(client, QT2160_CMD_PWMEN_X, pwmen);
mutex_unlock(&qt2160->led_lock); /*
} * 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);
static void qt2160_led_set(struct led_classdev *cdev, led->brightness = value;
enum led_brightness value) }
{
struct qt2160_led *led = container_of(cdev, struct qt2160_led, cdev);
led->new_brightness = value; return 0;
schedule_work(&led->work);
} }
#endif /* CONFIG_LEDS_CLASS */ #endif /* CONFIG_LEDS_CLASS */
...@@ -293,20 +284,16 @@ static int qt2160_register_leds(struct qt2160_data *qt2160) ...@@ -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) ...@@ -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
......
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