aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorRichard Purdie <rpurdie@rpsys.net>2005-11-13 05:07:47 -0500
committerRussell King <rmk+kernel@arm.linux.org.uk>2005-11-13 05:07:47 -0500
commite8b6f7f437a624fc2e2a2ec92fbeffdcf6f0e11e (patch)
tree2b80123b811f59c733b6a77615bc4a236863be8d /arch
parentd72f25b0dfb0807bd758da56a7ed88c0eb6e70d8 (diff)
[ARM] 3159/1: SharpSL: Add PM device driver for the SL-Cx00 machines.
Patch from Richard Purdie Add a SharpSL PM device driver for the SL-Cxx00 machines. Signed-off-by: Richard Purdie <rpurdie@rpsys.net> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Diffstat (limited to 'arch')
-rw-r--r--arch/arm/mach-pxa/Makefile2
-rw-r--r--arch/arm/mach-pxa/spitz_pm.c233
2 files changed, 234 insertions, 1 deletions
diff --git a/arch/arm/mach-pxa/Makefile b/arch/arm/mach-pxa/Makefile
index eecc5c199678..c83092e298a7 100644
--- a/arch/arm/mach-pxa/Makefile
+++ b/arch/arm/mach-pxa/Makefile
@@ -12,7 +12,7 @@ obj-$(CONFIG_ARCH_LUBBOCK) += lubbock.o
12obj-$(CONFIG_MACH_MAINSTONE) += mainstone.o 12obj-$(CONFIG_MACH_MAINSTONE) += mainstone.o
13obj-$(CONFIG_ARCH_PXA_IDP) += idp.o 13obj-$(CONFIG_ARCH_PXA_IDP) += idp.o
14obj-$(CONFIG_PXA_SHARP_C7xx) += corgi.o corgi_ssp.o corgi_lcd.o sharpsl_pm.o corgi_pm.o 14obj-$(CONFIG_PXA_SHARP_C7xx) += corgi.o corgi_ssp.o corgi_lcd.o sharpsl_pm.o corgi_pm.o
15obj-$(CONFIG_PXA_SHARP_Cxx00) += spitz.o corgi_ssp.o corgi_lcd.o 15obj-$(CONFIG_PXA_SHARP_Cxx00) += spitz.o corgi_ssp.o corgi_lcd.o sharpsl_pm.o spitz_pm.o
16obj-$(CONFIG_MACH_POODLE) += poodle.o 16obj-$(CONFIG_MACH_POODLE) += poodle.o
17obj-$(CONFIG_MACH_TOSA) += tosa.o 17obj-$(CONFIG_MACH_TOSA) += tosa.o
18 18
diff --git a/arch/arm/mach-pxa/spitz_pm.c b/arch/arm/mach-pxa/spitz_pm.c
new file mode 100644
index 000000000000..3ce7486daa51
--- /dev/null
+++ b/arch/arm/mach-pxa/spitz_pm.c
@@ -0,0 +1,233 @@
1/*
2 * Battery and Power Management code for the Sharp SL-Cxx00
3 *
4 * Copyright (c) 2005 Richard Purdie
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 */
11
12#include <linux/module.h>
13#include <linux/stat.h>
14#include <linux/init.h>
15#include <linux/kernel.h>
16#include <linux/delay.h>
17#include <linux/interrupt.h>
18#include <linux/platform_device.h>
19#include <asm/apm.h>
20#include <asm/irq.h>
21#include <asm/mach-types.h>
22#include <asm/hardware.h>
23#include <asm/hardware/scoop.h>
24
25#include <asm/arch/sharpsl.h>
26#include <asm/arch/spitz.h>
27#include <asm/arch/pxa-regs.h>
28#include "sharpsl.h"
29
30static int spitz_last_ac_status;
31
32static void spitz_charger_init(void)
33{
34 pxa_gpio_mode(SPITZ_GPIO_KEY_INT | GPIO_IN);
35 pxa_gpio_mode(SPITZ_GPIO_SYNC | GPIO_IN);
36}
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}
50
51static void spitz_measure_temp(int on)
52{
53 if (on)
54 set_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_ADC_TEMP_ON);
55 else
56 reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_ADC_TEMP_ON);
57}
58
59static void spitz_charge(int on)
60{
61 if (on) {
62 if (sharpsl_pm.flags & SHARPSL_SUSPENDED) {
63 set_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_JK_B);
64 reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_CHRG_ON);
65 } else {
66 reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_JK_B);
67 reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_CHRG_ON);
68 }
69 } else {
70 reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_JK_B);
71 set_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_CHRG_ON);
72 }
73}
74
75static void spitz_discharge(int on)
76{
77 if (on)
78 set_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_JK_A);
79 else
80 reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_JK_A);
81}
82
83/* HACK - For unknown reasons, accurate voltage readings are only made with a load
84 on the power bus which the green led on spitz provides */
85static void spitz_discharge1(int on)
86{
87 if (on)
88 set_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_LED_GREEN);
89 else
90 reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_LED_GREEN);
91}
92
93static void spitz_presuspend(void)
94{
95 spitz_last_ac_status = STATUS_AC_IN();
96
97 /* GPIO Sleep Register */
98 PGSR0 = 0x00144018;
99 PGSR1 = 0x00EF0000;
100 if (machine_is_akita()) {
101 PGSR2 = 0x2121C000;
102 PGSR3 = 0x00600400;
103 } else {
104 PGSR2 = 0x0121C000;
105 PGSR3 = 0x00600000;
106 }
107
108 PGSR0 &= ~SPITZ_GPIO_G0_STROBE_BIT;
109 PGSR1 &= ~SPITZ_GPIO_G1_STROBE_BIT;
110 PGSR2 &= ~SPITZ_GPIO_G2_STROBE_BIT;
111 PGSR3 &= ~SPITZ_GPIO_G3_STROBE_BIT;
112 PGSR2 |= GPIO_bit(SPITZ_GPIO_KEY_STROBE0);
113
114 pxa_gpio_mode(GPIO18_RDY|GPIO_OUT | GPIO_DFLT_HIGH);
115
116 PRER = GPIO_bit(SPITZ_GPIO_KEY_INT);
117 PFER = GPIO_bit(SPITZ_GPIO_KEY_INT) | GPIO_bit(SPITZ_GPIO_RESET);
118 PWER = GPIO_bit(SPITZ_GPIO_KEY_INT) | GPIO_bit(SPITZ_GPIO_RESET) | PWER_RTC;
119 PKWR = GPIO_bit(SPITZ_GPIO_SYNC) | GPIO_bit(SPITZ_GPIO_KEY_INT) | GPIO_bit(SPITZ_GPIO_RESET);
120 PKSR = 0xffffffff; // clear
121
122 /* nRESET_OUT Disable */
123 PSLR |= PSLR_SL_ROD;
124
125 /* Clear reset status */
126 RCSR = RCSR_HWR | RCSR_WDR | RCSR_SMR | RCSR_GPR;
127
128 /* Stop 3.6MHz and drive HIGH to PCMCIA and CS */
129 PCFR = PCFR_GPR_EN | PCFR_OPDE;
130}
131
132static void spitz_postsuspend(void)
133{
134 pxa_gpio_mode(GPIO18_RDY_MD);
135 pxa_gpio_mode(10 | GPIO_IN);
136}
137
138static int spitz_should_wakeup(unsigned int resume_on_alarm)
139{
140 int is_resume = 0;
141 int acin = STATUS_AC_IN();
142
143 if (spitz_last_ac_status != acin) {
144 if (acin) {
145 /* charge on */
146 sharpsl_pm.flags |= SHARPSL_DO_OFFLINE_CHRG;
147 dev_dbg(sharpsl_pm.dev, "AC Inserted\n");
148 } else {
149 /* charge off */
150 dev_dbg(sharpsl_pm.dev, "AC Removed\n");
151 CHARGE_LED_OFF();
152 CHARGE_OFF();
153 sharpsl_pm.charge_mode = CHRG_OFF;
154 }
155 spitz_last_ac_status = acin;
156 /* Return to suspend as this must be what we were woken for */
157 return 0;
158 }
159
160 if (PEDR & GPIO_bit(SPITZ_GPIO_KEY_INT))
161 is_resume |= GPIO_bit(SPITZ_GPIO_KEY_INT);
162
163 if (PKSR & GPIO_bit(SPITZ_GPIO_SYNC))
164 is_resume |= GPIO_bit(SPITZ_GPIO_SYNC);
165
166 if (resume_on_alarm && (PEDR & PWER_RTC))
167 is_resume |= PWER_RTC;
168
169 dev_dbg(sharpsl_pm.dev, "is_resume: %x\n",is_resume);
170 return is_resume;
171}
172
173static unsigned long spitz_charger_wakeup(void)
174{
175 return (~GPLR0 & GPIO_bit(SPITZ_GPIO_KEY_INT)) | (GPLR0 & GPIO_bit(SPITZ_GPIO_SYNC));
176}
177
178static int spitz_acin_status(void)
179{
180 return (((~GPLR(SPITZ_GPIO_AC_IN)) & GPIO_bit(SPITZ_GPIO_AC_IN)) != 0);
181}
182
183struct sharpsl_charger_machinfo spitz_pm_machinfo = {
184 .init = spitz_charger_init,
185 .gpio_batlock = SPITZ_GPIO_BAT_COVER,
186 .gpio_acin = SPITZ_GPIO_AC_IN,
187 .gpio_batfull = SPITZ_GPIO_CHRG_FULL,
188 .gpio_fatal = SPITZ_GPIO_FATAL_BAT,
189 .status_acin = spitz_acin_status,
190 .discharge = spitz_discharge,
191 .discharge1 = spitz_discharge1,
192 .charge = spitz_charge,
193 .chargeled = spitz_charge_led,
194 .measure_temp = spitz_measure_temp,
195 .presuspend = spitz_presuspend,
196 .postsuspend = spitz_postsuspend,
197 .charger_wakeup = spitz_charger_wakeup,
198 .should_wakeup = spitz_should_wakeup,
199 .bat_levels = 40,
200 .bat_levels_noac = spitz_battery_levels_noac,
201 .bat_levels_acin = spitz_battery_levels_acin,
202 .status_high_acin = 188,
203 .status_low_acin = 178,
204 .status_high_noac = 185,
205 .status_low_noac = 175,
206};
207
208static struct platform_device *spitzpm_device;
209
210static int __devinit spitzpm_init(void)
211{
212 int ret;
213
214 spitzpm_device = platform_device_alloc("sharpsl-pm", -1);
215 if (!spitzpm_device)
216 return -ENOMEM;
217
218 spitzpm_device->dev.platform_data = &spitz_pm_machinfo;
219 ret = platform_device_add(spitzpm_device);
220
221 if (ret)
222 platform_device_put(spitzpm_device);
223
224 return ret;
225}
226
227static void spitzpm_exit(void)
228{
229 platform_device_unregister(spitzpm_device);
230}
231
232module_init(spitzpm_init);
233module_exit(spitzpm_exit);