Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[PATCH] backlight: HP Jornada 680 Backlight driver updates/fixes

Updates to the HP Jornada 680 Backlight driver:

- Correct the suspend/resume functions so the driver compiles
(SUSPEND_POWER_DOWN/RESUME_POWER_ON no longer exist).

- Convert the driver to match the recent platform device changes.

- Replace the unsafe static struct platform_device with dynamic allocation.

- Convert the driver to the new backlight code.

This has not been tested on a device due to lack of hardware but wouldn't
compile beforehand.

Signed-off-by: Richard Purdie <rpurdie@rpsys.net>
Signed-off-by: Antonino Daplas <adaplas@pol.net>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by

Richard Purdie and committed by
Linus Torvalds
5f27a27b 6ca01765

+60 -81
+60 -81
drivers/video/backlight/hp680_bl.c
··· 13 13 #include <linux/module.h> 14 14 #include <linux/kernel.h> 15 15 #include <linux/init.h> 16 - #include <linux/device.h> 16 + #include <linux/platform_device.h> 17 17 #include <linux/spinlock.h> 18 18 #include <linux/fb.h> 19 19 #include <linux/backlight.h> ··· 25 25 #define HP680_MAX_INTENSITY 255 26 26 #define HP680_DEFAULT_INTENSITY 10 27 27 28 - static int hp680bl_powermode = FB_BLANK_UNBLANK; 28 + static int hp680bl_suspended; 29 29 static int current_intensity = 0; 30 30 static spinlock_t bl_lock = SPIN_LOCK_UNLOCKED; 31 + static struct backlight_device *hp680_backlight_device; 31 32 32 - static void hp680bl_send_intensity(int intensity) 33 + static void hp680bl_send_intensity(struct backlight_device *bd) 33 34 { 34 35 unsigned long flags; 36 + u16 v; 37 + int intensity = bd->props->brightness; 35 38 36 - if (hp680bl_powermode != FB_BLANK_UNBLANK) 39 + if (bd->props->power != FB_BLANK_UNBLANK) 40 + intensity = 0; 41 + if (bd->props->fb_blank != FB_BLANK_UNBLANK) 42 + intensity = 0; 43 + if (hp680bl_suspended) 37 44 intensity = 0; 38 45 39 46 spin_lock_irqsave(&bl_lock, flags); 40 - sh_dac_output(255-(u8)intensity, DAC_LCD_BRIGHTNESS); 41 - spin_unlock_irqrestore(&bl_lock, flags); 42 - } 43 - 44 - static void hp680bl_blank(int blank) 45 - { 46 - u16 v; 47 - 48 - switch(blank) { 49 - 50 - case FB_BLANK_NORMAL: 51 - case FB_BLANK_VSYNC_SUSPEND: 52 - case FB_BLANK_HSYNC_SUSPEND: 53 - case FB_BLANK_POWERDOWN: 54 - if (hp680bl_powermode == FB_BLANK_UNBLANK) { 55 - hp680bl_send_intensity(0); 56 - hp680bl_powermode = blank; 57 - sh_dac_disable(DAC_LCD_BRIGHTNESS); 58 - v = inw(HD64461_GPBDR); 59 - v |= HD64461_GPBDR_LCDOFF; 60 - outw(v, HD64461_GPBDR); 61 - } 62 - break; 63 - case FB_BLANK_UNBLANK: 64 - if (hp680bl_powermode != FB_BLANK_UNBLANK) { 65 - sh_dac_enable(DAC_LCD_BRIGHTNESS); 66 - v = inw(HD64461_GPBDR); 67 - v &= ~HD64461_GPBDR_LCDOFF; 68 - outw(v, HD64461_GPBDR); 69 - hp680bl_powermode = blank; 70 - hp680bl_send_intensity(current_intensity); 71 - } 72 - break; 47 + if (intensity && current_intensity == 0) { 48 + sh_dac_enable(DAC_LCD_BRIGHTNESS); 49 + v = inw(HD64461_GPBDR); 50 + v &= ~HD64461_GPBDR_LCDOFF; 51 + outw(v, HD64461_GPBDR); 52 + sh_dac_output(255-(u8)intensity, DAC_LCD_BRIGHTNESS); 53 + } else if (intensity == 0 && current_intensity != 0) { 54 + sh_dac_output(255-(u8)intensity, DAC_LCD_BRIGHTNESS); 55 + sh_dac_disable(DAC_LCD_BRIGHTNESS); 56 + v = inw(HD64461_GPBDR); 57 + v |= HD64461_GPBDR_LCDOFF; 58 + outw(v, HD64461_GPBDR); 59 + } else if (intensity) { 60 + sh_dac_output(255-(u8)intensity, DAC_LCD_BRIGHTNESS); 73 61 } 62 + spin_unlock_irqrestore(&bl_lock, flags); 63 + 64 + current_intensity = intensity; 74 65 } 66 + 75 67 76 68 #ifdef CONFIG_PM 77 - static int hp680bl_suspend(struct device *dev, pm_message_t state, u32 level) 69 + static int hp680bl_suspend(struct platform_device *dev, pm_message_t state) 78 70 { 79 - if (level == SUSPEND_POWER_DOWN) 80 - hp680bl_blank(FB_BLANK_POWERDOWN); 71 + hp680bl_suspended = 1; 72 + hp680bl_send_intensity(hp680_backlight_device); 81 73 return 0; 82 74 } 83 75 84 - static int hp680bl_resume(struct device *dev, u32 level) 76 + static int hp680bl_resume(struct platform_device *dev) 85 77 { 86 - if (level == RESUME_POWER_ON) 87 - hp680bl_blank(FB_BLANK_UNBLANK); 78 + hp680bl_suspended = 0; 79 + hp680bl_send_intensity(hp680_backlight_device); 88 80 return 0; 89 81 } 90 82 #else ··· 84 92 #define hp680bl_resume NULL 85 93 #endif 86 94 87 - 88 - static int hp680bl_set_power(struct backlight_device *bd, int state) 95 + static int hp680bl_set_intensity(struct backlight_device *bd) 89 96 { 90 - hp680bl_blank(state); 91 - return 0; 92 - } 93 - 94 - static int hp680bl_get_power(struct backlight_device *bd) 95 - { 96 - return hp680bl_powermode; 97 - } 98 - 99 - static int hp680bl_set_intensity(struct backlight_device *bd, int intensity) 100 - { 101 - if (intensity > HP680_MAX_INTENSITY) 102 - intensity = HP680_MAX_INTENSITY; 103 - hp680bl_send_intensity(intensity); 104 - current_intensity = intensity; 97 + hp680bl_send_intensity(bd); 105 98 return 0; 106 99 } 107 100 ··· 97 120 98 121 static struct backlight_properties hp680bl_data = { 99 122 .owner = THIS_MODULE, 100 - .get_power = hp680bl_get_power, 101 - .set_power = hp680bl_set_power, 102 123 .max_brightness = HP680_MAX_INTENSITY, 103 124 .get_brightness = hp680bl_get_intensity, 104 - .set_brightness = hp680bl_set_intensity, 125 + .update_status = hp680bl_set_intensity, 105 126 }; 106 127 107 - static struct backlight_device *hp680_backlight_device; 108 - 109 - static int __init hp680bl_probe(struct device *dev) 128 + static int __init hp680bl_probe(struct platform_device *dev) 110 129 { 111 130 hp680_backlight_device = backlight_device_register ("hp680-bl", 112 131 NULL, &hp680bl_data); 113 132 if (IS_ERR (hp680_backlight_device)) 114 133 return PTR_ERR (hp680_backlight_device); 115 134 116 - hp680bl_set_intensity(NULL, HP680_DEFAULT_INTENSITY); 135 + hp680_backlight_device->props->brightness = HP680_DEFAULT_INTENSITY; 136 + hp680bl_send_intensity(hp680_backlight_device); 117 137 118 138 return 0; 119 139 } 120 140 121 - static int hp680bl_remove(struct device *dev) 141 + static int hp680bl_remove(struct platform_device *dev) 122 142 { 123 143 backlight_device_unregister(hp680_backlight_device); 124 144 125 145 return 0; 126 146 } 127 147 128 - static struct device_driver hp680bl_driver = { 129 - .name = "hp680-bl", 130 - .bus = &platform_bus_type, 148 + static struct platform_driver hp680bl_driver = { 131 149 .probe = hp680bl_probe, 132 150 .remove = hp680bl_remove, 133 151 .suspend = hp680bl_suspend, 134 152 .resume = hp680bl_resume, 153 + .driver = { 154 + .name = "hp680-bl", 155 + }, 135 156 }; 136 157 137 - static struct platform_device hp680bl_device = { 138 - .name = "hp680-bl", 139 - .id = -1, 140 - }; 158 + static struct platform_device *hp680bl_device; 141 159 142 160 static int __init hp680bl_init(void) 143 161 { 144 162 int ret; 145 163 146 - ret=driver_register(&hp680bl_driver); 164 + ret = platform_driver_register(&hp680bl_driver); 147 165 if (!ret) { 148 - ret = platform_device_register(&hp680bl_device); 149 - if (ret) 150 - driver_unregister(&hp680bl_driver); 166 + hp680bl_device = platform_device_alloc("hp680-bl", -1); 167 + if (!hp680bl_device) 168 + return -ENOMEM; 169 + 170 + ret = platform_device_add(hp680bl_device); 171 + 172 + if (ret) { 173 + platform_device_put(hp680bl_device); 174 + platform_driver_unregister(&hp680bl_driver); 175 + } 151 176 } 152 177 return ret; 153 178 } 154 179 155 180 static void __exit hp680bl_exit(void) 156 181 { 157 - platform_device_unregister(&hp680bl_device); 158 - driver_unregister(&hp680bl_driver); 182 + platform_device_unregister(hp680bl_device); 183 + platform_driver_unregister(&hp680bl_driver); 159 184 } 160 185 161 186 module_init(hp680bl_init);