Add MPIO HD200 port - new files
[kugel-rb.git] / firmware / target / coldfire / mpio / hd200 / power-hd200.c
blobdd8576b9e4443fd86d6fbd224f6cba62a07a90bf
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id:$
10 * Copyright (C) 2010 Marcin Bukat
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
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"
30 #if CONFIG_TUNER
31 bool tuner_power(bool status)
33 (void)status;
34 if (status)
36 and_l(~(1<<17), &GPIO1_OUT);
38 else
40 or_l((1<<17), &GPIO1_OUT);
43 return status;
45 #endif /* #if CONFIG_TUNER */
47 void power_init(void)
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);
55 and_l(~(1<<15), &GPIO_OUT);
56 or_l((1<<15),&GPIO_ENABLE);
57 or_l((1<<15),&GPIO_FUNCTION);
59 or_l((1<<23), &GPIO_OUT);
60 and_l(~(1<<23), &GPIO_ENABLE);
61 or_l((1<<23), &GPIO_FUNCTION);
63 #ifndef BOOTLOADER
64 /* The boot loader controls the power */
65 ide_power_enable(true);
66 #endif
69 unsigned int power_input_status(void)
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;
76 return status;
79 /* Returns true if the unit is charging the batteries. */
80 bool charging_state(void)
82 if (!(GPIO1_READ & (1<<14)))
83 return (GPIO_READ & (1<<30) )?false:true;
84 else
85 return false;
88 void ide_power_enable(bool on)
90 (void)on;
91 if (on)
92 and_l(~(1<<31),&GPIO_OUT);
93 else
94 or_l((1<<31),&GPIO_OUT);
96 or_l((1<<31),&GPIO_ENABLE);
97 or_l((1<<31),&GPIO_FUNCTION);
101 bool ide_powered(void)
103 return true;
106 void power_off(void)
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);