rave-sp-backlight.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * LCD Backlight driver for RAVE SP
  4. *
  5. * Copyright (C) 2018 Zodiac Inflight Innovations
  6. *
  7. */
  8. #include <linux/backlight.h>
  9. #include <linux/kernel.h>
  10. #include <linux/mod_devicetable.h>
  11. #include <linux/module.h>
  12. #include <linux/mfd/rave-sp.h>
  13. #include <linux/of.h>
  14. #include <linux/platform_device.h>
  15. #define RAVE_SP_BACKLIGHT_LCD_EN BIT(7)
  16. static int rave_sp_backlight_update_status(struct backlight_device *bd)
  17. {
  18. const struct backlight_properties *p = &bd->props;
  19. const u8 intensity =
  20. (p->power == BACKLIGHT_POWER_ON) ? p->brightness : 0;
  21. struct rave_sp *sp = dev_get_drvdata(&bd->dev);
  22. u8 cmd[] = {
  23. [0] = RAVE_SP_CMD_SET_BACKLIGHT,
  24. [1] = 0,
  25. [2] = intensity ? RAVE_SP_BACKLIGHT_LCD_EN | intensity : 0,
  26. [3] = 0,
  27. [4] = 0,
  28. };
  29. return rave_sp_exec(sp, cmd, sizeof(cmd), NULL, 0);
  30. }
  31. static const struct backlight_ops rave_sp_backlight_ops = {
  32. .options = BL_CORE_SUSPENDRESUME,
  33. .update_status = rave_sp_backlight_update_status,
  34. };
  35. static struct backlight_properties rave_sp_backlight_props = {
  36. .type = BACKLIGHT_PLATFORM,
  37. .max_brightness = 100,
  38. .brightness = 50,
  39. };
  40. static int rave_sp_backlight_probe(struct platform_device *pdev)
  41. {
  42. struct device *dev = &pdev->dev;
  43. struct backlight_device *bd;
  44. bd = devm_backlight_device_register(dev, pdev->name, dev,
  45. dev_get_drvdata(dev->parent),
  46. &rave_sp_backlight_ops,
  47. &rave_sp_backlight_props);
  48. if (IS_ERR(bd))
  49. return PTR_ERR(bd);
  50. /*
  51. * If there is a phandle pointing to the device node we can
  52. * assume that another device will manage the status changes.
  53. * If not we make sure the backlight is in a consistent state.
  54. */
  55. if (!dev->of_node->phandle)
  56. backlight_update_status(bd);
  57. return 0;
  58. }
  59. static const struct of_device_id rave_sp_backlight_of_match[] = {
  60. { .compatible = "zii,rave-sp-backlight" },
  61. {}
  62. };
  63. static struct platform_driver rave_sp_backlight_driver = {
  64. .probe = rave_sp_backlight_probe,
  65. .driver = {
  66. .name = KBUILD_MODNAME,
  67. .of_match_table = rave_sp_backlight_of_match,
  68. },
  69. };
  70. module_platform_driver(rave_sp_backlight_driver);
  71. MODULE_DEVICE_TABLE(of, rave_sp_backlight_of_match);
  72. MODULE_LICENSE("GPL");
  73. MODULE_AUTHOR("Andrey Vostrikov <andrey.vostrikov@cogentembedded.com>");
  74. MODULE_AUTHOR("Nikita Yushchenko <nikita.yoush@cogentembedded.com>");
  75. MODULE_AUTHOR("Andrey Smirnov <andrew.smirnov@gmail.com>");
  76. MODULE_DESCRIPTION("RAVE SP Backlight driver");