FS#8961 - Anti-Aliased Fonts.
[kugel-rb.git] / firmware / target / arm / ipod / power-ipod.c
blob0b516466fefdaac2aa39786550335b383b787a67
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 "kernel.h"
25 #include "system.h"
26 #include "power.h"
27 #include "logf.h"
28 #include "pcf50605.h"
29 #include "usb.h"
30 #include "lcd.h"
32 void power_init(void)
34 #if defined(IPOD_1G2G) || defined(IPOD_3G)
35 GPIOC_ENABLE |= 0x40; /* GPIO C6 is HDD power (low active) */
36 GPIOC_OUTPUT_VAL &= ~0x40; /* on by default */
37 GPIOC_OUTPUT_EN |= 0x40; /* enable output */
38 #endif
39 #ifndef IPOD_1G2G
40 pcf50605_init();
41 #endif
44 #if CONFIG_CHARGING
45 unsigned int power_input_status(void)
47 unsigned int status = POWER_INPUT_NONE;
49 #if defined(IPOD_NANO) || defined(IPOD_VIDEO)
50 if ((GPIOL_INPUT_VAL & 0x08) == 0)
51 status = POWER_INPUT_MAIN_CHARGER;
53 if ((GPIOL_INPUT_VAL & 0x10) != 0)
54 status |= POWER_INPUT_USB_CHARGER;
55 /* */
56 #elif defined(IPOD_4G) || defined(IPOD_COLOR) \
57 || defined(IPOD_MINI) || defined(IPOD_MINI2G)
58 /* C2 is firewire power */
59 if ((GPIOC_INPUT_VAL & 0x04) == 0)
60 status = POWER_INPUT_MAIN_CHARGER;
62 if ((GPIOD_INPUT_VAL & 0x08) != 0)
63 status |= POWER_INPUT_USB_CHARGER;
64 /* */
65 #elif defined(IPOD_3G)
66 /* firewire power */
67 if ((GPIOC_INPUT_VAL & 0x10) == 0)
68 status = POWER_INPUT_MAIN_CHARGER;
69 /* */
70 #else
71 /* This needs filling in for other ipods. */
72 #endif
74 return status;
77 /* Returns true if the unit is charging the batteries. */
78 bool charging_state(void) {
79 #if defined(IPOD_COLOR)
80 /* 0x70000088 appears to be the input value for GPO32 bits.
81 Write a zero to 0x70000088 before reading.
82 To enable input set the corresponding 0x7000008C bit,
83 and clear the corresponding GPO32_ENABLE bit. */
84 outl(0, 0x70000088);
85 return (inl(0x70000088) & 1)?false:true;
86 #else
87 return (GPIOB_INPUT_VAL & 0x01)?false:true;
88 #endif
90 #endif /* CONFIG_CHARGING */
93 void ide_power_enable(bool on)
95 #if defined(IPOD_1G2G) || defined(IPOD_3G)
96 if (on)
97 GPIOC_OUTPUT_VAL &= ~0x40;
98 else
99 GPIOC_OUTPUT_VAL |= 0x40;
100 #elif defined(IPOD_4G) || defined(IPOD_COLOR) \
101 || defined(IPOD_MINI) || defined(IPOD_MINI2G)
102 if (on)
104 GPIO_CLEAR_BITWISE(GPIOJ_OUTPUT_VAL, 0x04);
105 DEV_EN |= DEV_IDE0;
107 else
109 DEV_EN &= ~DEV_IDE0;
110 GPIO_SET_BITWISE(GPIOJ_OUTPUT_VAL, 0x04);
112 #elif defined(IPOD_VIDEO)
113 if (on)
115 GPO32_VAL &= ~0x40000000;
116 DEV_EN |= DEV_IDE0;
118 else
120 DEV_EN &= ~DEV_IDE0;
121 GPO32_VAL |= 0x40000000;
123 #else /* Nano */
124 (void)on; /* Do nothing. */
125 #endif
128 bool ide_powered(void)
130 #if defined(IPOD_1G2G) || defined(IPOD_3G)
131 return !(GPIOC_OUTPUT_VAL & 0x40);
132 #elif defined(IPOD_4G) || defined(IPOD_COLOR) \
133 || defined(IPOD_MINI) || defined(IPOD_MINI2G)
134 return !(GPIOJ_OUTPUT_VAL & 0x04);
135 #elif defined(IPOD_VIDEO)
136 return !(GPO32_VAL & 0x40000000);
137 #else /* Nano */
138 return true; /* Pretend we are always powered */
139 #endif
142 void power_off(void)
144 #if defined(HAVE_LCD_COLOR) && !defined(HAVE_LCD_SHUTDOWN)
145 /* Clear the screen and backdrop to
146 remove ghosting effect on shutdown */
147 lcd_set_backdrop(NULL);
148 lcd_set_background(LCD_WHITE);
149 lcd_clear_display();
150 lcd_update();
151 sleep(HZ/16);
152 #endif
154 #ifndef BOOTLOADER
155 #ifdef IPOD_1G2G
156 /* we cannot turn off the 1st gen/ 2nd gen yet. Need to figure out sleep mode. */
157 system_reboot();
158 #else
159 /* We don't turn off the ipod, we put it in a deep sleep */
160 pcf50605_standby_mode();
161 #endif
162 #endif