hp680_bl.c 4.0 KB

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