Marcin Bukat | 28d54c6 | 2010-04-26 21:40:16 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
Marcin Bukat | 082c7d3 | 2010-10-22 12:28:43 +0000 | [diff] [blame^] | 8 | * $Id$ |
Marcin Bukat | 28d54c6 | 2010-04-26 21:40:16 +0000 | [diff] [blame] | 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 |
| 31 | bool tuner_power(bool status) |
| 32 | { |
Marcin Bukat | 28d54c6 | 2010-04-26 21:40:16 +0000 | [diff] [blame] | 33 | if (status) |
Marcin Bukat | 28d54c6 | 2010-04-26 21:40:16 +0000 | [diff] [blame] | 34 | and_l(~(1<<17), &GPIO1_OUT); |
Marcin Bukat | 28d54c6 | 2010-04-26 21:40:16 +0000 | [diff] [blame] | 35 | else |
Marcin Bukat | 28d54c6 | 2010-04-26 21:40:16 +0000 | [diff] [blame] | 36 | or_l((1<<17), &GPIO1_OUT); |
Marcin Bukat | 28d54c6 | 2010-04-26 21:40:16 +0000 | [diff] [blame] | 37 | |
| 38 | return status; |
| 39 | } |
| 40 | #endif /* #if CONFIG_TUNER */ |
| 41 | |
| 42 | void power_init(void) |
| 43 | { |
Marcin Bukat | 2f7bd4d | 2010-06-11 11:41:29 +0000 | [diff] [blame] | 44 | /* GPIO53 has to be high - low resets device |
| 45 | * it is setup in crt0.S |
| 46 | */ |
Marcin Bukat | 28d54c6 | 2010-04-26 21:40:16 +0000 | [diff] [blame] | 47 | |
Marcin Bukat | 2f7bd4d | 2010-06-11 11:41:29 +0000 | [diff] [blame] | 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); |
Marcin Bukat | 28d54c6 | 2010-04-26 21:40:16 +0000 | [diff] [blame] | 52 | |
Marcin Bukat | 2f7bd4d | 2010-06-11 11:41:29 +0000 | [diff] [blame] | 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); |
| 57 | |
| 58 | /* GPIO46 is wall charger detect (input) */ |
| 59 | and_l(~(1<<14), &GPIO1_ENABLE); |
| 60 | or_l((1<<14), &GPIO1_FUNCTION); |
| 61 | |
| 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); |
| 66 | |
| 67 | /* turn off charger by default*/ |
Marcin Bukat | 28d54c6 | 2010-04-26 21:40:16 +0000 | [diff] [blame] | 68 | or_l((1<<23), &GPIO_OUT); |
Marcin Bukat | f99e4fb | 2010-07-06 17:30:05 +0000 | [diff] [blame] | 69 | or_l((1<<23), &GPIO_ENABLE); |
Marcin Bukat | 28d54c6 | 2010-04-26 21:40:16 +0000 | [diff] [blame] | 70 | or_l((1<<23), &GPIO_FUNCTION); |
| 71 | |
Marcin Bukat | 2f7bd4d | 2010-06-11 11:41:29 +0000 | [diff] [blame] | 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); |
| 76 | |
Marcin Bukat | 28d54c6 | 2010-04-26 21:40:16 +0000 | [diff] [blame] | 77 | #ifndef BOOTLOADER |
| 78 | /* The boot loader controls the power */ |
| 79 | ide_power_enable(true); |
| 80 | #endif |
| 81 | } |
| 82 | |
| 83 | unsigned int power_input_status(void) |
| 84 | { |
| 85 | unsigned int status = POWER_INPUT_NONE; |
| 86 | /* GPIO46 is AC plug detect (low = AC plugged) */ |
| 87 | if (!(GPIO1_READ & (1<<14))) |
Marcin Bukat | 2f7bd4d | 2010-06-11 11:41:29 +0000 | [diff] [blame] | 88 | { |
| 89 | status |= POWER_INPUT_MAIN_CHARGER; |
| 90 | /* tristate GPIO23 to start charging cycle */ |
| 91 | and_l(~(1<<23), &GPIO_ENABLE); |
| 92 | } |
| 93 | else |
| 94 | { |
| 95 | /* drive GPIO23 high to enter LTC1733 shutdown mode */ |
| 96 | or_l((1<<23), &GPIO_ENABLE); |
| 97 | } |
Marcin Bukat | 28d54c6 | 2010-04-26 21:40:16 +0000 | [diff] [blame] | 98 | return status; |
| 99 | } |
| 100 | |
| 101 | /* Returns true if the unit is charging the batteries. */ |
| 102 | bool charging_state(void) |
| 103 | { |
| 104 | if (!(GPIO1_READ & (1<<14))) |
| 105 | return (GPIO_READ & (1<<30) )?false:true; |
| 106 | else |
| 107 | return false; |
| 108 | } |
| 109 | |
| 110 | void ide_power_enable(bool on) |
| 111 | { |
Marcin Bukat | 2f7bd4d | 2010-06-11 11:41:29 +0000 | [diff] [blame] | 112 | if (on) |
| 113 | and_l(~(1<<18),&GPIO1_OUT); |
Marcin Bukat | 28d54c6 | 2010-04-26 21:40:16 +0000 | [diff] [blame] | 114 | else |
Marcin Bukat | 2f7bd4d | 2010-06-11 11:41:29 +0000 | [diff] [blame] | 115 | or_l((1<<18),&GPIO1_OUT); |
Marcin Bukat | 28d54c6 | 2010-04-26 21:40:16 +0000 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | bool ide_powered(void) |
| 119 | { |
Marcin Bukat | 2f7bd4d | 2010-06-11 11:41:29 +0000 | [diff] [blame] | 120 | return (GPIO1_OUT & (1<<18))?false:true; |
Marcin Bukat | 28d54c6 | 2010-04-26 21:40:16 +0000 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | void power_off(void) |
| 124 | { |
| 125 | lcd_shutdown(); |
| 126 | set_irq_level(DISABLE_INTERRUPTS); |
| 127 | and_l(~(1<<21), &GPIO1_OUT); /* pull KEEPACT low */ |
| 128 | asm("halt"); |
| 129 | while(1); |
| 130 | } |