Merge tag 'trace-v5.11-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt...
[linux/fpc-iii.git] / drivers / video / backlight / rave-sp-backlight.c
blob05b5f003a3d1ab152118b427233b73af142e931c
1 // SPDX-License-Identifier: GPL-2.0+
3 /*
4 * LCD Backlight driver for RAVE SP
6 * Copyright (C) 2018 Zodiac Inflight Innovations
8 */
10 #include <linux/backlight.h>
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/mfd/rave-sp.h>
14 #include <linux/platform_device.h>
16 #define RAVE_SP_BACKLIGHT_LCD_EN BIT(7)
18 static int rave_sp_backlight_update_status(struct backlight_device *bd)
20 const struct backlight_properties *p = &bd->props;
21 const u8 intensity =
22 (p->power == FB_BLANK_UNBLANK) ? p->brightness : 0;
23 struct rave_sp *sp = dev_get_drvdata(&bd->dev);
24 u8 cmd[] = {
25 [0] = RAVE_SP_CMD_SET_BACKLIGHT,
26 [1] = 0,
27 [2] = intensity ? RAVE_SP_BACKLIGHT_LCD_EN | intensity : 0,
28 [3] = 0,
29 [4] = 0,
32 return rave_sp_exec(sp, cmd, sizeof(cmd), NULL, 0);
35 static const struct backlight_ops rave_sp_backlight_ops = {
36 .options = BL_CORE_SUSPENDRESUME,
37 .update_status = rave_sp_backlight_update_status,
40 static struct backlight_properties rave_sp_backlight_props = {
41 .type = BACKLIGHT_PLATFORM,
42 .max_brightness = 100,
43 .brightness = 50,
46 static int rave_sp_backlight_probe(struct platform_device *pdev)
48 struct device *dev = &pdev->dev;
49 struct backlight_device *bd;
51 bd = devm_backlight_device_register(dev, pdev->name, dev,
52 dev_get_drvdata(dev->parent),
53 &rave_sp_backlight_ops,
54 &rave_sp_backlight_props);
55 if (IS_ERR(bd))
56 return PTR_ERR(bd);
59 * If there is a phandle pointing to the device node we can
60 * assume that another device will manage the status changes.
61 * If not we make sure the backlight is in a consistent state.
63 if (!dev->of_node->phandle)
64 backlight_update_status(bd);
66 return 0;
69 static const struct of_device_id rave_sp_backlight_of_match[] = {
70 { .compatible = "zii,rave-sp-backlight" },
74 static struct platform_driver rave_sp_backlight_driver = {
75 .probe = rave_sp_backlight_probe,
76 .driver = {
77 .name = KBUILD_MODNAME,
78 .of_match_table = rave_sp_backlight_of_match,
81 module_platform_driver(rave_sp_backlight_driver);
83 MODULE_DEVICE_TABLE(of, rave_sp_backlight_of_match);
84 MODULE_LICENSE("GPL");
85 MODULE_AUTHOR("Andrey Vostrikov <andrey.vostrikov@cogentembedded.com>");
86 MODULE_AUTHOR("Nikita Yushchenko <nikita.yoush@cogentembedded.com>");
87 MODULE_AUTHOR("Andrey Smirnov <andrew.smirnov@gmail.com>");
88 MODULE_DESCRIPTION("RAVE SP Backlight driver");