summaryrefslogtreecommitdiff
path: root/firmware/target/coldfire/mpio/hd200/power-hd200.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/coldfire/mpio/hd200/power-hd200.c')
-rw-r--r--firmware/target/coldfire/mpio/hd200/power-hd200.c113
1 files changed, 113 insertions, 0 deletions
diff --git a/firmware/target/coldfire/mpio/hd200/power-hd200.c b/firmware/target/coldfire/mpio/hd200/power-hd200.c
new file mode 100644
index 0000000000..dd8576b9e4
--- /dev/null
+++ b/firmware/target/coldfire/mpio/hd200/power-hd200.c
@@ -0,0 +1,113 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id:$
9 *
10 * Copyright (C) 2010 Marcin Bukat
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "config.h"
23#include "cpu.h"
24#include <stdbool.h>
25#include "kernel.h"
26#include "system.h"
27#include "lcd.h"
28#include "power.h"
29
30#if CONFIG_TUNER
31bool tuner_power(bool status)
32{
33 (void)status;
34 if (status)
35 {
36 and_l(~(1<<17), &GPIO1_OUT);
37 }
38 else
39 {
40 or_l((1<<17), &GPIO1_OUT);
41 }
42
43 return status;
44}
45#endif /* #if CONFIG_TUNER */
46
47void power_init(void)
48{
49 /* GPIO53 has to be high - low resets device */
50 /* GPIO49 is FM related */
51 or_l((1<<21)|(1<<17), &GPIO1_OUT);
52 or_l((1<<21)|(1<<17), &GPIO1_ENABLE);
53 or_l((1<<21)|(1<<17)|(1<<14), &GPIO1_FUNCTION);
54
55 and_l(~(1<<15), &GPIO_OUT);
56 or_l((1<<15),&GPIO_ENABLE);
57 or_l((1<<15),&GPIO_FUNCTION);
58
59 or_l((1<<23), &GPIO_OUT);
60 and_l(~(1<<23), &GPIO_ENABLE);
61 or_l((1<<23), &GPIO_FUNCTION);
62
63#ifndef BOOTLOADER
64 /* The boot loader controls the power */
65 ide_power_enable(true);
66#endif
67}
68
69unsigned int power_input_status(void)
70{
71 unsigned int status = POWER_INPUT_NONE;
72/* GPIO46 is AC plug detect (low = AC plugged) */
73 if (!(GPIO1_READ & (1<<14)))
74 status |= POWER_INPUT_MAIN_CHARGER;
75
76 return status;
77}
78
79/* Returns true if the unit is charging the batteries. */
80bool charging_state(void)
81{
82 if (!(GPIO1_READ & (1<<14)))
83 return (GPIO_READ & (1<<30) )?false:true;
84 else
85 return false;
86}
87
88void ide_power_enable(bool on)
89{
90 (void)on;
91 if (on)
92 and_l(~(1<<31),&GPIO_OUT);
93 else
94 or_l((1<<31),&GPIO_OUT);
95
96 or_l((1<<31),&GPIO_ENABLE);
97 or_l((1<<31),&GPIO_FUNCTION);
98
99}
100
101bool ide_powered(void)
102{
103 return true;
104}
105
106void power_off(void)
107{
108 lcd_shutdown();
109 set_irq_level(DISABLE_INTERRUPTS);
110 and_l(~(1<<21), &GPIO1_OUT); /* pull KEEPACT low */
111 asm("halt");
112 while(1);
113}