Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 2 | /* |
| 3 | * SuperH SCIF device driver. |
Nobuhiro Iwamatsu | 48ca882 | 2013-07-23 13:58:20 +0900 | [diff] [blame] | 4 | * Copyright (C) 2013 Renesas Electronics Corporation |
Nobuhiro Iwamatsu | 59088e4 | 2015-02-12 13:48:04 +0900 | [diff] [blame] | 5 | * Copyright (C) 2007,2008,2010, 2014 Nobuhiro Iwamatsu |
Nobuhiro Iwamatsu | 3f6c8e3 | 2010-10-26 03:55:15 +0900 | [diff] [blame] | 6 | * Copyright (C) 2002 - 2008 Paul Mundt |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
Nobuhiro Iwamatsu | 59088e4 | 2015-02-12 13:48:04 +0900 | [diff] [blame] | 10 | #include <errno.h> |
Marek Vasut | 8171499 | 2017-07-21 23:19:18 +0200 | [diff] [blame] | 11 | #include <clk.h> |
Nobuhiro Iwamatsu | 59088e4 | 2015-02-12 13:48:04 +0900 | [diff] [blame] | 12 | #include <dm.h> |
Jean-Christophe PLAGNIOL-VILLARD | fc83c92 | 2009-01-11 16:35:16 +0100 | [diff] [blame] | 13 | #include <asm/io.h> |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 14 | #include <asm/processor.h> |
Marek Vasut | 8bdd7ef | 2012-09-14 22:40:08 +0200 | [diff] [blame] | 15 | #include <serial.h> |
| 16 | #include <linux/compiler.h> |
Nobuhiro Iwamatsu | 59088e4 | 2015-02-12 13:48:04 +0900 | [diff] [blame] | 17 | #include <dm/platform_data/serial_sh.h> |
| 18 | #include "serial_sh.h" |
| 19 | |
Yoshinori Sato | 359787c | 2016-04-18 16:51:04 +0900 | [diff] [blame] | 20 | DECLARE_GLOBAL_DATA_PTR; |
| 21 | |
Marek Vasut | 10e91cf | 2019-05-07 22:31:23 +0200 | [diff] [blame] | 22 | #if defined(CONFIG_CPU_SH7780) |
Nobuhiro Iwamatsu | 59088e4 | 2015-02-12 13:48:04 +0900 | [diff] [blame] | 23 | static int scif_rxfill(struct uart_port *port) |
| 24 | { |
| 25 | return sci_in(port, SCRFDR) & 0xff; |
| 26 | } |
| 27 | #elif defined(CONFIG_CPU_SH7763) |
| 28 | static int scif_rxfill(struct uart_port *port) |
| 29 | { |
| 30 | if ((port->mapbase == 0xffe00000) || |
| 31 | (port->mapbase == 0xffe08000)) { |
| 32 | /* SCIF0/1*/ |
| 33 | return sci_in(port, SCRFDR) & 0xff; |
| 34 | } else { |
| 35 | /* SCIF2 */ |
| 36 | return sci_in(port, SCFDR) & SCIF2_RFDC_MASK; |
| 37 | } |
| 38 | } |
Nobuhiro Iwamatsu | 59088e4 | 2015-02-12 13:48:04 +0900 | [diff] [blame] | 39 | #else |
| 40 | static int scif_rxfill(struct uart_port *port) |
| 41 | { |
| 42 | return sci_in(port, SCFDR) & SCIF_RFDC_MASK; |
| 43 | } |
| 44 | #endif |
| 45 | |
| 46 | static void sh_serial_init_generic(struct uart_port *port) |
| 47 | { |
| 48 | sci_out(port, SCSCR , SCSCR_INIT(port)); |
| 49 | sci_out(port, SCSCR , SCSCR_INIT(port)); |
| 50 | sci_out(port, SCSMR, 0); |
| 51 | sci_out(port, SCSMR, 0); |
| 52 | sci_out(port, SCFCR, SCFCR_RFRST|SCFCR_TFRST); |
| 53 | sci_in(port, SCFCR); |
| 54 | sci_out(port, SCFCR, 0); |
Marek Vasut | 67180fe | 2019-05-01 18:20:00 +0200 | [diff] [blame] | 55 | #if defined(CONFIG_RZA1) |
| 56 | sci_out(port, SCSPTR, 0x0003); |
| 57 | #endif |
Nobuhiro Iwamatsu | 59088e4 | 2015-02-12 13:48:04 +0900 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | static void |
| 61 | sh_serial_setbrg_generic(struct uart_port *port, int clk, int baudrate) |
| 62 | { |
| 63 | if (port->clk_mode == EXT_CLK) { |
| 64 | unsigned short dl = DL_VALUE(baudrate, clk); |
| 65 | sci_out(port, DL, dl); |
Nobuhiro Iwamatsu | 89f99a6 | 2014-12-10 14:42:05 +0900 | [diff] [blame] | 66 | /* Need wait: Clock * 1/dl * 1/16 */ |
Nobuhiro Iwamatsu | 59088e4 | 2015-02-12 13:48:04 +0900 | [diff] [blame] | 67 | udelay((1000000 * dl * 16 / clk) * 1000 + 1); |
| 68 | } else { |
| 69 | sci_out(port, SCBRR, SCBRR_VALUE(baudrate, clk)); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | static void handle_error(struct uart_port *port) |
| 74 | { |
| 75 | sci_in(port, SCxSR); |
| 76 | sci_out(port, SCxSR, SCxSR_ERROR_CLEAR(port)); |
| 77 | sci_in(port, SCLSR); |
| 78 | sci_out(port, SCLSR, 0x00); |
| 79 | } |
| 80 | |
| 81 | static int serial_raw_putc(struct uart_port *port, const char c) |
| 82 | { |
| 83 | /* Tx fifo is empty */ |
| 84 | if (!(sci_in(port, SCxSR) & SCxSR_TEND(port))) |
| 85 | return -EAGAIN; |
| 86 | |
| 87 | sci_out(port, SCxTDR, c); |
| 88 | sci_out(port, SCxSR, sci_in(port, SCxSR) & ~SCxSR_TEND(port)); |
| 89 | |
| 90 | return 0; |
| 91 | } |
| 92 | |
| 93 | static int serial_rx_fifo_level(struct uart_port *port) |
| 94 | { |
| 95 | return scif_rxfill(port); |
| 96 | } |
| 97 | |
| 98 | static int sh_serial_tstc_generic(struct uart_port *port) |
| 99 | { |
| 100 | if (sci_in(port, SCxSR) & SCIF_ERRORS) { |
| 101 | handle_error(port); |
| 102 | return 0; |
| 103 | } |
| 104 | |
| 105 | return serial_rx_fifo_level(port) ? 1 : 0; |
| 106 | } |
| 107 | |
| 108 | static int serial_getc_check(struct uart_port *port) |
| 109 | { |
| 110 | unsigned short status; |
| 111 | |
| 112 | status = sci_in(port, SCxSR); |
| 113 | |
| 114 | if (status & SCIF_ERRORS) |
| 115 | handle_error(port); |
| 116 | if (sci_in(port, SCLSR) & SCxSR_ORER(port)) |
| 117 | handle_error(port); |
| 118 | return status & (SCIF_DR | SCxSR_RDxF(port)); |
| 119 | } |
| 120 | |
| 121 | static int sh_serial_getc_generic(struct uart_port *port) |
| 122 | { |
| 123 | unsigned short status; |
| 124 | char ch; |
| 125 | |
| 126 | if (!serial_getc_check(port)) |
| 127 | return -EAGAIN; |
| 128 | |
| 129 | ch = sci_in(port, SCxRDR); |
| 130 | status = sci_in(port, SCxSR); |
| 131 | |
| 132 | sci_out(port, SCxSR, SCxSR_RDxF_CLEAR(port)); |
| 133 | |
| 134 | if (status & SCIF_ERRORS) |
| 135 | handle_error(port); |
| 136 | |
| 137 | if (sci_in(port, SCLSR) & SCxSR_ORER(port)) |
| 138 | handle_error(port); |
| 139 | |
| 140 | return ch; |
| 141 | } |
| 142 | |
Marek Vasut | 5c44ddc | 2018-02-16 01:33:27 +0100 | [diff] [blame] | 143 | #if CONFIG_IS_ENABLED(DM_SERIAL) |
Nobuhiro Iwamatsu | 59088e4 | 2015-02-12 13:48:04 +0900 | [diff] [blame] | 144 | |
| 145 | static int sh_serial_pending(struct udevice *dev, bool input) |
| 146 | { |
| 147 | struct uart_port *priv = dev_get_priv(dev); |
| 148 | |
| 149 | return sh_serial_tstc_generic(priv); |
| 150 | } |
| 151 | |
| 152 | static int sh_serial_putc(struct udevice *dev, const char ch) |
| 153 | { |
| 154 | struct uart_port *priv = dev_get_priv(dev); |
| 155 | |
| 156 | return serial_raw_putc(priv, ch); |
| 157 | } |
| 158 | |
| 159 | static int sh_serial_getc(struct udevice *dev) |
| 160 | { |
| 161 | struct uart_port *priv = dev_get_priv(dev); |
| 162 | |
| 163 | return sh_serial_getc_generic(priv); |
| 164 | } |
| 165 | |
| 166 | static int sh_serial_setbrg(struct udevice *dev, int baudrate) |
| 167 | { |
| 168 | struct sh_serial_platdata *plat = dev_get_platdata(dev); |
| 169 | struct uart_port *priv = dev_get_priv(dev); |
| 170 | |
| 171 | sh_serial_setbrg_generic(priv, plat->clk, baudrate); |
| 172 | |
| 173 | return 0; |
| 174 | } |
| 175 | |
| 176 | static int sh_serial_probe(struct udevice *dev) |
| 177 | { |
| 178 | struct sh_serial_platdata *plat = dev_get_platdata(dev); |
| 179 | struct uart_port *priv = dev_get_priv(dev); |
| 180 | |
| 181 | priv->membase = (unsigned char *)plat->base; |
| 182 | priv->mapbase = plat->base; |
| 183 | priv->type = plat->type; |
| 184 | priv->clk_mode = plat->clk_mode; |
| 185 | |
| 186 | sh_serial_init_generic(priv); |
| 187 | |
| 188 | return 0; |
| 189 | } |
| 190 | |
| 191 | static const struct dm_serial_ops sh_serial_ops = { |
| 192 | .putc = sh_serial_putc, |
| 193 | .pending = sh_serial_pending, |
| 194 | .getc = sh_serial_getc, |
| 195 | .setbrg = sh_serial_setbrg, |
| 196 | }; |
| 197 | |
Marek Vasut | 5c44ddc | 2018-02-16 01:33:27 +0100 | [diff] [blame] | 198 | #if CONFIG_IS_ENABLED(OF_CONTROL) |
Yoshinori Sato | 359787c | 2016-04-18 16:51:04 +0900 | [diff] [blame] | 199 | static const struct udevice_id sh_serial_id[] ={ |
Yoshinori Sato | 747431b | 2016-04-18 16:51:05 +0900 | [diff] [blame] | 200 | {.compatible = "renesas,sci", .data = PORT_SCI}, |
Yoshinori Sato | 359787c | 2016-04-18 16:51:04 +0900 | [diff] [blame] | 201 | {.compatible = "renesas,scif", .data = PORT_SCIF}, |
| 202 | {.compatible = "renesas,scifa", .data = PORT_SCIFA}, |
| 203 | {} |
| 204 | }; |
| 205 | |
| 206 | static int sh_serial_ofdata_to_platdata(struct udevice *dev) |
| 207 | { |
| 208 | struct sh_serial_platdata *plat = dev_get_platdata(dev); |
Marek Vasut | 8171499 | 2017-07-21 23:19:18 +0200 | [diff] [blame] | 209 | struct clk sh_serial_clk; |
Yoshinori Sato | 359787c | 2016-04-18 16:51:04 +0900 | [diff] [blame] | 210 | fdt_addr_t addr; |
Marek Vasut | 8171499 | 2017-07-21 23:19:18 +0200 | [diff] [blame] | 211 | int ret; |
Yoshinori Sato | 359787c | 2016-04-18 16:51:04 +0900 | [diff] [blame] | 212 | |
Marek Vasut | c493756 | 2018-01-17 22:36:37 +0100 | [diff] [blame] | 213 | addr = devfdt_get_addr(dev); |
| 214 | if (!addr) |
Yoshinori Sato | 359787c | 2016-04-18 16:51:04 +0900 | [diff] [blame] | 215 | return -EINVAL; |
| 216 | |
| 217 | plat->base = addr; |
Marek Vasut | 8171499 | 2017-07-21 23:19:18 +0200 | [diff] [blame] | 218 | |
| 219 | ret = clk_get_by_name(dev, "fck", &sh_serial_clk); |
Marek Vasut | 791c174 | 2017-09-15 21:11:27 +0200 | [diff] [blame] | 220 | if (!ret) { |
| 221 | ret = clk_enable(&sh_serial_clk); |
| 222 | if (!ret) |
| 223 | plat->clk = clk_get_rate(&sh_serial_clk); |
| 224 | } else { |
Marek Vasut | 8171499 | 2017-07-21 23:19:18 +0200 | [diff] [blame] | 225 | plat->clk = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev), |
| 226 | "clock", 1); |
Marek Vasut | 791c174 | 2017-09-15 21:11:27 +0200 | [diff] [blame] | 227 | } |
Marek Vasut | 8171499 | 2017-07-21 23:19:18 +0200 | [diff] [blame] | 228 | |
Yoshinori Sato | 359787c | 2016-04-18 16:51:04 +0900 | [diff] [blame] | 229 | plat->type = dev_get_driver_data(dev); |
| 230 | return 0; |
| 231 | } |
| 232 | #endif |
| 233 | |
Nobuhiro Iwamatsu | 59088e4 | 2015-02-12 13:48:04 +0900 | [diff] [blame] | 234 | U_BOOT_DRIVER(serial_sh) = { |
| 235 | .name = "serial_sh", |
| 236 | .id = UCLASS_SERIAL, |
Yoshinori Sato | 359787c | 2016-04-18 16:51:04 +0900 | [diff] [blame] | 237 | .of_match = of_match_ptr(sh_serial_id), |
| 238 | .ofdata_to_platdata = of_match_ptr(sh_serial_ofdata_to_platdata), |
| 239 | .platdata_auto_alloc_size = sizeof(struct sh_serial_platdata), |
Nobuhiro Iwamatsu | 59088e4 | 2015-02-12 13:48:04 +0900 | [diff] [blame] | 240 | .probe = sh_serial_probe, |
| 241 | .ops = &sh_serial_ops, |
Bin Meng | 4687919 | 2018-10-24 06:36:36 -0700 | [diff] [blame] | 242 | #if !CONFIG_IS_ENABLED(OF_CONTROL) |
Nobuhiro Iwamatsu | 59088e4 | 2015-02-12 13:48:04 +0900 | [diff] [blame] | 243 | .flags = DM_FLAG_PRE_RELOC, |
Bin Meng | 4687919 | 2018-10-24 06:36:36 -0700 | [diff] [blame] | 244 | #endif |
Nobuhiro Iwamatsu | 59088e4 | 2015-02-12 13:48:04 +0900 | [diff] [blame] | 245 | .priv_auto_alloc_size = sizeof(struct uart_port), |
| 246 | }; |
| 247 | |
| 248 | #else /* CONFIG_DM_SERIAL */ |
John Rigby | 2956532 | 2010-12-20 18:27:51 -0700 | [diff] [blame] | 249 | |
Nobuhiro Iwamatsu | ab09f43 | 2008-08-22 17:48:51 +0900 | [diff] [blame] | 250 | #if defined(CONFIG_CONS_SCIF0) |
| 251 | # define SCIF_BASE SCIF0_BASE |
| 252 | #elif defined(CONFIG_CONS_SCIF1) |
| 253 | # define SCIF_BASE SCIF1_BASE |
| 254 | #elif defined(CONFIG_CONS_SCIF2) |
| 255 | # define SCIF_BASE SCIF2_BASE |
| 256 | #elif defined(CONFIG_CONS_SCIF3) |
| 257 | # define SCIF_BASE SCIF3_BASE |
| 258 | #elif defined(CONFIG_CONS_SCIF4) |
| 259 | # define SCIF_BASE SCIF4_BASE |
| 260 | #elif defined(CONFIG_CONS_SCIF5) |
| 261 | # define SCIF_BASE SCIF5_BASE |
Phil Edworthy | 99744b7 | 2012-05-15 22:15:51 +0000 | [diff] [blame] | 262 | #elif defined(CONFIG_CONS_SCIF6) |
| 263 | # define SCIF_BASE SCIF6_BASE |
| 264 | #elif defined(CONFIG_CONS_SCIF7) |
| 265 | # define SCIF_BASE SCIF7_BASE |
Marek Vasut | 451e22f | 2018-04-12 15:23:46 +0200 | [diff] [blame] | 266 | #elif defined(CONFIG_CONS_SCIFA0) |
| 267 | # define SCIF_BASE SCIFA0_BASE |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 268 | #else |
Nobuhiro Iwamatsu | ab09f43 | 2008-08-22 17:48:51 +0900 | [diff] [blame] | 269 | # error "Default SCIF doesn't set....." |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 270 | #endif |
| 271 | |
Nobuhiro Iwamatsu | 3f6c8e3 | 2010-10-26 03:55:15 +0900 | [diff] [blame] | 272 | #if defined(CONFIG_SCIF_A) |
| 273 | #define SCIF_BASE_PORT PORT_SCIFA |
Yoshinori Sato | 747431b | 2016-04-18 16:51:05 +0900 | [diff] [blame] | 274 | #elif defined(CONFIG_SCI) |
| 275 | #define SCIF_BASE_PORT PORT_SCI |
Yoshihiro Shimoda | 7c10c57 | 2008-01-09 14:30:02 +0900 | [diff] [blame] | 276 | #else |
Nobuhiro Iwamatsu | 3f6c8e3 | 2010-10-26 03:55:15 +0900 | [diff] [blame] | 277 | #define SCIF_BASE_PORT PORT_SCIF |
Yoshihiro Shimoda | 7c10c57 | 2008-01-09 14:30:02 +0900 | [diff] [blame] | 278 | #endif |
| 279 | |
Nobuhiro Iwamatsu | 3f6c8e3 | 2010-10-26 03:55:15 +0900 | [diff] [blame] | 280 | static struct uart_port sh_sci = { |
Nobuhiro Iwamatsu | 59088e4 | 2015-02-12 13:48:04 +0900 | [diff] [blame] | 281 | .membase = (unsigned char *)SCIF_BASE, |
Nobuhiro Iwamatsu | 3f6c8e3 | 2010-10-26 03:55:15 +0900 | [diff] [blame] | 282 | .mapbase = SCIF_BASE, |
| 283 | .type = SCIF_BASE_PORT, |
Nobuhiro Iwamatsu | 59088e4 | 2015-02-12 13:48:04 +0900 | [diff] [blame] | 284 | #ifdef CONFIG_SCIF_USE_EXT_CLK |
| 285 | .clk_mode = EXT_CLK, |
| 286 | #endif |
Nobuhiro Iwamatsu | 3f6c8e3 | 2010-10-26 03:55:15 +0900 | [diff] [blame] | 287 | }; |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 288 | |
Marek Vasut | 8bdd7ef | 2012-09-14 22:40:08 +0200 | [diff] [blame] | 289 | static void sh_serial_setbrg(void) |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 290 | { |
Nobuhiro Iwamatsu | 3f6c8e3 | 2010-10-26 03:55:15 +0900 | [diff] [blame] | 291 | DECLARE_GLOBAL_DATA_PTR; |
Nobuhiro Iwamatsu | 59088e4 | 2015-02-12 13:48:04 +0900 | [diff] [blame] | 292 | struct uart_port *port = &sh_sci; |
| 293 | |
| 294 | sh_serial_setbrg_generic(port, CONFIG_SH_SCIF_CLK_FREQ, gd->baudrate); |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 295 | } |
| 296 | |
Marek Vasut | 8bdd7ef | 2012-09-14 22:40:08 +0200 | [diff] [blame] | 297 | static int sh_serial_init(void) |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 298 | { |
Nobuhiro Iwamatsu | 59088e4 | 2015-02-12 13:48:04 +0900 | [diff] [blame] | 299 | struct uart_port *port = &sh_sci; |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 300 | |
Nobuhiro Iwamatsu | 59088e4 | 2015-02-12 13:48:04 +0900 | [diff] [blame] | 301 | sh_serial_init_generic(port); |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 302 | serial_setbrg(); |
Nobuhiro Iwamatsu | 59088e4 | 2015-02-12 13:48:04 +0900 | [diff] [blame] | 303 | |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 304 | return 0; |
| 305 | } |
| 306 | |
Marek Vasut | 8bdd7ef | 2012-09-14 22:40:08 +0200 | [diff] [blame] | 307 | static void sh_serial_putc(const char c) |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 308 | { |
Nobuhiro Iwamatsu | 59088e4 | 2015-02-12 13:48:04 +0900 | [diff] [blame] | 309 | struct uart_port *port = &sh_sci; |
| 310 | |
| 311 | if (c == '\n') { |
| 312 | while (1) { |
| 313 | if (serial_raw_putc(port, '\r') != -EAGAIN) |
| 314 | break; |
| 315 | } |
| 316 | } |
| 317 | while (1) { |
| 318 | if (serial_raw_putc(port, c) != -EAGAIN) |
| 319 | break; |
| 320 | } |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 321 | } |
| 322 | |
Marek Vasut | 8bdd7ef | 2012-09-14 22:40:08 +0200 | [diff] [blame] | 323 | static int sh_serial_tstc(void) |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 324 | { |
Nobuhiro Iwamatsu | 59088e4 | 2015-02-12 13:48:04 +0900 | [diff] [blame] | 325 | struct uart_port *port = &sh_sci; |
Tetsuyuki Kobayashi | 7c791b3 | 2012-11-19 21:37:38 +0000 | [diff] [blame] | 326 | |
Nobuhiro Iwamatsu | 59088e4 | 2015-02-12 13:48:04 +0900 | [diff] [blame] | 327 | return sh_serial_tstc_generic(port); |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 328 | } |
| 329 | |
Marek Vasut | 8bdd7ef | 2012-09-14 22:40:08 +0200 | [diff] [blame] | 330 | static int sh_serial_getc(void) |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 331 | { |
Nobuhiro Iwamatsu | 59088e4 | 2015-02-12 13:48:04 +0900 | [diff] [blame] | 332 | struct uart_port *port = &sh_sci; |
| 333 | int ch; |
Nobuhiro Iwamatsu | ab09f43 | 2008-08-22 17:48:51 +0900 | [diff] [blame] | 334 | |
Nobuhiro Iwamatsu | 59088e4 | 2015-02-12 13:48:04 +0900 | [diff] [blame] | 335 | while (1) { |
| 336 | ch = sh_serial_getc_generic(port); |
| 337 | if (ch != -EAGAIN) |
| 338 | break; |
| 339 | } |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 340 | |
Nobuhiro Iwamatsu | 08c5fab | 2008-06-06 16:16:08 +0900 | [diff] [blame] | 341 | return ch; |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 342 | } |
Marek Vasut | 8bdd7ef | 2012-09-14 22:40:08 +0200 | [diff] [blame] | 343 | |
Marek Vasut | 8bdd7ef | 2012-09-14 22:40:08 +0200 | [diff] [blame] | 344 | static struct serial_device sh_serial_drv = { |
| 345 | .name = "sh_serial", |
| 346 | .start = sh_serial_init, |
| 347 | .stop = NULL, |
| 348 | .setbrg = sh_serial_setbrg, |
| 349 | .putc = sh_serial_putc, |
Marek Vasut | ec3fd68 | 2012-10-06 14:07:02 +0000 | [diff] [blame] | 350 | .puts = default_serial_puts, |
Marek Vasut | 8bdd7ef | 2012-09-14 22:40:08 +0200 | [diff] [blame] | 351 | .getc = sh_serial_getc, |
| 352 | .tstc = sh_serial_tstc, |
| 353 | }; |
| 354 | |
| 355 | void sh_serial_initialize(void) |
| 356 | { |
| 357 | serial_register(&sh_serial_drv); |
| 358 | } |
| 359 | |
| 360 | __weak struct serial_device *default_serial_console(void) |
| 361 | { |
| 362 | return &sh_serial_drv; |
| 363 | } |
Nobuhiro Iwamatsu | 59088e4 | 2015-02-12 13:48:04 +0900 | [diff] [blame] | 364 | #endif /* CONFIG_DM_SERIAL */ |