1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by Alan Korr & Nick Robinson
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
29 #include "backlight.h"
35 #if CONFIG_CPU == IMX31L
36 #include "serial-imx31.h"
39 #if CONFIG_CPU == SH7034
41 /* FIX: this doesn't work on iRiver or iPod yet */
42 /* iFP7xx has no remote */
44 /* Received byte identifiers */
52 void serial_setup (void)
54 /* Set PB10 function to serial Rx */
55 PBCR1
= (PBCR1
& 0xffcf) | 0x0020;
59 BRR1
= (FREQ
/(32*9600))-1;
60 and_b(0, &SSR1
); /* The status bits must be read before they are cleared,
61 so we do an AND operation */
63 /* Let the hardware settle. The serial port needs to wait "at least
64 the interval required to transmit or receive one bit" before it
68 SCR1
= 0x10; /* Enable the receiver, no interrupt */
85 void tx_writec(unsigned char c
)
91 unsigned char rx_readc(void)
94 /* Read byte and clear the Rx Full bit */
96 and_b(~SCI_RDRF
, &SSR1
);
101 /* This function returns the received remote control code only if it is
102 received without errors before or after the reception.
103 It therefore returns the received code on the second call after the
104 code has been received. */
105 int remote_control_rx(void)
107 static int last_valid_button
= BUTTON_NONE
;
108 static int last_was_error
= false;
110 int ret
= BUTTON_NONE
;
112 /* Errors? Just clear'em. The receiver stops if we don't */
113 if(SSR1
& (SCI_ORER
| SCI_FER
| SCI_PER
)) {
114 and_b(~(SCI_ORER
| SCI_FER
| SCI_PER
), &SSR1
);
115 last_valid_button
= BUTTON_NONE
;
116 last_was_error
= true;
125 last_valid_button
= BUTTON_NONE
;
133 last_valid_button
= BUTTON_RC_STOP
;
137 last_valid_button
= BUTTON_RC_PLAY
;
141 last_valid_button
= BUTTON_RC_VOL_UP
;
145 last_valid_button
= BUTTON_RC_VOL_DOWN
;
149 last_valid_button
= BUTTON_RC_LEFT
;
153 last_valid_button
= BUTTON_RC_RIGHT
;
157 last_valid_button
= BUTTON_NONE
;
164 /* This means that a valid remote control character was received
165 the last time we were called, with no receiver errors either before
166 or after. Then we can assume that there really is a remote control
167 attached, and return the button code. */
168 ret
= last_valid_button
;
169 last_valid_button
= BUTTON_NONE
;
172 last_was_error
= false;
177 #elif defined(CPU_COLDFIRE)
179 void serial_setup (void)
181 UCR0
= 0x30; /* Reset transmitter */
182 UCSR0
= 0xdd; /* Timer mode */
184 UCR0
= 0x10; /* Reset pointer */
185 UMR0
= 0x13; /* No parity, 8 bits */
186 UMR0
= 0x07; /* 1 stop bit */
188 UCR0
= 0x04; /* Tx enable */
205 void tx_writec(unsigned char c
)
210 #elif (CONFIG_CPU == IMX31L)
212 void serial_setup(void)
214 #ifdef UART_INT /*enable UART Interrupts */
215 UCR1_1
|= (EUARTUCR1_TRDYEN
| EUARTUCR1_RRDYEN
| EUARTUCR1_TXMPTYEN
);
216 UCR4_1
|= (EUARTUCR4_TCEN
);
217 #else /*disable UART Interrupts*/
218 UCR1_1
&= ~(EUARTUCR1_TRDYEN
| EUARTUCR1_RRDYEN
| EUARTUCR1_TXMPTYEN
);
219 UCR4_1
&= ~(EUARTUCR4_TCEN
);
221 UCR1_1
|= EUARTUCR1_UARTEN
;
222 UCR2_1
|= (EUARTUCR2_TXEN
| EUARTUCR2_RXEN
| EUARTUCR2_IRTS
);
224 /* Tx,Rx Interrupt Trigger levels, Disable for now*/
225 /*UFCR1 |= (UFCR1_TXTL_32 | UFCR1_RXTL_32);*/
230 if((UTS1
& EUARTUTS_TXEMPTY
))
236 /*Not ready...After first Rx, UTS1 & UTS1_RXEMPTY
237 keeps returning true*/
240 if(!(UTS1
& EUARTUTS_RXEMPTY
))
246 void tx_writec(unsigned char c
)
251 #elif defined(IPOD_ACCESSORY_PROTOCOL)
252 static int autobaud
= 0;
253 void serial_setup (void)
257 #if (MODEL_NUMBER == 3) || (MODEL_NUMBER == 8)
259 /* Route the Tx/Rx pins. 4G Ipod??? */
260 outl(0x70000018, inl(0x70000018) & ~0xc00);
261 #elif (MODEL_NUMBER == 4) || (MODEL_NUMBER == 5)
263 /* Route the Tx/Rx pins. 5G Ipod */
264 (*(volatile unsigned long *)(0x7000008C)) &= ~0x0C;
265 GPO32_ENABLE
&= ~0x0C;
268 DEV_EN
= DEV_EN
| DEV_SER0
;
269 CPU_HI_INT_DIS
= SER0_MASK
;
275 SER0_LCR
= 0x80; /* Divisor latch enable */
277 SER0_LCR
= 0x03; /* Divisor latch disable, 8-N-1 */
280 SER0_FCR
= 0x07; /* Tx+Rx FIFO reset and FIFO enable */
282 CPU_INT_EN
|= HI_MASK
;
283 CPU_HI_INT_EN
|= SER0_MASK
;
289 void serial_bitrate(int rate
)
294 SER0_LCR
= 0x80; /* Divisor latch enable */
295 SER0_DLL
= 0x0D; /* 24000000/13/16 = 115384 baud */
296 SER0_LCR
= 0x03; /* Divisor latch disable, 8-N-1 */
301 SER0_LCR
= 0x80; /* Divisor latch enable */
302 SER0_DLL
= 24000000L / rate
/ 16;
303 SER0_LCR
= 0x03; /* Divisor latch disable, 8-N-1 */
308 if((SER0_LSR
& 0x20))
322 void tx_writec(unsigned char c
)
327 unsigned char rx_readc(void)
329 return (SER0_RBR
& 0xFF);
334 static int badbaud
= 0;
335 static bool newpkt
= true;
341 if (newpkt
&& autobaud
> 0)
351 SER0_LCR
= 0x80; /* Divisor latch enable */
352 SER0_DLL
= 0x4E; /* 24000000/78/16 = 19230 baud */
353 SER0_LCR
= 0x03; /* Divisor latch disable, 8-N-1 */
357 SER0_LCR
= 0x80; /* Divisor latch enable */
358 SER0_DLL
= 0x9C; /* 24000000/156/16 = 9615 baud */
359 SER0_LCR
= 0x03; /* Divisor latch disable, 8-N-1 */
364 if (badbaud
>= 6) /* Switch baud detection mode */
367 SER0_LCR
= 0x80; /* Divisor latch enable */
368 SER0_DLL
= 0x0D; /* 24000000/13/16 = 115384 baud */
369 SER0_LCR
= 0x03; /* Divisor latch disable, 8-N-1 */
372 SER0_LCR
= 0x80; /* Divisor latch enable */
373 SER0_DLL
= 0x1A; /* 24000000/26/16 = 57692 baud */
374 SER0_LCR
= 0x03; /* Divisor latch disable, 8-N-1 */
385 SER0_LCR
= 0x80; /* Divisor latch enable */
386 SER0_DLL
= 0x1A; /* 24000000/26/16 = 57692 baud */
387 SER0_LCR
= 0x03; /* Divisor latch disable, 8-N-1 */
391 SER0_LCR
= 0x80; /* Divisor latch enable */
392 SER0_DLL
= 0x27; /* 24000000/39/16 = 38461 baud */
393 SER0_LCR
= 0x03; /* Divisor latch disable, 8-N-1 */
397 SER0_LCR
= 0x80; /* Divisor latch enable */
398 SER0_DLL
= 0x4E; /* 24000000/78/16 = 19230 baud */
399 SER0_LCR
= 0x03; /* Divisor latch disable, 8-N-1 */
404 if (badbaud
>= 6) /* Switch baud detection */
407 SER0_LCR
= 0x80; /* Divisor latch enable */
408 SER0_DLL
= 0x1A; /* 24000000/26/16 = 57692 baud */
409 SER0_LCR
= 0x03; /* Divisor latch disable, 8-N-1 */
412 SER0_LCR
= 0x80; /* Divisor latch enable */
413 SER0_DLL
= 0x0D; /* 24000000/13/16 = 115384 baud */
414 SER0_LCR
= 0x03; /* Divisor latch disable, 8-N-1 */
420 bool pkt
= iap_getc(temp
);
421 if(newpkt
== true && pkt
== false)
422 autobaud
= 0; /* Found good baud */
429 void dprintf(const char * str
, ... )
431 char dprintfbuff
[256];
438 vsnprintf(ptr
,sizeof(dprintfbuff
),str
,ap
);
441 serial_tx((unsigned char *)ptr
);
444 void serial_tx(const unsigned char * buf
)