1 // SPDX-License-Identifier: GPL-2.0-only
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
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>
20 #include <linux/backlight.h>
22 #include <asm/hardware/locomo.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);
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);
44 locomo_m62332_senddata(locomolcd_dev
, comadj
, 0);
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);
51 /* TFTCRST | CPSOUT=0 | CPSEN */
52 locomo_writel(0x01, locomolcd_dev
->mapbase
+ LOCOMO_TC
);
55 locomo_writel(6, locomolcd_dev
->mapbase
+ LOCOMO_CPSD
);
57 /* TFTCRST | CPSOUT=0 | CPSEN */
58 locomo_writel((0x04 | 0x01), locomolcd_dev
->mapbase
+ LOCOMO_TC
);
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
);
71 locomo_gpio_write(locomolcd_dev
->dev
.parent
, LOCOMO_GPIO_LCD_VSHA_ON
, 0);
74 locomo_gpio_write(locomolcd_dev
->dev
.parent
, LOCOMO_GPIO_LCD_VEE_ON
, 0);
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
;
88 local_irq_save(flags
);
91 local_irq_restore(flags
);
96 if (comadj
== -1 && machine_is_collie())
98 if (comadj
== -1 && machine_is_poodle())
102 locomolcd_on(comadj
);
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
= bd
->props
.brightness
;
116 if (bd
->props
.power
!= FB_BLANK_UNBLANK
)
118 if (bd
->props
.fb_blank
!= FB_BLANK_UNBLANK
)
120 if (locomolcd_flags
& LOCOMOLCD_SUSPENDED
)
125 * AC and non-AC are handled differently,
126 * but produce same results in sharp code?
129 locomo_frontlight_set(locomolcd_dev
, 0, 0, 161);
132 locomo_frontlight_set(locomolcd_dev
, 117, 0, 161);
135 locomo_frontlight_set(locomolcd_dev
, 163, 0, 148);
138 locomo_frontlight_set(locomolcd_dev
, 194, 0, 161);
141 locomo_frontlight_set(locomolcd_dev
, 194, 1, 161);
146 current_intensity
= intensity
;
150 static int locomolcd_get_intensity(struct backlight_device
*bd
)
152 return current_intensity
;
155 static const struct backlight_ops locomobl_data
= {
156 .get_brightness
= locomolcd_get_intensity
,
157 .update_status
= locomolcd_set_intensity
,
160 #ifdef CONFIG_PM_SLEEP
161 static int locomolcd_suspend(struct device
*dev
)
163 locomolcd_flags
|= LOCOMOLCD_SUSPENDED
;
164 locomolcd_set_intensity(locomolcd_bl_device
);
168 static int locomolcd_resume(struct device
*dev
)
170 locomolcd_flags
&= ~LOCOMOLCD_SUSPENDED
;
171 locomolcd_set_intensity(locomolcd_bl_device
);
176 static SIMPLE_DEV_PM_OPS(locomolcd_pm_ops
, locomolcd_suspend
, locomolcd_resume
);
178 static int locomolcd_probe(struct locomo_dev
*ldev
)
180 struct backlight_properties props
;
183 local_irq_save(flags
);
184 locomolcd_dev
= ldev
;
186 locomo_gpio_set_dir(ldev
->dev
.parent
, LOCOMO_GPIO_FL_VR
, 0);
189 * the poodle_lcd_power function is called for the first time
190 * from fs_initcall, which is before locomo is activated.
191 * We need to recall poodle_lcd_power here
193 if (machine_is_poodle())
196 local_irq_restore(flags
);
198 memset(&props
, 0, sizeof(struct backlight_properties
));
199 props
.type
= BACKLIGHT_RAW
;
200 props
.max_brightness
= 4;
201 locomolcd_bl_device
= backlight_device_register("locomo-bl",
203 &locomobl_data
, &props
);
205 if (IS_ERR(locomolcd_bl_device
))
206 return PTR_ERR(locomolcd_bl_device
);
208 /* Set up frontlight so that screen is readable */
209 locomolcd_bl_device
->props
.brightness
= 2;
210 locomolcd_set_intensity(locomolcd_bl_device
);
215 static int locomolcd_remove(struct locomo_dev
*dev
)
219 locomolcd_bl_device
->props
.brightness
= 0;
220 locomolcd_bl_device
->props
.power
= 0;
221 locomolcd_set_intensity(locomolcd_bl_device
);
223 backlight_device_unregister(locomolcd_bl_device
);
224 local_irq_save(flags
);
225 locomolcd_dev
= NULL
;
226 local_irq_restore(flags
);
230 static struct locomo_driver poodle_lcd_driver
= {
232 .name
= "locomo-backlight",
233 .pm
= &locomolcd_pm_ops
,
235 .devid
= LOCOMO_DEVID_BACKLIGHT
,
236 .probe
= locomolcd_probe
,
237 .remove
= locomolcd_remove
,
240 static int __init
locomolcd_init(void)
242 return locomo_driver_register(&poodle_lcd_driver
);
245 static void __exit
locomolcd_exit(void)
247 locomo_driver_unregister(&poodle_lcd_driver
);
250 module_init(locomolcd_init
);
251 module_exit(locomolcd_exit
);
253 MODULE_AUTHOR("John Lenz <lenz@cs.wisc.edu>, Pavel Machek <pavel@ucw.cz>");
254 MODULE_DESCRIPTION("Collie LCD driver");
255 MODULE_LICENSE("GPL");