i2c-eg20t: change timeout value 50msec to 1000msec
[zen-stable.git] / drivers / staging / nvec / nvec_leds.c
blobf4cbcd6250014ce87a7976ffddd82ab52702d1dd
1 /*
2 * nvec_leds: LED driver for a NVIDIA compliant embedded controller
4 * Copyright (C) 2011 The AC100 Kernel Team <ac100@lists.launchpad.net>
6 * Authors: Ilya Petrov <ilya.muromec@gmail.com>
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.
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"
21 #define to_nvec_led(led_cdev) \
22 container_of(led_cdev, struct nvec_led, cdev)
24 #define NVEC_LED_REQ {'\x0d', '\x10', '\x45', '\x10', '\x00'}
26 #define NVEC_LED_MAX 8
28 struct nvec_led {
29 struct led_classdev cdev;
30 struct nvec_chip *nvec;
33 static void nvec_led_brightness_set(struct led_classdev *led_cdev,
34 enum led_brightness value)
36 struct nvec_led *led = to_nvec_led(led_cdev);
37 unsigned char buf[] = NVEC_LED_REQ;
38 buf[4] = value;
40 nvec_write_async(led->nvec, buf, sizeof(buf));
42 led->cdev.brightness = value;
46 static int __devinit nvec_led_probe(struct platform_device *pdev)
48 struct nvec_chip *nvec = dev_get_drvdata(pdev->dev.parent);
49 struct nvec_led *led;
50 int ret = 0;
52 led = kzalloc(sizeof(*led), GFP_KERNEL);
53 if (led == NULL)
54 return -ENOMEM;
56 led->cdev.max_brightness = NVEC_LED_MAX;
58 led->cdev.brightness_set = nvec_led_brightness_set;
59 led->cdev.name = "nvec-led";
60 led->cdev.flags |= LED_CORE_SUSPENDRESUME;
61 led->nvec = nvec;
63 platform_set_drvdata(pdev, led);
65 ret = led_classdev_register(&pdev->dev, &led->cdev);
66 if (ret < 0)
67 goto err_led;
69 /* to expose the default value to userspace */
70 led->cdev.brightness = 0;
72 return 0;
74 err_led:
75 kfree(led);
76 return ret;
79 static int __devexit nvec_led_remove(struct platform_device *pdev)
81 struct nvec_led *led = platform_get_drvdata(pdev);
83 led_classdev_unregister(&led->cdev);
84 kfree(led);
85 return 0;
88 static struct platform_driver nvec_led_driver = {
89 .probe = nvec_led_probe,
90 .remove = __devexit_p(nvec_led_remove),
91 .driver = {
92 .name = "nvec-leds",
93 .owner = THIS_MODULE,
97 static int __init nvec_led_init(void)
99 return platform_driver_register(&nvec_led_driver);
102 module_init(nvec_led_init);
104 static void __exit nvec_led_exit(void)
106 platform_driver_unregister(&nvec_led_driver);
109 module_exit(nvec_led_exit);
111 MODULE_AUTHOR("Ilya Petrov <ilya.muromec@gmail.com>");
112 MODULE_DESCRIPTION("Tegra NVEC LED driver");
113 MODULE_LICENSE("GPL");
114 MODULE_ALIAS("platform:nvec-leds");