blob: 6eb403732d1a8bc06e814dedff36d0b5d87b42fc [file] [log] [blame]
Jonathan Gordon139f9f22006-10-30 08:56:06 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Linus Nielsen Feltzing
11 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000012 * 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.
Jonathan Gordon139f9f22006-10-30 08:56:06 +000016 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include "config.h"
22#include "cpu.h"
23#include <stdbool.h>
24#include "kernel.h"
25#include "system.h"
26#include "power.h"
Michael Sevakiscc50c142006-11-13 23:21:54 +000027#include "spdif.h"
Jonathan Gordon139f9f22006-10-30 08:56:06 +000028
29
Jens Arnoldc6522182007-02-18 08:46:12 +000030#if CONFIG_TUNER
Jonathan Gordon139f9f22006-10-30 08:56:06 +000031
Michael Sevakis7d759f62007-07-14 11:20:31 +000032bool tuner_power(bool status)
Jonathan Gordon139f9f22006-10-30 08:56:06 +000033{
Jens Arnold8a177342007-08-14 22:06:23 +000034 (void)status;
35 return true;
Jonathan Gordon139f9f22006-10-30 08:56:06 +000036}
37
Jens Arnoldc6522182007-02-18 08:46:12 +000038#endif /* #if CONFIG_TUNER */
Jonathan Gordon139f9f22006-10-30 08:56:06 +000039
40#ifndef SIMULATOR
41
42void power_init(void)
43{
44 or_l(0x00080000, &GPIO1_OUT);
45 or_l(0x00080000, &GPIO1_ENABLE);
46 or_l(0x00080000, &GPIO1_FUNCTION);
47
48#ifndef BOOTLOADER
49 /* The boot loader controls the power */
50 ide_power_enable(true);
51#endif
52 or_l(0x80000000, &GPIO_ENABLE);
53 or_l(0x80000000, &GPIO_FUNCTION);
54#ifdef HAVE_SPDIF_POWER
55 spdif_power_enable(false);
56#endif
57}
58
59
60bool charger_inserted(void)
61{
62 return (GPIO1_READ & 0x00400000)?true:false;
63}
64/* Returns true if the unit is charging the batteries. */
65bool charging_state(void) {
66 return charger_inserted();
67}
68
69#ifdef HAVE_SPDIF_POWER
70void spdif_power_enable(bool on)
71{
72 or_l(0x01000000, &GPIO1_FUNCTION);
73 or_l(0x01000000, &GPIO1_ENABLE);
74
75#ifdef SPDIF_POWER_INVERTED
76 if(!on)
77#else
78 if(on)
79#endif
80 and_l(~0x01000000, &GPIO1_OUT);
81 else
82 or_l(0x01000000, &GPIO1_OUT);
Michael Sevakiscc50c142006-11-13 23:21:54 +000083
84#ifndef BOOTLOADER
85 /* Make sure the feed is reset */
Michael Sevakis2d48d0f2007-06-08 23:42:04 +000086 spdif_set_output_source(spdif_get_output_source(NULL)
87 IF_SPDIF_POWER_(, true));
Jonathan Gordon139f9f22006-10-30 08:56:06 +000088#endif
Michael Sevakiscc50c142006-11-13 23:21:54 +000089}
90
91bool spdif_powered(void)
92{
93 bool state = (GPIO1_READ & 0x01000000)?false:true;
94#ifdef SPDIF_POWER_INVERTED
95 return !state;
96#else
97 return state;
98#endif /* SPDIF_POWER_INVERTED */
99}
100#endif /* HAVE_SPDIF_POWER */
Jonathan Gordon139f9f22006-10-30 08:56:06 +0000101
102void ide_power_enable(bool on)
103{
104 if(on)
105 and_l(~0x80000000, &GPIO_OUT);
106 else
107 or_l(0x80000000, &GPIO_OUT);
108}
109
Jonathan Gordon139f9f22006-10-30 08:56:06 +0000110bool ide_powered(void)
111{
112 return (GPIO_OUT & 0x80000000)?false:true;
113}
114
Jonathan Gordon139f9f22006-10-30 08:56:06 +0000115void power_off(void)
116{
Michael Sevakis633f3882007-03-07 06:23:02 +0000117 set_irq_level(DISABLE_INTERRUPTS);
Jonathan Gordon139f9f22006-10-30 08:56:06 +0000118 and_l(~0x00080000, &GPIO1_OUT);
119 asm("halt");
Michael Sevakisaf395f42008-03-26 01:50:41 +0000120 while(1);
Jonathan Gordon139f9f22006-10-30 08:56:06 +0000121}
122
Jonathan Gordon139f9f22006-10-30 08:56:06 +0000123#endif /* SIMULATOR */