ipaq_micro_bl.c 2.0 KB

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