locomolcd.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /*
  2. * Backlight control code for Sharp Zaurus SL-5500
  3. *
  4. * Copyright 2005 John Lenz <lenz@cs.wisc.edu>
  5. * Maintainer: Pavel Machek <pavel@ucw.cz> (unless John wants to :-)
  6. * GPL v2
  7. *
  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.
  11. */
  12. /* LCD power functions */
  13. #include <linux/module.h>
  14. #include <linux/init.h>
  15. #include <linux/delay.h>
  16. #include <linux/device.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/fb.h>
  19. #include <linux/backlight.h>
  20. #include <asm/hardware/locomo.h>
  21. #include <asm/irq.h>
  22. #include <asm/mach/sharpsl_param.h>
  23. #include <asm/mach-types.h>
  24. #include "../../../arch/arm/mach-sa1100/generic.h"
  25. static struct backlight_device *locomolcd_bl_device;
  26. static struct locomo_dev *locomolcd_dev;
  27. static unsigned long locomolcd_flags;
  28. #define LOCOMOLCD_SUSPENDED 0x01
  29. static void locomolcd_on(int comadj)
  30. {
  31. locomo_gpio_set_dir(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VSHA_ON, 0);
  32. locomo_gpio_write(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VSHA_ON, 1);
  33. mdelay(2);
  34. locomo_gpio_set_dir(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VSHD_ON, 0);
  35. locomo_gpio_write(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VSHD_ON, 1);
  36. mdelay(2);
  37. locomo_m62332_senddata(locomolcd_dev, comadj, 0);
  38. mdelay(5);
  39. locomo_gpio_set_dir(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VEE_ON, 0);
  40. locomo_gpio_write(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VEE_ON, 1);
  41. mdelay(10);
  42. /* TFTCRST | CPSOUT=0 | CPSEN */
  43. locomo_writel(0x01, locomolcd_dev->mapbase + LOCOMO_TC);
  44. /* Set CPSD */
  45. locomo_writel(6, locomolcd_dev->mapbase + LOCOMO_CPSD);
  46. /* TFTCRST | CPSOUT=0 | CPSEN */
  47. locomo_writel((0x04 | 0x01), locomolcd_dev->mapbase + LOCOMO_TC);
  48. mdelay(10);
  49. locomo_gpio_set_dir(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_MOD, 0);
  50. locomo_gpio_write(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_MOD, 1);
  51. }
  52. static void locomolcd_off(int comadj)
  53. {
  54. /* TFTCRST=1 | CPSOUT=1 | CPSEN = 0 */
  55. locomo_writel(0x06, locomolcd_dev->mapbase + LOCOMO_TC);
  56. mdelay(1);
  57. locomo_gpio_write(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VSHA_ON, 0);
  58. mdelay(110);
  59. locomo_gpio_write(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VEE_ON, 0);
  60. mdelay(700);
  61. /* TFTCRST=0 | CPSOUT=0 | CPSEN = 0 */
  62. locomo_writel(0, locomolcd_dev->mapbase + LOCOMO_TC);
  63. locomo_gpio_write(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_MOD, 0);
  64. locomo_gpio_write(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VSHD_ON, 0);
  65. }
  66. void locomolcd_power(int on)
  67. {
  68. int comadj = sharpsl_param.comadj;
  69. unsigned long flags;
  70. local_irq_save(flags);
  71. if (!locomolcd_dev) {
  72. local_irq_restore(flags);
  73. return;
  74. }
  75. /* read comadj */
  76. if (comadj == -1 && machine_is_collie())
  77. comadj = 128;
  78. if (comadj == -1 && machine_is_poodle())
  79. comadj = 118;
  80. if (on)
  81. locomolcd_on(comadj);
  82. else
  83. locomolcd_off(comadj);
  84. local_irq_restore(flags);
  85. }
  86. EXPORT_SYMBOL(locomolcd_power);
  87. static int current_intensity;
  88. static int locomolcd_set_intensity(struct backlight_device *bd)
  89. {
  90. int intensity = bd->props.brightness;
  91. if (bd->props.power != FB_BLANK_UNBLANK)
  92. intensity = 0;
  93. if (bd->props.fb_blank != FB_BLANK_UNBLANK)
  94. intensity = 0;
  95. if (locomolcd_flags & LOCOMOLCD_SUSPENDED)
  96. intensity = 0;
  97. switch (intensity) {
  98. /*
  99. * AC and non-AC are handled differently,
  100. * but produce same results in sharp code?
  101. */
  102. case 0:
  103. locomo_frontlight_set(locomolcd_dev, 0, 0, 161);
  104. break;
  105. case 1:
  106. locomo_frontlight_set(locomolcd_dev, 117, 0, 161);
  107. break;
  108. case 2:
  109. locomo_frontlight_set(locomolcd_dev, 163, 0, 148);
  110. break;
  111. case 3:
  112. locomo_frontlight_set(locomolcd_dev, 194, 0, 161);
  113. break;
  114. case 4:
  115. locomo_frontlight_set(locomolcd_dev, 194, 1, 161);
  116. break;
  117. default:
  118. return -ENODEV;
  119. }
  120. current_intensity = intensity;
  121. return 0;
  122. }
  123. static int locomolcd_get_intensity(struct backlight_device *bd)
  124. {
  125. return current_intensity;
  126. }
  127. static const struct backlight_ops locomobl_data = {
  128. .get_brightness = locomolcd_get_intensity,
  129. .update_status = locomolcd_set_intensity,
  130. };
  131. #ifdef CONFIG_PM_SLEEP
  132. static int locomolcd_suspend(struct device *dev)
  133. {
  134. locomolcd_flags |= LOCOMOLCD_SUSPENDED;
  135. locomolcd_set_intensity(locomolcd_bl_device);
  136. return 0;
  137. }
  138. static int locomolcd_resume(struct device *dev)
  139. {
  140. locomolcd_flags &= ~LOCOMOLCD_SUSPENDED;
  141. locomolcd_set_intensity(locomolcd_bl_device);
  142. return 0;
  143. }
  144. #endif
  145. static SIMPLE_DEV_PM_OPS(locomolcd_pm_ops, locomolcd_suspend, locomolcd_resume);
  146. static int locomolcd_probe(struct locomo_dev *ldev)
  147. {
  148. struct backlight_properties props;
  149. unsigned long flags;
  150. local_irq_save(flags);
  151. locomolcd_dev = ldev;
  152. locomo_gpio_set_dir(ldev->dev.parent, LOCOMO_GPIO_FL_VR, 0);
  153. /*
  154. * the poodle_lcd_power function is called for the first time
  155. * from fs_initcall, which is before locomo is activated.
  156. * We need to recall poodle_lcd_power here
  157. */
  158. if (machine_is_poodle())
  159. locomolcd_power(1);
  160. local_irq_restore(flags);
  161. memset(&props, 0, sizeof(struct backlight_properties));
  162. props.type = BACKLIGHT_RAW;
  163. props.max_brightness = 4;
  164. locomolcd_bl_device = backlight_device_register("locomo-bl",
  165. &ldev->dev, NULL,
  166. &locomobl_data, &props);
  167. if (IS_ERR(locomolcd_bl_device))
  168. return PTR_ERR(locomolcd_bl_device);
  169. /* Set up frontlight so that screen is readable */
  170. locomolcd_bl_device->props.brightness = 2;
  171. locomolcd_set_intensity(locomolcd_bl_device);
  172. return 0;
  173. }
  174. static int locomolcd_remove(struct locomo_dev *dev)
  175. {
  176. unsigned long flags;
  177. locomolcd_bl_device->props.brightness = 0;
  178. locomolcd_bl_device->props.power = 0;
  179. locomolcd_set_intensity(locomolcd_bl_device);
  180. backlight_device_unregister(locomolcd_bl_device);
  181. local_irq_save(flags);
  182. locomolcd_dev = NULL;
  183. local_irq_restore(flags);
  184. return 0;
  185. }
  186. static struct locomo_driver poodle_lcd_driver = {
  187. .drv = {
  188. .name = "locomo-backlight",
  189. .pm = &locomolcd_pm_ops,
  190. },
  191. .devid = LOCOMO_DEVID_BACKLIGHT,
  192. .probe = locomolcd_probe,
  193. .remove = locomolcd_remove,
  194. };
  195. static int __init locomolcd_init(void)
  196. {
  197. return locomo_driver_register(&poodle_lcd_driver);
  198. }
  199. static void __exit locomolcd_exit(void)
  200. {
  201. locomo_driver_unregister(&poodle_lcd_driver);
  202. }
  203. module_init(locomolcd_init);
  204. module_exit(locomolcd_exit);
  205. MODULE_AUTHOR("John Lenz <lenz@cs.wisc.edu>, Pavel Machek <pavel@ucw.cz>");
  206. MODULE_DESCRIPTION("Collie LCD driver");
  207. MODULE_LICENSE("GPL");