jornada720_bl.c 3.7 KB

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