1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2009 by Bob Cousins
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 ****************************************************************************/
22 /* Include Standard files */
34 #include "system-target.h"
35 #include "uart-s3c2440.h"
37 #define MAX_PRINTF_BUF 1024
39 /****************************************************************************
41 ****************************************************************************/
42 void serial_setup (void)
45 uart_init_device(DEBUG_UART_PORT
);
50 if (uart_tx_ready (DEBUG_UART_PORT
))
56 void tx_writec(unsigned char c
)
58 uart_send_byte (DEBUG_UART_PORT
, c
);
62 static int uart_push(void *user_data
, unsigned char ch
)
66 uart_send_byte(DEBUG_UART_PORT
, ch
);
68 uart_send_byte(DEBUG_UART_PORT
, '\r');
72 /****************************************************************************
73 * General purpose debug function
74 ****************************************************************************/
75 void uart_printf (const char *format
, ...)
77 static bool debug_uart_init
= false;
82 uart_init_device(DEBUG_UART_PORT
);
83 debug_uart_init
= true;
87 vuprintf(uart_push
, NULL
, format
, ap
);
91 /****************************************************************************
92 * Device level functions specific to S3C2440
93 *****************************************************************************/
101 bool uart_init_device (unsigned dev
)
103 /* set GPIOs, clock enable? etc */
109 S3C2440_GPIO_CONFIG (GPHCON
, 2, GPIO_FUNCTION
);
110 S3C2440_GPIO_CONFIG (GPHCON
, 3, GPIO_FUNCTION
);
111 S3C2440_GPIO_PULLUP (GPHUP
, 2, GPIO_PULLUP_DISABLE
);
112 S3C2440_GPIO_PULLUP (GPHUP
, 3, GPIO_PULLUP_DISABLE
);
117 S3C2440_GPIO_CONFIG (GPHCON
, 4, GPIO_FUNCTION
);
118 S3C2440_GPIO_CONFIG (GPHCON
, 5, GPIO_FUNCTION
);
119 S3C2440_GPIO_PULLUP (GPHUP
, 4, GPIO_PULLUP_DISABLE
);
120 S3C2440_GPIO_PULLUP (GPHUP
, 5, GPIO_PULLUP_DISABLE
);
125 S3C2440_GPIO_CONFIG (GPHCON
, 6, GPIO_FUNCTION
);
126 S3C2440_GPIO_CONFIG (GPHCON
, 7, GPIO_FUNCTION
);
127 S3C2440_GPIO_PULLUP (GPHUP
, 6, GPIO_PULLUP_DISABLE
);
128 S3C2440_GPIO_PULLUP (GPHUP
, 7, GPIO_PULLUP_DISABLE
);
135 /* set a default configuration */
136 uart_config (dev
, 115200, 8, UART_NO_PARITY
, UART_1_STOP_BIT
);
140 bool uart_config (unsigned dev
, unsigned speed
, unsigned num_bits
,
141 unsigned parity
, unsigned stop_bits
)
146 ULCON0
= (parity
<< 3) + (stop_bits
<< 2) + (num_bits
-5);
147 UCON0
= (1 << 2) + (1 << 0); /* enable TX, RX, use PCLK */
148 UBRDIV0
= PCLK
/ (speed
*16);
152 ULCON1
= (parity
<< 3) + (stop_bits
<< 2) + (num_bits
-5);
153 UCON1
= (1 << 2) + (1 << 0); /* enable TX, RX, use PCLK */
154 UBRDIV1
= PCLK
/ (speed
*16);
158 ULCON2
= (parity
<< 3) + (stop_bits
<< 2) + (num_bits
-5);
159 UCON2
= (1 << 2) + (1 << 0); /* enable TX, RX, use PCLK */
160 UBRDIV2
= PCLK
/ (speed
*16);
168 bool uart_tx_ready (unsigned dev
)
170 /* test if transmit buffer empty */
195 bool uart_send_byte (unsigned dev
, char ch
)
197 /* wait for transmit buffer empty */
198 while (!uart_tx_ready(dev
))
219 bool uart_rx_ready (unsigned dev
)
221 /* test receive buffer data ready */
246 char uart_read_byte (unsigned dev
)
248 while (!uart_rx_ready(dev
))
266 /****************************************************************************
268 *****************************************************************************/
270 bool uart_send_buf (unsigned dev
, char *buf
, unsigned len
)
275 uart_send_byte (dev
, buf
[index
]);
282 /****************************************************************************/