Submit FS#9890 by Boris Gjenero. Enabling option for iPod Video to shut down LCD...
[kugel-rb.git] / firmware / target / arm / ipod / power-ipod.c
blob66d703859cea97a46763e66a1f2c63dfb212bf1c
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
21 #include "config.h"
22 #include "cpu.h"
23 #include <stdbool.h>
24 #include "adc.h"
25 #include "kernel.h"
26 #include "system.h"
27 #include "power.h"
28 #include "logf.h"
29 #include "pcf50605.h"
30 #include "usb.h"
31 #include "lcd.h"
33 void power_init(void)
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 */
39 #endif
40 #ifndef IPOD_1G2G
41 pcf50605_init();
42 #endif
45 #if CONFIG_CHARGING
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;
56 /* */
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;
62 /* */
63 #elif defined(IPOD_3G)
64 /* firewire power */
65 if ((GPIOC_INPUT_VAL & 0x10) == 0)
66 status = POWER_INPUT_MAIN_CHARGER;
67 /* */
68 #else
69 /* This needs filling in for other ipods. */
70 #endif
72 return status;
75 /* Returns true if the unit is charging the batteries. */
76 bool charging_state(void) {
77 return (GPIOB_INPUT_VAL & 0x01)?false:true;
79 #endif /* CONFIG_CHARGING */
82 void ide_power_enable(bool on)
84 #if defined(IPOD_1G2G) || defined(IPOD_3G)
85 if (on)
86 GPIOC_OUTPUT_VAL &= ~0x40;
87 else
88 GPIOC_OUTPUT_VAL |= 0x40;
89 #elif defined(IPOD_4G) || defined(IPOD_COLOR) \
90 || defined(IPOD_MINI) || defined(IPOD_MINI2G)
91 if (on)
93 GPIO_CLEAR_BITWISE(GPIOJ_OUTPUT_VAL, 0x04);
94 DEV_EN |= DEV_IDE0;
96 else
98 DEV_EN &= ~DEV_IDE0;
99 GPIO_SET_BITWISE(GPIOJ_OUTPUT_VAL, 0x04);
101 #elif defined(IPOD_VIDEO)
102 if (on)
104 GPO32_VAL &= ~0x40000000;
105 DEV_EN |= DEV_IDE0;
107 else
109 DEV_EN &= ~DEV_IDE0;
110 GPO32_VAL |= 0x40000000;
112 #else /* Nano */
113 (void)on; /* Do nothing. */
114 #endif
117 bool ide_powered(void)
119 #if defined(IPOD_1G2G) || defined(IPOD_3G)
120 return !(GPIOC_OUTPUT_VAL & 0x40);
121 #elif defined(IPOD_4G) || defined(IPOD_COLOR) \
122 || defined(IPOD_MINI) || defined(IPOD_MINI2G)
123 return !(GPIOJ_OUTPUT_VAL & 0x04);
124 #elif defined(IPOD_VIDEO)
125 return !(GPO32_VAL & 0x40000000);
126 #else /* Nano */
127 return true; /* Pretend we are always powered */
128 #endif
131 void power_off(void)
133 #if defined(HAVE_LCD_COLOR) && !defined(HAVE_LCD_SHUTDOWN)
134 /* Clear the screen and backdrop to
135 remove ghosting effect on shutdown */
136 lcd_set_backdrop(NULL);
137 lcd_set_background(LCD_WHITE);
138 lcd_clear_display();
139 lcd_update();
140 sleep(HZ/16);
141 #endif
143 #ifndef BOOTLOADER
144 #ifdef IPOD_1G2G
145 /* we cannot turn off the 1st gen/ 2nd gen yet. Need to figure out sleep mode. */
146 system_reboot();
147 #else
148 /* We don't turn off the ipod, we put it in a deep sleep */
149 pcf50605_standby_mode();
150 #endif
151 #endif