1
2
3
4
5
6
7
8
9
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>
15
16#define RAVE_SP_BACKLIGHT_LCD_EN BIT(7)
17
18static int rave_sp_backlight_update_status(struct backlight_device *bd)
19{
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,
30 };
31
32 return rave_sp_exec(sp, cmd, sizeof(cmd), NULL, 0);
33}
34
35static const struct backlight_ops rave_sp_backlight_ops = {
36 .options = BL_CORE_SUSPENDRESUME,
37 .update_status = rave_sp_backlight_update_status,
38};
39
40static struct backlight_properties rave_sp_backlight_props = {
41 .type = BACKLIGHT_PLATFORM,
42 .max_brightness = 100,
43 .brightness = 50,
44};
45
46static int rave_sp_backlight_probe(struct platform_device *pdev)
47{
48 struct device *dev = &pdev->dev;
49 struct backlight_device *bd;
50
51 bd = devm_backlight_device_register(dev, pdev->name, dev->parent,
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);
57
58 backlight_update_status(bd);
59
60 return 0;
61}
62
63static const struct of_device_id rave_sp_backlight_of_match[] = {
64 { .compatible = "zii,rave-sp-backlight" },
65 {}
66};
67
68static struct platform_driver rave_sp_backlight_driver = {
69 .probe = rave_sp_backlight_probe,
70 .driver = {
71 .name = KBUILD_MODNAME,
72 .of_match_table = rave_sp_backlight_of_match,
73 },
74};
75module_platform_driver(rave_sp_backlight_driver);
76
77MODULE_DEVICE_TABLE(of, rave_sp_backlight_of_match);
78MODULE_LICENSE("GPL");
79MODULE_AUTHOR("Andrey Vostrikov <andrey.vostrikov@cogentembedded.com>");
80MODULE_AUTHOR("Nikita Yushchenko <nikita.yoush@cogentembedded.com>");
81MODULE_AUTHOR("Andrey Smirnov <andrew.smirnov@gmail.com>");
82MODULE_DESCRIPTION("RAVE SP Backlight driver");
83