aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-pxa/sharpsl_pm.c
diff options
context:
space:
mode:
authorDmitry Eremin-Solenikov <dbaryshkov@gmail.com>2009-03-28 11:18:52 -0400
committerEric Miao <eric.y.miao@gmail.com>2009-06-11 10:20:42 -0400
commitd48898a3c88c1f36a66a8d4e3e45843c3171c548 (patch)
tree149a8f83108a1b8528380ae8630b200ef29e6594 /arch/arm/mach-pxa/sharpsl_pm.c
parent78731d33c1868f4ba43bafcca8dcaf938872c1f2 (diff)
[ARM] pxa/sharpsl_pm: merge pxa-specific code into generic one
As pxa now is the only user of sharpsl_pm we can drop several startup functions into generic code thus dropping several global functions. Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> Signed-off-by: Eric Miao <eric.miao@marvell.com>
Diffstat (limited to 'arch/arm/mach-pxa/sharpsl_pm.c')
-rw-r--r--arch/arm/mach-pxa/sharpsl_pm.c104
1 files changed, 49 insertions, 55 deletions
diff --git a/arch/arm/mach-pxa/sharpsl_pm.c b/arch/arm/mach-pxa/sharpsl_pm.c
index 9d61c4916968..540b567278f5 100644
--- a/arch/arm/mach-pxa/sharpsl_pm.c
+++ b/arch/arm/mach-pxa/sharpsl_pm.c
@@ -15,19 +15,16 @@
15#undef DEBUG 15#undef DEBUG
16 16
17#include <linux/module.h> 17#include <linux/module.h>
18#include <linux/init.h>
19#include <linux/kernel.h> 18#include <linux/kernel.h>
20#include <linux/interrupt.h> 19#include <linux/interrupt.h>
21#include <linux/irq.h> 20#include <linux/irq.h>
22#include <linux/platform_device.h> 21#include <linux/platform_device.h>
23#include <linux/apm-emulation.h> 22#include <linux/apm-emulation.h>
24#include <linux/timer.h> 23#include <linux/timer.h>
25#include <linux/apm_bios.h>
26#include <linux/delay.h> 24#include <linux/delay.h>
27#include <linux/leds.h> 25#include <linux/leds.h>
28#include <linux/suspend.h> 26#include <linux/suspend.h>
29 27
30#include <mach/hardware.h>
31#include <asm/mach-types.h> 28#include <asm/mach-types.h>
32#include <mach/pm.h> 29#include <mach/pm.h>
33#include <mach/pxa2xx-regs.h> 30#include <mach/pxa2xx-regs.h>
@@ -36,6 +33,8 @@
36#include <mach/sharpsl.h> 33#include <mach/sharpsl.h>
37#include <mach/sharpsl_pm.h> 34#include <mach/sharpsl_pm.h>
38 35
36#include "sharpsl.h"
37
39/* 38/*
40 * Constants 39 * Constants
41 */ 40 */
@@ -73,8 +72,8 @@ static void sharpsl_battery_thread(struct work_struct *private_);
73 * Variables 72 * Variables
74 */ 73 */
75struct sharpsl_pm_status sharpsl_pm; 74struct sharpsl_pm_status sharpsl_pm;
76DECLARE_DELAYED_WORK(toggle_charger, sharpsl_charge_toggle); 75static DECLARE_DELAYED_WORK(toggle_charger, sharpsl_charge_toggle);
77DECLARE_DELAYED_WORK(sharpsl_bat, sharpsl_battery_thread); 76static DECLARE_DELAYED_WORK(sharpsl_bat, sharpsl_battery_thread);
78DEFINE_LED_TRIGGER(sharpsl_charge_led_trigger); 77DEFINE_LED_TRIGGER(sharpsl_charge_led_trigger);
79 78
80 79
@@ -194,52 +193,6 @@ int sharpsl_pm_pxa_read_max1111(int channel)
194#endif 193#endif
195} 194}
196 195
197void sharpsl_pm_pxa_init(void)
198{
199 pxa_gpio_mode(sharpsl_pm.machinfo->gpio_acin | GPIO_IN);
200 pxa_gpio_mode(sharpsl_pm.machinfo->gpio_batfull | GPIO_IN);
201 pxa_gpio_mode(sharpsl_pm.machinfo->gpio_batlock | GPIO_IN);
202
203 /* Register interrupt handlers */
204 if (request_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_acin), sharpsl_ac_isr, IRQF_DISABLED, "AC Input Detect", sharpsl_ac_isr)) {
205 dev_err(sharpsl_pm.dev, "Could not get irq %d.\n", IRQ_GPIO(sharpsl_pm.machinfo->gpio_acin));
206 }
207 else set_irq_type(IRQ_GPIO(sharpsl_pm.machinfo->gpio_acin),IRQ_TYPE_EDGE_BOTH);
208
209 if (request_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batlock), sharpsl_fatal_isr, IRQF_DISABLED, "Battery Cover", sharpsl_fatal_isr)) {
210 dev_err(sharpsl_pm.dev, "Could not get irq %d.\n", IRQ_GPIO(sharpsl_pm.machinfo->gpio_batlock));
211 }
212 else set_irq_type(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batlock),IRQ_TYPE_EDGE_FALLING);
213
214 if (sharpsl_pm.machinfo->gpio_fatal) {
215 if (request_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_fatal), sharpsl_fatal_isr, IRQF_DISABLED, "Fatal Battery", sharpsl_fatal_isr)) {
216 dev_err(sharpsl_pm.dev, "Could not get irq %d.\n", IRQ_GPIO(sharpsl_pm.machinfo->gpio_fatal));
217 }
218 else set_irq_type(IRQ_GPIO(sharpsl_pm.machinfo->gpio_fatal),IRQ_TYPE_EDGE_FALLING);
219 }
220
221 if (sharpsl_pm.machinfo->batfull_irq)
222 {
223 /* Register interrupt handler. */
224 if (request_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batfull), sharpsl_chrg_full_isr, IRQF_DISABLED, "CO", sharpsl_chrg_full_isr)) {
225 dev_err(sharpsl_pm.dev, "Could not get irq %d.\n", IRQ_GPIO(sharpsl_pm.machinfo->gpio_batfull));
226 }
227 else set_irq_type(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batfull),IRQ_TYPE_EDGE_RISING);
228 }
229}
230
231void sharpsl_pm_pxa_remove(void)
232{
233 free_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_acin), sharpsl_ac_isr);
234 free_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batlock), sharpsl_fatal_isr);
235
236 if (sharpsl_pm.machinfo->gpio_fatal)
237 free_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_fatal), sharpsl_fatal_isr);
238
239 if (sharpsl_pm.machinfo->batfull_irq)
240 free_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batfull), sharpsl_chrg_full_isr);
241}
242
243static int get_percentage(int voltage) 196static int get_percentage(int voltage)
244{ 197{
245 int i = sharpsl_pm.machinfo->bat_levels - 1; 198 int i = sharpsl_pm.machinfo->bat_levels - 1;
@@ -427,7 +380,7 @@ static void sharpsl_ac_timer(unsigned long data)
427} 380}
428 381
429 382
430irqreturn_t sharpsl_ac_isr(int irq, void *dev_id) 383static irqreturn_t sharpsl_ac_isr(int irq, void *dev_id)
431{ 384{
432 /* Delay the event slightly to debounce */ 385 /* Delay the event slightly to debounce */
433 /* Must be a smaller delay than the chrg_full_isr below */ 386 /* Must be a smaller delay than the chrg_full_isr below */
@@ -462,7 +415,7 @@ static void sharpsl_chrg_full_timer(unsigned long data)
462/* Charging Finished Interrupt (Not present on Corgi) */ 415/* Charging Finished Interrupt (Not present on Corgi) */
463/* Can trigger at the same time as an AC status change so 416/* Can trigger at the same time as an AC status change so
464 delay until after that has been processed */ 417 delay until after that has been processed */
465irqreturn_t sharpsl_chrg_full_isr(int irq, void *dev_id) 418static irqreturn_t sharpsl_chrg_full_isr(int irq, void *dev_id)
466{ 419{
467 if (sharpsl_pm.flags & SHARPSL_SUSPENDED) 420 if (sharpsl_pm.flags & SHARPSL_SUSPENDED)
468 return IRQ_HANDLED; 421 return IRQ_HANDLED;
@@ -473,7 +426,7 @@ irqreturn_t sharpsl_chrg_full_isr(int irq, void *dev_id)
473 return IRQ_HANDLED; 426 return IRQ_HANDLED;
474} 427}
475 428
476irqreturn_t sharpsl_fatal_isr(int irq, void *dev_id) 429static irqreturn_t sharpsl_fatal_isr(int irq, void *dev_id)
477{ 430{
478 int is_fatal = 0; 431 int is_fatal = 0;
479 432
@@ -966,6 +919,37 @@ static int __init sharpsl_pm_probe(struct platform_device *pdev)
966 919
967 sharpsl_pm.machinfo->init(); 920 sharpsl_pm.machinfo->init();
968 921
922 pxa_gpio_mode(sharpsl_pm.machinfo->gpio_acin | GPIO_IN);
923 pxa_gpio_mode(sharpsl_pm.machinfo->gpio_batfull | GPIO_IN);
924 pxa_gpio_mode(sharpsl_pm.machinfo->gpio_batlock | GPIO_IN);
925
926 /* Register interrupt handlers */
927 if (request_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_acin), sharpsl_ac_isr, IRQF_DISABLED, "AC Input Detect", sharpsl_ac_isr)) {
928 dev_err(sharpsl_pm.dev, "Could not get irq %d.\n", IRQ_GPIO(sharpsl_pm.machinfo->gpio_acin));
929 }
930 else set_irq_type(IRQ_GPIO(sharpsl_pm.machinfo->gpio_acin),IRQ_TYPE_EDGE_BOTH);
931
932 if (request_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batlock), sharpsl_fatal_isr, IRQF_DISABLED, "Battery Cover", sharpsl_fatal_isr)) {
933 dev_err(sharpsl_pm.dev, "Could not get irq %d.\n", IRQ_GPIO(sharpsl_pm.machinfo->gpio_batlock));
934 }
935 else set_irq_type(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batlock),IRQ_TYPE_EDGE_FALLING);
936
937 if (sharpsl_pm.machinfo->gpio_fatal) {
938 if (request_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_fatal), sharpsl_fatal_isr, IRQF_DISABLED, "Fatal Battery", sharpsl_fatal_isr)) {
939 dev_err(sharpsl_pm.dev, "Could not get irq %d.\n", IRQ_GPIO(sharpsl_pm.machinfo->gpio_fatal));
940 }
941 else set_irq_type(IRQ_GPIO(sharpsl_pm.machinfo->gpio_fatal),IRQ_TYPE_EDGE_FALLING);
942 }
943
944 if (sharpsl_pm.machinfo->batfull_irq)
945 {
946 /* Register interrupt handler. */
947 if (request_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batfull), sharpsl_chrg_full_isr, IRQF_DISABLED, "CO", sharpsl_chrg_full_isr)) {
948 dev_err(sharpsl_pm.dev, "Could not get irq %d.\n", IRQ_GPIO(sharpsl_pm.machinfo->gpio_batfull));
949 }
950 else set_irq_type(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batfull),IRQ_TYPE_EDGE_RISING);
951 }
952
969 ret = device_create_file(&pdev->dev, &dev_attr_battery_percentage); 953 ret = device_create_file(&pdev->dev, &dev_attr_battery_percentage);
970 ret |= device_create_file(&pdev->dev, &dev_attr_battery_voltage); 954 ret |= device_create_file(&pdev->dev, &dev_attr_battery_voltage);
971 if (ret != 0) 955 if (ret != 0)
@@ -991,7 +975,17 @@ static int sharpsl_pm_remove(struct platform_device *pdev)
991 975
992 led_trigger_unregister_simple(sharpsl_charge_led_trigger); 976 led_trigger_unregister_simple(sharpsl_charge_led_trigger);
993 977
994 sharpsl_pm.machinfo->exit(); 978 free_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_acin), sharpsl_ac_isr);
979 free_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batlock), sharpsl_fatal_isr);
980
981 if (sharpsl_pm.machinfo->gpio_fatal)
982 free_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_fatal), sharpsl_fatal_isr);
983
984 if (sharpsl_pm.machinfo->batfull_irq)
985 free_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batfull), sharpsl_chrg_full_isr);
986
987 if (sharpsl_pm.machinfo->exit)
988 sharpsl_pm.machinfo->exit();
995 989
996 del_timer_sync(&sharpsl_pm.chrg_full_timer); 990 del_timer_sync(&sharpsl_pm.chrg_full_timer);
997 del_timer_sync(&sharpsl_pm.ac_timer); 991 del_timer_sync(&sharpsl_pm.ac_timer);