xref: /openbmc/linux/drivers/leds/leds-locomo.c (revision 8fdff1dc)
1 /*
2  * linux/drivers/leds/leds-locomo.c
3  *
4  * Copyright (C) 2005 John Lenz <lenz@cs.wisc.edu>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  */
10 
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/module.h>
14 #include <linux/device.h>
15 #include <linux/leds.h>
16 
17 #include <mach/hardware.h>
18 #include <asm/hardware/locomo.h>
19 
20 static void locomoled_brightness_set(struct led_classdev *led_cdev,
21 				enum led_brightness value, int offset)
22 {
23 	struct locomo_dev *locomo_dev = LOCOMO_DEV(led_cdev->dev->parent);
24 	unsigned long flags;
25 
26 	local_irq_save(flags);
27 	if (value)
28 		locomo_writel(LOCOMO_LPT_TOFH, locomo_dev->mapbase + offset);
29 	else
30 		locomo_writel(LOCOMO_LPT_TOFL, locomo_dev->mapbase + offset);
31 	local_irq_restore(flags);
32 }
33 
34 static void locomoled_brightness_set0(struct led_classdev *led_cdev,
35 				enum led_brightness value)
36 {
37 	locomoled_brightness_set(led_cdev, value, LOCOMO_LPT0);
38 }
39 
40 static void locomoled_brightness_set1(struct led_classdev *led_cdev,
41 				enum led_brightness value)
42 {
43 	locomoled_brightness_set(led_cdev, value, LOCOMO_LPT1);
44 }
45 
46 static struct led_classdev locomo_led0 = {
47 	.name			= "locomo:amber:charge",
48 	.default_trigger	= "main-battery-charging",
49 	.brightness_set		= locomoled_brightness_set0,
50 };
51 
52 static struct led_classdev locomo_led1 = {
53 	.name			= "locomo:green:mail",
54 	.default_trigger	= "nand-disk",
55 	.brightness_set		= locomoled_brightness_set1,
56 };
57 
58 static int locomoled_probe(struct locomo_dev *ldev)
59 {
60 	int ret;
61 
62 	ret = led_classdev_register(&ldev->dev, &locomo_led0);
63 	if (ret < 0)
64 		return ret;
65 
66 	ret = led_classdev_register(&ldev->dev, &locomo_led1);
67 	if (ret < 0)
68 		led_classdev_unregister(&locomo_led0);
69 
70 	return ret;
71 }
72 
73 static int locomoled_remove(struct locomo_dev *dev)
74 {
75 	led_classdev_unregister(&locomo_led0);
76 	led_classdev_unregister(&locomo_led1);
77 	return 0;
78 }
79 
80 static struct locomo_driver locomoled_driver = {
81 	.drv = {
82 		.name = "locomoled"
83 	},
84 	.devid	= LOCOMO_DEVID_LED,
85 	.probe	= locomoled_probe,
86 	.remove	= locomoled_remove,
87 };
88 
89 static int __init locomoled_init(void)
90 {
91 	return locomo_driver_register(&locomoled_driver);
92 }
93 module_init(locomoled_init);
94 
95 MODULE_AUTHOR("John Lenz <lenz@cs.wisc.edu>");
96 MODULE_DESCRIPTION("Locomo LED driver");
97 MODULE_LICENSE("GPL");
98