xref: /openbmc/u-boot/drivers/serial/serial_pl01x.c (revision 6001985f92e4a99504343485bfe2c18940a41011)
120c9226cSAndreas Engel /*
220c9226cSAndreas Engel  * (C) Copyright 2000
320c9226cSAndreas Engel  * Rob Taylor, Flying Pig Systems. robt@flyingpig.com.
420c9226cSAndreas Engel  *
520c9226cSAndreas Engel  * (C) Copyright 2004
620c9226cSAndreas Engel  * ARM Ltd.
720c9226cSAndreas Engel  * Philippe Robin, <philippe.robin@arm.com>
820c9226cSAndreas Engel  *
91a459660SWolfgang Denk  * SPDX-License-Identifier:	GPL-2.0+
1020c9226cSAndreas Engel  */
1120c9226cSAndreas Engel 
1248d0192fSAndreas Engel /* Simple U-Boot driver for the PrimeCell PL010/PL011 UARTs */
1320c9226cSAndreas Engel 
1420c9226cSAndreas Engel #include <common.h>
158a9cd5adSSimon Glass #include <dm.h>
16aed2fbefSSimon Glass #include <errno.h>
1720c9226cSAndreas Engel #include <watchdog.h>
18249d5219SMatt Waddel #include <asm/io.h>
1939f61477SMarek Vasut #include <serial.h>
2086256b79SMasahiro Yamada #include <dm/platform_data/serial_pl01x.h>
2139f61477SMarek Vasut #include <linux/compiler.h>
22aed2fbefSSimon Glass #include "serial_pl01x_internal.h"
2369751729SVikas Manocha 
2469751729SVikas Manocha DECLARE_GLOBAL_DATA_PTR;
2520c9226cSAndreas Engel 
268a9cd5adSSimon Glass #ifndef CONFIG_DM_SERIAL
278a9cd5adSSimon Glass 
2820c9226cSAndreas Engel static volatile unsigned char *const port[] = CONFIG_PL01x_PORTS;
29aed2fbefSSimon Glass static enum pl01x_type pl01x_type __attribute__ ((section(".data")));
30aed2fbefSSimon Glass static struct pl01x_regs *base_regs __attribute__ ((section(".data")));
3120c9226cSAndreas Engel #define NUM_PORTS (sizeof(port)/sizeof(port[0]))
3220c9226cSAndreas Engel 
338a9cd5adSSimon Glass #endif
3420c9226cSAndreas Engel 
35aed2fbefSSimon Glass static int pl01x_putc(struct pl01x_regs *regs, char c)
3672d5e44cSRabin Vincent {
3720c9226cSAndreas Engel 	/* Wait until there is space in the FIFO */
38aed2fbefSSimon Glass 	if (readl(&regs->fr) & UART_PL01x_FR_TXFF)
39aed2fbefSSimon Glass 		return -EAGAIN;
4020c9226cSAndreas Engel 
4120c9226cSAndreas Engel 	/* Send the character */
4272d5e44cSRabin Vincent 	writel(c, &regs->dr);
43aed2fbefSSimon Glass 
44aed2fbefSSimon Glass 	return 0;
4520c9226cSAndreas Engel }
4620c9226cSAndreas Engel 
47aed2fbefSSimon Glass static int pl01x_getc(struct pl01x_regs *regs)
4820c9226cSAndreas Engel {
4920c9226cSAndreas Engel 	unsigned int data;
5020c9226cSAndreas Engel 
5120c9226cSAndreas Engel 	/* Wait until there is data in the FIFO */
52aed2fbefSSimon Glass 	if (readl(&regs->fr) & UART_PL01x_FR_RXFE)
53aed2fbefSSimon Glass 		return -EAGAIN;
5420c9226cSAndreas Engel 
5572d5e44cSRabin Vincent 	data = readl(&regs->dr);
5620c9226cSAndreas Engel 
5720c9226cSAndreas Engel 	/* Check for an error flag */
5820c9226cSAndreas Engel 	if (data & 0xFFFFFF00) {
5920c9226cSAndreas Engel 		/* Clear the error */
6072d5e44cSRabin Vincent 		writel(0xFFFFFFFF, &regs->ecr);
6120c9226cSAndreas Engel 		return -1;
6220c9226cSAndreas Engel 	}
6320c9226cSAndreas Engel 
6420c9226cSAndreas Engel 	return (int) data;
6520c9226cSAndreas Engel }
6620c9226cSAndreas Engel 
67aed2fbefSSimon Glass static int pl01x_tstc(struct pl01x_regs *regs)
6820c9226cSAndreas Engel {
6920c9226cSAndreas Engel 	WATCHDOG_RESET();
7072d5e44cSRabin Vincent 	return !(readl(&regs->fr) & UART_PL01x_FR_RXFE);
7120c9226cSAndreas Engel }
7239f61477SMarek Vasut 
73aed2fbefSSimon Glass static int pl01x_generic_serial_init(struct pl01x_regs *regs,
74aed2fbefSSimon Glass 				     enum pl01x_type type)
75aed2fbefSSimon Glass {
76aed2fbefSSimon Glass 	switch (type) {
77aed2fbefSSimon Glass 	case TYPE_PL010:
78f7e517b4SVikas Manocha 		/* disable everything */
79f7e517b4SVikas Manocha 		writel(0, &regs->pl010_cr);
80aed2fbefSSimon Glass 		break;
81d2ca9fd2SVikas Manocha 	case TYPE_PL011:
82f7e517b4SVikas Manocha 		/* disable everything */
83f7e517b4SVikas Manocha 		writel(0, &regs->pl011_cr);
84d2ca9fd2SVikas Manocha 		break;
85d2ca9fd2SVikas Manocha 	default:
86d2ca9fd2SVikas Manocha 		return -EINVAL;
87d2ca9fd2SVikas Manocha 	}
88d2ca9fd2SVikas Manocha 
89d2ca9fd2SVikas Manocha 	return 0;
90d2ca9fd2SVikas Manocha }
91d2ca9fd2SVikas Manocha 
92d77447fdSLinus Walleij static int pl011_set_line_control(struct pl01x_regs *regs)
93d2ca9fd2SVikas Manocha {
94d2ca9fd2SVikas Manocha 	unsigned int lcr;
95d2ca9fd2SVikas Manocha 	/*
96d2ca9fd2SVikas Manocha 	 * Internal update of baud rate register require line
97d2ca9fd2SVikas Manocha 	 * control register write
98d2ca9fd2SVikas Manocha 	 */
99d2ca9fd2SVikas Manocha 	lcr = UART_PL011_LCRH_WLEN_8 | UART_PL011_LCRH_FEN;
100d2ca9fd2SVikas Manocha 	writel(lcr, &regs->pl011_lcrh);
101aed2fbefSSimon Glass 	return 0;
102aed2fbefSSimon Glass }
103aed2fbefSSimon Glass 
104aed2fbefSSimon Glass static int pl01x_generic_setbrg(struct pl01x_regs *regs, enum pl01x_type type,
105aed2fbefSSimon Glass 				int clock, int baudrate)
106aed2fbefSSimon Glass {
107aed2fbefSSimon Glass 	switch (type) {
108aed2fbefSSimon Glass 	case TYPE_PL010: {
109aed2fbefSSimon Glass 		unsigned int divisor;
110aed2fbefSSimon Glass 
111d77447fdSLinus Walleij 		/* disable everything */
112d77447fdSLinus Walleij 		writel(0, &regs->pl010_cr);
113d77447fdSLinus Walleij 
114aed2fbefSSimon Glass 		switch (baudrate) {
115aed2fbefSSimon Glass 		case 9600:
116aed2fbefSSimon Glass 			divisor = UART_PL010_BAUD_9600;
117aed2fbefSSimon Glass 			break;
118aed2fbefSSimon Glass 		case 19200:
119b2aa8894SAlyssa Rosenzweig 			divisor = UART_PL010_BAUD_19200;
120aed2fbefSSimon Glass 			break;
121aed2fbefSSimon Glass 		case 38400:
122aed2fbefSSimon Glass 			divisor = UART_PL010_BAUD_38400;
123aed2fbefSSimon Glass 			break;
124aed2fbefSSimon Glass 		case 57600:
125aed2fbefSSimon Glass 			divisor = UART_PL010_BAUD_57600;
126aed2fbefSSimon Glass 			break;
127aed2fbefSSimon Glass 		case 115200:
128aed2fbefSSimon Glass 			divisor = UART_PL010_BAUD_115200;
129aed2fbefSSimon Glass 			break;
130aed2fbefSSimon Glass 		default:
131aed2fbefSSimon Glass 			divisor = UART_PL010_BAUD_38400;
132aed2fbefSSimon Glass 		}
133aed2fbefSSimon Glass 
134aed2fbefSSimon Glass 		writel((divisor & 0xf00) >> 8, &regs->pl010_lcrm);
135aed2fbefSSimon Glass 		writel(divisor & 0xff, &regs->pl010_lcrl);
136aed2fbefSSimon Glass 
137d77447fdSLinus Walleij 		/*
138d77447fdSLinus Walleij 		 * Set line control for the PL010 to be 8 bits, 1 stop bit,
139d77447fdSLinus Walleij 		 * no parity, fifo enabled
140d77447fdSLinus Walleij 		 */
141d77447fdSLinus Walleij 		writel(UART_PL010_LCRH_WLEN_8 | UART_PL010_LCRH_FEN,
142d77447fdSLinus Walleij 		       &regs->pl010_lcrh);
143aed2fbefSSimon Glass 		/* Finally, enable the UART */
144aed2fbefSSimon Glass 		writel(UART_PL010_CR_UARTEN, &regs->pl010_cr);
145aed2fbefSSimon Glass 		break;
146aed2fbefSSimon Glass 	}
147aed2fbefSSimon Glass 	case TYPE_PL011: {
148aed2fbefSSimon Glass 		unsigned int temp;
149aed2fbefSSimon Glass 		unsigned int divider;
150aed2fbefSSimon Glass 		unsigned int remainder;
151aed2fbefSSimon Glass 		unsigned int fraction;
152aed2fbefSSimon Glass 
153aed2fbefSSimon Glass 		/*
154aed2fbefSSimon Glass 		* Set baud rate
155aed2fbefSSimon Glass 		*
156aed2fbefSSimon Glass 		* IBRD = UART_CLK / (16 * BAUD_RATE)
157aed2fbefSSimon Glass 		* FBRD = RND((64 * MOD(UART_CLK,(16 * BAUD_RATE)))
158aed2fbefSSimon Glass 		*		/ (16 * BAUD_RATE))
159aed2fbefSSimon Glass 		*/
160aed2fbefSSimon Glass 		temp = 16 * baudrate;
161aed2fbefSSimon Glass 		divider = clock / temp;
162aed2fbefSSimon Glass 		remainder = clock % temp;
163aed2fbefSSimon Glass 		temp = (8 * remainder) / baudrate;
164aed2fbefSSimon Glass 		fraction = (temp >> 1) + (temp & 1);
165aed2fbefSSimon Glass 
166aed2fbefSSimon Glass 		writel(divider, &regs->pl011_ibrd);
167aed2fbefSSimon Glass 		writel(fraction, &regs->pl011_fbrd);
168aed2fbefSSimon Glass 
169d77447fdSLinus Walleij 		pl011_set_line_control(regs);
170aed2fbefSSimon Glass 		/* Finally, enable the UART */
171aed2fbefSSimon Glass 		writel(UART_PL011_CR_UARTEN | UART_PL011_CR_TXE |
172aed2fbefSSimon Glass 		       UART_PL011_CR_RXE | UART_PL011_CR_RTS, &regs->pl011_cr);
173aed2fbefSSimon Glass 		break;
174aed2fbefSSimon Glass 	}
175aed2fbefSSimon Glass 	default:
176aed2fbefSSimon Glass 		return -EINVAL;
177aed2fbefSSimon Glass 	}
178aed2fbefSSimon Glass 
179aed2fbefSSimon Glass 	return 0;
180aed2fbefSSimon Glass }
181aed2fbefSSimon Glass 
182aed2fbefSSimon Glass #ifndef CONFIG_DM_SERIAL
183aed2fbefSSimon Glass static void pl01x_serial_init_baud(int baudrate)
184aed2fbefSSimon Glass {
185aed2fbefSSimon Glass 	int clock = 0;
186aed2fbefSSimon Glass 
187aed2fbefSSimon Glass #if defined(CONFIG_PL010_SERIAL)
188aed2fbefSSimon Glass 	pl01x_type = TYPE_PL010;
189aed2fbefSSimon Glass #elif defined(CONFIG_PL011_SERIAL)
190aed2fbefSSimon Glass 	pl01x_type = TYPE_PL011;
191aed2fbefSSimon Glass 	clock = CONFIG_PL011_CLOCK;
192aed2fbefSSimon Glass #endif
193aed2fbefSSimon Glass 	base_regs = (struct pl01x_regs *)port[CONFIG_CONS_INDEX];
194aed2fbefSSimon Glass 
195aed2fbefSSimon Glass 	pl01x_generic_serial_init(base_regs, pl01x_type);
196a7deea69SVikas Manocha 	pl01x_generic_setbrg(base_regs, pl01x_type, clock, baudrate);
197aed2fbefSSimon Glass }
198aed2fbefSSimon Glass 
199aed2fbefSSimon Glass /*
200aed2fbefSSimon Glass  * Integrator AP has two UARTs, we use the first one, at 38400-8-N-1
201aed2fbefSSimon Glass  * Integrator CP has two UARTs, use the first one, at 38400-8-N-1
202aed2fbefSSimon Glass  * Versatile PB has four UARTs.
203aed2fbefSSimon Glass  */
204aed2fbefSSimon Glass int pl01x_serial_init(void)
205aed2fbefSSimon Glass {
206aed2fbefSSimon Glass 	pl01x_serial_init_baud(CONFIG_BAUDRATE);
207aed2fbefSSimon Glass 
208aed2fbefSSimon Glass 	return 0;
209aed2fbefSSimon Glass }
210aed2fbefSSimon Glass 
211aed2fbefSSimon Glass static void pl01x_serial_putc(const char c)
212aed2fbefSSimon Glass {
213aed2fbefSSimon Glass 	if (c == '\n')
214aed2fbefSSimon Glass 		while (pl01x_putc(base_regs, '\r') == -EAGAIN);
215aed2fbefSSimon Glass 
216aed2fbefSSimon Glass 	while (pl01x_putc(base_regs, c) == -EAGAIN);
217aed2fbefSSimon Glass }
218aed2fbefSSimon Glass 
219aed2fbefSSimon Glass static int pl01x_serial_getc(void)
220aed2fbefSSimon Glass {
221aed2fbefSSimon Glass 	while (1) {
222aed2fbefSSimon Glass 		int ch = pl01x_getc(base_regs);
223aed2fbefSSimon Glass 
224aed2fbefSSimon Glass 		if (ch == -EAGAIN) {
225aed2fbefSSimon Glass 			WATCHDOG_RESET();
226aed2fbefSSimon Glass 			continue;
227aed2fbefSSimon Glass 		}
228aed2fbefSSimon Glass 
229aed2fbefSSimon Glass 		return ch;
230aed2fbefSSimon Glass 	}
231aed2fbefSSimon Glass }
232aed2fbefSSimon Glass 
233aed2fbefSSimon Glass static int pl01x_serial_tstc(void)
234aed2fbefSSimon Glass {
235aed2fbefSSimon Glass 	return pl01x_tstc(base_regs);
236aed2fbefSSimon Glass }
237aed2fbefSSimon Glass 
238aed2fbefSSimon Glass static void pl01x_serial_setbrg(void)
239aed2fbefSSimon Glass {
240aed2fbefSSimon Glass 	/*
241aed2fbefSSimon Glass 	 * Flush FIFO and wait for non-busy before changing baudrate to avoid
242aed2fbefSSimon Glass 	 * crap in console
243aed2fbefSSimon Glass 	 */
244aed2fbefSSimon Glass 	while (!(readl(&base_regs->fr) & UART_PL01x_FR_TXFE))
245aed2fbefSSimon Glass 		WATCHDOG_RESET();
246aed2fbefSSimon Glass 	while (readl(&base_regs->fr) & UART_PL01x_FR_BUSY)
247aed2fbefSSimon Glass 		WATCHDOG_RESET();
248aed2fbefSSimon Glass 	pl01x_serial_init_baud(gd->baudrate);
249aed2fbefSSimon Glass }
250aed2fbefSSimon Glass 
25139f61477SMarek Vasut static struct serial_device pl01x_serial_drv = {
25239f61477SMarek Vasut 	.name	= "pl01x_serial",
25339f61477SMarek Vasut 	.start	= pl01x_serial_init,
25439f61477SMarek Vasut 	.stop	= NULL,
25539f61477SMarek Vasut 	.setbrg	= pl01x_serial_setbrg,
25639f61477SMarek Vasut 	.putc	= pl01x_serial_putc,
257ec3fd689SMarek Vasut 	.puts	= default_serial_puts,
25839f61477SMarek Vasut 	.getc	= pl01x_serial_getc,
25939f61477SMarek Vasut 	.tstc	= pl01x_serial_tstc,
26039f61477SMarek Vasut };
26139f61477SMarek Vasut 
26239f61477SMarek Vasut void pl01x_serial_initialize(void)
26339f61477SMarek Vasut {
26439f61477SMarek Vasut 	serial_register(&pl01x_serial_drv);
26539f61477SMarek Vasut }
26639f61477SMarek Vasut 
26739f61477SMarek Vasut __weak struct serial_device *default_serial_console(void)
26839f61477SMarek Vasut {
26939f61477SMarek Vasut 	return &pl01x_serial_drv;
27039f61477SMarek Vasut }
271aed2fbefSSimon Glass 
272aed2fbefSSimon Glass #endif /* nCONFIG_DM_SERIAL */
2738a9cd5adSSimon Glass 
2748a9cd5adSSimon Glass #ifdef CONFIG_DM_SERIAL
2758a9cd5adSSimon Glass 
2768a9cd5adSSimon Glass static int pl01x_serial_setbrg(struct udevice *dev, int baudrate)
2778a9cd5adSSimon Glass {
2788a9cd5adSSimon Glass 	struct pl01x_serial_platdata *plat = dev_get_platdata(dev);
2798a9cd5adSSimon Glass 	struct pl01x_priv *priv = dev_get_priv(dev);
2808a9cd5adSSimon Glass 
281cd0fa5bfSEric Anholt 	if (!plat->skip_init) {
282cd0fa5bfSEric Anholt 		pl01x_generic_setbrg(priv->regs, priv->type, plat->clock,
283cd0fa5bfSEric Anholt 				     baudrate);
284cd0fa5bfSEric Anholt 	}
2858a9cd5adSSimon Glass 
2868a9cd5adSSimon Glass 	return 0;
2878a9cd5adSSimon Glass }
2888a9cd5adSSimon Glass 
289*6001985fSAlexander Graf int pl01x_serial_probe(struct udevice *dev)
2908a9cd5adSSimon Glass {
2918a9cd5adSSimon Glass 	struct pl01x_serial_platdata *plat = dev_get_platdata(dev);
2928a9cd5adSSimon Glass 	struct pl01x_priv *priv = dev_get_priv(dev);
2938a9cd5adSSimon Glass 
2948a9cd5adSSimon Glass 	priv->regs = (struct pl01x_regs *)plat->base;
2958a9cd5adSSimon Glass 	priv->type = plat->type;
296cd0fa5bfSEric Anholt 	if (!plat->skip_init)
2978a9cd5adSSimon Glass 		return pl01x_generic_serial_init(priv->regs, priv->type);
298cd0fa5bfSEric Anholt 	else
299cd0fa5bfSEric Anholt 		return 0;
3008a9cd5adSSimon Glass }
3018a9cd5adSSimon Glass 
3028a9cd5adSSimon Glass static int pl01x_serial_getc(struct udevice *dev)
3038a9cd5adSSimon Glass {
3048a9cd5adSSimon Glass 	struct pl01x_priv *priv = dev_get_priv(dev);
3058a9cd5adSSimon Glass 
3068a9cd5adSSimon Glass 	return pl01x_getc(priv->regs);
3078a9cd5adSSimon Glass }
3088a9cd5adSSimon Glass 
3098a9cd5adSSimon Glass static int pl01x_serial_putc(struct udevice *dev, const char ch)
3108a9cd5adSSimon Glass {
3118a9cd5adSSimon Glass 	struct pl01x_priv *priv = dev_get_priv(dev);
3128a9cd5adSSimon Glass 
3138a9cd5adSSimon Glass 	return pl01x_putc(priv->regs, ch);
3148a9cd5adSSimon Glass }
3158a9cd5adSSimon Glass 
3168a9cd5adSSimon Glass static int pl01x_serial_pending(struct udevice *dev, bool input)
3178a9cd5adSSimon Glass {
3188a9cd5adSSimon Glass 	struct pl01x_priv *priv = dev_get_priv(dev);
3198a9cd5adSSimon Glass 	unsigned int fr = readl(&priv->regs->fr);
3208a9cd5adSSimon Glass 
3218a9cd5adSSimon Glass 	if (input)
3228a9cd5adSSimon Glass 		return pl01x_tstc(priv->regs);
3238a9cd5adSSimon Glass 	else
3248a9cd5adSSimon Glass 		return fr & UART_PL01x_FR_TXFF ? 0 : 1;
3258a9cd5adSSimon Glass }
3268a9cd5adSSimon Glass 
327*6001985fSAlexander Graf const struct dm_serial_ops pl01x_serial_ops = {
3288a9cd5adSSimon Glass 	.putc = pl01x_serial_putc,
3298a9cd5adSSimon Glass 	.pending = pl01x_serial_pending,
3308a9cd5adSSimon Glass 	.getc = pl01x_serial_getc,
3318a9cd5adSSimon Glass 	.setbrg = pl01x_serial_setbrg,
3328a9cd5adSSimon Glass };
3338a9cd5adSSimon Glass 
3340f925822SMasahiro Yamada #if CONFIG_IS_ENABLED(OF_CONTROL)
33569751729SVikas Manocha static const struct udevice_id pl01x_serial_id[] ={
33669751729SVikas Manocha 	{.compatible = "arm,pl011", .data = TYPE_PL011},
33769751729SVikas Manocha 	{.compatible = "arm,pl010", .data = TYPE_PL010},
33869751729SVikas Manocha 	{}
33969751729SVikas Manocha };
34069751729SVikas Manocha 
341*6001985fSAlexander Graf int pl01x_serial_ofdata_to_platdata(struct udevice *dev)
34269751729SVikas Manocha {
34369751729SVikas Manocha 	struct pl01x_serial_platdata *plat = dev_get_platdata(dev);
34469751729SVikas Manocha 	fdt_addr_t addr;
34569751729SVikas Manocha 
346a821c4afSSimon Glass 	addr = devfdt_get_addr(dev);
34769751729SVikas Manocha 	if (addr == FDT_ADDR_T_NONE)
34869751729SVikas Manocha 		return -EINVAL;
34969751729SVikas Manocha 
35069751729SVikas Manocha 	plat->base = addr;
351b3111630SAlexander Graf 	plat->clock = dev_read_u32_default(dev, "clock", 1);
35269751729SVikas Manocha 	plat->type = dev_get_driver_data(dev);
353b3111630SAlexander Graf 	plat->skip_init = dev_read_bool(dev, "skip-init");
354b3111630SAlexander Graf 
35569751729SVikas Manocha 	return 0;
35669751729SVikas Manocha }
35769751729SVikas Manocha #endif
35869751729SVikas Manocha 
3598a9cd5adSSimon Glass U_BOOT_DRIVER(serial_pl01x) = {
3608a9cd5adSSimon Glass 	.name	= "serial_pl01x",
3618a9cd5adSSimon Glass 	.id	= UCLASS_SERIAL,
36269751729SVikas Manocha 	.of_match = of_match_ptr(pl01x_serial_id),
36369751729SVikas Manocha 	.ofdata_to_platdata = of_match_ptr(pl01x_serial_ofdata_to_platdata),
36469751729SVikas Manocha 	.platdata_auto_alloc_size = sizeof(struct pl01x_serial_platdata),
3658a9cd5adSSimon Glass 	.probe = pl01x_serial_probe,
3668a9cd5adSSimon Glass 	.ops	= &pl01x_serial_ops,
3678a9cd5adSSimon Glass 	.flags = DM_FLAG_PRE_RELOC,
36859c73d75SSimon Glass 	.priv_auto_alloc_size = sizeof(struct pl01x_priv),
3698a9cd5adSSimon Glass };
3708a9cd5adSSimon Glass 
3718a9cd5adSSimon Glass #endif
372b81406dbSSergey Temerkhanov 
373b81406dbSSergey Temerkhanov #if defined(CONFIG_DEBUG_UART_PL010) || defined(CONFIG_DEBUG_UART_PL011)
374b81406dbSSergey Temerkhanov 
375b81406dbSSergey Temerkhanov #include <debug_uart.h>
376b81406dbSSergey Temerkhanov 
377b81406dbSSergey Temerkhanov static void _debug_uart_init(void)
378b81406dbSSergey Temerkhanov {
379b81406dbSSergey Temerkhanov #ifndef CONFIG_DEBUG_UART_SKIP_INIT
380b81406dbSSergey Temerkhanov 	struct pl01x_regs *regs = (struct pl01x_regs *)CONFIG_DEBUG_UART_BASE;
381b81406dbSSergey Temerkhanov 	enum pl01x_type type = CONFIG_IS_ENABLED(DEBUG_UART_PL011) ?
382b81406dbSSergey Temerkhanov 				TYPE_PL011 : TYPE_PL010;
383b81406dbSSergey Temerkhanov 
384b81406dbSSergey Temerkhanov 	pl01x_generic_serial_init(regs, type);
385b81406dbSSergey Temerkhanov 	pl01x_generic_setbrg(regs, type,
386b81406dbSSergey Temerkhanov 			     CONFIG_DEBUG_UART_CLOCK, CONFIG_BAUDRATE);
387b81406dbSSergey Temerkhanov #endif
388b81406dbSSergey Temerkhanov }
389b81406dbSSergey Temerkhanov 
390b81406dbSSergey Temerkhanov static inline void _debug_uart_putc(int ch)
391b81406dbSSergey Temerkhanov {
392b81406dbSSergey Temerkhanov 	struct pl01x_regs *regs = (struct pl01x_regs *)CONFIG_DEBUG_UART_BASE;
393b81406dbSSergey Temerkhanov 
394b81406dbSSergey Temerkhanov 	pl01x_putc(regs, ch);
395b81406dbSSergey Temerkhanov }
396b81406dbSSergey Temerkhanov 
397b81406dbSSergey Temerkhanov DEBUG_UART_FUNCS
398b81406dbSSergey Temerkhanov 
399b81406dbSSergey Temerkhanov #endif
400