summaryrefslogtreecommitdiff
path: root/firmware/target/coldfire/iaudio/x5
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2007-03-05 00:04:00 +0000
committerJens Arnold <amiconn@rockbox.org>2007-03-05 00:04:00 +0000
commit8876018d25c6a56cce118482c1372bbff344cb23 (patch)
treea66dca10bf92674c655b9862fd366ecc77bba76a /firmware/target/coldfire/iaudio/x5
parentee07215d506def8d3483f4adf6e1d4ae51c10c52 (diff)
downloadrockbox-8876018d25c6a56cce118482c1372bbff344cb23.tar.gz
rockbox-8876018d25c6a56cce118482c1372bbff344cb23.zip
Bring up the M5 port to a working stage: Extended numerous explicit checks for IAUDIO_X5 to also check for IAUDIO_M5, moved code around the target tree, added preliminary background for the sim.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12610 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target/coldfire/iaudio/x5')
-rw-r--r--firmware/target/coldfire/iaudio/x5/adc-target.h35
-rw-r--r--firmware/target/coldfire/iaudio/x5/adc-x5.c58
-rw-r--r--firmware/target/coldfire/iaudio/x5/ata-x5.c64
-rw-r--r--firmware/target/coldfire/iaudio/x5/button-target.h73
-rw-r--r--firmware/target/coldfire/iaudio/x5/lcd-remote-target.h38
-rw-r--r--firmware/target/coldfire/iaudio/x5/lcd-remote-x5.c517
-rw-r--r--firmware/target/coldfire/iaudio/x5/pcf50606-x5.c127
-rw-r--r--firmware/target/coldfire/iaudio/x5/system-x5.c90
-rw-r--r--firmware/target/coldfire/iaudio/x5/usb-x5.c45
9 files changed, 0 insertions, 1047 deletions
diff --git a/firmware/target/coldfire/iaudio/x5/adc-target.h b/firmware/target/coldfire/iaudio/x5/adc-target.h
deleted file mode 100644
index 28ba6225d1..0000000000
--- a/firmware/target/coldfire/iaudio/x5/adc-target.h
+++ /dev/null
@@ -1,35 +0,0 @@
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 3
23
24#define ADC_BUTTONS 0
25#define ADC_REMOTE 1
26#define ADC_BATTERY 2
27#define ADC_UNREG_POWER ADC_BATTERY /* For compatibility */
28
29/* Force a scan now */
30unsigned short adc_scan(int channel);
31static inline unsigned short adc_read(int channel)
32 { return adc_scan(channel); }
33static inline void adc_init(void)
34 {}
35#endif /* _ADC_TARGET_H_ */
diff --git a/firmware/target/coldfire/iaudio/x5/adc-x5.c b/firmware/target/coldfire/iaudio/x5/adc-x5.c
deleted file mode 100644
index 1895cacfe9..0000000000
--- a/firmware/target/coldfire/iaudio/x5/adc-x5.c
+++ /dev/null
@@ -1,58 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 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 "adc.h"
25#include "pcf50606.h"
26
27/* get remaining 2 bits and return 10 bit value */
28static int get_10bit_voltage(int msbdata)
29{
30 int data = msbdata << 2;
31 data |= pcf50606_read(0x31) & 0x3;
32 return data;
33}
34
35unsigned short adc_scan(int channel)
36{
37 static const int adcc2_parms[] =
38 {
39 [ADC_BUTTONS] = 0x81 | (5 << 1), /* 8b - ADCIN2 */
40 [ADC_REMOTE] = 0x81 | (6 << 1), /* 8b - ADCIN3 */
41 [ADC_BATTERY] = 0x01 | (0 << 1), /* 10b - BATVOLT, resistive divider */
42 };
43
44 int level;
45 int data;
46
47 level = set_irq_level(HIGHEST_IRQ_LEVEL);
48
49 pcf50606_write(0x2f, adcc2_parms[channel]);
50 data = pcf50606_read(0x30);
51
52 if (channel == ADC_BATTERY)
53 data = get_10bit_voltage(data);
54
55 set_irq_level(level);
56
57 return (unsigned short)data;
58}
diff --git a/firmware/target/coldfire/iaudio/x5/ata-x5.c b/firmware/target/coldfire/iaudio/x5/ata-x5.c
deleted file mode 100644
index 21c088288a..0000000000
--- a/firmware/target/coldfire/iaudio/x5/ata-x5.c
+++ /dev/null
@@ -1,64 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 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 "kernel.h"
23#include "system.h"
24#include "power.h"
25#include "pcf50606.h"
26
27void ata_reset(void)
28{
29 and_l(~0x40000000, &GPIO_OUT);
30 sleep(1); /* > 25us */
31 or_l(0x40000000, &GPIO_OUT);
32 sleep(1); /* > 2ms */
33}
34
35void ata_enable(bool on)
36{
37 if(on)
38 and_l(~0x00000800, &GPIO1_OUT);
39 else
40 or_l(0x00000800, &GPIO1_OUT);
41}
42
43bool ata_is_coldstart(void)
44{
45 return true; /* TODO */
46}
47
48void ata_device_init(void)
49{
50 /* ATA reset */
51 or_l(0x40000000, &GPIO_OUT);
52 or_l(0x40000000, &GPIO_ENABLE);
53 or_l(0x40000000, &GPIO_FUNCTION);
54
55 /* ATA enable */
56 or_l(0x00000800, &GPIO1_OUT);
57 or_l(0x00000800, &GPIO1_ENABLE);
58 or_l(0x00000800, &GPIO1_FUNCTION);
59
60 /* USB enable */
61 and_l(~0x00000008, &GPIO1_OUT);
62 or_l(0x00000008, &GPIO1_ENABLE);
63 or_l(0x00000008, &GPIO1_FUNCTION);
64}
diff --git a/firmware/target/coldfire/iaudio/x5/button-target.h b/firmware/target/coldfire/iaudio/x5/button-target.h
deleted file mode 100644
index af1088dfed..0000000000
--- a/firmware/target/coldfire/iaudio/x5/button-target.h
+++ /dev/null
@@ -1,73 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 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 _BUTTON_TARGET_H_
20#define _BUTTON_TARGET_H_
21
22#include <stdbool.h>
23#include "config.h"
24
25#define HAS_BUTTON_HOLD
26#define HAS_REMOTE_BUTTON_HOLD
27
28bool button_hold(void);
29bool remote_button_hold(void);
30void button_init_device(void);
31int button_read_device(void);
32void button_enable_scan(bool enable);
33bool button_scan_enabled(void);
34
35/* iaudio X5 specific button codes */
36
37 /* Main unit's buttons */
38#define BUTTON_POWER 0x00000001
39#define BUTTON_REC 0x00000002
40
41#define BUTTON_LEFT 0x00000004
42#define BUTTON_RIGHT 0x00000008
43#define BUTTON_UP 0x00000010
44#define BUTTON_DOWN 0x00000020
45
46#define BUTTON_PLAY 0x00000040
47#define BUTTON_SELECT 0x00000080
48
49#define BUTTON_MAIN (BUTTON_POWER|BUTTON_PLAY|BUTTON_LEFT|BUTTON_RIGHT\
50 |BUTTON_UP|BUTTON_DOWN|BUTTON_REC|BUTTON_SELECT)
51
52 /* Remote control's buttons */
53#define BUTTON_RC_PLAY 0x00100000
54
55#define BUTTON_RC_REW 0x00080000
56#define BUTTON_RC_FF 0x00040000
57#define BUTTON_RC_VOL_UP 0x00020000
58#define BUTTON_RC_VOL_DOWN 0x00010000
59
60#define BUTTON_RC_REC 0x00008000
61#define BUTTON_RC_MENU 0x00004000
62
63#define BUTTON_RC_MODE 0x00002000
64
65#define BUTTON_REMOTE (BUTTON_RC_PLAY|BUTTON_RC_VOL_UP|BUTTON_RC_VOL_DOWN\
66 |BUTTON_RC_REW|BUTTON_RC_FF\
67 |BUTTON_RC_REC|BUTTON_RC_MENU|BUTTON_RC_MODE)
68
69#define POWEROFF_BUTTON BUTTON_POWER
70#define RC_POWEROFF_BUTTON BUTTON_RC_PLAY
71#define POWEROFF_COUNT 30
72
73#endif /* _BUTTON_TARGET_H_ */
diff --git a/firmware/target/coldfire/iaudio/x5/lcd-remote-target.h b/firmware/target/coldfire/iaudio/x5/lcd-remote-target.h
deleted file mode 100644
index 86c361097b..0000000000
--- a/firmware/target/coldfire/iaudio/x5/lcd-remote-target.h
+++ /dev/null
@@ -1,38 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 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 LCD_REMOTE_TARGET_H
20#define LCD_REMOTE_TARGET_H
21
22#define REMOTE_INIT_LCD 1
23#define REMOTE_DEINIT_LCD 2
24
25void lcd_remote_init_device(void);
26void lcd_remote_write_command(int cmd);
27void lcd_remote_write_command_ex(int cmd, int data);
28void lcd_remote_write_data(const unsigned char* p_bytes, int count);
29bool remote_detect(void);
30void lcd_remote_powersave(bool on);
31void lcd_remote_set_contrast(int val);
32void lcd_remote_on(void);
33void lcd_remote_off(void);
34void lcd_remote_poweroff(void); /* for when remote is plugged during shutdown*/
35
36extern bool remote_initialized;
37
38#endif
diff --git a/firmware/target/coldfire/iaudio/x5/lcd-remote-x5.c b/firmware/target/coldfire/iaudio/x5/lcd-remote-x5.c
deleted file mode 100644
index 139ebbc2a3..0000000000
--- a/firmware/target/coldfire/iaudio/x5/lcd-remote-x5.c
+++ /dev/null
@@ -1,517 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 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 "system.h"
21#include "kernel.h"
22#include "lcd-remote.h"
23
24/* The LCD in the iAudio M3/M5/X5 remote control is a Tomato LSI 0350 */
25
26#define LCD_SET_DUTY_RATIO 0x48
27#define LCD_SELECT_ADC 0xa0
28#define LCD_SELECT_SHL 0xc0
29#define LCD_SET_COM0 0x44
30#define LCD_OSC_ON 0xab
31#define LCD_SELECT_DCDC 0x64
32#define LCD_SELECT_RES 0x20
33#define LCD_SET_VOLUME 0x81
34#define LCD_SET_BIAS 0x50
35#define LCD_CONTROL_POWER 0x28
36#define LCD_DISPLAY_ON 0xae
37#define LCD_SET_INITLINE 0x40
38#define LCD_SET_COLUMN 0x10
39#define LCD_SET_PAGE 0xb0
40#define LCD_SET_GRAY 0x88
41#define LCD_SET_PWM_FRC 0x90
42#define LCD_SET_POWER_SAVE 0xa8
43#define LCD_REVERSE 0xa6
44
45#define CS_LO and_l(~0x00000020, &GPIO1_OUT)
46#define CS_HI or_l(0x00000020, &GPIO1_OUT)
47#define CLK_LO and_l(~0x00004000, &GPIO_OUT)
48#define CLK_HI or_l(0x00004000, &GPIO_OUT)
49#define DATA_LO and_l(~0x00002000, &GPIO_OUT)
50#define DATA_HI or_l(0x00002000, &GPIO_OUT)
51#define RS_LO and_l(~0x00008000, &GPIO_OUT)
52#define RS_HI or_l(0x00008000, &GPIO_OUT)
53
54/* cached settings values */
55static bool cached_invert = false;
56static bool cached_flip = false;
57static int cached_contrast = DEFAULT_REMOTE_CONTRAST_SETTING;
58
59bool remote_initialized = false;
60
61static void remote_tick(void);
62
63/* Standard low-level byte writer. Requires CLK high on entry */
64static inline void _write_byte(unsigned data)
65{
66 asm volatile (
67 "move.l (%[gpo0]), %%d0 \n" /* Get current state of data line */
68 "and.l %[dbit], %%d0 \n"
69 "beq.s 1f \n" /* and set it as previous-state bit */
70 "bset #8, %[data] \n"
71 "1: \n"
72 "move.l %[data], %%d0 \n" /* Compute the 'bit derivative', i.e. a value */
73 "lsr.l #1, %%d0 \n" /* with 1's where the data changes from the */
74 "eor.l %%d0, %[data] \n" /* previous state, and 0's where it doesn't */
75 "swap %[data] \n" /* Shift data to upper byte */
76 "lsl.l #8, %[data] \n"
77
78 "move.l %[cbit], %%d1 \n" /* Prepare mask for flipping CLK */
79 "or.l %[dbit], %%d1 \n" /* and DATA at once */
80
81 "lsl.l #1,%[data] \n" /* Shift out MSB */
82 "bcc.s 1f \n"
83 "eor.l %%d1, (%[gpo0]) \n" /* 1: Flip both CLK and DATA */
84 ".word 0x51fa \n" /* (trapf.w - shadow next insn) */
85 "1: \n"
86 "eor.l %[cbit], (%[gpo0]) \n" /* else flip CLK only */
87 "eor.l %[cbit], (%[gpo0]) \n" /* Flip CLK again */
88
89 "lsl.l #1,%[data] \n" /* ..unrolled.. */
90 "bcc.s 1f \n"
91 "eor.l %%d1, (%[gpo0]) \n"
92 ".word 0x51fa \n"
93 "1: \n"
94 "eor.l %[cbit], (%[gpo0]) \n"
95 "eor.l %[cbit], (%[gpo0]) \n"
96
97 "lsl.l #1,%[data] \n"
98 "bcc.s 1f \n"
99 "eor.l %%d1, (%[gpo0]) \n"
100 ".word 0x51fa \n"
101 "1: \n"
102 "eor.l %[cbit], (%[gpo0]) \n"
103 "eor.l %[cbit], (%[gpo0]) \n"
104
105 "lsl.l #1,%[data] \n"
106 "bcc.s 1f \n"
107 "eor.l %%d1, (%[gpo0]) \n"
108 ".word 0x51fa \n"
109 "1: \n"
110 "eor.l %[cbit], (%[gpo0]) \n"
111 "eor.l %[cbit], (%[gpo0]) \n"
112
113 "lsl.l #1,%[data] \n"
114 "bcc.s 1f \n"
115 "eor.l %%d1, (%[gpo0]) \n"
116 ".word 0x51fa \n"
117 "1: \n"
118 "eor.l %[cbit], (%[gpo0]) \n"
119 "eor.l %[cbit], (%[gpo0]) \n"
120
121 "lsl.l #1,%[data] \n"
122 "bcc.s 1f \n"
123 "eor.l %%d1, (%[gpo0]) \n"
124 ".word 0x51fa \n"
125 "1: \n"
126 "eor.l %[cbit], (%[gpo0]) \n"
127 "eor.l %[cbit], (%[gpo0]) \n"
128
129 "lsl.l #1,%[data] \n"
130 "bcc.s 1f \n"
131 "eor.l %%d1, (%[gpo0]) \n"
132 ".word 0x51fa \n"
133 "1: \n"
134 "eor.l %[cbit], (%[gpo0]) \n"
135 "eor.l %[cbit], (%[gpo0]) \n"
136
137 "lsl.l #1,%[data] \n"
138 "bcc.s 1f \n"
139 "eor.l %%d1, (%[gpo0]) \n"
140 ".word 0x51fa \n"
141 "1: \n"
142 "eor.l %[cbit], (%[gpo0]) \n"
143 "eor.l %[cbit], (%[gpo0]) \n"
144 : /* outputs */
145 [data]"+d"(data)
146 : /* inputs */
147 [gpo0]"a"(&GPIO_OUT),
148 [cbit]"d"(0x00004000),
149 [dbit]"d"(0x00002000)
150 : /* clobbers */
151 "d0", "d1"
152 );
153}
154
155/* Fast low-level byte writer. Don't use with high CPU clock.
156 * Requires CLK high on entry */
157static inline void _write_fast(unsigned data)
158{
159 asm volatile (
160 "move.w %%sr,%%d3 \n" /* Get current interrupt level */
161 "move.w #0x2700,%%sr \n" /* Disable interrupts */
162
163 "move.l (%[gpo0]), %%d0 \n" /* Get current state of data port */
164 "move.l %%d0, %%d1 \n"
165 "and.l %[dbit], %%d1 \n" /* Check current state of data line */
166 "beq.s 1f \n" /* and set it as previous-state bit */
167 "bset #8, %[data] \n"
168 "1: \n"
169 "move.l %[data], %%d1 \n" /* Compute the 'bit derivative', i.e. a value */
170 "lsr.l #1, %%d1 \n" /* with 1's where the data changes from the */
171 "eor.l %%d1, %[data] \n" /* previous state, and 0's where it doesn't */
172 "swap %[data] \n" /* Shift data to upper byte */
173 "lsl.l #8, %[data] \n"
174
175 "lsl.l #1,%[data] \n" /* Shift out MSB */
176 "bcc.s 1f \n"
177 "eor.l %[dbit], %%d0 \n" /* 1: Flip data bit */
178 "1: \n"
179 "eor.l %[cbit], %%d0 \n" /* Flip clock bit */
180 "move.l %%d0, (%[gpo0]) \n" /* Output new state */
181 "eor.l %[cbit], %%d0 \n" /* Flip clock bit */
182 "move.l %%d0, (%[gpo0]) \n" /* Output new state */
183
184 "lsl.l #1,%[data] \n" /* ..unrolled.. */
185 "bcc.s 1f \n"
186 "eor.l %[dbit], %%d0 \n"
187 "1: \n"
188 "eor.l %[cbit], %%d0 \n"
189 "move.l %%d0, (%[gpo0]) \n"
190 "eor.l %[cbit], %%d0 \n"
191 "move.l %%d0, (%[gpo0]) \n"
192
193 "lsl.l #1,%[data] \n"
194 "bcc.s 1f \n"
195 "eor.l %[dbit], %%d0 \n"
196 "1: \n"
197 "eor.l %[cbit], %%d0 \n"
198 "move.l %%d0, (%[gpo0]) \n"
199 "eor.l %[cbit], %%d0 \n"
200 "move.l %%d0, (%[gpo0]) \n"
201
202 "lsl.l #1,%[data] \n"
203 "bcc.s 1f \n"
204 "eor.l %[dbit], %%d0 \n"
205 "1: \n"
206 "eor.l %[cbit], %%d0 \n"
207 "move.l %%d0, (%[gpo0]) \n"
208 "eor.l %[cbit], %%d0 \n"
209 "move.l %%d0, (%[gpo0]) \n"
210
211 "lsl.l #1,%[data] \n"
212 "bcc.s 1f \n"
213 "eor.l %[dbit], %%d0 \n"
214 "1: \n"
215 "eor.l %[cbit], %%d0 \n"
216 "move.l %%d0, (%[gpo0]) \n"
217 "eor.l %[cbit], %%d0 \n"
218 "move.l %%d0, (%[gpo0]) \n"
219
220 "lsl.l #1,%[data] \n"
221 "bcc.s 1f \n"
222 "eor.l %[dbit], %%d0 \n"
223 "1: \n"
224 "eor.l %[cbit], %%d0 \n"
225 "move.l %%d0, (%[gpo0]) \n"
226 "eor.l %[cbit], %%d0 \n"
227 "move.l %%d0, (%[gpo0]) \n"
228
229 "lsl.l #1,%[data] \n"
230 "bcc.s 1f \n"
231 "eor.l %[dbit], %%d0 \n"
232 "1: \n"
233 "eor.l %[cbit], %%d0 \n"
234 "move.l %%d0, (%[gpo0]) \n"
235 "eor.l %[cbit], %%d0 \n"
236 "move.l %%d0, (%[gpo0]) \n"
237
238 "lsl.l #1,%[data] \n"
239 "bcc.s 1f \n"
240 "eor.l %[dbit], %%d0 \n"
241 "1: \n"
242 "eor.l %[cbit], %%d0 \n"
243 "move.l %%d0, (%[gpo0]) \n"
244 "eor.l %[cbit], %%d0 \n"
245 "move.l %%d0, (%[gpo0]) \n"
246
247 "move.w %%d3, %%sr \n" /* Restore interrupt level */
248 : /* outputs */
249 [data]"+d"(data)
250 : /* inputs */
251 [gpo0]"a"(&GPIO_OUT),
252 [cbit]"d"(0x00004000),
253 [dbit]"d"(0x00002000)
254 : /* clobbers */
255 "d0", "d1", "d2", "d3"
256 );
257}
258
259void lcd_remote_write_command(int cmd)
260{
261 RS_LO;
262 CS_LO;
263 _write_byte(cmd);
264 CS_HI;
265}
266
267void lcd_remote_write_command_ex(int cmd, int data)
268{
269 RS_LO;
270 CS_LO;
271 _write_byte(cmd);
272 _write_byte(data);
273 CS_HI;
274}
275
276void lcd_remote_write_data(const unsigned char* p_bytes, int count)
277{
278 const unsigned char *p_end = p_bytes + count;
279
280 RS_HI;
281 CS_LO;
282 if (cpu_frequency < 50000000)
283 {
284 while (p_bytes < p_end)
285 _write_fast(*p_bytes++);
286 }
287 else
288 {
289 while (p_bytes < p_end)
290 _write_byte(*p_bytes++);
291 }
292 CS_HI;
293}
294
295int lcd_remote_default_contrast(void)
296{
297 return DEFAULT_REMOTE_CONTRAST_SETTING;
298}
299
300void lcd_remote_powersave(bool on)
301{
302 if(remote_initialized) {
303 if (on)
304 lcd_remote_write_command(LCD_SET_POWER_SAVE | 1);
305 else
306 lcd_remote_write_command(LCD_SET_POWER_SAVE | 1);
307 }
308}
309
310void lcd_remote_set_contrast(int val)
311{
312 if (val < 0)
313 val = 0;
314 else if (val > 63)
315 val = 63;
316
317 cached_contrast = val;
318 if(remote_initialized)
319 lcd_remote_write_command_ex(LCD_SET_VOLUME, val);
320}
321
322bool remote_detect(void)
323{
324 return (GPIO_READ & 0x01000000)?false:true;
325}
326
327void lcd_remote_init_device(void)
328{
329 or_l(0x0000e000, &GPIO_OUT);
330 or_l(0x0000e000, &GPIO_ENABLE);
331 or_l(0x0000e000, &GPIO_FUNCTION);
332
333 or_l(0x00000020, &GPIO1_OUT);
334 or_l(0x00000020, &GPIO1_ENABLE);
335 or_l(0x00000020, &GPIO1_FUNCTION);
336
337 and_l(~0x01000000, &GPIO_OUT);
338 and_l(~0x01000000, &GPIO_ENABLE);
339 or_l(0x01000000, &GPIO_FUNCTION);
340
341 lcd_remote_clear_display();
342 tick_add_task(remote_tick);
343}
344
345void lcd_remote_on(void)
346{
347 CS_HI;
348 CLK_HI;
349 sleep(10);
350
351 lcd_remote_write_command(LCD_SET_DUTY_RATIO);
352 lcd_remote_write_command(0x70); /* 1/128 */
353
354 lcd_remote_write_command(LCD_OSC_ON);
355
356 lcd_remote_write_command(LCD_SELECT_DCDC | 2); /* DC/DC 5xboost */
357
358 lcd_remote_write_command(LCD_SELECT_RES | 7); /* Regulator resistor: 7.2 */
359
360 lcd_remote_write_command(LCD_SET_BIAS | 6); /* 1/11 */
361
362 lcd_remote_write_command(LCD_CONTROL_POWER | 7); /* All circuits ON */
363
364 sleep(30);
365
366 lcd_remote_write_command_ex(LCD_SET_GRAY | 0, 0x00);
367 lcd_remote_write_command_ex(LCD_SET_GRAY | 1, 0x00);
368 lcd_remote_write_command_ex(LCD_SET_GRAY | 2, 0x0c);
369 lcd_remote_write_command_ex(LCD_SET_GRAY | 3, 0x00);
370 lcd_remote_write_command_ex(LCD_SET_GRAY | 4, 0xcc);
371 lcd_remote_write_command_ex(LCD_SET_GRAY | 5, 0x00);
372 lcd_remote_write_command_ex(LCD_SET_GRAY | 6, 0xcc);
373 lcd_remote_write_command_ex(LCD_SET_GRAY | 7, 0x0c);
374
375 lcd_remote_write_command(LCD_SET_PWM_FRC | 6); /* 4FRC + 12PWM */
376
377 lcd_remote_write_command(LCD_DISPLAY_ON | 1); /* display on */
378
379 remote_initialized = true;
380
381 lcd_remote_set_flip(cached_flip);
382 lcd_remote_set_contrast(cached_contrast);
383 lcd_remote_set_invert_display(cached_invert);
384}
385
386void lcd_remote_off(void)
387{
388 remote_initialized = false;
389 CS_HI;
390 RS_HI;
391}
392
393void lcd_remote_poweroff(void)
394{
395 /* Set power save -> Power OFF (VDD - VSS) .. that's it */
396 if (remote_initialized && remote_detect())
397 lcd_remote_write_command(LCD_SET_POWER_SAVE | 1);
398}
399
400/* Monitor remote hotswap */
401static void remote_tick(void)
402{
403 static bool last_status = false;
404 static int countdown = 0;
405 static int init_delay = 0;
406 bool current_status;
407
408 current_status = remote_detect();
409
410 /* Only report when the status has changed */
411 if (current_status != last_status)
412 {
413 last_status = current_status;
414 countdown = current_status ? 20*HZ : 1;
415 }
416 else
417 {
418 /* Count down until it gets negative */
419 if (countdown >= 0)
420 countdown--;
421
422 if (current_status)
423 {
424 if (!(countdown % 8))
425 {
426 if (--init_delay <= 0)
427 {
428 queue_post(&remote_scroll_queue, REMOTE_INIT_LCD, 0);
429 init_delay = 6;
430 }
431 }
432 }
433 else
434 {
435 if (countdown == 0)
436 {
437 queue_post(&remote_scroll_queue, REMOTE_DEINIT_LCD, 0);
438 }
439 }
440 }
441}
442
443/* Update the display.
444 This must be called after all other LCD functions that change the display. */
445void lcd_remote_update(void) ICODE_ATTR;
446void lcd_remote_update(void)
447{
448 int y;
449 if(remote_initialized) {
450 for(y = 0;y < LCD_REMOTE_FBHEIGHT;y++) {
451 /* Copy display bitmap to hardware.
452 The COM48-COM63 lines are not connected so we have to skip
453 them. Further, the column address doesn't wrap, so we
454 have to update one page at a time. */
455 lcd_remote_write_command(LCD_SET_PAGE | (y>5?y+2:y));
456 lcd_remote_write_command_ex(LCD_SET_COLUMN | 0, 0);
457 lcd_remote_write_data((unsigned char *)lcd_remote_framebuffer[y],
458 LCD_REMOTE_WIDTH*2);
459 }
460 }
461}
462
463/* Update a fraction of the display. */
464void lcd_remote_update_rect(int, int, int, int) ICODE_ATTR;
465void lcd_remote_update_rect(int x, int y, int width, int height)
466{
467 if(remote_initialized) {
468 int ymax;
469
470 /* The Y coordinates have to work on even 8 pixel rows */
471 ymax = (y + height-1) >> 3;
472 y >>= 3;
473
474 if(x + width > LCD_REMOTE_WIDTH)
475 width = LCD_REMOTE_WIDTH - x;
476 if (width <= 0)
477 return; /* nothing left to do, 0 is harmful to lcd_write_data() */
478 if(ymax >= LCD_REMOTE_FBHEIGHT)
479 ymax = LCD_REMOTE_FBHEIGHT-1;
480
481 /* Copy specified rectangle bitmap to hardware
482 COM48-COM63 are not connected, so we need to skip those */
483 for (; y <= ymax; y++)
484 {
485 lcd_remote_write_command(LCD_SET_PAGE |
486 ((y > 5?y + 2:y) & 0xf));
487 lcd_remote_write_command_ex(LCD_SET_COLUMN | ((x >> 4) & 0xf),
488 x & 0xf);
489
490 lcd_remote_write_data (
491 (unsigned char *)&lcd_remote_framebuffer[y][x], width*2);
492 }
493 }
494}
495
496void lcd_remote_set_invert_display(bool yesno)
497{
498 cached_invert = yesno;
499 if(remote_initialized)
500 lcd_remote_write_command(LCD_REVERSE | yesno);
501}
502
503void lcd_remote_set_flip(bool yesno)
504{
505 cached_flip = yesno;
506 if(remote_initialized) {
507 if(yesno) {
508 lcd_remote_write_command(LCD_SELECT_ADC | 0);
509 lcd_remote_write_command(LCD_SELECT_SHL | 0);
510 lcd_remote_write_command_ex(LCD_SET_COM0, 16);
511 } else {
512 lcd_remote_write_command(LCD_SELECT_ADC | 1);
513 lcd_remote_write_command(LCD_SELECT_SHL | 8);
514 lcd_remote_write_command_ex(LCD_SET_COM0, 0);
515 }
516 }
517}
diff --git a/firmware/target/coldfire/iaudio/x5/pcf50606-x5.c b/firmware/target/coldfire/iaudio/x5/pcf50606-x5.c
deleted file mode 100644
index f8f6c1d675..0000000000
--- a/firmware/target/coldfire/iaudio/x5/pcf50606-x5.c
+++ /dev/null
@@ -1,127 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 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 "system.h"
21#include "kernel.h"
22#include "pcf50606.h"
23#include "button-target.h"
24#include "powermgmt.h"
25
26/* These voltages were determined by measuring the output of the PCF50606
27 on a running X5, and verified by disassembling the original firmware */
28static void set_voltages(void)
29{
30 static const unsigned char buf[4] =
31 {
32 0xf4, /* IOREGC = 2.9V, ON in all states */
33 0xf0, /* D1REGC = 2.5V, ON in all states */
34 0xf6, /* D2REGC = 3.1V, ON in all states */
35 0xf4, /* D3REGC = 2.9V, ON in all states */
36 };
37
38 pcf50606_write_multiple(0x23, buf, 4);
39}
40
41static void init_pmu_interrupts(void)
42{
43 /* inital data is interrupt masks */
44 unsigned char data[3] =
45 {
46 ~0x04, /* unmask ONKEY1S */
47 ~0x00,
48 ~0x06, /* unmask ACDREM, ACDINS */
49 };
50
51 /* make sure GPI0 interrupt is off before unmasking anything */
52 and_l(~0xf, &INTPRI5); /* INT32 - Priority 0 (Off) */
53
54 /* unmask the PMU interrupts we want to service */
55 pcf50606_write_multiple(0x05, data, 3);
56 /* clear INT1-3 as these are left set after standby */
57 pcf50606_read_multiple(0x02, data, 3);
58
59 /* Set to read pcf50606 INT but keep GPI0 off until init completes */
60 and_l(~0x00000001, &GPIO_ENABLE);
61 or_l(0x00000001, &GPIO_FUNCTION);
62 or_l(0x00000100, &GPIO_INT_EN); /* GPI0 H-L */
63}
64
65static inline void enable_pmu_interrupts(void)
66{
67 /* clear pending GPI0 interrupts first or it may miss the first
68 H-L transition */
69 or_l(0x00000100, &GPIO_INT_CLEAR);
70 or_l(0x3, &INTPRI5); /* INT32 - Priority 3 */
71}
72
73void pcf50606_init(void)
74{
75 pcf50606_i2c_init();
76
77 /* initialize pmu interrupts but don't service them yet */
78 init_pmu_interrupts();
79 set_voltages();
80
81 pcf50606_write(0x39, 0x00); /* GPOOD0 = green led OFF */
82 pcf50606_write(0x3a, 0x00); /* GPOOD1 = red led OFF */
83
84 /* Accessory detect */
85 pcf50606_write(0x33, 0x8c); /* ACDAPE=1, THRSHLD=2.20V */
86
87 /* allow GPI0 interrupts from PMU now */
88 enable_pmu_interrupts();
89}
90
91void pcf50606_reset_timeout(void)
92{
93 int level = set_irq_level(HIGHEST_IRQ_LEVEL);
94 pcf50606_write(0x08, pcf50606_read(0x08) | 0x02); /* OOCC1 - TOTRST=1 */
95 set_irq_level(level);
96}
97
98/* Handles interrupts generated by the pcf50606 */
99void GPI0(void) __attribute__ ((interrupt_handler, section(".text")));
100void GPI0(void)
101{
102 unsigned char data[3]; /* 0 = INT1, 1 = INT2, 2 = INT3 */
103
104 /* Clear pending GPI0 interrupts */
105 or_l(0x00000100, &GPIO_INT_CLEAR);
106
107 /* clear pending interrupts from pcf50606 */
108 pcf50606_read_multiple(0x02, data, 3);
109
110 if (data[0] & 0x04)
111 {
112 /* ONKEY1S */
113 if (GPIO_READ & 0x02000000)
114 sys_poweroff(); /* main ONKEY */
115 else
116 pcf50606_reset_timeout(); /* remote ONKEY */
117 }
118
119 if (data[2] & 0x06)
120 {
121 /* ACDINS/ACDREM */
122 /* Check if main buttons should be actually be scanned or not
123 - bias towards "yes" out of paranoia. */
124 button_enable_scan((data[2] & 0x02) != 0 ||
125 (pcf50606_read(0x33) & 0x01) != 0);
126 }
127}
diff --git a/firmware/target/coldfire/iaudio/x5/system-x5.c b/firmware/target/coldfire/iaudio/x5/system-x5.c
deleted file mode 100644
index 30a4f6e71b..0000000000
--- a/firmware/target/coldfire/iaudio/x5/system-x5.c
+++ /dev/null
@@ -1,90 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 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 "kernel.h"
22#include "system.h"
23#include "power.h"
24#include "timer.h"
25#include "pcf50606.h"
26
27#define MAX_REFRESH_TIMER 59
28#define NORMAL_REFRESH_TIMER 21
29#define DEFAULT_REFRESH_TIMER 4
30
31#define RECALC_DELAYS(f) \
32 pcf50606_i2c_recalc_delay(f)
33
34void set_cpu_frequency (long) __attribute__ ((section (".icode")));
35void set_cpu_frequency(long frequency)
36{
37 switch(frequency)
38 {
39 case CPUFREQ_MAX:
40 DCR = (0x8200 | DEFAULT_REFRESH_TIMER);
41 /* Refresh timer for bypass frequency */
42 PLLCR &= ~1; /* Bypass mode */
43 timers_adjust_prescale(CPUFREQ_DEFAULT_MULT, false);
44 RECALC_DELAYS(CPUFREQ_MAX);
45 PLLCR = 0x03042045 | (PLLCR & 0x70C00000);
46 CSCR0 = 0x00001180; /* Flash: 4 wait states */
47 CSCR1 = 0x00000980; /* LCD: 2 wait states */
48 while(!(PLLCR & 0x80000000)) {}; /* Wait until the PLL has locked.
49 This may take up to 10ms! */
50 timers_adjust_prescale(CPUFREQ_MAX_MULT, true);
51 DCR = (0x8200 | MAX_REFRESH_TIMER); /* Refresh timer */
52 cpu_frequency = CPUFREQ_MAX;
53 IDECONFIG1 = 0x106000 | (5 << 10); /* BUFEN2 enable + CS2Pre/CS2Post */
54 IDECONFIG2 = 0x40000 | (1 << 8); /* TA enable + CS2wait */
55 break;
56
57 case CPUFREQ_NORMAL:
58 DCR = (DCR & ~0x01ff) | DEFAULT_REFRESH_TIMER;
59 /* Refresh timer for bypass frequency */
60 PLLCR &= ~1; /* Bypass mode */
61 timers_adjust_prescale(CPUFREQ_DEFAULT_MULT, false);
62 RECALC_DELAYS(CPUFREQ_NORMAL);
63 PLLCR = 0x06030045 | (PLLCR & 0x70C00000);
64 CSCR0 = 0x00000580; /* Flash: 1 wait state */
65 CSCR1 = 0x00000180; /* LCD: 0 wait states */
66 while(!(PLLCR & 0x80000000)) {}; /* Wait until the PLL has locked.
67 This may take up to 10ms! */
68 timers_adjust_prescale(CPUFREQ_NORMAL_MULT, true);
69 DCR = (0x8000 | NORMAL_REFRESH_TIMER); /* Refresh timer */
70 cpu_frequency = CPUFREQ_NORMAL;
71 IDECONFIG1 = 0x106000 | (5 << 10); /* BUFEN2 enable + CS2Pre/CS2Post */
72 IDECONFIG2 = 0x40000 | (0 << 8); /* TA enable + CS2wait */
73 break;
74 default:
75 DCR = (DCR & ~0x01ff) | DEFAULT_REFRESH_TIMER;
76 /* Refresh timer for bypass frequency */
77 PLLCR &= ~1; /* Bypass mode */
78 timers_adjust_prescale(CPUFREQ_DEFAULT_MULT, true);
79 RECALC_DELAYS(CPUFREQ_DEFAULT);
80 /* Power down PLL, but keep CLSEL and CRSEL */
81 PLLCR = 0x00000200 | (PLLCR & 0x70C00000);
82 CSCR0 = 0x00000180; /* Flash: 0 wait states */
83 CSCR1 = 0x00000180; /* LCD: 0 wait states */
84 DCR = (0x8000 | DEFAULT_REFRESH_TIMER); /* Refresh timer */
85 cpu_frequency = CPUFREQ_DEFAULT;
86 IDECONFIG1 = 0x106000 | (1 << 10); /* BUFEN2 enable + CS2Pre/CS2Post */
87 IDECONFIG2 = 0x40000 | (0 << 8); /* TA enable + CS2wait */
88 break;
89 }
90}
diff --git a/firmware/target/coldfire/iaudio/x5/usb-x5.c b/firmware/target/coldfire/iaudio/x5/usb-x5.c
deleted file mode 100644
index 3bd1a7a458..0000000000
--- a/firmware/target/coldfire/iaudio/x5/usb-x5.c
+++ /dev/null
@@ -1,45 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 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 <stdbool.h>
21#include "cpu.h"
22#include "system.h"
23
24void usb_init_device(void)
25{
26 or_l(0x00800010, &GPIO_OUT); /* RESET deasserted, VBUS powered */
27 or_l(0x00800010, &GPIO_ENABLE);
28 or_l(0x00800010, &GPIO_FUNCTION);
29
30 or_l(0x00800000, &GPIO1_FUNCTION); /* USB detect */
31}
32
33bool usb_detect(void)
34{
35 return (GPIO1_READ & 0x00800000)?true:false;
36}
37
38void usb_enable(bool on)
39{
40 if(on) {
41 or_l(0x00000008, &GPIO1_OUT);
42 } else {
43 and_l(~0x00000008, &GPIO1_OUT);
44 }
45}