wdenk | 4989f87 | 2004-03-14 15:06:13 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2000 |
| 3 | * Rob Taylor, Flying Pig Systems. robt@flyingpig.com. |
| 4 | * |
| 5 | * (C) Copyright 2004 |
| 6 | * ARM Ltd. |
| 7 | * Philippe Robin, <philippe.robin@arm.com> |
| 8 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 9 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 4989f87 | 2004-03-14 15:06:13 +0000 | [diff] [blame] | 10 | */ |
| 11 | |
Andreas Engel | 0813b12 | 2008-09-08 14:30:53 +0200 | [diff] [blame] | 12 | /* Simple U-Boot driver for the PrimeCell PL010/PL011 UARTs */ |
wdenk | 4989f87 | 2004-03-14 15:06:13 +0000 | [diff] [blame] | 13 | |
| 14 | #include <common.h> |
Simon Glass | 3ad93fe | 2014-09-22 17:30:58 -0600 | [diff] [blame] | 15 | #include <dm.h> |
Simon Glass | f35484d | 2014-09-22 17:30:57 -0600 | [diff] [blame] | 16 | #include <errno.h> |
Stuart Wood | 26136ef | 2008-06-02 16:42:19 -0400 | [diff] [blame] | 17 | #include <watchdog.h> |
Matt Waddel | d6ce53e | 2010-10-07 15:48:46 -0600 | [diff] [blame] | 18 | #include <asm/io.h> |
Marek Vasut | 46e4d5f | 2012-09-14 22:38:46 +0200 | [diff] [blame] | 19 | #include <serial.h> |
Masahiro Yamada | 22c97de | 2014-10-24 12:41:19 +0900 | [diff] [blame] | 20 | #include <dm/platform_data/serial_pl01x.h> |
Marek Vasut | 46e4d5f | 2012-09-14 22:38:46 +0200 | [diff] [blame] | 21 | #include <linux/compiler.h> |
Simon Glass | f35484d | 2014-09-22 17:30:57 -0600 | [diff] [blame] | 22 | #include "serial_pl01x_internal.h" |
Vikas Manocha | 92e349e | 2015-05-06 11:46:29 -0700 | [diff] [blame] | 23 | #include <fdtdec.h> |
| 24 | |
| 25 | DECLARE_GLOBAL_DATA_PTR; |
wdenk | 4989f87 | 2004-03-14 15:06:13 +0000 | [diff] [blame] | 26 | |
Simon Glass | 3ad93fe | 2014-09-22 17:30:58 -0600 | [diff] [blame] | 27 | #ifndef CONFIG_DM_SERIAL |
| 28 | |
wdenk | da04a8b | 2004-08-02 23:22:59 +0000 | [diff] [blame] | 29 | static volatile unsigned char *const port[] = CONFIG_PL01x_PORTS; |
Simon Glass | f35484d | 2014-09-22 17:30:57 -0600 | [diff] [blame] | 30 | static enum pl01x_type pl01x_type __attribute__ ((section(".data"))); |
| 31 | static struct pl01x_regs *base_regs __attribute__ ((section(".data"))); |
wdenk | da04a8b | 2004-08-02 23:22:59 +0000 | [diff] [blame] | 32 | #define NUM_PORTS (sizeof(port)/sizeof(port[0])) |
wdenk | 4989f87 | 2004-03-14 15:06:13 +0000 | [diff] [blame] | 33 | |
Simon Glass | 3ad93fe | 2014-09-22 17:30:58 -0600 | [diff] [blame] | 34 | #endif |
wdenk | 4989f87 | 2004-03-14 15:06:13 +0000 | [diff] [blame] | 35 | |
Simon Glass | f35484d | 2014-09-22 17:30:57 -0600 | [diff] [blame] | 36 | static int pl01x_putc(struct pl01x_regs *regs, char c) |
wdenk | 4989f87 | 2004-03-14 15:06:13 +0000 | [diff] [blame] | 37 | { |
Simon Glass | f35484d | 2014-09-22 17:30:57 -0600 | [diff] [blame] | 38 | /* Wait until there is space in the FIFO */ |
| 39 | if (readl(®s->fr) & UART_PL01x_FR_TXFF) |
| 40 | return -EAGAIN; |
wdenk | 4989f87 | 2004-03-14 15:06:13 +0000 | [diff] [blame] | 41 | |
Simon Glass | f35484d | 2014-09-22 17:30:57 -0600 | [diff] [blame] | 42 | /* Send the character */ |
| 43 | writel(c, ®s->dr); |
wdenk | 4989f87 | 2004-03-14 15:06:13 +0000 | [diff] [blame] | 44 | |
Simon Glass | f35484d | 2014-09-22 17:30:57 -0600 | [diff] [blame] | 45 | return 0; |
| 46 | } |
wdenk | 4989f87 | 2004-03-14 15:06:13 +0000 | [diff] [blame] | 47 | |
Simon Glass | f35484d | 2014-09-22 17:30:57 -0600 | [diff] [blame] | 48 | static int pl01x_getc(struct pl01x_regs *regs) |
| 49 | { |
| 50 | unsigned int data; |
wdenk | 4989f87 | 2004-03-14 15:06:13 +0000 | [diff] [blame] | 51 | |
Simon Glass | f35484d | 2014-09-22 17:30:57 -0600 | [diff] [blame] | 52 | /* Wait until there is data in the FIFO */ |
| 53 | if (readl(®s->fr) & UART_PL01x_FR_RXFE) |
| 54 | return -EAGAIN; |
wdenk | 4989f87 | 2004-03-14 15:06:13 +0000 | [diff] [blame] | 55 | |
Simon Glass | f35484d | 2014-09-22 17:30:57 -0600 | [diff] [blame] | 56 | data = readl(®s->dr); |
wdenk | 4989f87 | 2004-03-14 15:06:13 +0000 | [diff] [blame] | 57 | |
Simon Glass | f35484d | 2014-09-22 17:30:57 -0600 | [diff] [blame] | 58 | /* Check for an error flag */ |
| 59 | if (data & 0xFFFFFF00) { |
| 60 | /* Clear the error */ |
| 61 | writel(0xFFFFFFFF, ®s->ecr); |
| 62 | return -1; |
wdenk | c35ba4e | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 63 | } |
| 64 | |
Simon Glass | f35484d | 2014-09-22 17:30:57 -0600 | [diff] [blame] | 65 | return (int) data; |
wdenk | 4989f87 | 2004-03-14 15:06:13 +0000 | [diff] [blame] | 66 | } |
| 67 | |
Simon Glass | f35484d | 2014-09-22 17:30:57 -0600 | [diff] [blame] | 68 | static int pl01x_tstc(struct pl01x_regs *regs) |
| 69 | { |
| 70 | WATCHDOG_RESET(); |
| 71 | return !(readl(®s->fr) & UART_PL01x_FR_RXFE); |
| 72 | } |
Andreas Engel | 8043861 | 2008-09-08 10:17:31 +0200 | [diff] [blame] | 73 | |
Simon Glass | f35484d | 2014-09-22 17:30:57 -0600 | [diff] [blame] | 74 | static int pl01x_generic_serial_init(struct pl01x_regs *regs, |
| 75 | enum pl01x_type type) |
Andreas Engel | 8043861 | 2008-09-08 10:17:31 +0200 | [diff] [blame] | 76 | { |
Vikas Manocha | be14f15 | 2014-11-21 10:34:23 -0800 | [diff] [blame] | 77 | switch (type) { |
| 78 | case TYPE_PL010: |
| 79 | /* disable everything */ |
| 80 | writel(0, ®s->pl010_cr); |
| 81 | break; |
| 82 | case TYPE_PL011: |
John Rigby | 34e21ee | 2011-04-19 10:42:39 +0000 | [diff] [blame] | 83 | #ifdef CONFIG_PL011_SERIAL_FLUSH_ON_INIT |
Simon Glass | f35484d | 2014-09-22 17:30:57 -0600 | [diff] [blame] | 84 | /* Empty RX fifo if necessary */ |
| 85 | if (readl(®s->pl011_cr) & UART_PL011_CR_UARTEN) { |
| 86 | while (!(readl(®s->fr) & UART_PL01x_FR_RXFE)) |
| 87 | readl(®s->dr); |
| 88 | } |
John Rigby | 34e21ee | 2011-04-19 10:42:39 +0000 | [diff] [blame] | 89 | #endif |
Vikas Manocha | ee038e2 | 2014-11-21 10:34:22 -0800 | [diff] [blame] | 90 | /* disable everything */ |
| 91 | writel(0, ®s->pl011_cr); |
Vikas Manocha | fe96bbd | 2014-11-21 10:34:21 -0800 | [diff] [blame] | 92 | break; |
| 93 | default: |
| 94 | return -EINVAL; |
| 95 | } |
| 96 | |
| 97 | return 0; |
| 98 | } |
| 99 | |
Linus Walleij | 70864f6 | 2015-04-21 15:10:06 +0200 | [diff] [blame] | 100 | static int pl011_set_line_control(struct pl01x_regs *regs) |
Vikas Manocha | fe96bbd | 2014-11-21 10:34:21 -0800 | [diff] [blame] | 101 | { |
| 102 | unsigned int lcr; |
| 103 | /* |
| 104 | * Internal update of baud rate register require line |
| 105 | * control register write |
| 106 | */ |
| 107 | lcr = UART_PL011_LCRH_WLEN_8 | UART_PL011_LCRH_FEN; |
John Rigby | 34e21ee | 2011-04-19 10:42:39 +0000 | [diff] [blame] | 108 | #ifdef CONFIG_PL011_SERIAL_RLCR |
Vikas Manocha | fe96bbd | 2014-11-21 10:34:21 -0800 | [diff] [blame] | 109 | { |
John Rigby | 34e21ee | 2011-04-19 10:42:39 +0000 | [diff] [blame] | 110 | int i; |
| 111 | |
| 112 | /* |
| 113 | * Program receive line control register after waiting |
| 114 | * 10 bus cycles. Delay be writing to readonly register |
| 115 | * 10 times |
| 116 | */ |
| 117 | for (i = 0; i < 10; i++) |
| 118 | writel(lcr, ®s->fr); |
Andreas Engel | 8043861 | 2008-09-08 10:17:31 +0200 | [diff] [blame] | 119 | |
John Rigby | 34e21ee | 2011-04-19 10:42:39 +0000 | [diff] [blame] | 120 | writel(lcr, ®s->pl011_rlcr); |
Simon Glass | f35484d | 2014-09-22 17:30:57 -0600 | [diff] [blame] | 121 | } |
Vikas Manocha | fe96bbd | 2014-11-21 10:34:21 -0800 | [diff] [blame] | 122 | #endif |
| 123 | writel(lcr, ®s->pl011_lcrh); |
Andreas Engel | 8043861 | 2008-09-08 10:17:31 +0200 | [diff] [blame] | 124 | return 0; |
| 125 | } |
| 126 | |
Simon Glass | f35484d | 2014-09-22 17:30:57 -0600 | [diff] [blame] | 127 | static int pl01x_generic_setbrg(struct pl01x_regs *regs, enum pl01x_type type, |
| 128 | int clock, int baudrate) |
wdenk | 4989f87 | 2004-03-14 15:06:13 +0000 | [diff] [blame] | 129 | { |
Simon Glass | f35484d | 2014-09-22 17:30:57 -0600 | [diff] [blame] | 130 | switch (type) { |
| 131 | case TYPE_PL010: { |
| 132 | unsigned int divisor; |
wdenk | 4989f87 | 2004-03-14 15:06:13 +0000 | [diff] [blame] | 133 | |
Linus Walleij | 70864f6 | 2015-04-21 15:10:06 +0200 | [diff] [blame] | 134 | /* disable everything */ |
| 135 | writel(0, ®s->pl010_cr); |
| 136 | |
Simon Glass | f35484d | 2014-09-22 17:30:57 -0600 | [diff] [blame] | 137 | switch (baudrate) { |
| 138 | case 9600: |
| 139 | divisor = UART_PL010_BAUD_9600; |
| 140 | break; |
| 141 | case 19200: |
| 142 | divisor = UART_PL010_BAUD_9600; |
| 143 | break; |
| 144 | case 38400: |
| 145 | divisor = UART_PL010_BAUD_38400; |
| 146 | break; |
| 147 | case 57600: |
| 148 | divisor = UART_PL010_BAUD_57600; |
| 149 | break; |
| 150 | case 115200: |
| 151 | divisor = UART_PL010_BAUD_115200; |
| 152 | break; |
| 153 | default: |
| 154 | divisor = UART_PL010_BAUD_38400; |
| 155 | } |
wdenk | 4989f87 | 2004-03-14 15:06:13 +0000 | [diff] [blame] | 156 | |
Simon Glass | f35484d | 2014-09-22 17:30:57 -0600 | [diff] [blame] | 157 | writel((divisor & 0xf00) >> 8, ®s->pl010_lcrm); |
| 158 | writel(divisor & 0xff, ®s->pl010_lcrl); |
| 159 | |
Linus Walleij | 70864f6 | 2015-04-21 15:10:06 +0200 | [diff] [blame] | 160 | /* |
| 161 | * Set line control for the PL010 to be 8 bits, 1 stop bit, |
| 162 | * no parity, fifo enabled |
| 163 | */ |
| 164 | writel(UART_PL010_LCRH_WLEN_8 | UART_PL010_LCRH_FEN, |
| 165 | ®s->pl010_lcrh); |
Simon Glass | f35484d | 2014-09-22 17:30:57 -0600 | [diff] [blame] | 166 | /* Finally, enable the UART */ |
| 167 | writel(UART_PL010_CR_UARTEN, ®s->pl010_cr); |
| 168 | break; |
| 169 | } |
| 170 | case TYPE_PL011: { |
| 171 | unsigned int temp; |
| 172 | unsigned int divider; |
| 173 | unsigned int remainder; |
| 174 | unsigned int fraction; |
| 175 | |
| 176 | /* |
| 177 | * Set baud rate |
| 178 | * |
| 179 | * IBRD = UART_CLK / (16 * BAUD_RATE) |
| 180 | * FBRD = RND((64 * MOD(UART_CLK,(16 * BAUD_RATE))) |
| 181 | * / (16 * BAUD_RATE)) |
| 182 | */ |
| 183 | temp = 16 * baudrate; |
| 184 | divider = clock / temp; |
| 185 | remainder = clock % temp; |
| 186 | temp = (8 * remainder) / baudrate; |
| 187 | fraction = (temp >> 1) + (temp & 1); |
| 188 | |
| 189 | writel(divider, ®s->pl011_ibrd); |
| 190 | writel(fraction, ®s->pl011_fbrd); |
| 191 | |
Linus Walleij | 70864f6 | 2015-04-21 15:10:06 +0200 | [diff] [blame] | 192 | pl011_set_line_control(regs); |
Simon Glass | f35484d | 2014-09-22 17:30:57 -0600 | [diff] [blame] | 193 | /* Finally, enable the UART */ |
| 194 | writel(UART_PL011_CR_UARTEN | UART_PL011_CR_TXE | |
| 195 | UART_PL011_CR_RXE | UART_PL011_CR_RTS, ®s->pl011_cr); |
| 196 | break; |
| 197 | } |
| 198 | default: |
| 199 | return -EINVAL; |
| 200 | } |
| 201 | |
| 202 | return 0; |
wdenk | 4989f87 | 2004-03-14 15:06:13 +0000 | [diff] [blame] | 203 | } |
| 204 | |
Simon Glass | f35484d | 2014-09-22 17:30:57 -0600 | [diff] [blame] | 205 | #ifndef CONFIG_DM_SERIAL |
| 206 | static void pl01x_serial_init_baud(int baudrate) |
wdenk | 4989f87 | 2004-03-14 15:06:13 +0000 | [diff] [blame] | 207 | { |
Simon Glass | f35484d | 2014-09-22 17:30:57 -0600 | [diff] [blame] | 208 | int clock = 0; |
| 209 | |
| 210 | #if defined(CONFIG_PL010_SERIAL) |
| 211 | pl01x_type = TYPE_PL010; |
| 212 | #elif defined(CONFIG_PL011_SERIAL) |
| 213 | pl01x_type = TYPE_PL011; |
| 214 | clock = CONFIG_PL011_CLOCK; |
| 215 | #endif |
| 216 | base_regs = (struct pl01x_regs *)port[CONFIG_CONS_INDEX]; |
| 217 | |
| 218 | pl01x_generic_serial_init(base_regs, pl01x_type); |
Vikas Manocha | aac2396 | 2014-11-21 10:34:19 -0800 | [diff] [blame] | 219 | pl01x_generic_setbrg(base_regs, pl01x_type, clock, baudrate); |
wdenk | 4989f87 | 2004-03-14 15:06:13 +0000 | [diff] [blame] | 220 | } |
| 221 | |
Simon Glass | f35484d | 2014-09-22 17:30:57 -0600 | [diff] [blame] | 222 | /* |
| 223 | * Integrator AP has two UARTs, we use the first one, at 38400-8-N-1 |
| 224 | * Integrator CP has two UARTs, use the first one, at 38400-8-N-1 |
| 225 | * Versatile PB has four UARTs. |
| 226 | */ |
| 227 | int pl01x_serial_init(void) |
wdenk | 4989f87 | 2004-03-14 15:06:13 +0000 | [diff] [blame] | 228 | { |
Simon Glass | f35484d | 2014-09-22 17:30:57 -0600 | [diff] [blame] | 229 | pl01x_serial_init_baud(CONFIG_BAUDRATE); |
Linus Walleij | b8058e8 | 2011-10-02 11:52:52 +0000 | [diff] [blame] | 230 | |
Simon Glass | f35484d | 2014-09-22 17:30:57 -0600 | [diff] [blame] | 231 | return 0; |
wdenk | 4989f87 | 2004-03-14 15:06:13 +0000 | [diff] [blame] | 232 | } |
| 233 | |
Simon Glass | f35484d | 2014-09-22 17:30:57 -0600 | [diff] [blame] | 234 | static void pl01x_serial_putc(const char c) |
wdenk | 4989f87 | 2004-03-14 15:06:13 +0000 | [diff] [blame] | 235 | { |
Simon Glass | f35484d | 2014-09-22 17:30:57 -0600 | [diff] [blame] | 236 | if (c == '\n') |
| 237 | while (pl01x_putc(base_regs, '\r') == -EAGAIN); |
wdenk | c35ba4e | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 238 | |
Simon Glass | f35484d | 2014-09-22 17:30:57 -0600 | [diff] [blame] | 239 | while (pl01x_putc(base_regs, c) == -EAGAIN); |
wdenk | 4989f87 | 2004-03-14 15:06:13 +0000 | [diff] [blame] | 240 | } |
| 241 | |
Simon Glass | f35484d | 2014-09-22 17:30:57 -0600 | [diff] [blame] | 242 | static int pl01x_serial_getc(void) |
wdenk | 4989f87 | 2004-03-14 15:06:13 +0000 | [diff] [blame] | 243 | { |
Simon Glass | f35484d | 2014-09-22 17:30:57 -0600 | [diff] [blame] | 244 | while (1) { |
| 245 | int ch = pl01x_getc(base_regs); |
wdenk | c35ba4e | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 246 | |
Simon Glass | f35484d | 2014-09-22 17:30:57 -0600 | [diff] [blame] | 247 | if (ch == -EAGAIN) { |
| 248 | WATCHDOG_RESET(); |
| 249 | continue; |
| 250 | } |
wdenk | 4989f87 | 2004-03-14 15:06:13 +0000 | [diff] [blame] | 251 | |
Simon Glass | f35484d | 2014-09-22 17:30:57 -0600 | [diff] [blame] | 252 | return ch; |
wdenk | c35ba4e | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 253 | } |
wdenk | 4989f87 | 2004-03-14 15:06:13 +0000 | [diff] [blame] | 254 | } |
| 255 | |
Simon Glass | f35484d | 2014-09-22 17:30:57 -0600 | [diff] [blame] | 256 | static int pl01x_serial_tstc(void) |
wdenk | 4989f87 | 2004-03-14 15:06:13 +0000 | [diff] [blame] | 257 | { |
Simon Glass | f35484d | 2014-09-22 17:30:57 -0600 | [diff] [blame] | 258 | return pl01x_tstc(base_regs); |
| 259 | } |
Rabin Vincent | fb3c95f | 2010-05-05 09:23:07 +0530 | [diff] [blame] | 260 | |
Simon Glass | f35484d | 2014-09-22 17:30:57 -0600 | [diff] [blame] | 261 | static void pl01x_serial_setbrg(void) |
| 262 | { |
| 263 | /* |
| 264 | * Flush FIFO and wait for non-busy before changing baudrate to avoid |
| 265 | * crap in console |
| 266 | */ |
| 267 | while (!(readl(&base_regs->fr) & UART_PL01x_FR_TXFE)) |
| 268 | WATCHDOG_RESET(); |
| 269 | while (readl(&base_regs->fr) & UART_PL01x_FR_BUSY) |
| 270 | WATCHDOG_RESET(); |
| 271 | pl01x_serial_init_baud(gd->baudrate); |
wdenk | 4989f87 | 2004-03-14 15:06:13 +0000 | [diff] [blame] | 272 | } |
Marek Vasut | 46e4d5f | 2012-09-14 22:38:46 +0200 | [diff] [blame] | 273 | |
Marek Vasut | 46e4d5f | 2012-09-14 22:38:46 +0200 | [diff] [blame] | 274 | static struct serial_device pl01x_serial_drv = { |
| 275 | .name = "pl01x_serial", |
| 276 | .start = pl01x_serial_init, |
| 277 | .stop = NULL, |
| 278 | .setbrg = pl01x_serial_setbrg, |
| 279 | .putc = pl01x_serial_putc, |
Marek Vasut | d9c6449 | 2012-10-06 14:07:02 +0000 | [diff] [blame] | 280 | .puts = default_serial_puts, |
Marek Vasut | 46e4d5f | 2012-09-14 22:38:46 +0200 | [diff] [blame] | 281 | .getc = pl01x_serial_getc, |
| 282 | .tstc = pl01x_serial_tstc, |
| 283 | }; |
| 284 | |
| 285 | void pl01x_serial_initialize(void) |
| 286 | { |
| 287 | serial_register(&pl01x_serial_drv); |
| 288 | } |
| 289 | |
| 290 | __weak struct serial_device *default_serial_console(void) |
| 291 | { |
| 292 | return &pl01x_serial_drv; |
| 293 | } |
Simon Glass | f35484d | 2014-09-22 17:30:57 -0600 | [diff] [blame] | 294 | |
| 295 | #endif /* nCONFIG_DM_SERIAL */ |
Simon Glass | 3ad93fe | 2014-09-22 17:30:58 -0600 | [diff] [blame] | 296 | |
| 297 | #ifdef CONFIG_DM_SERIAL |
| 298 | |
| 299 | struct pl01x_priv { |
| 300 | struct pl01x_regs *regs; |
| 301 | enum pl01x_type type; |
| 302 | }; |
| 303 | |
| 304 | static int pl01x_serial_setbrg(struct udevice *dev, int baudrate) |
| 305 | { |
| 306 | struct pl01x_serial_platdata *plat = dev_get_platdata(dev); |
| 307 | struct pl01x_priv *priv = dev_get_priv(dev); |
| 308 | |
| 309 | pl01x_generic_setbrg(priv->regs, priv->type, plat->clock, baudrate); |
| 310 | |
| 311 | return 0; |
| 312 | } |
| 313 | |
| 314 | static int pl01x_serial_probe(struct udevice *dev) |
| 315 | { |
| 316 | struct pl01x_serial_platdata *plat = dev_get_platdata(dev); |
| 317 | struct pl01x_priv *priv = dev_get_priv(dev); |
| 318 | |
| 319 | priv->regs = (struct pl01x_regs *)plat->base; |
| 320 | priv->type = plat->type; |
| 321 | return pl01x_generic_serial_init(priv->regs, priv->type); |
| 322 | } |
| 323 | |
| 324 | static int pl01x_serial_getc(struct udevice *dev) |
| 325 | { |
| 326 | struct pl01x_priv *priv = dev_get_priv(dev); |
| 327 | |
| 328 | return pl01x_getc(priv->regs); |
| 329 | } |
| 330 | |
| 331 | static int pl01x_serial_putc(struct udevice *dev, const char ch) |
| 332 | { |
| 333 | struct pl01x_priv *priv = dev_get_priv(dev); |
| 334 | |
| 335 | return pl01x_putc(priv->regs, ch); |
| 336 | } |
| 337 | |
| 338 | static int pl01x_serial_pending(struct udevice *dev, bool input) |
| 339 | { |
| 340 | struct pl01x_priv *priv = dev_get_priv(dev); |
| 341 | unsigned int fr = readl(&priv->regs->fr); |
| 342 | |
| 343 | if (input) |
| 344 | return pl01x_tstc(priv->regs); |
| 345 | else |
| 346 | return fr & UART_PL01x_FR_TXFF ? 0 : 1; |
| 347 | } |
| 348 | |
| 349 | static const struct dm_serial_ops pl01x_serial_ops = { |
| 350 | .putc = pl01x_serial_putc, |
| 351 | .pending = pl01x_serial_pending, |
| 352 | .getc = pl01x_serial_getc, |
| 353 | .setbrg = pl01x_serial_setbrg, |
| 354 | }; |
| 355 | |
Vikas Manocha | 92e349e | 2015-05-06 11:46:29 -0700 | [diff] [blame] | 356 | #ifdef CONFIG_OF_CONTROL |
| 357 | static const struct udevice_id pl01x_serial_id[] ={ |
| 358 | {.compatible = "arm,pl011", .data = TYPE_PL011}, |
| 359 | {.compatible = "arm,pl010", .data = TYPE_PL010}, |
| 360 | {} |
| 361 | }; |
| 362 | |
| 363 | static int pl01x_serial_ofdata_to_platdata(struct udevice *dev) |
| 364 | { |
| 365 | struct pl01x_serial_platdata *plat = dev_get_platdata(dev); |
| 366 | fdt_addr_t addr; |
| 367 | |
| 368 | addr = fdtdec_get_addr(gd->fdt_blob, dev->of_offset, "reg"); |
| 369 | if (addr == FDT_ADDR_T_NONE) |
| 370 | return -EINVAL; |
| 371 | |
| 372 | plat->base = addr; |
| 373 | plat->clock = fdtdec_get_int(gd->fdt_blob, dev->of_offset, "clock", 1); |
| 374 | plat->type = dev_get_driver_data(dev); |
| 375 | return 0; |
| 376 | } |
| 377 | #endif |
| 378 | |
Simon Glass | 3ad93fe | 2014-09-22 17:30:58 -0600 | [diff] [blame] | 379 | U_BOOT_DRIVER(serial_pl01x) = { |
| 380 | .name = "serial_pl01x", |
| 381 | .id = UCLASS_SERIAL, |
Vikas Manocha | 92e349e | 2015-05-06 11:46:29 -0700 | [diff] [blame] | 382 | .of_match = of_match_ptr(pl01x_serial_id), |
| 383 | .ofdata_to_platdata = of_match_ptr(pl01x_serial_ofdata_to_platdata), |
| 384 | .platdata_auto_alloc_size = sizeof(struct pl01x_serial_platdata), |
Simon Glass | 3ad93fe | 2014-09-22 17:30:58 -0600 | [diff] [blame] | 385 | .probe = pl01x_serial_probe, |
| 386 | .ops = &pl01x_serial_ops, |
| 387 | .flags = DM_FLAG_PRE_RELOC, |
Simon Glass | 900de91 | 2014-11-24 21:36:35 -0700 | [diff] [blame] | 388 | .priv_auto_alloc_size = sizeof(struct pl01x_priv), |
Simon Glass | 3ad93fe | 2014-09-22 17:30:58 -0600 | [diff] [blame] | 389 | }; |
| 390 | |
| 391 | #endif |