diff options
Diffstat (limited to 'arch/arm/common')
-rw-r--r-- | arch/arm/common/Kconfig | 12 | ||||
-rw-r--r-- | arch/arm/common/Makefile | 1 | ||||
-rw-r--r-- | arch/arm/common/clkdev.c | 18 | ||||
-rw-r--r-- | arch/arm/common/gic.c | 8 | ||||
-rw-r--r-- | arch/arm/common/sharpsl_pm.c | 859 | ||||
-rw-r--r-- | arch/arm/common/vic.c | 221 |
6 files changed, 245 insertions, 874 deletions
diff --git a/arch/arm/common/Kconfig b/arch/arm/common/Kconfig index a2cd9beaf37d..4efbb9df0444 100644 --- a/arch/arm/common/Kconfig +++ b/arch/arm/common/Kconfig | |||
@@ -4,6 +4,14 @@ config ARM_GIC | |||
4 | config ARM_VIC | 4 | config ARM_VIC |
5 | bool | 5 | bool |
6 | 6 | ||
7 | config ARM_VIC_NR | ||
8 | int | ||
9 | default 2 | ||
10 | depends on ARM_VIC | ||
11 | help | ||
12 | The maximum number of VICs available in the system, for | ||
13 | power management. | ||
14 | |||
7 | config ICST525 | 15 | config ICST525 |
8 | bool | 16 | bool |
9 | 17 | ||
@@ -27,10 +35,6 @@ config SHARP_LOCOMO | |||
27 | config SHARP_PARAM | 35 | config SHARP_PARAM |
28 | bool | 36 | bool |
29 | 37 | ||
30 | config SHARPSL_PM | ||
31 | bool | ||
32 | select APM_EMULATION | ||
33 | |||
34 | config SHARP_SCOOP | 38 | config SHARP_SCOOP |
35 | bool | 39 | bool |
36 | 40 | ||
diff --git a/arch/arm/common/Makefile b/arch/arm/common/Makefile index 7cb7961d81cb..76be7ff2a7ca 100644 --- a/arch/arm/common/Makefile +++ b/arch/arm/common/Makefile | |||
@@ -12,7 +12,6 @@ obj-$(CONFIG_DMABOUNCE) += dmabounce.o | |||
12 | obj-$(CONFIG_TIMER_ACORN) += time-acorn.o | 12 | obj-$(CONFIG_TIMER_ACORN) += time-acorn.o |
13 | obj-$(CONFIG_SHARP_LOCOMO) += locomo.o | 13 | obj-$(CONFIG_SHARP_LOCOMO) += locomo.o |
14 | obj-$(CONFIG_SHARP_PARAM) += sharpsl_param.o | 14 | obj-$(CONFIG_SHARP_PARAM) += sharpsl_param.o |
15 | obj-$(CONFIG_SHARPSL_PM) += sharpsl_pm.o | ||
16 | obj-$(CONFIG_SHARP_SCOOP) += scoop.o | 15 | obj-$(CONFIG_SHARP_SCOOP) += scoop.o |
17 | obj-$(CONFIG_ARCH_IXP2000) += uengine.o | 16 | obj-$(CONFIG_ARCH_IXP2000) += uengine.o |
18 | obj-$(CONFIG_ARCH_IXP23XX) += uengine.o | 17 | obj-$(CONFIG_ARCH_IXP23XX) += uengine.o |
diff --git a/arch/arm/common/clkdev.c b/arch/arm/common/clkdev.c index 5589444ff437..f37afd9422f3 100644 --- a/arch/arm/common/clkdev.c +++ b/arch/arm/common/clkdev.c | |||
@@ -135,6 +135,24 @@ struct clk_lookup *clkdev_alloc(struct clk *clk, const char *con_id, | |||
135 | } | 135 | } |
136 | EXPORT_SYMBOL(clkdev_alloc); | 136 | EXPORT_SYMBOL(clkdev_alloc); |
137 | 137 | ||
138 | int clk_add_alias(const char *alias, const char *alias_dev_name, char *id, | ||
139 | struct device *dev) | ||
140 | { | ||
141 | struct clk *r = clk_get(dev, id); | ||
142 | struct clk_lookup *l; | ||
143 | |||
144 | if (IS_ERR(r)) | ||
145 | return PTR_ERR(r); | ||
146 | |||
147 | l = clkdev_alloc(r, alias, alias_dev_name); | ||
148 | clk_put(r); | ||
149 | if (!l) | ||
150 | return -ENODEV; | ||
151 | clkdev_add(l); | ||
152 | return 0; | ||
153 | } | ||
154 | EXPORT_SYMBOL(clk_add_alias); | ||
155 | |||
138 | /* | 156 | /* |
139 | * clkdev_drop - remove a clock dynamically allocated | 157 | * clkdev_drop - remove a clock dynamically allocated |
140 | */ | 158 | */ |
diff --git a/arch/arm/common/gic.c b/arch/arm/common/gic.c index c6884ba1d5ed..664c7b8b1ba8 100644 --- a/arch/arm/common/gic.c +++ b/arch/arm/common/gic.c | |||
@@ -109,7 +109,7 @@ static void gic_unmask_irq(unsigned int irq) | |||
109 | } | 109 | } |
110 | 110 | ||
111 | #ifdef CONFIG_SMP | 111 | #ifdef CONFIG_SMP |
112 | static void gic_set_cpu(unsigned int irq, const struct cpumask *mask_val) | 112 | static int gic_set_cpu(unsigned int irq, const struct cpumask *mask_val) |
113 | { | 113 | { |
114 | void __iomem *reg = gic_dist_base(irq) + GIC_DIST_TARGET + (gic_irq(irq) & ~3); | 114 | void __iomem *reg = gic_dist_base(irq) + GIC_DIST_TARGET + (gic_irq(irq) & ~3); |
115 | unsigned int shift = (irq % 4) * 8; | 115 | unsigned int shift = (irq % 4) * 8; |
@@ -122,6 +122,8 @@ static void gic_set_cpu(unsigned int irq, const struct cpumask *mask_val) | |||
122 | val |= 1 << (cpu + shift); | 122 | val |= 1 << (cpu + shift); |
123 | writel(val, reg); | 123 | writel(val, reg); |
124 | spin_unlock(&irq_controller_lock); | 124 | spin_unlock(&irq_controller_lock); |
125 | |||
126 | return 0; | ||
125 | } | 127 | } |
126 | #endif | 128 | #endif |
127 | 129 | ||
@@ -253,9 +255,9 @@ void __cpuinit gic_cpu_init(unsigned int gic_nr, void __iomem *base) | |||
253 | } | 255 | } |
254 | 256 | ||
255 | #ifdef CONFIG_SMP | 257 | #ifdef CONFIG_SMP |
256 | void gic_raise_softirq(cpumask_t cpumask, unsigned int irq) | 258 | void gic_raise_softirq(const struct cpumask *mask, unsigned int irq) |
257 | { | 259 | { |
258 | unsigned long map = *cpus_addr(cpumask); | 260 | unsigned long map = *cpus_addr(*mask); |
259 | 261 | ||
260 | /* this always happens on GIC0 */ | 262 | /* this always happens on GIC0 */ |
261 | writel(map << 16 | irq, gic_data[0].dist_base + GIC_DIST_SOFTINT); | 263 | writel(map << 16 | irq, gic_data[0].dist_base + GIC_DIST_SOFTINT); |
diff --git a/arch/arm/common/sharpsl_pm.c b/arch/arm/common/sharpsl_pm.c deleted file mode 100644 index 140f1d721d50..000000000000 --- a/arch/arm/common/sharpsl_pm.c +++ /dev/null | |||
@@ -1,859 +0,0 @@ | |||
1 | /* | ||
2 | * Battery and Power Management code for the Sharp SL-C7xx and SL-Cxx00 | ||
3 | * series of PDAs | ||
4 | * | ||
5 | * Copyright (c) 2004-2005 Richard Purdie | ||
6 | * | ||
7 | * Based on code written by Sharp for 2.4 kernels | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License version 2 as | ||
11 | * published by the Free Software Foundation. | ||
12 | * | ||
13 | */ | ||
14 | |||
15 | #undef DEBUG | ||
16 | |||
17 | #include <linux/module.h> | ||
18 | #include <linux/timer.h> | ||
19 | #include <linux/init.h> | ||
20 | #include <linux/kernel.h> | ||
21 | #include <linux/apm_bios.h> | ||
22 | #include <linux/delay.h> | ||
23 | #include <linux/interrupt.h> | ||
24 | #include <linux/platform_device.h> | ||
25 | #include <linux/leds.h> | ||
26 | #include <linux/apm-emulation.h> | ||
27 | #include <linux/suspend.h> | ||
28 | |||
29 | #include <mach/hardware.h> | ||
30 | #include <asm/irq.h> | ||
31 | #include <mach/pm.h> | ||
32 | #include <mach/pxa2xx-regs.h> | ||
33 | #include <mach/regs-rtc.h> | ||
34 | #include <mach/sharpsl.h> | ||
35 | #include <asm/hardware/sharpsl_pm.h> | ||
36 | |||
37 | /* | ||
38 | * Constants | ||
39 | */ | ||
40 | #define SHARPSL_CHARGE_ON_TIME_INTERVAL (msecs_to_jiffies(1*60*1000)) /* 1 min */ | ||
41 | #define SHARPSL_CHARGE_FINISH_TIME (msecs_to_jiffies(10*60*1000)) /* 10 min */ | ||
42 | #define SHARPSL_BATCHK_TIME (msecs_to_jiffies(15*1000)) /* 15 sec */ | ||
43 | #define SHARPSL_BATCHK_TIME_SUSPEND (60*10) /* 10 min */ | ||
44 | |||
45 | #define SHARPSL_WAIT_CO_TIME 15 /* 15 sec */ | ||
46 | #define SHARPSL_WAIT_DISCHARGE_ON 100 /* 100 msec */ | ||
47 | #define SHARPSL_CHECK_BATTERY_WAIT_TIME_TEMP 10 /* 10 msec */ | ||
48 | #define SHARPSL_CHECK_BATTERY_WAIT_TIME_VOLT 10 /* 10 msec */ | ||
49 | #define SHARPSL_CHECK_BATTERY_WAIT_TIME_ACIN 10 /* 10 msec */ | ||
50 | #define SHARPSL_CHARGE_WAIT_TIME 15 /* 15 msec */ | ||
51 | #define SHARPSL_CHARGE_CO_CHECK_TIME 5 /* 5 msec */ | ||
52 | #define SHARPSL_CHARGE_RETRY_CNT 1 /* eqv. 10 min */ | ||
53 | |||
54 | /* | ||
55 | * Prototypes | ||
56 | */ | ||
57 | #ifdef CONFIG_PM | ||
58 | static int sharpsl_off_charge_battery(void); | ||
59 | static int sharpsl_check_battery_voltage(void); | ||
60 | static int sharpsl_fatal_check(void); | ||
61 | #endif | ||
62 | static int sharpsl_check_battery_temp(void); | ||
63 | static int sharpsl_ac_check(void); | ||
64 | static int sharpsl_average_value(int ad); | ||
65 | static void sharpsl_average_clear(void); | ||
66 | static void sharpsl_charge_toggle(struct work_struct *private_); | ||
67 | static void sharpsl_battery_thread(struct work_struct *private_); | ||
68 | |||
69 | |||
70 | /* | ||
71 | * Variables | ||
72 | */ | ||
73 | struct sharpsl_pm_status sharpsl_pm; | ||
74 | DECLARE_DELAYED_WORK(toggle_charger, sharpsl_charge_toggle); | ||
75 | DECLARE_DELAYED_WORK(sharpsl_bat, sharpsl_battery_thread); | ||
76 | DEFINE_LED_TRIGGER(sharpsl_charge_led_trigger); | ||
77 | |||
78 | |||
79 | static int get_percentage(int voltage) | ||
80 | { | ||
81 | int i = sharpsl_pm.machinfo->bat_levels - 1; | ||
82 | int bl_status = sharpsl_pm.machinfo->backlight_get_status ? sharpsl_pm.machinfo->backlight_get_status() : 0; | ||
83 | struct battery_thresh *thresh; | ||
84 | |||
85 | if (sharpsl_pm.charge_mode == CHRG_ON) | ||
86 | thresh = bl_status ? sharpsl_pm.machinfo->bat_levels_acin_bl : sharpsl_pm.machinfo->bat_levels_acin; | ||
87 | else | ||
88 | thresh = bl_status ? sharpsl_pm.machinfo->bat_levels_noac_bl : sharpsl_pm.machinfo->bat_levels_noac; | ||
89 | |||
90 | while (i > 0 && (voltage > thresh[i].voltage)) | ||
91 | i--; | ||
92 | |||
93 | return thresh[i].percentage; | ||
94 | } | ||
95 | |||
96 | static int get_apm_status(int voltage) | ||
97 | { | ||
98 | int low_thresh, high_thresh; | ||
99 | |||
100 | if (sharpsl_pm.charge_mode == CHRG_ON) { | ||
101 | high_thresh = sharpsl_pm.machinfo->status_high_acin; | ||
102 | low_thresh = sharpsl_pm.machinfo->status_low_acin; | ||
103 | } else { | ||
104 | high_thresh = sharpsl_pm.machinfo->status_high_noac; | ||
105 | low_thresh = sharpsl_pm.machinfo->status_low_noac; | ||
106 | } | ||
107 | |||
108 | if (voltage >= high_thresh) | ||
109 | return APM_BATTERY_STATUS_HIGH; | ||
110 | if (voltage >= low_thresh) | ||
111 | return APM_BATTERY_STATUS_LOW; | ||
112 | return APM_BATTERY_STATUS_CRITICAL; | ||
113 | } | ||
114 | |||
115 | void sharpsl_battery_kick(void) | ||
116 | { | ||
117 | schedule_delayed_work(&sharpsl_bat, msecs_to_jiffies(125)); | ||
118 | } | ||
119 | EXPORT_SYMBOL(sharpsl_battery_kick); | ||
120 | |||
121 | |||
122 | static void sharpsl_battery_thread(struct work_struct *private_) | ||
123 | { | ||
124 | int voltage, percent, apm_status, i = 0; | ||
125 | |||
126 | if (!sharpsl_pm.machinfo) | ||
127 | return; | ||
128 | |||
129 | sharpsl_pm.battstat.ac_status = (sharpsl_pm.machinfo->read_devdata(SHARPSL_STATUS_ACIN) ? APM_AC_ONLINE : APM_AC_OFFLINE); | ||
130 | |||
131 | /* Corgi cannot confirm when battery fully charged so periodically kick! */ | ||
132 | if (!sharpsl_pm.machinfo->batfull_irq && (sharpsl_pm.charge_mode == CHRG_ON) | ||
133 | && time_after(jiffies, sharpsl_pm.charge_start_time + SHARPSL_CHARGE_ON_TIME_INTERVAL)) | ||
134 | schedule_delayed_work(&toggle_charger, 0); | ||
135 | |||
136 | while(1) { | ||
137 | voltage = sharpsl_pm.machinfo->read_devdata(SHARPSL_BATT_VOLT); | ||
138 | |||
139 | if (voltage > 0) break; | ||
140 | if (i++ > 5) { | ||
141 | voltage = sharpsl_pm.machinfo->bat_levels_noac[0].voltage; | ||
142 | dev_warn(sharpsl_pm.dev, "Warning: Cannot read main battery!\n"); | ||
143 | break; | ||
144 | } | ||
145 | } | ||
146 | |||
147 | voltage = sharpsl_average_value(voltage); | ||
148 | apm_status = get_apm_status(voltage); | ||
149 | percent = get_percentage(voltage); | ||
150 | |||
151 | /* At low battery voltages, the voltage has a tendency to start | ||
152 | creeping back up so we try to avoid this here */ | ||
153 | if ((sharpsl_pm.battstat.ac_status == APM_AC_ONLINE) || (apm_status == APM_BATTERY_STATUS_HIGH) || percent <= sharpsl_pm.battstat.mainbat_percent) { | ||
154 | sharpsl_pm.battstat.mainbat_voltage = voltage; | ||
155 | sharpsl_pm.battstat.mainbat_status = apm_status; | ||
156 | sharpsl_pm.battstat.mainbat_percent = percent; | ||
157 | } | ||
158 | |||
159 | dev_dbg(sharpsl_pm.dev, "Battery: voltage: %d, status: %d, percentage: %d, time: %ld\n", voltage, | ||
160 | sharpsl_pm.battstat.mainbat_status, sharpsl_pm.battstat.mainbat_percent, jiffies); | ||
161 | |||
162 | #ifdef CONFIG_BACKLIGHT_CORGI | ||
163 | /* If battery is low. limit backlight intensity to save power. */ | ||
164 | if ((sharpsl_pm.battstat.ac_status != APM_AC_ONLINE) | ||
165 | && ((sharpsl_pm.battstat.mainbat_status == APM_BATTERY_STATUS_LOW) || | ||
166 | (sharpsl_pm.battstat.mainbat_status == APM_BATTERY_STATUS_CRITICAL))) { | ||
167 | if (!(sharpsl_pm.flags & SHARPSL_BL_LIMIT)) { | ||
168 | sharpsl_pm.machinfo->backlight_limit(1); | ||
169 | sharpsl_pm.flags |= SHARPSL_BL_LIMIT; | ||
170 | } | ||
171 | } else if (sharpsl_pm.flags & SHARPSL_BL_LIMIT) { | ||
172 | sharpsl_pm.machinfo->backlight_limit(0); | ||
173 | sharpsl_pm.flags &= ~SHARPSL_BL_LIMIT; | ||
174 | } | ||
175 | #endif | ||
176 | |||
177 | /* Suspend if critical battery level */ | ||
178 | if ((sharpsl_pm.battstat.ac_status != APM_AC_ONLINE) | ||
179 | && (sharpsl_pm.battstat.mainbat_status == APM_BATTERY_STATUS_CRITICAL) | ||
180 | && !(sharpsl_pm.flags & SHARPSL_APM_QUEUED)) { | ||
181 | sharpsl_pm.flags |= SHARPSL_APM_QUEUED; | ||
182 | dev_err(sharpsl_pm.dev, "Fatal Off\n"); | ||
183 | apm_queue_event(APM_CRITICAL_SUSPEND); | ||
184 | } | ||
185 | |||
186 | schedule_delayed_work(&sharpsl_bat, SHARPSL_BATCHK_TIME); | ||
187 | } | ||
188 | |||
189 | void sharpsl_pm_led(int val) | ||
190 | { | ||
191 | if (val == SHARPSL_LED_ERROR) { | ||
192 | dev_err(sharpsl_pm.dev, "Charging Error!\n"); | ||
193 | } else if (val == SHARPSL_LED_ON) { | ||
194 | dev_dbg(sharpsl_pm.dev, "Charge LED On\n"); | ||
195 | led_trigger_event(sharpsl_charge_led_trigger, LED_FULL); | ||
196 | } else { | ||
197 | dev_dbg(sharpsl_pm.dev, "Charge LED Off\n"); | ||
198 | led_trigger_event(sharpsl_charge_led_trigger, LED_OFF); | ||
199 | } | ||
200 | } | ||
201 | |||
202 | static void sharpsl_charge_on(void) | ||
203 | { | ||
204 | dev_dbg(sharpsl_pm.dev, "Turning Charger On\n"); | ||
205 | |||
206 | sharpsl_pm.full_count = 0; | ||
207 | sharpsl_pm.charge_mode = CHRG_ON; | ||
208 | schedule_delayed_work(&toggle_charger, msecs_to_jiffies(250)); | ||
209 | schedule_delayed_work(&sharpsl_bat, msecs_to_jiffies(500)); | ||
210 | } | ||
211 | |||
212 | static void sharpsl_charge_off(void) | ||
213 | { | ||
214 | dev_dbg(sharpsl_pm.dev, "Turning Charger Off\n"); | ||
215 | |||
216 | sharpsl_pm.machinfo->charge(0); | ||
217 | sharpsl_pm_led(SHARPSL_LED_OFF); | ||
218 | sharpsl_pm.charge_mode = CHRG_OFF; | ||
219 | |||
220 | schedule_delayed_work(&sharpsl_bat, 0); | ||
221 | } | ||
222 | |||
223 | static void sharpsl_charge_error(void) | ||
224 | { | ||
225 | sharpsl_pm_led(SHARPSL_LED_ERROR); | ||
226 | sharpsl_pm.machinfo->charge(0); | ||
227 | sharpsl_pm.charge_mode = CHRG_ERROR; | ||
228 | } | ||
229 | |||
230 | static void sharpsl_charge_toggle(struct work_struct *private_) | ||
231 | { | ||
232 | dev_dbg(sharpsl_pm.dev, "Toogling Charger at time: %lx\n", jiffies); | ||
233 | |||
234 | if (!sharpsl_pm.machinfo->read_devdata(SHARPSL_STATUS_ACIN)) { | ||
235 | sharpsl_charge_off(); | ||
236 | return; | ||
237 | } else if ((sharpsl_check_battery_temp() < 0) || (sharpsl_ac_check() < 0)) { | ||
238 | sharpsl_charge_error(); | ||
239 | return; | ||
240 | } | ||
241 | |||
242 | sharpsl_pm_led(SHARPSL_LED_ON); | ||
243 | sharpsl_pm.machinfo->charge(0); | ||
244 | mdelay(SHARPSL_CHARGE_WAIT_TIME); | ||
245 | sharpsl_pm.machinfo->charge(1); | ||
246 | |||
247 | sharpsl_pm.charge_start_time = jiffies; | ||
248 | } | ||
249 | |||
250 | static void sharpsl_ac_timer(unsigned long data) | ||
251 | { | ||
252 | int acin = sharpsl_pm.machinfo->read_devdata(SHARPSL_STATUS_ACIN); | ||
253 | |||
254 | dev_dbg(sharpsl_pm.dev, "AC Status: %d\n",acin); | ||
255 | |||
256 | sharpsl_average_clear(); | ||
257 | if (acin && (sharpsl_pm.charge_mode != CHRG_ON)) | ||
258 | sharpsl_charge_on(); | ||
259 | else if (sharpsl_pm.charge_mode == CHRG_ON) | ||
260 | sharpsl_charge_off(); | ||
261 | |||
262 | schedule_delayed_work(&sharpsl_bat, 0); | ||
263 | } | ||
264 | |||
265 | |||
266 | irqreturn_t sharpsl_ac_isr(int irq, void *dev_id) | ||
267 | { | ||
268 | /* Delay the event slightly to debounce */ | ||
269 | /* Must be a smaller delay than the chrg_full_isr below */ | ||
270 | mod_timer(&sharpsl_pm.ac_timer, jiffies + msecs_to_jiffies(250)); | ||
271 | |||
272 | return IRQ_HANDLED; | ||
273 | } | ||
274 | |||
275 | static void sharpsl_chrg_full_timer(unsigned long data) | ||
276 | { | ||
277 | dev_dbg(sharpsl_pm.dev, "Charge Full at time: %lx\n", jiffies); | ||
278 | |||
279 | sharpsl_pm.full_count++; | ||
280 | |||
281 | if (!sharpsl_pm.machinfo->read_devdata(SHARPSL_STATUS_ACIN)) { | ||
282 | dev_dbg(sharpsl_pm.dev, "Charge Full: AC removed - stop charging!\n"); | ||
283 | if (sharpsl_pm.charge_mode == CHRG_ON) | ||
284 | sharpsl_charge_off(); | ||
285 | } else if (sharpsl_pm.full_count < 2) { | ||
286 | dev_dbg(sharpsl_pm.dev, "Charge Full: Count too low\n"); | ||
287 | schedule_delayed_work(&toggle_charger, 0); | ||
288 | } else if (time_after(jiffies, sharpsl_pm.charge_start_time + SHARPSL_CHARGE_FINISH_TIME)) { | ||
289 | dev_dbg(sharpsl_pm.dev, "Charge Full: Interrupt generated too slowly - retry.\n"); | ||
290 | schedule_delayed_work(&toggle_charger, 0); | ||
291 | } else { | ||
292 | sharpsl_charge_off(); | ||
293 | sharpsl_pm.charge_mode = CHRG_DONE; | ||
294 | dev_dbg(sharpsl_pm.dev, "Charge Full: Charging Finished\n"); | ||
295 | } | ||
296 | } | ||
297 | |||
298 | /* Charging Finished Interrupt (Not present on Corgi) */ | ||
299 | /* Can trigger at the same time as an AC status change so | ||
300 | delay until after that has been processed */ | ||
301 | irqreturn_t sharpsl_chrg_full_isr(int irq, void *dev_id) | ||
302 | { | ||
303 | if (sharpsl_pm.flags & SHARPSL_SUSPENDED) | ||
304 | return IRQ_HANDLED; | ||
305 | |||
306 | /* delay until after any ac interrupt */ | ||
307 | mod_timer(&sharpsl_pm.chrg_full_timer, jiffies + msecs_to_jiffies(500)); | ||
308 | |||
309 | return IRQ_HANDLED; | ||
310 | } | ||
311 | |||
312 | irqreturn_t sharpsl_fatal_isr(int irq, void *dev_id) | ||
313 | { | ||
314 | int is_fatal = 0; | ||
315 | |||
316 | if (!sharpsl_pm.machinfo->read_devdata(SHARPSL_STATUS_LOCK)) { | ||
317 | dev_err(sharpsl_pm.dev, "Battery now Unlocked! Suspending.\n"); | ||
318 | is_fatal = 1; | ||
319 | } | ||
320 | |||
321 | if (!sharpsl_pm.machinfo->read_devdata(SHARPSL_STATUS_FATAL)) { | ||
322 | dev_err(sharpsl_pm.dev, "Fatal Batt Error! Suspending.\n"); | ||
323 | is_fatal = 1; | ||
324 | } | ||
325 | |||
326 | if (!(sharpsl_pm.flags & SHARPSL_APM_QUEUED) && is_fatal) { | ||
327 | sharpsl_pm.flags |= SHARPSL_APM_QUEUED; | ||
328 | apm_queue_event(APM_CRITICAL_SUSPEND); | ||
329 | } | ||
330 | |||
331 | return IRQ_HANDLED; | ||
332 | } | ||
333 | |||
334 | /* | ||
335 | * Maintain an average of the last 10 readings | ||
336 | */ | ||
337 | #define SHARPSL_CNV_VALUE_NUM 10 | ||
338 | static int sharpsl_ad_index; | ||
339 | |||
340 | static void sharpsl_average_clear(void) | ||
341 | { | ||
342 | sharpsl_ad_index = 0; | ||
343 | } | ||
344 | |||
345 | static int sharpsl_average_value(int ad) | ||
346 | { | ||
347 | int i, ad_val = 0; | ||
348 | static int sharpsl_ad[SHARPSL_CNV_VALUE_NUM+1]; | ||
349 | |||
350 | if (sharpsl_pm.battstat.mainbat_status != APM_BATTERY_STATUS_HIGH) { | ||
351 | sharpsl_ad_index = 0; | ||
352 | return ad; | ||
353 | } | ||
354 | |||
355 | sharpsl_ad[sharpsl_ad_index] = ad; | ||
356 | sharpsl_ad_index++; | ||
357 | if (sharpsl_ad_index >= SHARPSL_CNV_VALUE_NUM) { | ||
358 | for (i=0; i < (SHARPSL_CNV_VALUE_NUM-1); i++) | ||
359 | sharpsl_ad[i] = sharpsl_ad[i+1]; | ||
360 | sharpsl_ad_index = SHARPSL_CNV_VALUE_NUM - 1; | ||
361 | } | ||
362 | for (i=0; i < sharpsl_ad_index; i++) | ||
363 | ad_val += sharpsl_ad[i]; | ||
364 | |||
365 | return (ad_val / sharpsl_ad_index); | ||
366 | } | ||
367 | |||
368 | /* | ||
369 | * Take an array of 5 integers, remove the maximum and minimum values | ||
370 | * and return the average. | ||
371 | */ | ||
372 | static int get_select_val(int *val) | ||
373 | { | ||
374 | int i, j, k, temp, sum = 0; | ||
375 | |||
376 | /* Find MAX val */ | ||
377 | temp = val[0]; | ||
378 | j=0; | ||
379 | for (i=1; i<5; i++) { | ||
380 | if (temp < val[i]) { | ||
381 | temp = val[i]; | ||
382 | j = i; | ||
383 | } | ||
384 | } | ||
385 | |||
386 | /* Find MIN val */ | ||
387 | temp = val[4]; | ||
388 | k=4; | ||
389 | for (i=3; i>=0; i--) { | ||
390 | if (temp > val[i]) { | ||
391 | temp = val[i]; | ||
392 | k = i; | ||
393 | } | ||
394 | } | ||
395 | |||
396 | for (i=0; i<5; i++) | ||
397 | if (i != j && i != k ) | ||
398 | sum += val[i]; | ||
399 | |||
400 | dev_dbg(sharpsl_pm.dev, "Average: %d from values: %d, %d, %d, %d, %d\n", sum/3, val[0], val[1], val[2], val[3], val[4]); | ||
401 | |||
402 | return (sum/3); | ||
403 | } | ||
404 | |||
405 | static int sharpsl_check_battery_temp(void) | ||
406 | { | ||
407 | int val, i, buff[5]; | ||
408 | |||
409 | /* Check battery temperature */ | ||
410 | for (i=0; i<5; i++) { | ||
411 | mdelay(SHARPSL_CHECK_BATTERY_WAIT_TIME_TEMP); | ||
412 | sharpsl_pm.machinfo->measure_temp(1); | ||
413 | mdelay(SHARPSL_CHECK_BATTERY_WAIT_TIME_TEMP); | ||
414 | buff[i] = sharpsl_pm.machinfo->read_devdata(SHARPSL_BATT_TEMP); | ||
415 | sharpsl_pm.machinfo->measure_temp(0); | ||
416 | } | ||
417 | |||
418 | val = get_select_val(buff); | ||
419 | |||
420 | dev_dbg(sharpsl_pm.dev, "Temperature: %d\n", val); | ||
421 | if (val > sharpsl_pm.machinfo->charge_on_temp) { | ||
422 | printk(KERN_WARNING "Not charging: temperature out of limits.\n"); | ||
423 | return -1; | ||
424 | } | ||
425 | |||
426 | return 0; | ||
427 | } | ||
428 | |||
429 | #ifdef CONFIG_PM | ||
430 | static int sharpsl_check_battery_voltage(void) | ||
431 | { | ||
432 | int val, i, buff[5]; | ||
433 | |||
434 | /* disable charge, enable discharge */ | ||
435 | sharpsl_pm.machinfo->charge(0); | ||
436 | sharpsl_pm.machinfo->discharge(1); | ||
437 | mdelay(SHARPSL_WAIT_DISCHARGE_ON); | ||
438 | |||
439 | if (sharpsl_pm.machinfo->discharge1) | ||
440 | sharpsl_pm.machinfo->discharge1(1); | ||
441 | |||
442 | /* Check battery voltage */ | ||
443 | for (i=0; i<5; i++) { | ||
444 | buff[i] = sharpsl_pm.machinfo->read_devdata(SHARPSL_BATT_VOLT); | ||
445 | mdelay(SHARPSL_CHECK_BATTERY_WAIT_TIME_VOLT); | ||
446 | } | ||
447 | |||
448 | if (sharpsl_pm.machinfo->discharge1) | ||
449 | sharpsl_pm.machinfo->discharge1(0); | ||
450 | |||
451 | sharpsl_pm.machinfo->discharge(0); | ||
452 | |||
453 | val = get_select_val(buff); | ||
454 | dev_dbg(sharpsl_pm.dev, "Battery Voltage: %d\n", val); | ||
455 | |||
456 | if (val < sharpsl_pm.machinfo->charge_on_volt) | ||
457 | return -1; | ||
458 | |||
459 | return 0; | ||
460 | } | ||
461 | #endif | ||
462 | |||
463 | static int sharpsl_ac_check(void) | ||
464 | { | ||
465 | int temp, i, buff[5]; | ||
466 | |||
467 | for (i=0; i<5; i++) { | ||
468 | buff[i] = sharpsl_pm.machinfo->read_devdata(SHARPSL_ACIN_VOLT); | ||
469 | mdelay(SHARPSL_CHECK_BATTERY_WAIT_TIME_ACIN); | ||
470 | } | ||
471 | |||
472 | temp = get_select_val(buff); | ||
473 | dev_dbg(sharpsl_pm.dev, "AC Voltage: %d\n",temp); | ||
474 | |||
475 | if ((temp > sharpsl_pm.machinfo->charge_acin_high) || (temp < sharpsl_pm.machinfo->charge_acin_low)) { | ||
476 | dev_err(sharpsl_pm.dev, "Error: AC check failed.\n"); | ||
477 | return -1; | ||
478 | } | ||
479 | |||
480 | return 0; | ||
481 | } | ||
482 | |||
483 | #ifdef CONFIG_PM | ||
484 | static int sharpsl_pm_suspend(struct platform_device *pdev, pm_message_t state) | ||
485 | { | ||
486 | sharpsl_pm.flags |= SHARPSL_SUSPENDED; | ||
487 | flush_scheduled_work(); | ||
488 | |||
489 | if (sharpsl_pm.charge_mode == CHRG_ON) | ||
490 | sharpsl_pm.flags |= SHARPSL_DO_OFFLINE_CHRG; | ||
491 | else | ||
492 | sharpsl_pm.flags &= ~SHARPSL_DO_OFFLINE_CHRG; | ||
493 | |||
494 | return 0; | ||
495 | } | ||
496 | |||
497 | static int sharpsl_pm_resume(struct platform_device *pdev) | ||
498 | { | ||
499 | /* Clear the reset source indicators as they break the bootloader upon reboot */ | ||
500 | RCSR = 0x0f; | ||
501 | sharpsl_average_clear(); | ||
502 | sharpsl_pm.flags &= ~SHARPSL_APM_QUEUED; | ||
503 | sharpsl_pm.flags &= ~SHARPSL_SUSPENDED; | ||
504 | |||
505 | return 0; | ||
506 | } | ||
507 | |||
508 | static void corgi_goto_sleep(unsigned long alarm_time, unsigned int alarm_enable, suspend_state_t state) | ||
509 | { | ||
510 | dev_dbg(sharpsl_pm.dev, "Time is: %08x\n",RCNR); | ||
511 | |||
512 | dev_dbg(sharpsl_pm.dev, "Offline Charge Activate = %d\n",sharpsl_pm.flags & SHARPSL_DO_OFFLINE_CHRG); | ||
513 | /* not charging and AC-IN! */ | ||
514 | |||
515 | if ((sharpsl_pm.flags & SHARPSL_DO_OFFLINE_CHRG) && (sharpsl_pm.machinfo->read_devdata(SHARPSL_STATUS_ACIN))) { | ||
516 | dev_dbg(sharpsl_pm.dev, "Activating Offline Charger...\n"); | ||
517 | sharpsl_pm.charge_mode = CHRG_OFF; | ||
518 | sharpsl_pm.flags &= ~SHARPSL_DO_OFFLINE_CHRG; | ||
519 | sharpsl_off_charge_battery(); | ||
520 | } | ||
521 | |||
522 | sharpsl_pm.machinfo->presuspend(); | ||
523 | |||
524 | PEDR = 0xffffffff; /* clear it */ | ||
525 | |||
526 | sharpsl_pm.flags &= ~SHARPSL_ALARM_ACTIVE; | ||
527 | if ((sharpsl_pm.charge_mode == CHRG_ON) && ((alarm_enable && ((alarm_time - RCNR) > (SHARPSL_BATCHK_TIME_SUSPEND + 30))) || !alarm_enable)) { | ||
528 | RTSR &= RTSR_ALE; | ||
529 | RTAR = RCNR + SHARPSL_BATCHK_TIME_SUSPEND; | ||
530 | dev_dbg(sharpsl_pm.dev, "Charging alarm at: %08x\n",RTAR); | ||
531 | sharpsl_pm.flags |= SHARPSL_ALARM_ACTIVE; | ||
532 | } else if (alarm_enable) { | ||
533 | RTSR &= RTSR_ALE; | ||
534 | RTAR = alarm_time; | ||
535 | dev_dbg(sharpsl_pm.dev, "User alarm at: %08x\n",RTAR); | ||
536 | } else { | ||
537 | dev_dbg(sharpsl_pm.dev, "No alarms set.\n"); | ||
538 | } | ||
539 | |||
540 | pxa_pm_enter(state); | ||
541 | |||
542 | sharpsl_pm.machinfo->postsuspend(); | ||
543 | |||
544 | dev_dbg(sharpsl_pm.dev, "Corgi woken up from suspend: %08x\n",PEDR); | ||
545 | } | ||
546 | |||
547 | static int corgi_enter_suspend(unsigned long alarm_time, unsigned int alarm_enable, suspend_state_t state) | ||
548 | { | ||
549 | if (!sharpsl_pm.machinfo->should_wakeup(!(sharpsl_pm.flags & SHARPSL_ALARM_ACTIVE) && alarm_enable) ) | ||
550 | { | ||
551 | if (!(sharpsl_pm.flags & SHARPSL_ALARM_ACTIVE)) { | ||
552 | dev_dbg(sharpsl_pm.dev, "No user triggered wakeup events and not charging. Strange. Suspend.\n"); | ||
553 | corgi_goto_sleep(alarm_time, alarm_enable, state); | ||
554 | return 1; | ||
555 | } | ||
556 | if(sharpsl_off_charge_battery()) { | ||
557 | dev_dbg(sharpsl_pm.dev, "Charging. Suspend...\n"); | ||
558 | corgi_goto_sleep(alarm_time, alarm_enable, state); | ||
559 | return 1; | ||
560 | } | ||
561 | dev_dbg(sharpsl_pm.dev, "User triggered wakeup in offline charger.\n"); | ||
562 | } | ||
563 | |||
564 | if ((!sharpsl_pm.machinfo->read_devdata(SHARPSL_STATUS_LOCK)) || (sharpsl_fatal_check() < 0) ) | ||
565 | { | ||
566 | dev_err(sharpsl_pm.dev, "Fatal condition. Suspend.\n"); | ||
567 | corgi_goto_sleep(alarm_time, alarm_enable, state); | ||
568 | return 1; | ||
569 | } | ||
570 | |||
571 | return 0; | ||
572 | } | ||
573 | |||
574 | static int corgi_pxa_pm_enter(suspend_state_t state) | ||
575 | { | ||
576 | unsigned long alarm_time = RTAR; | ||
577 | unsigned int alarm_status = ((RTSR & RTSR_ALE) != 0); | ||
578 | |||
579 | dev_dbg(sharpsl_pm.dev, "SharpSL suspending for first time.\n"); | ||
580 | |||
581 | corgi_goto_sleep(alarm_time, alarm_status, state); | ||
582 | |||
583 | while (corgi_enter_suspend(alarm_time,alarm_status,state)) | ||
584 | {} | ||
585 | |||
586 | if (sharpsl_pm.machinfo->earlyresume) | ||
587 | sharpsl_pm.machinfo->earlyresume(); | ||
588 | |||
589 | dev_dbg(sharpsl_pm.dev, "SharpSL resuming...\n"); | ||
590 | |||
591 | return 0; | ||
592 | } | ||
593 | |||
594 | /* | ||
595 | * Check for fatal battery errors | ||
596 | * Fatal returns -1 | ||
597 | */ | ||
598 | static int sharpsl_fatal_check(void) | ||
599 | { | ||
600 | int buff[5], temp, i, acin; | ||
601 | |||
602 | dev_dbg(sharpsl_pm.dev, "sharpsl_fatal_check entered\n"); | ||
603 | |||
604 | /* Check AC-Adapter */ | ||
605 | acin = sharpsl_pm.machinfo->read_devdata(SHARPSL_STATUS_ACIN); | ||
606 | |||
607 | if (acin && (sharpsl_pm.charge_mode == CHRG_ON)) { | ||
608 | sharpsl_pm.machinfo->charge(0); | ||
609 | udelay(100); | ||
610 | sharpsl_pm.machinfo->discharge(1); /* enable discharge */ | ||
611 | mdelay(SHARPSL_WAIT_DISCHARGE_ON); | ||
612 | } | ||
613 | |||
614 | if (sharpsl_pm.machinfo->discharge1) | ||
615 | sharpsl_pm.machinfo->discharge1(1); | ||
616 | |||
617 | /* Check battery : check inserting battery ? */ | ||
618 | for (i=0; i<5; i++) { | ||
619 | buff[i] = sharpsl_pm.machinfo->read_devdata(SHARPSL_BATT_VOLT); | ||
620 | mdelay(SHARPSL_CHECK_BATTERY_WAIT_TIME_VOLT); | ||
621 | } | ||
622 | |||
623 | if (sharpsl_pm.machinfo->discharge1) | ||
624 | sharpsl_pm.machinfo->discharge1(0); | ||
625 | |||
626 | if (acin && (sharpsl_pm.charge_mode == CHRG_ON)) { | ||
627 | udelay(100); | ||
628 | sharpsl_pm.machinfo->charge(1); | ||
629 | sharpsl_pm.machinfo->discharge(0); | ||
630 | } | ||
631 | |||
632 | temp = get_select_val(buff); | ||
633 | dev_dbg(sharpsl_pm.dev, "sharpsl_fatal_check: acin: %d, discharge voltage: %d, no discharge: %ld\n", acin, temp, sharpsl_pm.machinfo->read_devdata(SHARPSL_BATT_VOLT)); | ||
634 | |||
635 | if ((acin && (temp < sharpsl_pm.machinfo->fatal_acin_volt)) || | ||
636 | (!acin && (temp < sharpsl_pm.machinfo->fatal_noacin_volt))) | ||
637 | return -1; | ||
638 | return 0; | ||
639 | } | ||
640 | |||
641 | static int sharpsl_off_charge_error(void) | ||
642 | { | ||
643 | dev_err(sharpsl_pm.dev, "Offline Charger: Error occurred.\n"); | ||
644 | sharpsl_pm.machinfo->charge(0); | ||
645 | sharpsl_pm_led(SHARPSL_LED_ERROR); | ||
646 | sharpsl_pm.charge_mode = CHRG_ERROR; | ||
647 | return 1; | ||
648 | } | ||
649 | |||
650 | /* | ||
651 | * Charging Control while suspended | ||
652 | * Return 1 - go straight to sleep | ||
653 | * Return 0 - sleep or wakeup depending on other factors | ||
654 | */ | ||
655 | static int sharpsl_off_charge_battery(void) | ||
656 | { | ||
657 | int time; | ||
658 | |||
659 | dev_dbg(sharpsl_pm.dev, "Charge Mode: %d\n", sharpsl_pm.charge_mode); | ||
660 | |||
661 | if (sharpsl_pm.charge_mode == CHRG_OFF) { | ||
662 | dev_dbg(sharpsl_pm.dev, "Offline Charger: Step 1\n"); | ||
663 | |||
664 | /* AC Check */ | ||
665 | if ((sharpsl_ac_check() < 0) || (sharpsl_check_battery_temp() < 0)) | ||
666 | return sharpsl_off_charge_error(); | ||
667 | |||
668 | /* Start Charging */ | ||
669 | sharpsl_pm_led(SHARPSL_LED_ON); | ||
670 | sharpsl_pm.machinfo->charge(0); | ||
671 | mdelay(SHARPSL_CHARGE_WAIT_TIME); | ||
672 | sharpsl_pm.machinfo->charge(1); | ||
673 | |||
674 | sharpsl_pm.charge_mode = CHRG_ON; | ||
675 | sharpsl_pm.full_count = 0; | ||
676 | |||
677 | return 1; | ||
678 | } else if (sharpsl_pm.charge_mode != CHRG_ON) { | ||
679 | return 1; | ||
680 | } | ||
681 | |||
682 | if (sharpsl_pm.full_count == 0) { | ||
683 | int time; | ||
684 | |||
685 | dev_dbg(sharpsl_pm.dev, "Offline Charger: Step 2\n"); | ||
686 | |||
687 | if ((sharpsl_check_battery_temp() < 0) || (sharpsl_check_battery_voltage() < 0)) | ||
688 | return sharpsl_off_charge_error(); | ||
689 | |||
690 | sharpsl_pm.machinfo->charge(0); | ||
691 | mdelay(SHARPSL_CHARGE_WAIT_TIME); | ||
692 | sharpsl_pm.machinfo->charge(1); | ||
693 | sharpsl_pm.charge_mode = CHRG_ON; | ||
694 | |||
695 | mdelay(SHARPSL_CHARGE_CO_CHECK_TIME); | ||
696 | |||
697 | time = RCNR; | ||
698 | while(1) { | ||
699 | /* Check if any wakeup event had occurred */ | ||
700 | if (sharpsl_pm.machinfo->charger_wakeup() != 0) | ||
701 | return 0; | ||
702 | /* Check for timeout */ | ||
703 | if ((RCNR - time) > SHARPSL_WAIT_CO_TIME) | ||
704 | return 1; | ||
705 | if (sharpsl_pm.machinfo->read_devdata(SHARPSL_STATUS_CHRGFULL)) { | ||
706 | dev_dbg(sharpsl_pm.dev, "Offline Charger: Charge full occurred. Retrying to check\n"); | ||
707 | sharpsl_pm.full_count++; | ||
708 | sharpsl_pm.machinfo->charge(0); | ||
709 | mdelay(SHARPSL_CHARGE_WAIT_TIME); | ||
710 | sharpsl_pm.machinfo->charge(1); | ||
711 | return 1; | ||
712 | } | ||
713 | } | ||
714 | } | ||
715 | |||
716 | dev_dbg(sharpsl_pm.dev, "Offline Charger: Step 3\n"); | ||
717 | |||
718 | mdelay(SHARPSL_CHARGE_CO_CHECK_TIME); | ||
719 | |||
720 | time = RCNR; | ||
721 | while(1) { | ||
722 | /* Check if any wakeup event had occurred */ | ||
723 | if (sharpsl_pm.machinfo->charger_wakeup() != 0) | ||
724 | return 0; | ||
725 | /* Check for timeout */ | ||
726 | if ((RCNR-time) > SHARPSL_WAIT_CO_TIME) { | ||
727 | if (sharpsl_pm.full_count > SHARPSL_CHARGE_RETRY_CNT) { | ||
728 | dev_dbg(sharpsl_pm.dev, "Offline Charger: Not charged sufficiently. Retrying.\n"); | ||
729 | sharpsl_pm.full_count = 0; | ||
730 | } | ||
731 | sharpsl_pm.full_count++; | ||
732 | return 1; | ||
733 | } | ||
734 | if (sharpsl_pm.machinfo->read_devdata(SHARPSL_STATUS_CHRGFULL)) { | ||
735 | dev_dbg(sharpsl_pm.dev, "Offline Charger: Charging complete.\n"); | ||
736 | sharpsl_pm_led(SHARPSL_LED_OFF); | ||
737 | sharpsl_pm.machinfo->charge(0); | ||
738 | sharpsl_pm.charge_mode = CHRG_DONE; | ||
739 | return 1; | ||
740 | } | ||
741 | } | ||
742 | } | ||
743 | #else | ||
744 | #define sharpsl_pm_suspend NULL | ||
745 | #define sharpsl_pm_resume NULL | ||
746 | #endif | ||
747 | |||
748 | static ssize_t battery_percentage_show(struct device *dev, struct device_attribute *attr, char *buf) | ||
749 | { | ||
750 | return sprintf(buf, "%d\n",sharpsl_pm.battstat.mainbat_percent); | ||
751 | } | ||
752 | |||
753 | static ssize_t battery_voltage_show(struct device *dev, struct device_attribute *attr, char *buf) | ||
754 | { | ||
755 | return sprintf(buf, "%d\n",sharpsl_pm.battstat.mainbat_voltage); | ||
756 | } | ||
757 | |||
758 | static DEVICE_ATTR(battery_percentage, 0444, battery_percentage_show, NULL); | ||
759 | static DEVICE_ATTR(battery_voltage, 0444, battery_voltage_show, NULL); | ||
760 | |||
761 | extern void (*apm_get_power_status)(struct apm_power_info *); | ||
762 | |||
763 | static void sharpsl_apm_get_power_status(struct apm_power_info *info) | ||
764 | { | ||
765 | info->ac_line_status = sharpsl_pm.battstat.ac_status; | ||
766 | |||
767 | if (sharpsl_pm.charge_mode == CHRG_ON) | ||
768 | info->battery_status = APM_BATTERY_STATUS_CHARGING; | ||
769 | else | ||
770 | info->battery_status = sharpsl_pm.battstat.mainbat_status; | ||
771 | |||
772 | info->battery_flag = (1 << info->battery_status); | ||
773 | info->battery_life = sharpsl_pm.battstat.mainbat_percent; | ||
774 | } | ||
775 | |||
776 | #ifdef CONFIG_PM | ||
777 | static struct platform_suspend_ops sharpsl_pm_ops = { | ||
778 | .enter = corgi_pxa_pm_enter, | ||
779 | .valid = suspend_valid_only_mem, | ||
780 | }; | ||
781 | #endif | ||
782 | |||
783 | static int __init sharpsl_pm_probe(struct platform_device *pdev) | ||
784 | { | ||
785 | int ret; | ||
786 | |||
787 | if (!pdev->dev.platform_data) | ||
788 | return -EINVAL; | ||
789 | |||
790 | sharpsl_pm.dev = &pdev->dev; | ||
791 | sharpsl_pm.machinfo = pdev->dev.platform_data; | ||
792 | sharpsl_pm.charge_mode = CHRG_OFF; | ||
793 | sharpsl_pm.flags = 0; | ||
794 | |||
795 | init_timer(&sharpsl_pm.ac_timer); | ||
796 | sharpsl_pm.ac_timer.function = sharpsl_ac_timer; | ||
797 | |||
798 | init_timer(&sharpsl_pm.chrg_full_timer); | ||
799 | sharpsl_pm.chrg_full_timer.function = sharpsl_chrg_full_timer; | ||
800 | |||
801 | led_trigger_register_simple("sharpsl-charge", &sharpsl_charge_led_trigger); | ||
802 | |||
803 | sharpsl_pm.machinfo->init(); | ||
804 | |||
805 | ret = device_create_file(&pdev->dev, &dev_attr_battery_percentage); | ||
806 | ret |= device_create_file(&pdev->dev, &dev_attr_battery_voltage); | ||
807 | if (ret != 0) | ||
808 | dev_warn(&pdev->dev, "Failed to register attributes (%d)\n", ret); | ||
809 | |||
810 | apm_get_power_status = sharpsl_apm_get_power_status; | ||
811 | |||
812 | #ifdef CONFIG_PM | ||
813 | suspend_set_ops(&sharpsl_pm_ops); | ||
814 | #endif | ||
815 | |||
816 | mod_timer(&sharpsl_pm.ac_timer, jiffies + msecs_to_jiffies(250)); | ||
817 | |||
818 | return 0; | ||
819 | } | ||
820 | |||
821 | static int sharpsl_pm_remove(struct platform_device *pdev) | ||
822 | { | ||
823 | suspend_set_ops(NULL); | ||
824 | |||
825 | device_remove_file(&pdev->dev, &dev_attr_battery_percentage); | ||
826 | device_remove_file(&pdev->dev, &dev_attr_battery_voltage); | ||
827 | |||
828 | led_trigger_unregister_simple(sharpsl_charge_led_trigger); | ||
829 | |||
830 | sharpsl_pm.machinfo->exit(); | ||
831 | |||
832 | del_timer_sync(&sharpsl_pm.chrg_full_timer); | ||
833 | del_timer_sync(&sharpsl_pm.ac_timer); | ||
834 | |||
835 | return 0; | ||
836 | } | ||
837 | |||
838 | static struct platform_driver sharpsl_pm_driver = { | ||
839 | .probe = sharpsl_pm_probe, | ||
840 | .remove = sharpsl_pm_remove, | ||
841 | .suspend = sharpsl_pm_suspend, | ||
842 | .resume = sharpsl_pm_resume, | ||
843 | .driver = { | ||
844 | .name = "sharpsl-pm", | ||
845 | }, | ||
846 | }; | ||
847 | |||
848 | static int __devinit sharpsl_pm_init(void) | ||
849 | { | ||
850 | return platform_driver_register(&sharpsl_pm_driver); | ||
851 | } | ||
852 | |||
853 | static void sharpsl_pm_exit(void) | ||
854 | { | ||
855 | platform_driver_unregister(&sharpsl_pm_driver); | ||
856 | } | ||
857 | |||
858 | late_initcall(sharpsl_pm_init); | ||
859 | module_exit(sharpsl_pm_exit); | ||
diff --git a/arch/arm/common/vic.c b/arch/arm/common/vic.c index b2a781d9ce05..887c6eb3a18a 100644 --- a/arch/arm/common/vic.c +++ b/arch/arm/common/vic.c | |||
@@ -21,6 +21,7 @@ | |||
21 | #include <linux/init.h> | 21 | #include <linux/init.h> |
22 | #include <linux/list.h> | 22 | #include <linux/list.h> |
23 | #include <linux/io.h> | 23 | #include <linux/io.h> |
24 | #include <linux/sysdev.h> | ||
24 | 25 | ||
25 | #include <asm/mach/irq.h> | 26 | #include <asm/mach/irq.h> |
26 | #include <asm/hardware/vic.h> | 27 | #include <asm/hardware/vic.h> |
@@ -39,11 +40,219 @@ static void vic_unmask_irq(unsigned int irq) | |||
39 | writel(1 << irq, base + VIC_INT_ENABLE); | 40 | writel(1 << irq, base + VIC_INT_ENABLE); |
40 | } | 41 | } |
41 | 42 | ||
43 | /** | ||
44 | * vic_init2 - common initialisation code | ||
45 | * @base: Base of the VIC. | ||
46 | * | ||
47 | * Common initialisation code for registeration | ||
48 | * and resume. | ||
49 | */ | ||
50 | static void vic_init2(void __iomem *base) | ||
51 | { | ||
52 | int i; | ||
53 | |||
54 | for (i = 0; i < 16; i++) { | ||
55 | void __iomem *reg = base + VIC_VECT_CNTL0 + (i * 4); | ||
56 | writel(VIC_VECT_CNTL_ENABLE | i, reg); | ||
57 | } | ||
58 | |||
59 | writel(32, base + VIC_PL190_DEF_VECT_ADDR); | ||
60 | } | ||
61 | |||
62 | #if defined(CONFIG_PM) | ||
63 | /** | ||
64 | * struct vic_device - VIC PM device | ||
65 | * @sysdev: The system device which is registered. | ||
66 | * @irq: The IRQ number for the base of the VIC. | ||
67 | * @base: The register base for the VIC. | ||
68 | * @resume_sources: A bitmask of interrupts for resume. | ||
69 | * @resume_irqs: The IRQs enabled for resume. | ||
70 | * @int_select: Save for VIC_INT_SELECT. | ||
71 | * @int_enable: Save for VIC_INT_ENABLE. | ||
72 | * @soft_int: Save for VIC_INT_SOFT. | ||
73 | * @protect: Save for VIC_PROTECT. | ||
74 | */ | ||
75 | struct vic_device { | ||
76 | struct sys_device sysdev; | ||
77 | |||
78 | void __iomem *base; | ||
79 | int irq; | ||
80 | u32 resume_sources; | ||
81 | u32 resume_irqs; | ||
82 | u32 int_select; | ||
83 | u32 int_enable; | ||
84 | u32 soft_int; | ||
85 | u32 protect; | ||
86 | }; | ||
87 | |||
88 | /* we cannot allocate memory when VICs are initially registered */ | ||
89 | static struct vic_device vic_devices[CONFIG_ARM_VIC_NR]; | ||
90 | |||
91 | static inline struct vic_device *to_vic(struct sys_device *sys) | ||
92 | { | ||
93 | return container_of(sys, struct vic_device, sysdev); | ||
94 | } | ||
95 | |||
96 | static int vic_id; | ||
97 | |||
98 | static int vic_class_resume(struct sys_device *dev) | ||
99 | { | ||
100 | struct vic_device *vic = to_vic(dev); | ||
101 | void __iomem *base = vic->base; | ||
102 | |||
103 | printk(KERN_DEBUG "%s: resuming vic at %p\n", __func__, base); | ||
104 | |||
105 | /* re-initialise static settings */ | ||
106 | vic_init2(base); | ||
107 | |||
108 | writel(vic->int_select, base + VIC_INT_SELECT); | ||
109 | writel(vic->protect, base + VIC_PROTECT); | ||
110 | |||
111 | /* set the enabled ints and then clear the non-enabled */ | ||
112 | writel(vic->int_enable, base + VIC_INT_ENABLE); | ||
113 | writel(~vic->int_enable, base + VIC_INT_ENABLE_CLEAR); | ||
114 | |||
115 | /* and the same for the soft-int register */ | ||
116 | |||
117 | writel(vic->soft_int, base + VIC_INT_SOFT); | ||
118 | writel(~vic->soft_int, base + VIC_INT_SOFT_CLEAR); | ||
119 | |||
120 | return 0; | ||
121 | } | ||
122 | |||
123 | static int vic_class_suspend(struct sys_device *dev, pm_message_t state) | ||
124 | { | ||
125 | struct vic_device *vic = to_vic(dev); | ||
126 | void __iomem *base = vic->base; | ||
127 | |||
128 | printk(KERN_DEBUG "%s: suspending vic at %p\n", __func__, base); | ||
129 | |||
130 | vic->int_select = readl(base + VIC_INT_SELECT); | ||
131 | vic->int_enable = readl(base + VIC_INT_ENABLE); | ||
132 | vic->soft_int = readl(base + VIC_INT_SOFT); | ||
133 | vic->protect = readl(base + VIC_PROTECT); | ||
134 | |||
135 | /* set the interrupts (if any) that are used for | ||
136 | * resuming the system */ | ||
137 | |||
138 | writel(vic->resume_irqs, base + VIC_INT_ENABLE); | ||
139 | writel(~vic->resume_irqs, base + VIC_INT_ENABLE_CLEAR); | ||
140 | |||
141 | return 0; | ||
142 | } | ||
143 | |||
144 | struct sysdev_class vic_class = { | ||
145 | .name = "vic", | ||
146 | .suspend = vic_class_suspend, | ||
147 | .resume = vic_class_resume, | ||
148 | }; | ||
149 | |||
150 | /** | ||
151 | * vic_pm_register - Register a VIC for later power management control | ||
152 | * @base: The base address of the VIC. | ||
153 | * @irq: The base IRQ for the VIC. | ||
154 | * @resume_sources: bitmask of interrupts allowed for resume sources. | ||
155 | * | ||
156 | * Register the VIC with the system device tree so that it can be notified | ||
157 | * of suspend and resume requests and ensure that the correct actions are | ||
158 | * taken to re-instate the settings on resume. | ||
159 | */ | ||
160 | static void __init vic_pm_register(void __iomem *base, unsigned int irq, u32 resume_sources) | ||
161 | { | ||
162 | struct vic_device *v; | ||
163 | |||
164 | if (vic_id >= ARRAY_SIZE(vic_devices)) | ||
165 | printk(KERN_ERR "%s: too few VICs, increase CONFIG_ARM_VIC_NR\n", __func__); | ||
166 | else { | ||
167 | v = &vic_devices[vic_id]; | ||
168 | v->base = base; | ||
169 | v->resume_sources = resume_sources; | ||
170 | v->irq = irq; | ||
171 | vic_id++; | ||
172 | } | ||
173 | } | ||
174 | |||
175 | /** | ||
176 | * vic_pm_init - initicall to register VIC pm | ||
177 | * | ||
178 | * This is called via late_initcall() to register | ||
179 | * the resources for the VICs due to the early | ||
180 | * nature of the VIC's registration. | ||
181 | */ | ||
182 | static int __init vic_pm_init(void) | ||
183 | { | ||
184 | struct vic_device *dev = vic_devices; | ||
185 | int err; | ||
186 | int id; | ||
187 | |||
188 | if (vic_id == 0) | ||
189 | return 0; | ||
190 | |||
191 | err = sysdev_class_register(&vic_class); | ||
192 | if (err) { | ||
193 | printk(KERN_ERR "%s: cannot register class\n", __func__); | ||
194 | return err; | ||
195 | } | ||
196 | |||
197 | for (id = 0; id < vic_id; id++, dev++) { | ||
198 | dev->sysdev.id = id; | ||
199 | dev->sysdev.cls = &vic_class; | ||
200 | |||
201 | err = sysdev_register(&dev->sysdev); | ||
202 | if (err) { | ||
203 | printk(KERN_ERR "%s: failed to register device\n", | ||
204 | __func__); | ||
205 | return err; | ||
206 | } | ||
207 | } | ||
208 | |||
209 | return 0; | ||
210 | } | ||
211 | |||
212 | late_initcall(vic_pm_init); | ||
213 | |||
214 | static struct vic_device *vic_from_irq(unsigned int irq) | ||
215 | { | ||
216 | struct vic_device *v = vic_devices; | ||
217 | unsigned int base_irq = irq & ~31; | ||
218 | int id; | ||
219 | |||
220 | for (id = 0; id < vic_id; id++, v++) { | ||
221 | if (v->irq == base_irq) | ||
222 | return v; | ||
223 | } | ||
224 | |||
225 | return NULL; | ||
226 | } | ||
227 | |||
228 | static int vic_set_wake(unsigned int irq, unsigned int on) | ||
229 | { | ||
230 | struct vic_device *v = vic_from_irq(irq); | ||
231 | unsigned int off = irq & 31; | ||
232 | |||
233 | if (!v) | ||
234 | return -EINVAL; | ||
235 | |||
236 | if (on) | ||
237 | v->resume_irqs |= 1 << off; | ||
238 | else | ||
239 | v->resume_irqs &= ~(1 << off); | ||
240 | |||
241 | return 0; | ||
242 | } | ||
243 | |||
244 | #else | ||
245 | static inline void vic_pm_register(void __iomem *base, unsigned int irq, u32 arg1) { } | ||
246 | |||
247 | #define vic_set_wake NULL | ||
248 | #endif /* CONFIG_PM */ | ||
249 | |||
42 | static struct irq_chip vic_chip = { | 250 | static struct irq_chip vic_chip = { |
43 | .name = "VIC", | 251 | .name = "VIC", |
44 | .ack = vic_mask_irq, | 252 | .ack = vic_mask_irq, |
45 | .mask = vic_mask_irq, | 253 | .mask = vic_mask_irq, |
46 | .unmask = vic_unmask_irq, | 254 | .unmask = vic_unmask_irq, |
255 | .set_wake = vic_set_wake, | ||
47 | }; | 256 | }; |
48 | 257 | ||
49 | /** | 258 | /** |
@@ -51,9 +260,10 @@ static struct irq_chip vic_chip = { | |||
51 | * @base: iomem base address | 260 | * @base: iomem base address |
52 | * @irq_start: starting interrupt number, must be muliple of 32 | 261 | * @irq_start: starting interrupt number, must be muliple of 32 |
53 | * @vic_sources: bitmask of interrupt sources to allow | 262 | * @vic_sources: bitmask of interrupt sources to allow |
263 | * @resume_sources: bitmask of interrupt sources to allow for resume | ||
54 | */ | 264 | */ |
55 | void __init vic_init(void __iomem *base, unsigned int irq_start, | 265 | void __init vic_init(void __iomem *base, unsigned int irq_start, |
56 | u32 vic_sources) | 266 | u32 vic_sources, u32 resume_sources) |
57 | { | 267 | { |
58 | unsigned int i; | 268 | unsigned int i; |
59 | 269 | ||
@@ -77,12 +287,7 @@ void __init vic_init(void __iomem *base, unsigned int irq_start, | |||
77 | writel(value, base + VIC_PL190_VECT_ADDR); | 287 | writel(value, base + VIC_PL190_VECT_ADDR); |
78 | } | 288 | } |
79 | 289 | ||
80 | for (i = 0; i < 16; i++) { | 290 | vic_init2(base); |
81 | void __iomem *reg = base + VIC_VECT_CNTL0 + (i * 4); | ||
82 | writel(VIC_VECT_CNTL_ENABLE | i, reg); | ||
83 | } | ||
84 | |||
85 | writel(32, base + VIC_PL190_DEF_VECT_ADDR); | ||
86 | 291 | ||
87 | for (i = 0; i < 32; i++) { | 292 | for (i = 0; i < 32; i++) { |
88 | if (vic_sources & (1 << i)) { | 293 | if (vic_sources & (1 << i)) { |
@@ -94,4 +299,6 @@ void __init vic_init(void __iomem *base, unsigned int irq_start, | |||
94 | set_irq_flags(irq, IRQF_VALID | IRQF_PROBE); | 299 | set_irq_flags(irq, IRQF_VALID | IRQF_PROBE); |
95 | } | 300 | } |
96 | } | 301 | } |
302 | |||
303 | vic_pm_register(base, irq_start, resume_sources); | ||
97 | } | 304 | } |