2424#include <linux/workqueue.h>
2525#include <linux/backlight.h>
2626#include "tinker_mcu.h"
27+ #include <linux/fb.h>
2728
2829#define BL_DEBUG 0
2930static struct tinker_mcu_data * g_mcu_data ;
3031static int connected = 0 ;
3132static int lcd_bright_level = 0 ;
33+ static struct backlight_device * bl = NULL ;
34+
35+ #define MAX_BRIGHENESS (255)
3236
3337static int is_hex (char num )
3438{
@@ -178,10 +182,40 @@ static int tinker_mcu_bl_get_brightness(struct backlight_device *bd)
178182 return lcd_bright_level ;
179183}
180184
185+ int tinker_mcu_bl_update_status (struct backlight_device * bd )
186+ {
187+ int brightness = bd -> props .brightness ;
188+
189+ if (brightness > MAX_BRIGHENESS )
190+ brightness = MAX_BRIGHENESS ;
191+
192+ if (brightness <= 0 )
193+ brightness = 1 ;
194+
195+ if (bd -> props .power != FB_BLANK_UNBLANK )
196+ brightness = 0 ;
197+
198+ if (bd -> props .state & BL_CORE_SUSPENDED )
199+ brightness = 0 ;
200+
201+ LOG_INFO ("tinker_mcu_bl_update_status brightness=%d power=%d fb_blank=%d state =%d bd->props.brightness=%d\n" , brightness , bd -> props .power , bd -> props .fb_blank , bd -> props .state , bd -> props .brightness );
202+ return tinker_mcu_set_bright (brightness );
203+ }
204+
181205static const struct backlight_ops tinker_mcu_bl_ops = {
182- .get_brightness = tinker_mcu_bl_get_brightness ,
206+ .get_brightness = tinker_mcu_bl_get_brightness ,//actual_brightness_show
207+ .update_status = tinker_mcu_bl_update_status ,
208+ .options = BL_CORE_SUSPENDRESUME ,
183209};
184210
211+ struct backlight_device * tinker_mcu_get_backlightdev (void )
212+ {
213+ if (!connected ) {
214+ printk ("tinker_mcu_get_backlightdev is not ready\n" );
215+ return NULL ;
216+ }
217+ return bl ;
218+ }
185219
186220static ssize_t tinker_mcu_bl_show (struct device * dev , struct device_attribute * attr , char * buf )
187221{
@@ -196,7 +230,7 @@ static ssize_t tinker_mcu_bl_store(struct device *dev, struct device_attribute *
196230
197231 value = simple_strtoul (buf , NULL , 0 );
198232
199- if ((value < 0 ) || (value > 255 )) {
233+ if ((value < 0 ) || (value > MAX_BRIGHENESS )) {
200234 LOG_ERR ("Invalid value for backlight setting, value = %d\n" , value );
201235 } else
202236 tinker_mcu_set_bright (value );
@@ -217,7 +251,6 @@ static int tinker_mcu_probe(struct i2c_client *client,
217251 struct tinker_mcu_data * mcu_data ;
218252 int ret ;
219253 struct backlight_properties props ;
220- struct backlight_device * bl ;
221254
222255 LOG_INFO ("address = 0x%x\n" , client -> addr );
223256
@@ -245,7 +278,7 @@ static int tinker_mcu_probe(struct i2c_client *client,
245278
246279 memset (& props , 0 , sizeof (props ));
247280 props .type = BACKLIGHT_RAW ;
248- props .max_brightness = 255 ;
281+ props .max_brightness = MAX_BRIGHENESS ;
249282
250283 bl = backlight_device_register ("panel_backlight" , NULL , NULL ,
251284 & tinker_mcu_bl_ops , & props );
0 commit comments