1/*
2 * nvec_paz00: OEM specific driver for Compal PAZ00 based devices
3 *
4 * Copyright (C) 2011 The AC100 Kernel Team <ac100@lists.launchpad.net>
5 *
6 * Authors:  Ilya Petrov <ilya.muromec@gmail.com>
7 *
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License.  See the file "COPYING" in the main directory of this archive
10 * for more details.
11 *
12 */
13
14#include <linux/module.h>
15#include <linux/err.h>
16#include <linux/slab.h>
17#include <linux/leds.h>
18#include <linux/platform_device.h>
19#include "nvec.h"
20
21#define to_nvec_led(led_cdev) \
22	container_of(led_cdev, struct nvec_led, cdev)
23
24#define NVEC_LED_REQ {'\x0d', '\x10', '\x45', '\x10', '\x00'}
25
26#define NVEC_LED_MAX 8
27
28struct nvec_led {
29	struct led_classdev cdev;
30	struct nvec_chip *nvec;
31};
32
33static void nvec_led_brightness_set(struct led_classdev *led_cdev,
34				    enum led_brightness value)
35{
36	struct nvec_led *led = to_nvec_led(led_cdev);
37	unsigned char buf[] = NVEC_LED_REQ;
38
39	buf[4] = value;
40
41	nvec_write_async(led->nvec, buf, sizeof(buf));
42
43	led->cdev.brightness = value;
44
45}
46
47static int nvec_paz00_probe(struct platform_device *pdev)
48{
49	struct nvec_chip *nvec = dev_get_drvdata(pdev->dev.parent);
50	struct nvec_led *led;
51	int ret = 0;
52
53	led = devm_kzalloc(&pdev->dev, sizeof(*led), GFP_KERNEL);
54	if (!led)
55		return -ENOMEM;
56
57	led->cdev.max_brightness = NVEC_LED_MAX;
58
59	led->cdev.brightness_set = nvec_led_brightness_set;
60	led->cdev.name = "paz00-led";
61	led->cdev.flags |= LED_CORE_SUSPENDRESUME;
62	led->nvec = nvec;
63
64	platform_set_drvdata(pdev, led);
65
66	ret = led_classdev_register(&pdev->dev, &led->cdev);
67	if (ret < 0)
68		return ret;
69
70	/* to expose the default value to userspace */
71	led->cdev.brightness = 0;
72
73	return 0;
74}
75
76static int nvec_paz00_remove(struct platform_device *pdev)
77{
78	struct nvec_led *led = platform_get_drvdata(pdev);
79
80	led_classdev_unregister(&led->cdev);
81
82	return 0;
83}
84
85static struct platform_driver nvec_paz00_driver = {
86	.probe  = nvec_paz00_probe,
87	.remove = nvec_paz00_remove,
88	.driver = {
89		.name  = "nvec-paz00",
90	},
91};
92
93module_platform_driver(nvec_paz00_driver);
94
95MODULE_AUTHOR("Ilya Petrov <ilya.muromec@gmail.com>");
96MODULE_DESCRIPTION("Tegra NVEC PAZ00 driver");
97MODULE_LICENSE("GPL");
98MODULE_ALIAS("platform:nvec-paz00");
99