1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by Linus Nielsen Feltzing
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 ****************************************************************************/
35 #if defined(IPOD_1G2G) || defined(IPOD_3G)
36 GPIOC_ENABLE
|= 0x40; /* GPIO C6 is HDD power (low active) */
37 GPIOC_OUTPUT_VAL
&= ~0x40; /* on by default */
38 GPIOC_OUTPUT_EN
|= 0x40; /* enable output */
46 unsigned int power_input_status(void)
48 unsigned int status
= POWER_INPUT_NONE
;
50 #if defined(IPOD_NANO) || defined(IPOD_VIDEO)
51 if ((GPIOL_INPUT_VAL
& 0x08) == 0)
52 status
= POWER_INPUT_MAIN_CHARGER
;
54 if ((GPIOL_INPUT_VAL
& 0x10) != 0)
55 status
|= POWER_INPUT_USB_CHARGER
;
57 #elif defined(IPOD_4G) || defined(IPOD_COLOR) \
58 || defined(IPOD_MINI) || defined(IPOD_MINI2G)
59 /* C2 is firewire power */
60 if ((GPIOC_INPUT_VAL
& 0x04) == 0)
61 status
= POWER_INPUT_MAIN_CHARGER
;
63 if ((GPIOD_INPUT_VAL
& 0x08) != 0)
64 status
|= POWER_INPUT_USB_CHARGER
;
66 #elif defined(IPOD_3G)
68 if ((GPIOC_INPUT_VAL
& 0x10) == 0)
69 status
= POWER_INPUT_MAIN_CHARGER
;
72 /* This needs filling in for other ipods. */
78 /* Returns true if the unit is charging the batteries. */
79 bool charging_state(void) {
80 #if defined(IPOD_COLOR)
81 /* 0x70000088 appears to be the input value for GPO32 bits.
82 Write a zero to 0x70000088 before reading.
83 To enable input set the corresponding 0x7000008C bit,
84 and clear the corresponding GPO32_ENABLE bit. */
86 return (inl(0x70000088) & 1)?false:true;
88 return (GPIOB_INPUT_VAL
& 0x01)?false:true;
91 #endif /* CONFIG_CHARGING */
94 void ide_power_enable(bool on
)
96 #if defined(IPOD_1G2G) || defined(IPOD_3G)
98 GPIOC_OUTPUT_VAL
&= ~0x40;
100 GPIOC_OUTPUT_VAL
|= 0x40;
101 #elif defined(IPOD_4G) || defined(IPOD_COLOR) \
102 || defined(IPOD_MINI) || defined(IPOD_MINI2G)
105 GPIO_CLEAR_BITWISE(GPIOJ_OUTPUT_VAL
, 0x04);
111 GPIO_SET_BITWISE(GPIOJ_OUTPUT_VAL
, 0x04);
113 #elif defined(IPOD_VIDEO)
116 GPO32_VAL
&= ~0x40000000;
117 sleep(1); /* only need 4 ms */
121 GPIO_CLEAR_BITWISE(GPIOI_ENABLE
, 0xBF);
122 GPIO_CLEAR_BITWISE(GPIOK_ENABLE
, 0x1F);
131 GPIO_SET_BITWISE(GPIOI_ENABLE
, 0xBF);
132 GPIO_SET_BITWISE(GPIOK_ENABLE
, 0x1F);
133 GPO32_VAL
|= 0x40000000;
136 (void)on
; /* Do nothing. */
140 bool ide_powered(void)
142 #if defined(IPOD_1G2G) || defined(IPOD_3G)
143 return !(GPIOC_OUTPUT_VAL
& 0x40);
144 #elif defined(IPOD_4G) || defined(IPOD_COLOR) \
145 || defined(IPOD_MINI) || defined(IPOD_MINI2G)
146 return !(GPIOJ_OUTPUT_VAL
& 0x04);
147 #elif defined(IPOD_VIDEO)
148 return !(GPO32_VAL
& 0x40000000);
150 return true; /* Pretend we are always powered */
156 #if defined(HAVE_LCD_COLOR) && !defined(HAVE_LCD_SHUTDOWN)
157 /* Clear the screen and backdrop to
158 remove ghosting effect on shutdown */
159 lcd_set_backdrop(NULL
);
160 lcd_set_background(LCD_WHITE
);
168 /* we cannot turn off the 1st gen/ 2nd gen yet. Need to figure out sleep mode. */
171 /* We don't turn off the ipod, we put it in a deep sleep */
172 /* Clear latter part of iram (the part used by plugins/codecs) to ensure
173 * that the OF behaves properly on boot. There is some kind of boot
174 * failure flag there which otherwise may not be cleared.
176 #if CONFIG_CPU == PP5022
177 memset((void*)0x4000c000, 0, 0x14000);
178 #elif CONFIG_CPU == PP5020
179 memset((void*)0x4000c000, 0, 0xc000);
181 pcf50605_standby_mode();
186 #ifdef HAVE_USB_CHARGING_ENABLE
187 void usb_charging_maxcurrent_change(int maxcurrent
)
189 bool suspend_charging
= (maxcurrent
< 100);
190 bool fast_charging
= (maxcurrent
>= 500);
192 /* This GPIO is connected to the LTC4066's SUSP pin */
193 /* Setting it high prevents any power being drawn over USB */
194 /* which supports USB suspend */
195 #if defined(IPOD_VIDEO) || defined(IPOD_NANO)
196 if (suspend_charging
)
197 GPIO_SET_BITWISE(GPIOL_OUTPUT_VAL
, 4);
199 GPIO_CLEAR_BITWISE(GPIOL_OUTPUT_VAL
, 4);
200 #elif defined(IPOD_MINI2G)
201 if (suspend_charging
)
202 GPIO_SET_BITWISE(GPIOJ_OUTPUT_VAL
, 2);
204 GPIO_CLEAR_BITWISE(GPIOJ_OUTPUT_VAL
, 2);
205 #else /* Color, 4G, Mini G1 */
206 if (suspend_charging
)
207 GPO32_VAL
|= 0x8000000;
209 GPO32_VAL
&= ~0x8000000;
212 /* This GPIO is connected to the LTC4066's HPWR pin */
213 /* Setting it low limits current to 100mA, setting it high allows 500mA */
214 #if defined(IPOD_VIDEO) || defined(IPOD_NANO)
216 GPIO_SET_BITWISE(GPIOA_OUTPUT_VAL
, 4);
218 GPIO_CLEAR_BITWISE(GPIOA_OUTPUT_VAL
, 4);
226 /* This GPIO is connected to the LTC4066's CLDIS pin */
227 /* Setting it high allows up to 1.5A of current to be drawn */
228 /* This doesn't appear to actually be safe even with an AC charger */
229 /* so for now it is disabled. It's not known (or maybe doesn't exist) */
232 #if defined(IPOD_VIDEO)
233 if (unlimited_charging
)
234 GPO32_VAL
|= 0x10000000;
236 GPO32_VAL
&= ~0x10000000;
237 #elif defined(IPOD_4G) || defined(IPOD_COLOR)
238 if (unlimited_charging
)
243 /* This might be GPIOD & 40 on 2G */
246 #endif /* HAVE_USB_CHARGING_ENABLE */