aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAxel Lin <axel.lin@gmail.com>2012-07-24 02:29:47 -0400
committerBryan Wu <bryan.wu@canonical.com>2012-07-24 03:48:47 -0400
commiteb18618b8018bffad6e62f1bc40e4e0c7ee2fa19 (patch)
tree724aafc2a5a3a8766a4e468714c2479b1fed10fb
parent5ecf6e40bbb8649b8418c8038a2af1faefbc56e4 (diff)
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: Axel Lin <axel.lin@gmail.com> Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
-rw-r--r--drivers/leds/leds-max8997.c60
1 files changed, 13 insertions, 47 deletions
diff --git a/drivers/leds/leds-max8997.c b/drivers/leds/leds-max8997.c
index bf86d5483f43..569e36de37df 100644
--- a/drivers/leds/leds-max8997.c
+++ b/drivers/leds/leds-max8997.c
@@ -49,71 +49,37 @@ struct max8997_led {
49 struct mutex mutex; 49 struct mutex mutex;
50}; 50};
51 51
52static void max8997_led_clear_mode(struct max8997_led *led,
53 enum max8997_led_mode mode)
54{
55 struct i2c_client *client = led->iodev->i2c;
56 u8 val = 0, mask = 0;
57 int ret;
58
59 switch (mode) {
60 case MAX8997_FLASH_MODE:
61 mask = led->id ?
62 MAX8997_LED1_FLASH_MASK : MAX8997_LED0_FLASH_MASK;
63 break;
64 case MAX8997_MOVIE_MODE:
65 mask = led->id ?
66 MAX8997_LED1_MOVIE_MASK : MAX8997_LED0_MOVIE_MASK;
67 break;
68 case MAX8997_FLASH_PIN_CONTROL_MODE:
69 mask = led->id ?
70 MAX8997_LED1_FLASH_PIN_MASK : MAX8997_LED0_FLASH_PIN_MASK;
71 break;
72 case MAX8997_MOVIE_PIN_CONTROL_MODE:
73 mask = led->id ?
74 MAX8997_LED1_MOVIE_PIN_MASK : MAX8997_LED0_MOVIE_PIN_MASK;
75 break;
76 default:
77 break;
78 }
79
80 if (mask) {
81 ret = max8997_update_reg(client,
82 MAX8997_REG_LEN_CNTL, val, mask);
83 if (ret)
84 dev_err(led->iodev->dev,
85 "failed to update register(%d)\n", ret);
86 }
87}
88
89static void max8997_led_set_mode(struct max8997_led *led, 52static void max8997_led_set_mode(struct max8997_led *led,
90 enum max8997_led_mode mode) 53 enum max8997_led_mode mode)
91{ 54{
92 int ret; 55 int ret;
93 struct i2c_client *client = led->iodev->i2c; 56 struct i2c_client *client = led->iodev->i2c;
94 u8 mask = 0; 57 u8 mask = 0, val;
95
96 /* First, clear the previous mode */
97 max8997_led_clear_mode(led, led->led_mode);
98 58
99 switch (mode) { 59 switch (mode) {
100 case MAX8997_FLASH_MODE: 60 case MAX8997_FLASH_MODE:
101 mask = led->id ? 61 mask = MAX8997_LED1_FLASH_MASK | MAX8997_LED0_FLASH_MASK;
62 val = led->id ?
102 MAX8997_LED1_FLASH_MASK : MAX8997_LED0_FLASH_MASK; 63 MAX8997_LED1_FLASH_MASK : MAX8997_LED0_FLASH_MASK;
103 led->cdev.max_brightness = MAX8997_LED_FLASH_MAX_BRIGHTNESS; 64 led->cdev.max_brightness = MAX8997_LED_FLASH_MAX_BRIGHTNESS;
104 break; 65 break;
105 case MAX8997_MOVIE_MODE: 66 case MAX8997_MOVIE_MODE:
106 mask = led->id ? 67 mask = MAX8997_LED1_MOVIE_MASK | MAX8997_LED0_MOVIE_MASK;
68 val = led->id ?
107 MAX8997_LED1_MOVIE_MASK : MAX8997_LED0_MOVIE_MASK; 69 MAX8997_LED1_MOVIE_MASK : MAX8997_LED0_MOVIE_MASK;
108 led->cdev.max_brightness = MAX8997_LED_MOVIE_MAX_BRIGHTNESS; 70 led->cdev.max_brightness = MAX8997_LED_MOVIE_MAX_BRIGHTNESS;
109 break; 71 break;
110 case MAX8997_FLASH_PIN_CONTROL_MODE: 72 case MAX8997_FLASH_PIN_CONTROL_MODE:
111 mask = led->id ? 73 mask = MAX8997_LED1_FLASH_PIN_MASK |
74 MAX8997_LED0_FLASH_PIN_MASK;
75 val = led->id ?
112 MAX8997_LED1_FLASH_PIN_MASK : MAX8997_LED0_FLASH_PIN_MASK; 76 MAX8997_LED1_FLASH_PIN_MASK : MAX8997_LED0_FLASH_PIN_MASK;
113 led->cdev.max_brightness = MAX8997_LED_FLASH_MAX_BRIGHTNESS; 77 led->cdev.max_brightness = MAX8997_LED_FLASH_MAX_BRIGHTNESS;
114 break; 78 break;
115 case MAX8997_MOVIE_PIN_CONTROL_MODE: 79 case MAX8997_MOVIE_PIN_CONTROL_MODE:
116 mask = led->id ? 80 mask = MAX8997_LED1_MOVIE_PIN_MASK |
81 MAX8997_LED0_MOVIE_PIN_MASK;
82 val = led->id ?
117 MAX8997_LED1_MOVIE_PIN_MASK : MAX8997_LED0_MOVIE_PIN_MASK; 83 MAX8997_LED1_MOVIE_PIN_MASK : MAX8997_LED0_MOVIE_PIN_MASK;
118 led->cdev.max_brightness = MAX8997_LED_MOVIE_MAX_BRIGHTNESS; 84 led->cdev.max_brightness = MAX8997_LED_MOVIE_MAX_BRIGHTNESS;
119 break; 85 break;
@@ -123,8 +89,8 @@ static void max8997_led_set_mode(struct max8997_led *led,
123 } 89 }
124 90
125 if (mask) { 91 if (mask) {
126 ret = max8997_update_reg(client, 92 ret = max8997_update_reg(client, MAX8997_REG_LEN_CNTL, val,
127 MAX8997_REG_LEN_CNTL, mask, mask); 93 mask);
128 if (ret) 94 if (ret)
129 dev_err(led->iodev->dev, 95 dev_err(led->iodev->dev,
130 "failed to update register(%d)\n", ret); 96 "failed to update register(%d)\n", ret);