rave-sp-backlight.c 2.3 KB

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