WIP FPC-III support
[linux/fpc-iii.git] / drivers / video / backlight / locomolcd.c
blob297ee2e1ab0b89e71060e42e7a593f32556c3ca9
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Backlight control code for Sharp Zaurus SL-5500
5 * Copyright 2005 John Lenz <lenz@cs.wisc.edu>
6 * Maintainer: Pavel Machek <pavel@ucw.cz> (unless John wants to :-)
8 * This driver assumes single CPU. That's okay, because collie is
9 * slightly old hardware, and no one is going to retrofit second CPU to
10 * old PDA.
13 /* LCD power functions */
14 #include <linux/module.h>
15 #include <linux/init.h>
16 #include <linux/delay.h>
17 #include <linux/device.h>
18 #include <linux/interrupt.h>
19 #include <linux/fb.h>
20 #include <linux/backlight.h>
22 #include <asm/hardware/locomo.h>
23 #include <asm/irq.h>
24 #include <asm/mach/sharpsl_param.h>
25 #include <asm/mach-types.h>
27 #include "../../../arch/arm/mach-sa1100/generic.h"
29 static struct backlight_device *locomolcd_bl_device;
30 static struct locomo_dev *locomolcd_dev;
31 static unsigned long locomolcd_flags;
32 #define LOCOMOLCD_SUSPENDED 0x01
34 static void locomolcd_on(int comadj)
36 locomo_gpio_set_dir(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VSHA_ON, 0);
37 locomo_gpio_write(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VSHA_ON, 1);
38 mdelay(2);
40 locomo_gpio_set_dir(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VSHD_ON, 0);
41 locomo_gpio_write(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VSHD_ON, 1);
42 mdelay(2);
44 locomo_m62332_senddata(locomolcd_dev, comadj, 0);
45 mdelay(5);
47 locomo_gpio_set_dir(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VEE_ON, 0);
48 locomo_gpio_write(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VEE_ON, 1);
49 mdelay(10);
51 /* TFTCRST | CPSOUT=0 | CPSEN */
52 locomo_writel(0x01, locomolcd_dev->mapbase + LOCOMO_TC);
54 /* Set CPSD */
55 locomo_writel(6, locomolcd_dev->mapbase + LOCOMO_CPSD);
57 /* TFTCRST | CPSOUT=0 | CPSEN */
58 locomo_writel((0x04 | 0x01), locomolcd_dev->mapbase + LOCOMO_TC);
59 mdelay(10);
61 locomo_gpio_set_dir(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_MOD, 0);
62 locomo_gpio_write(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_MOD, 1);
65 static void locomolcd_off(int comadj)
67 /* TFTCRST=1 | CPSOUT=1 | CPSEN = 0 */
68 locomo_writel(0x06, locomolcd_dev->mapbase + LOCOMO_TC);
69 mdelay(1);
71 locomo_gpio_write(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VSHA_ON, 0);
72 mdelay(110);
74 locomo_gpio_write(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VEE_ON, 0);
75 mdelay(700);
77 /* TFTCRST=0 | CPSOUT=0 | CPSEN = 0 */
78 locomo_writel(0, locomolcd_dev->mapbase + LOCOMO_TC);
79 locomo_gpio_write(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_MOD, 0);
80 locomo_gpio_write(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VSHD_ON, 0);
83 void locomolcd_power(int on)
85 int comadj = sharpsl_param.comadj;
86 unsigned long flags;
88 local_irq_save(flags);
90 if (!locomolcd_dev) {
91 local_irq_restore(flags);
92 return;
95 /* read comadj */
96 if (comadj == -1 && machine_is_collie())
97 comadj = 128;
98 if (comadj == -1 && machine_is_poodle())
99 comadj = 118;
101 if (on)
102 locomolcd_on(comadj);
103 else
104 locomolcd_off(comadj);
106 local_irq_restore(flags);
108 EXPORT_SYMBOL(locomolcd_power);
110 static int current_intensity;
112 static int locomolcd_set_intensity(struct backlight_device *bd)
114 int intensity = backlight_get_brightness(bd);
116 if (locomolcd_flags & LOCOMOLCD_SUSPENDED)
117 intensity = 0;
119 switch (intensity) {
121 * AC and non-AC are handled differently,
122 * but produce same results in sharp code?
124 case 0:
125 locomo_frontlight_set(locomolcd_dev, 0, 0, 161);
126 break;
127 case 1:
128 locomo_frontlight_set(locomolcd_dev, 117, 0, 161);
129 break;
130 case 2:
131 locomo_frontlight_set(locomolcd_dev, 163, 0, 148);
132 break;
133 case 3:
134 locomo_frontlight_set(locomolcd_dev, 194, 0, 161);
135 break;
136 case 4:
137 locomo_frontlight_set(locomolcd_dev, 194, 1, 161);
138 break;
139 default:
140 return -ENODEV;
142 current_intensity = intensity;
143 return 0;
146 static int locomolcd_get_intensity(struct backlight_device *bd)
148 return current_intensity;
151 static const struct backlight_ops locomobl_data = {
152 .get_brightness = locomolcd_get_intensity,
153 .update_status = locomolcd_set_intensity,
156 #ifdef CONFIG_PM_SLEEP
157 static int locomolcd_suspend(struct device *dev)
159 locomolcd_flags |= LOCOMOLCD_SUSPENDED;
160 locomolcd_set_intensity(locomolcd_bl_device);
161 return 0;
164 static int locomolcd_resume(struct device *dev)
166 locomolcd_flags &= ~LOCOMOLCD_SUSPENDED;
167 locomolcd_set_intensity(locomolcd_bl_device);
168 return 0;
170 #endif
172 static SIMPLE_DEV_PM_OPS(locomolcd_pm_ops, locomolcd_suspend, locomolcd_resume);
174 static int locomolcd_probe(struct locomo_dev *ldev)
176 struct backlight_properties props;
177 unsigned long flags;
179 local_irq_save(flags);
180 locomolcd_dev = ldev;
182 locomo_gpio_set_dir(ldev->dev.parent, LOCOMO_GPIO_FL_VR, 0);
185 * the poodle_lcd_power function is called for the first time
186 * from fs_initcall, which is before locomo is activated.
187 * We need to recall poodle_lcd_power here
189 if (machine_is_poodle())
190 locomolcd_power(1);
192 local_irq_restore(flags);
194 memset(&props, 0, sizeof(struct backlight_properties));
195 props.type = BACKLIGHT_RAW;
196 props.max_brightness = 4;
197 locomolcd_bl_device = backlight_device_register("locomo-bl",
198 &ldev->dev, NULL,
199 &locomobl_data, &props);
201 if (IS_ERR(locomolcd_bl_device))
202 return PTR_ERR(locomolcd_bl_device);
204 /* Set up frontlight so that screen is readable */
205 locomolcd_bl_device->props.brightness = 2;
206 locomolcd_set_intensity(locomolcd_bl_device);
208 return 0;
211 static int locomolcd_remove(struct locomo_dev *dev)
213 unsigned long flags;
215 locomolcd_bl_device->props.brightness = 0;
216 locomolcd_bl_device->props.power = 0;
217 locomolcd_set_intensity(locomolcd_bl_device);
219 backlight_device_unregister(locomolcd_bl_device);
220 local_irq_save(flags);
221 locomolcd_dev = NULL;
222 local_irq_restore(flags);
223 return 0;
226 static struct locomo_driver poodle_lcd_driver = {
227 .drv = {
228 .name = "locomo-backlight",
229 .pm = &locomolcd_pm_ops,
231 .devid = LOCOMO_DEVID_BACKLIGHT,
232 .probe = locomolcd_probe,
233 .remove = locomolcd_remove,
236 static int __init locomolcd_init(void)
238 return locomo_driver_register(&poodle_lcd_driver);
241 static void __exit locomolcd_exit(void)
243 locomo_driver_unregister(&poodle_lcd_driver);
246 module_init(locomolcd_init);
247 module_exit(locomolcd_exit);
249 MODULE_AUTHOR("John Lenz <lenz@cs.wisc.edu>, Pavel Machek <pavel@ucw.cz>");
250 MODULE_DESCRIPTION("Collie LCD driver");
251 MODULE_LICENSE("GPL");