hh.org updates
[hh.org.git] / arch / arm / mach-pxa / htcuniversal / htcuniversal_lcd.c
blob8eec3e494dd2ab8c35c7796a3fcf58b3741d74fa
1 /*
2 * Use consistent with the GNU GPL is permitted,
3 * provided that this copyright notice is
4 * preserved in its entirety in all copies and derived works.
6 * History:
8 * 2004-03-01 Eddi De Pieri Adapted for htcuniversal using h3900_lcd.c
9 * 2004 Shawn Anderson Lcd hacking on htcuniversal
10 * see h3900_lcd.c for more history.
14 #include <linux/types.h>
15 #include <asm/arch/hardware.h> /* for pxa-regs.h (__REG) */
16 #include <linux/platform_device.h>
17 #include <asm/arch/pxa-regs.h> /* LCCR[0,1,2,3]* */
18 #include <asm/arch/bitfield.h> /* for pxa-regs.h (Fld, etc) */
19 #include <asm/arch/pxafb.h> /* pxafb_mach_info, set_pxa_fb_info */
20 #include <asm/mach-types.h> /* machine_is_htcuniversal */
21 #include <linux/lcd.h> /* lcd_device */
22 #include <linux/err.h>
23 #include <linux/delay.h>
25 #include <asm/arch/htcuniversal-gpio.h>
26 #include <asm/arch/htcuniversal-asic.h>
27 #include <asm/hardware/ipaq-asic3.h>
28 #include <linux/soc/asic3_base.h>
30 static int saved_lcdpower=-1;
32 static int powerup_lcd(void)
34 printk( KERN_INFO "htcuniversal powerup_lcd: called\n");
36 asic3_set_gpio_out_c(&htcuniversal_asic3.dev, 1<<GPIOC_LCD_PWR1_ON, 0);
37 asic3_set_gpio_out_c(&htcuniversal_asic3.dev, 1<<GPIOC_LCD_PWR2_ON, 0);
38 asic3_set_gpio_out_b(&htcuniversal_asic3.dev, 1<<GPIOB_LCD_PWR3_ON, 0);
39 asic3_set_gpio_out_d(&htcuniversal_asic3.dev, 1<<GPIOD_LCD_PWR4_ON, 0);
40 asic3_set_gpio_out_a(&htcuniversal_asic3.dev, 1<<GPIOA_LCD_PWR5_ON, 0);
41 pxa_set_cken(CKEN16_LCD, 0);
43 mdelay(100);
44 asic3_set_gpio_out_a(&htcuniversal_asic3.dev, 1<<GPIOA_LCD_PWR5_ON, 1<<GPIOA_LCD_PWR5_ON);
45 mdelay(5);
46 asic3_set_gpio_out_b(&htcuniversal_asic3.dev, 1<<GPIOB_LCD_PWR3_ON, 1<<GPIOB_LCD_PWR3_ON);
47 mdelay(2);
48 asic3_set_gpio_out_c(&htcuniversal_asic3.dev, 1<<GPIOC_LCD_PWR1_ON, 1<<GPIOC_LCD_PWR1_ON);
49 mdelay(2);
50 asic3_set_gpio_out_c(&htcuniversal_asic3.dev, 1<<GPIOC_LCD_PWR2_ON, 1<<GPIOC_LCD_PWR2_ON);
51 mdelay(20);
52 asic3_set_gpio_out_d(&htcuniversal_asic3.dev, 1<<GPIOD_LCD_PWR4_ON, 1<<GPIOD_LCD_PWR4_ON);
53 mdelay(1);
54 pxa_set_cken(CKEN16_LCD, 1);
56 SET_HTCUNIVERSAL_GPIO(LCD1,1);
57 SET_HTCUNIVERSAL_GPIO(LCD2,1);
58 return 0;
61 static int powerdown_lcd(void)
63 printk( KERN_INFO "htcuniversal powerdown_lcd: called\n");
65 #if 1
66 asic3_set_gpio_out_c(&htcuniversal_asic3.dev, 1<<GPIOC_LCD_PWR2_ON, 0);
67 mdelay(100);
68 asic3_set_gpio_out_d(&htcuniversal_asic3.dev, 1<<GPIOD_LCD_PWR4_ON, 0);
69 mdelay(10);
70 asic3_set_gpio_out_a(&htcuniversal_asic3.dev, 1<<GPIOA_LCD_PWR5_ON, 0);
71 mdelay(1);
72 asic3_set_gpio_out_b(&htcuniversal_asic3.dev, 1<<GPIOB_LCD_PWR3_ON, 0);
73 mdelay(1);
74 asic3_set_gpio_out_c(&htcuniversal_asic3.dev, 1<<GPIOC_LCD_PWR1_ON, 0);
75 pxa_set_cken(CKEN16_LCD, 0);
77 SET_HTCUNIVERSAL_GPIO(LCD1,0);
78 SET_HTCUNIVERSAL_GPIO(LCD2,0);
79 #else
80 pxa_set_cken(CKEN16_LCD, 0);
82 SET_HTCUNIVERSAL_GPIO(LCD1,0);
83 SET_HTCUNIVERSAL_GPIO(LCD2,0);
85 asic3_set_gpio_out_c(&htcuniversal_asic3.dev, 1<<GPIOC_LCD_PWR2_ON, 0);
86 mdelay(100);
87 asic3_set_gpio_out_d(&htcuniversal_asic3.dev, 1<<GPIOD_LCD_PWR4_ON, 0);
88 mdelay(10);
89 asic3_set_gpio_out_a(&htcuniversal_asic3.dev, 1<<GPIOA_LCD_PWR5_ON, 0);
90 mdelay(1);
91 asic3_set_gpio_out_b(&htcuniversal_asic3.dev, 1<<GPIOB_LCD_PWR3_ON, 0);
92 mdelay(1);
93 asic3_set_gpio_out_c(&htcuniversal_asic3.dev, 1<<GPIOC_LCD_PWR1_ON, 0);
94 #endif
95 return 0;
98 static int htcuniversal_lcd_set_power(struct lcd_device *lm, int power)
100 /* Enable or disable power to the LCD (0: on; 4: off) */
102 if ( power < 1 ) {
104 powerup_lcd();
106 } else {
108 powerdown_lcd();
112 #if 0
113 if ( power < 4 ) {
114 mdelay(17); // Wait one from before turning on
115 asic3_set_gpio_out_b(&htcuniversal_asic3.dev,
116 GPIOB_LCD_PCI, GPIOB_LCD_PCI);
117 } else {
118 asic3_set_gpio_out_b (&htcuniversal_asic3.dev, GPIOB_LCD_PCI, 0);
119 mdelay(30); // Wait before turning off
121 #endif
122 saved_lcdpower=power;
124 return 0;
127 static int htcuniversal_lcd_get_power(struct lcd_device *lm)
129 /* Get the LCD panel power status (0: full on, 1..3: controller
130 * power on, flat panel power off, 4: full off) */
132 #if 0
133 if (asic3_get_gpio_status_b(&htcuniversal_asic3.dev) & GPIOB_LCD_PCI) {
134 if (asic3_get_gpio_out_b(&htcuniversal_asic3.dev) & GPIOB_LCD_ON)
135 return 0;
136 else
137 return 2;
138 } else
139 return 4;
140 #else
142 if (saved_lcdpower == -1)
144 htcuniversal_lcd_set_power(lm, 4);
145 saved_lcdpower=4;
147 #endif
148 return saved_lcdpower;
151 static struct lcd_properties htcuniversal_lcd_properties =
153 .owner = THIS_MODULE,
154 .get_power = htcuniversal_lcd_get_power,
155 .set_power = htcuniversal_lcd_set_power,
158 static struct lcd_device *htcuniversal_lcd_dev;
160 static int htcuniversal_lcd_probe(struct platform_device * dev)
162 htcuniversal_lcd_dev = lcd_device_register("pxa2xx-fb", NULL,
163 &htcuniversal_lcd_properties);
164 if (IS_ERR(htcuniversal_lcd_dev)) {
165 printk("htcuniversal_lcd_probe: error registering devices\n");
166 return -1;
169 return 0;
172 static int htcuniversal_lcd_remove(struct platform_device * dev)
174 htcuniversal_lcd_set_power(htcuniversal_lcd_dev, 4);
175 lcd_device_unregister(htcuniversal_lcd_dev);
177 return 0;
180 static int htcuniversal_lcd_suspend(struct platform_device * dev, pm_message_t state)
182 printk("htcuniversal_lcd_suspend: called.\n");
183 htcuniversal_lcd_set_power(htcuniversal_lcd_dev, 4);
184 return 0;
187 static int htcuniversal_lcd_resume(struct platform_device * dev)
189 printk("htcuniversal_lcd_resume: called.\n");
190 htcuniversal_lcd_set_power(htcuniversal_lcd_dev, 0);
191 return 0;
194 static struct platform_driver htcuniversal_lcd_driver = {
195 .driver = {
196 .name = "htcuniversal_lcd",
198 .probe = htcuniversal_lcd_probe,
199 .remove = htcuniversal_lcd_remove,
200 .suspend = htcuniversal_lcd_suspend,
201 .resume = htcuniversal_lcd_resume,
204 static int htcuniversal_lcd_init(void)
206 if (!machine_is_htcuniversal())
207 return -ENODEV;
209 return platform_driver_register(&htcuniversal_lcd_driver);
212 static void htcuniversal_lcd_exit(void)
214 lcd_device_unregister(htcuniversal_lcd_dev);
215 platform_driver_unregister(&htcuniversal_lcd_driver);
218 module_init(htcuniversal_lcd_init);
219 module_exit(htcuniversal_lcd_exit);
221 MODULE_AUTHOR("xanadux.org");
222 MODULE_DESCRIPTION("Framebuffer driver for HTC Universal");
223 MODULE_LICENSE("GPL");