summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2007-08-14 22:06:23 +0000
committerJens Arnold <amiconn@rockbox.org>2007-08-14 22:06:23 +0000
commit8a177345ce7b96a00f1f14387412c2dfacfeaf34 (patch)
treefbb8dfa828cf578d535e3d77deebf077b24d2970
parent360d951271659af590103dd81efb8166f5b226a2 (diff)
downloadrockbox-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
-rw-r--r--firmware/SOURCES7
-rw-r--r--firmware/drivers/power.c225
-rw-r--r--firmware/export/config-fmrecorder.h6
-rw-r--r--firmware/export/config-ondiofm.h3
-rw-r--r--firmware/export/config-ondiosp.h3
-rw-r--r--firmware/export/config-player.h6
-rw-r--r--firmware/export/config-recorder.h6
-rw-r--r--firmware/export/config-recorderv2.h6
-rw-r--r--firmware/export/power.h5
-rw-r--r--firmware/export/tuner.h1
-rw-r--r--firmware/target/arm/archos/av300/power-av300.c12
-rw-r--r--firmware/target/arm/iriver/h10/power-h10.c24
-rw-r--r--firmware/target/arm/pnx0101/iriver-ifp7xx/power-ifp7xx.c13
-rw-r--r--firmware/target/arm/sandisk/sansa-e200/power-e200.c5
-rw-r--r--firmware/target/coldfire/iaudio/x5/power-x5.c12
-rw-r--r--firmware/target/coldfire/iriver/h100/power-h100.c12
-rw-r--r--firmware/target/coldfire/iriver/h300/power-h300.c12
-rw-r--r--firmware/target/sh/archos/fm_v2/power-fm_v2.c109
-rw-r--r--firmware/target/sh/archos/ondio/power-ondio.c78
-rw-r--r--firmware/target/sh/archos/player/power-player.c87
-rw-r--r--firmware/target/sh/archos/recorder/power-recorder.c103
-rw-r--r--uisimulator/common/fmradio.c4
22 files changed, 397 insertions, 342 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES
index bbbe150112..363ba81f23 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -96,9 +96,6 @@ drivers/lcd-remote-2bit-vi.c
96/* Misc. */ 96/* Misc. */
97drivers/led.c 97drivers/led.c
98drivers/button.c 98drivers/button.c
99#ifndef TARGET_TREE
100drivers/power.c
101#endif /* TARGET_TREE */
102#ifndef SIMULATOR 99#ifndef SIMULATOR
103drivers/dac.c 100drivers/dac.c
104drivers/serial.c 101drivers/serial.c
@@ -340,6 +337,7 @@ target/sh/archos/player/button-player.c
340target/sh/archos/player/hwcompat-player.c 337target/sh/archos/player/hwcompat-player.c
341target/sh/archos/player/lcd-as-player.S 338target/sh/archos/player/lcd-as-player.S
342target/sh/archos/player/lcd-player.c 339target/sh/archos/player/lcd-player.c
340target/sh/archos/player/power-player.c
343target/sh/archos/player/usb-player.c 341target/sh/archos/player/usb-player.c
344#endif /* SIMULATOR */ 342#endif /* SIMULATOR */
345#endif /* ARCHOS_PLAYER */ 343#endif /* ARCHOS_PLAYER */
@@ -351,6 +349,7 @@ target/sh/archos/ata-as-archos.S
351target/sh/archos/lcd-archos-bitmap.c 349target/sh/archos/lcd-archos-bitmap.c
352target/sh/archos/lcd-as-archos-bitmap.S 350target/sh/archos/lcd-as-archos-bitmap.S
353target/sh/archos/recorder/button-recorder.c 351target/sh/archos/recorder/button-recorder.c
352target/sh/archos/recorder/power-recorder.c
354target/sh/archos/recorder/usb-recorder.c 353target/sh/archos/recorder/usb-recorder.c
355#endif /* SIMULATOR */ 354#endif /* SIMULATOR */
356#endif /* ARCHOS_RECORDER */ 355#endif /* ARCHOS_RECORDER */
@@ -362,6 +361,7 @@ target/sh/archos/ata-as-archos.S
362target/sh/archos/lcd-archos-bitmap.c 361target/sh/archos/lcd-archos-bitmap.c
363target/sh/archos/lcd-as-archos-bitmap.S 362target/sh/archos/lcd-as-archos-bitmap.S
364target/sh/archos/fm_v2/button-fm_v2.c 363target/sh/archos/fm_v2/button-fm_v2.c
364target/sh/archos/fm_v2/power-fm_v2.c
365target/sh/archos/fm_v2/usb-fm_v2.c 365target/sh/archos/fm_v2/usb-fm_v2.c
366#endif /* SIMULATOR */ 366#endif /* SIMULATOR */
367#endif /* ARCHOS_FMRECORDER || ARCHOS_RECORDERV2 */ 367#endif /* ARCHOS_FMRECORDER || ARCHOS_RECORDERV2 */
@@ -371,6 +371,7 @@ target/sh/archos/fm_v2/usb-fm_v2.c
371target/sh/archos/lcd-archos-bitmap.c 371target/sh/archos/lcd-archos-bitmap.c
372target/sh/archos/lcd-as-archos-bitmap.S 372target/sh/archos/lcd-as-archos-bitmap.S
373target/sh/archos/ondio/button-ondio.c 373target/sh/archos/ondio/button-ondio.c
374target/sh/archos/ondio/power-ondio.c
374target/sh/archos/ondio/usb-ondio.c 375target/sh/archos/ondio/usb-ondio.c
375#endif /* SIMULATOR */ 376#endif /* SIMULATOR */
376#endif /* ARCHOS_ONDIOFM || ARCHOS_ONDIOFM */ 377#endif /* ARCHOS_ONDIOFM || ARCHOS_ONDIOFM */
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
31bool charger_enabled;
32#endif
33
34
35#if CONFIG_TUNER
36
37static bool powered = false;
38
39bool tuner_powered(void)
40{
41 return powered;
42}
43
44bool 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
64void 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
91bool 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
107void 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. */
124bool 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
138void 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
181bool 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
204void 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 */
diff --git a/firmware/export/config-fmrecorder.h b/firmware/export/config-fmrecorder.h
index 2f5254f3bc..a41c69a7bf 100644
--- a/firmware/export/config-fmrecorder.h
+++ b/firmware/export/config-fmrecorder.h
@@ -84,18 +84,12 @@
84/* Define this if you have a FM Recorder key system */ 84/* Define this if you have a FM Recorder key system */
85#define HAVE_FMADC 85#define HAVE_FMADC
86 86
87/* Define this if you need to power on ATA */
88#define NEEDS_ATA_POWER_ON
89
90/* Define this if battery voltage can only be measured with ATA powered */ 87/* Define this if battery voltage can only be measured with ATA powered */
91#define NEED_ATA_POWER_BATT_MEASURE 88#define NEED_ATA_POWER_BATT_MEASURE
92 89
93/* Define this to the CPU frequency */ 90/* Define this to the CPU frequency */
94#define CPU_FREQ 11059200 91#define CPU_FREQ 11059200
95 92
96/* Define this if you control power on PB5 (instead of the OFF button) */
97#define HAVE_POWEROFF_ON_PB5
98
99/* Offset ( in the firmware file's header ) to the file length */ 93/* Offset ( in the firmware file's header ) to the file length */
100#define FIRMWARE_OFFSET_FILE_LENGTH 20 94#define FIRMWARE_OFFSET_FILE_LENGTH 20
101 95
diff --git a/firmware/export/config-ondiofm.h b/firmware/export/config-ondiofm.h
index f9c2b191f1..335ce855fc 100644
--- a/firmware/export/config-ondiofm.h
+++ b/firmware/export/config-ondiofm.h
@@ -75,9 +75,6 @@
75/* Define this for different I2C pinout */ 75/* Define this for different I2C pinout */
76#define CONFIG_I2C I2C_ONDIO 76#define CONFIG_I2C I2C_ONDIO
77 77
78/* Define this if you control power on PB5 (instead of the OFF button) */
79#define HAVE_POWEROFF_ON_PB5
80
81/* Offset ( in the firmware file's header ) to the file length */ 78/* Offset ( in the firmware file's header ) to the file length */
82#define FIRMWARE_OFFSET_FILE_LENGTH 20 79#define FIRMWARE_OFFSET_FILE_LENGTH 20
83 80
diff --git a/firmware/export/config-ondiosp.h b/firmware/export/config-ondiosp.h
index 510ce01f57..0ceb72e936 100644
--- a/firmware/export/config-ondiosp.h
+++ b/firmware/export/config-ondiosp.h
@@ -61,9 +61,6 @@
61/* Define this to the CPU frequency */ 61/* Define this to the CPU frequency */
62#define CPU_FREQ 12000000 62#define CPU_FREQ 12000000
63 63
64/* Define this if you control power on PB5 (instead of the OFF button) */
65#define HAVE_POWEROFF_ON_PB5
66
67/* Offset ( in the firmware file's header ) to the file length */ 64/* Offset ( in the firmware file's header ) to the file length */
68#define FIRMWARE_OFFSET_FILE_LENGTH 20 65#define FIRMWARE_OFFSET_FILE_LENGTH 20
69 66
diff --git a/firmware/export/config-player.h b/firmware/export/config-player.h
index 5e20d9e393..bd89b0bb2e 100644
--- a/firmware/export/config-player.h
+++ b/firmware/export/config-player.h
@@ -48,9 +48,6 @@
48 * Attention, some players crash when ATA power-off is enabled! */ 48 * Attention, some players crash when ATA power-off is enabled! */
49//#define HAVE_ATA_POWER_OFF 49//#define HAVE_ATA_POWER_OFF
50 50
51/* Define this if you need to power on ATA */
52#define NEEDS_ATA_POWER_ON
53
54/* Define this if you control ata power player style 51/* Define this if you control ata power player style
55 (with PB4, new player only) */ 52 (with PB4, new player only) */
56#define ATA_POWER_PLAYERSTYLE 53#define ATA_POWER_PLAYERSTYLE
@@ -64,9 +61,6 @@
64 61
65#define CONFIG_I2C I2C_PLAYREC 62#define CONFIG_I2C I2C_PLAYREC
66 63
67/* Define this if you control power on PADR (instead of PBDR) */
68#define HAVE_POWEROFF_ON_PADR
69
70/* Offset ( in the firmware file's header ) to the file length */ 64/* Offset ( in the firmware file's header ) to the file length */
71#define FIRMWARE_OFFSET_FILE_LENGTH 0 65#define FIRMWARE_OFFSET_FILE_LENGTH 0
72 66
diff --git a/firmware/export/config-recorder.h b/firmware/export/config-recorder.h
index 920db04a01..4569c8bfd0 100644
--- a/firmware/export/config-recorder.h
+++ b/firmware/export/config-recorder.h
@@ -71,15 +71,9 @@
71/* Define this if you have ATA power-off control */ 71/* Define this if you have ATA power-off control */
72#define HAVE_ATA_POWER_OFF 72#define HAVE_ATA_POWER_OFF
73 73
74/* Define this if you need to power on ATA */
75#define NEEDS_ATA_POWER_ON
76
77/* Define this to the CPU frequency */ 74/* Define this to the CPU frequency */
78#define CPU_FREQ 11059200 75#define CPU_FREQ 11059200
79 76
80/* Define this if you control power on PBDR (instead of PADR) */
81#define HAVE_POWEROFF_ON_PBDR
82
83/* Offset ( in the firmware file's header ) to the file length */ 77/* Offset ( in the firmware file's header ) to the file length */
84#define FIRMWARE_OFFSET_FILE_LENGTH 0 78#define FIRMWARE_OFFSET_FILE_LENGTH 0
85 79
diff --git a/firmware/export/config-recorderv2.h b/firmware/export/config-recorderv2.h
index fc1461066a..d28595d154 100644
--- a/firmware/export/config-recorderv2.h
+++ b/firmware/export/config-recorderv2.h
@@ -81,18 +81,12 @@
81/* Define this if you have a FM Recorder key system */ 81/* Define this if you have a FM Recorder key system */
82#define HAVE_FMADC 82#define HAVE_FMADC
83 83
84/* Define this if you need to power on ATA */
85#define NEEDS_ATA_POWER_ON
86
87/* Define this if battery voltage can only be measured with ATA powered */ 84/* Define this if battery voltage can only be measured with ATA powered */
88#define NEED_ATA_POWER_BATT_MEASURE 85#define NEED_ATA_POWER_BATT_MEASURE
89 86
90/* Define this to the CPU frequency */ 87/* Define this to the CPU frequency */
91#define CPU_FREQ 11059200 88#define CPU_FREQ 11059200
92 89
93/* Define this if you control power on PB5 (instead of the OFF button) */
94#define HAVE_POWEROFF_ON_PB5
95
96/* Offset ( in the firmware file's header ) to the file length */ 90/* Offset ( in the firmware file's header ) to the file length */
97#define FIRMWARE_OFFSET_FILE_LENGTH 20 91#define FIRMWARE_OFFSET_FILE_LENGTH 20
98 92
diff --git a/firmware/export/power.h b/firmware/export/power.h
index b97410fd54..7c0ed3df89 100644
--- a/firmware/export/power.h
+++ b/firmware/export/power.h
@@ -48,9 +48,8 @@ bool spdif_powered(void);
48#endif 48#endif
49 49
50#if CONFIG_TUNER 50#if CONFIG_TUNER
51extern bool tuner_power(bool status); 51bool tuner_power(bool status);
52extern bool tuner_power_nolock(bool status); 52bool tuner_power_nolock(bool status);
53extern bool tuner_powered(void);
54#endif 53#endif
55 54
56#endif 55#endif
diff --git a/firmware/export/tuner.h b/firmware/export/tuner.h
index 1225830094..c1bd326c0f 100644
--- a/firmware/export/tuner.h
+++ b/firmware/export/tuner.h
@@ -127,7 +127,6 @@ enum
127 127
128void tuner_init(void); 128void tuner_init(void);
129bool tuner_power(bool power); 129bool tuner_power(bool power);
130bool tuner_powered(void);
131 130
132#endif /* #if CONFIG_TUNER */ 131#endif /* #if CONFIG_TUNER */
133 132
diff --git a/firmware/target/arm/archos/av300/power-av300.c b/firmware/target/arm/archos/av300/power-av300.c
index 6cc8b4f7c7..1bd4470fd3 100644
--- a/firmware/target/arm/archos/av300/power-av300.c
+++ b/firmware/target/arm/archos/av300/power-av300.c
@@ -82,16 +82,8 @@ void ide_power_enable(bool on)
82 82
83#endif /* SIMULATOR */ 83#endif /* SIMULATOR */
84 84
85static bool powered = false;
86
87bool tuner_powered()
88{
89 return powered;
90}
91
92bool tuner_power(bool status) 85bool tuner_power(bool status)
93{ 86{
94 bool old_status = powered; 87 (void)status;
95 powered = status; 88 return true;
96 return old_status;
97} 89}
diff --git a/firmware/target/arm/iriver/h10/power-h10.c b/firmware/target/arm/iriver/h10/power-h10.c
index d0d3ce59d1..9cbdb50080 100644
--- a/firmware/target/arm/iriver/h10/power-h10.c
+++ b/firmware/target/arm/iriver/h10/power-h10.c
@@ -38,27 +38,11 @@ bool charger_enabled;
38#if 0 38#if 0
39#if CONFIG_TUNER 39#if CONFIG_TUNER
40 40
41static bool powered = false;
42
43bool tuner_powered()
44{
45 return powered;
46}
47
48bool tuner_power(bool status) 41bool tuner_power(bool status)
49{ 42{
50 bool old_status = powered; 43 (void)status;
51 powered = status; 44 /* TODO: tuner power control */
52#ifdef HAVE_TUNER_PWR_CTRL 45 return true;
53 if (status)
54 {
55 and_b(~0x04, &PADRL); /* drive PA2 low for tuner enable */
56 sleep(1); /* let the voltage settle */
57 }
58 else
59 or_b(0x04, &PADRL); /* drive PA2 high for tuner disable */
60#endif
61 return old_status;
62} 46}
63 47
64#endif /* #if CONFIG_TUNER */ 48#endif /* #if CONFIG_TUNER */
@@ -69,7 +53,7 @@ void power_init(void)
69} 53}
70 54
71bool charger_inserted(void) 55bool charger_inserted(void)
72{ 56{
73 return (GPIOF_INPUT_VAL & 0x08)?true:false; 57 return (GPIOF_INPUT_VAL & 0x08)?true:false;
74} 58}
75 59
diff --git a/firmware/target/arm/pnx0101/iriver-ifp7xx/power-ifp7xx.c b/firmware/target/arm/pnx0101/iriver-ifp7xx/power-ifp7xx.c
index dfdcb1d27a..b219244510 100644
--- a/firmware/target/arm/pnx0101/iriver-ifp7xx/power-ifp7xx.c
+++ b/firmware/target/arm/pnx0101/iriver-ifp7xx/power-ifp7xx.c
@@ -28,19 +28,10 @@
28 28
29#if CONFIG_TUNER 29#if CONFIG_TUNER
30 30
31static bool powered = false;
32
33bool tuner_powered(void)
34{
35 return powered;
36}
37
38bool tuner_power(bool status) 31bool tuner_power(bool status)
39{ 32{
40 bool old_status = powered; 33 (void)status;
41 powered = status; 34 return true;
42
43 return old_status;
44} 35}
45 36
46#endif /* #if CONFIG_TUNER */ 37#endif /* #if CONFIG_TUNER */
diff --git a/firmware/target/arm/sandisk/sansa-e200/power-e200.c b/firmware/target/arm/sandisk/sansa-e200/power-e200.c
index 2745f0ba50..b9a77cb9e0 100644
--- a/firmware/target/arm/sandisk/sansa-e200/power-e200.c
+++ b/firmware/target/arm/sandisk/sansa-e200/power-e200.c
@@ -125,8 +125,3 @@ bool tuner_power(bool status)
125 lv24020lp_unlock(); 125 lv24020lp_unlock();
126 return old_status; 126 return old_status;
127} 127}
128
129bool tuner_powered(void)
130{
131 return powered;
132}
diff --git a/firmware/target/coldfire/iaudio/x5/power-x5.c b/firmware/target/coldfire/iaudio/x5/power-x5.c
index 76d612334b..cfcb384a24 100644
--- a/firmware/target/coldfire/iaudio/x5/power-x5.c
+++ b/firmware/target/coldfire/iaudio/x5/power-x5.c
@@ -67,16 +67,8 @@ void power_off(void)
67 67
68#endif /* SIMULATOR */ 68#endif /* SIMULATOR */
69 69
70static bool powered = false;
71
72bool tuner_powered()
73{
74 return powered;
75}
76
77bool tuner_power(bool status) 70bool tuner_power(bool status)
78{ 71{
79 bool old_status = powered; 72 (void)status;
80 powered = status; 73 return true;
81 return old_status;
82} 74}
diff --git a/firmware/target/coldfire/iriver/h100/power-h100.c b/firmware/target/coldfire/iriver/h100/power-h100.c
index 27000ebf8a..5dc8618cc6 100644
--- a/firmware/target/coldfire/iriver/h100/power-h100.c
+++ b/firmware/target/coldfire/iriver/h100/power-h100.c
@@ -27,18 +27,10 @@
27 27
28#if CONFIG_TUNER 28#if CONFIG_TUNER
29 29
30static bool powered = false;
31
32bool tuner_powered(void)
33{
34 return powered;
35}
36
37bool tuner_power(bool status) 30bool tuner_power(bool status)
38{ 31{
39 bool old_status = powered; 32 (void)status;
40 powered = status; 33 return true;
41 return old_status;
42} 34}
43 35
44#endif /* #if CONFIG_TUNER */ 36#endif /* #if CONFIG_TUNER */
diff --git a/firmware/target/coldfire/iriver/h300/power-h300.c b/firmware/target/coldfire/iriver/h300/power-h300.c
index b687b29cba..21c723da8e 100644
--- a/firmware/target/coldfire/iriver/h300/power-h300.c
+++ b/firmware/target/coldfire/iriver/h300/power-h300.c
@@ -27,18 +27,10 @@
27 27
28#if CONFIG_TUNER 28#if CONFIG_TUNER
29 29
30static bool powered = false;
31
32bool tuner_powered(void)
33{
34 return powered;
35}
36
37bool tuner_power(bool status) 30bool tuner_power(bool status)
38{ 31{
39 bool old_status = powered; 32 (void)status;
40 powered = status; 33 return true;
41 return old_status;
42} 34}
43 35
44#endif /* #if CONFIG_TUNER */ 36#endif /* #if CONFIG_TUNER */
diff --git a/firmware/target/sh/archos/fm_v2/power-fm_v2.c b/firmware/target/sh/archos/fm_v2/power-fm_v2.c
new file mode 100644
index 0000000000..94a36339bb
--- /dev/null
+++ b/firmware/target/sh/archos/fm_v2/power-fm_v2.c
@@ -0,0 +1,109 @@
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 "usb.h"
27
28#if CONFIG_TUNER
29
30bool tuner_power(bool status)
31{
32 (void)status;
33 return true;
34}
35
36#endif /* #if CONFIG_TUNER */
37
38void power_init(void)
39{
40 PBCR2 &= ~0x0c00; /* GPIO for PB5 */
41 or_b(0x20, &PBIORL);
42 or_b(0x20, &PBDRL); /* hold power */
43}
44
45bool charger_inserted(void)
46{
47 /* FM or V2 can also charge from the USB port */
48 return (adc_read(ADC_CHARGE_REGULATOR) < 0x1FF);
49}
50
51/* Returns true if the unit is charging the batteries. */
52bool charging_state(void)
53{
54 /* We use the information from the ADC_EXT_POWER ADC channel, which
55 tells us the charging current from the LTC1734. When DC is
56 connected (either via the external adapter, or via USB), we try
57 to determine if it is actively charging or only maintaining the
58 charge. My tests show that ADC readings below about 0x80 means
59 that the LTC1734 is only maintaining the charge. */
60 return adc_read(ADC_EXT_POWER) >= 0x80;
61}
62
63void ide_power_enable(bool on)
64{
65 bool touched = false;
66
67 if(on)
68 {
69 or_b(0x20, &PADRL);
70 touched = true;
71 }
72#ifdef HAVE_ATA_POWER_OFF
73 if(!on)
74 {
75 and_b(~0x20, &PADRL);
76 touched = true;
77 }
78#endif /* HAVE_ATA_POWER_OFF */
79
80/* late port preparation, else problems with read/modify/write
81 of other bits on same port, while input and floating high */
82 if (touched)
83 {
84 or_b(0x20, &PAIORL); /* PA5 is an output */
85 PACR2 &= 0xFBFF; /* GPIO for PA5 */
86 }
87}
88
89
90bool ide_powered(void)
91{
92#ifdef HAVE_ATA_POWER_OFF
93 if ((PACR2 & 0x0400) || !(PAIORL & 0x20)) /* not configured for output */
94 return true; /* would be floating high, disk on */
95 else
96 return (PADRL & 0x20) != 0;
97#else /* !defined(NEEDS_ATA_POWER_ON) && !defined(HAVE_ATA_POWER_OFF) */
98 return true; /* pretend always powered if not controlable */
99#endif
100}
101
102void power_off(void)
103{
104 set_irq_level(HIGHEST_IRQ_LEVEL);
105 and_b(~0x20, &PBDRL);
106 or_b(0x20, &PBIORL);
107 while(1)
108 yield();
109}
diff --git a/firmware/target/sh/archos/ondio/power-ondio.c b/firmware/target/sh/archos/ondio/power-ondio.c
new file mode 100644
index 0000000000..cedc3d10b9
--- /dev/null
+++ b/firmware/target/sh/archos/ondio/power-ondio.c
@@ -0,0 +1,78 @@
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 "usb.h"
27#include "backlight-target.h"
28
29#if CONFIG_TUNER
30
31static bool powered = false;
32
33bool tuner_power(bool status)
34{
35 bool old_status = powered;
36
37 powered = status;
38 if (status)
39 {
40 and_b(~0x04, &PADRL); /* drive PA2 low for tuner enable */
41 sleep(1); /* let the voltage settle */
42 }
43 else
44 or_b(0x04, &PADRL); /* drive PA2 high for tuner disable */
45 return old_status;
46}
47
48#endif /* #if CONFIG_TUNER */
49
50void power_init(void)
51{
52 PBCR2 &= ~0x0c00; /* GPIO for PB5 */
53 or_b(0x20, &PBIORL);
54 or_b(0x20, &PBDRL); /* hold power */
55#ifndef HAVE_BACKLIGHT
56 /* Disable backlight on backlight-modded Ondios when running
57 * a standard build (always on otherwise). */
58 PACR1 &= ~0x3000; /* Set PA14 (backlight control) to GPIO */
59 and_b(~0x40, &PADRH); /* drive it low */
60 or_b(0x40, &PAIORH); /* ..and output */
61#endif
62 PACR2 &= ~0x0030; /* GPIO for PA2 */
63 or_b(0x04, &PADRL); /* drive PA2 high for tuner disable */
64 or_b(0x04, &PAIORL); /* output for PA2 */
65}
66
67void power_off(void)
68{
69 set_irq_level(HIGHEST_IRQ_LEVEL);
70#ifdef HAVE_BACKLIGHT
71 /* Switch off the light on backlight-modded Ondios */
72 __backlight_off();
73#endif
74 and_b(~0x20, &PBDRL);
75 or_b(0x20, &PBIORL);
76 while(1)
77 yield();
78}
diff --git a/firmware/target/sh/archos/player/power-player.c b/firmware/target/sh/archos/player/power-player.c
new file mode 100644
index 0000000000..7d9d0d7d16
--- /dev/null
+++ b/firmware/target/sh/archos/player/power-player.c
@@ -0,0 +1,87 @@
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 "usb.h"
27
28void power_init(void)
29{
30}
31
32bool charger_inserted(void)
33{
34 /* Player */
35 return (PADR & 1) == 0;
36}
37
38void ide_power_enable(bool on)
39{
40 bool touched = false;
41
42 if(on)
43 {
44 or_b(0x10, &PBDRL);
45 touched = true;
46 }
47#ifdef HAVE_ATA_POWER_OFF
48 if(!on)
49 {
50 and_b(~0x10, &PBDRL);
51 touched = true;
52 }
53#endif /* HAVE_ATA_POWER_OFF */
54
55/* late port preparation, else problems with read/modify/write
56 of other bits on same port, while input and floating high */
57 if (touched)
58 {
59 or_b(0x10, &PBIORL); /* PB4 is an output */
60 PBCR2 &= ~0x0300; /* GPIO for PB4 */
61 }
62}
63
64
65bool ide_powered(void)
66{
67#ifdef HAVE_ATA_POWER_OFF
68 /* This is not correct for very old players, since these are unable to
69 * control hd power. However, driving the pin doesn't hurt, because it
70 * is not connected anywhere */
71 if ((PBCR2 & 0x0300) || !(PBIORL & 0x10)) /* not configured for output */
72 return false; /* would be floating low, disk off */
73 else
74 return (PBDRL & 0x10) != 0;
75#else /* !defined(NEEDS_ATA_POWER_ON) && !defined(HAVE_ATA_POWER_OFF) */
76 return true; /* pretend always powered if not controlable */
77#endif
78}
79
80void power_off(void)
81{
82 set_irq_level(HIGHEST_IRQ_LEVEL);
83 and_b(~0x08, &PADRH);
84 or_b(0x08, &PAIORH);
85 while(1)
86 yield();
87}
diff --git a/firmware/target/sh/archos/recorder/power-recorder.c b/firmware/target/sh/archos/recorder/power-recorder.c
new file mode 100644
index 0000000000..2af8df1bb6
--- /dev/null
+++ b/firmware/target/sh/archos/recorder/power-recorder.c
@@ -0,0 +1,103 @@
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 "usb.h"
27
28bool charger_enabled;
29
30void power_init(void)
31{
32 PBCR2 &= ~0x0c00; /* GPIO for PB5 */
33 or_b(0x20, &PBIORL); /* Set charging control bit to output */
34 charger_enable(false); /* Default to charger OFF */
35}
36
37bool charger_inserted(void)
38{
39 /* Recorder */
40 return adc_read(ADC_EXT_POWER) > 0x100;
41}
42
43void charger_enable(bool on)
44{
45 if(on)
46 {
47 and_b(~0x20, &PBDRL);
48 charger_enabled = 1;
49 }
50 else
51 {
52 or_b(0x20, &PBDRL);
53 charger_enabled = 0;
54 }
55}
56
57void ide_power_enable(bool on)
58{
59 bool touched = false;
60
61 if(on)
62 {
63 or_b(0x20, &PADRL);
64 touched = true;
65 }
66#ifdef HAVE_ATA_POWER_OFF
67 if(!on)
68 {
69 and_b(~0x20, &PADRL);
70 touched = true;
71 }
72#endif /* HAVE_ATA_POWER_OFF */
73
74/* late port preparation, else problems with read/modify/write
75 of other bits on same port, while input and floating high */
76 if (touched)
77 {
78 or_b(0x20, &PAIORL); /* PA5 is an output */
79 PACR2 &= 0xFBFF; /* GPIO for PA5 */
80 }
81}
82
83
84bool ide_powered(void)
85{
86#ifdef HAVE_ATA_POWER_OFF
87 if ((PACR2 & 0x0400) || !(PAIORL & 0x20)) /* not configured for output */
88 return true; /* would be floating high, disk on */
89 else
90 return (PADRL & 0x20) != 0;
91#else /* !defined(NEEDS_ATA_POWER_ON) && !defined(HAVE_ATA_POWER_OFF) */
92 return true; /* pretend always powered if not controlable */
93#endif
94}
95
96void power_off(void)
97{
98 set_irq_level(HIGHEST_IRQ_LEVEL);
99 and_b(~0x10, &PBDRL);
100 or_b(0x10, &PBIORL);
101 while(1)
102 yield();
103}
diff --git a/uisimulator/common/fmradio.c b/uisimulator/common/fmradio.c
index 63edd9dd23..279e1b8d23 100644
--- a/uisimulator/common/fmradio.c
+++ b/uisimulator/common/fmradio.c
@@ -26,9 +26,7 @@
26static int frequency = 0; 26static int frequency = 0;
27static bool mono = false; 27static bool mono = false;
28 28
29#ifdef HAVE_TUNER_PWR_CTRL
30static bool powered = false; 29static bool powered = false;
31#endif
32 30
33void tuner_init(void) 31void tuner_init(void)
34{ 32{
@@ -89,13 +87,11 @@ int tuner_get(int setting)
89 return val; 87 return val;
90} 88}
91 89
92#ifdef HAVE_TUNER_PWR_CTRL
93bool tuner_power(bool status) 90bool tuner_power(bool status)
94{ 91{
95 bool oldstatus = powered; 92 bool oldstatus = powered;
96 powered = status; 93 powered = status;
97 return oldstatus; 94 return oldstatus;
98} 95}
99#endif
100 96
101#endif 97#endif