diff options
Diffstat (limited to 'firmware/target/coldfire/iriver/lcd-remote-as-iriver.S')
-rw-r--r-- | firmware/target/coldfire/iriver/lcd-remote-as-iriver.S | 302 |
1 files changed, 302 insertions, 0 deletions
diff --git a/firmware/target/coldfire/iriver/lcd-remote-as-iriver.S b/firmware/target/coldfire/iriver/lcd-remote-as-iriver.S new file mode 100644 index 0000000000..0325e5176c --- /dev/null +++ b/firmware/target/coldfire/iriver/lcd-remote-as-iriver.S | |||
@@ -0,0 +1,302 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2008 by Jens Arnold | ||
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 | |||
20 | #include "config.h" | ||
21 | |||
22 | #define RS_MASK 0x00010000 | ||
23 | #define CLOCK_MASK 0x10000000 | ||
24 | #define GPIO_OUT_ADDR 0x80000004 | ||
25 | |||
26 | #define CS_MASK 0x00000004 /* used in moveq.l */ | ||
27 | #define DATA_MASK 0x00040000 | ||
28 | #define GPIO1_OUT_ADDR 0x800000b4 | ||
29 | |||
30 | #define CS_TIMEOUT 10 /* HZ/10 */ | ||
31 | |||
32 | .extern cpu_frequency /* Global variable from system.c */ | ||
33 | .extern remote_byte_delay /* Global variable from lcd-remote-iriver.c */ | ||
34 | .extern remote_cs_countdown /* Global variable from lcd-remote-iriver.c */ | ||
35 | |||
36 | .section .icode,"ax",@progbits | ||
37 | |||
38 | /* Output 8 bits to the LCD. Instruction order is devised to maximize the | ||
39 | * delay between changing the data line and the CLK L->H transition, which | ||
40 | * makes the LCD controller sample DATA. | ||
41 | * Requires CLK = 0 on entry. | ||
42 | * | ||
43 | * Custom calling convention: | ||
44 | * %a0 - GPIO_OUT_ADDR | ||
45 | * %a1 - GPIO1_OUT_ADDR | ||
46 | * %d4 - data byte | ||
47 | * %d6 - DATA_MASK | ||
48 | * Clobbers: | ||
49 | * %d0..%d4 | ||
50 | */ | ||
51 | #ifdef HAVE_REMOTE_LCD_TICKING | ||
52 | .write_byte_delayed: | ||
53 | move.l remote_byte_delay, %d0 | ||
54 | 1: | ||
55 | subq.l #1, %d0 | ||
56 | bne.s 1b | ||
57 | #endif | ||
58 | |||
59 | .write_byte: | ||
60 | move.w %sr, %d3 /* Get current interrupt level */ | ||
61 | move.w #0x2700, %sr /* Disable interrupts */ | ||
62 | |||
63 | move.l (%a1), %d0 /* Get current state of data port */ | ||
64 | move.l %d0, %d1 | ||
65 | and.l %d6, %d1 /* Check current state of data line */ | ||
66 | beq.s 1f /* and set it as previous-state bit */ | ||
67 | bset #8, %d4 | ||
68 | 1: | ||
69 | move.l %d4, %d1 /* Compute the 'bit derivative', i.e. a value */ | ||
70 | lsr.l #1, %d1 /* with 1's where the data changes from the */ | ||
71 | eor.l %d1, %d4 /* previous state, and 0's where it doesn't */ | ||
72 | swap %d4 /* Shift data to upper byte */ | ||
73 | lsl.l #8, %d4 | ||
74 | |||
75 | move.l (%a0),%d1 /* Get current state of clock port */ | ||
76 | move.l %d1, %d2 /* Precalculate opposite state of clock line */ | ||
77 | eor.l #CLOCK_MASK, %d2 | ||
78 | |||
79 | lsl.l #1, %d4 /* Invert data line for bit7 ? */ | ||
80 | bcc.s 1f /* no: skip */ | ||
81 | eor.l %d6, %d0 /* invert data bit */ | ||
82 | move.l %d0, (%a1) /* output data bit7 */ | ||
83 | nop | ||
84 | 1: | ||
85 | |||
86 | .macro bit_out | ||
87 | lsl.l #1, %d4 /* Invert data line for bit6 ? */ | ||
88 | bcc.s 1f /* no: skip */ | ||
89 | eor.l %d6, %d0 /* Invert data bit */ | ||
90 | move.l %d2, (%a0) /* Bit7: set CLK = 1 */ | ||
91 | move.l %d1, (%a0) /* set CLK = 0 */ | ||
92 | move.l %d0, (%a1) /* Output data bit6 */ | ||
93 | bra.s 2f /* slower than trapf.l - required here */ | ||
94 | 1: /* else */ | ||
95 | move.l %d2, (%a0) /* Bit7: set CLK = 1 */ | ||
96 | move.l %d1, (%a0) /* set CLK = 0 */ | ||
97 | 2: | ||
98 | .endm | ||
99 | bit_out | ||
100 | bit_out | ||
101 | bit_out | ||
102 | bit_out | ||
103 | bit_out | ||
104 | bit_out | ||
105 | bit_out | ||
106 | |||
107 | nop /* Let data line settle */ | ||
108 | move.l %d2, (%a0) /* Bit0: Set CLK = 1 */ | ||
109 | move.l %d1, (%a0) /* Set CLK = 0 */ | ||
110 | |||
111 | move.w %d3, %sr /* Restore interrupt level */ | ||
112 | rts | ||
113 | |||
114 | /* Output 8 bits to the LCD as fast as possible. Use only at < 60MHz. | ||
115 | * | ||
116 | * Custom calling convention: | ||
117 | * %a0 - GPIO_OUT_ADDR | ||
118 | * %a1 - GPIO1_OUT_ADDR | ||
119 | * %d4 - data word | ||
120 | * %d6 - DATA_MASK | ||
121 | * Clobbers: | ||
122 | * %d0..%d4 | ||
123 | */ | ||
124 | #ifdef HAVE_REMOTE_LCD_TICKING | ||
125 | .write_byte_fast_delayed: | ||
126 | move.l remote_byte_delay, %d0 | ||
127 | 1: | ||
128 | subq.l #1, %d0 | ||
129 | bne.s 1b | ||
130 | #endif | ||
131 | |||
132 | .write_byte_fast: | ||
133 | move.w %sr, %d3 /* Get current interrupt level */ | ||
134 | move.w #0x2700,%sr /* Disable interrupts */ | ||
135 | |||
136 | move.l (%a1), %d0 /* Get current state of data port */ | ||
137 | move.l %d0, %d1 | ||
138 | and.l %d6, %d1 /* Check current state of data line */ | ||
139 | beq.s 1f /* and set it as previous-state bit */ | ||
140 | bset #8, %d4 | ||
141 | 1: | ||
142 | move.l %d4, %d1 /* Compute the 'bit derivative', i.e. a value */ | ||
143 | lsr.l #1, %d1 /* with 1's where the data changes from the */ | ||
144 | eor.l %d1, %d4 /* previous state, and 0's where it doesn't */ | ||
145 | swap %d4 /* Shift data to upper byte */ | ||
146 | lsl.l #8, %d4 | ||
147 | |||
148 | move.l (%a0), %d1 /* Get current state of clock port */ | ||
149 | move.l %d1, %d2 /* Precalculate opposite state of clock line */ | ||
150 | eor.l #CLOCK_MASK, %d2 | ||
151 | |||
152 | .macro bit_out_fast | ||
153 | lsl.l #1,%d4 /* Shift out MSB */ | ||
154 | bcc.s 1f | ||
155 | eor.l %d6, %d0 /* 1: flip data bit */ | ||
156 | move.l %d0, (%a1) /* and output new DATA state */ | ||
157 | 1: | ||
158 | move.l %d2, (%a0) /* Set CLK */ | ||
159 | move.l %d1, (%a0) /* Reset CLK */ | ||
160 | .endm | ||
161 | bit_out_fast | ||
162 | bit_out_fast | ||
163 | bit_out_fast | ||
164 | bit_out_fast | ||
165 | bit_out_fast | ||
166 | bit_out_fast | ||
167 | bit_out_fast | ||
168 | bit_out_fast | ||
169 | |||
170 | move.w %d3, %sr /* Restore interrupt level */ | ||
171 | rts | ||
172 | |||
173 | |||
174 | .global lcd_remote_write_command | ||
175 | .type lcd_remote_write_command, @function | ||
176 | |||
177 | lcd_remote_write_command: | ||
178 | lea.l (-4*4, %sp), %sp | ||
179 | movem.l %d2-%d4/%d6, (%sp) | ||
180 | |||
181 | move.l (4*4+4, %sp), %d4 /* cmd */ | ||
182 | |||
183 | lea.l GPIO_OUT_ADDR, %a0 | ||
184 | lea.l GPIO1_OUT_ADDR, %a1 | ||
185 | move.l #DATA_MASK, %d6 | ||
186 | |||
187 | clr.l remote_cs_countdown | ||
188 | |||
189 | move.l #~RS_MASK, %d0 | ||
190 | and.l %d0, (%a0) | ||
191 | moveq.l #~CS_MASK, %d0 | ||
192 | and.l %d0, (%a1) | ||
193 | |||
194 | #ifdef HAVE_REMOTE_LCD_TICKING | ||
195 | tst.l remote_byte_delay | ||
196 | ble.s 1f | ||
197 | bsr.w .write_byte_delayed | ||
198 | bra.s 2f | ||
199 | 1: | ||
200 | #endif | ||
201 | bsr.w .write_byte | ||
202 | 2: | ||
203 | |||
204 | moveq.l #CS_TIMEOUT, %d0 | ||
205 | move.l %d0, remote_cs_countdown | ||
206 | |||
207 | movem.l (%sp), %d2-%d4/%d6 | ||
208 | lea.l (4*4, %sp), %sp | ||
209 | rts | ||
210 | |||
211 | |||
212 | .global lcd_remote_write_command_ex | ||
213 | .type lcd_remote_write_command_ex, @function | ||
214 | |||
215 | lcd_remote_write_command_ex: | ||
216 | lea.l (-4*4, %sp), %sp | ||
217 | movem.l %d2-%d4/%d6, (%sp) | ||
218 | |||
219 | lea.l GPIO_OUT_ADDR, %a0 | ||
220 | lea.l GPIO1_OUT_ADDR, %a1 | ||
221 | move.l #DATA_MASK, %d6 | ||
222 | |||
223 | clr.l remote_cs_countdown | ||
224 | |||
225 | move.l #~RS_MASK, %d0 | ||
226 | and.l %d0, (%a0) | ||
227 | moveq.l #~CS_MASK, %d0 | ||
228 | and.l %d0, (%a1) | ||
229 | |||
230 | move.l (4*4+4, %sp), %d4 | ||
231 | |||
232 | #ifdef HAVE_REMOTE_LCD_TICKING | ||
233 | tst.l remote_byte_delay | ||
234 | ble.s 1f | ||
235 | bsr.w .write_byte_delayed | ||
236 | move.l (4*4+8, %sp), %d4 | ||
237 | bsr.w .write_byte_delayed | ||
238 | bra.s 2f | ||
239 | 1: | ||
240 | #endif | ||
241 | bsr.w .write_byte | ||
242 | move.l (4*4+8, %sp), %d4 | ||
243 | bsr.w .write_byte | ||
244 | 2: | ||
245 | |||
246 | moveq.l #CS_TIMEOUT, %d0 | ||
247 | move.l %d0, remote_cs_countdown | ||
248 | |||
249 | movem.l (%sp), %d2-%d4/%d6 | ||
250 | lea.l (4*4, %sp), %sp | ||
251 | rts | ||
252 | |||
253 | |||
254 | .global lcd_remote_write_data | ||
255 | .type lcd_remote_write_data, @function | ||
256 | |||
257 | lcd_remote_write_data: | ||
258 | lea.l (-7*4, %sp), %sp | ||
259 | movem.l %d2-%d6/%a2-%a3, (%sp) | ||
260 | |||
261 | move.l (7*4+4, %sp), %a2 /* p_bytes */ | ||
262 | move.l (7*4+8, %sp), %d5 /* count */ | ||
263 | |||
264 | lea.l GPIO_OUT_ADDR, %a0 | ||
265 | lea.l GPIO1_OUT_ADDR, %a1 | ||
266 | move.l #DATA_MASK, %d6 | ||
267 | |||
268 | lea.l .write_byte, %a3 | ||
269 | move.l cpu_frequency, %d0 | ||
270 | cmp.l #60000000, %d0 | ||
271 | bhi.b 1f | ||
272 | lea.l .write_byte_fast, %a3 | ||
273 | 1: | ||
274 | |||
275 | #ifdef HAVE_REMOTE_LCD_TICKING | ||
276 | tst.l remote_byte_delay | ||
277 | ble.s 1f | ||
278 | moveq.l #(.write_byte_delayed - .write_byte), %d0 | ||
279 | add.l %d0, %a3 | ||
280 | 1: | ||
281 | #endif | ||
282 | |||
283 | clr.l remote_cs_countdown | ||
284 | |||
285 | move.l #RS_MASK, %d0 | ||
286 | or.l %d0, (%a0) | ||
287 | moveq.l #~CS_MASK, %d0 | ||
288 | and.l %d0, (%a1) | ||
289 | |||
290 | .wd_loop: | ||
291 | clr.l %d4 | ||
292 | move.b (%a2)+, %d4 | ||
293 | jsr (%a3) | ||
294 | subq.l #1, %d5 | ||
295 | bne.s .wd_loop | ||
296 | |||
297 | moveq.l #CS_TIMEOUT, %d0 | ||
298 | move.l %d0, remote_cs_countdown | ||
299 | |||
300 | movem.l (%sp), %d2-%d6/%a2-%a3 | ||
301 | lea.l (7*4, %sp), %sp | ||
302 | rts | ||