Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 2 | /* |
Marek Vasut | ac737ff | 2011-08-28 03:35:13 +0200 | [diff] [blame] | 3 | * Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com> |
| 4 | * |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 5 | * (C) Copyright 2002 |
| 6 | * Wolfgang Denk, DENX Software Engineering, <wd@denx.de> |
| 7 | * |
| 8 | * (C) Copyright 2002 |
| 9 | * Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
| 10 | * Marius Groeger <mgroeger@sysgo.de> |
| 11 | * |
| 12 | * (C) Copyright 2002 |
| 13 | * Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
| 14 | * Alex Zuepke <azu@sysgo.de> |
| 15 | * |
| 16 | * Copyright (C) 1999 2000 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl) |
| 17 | * |
Marcel Ziswiler | 90392d0 | 2016-11-14 21:40:26 +0100 | [diff] [blame] | 18 | * Modified to add driver model (DM) support |
| 19 | * (C) Copyright 2016 Marcel Ziswiler <marcel.ziswiler@toradex.com> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #include <common.h> |
Simon Glass | f11478f | 2019-12-28 10:45:07 -0700 | [diff] [blame] | 23 | #include <hang.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 24 | #include <asm/arch/pxa-regs.h> |
Marek Vasut | ac737ff | 2011-08-28 03:35:13 +0200 | [diff] [blame] | 25 | #include <asm/arch/regs-uart.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 26 | #include <asm/global_data.h> |
Marek Vasut | 2db1e96 | 2010-09-09 09:50:39 +0200 | [diff] [blame] | 27 | #include <asm/io.h> |
Marcel Ziswiler | 90392d0 | 2016-11-14 21:40:26 +0100 | [diff] [blame] | 28 | #include <dm.h> |
| 29 | #include <dm/platform_data/serial_pxa.h> |
Marek Vasut | bc53d14 | 2012-09-12 12:26:30 +0200 | [diff] [blame] | 30 | #include <linux/compiler.h> |
Marcel Ziswiler | 7cfcbee | 2015-08-16 04:16:29 +0200 | [diff] [blame] | 31 | #include <serial.h> |
| 32 | #include <watchdog.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 33 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 34 | DECLARE_GLOBAL_DATA_PTR; |
| 35 | |
Marcel Ziswiler | 90392d0 | 2016-11-14 21:40:26 +0100 | [diff] [blame] | 36 | static uint32_t pxa_uart_get_baud_divider(int baudrate) |
Marek Vasut | ac737ff | 2011-08-28 03:35:13 +0200 | [diff] [blame] | 37 | { |
Marcel Ziswiler | 90392d0 | 2016-11-14 21:40:26 +0100 | [diff] [blame] | 38 | return 921600 / baudrate; |
Marek Vasut | ac737ff | 2011-08-28 03:35:13 +0200 | [diff] [blame] | 39 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 40 | |
Marek Vasut | bcf4872 | 2012-09-12 12:59:42 +0200 | [diff] [blame] | 41 | static void pxa_uart_toggle_clock(uint32_t uart_index, int enable) |
Marek Vasut | ac737ff | 2011-08-28 03:35:13 +0200 | [diff] [blame] | 42 | { |
| 43 | uint32_t clk_reg, clk_offset, reg; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 44 | |
Marek Vasut | ac737ff | 2011-08-28 03:35:13 +0200 | [diff] [blame] | 45 | clk_reg = UART_CLK_REG; |
| 46 | clk_offset = UART_CLK_BASE << uart_index; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 47 | |
Marek Vasut | ac737ff | 2011-08-28 03:35:13 +0200 | [diff] [blame] | 48 | reg = readl(clk_reg); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 49 | |
Marek Vasut | ac737ff | 2011-08-28 03:35:13 +0200 | [diff] [blame] | 50 | if (enable) |
| 51 | reg |= clk_offset; |
| 52 | else |
| 53 | reg &= ~clk_offset; |
wdenk | b02744a | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 54 | |
Marek Vasut | ac737ff | 2011-08-28 03:35:13 +0200 | [diff] [blame] | 55 | writel(reg, clk_reg); |
| 56 | } |
wdenk | b02744a | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 57 | |
Marek Vasut | ac737ff | 2011-08-28 03:35:13 +0200 | [diff] [blame] | 58 | /* |
| 59 | * Enable clock and set baud rate, parity etc. |
| 60 | */ |
Marcel Ziswiler | 90392d0 | 2016-11-14 21:40:26 +0100 | [diff] [blame] | 61 | void pxa_setbrg_common(struct pxa_uart_regs *uart_regs, int port, int baudrate) |
Marek Vasut | ac737ff | 2011-08-28 03:35:13 +0200 | [diff] [blame] | 62 | { |
Marcel Ziswiler | 90392d0 | 2016-11-14 21:40:26 +0100 | [diff] [blame] | 63 | uint32_t divider = pxa_uart_get_baud_divider(baudrate); |
Marek Vasut | ac737ff | 2011-08-28 03:35:13 +0200 | [diff] [blame] | 64 | if (!divider) |
| 65 | hang(); |
stefano babic | 5ab4f03 | 2007-08-30 22:57:04 +0200 | [diff] [blame] | 66 | |
wdenk | 5958f4a | 2003-09-18 09:21:33 +0000 | [diff] [blame] | 67 | |
Marcel Ziswiler | 90392d0 | 2016-11-14 21:40:26 +0100 | [diff] [blame] | 68 | pxa_uart_toggle_clock(port, 1); |
wdenk | 5958f4a | 2003-09-18 09:21:33 +0000 | [diff] [blame] | 69 | |
Marek Vasut | ac737ff | 2011-08-28 03:35:13 +0200 | [diff] [blame] | 70 | /* Disable interrupts and FIFOs */ |
| 71 | writel(0, &uart_regs->ier); |
| 72 | writel(0, &uart_regs->fcr); |
wdenk | 5958f4a | 2003-09-18 09:21:33 +0000 | [diff] [blame] | 73 | |
Marek Vasut | ac737ff | 2011-08-28 03:35:13 +0200 | [diff] [blame] | 74 | /* Set baud rate */ |
| 75 | writel(LCR_WLS0 | LCR_WLS1 | LCR_DLAB, &uart_regs->lcr); |
| 76 | writel(divider & 0xff, &uart_regs->dll); |
| 77 | writel(divider >> 8, &uart_regs->dlh); |
| 78 | writel(LCR_WLS0 | LCR_WLS1, &uart_regs->lcr); |
wdenk | 5958f4a | 2003-09-18 09:21:33 +0000 | [diff] [blame] | 79 | |
Marek Vasut | ac737ff | 2011-08-28 03:35:13 +0200 | [diff] [blame] | 80 | /* Enable UART */ |
| 81 | writel(IER_UUE, &uart_regs->ier); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 82 | } |
| 83 | |
Marcel Ziswiler | 90392d0 | 2016-11-14 21:40:26 +0100 | [diff] [blame] | 84 | #ifndef CONFIG_DM_SERIAL |
| 85 | static struct pxa_uart_regs *pxa_uart_index_to_regs(uint32_t uart_index) |
| 86 | { |
| 87 | switch (uart_index) { |
| 88 | case FFUART_INDEX: return (struct pxa_uart_regs *)FFUART_BASE; |
| 89 | case BTUART_INDEX: return (struct pxa_uart_regs *)BTUART_BASE; |
| 90 | case STUART_INDEX: return (struct pxa_uart_regs *)STUART_BASE; |
| 91 | case HWUART_INDEX: return (struct pxa_uart_regs *)HWUART_BASE; |
| 92 | default: |
| 93 | return NULL; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | /* |
| 98 | * Enable clock and set baud rate, parity etc. |
| 99 | */ |
| 100 | void pxa_setbrg_dev(uint32_t uart_index) |
| 101 | { |
| 102 | struct pxa_uart_regs *uart_regs = pxa_uart_index_to_regs(uart_index); |
| 103 | if (!uart_regs) |
| 104 | panic("Failed getting UART registers\n"); |
| 105 | |
| 106 | pxa_setbrg_common(uart_regs, uart_index, gd->baudrate); |
| 107 | } |
| 108 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 109 | /* |
| 110 | * Initialise the serial port with the given baudrate. The settings |
| 111 | * are always 8 data bits, no parity, 1 stop bit, no start bits. |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 112 | */ |
Marek Vasut | ac737ff | 2011-08-28 03:35:13 +0200 | [diff] [blame] | 113 | int pxa_init_dev(unsigned int uart_index) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 114 | { |
Marcel Ziswiler | 90392d0 | 2016-11-14 21:40:26 +0100 | [diff] [blame] | 115 | pxa_setbrg_dev(uart_index); |
Marek Vasut | ac737ff | 2011-08-28 03:35:13 +0200 | [diff] [blame] | 116 | return 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 117 | } |
| 118 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 119 | /* |
| 120 | * Output a single byte to the serial port. |
| 121 | */ |
Marek Vasut | ac737ff | 2011-08-28 03:35:13 +0200 | [diff] [blame] | 122 | void pxa_putc_dev(unsigned int uart_index, const char c) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 123 | { |
Marek Vasut | ac737ff | 2011-08-28 03:35:13 +0200 | [diff] [blame] | 124 | struct pxa_uart_regs *uart_regs; |
stefano babic | 5ab4f03 | 2007-08-30 22:57:04 +0200 | [diff] [blame] | 125 | |
Alison Wang | 23e06b5 | 2016-03-02 11:00:37 +0800 | [diff] [blame] | 126 | /* If \n, also do \r */ |
| 127 | if (c == '\n') |
| 128 | pxa_putc_dev(uart_index, '\r'); |
| 129 | |
Marek Vasut | ac737ff | 2011-08-28 03:35:13 +0200 | [diff] [blame] | 130 | uart_regs = pxa_uart_index_to_regs(uart_index); |
| 131 | if (!uart_regs) |
| 132 | hang(); |
stefano babic | 5ab4f03 | 2007-08-30 22:57:04 +0200 | [diff] [blame] | 133 | |
Marek Vasut | ac737ff | 2011-08-28 03:35:13 +0200 | [diff] [blame] | 134 | while (!(readl(&uart_regs->lsr) & LSR_TEMT)) |
| 135 | WATCHDOG_RESET(); |
| 136 | writel(c, &uart_regs->thr); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | /* |
| 140 | * Read a single byte from the serial port. Returns 1 on success, 0 |
| 141 | * otherwise. When the function is succesfull, the character read is |
| 142 | * written into its argument c. |
| 143 | */ |
Marek Vasut | ac737ff | 2011-08-28 03:35:13 +0200 | [diff] [blame] | 144 | int pxa_tstc_dev(unsigned int uart_index) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 145 | { |
Marek Vasut | ac737ff | 2011-08-28 03:35:13 +0200 | [diff] [blame] | 146 | struct pxa_uart_regs *uart_regs; |
| 147 | |
| 148 | uart_regs = pxa_uart_index_to_regs(uart_index); |
| 149 | if (!uart_regs) |
| 150 | return -1; |
| 151 | |
| 152 | return readl(&uart_regs->lsr) & LSR_DR; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | /* |
| 156 | * Read a single byte from the serial port. Returns 1 on success, 0 |
| 157 | * otherwise. When the function is succesfull, the character read is |
| 158 | * written into its argument c. |
| 159 | */ |
Marek Vasut | ac737ff | 2011-08-28 03:35:13 +0200 | [diff] [blame] | 160 | int pxa_getc_dev(unsigned int uart_index) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 161 | { |
Marek Vasut | ac737ff | 2011-08-28 03:35:13 +0200 | [diff] [blame] | 162 | struct pxa_uart_regs *uart_regs; |
stefano babic | 5ab4f03 | 2007-08-30 22:57:04 +0200 | [diff] [blame] | 163 | |
Marek Vasut | ac737ff | 2011-08-28 03:35:13 +0200 | [diff] [blame] | 164 | uart_regs = pxa_uart_index_to_regs(uart_index); |
| 165 | if (!uart_regs) |
| 166 | return -1; |
stefano babic | 5ab4f03 | 2007-08-30 22:57:04 +0200 | [diff] [blame] | 167 | |
Marek Vasut | ac737ff | 2011-08-28 03:35:13 +0200 | [diff] [blame] | 168 | while (!(readl(&uart_regs->lsr) & LSR_DR)) |
| 169 | WATCHDOG_RESET(); |
| 170 | return readl(&uart_regs->rbr) & 0xff; |
stefano babic | 5ab4f03 | 2007-08-30 22:57:04 +0200 | [diff] [blame] | 171 | } |
| 172 | |
Marek Vasut | ac737ff | 2011-08-28 03:35:13 +0200 | [diff] [blame] | 173 | void pxa_puts_dev(unsigned int uart_index, const char *s) |
stefano babic | 5ab4f03 | 2007-08-30 22:57:04 +0200 | [diff] [blame] | 174 | { |
Marek Vasut | ac737ff | 2011-08-28 03:35:13 +0200 | [diff] [blame] | 175 | while (*s) |
| 176 | pxa_putc_dev(uart_index, *s++); |
stefano babic | 5ab4f03 | 2007-08-30 22:57:04 +0200 | [diff] [blame] | 177 | } |
| 178 | |
Marek Vasut | ac737ff | 2011-08-28 03:35:13 +0200 | [diff] [blame] | 179 | #define pxa_uart(uart, UART) \ |
| 180 | int uart##_init(void) \ |
| 181 | { \ |
| 182 | return pxa_init_dev(UART##_INDEX); \ |
| 183 | } \ |
| 184 | \ |
| 185 | void uart##_setbrg(void) \ |
| 186 | { \ |
| 187 | return pxa_setbrg_dev(UART##_INDEX); \ |
| 188 | } \ |
| 189 | \ |
| 190 | void uart##_putc(const char c) \ |
| 191 | { \ |
| 192 | return pxa_putc_dev(UART##_INDEX, c); \ |
| 193 | } \ |
| 194 | \ |
| 195 | void uart##_puts(const char *s) \ |
| 196 | { \ |
| 197 | return pxa_puts_dev(UART##_INDEX, s); \ |
| 198 | } \ |
| 199 | \ |
| 200 | int uart##_getc(void) \ |
| 201 | { \ |
| 202 | return pxa_getc_dev(UART##_INDEX); \ |
| 203 | } \ |
| 204 | \ |
| 205 | int uart##_tstc(void) \ |
| 206 | { \ |
| 207 | return pxa_tstc_dev(UART##_INDEX); \ |
| 208 | } \ |
stefano babic | 5ab4f03 | 2007-08-30 22:57:04 +0200 | [diff] [blame] | 209 | |
Marek Vasut | ac737ff | 2011-08-28 03:35:13 +0200 | [diff] [blame] | 210 | #define pxa_uart_desc(uart) \ |
| 211 | struct serial_device serial_##uart##_device = \ |
| 212 | { \ |
Marek Vasut | 5bcdf24 | 2012-09-09 18:48:28 +0200 | [diff] [blame] | 213 | .name = "serial_"#uart, \ |
| 214 | .start = uart##_init, \ |
| 215 | .stop = NULL, \ |
| 216 | .setbrg = uart##_setbrg, \ |
| 217 | .getc = uart##_getc, \ |
| 218 | .tstc = uart##_tstc, \ |
| 219 | .putc = uart##_putc, \ |
| 220 | .puts = uart##_puts, \ |
Marek Vasut | ac737ff | 2011-08-28 03:35:13 +0200 | [diff] [blame] | 221 | }; |
stefano babic | 5ab4f03 | 2007-08-30 22:57:04 +0200 | [diff] [blame] | 222 | |
Marek Vasut | ac737ff | 2011-08-28 03:35:13 +0200 | [diff] [blame] | 223 | #define pxa_uart_multi(uart, UART) \ |
| 224 | pxa_uart(uart, UART) \ |
| 225 | pxa_uart_desc(uart) |
stefano babic | 5ab4f03 | 2007-08-30 22:57:04 +0200 | [diff] [blame] | 226 | |
Marek Vasut | ac737ff | 2011-08-28 03:35:13 +0200 | [diff] [blame] | 227 | #if defined(CONFIG_HWUART) |
| 228 | pxa_uart_multi(hwuart, HWUART) |
stefano babic | 5ab4f03 | 2007-08-30 22:57:04 +0200 | [diff] [blame] | 229 | #endif |
Marek Vasut | ac737ff | 2011-08-28 03:35:13 +0200 | [diff] [blame] | 230 | #if defined(CONFIG_STUART) |
| 231 | pxa_uart_multi(stuart, STUART) |
stefano babic | 5ab4f03 | 2007-08-30 22:57:04 +0200 | [diff] [blame] | 232 | #endif |
Marek Vasut | ac737ff | 2011-08-28 03:35:13 +0200 | [diff] [blame] | 233 | #if defined(CONFIG_FFUART) |
| 234 | pxa_uart_multi(ffuart, FFUART) |
stefano babic | 5ab4f03 | 2007-08-30 22:57:04 +0200 | [diff] [blame] | 235 | #endif |
Marek Vasut | ac737ff | 2011-08-28 03:35:13 +0200 | [diff] [blame] | 236 | #if defined(CONFIG_BTUART) |
| 237 | pxa_uart_multi(btuart, BTUART) |
| 238 | #endif |
stefano babic | 5ab4f03 | 2007-08-30 22:57:04 +0200 | [diff] [blame] | 239 | |
Marek Vasut | bc53d14 | 2012-09-12 12:26:30 +0200 | [diff] [blame] | 240 | __weak struct serial_device *default_serial_console(void) |
| 241 | { |
| 242 | #if CONFIG_CONS_INDEX == 1 |
| 243 | return &serial_hwuart_device; |
| 244 | #elif CONFIG_CONS_INDEX == 2 |
| 245 | return &serial_stuart_device; |
| 246 | #elif CONFIG_CONS_INDEX == 3 |
| 247 | return &serial_ffuart_device; |
| 248 | #elif CONFIG_CONS_INDEX == 4 |
| 249 | return &serial_btuart_device; |
| 250 | #else |
| 251 | #error "Bad CONFIG_CONS_INDEX." |
| 252 | #endif |
| 253 | } |
Marek Vasut | f344201 | 2012-09-12 13:57:58 +0200 | [diff] [blame] | 254 | |
| 255 | void pxa_serial_initialize(void) |
| 256 | { |
| 257 | #if defined(CONFIG_FFUART) |
| 258 | serial_register(&serial_ffuart_device); |
| 259 | #endif |
| 260 | #if defined(CONFIG_BTUART) |
| 261 | serial_register(&serial_btuart_device); |
| 262 | #endif |
| 263 | #if defined(CONFIG_STUART) |
| 264 | serial_register(&serial_stuart_device); |
| 265 | #endif |
| 266 | } |
Marcel Ziswiler | 90392d0 | 2016-11-14 21:40:26 +0100 | [diff] [blame] | 267 | #endif /* CONFIG_DM_SERIAL */ |
| 268 | |
| 269 | #ifdef CONFIG_DM_SERIAL |
| 270 | static int pxa_serial_probe(struct udevice *dev) |
| 271 | { |
Simon Glass | 9558862 | 2020-12-22 19:30:28 -0700 | [diff] [blame] | 272 | struct pxa_serial_plat *plat = dev_get_plat(dev); |
Marcel Ziswiler | 90392d0 | 2016-11-14 21:40:26 +0100 | [diff] [blame] | 273 | |
| 274 | pxa_setbrg_common((struct pxa_uart_regs *)plat->base, plat->port, |
| 275 | plat->baudrate); |
| 276 | return 0; |
| 277 | } |
| 278 | |
| 279 | static int pxa_serial_putc(struct udevice *dev, const char ch) |
| 280 | { |
Simon Glass | 9558862 | 2020-12-22 19:30:28 -0700 | [diff] [blame] | 281 | struct pxa_serial_plat *plat = dev_get_plat(dev); |
Marcel Ziswiler | 90392d0 | 2016-11-14 21:40:26 +0100 | [diff] [blame] | 282 | struct pxa_uart_regs *uart_regs = (struct pxa_uart_regs *)plat->base; |
| 283 | |
| 284 | /* Wait for last character to go. */ |
| 285 | if (!(readl(&uart_regs->lsr) & LSR_TEMT)) |
| 286 | return -EAGAIN; |
| 287 | |
| 288 | writel(ch, &uart_regs->thr); |
| 289 | |
| 290 | return 0; |
| 291 | } |
| 292 | |
| 293 | static int pxa_serial_getc(struct udevice *dev) |
| 294 | { |
Simon Glass | 9558862 | 2020-12-22 19:30:28 -0700 | [diff] [blame] | 295 | struct pxa_serial_plat *plat = dev_get_plat(dev); |
Marcel Ziswiler | 90392d0 | 2016-11-14 21:40:26 +0100 | [diff] [blame] | 296 | struct pxa_uart_regs *uart_regs = (struct pxa_uart_regs *)plat->base; |
| 297 | |
| 298 | /* Wait for a character to arrive. */ |
| 299 | if (!(readl(&uart_regs->lsr) & LSR_DR)) |
| 300 | return -EAGAIN; |
| 301 | |
| 302 | return readl(&uart_regs->rbr) & 0xff; |
| 303 | } |
| 304 | |
| 305 | int pxa_serial_setbrg(struct udevice *dev, int baudrate) |
| 306 | { |
Simon Glass | 9558862 | 2020-12-22 19:30:28 -0700 | [diff] [blame] | 307 | struct pxa_serial_plat *plat = dev_get_plat(dev); |
Marcel Ziswiler | 90392d0 | 2016-11-14 21:40:26 +0100 | [diff] [blame] | 308 | struct pxa_uart_regs *uart_regs = (struct pxa_uart_regs *)plat->base; |
| 309 | int port = plat->port; |
| 310 | |
| 311 | pxa_setbrg_common(uart_regs, port, baudrate); |
| 312 | |
| 313 | return 0; |
| 314 | } |
| 315 | |
| 316 | static int pxa_serial_pending(struct udevice *dev, bool input) |
| 317 | { |
Simon Glass | 9558862 | 2020-12-22 19:30:28 -0700 | [diff] [blame] | 318 | struct pxa_serial_plat *plat = dev_get_plat(dev); |
Marcel Ziswiler | 90392d0 | 2016-11-14 21:40:26 +0100 | [diff] [blame] | 319 | struct pxa_uart_regs *uart_regs = (struct pxa_uart_regs *)plat->base; |
| 320 | |
| 321 | if (input) |
| 322 | return readl(&uart_regs->lsr) & LSR_DR ? 1 : 0; |
| 323 | else |
| 324 | return readl(&uart_regs->lsr) & LSR_TEMT ? 0 : 1; |
| 325 | |
| 326 | return 0; |
| 327 | } |
| 328 | |
| 329 | static const struct dm_serial_ops pxa_serial_ops = { |
| 330 | .putc = pxa_serial_putc, |
| 331 | .pending = pxa_serial_pending, |
| 332 | .getc = pxa_serial_getc, |
| 333 | .setbrg = pxa_serial_setbrg, |
| 334 | }; |
| 335 | |
| 336 | U_BOOT_DRIVER(serial_pxa) = { |
| 337 | .name = "serial_pxa", |
| 338 | .id = UCLASS_SERIAL, |
| 339 | .probe = pxa_serial_probe, |
| 340 | .ops = &pxa_serial_ops, |
| 341 | .flags = DM_FLAG_PRE_RELOC, |
| 342 | }; |
| 343 | #endif /* CONFIG_DM_SERIAL */ |