aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-pxa
diff options
context:
space:
mode:
Diffstat (limited to 'arch/arm/mach-pxa')
-rw-r--r--arch/arm/mach-pxa/Kconfig2
-rw-r--r--arch/arm/mach-pxa/corgi_pm.c44
-rw-r--r--arch/arm/mach-pxa/mainstone.c6
-rw-r--r--arch/arm/mach-pxa/sharpsl.h101
-rw-r--r--arch/arm/mach-pxa/sharpsl_pm.c824
-rw-r--r--arch/arm/mach-pxa/spitz.c35
-rw-r--r--arch/arm/mach-pxa/spitz_pm.c46
7 files changed, 116 insertions, 942 deletions
diff --git a/arch/arm/mach-pxa/Kconfig b/arch/arm/mach-pxa/Kconfig
index 2a58499c0968..c1d77f5b3823 100644
--- a/arch/arm/mach-pxa/Kconfig
+++ b/arch/arm/mach-pxa/Kconfig
@@ -112,12 +112,14 @@ config IWMMXT
112config PXA_SHARP_C7xx 112config PXA_SHARP_C7xx
113 bool 113 bool
114 select PXA_SSP 114 select PXA_SSP
115 select SHARPSL_PM
115 help 116 help
116 Enable support for all Sharp C7xx models 117 Enable support for all Sharp C7xx models
117 118
118config PXA_SHARP_Cxx00 119config PXA_SHARP_Cxx00
119 bool 120 bool
120 select PXA_SSP 121 select PXA_SSP
122 select SHARPSL_PM
121 help 123 help
122 Enable common support for Sharp Cxx00 models 124 Enable common support for Sharp Cxx00 models
123 125
diff --git a/arch/arm/mach-pxa/corgi_pm.c b/arch/arm/mach-pxa/corgi_pm.c
index 599be14754f9..7a1ab73e9e10 100644
--- a/arch/arm/mach-pxa/corgi_pm.c
+++ b/arch/arm/mach-pxa/corgi_pm.c
@@ -33,19 +33,7 @@ static void corgi_charger_init(void)
33 pxa_gpio_mode(CORGI_GPIO_CHRG_ON | GPIO_OUT); 33 pxa_gpio_mode(CORGI_GPIO_CHRG_ON | GPIO_OUT);
34 pxa_gpio_mode(CORGI_GPIO_CHRG_UKN | GPIO_OUT); 34 pxa_gpio_mode(CORGI_GPIO_CHRG_UKN | GPIO_OUT);
35 pxa_gpio_mode(CORGI_GPIO_KEY_INT | GPIO_IN); 35 pxa_gpio_mode(CORGI_GPIO_KEY_INT | GPIO_IN);
36} 36 sharpsl_pm_pxa_init();
37
38static void corgi_charge_led(int val)
39{
40 if (val == SHARPSL_LED_ERROR) {
41 dev_dbg(sharpsl_pm.dev, "Charge LED Error\n");
42 } else if (val == SHARPSL_LED_ON) {
43 dev_dbg(sharpsl_pm.dev, "Charge LED On\n");
44 GPSR0 = GPIO_bit(CORGI_GPIO_LED_ORANGE);
45 } else {
46 dev_dbg(sharpsl_pm.dev, "Charge LED Off\n");
47 GPCR0 = GPIO_bit(CORGI_GPIO_LED_ORANGE);
48 }
49} 37}
50 38
51static void corgi_measure_temp(int on) 39static void corgi_measure_temp(int on)
@@ -138,15 +126,15 @@ static int corgi_should_wakeup(unsigned int resume_on_alarm)
138 dev_dbg(sharpsl_pm.dev, "GPLR0 = %x,%x\n", GPLR0, PEDR); 126 dev_dbg(sharpsl_pm.dev, "GPLR0 = %x,%x\n", GPLR0, PEDR);
139 127
140 if ((PEDR & GPIO_bit(CORGI_GPIO_AC_IN))) { 128 if ((PEDR & GPIO_bit(CORGI_GPIO_AC_IN))) {
141 if (STATUS_AC_IN()) { 129 if (sharpsl_pm.machinfo->read_devdata(SHARPSL_STATUS_ACIN)) {
142 /* charge on */ 130 /* charge on */
143 dev_dbg(sharpsl_pm.dev, "ac insert\n"); 131 dev_dbg(sharpsl_pm.dev, "ac insert\n");
144 sharpsl_pm.flags |= SHARPSL_DO_OFFLINE_CHRG; 132 sharpsl_pm.flags |= SHARPSL_DO_OFFLINE_CHRG;
145 } else { 133 } else {
146 /* charge off */ 134 /* charge off */
147 dev_dbg(sharpsl_pm.dev, "ac remove\n"); 135 dev_dbg(sharpsl_pm.dev, "ac remove\n");
148 CHARGE_LED_OFF(); 136 sharpsl_pm_led(SHARPSL_LED_OFF);
149 CHARGE_OFF(); 137 sharpsl_pm.machinfo->charge(0);
150 sharpsl_pm.charge_mode = CHRG_OFF; 138 sharpsl_pm.charge_mode = CHRG_OFF;
151 } 139 }
152 } 140 }
@@ -172,23 +160,39 @@ static unsigned long corgi_charger_wakeup(void)
172 return ~GPLR0 & ( GPIO_bit(CORGI_GPIO_AC_IN) | GPIO_bit(CORGI_GPIO_KEY_INT) | GPIO_bit(CORGI_GPIO_WAKEUP) ); 160 return ~GPLR0 & ( GPIO_bit(CORGI_GPIO_AC_IN) | GPIO_bit(CORGI_GPIO_KEY_INT) | GPIO_bit(CORGI_GPIO_WAKEUP) );
173} 161}
174 162
175static int corgi_acin_status(void) 163unsigned long corgipm_read_devdata(int type)
176{ 164{
177 return ((GPLR(CORGI_GPIO_AC_IN) & GPIO_bit(CORGI_GPIO_AC_IN)) != 0); 165 switch(type) {
166 case SHARPSL_STATUS_ACIN:
167 return ((GPLR(CORGI_GPIO_AC_IN) & GPIO_bit(CORGI_GPIO_AC_IN)) != 0);
168 case SHARPSL_STATUS_LOCK:
169 return READ_GPIO_BIT(sharpsl_pm.machinfo->gpio_batlock);
170 case SHARPSL_STATUS_CHRGFULL:
171 return READ_GPIO_BIT(sharpsl_pm.machinfo->gpio_batfull);
172 case SHARPSL_STATUS_FATAL:
173 return READ_GPIO_BIT(sharpsl_pm.machinfo->gpio_fatal);
174 case SHARPSL_ACIN_VOLT:
175 return sharpsl_pm_pxa_read_max1111(MAX1111_ACIN_VOLT);
176 case SHARPSL_BATT_TEMP:
177 return sharpsl_pm_pxa_read_max1111(MAX1111_BATT_TEMP);
178 case SHARPSL_BATT_VOLT:
179 default:
180 return sharpsl_pm_pxa_read_max1111(MAX1111_BATT_VOLT);
181 }
178} 182}
179 183
180static struct sharpsl_charger_machinfo corgi_pm_machinfo = { 184static struct sharpsl_charger_machinfo corgi_pm_machinfo = {
181 .init = corgi_charger_init, 185 .init = corgi_charger_init,
186 .exit = sharpsl_pm_pxa_remove,
182 .gpio_batlock = CORGI_GPIO_BAT_COVER, 187 .gpio_batlock = CORGI_GPIO_BAT_COVER,
183 .gpio_acin = CORGI_GPIO_AC_IN, 188 .gpio_acin = CORGI_GPIO_AC_IN,
184 .gpio_batfull = CORGI_GPIO_CHRG_FULL, 189 .gpio_batfull = CORGI_GPIO_CHRG_FULL,
185 .status_acin = corgi_acin_status,
186 .discharge = corgi_discharge, 190 .discharge = corgi_discharge,
187 .charge = corgi_charge, 191 .charge = corgi_charge,
188 .chargeled = corgi_charge_led,
189 .measure_temp = corgi_measure_temp, 192 .measure_temp = corgi_measure_temp,
190 .presuspend = corgi_presuspend, 193 .presuspend = corgi_presuspend,
191 .postsuspend = corgi_postsuspend, 194 .postsuspend = corgi_postsuspend,
195 .read_devdata = corgipm_read_devdata,
192 .charger_wakeup = corgi_charger_wakeup, 196 .charger_wakeup = corgi_charger_wakeup,
193 .should_wakeup = corgi_should_wakeup, 197 .should_wakeup = corgi_should_wakeup,
194 .bat_levels = 40, 198 .bat_levels = 40,
diff --git a/arch/arm/mach-pxa/mainstone.c b/arch/arm/mach-pxa/mainstone.c
index 277498ae5b6c..8da9d3efe9a0 100644
--- a/arch/arm/mach-pxa/mainstone.c
+++ b/arch/arm/mach-pxa/mainstone.c
@@ -427,6 +427,12 @@ static void __init mainstone_init(void)
427 printk(KERN_NOTICE "Mainstone configured to boot from %s\n", 427 printk(KERN_NOTICE "Mainstone configured to boot from %s\n",
428 mst_flash_data[0].name); 428 mst_flash_data[0].name);
429 429
430 /* system bus arbiter setting
431 * - Core_Park
432 * - LCD_wt:DMA_wt:CORE_Wt = 2:3:4
433 */
434 ARB_CNTRL = ARB_CORE_PARK | 0x234;
435
430 /* 436 /*
431 * On Mainstone, we route AC97_SYSCLK via GPIO45 to 437 * On Mainstone, we route AC97_SYSCLK via GPIO45 to
432 * the audio daughter card 438 * the audio daughter card
diff --git a/arch/arm/mach-pxa/sharpsl.h b/arch/arm/mach-pxa/sharpsl.h
index b0c40a1d6671..da4769caaf72 100644
--- a/arch/arm/mach-pxa/sharpsl.h
+++ b/arch/arm/mach-pxa/sharpsl.h
@@ -1,7 +1,17 @@
1/* 1/*
2 * SharpSL SSP Driver 2 * Copyright (c) 2004-2005 Richard Purdie
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
3 */ 8 */
4 9
10#include <asm/hardware/sharpsl_pm.h>
11
12/*
13 * SharpSL SSP Driver
14 */
5struct corgissp_machinfo { 15struct corgissp_machinfo {
6 int port; 16 int port;
7 int cs_lcdcon; 17 int cs_lcdcon;
@@ -14,18 +24,18 @@ struct corgissp_machinfo {
14 24
15void corgi_ssp_set_machinfo(struct corgissp_machinfo *machinfo); 25void corgi_ssp_set_machinfo(struct corgissp_machinfo *machinfo);
16 26
27
17/* 28/*
18 * SharpSL Backlight 29 * SharpSL Backlight
19 */ 30 */
20
21void corgi_bl_set_intensity(int intensity); 31void corgi_bl_set_intensity(int intensity);
22void spitz_bl_set_intensity(int intensity); 32void spitz_bl_set_intensity(int intensity);
23void akita_bl_set_intensity(int intensity); 33void akita_bl_set_intensity(int intensity);
24 34
35
25/* 36/*
26 * SharpSL Touchscreen Driver 37 * SharpSL Touchscreen Driver
27 */ 38 */
28
29unsigned long corgi_get_hsync_len(void); 39unsigned long corgi_get_hsync_len(void);
30unsigned long spitz_get_hsync_len(void); 40unsigned long spitz_get_hsync_len(void);
31void corgi_put_hsync(void); 41void corgi_put_hsync(void);
@@ -33,89 +43,22 @@ void spitz_put_hsync(void);
33void corgi_wait_hsync(void); 43void corgi_wait_hsync(void);
34void spitz_wait_hsync(void); 44void spitz_wait_hsync(void);
35 45
46
36/* 47/*
37 * SharpSL Battery/PM Driver 48 * SharpSL Battery/PM Driver
38 */ 49 */
39 50
40struct sharpsl_charger_machinfo { 51#define READ_GPIO_BIT(x) (GPLR(x) & GPIO_bit(x))
41 void (*init)(void);
42 int gpio_acin;
43 int gpio_batfull;
44 int gpio_batlock;
45 int gpio_fatal;
46 int (*status_acin)(void);
47 void (*discharge)(int);
48 void (*discharge1)(int);
49 void (*charge)(int);
50 void (*chargeled)(int);
51 void (*measure_temp)(int);
52 void (*presuspend)(void);
53 void (*postsuspend)(void);
54 unsigned long (*charger_wakeup)(void);
55 int (*should_wakeup)(unsigned int resume_on_alarm);
56 int bat_levels;
57 struct battery_thresh *bat_levels_noac;
58 struct battery_thresh *bat_levels_acin;
59 int status_high_acin;
60 int status_low_acin;
61 int status_high_noac;
62 int status_low_noac;
63};
64
65struct battery_thresh {
66 int voltage;
67 int percentage;
68};
69
70struct battery_stat {
71 int ac_status; /* APM AC Present/Not Present */
72 int mainbat_status; /* APM Main Battery Status */
73 int mainbat_percent; /* Main Battery Percentage Charge */
74 int mainbat_voltage; /* Main Battery Voltage */
75};
76
77struct sharpsl_pm_status {
78 struct device *dev;
79 struct timer_list ac_timer;
80 struct timer_list chrg_full_timer;
81
82 int charge_mode;
83#define CHRG_ERROR (-1)
84#define CHRG_OFF (0)
85#define CHRG_ON (1)
86#define CHRG_DONE (2)
87
88 unsigned int flags;
89#define SHARPSL_SUSPENDED (1 << 0) /* Device is Suspended */
90#define SHARPSL_ALARM_ACTIVE (1 << 1) /* Alarm is for charging event (not user) */
91#define SHARPSL_BL_LIMIT (1 << 2) /* Backlight Intensity Limited */
92#define SHARPSL_APM_QUEUED (1 << 3) /* APM Event Queued */
93#define SHARPSL_DO_OFFLINE_CHRG (1 << 4) /* Trigger the offline charger */
94 52
95 int full_count; 53/* MAX1111 Channel Definitions */
96 unsigned long charge_start_time; 54#define MAX1111_BATT_VOLT 4u
97 struct sharpsl_charger_machinfo *machinfo; 55#define MAX1111_BATT_TEMP 2u
98 struct battery_stat battstat; 56#define MAX1111_ACIN_VOLT 6u
99};
100 57
101extern struct sharpsl_pm_status sharpsl_pm;
102extern struct battery_thresh spitz_battery_levels_acin[]; 58extern struct battery_thresh spitz_battery_levels_acin[];
103extern struct battery_thresh spitz_battery_levels_noac[]; 59extern struct battery_thresh spitz_battery_levels_noac[];
60void sharpsl_pm_pxa_init(void);
61void sharpsl_pm_pxa_remove(void);
62int sharpsl_pm_pxa_read_max1111(int channel);
104 63
105#define READ_GPIO_BIT(x) (GPLR(x) & GPIO_bit(x))
106
107#define SHARPSL_LED_ERROR 2
108#define SHARPSL_LED_ON 1
109#define SHARPSL_LED_OFF 0
110 64
111#define CHARGE_ON() sharpsl_pm.machinfo->charge(1)
112#define CHARGE_OFF() sharpsl_pm.machinfo->charge(0)
113#define CHARGE_LED_ON() sharpsl_pm.machinfo->chargeled(SHARPSL_LED_ON)
114#define CHARGE_LED_OFF() sharpsl_pm.machinfo->chargeled(SHARPSL_LED_OFF)
115#define CHARGE_LED_ERR() sharpsl_pm.machinfo->chargeled(SHARPSL_LED_ERROR)
116#define DISCHARGE_ON() sharpsl_pm.machinfo->discharge(1)
117#define DISCHARGE_OFF() sharpsl_pm.machinfo->discharge(0)
118#define STATUS_AC_IN() sharpsl_pm.machinfo->status_acin()
119#define STATUS_BATT_LOCKED() READ_GPIO_BIT(sharpsl_pm.machinfo->gpio_batlock)
120#define STATUS_CHRG_FULL() READ_GPIO_BIT(sharpsl_pm.machinfo->gpio_batfull)
121#define STATUS_FATAL() READ_GPIO_BIT(sharpsl_pm.machinfo->gpio_fatal)
diff --git a/arch/arm/mach-pxa/sharpsl_pm.c b/arch/arm/mach-pxa/sharpsl_pm.c
index c10be00fb526..6d402b262d8a 100644
--- a/arch/arm/mach-pxa/sharpsl_pm.c
+++ b/arch/arm/mach-pxa/sharpsl_pm.c
@@ -15,48 +15,20 @@
15#undef DEBUG 15#undef DEBUG
16 16
17#include <linux/module.h> 17#include <linux/module.h>
18#include <linux/timer.h>
19#include <linux/init.h> 18#include <linux/init.h>
20#include <linux/kernel.h> 19#include <linux/kernel.h>
21#include <linux/apm_bios.h>
22#include <linux/delay.h>
23#include <linux/interrupt.h> 20#include <linux/interrupt.h>
24#include <linux/platform_device.h> 21#include <linux/platform_device.h>
25 22
26#include <asm/hardware.h> 23#include <asm/hardware.h>
27#include <asm/hardware/scoop.h>
28#include <asm/mach-types.h> 24#include <asm/mach-types.h>
29#include <asm/irq.h> 25#include <asm/irq.h>
30#include <asm/apm.h> 26#include <asm/apm.h>
31
32#include <asm/arch/pm.h> 27#include <asm/arch/pm.h>
33#include <asm/arch/pxa-regs.h> 28#include <asm/arch/pxa-regs.h>
34#include <asm/arch/sharpsl.h> 29#include <asm/arch/sharpsl.h>
35#include "sharpsl.h" 30#include "sharpsl.h"
36 31
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#define SHARPSL_WAIT_CO_TIME 15 /* 15 sec */
45#define SHARPSL_WAIT_DISCHARGE_ON 100 /* 100 msec */
46#define SHARPSL_CHECK_BATTERY_WAIT_TIME_TEMP 10 /* 10 msec */
47#define SHARPSL_CHECK_BATTERY_WAIT_TIME_VOLT 10 /* 10 msec */
48#define SHARPSL_CHECK_BATTERY_WAIT_TIME_ACIN 10 /* 10 msec */
49#define SHARPSL_CHARGE_WAIT_TIME 15 /* 15 msec */
50#define SHARPSL_CHARGE_CO_CHECK_TIME 5 /* 5 msec */
51#define SHARPSL_CHARGE_RETRY_CNT 1 /* eqv. 10 min */
52
53#define SHARPSL_CHARGE_ON_VOLT 0x99 /* 2.9V */
54#define SHARPSL_CHARGE_ON_TEMP 0xe0 /* 2.9V */
55#define SHARPSL_CHARGE_ON_ACIN_HIGH 0x9b /* 6V */
56#define SHARPSL_CHARGE_ON_ACIN_LOW 0x34 /* 2V */
57#define SHARPSL_FATAL_ACIN_VOLT 182 /* 3.45V */
58#define SHARPSL_FATAL_NOACIN_VOLT 170 /* 3.40V */
59
60struct battery_thresh spitz_battery_levels_acin[] = { 32struct battery_thresh spitz_battery_levels_acin[] = {
61 { 213, 100}, 33 { 213, 100},
62 { 212, 98}, 34 { 212, 98},
@@ -151,763 +123,17 @@ struct battery_thresh spitz_battery_levels_noac[] = {
151#define MAXCTRL_SEL_SH 4 123#define MAXCTRL_SEL_SH 4
152#define MAXCTRL_STR 1u << 7 124#define MAXCTRL_STR 1u << 7
153 125
154/* MAX1111 Channel Definitions */
155#define BATT_AD 4u
156#define BATT_THM 2u
157#define JK_VAD 6u
158
159
160/*
161 * Prototypes
162 */
163static int sharpsl_read_main_battery(void);
164static int sharpsl_off_charge_battery(void);
165static int sharpsl_check_battery_temp(void);
166static int sharpsl_check_battery_voltage(void);
167static int sharpsl_ac_check(void);
168static int sharpsl_fatal_check(void);
169static int sharpsl_average_value(int ad);
170static void sharpsl_average_clear(void);
171static void sharpsl_charge_toggle(void *private_);
172static void sharpsl_battery_thread(void *private_);
173
174
175/*
176 * Variables
177 */
178struct sharpsl_pm_status sharpsl_pm;
179DECLARE_WORK(toggle_charger, sharpsl_charge_toggle, NULL);
180DECLARE_WORK(sharpsl_bat, sharpsl_battery_thread, NULL);
181
182
183static int get_percentage(int voltage)
184{
185 int i = sharpsl_pm.machinfo->bat_levels - 1;
186 struct battery_thresh *thresh;
187
188 if (sharpsl_pm.charge_mode == CHRG_ON)
189 thresh=sharpsl_pm.machinfo->bat_levels_acin;
190 else
191 thresh=sharpsl_pm.machinfo->bat_levels_noac;
192
193 while (i > 0 && (voltage > thresh[i].voltage))
194 i--;
195
196 return thresh[i].percentage;
197}
198
199static int get_apm_status(int voltage)
200{
201 int low_thresh, high_thresh;
202
203 if (sharpsl_pm.charge_mode == CHRG_ON) {
204 high_thresh = sharpsl_pm.machinfo->status_high_acin;
205 low_thresh = sharpsl_pm.machinfo->status_low_acin;
206 } else {
207 high_thresh = sharpsl_pm.machinfo->status_high_noac;
208 low_thresh = sharpsl_pm.machinfo->status_low_noac;
209 }
210
211 if (voltage >= high_thresh)
212 return APM_BATTERY_STATUS_HIGH;
213 if (voltage >= low_thresh)
214 return APM_BATTERY_STATUS_LOW;
215 return APM_BATTERY_STATUS_CRITICAL;
216}
217
218void sharpsl_battery_kick(void)
219{
220 schedule_delayed_work(&sharpsl_bat, msecs_to_jiffies(125));
221}
222EXPORT_SYMBOL(sharpsl_battery_kick);
223
224
225static void sharpsl_battery_thread(void *private_)
226{
227 int voltage, percent, apm_status, i = 0;
228
229 if (!sharpsl_pm.machinfo)
230 return;
231
232 sharpsl_pm.battstat.ac_status = (STATUS_AC_IN() ? APM_AC_ONLINE : APM_AC_OFFLINE);
233
234 /* Corgi cannot confirm when battery fully charged so periodically kick! */
235 if (machine_is_corgi() && (sharpsl_pm.charge_mode == CHRG_ON)
236 && time_after(jiffies, sharpsl_pm.charge_start_time + SHARPSL_CHARGE_ON_TIME_INTERVAL))
237 schedule_work(&toggle_charger);
238
239 while(1) {
240 voltage = sharpsl_read_main_battery();
241 if (voltage > 0) break;
242 if (i++ > 5) {
243 voltage = sharpsl_pm.machinfo->bat_levels_noac[0].voltage;
244 dev_warn(sharpsl_pm.dev, "Warning: Cannot read main battery!\n");
245 break;
246 }
247 }
248
249 voltage = sharpsl_average_value(voltage);
250 apm_status = get_apm_status(voltage);
251 percent = get_percentage(voltage);
252
253 /* At low battery voltages, the voltage has a tendency to start
254 creeping back up so we try to avoid this here */
255 if ((sharpsl_pm.battstat.ac_status == APM_AC_ONLINE) || (apm_status == APM_BATTERY_STATUS_HIGH) || percent <= sharpsl_pm.battstat.mainbat_percent) {
256 sharpsl_pm.battstat.mainbat_voltage = voltage;
257 sharpsl_pm.battstat.mainbat_status = apm_status;
258 sharpsl_pm.battstat.mainbat_percent = percent;
259 }
260
261 dev_dbg(sharpsl_pm.dev, "Battery: voltage: %d, status: %d, percentage: %d, time: %d\n", voltage,
262 sharpsl_pm.battstat.mainbat_status, sharpsl_pm.battstat.mainbat_percent, jiffies);
263
264 /* If battery is low. limit backlight intensity to save power. */
265 if ((sharpsl_pm.battstat.ac_status != APM_AC_ONLINE)
266 && ((sharpsl_pm.battstat.mainbat_status == APM_BATTERY_STATUS_LOW) ||
267 (sharpsl_pm.battstat.mainbat_status == APM_BATTERY_STATUS_CRITICAL))) {
268 if (!(sharpsl_pm.flags & SHARPSL_BL_LIMIT)) {
269 corgibl_limit_intensity(1);
270 sharpsl_pm.flags |= SHARPSL_BL_LIMIT;
271 }
272 } else if (sharpsl_pm.flags & SHARPSL_BL_LIMIT) {
273 corgibl_limit_intensity(0);
274 sharpsl_pm.flags &= ~SHARPSL_BL_LIMIT;
275 }
276
277 /* Suspend if critical battery level */
278 if ((sharpsl_pm.battstat.ac_status != APM_AC_ONLINE)
279 && (sharpsl_pm.battstat.mainbat_status == APM_BATTERY_STATUS_CRITICAL)
280 && !(sharpsl_pm.flags & SHARPSL_APM_QUEUED)) {
281 sharpsl_pm.flags |= SHARPSL_APM_QUEUED;
282 dev_err(sharpsl_pm.dev, "Fatal Off\n");
283 apm_queue_event(APM_CRITICAL_SUSPEND);
284 }
285
286 schedule_delayed_work(&sharpsl_bat, SHARPSL_BATCHK_TIME);
287}
288
289static void sharpsl_charge_on(void)
290{
291 dev_dbg(sharpsl_pm.dev, "Turning Charger On\n");
292
293 sharpsl_pm.full_count = 0;
294 sharpsl_pm.charge_mode = CHRG_ON;
295 schedule_delayed_work(&toggle_charger, msecs_to_jiffies(250));
296 schedule_delayed_work(&sharpsl_bat, msecs_to_jiffies(500));
297}
298
299static void sharpsl_charge_off(void)
300{
301 dev_dbg(sharpsl_pm.dev, "Turning Charger Off\n");
302
303 CHARGE_OFF();
304 CHARGE_LED_OFF();
305 sharpsl_pm.charge_mode = CHRG_OFF;
306
307 schedule_work(&sharpsl_bat);
308}
309
310static void sharpsl_charge_error(void)
311{
312 CHARGE_LED_ERR();
313 CHARGE_OFF();
314 sharpsl_pm.charge_mode = CHRG_ERROR;
315}
316
317static void sharpsl_charge_toggle(void *private_)
318{
319 dev_dbg(sharpsl_pm.dev, "Toogling Charger at time: %lx\n", jiffies);
320
321 if (STATUS_AC_IN() == 0) {
322 sharpsl_charge_off();
323 return;
324 } else if ((sharpsl_check_battery_temp() < 0) || (sharpsl_ac_check() < 0)) {
325 sharpsl_charge_error();
326 return;
327 }
328
329 CHARGE_LED_ON();
330 CHARGE_OFF();
331 mdelay(SHARPSL_CHARGE_WAIT_TIME);
332 CHARGE_ON();
333
334 sharpsl_pm.charge_start_time = jiffies;
335}
336
337static void sharpsl_ac_timer(unsigned long data)
338{
339 int acin = STATUS_AC_IN();
340
341 dev_dbg(sharpsl_pm.dev, "AC Status: %d\n",acin);
342
343 sharpsl_average_clear();
344 if (acin && (sharpsl_pm.charge_mode != CHRG_ON))
345 sharpsl_charge_on();
346 else if (sharpsl_pm.charge_mode == CHRG_ON)
347 sharpsl_charge_off();
348
349 schedule_work(&sharpsl_bat);
350}
351
352
353static irqreturn_t sharpsl_ac_isr(int irq, void *dev_id, struct pt_regs *fp)
354{
355 /* Delay the event slightly to debounce */
356 /* Must be a smaller delay than the chrg_full_isr below */
357 mod_timer(&sharpsl_pm.ac_timer, jiffies + msecs_to_jiffies(250));
358
359 return IRQ_HANDLED;
360}
361
362static void sharpsl_chrg_full_timer(unsigned long data)
363{
364 dev_dbg(sharpsl_pm.dev, "Charge Full at time: %lx\n", jiffies);
365
366 sharpsl_pm.full_count++;
367
368 if (STATUS_AC_IN() == 0) {
369 dev_dbg(sharpsl_pm.dev, "Charge Full: AC removed - stop charging!\n");
370 if (sharpsl_pm.charge_mode == CHRG_ON)
371 sharpsl_charge_off();
372 } else if (sharpsl_pm.full_count < 2) {
373 dev_dbg(sharpsl_pm.dev, "Charge Full: Count too low\n");
374 schedule_work(&toggle_charger);
375 } else if (time_after(jiffies, sharpsl_pm.charge_start_time + SHARPSL_CHARGE_FINISH_TIME)) {
376 dev_dbg(sharpsl_pm.dev, "Charge Full: Interrupt generated too slowly - retry.\n");
377 schedule_work(&toggle_charger);
378 } else {
379 sharpsl_charge_off();
380 sharpsl_pm.charge_mode = CHRG_DONE;
381 dev_dbg(sharpsl_pm.dev, "Charge Full: Charging Finished\n");
382 }
383}
384
385/* Charging Finished Interrupt (Not present on Corgi) */
386/* Can trigger at the same time as an AC staus change so
387 delay until after that has been processed */
388static irqreturn_t sharpsl_chrg_full_isr(int irq, void *dev_id, struct pt_regs *fp)
389{
390 if (sharpsl_pm.flags & SHARPSL_SUSPENDED)
391 return IRQ_HANDLED;
392
393 /* delay until after any ac interrupt */
394 mod_timer(&sharpsl_pm.chrg_full_timer, jiffies + msecs_to_jiffies(500));
395
396 return IRQ_HANDLED;
397}
398
399static irqreturn_t sharpsl_fatal_isr(int irq, void *dev_id, struct pt_regs *fp)
400{
401 int is_fatal = 0;
402
403 if (STATUS_BATT_LOCKED() == 0) {
404 dev_err(sharpsl_pm.dev, "Battery now Unlocked! Suspending.\n");
405 is_fatal = 1;
406 }
407
408 if (sharpsl_pm.machinfo->gpio_fatal && (STATUS_FATAL() == 0)) {
409 dev_err(sharpsl_pm.dev, "Fatal Batt Error! Suspending.\n");
410 is_fatal = 1;
411 }
412
413 if (!(sharpsl_pm.flags & SHARPSL_APM_QUEUED) && is_fatal) {
414 sharpsl_pm.flags |= SHARPSL_APM_QUEUED;
415 apm_queue_event(APM_CRITICAL_SUSPEND);
416 }
417
418 return IRQ_HANDLED;
419}
420
421/*
422 * Maintain an average of the last 10 readings
423 */
424#define SHARPSL_CNV_VALUE_NUM 10
425static int sharpsl_ad_index;
426
427static void sharpsl_average_clear(void)
428{
429 sharpsl_ad_index = 0;
430}
431
432static int sharpsl_average_value(int ad)
433{
434 int i, ad_val = 0;
435 static int sharpsl_ad[SHARPSL_CNV_VALUE_NUM+1];
436
437 if (sharpsl_pm.battstat.mainbat_status != APM_BATTERY_STATUS_HIGH) {
438 sharpsl_ad_index = 0;
439 return ad;
440 }
441
442 sharpsl_ad[sharpsl_ad_index] = ad;
443 sharpsl_ad_index++;
444 if (sharpsl_ad_index >= SHARPSL_CNV_VALUE_NUM) {
445 for (i=0; i < (SHARPSL_CNV_VALUE_NUM-1); i++)
446 sharpsl_ad[i] = sharpsl_ad[i+1];
447 sharpsl_ad_index = SHARPSL_CNV_VALUE_NUM - 1;
448 }
449 for (i=0; i < sharpsl_ad_index; i++)
450 ad_val += sharpsl_ad[i];
451
452 return (ad_val / sharpsl_ad_index);
453}
454
455
456/* 126/*
457 * Read MAX1111 ADC 127 * Read MAX1111 ADC
458 */ 128 */
459static int read_max1111(int channel) 129int sharpsl_pm_pxa_read_max1111(int channel)
460{ 130{
461 return corgi_ssp_max1111_get((channel << MAXCTRL_SEL_SH) | MAXCTRL_PD0 | MAXCTRL_PD1 131 return corgi_ssp_max1111_get((channel << MAXCTRL_SEL_SH) | MAXCTRL_PD0 | MAXCTRL_PD1
462 | MAXCTRL_SGL | MAXCTRL_UNI | MAXCTRL_STR); 132 | MAXCTRL_SGL | MAXCTRL_UNI | MAXCTRL_STR);
463} 133}
464 134
465static int sharpsl_read_main_battery(void) 135void sharpsl_pm_pxa_init(void)
466{
467 return read_max1111(BATT_AD);
468}
469
470static int sharpsl_read_temp(void)
471{ 136{
472 int temp;
473
474 sharpsl_pm.machinfo->measure_temp(1);
475
476 mdelay(SHARPSL_CHECK_BATTERY_WAIT_TIME_TEMP);
477 temp = read_max1111(BATT_THM);
478
479 sharpsl_pm.machinfo->measure_temp(0);
480
481 return temp;
482}
483
484static int sharpsl_read_acin(void)
485{
486 return read_max1111(JK_VAD);
487}
488
489/*
490 * Take an array of 5 integers, remove the maximum and minimum values
491 * and return the average.
492 */
493static int get_select_val(int *val)
494{
495 int i, j, k, temp, sum = 0;
496
497 /* Find MAX val */
498 temp = val[0];
499 j=0;
500 for (i=1; i<5; i++) {
501 if (temp < val[i]) {
502 temp = val[i];
503 j = i;
504 }
505 }
506
507 /* Find MIN val */
508 temp = val[4];
509 k=4;
510 for (i=3; i>=0; i--) {
511 if (temp > val[i]) {
512 temp = val[i];
513 k = i;
514 }
515 }
516
517 for (i=0; i<5; i++)
518 if (i != j && i != k )
519 sum += val[i];
520
521 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]);
522
523 return (sum/3);
524}
525
526static int sharpsl_check_battery_temp(void)
527{
528 int val, i, buff[5];
529
530 /* Check battery temperature */
531 for (i=0; i<5; i++) {
532 mdelay(SHARPSL_CHECK_BATTERY_WAIT_TIME_TEMP);
533 buff[i] = sharpsl_read_temp();
534 }
535
536 val = get_select_val(buff);
537
538 dev_dbg(sharpsl_pm.dev, "Temperature: %d\n", val);
539 if (val > SHARPSL_CHARGE_ON_TEMP)
540 return -1;
541
542 return 0;
543}
544
545static int sharpsl_check_battery_voltage(void)
546{
547 int val, i, buff[5];
548
549 /* disable charge, enable discharge */
550 CHARGE_OFF();
551 DISCHARGE_ON();
552 mdelay(SHARPSL_WAIT_DISCHARGE_ON);
553
554 if (sharpsl_pm.machinfo->discharge1)
555 sharpsl_pm.machinfo->discharge1(1);
556
557 /* Check battery voltage */
558 for (i=0; i<5; i++) {
559 buff[i] = sharpsl_read_main_battery();
560 mdelay(SHARPSL_CHECK_BATTERY_WAIT_TIME_VOLT);
561 }
562
563 if (sharpsl_pm.machinfo->discharge1)
564 sharpsl_pm.machinfo->discharge1(0);
565
566 DISCHARGE_OFF();
567
568 val = get_select_val(buff);
569 dev_dbg(sharpsl_pm.dev, "Battery Voltage: %d\n", val);
570
571 if (val < SHARPSL_CHARGE_ON_VOLT)
572 return -1;
573
574 return 0;
575}
576
577static int sharpsl_ac_check(void)
578{
579 int temp, i, buff[5];
580
581 for (i=0; i<5; i++) {
582 buff[i] = sharpsl_read_acin();
583 mdelay(SHARPSL_CHECK_BATTERY_WAIT_TIME_ACIN);
584 }
585
586 temp = get_select_val(buff);
587 dev_dbg(sharpsl_pm.dev, "AC Voltage: %d\n",temp);
588
589 if ((temp > SHARPSL_CHARGE_ON_ACIN_HIGH) || (temp < SHARPSL_CHARGE_ON_ACIN_LOW)) {
590 dev_err(sharpsl_pm.dev, "Error: AC check failed.\n");
591 return -1;
592 }
593
594 return 0;
595}
596
597#ifdef CONFIG_PM
598static int sharpsl_pm_suspend(struct platform_device *pdev, pm_message_t state)
599{
600 sharpsl_pm.flags |= SHARPSL_SUSPENDED;
601 flush_scheduled_work();
602
603 if (sharpsl_pm.charge_mode == CHRG_ON)
604 sharpsl_pm.flags |= SHARPSL_DO_OFFLINE_CHRG;
605 else
606 sharpsl_pm.flags &= ~SHARPSL_DO_OFFLINE_CHRG;
607
608 return 0;
609}
610
611static int sharpsl_pm_resume(struct platform_device *pdev)
612{
613 /* Clear the reset source indicators as they break the bootloader upon reboot */
614 RCSR = 0x0f;
615 sharpsl_average_clear();
616 sharpsl_pm.flags &= ~SHARPSL_APM_QUEUED;
617 sharpsl_pm.flags &= ~SHARPSL_SUSPENDED;
618
619 return 0;
620}
621
622static void corgi_goto_sleep(unsigned long alarm_time, unsigned int alarm_enable, suspend_state_t state)
623{
624 dev_dbg(sharpsl_pm.dev, "Time is: %08x\n",RCNR);
625
626 dev_dbg(sharpsl_pm.dev, "Offline Charge Activate = %d\n",sharpsl_pm.flags & SHARPSL_DO_OFFLINE_CHRG);
627 /* not charging and AC-IN! */
628
629 if ((sharpsl_pm.flags & SHARPSL_DO_OFFLINE_CHRG) && (STATUS_AC_IN() != 0)) {
630 dev_dbg(sharpsl_pm.dev, "Activating Offline Charger...\n");
631 sharpsl_pm.charge_mode = CHRG_OFF;
632 sharpsl_pm.flags &= ~SHARPSL_DO_OFFLINE_CHRG;
633 sharpsl_off_charge_battery();
634 }
635
636 sharpsl_pm.machinfo->presuspend();
637
638 PEDR = 0xffffffff; /* clear it */
639
640 sharpsl_pm.flags &= ~SHARPSL_ALARM_ACTIVE;
641 if ((sharpsl_pm.charge_mode == CHRG_ON) && ((alarm_enable && ((alarm_time - RCNR) > (SHARPSL_BATCHK_TIME_SUSPEND + 30))) || !alarm_enable)) {
642 RTSR &= RTSR_ALE;
643 RTAR = RCNR + SHARPSL_BATCHK_TIME_SUSPEND;
644 dev_dbg(sharpsl_pm.dev, "Charging alarm at: %08x\n",RTAR);
645 sharpsl_pm.flags |= SHARPSL_ALARM_ACTIVE;
646 } else if (alarm_enable) {
647 RTSR &= RTSR_ALE;
648 RTAR = alarm_time;
649 dev_dbg(sharpsl_pm.dev, "User alarm at: %08x\n",RTAR);
650 } else {
651 dev_dbg(sharpsl_pm.dev, "No alarms set.\n");
652 }
653
654 pxa_pm_enter(state);
655
656 sharpsl_pm.machinfo->postsuspend();
657
658 dev_dbg(sharpsl_pm.dev, "Corgi woken up from suspend: %08x\n",PEDR);
659}
660
661static int corgi_enter_suspend(unsigned long alarm_time, unsigned int alarm_enable, suspend_state_t state)
662{
663 if (!sharpsl_pm.machinfo->should_wakeup(!(sharpsl_pm.flags & SHARPSL_ALARM_ACTIVE) && alarm_enable) )
664 {
665 if (!(sharpsl_pm.flags & SHARPSL_ALARM_ACTIVE)) {
666 dev_dbg(sharpsl_pm.dev, "No user triggered wakeup events and not charging. Strange. Suspend.\n");
667 corgi_goto_sleep(alarm_time, alarm_enable, state);
668 return 1;
669 }
670 if(sharpsl_off_charge_battery()) {
671 dev_dbg(sharpsl_pm.dev, "Charging. Suspend...\n");
672 corgi_goto_sleep(alarm_time, alarm_enable, state);
673 return 1;
674 }
675 dev_dbg(sharpsl_pm.dev, "User triggered wakeup in offline charger.\n");
676 }
677
678 if ((STATUS_BATT_LOCKED() == 0) || (sharpsl_fatal_check() < 0) )
679 {
680 dev_err(sharpsl_pm.dev, "Fatal condition. Suspend.\n");
681 corgi_goto_sleep(alarm_time, alarm_enable, state);
682 return 1;
683 }
684
685 return 0;
686}
687
688static int corgi_pxa_pm_enter(suspend_state_t state)
689{
690 unsigned long alarm_time = RTAR;
691 unsigned int alarm_status = ((RTSR & RTSR_ALE) != 0);
692
693 dev_dbg(sharpsl_pm.dev, "SharpSL suspending for first time.\n");
694
695 corgi_goto_sleep(alarm_time, alarm_status, state);
696
697 while (corgi_enter_suspend(alarm_time,alarm_status,state))
698 {}
699
700 dev_dbg(sharpsl_pm.dev, "SharpSL resuming...\n");
701
702 return 0;
703}
704#endif
705
706
707/*
708 * Check for fatal battery errors
709 * Fatal returns -1
710 */
711static int sharpsl_fatal_check(void)
712{
713 int buff[5], temp, i, acin;
714
715 dev_dbg(sharpsl_pm.dev, "sharpsl_fatal_check entered\n");
716
717 /* Check AC-Adapter */
718 acin = STATUS_AC_IN();
719
720 if (acin && (sharpsl_pm.charge_mode == CHRG_ON)) {
721 CHARGE_OFF();
722 udelay(100);
723 DISCHARGE_ON(); /* enable discharge */
724 mdelay(SHARPSL_WAIT_DISCHARGE_ON);
725 }
726
727 if (sharpsl_pm.machinfo->discharge1)
728 sharpsl_pm.machinfo->discharge1(1);
729
730 /* Check battery : check inserting battery ? */
731 for (i=0; i<5; i++) {
732 buff[i] = sharpsl_read_main_battery();
733 mdelay(SHARPSL_CHECK_BATTERY_WAIT_TIME_VOLT);
734 }
735
736 if (sharpsl_pm.machinfo->discharge1)
737 sharpsl_pm.machinfo->discharge1(0);
738
739 if (acin && (sharpsl_pm.charge_mode == CHRG_ON)) {
740 udelay(100);
741 CHARGE_ON();
742 DISCHARGE_OFF();
743 }
744
745 temp = get_select_val(buff);
746 dev_dbg(sharpsl_pm.dev, "sharpsl_fatal_check: acin: %d, discharge voltage: %d, no discharge: %d\n", acin, temp, sharpsl_read_main_battery());
747
748 if ((acin && (temp < SHARPSL_FATAL_ACIN_VOLT)) ||
749 (!acin && (temp < SHARPSL_FATAL_NOACIN_VOLT)))
750 return -1;
751 return 0;
752}
753
754static int sharpsl_off_charge_error(void)
755{
756 dev_err(sharpsl_pm.dev, "Offline Charger: Error occured.\n");
757 CHARGE_OFF();
758 CHARGE_LED_ERR();
759 sharpsl_pm.charge_mode = CHRG_ERROR;
760 return 1;
761}
762
763/*
764 * Charging Control while suspended
765 * Return 1 - go straight to sleep
766 * Return 0 - sleep or wakeup depending on other factors
767 */
768static int sharpsl_off_charge_battery(void)
769{
770 int time;
771
772 dev_dbg(sharpsl_pm.dev, "Charge Mode: %d\n", sharpsl_pm.charge_mode);
773
774 if (sharpsl_pm.charge_mode == CHRG_OFF) {
775 dev_dbg(sharpsl_pm.dev, "Offline Charger: Step 1\n");
776
777 /* AC Check */
778 if ((sharpsl_ac_check() < 0) || (sharpsl_check_battery_temp() < 0))
779 return sharpsl_off_charge_error();
780
781 /* Start Charging */
782 CHARGE_LED_ON();
783 CHARGE_OFF();
784 mdelay(SHARPSL_CHARGE_WAIT_TIME);
785 CHARGE_ON();
786
787 sharpsl_pm.charge_mode = CHRG_ON;
788 sharpsl_pm.full_count = 0;
789
790 return 1;
791 } else if (sharpsl_pm.charge_mode != CHRG_ON) {
792 return 1;
793 }
794
795 if (sharpsl_pm.full_count == 0) {
796 int time;
797
798 dev_dbg(sharpsl_pm.dev, "Offline Charger: Step 2\n");
799
800 if ((sharpsl_check_battery_temp() < 0) || (sharpsl_check_battery_voltage() < 0))
801 return sharpsl_off_charge_error();
802
803 CHARGE_OFF();
804 mdelay(SHARPSL_CHARGE_WAIT_TIME);
805 CHARGE_ON();
806 sharpsl_pm.charge_mode = CHRG_ON;
807
808 mdelay(SHARPSL_CHARGE_CO_CHECK_TIME);
809
810 time = RCNR;
811 while(1) {
812 /* Check if any wakeup event had occured */
813 if (sharpsl_pm.machinfo->charger_wakeup() != 0)
814 return 0;
815 /* Check for timeout */
816 if ((RCNR - time) > SHARPSL_WAIT_CO_TIME)
817 return 1;
818 if (STATUS_CHRG_FULL()) {
819 dev_dbg(sharpsl_pm.dev, "Offline Charger: Charge full occured. Retrying to check\n");
820 sharpsl_pm.full_count++;
821 CHARGE_OFF();
822 mdelay(SHARPSL_CHARGE_WAIT_TIME);
823 CHARGE_ON();
824 return 1;
825 }
826 }
827 }
828
829 dev_dbg(sharpsl_pm.dev, "Offline Charger: Step 3\n");
830
831 mdelay(SHARPSL_CHARGE_CO_CHECK_TIME);
832
833 time = RCNR;
834 while(1) {
835 /* Check if any wakeup event had occured */
836 if (sharpsl_pm.machinfo->charger_wakeup() != 0)
837 return 0;
838 /* Check for timeout */
839 if ((RCNR-time) > SHARPSL_WAIT_CO_TIME) {
840 if (sharpsl_pm.full_count > SHARPSL_CHARGE_RETRY_CNT) {
841 dev_dbg(sharpsl_pm.dev, "Offline Charger: Not charged sufficiently. Retrying.\n");
842 sharpsl_pm.full_count = 0;
843 }
844 sharpsl_pm.full_count++;
845 return 1;
846 }
847 if (STATUS_CHRG_FULL()) {
848 dev_dbg(sharpsl_pm.dev, "Offline Charger: Charging complete.\n");
849 CHARGE_LED_OFF();
850 CHARGE_OFF();
851 sharpsl_pm.charge_mode = CHRG_DONE;
852 return 1;
853 }
854 }
855}
856
857
858static ssize_t battery_percentage_show(struct device *dev, struct device_attribute *attr, char *buf)
859{
860 return sprintf(buf, "%d\n",sharpsl_pm.battstat.mainbat_percent);
861}
862
863static ssize_t battery_voltage_show(struct device *dev, struct device_attribute *attr, char *buf)
864{
865 return sprintf(buf, "%d\n",sharpsl_pm.battstat.mainbat_voltage);
866}
867
868static DEVICE_ATTR(battery_percentage, 0444, battery_percentage_show, NULL);
869static DEVICE_ATTR(battery_voltage, 0444, battery_voltage_show, NULL);
870
871extern void (*apm_get_power_status)(struct apm_power_info *);
872
873static void sharpsl_apm_get_power_status(struct apm_power_info *info)
874{
875 info->ac_line_status = sharpsl_pm.battstat.ac_status;
876
877 if (sharpsl_pm.charge_mode == CHRG_ON)
878 info->battery_status = APM_BATTERY_STATUS_CHARGING;
879 else
880 info->battery_status = sharpsl_pm.battstat.mainbat_status;
881
882 info->battery_flag = (1 << info->battery_status);
883 info->battery_life = sharpsl_pm.battstat.mainbat_percent;
884}
885
886static struct pm_ops sharpsl_pm_ops = {
887 .pm_disk_mode = PM_DISK_FIRMWARE,
888 .prepare = pxa_pm_prepare,
889 .enter = corgi_pxa_pm_enter,
890 .finish = pxa_pm_finish,
891};
892
893static int __init sharpsl_pm_probe(struct platform_device *pdev)
894{
895 if (!pdev->dev.platform_data)
896 return -EINVAL;
897
898 sharpsl_pm.dev = &pdev->dev;
899 sharpsl_pm.machinfo = pdev->dev.platform_data;
900 sharpsl_pm.charge_mode = CHRG_OFF;
901 sharpsl_pm.flags = 0;
902
903 sharpsl_pm.machinfo->init();
904
905 init_timer(&sharpsl_pm.ac_timer);
906 sharpsl_pm.ac_timer.function = sharpsl_ac_timer;
907
908 init_timer(&sharpsl_pm.chrg_full_timer);
909 sharpsl_pm.chrg_full_timer.function = sharpsl_chrg_full_timer;
910
911 pxa_gpio_mode(sharpsl_pm.machinfo->gpio_acin | GPIO_IN); 137 pxa_gpio_mode(sharpsl_pm.machinfo->gpio_acin | GPIO_IN);
912 pxa_gpio_mode(sharpsl_pm.machinfo->gpio_batfull | GPIO_IN); 138 pxa_gpio_mode(sharpsl_pm.machinfo->gpio_batfull | GPIO_IN);
913 pxa_gpio_mode(sharpsl_pm.machinfo->gpio_batlock | GPIO_IN); 139 pxa_gpio_mode(sharpsl_pm.machinfo->gpio_batlock | GPIO_IN);
@@ -938,26 +164,10 @@ static int __init sharpsl_pm_probe(struct platform_device *pdev)
938 } 164 }
939 else set_irq_type(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batfull),IRQT_RISING); 165 else set_irq_type(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batfull),IRQT_RISING);
940 } 166 }
941
942 device_create_file(&pdev->dev, &dev_attr_battery_percentage);
943 device_create_file(&pdev->dev, &dev_attr_battery_voltage);
944
945 apm_get_power_status = sharpsl_apm_get_power_status;
946
947 pm_set_ops(&sharpsl_pm_ops);
948
949 mod_timer(&sharpsl_pm.ac_timer, jiffies + msecs_to_jiffies(250));
950
951 return 0;
952} 167}
953 168
954static int sharpsl_pm_remove(struct platform_device *pdev) 169void sharpsl_pm_pxa_remove(void)
955{ 170{
956 pm_set_ops(NULL);
957
958 device_remove_file(&pdev->dev, &dev_attr_battery_percentage);
959 device_remove_file(&pdev->dev, &dev_attr_battery_voltage);
960
961 free_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_acin), sharpsl_ac_isr); 171 free_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_acin), sharpsl_ac_isr);
962 free_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batlock), sharpsl_fatal_isr); 172 free_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batlock), sharpsl_fatal_isr);
963 173
@@ -966,32 +176,4 @@ static int sharpsl_pm_remove(struct platform_device *pdev)
966 176
967 if (!machine_is_corgi()) 177 if (!machine_is_corgi())
968 free_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batfull), sharpsl_chrg_full_isr); 178 free_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batfull), sharpsl_chrg_full_isr);
969
970 del_timer_sync(&sharpsl_pm.chrg_full_timer);
971 del_timer_sync(&sharpsl_pm.ac_timer);
972
973 return 0;
974} 179}
975
976static struct platform_driver sharpsl_pm_driver = {
977 .probe = sharpsl_pm_probe,
978 .remove = sharpsl_pm_remove,
979 .suspend = sharpsl_pm_suspend,
980 .resume = sharpsl_pm_resume,
981 .driver = {
982 .name = "sharpsl-pm",
983 },
984};
985
986static int __devinit sharpsl_pm_init(void)
987{
988 return platform_driver_register(&sharpsl_pm_driver);
989}
990
991static void sharpsl_pm_exit(void)
992{
993 platform_driver_unregister(&sharpsl_pm_driver);
994}
995
996late_initcall(sharpsl_pm_init);
997module_exit(sharpsl_pm_exit);
diff --git a/arch/arm/mach-pxa/spitz.c b/arch/arm/mach-pxa/spitz.c
index 2df1b56615b1..f2007db0cda5 100644
--- a/arch/arm/mach-pxa/spitz.c
+++ b/arch/arm/mach-pxa/spitz.c
@@ -36,6 +36,7 @@
36#include <asm/arch/irq.h> 36#include <asm/arch/irq.h>
37#include <asm/arch/irda.h> 37#include <asm/arch/irda.h>
38#include <asm/arch/mmc.h> 38#include <asm/arch/mmc.h>
39#include <asm/arch/ohci.h>
39#include <asm/arch/udc.h> 40#include <asm/arch/udc.h>
40#include <asm/arch/pxafb.h> 41#include <asm/arch/pxafb.h>
41#include <asm/arch/akita.h> 42#include <asm/arch/akita.h>
@@ -126,10 +127,12 @@ static void spitz_card_pwr_ctrl(int device, unsigned short new_cpr)
126 cpr &= ~0x0002; 127 cpr &= ~0x0002;
127 if (device == SPITZ_PWR_SD) 128 if (device == SPITZ_PWR_SD)
128 cpr &= ~0x0004; 129 cpr &= ~0x0004;
129 write_scoop_reg(&spitzscoop_device.dev, SCOOP_CPR, cpr | new_cpr);
130 if (!(cpr & 0x0002) && !(cpr & 0x0004)) { 130 if (!(cpr & 0x0002) && !(cpr & 0x0004)) {
131 write_scoop_reg(&spitzscoop_device.dev, SCOOP_CPR, 0x0000);
131 mdelay(1); 132 mdelay(1);
132 reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_CF_POWER); 133 reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_CF_POWER);
134 } else {
135 write_scoop_reg(&spitzscoop_device.dev, SCOOP_CPR, cpr | new_cpr);
133 } 136 }
134 } 137 }
135} 138}
@@ -335,6 +338,35 @@ static struct pxamci_platform_data spitz_mci_platform_data = {
335 338
336 339
337/* 340/*
341 * USB Host (OHCI)
342 */
343static int spitz_ohci_init(struct device *dev)
344{
345 /* Only Port 2 is connected */
346 pxa_gpio_mode(SPITZ_GPIO_USB_CONNECT | GPIO_IN);
347 pxa_gpio_mode(SPITZ_GPIO_USB_HOST | GPIO_OUT);
348 pxa_gpio_mode(SPITZ_GPIO_USB_DEVICE | GPIO_IN);
349
350 /* Setup USB Port 2 Output Control Register */
351 UP2OCR = UP2OCR_HXS | UP2OCR_HXOE | UP2OCR_DPPDE | UP2OCR_DMPDE;
352
353 GPSR(SPITZ_GPIO_USB_HOST) = GPIO_bit(SPITZ_GPIO_USB_HOST);
354
355 UHCHR = (UHCHR) &
356 ~(UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSEP3 | UHCHR_SSE);
357
358 UHCRHDA |= UHCRHDA_NOCP;
359
360 return 0;
361}
362
363static struct pxaohci_platform_data spitz_ohci_platform_data = {
364 .port_mode = PMM_NPS_MODE,
365 .init = spitz_ohci_init,
366};
367
368
369/*
338 * Irda 370 * Irda
339 */ 371 */
340static void spitz_irda_transceiver_mode(struct device *dev, int mode) 372static void spitz_irda_transceiver_mode(struct device *dev, int mode)
@@ -411,6 +443,7 @@ static void __init common_init(void)
411 443
412 platform_add_devices(devices, ARRAY_SIZE(devices)); 444 platform_add_devices(devices, ARRAY_SIZE(devices));
413 pxa_set_mci_info(&spitz_mci_platform_data); 445 pxa_set_mci_info(&spitz_mci_platform_data);
446 pxa_set_ohci_info(&spitz_ohci_platform_data);
414 pxa_set_ficp_info(&spitz_ficp_platform_data); 447 pxa_set_ficp_info(&spitz_ficp_platform_data);
415 set_pxa_fb_parent(&spitzssp_device.dev); 448 set_pxa_fb_parent(&spitzssp_device.dev);
416 set_pxa_fb_info(&spitz_pxafb_info); 449 set_pxa_fb_info(&spitz_pxafb_info);
diff --git a/arch/arm/mach-pxa/spitz_pm.c b/arch/arm/mach-pxa/spitz_pm.c
index 3ce7486daa51..5e5bdc898482 100644
--- a/arch/arm/mach-pxa/spitz_pm.c
+++ b/arch/arm/mach-pxa/spitz_pm.c
@@ -33,19 +33,7 @@ static void spitz_charger_init(void)
33{ 33{
34 pxa_gpio_mode(SPITZ_GPIO_KEY_INT | GPIO_IN); 34 pxa_gpio_mode(SPITZ_GPIO_KEY_INT | GPIO_IN);
35 pxa_gpio_mode(SPITZ_GPIO_SYNC | GPIO_IN); 35 pxa_gpio_mode(SPITZ_GPIO_SYNC | GPIO_IN);
36} 36 sharpsl_pm_pxa_init();
37
38static void spitz_charge_led(int val)
39{
40 if (val == SHARPSL_LED_ERROR) {
41 dev_dbg(sharpsl_pm.dev, "Charge LED Error\n");
42 } else if (val == SHARPSL_LED_ON) {
43 dev_dbg(sharpsl_pm.dev, "Charge LED On\n");
44 set_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_LED_ORANGE);
45 } else {
46 dev_dbg(sharpsl_pm.dev, "Charge LED Off\n");
47 reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_LED_ORANGE);
48 }
49} 37}
50 38
51static void spitz_measure_temp(int on) 39static void spitz_measure_temp(int on)
@@ -92,7 +80,7 @@ static void spitz_discharge1(int on)
92 80
93static void spitz_presuspend(void) 81static void spitz_presuspend(void)
94{ 82{
95 spitz_last_ac_status = STATUS_AC_IN(); 83 spitz_last_ac_status = sharpsl_pm.machinfo->read_devdata(SHARPSL_STATUS_ACIN);
96 84
97 /* GPIO Sleep Register */ 85 /* GPIO Sleep Register */
98 PGSR0 = 0x00144018; 86 PGSR0 = 0x00144018;
@@ -138,7 +126,7 @@ static void spitz_postsuspend(void)
138static int spitz_should_wakeup(unsigned int resume_on_alarm) 126static int spitz_should_wakeup(unsigned int resume_on_alarm)
139{ 127{
140 int is_resume = 0; 128 int is_resume = 0;
141 int acin = STATUS_AC_IN(); 129 int acin = sharpsl_pm.machinfo->read_devdata(SHARPSL_STATUS_ACIN);
142 130
143 if (spitz_last_ac_status != acin) { 131 if (spitz_last_ac_status != acin) {
144 if (acin) { 132 if (acin) {
@@ -148,8 +136,8 @@ static int spitz_should_wakeup(unsigned int resume_on_alarm)
148 } else { 136 } else {
149 /* charge off */ 137 /* charge off */
150 dev_dbg(sharpsl_pm.dev, "AC Removed\n"); 138 dev_dbg(sharpsl_pm.dev, "AC Removed\n");
151 CHARGE_LED_OFF(); 139 sharpsl_pm_led(SHARPSL_LED_OFF);
152 CHARGE_OFF(); 140 sharpsl_pm.machinfo->charge(0);
153 sharpsl_pm.charge_mode = CHRG_OFF; 141 sharpsl_pm.charge_mode = CHRG_OFF;
154 } 142 }
155 spitz_last_ac_status = acin; 143 spitz_last_ac_status = acin;
@@ -175,25 +163,41 @@ static unsigned long spitz_charger_wakeup(void)
175 return (~GPLR0 & GPIO_bit(SPITZ_GPIO_KEY_INT)) | (GPLR0 & GPIO_bit(SPITZ_GPIO_SYNC)); 163 return (~GPLR0 & GPIO_bit(SPITZ_GPIO_KEY_INT)) | (GPLR0 & GPIO_bit(SPITZ_GPIO_SYNC));
176} 164}
177 165
178static int spitz_acin_status(void) 166unsigned long spitzpm_read_devdata(int type)
179{ 167{
180 return (((~GPLR(SPITZ_GPIO_AC_IN)) & GPIO_bit(SPITZ_GPIO_AC_IN)) != 0); 168 switch(type) {
169 case SHARPSL_STATUS_ACIN:
170 return (((~GPLR(SPITZ_GPIO_AC_IN)) & GPIO_bit(SPITZ_GPIO_AC_IN)) != 0);
171 case SHARPSL_STATUS_LOCK:
172 return READ_GPIO_BIT(sharpsl_pm.machinfo->gpio_batlock);
173 case SHARPSL_STATUS_CHRGFULL:
174 return READ_GPIO_BIT(sharpsl_pm.machinfo->gpio_batfull);
175 case SHARPSL_STATUS_FATAL:
176 return READ_GPIO_BIT(sharpsl_pm.machinfo->gpio_fatal);
177 case SHARPSL_ACIN_VOLT:
178 return sharpsl_pm_pxa_read_max1111(MAX1111_ACIN_VOLT);
179 case SHARPSL_BATT_TEMP:
180 return sharpsl_pm_pxa_read_max1111(MAX1111_BATT_TEMP);
181 case SHARPSL_BATT_VOLT:
182 default:
183 return sharpsl_pm_pxa_read_max1111(MAX1111_BATT_VOLT);
184 }
181} 185}
182 186
183struct sharpsl_charger_machinfo spitz_pm_machinfo = { 187struct sharpsl_charger_machinfo spitz_pm_machinfo = {
184 .init = spitz_charger_init, 188 .init = spitz_charger_init,
189 .exit = sharpsl_pm_pxa_remove,
185 .gpio_batlock = SPITZ_GPIO_BAT_COVER, 190 .gpio_batlock = SPITZ_GPIO_BAT_COVER,
186 .gpio_acin = SPITZ_GPIO_AC_IN, 191 .gpio_acin = SPITZ_GPIO_AC_IN,
187 .gpio_batfull = SPITZ_GPIO_CHRG_FULL, 192 .gpio_batfull = SPITZ_GPIO_CHRG_FULL,
188 .gpio_fatal = SPITZ_GPIO_FATAL_BAT, 193 .gpio_fatal = SPITZ_GPIO_FATAL_BAT,
189 .status_acin = spitz_acin_status,
190 .discharge = spitz_discharge, 194 .discharge = spitz_discharge,
191 .discharge1 = spitz_discharge1, 195 .discharge1 = spitz_discharge1,
192 .charge = spitz_charge, 196 .charge = spitz_charge,
193 .chargeled = spitz_charge_led,
194 .measure_temp = spitz_measure_temp, 197 .measure_temp = spitz_measure_temp,
195 .presuspend = spitz_presuspend, 198 .presuspend = spitz_presuspend,
196 .postsuspend = spitz_postsuspend, 199 .postsuspend = spitz_postsuspend,
200 .read_devdata = spitzpm_read_devdata,
197 .charger_wakeup = spitz_charger_wakeup, 201 .charger_wakeup = spitz_charger_wakeup,
198 .should_wakeup = spitz_should_wakeup, 202 .should_wakeup = spitz_should_wakeup,
199 .bat_levels = 40, 203 .bat_levels = 40,