jornada720_bl.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. } else {
  36. /* exchange txdummy for value */
  37. ret = jornada_ssp_byte(TXDUMMY);
  38. }
  39. jornada_ssp_end();
  40. return BL_MAX_BRIGHT - ret;
  41. }
  42. static int jornada_bl_update_status(struct backlight_device *bd)
  43. {
  44. int ret = 0;
  45. jornada_ssp_start();
  46. /* If backlight is off then really turn it off */
  47. if ((bd->props.power != FB_BLANK_UNBLANK) || (bd->props.fb_blank != FB_BLANK_UNBLANK)) {
  48. ret = jornada_ssp_byte(BRIGHTNESSOFF);
  49. if (ret != TXDUMMY) {
  50. dev_info(&bd->dev, "brightness off timeout\n");
  51. /* turn off backlight */
  52. PPSR &= ~PPC_LDD1;
  53. PPDR |= PPC_LDD1;
  54. ret = -ETIMEDOUT;
  55. }
  56. } else /* turn on backlight */
  57. PPSR |= PPC_LDD1;
  58. /* send command to our mcu */
  59. if (jornada_ssp_byte(SETBRIGHTNESS) != TXDUMMY) {
  60. dev_info(&bd->dev, "failed to set brightness\n");
  61. ret = -ETIMEDOUT;
  62. goto out;
  63. }
  64. /*
  65. * at this point we expect that the mcu has accepted
  66. * our command and is waiting for our new value
  67. * please note that maximum brightness is 255,
  68. * but due to physical layout it is equal to 0, so we simply
  69. * invert the value (MAX VALUE - NEW VALUE).
  70. */
  71. if (jornada_ssp_byte(BL_MAX_BRIGHT - bd->props.brightness)
  72. != TXDUMMY) {
  73. dev_err(&bd->dev, "set brightness failed\n");
  74. ret = -ETIMEDOUT;
  75. }
  76. /*
  77. * If infact we get an TXDUMMY as output we are happy and dont
  78. * make any further comments about it
  79. */
  80. out:
  81. jornada_ssp_end();
  82. return ret;
  83. }
  84. static const struct backlight_ops jornada_bl_ops = {
  85. .get_brightness = jornada_bl_get_brightness,
  86. .update_status = jornada_bl_update_status,
  87. .options = BL_CORE_SUSPENDRESUME,
  88. };
  89. static int jornada_bl_probe(struct platform_device *pdev)
  90. {
  91. struct backlight_properties props;
  92. int ret;
  93. struct backlight_device *bd;
  94. memset(&props, 0, sizeof(struct backlight_properties));
  95. props.type = BACKLIGHT_RAW;
  96. props.max_brightness = BL_MAX_BRIGHT;
  97. bd = backlight_device_register(S1D_DEVICENAME, &pdev->dev, NULL,
  98. &jornada_bl_ops, &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 int jornada_bl_remove(struct platform_device *pdev)
  117. {
  118. struct backlight_device *bd = platform_get_drvdata(pdev);
  119. backlight_device_unregister(bd);
  120. return 0;
  121. }
  122. static struct platform_driver jornada_bl_driver = {
  123. .probe = jornada_bl_probe,
  124. .remove = jornada_bl_remove,
  125. .driver = {
  126. .name = "jornada_bl",
  127. },
  128. };
  129. module_platform_driver(jornada_bl_driver);
  130. MODULE_AUTHOR("Kristoffer Ericson <kristoffer.ericson>");
  131. MODULE_DESCRIPTION("HP Jornada 710/720/728 Backlight driver");
  132. MODULE_LICENSE("GPL");