jornada720_bl.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. printk(KERN_ERR "bl : get brightness timeout\n");
  33. jornada_ssp_end();
  34. return -ETIMEDOUT;
  35. } else /* exchange txdummy for value */
  36. ret = jornada_ssp_byte(TXDUMMY);
  37. jornada_ssp_end();
  38. return (BL_MAX_BRIGHT - ret);
  39. }
  40. static int jornada_bl_update_status(struct backlight_device *bd)
  41. {
  42. int ret = 0;
  43. jornada_ssp_start();
  44. /* If backlight is off then really turn it off */
  45. if ((bd->props.power != FB_BLANK_UNBLANK) || (bd->props.fb_blank != FB_BLANK_UNBLANK)) {
  46. ret = jornada_ssp_byte(BRIGHTNESSOFF);
  47. if (ret != TXDUMMY) {
  48. printk(KERN_INFO "bl : brightness off timeout\n");
  49. /* turn off backlight */
  50. PPSR &= ~PPC_LDD1;
  51. PPDR |= PPC_LDD1;
  52. ret = -ETIMEDOUT;
  53. }
  54. } else /* turn on backlight */
  55. PPSR |= PPC_LDD1;
  56. /* send command to our mcu */
  57. if (jornada_ssp_byte(SETBRIGHTNESS) != TXDUMMY) {
  58. printk(KERN_INFO "bl : failed to set brightness\n");
  59. ret = -ETIMEDOUT;
  60. goto out;
  61. }
  62. /* at this point we expect that the mcu has accepted
  63. our command and is waiting for our new value
  64. please note that maximum brightness is 255,
  65. but due to physical layout it is equal to 0, so we simply
  66. invert the value (MAX VALUE - NEW VALUE). */
  67. if (jornada_ssp_byte(BL_MAX_BRIGHT - bd->props.brightness) != TXDUMMY) {
  68. printk(KERN_ERR "bl : set brightness failed\n");
  69. ret = -ETIMEDOUT;
  70. }
  71. /* If infact we get an TXDUMMY as output we are happy and dont
  72. make any further comments about it */
  73. out:
  74. jornada_ssp_end();
  75. return ret;
  76. }
  77. static const struct backlight_ops jornada_bl_ops = {
  78. .get_brightness = jornada_bl_get_brightness,
  79. .update_status = jornada_bl_update_status,
  80. .options = BL_CORE_SUSPENDRESUME,
  81. };
  82. static int jornada_bl_probe(struct platform_device *pdev)
  83. {
  84. struct backlight_properties props;
  85. int ret;
  86. struct backlight_device *bd;
  87. memset(&props, 0, sizeof(struct backlight_properties));
  88. props.type = BACKLIGHT_RAW;
  89. props.max_brightness = BL_MAX_BRIGHT;
  90. bd = backlight_device_register(S1D_DEVICENAME, &pdev->dev, NULL,
  91. &jornada_bl_ops, &props);
  92. if (IS_ERR(bd)) {
  93. ret = PTR_ERR(bd);
  94. printk(KERN_ERR "bl : failed to register device, err=%x\n", ret);
  95. return ret;
  96. }
  97. bd->props.power = FB_BLANK_UNBLANK;
  98. bd->props.brightness = BL_DEF_BRIGHT;
  99. /* note. make sure max brightness is set otherwise
  100. you will get seemingly non-related errors when
  101. trying to change brightness */
  102. jornada_bl_update_status(bd);
  103. platform_set_drvdata(pdev, bd);
  104. printk(KERN_INFO "HP Jornada 700 series backlight driver\n");
  105. return 0;
  106. }
  107. static int jornada_bl_remove(struct platform_device *pdev)
  108. {
  109. struct backlight_device *bd = platform_get_drvdata(pdev);
  110. backlight_device_unregister(bd);
  111. return 0;
  112. }
  113. static struct platform_driver jornada_bl_driver = {
  114. .probe = jornada_bl_probe,
  115. .remove = jornada_bl_remove,
  116. .driver = {
  117. .name = "jornada_bl",
  118. },
  119. };
  120. static int __init jornada_bl_init(void)
  121. {
  122. return platform_driver_register(&jornada_bl_driver);
  123. }
  124. static void __exit jornada_bl_exit(void)
  125. {
  126. platform_driver_unregister(&jornada_bl_driver);
  127. }
  128. MODULE_AUTHOR("Kristoffer Ericson <kristoffer.ericson>");
  129. MODULE_DESCRIPTION("HP Jornada 710/720/728 Backlight driver");
  130. MODULE_LICENSE("GPL");
  131. module_init(jornada_bl_init);
  132. module_exit(jornada_bl_exit);