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