jornada720_bl.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. *
  4. * Backlight driver for HP Jornada 700 series (710/720/728)
  5. * Copyright (C) 2006-2009 Kristoffer Ericson <kristoffer.ericson@gmail.com>
  6. */
  7. #include <linux/backlight.h>
  8. #include <linux/device.h>
  9. #include <linux/fb.h>
  10. #include <linux/kernel.h>
  11. #include <linux/module.h>
  12. #include <linux/platform_device.h>
  13. #include <mach/jornada720.h>
  14. #include <mach/hardware.h>
  15. #include <video/s1d13xxxfb.h>
  16. #define BL_MAX_BRIGHT 255
  17. #define BL_DEF_BRIGHT 25
  18. static int jornada_bl_get_brightness(struct backlight_device *bd)
  19. {
  20. int ret;
  21. /* check if backlight is on */
  22. if (!(PPSR & PPC_LDD1))
  23. return 0;
  24. jornada_ssp_start();
  25. /* cmd should return txdummy */
  26. ret = jornada_ssp_byte(GETBRIGHTNESS);
  27. if (jornada_ssp_byte(GETBRIGHTNESS) != TXDUMMY) {
  28. dev_err(&bd->dev, "get brightness timeout\n");
  29. jornada_ssp_end();
  30. return -ETIMEDOUT;
  31. }
  32. /* exchange txdummy for value */
  33. ret = jornada_ssp_byte(TXDUMMY);
  34. jornada_ssp_end();
  35. return BL_MAX_BRIGHT - ret;
  36. }
  37. static int jornada_bl_update_status(struct backlight_device *bd)
  38. {
  39. int ret = 0;
  40. jornada_ssp_start();
  41. /* If backlight is off then really turn it off */
  42. if (backlight_is_blank(bd)) {
  43. ret = jornada_ssp_byte(BRIGHTNESSOFF);
  44. if (ret != TXDUMMY) {
  45. dev_info(&bd->dev, "brightness off timeout\n");
  46. /* turn off backlight */
  47. PPSR &= ~PPC_LDD1;
  48. PPDR |= PPC_LDD1;
  49. ret = -ETIMEDOUT;
  50. }
  51. } else /* turn on backlight */
  52. PPSR |= PPC_LDD1;
  53. /* send command to our mcu */
  54. if (jornada_ssp_byte(SETBRIGHTNESS) != TXDUMMY) {
  55. dev_info(&bd->dev, "failed to set brightness\n");
  56. ret = -ETIMEDOUT;
  57. goto out;
  58. }
  59. /*
  60. * at this point we expect that the mcu has accepted
  61. * our command and is waiting for our new value
  62. * please note that maximum brightness is 255,
  63. * but due to physical layout it is equal to 0, so we simply
  64. * invert the value (MAX VALUE - NEW VALUE).
  65. */
  66. if (jornada_ssp_byte(BL_MAX_BRIGHT - bd->props.brightness)
  67. != TXDUMMY) {
  68. dev_err(&bd->dev, "set brightness failed\n");
  69. ret = -ETIMEDOUT;
  70. }
  71. /*
  72. * If infact we get an TXDUMMY as output we are happy and dont
  73. * make any further comments about it
  74. */
  75. out:
  76. jornada_ssp_end();
  77. return ret;
  78. }
  79. static const struct backlight_ops jornada_bl_ops = {
  80. .get_brightness = jornada_bl_get_brightness,
  81. .update_status = jornada_bl_update_status,
  82. .options = BL_CORE_SUSPENDRESUME,
  83. };
  84. static int jornada_bl_probe(struct platform_device *pdev)
  85. {
  86. struct backlight_properties props;
  87. int ret;
  88. struct backlight_device *bd;
  89. memset(&props, 0, sizeof(struct backlight_properties));
  90. props.type = BACKLIGHT_RAW;
  91. props.max_brightness = BL_MAX_BRIGHT;
  92. bd = devm_backlight_device_register(&pdev->dev, S1D_DEVICENAME,
  93. &pdev->dev, NULL, &jornada_bl_ops,
  94. &props);
  95. if (IS_ERR(bd)) {
  96. ret = PTR_ERR(bd);
  97. dev_err(&pdev->dev, "failed to register device, err=%x\n", ret);
  98. return ret;
  99. }
  100. bd->props.power = FB_BLANK_UNBLANK;
  101. bd->props.brightness = BL_DEF_BRIGHT;
  102. /*
  103. * note. make sure max brightness is set otherwise
  104. * you will get seemingly non-related errors when
  105. * trying to change brightness
  106. */
  107. jornada_bl_update_status(bd);
  108. platform_set_drvdata(pdev, bd);
  109. dev_info(&pdev->dev, "HP Jornada 700 series backlight driver\n");
  110. return 0;
  111. }
  112. static struct platform_driver jornada_bl_driver = {
  113. .probe = jornada_bl_probe,
  114. .driver = {
  115. .name = "jornada_bl",
  116. },
  117. };
  118. module_platform_driver(jornada_bl_driver);
  119. MODULE_AUTHOR("Kristoffer Ericson <kristoffer.ericson>");
  120. MODULE_DESCRIPTION("HP Jornada 710/720/728 Backlight driver");
  121. MODULE_LICENSE("GPL");