locomolcd.c 6.1 KB

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