summaryrefslogtreecommitdiffstats
path: root/drivers/video/rave-sp-backlight.c
blob: 877a5feeb62714a773e20cd2061e3d24985eb3b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
 * LCD Backlight driver for RAVE SP
 *
 * Copyright (C) 2018 Zodiac Inflight Innovations
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 */

#include <common.h>
#include <malloc.h>
#include <init.h>
#include <video/backlight.h>
#include <linux/mfd/rave-sp.h>

#define	RAVE_SP_BACKLIGHT_LCD_EN	BIT(7)

static int rave_sp_backlight_set(struct backlight_device *bd, int brightness)
{
	struct rave_sp *sp = bd->dev.priv;
	u8 cmd[] = {
		[0] = RAVE_SP_CMD_SET_BACKLIGHT,
		[1] = 0,
		[2] = brightness ? RAVE_SP_BACKLIGHT_LCD_EN | brightness : 0,
		[3] = 0,
		[4] = 0,
	};

	return rave_sp_exec(sp, cmd, sizeof(cmd), NULL, 0);
}

static int rave_sp_backlight_probe(struct device_d *dev)
{
	struct backlight_device *bd;
	int ret;

	bd = xzalloc(sizeof(*bd));
	bd->dev.priv = dev->parent->priv;
	bd->dev.parent = dev;
	bd->brightness = bd->brightness_cur = bd->brightness_default = 50;
	bd->brightness_max = 100;
	bd->brightness_set = rave_sp_backlight_set;

	ret = backlight_register(bd);
	if (ret) {
		free(bd);
		return ret;
	}

	return 0;
}

static const struct of_device_id rave_sp_backlight_of_match[] = {
	{ .compatible = "zii,rave-sp-backlight" },
	{}
};

static struct driver_d rave_sp_backlight_driver = {
	.name  = "rave-sp-backlight",
	.probe = rave_sp_backlight_probe,
	.of_compatible = DRV_OF_COMPAT(rave_sp_backlight_of_match),
};
device_platform_driver(rave_sp_backlight_driver);