ipaq_micro_bl.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License version 2 as
  4. * published by the Free Software Foundation.
  5. *
  6. * iPAQ microcontroller backlight support
  7. * Author : Linus Walleij <linus.walleij@linaro.org>
  8. */
  9. #include <linux/backlight.h>
  10. #include <linux/err.h>
  11. #include <linux/fb.h>
  12. #include <linux/init.h>
  13. #include <linux/mfd/ipaq-micro.h>
  14. #include <linux/module.h>
  15. #include <linux/platform_device.h>
  16. static int micro_bl_update_status(struct backlight_device *bd)
  17. {
  18. struct ipaq_micro *micro = dev_get_drvdata(&bd->dev);
  19. int intensity = bd->props.brightness;
  20. struct ipaq_micro_msg msg = {
  21. .id = MSG_BACKLIGHT,
  22. .tx_len = 3,
  23. };
  24. if (bd->props.power != FB_BLANK_UNBLANK)
  25. intensity = 0;
  26. if (bd->props.state & (BL_CORE_FBBLANK | BL_CORE_SUSPENDED))
  27. intensity = 0;
  28. /*
  29. * Message format:
  30. * Byte 0: backlight instance (usually 1)
  31. * Byte 1: on/off
  32. * Byte 2: intensity, 0-255
  33. */
  34. msg.tx_data[0] = 0x01;
  35. msg.tx_data[1] = intensity > 0 ? 1 : 0;
  36. msg.tx_data[2] = intensity;
  37. return ipaq_micro_tx_msg_sync(micro, &msg);
  38. }
  39. static const struct backlight_ops micro_bl_ops = {
  40. .options = BL_CORE_SUSPENDRESUME,
  41. .update_status = micro_bl_update_status,
  42. };
  43. static struct backlight_properties micro_bl_props = {
  44. .type = BACKLIGHT_RAW,
  45. .max_brightness = 255,
  46. .power = FB_BLANK_UNBLANK,
  47. .brightness = 64,
  48. };
  49. static int micro_backlight_probe(struct platform_device *pdev)
  50. {
  51. struct backlight_device *bd;
  52. struct ipaq_micro *micro = dev_get_drvdata(pdev->dev.parent);
  53. bd = devm_backlight_device_register(&pdev->dev, "ipaq-micro-backlight",
  54. &pdev->dev, micro, &micro_bl_ops,
  55. &micro_bl_props);
  56. if (IS_ERR(bd))
  57. return PTR_ERR(bd);
  58. platform_set_drvdata(pdev, bd);
  59. backlight_update_status(bd);
  60. return 0;
  61. }
  62. static struct platform_driver micro_backlight_device_driver = {
  63. .driver = {
  64. .name = "ipaq-micro-backlight",
  65. },
  66. .probe = micro_backlight_probe,
  67. };
  68. module_platform_driver(micro_backlight_device_driver);
  69. MODULE_LICENSE("GPL v2");
  70. MODULE_DESCRIPTION("driver for iPAQ Atmel micro backlight");
  71. MODULE_ALIAS("platform:ipaq-micro-backlight");