aboutsummaryrefslogtreecommitdiff
path: root/src/cpu/ti/am335x/uart.c
blob: fdf5c059085582b132fa241edaf0b6508295cc3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
 * (C) Copyright 2009 SAMSUNG Electronics
 * Minkyu Kang <mk7.kang@samsung.com>
 * Heungjun Kim <riverful.kim@samsung.com>
 *
 * based on drivers/serial/s3c64xx.c
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
 *
 */

#include <types.h>
#include <uart.h>
#include <arch/io.h>

#include <console/console.h>	/* for __console definition */

#include <cpu/ti/am335x/uart.h>

#define RX_FIFO_COUNT_MASK	0xff
#define RX_FIFO_FULL_MASK	(1 << 8)
#define TX_FIFO_FULL_MASK	(1 << 24)

/*
 * Initialise the serial port with the given baudrate. The settings
 * are always 8 data bits, no parity, 1 stop bit, no start bits.
 */
static void am335x_uart_init_dev(void)
{
	/* FIXME: implement this
	 * ref: section 19.4.1.1.1 for reset
	 * ref: section 19.4.1.1.2 for FIFO, skip DMA
	 * ref: section 19.4.1.1.3 for baud rate, skip
	 *      interrupts and protocol stuff.
	 * */
#if 0
	struct s5p_uart *uart = (struct s5p_uart *)base_port;

	// TODO initialize with correct peripheral id by base_port.
	exynos_pinmux_config(PERIPH_ID_UART3, PINMUX_FLAG_NONE);

	/* enable FIFOs */
	writel(0x1, &uart->ufcon);
	writel(0, &uart->umcon);
	/* 8N1 */
	writel(0x3, &uart->ulcon);
	/* No interrupts, no DMA, pure polling */
	writel(0x245, &uart->ucon);

	serial_setbrg_dev();
#endif
}

/*
 * Read a single byte from the serial port. Returns 1 on success, 0
 * otherwise. When the function is succesfull, the character read is
 * written into its argument c.
 */
static unsigned char am335x_uart_rx_byte(void)
{
	/* FIXME: stub */
#if 0
	struct s5p_uart *uart = (struct s5p_uart *)base_port;

	/* wait for character to arrive */
	while (!(readl(&uart->ufstat) & (RX_FIFO_COUNT_MASK |
					 RX_FIFO_FULL_MASK))) {
		if (exynos5_uart_err_check(0))
			return 0;
	}

	return readb(&uart->urxh) & 0xff;
#endif
	return 0xaa;
}

/*
 * Output a single byte to the serial port.
 */
static void am335x_uart_tx_byte(unsigned char data)
{
	/* FIXME: stub */
#if 0
	struct s5p_uart *uart = (struct s5p_uart *)base_port;

	/* wait for room in the tx FIFO */
	while ((readl(&uart->ufstat) & TX_FIFO_FULL_MASK)) {
		if (exynos5_uart_err_check(1))
			return;
	}

	writeb(data, &uart->utxh);
#endif
}

uint32_t uartmem_getbaseaddr(void)
{
	return CONFIG_CONSOLE_SERIAL_UART_ADDRESS;
}

#if !defined(__PRE_RAM__)
static const struct console_driver exynos5_uart_console __console = {
	.init     = am335x_uart_init_dev,
	.tx_byte  = am335x_uart_tx_byte,
	.rx_byte  = am335x_uart_rx_byte,
};
#else
void uart_init(void)
{
	am335x_uart_init_dev();
}

unsigned char uart_rx_byte(void)
{
	return am335x_uart_rx_byte();
}

void uart_tx_byte(unsigned char data)
{
	am335x_uart_tx_byte(data);
}

void uart_tx_flush(void) {
}
#endif