Prepare new maemo release
[maemo-rb.git] / firmware / target / coldfire / mpio / power-mpio.c
blob5ca3b947b0ccd29318d817ce50f096a7fcbb523a
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 if (status)
34 and_l(~(1<<17), &GPIO1_OUT);
35 else
36 or_l((1<<17), &GPIO1_OUT);
38 return status;
40 #endif /* #if CONFIG_TUNER */
42 void power_init(void)
44 /* GPIO53 has to be high - low resets device
45 * it is setup in crt0.S
48 /* GPIO50 is ATA power (default OFF) */
49 or_l((1<<18), &GPIO1_OUT);
50 or_l((1<<18), &GPIO1_ENABLE);
51 or_l((1<<18), &GPIO1_FUNCTION);
53 /* GPIO49 is FM power (default OFF) */
54 or_l((1<<17), &GPIO1_OUT);
55 or_l((1<<17), &GPIO1_ENABLE);
56 or_l((1<<17), &GPIO1_FUNCTION);
58 /* GPIO46 is wall charger detect (input) */
59 and_l(~(1<<14), &GPIO1_ENABLE);
60 or_l((1<<14), &GPIO1_FUNCTION);
62 /* GPIO31 needs to be low */
63 and_l(~(1<<31), &GPIO_OUT);
64 or_l((1<<31),&GPIO_ENABLE);
65 or_l((1<<31),&GPIO_FUNCTION);
67 /* turn off charger by default*/
68 or_l((1<<23), &GPIO_OUT);
69 or_l((1<<23), &GPIO_ENABLE);
70 or_l((1<<23), &GPIO_FUNCTION);
72 /* high current charge mode */
73 or_l((1<<15), &GPIO_OUT);
74 or_l((1<<15),&GPIO_ENABLE);
75 or_l((1<<15),&GPIO_FUNCTION);
77 #ifndef BOOTLOADER
78 /* The boot loader controls the power */
79 ide_power_enable(true);
80 #endif
83 unsigned int power_input_status(void)
85 unsigned int status = POWER_INPUT_NONE;
86 /* GPIO46 is AC plug detect (low = AC plugged) */
87 if (!(GPIO1_READ & (1<<14)))
89 status |= POWER_INPUT_MAIN_CHARGER;
90 /* tristate GPIO23 to start charging cycle */
91 and_l(~(1<<23), &GPIO_ENABLE);
93 else
95 /* drive GPIO23 high to enter LTC1733 shutdown mode */
96 or_l((1<<23), &GPIO_ENABLE);
98 return status;
101 /* Returns true if the unit is charging the batteries. */
102 bool charging_state(void)
104 if (!(GPIO1_READ & (1<<14)))
105 return (GPIO_READ & (1<<30) )?false:true;
106 else
107 return false;
110 void ide_power_enable(bool on)
112 if (on)
113 and_l(~(1<<18),&GPIO1_OUT);
114 else
115 or_l((1<<18),&GPIO1_OUT);
118 bool ide_powered(void)
120 return (GPIO1_OUT & (1<<18))?false:true;
123 void power_off(void)
125 #ifdef HAVE_LCD_SHUTDOWN
126 lcd_shutdown();
127 #endif
128 set_irq_level(DISABLE_INTERRUPTS);
129 and_l(~(1<<21), &GPIO1_OUT); /* pull KEEPACT low */
130 asm("halt");
131 while(1);