maru_brightness : Implemented the missing functionality. 94/17594/1
authorjinhyung.jo <jinhyung.jo@samsung.com>
Wed, 26 Feb 2014 07:31:00 +0000 (16:31 +0900)
committerjinhyung.jo <jinhyung.jo@samsung.com>
Fri, 7 Mar 2014 04:18:51 +0000 (13:18 +0900)
If the HBM turns off, restores previous level.

Change-Id: I43990612d2f63ef6d877d1c9fc9dce8158b3d2d6
Signed-off-by: Jinhyung Jo <jinhyung.jo@samsung.com>
drivers/maru/maru_bl.c

index 2fbbdc8c17e29948493ee0304e68cc731d07b165..d5972cc32ab411a575a78536043af9f0a7d859d4 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * MARU Virtual Backlight Driver
  *
- * Copyright (c) 2011 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (c) 2011 - 2014 Samsung Electronics Co., Ltd. All rights reserved.
  *
  * Contact:
  *  Jinhyung Jo <jinhyung.jo@samsung.com>
@@ -61,6 +61,7 @@ MODULE_DEVICE_TABLE(pci, marubl_pci_table);
 struct marubl {
        struct backlight_device         *bl_dev;
        struct lcd_device               *lcd_dev;
+       unsigned int                    prev_brightness;
        unsigned int                    brightness;
        resource_size_t                 reg_start, reg_size;
        /* memory mapped registers */
@@ -98,6 +99,10 @@ static int marubl_send_intensity(struct backlight_device *bd)
                intensity = 0;
                off = 1;
        }
+       if (marubl_device->hbm_on && !off && intensity != MAX_BRIGHTNESS) {
+               marubl_device->hbm_on = 0;
+               printk(KERN_INFO "HBM is turned off because brightness reduced.\n");
+       }
 
        writel(intensity, marubl_device->marubl_mmreg);
        writel(off, marubl_device->marubl_mmreg + 0x04);
@@ -155,16 +160,30 @@ static ssize_t hbm_store_status(struct device *dev,
                return -EINVAL;
        }
 
+       /* If the same as the previous state, ignore it */
+       if (ret == marubl_device->hbm_on)
+               return count;
+
        if (ret) {
+               /* Save previous level, set to MAX level */
                mutex_lock(&marubl_device->bl_dev->ops_lock);
+               marubl_device->prev_brightness =
+                               marubl_device->bl_dev->props.brightness;
                marubl_device->bl_dev->props.brightness = MAX_BRIGHTNESS;
                marubl_send_intensity(marubl_device->bl_dev);
                mutex_unlock(&marubl_device->bl_dev->ops_lock);
+       } else {
+               /* Restore previous level */
+               mutex_lock(&marubl_device->bl_dev->ops_lock);
+               marubl_device->bl_dev->props.brightness =
+                                               marubl_device->prev_brightness;
+               marubl_send_intensity(marubl_device->bl_dev);
+               mutex_unlock(&marubl_device->bl_dev->ops_lock);
        }
        marubl_device->hbm_on = ret;
        printk(KERN_INFO "[%s] hbm = %d\n", __func__, ret);
 
-       return ret;
+       return count;
 }
 
 static struct device_attribute hbm_device_attr =