Commit eb18618b authored by Axel Lin's avatar Axel Lin Committed by Bryan Wu

leds: max8997: Simplify max8997_led_set_mode implementation

It is not necessary to call max8997_update_reg() twice just for updating
MAX8997_REG_LEN_CNTL register. With proper val and mask arguments to
max8997_update_reg() call, this can be done in one max8997_update_reg() call.
And then we can remove max8997_led_clear_mode() function.
Signed-off-by: default avatarAxel Lin <axel.lin@gmail.com>
Signed-off-by: default avatarBryan Wu <bryan.wu@canonical.com>
parent 5ecf6e40
...@@ -49,71 +49,37 @@ struct max8997_led { ...@@ -49,71 +49,37 @@ struct max8997_led {
struct mutex mutex; struct mutex mutex;
}; };
static void max8997_led_clear_mode(struct max8997_led *led,
enum max8997_led_mode mode)
{
struct i2c_client *client = led->iodev->i2c;
u8 val = 0, mask = 0;
int ret;
switch (mode) {
case MAX8997_FLASH_MODE:
mask = led->id ?
MAX8997_LED1_FLASH_MASK : MAX8997_LED0_FLASH_MASK;
break;
case MAX8997_MOVIE_MODE:
mask = led->id ?
MAX8997_LED1_MOVIE_MASK : MAX8997_LED0_MOVIE_MASK;
break;
case MAX8997_FLASH_PIN_CONTROL_MODE:
mask = led->id ?
MAX8997_LED1_FLASH_PIN_MASK : MAX8997_LED0_FLASH_PIN_MASK;
break;
case MAX8997_MOVIE_PIN_CONTROL_MODE:
mask = led->id ?
MAX8997_LED1_MOVIE_PIN_MASK : MAX8997_LED0_MOVIE_PIN_MASK;
break;
default:
break;
}
if (mask) {
ret = max8997_update_reg(client,
MAX8997_REG_LEN_CNTL, val, mask);
if (ret)
dev_err(led->iodev->dev,
"failed to update register(%d)\n", ret);
}
}
static void max8997_led_set_mode(struct max8997_led *led, static void max8997_led_set_mode(struct max8997_led *led,
enum max8997_led_mode mode) enum max8997_led_mode mode)
{ {
int ret; int ret;
struct i2c_client *client = led->iodev->i2c; struct i2c_client *client = led->iodev->i2c;
u8 mask = 0; u8 mask = 0, val;
/* First, clear the previous mode */
max8997_led_clear_mode(led, led->led_mode);
switch (mode) { switch (mode) {
case MAX8997_FLASH_MODE: case MAX8997_FLASH_MODE:
mask = led->id ? mask = MAX8997_LED1_FLASH_MASK | MAX8997_LED0_FLASH_MASK;
val = led->id ?
MAX8997_LED1_FLASH_MASK : MAX8997_LED0_FLASH_MASK; MAX8997_LED1_FLASH_MASK : MAX8997_LED0_FLASH_MASK;
led->cdev.max_brightness = MAX8997_LED_FLASH_MAX_BRIGHTNESS; led->cdev.max_brightness = MAX8997_LED_FLASH_MAX_BRIGHTNESS;
break; break;
case MAX8997_MOVIE_MODE: case MAX8997_MOVIE_MODE:
mask = led->id ? mask = MAX8997_LED1_MOVIE_MASK | MAX8997_LED0_MOVIE_MASK;
val = led->id ?
MAX8997_LED1_MOVIE_MASK : MAX8997_LED0_MOVIE_MASK; MAX8997_LED1_MOVIE_MASK : MAX8997_LED0_MOVIE_MASK;
led->cdev.max_brightness = MAX8997_LED_MOVIE_MAX_BRIGHTNESS; led->cdev.max_brightness = MAX8997_LED_MOVIE_MAX_BRIGHTNESS;
break; break;
case MAX8997_FLASH_PIN_CONTROL_MODE: case MAX8997_FLASH_PIN_CONTROL_MODE:
mask = led->id ? mask = MAX8997_LED1_FLASH_PIN_MASK |
MAX8997_LED0_FLASH_PIN_MASK;
val = led->id ?
MAX8997_LED1_FLASH_PIN_MASK : MAX8997_LED0_FLASH_PIN_MASK; MAX8997_LED1_FLASH_PIN_MASK : MAX8997_LED0_FLASH_PIN_MASK;
led->cdev.max_brightness = MAX8997_LED_FLASH_MAX_BRIGHTNESS; led->cdev.max_brightness = MAX8997_LED_FLASH_MAX_BRIGHTNESS;
break; break;
case MAX8997_MOVIE_PIN_CONTROL_MODE: case MAX8997_MOVIE_PIN_CONTROL_MODE:
mask = led->id ? mask = MAX8997_LED1_MOVIE_PIN_MASK |
MAX8997_LED0_MOVIE_PIN_MASK;
val = led->id ?
MAX8997_LED1_MOVIE_PIN_MASK : MAX8997_LED0_MOVIE_PIN_MASK; MAX8997_LED1_MOVIE_PIN_MASK : MAX8997_LED0_MOVIE_PIN_MASK;
led->cdev.max_brightness = MAX8997_LED_MOVIE_MAX_BRIGHTNESS; led->cdev.max_brightness = MAX8997_LED_MOVIE_MAX_BRIGHTNESS;
break; break;
...@@ -123,8 +89,8 @@ static void max8997_led_set_mode(struct max8997_led *led, ...@@ -123,8 +89,8 @@ static void max8997_led_set_mode(struct max8997_led *led,
} }
if (mask) { if (mask) {
ret = max8997_update_reg(client, ret = max8997_update_reg(client, MAX8997_REG_LEN_CNTL, val,
MAX8997_REG_LEN_CNTL, mask, mask); mask);
if (ret) if (ret)
dev_err(led->iodev->dev, dev_err(led->iodev->dev,
"failed to update register(%d)\n", ret); "failed to update register(%d)\n", ret);
......
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