summaryrefslogtreecommitdiff
path: root/firmware/target/coldfire/iriver/h100/power-h100.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/coldfire/iriver/h100/power-h100.c')
-rw-r--r--firmware/target/coldfire/iriver/h100/power-h100.c143
1 files changed, 143 insertions, 0 deletions
diff --git a/firmware/target/coldfire/iriver/h100/power-h100.c b/firmware/target/coldfire/iriver/h100/power-h100.c
new file mode 100644
index 0000000000..0714ab2d3f
--- /dev/null
+++ b/firmware/target/coldfire/iriver/h100/power-h100.c
@@ -0,0 +1,143 @@
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 "kernel.h"
23#include "system.h"
24#include "power.h"
25
26
27#ifdef CONFIG_TUNER
28
29static bool powered = false;
30
31bool radio_powered(void)
32{
33 return powered;
34}
35
36bool radio_power(bool status)
37{
38 bool old_status = powered;
39 powered = status;
40 return old_status;
41}
42
43#endif /* #ifdef CONFIG_TUNER */
44
45#ifndef SIMULATOR
46
47void power_init(void)
48{
49 or_l(0x00080000, &GPIO1_OUT);
50 or_l(0x00080000, &GPIO1_ENABLE);
51 or_l(0x00080000, &GPIO1_FUNCTION);
52
53#ifndef BOOTLOADER
54 /* The boot loader controls the power */
55 ide_power_enable(true);
56#endif
57 or_l(0x80000000, &GPIO_ENABLE);
58 or_l(0x80000000, &GPIO_FUNCTION);
59#ifdef HAVE_SPDIF_POWER
60 spdif_power_enable(false);
61#endif
62}
63
64
65bool charger_inserted(void)
66{
67 return (GPIO1_READ & 0x00400000)?true:false;
68}
69/* Returns true if the unit is charging the batteries. */
70bool charging_state(void) {
71 return charger_inserted();
72}
73
74#ifdef HAVE_SPDIF_POWER
75void spdif_power_enable(bool on)
76{
77 or_l(0x01000000, &GPIO1_FUNCTION);
78 or_l(0x01000000, &GPIO1_ENABLE);
79
80#ifdef SPDIF_POWER_INVERTED
81 if(!on)
82#else
83 if(on)
84#endif
85 and_l(~0x01000000, &GPIO1_OUT);
86 else
87 or_l(0x01000000, &GPIO1_OUT);
88}
89#endif
90
91void ide_power_enable(bool on)
92{
93 if(on)
94 and_l(~0x80000000, &GPIO_OUT);
95 else
96 or_l(0x80000000, &GPIO_OUT);
97}
98
99
100bool ide_powered(void)
101{
102 return (GPIO_OUT & 0x80000000)?false:true;
103}
104
105
106void power_off(void)
107{
108 set_irq_level(HIGHEST_IRQ_LEVEL);
109 and_l(~0x00080000, &GPIO1_OUT);
110 asm("halt");
111 while(1)
112 yield();
113}
114
115#else
116
117bool charger_inserted(void)
118{
119 return false;
120}
121
122void charger_enable(bool on)
123{
124 (void)on;
125}
126
127void power_off(void)
128{
129}
130
131void ide_power_enable(bool on)
132{
133 (void)on;
134}
135
136#ifdef HAVE_SPDIF_POWER
137void spdif_power_enable(bool on)
138{
139 (void)on;
140}
141#endif
142
143#endif /* SIMULATOR */