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 */
33 #include "system-target.h"
34 #include "uart-s3c2440.h"
36 #define MAX_PRINTF_BUF 1024
38 /****************************************************************************
40 ****************************************************************************/
41 void serial_setup (void)
44 uart_init_device(DEBUG_UART_PORT
);
49 if (uart_tx_ready (DEBUG_UART_PORT
))
55 void tx_writec(unsigned char c
)
57 uart_send_byte (DEBUG_UART_PORT
, c
);
61 /****************************************************************************
62 * General purpose debug function
63 ****************************************************************************/
65 void uart_printf (const char *format
, ...)
67 static bool debug_uart_init
= false;
68 static char tx_buf
[MAX_PRINTF_BUF
];
78 len
= vsnprintf(ptr
, sizeof(tx_buf
), format
, ap
);
83 uart_init_device(DEBUG_UART_PORT
);
84 debug_uart_init
= true;
89 uart_send_byte (DEBUG_UART_PORT
, tx_buf
[j
]);
90 if ( tx_buf
[j
] == '\n')
91 uart_send_byte (DEBUG_UART_PORT
, '\r');
95 /****************************************************************************
96 * Device level functions specific to S3C2440
97 *****************************************************************************/
105 bool uart_init_device (unsigned dev
)
107 /* set GPIOs, clock enable? etc */
113 S3C2440_GPIO_CONFIG (GPHCON
, 2, GPIO_FUNCTION
);
114 S3C2440_GPIO_CONFIG (GPHCON
, 3, GPIO_FUNCTION
);
115 S3C2440_GPIO_PULLUP (GPHUP
, 2, GPIO_PULLUP_DISABLE
);
116 S3C2440_GPIO_PULLUP (GPHUP
, 3, GPIO_PULLUP_DISABLE
);
121 S3C2440_GPIO_CONFIG (GPHCON
, 4, GPIO_FUNCTION
);
122 S3C2440_GPIO_CONFIG (GPHCON
, 5, GPIO_FUNCTION
);
123 S3C2440_GPIO_PULLUP (GPHUP
, 4, GPIO_PULLUP_DISABLE
);
124 S3C2440_GPIO_PULLUP (GPHUP
, 5, GPIO_PULLUP_DISABLE
);
129 S3C2440_GPIO_CONFIG (GPHCON
, 6, GPIO_FUNCTION
);
130 S3C2440_GPIO_CONFIG (GPHCON
, 7, GPIO_FUNCTION
);
131 S3C2440_GPIO_PULLUP (GPHUP
, 6, GPIO_PULLUP_DISABLE
);
132 S3C2440_GPIO_PULLUP (GPHUP
, 7, GPIO_PULLUP_DISABLE
);
139 /* set a default configuration */
140 uart_config (dev
, 115200, 8, UART_NO_PARITY
, UART_1_STOP_BIT
);
144 bool uart_config (unsigned dev
, unsigned speed
, unsigned num_bits
,
145 unsigned parity
, unsigned stop_bits
)
150 ULCON0
= (parity
<< 3) + (stop_bits
<< 2) + (num_bits
-5);
151 UCON0
= (1 << 2) + (1 << 0); /* enable TX, RX, use PCLK */
152 UBRDIV0
= PCLK
/ (speed
*16);
156 ULCON1
= (parity
<< 3) + (stop_bits
<< 2) + (num_bits
-5);
157 UCON1
= (1 << 2) + (1 << 0); /* enable TX, RX, use PCLK */
158 UBRDIV1
= PCLK
/ (speed
*16);
162 ULCON2
= (parity
<< 3) + (stop_bits
<< 2) + (num_bits
-5);
163 UCON2
= (1 << 2) + (1 << 0); /* enable TX, RX, use PCLK */
164 UBRDIV2
= PCLK
/ (speed
*16);
172 bool uart_tx_ready (unsigned dev
)
174 /* test if transmit buffer empty */
199 bool uart_send_byte (unsigned dev
, char ch
)
201 /* wait for transmit buffer empty */
202 while (!uart_tx_ready(dev
))
223 bool uart_rx_ready (unsigned dev
)
225 /* test receive buffer data ready */
250 char uart_read_byte (unsigned dev
)
252 while (!uart_rx_ready(dev
))
270 /****************************************************************************
272 *****************************************************************************/
274 bool uart_send_buf (unsigned dev
, char *buf
, unsigned len
)
279 uart_send_byte (dev
, buf
[index
]);
286 /****************************************************************************/