blob: cc85a502726ecc46463b33ea2c3fade80dd419ce [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Sascha Hauer1a7676f2008-03-26 20:40:42 +01002/*
3 * (c) 2007 Sascha Hauer <s.hauer@pengutronix.de>
Sascha Hauer1a7676f2008-03-26 20:40:42 +01004 */
5
6#include <common.h>
Simon Glass8bc85192014-10-01 19:57:27 -06007#include <dm.h>
8#include <errno.h>
Stefano Babic733c4352010-08-18 10:22:42 +02009#include <watchdog.h>
Ilya Yanok7bfca972009-06-08 04:12:46 +040010#include <asm/arch/imx-regs.h>
11#include <asm/arch/clock.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060012#include <asm/global_data.h>
Masahiro Yamada22c97de2014-10-24 12:41:19 +090013#include <dm/platform_data/serial_mxc.h>
Marek Vasut64c60552012-09-14 22:37:43 +020014#include <serial.h>
15#include <linux/compiler.h>
Loic Poulain3e7a9992023-01-12 18:19:50 +010016#include <linux/delay.h>
Sascha Hauer1a7676f2008-03-26 20:40:42 +010017
Sascha Hauer1a7676f2008-03-26 20:40:42 +010018/* UART Control Register Bit Fields.*/
Jagan Teki71eb2bf2017-06-06 05:31:50 +000019#define URXD_CHARRDY (1<<15)
20#define URXD_ERR (1<<14)
21#define URXD_OVRRUN (1<<13)
22#define URXD_FRMERR (1<<12)
23#define URXD_BRK (1<<11)
24#define URXD_PRERR (1<<10)
25#define URXD_RX_DATA (0xFF)
26#define UCR1_ADEN (1<<15) /* Auto dectect interrupt */
27#define UCR1_ADBR (1<<14) /* Auto detect baud rate */
28#define UCR1_TRDYEN (1<<13) /* Transmitter ready interrupt enable */
29#define UCR1_IDEN (1<<12) /* Idle condition interrupt */
30#define UCR1_RRDYEN (1<<9) /* Recv ready interrupt enable */
31#define UCR1_RDMAEN (1<<8) /* Recv ready DMA enable */
32#define UCR1_IREN (1<<7) /* Infrared interface enable */
33#define UCR1_TXMPTYEN (1<<6) /* Transimitter empty interrupt enable */
34#define UCR1_RTSDEN (1<<5) /* RTS delta interrupt enable */
35#define UCR1_SNDBRK (1<<4) /* Send break */
36#define UCR1_TDMAEN (1<<3) /* Transmitter ready DMA enable */
37#define UCR1_UARTCLKEN (1<<2) /* UART clock enabled */
38#define UCR1_DOZE (1<<1) /* Doze */
39#define UCR1_UARTEN (1<<0) /* UART enabled */
40#define UCR2_ESCI (1<<15) /* Escape seq interrupt enable */
41#define UCR2_IRTS (1<<14) /* Ignore RTS pin */
42#define UCR2_CTSC (1<<13) /* CTS pin control */
43#define UCR2_CTS (1<<12) /* Clear to send */
44#define UCR2_ESCEN (1<<11) /* Escape enable */
45#define UCR2_PREN (1<<8) /* Parity enable */
46#define UCR2_PROE (1<<7) /* Parity odd/even */
47#define UCR2_STPB (1<<6) /* Stop */
48#define UCR2_WS (1<<5) /* Word size */
49#define UCR2_RTSEN (1<<4) /* Request to send interrupt enable */
50#define UCR2_TXEN (1<<2) /* Transmitter enabled */
51#define UCR2_RXEN (1<<1) /* Receiver enabled */
52#define UCR2_SRST (1<<0) /* SW reset */
53#define UCR3_DTREN (1<<13) /* DTR interrupt enable */
54#define UCR3_PARERREN (1<<12) /* Parity enable */
55#define UCR3_FRAERREN (1<<11) /* Frame error interrupt enable */
56#define UCR3_DSR (1<<10) /* Data set ready */
57#define UCR3_DCD (1<<9) /* Data carrier detect */
58#define UCR3_RI (1<<8) /* Ring indicator */
59#define UCR3_ADNIMP (1<<7) /* Autobaud Detection Not Improved */
60#define UCR3_RXDSEN (1<<6) /* Receive status interrupt enable */
61#define UCR3_AIRINTEN (1<<5) /* Async IR wake interrupt enable */
62#define UCR3_AWAKEN (1<<4) /* Async wake interrupt enable */
63#define UCR3_REF25 (1<<3) /* Ref freq 25 MHz */
64#define UCR3_REF30 (1<<2) /* Ref Freq 30 MHz */
Johannes Schneiderba98bef2022-09-06 14:15:03 +020065
66/* imx8 names these bitsfields instead: */
67#define UCR3_DTRDEN BIT(3) /* bit not used in this chip */
68#define UCR3_RXDMUXSEL BIT(2) /* RXD muxed input selected; 'should always be set' */
69
Jagan Teki71eb2bf2017-06-06 05:31:50 +000070#define UCR3_INVT (1<<1) /* Inverted Infrared transmission */
71#define UCR3_BPEN (1<<0) /* Preset registers enable */
72#define UCR4_CTSTL_32 (32<<10) /* CTS trigger level (32 chars) */
73#define UCR4_INVR (1<<9) /* Inverted infrared reception */
74#define UCR4_ENIRI (1<<8) /* Serial infrared interrupt enable */
75#define UCR4_WKEN (1<<7) /* Wake interrupt enable */
76#define UCR4_REF16 (1<<6) /* Ref freq 16 MHz */
77#define UCR4_IRSC (1<<5) /* IR special case */
78#define UCR4_TCEN (1<<3) /* Transmit complete interrupt enable */
79#define UCR4_BKEN (1<<2) /* Break condition interrupt enable */
80#define UCR4_OREN (1<<1) /* Receiver overrun interrupt enable */
81#define UCR4_DREN (1<<0) /* Recv data ready interrupt enable */
82#define UFCR_RXTL_SHF 0 /* Receiver trigger level shift */
83#define UFCR_RFDIV (7<<7) /* Reference freq divider mask */
84#define UFCR_RFDIV_SHF 7 /* Reference freq divider shift */
85#define RFDIV 4 /* divide input clock by 2 */
86#define UFCR_DCEDTE (1<<6) /* DTE mode select */
87#define UFCR_TXTL_SHF 10 /* Transmitter trigger level shift */
88#define USR1_PARITYERR (1<<15) /* Parity error interrupt flag */
89#define USR1_RTSS (1<<14) /* RTS pin status */
90#define USR1_TRDY (1<<13) /* Transmitter ready interrupt/dma flag */
91#define USR1_RTSD (1<<12) /* RTS delta */
92#define USR1_ESCF (1<<11) /* Escape seq interrupt flag */
93#define USR1_FRAMERR (1<<10) /* Frame error interrupt flag */
94#define USR1_RRDY (1<<9) /* Receiver ready interrupt/dma flag */
95#define USR1_TIMEOUT (1<<7) /* Receive timeout interrupt status */
96#define USR1_RXDS (1<<6) /* Receiver idle interrupt flag */
97#define USR1_AIRINT (1<<5) /* Async IR wake interrupt flag */
98#define USR1_AWAKE (1<<4) /* Aysnc wake interrupt flag */
99#define USR2_ADET (1<<15) /* Auto baud rate detect complete */
100#define USR2_TXFE (1<<14) /* Transmit buffer FIFO empty */
101#define USR2_DTRF (1<<13) /* DTR edge interrupt flag */
102#define USR2_IDLE (1<<12) /* Idle condition */
103#define USR2_IRINT (1<<8) /* Serial infrared interrupt flag */
104#define USR2_WAKE (1<<7) /* Wake */
105#define USR2_RTSF (1<<4) /* RTS edge interrupt flag */
106#define USR2_TXDC (1<<3) /* Transmitter complete */
107#define USR2_BRCD (1<<2) /* Break condition */
108#define USR2_ORE (1<<1) /* Overrun error */
109#define USR2_RDR (1<<0) /* Recv data ready */
110#define UTS_FRCPERR (1<<13) /* Force parity error */
111#define UTS_LOOP (1<<12) /* Loop tx and rx */
112#define UTS_TXEMPTY (1<<6) /* TxFIFO empty */
113#define UTS_RXEMPTY (1<<5) /* RxFIFO empty */
114#define UTS_TXFULL (1<<4) /* TxFIFO full */
115#define UTS_RXFULL (1<<3) /* RxFIFO full */
116#define UTS_SOFTRS (1<<0) /* Software reset */
Jagan Teki9df89922017-06-06 05:31:49 +0000117#define TXTL 2 /* reset default */
118#define RXTL 1 /* reset default */
Sascha Hauer1a7676f2008-03-26 20:40:42 +0100119
Stefan Agnera23ac7b2016-10-05 15:27:03 -0700120DECLARE_GLOBAL_DATA_PTR;
121
Jagan Tekif8fd2752017-06-06 05:31:45 +0000122struct mxc_uart {
123 u32 rxd;
124 u32 spare0[15];
125
126 u32 txd;
127 u32 spare1[15];
128
129 u32 cr1;
130 u32 cr2;
131 u32 cr3;
132 u32 cr4;
133
134 u32 fcr;
135 u32 sr1;
136 u32 sr2;
137 u32 esc;
138
139 u32 tim;
140 u32 bir;
141 u32 bmr;
142 u32 brc;
143
144 u32 onems;
145 u32 ts;
146};
147
Loic Poulain3e7a9992023-01-12 18:19:50 +0100148static void _mxc_serial_flush(struct mxc_uart *base)
149{
150 unsigned int timeout = 4000;
151
152 if (!(readl(&base->cr1) & UCR1_UARTEN) ||
153 !(readl(&base->cr2) & UCR2_TXEN))
154 return;
155
156 while (!(readl(&base->sr2) & USR2_TXDC) && --timeout)
157 udelay(1);
158}
159
Max Krummenacher45d67232019-02-01 16:04:50 +0100160static void _mxc_serial_init(struct mxc_uart *base, int use_dte)
Jagan Teki01fcb6e2017-06-06 05:31:48 +0000161{
Loic Poulain3e7a9992023-01-12 18:19:50 +0100162 _mxc_serial_flush(base);
163
Jagan Teki01fcb6e2017-06-06 05:31:48 +0000164 writel(0, &base->cr1);
165 writel(0, &base->cr2);
166
167 while (!(readl(&base->cr2) & UCR2_SRST));
168
Max Krummenacher45d67232019-02-01 16:04:50 +0100169 if (use_dte)
170 writel(0x404 | UCR3_ADNIMP, &base->cr3);
171 else
172 writel(0x704 | UCR3_ADNIMP, &base->cr3);
173
Jagan Teki01fcb6e2017-06-06 05:31:48 +0000174 writel(0x704 | UCR3_ADNIMP, &base->cr3);
175 writel(0x8000, &base->cr4);
176 writel(0x2b, &base->esc);
177 writel(0, &base->tim);
178
179 writel(0, &base->ts);
180}
181
Jagan Teki9df89922017-06-06 05:31:49 +0000182static void _mxc_serial_setbrg(struct mxc_uart *base, unsigned long clk,
183 unsigned long baudrate, bool use_dte)
184{
185 u32 tmp;
186
Loic Poulain3e7a9992023-01-12 18:19:50 +0100187 _mxc_serial_flush(base);
188
Jagan Teki9df89922017-06-06 05:31:49 +0000189 tmp = RFDIV << UFCR_RFDIV_SHF;
190 if (use_dte)
191 tmp |= UFCR_DCEDTE;
192 else
193 tmp |= (TXTL << UFCR_TXTL_SHF) | (RXTL << UFCR_RXTL_SHF);
194 writel(tmp, &base->fcr);
195
196 writel(0xf, &base->bir);
197 writel(clk / (2 * baudrate), &base->bmr);
198
199 writel(UCR2_WS | UCR2_IRTS | UCR2_RXEN | UCR2_TXEN | UCR2_SRST,
200 &base->cr2);
Johannes Schneiderba98bef2022-09-06 14:15:03 +0200201
202 /*
203 * setting the baudrate triggers a reset, returning cr3 to its
204 * reset value but UCR3_RXDMUXSEL "should always be set."
205 * according to the imx8 reference-manual
206 */
207 writel(readl(&base->cr3) | UCR3_RXDMUXSEL, &base->cr3);
208
Jagan Teki9df89922017-06-06 05:31:49 +0000209 writel(UCR1_UARTEN, &base->cr1);
210}
211
Adam Fordfd5fc9e2019-02-19 22:07:22 -0600212#if !CONFIG_IS_ENABLED(DM_SERIAL)
Simon Glass8bc85192014-10-01 19:57:27 -0600213
Tom Rinia17aa192022-12-04 10:04:55 -0500214#ifndef CFG_MXC_UART_BASE
215#error "define CFG_MXC_UART_BASE to use the MXC UART driver"
Simon Glass8bc85192014-10-01 19:57:27 -0600216#endif
217
Tom Rinia17aa192022-12-04 10:04:55 -0500218#define mxc_base ((struct mxc_uart *)CFG_MXC_UART_BASE)
Simon Glass8bc85192014-10-01 19:57:27 -0600219
Marek Vasut64c60552012-09-14 22:37:43 +0200220static void mxc_serial_setbrg(void)
Sascha Hauer1a7676f2008-03-26 20:40:42 +0100221{
Stefano Babica1b7a772010-01-20 18:20:19 +0100222 u32 clk = imx_get_uartclk();
Sascha Hauer1a7676f2008-03-26 20:40:42 +0100223
224 if (!gd->baudrate)
225 gd->baudrate = CONFIG_BAUDRATE;
226
Jagan Teki9df89922017-06-06 05:31:49 +0000227 _mxc_serial_setbrg(mxc_base, clk, gd->baudrate, false);
Sascha Hauer1a7676f2008-03-26 20:40:42 +0100228}
229
Marek Vasut64c60552012-09-14 22:37:43 +0200230static int mxc_serial_getc(void)
Sascha Hauer1a7676f2008-03-26 20:40:42 +0100231{
Jagan Tekif8fd2752017-06-06 05:31:45 +0000232 while (readl(&mxc_base->ts) & UTS_RXEMPTY)
Stefan Roese80877fa2022-09-02 14:10:46 +0200233 schedule();
Jagan Tekif8fd2752017-06-06 05:31:45 +0000234 return (readl(&mxc_base->rxd) & URXD_RX_DATA); /* mask out status from upper word */
Sascha Hauer1a7676f2008-03-26 20:40:42 +0100235}
236
Marek Vasut64c60552012-09-14 22:37:43 +0200237static void mxc_serial_putc(const char c)
Sascha Hauer1a7676f2008-03-26 20:40:42 +0100238{
Alison Wang23e06b52016-03-02 11:00:37 +0800239 /* If \n, also do \r */
240 if (c == '\n')
241 serial_putc('\r');
242
Sascha Hauer1a7676f2008-03-26 20:40:42 +0100243 /* wait for transmitter to be ready */
Loic Poulainf1d96692023-01-12 18:19:51 +0100244 while (readl(&mxc_base->ts) & UTS_TXFULL)
Stefan Roese80877fa2022-09-02 14:10:46 +0200245 schedule();
Loic Poulainf1d96692023-01-12 18:19:51 +0100246
247 writel(c, &mxc_base->txd);
Sascha Hauer1a7676f2008-03-26 20:40:42 +0100248}
249
Jagan Teki71eb2bf2017-06-06 05:31:50 +0000250/* Test whether a character is in the RX buffer */
Marek Vasut64c60552012-09-14 22:37:43 +0200251static int mxc_serial_tstc(void)
Sascha Hauer1a7676f2008-03-26 20:40:42 +0100252{
253 /* If receive fifo is empty, return false */
Jagan Tekif8fd2752017-06-06 05:31:45 +0000254 if (readl(&mxc_base->ts) & UTS_RXEMPTY)
Sascha Hauer1a7676f2008-03-26 20:40:42 +0100255 return 0;
256 return 1;
257}
258
Sascha Hauer1a7676f2008-03-26 20:40:42 +0100259/*
260 * Initialise the serial port with the given baudrate. The settings
261 * are always 8 data bits, no parity, 1 stop bit, no start bits.
Sascha Hauer1a7676f2008-03-26 20:40:42 +0100262 */
Marek Vasut64c60552012-09-14 22:37:43 +0200263static int mxc_serial_init(void)
Sascha Hauer1a7676f2008-03-26 20:40:42 +0100264{
Max Krummenacher45d67232019-02-01 16:04:50 +0100265 _mxc_serial_init(mxc_base, false);
Sascha Hauer1a7676f2008-03-26 20:40:42 +0100266
267 serial_setbrg();
268
Sascha Hauer1a7676f2008-03-26 20:40:42 +0100269 return 0;
270}
Marek Vasut64c60552012-09-14 22:37:43 +0200271
Loic Poulain3e7a9992023-01-12 18:19:50 +0100272static int mxc_serial_stop(void)
273{
274 _mxc_serial_flush(mxc_base);
275
276 return 0;
277}
278
Marek Vasut64c60552012-09-14 22:37:43 +0200279static struct serial_device mxc_serial_drv = {
280 .name = "mxc_serial",
281 .start = mxc_serial_init,
Loic Poulain3e7a9992023-01-12 18:19:50 +0100282 .stop = mxc_serial_stop,
Marek Vasut64c60552012-09-14 22:37:43 +0200283 .setbrg = mxc_serial_setbrg,
284 .putc = mxc_serial_putc,
Marek Vasutd9c64492012-10-06 14:07:02 +0000285 .puts = default_serial_puts,
Marek Vasut64c60552012-09-14 22:37:43 +0200286 .getc = mxc_serial_getc,
287 .tstc = mxc_serial_tstc,
288};
289
290void mxc_serial_initialize(void)
291{
292 serial_register(&mxc_serial_drv);
293}
294
295__weak struct serial_device *default_serial_console(void)
296{
297 return &mxc_serial_drv;
298}
Simon Glass8bc85192014-10-01 19:57:27 -0600299#endif
300
Adam Fordfd5fc9e2019-02-19 22:07:22 -0600301#if CONFIG_IS_ENABLED(DM_SERIAL)
Simon Glass8bc85192014-10-01 19:57:27 -0600302
Simon Glass8bc85192014-10-01 19:57:27 -0600303int mxc_serial_setbrg(struct udevice *dev, int baudrate)
304{
Simon Glass95588622020-12-22 19:30:28 -0700305 struct mxc_serial_plat *plat = dev_get_plat(dev);
Simon Glass8bc85192014-10-01 19:57:27 -0600306 u32 clk = imx_get_uartclk();
Stefan Agner07b3f332016-07-13 00:25:35 -0700307
Jagan Teki9df89922017-06-06 05:31:49 +0000308 _mxc_serial_setbrg(plat->reg, clk, baudrate, plat->use_dte);
Simon Glass8bc85192014-10-01 19:57:27 -0600309
310 return 0;
311}
312
313static int mxc_serial_probe(struct udevice *dev)
314{
Simon Glass95588622020-12-22 19:30:28 -0700315 struct mxc_serial_plat *plat = dev_get_plat(dev);
Simon Glass8bc85192014-10-01 19:57:27 -0600316
Max Krummenacher45d67232019-02-01 16:04:50 +0100317 _mxc_serial_init(plat->reg, plat->use_dte);
Simon Glass8bc85192014-10-01 19:57:27 -0600318
319 return 0;
320}
321
322static int mxc_serial_getc(struct udevice *dev)
323{
Simon Glass95588622020-12-22 19:30:28 -0700324 struct mxc_serial_plat *plat = dev_get_plat(dev);
Simon Glass8bc85192014-10-01 19:57:27 -0600325 struct mxc_uart *const uart = plat->reg;
326
327 if (readl(&uart->ts) & UTS_RXEMPTY)
328 return -EAGAIN;
329
330 return readl(&uart->rxd) & URXD_RX_DATA;
331}
332
333static int mxc_serial_putc(struct udevice *dev, const char ch)
334{
Simon Glass95588622020-12-22 19:30:28 -0700335 struct mxc_serial_plat *plat = dev_get_plat(dev);
Simon Glass8bc85192014-10-01 19:57:27 -0600336 struct mxc_uart *const uart = plat->reg;
337
Loic Poulainf1d96692023-01-12 18:19:51 +0100338 if (readl(&uart->ts) & UTS_TXFULL)
Simon Glass8bc85192014-10-01 19:57:27 -0600339 return -EAGAIN;
340
341 writel(ch, &uart->txd);
342
343 return 0;
344}
345
346static int mxc_serial_pending(struct udevice *dev, bool input)
347{
Simon Glass95588622020-12-22 19:30:28 -0700348 struct mxc_serial_plat *plat = dev_get_plat(dev);
Simon Glass8bc85192014-10-01 19:57:27 -0600349 struct mxc_uart *const uart = plat->reg;
350 uint32_t sr2 = readl(&uart->sr2);
351
352 if (input)
353 return sr2 & USR2_RDR ? 1 : 0;
354 else
355 return sr2 & USR2_TXDC ? 0 : 1;
356}
357
358static const struct dm_serial_ops mxc_serial_ops = {
359 .putc = mxc_serial_putc,
360 .pending = mxc_serial_pending,
361 .getc = mxc_serial_getc,
362 .setbrg = mxc_serial_setbrg,
363};
Stefan Agnera23ac7b2016-10-05 15:27:03 -0700364
365#if CONFIG_IS_ENABLED(OF_CONTROL)
Simon Glassaad29ae2020-12-03 16:55:21 -0700366static int mxc_serial_of_to_plat(struct udevice *dev)
Stefan Agnera23ac7b2016-10-05 15:27:03 -0700367{
Simon Glass95588622020-12-22 19:30:28 -0700368 struct mxc_serial_plat *plat = dev_get_plat(dev);
Stefan Agnera23ac7b2016-10-05 15:27:03 -0700369 fdt_addr_t addr;
370
Masahiro Yamadaa89b4de2020-07-17 14:36:48 +0900371 addr = dev_read_addr(dev);
Stefan Agnera23ac7b2016-10-05 15:27:03 -0700372 if (addr == FDT_ADDR_T_NONE)
373 return -EINVAL;
374
375 plat->reg = (struct mxc_uart *)addr;
376
Simon Glassdd79d6e2017-01-17 16:52:55 -0700377 plat->use_dte = fdtdec_get_bool(gd->fdt_blob, dev_of_offset(dev),
Stefan Agnera23ac7b2016-10-05 15:27:03 -0700378 "fsl,dte-mode");
379 return 0;
380}
381
382static const struct udevice_id mxc_serial_ids[] = {
Lukasz Majewski9ac180e2019-07-09 17:00:05 +0200383 { .compatible = "fsl,imx21-uart" },
384 { .compatible = "fsl,imx53-uart" },
Marek Vasut668caf92019-05-17 21:56:40 +0200385 { .compatible = "fsl,imx6sx-uart" },
Sébastien Szymanskie3b8d392017-03-07 14:33:24 +0100386 { .compatible = "fsl,imx6ul-uart" },
Stefan Agnera23ac7b2016-10-05 15:27:03 -0700387 { .compatible = "fsl,imx7d-uart" },
Bernhard Messerklinger822cab32018-09-03 10:17:35 +0200388 { .compatible = "fsl,imx6q-uart" },
Stefan Agnera23ac7b2016-10-05 15:27:03 -0700389 { }
390};
391#endif
Simon Glass8bc85192014-10-01 19:57:27 -0600392
393U_BOOT_DRIVER(serial_mxc) = {
394 .name = "serial_mxc",
395 .id = UCLASS_SERIAL,
Stefan Agnera23ac7b2016-10-05 15:27:03 -0700396#if CONFIG_IS_ENABLED(OF_CONTROL)
397 .of_match = mxc_serial_ids,
Simon Glassaad29ae2020-12-03 16:55:21 -0700398 .of_to_plat = mxc_serial_of_to_plat,
Simon Glassb75b15b2020-12-03 16:55:23 -0700399 .plat_auto = sizeof(struct mxc_serial_plat),
Stefan Agnera23ac7b2016-10-05 15:27:03 -0700400#endif
Simon Glass8bc85192014-10-01 19:57:27 -0600401 .probe = mxc_serial_probe,
402 .ops = &mxc_serial_ops,
403 .flags = DM_FLAG_PRE_RELOC,
404};
405#endif
Jagan Tekicf6db162017-06-06 05:31:51 +0000406
407#ifdef CONFIG_DEBUG_UART_MXC
408#include <debug_uart.h>
409
410static inline void _debug_uart_init(void)
411{
Pali Rohár8864b352022-05-27 22:15:24 +0200412 struct mxc_uart *base = (struct mxc_uart *)CONFIG_VAL(DEBUG_UART_BASE);
Jagan Tekicf6db162017-06-06 05:31:51 +0000413
Max Krummenacher45d67232019-02-01 16:04:50 +0100414 _mxc_serial_init(base, false);
Jagan Tekicf6db162017-06-06 05:31:51 +0000415 _mxc_serial_setbrg(base, CONFIG_DEBUG_UART_CLOCK,
416 CONFIG_BAUDRATE, false);
417}
418
419static inline void _debug_uart_putc(int ch)
420{
Pali Rohár8864b352022-05-27 22:15:24 +0200421 struct mxc_uart *base = (struct mxc_uart *)CONFIG_VAL(DEBUG_UART_BASE);
Jagan Tekicf6db162017-06-06 05:31:51 +0000422
423 while (!(readl(&base->ts) & UTS_TXEMPTY))
Stefan Roese80877fa2022-09-02 14:10:46 +0200424 schedule();
Jagan Tekicf6db162017-06-06 05:31:51 +0000425
426 writel(ch, &base->txd);
427}
428
429DEBUG_UART_FUNCS
430
431#endif