lv24020lp tuner: On PP targets (c200/e200), use the atomic GPIO bitwise macros for...
[kugel-rb.git] / firmware / target / arm / sandisk / power-c200_e200.c
blob6637111ec8d1d7792709caf559858c5399662a89
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2006 by Daniel Ankers
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include <stdbool.h>
23 #include "system.h"
24 #include "cpu.h"
25 #include "ascodec.h"
26 #include "tuner.h"
27 #include "as3514.h"
28 #include "power.h"
29 #include "usb.h"
31 void power_init(void)
35 void power_off(void)
37 char byte;
39 /* Send shutdown command to PMU */
40 byte = ascodec_read(AS3514_SYSTEM);
41 byte &= ~0x1;
42 ascodec_write(AS3514_SYSTEM, byte);
44 /* Stop interrupts on both cores */
45 disable_interrupt(IRQ_FIQ_STATUS);
46 COP_INT_DIS = -1;
47 CPU_INT_DIS = -1;
49 /* Halt everything and wait for device to power off */
50 while (1)
52 COP_CTL = 0x40000000;
53 CPU_CTL = 0x40000000;
57 unsigned int power_input_status(void)
59 unsigned int status = POWER_INPUT_NONE;
61 #if defined(SANSA_E200)
62 #define _charger_present() (GPIOB_INPUT_VAL & 0x10)
63 #elif defined(SANSA_C200)
64 #define _charger_present() (GPIOH_INPUT_VAL & 0x2)
65 #else
66 #define _charger_present() 0
67 #endif
69 if (_charger_present())
70 status = POWER_INPUT_MAIN_CHARGER;
72 /* No separate source for USB */
74 return status;
77 void ide_power_enable(bool on)
79 (void)on;
82 #if CONFIG_TUNER
84 /** Tuner **/
85 static bool powered = false;
87 bool tuner_power(bool status)
89 bool old_status;
90 lv24020lp_lock();
92 old_status = powered;
94 if (status != old_status)
96 if (status)
98 /* init mystery amplification device */
99 #if defined(SANSA_E200)
100 GPO32_ENABLE |= 0x1;
101 #else /* SANSA_C200 */
102 DEV_INIT2 &= ~0x800;
103 #endif
104 udelay(5);
106 /* When power up, host should initialize the 3-wire bus
107 in host read mode: */
109 /* 1. Set direction of the DATA-line to input-mode. */
110 GPIO_CLEAR_BITWISE(GPIOH_OUTPUT_EN, 1 << 5);
111 GPIO_SET_BITWISE(GPIOH_ENABLE, 1 << 5);
113 /* 2. Drive NR_W low */
114 GPIO_CLEAR_BITWISE(GPIOH_OUTPUT_VAL, 1 << 3);
115 GPIO_SET_BITWISE(GPIOH_OUTPUT_EN, 1 << 3);
116 GPIO_SET_BITWISE(GPIOH_ENABLE, 1 << 3);
118 /* 3. Drive CLOCK high */
119 GPIO_SET_BITWISE(GPIOH_OUTPUT_VAL, 1 << 4);
120 GPIO_SET_BITWISE(GPIOH_OUTPUT_EN, 1 << 4);
121 GPIO_SET_BITWISE(GPIOH_ENABLE, 1 << 4);
123 lv24020lp_power(true);
125 else
127 lv24020lp_power(false);
129 /* set all as inputs */
130 GPIO_CLEAR_BITWISE(GPIOH_OUTPUT_EN, (1 << 5) | (1 << 3) | (1 << 4));
131 GPIO_CLEAR_BITWISE(GPIOH_ENABLE, (1 << 3) | (1 << 4));
133 /* turn off mystery amplification device */
134 #if defined (SANSA_E200)
135 GPO32_ENABLE &= ~0x1;
136 #else
137 DEV_INIT2 |= 0x800;
138 #endif
141 powered = status;
144 lv24020lp_unlock();
145 return old_status;
148 #endif /* CONFIG_TUNER */