xref: /linux/drivers/video/backlight/rave-sp-backlight.c (revision bfd5bb6f90af092aa345b15cd78143956a13c2a8)
1 // SPDX-License-Identifier: GPL-2.0+
2 
3 /*
4  * LCD Backlight driver for RAVE SP
5  *
6  * Copyright (C) 2018 Zodiac Inflight Innovations
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 
18 static 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 
35 static const struct backlight_ops rave_sp_backlight_ops = {
36 	.options	= BL_CORE_SUSPENDRESUME,
37 	.update_status	= rave_sp_backlight_update_status,
38 };
39 
40 static struct backlight_properties rave_sp_backlight_props = {
41 	.type		= BACKLIGHT_PLATFORM,
42 	.max_brightness = 100,
43 	.brightness	= 50,
44 };
45 
46 static 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 
63 static const struct of_device_id rave_sp_backlight_of_match[] = {
64 	{ .compatible = "zii,rave-sp-backlight" },
65 	{}
66 };
67 
68 static 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 };
75 module_platform_driver(rave_sp_backlight_driver);
76 
77 MODULE_DEVICE_TABLE(of, rave_sp_backlight_of_match);
78 MODULE_LICENSE("GPL");
79 MODULE_AUTHOR("Andrey Vostrikov <andrey.vostrikov@cogentembedded.com>");
80 MODULE_AUTHOR("Nikita Yushchenko <nikita.yoush@cogentembedded.com>");
81 MODULE_AUTHOR("Andrey Smirnov <andrew.smirnov@gmail.com>");
82 MODULE_DESCRIPTION("RAVE SP Backlight driver");
83