hp680_bl.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. * Backlight Driver for HP Jornada 680
  3. *
  4. * Copyright (c) 2005 Andriy Skulysh
  5. *
  6. * Based on Sharp's Corgi Backlight Driver
  7. *
  8. * This file is subject to the terms and conditions of the GNU General Public
  9. * License. See the file "COPYING" in the main directory of this archive
  10. * for more details.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/kernel.h>
  14. #include <linux/init.h>
  15. #include <linux/device.h>
  16. #include <linux/spinlock.h>
  17. #include <linux/fb.h>
  18. #include <linux/backlight.h>
  19. #include <asm/cpu/dac.h>
  20. #include <asm/hp6xx/hp6xx.h>
  21. #include <asm/hd64461/hd64461.h>
  22. #define HP680_MAX_INTENSITY 255
  23. #define HP680_DEFAULT_INTENSITY 10
  24. static int hp680bl_powermode = FB_BLANK_UNBLANK;
  25. static int current_intensity = 0;
  26. static spinlock_t bl_lock = SPIN_LOCK_UNLOCKED;
  27. static void hp680bl_send_intensity(int intensity)
  28. {
  29. unsigned long flags;
  30. if (hp680bl_powermode != FB_BLANK_UNBLANK)
  31. intensity = 0;
  32. spin_lock_irqsave(&bl_lock, flags);
  33. sh_dac_output(255-(u8)intensity, DAC_LCD_BRIGHTNESS);
  34. spin_unlock_irqrestore(&bl_lock, flags);
  35. }
  36. static void hp680bl_blank(int blank)
  37. {
  38. u16 v;
  39. switch(blank) {
  40. case FB_BLANK_NORMAL:
  41. case FB_BLANK_VSYNC_SUSPEND:
  42. case FB_BLANK_HSYNC_SUSPEND:
  43. case FB_BLANK_POWERDOWN:
  44. if (hp680bl_powermode == FB_BLANK_UNBLANK) {
  45. hp680bl_send_intensity(0);
  46. hp680bl_powermode = blank;
  47. sh_dac_disable(DAC_LCD_BRIGHTNESS);
  48. v = inw(HD64461_GPBDR);
  49. v |= HD64461_GPBDR_LCDOFF;
  50. outw(v, HD64461_GPBDR);
  51. }
  52. break;
  53. case FB_BLANK_UNBLANK:
  54. if (hp680bl_powermode != FB_BLANK_UNBLANK) {
  55. sh_dac_enable(DAC_LCD_BRIGHTNESS);
  56. v = inw(HD64461_GPBDR);
  57. v &= ~HD64461_GPBDR_LCDOFF;
  58. outw(v, HD64461_GPBDR);
  59. hp680bl_powermode = blank;
  60. hp680bl_send_intensity(current_intensity);
  61. }
  62. break;
  63. }
  64. }
  65. #ifdef CONFIG_PM
  66. static int hp680bl_suspend(struct device *dev, pm_message_t state, u32 level)
  67. {
  68. if (level == SUSPEND_POWER_DOWN)
  69. hp680bl_blank(FB_BLANK_POWERDOWN);
  70. return 0;
  71. }
  72. static int hp680bl_resume(struct device *dev, u32 level)
  73. {
  74. if (level == RESUME_POWER_ON)
  75. hp680bl_blank(FB_BLANK_UNBLANK);
  76. return 0;
  77. }
  78. #else
  79. #define hp680bl_suspend NULL
  80. #define hp680bl_resume NULL
  81. #endif
  82. static int hp680bl_set_power(struct backlight_device *bd, int state)
  83. {
  84. hp680bl_blank(state);
  85. return 0;
  86. }
  87. static int hp680bl_get_power(struct backlight_device *bd)
  88. {
  89. return hp680bl_powermode;
  90. }
  91. static int hp680bl_set_intensity(struct backlight_device *bd, int intensity)
  92. {
  93. if (intensity > HP680_MAX_INTENSITY)
  94. intensity = HP680_MAX_INTENSITY;
  95. hp680bl_send_intensity(intensity);
  96. current_intensity = intensity;
  97. return 0;
  98. }
  99. static int hp680bl_get_intensity(struct backlight_device *bd)
  100. {
  101. return current_intensity;
  102. }
  103. static struct backlight_properties hp680bl_data = {
  104. .owner = THIS_MODULE,
  105. .get_power = hp680bl_get_power,
  106. .set_power = hp680bl_set_power,
  107. .max_brightness = HP680_MAX_INTENSITY,
  108. .get_brightness = hp680bl_get_intensity,
  109. .set_brightness = hp680bl_set_intensity,
  110. };
  111. static struct backlight_device *hp680_backlight_device;
  112. static int __init hp680bl_probe(struct device *dev)
  113. {
  114. hp680_backlight_device = backlight_device_register ("hp680-bl",
  115. NULL, &hp680bl_data);
  116. if (IS_ERR (hp680_backlight_device))
  117. return PTR_ERR (hp680_backlight_device);
  118. hp680bl_set_intensity(NULL, HP680_DEFAULT_INTENSITY);
  119. return 0;
  120. }
  121. static int hp680bl_remove(struct device *dev)
  122. {
  123. backlight_device_unregister(hp680_backlight_device);
  124. return 0;
  125. }
  126. static struct device_driver hp680bl_driver = {
  127. .name = "hp680-bl",
  128. .bus = &platform_bus_type,
  129. .probe = hp680bl_probe,
  130. .remove = hp680bl_remove,
  131. .suspend = hp680bl_suspend,
  132. .resume = hp680bl_resume,
  133. };
  134. static struct platform_device hp680bl_device = {
  135. .name = "hp680-bl",
  136. .id = -1,
  137. };
  138. static int __init hp680bl_init(void)
  139. {
  140. int ret;
  141. ret=driver_register(&hp680bl_driver);
  142. if (!ret) {
  143. ret = platform_device_register(&hp680bl_device);
  144. if (ret)
  145. driver_unregister(&hp680bl_driver);
  146. }
  147. return ret;
  148. }
  149. static void __exit hp680bl_exit(void)
  150. {
  151. platform_device_unregister(&hp680bl_device);
  152. driver_unregister(&hp680bl_driver);
  153. }
  154. module_init(hp680bl_init);
  155. module_exit(hp680bl_exit);
  156. MODULE_AUTHOR("Andriy Skulysh <askulysh@image.kiev.ua>");
  157. MODULE_DESCRIPTION("HP Jornada 680 Backlight Driver");
  158. MODULE_LICENSE("GPL");