1 /*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved.
7 */
8 #include <linux/kernel.h>
9 #include <linux/module.h>
10 #include <linux/init.h>
11 #include <linux/platform_device.h>
12 #include <linux/leds.h>
13 #include <linux/err.h>
14 #include <linux/io.h>
15
16 #define DRVNAME "sead3-led"
17
18 static struct platform_device *pdev;
19
sead3_pled_set(struct led_classdev * led_cdev,enum led_brightness value)20 static void sead3_pled_set(struct led_classdev *led_cdev,
21 enum led_brightness value)
22 {
23 pr_debug("sead3_pled_set\n");
24 writel(value, (void __iomem *)0xBF000210); /* FIXME */
25 }
26
sead3_fled_set(struct led_classdev * led_cdev,enum led_brightness value)27 static void sead3_fled_set(struct led_classdev *led_cdev,
28 enum led_brightness value)
29 {
30 pr_debug("sead3_fled_set\n");
31 writel(value, (void __iomem *)0xBF000218); /* FIXME */
32 }
33
34 static struct led_classdev sead3_pled = {
35 .name = "sead3::pled",
36 .brightness_set = sead3_pled_set,
37 .flags = LED_CORE_SUSPENDRESUME,
38 };
39
40 static struct led_classdev sead3_fled = {
41 .name = "sead3::fled",
42 .brightness_set = sead3_fled_set,
43 .flags = LED_CORE_SUSPENDRESUME,
44 };
45
sead3_led_probe(struct platform_device * pdev)46 static int sead3_led_probe(struct platform_device *pdev)
47 {
48 int ret;
49
50 ret = led_classdev_register(&pdev->dev, &sead3_pled);
51 if (ret < 0)
52 return ret;
53
54 ret = led_classdev_register(&pdev->dev, &sead3_fled);
55 if (ret < 0)
56 led_classdev_unregister(&sead3_pled);
57
58 return ret;
59 }
60
sead3_led_remove(struct platform_device * pdev)61 static int sead3_led_remove(struct platform_device *pdev)
62 {
63 led_classdev_unregister(&sead3_pled);
64 led_classdev_unregister(&sead3_fled);
65 return 0;
66 }
67
68 static struct platform_driver sead3_led_driver = {
69 .probe = sead3_led_probe,
70 .remove = sead3_led_remove,
71 .driver = {
72 .name = DRVNAME,
73 .owner = THIS_MODULE,
74 },
75 };
76
sead3_led_init(void)77 static int __init sead3_led_init(void)
78 {
79 int ret;
80
81 ret = platform_driver_register(&sead3_led_driver);
82 if (ret < 0)
83 goto out;
84
85 pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0);
86 if (IS_ERR(pdev)) {
87 ret = PTR_ERR(pdev);
88 platform_driver_unregister(&sead3_led_driver);
89 goto out;
90 }
91
92 out:
93 return ret;
94 }
95
sead3_led_exit(void)96 static void __exit sead3_led_exit(void)
97 {
98 platform_device_unregister(pdev);
99 platform_driver_unregister(&sead3_led_driver);
100 }
101
102 module_init(sead3_led_init);
103 module_exit(sead3_led_exit);
104
105 MODULE_AUTHOR("Kristian Kielhofner <kris@krisk.org>");
106 MODULE_DESCRIPTION("SEAD3 LED driver");
107 MODULE_LICENSE("GPL");
108