diff options
author | Jens Arnold <amiconn@rockbox.org> | 2007-08-14 22:06:23 +0000 |
---|---|---|
committer | Jens Arnold <amiconn@rockbox.org> | 2007-08-14 22:06:23 +0000 |
commit | 8a177345ce7b96a00f1f14387412c2dfacfeaf34 (patch) | |
tree | fbb8dfa828cf578d535e3d77deebf077b24d2970 /firmware/drivers | |
parent | 360d951271659af590103dd81efb8166f5b226a2 (diff) | |
download | rockbox-8a177345ce7b96a00f1f14387412c2dfacfeaf34.tar.gz rockbox-8a177345ce7b96a00f1f14387412c2dfacfeaf34.zip |
Moved archos power handling into target tree. * Tuner power handling cleaned up a bit.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14345 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/drivers')
-rw-r--r-- | firmware/drivers/power.c | 225 |
1 files changed, 0 insertions, 225 deletions
diff --git a/firmware/drivers/power.c b/firmware/drivers/power.c deleted file mode 100644 index 17a3fecea1..0000000000 --- a/firmware/drivers/power.c +++ /dev/null | |||
@@ -1,225 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Linus Nielsen Feltzing | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #include "config.h" | ||
20 | #include "cpu.h" | ||
21 | #include <stdbool.h> | ||
22 | #include "adc.h" | ||
23 | #include "kernel.h" | ||
24 | #include "system.h" | ||
25 | #include "power.h" | ||
26 | #include "logf.h" | ||
27 | #include "usb.h" | ||
28 | #include "backlight-target.h" | ||
29 | |||
30 | #if CONFIG_CHARGING == CHARGING_CONTROL | ||
31 | bool charger_enabled; | ||
32 | #endif | ||
33 | |||
34 | |||
35 | #if CONFIG_TUNER | ||
36 | |||
37 | static bool powered = false; | ||
38 | |||
39 | bool tuner_powered(void) | ||
40 | { | ||
41 | return powered; | ||
42 | } | ||
43 | |||
44 | bool tuner_power(bool status) | ||
45 | { | ||
46 | bool old_status = powered; | ||
47 | powered = status; | ||
48 | #ifdef HAVE_TUNER_PWR_CTRL | ||
49 | if (status) | ||
50 | { | ||
51 | and_b(~0x04, &PADRL); /* drive PA2 low for tuner enable */ | ||
52 | sleep(1); /* let the voltage settle */ | ||
53 | } | ||
54 | else | ||
55 | or_b(0x04, &PADRL); /* drive PA2 high for tuner disable */ | ||
56 | #endif | ||
57 | return old_status; | ||
58 | } | ||
59 | |||
60 | #endif /* #if CONFIG_TUNER */ | ||
61 | |||
62 | #ifndef SIMULATOR | ||
63 | |||
64 | void power_init(void) | ||
65 | { | ||
66 | #ifdef HAVE_POWEROFF_ON_PB5 | ||
67 | PBCR2 &= ~0x0c00; /* GPIO for PB5 */ | ||
68 | or_b(0x20, &PBIORL); | ||
69 | or_b(0x20, &PBDRL); /* hold power */ | ||
70 | #if defined(HAVE_MMC) && !defined(HAVE_BACKLIGHT) | ||
71 | /* Disable backlight on backlight-modded Ondios when running | ||
72 | * a standard build (always on otherwise). */ | ||
73 | PACR1 &= ~0x3000; /* Set PA14 (backlight control) to GPIO */ | ||
74 | and_b(~0x40, &PADRH); /* drive it low */ | ||
75 | or_b(0x40, &PAIORH); /* ..and output */ | ||
76 | #endif | ||
77 | #endif | ||
78 | #if CONFIG_CHARGING == CHARGING_CONTROL | ||
79 | PBCR2 &= ~0x0c00; /* GPIO for PB5 */ | ||
80 | or_b(0x20, &PBIORL); /* Set charging control bit to output */ | ||
81 | charger_enable(false); /* Default to charger OFF */ | ||
82 | #endif | ||
83 | #ifdef HAVE_TUNER_PWR_CTRL | ||
84 | PACR2 &= ~0x0030; /* GPIO for PA2 */ | ||
85 | or_b(0x04, &PADRL); /* drive PA2 high for tuner disable */ | ||
86 | or_b(0x04, &PAIORL); /* output for PA2 */ | ||
87 | #endif | ||
88 | } | ||
89 | |||
90 | #if CONFIG_CHARGING | ||
91 | bool charger_inserted(void) | ||
92 | { | ||
93 | #if CONFIG_CHARGING == CHARGING_CONTROL | ||
94 | /* Recorder */ | ||
95 | return adc_read(ADC_EXT_POWER) > 0x100; | ||
96 | #elif defined (HAVE_FMADC) | ||
97 | /* FM or V2, can also charge from the USB port */ | ||
98 | return (adc_read(ADC_CHARGE_REGULATOR) < 0x1FF); | ||
99 | #else | ||
100 | /* Player */ | ||
101 | return (PADR & 1) == 0; | ||
102 | #endif | ||
103 | } | ||
104 | #endif /* CONFIG_CHARGING */ | ||
105 | |||
106 | #if CONFIG_CHARGING == CHARGING_CONTROL | ||
107 | void charger_enable(bool on) | ||
108 | { | ||
109 | if(on) | ||
110 | { | ||
111 | and_b(~0x20, &PBDRL); | ||
112 | charger_enabled = 1; | ||
113 | } | ||
114 | else | ||
115 | { | ||
116 | or_b(0x20, &PBDRL); | ||
117 | charger_enabled = 0; | ||
118 | } | ||
119 | } | ||
120 | #endif | ||
121 | |||
122 | #if CONFIG_CHARGING == CHARGING_MONITOR | ||
123 | /* Returns true if the unit is charging the batteries. */ | ||
124 | bool charging_state(void) { | ||
125 | #if CONFIG_BATTERY == BATT_LIION2200 | ||
126 | /* We use the information from the ADC_EXT_POWER ADC channel, which | ||
127 | tells us the charging current from the LTC1734. When DC is | ||
128 | connected (either via the external adapter, or via USB), we try | ||
129 | to determine if it is actively charging or only maintaining the | ||
130 | charge. My tests show that ADC readings below about 0x80 means | ||
131 | that the LTC1734 is only maintaining the charge. */ | ||
132 | return adc_read(ADC_EXT_POWER) >= 0x80; | ||
133 | #endif | ||
134 | } | ||
135 | #endif | ||
136 | |||
137 | #ifndef HAVE_MMC | ||
138 | void ide_power_enable(bool on) | ||
139 | { | ||
140 | (void)on; | ||
141 | |||
142 | bool touched = false; | ||
143 | #ifdef NEEDS_ATA_POWER_ON | ||
144 | if(on) | ||
145 | { | ||
146 | #ifdef ATA_POWER_PLAYERSTYLE | ||
147 | or_b(0x10, &PBDRL); | ||
148 | #else | ||
149 | or_b(0x20, &PADRL); | ||
150 | #endif | ||
151 | touched = true; | ||
152 | } | ||
153 | #endif /* NEEDS_ATA_POWER_ON */ | ||
154 | #ifdef HAVE_ATA_POWER_OFF | ||
155 | if(!on) | ||
156 | { | ||
157 | #ifdef ATA_POWER_PLAYERSTYLE | ||
158 | and_b(~0x10, &PBDRL); | ||
159 | #else | ||
160 | and_b(~0x20, &PADRL); | ||
161 | #endif | ||
162 | touched = true; | ||
163 | } | ||
164 | #endif /* HAVE_ATA_POWER_OFF */ | ||
165 | |||
166 | /* late port preparation, else problems with read/modify/write | ||
167 | of other bits on same port, while input and floating high */ | ||
168 | if (touched) | ||
169 | { | ||
170 | #ifdef ATA_POWER_PLAYERSTYLE | ||
171 | or_b(0x10, &PBIORL); /* PB4 is an output */ | ||
172 | PBCR2 &= ~0x0300; /* GPIO for PB4 */ | ||
173 | #else | ||
174 | or_b(0x20, &PAIORL); /* PA5 is an output */ | ||
175 | PACR2 &= 0xFBFF; /* GPIO for PA5 */ | ||
176 | #endif | ||
177 | } | ||
178 | } | ||
179 | |||
180 | |||
181 | bool ide_powered(void) | ||
182 | { | ||
183 | #if defined(NEEDS_ATA_POWER_ON) || defined(HAVE_ATA_POWER_OFF) | ||
184 | #ifdef ATA_POWER_PLAYERSTYLE | ||
185 | /* This is not correct for very old players, since these are unable to | ||
186 | * control hd power. However, driving the pin doesn't hurt, because it | ||
187 | * is not connected anywhere */ | ||
188 | if ((PBCR2 & 0x0300) || !(PBIORL & 0x10)) /* not configured for output */ | ||
189 | return false; /* would be floating low, disk off */ | ||
190 | else | ||
191 | return (PBDRL & 0x10) != 0; | ||
192 | #else /* !ATA_POWER_PLAYERSTYLE */ | ||
193 | if ((PACR2 & 0x0400) || !(PAIORL & 0x20)) /* not configured for output */ | ||
194 | return true; /* would be floating high, disk on */ | ||
195 | else | ||
196 | return (PADRL & 0x20) != 0; | ||
197 | #endif /* !ATA_POWER_PLAYERSTYLE */ | ||
198 | #else /* !defined(NEEDS_ATA_POWER_ON) && !defined(HAVE_ATA_POWER_OFF) */ | ||
199 | return true; /* pretend always powered if not controlable */ | ||
200 | #endif | ||
201 | } | ||
202 | #endif /* !HAVE_MMC */ | ||
203 | |||
204 | void power_off(void) | ||
205 | { | ||
206 | set_irq_level(HIGHEST_IRQ_LEVEL); | ||
207 | #ifdef HAVE_POWEROFF_ON_PBDR | ||
208 | and_b(~0x10, &PBDRL); | ||
209 | or_b(0x10, &PBIORL); | ||
210 | #elif defined(HAVE_POWEROFF_ON_PB5) | ||
211 | #if defined(HAVE_MMC) && defined(HAVE_BACKLIGHT) | ||
212 | /* Switch off the light on backlight-modded Ondios */ | ||
213 | __backlight_off(); | ||
214 | #endif | ||
215 | and_b(~0x20, &PBDRL); | ||
216 | or_b(0x20, &PBIORL); | ||
217 | #else /* player */ | ||
218 | and_b(~0x08, &PADRH); | ||
219 | or_b(0x08, &PAIORH); | ||
220 | #endif | ||
221 | while(1) | ||
222 | yield(); | ||
223 | } | ||
224 | |||
225 | #endif /* SIMULATOR */ | ||