File Index
Files and directories
Sign in
FILE

rave-sp-backlight.c

File preview with syntax highlighting.

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