blob: 870f5a3789e8375269f9c13b92e1ca78d0e18cf5 [file] [log] [blame]
Kristoffer Ericsond39a7a62008-02-07 10:10:28 +00001/*
2 * LED Triggers Core
3 * For the HP Jornada 620/660/680/690 handhelds
4 *
5 * Copyright 2008 Kristoffer Ericson <kristoffer.ericson@gmail.com>
6 * this driver is based on leds-spitz.c by Richard Purdie.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12
13#include <linux/kernel.h>
14#include <linux/init.h>
15#include <linux/platform_device.h>
16#include <linux/leds.h>
17#include <asm/hd64461.h>
18#include <asm/hp6xx.h>
19
20static void hp6xxled_green_set(struct led_classdev *led_cdev, enum led_brightness value)
21{
22 u8 v8;
23
24 v8 = inb(PKDR);
25 if (value)
26 outb(v8 & (~PKDR_LED_GREEN), PKDR);
27 else
28 outb(v8 | PKDR_LED_GREEN, PKDR);
29}
30
31static void hp6xxled_red_set(struct led_classdev *led_cdev, enum led_brightness value)
32{
33 u16 v16;
34
35 v16 = inw(HD64461_GPBDR);
36 if (value)
37 outw(v16 & (~HD64461_GPBDR_LED_RED), HD64461_GPBDR);
38 else
39 outw(v16 | HD64461_GPBDR_LED_RED, HD64461_GPBDR);
40}
41
42static struct led_classdev hp6xx_red_led = {
43 .name = "hp6xx:red",
44 .default_trigger = "hp6xx-charge",
45 .brightness_set = hp6xxled_red_set,
46};
47
48static struct led_classdev hp6xx_green_led = {
49 .name = "hp6xx:green",
50 .default_trigger = "ide-disk",
51 .brightness_set = hp6xxled_green_set,
52};
53
54#ifdef CONFIG_PM
55static int hp6xxled_suspend(struct platform_device *dev, pm_message_t state)
56{
57 led_classdev_suspend(&hp6xx_red_led);
58 led_classdev_suspend(&hp6xx_green_led);
59 return 0;
60}
61
62static int hp6xxled_resume(struct platform_device *dev)
63{
64 led_classdev_resume(&hp6xx_red_led);
65 led_classdev_resume(&hp6xx_green_led);
66 return 0;
67}
68#endif
69
70static int hp6xxled_probe(struct platform_device *pdev)
71{
72 int ret;
73
74 ret = led_classdev_register(&pdev->dev, &hp6xx_red_led);
75 if (ret < 0)
76 return ret;
77
78 ret = led_classdev_register(&pdev->dev, &hp6xx_green_led);
79 if (ret < 0)
80 led_classdev_unregister(&hp6xx_red_led);
81
82 return ret;
83}
84
85static int hp6xxled_remove(struct platform_device *pdev)
86{
87 led_classdev_unregister(&hp6xx_red_led);
88 led_classdev_unregister(&hp6xx_green_led);
89
90 return 0;
91}
92
Kay Sievers3c4ded92008-04-15 14:34:30 -070093/* work with hotplug and coldplug */
94MODULE_ALIAS("platform:hp6xx-led");
95
Kristoffer Ericsond39a7a62008-02-07 10:10:28 +000096static struct platform_driver hp6xxled_driver = {
97 .probe = hp6xxled_probe,
98 .remove = hp6xxled_remove,
99#ifdef CONFIG_PM
100 .suspend = hp6xxled_suspend,
101 .resume = hp6xxled_resume,
102#endif
103 .driver = {
104 .name = "hp6xx-led",
Kay Sievers3c4ded92008-04-15 14:34:30 -0700105 .owner = THIS_MODULE,
Kristoffer Ericsond39a7a62008-02-07 10:10:28 +0000106 },
107};
108
109static int __init hp6xxled_init(void)
110{
111 return platform_driver_register(&hp6xxled_driver);
112}
113
114static void __exit hp6xxled_exit(void)
115{
116 platform_driver_unregister(&hp6xxled_driver);
117}
118
119module_init(hp6xxled_init);
120module_exit(hp6xxled_exit);
121
122MODULE_AUTHOR("Kristoffer Ericson <kristoffer.ericson@gmail.com>");
123MODULE_DESCRIPTION("HP Jornada 6xx LED driver");
124MODULE_LICENSE("GPL");