diff options
Diffstat (limited to 'firmware/target/arm')
-rw-r--r-- | firmware/target/arm/ipod/3g/backlight-3g.c | 42 | ||||
-rw-r--r-- | firmware/target/arm/ipod/3g/button-3g.c | 189 | ||||
-rw-r--r-- | firmware/target/arm/ipod/adc-ipod.c | 80 | ||||
-rw-r--r-- | firmware/target/arm/ipod/adc-target.h | 29 | ||||
-rw-r--r-- | firmware/target/arm/ipod/backlight-4g_color.c | 48 | ||||
-rw-r--r-- | firmware/target/arm/ipod/backlight-mini1g_mini2g.c | 44 | ||||
-rw-r--r-- | firmware/target/arm/ipod/backlight-nano_video.c | 50 | ||||
-rw-r--r-- | firmware/target/arm/ipod/backlight-target.h | 25 | ||||
-rw-r--r-- | firmware/target/arm/ipod/button-clickwheel.c | 237 | ||||
-rw-r--r-- | firmware/target/arm/ipod/button-mini1g.c | 217 | ||||
-rw-r--r-- | firmware/target/arm/ipod/button-target.h | 61 | ||||
-rw-r--r-- | firmware/target/arm/ipod/power-ipod.c | 81 | ||||
-rw-r--r-- | firmware/target/arm/ipod/usb-ipod.c | 114 | ||||
-rw-r--r-- | firmware/target/arm/ipod/usb-target.h | 24 |
14 files changed, 1241 insertions, 0 deletions
diff --git a/firmware/target/arm/ipod/3g/backlight-3g.c b/firmware/target/arm/ipod/3g/backlight-3g.c new file mode 100644 index 0000000000..b676e2473b --- /dev/null +++ b/firmware/target/arm/ipod/3g/backlight-3g.c | |||
@@ -0,0 +1,42 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Linus Nielsen Feltzing | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #include "config.h" | ||
20 | #include <stdlib.h> | ||
21 | #include "cpu.h" | ||
22 | #include "kernel.h" | ||
23 | #include "thread.h" | ||
24 | #include "i2c.h" | ||
25 | #include "debug.h" | ||
26 | #include "rtc.h" | ||
27 | #include "usb.h" | ||
28 | #include "power.h" | ||
29 | #include "system.h" | ||
30 | #include "button.h" | ||
31 | #include "timer.h" | ||
32 | #include "backlight.h" | ||
33 | |||
34 | inline void __backlight_on(void) | ||
35 | { | ||
36 | outl(inl(0xc0001000) | 0x02, 0xc0001000); | ||
37 | } | ||
38 | |||
39 | inline void __backlight_off(void) | ||
40 | { | ||
41 | outl(inl(0xc0001000) & ~0x02, 0xc0001000); | ||
42 | } | ||
diff --git a/firmware/target/arm/ipod/3g/button-3g.c b/firmware/target/arm/ipod/3g/button-3g.c new file mode 100644 index 0000000000..7244dd597b --- /dev/null +++ b/firmware/target/arm/ipod/3g/button-3g.c | |||
@@ -0,0 +1,189 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Daniel Stenberg | ||
11 | * | ||
12 | * iPod driver based on code from the ipodlinux project - http://ipodlinux.org | ||
13 | * Adapted for Rockbox in December 2005 | ||
14 | * Original file: linux/arch/armnommu/mach-ipod/keyboard.c | ||
15 | * Copyright (c) 2003-2005 Bernard Leach (leachbj@bouncycastle.org) | ||
16 | * | ||
17 | * | ||
18 | * All files in this archive are subject to the GNU General Public License. | ||
19 | * See the file COPYING in the source tree root for full license agreement. | ||
20 | * | ||
21 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
22 | * KIND, either express or implied. | ||
23 | * | ||
24 | ****************************************************************************/ | ||
25 | |||
26 | /* | ||
27 | * Rockbox button functions | ||
28 | */ | ||
29 | |||
30 | #include <stdlib.h> | ||
31 | #include "config.h" | ||
32 | #include "cpu.h" | ||
33 | #include "system.h" | ||
34 | #include "button.h" | ||
35 | #include "kernel.h" | ||
36 | #include "backlight.h" | ||
37 | #include "adc.h" | ||
38 | #include "serial.h" | ||
39 | #include "power.h" | ||
40 | #include "system.h" | ||
41 | #include "powermgmt.h" | ||
42 | |||
43 | /* iPod 3G and mini 1G, mini 2G uses iPod 4G code */ | ||
44 | void handle_scroll_wheel(int new_scroll, int was_hold, int reverse) | ||
45 | { | ||
46 | int wheel_keycode = BUTTON_NONE; | ||
47 | static int prev_scroll = -1; | ||
48 | static int direction = 0; | ||
49 | static int count = 0; | ||
50 | static int scroll_state[4][4] = { | ||
51 | {0, 1, -1, 0}, | ||
52 | {-1, 0, 0, 1}, | ||
53 | {1, 0, 0, -1}, | ||
54 | {0, -1, 1, 0} | ||
55 | }; | ||
56 | |||
57 | if ( prev_scroll == -1 ) { | ||
58 | prev_scroll = new_scroll; | ||
59 | } | ||
60 | else if (direction != scroll_state[prev_scroll][new_scroll]) { | ||
61 | direction = scroll_state[prev_scroll][new_scroll]; | ||
62 | count = 0; | ||
63 | } | ||
64 | else if (!was_hold) { | ||
65 | backlight_on(); | ||
66 | if (++count == 6) { /* reduce sensitivity */ | ||
67 | count = 0; | ||
68 | switch (direction) { | ||
69 | case 1: | ||
70 | if (reverse) { | ||
71 | /* 'r' keypress */ | ||
72 | wheel_keycode = BUTTON_SCROLL_FWD; | ||
73 | } | ||
74 | else { | ||
75 | /* 'l' keypress */ | ||
76 | wheel_keycode = BUTTON_SCROLL_BACK; | ||
77 | } | ||
78 | break; | ||
79 | case -1: | ||
80 | if (reverse) { | ||
81 | /* 'l' keypress */ | ||
82 | wheel_keycode = BUTTON_SCROLL_BACK; | ||
83 | } | ||
84 | else { | ||
85 | /* 'r' keypress */ | ||
86 | wheel_keycode = BUTTON_SCROLL_FWD; | ||
87 | } | ||
88 | break; | ||
89 | default: | ||
90 | /* only happens if we get out of sync */ | ||
91 | break; | ||
92 | } | ||
93 | } | ||
94 | } | ||
95 | if (wheel_keycode != BUTTON_NONE && queue_empty(&button_queue)) | ||
96 | queue_post(&button_queue, wheel_keycode, NULL); | ||
97 | prev_scroll = new_scroll; | ||
98 | } | ||
99 | |||
100 | static int ipod_3g_button_read(void) | ||
101 | { | ||
102 | unsigned char source, state; | ||
103 | static int was_hold = 0; | ||
104 | int btn = BUTTON_NONE; | ||
105 | /* | ||
106 | * we need some delay for g3, cause hold generates several interrupts, | ||
107 | * some of them delayed | ||
108 | */ | ||
109 | udelay(250); | ||
110 | |||
111 | /* get source of interupts */ | ||
112 | source = GPIOA_INT_STAT; | ||
113 | |||
114 | |||
115 | /* get current keypad status */ | ||
116 | state = GPIOA_INPUT_VAL; | ||
117 | GPIOA_INT_LEV = ~state; | ||
118 | |||
119 | if (was_hold && source == 0x40 && state == 0xbf) { | ||
120 | /* ack any active interrupts */ | ||
121 | GPIOA_INT_CLR = source; | ||
122 | return BUTTON_NONE; | ||
123 | } | ||
124 | was_hold = 0; | ||
125 | |||
126 | |||
127 | if ((state & 0x20) == 0) { | ||
128 | /* 3g hold switch is active low */ | ||
129 | was_hold = 1; | ||
130 | /* hold switch on 3g causes all outputs to go low */ | ||
131 | /* we shouldn't interpret these as key presses */ | ||
132 | GPIOA_INT_CLR = source; | ||
133 | return BUTTON_NONE; | ||
134 | } | ||
135 | if ((state & 0x1) == 0) { | ||
136 | btn |= BUTTON_RIGHT; | ||
137 | } | ||
138 | if ((state & 0x2) == 0) { | ||
139 | btn |= BUTTON_SELECT; | ||
140 | } | ||
141 | if ((state & 0x4) == 0) { | ||
142 | btn |= BUTTON_PLAY; | ||
143 | } | ||
144 | if ((state & 0x8) == 0) { | ||
145 | btn |= BUTTON_LEFT; | ||
146 | } | ||
147 | if ((state & 0x10) == 0) { | ||
148 | btn |= BUTTON_MENU; | ||
149 | } | ||
150 | |||
151 | if (source & 0xc0) { | ||
152 | handle_scroll_wheel((state & 0xc0) >> 6, was_hold, 0); | ||
153 | } | ||
154 | |||
155 | /* ack any active interrupts */ | ||
156 | GPIOA_INT_CLR = source; | ||
157 | |||
158 | return btn; | ||
159 | } | ||
160 | |||
161 | void button_init_device(void) | ||
162 | { | ||
163 | GPIOA_INT_LEV = ~GPIOA_INPUT_VAL; | ||
164 | GPIOA_INT_CLR = GPIOA_INT_STAT; | ||
165 | GPIOA_INT_EN = 0xff; | ||
166 | } | ||
167 | |||
168 | /* | ||
169 | * Get button pressed from hardware | ||
170 | */ | ||
171 | int button_read_device(void) | ||
172 | { | ||
173 | static bool hold_button = false; | ||
174 | bool hold_button_old; | ||
175 | |||
176 | /* normal buttons */ | ||
177 | hold_button_old = hold_button; | ||
178 | hold_button = button_hold(); | ||
179 | |||
180 | if (hold_button != hold_button_old) | ||
181 | backlight_hold_changed(hold_button); | ||
182 | |||
183 | return ipod_3g_button_read(); | ||
184 | } | ||
185 | |||
186 | bool button_hold(void) | ||
187 | { | ||
188 | return (GPIOA_INPUT_VAL & 0x20)?false:true; | ||
189 | } | ||
diff --git a/firmware/target/arm/ipod/adc-ipod.c b/firmware/target/arm/ipod/adc-ipod.c new file mode 100644 index 0000000000..d351f0ee81 --- /dev/null +++ b/firmware/target/arm/ipod/adc-ipod.c | |||
@@ -0,0 +1,80 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Linus Nielsen Feltzing | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #include "config.h" | ||
20 | #include "cpu.h" | ||
21 | #include "system.h" | ||
22 | #include "kernel.h" | ||
23 | #include "thread.h" | ||
24 | #include "string.h" | ||
25 | #include "adc.h" | ||
26 | #include "pcf50605.h" | ||
27 | |||
28 | struct adc_struct { | ||
29 | long timeout; | ||
30 | void (*conversion)(unsigned short *data); | ||
31 | short channelnum; | ||
32 | unsigned short data; | ||
33 | }; | ||
34 | |||
35 | static struct adc_struct adcdata[NUM_ADC_CHANNELS] IDATA_ATTR; | ||
36 | |||
37 | static unsigned short _adc_read(struct adc_struct *adc) | ||
38 | { | ||
39 | if (adc->timeout < current_tick) { | ||
40 | unsigned char data[2]; | ||
41 | unsigned short value; | ||
42 | /* 5x per 2 seconds */ | ||
43 | adc->timeout = current_tick + (HZ * 2 / 5); | ||
44 | |||
45 | /* ADCC1, 10 bit, start */ | ||
46 | pcf50605_write(0x2f, (adc->channelnum << 1) | 0x1); | ||
47 | pcf50605_read_multiple(0x30, data, 2); /* ADCS1, ADCS2 */ | ||
48 | value = data[0]; | ||
49 | value <<= 2; | ||
50 | value |= data[1] & 0x3; | ||
51 | |||
52 | if (adc->conversion) { | ||
53 | adc->conversion(&value); | ||
54 | } | ||
55 | adc->data = value; | ||
56 | return value; | ||
57 | } else { | ||
58 | return adc->data; | ||
59 | } | ||
60 | } | ||
61 | |||
62 | /* Force an ADC scan _now_ */ | ||
63 | unsigned short adc_scan(int channel) { | ||
64 | struct adc_struct *adc = &adcdata[channel]; | ||
65 | adc->timeout = 0; | ||
66 | return _adc_read(adc); | ||
67 | } | ||
68 | |||
69 | /* Retrieve the ADC value, only does a scan periodically */ | ||
70 | unsigned short adc_read(int channel) { | ||
71 | return _adc_read(&adcdata[channel]); | ||
72 | } | ||
73 | |||
74 | void adc_init(void) | ||
75 | { | ||
76 | struct adc_struct *adc_battery = &adcdata[ADC_BATTERY]; | ||
77 | adc_battery->channelnum = 0x2; /* ADCVIN1, resistive divider */ | ||
78 | adc_battery->timeout = 0; | ||
79 | _adc_read(adc_battery); | ||
80 | } | ||
diff --git a/firmware/target/arm/ipod/adc-target.h b/firmware/target/arm/ipod/adc-target.h new file mode 100644 index 0000000000..8458779b59 --- /dev/null +++ b/firmware/target/arm/ipod/adc-target.h | |||
@@ -0,0 +1,29 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Linus Nielsen Feltzing | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #ifndef _ADC_TARGET_H_ | ||
20 | #define _ADC_TARGET_H_ | ||
21 | |||
22 | #define NUM_ADC_CHANNELS 1 | ||
23 | |||
24 | #define ADC_BATTERY 0 | ||
25 | #define ADC_UNREG_POWER ADC_BATTERY | ||
26 | |||
27 | /* Force a scan now */ | ||
28 | unsigned short adc_scan(int channel); | ||
29 | #endif | ||
diff --git a/firmware/target/arm/ipod/backlight-4g_color.c b/firmware/target/arm/ipod/backlight-4g_color.c new file mode 100644 index 0000000000..be1dff7c0b --- /dev/null +++ b/firmware/target/arm/ipod/backlight-4g_color.c | |||
@@ -0,0 +1,48 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Linus Nielsen Feltzing | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #include "config.h" | ||
20 | #include <stdlib.h> | ||
21 | #include "cpu.h" | ||
22 | #include "kernel.h" | ||
23 | #include "thread.h" | ||
24 | #include "i2c.h" | ||
25 | #include "debug.h" | ||
26 | #include "rtc.h" | ||
27 | #include "usb.h" | ||
28 | #include "power.h" | ||
29 | #include "system.h" | ||
30 | #include "button.h" | ||
31 | #include "timer.h" | ||
32 | #include "backlight.h" | ||
33 | |||
34 | inline void __backlight_on(void) | ||
35 | { | ||
36 | /* brightness full */ | ||
37 | outl(0x80000000 | (0xff << 16), 0x7000a010); | ||
38 | |||
39 | /* set port b bit 3 on */ | ||
40 | outl(((0x100 | 1) << 3), 0x6000d824); | ||
41 | } | ||
42 | |||
43 | inline void __backlight_off(void) | ||
44 | { | ||
45 | /* fades backlight off on 4g */ | ||
46 | outl(inl(0x70000084) & ~0x2000000, 0x70000084); | ||
47 | outl(0x80000000, 0x7000a010); | ||
48 | } | ||
diff --git a/firmware/target/arm/ipod/backlight-mini1g_mini2g.c b/firmware/target/arm/ipod/backlight-mini1g_mini2g.c new file mode 100644 index 0000000000..6cfa8f889c --- /dev/null +++ b/firmware/target/arm/ipod/backlight-mini1g_mini2g.c | |||
@@ -0,0 +1,44 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Linus Nielsen Feltzing | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #include "config.h" | ||
20 | #include <stdlib.h> | ||
21 | #include "cpu.h" | ||
22 | #include "kernel.h" | ||
23 | #include "thread.h" | ||
24 | #include "i2c.h" | ||
25 | #include "debug.h" | ||
26 | #include "rtc.h" | ||
27 | #include "usb.h" | ||
28 | #include "power.h" | ||
29 | #include "system.h" | ||
30 | #include "button.h" | ||
31 | #include "timer.h" | ||
32 | #include "backlight.h" | ||
33 | |||
34 | inline void __backlight_on(void) | ||
35 | { | ||
36 | /* set port B03 on */ | ||
37 | outl(((0x100 | 1) << 3), 0x6000d824); | ||
38 | } | ||
39 | |||
40 | inline void __backlight_off(void) | ||
41 | { | ||
42 | /* set port B03 off */ | ||
43 | outl(((0x100 | 0) << 3), 0x6000d824); | ||
44 | } | ||
diff --git a/firmware/target/arm/ipod/backlight-nano_video.c b/firmware/target/arm/ipod/backlight-nano_video.c new file mode 100644 index 0000000000..5559709333 --- /dev/null +++ b/firmware/target/arm/ipod/backlight-nano_video.c | |||
@@ -0,0 +1,50 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Linus Nielsen Feltzing | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #include "config.h" | ||
20 | #include <stdlib.h> | ||
21 | #include "cpu.h" | ||
22 | #include "kernel.h" | ||
23 | #include "thread.h" | ||
24 | #include "i2c.h" | ||
25 | #include "debug.h" | ||
26 | #include "rtc.h" | ||
27 | #include "usb.h" | ||
28 | #include "power.h" | ||
29 | #include "system.h" | ||
30 | #include "button.h" | ||
31 | #include "timer.h" | ||
32 | #include "backlight.h" | ||
33 | |||
34 | inline void __backlight_on(void) | ||
35 | { | ||
36 | /* set port B03 on */ | ||
37 | outl(((0x100 | 1) << 3), 0x6000d824); | ||
38 | |||
39 | /* set port L07 on */ | ||
40 | outl(((0x100 | 1) << 7), 0x6000d12c); | ||
41 | } | ||
42 | |||
43 | inline void __backlight_off(void) | ||
44 | { | ||
45 | /* set port B03 off */ | ||
46 | outl(((0x100 | 0) << 3), 0x6000d824); | ||
47 | |||
48 | /* set port L07 off */ | ||
49 | outl(((0x100 | 0) << 7), 0x6000d12c); | ||
50 | } | ||
diff --git a/firmware/target/arm/ipod/backlight-target.h b/firmware/target/arm/ipod/backlight-target.h new file mode 100644 index 0000000000..d35dccdc4a --- /dev/null +++ b/firmware/target/arm/ipod/backlight-target.h | |||
@@ -0,0 +1,25 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2006 by Barry Wardell | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #ifndef BACKLIGHT_TARGET_H | ||
20 | #define BACKLIGHT_TARGET_H | ||
21 | |||
22 | void __backlight_on(void); | ||
23 | void __backlight_off(void); | ||
24 | |||
25 | #endif | ||
diff --git a/firmware/target/arm/ipod/button-clickwheel.c b/firmware/target/arm/ipod/button-clickwheel.c new file mode 100644 index 0000000000..4c536343c4 --- /dev/null +++ b/firmware/target/arm/ipod/button-clickwheel.c | |||
@@ -0,0 +1,237 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Daniel Stenberg | ||
11 | * | ||
12 | * iPod driver based on code from the ipodlinux project - http://ipodlinux.org | ||
13 | * Adapted for Rockbox in December 2005 | ||
14 | * Original file: linux/arch/armnommu/mach-ipod/keyboard.c | ||
15 | * Copyright (c) 2003-2005 Bernard Leach (leachbj@bouncycastle.org) | ||
16 | * | ||
17 | * | ||
18 | * All files in this archive are subject to the GNU General Public License. | ||
19 | * See the file COPYING in the source tree root for full license agreement. | ||
20 | * | ||
21 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
22 | * KIND, either express or implied. | ||
23 | * | ||
24 | ****************************************************************************/ | ||
25 | |||
26 | /* | ||
27 | * Rockbox button functions | ||
28 | */ | ||
29 | |||
30 | #include <stdlib.h> | ||
31 | #include "config.h" | ||
32 | #include "cpu.h" | ||
33 | #include "system.h" | ||
34 | #include "button.h" | ||
35 | #include "kernel.h" | ||
36 | #include "backlight.h" | ||
37 | #include "adc.h" | ||
38 | #include "serial.h" | ||
39 | #include "power.h" | ||
40 | #include "system.h" | ||
41 | #include "powermgmt.h" | ||
42 | |||
43 | /* Variable to use for setting button status in interrupt handler */ | ||
44 | int int_btn = BUTTON_NONE; | ||
45 | #ifdef HAVE_WHEEL_POSITION | ||
46 | static int wheel_position = -1; | ||
47 | static bool send_events = true; | ||
48 | #endif | ||
49 | |||
50 | static void opto_i2c_init(void) | ||
51 | { | ||
52 | int i, curr_value; | ||
53 | |||
54 | /* wait for value to settle */ | ||
55 | i = 1000; | ||
56 | curr_value = (inl(0x7000c104) << 16) >> 24; | ||
57 | while (i > 0) | ||
58 | { | ||
59 | int new_value = (inl(0x7000c104) << 16) >> 24; | ||
60 | |||
61 | if (new_value != curr_value) { | ||
62 | i = 10000; | ||
63 | curr_value = new_value; | ||
64 | } | ||
65 | else { | ||
66 | i--; | ||
67 | } | ||
68 | } | ||
69 | |||
70 | GPIOB_OUTPUT_VAL |= 0x10; | ||
71 | DEV_EN |= 0x10000; | ||
72 | DEV_RS |= 0x10000; | ||
73 | udelay(5); | ||
74 | DEV_RS &= ~0x10000; /* finish reset */ | ||
75 | |||
76 | outl(0xffffffff, 0x7000c120); | ||
77 | outl(0xffffffff, 0x7000c124); | ||
78 | outl(0xc00a1f00, 0x7000c100); | ||
79 | outl(0x1000000, 0x7000c104); | ||
80 | } | ||
81 | |||
82 | static inline int ipod_4g_button_read(void) | ||
83 | { | ||
84 | int whl = -1; | ||
85 | |||
86 | /* The ipodlinux source had a udelay(250) here, but testing has shown that | ||
87 | it is not needed - tested on Nano, Color/Photo and Video. */ | ||
88 | /* udelay(250);*/ | ||
89 | |||
90 | int btn = BUTTON_NONE; | ||
91 | unsigned reg = 0x7000c104; | ||
92 | if ((inl(0x7000c104) & 0x4000000) != 0) { | ||
93 | unsigned status = inl(0x7000c140); | ||
94 | |||
95 | reg = reg + 0x3C; /* 0x7000c140 */ | ||
96 | outl(0x0, 0x7000c140); /* clear interrupt status? */ | ||
97 | |||
98 | if ((status & 0x800000ff) == 0x8000001a) { | ||
99 | static int old_wheel_value IDATA_ATTR = -1; | ||
100 | static int wheel_repeat = 0; | ||
101 | |||
102 | if (status & 0x100) | ||
103 | btn |= BUTTON_SELECT; | ||
104 | if (status & 0x200) | ||
105 | btn |= BUTTON_RIGHT; | ||
106 | if (status & 0x400) | ||
107 | btn |= BUTTON_LEFT; | ||
108 | if (status & 0x800) | ||
109 | btn |= BUTTON_PLAY; | ||
110 | if (status & 0x1000) | ||
111 | btn |= BUTTON_MENU; | ||
112 | if (status & 0x40000000) { | ||
113 | /* NB: highest wheel = 0x5F, clockwise increases */ | ||
114 | int new_wheel_value = (status << 9) >> 25; | ||
115 | whl = new_wheel_value; | ||
116 | backlight_on(); | ||
117 | /* The queue should have no other events when scrolling */ | ||
118 | if (queue_empty(&button_queue) && old_wheel_value >= 0) { | ||
119 | |||
120 | /* This is for later = BUTTON_SCROLL_TOUCH;*/ | ||
121 | int wheel_delta = new_wheel_value - old_wheel_value; | ||
122 | unsigned long data; | ||
123 | int wheel_keycode; | ||
124 | |||
125 | if (wheel_delta < -48) | ||
126 | wheel_delta += 96; /* Forward wrapping case */ | ||
127 | else if (wheel_delta > 48) | ||
128 | wheel_delta -= 96; /* Backward wrapping case */ | ||
129 | |||
130 | if (wheel_delta > 4) { | ||
131 | wheel_keycode = BUTTON_SCROLL_FWD; | ||
132 | } else if (wheel_delta < -4) { | ||
133 | wheel_keycode = BUTTON_SCROLL_BACK; | ||
134 | } else goto wheel_end; | ||
135 | |||
136 | #ifdef HAVE_WHEEL_POSITION | ||
137 | if (send_events) | ||
138 | #endif | ||
139 | { | ||
140 | data = (wheel_delta << 16) | new_wheel_value; | ||
141 | queue_post(&button_queue, wheel_keycode | wheel_repeat, | ||
142 | (void *)data); | ||
143 | } | ||
144 | |||
145 | if (!wheel_repeat) wheel_repeat = BUTTON_REPEAT; | ||
146 | } | ||
147 | |||
148 | old_wheel_value = new_wheel_value; | ||
149 | } else if (old_wheel_value >= 0) { | ||
150 | /* scroll wheel up */ | ||
151 | old_wheel_value = -1; | ||
152 | wheel_repeat = 0; | ||
153 | } | ||
154 | |||
155 | } else if (status == 0xffffffff) { | ||
156 | opto_i2c_init(); | ||
157 | } | ||
158 | } | ||
159 | |||
160 | wheel_end: | ||
161 | |||
162 | if ((inl(reg) & 0x8000000) != 0) { | ||
163 | outl(0xffffffff, 0x7000c120); | ||
164 | outl(0xffffffff, 0x7000c124); | ||
165 | } | ||
166 | /* Save the new absolute wheel position */ | ||
167 | wheel_position = whl; | ||
168 | return btn; | ||
169 | } | ||
170 | |||
171 | #ifdef HAVE_WHEEL_POSITION | ||
172 | int wheel_status(void) | ||
173 | { | ||
174 | return wheel_position; | ||
175 | } | ||
176 | |||
177 | void wheel_send_events(bool send) | ||
178 | { | ||
179 | send_events = send; | ||
180 | } | ||
181 | #endif | ||
182 | |||
183 | void ipod_4g_button_int(void) | ||
184 | { | ||
185 | CPU_HI_INT_CLR = I2C_MASK; | ||
186 | /* The following delay was 250 in the ipodlinux source, but 50 seems to | ||
187 | work fine - tested on Nano, Color/Photo and Video. */ | ||
188 | udelay(50); | ||
189 | outl(0x0, 0x7000c140); | ||
190 | int_btn = ipod_4g_button_read(); | ||
191 | outl(inl(0x7000c104) | 0xC000000, 0x7000c104); | ||
192 | outl(0x400a1f00, 0x7000c100); | ||
193 | |||
194 | GPIOB_OUTPUT_VAL |= 0x10; | ||
195 | CPU_INT_EN = 0x40000000; | ||
196 | CPU_HI_INT_EN = I2C_MASK; | ||
197 | } | ||
198 | |||
199 | void button_init_device(void) | ||
200 | { | ||
201 | opto_i2c_init(); | ||
202 | /* hold button - enable as input */ | ||
203 | GPIOA_ENABLE |= 0x20; | ||
204 | GPIOA_OUTPUT_EN &= ~0x20; | ||
205 | /* hold button - set interrupt levels */ | ||
206 | GPIOA_INT_LEV = ~(GPIOA_INPUT_VAL & 0x20); | ||
207 | GPIOA_INT_CLR = GPIOA_INT_STAT & 0x20; | ||
208 | /* enable interrupts */ | ||
209 | GPIOA_INT_EN = 0x20; | ||
210 | /* unmask interrupt */ | ||
211 | CPU_INT_EN = 0x40000000; | ||
212 | CPU_HI_INT_EN = I2C_MASK; | ||
213 | } | ||
214 | |||
215 | /* | ||
216 | * Get button pressed from hardware | ||
217 | */ | ||
218 | int button_read_device(void) | ||
219 | { | ||
220 | static bool hold_button = false; | ||
221 | bool hold_button_old; | ||
222 | |||
223 | /* normal buttons */ | ||
224 | hold_button_old = hold_button; | ||
225 | hold_button = button_hold(); | ||
226 | |||
227 | if (hold_button != hold_button_old) | ||
228 | backlight_hold_changed(hold_button); | ||
229 | |||
230 | /* The int_btn variable is set in the button interrupt handler */ | ||
231 | return int_btn; | ||
232 | } | ||
233 | |||
234 | bool button_hold(void) | ||
235 | { | ||
236 | return (GPIOA_INPUT_VAL & 0x20)?false:true; | ||
237 | } | ||
diff --git a/firmware/target/arm/ipod/button-mini1g.c b/firmware/target/arm/ipod/button-mini1g.c new file mode 100644 index 0000000000..07885bc159 --- /dev/null +++ b/firmware/target/arm/ipod/button-mini1g.c | |||
@@ -0,0 +1,217 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Daniel Stenberg | ||
11 | * | ||
12 | * iPod driver based on code from the ipodlinux project - http://ipodlinux.org | ||
13 | * Adapted for Rockbox in December 2005 | ||
14 | * Original file: linux/arch/armnommu/mach-ipod/keyboard.c | ||
15 | * Copyright (c) 2003-2005 Bernard Leach (leachbj@bouncycastle.org) | ||
16 | * | ||
17 | * | ||
18 | * All files in this archive are subject to the GNU General Public License. | ||
19 | * See the file COPYING in the source tree root for full license agreement. | ||
20 | * | ||
21 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
22 | * KIND, either express or implied. | ||
23 | * | ||
24 | ****************************************************************************/ | ||
25 | |||
26 | /* | ||
27 | * Rockbox button functions | ||
28 | */ | ||
29 | |||
30 | #include <stdlib.h> | ||
31 | #include "config.h" | ||
32 | #include "cpu.h" | ||
33 | #include "system.h" | ||
34 | #include "button.h" | ||
35 | #include "kernel.h" | ||
36 | #include "backlight.h" | ||
37 | #include "adc.h" | ||
38 | #include "serial.h" | ||
39 | #include "power.h" | ||
40 | #include "system.h" | ||
41 | #include "powermgmt.h" | ||
42 | |||
43 | /* Variable to use for setting button status in interrupt handler */ | ||
44 | int int_btn = BUTTON_NONE; | ||
45 | #ifdef HAVE_WHEEL_POSITION | ||
46 | static int wheel_position = -1; | ||
47 | static bool send_events = true; | ||
48 | #endif | ||
49 | |||
50 | /* iPod 3G and mini 1G, mini 2G uses iPod 4G code */ | ||
51 | void handle_scroll_wheel(int new_scroll, int was_hold, int reverse) | ||
52 | { | ||
53 | int wheel_keycode = BUTTON_NONE; | ||
54 | static int prev_scroll = -1; | ||
55 | static int direction = 0; | ||
56 | static int count = 0; | ||
57 | static int scroll_state[4][4] = { | ||
58 | {0, 1, -1, 0}, | ||
59 | {-1, 0, 0, 1}, | ||
60 | {1, 0, 0, -1}, | ||
61 | {0, -1, 1, 0} | ||
62 | }; | ||
63 | |||
64 | if ( prev_scroll == -1 ) { | ||
65 | prev_scroll = new_scroll; | ||
66 | } | ||
67 | else if (direction != scroll_state[prev_scroll][new_scroll]) { | ||
68 | direction = scroll_state[prev_scroll][new_scroll]; | ||
69 | count = 0; | ||
70 | } | ||
71 | else if (!was_hold) { | ||
72 | backlight_on(); | ||
73 | if (++count == 6) { /* reduce sensitivity */ | ||
74 | count = 0; | ||
75 | switch (direction) { | ||
76 | case 1: | ||
77 | if (reverse) { | ||
78 | /* 'r' keypress */ | ||
79 | wheel_keycode = BUTTON_SCROLL_FWD; | ||
80 | } | ||
81 | else { | ||
82 | /* 'l' keypress */ | ||
83 | wheel_keycode = BUTTON_SCROLL_BACK; | ||
84 | } | ||
85 | break; | ||
86 | case -1: | ||
87 | if (reverse) { | ||
88 | /* 'l' keypress */ | ||
89 | wheel_keycode = BUTTON_SCROLL_BACK; | ||
90 | } | ||
91 | else { | ||
92 | /* 'r' keypress */ | ||
93 | wheel_keycode = BUTTON_SCROLL_FWD; | ||
94 | } | ||
95 | break; | ||
96 | default: | ||
97 | /* only happens if we get out of sync */ | ||
98 | break; | ||
99 | } | ||
100 | } | ||
101 | } | ||
102 | if (wheel_keycode != BUTTON_NONE && queue_empty(&button_queue)) | ||
103 | queue_post(&button_queue, wheel_keycode, NULL); | ||
104 | prev_scroll = new_scroll; | ||
105 | } | ||
106 | |||
107 | /* mini 1 only, mini 2G uses iPod 4G code */ | ||
108 | static int ipod_mini_button_read(void) | ||
109 | { | ||
110 | unsigned char source, wheel_source, state, wheel_state; | ||
111 | static bool was_hold = false; | ||
112 | int btn = BUTTON_NONE; | ||
113 | |||
114 | /* The ipodlinux source had a udelay(250) here, but testing has shown that | ||
115 | it is not needed - tested on mini 1g. */ | ||
116 | /* udelay(250);*/ | ||
117 | |||
118 | /* get source(s) of interupt */ | ||
119 | source = GPIOA_INT_STAT & 0x3f; | ||
120 | wheel_source = GPIOB_INT_STAT & 0x30; | ||
121 | |||
122 | if (source == 0 && wheel_source == 0) { | ||
123 | return BUTTON_NONE; /* not for us */ | ||
124 | } | ||
125 | |||
126 | /* get current keypad & wheel status */ | ||
127 | state = GPIOA_INPUT_VAL & 0x3f; | ||
128 | wheel_state = GPIOB_INPUT_VAL & 0x30; | ||
129 | |||
130 | /* toggle interrupt level */ | ||
131 | GPIOA_INT_LEV = ~state; | ||
132 | GPIOB_INT_LEV = ~wheel_state; | ||
133 | |||
134 | /* hold switch causes all outputs to go low */ | ||
135 | /* we shouldn't interpret these as key presses */ | ||
136 | if ((state & 0x20)) { | ||
137 | if (!(state & 0x1)) | ||
138 | btn |= BUTTON_SELECT; | ||
139 | if (!(state & 0x2)) | ||
140 | btn |= BUTTON_MENU; | ||
141 | if (!(state & 0x4)) | ||
142 | btn |= BUTTON_PLAY; | ||
143 | if (!(state & 0x8)) | ||
144 | btn |= BUTTON_RIGHT; | ||
145 | if (!(state & 0x10)) | ||
146 | btn |= BUTTON_LEFT; | ||
147 | |||
148 | if (wheel_source & 0x30) { | ||
149 | handle_scroll_wheel((wheel_state & 0x30) >> 4, was_hold, 1); | ||
150 | } | ||
151 | } | ||
152 | |||
153 | was_hold = button_hold(); | ||
154 | |||
155 | /* ack any active interrupts */ | ||
156 | if (source) | ||
157 | GPIOA_INT_CLR = source; | ||
158 | if (wheel_source) | ||
159 | GPIOB_INT_CLR = wheel_source; | ||
160 | |||
161 | return btn; | ||
162 | } | ||
163 | |||
164 | void ipod_mini_button_int(void) | ||
165 | { | ||
166 | CPU_HI_INT_CLR = GPIO_MASK; | ||
167 | int_btn = ipod_mini_button_read(); | ||
168 | //CPU_INT_EN = 0x40000000; | ||
169 | CPU_HI_INT_EN = GPIO_MASK; | ||
170 | } | ||
171 | |||
172 | void button_init_device(void) | ||
173 | { | ||
174 | /* iPod Mini G1 */ | ||
175 | /* buttons - enable as input */ | ||
176 | GPIOA_ENABLE |= 0x3f; | ||
177 | GPIOA_OUTPUT_EN &= ~0x3f; | ||
178 | /* scroll wheel- enable as input */ | ||
179 | GPIOB_ENABLE |= 0x30; /* port b 4,5 */ | ||
180 | GPIOB_OUTPUT_EN &= ~0x30; /* port b 4,5 */ | ||
181 | /* buttons - set interrupt levels */ | ||
182 | GPIOA_INT_LEV = ~(GPIOA_INPUT_VAL & 0x3f); | ||
183 | GPIOA_INT_CLR = GPIOA_INT_STAT & 0x3f; | ||
184 | /* scroll wheel - set interrupt levels */ | ||
185 | GPIOB_INT_LEV = ~(GPIOB_INPUT_VAL & 0x30); | ||
186 | GPIOB_INT_CLR = GPIOB_INT_STAT & 0x30; | ||
187 | /* enable interrupts */ | ||
188 | GPIOA_INT_EN = 0x3f; | ||
189 | GPIOB_INT_EN = 0x30; | ||
190 | /* unmask interrupt */ | ||
191 | CPU_INT_EN = 0x40000000; | ||
192 | CPU_HI_INT_EN = GPIO_MASK; | ||
193 | } | ||
194 | |||
195 | /* | ||
196 | * Get button pressed from hardware | ||
197 | */ | ||
198 | int button_read_device(void) | ||
199 | { | ||
200 | static bool hold_button = false; | ||
201 | bool hold_button_old; | ||
202 | |||
203 | /* normal buttons */ | ||
204 | hold_button_old = hold_button; | ||
205 | hold_button = button_hold(); | ||
206 | |||
207 | if (hold_button != hold_button_old) | ||
208 | backlight_hold_changed(hold_button); | ||
209 | |||
210 | /* The int_btn variable is set in the button interrupt handler */ | ||
211 | return int_btn; | ||
212 | } | ||
213 | |||
214 | bool button_hold(void) | ||
215 | { | ||
216 | return (GPIOA_INPUT_VAL & 0x20)?false:true; | ||
217 | } | ||
diff --git a/firmware/target/arm/ipod/button-target.h b/firmware/target/arm/ipod/button-target.h new file mode 100644 index 0000000000..d736effb72 --- /dev/null +++ b/firmware/target/arm/ipod/button-target.h | |||
@@ -0,0 +1,61 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2006 by Barry Wardell | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #ifndef _BUTTON_TARGET_H_ | ||
20 | #define _BUTTON_TARGET_H_ | ||
21 | |||
22 | #include <stdbool.h> | ||
23 | #include "config.h" | ||
24 | |||
25 | #define HAS_BUTTON_HOLD | ||
26 | |||
27 | bool button_hold(void); | ||
28 | void button_init_device(void); | ||
29 | int button_read_device(void); | ||
30 | |||
31 | void handle_scroll_wheel(int new_scroll, int was_hold, int reverse); | ||
32 | void ipod_mini_button_int(void); | ||
33 | void ipod_4g_button_int(void); | ||
34 | |||
35 | /* iPod specific button codes */ | ||
36 | |||
37 | #define BUTTON_SELECT 0x00000001 | ||
38 | #define BUTTON_MENU 0x00000002 | ||
39 | |||
40 | #define BUTTON_LEFT 0x00000004 | ||
41 | #define BUTTON_RIGHT 0x00000008 | ||
42 | #define BUTTON_SCROLL_FWD 0x00000010 | ||
43 | #define BUTTON_SCROLL_BACK 0x00000020 | ||
44 | |||
45 | #define BUTTON_PLAY 0x00000040 | ||
46 | |||
47 | #define BUTTON_MAIN (BUTTON_SELECT|BUTTON_MENU\ | ||
48 | |BUTTON_LEFT|BUTTON_RIGHT|BUTTON_SCROLL_FWD\ | ||
49 | |BUTTON_SCROLL_BACK|BUTTON_PLAY) | ||
50 | |||
51 | #define BUTTON_REMOTE 0 | ||
52 | |||
53 | /* This is for later | ||
54 | #define BUTTON_SCROLL_TOUCH 0x00000200 | ||
55 | */ | ||
56 | |||
57 | |||
58 | #define POWEROFF_BUTTON BUTTON_PLAY | ||
59 | #define POWEROFF_COUNT 40 | ||
60 | |||
61 | #endif /* _BUTTON_TARGET_H_ */ | ||
diff --git a/firmware/target/arm/ipod/power-ipod.c b/firmware/target/arm/ipod/power-ipod.c new file mode 100644 index 0000000000..8932b95cdd --- /dev/null +++ b/firmware/target/arm/ipod/power-ipod.c | |||
@@ -0,0 +1,81 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Linus Nielsen Feltzing | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #include "config.h" | ||
20 | #include "cpu.h" | ||
21 | #include <stdbool.h> | ||
22 | #include "adc.h" | ||
23 | #include "kernel.h" | ||
24 | #include "system.h" | ||
25 | #include "power.h" | ||
26 | #include "hwcompat.h" | ||
27 | #include "logf.h" | ||
28 | #include "pcf50605.h" | ||
29 | #include "usb.h" | ||
30 | #include "lcd.h" | ||
31 | |||
32 | void power_init(void) | ||
33 | { | ||
34 | pcf50605_init(); | ||
35 | } | ||
36 | |||
37 | bool charger_inserted(void) | ||
38 | { | ||
39 | #ifdef IPOD_VIDEO | ||
40 | return (GPIOL_INPUT_VAL & 0x08)?false:true; | ||
41 | #else | ||
42 | /* This needs filling in for other ipods. */ | ||
43 | return false; | ||
44 | #endif | ||
45 | } | ||
46 | |||
47 | /* Returns true if the unit is charging the batteries. */ | ||
48 | bool charging_state(void) { | ||
49 | return (GPIOB_INPUT_VAL & 0x01)?false:true; | ||
50 | } | ||
51 | |||
52 | |||
53 | void ide_power_enable(bool on) | ||
54 | { | ||
55 | /* We do nothing on the iPod */ | ||
56 | (void)on; | ||
57 | } | ||
58 | |||
59 | bool ide_powered(void) | ||
60 | { | ||
61 | /* pretend we are always powered - we don't turn it off on the ipod */ | ||
62 | return true; | ||
63 | } | ||
64 | |||
65 | void power_off(void) | ||
66 | { | ||
67 | #if defined(HAVE_LCD_COLOR) | ||
68 | /* Clear the screen and backdrop to | ||
69 | remove ghosting effect on shutdown */ | ||
70 | lcd_set_backdrop(NULL); | ||
71 | lcd_set_background(LCD_WHITE); | ||
72 | lcd_clear_display(); | ||
73 | lcd_update(); | ||
74 | sleep(HZ/16); | ||
75 | #endif | ||
76 | |||
77 | #ifndef BOOTLOADER | ||
78 | /* We don't turn off the ipod, we put it in a deep sleep */ | ||
79 | pcf50605_standby_mode(); | ||
80 | #endif | ||
81 | } | ||
diff --git a/firmware/target/arm/ipod/usb-ipod.c b/firmware/target/arm/ipod/usb-ipod.c new file mode 100644 index 0000000000..c481355768 --- /dev/null +++ b/firmware/target/arm/ipod/usb-ipod.c | |||
@@ -0,0 +1,114 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Linus Nielsen Feltzing | ||
11 | * | ||
12 | * iPod driver based on code from the ipodlinux project - http://ipodlinux.org | ||
13 | * Adapted for Rockbox in January 2006 | ||
14 | * Original file: podzilla/usb.c | ||
15 | * Copyright (C) 2005 Adam Johnston | ||
16 | * | ||
17 | * All files in this archive are subject to the GNU General Public License. | ||
18 | * See the file COPYING in the source tree root for full license agreement. | ||
19 | * | ||
20 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
21 | * KIND, either express or implied. | ||
22 | * | ||
23 | ****************************************************************************/ | ||
24 | #include "config.h" | ||
25 | #include "cpu.h" | ||
26 | #include "kernel.h" | ||
27 | #include "thread.h" | ||
28 | #include "system.h" | ||
29 | #include "debug.h" | ||
30 | #include "ata.h" | ||
31 | #include "fat.h" | ||
32 | #include "disk.h" | ||
33 | #include "panic.h" | ||
34 | #include "lcd.h" | ||
35 | #include "adc.h" | ||
36 | #include "usb.h" | ||
37 | #include "button.h" | ||
38 | #include "sprintf.h" | ||
39 | #include "string.h" | ||
40 | #include "hwcompat.h" | ||
41 | |||
42 | void usb_init_device(void) | ||
43 | { | ||
44 | int r0; | ||
45 | outl(inl(0x70000084) | 0x200, 0x70000084); | ||
46 | |||
47 | outl(inl(0x7000002C) | 0x3000000, 0x7000002C); | ||
48 | outl(inl(0x6000600C) | 0x400000, 0x6000600C); | ||
49 | |||
50 | outl(inl(0x60006004) | 0x400000, 0x60006004); /* reset usb start */ | ||
51 | outl(inl(0x60006004) & ~0x400000, 0x60006004); /* reset usb end */ | ||
52 | |||
53 | outl(inl(0x70000020) | 0x80000000, 0x70000020); | ||
54 | while ((inl(0x70000028) & 0x80) == 0); | ||
55 | |||
56 | outl(inl(0xc5000184) | 0x100, 0xc5000184); | ||
57 | while ((inl(0xc5000184) & 0x100) != 0); | ||
58 | |||
59 | outl(inl(0xc50001A4) | 0x5F000000, 0xc50001A4); | ||
60 | if ((inl(0xc50001A4) & 0x100) == 0) { | ||
61 | outl(inl(0xc50001A8) & ~0x3, 0xc50001A8); | ||
62 | outl(inl(0xc50001A8) | 0x2, 0xc50001A8); | ||
63 | outl(inl(0x70000028) | 0x4000, 0x70000028); | ||
64 | outl(inl(0x70000028) | 0x2, 0x70000028); | ||
65 | } else { | ||
66 | outl(inl(0xc50001A8) | 0x3, 0xc50001A8); | ||
67 | outl(inl(0x70000028) &~0x4000, 0x70000028); | ||
68 | outl(inl(0x70000028) | 0x2, 0x70000028); | ||
69 | } | ||
70 | outl(inl(0xc5000140) | 0x2, 0xc5000140); | ||
71 | while((inl(0xc5000140) & 0x2) != 0); | ||
72 | r0 = inl(0xc5000184); | ||
73 | |||
74 | /* Note from IPL source (referring to next 5 lines of code: | ||
75 | THIS NEEDS TO BE CHANGED ONCE THERE IS KERNEL USB */ | ||
76 | outl(inl(0x70000020) | 0x80000000, 0x70000020); | ||
77 | outl(inl(0x6000600C) | 0x400000, 0x6000600C); | ||
78 | while ((inl(0x70000028) & 0x80) == 0); | ||
79 | outl(inl(0x70000028) | 0x2, 0x70000028); | ||
80 | |||
81 | udelay(0x186A0); | ||
82 | } | ||
83 | |||
84 | void usb_enable(bool on) | ||
85 | { | ||
86 | /* For the ipod, we can only do one thing with USB mode - reboot | ||
87 | into Apple's flash-based disk-mode. This does not return. */ | ||
88 | if (on) | ||
89 | { | ||
90 | /* The following code is copied from ipodlinux */ | ||
91 | #if defined(IPOD_COLOR) || defined(IPOD_3G) || \ | ||
92 | defined(IPOD_4G) || defined(IPOD_MINI) | ||
93 | unsigned char* storage_ptr = (unsigned char *)0x40017F00; | ||
94 | #elif defined(IPOD_NANO) || defined(IPOD_VIDEO) || defined(IPOD_MINI2G) | ||
95 | unsigned char* storage_ptr = (unsigned char *)0x4001FF00; | ||
96 | #endif | ||
97 | memcpy(storage_ptr, "diskmode\0\0hotstuff\0\0\1", 21); | ||
98 | DEV_RS |= 4; /* Reboot */ | ||
99 | } | ||
100 | } | ||
101 | |||
102 | bool usb_detect(void) | ||
103 | { | ||
104 | bool current_status; | ||
105 | |||
106 | /* The following check is in the ipodlinux source, with the | ||
107 | comment "USB2D_IDENT is bad" if USB2D_IDENT != 0x22FA05 */ | ||
108 | if (USB2D_IDENT != 0x22FA05) { | ||
109 | return false; | ||
110 | } | ||
111 | current_status = (USB_STATUS & 0x800)?true:false; | ||
112 | |||
113 | return current_status; | ||
114 | } | ||
diff --git a/firmware/target/arm/ipod/usb-target.h b/firmware/target/arm/ipod/usb-target.h new file mode 100644 index 0000000000..69a81472f8 --- /dev/null +++ b/firmware/target/arm/ipod/usb-target.h | |||
@@ -0,0 +1,24 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2006 by Barry Wardelll | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #ifndef USB_TARGET_H | ||
20 | #define USB_TARGET_H | ||
21 | |||
22 | bool usb_init_device(void); | ||
23 | |||
24 | #endif | ||