leds: lp8550: restore register values on resume
authorJames Wylder <james.wylder@motorola.com>
Sat, 29 Jan 2011 00:50:32 +0000 (18:50 -0600)
committerColin Cross <ccross@android.com>
Sat, 29 Jan 2011 05:10:53 +0000 (21:10 -0800)
In some cases the lp8550 is resetting on resume and
we need to restore the default values of registers a1-a7

Change-Id: I42e20d646c077008eab2a7100a731ece2bf835d8
Signed-off-by: James Wylder <james.wylder@motorola.com>
drivers/leds/leds-lp8550.c

index 8ea437da157473085951a7a683a724ddd529612d..2f4e4f380941c798f9c233a8f82e97a80a9ba8f9 100755 (executable)
@@ -209,6 +209,8 @@ static void lp8550_brightness_write(struct lp8550_data *led_data)
 {
        int error = 0;
        int brightness = led_data->brightness;
+       unsigned i, reg_addr;
+       uint8_t value = 0;
 
        if (lp8550_debug)
                pr_info("%s: setting brightness to %i\n",
@@ -228,11 +230,21 @@ static void lp8550_brightness_write(struct lp8550_data *led_data)
                        if (!IS_ERR_OR_NULL(led_data->regulator))
                                regulator_enable(led_data->regulator);
                        if (lp8550_write_reg(led_data, LP8550_DEVICE_CTRL,
-                               led_data->led_pdata->dev_ctrl_config | 0x01))
+                               led_data->led_pdata->dev_ctrl_config | 0x01)) {
                                pr_err("%s:writing failed while setting brightness:%d\n",
                                        __func__, error);
-                       else
-                               atomic_set(&led_data->enabled, 1);
+                               atomic_set(&led_data->enabled, 0);
+                       }
+
+                       /* restore values a1 to a8 in case they have been reset */
+                       /* a0 will be set below with the brightness */
+                       for (i = 1; i < led_data->led_pdata->eeprom_tbl_sz; i++) {
+                               reg_addr = LP8550_EEPROM_A0 + i;
+                               value = led_data->led_pdata->eeprom_table[i].eeprom_data;
+                               if (lp8550_write_reg(led_data, reg_addr, value))
+                                       pr_err("%s: Register initialization failed\n",
+                                               __func__);
+                       }
                }
 
                if (led_data->led_pdata->dev_ctrl_config ==