2 * LED driver for the Openmoko GTA02 GSM phone
4 * (C) 2006-2008 by Openmoko, Inc.
5 * Author: Harald Welte <laforge@openmoko.org>
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.
14 #include <linux/kernel.h>
15 #include <linux/init.h>
16 #include <linux/platform_device.h>
17 #include <linux/leds.h>
18 #include <mach/hardware.h>
19 #include <asm/mach-types.h>
20 #include <mach/gta02.h>
21 #include <plat/regs-timer.h>
22 #include <linux/gta02-shadow.h>
30 struct led_classdev cdev
;
34 struct gta02_led_bundle
37 struct gta02_led_priv led
[MAX_LEDS
];
40 static inline struct gta02_led_priv
*to_priv(struct led_classdev
*led_cdev
)
42 return container_of(led_cdev
, struct gta02_led_priv
, cdev
);
45 static inline struct gta02_led_bundle
*to_bundle(struct led_classdev
*led_cdev
)
47 return dev_get_drvdata(led_cdev
->dev
->parent
);
50 static void gta02led_set(struct led_classdev
*led_cdev
,
51 enum led_brightness value
)
54 struct gta02_led_priv
*lp
= to_priv(led_cdev
);
56 spin_lock_irqsave(&lp
->lock
, flags
);
57 gta02_gpb_setpin(lp
->gpio
, value
? 1 : 0);
58 spin_unlock_irqrestore(&lp
->lock
, flags
);
62 static int gta02led_suspend(struct platform_device
*pdev
, pm_message_t state
)
64 struct gta02_led_bundle
*bundle
= platform_get_drvdata(pdev
);
67 for (i
= 0; i
< bundle
->num_leds
; i
++)
68 led_classdev_suspend(&bundle
->led
[i
].cdev
);
73 static int gta02led_resume(struct platform_device
*pdev
)
75 struct gta02_led_bundle
*bundle
= platform_get_drvdata(pdev
);
78 for (i
= 0; i
< bundle
->num_leds
; i
++)
79 led_classdev_resume(&bundle
->led
[i
].cdev
);
85 static int __init
gta02led_probe(struct platform_device
*pdev
)
88 struct gta02_led_bundle
*bundle
;
90 if (!machine_is_neo1973_gta02())
93 bundle
= kzalloc(sizeof(struct gta02_led_bundle
), GFP_KERNEL
);
96 platform_set_drvdata(pdev
, bundle
);
98 for (i
= 0; i
< pdev
->num_resources
; i
++) {
99 struct gta02_led_priv
*lp
;
105 r
= platform_get_resource(pdev
, 0, i
);
106 if (!r
|| !r
->start
|| !r
->name
)
109 lp
= &bundle
->led
[i
];
112 lp
->cdev
.name
= r
->name
;
113 lp
->cdev
.brightness_set
= gta02led_set
;
119 s3c2410_gpio_cfgpin(lp
->gpio
, S3C2410_GPIO_OUTPUT
);
120 gta02_gpb_add_shadow_gpio(lp
->gpio
);
126 spin_lock_init(&lp
->lock
);
127 rc
= led_classdev_register(&pdev
->dev
, &lp
->cdev
);
130 bundle
->num_leds
= i
;
135 static int gta02led_remove(struct platform_device
*pdev
)
137 struct gta02_led_bundle
*bundle
= platform_get_drvdata(pdev
);
140 for (i
= 0; i
< bundle
->num_leds
; i
++) {
141 struct gta02_led_priv
*lp
= &bundle
->led
[i
];
142 gta02led_set(&lp
->cdev
, 0);
143 led_classdev_unregister(&lp
->cdev
);
146 platform_set_drvdata(pdev
, NULL
);
152 static struct platform_driver gta02led_driver
= {
153 .probe
= gta02led_probe
,
154 .remove
= gta02led_remove
,
156 .suspend
= gta02led_suspend
,
157 .resume
= gta02led_resume
,
164 static int __init
gta02led_init(void)
166 return platform_driver_register(>a02led_driver
);
169 static void __exit
gta02led_exit(void)
171 platform_driver_unregister(>a02led_driver
);
174 module_init(gta02led_init
);
175 module_exit(gta02led_exit
);
177 MODULE_AUTHOR("Harald Welte <laforge@openmoko.org>");
178 MODULE_DESCRIPTION("Openmoko GTA02 LED driver");
179 MODULE_LICENSE("GPL");