locomolcd.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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@suse.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 noone is going to retrofit second CPU to
  10. * old PDA.
  11. */
  12. /* LCD power functions */
  13. #include <linux/config.h>
  14. #include <linux/module.h>
  15. #include <linux/init.h>
  16. #include <linux/delay.h>
  17. #include <linux/device.h>
  18. #include <linux/interrupt.h>
  19. #include <asm/hardware/locomo.h>
  20. #include <asm/irq.h>
  21. #ifdef CONFIG_SA1100_COLLIE
  22. #include <asm/arch/collie.h>
  23. #else
  24. #include <asm/arch/poodle.h>
  25. #endif
  26. extern void (*sa1100fb_lcd_power)(int on);
  27. static struct locomo_dev *locomolcd_dev;
  28. static void locomolcd_on(int comadj)
  29. {
  30. locomo_gpio_set_dir(locomolcd_dev, LOCOMO_GPIO_LCD_VSHA_ON, 0);
  31. locomo_gpio_write(locomolcd_dev, LOCOMO_GPIO_LCD_VSHA_ON, 1);
  32. mdelay(2);
  33. locomo_gpio_set_dir(locomolcd_dev, LOCOMO_GPIO_LCD_VSHD_ON, 0);
  34. locomo_gpio_write(locomolcd_dev, 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, LOCOMO_GPIO_LCD_VEE_ON, 0);
  39. locomo_gpio_write(locomolcd_dev, 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, LOCOMO_GPIO_LCD_MOD, 0);
  49. locomo_gpio_write(locomolcd_dev, 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, LOCOMO_GPIO_LCD_VSHA_ON, 0);
  57. mdelay(110);
  58. locomo_gpio_write(locomolcd_dev, 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, LOCOMO_GPIO_LCD_MOD, 0);
  63. locomo_gpio_write(locomolcd_dev, LOCOMO_GPIO_LCD_VSHD_ON, 0);
  64. }
  65. void locomolcd_power(int on)
  66. {
  67. int comadj = 118;
  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. #ifdef CONFIG_MACH_POODLE
  76. comadj = 118;
  77. #else
  78. comadj = 128;
  79. #endif
  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 poodle_lcd_probe(struct locomo_dev *dev)
  88. {
  89. unsigned long flags;
  90. local_irq_save(flags);
  91. locomolcd_dev = dev;
  92. /* the poodle_lcd_power function is called for the first time
  93. * from fs_initcall, which is before locomo is activated.
  94. * We need to recall poodle_lcd_power here*/
  95. #ifdef CONFIG_MACH_POODLE
  96. locomolcd_power(1);
  97. #endif
  98. local_irq_restore(flags);
  99. return 0;
  100. }
  101. static int poodle_lcd_remove(struct locomo_dev *dev)
  102. {
  103. unsigned long flags;
  104. local_irq_save(flags);
  105. locomolcd_dev = NULL;
  106. local_irq_restore(flags);
  107. return 0;
  108. }
  109. static struct locomo_driver poodle_lcd_driver = {
  110. .drv = {
  111. .name = "locomo-backlight",
  112. },
  113. .devid = LOCOMO_DEVID_BACKLIGHT,
  114. .probe = poodle_lcd_probe,
  115. .remove = poodle_lcd_remove,
  116. };
  117. static int __init poodle_lcd_init(void)
  118. {
  119. int ret = locomo_driver_register(&poodle_lcd_driver);
  120. if (ret) return ret;
  121. #ifdef CONFIG_SA1100_COLLIE
  122. sa1100fb_lcd_power = locomolcd_power;
  123. #endif
  124. return 0;
  125. }
  126. device_initcall(poodle_lcd_init);