Jonathan Gordon | 139f9f2 | 2006-10-30 08:56:06 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2002 by Linus Nielsen Feltzing |
| 11 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame^] | 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. |
Jonathan Gordon | 139f9f2 | 2006-10-30 08:56:06 +0000 | [diff] [blame] | 16 | * |
| 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 Sevakis | cc50c14 | 2006-11-13 23:21:54 +0000 | [diff] [blame] | 27 | #include "spdif.h" |
Jonathan Gordon | 139f9f2 | 2006-10-30 08:56:06 +0000 | [diff] [blame] | 28 | |
| 29 | |
Jens Arnold | c652218 | 2007-02-18 08:46:12 +0000 | [diff] [blame] | 30 | #if CONFIG_TUNER |
Jonathan Gordon | 139f9f2 | 2006-10-30 08:56:06 +0000 | [diff] [blame] | 31 | |
Michael Sevakis | 7d759f6 | 2007-07-14 11:20:31 +0000 | [diff] [blame] | 32 | bool tuner_power(bool status) |
Jonathan Gordon | 139f9f2 | 2006-10-30 08:56:06 +0000 | [diff] [blame] | 33 | { |
Jens Arnold | 8a17734 | 2007-08-14 22:06:23 +0000 | [diff] [blame] | 34 | (void)status; |
| 35 | return true; |
Jonathan Gordon | 139f9f2 | 2006-10-30 08:56:06 +0000 | [diff] [blame] | 36 | } |
| 37 | |
Jens Arnold | c652218 | 2007-02-18 08:46:12 +0000 | [diff] [blame] | 38 | #endif /* #if CONFIG_TUNER */ |
Jonathan Gordon | 139f9f2 | 2006-10-30 08:56:06 +0000 | [diff] [blame] | 39 | |
| 40 | #ifndef SIMULATOR |
| 41 | |
| 42 | void 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 | |
| 60 | bool charger_inserted(void) |
| 61 | { |
| 62 | return (GPIO1_READ & 0x00400000)?true:false; |
| 63 | } |
| 64 | /* Returns true if the unit is charging the batteries. */ |
| 65 | bool charging_state(void) { |
| 66 | return charger_inserted(); |
| 67 | } |
| 68 | |
| 69 | #ifdef HAVE_SPDIF_POWER |
| 70 | void 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 Sevakis | cc50c14 | 2006-11-13 23:21:54 +0000 | [diff] [blame] | 83 | |
| 84 | #ifndef BOOTLOADER |
| 85 | /* Make sure the feed is reset */ |
Michael Sevakis | 2d48d0f | 2007-06-08 23:42:04 +0000 | [diff] [blame] | 86 | spdif_set_output_source(spdif_get_output_source(NULL) |
| 87 | IF_SPDIF_POWER_(, true)); |
Jonathan Gordon | 139f9f2 | 2006-10-30 08:56:06 +0000 | [diff] [blame] | 88 | #endif |
Michael Sevakis | cc50c14 | 2006-11-13 23:21:54 +0000 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | bool 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 Gordon | 139f9f2 | 2006-10-30 08:56:06 +0000 | [diff] [blame] | 101 | |
| 102 | void 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 Gordon | 139f9f2 | 2006-10-30 08:56:06 +0000 | [diff] [blame] | 110 | bool ide_powered(void) |
| 111 | { |
| 112 | return (GPIO_OUT & 0x80000000)?false:true; |
| 113 | } |
| 114 | |
Jonathan Gordon | 139f9f2 | 2006-10-30 08:56:06 +0000 | [diff] [blame] | 115 | void power_off(void) |
| 116 | { |
Michael Sevakis | 633f388 | 2007-03-07 06:23:02 +0000 | [diff] [blame] | 117 | set_irq_level(DISABLE_INTERRUPTS); |
Jonathan Gordon | 139f9f2 | 2006-10-30 08:56:06 +0000 | [diff] [blame] | 118 | and_l(~0x00080000, &GPIO1_OUT); |
| 119 | asm("halt"); |
Michael Sevakis | af395f4 | 2008-03-26 01:50:41 +0000 | [diff] [blame] | 120 | while(1); |
Jonathan Gordon | 139f9f2 | 2006-10-30 08:56:06 +0000 | [diff] [blame] | 121 | } |
| 122 | |
Jonathan Gordon | 139f9f2 | 2006-10-30 08:56:06 +0000 | [diff] [blame] | 123 | #endif /* SIMULATOR */ |