add max limit and brightness updata mode in rk29 bl
authorxxx <xxx@rock-chips.com>
Tue, 29 Jan 2013 09:37:12 +0000 (17:37 +0800)
committerxxx <xxx@rock-chips.com>
Tue, 29 Jan 2013 09:37:12 +0000 (17:37 +0800)
arch/arm/mach-rk30/board-rk3168-tb.c
arch/arm/plat-rk/include/plat/board.h
drivers/video/backlight/rk29_backlight.c

index 396b1e4037ebe0a3f9ab875e6c18d98dc5fbbf70..42c7046cc415e29b6ed4b24dc6067b1c3c477d14 100755 (executable)
@@ -196,6 +196,9 @@ static int rk29_backlight_pwm_resume(void)
 
 static struct rk29_bl_info rk29_bl_info = {
        .pwm_id = PWM_ID,
+       .min_brightness=20,
+       .max_brightness=255,
+       .brightness_mode =1,
        .bl_ref = PWM_EFFECT_VALUE,
        .io_init = rk29_backlight_io_init,
        .io_deinit = rk29_backlight_io_deinit,
index 31abdb4a76793fb511001a2f1d5057352dd45fe9..520ff55ef807179ddbef2e598c18c2398271817a 100755 (executable)
@@ -64,6 +64,8 @@ struct rk29_bl_info {
        int (*pwm_suspend)(void);
        int (*pwm_resume)(void);
        int min_brightness;     /* 0 ~ 255 */
+       int max_brightness;     /* 0 ~ 255 */
+       int brightness_mode;
        unsigned int delay_ms;  /* in milliseconds */
        int pre_div;
 };
index 9a8fedf254d1f7ad0301fc240ab05258623cf53d..67cecf3dba4404338e09260ec8421a93375f791a 100755 (executable)
@@ -30,7 +30,8 @@
 
 #define PWM_DIV              PWM_DIV2
 #define PWM_APB_PRE_DIV      1000
-#define BL_STEP              255
+#define BL_STEP              (255)
+#define MAX_BRIGHTNESS_CORRECT (50)
 
 /*
  * Debug
@@ -84,6 +85,64 @@ static DEVICE_ATTR(rk29backlight, 0660, backlight_read, backlight_write);
 
 static DEFINE_MUTEX(backlight_mutex);
 
+static inline void rk29_bl_min_brightness_check(struct rk29_bl_info *rk29_bl_info)
+{
+
+       if (rk29_bl_info->min_brightness < 0 || rk29_bl_info->min_brightness > BL_STEP)
+               rk29_bl_info->min_brightness = MAX_BRIGHTNESS_CORRECT;
+
+
+}      
+static inline void rk29_bl_max_brightness_check(struct rk29_bl_info *rk29_bl_info)
+{
+       if (rk29_bl_info->max_brightness <= 0 || rk29_bl_info->max_brightness > BL_STEP)
+               rk29_bl_info->max_brightness = BL_STEP;
+}      
+
+
+
+int rk29_bl_val_scalor_line(struct rk29_bl_info *rk29_bl_info,int brightness)
+{
+       //rk29_bl_min_brightness_check(rk29_bl_info);
+       //rk29_bl_max_brightness_check(rk29_bl_info);
+       if(rk29_bl_info->max_brightness<rk29_bl_info->min_brightness)
+               rk29_bl_info->max_brightness=rk29_bl_info->min_brightness;
+
+       if(brightness>rk29_bl_info->max_brightness)
+               brightness=rk29_bl_info->max_brightness;
+       else if(brightness<rk29_bl_info->min_brightness)
+               brightness=rk29_bl_info->min_brightness;
+       #if 0
+               brightness = brightness*(rk29_bl_info->max_brightness - rk29_bl_info->min_brightness);
+               brightness = (brightness/255) + rk29_bl_info->min_brightness;
+       #endif
+       return brightness;
+}
+int rk29_bl_val_scalor_conic(struct rk29_bl_info *rk29_bl_info,int brightness)
+{
+       
+       //rk29_bl_min_brightness_check(rk29_bl_info);
+       //rk29_bl_max_brightness_check(rk29_bl_info);
+       
+       if(rk29_bl_info->max_brightness<rk29_bl_info->min_brightness)
+               rk29_bl_info->max_brightness=rk29_bl_info->min_brightness;
+       #if 0
+               brightness = (brightness*brightness)*(rk29_bl_info->max_brightness - rk29_bl_info->min_brightness);
+               brightness = (brightness/(BL_STEP*BL_STEP)) + rk29_bl_info->min_brightness;
+       #else
+               if(brightness<rk29_bl_info->min_brightness)
+                       brightness=rk29_bl_info->min_brightness;
+               brightness = (brightness-rk29_bl_info->min_brightness)*(brightness-rk29_bl_info->min_brightness);
+               brightness = (brightness/(rk29_bl_info->max_brightness - rk29_bl_info->min_brightness)) + rk29_bl_info->min_brightness;
+       #endif
+       
+       if(brightness > rk29_bl_info->max_brightness)
+               brightness = rk29_bl_info->max_brightness;
+       if(brightness < rk29_bl_info->min_brightness)   
+               brightness = rk29_bl_info->min_brightness;
+       
+       return brightness;
+}
 static int rk29_bl_update_status(struct backlight_device *bl)
 {
        u32 divh,div_total;
@@ -93,19 +152,18 @@ static int rk29_bl_update_status(struct backlight_device *bl)
        int brightness = 0;
        
        mutex_lock(&backlight_mutex);
-//BL_CORE_DRIVER2 is the flag if backlight is into early_suspend.
+       //BL_CORE_DRIVER2 is the flag if backlight is into early_suspend.
        if (suspend_flag && (bl->props.state & BL_CORE_DRIVER2))
            goto out;
 
        brightness = bl->props.brightness;
-       if(rk29_bl_info->min_brightness){
-           if(brightness){
-               brightness = brightness*(256 - rk29_bl_info->min_brightness);
-               brightness = (brightness>>8) + rk29_bl_info->min_brightness;
-           }
-           if(brightness > 255)
-               brightness = 255;
-       }
+
+       
+       if(!rk29_bl_info->brightness_mode)
+               brightness=rk29_bl_val_scalor_line(rk29_bl_info,brightness);
+       else
+               brightness=rk29_bl_val_scalor_conic(rk29_bl_info,brightness);
+       //printk("%s,req brightness=%d,real is=%d\n",__FUNCTION__,bl->props.brightness,brightness);
 
        if (bl->props.power != FB_BLANK_UNBLANK)
                brightness = 0;
@@ -260,10 +318,23 @@ static int rk29_backlight_probe(struct platform_device *pdev)
 
        if (!rk29_bl_info->delay_ms)
                rk29_bl_info->delay_ms = 100;
-
-       if (rk29_bl_info->min_brightness < 0 || rk29_bl_info->min_brightness > BL_STEP)
-               rk29_bl_info->min_brightness = 52;
-
+       
+       rk29_bl_min_brightness_check(rk29_bl_info);
+       rk29_bl_max_brightness_check(rk29_bl_info);
+       #if 0
+       {
+               int temp,temp_val;
+               rk29_bl_info->max_brightness=180;
+               rk29_bl_info->min_brightness=20;
+               for(temp=0;temp<=255;temp++)
+               {       
+                       temp_val=rk29_bl_val_scalor_conic(rk29_bl_info,temp);
+                       //if(temp_val<=rk29_bl_info->max_brightness)
+                       printk("conic req %d,get %d\n",temp,temp_val);
+               }       
+       }
+       #endif
+       
        if (rk29_bl_info && rk29_bl_info->io_init) {
                rk29_bl_info->io_init();
        }