X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;ds=sidebyside;f=drivers%2Fvideo%2Fbacklight%2Fhp680_bl.c;fp=drivers%2Fvideo%2Fbacklight%2Fhp680_bl.c;h=95da4c9ed1f1459218021926cf124df6eb35c577;hb=64ba3f394c830ec48a1c31b53dcae312c56f1604;hp=ffc72ae3ada80a01f98c959099b004e57bc5aed4;hpb=be1e6109ac94a859551f8e1774eb9a8469fe055c;p=linux-2.6.git diff --git a/drivers/video/backlight/hp680_bl.c b/drivers/video/backlight/hp680_bl.c index ffc72ae3a..95da4c9ed 100644 --- a/drivers/video/backlight/hp680_bl.c +++ b/drivers/video/backlight/hp680_bl.c @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include #include @@ -25,58 +25,66 @@ #define HP680_MAX_INTENSITY 255 #define HP680_DEFAULT_INTENSITY 10 -static int hp680bl_suspended; +static int hp680bl_powermode = FB_BLANK_UNBLANK; static int current_intensity = 0; -static DEFINE_SPINLOCK(bl_lock); -static struct backlight_device *hp680_backlight_device; +static spinlock_t bl_lock = SPIN_LOCK_UNLOCKED; -static void hp680bl_send_intensity(struct backlight_device *bd) +static void hp680bl_send_intensity(int intensity) { unsigned long flags; - u16 v; - int intensity = bd->props->brightness; - if (bd->props->power != FB_BLANK_UNBLANK) - intensity = 0; - if (bd->props->fb_blank != FB_BLANK_UNBLANK) - intensity = 0; - if (hp680bl_suspended) + if (hp680bl_powermode != FB_BLANK_UNBLANK) intensity = 0; spin_lock_irqsave(&bl_lock, flags); - if (intensity && current_intensity == 0) { - sh_dac_enable(DAC_LCD_BRIGHTNESS); - v = inw(HD64461_GPBDR); - v &= ~HD64461_GPBDR_LCDOFF; - outw(v, HD64461_GPBDR); - sh_dac_output(255-(u8)intensity, DAC_LCD_BRIGHTNESS); - } else if (intensity == 0 && current_intensity != 0) { - sh_dac_output(255-(u8)intensity, DAC_LCD_BRIGHTNESS); - sh_dac_disable(DAC_LCD_BRIGHTNESS); - v = inw(HD64461_GPBDR); - v |= HD64461_GPBDR_LCDOFF; - outw(v, HD64461_GPBDR); - } else if (intensity) { - sh_dac_output(255-(u8)intensity, DAC_LCD_BRIGHTNESS); - } + sh_dac_output(255-(u8)intensity, DAC_LCD_BRIGHTNESS); spin_unlock_irqrestore(&bl_lock, flags); - - current_intensity = intensity; } +static void hp680bl_blank(int blank) +{ + u16 v; + + switch(blank) { + + case FB_BLANK_NORMAL: + case FB_BLANK_VSYNC_SUSPEND: + case FB_BLANK_HSYNC_SUSPEND: + case FB_BLANK_POWERDOWN: + if (hp680bl_powermode == FB_BLANK_UNBLANK) { + hp680bl_send_intensity(0); + hp680bl_powermode = blank; + sh_dac_disable(DAC_LCD_BRIGHTNESS); + v = inw(HD64461_GPBDR); + v |= HD64461_GPBDR_LCDOFF; + outw(v, HD64461_GPBDR); + } + break; + case FB_BLANK_UNBLANK: + if (hp680bl_powermode != FB_BLANK_UNBLANK) { + sh_dac_enable(DAC_LCD_BRIGHTNESS); + v = inw(HD64461_GPBDR); + v &= ~HD64461_GPBDR_LCDOFF; + outw(v, HD64461_GPBDR); + hp680bl_powermode = blank; + hp680bl_send_intensity(current_intensity); + } + break; + } +} #ifdef CONFIG_PM -static int hp680bl_suspend(struct platform_device *dev, pm_message_t state) +static int hp680bl_suspend(struct device *dev, pm_message_t state, u32 level) { - hp680bl_suspended = 1; - hp680bl_send_intensity(hp680_backlight_device); + if (level == SUSPEND_POWER_DOWN) + hp680bl_blank(FB_BLANK_POWERDOWN); return 0; } -static int hp680bl_resume(struct platform_device *dev) +static int hp680bl_resume(struct device *dev, u32 level) { - hp680bl_suspended = 0; - hp680bl_send_intensity(hp680_backlight_device); + if (level == RESUME_POWER_ON) + hp680bl_blank(FB_BLANK_UNBLANK); return 0; } #else @@ -84,9 +92,24 @@ static int hp680bl_resume(struct platform_device *dev) #define hp680bl_resume NULL #endif -static int hp680bl_set_intensity(struct backlight_device *bd) + +static int hp680bl_set_power(struct backlight_device *bd, int state) { - hp680bl_send_intensity(bd); + hp680bl_blank(state); + return 0; +} + +static int hp680bl_get_power(struct backlight_device *bd) +{ + return hp680bl_powermode; +} + +static int hp680bl_set_intensity(struct backlight_device *bd, int intensity) +{ + if (intensity > HP680_MAX_INTENSITY) + intensity = HP680_MAX_INTENSITY; + hp680bl_send_intensity(intensity); + current_intensity = intensity; return 0; } @@ -97,67 +120,65 @@ static int hp680bl_get_intensity(struct backlight_device *bd) static struct backlight_properties hp680bl_data = { .owner = THIS_MODULE, + .get_power = hp680bl_get_power, + .set_power = hp680bl_set_power, .max_brightness = HP680_MAX_INTENSITY, .get_brightness = hp680bl_get_intensity, - .update_status = hp680bl_set_intensity, + .set_brightness = hp680bl_set_intensity, }; -static int __init hp680bl_probe(struct platform_device *dev) +static struct backlight_device *hp680_backlight_device; + +static int __init hp680bl_probe(struct device *dev) { hp680_backlight_device = backlight_device_register ("hp680-bl", NULL, &hp680bl_data); if (IS_ERR (hp680_backlight_device)) return PTR_ERR (hp680_backlight_device); - hp680_backlight_device->props->brightness = HP680_DEFAULT_INTENSITY; - hp680bl_send_intensity(hp680_backlight_device); + hp680bl_set_intensity(NULL, HP680_DEFAULT_INTENSITY); return 0; } -static int hp680bl_remove(struct platform_device *dev) +static int hp680bl_remove(struct device *dev) { backlight_device_unregister(hp680_backlight_device); return 0; } -static struct platform_driver hp680bl_driver = { +static struct device_driver hp680bl_driver = { + .name = "hp680-bl", + .bus = &platform_bus_type, .probe = hp680bl_probe, .remove = hp680bl_remove, .suspend = hp680bl_suspend, .resume = hp680bl_resume, - .driver = { - .name = "hp680-bl", - }, }; -static struct platform_device *hp680bl_device; +static struct platform_device hp680bl_device = { + .name = "hp680-bl", + .id = -1, +}; static int __init hp680bl_init(void) { int ret; - ret = platform_driver_register(&hp680bl_driver); + ret=driver_register(&hp680bl_driver); if (!ret) { - hp680bl_device = platform_device_alloc("hp680-bl", -1); - if (!hp680bl_device) - return -ENOMEM; - - ret = platform_device_add(hp680bl_device); - - if (ret) { - platform_device_put(hp680bl_device); - platform_driver_unregister(&hp680bl_driver); - } + ret = platform_device_register(&hp680bl_device); + if (ret) + driver_unregister(&hp680bl_driver); } return ret; } static void __exit hp680bl_exit(void) { - platform_device_unregister(hp680bl_device); - platform_driver_unregister(&hp680bl_driver); + platform_device_unregister(&hp680bl_device); + driver_unregister(&hp680bl_driver); } module_init(hp680bl_init);