Rob Purchase | 47ea030 | 2008-01-14 22:04:48 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2007 Dave Chapman |
| 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. |
Rob Purchase | 47ea030 | 2008-01-14 22:04:48 +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 | ****************************************************************************/ |
Rob Purchase | 47ea030 | 2008-01-14 22:04:48 +0000 | [diff] [blame] | 21 | #include "cpu.h" |
Rob Purchase | 47ea030 | 2008-01-14 22:04:48 +0000 | [diff] [blame] | 22 | #include "kernel.h" |
| 23 | #include "system.h" |
| 24 | #include "power.h" |
Rob Purchase | 2fee08a | 2008-04-08 20:43:04 +0000 | [diff] [blame] | 25 | #include "pcf50606.h" |
Rob Purchase | 18b004b | 2008-04-27 13:30:11 +0000 | [diff] [blame] | 26 | #include "button-target.h" |
Rob Purchase | d6159ea | 2008-06-22 18:48:22 +0000 | [diff] [blame] | 27 | #include "tuner.h" |
Rob Purchase | 47ea030 | 2008-01-14 22:04:48 +0000 | [diff] [blame] | 28 | |
| 29 | #ifndef SIMULATOR |
| 30 | |
| 31 | void power_init(void) |
| 32 | { |
Rob Purchase | b14c2de | 2008-04-12 18:17:15 +0000 | [diff] [blame] | 33 | unsigned char data[3]; /* 0 = INT1, 1 = INT2, 2 = INT3 */ |
| 34 | |
| 35 | /* Clear pending interrupts from pcf50606 */ |
| 36 | pcf50606_read_multiple(0x02, data, 3); |
| 37 | |
Rob Purchase | 2fee08a | 2008-04-08 20:43:04 +0000 | [diff] [blame] | 38 | /* Set outputs as per OF - further investigation required. */ |
| 39 | pcf50606_write(PCF5060X_DCDEC1, 0xe4); |
| 40 | pcf50606_write(PCF5060X_IOREGC, 0xf5); |
| 41 | pcf50606_write(PCF5060X_D1REGC1, 0xf5); |
| 42 | pcf50606_write(PCF5060X_D2REGC1, 0xe9); |
| 43 | pcf50606_write(PCF5060X_D3REGC1, 0xf8); /* WM8985 3.3v */ |
| 44 | pcf50606_write(PCF5060X_DCUDC1, 0xe7); |
| 45 | pcf50606_write(PCF5060X_LPREGC1, 0x0); |
| 46 | pcf50606_write(PCF5060X_LPREGC2, 0x2); |
Rob Purchase | b14c2de | 2008-04-12 18:17:15 +0000 | [diff] [blame] | 47 | |
| 48 | #ifndef BOOTLOADER |
| 49 | IEN |= EXT3_IRQ_MASK; /* Unmask EXT3 */ |
| 50 | #endif |
Rob Purchase | 47ea030 | 2008-01-14 22:04:48 +0000 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | void ide_power_enable(bool on) |
| 54 | { |
Rob Purchase | 47ea030 | 2008-01-14 22:04:48 +0000 | [diff] [blame] | 55 | (void)on; |
| 56 | } |
| 57 | |
| 58 | bool ide_powered(void) |
| 59 | { |
Rob Purchase | 47ea030 | 2008-01-14 22:04:48 +0000 | [diff] [blame] | 60 | return true; |
| 61 | } |
| 62 | |
| 63 | void power_off(void) |
| 64 | { |
Rob Purchase | 2fee08a | 2008-04-08 20:43:04 +0000 | [diff] [blame] | 65 | /* Forcibly cut power to SoC & peripherals by putting the PCF to sleep */ |
| 66 | pcf50606_write(PCF5060X_OOCC1, GOSTDBY | CHGWAK | EXTONWAK); |
Rob Purchase | 47ea030 | 2008-01-14 22:04:48 +0000 | [diff] [blame] | 67 | } |
| 68 | |
Rob Purchase | b14c2de | 2008-04-12 18:17:15 +0000 | [diff] [blame] | 69 | #ifndef BOOTLOADER |
| 70 | void EXT3(void) |
| 71 | { |
| 72 | unsigned char data[3]; /* 0 = INT1, 1 = INT2, 2 = INT3 */ |
| 73 | |
| 74 | /* Clear pending interrupts from pcf50606 */ |
Rob Purchase | b14c2de | 2008-04-12 18:17:15 +0000 | [diff] [blame] | 75 | pcf50606_read_multiple(0x02, data, 3); |
| 76 | |
| 77 | if (data[0] & 0x04) |
| 78 | { |
Rob Purchase | 18b004b | 2008-04-27 13:30:11 +0000 | [diff] [blame] | 79 | /* ONKEY1S: don't reset the timeout, because we want a way to power off |
| 80 | the player in the event of a crashed plugin or UIE/panic, etc. */ |
| 81 | #if 0 |
Rob Purchase | b14c2de | 2008-04-12 18:17:15 +0000 | [diff] [blame] | 82 | /* ONKEY1S: reset timeout as we're using SW poweroff */ |
| 83 | pcf50606_write(0x08, pcf50606_read(0x08) | 0x02); /* OOCC1: TOTRST=1 */ |
Rob Purchase | 18b004b | 2008-04-27 13:30:11 +0000 | [diff] [blame] | 84 | #endif |
Rob Purchase | b14c2de | 2008-04-12 18:17:15 +0000 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | if (data[2] & 0x08) |
| 88 | { |
Rob Purchase | 18b004b | 2008-04-27 13:30:11 +0000 | [diff] [blame] | 89 | /* Touchscreen event, do something about it */ |
| 90 | button_set_touch_available(); |
Rob Purchase | b14c2de | 2008-04-12 18:17:15 +0000 | [diff] [blame] | 91 | } |
Rob Purchase | b14c2de | 2008-04-12 18:17:15 +0000 | [diff] [blame] | 92 | } |
| 93 | #endif |
| 94 | |
| 95 | #if CONFIG_CHARGING |
| 96 | bool charger_inserted(void) |
| 97 | { |
| 98 | return (GPIOC & (1<<26)) ? false:true; |
| 99 | } |
| 100 | #endif |
| 101 | |
Rob Purchase | 47ea030 | 2008-01-14 22:04:48 +0000 | [diff] [blame] | 102 | #else /* SIMULATOR */ |
| 103 | |
| 104 | bool charger_inserted(void) |
| 105 | { |
| 106 | return false; |
| 107 | } |
| 108 | |
| 109 | void charger_enable(bool on) |
| 110 | { |
| 111 | (void)on; |
| 112 | } |
| 113 | |
| 114 | void power_off(void) |
| 115 | { |
Rob Purchase | 47ea030 | 2008-01-14 22:04:48 +0000 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | void ide_power_enable(bool on) |
| 119 | { |
| 120 | (void)on; |
| 121 | } |
| 122 | |
| 123 | #endif /* SIMULATOR */ |