hh.org updates
[hh.org.git] / arch / arm / mach-pxa / eseries / e740_bl.c
blob07ff9fa0a4afcce2fd018ece60517bb909525d65
1 /* e740_lcd.c
3 * (c) Ian Molton 2005
5 * This file contains the definitions for the LCD timings and functions
6 * to control the LCD power / frontlighting via the w100fb driver.
8 */
9 #include <linux/platform_device.h>
11 #include <linux/module.h>
12 #include <linux/init.h>
13 #include <linux/kernel.h>
14 #include <linux/tty.h>
15 #include <linux/sched.h>
16 #include <linux/delay.h>
17 #include <linux/pm.h>
18 #include <linux/lcd.h>
19 #include <linux/backlight.h>
20 #include <linux/fb.h>
21 #include <linux/err.h>
24 #include <asm/mach-types.h>
25 #include <asm/hardware.h>
26 #include <asm/setup.h>
28 #include <asm/mach/arch.h>
29 #include <asm/arch/pxa-regs.h>
30 #include <asm/arch/eseries-gpio.h>
32 #include <video/w100fb.h>
34 /* ------------------- backlight driver ------------------ */
36 static int current_brightness = 0;
38 static int e740_bl_update_status (struct backlight_device *bd)
40 int intensity = bd->props->brightness;
41 u32 gpio;
43 if (bd->props->power != FB_BLANK_UNBLANK)
44 intensity = 0;
45 if (bd->props->fb_blank != FB_BLANK_UNBLANK)
46 intensity = 0;
48 current_brightness=intensity;
50 gpio = w100fb_gpio_read(W100_GPIO_PORT_B);
51 gpio &= ~0x31;
52 if(intensity)
53 gpio |= (((intensity-1) & 0x3) << 4) | 1;
54 w100fb_gpio_write(W100_GPIO_PORT_B, gpio);
56 return 0;
59 static int e740_bl_get_brightness (struct backlight_device *bl)
61 return current_brightness;
64 static struct backlight_properties e740_bl_info = {
65 .owner = THIS_MODULE,
66 .update_status = e740_bl_update_status,
67 .max_brightness = 4,
68 .get_brightness = e740_bl_get_brightness,
71 /* -------------------------- LCD driver -----------------------*/
73 static int lcd_power;
75 void __e740_lcd_set_power(int power)
77 int gpio;
78 gpio = w100fb_gpio_read(W100_GPIO_PORT_B);
79 if(power)
80 gpio &= ~0xe;
81 else
82 gpio |= 0xe;
83 w100fb_gpio_write(W100_GPIO_PORT_B, gpio);
86 static int e740_lcd_set_power (struct lcd_device *ld, int state)
88 lcd_power = state;
89 __e740_lcd_set_power(lcd_power);
91 return 0;
94 static int e740_lcd_get_power (struct lcd_device *ld){
95 return lcd_power;
98 static struct lcd_properties e740_lcd_info = {
99 .owner = THIS_MODULE,
100 .get_power = e740_lcd_get_power,
101 .set_power = e740_lcd_set_power,
104 /* ----------------------- device declarations -------------------------- */
106 #ifdef CONFIG_PM
107 static int e740_lcd_hook_suspend(struct platform_device *dev, pm_message_t state)
109 __e740_lcd_set_power(1);
110 // __e740_set_brightness(NULL, 0);
111 return 0;
114 static int e740_lcd_hook_resume(struct platform_device *dev)
116 // e740_bl_set_power(NULL, FB_BLANK_UNBLANK);
117 __e740_lcd_set_power(lcd_power);
118 return 0;
120 #endif
123 static struct backlight_device *e740_bl_device;
124 static struct lcd_device *e740_lcd_device;
126 static int e740_lcd_hook_probe (struct platform_device *dev) {
127 e740_lcd_device = lcd_device_register("w100fb", NULL, &e740_lcd_info);
128 e740_bl_device = backlight_device_register("w100fb", NULL, &e740_bl_info);
129 return 0;
132 static int e740_lcd_hook_remove(struct platform_device *dev)
134 lcd_device_unregister(e740_lcd_device);
135 backlight_device_unregister(e740_bl_device);
136 return 0;
139 static struct platform_driver e740_lcd_hook_driver = {
140 .driver = {
141 .name = "e740-lcd-hook",
143 .probe = e740_lcd_hook_probe,
144 .remove = e740_lcd_hook_remove,
145 #ifdef CONFIG_PM
146 .suspend = e740_lcd_hook_suspend,
147 .resume = e740_lcd_hook_resume,
148 #endif
151 static int e740_bl_init (void) {
152 return platform_driver_register(&e740_lcd_hook_driver);
155 static void e740_bl_exit (void)
157 platform_driver_unregister(&e740_lcd_hook_driver);
160 module_init (e740_bl_init);
161 module_exit (e740_bl_exit);
163 MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
164 MODULE_DESCRIPTION("e740 lcd driver");
165 MODULE_LICENSE("GPLv2");