hp680_bl.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 <mach/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;
  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_SLEEP
  58. static int hp680bl_suspend(struct device *dev)
  59. {
  60. struct backlight_device *bd = dev_get_drvdata(dev);
  61. hp680bl_suspended = 1;
  62. hp680bl_send_intensity(bd);
  63. return 0;
  64. }
  65. static int hp680bl_resume(struct device *dev)
  66. {
  67. struct backlight_device *bd = dev_get_drvdata(dev);
  68. hp680bl_suspended = 0;
  69. hp680bl_send_intensity(bd);
  70. return 0;
  71. }
  72. #endif
  73. static SIMPLE_DEV_PM_OPS(hp680bl_pm_ops, hp680bl_suspend, hp680bl_resume);
  74. static int hp680bl_set_intensity(struct backlight_device *bd)
  75. {
  76. hp680bl_send_intensity(bd);
  77. return 0;
  78. }
  79. static int hp680bl_get_intensity(struct backlight_device *bd)
  80. {
  81. return current_intensity;
  82. }
  83. static const struct backlight_ops hp680bl_ops = {
  84. .get_brightness = hp680bl_get_intensity,
  85. .update_status = hp680bl_set_intensity,
  86. };
  87. static int hp680bl_probe(struct platform_device *pdev)
  88. {
  89. struct backlight_properties props;
  90. struct backlight_device *bd;
  91. memset(&props, 0, sizeof(struct backlight_properties));
  92. props.type = BACKLIGHT_RAW;
  93. props.max_brightness = HP680_MAX_INTENSITY;
  94. bd = devm_backlight_device_register(&pdev->dev, "hp680-bl", &pdev->dev,
  95. NULL, &hp680bl_ops, &props);
  96. if (IS_ERR(bd))
  97. return PTR_ERR(bd);
  98. platform_set_drvdata(pdev, bd);
  99. bd->props.brightness = HP680_DEFAULT_INTENSITY;
  100. hp680bl_send_intensity(bd);
  101. return 0;
  102. }
  103. static int hp680bl_remove(struct platform_device *pdev)
  104. {
  105. struct backlight_device *bd = platform_get_drvdata(pdev);
  106. bd->props.brightness = 0;
  107. bd->props.power = 0;
  108. hp680bl_send_intensity(bd);
  109. return 0;
  110. }
  111. static struct platform_driver hp680bl_driver = {
  112. .probe = hp680bl_probe,
  113. .remove = hp680bl_remove,
  114. .driver = {
  115. .name = "hp680-bl",
  116. .pm = &hp680bl_pm_ops,
  117. },
  118. };
  119. static struct platform_device *hp680bl_device;
  120. static int __init hp680bl_init(void)
  121. {
  122. int ret;
  123. ret = platform_driver_register(&hp680bl_driver);
  124. if (ret)
  125. return ret;
  126. hp680bl_device = platform_device_register_simple("hp680-bl", -1,
  127. NULL, 0);
  128. if (IS_ERR(hp680bl_device)) {
  129. platform_driver_unregister(&hp680bl_driver);
  130. return PTR_ERR(hp680bl_device);
  131. }
  132. return 0;
  133. }
  134. static void __exit hp680bl_exit(void)
  135. {
  136. platform_device_unregister(hp680bl_device);
  137. platform_driver_unregister(&hp680bl_driver);
  138. }
  139. module_init(hp680bl_init);
  140. module_exit(hp680bl_exit);
  141. MODULE_AUTHOR("Andriy Skulysh <askulysh@gmail.com>");
  142. MODULE_DESCRIPTION("HP Jornada 680 Backlight Driver");
  143. MODULE_LICENSE("GPL");