locomolcd.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. /* AC and non-AC are handled differently, but produce same results in sharp code? */
  99. case 0: locomo_frontlight_set(locomolcd_dev, 0, 0, 161); break;
  100. case 1: locomo_frontlight_set(locomolcd_dev, 117, 0, 161); break;
  101. case 2: locomo_frontlight_set(locomolcd_dev, 163, 0, 148); break;
  102. case 3: locomo_frontlight_set(locomolcd_dev, 194, 0, 161); break;
  103. case 4: locomo_frontlight_set(locomolcd_dev, 194, 1, 161); break;
  104. default:
  105. return -ENODEV;
  106. }
  107. current_intensity = intensity;
  108. return 0;
  109. }
  110. static int locomolcd_get_intensity(struct backlight_device *bd)
  111. {
  112. return current_intensity;
  113. }
  114. static const struct backlight_ops locomobl_data = {
  115. .get_brightness = locomolcd_get_intensity,
  116. .update_status = locomolcd_set_intensity,
  117. };
  118. #ifdef CONFIG_PM
  119. static int locomolcd_suspend(struct locomo_dev *dev, pm_message_t state)
  120. {
  121. locomolcd_flags |= LOCOMOLCD_SUSPENDED;
  122. locomolcd_set_intensity(locomolcd_bl_device);
  123. return 0;
  124. }
  125. static int locomolcd_resume(struct locomo_dev *dev)
  126. {
  127. locomolcd_flags &= ~LOCOMOLCD_SUSPENDED;
  128. locomolcd_set_intensity(locomolcd_bl_device);
  129. return 0;
  130. }
  131. #else
  132. #define locomolcd_suspend NULL
  133. #define locomolcd_resume NULL
  134. #endif
  135. static int locomolcd_probe(struct locomo_dev *ldev)
  136. {
  137. struct backlight_properties props;
  138. unsigned long flags;
  139. local_irq_save(flags);
  140. locomolcd_dev = ldev;
  141. locomo_gpio_set_dir(ldev->dev.parent, LOCOMO_GPIO_FL_VR, 0);
  142. /* the poodle_lcd_power function is called for the first time
  143. * from fs_initcall, which is before locomo is activated.
  144. * We need to recall poodle_lcd_power here*/
  145. if (machine_is_poodle())
  146. locomolcd_power(1);
  147. local_irq_restore(flags);
  148. memset(&props, 0, sizeof(struct backlight_properties));
  149. props.type = BACKLIGHT_RAW;
  150. props.max_brightness = 4;
  151. locomolcd_bl_device = backlight_device_register("locomo-bl",
  152. &ldev->dev, NULL,
  153. &locomobl_data, &props);
  154. if (IS_ERR (locomolcd_bl_device))
  155. return PTR_ERR (locomolcd_bl_device);
  156. /* Set up frontlight so that screen is readable */
  157. locomolcd_bl_device->props.brightness = 2;
  158. locomolcd_set_intensity(locomolcd_bl_device);
  159. return 0;
  160. }
  161. static int locomolcd_remove(struct locomo_dev *dev)
  162. {
  163. unsigned long flags;
  164. locomolcd_bl_device->props.brightness = 0;
  165. locomolcd_bl_device->props.power = 0;
  166. locomolcd_set_intensity(locomolcd_bl_device);
  167. backlight_device_unregister(locomolcd_bl_device);
  168. local_irq_save(flags);
  169. locomolcd_dev = NULL;
  170. local_irq_restore(flags);
  171. return 0;
  172. }
  173. static struct locomo_driver poodle_lcd_driver = {
  174. .drv = {
  175. .name = "locomo-backlight",
  176. },
  177. .devid = LOCOMO_DEVID_BACKLIGHT,
  178. .probe = locomolcd_probe,
  179. .remove = locomolcd_remove,
  180. .suspend = locomolcd_suspend,
  181. .resume = locomolcd_resume,
  182. };
  183. static int __init locomolcd_init(void)
  184. {
  185. int ret = locomo_driver_register(&poodle_lcd_driver);
  186. if (ret)
  187. return ret;
  188. #ifdef CONFIG_SA1100_COLLIE
  189. sa1100fb_lcd_power = locomolcd_power;
  190. #endif
  191. return 0;
  192. }
  193. static void __exit locomolcd_exit(void)
  194. {
  195. locomo_driver_unregister(&poodle_lcd_driver);
  196. }
  197. module_init(locomolcd_init);
  198. module_exit(locomolcd_exit);
  199. MODULE_AUTHOR("John Lenz <lenz@cs.wisc.edu>, Pavel Machek <pavel@ucw.cz>");
  200. MODULE_DESCRIPTION("Collie LCD driver");
  201. MODULE_LICENSE("GPL");