hp680_bl.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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/platform_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_suspended;
  25. static int current_intensity = 0;
  26. static spinlock_t bl_lock = SPIN_LOCK_UNLOCKED;
  27. static struct backlight_device *hp680_backlight_device;
  28. static void hp680bl_send_intensity(struct backlight_device *bd)
  29. {
  30. unsigned long flags;
  31. u16 v;
  32. int intensity = bd->props->brightness;
  33. if (bd->props->power != FB_BLANK_UNBLANK)
  34. intensity = 0;
  35. if (bd->props->fb_blank != FB_BLANK_UNBLANK)
  36. intensity = 0;
  37. if (hp680bl_suspended)
  38. intensity = 0;
  39. spin_lock_irqsave(&bl_lock, flags);
  40. if (intensity && current_intensity == 0) {
  41. sh_dac_enable(DAC_LCD_BRIGHTNESS);
  42. v = inw(HD64461_GPBDR);
  43. v &= ~HD64461_GPBDR_LCDOFF;
  44. outw(v, HD64461_GPBDR);
  45. sh_dac_output(255-(u8)intensity, DAC_LCD_BRIGHTNESS);
  46. } else if (intensity == 0 && current_intensity != 0) {
  47. sh_dac_output(255-(u8)intensity, DAC_LCD_BRIGHTNESS);
  48. sh_dac_disable(DAC_LCD_BRIGHTNESS);
  49. v = inw(HD64461_GPBDR);
  50. v |= HD64461_GPBDR_LCDOFF;
  51. outw(v, HD64461_GPBDR);
  52. } else if (intensity) {
  53. sh_dac_output(255-(u8)intensity, DAC_LCD_BRIGHTNESS);
  54. }
  55. spin_unlock_irqrestore(&bl_lock, flags);
  56. current_intensity = intensity;
  57. }
  58. #ifdef CONFIG_PM
  59. static int hp680bl_suspend(struct platform_device *dev, pm_message_t state)
  60. {
  61. hp680bl_suspended = 1;
  62. hp680bl_send_intensity(hp680_backlight_device);
  63. return 0;
  64. }
  65. static int hp680bl_resume(struct platform_device *dev)
  66. {
  67. hp680bl_suspended = 0;
  68. hp680bl_send_intensity(hp680_backlight_device);
  69. return 0;
  70. }
  71. #else
  72. #define hp680bl_suspend NULL
  73. #define hp680bl_resume NULL
  74. #endif
  75. static int hp680bl_set_intensity(struct backlight_device *bd)
  76. {
  77. hp680bl_send_intensity(bd);
  78. return 0;
  79. }
  80. static int hp680bl_get_intensity(struct backlight_device *bd)
  81. {
  82. return current_intensity;
  83. }
  84. static struct backlight_properties hp680bl_data = {
  85. .owner = THIS_MODULE,
  86. .max_brightness = HP680_MAX_INTENSITY,
  87. .get_brightness = hp680bl_get_intensity,
  88. .update_status = hp680bl_set_intensity,
  89. };
  90. static int __init hp680bl_probe(struct platform_device *dev)
  91. {
  92. hp680_backlight_device = backlight_device_register ("hp680-bl",
  93. NULL, &hp680bl_data);
  94. if (IS_ERR (hp680_backlight_device))
  95. return PTR_ERR (hp680_backlight_device);
  96. hp680_backlight_device->props->brightness = HP680_DEFAULT_INTENSITY;
  97. hp680bl_send_intensity(hp680_backlight_device);
  98. return 0;
  99. }
  100. static int hp680bl_remove(struct platform_device *dev)
  101. {
  102. backlight_device_unregister(hp680_backlight_device);
  103. return 0;
  104. }
  105. static struct platform_driver hp680bl_driver = {
  106. .probe = hp680bl_probe,
  107. .remove = hp680bl_remove,
  108. .suspend = hp680bl_suspend,
  109. .resume = hp680bl_resume,
  110. .driver = {
  111. .name = "hp680-bl",
  112. },
  113. };
  114. static struct platform_device *hp680bl_device;
  115. static int __init hp680bl_init(void)
  116. {
  117. int ret;
  118. ret = platform_driver_register(&hp680bl_driver);
  119. if (!ret) {
  120. hp680bl_device = platform_device_alloc("hp680-bl", -1);
  121. if (!hp680bl_device)
  122. return -ENOMEM;
  123. ret = platform_device_add(hp680bl_device);
  124. if (ret) {
  125. platform_device_put(hp680bl_device);
  126. platform_driver_unregister(&hp680bl_driver);
  127. }
  128. }
  129. return ret;
  130. }
  131. static void __exit hp680bl_exit(void)
  132. {
  133. platform_device_unregister(hp680bl_device);
  134. platform_driver_unregister(&hp680bl_driver);
  135. }
  136. module_init(hp680bl_init);
  137. module_exit(hp680bl_exit);
  138. MODULE_AUTHOR("Andriy Skulysh <askulysh@image.kiev.ua>");
  139. MODULE_DESCRIPTION("HP Jornada 680 Backlight Driver");
  140. MODULE_LICENSE("GPL");