blob: 5b09cc1c17604d147b7f58731a387124e2514804 [file] [log] [blame]
Rob Purchase47ea0302008-01-14 22:04:48 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2007 Dave Chapman
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.
Rob Purchase47ea0302008-01-14 22:04:48 +000016 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
Rob Purchase47ea0302008-01-14 22:04:48 +000021#include "cpu.h"
Rob Purchase47ea0302008-01-14 22:04:48 +000022#include "kernel.h"
23#include "system.h"
24#include "power.h"
Rob Purchase2fee08a2008-04-08 20:43:04 +000025#include "pcf50606.h"
Rob Purchase18b004b2008-04-27 13:30:11 +000026#include "button-target.h"
Rob Purchased6159ea2008-06-22 18:48:22 +000027#include "tuner.h"
Rob Purchase47ea0302008-01-14 22:04:48 +000028
29#ifndef SIMULATOR
30
31void power_init(void)
32{
Rob Purchaseb14c2de2008-04-12 18:17:15 +000033 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 Purchase2fee08a2008-04-08 20:43:04 +000038 /* 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 Purchaseb14c2de2008-04-12 18:17:15 +000047
48#ifndef BOOTLOADER
49 IEN |= EXT3_IRQ_MASK; /* Unmask EXT3 */
50#endif
Rob Purchase47ea0302008-01-14 22:04:48 +000051}
52
53void ide_power_enable(bool on)
54{
Rob Purchase47ea0302008-01-14 22:04:48 +000055 (void)on;
56}
57
58bool ide_powered(void)
59{
Rob Purchase47ea0302008-01-14 22:04:48 +000060 return true;
61}
62
63void power_off(void)
64{
Rob Purchase2fee08a2008-04-08 20:43:04 +000065 /* Forcibly cut power to SoC & peripherals by putting the PCF to sleep */
66 pcf50606_write(PCF5060X_OOCC1, GOSTDBY | CHGWAK | EXTONWAK);
Rob Purchase47ea0302008-01-14 22:04:48 +000067}
68
Rob Purchaseb14c2de2008-04-12 18:17:15 +000069#ifndef BOOTLOADER
70void EXT3(void)
71{
72 unsigned char data[3]; /* 0 = INT1, 1 = INT2, 2 = INT3 */
73
74 /* Clear pending interrupts from pcf50606 */
Rob Purchaseb14c2de2008-04-12 18:17:15 +000075 pcf50606_read_multiple(0x02, data, 3);
76
77 if (data[0] & 0x04)
78 {
Rob Purchase18b004b2008-04-27 13:30:11 +000079 /* 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 Purchaseb14c2de2008-04-12 18:17:15 +000082 /* ONKEY1S: reset timeout as we're using SW poweroff */
83 pcf50606_write(0x08, pcf50606_read(0x08) | 0x02); /* OOCC1: TOTRST=1 */
Rob Purchase18b004b2008-04-27 13:30:11 +000084#endif
Rob Purchaseb14c2de2008-04-12 18:17:15 +000085 }
86
87 if (data[2] & 0x08)
88 {
Rob Purchase18b004b2008-04-27 13:30:11 +000089 /* Touchscreen event, do something about it */
90 button_set_touch_available();
Rob Purchaseb14c2de2008-04-12 18:17:15 +000091 }
Rob Purchaseb14c2de2008-04-12 18:17:15 +000092}
93#endif
94
95#if CONFIG_CHARGING
96bool charger_inserted(void)
97{
98 return (GPIOC & (1<<26)) ? false:true;
99}
100#endif
101
Rob Purchase47ea0302008-01-14 22:04:48 +0000102#else /* SIMULATOR */
103
104bool charger_inserted(void)
105{
106 return false;
107}
108
109void charger_enable(bool on)
110{
111 (void)on;
112}
113
114void power_off(void)
115{
Rob Purchase47ea0302008-01-14 22:04:48 +0000116}
117
118void ide_power_enable(bool on)
119{
120 (void)on;
121}
122
123#endif /* SIMULATOR */