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