hp680_bl.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 = backlight_get_brightness(bd);
  32. if (hp680bl_suspended)
  33. intensity = 0;
  34. spin_lock_irqsave(&bl_lock, flags);
  35. if (intensity && current_intensity == 0) {
  36. sh_dac_enable(DAC_LCD_BRIGHTNESS);
  37. v = inw(HD64461_GPBDR);
  38. v &= ~HD64461_GPBDR_LCDOFF;
  39. outw(v, HD64461_GPBDR);
  40. sh_dac_output(255-(u8)intensity, DAC_LCD_BRIGHTNESS);
  41. } else if (intensity == 0 && current_intensity != 0) {
  42. sh_dac_output(255-(u8)intensity, DAC_LCD_BRIGHTNESS);
  43. sh_dac_disable(DAC_LCD_BRIGHTNESS);
  44. v = inw(HD64461_GPBDR);
  45. v |= HD64461_GPBDR_LCDOFF;
  46. outw(v, HD64461_GPBDR);
  47. } else if (intensity) {
  48. sh_dac_output(255-(u8)intensity, DAC_LCD_BRIGHTNESS);
  49. }
  50. spin_unlock_irqrestore(&bl_lock, flags);
  51. current_intensity = intensity;
  52. }
  53. #ifdef CONFIG_PM_SLEEP
  54. static int hp680bl_suspend(struct device *dev)
  55. {
  56. struct backlight_device *bd = dev_get_drvdata(dev);
  57. hp680bl_suspended = 1;
  58. hp680bl_send_intensity(bd);
  59. return 0;
  60. }
  61. static int hp680bl_resume(struct device *dev)
  62. {
  63. struct backlight_device *bd = dev_get_drvdata(dev);
  64. hp680bl_suspended = 0;
  65. hp680bl_send_intensity(bd);
  66. return 0;
  67. }
  68. #endif
  69. static SIMPLE_DEV_PM_OPS(hp680bl_pm_ops, hp680bl_suspend, hp680bl_resume);
  70. static int hp680bl_set_intensity(struct backlight_device *bd)
  71. {
  72. hp680bl_send_intensity(bd);
  73. return 0;
  74. }
  75. static int hp680bl_get_intensity(struct backlight_device *bd)
  76. {
  77. return current_intensity;
  78. }
  79. static const struct backlight_ops hp680bl_ops = {
  80. .get_brightness = hp680bl_get_intensity,
  81. .update_status = hp680bl_set_intensity,
  82. };
  83. static int hp680bl_probe(struct platform_device *pdev)
  84. {
  85. struct backlight_properties props;
  86. struct backlight_device *bd;
  87. memset(&props, 0, sizeof(struct backlight_properties));
  88. props.type = BACKLIGHT_RAW;
  89. props.max_brightness = HP680_MAX_INTENSITY;
  90. bd = devm_backlight_device_register(&pdev->dev, "hp680-bl", &pdev->dev,
  91. NULL, &hp680bl_ops, &props);
  92. if (IS_ERR(bd))
  93. return PTR_ERR(bd);
  94. platform_set_drvdata(pdev, bd);
  95. bd->props.brightness = HP680_DEFAULT_INTENSITY;
  96. hp680bl_send_intensity(bd);
  97. return 0;
  98. }
  99. static int hp680bl_remove(struct platform_device *pdev)
  100. {
  101. struct backlight_device *bd = platform_get_drvdata(pdev);
  102. bd->props.brightness = 0;
  103. bd->props.power = 0;
  104. hp680bl_send_intensity(bd);
  105. return 0;
  106. }
  107. static struct platform_driver hp680bl_driver = {
  108. .probe = hp680bl_probe,
  109. .remove = hp680bl_remove,
  110. .driver = {
  111. .name = "hp680-bl",
  112. .pm = &hp680bl_pm_ops,
  113. },
  114. };
  115. static struct platform_device *hp680bl_device;
  116. static int __init hp680bl_init(void)
  117. {
  118. int ret;
  119. ret = platform_driver_register(&hp680bl_driver);
  120. if (ret)
  121. return ret;
  122. hp680bl_device = platform_device_register_simple("hp680-bl", -1,
  123. NULL, 0);
  124. if (IS_ERR(hp680bl_device)) {
  125. platform_driver_unregister(&hp680bl_driver);
  126. return PTR_ERR(hp680bl_device);
  127. }
  128. return 0;
  129. }
  130. static void __exit hp680bl_exit(void)
  131. {
  132. platform_device_unregister(hp680bl_device);
  133. platform_driver_unregister(&hp680bl_driver);
  134. }
  135. module_init(hp680bl_init);
  136. module_exit(hp680bl_exit);
  137. MODULE_AUTHOR("Andriy Skulysh <askulysh@gmail.com>");
  138. MODULE_DESCRIPTION("HP Jornada 680 Backlight Driver");
  139. MODULE_LICENSE("GPL");