Pavel Machek | 987132b | 2005-09-06 15:16:45 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Backlight control code for Sharp Zaurus SL-5500 |
| 3 | * |
| 4 | * Copyright 2005 John Lenz <lenz@cs.wisc.edu> |
Pavel Machek | a253129 | 2010-07-18 14:27:13 +0200 | [diff] [blame] | 5 | * Maintainer: Pavel Machek <pavel@ucw.cz> (unless John wants to :-) |
Pavel Machek | 987132b | 2005-09-06 15:16:45 -0700 | [diff] [blame] | 6 | * GPL v2 |
| 7 | * |
| 8 | * This driver assumes single CPU. That's okay, because collie is |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9 | * slightly old hardware, and no one is going to retrofit second CPU to |
Pavel Machek | 987132b | 2005-09-06 15:16:45 -0700 | [diff] [blame] | 10 | * old PDA. |
| 11 | */ |
| 12 | |
| 13 | /* LCD power functions */ |
Pavel Machek | 987132b | 2005-09-06 15:16:45 -0700 | [diff] [blame] | 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> |
Richard Purdie | e442378 | 2006-06-26 00:26:27 -0700 | [diff] [blame] | 19 | #include <linux/fb.h> |
| 20 | #include <linux/backlight.h> |
Pavel Machek | 987132b | 2005-09-06 15:16:45 -0700 | [diff] [blame] | 21 | |
| 22 | #include <asm/hardware/locomo.h> |
| 23 | #include <asm/irq.h> |
Pavel Machek | 36a95bf | 2006-03-25 03:07:33 -0800 | [diff] [blame] | 24 | #include <asm/mach/sharpsl_param.h> |
| 25 | #include <asm/mach-types.h> |
Pavel Machek | 987132b | 2005-09-06 15:16:45 -0700 | [diff] [blame] | 26 | |
Pavel Machek | 36a95bf | 2006-03-25 03:07:33 -0800 | [diff] [blame] | 27 | #include "../../../arch/arm/mach-sa1100/generic.h" |
Pavel Machek | 987132b | 2005-09-06 15:16:45 -0700 | [diff] [blame] | 28 | |
Richard Purdie | e442378 | 2006-06-26 00:26:27 -0700 | [diff] [blame] | 29 | static struct backlight_device *locomolcd_bl_device; |
Pavel Machek | 987132b | 2005-09-06 15:16:45 -0700 | [diff] [blame] | 30 | static struct locomo_dev *locomolcd_dev; |
Richard Purdie | e442378 | 2006-06-26 00:26:27 -0700 | [diff] [blame] | 31 | static unsigned long locomolcd_flags; |
| 32 | #define LOCOMOLCD_SUSPENDED 0x01 |
Pavel Machek | 987132b | 2005-09-06 15:16:45 -0700 | [diff] [blame] | 33 | |
| 34 | static void locomolcd_on(int comadj) |
| 35 | { |
Richard Purdie | 8d48427 | 2006-09-25 20:11:48 +0100 | [diff] [blame] | 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); |
Pavel Machek | 987132b | 2005-09-06 15:16:45 -0700 | [diff] [blame] | 38 | mdelay(2); |
| 39 | |
Richard Purdie | 8d48427 | 2006-09-25 20:11:48 +0100 | [diff] [blame] | 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); |
Pavel Machek | 987132b | 2005-09-06 15:16:45 -0700 | [diff] [blame] | 42 | mdelay(2); |
| 43 | |
| 44 | locomo_m62332_senddata(locomolcd_dev, comadj, 0); |
| 45 | mdelay(5); |
| 46 | |
Richard Purdie | 8d48427 | 2006-09-25 20:11:48 +0100 | [diff] [blame] | 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); |
Pavel Machek | 987132b | 2005-09-06 15:16:45 -0700 | [diff] [blame] | 49 | mdelay(10); |
| 50 | |
| 51 | /* TFTCRST | CPSOUT=0 | CPSEN */ |
| 52 | locomo_writel(0x01, locomolcd_dev->mapbase + LOCOMO_TC); |
| 53 | |
| 54 | /* Set CPSD */ |
| 55 | locomo_writel(6, locomolcd_dev->mapbase + LOCOMO_CPSD); |
| 56 | |
| 57 | /* TFTCRST | CPSOUT=0 | CPSEN */ |
| 58 | locomo_writel((0x04 | 0x01), locomolcd_dev->mapbase + LOCOMO_TC); |
| 59 | mdelay(10); |
| 60 | |
Richard Purdie | 8d48427 | 2006-09-25 20:11:48 +0100 | [diff] [blame] | 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); |
Pavel Machek | 987132b | 2005-09-06 15:16:45 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | static void locomolcd_off(int comadj) |
| 66 | { |
| 67 | /* TFTCRST=1 | CPSOUT=1 | CPSEN = 0 */ |
| 68 | locomo_writel(0x06, locomolcd_dev->mapbase + LOCOMO_TC); |
| 69 | mdelay(1); |
| 70 | |
Richard Purdie | 8d48427 | 2006-09-25 20:11:48 +0100 | [diff] [blame] | 71 | locomo_gpio_write(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VSHA_ON, 0); |
Pavel Machek | 987132b | 2005-09-06 15:16:45 -0700 | [diff] [blame] | 72 | mdelay(110); |
| 73 | |
Richard Purdie | 8d48427 | 2006-09-25 20:11:48 +0100 | [diff] [blame] | 74 | locomo_gpio_write(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VEE_ON, 0); |
Pavel Machek | 987132b | 2005-09-06 15:16:45 -0700 | [diff] [blame] | 75 | mdelay(700); |
| 76 | |
| 77 | /* TFTCRST=0 | CPSOUT=0 | CPSEN = 0 */ |
| 78 | locomo_writel(0, locomolcd_dev->mapbase + LOCOMO_TC); |
Richard Purdie | 8d48427 | 2006-09-25 20:11:48 +0100 | [diff] [blame] | 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); |
Pavel Machek | 987132b | 2005-09-06 15:16:45 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | void locomolcd_power(int on) |
| 84 | { |
Pavel Machek | 36a95bf | 2006-03-25 03:07:33 -0800 | [diff] [blame] | 85 | int comadj = sharpsl_param.comadj; |
Pavel Machek | 987132b | 2005-09-06 15:16:45 -0700 | [diff] [blame] | 86 | unsigned long flags; |
| 87 | |
| 88 | local_irq_save(flags); |
| 89 | |
| 90 | if (!locomolcd_dev) { |
| 91 | local_irq_restore(flags); |
| 92 | return; |
| 93 | } |
| 94 | |
| 95 | /* read comadj */ |
Richard Purdie | e442378 | 2006-06-26 00:26:27 -0700 | [diff] [blame] | 96 | if (comadj == -1 && machine_is_collie()) |
| 97 | comadj = 128; |
| 98 | if (comadj == -1 && machine_is_poodle()) |
| 99 | comadj = 118; |
Pavel Machek | 987132b | 2005-09-06 15:16:45 -0700 | [diff] [blame] | 100 | |
| 101 | if (on) |
| 102 | locomolcd_on(comadj); |
| 103 | else |
| 104 | locomolcd_off(comadj); |
| 105 | |
| 106 | local_irq_restore(flags); |
| 107 | } |
| 108 | EXPORT_SYMBOL(locomolcd_power); |
| 109 | |
Richard Purdie | e442378 | 2006-06-26 00:26:27 -0700 | [diff] [blame] | 110 | static int current_intensity; |
| 111 | |
| 112 | static int locomolcd_set_intensity(struct backlight_device *bd) |
| 113 | { |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 114 | int intensity = bd->props.brightness; |
Richard Purdie | e442378 | 2006-06-26 00:26:27 -0700 | [diff] [blame] | 115 | |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 116 | if (bd->props.power != FB_BLANK_UNBLANK) |
Richard Purdie | e442378 | 2006-06-26 00:26:27 -0700 | [diff] [blame] | 117 | intensity = 0; |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 118 | if (bd->props.fb_blank != FB_BLANK_UNBLANK) |
Richard Purdie | e442378 | 2006-06-26 00:26:27 -0700 | [diff] [blame] | 119 | intensity = 0; |
| 120 | if (locomolcd_flags & LOCOMOLCD_SUSPENDED) |
| 121 | intensity = 0; |
| 122 | |
| 123 | switch (intensity) { |
Jingoo Han | 9f67675 | 2012-12-18 14:21:18 -0800 | [diff] [blame] | 124 | /* |
| 125 | * AC and non-AC are handled differently, |
| 126 | * but produce same results in sharp code? |
| 127 | */ |
| 128 | case 0: |
| 129 | locomo_frontlight_set(locomolcd_dev, 0, 0, 161); |
| 130 | break; |
| 131 | case 1: |
| 132 | locomo_frontlight_set(locomolcd_dev, 117, 0, 161); |
| 133 | break; |
| 134 | case 2: |
| 135 | locomo_frontlight_set(locomolcd_dev, 163, 0, 148); |
| 136 | break; |
| 137 | case 3: |
| 138 | locomo_frontlight_set(locomolcd_dev, 194, 0, 161); |
| 139 | break; |
| 140 | case 4: |
| 141 | locomo_frontlight_set(locomolcd_dev, 194, 1, 161); |
| 142 | break; |
Richard Purdie | e442378 | 2006-06-26 00:26:27 -0700 | [diff] [blame] | 143 | default: |
| 144 | return -ENODEV; |
| 145 | } |
| 146 | current_intensity = intensity; |
| 147 | return 0; |
| 148 | } |
| 149 | |
| 150 | static int locomolcd_get_intensity(struct backlight_device *bd) |
| 151 | { |
| 152 | return current_intensity; |
| 153 | } |
| 154 | |
Emese Revfy | 9905a43 | 2009-12-14 00:58:57 +0100 | [diff] [blame] | 155 | static const struct backlight_ops locomobl_data = { |
Richard Purdie | e442378 | 2006-06-26 00:26:27 -0700 | [diff] [blame] | 156 | .get_brightness = locomolcd_get_intensity, |
| 157 | .update_status = locomolcd_set_intensity, |
Richard Purdie | e442378 | 2006-06-26 00:26:27 -0700 | [diff] [blame] | 158 | }; |
| 159 | |
Jingoo Han | 5a3778e | 2013-04-29 16:17:45 -0700 | [diff] [blame] | 160 | #ifdef CONFIG_PM_SLEEP |
| 161 | static int locomolcd_suspend(struct device *dev) |
Richard Purdie | e442378 | 2006-06-26 00:26:27 -0700 | [diff] [blame] | 162 | { |
| 163 | locomolcd_flags |= LOCOMOLCD_SUSPENDED; |
| 164 | locomolcd_set_intensity(locomolcd_bl_device); |
| 165 | return 0; |
| 166 | } |
| 167 | |
Jingoo Han | 5a3778e | 2013-04-29 16:17:45 -0700 | [diff] [blame] | 168 | static int locomolcd_resume(struct device *dev) |
Richard Purdie | e442378 | 2006-06-26 00:26:27 -0700 | [diff] [blame] | 169 | { |
| 170 | locomolcd_flags &= ~LOCOMOLCD_SUSPENDED; |
| 171 | locomolcd_set_intensity(locomolcd_bl_device); |
| 172 | return 0; |
| 173 | } |
Richard Purdie | e442378 | 2006-06-26 00:26:27 -0700 | [diff] [blame] | 174 | #endif |
| 175 | |
Jingoo Han | 5a3778e | 2013-04-29 16:17:45 -0700 | [diff] [blame] | 176 | static SIMPLE_DEV_PM_OPS(locomolcd_pm_ops, locomolcd_suspend, locomolcd_resume); |
| 177 | |
Richard Purdie | 8d48427 | 2006-09-25 20:11:48 +0100 | [diff] [blame] | 178 | static int locomolcd_probe(struct locomo_dev *ldev) |
Pavel Machek | 987132b | 2005-09-06 15:16:45 -0700 | [diff] [blame] | 179 | { |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 180 | struct backlight_properties props; |
Pavel Machek | 987132b | 2005-09-06 15:16:45 -0700 | [diff] [blame] | 181 | unsigned long flags; |
| 182 | |
| 183 | local_irq_save(flags); |
Richard Purdie | 8d48427 | 2006-09-25 20:11:48 +0100 | [diff] [blame] | 184 | locomolcd_dev = ldev; |
Pavel Machek | 987132b | 2005-09-06 15:16:45 -0700 | [diff] [blame] | 185 | |
Richard Purdie | 8d48427 | 2006-09-25 20:11:48 +0100 | [diff] [blame] | 186 | locomo_gpio_set_dir(ldev->dev.parent, LOCOMO_GPIO_FL_VR, 0); |
Richard Purdie | e442378 | 2006-06-26 00:26:27 -0700 | [diff] [blame] | 187 | |
Jingoo Han | 9f67675 | 2012-12-18 14:21:18 -0800 | [diff] [blame] | 188 | /* |
| 189 | * the poodle_lcd_power function is called for the first time |
Pavel Machek | 987132b | 2005-09-06 15:16:45 -0700 | [diff] [blame] | 190 | * from fs_initcall, which is before locomo is activated. |
Jingoo Han | 9f67675 | 2012-12-18 14:21:18 -0800 | [diff] [blame] | 191 | * We need to recall poodle_lcd_power here |
| 192 | */ |
Richard Purdie | e442378 | 2006-06-26 00:26:27 -0700 | [diff] [blame] | 193 | if (machine_is_poodle()) |
| 194 | locomolcd_power(1); |
| 195 | |
Pavel Machek | 987132b | 2005-09-06 15:16:45 -0700 | [diff] [blame] | 196 | local_irq_restore(flags); |
Richard Purdie | e442378 | 2006-06-26 00:26:27 -0700 | [diff] [blame] | 197 | |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 198 | memset(&props, 0, sizeof(struct backlight_properties)); |
Matthew Garrett | bb7ca74 | 2011-03-22 16:30:21 -0700 | [diff] [blame] | 199 | props.type = BACKLIGHT_RAW; |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 200 | props.max_brightness = 4; |
| 201 | locomolcd_bl_device = backlight_device_register("locomo-bl", |
| 202 | &ldev->dev, NULL, |
| 203 | &locomobl_data, &props); |
Richard Purdie | e442378 | 2006-06-26 00:26:27 -0700 | [diff] [blame] | 204 | |
Jingoo Han | 9f67675 | 2012-12-18 14:21:18 -0800 | [diff] [blame] | 205 | if (IS_ERR(locomolcd_bl_device)) |
| 206 | return PTR_ERR(locomolcd_bl_device); |
Richard Purdie | e442378 | 2006-06-26 00:26:27 -0700 | [diff] [blame] | 207 | |
| 208 | /* Set up frontlight so that screen is readable */ |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 209 | locomolcd_bl_device->props.brightness = 2; |
Richard Purdie | e442378 | 2006-06-26 00:26:27 -0700 | [diff] [blame] | 210 | locomolcd_set_intensity(locomolcd_bl_device); |
| 211 | |
Pavel Machek | 987132b | 2005-09-06 15:16:45 -0700 | [diff] [blame] | 212 | return 0; |
| 213 | } |
| 214 | |
Richard Purdie | e442378 | 2006-06-26 00:26:27 -0700 | [diff] [blame] | 215 | static int locomolcd_remove(struct locomo_dev *dev) |
Pavel Machek | 987132b | 2005-09-06 15:16:45 -0700 | [diff] [blame] | 216 | { |
| 217 | unsigned long flags; |
Richard Purdie | e442378 | 2006-06-26 00:26:27 -0700 | [diff] [blame] | 218 | |
Richard Purdie | 2a391a1 | 2007-03-07 00:29:33 +0100 | [diff] [blame] | 219 | locomolcd_bl_device->props.brightness = 0; |
| 220 | locomolcd_bl_device->props.power = 0; |
Henrique de Moraes Holschuh | 4437cd1 | 2006-12-08 02:40:49 -0800 | [diff] [blame] | 221 | locomolcd_set_intensity(locomolcd_bl_device); |
| 222 | |
Richard Purdie | e442378 | 2006-06-26 00:26:27 -0700 | [diff] [blame] | 223 | backlight_device_unregister(locomolcd_bl_device); |
Pavel Machek | 987132b | 2005-09-06 15:16:45 -0700 | [diff] [blame] | 224 | local_irq_save(flags); |
| 225 | locomolcd_dev = NULL; |
| 226 | local_irq_restore(flags); |
| 227 | return 0; |
| 228 | } |
| 229 | |
| 230 | static struct locomo_driver poodle_lcd_driver = { |
| 231 | .drv = { |
Jingoo Han | 5a3778e | 2013-04-29 16:17:45 -0700 | [diff] [blame] | 232 | .name = "locomo-backlight", |
| 233 | .pm = &locomolcd_pm_ops, |
Pavel Machek | 987132b | 2005-09-06 15:16:45 -0700 | [diff] [blame] | 234 | }, |
| 235 | .devid = LOCOMO_DEVID_BACKLIGHT, |
Richard Purdie | e442378 | 2006-06-26 00:26:27 -0700 | [diff] [blame] | 236 | .probe = locomolcd_probe, |
| 237 | .remove = locomolcd_remove, |
Pavel Machek | 987132b | 2005-09-06 15:16:45 -0700 | [diff] [blame] | 238 | }; |
| 239 | |
Richard Purdie | e442378 | 2006-06-26 00:26:27 -0700 | [diff] [blame] | 240 | static int __init locomolcd_init(void) |
Pavel Machek | 987132b | 2005-09-06 15:16:45 -0700 | [diff] [blame] | 241 | { |
Paul Gortmaker | beca98c9 | 2012-04-02 18:17:17 -0400 | [diff] [blame] | 242 | return locomo_driver_register(&poodle_lcd_driver); |
Pavel Machek | 987132b | 2005-09-06 15:16:45 -0700 | [diff] [blame] | 243 | } |
Pavel Machek | 987132b | 2005-09-06 15:16:45 -0700 | [diff] [blame] | 244 | |
Richard Purdie | e442378 | 2006-06-26 00:26:27 -0700 | [diff] [blame] | 245 | static void __exit locomolcd_exit(void) |
| 246 | { |
| 247 | locomo_driver_unregister(&poodle_lcd_driver); |
| 248 | } |
| 249 | |
| 250 | module_init(locomolcd_init); |
| 251 | module_exit(locomolcd_exit); |
| 252 | |
Pavel Machek | a253129 | 2010-07-18 14:27:13 +0200 | [diff] [blame] | 253 | MODULE_AUTHOR("John Lenz <lenz@cs.wisc.edu>, Pavel Machek <pavel@ucw.cz>"); |
Richard Purdie | e442378 | 2006-06-26 00:26:27 -0700 | [diff] [blame] | 254 | MODULE_DESCRIPTION("Collie LCD driver"); |
| 255 | MODULE_LICENSE("GPL"); |