locomolcd.c 5.8 KB

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