Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Backlight control code for Sharp Zaurus SL-5500
0004  *
0005  * Copyright 2005 John Lenz <lenz@cs.wisc.edu>
0006  * Maintainer: Pavel Machek <pavel@ucw.cz> (unless John wants to :-)
0007  *
0008  * This driver assumes single CPU. That's okay, because collie is
0009  * slightly old hardware, and no one is going to retrofit second CPU to
0010  * old PDA.
0011  */
0012 
0013 /* LCD power functions */
0014 #include <linux/module.h>
0015 #include <linux/init.h>
0016 #include <linux/delay.h>
0017 #include <linux/device.h>
0018 #include <linux/interrupt.h>
0019 #include <linux/fb.h>
0020 #include <linux/backlight.h>
0021 
0022 #include <asm/hardware/locomo.h>
0023 #include <asm/irq.h>
0024 #include <asm/mach/sharpsl_param.h>
0025 #include <asm/mach-types.h>
0026 
0027 #include "../../../arch/arm/mach-sa1100/generic.h"
0028 
0029 static struct backlight_device *locomolcd_bl_device;
0030 static struct locomo_dev *locomolcd_dev;
0031 static unsigned long locomolcd_flags;
0032 #define LOCOMOLCD_SUSPENDED     0x01
0033 
0034 static void locomolcd_on(int comadj)
0035 {
0036     locomo_gpio_set_dir(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VSHA_ON, 0);
0037     locomo_gpio_write(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VSHA_ON, 1);
0038     mdelay(2);
0039 
0040     locomo_gpio_set_dir(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VSHD_ON, 0);
0041     locomo_gpio_write(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VSHD_ON, 1);
0042     mdelay(2);
0043 
0044     locomo_m62332_senddata(locomolcd_dev, comadj, 0);
0045     mdelay(5);
0046 
0047     locomo_gpio_set_dir(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VEE_ON, 0);
0048     locomo_gpio_write(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VEE_ON, 1);
0049     mdelay(10);
0050 
0051     /* TFTCRST | CPSOUT=0 | CPSEN */
0052     locomo_writel(0x01, locomolcd_dev->mapbase + LOCOMO_TC);
0053 
0054     /* Set CPSD */
0055     locomo_writel(6, locomolcd_dev->mapbase + LOCOMO_CPSD);
0056 
0057     /* TFTCRST | CPSOUT=0 | CPSEN */
0058     locomo_writel((0x04 | 0x01), locomolcd_dev->mapbase + LOCOMO_TC);
0059     mdelay(10);
0060 
0061     locomo_gpio_set_dir(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_MOD, 0);
0062     locomo_gpio_write(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_MOD, 1);
0063 }
0064 
0065 static void locomolcd_off(int comadj)
0066 {
0067     /* TFTCRST=1 | CPSOUT=1 | CPSEN = 0 */
0068     locomo_writel(0x06, locomolcd_dev->mapbase + LOCOMO_TC);
0069     mdelay(1);
0070 
0071     locomo_gpio_write(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VSHA_ON, 0);
0072     mdelay(110);
0073 
0074     locomo_gpio_write(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VEE_ON, 0);
0075     mdelay(700);
0076 
0077     /* TFTCRST=0 | CPSOUT=0 | CPSEN = 0 */
0078     locomo_writel(0, locomolcd_dev->mapbase + LOCOMO_TC);
0079     locomo_gpio_write(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_MOD, 0);
0080     locomo_gpio_write(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VSHD_ON, 0);
0081 }
0082 
0083 void locomolcd_power(int on)
0084 {
0085     int comadj = sharpsl_param.comadj;
0086     unsigned long flags;
0087 
0088     local_irq_save(flags);
0089 
0090     if (!locomolcd_dev) {
0091         local_irq_restore(flags);
0092         return;
0093     }
0094 
0095     /* read comadj */
0096     if (comadj == -1 && machine_is_collie())
0097         comadj = 128;
0098     if (comadj == -1 && machine_is_poodle())
0099         comadj = 118;
0100 
0101     if (on)
0102         locomolcd_on(comadj);
0103     else
0104         locomolcd_off(comadj);
0105 
0106     local_irq_restore(flags);
0107 }
0108 EXPORT_SYMBOL(locomolcd_power);
0109 
0110 static int current_intensity;
0111 
0112 static int locomolcd_set_intensity(struct backlight_device *bd)
0113 {
0114     int intensity = backlight_get_brightness(bd);
0115 
0116     if (locomolcd_flags & LOCOMOLCD_SUSPENDED)
0117         intensity = 0;
0118 
0119     switch (intensity) {
0120     /*
0121      * AC and non-AC are handled differently,
0122      * but produce same results in sharp code?
0123      */
0124     case 0:
0125         locomo_frontlight_set(locomolcd_dev, 0, 0, 161);
0126         break;
0127     case 1:
0128         locomo_frontlight_set(locomolcd_dev, 117, 0, 161);
0129         break;
0130     case 2:
0131         locomo_frontlight_set(locomolcd_dev, 163, 0, 148);
0132         break;
0133     case 3:
0134         locomo_frontlight_set(locomolcd_dev, 194, 0, 161);
0135         break;
0136     case 4:
0137         locomo_frontlight_set(locomolcd_dev, 194, 1, 161);
0138         break;
0139     default:
0140         return -ENODEV;
0141     }
0142     current_intensity = intensity;
0143     return 0;
0144 }
0145 
0146 static int locomolcd_get_intensity(struct backlight_device *bd)
0147 {
0148     return current_intensity;
0149 }
0150 
0151 static const struct backlight_ops locomobl_data = {
0152     .get_brightness = locomolcd_get_intensity,
0153     .update_status  = locomolcd_set_intensity,
0154 };
0155 
0156 #ifdef CONFIG_PM_SLEEP
0157 static int locomolcd_suspend(struct device *dev)
0158 {
0159     locomolcd_flags |= LOCOMOLCD_SUSPENDED;
0160     locomolcd_set_intensity(locomolcd_bl_device);
0161     return 0;
0162 }
0163 
0164 static int locomolcd_resume(struct device *dev)
0165 {
0166     locomolcd_flags &= ~LOCOMOLCD_SUSPENDED;
0167     locomolcd_set_intensity(locomolcd_bl_device);
0168     return 0;
0169 }
0170 #endif
0171 
0172 static SIMPLE_DEV_PM_OPS(locomolcd_pm_ops, locomolcd_suspend, locomolcd_resume);
0173 
0174 static int locomolcd_probe(struct locomo_dev *ldev)
0175 {
0176     struct backlight_properties props;
0177     unsigned long flags;
0178 
0179     local_irq_save(flags);
0180     locomolcd_dev = ldev;
0181 
0182     locomo_gpio_set_dir(ldev->dev.parent, LOCOMO_GPIO_FL_VR, 0);
0183 
0184     /*
0185      * the poodle_lcd_power function is called for the first time
0186      * from fs_initcall, which is before locomo is activated.
0187      * We need to recall poodle_lcd_power here
0188      */
0189     if (machine_is_poodle())
0190         locomolcd_power(1);
0191 
0192     local_irq_restore(flags);
0193 
0194     memset(&props, 0, sizeof(struct backlight_properties));
0195     props.type = BACKLIGHT_RAW;
0196     props.max_brightness = 4;
0197     locomolcd_bl_device = backlight_device_register("locomo-bl",
0198                             &ldev->dev, NULL,
0199                             &locomobl_data, &props);
0200 
0201     if (IS_ERR(locomolcd_bl_device))
0202         return PTR_ERR(locomolcd_bl_device);
0203 
0204     /* Set up frontlight so that screen is readable */
0205     locomolcd_bl_device->props.brightness = 2;
0206     locomolcd_set_intensity(locomolcd_bl_device);
0207 
0208     return 0;
0209 }
0210 
0211 static void locomolcd_remove(struct locomo_dev *dev)
0212 {
0213     unsigned long flags;
0214 
0215     locomolcd_bl_device->props.brightness = 0;
0216     locomolcd_bl_device->props.power = 0;
0217     locomolcd_set_intensity(locomolcd_bl_device);
0218 
0219     backlight_device_unregister(locomolcd_bl_device);
0220     local_irq_save(flags);
0221     locomolcd_dev = NULL;
0222     local_irq_restore(flags);
0223 }
0224 
0225 static struct locomo_driver poodle_lcd_driver = {
0226     .drv = {
0227         .name   = "locomo-backlight",
0228         .pm = &locomolcd_pm_ops,
0229     },
0230     .devid  = LOCOMO_DEVID_BACKLIGHT,
0231     .probe  = locomolcd_probe,
0232     .remove = locomolcd_remove,
0233 };
0234 
0235 static int __init locomolcd_init(void)
0236 {
0237     return locomo_driver_register(&poodle_lcd_driver);
0238 }
0239 
0240 static void __exit locomolcd_exit(void)
0241 {
0242     locomo_driver_unregister(&poodle_lcd_driver);
0243 }
0244 
0245 module_init(locomolcd_init);
0246 module_exit(locomolcd_exit);
0247 
0248 MODULE_AUTHOR("John Lenz <lenz@cs.wisc.edu>, Pavel Machek <pavel@ucw.cz>");
0249 MODULE_DESCRIPTION("Collie LCD driver");
0250 MODULE_LICENSE("GPL");