20 #if defined(CONFIG_SERIAL_SH_SCI_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
26 #include <linux/module.h>
27 #include <linux/errno.h>
31 #include <linux/tty.h>
33 #include <linux/serial.h>
35 #include <linux/string.h>
48 #include <linux/ctype.h>
53 #include <linux/slab.h>
57 #include <asm/sh_bios.h>
83 #ifdef CONFIG_SERIAL_SH_SCI_DMA
90 unsigned int sg_len_tx;
98 unsigned int rx_timeout;
103 #ifdef CONFIG_SERIAL_SH_SCI_CONSOLE
104 unsigned short saved_smr;
105 unsigned short saved_fcr;
106 unsigned char saved_brr;
115 #define SCI_NPORTS CONFIG_SERIAL_SH_SCI_NR_UARTS
131 #define sci_reg_invalid { .offset = 0, .size = 0 }
143 [
SCSMR] = { 0x00, 8 },
144 [
SCBRR] = { 0x01, 8 },
145 [
SCSCR] = { 0x02, 8 },
147 [
SCxSR] = { 0x04, 8 },
162 [
SCSMR] = { 0x00, 8 },
163 [
SCBRR] = { 0x01, 8 },
164 [
SCSCR] = { 0x02, 8 },
166 [
SCxSR] = { 0x04, 8 },
168 [
SCFCR] = { 0x06, 8 },
169 [
SCFDR] = { 0x07, 16 },
180 [
SCSMR] = { 0x00, 16 },
181 [
SCBRR] = { 0x04, 8 },
182 [
SCSCR] = { 0x08, 16 },
184 [
SCxSR] = { 0x14, 16 },
186 [
SCFCR] = { 0x18, 16 },
187 [
SCFDR] = { 0x1c, 16 },
198 [
SCSMR] = { 0x00, 16 },
199 [
SCBRR] = { 0x04, 8 },
200 [
SCSCR] = { 0x08, 16 },
202 [
SCxSR] = { 0x14, 16 },
204 [
SCFCR] = { 0x18, 16 },
205 [
SCFDR] = { 0x1c, 16 },
217 [
SCSMR] = { 0x00, 16 },
218 [
SCBRR] = { 0x04, 8 },
219 [
SCSCR] = { 0x08, 16 },
221 [
SCxSR] = { 0x10, 16 },
223 [
SCFCR] = { 0x18, 16 },
224 [
SCFDR] = { 0x1c, 16 },
228 [
SCLSR] = { 0x24, 16 },
235 [
SCSMR] = { 0x00, 8 },
236 [
SCBRR] = { 0x02, 8 },
237 [
SCSCR] = { 0x04, 8 },
239 [
SCxSR] = { 0x08, 16 },
241 [
SCFCR] = { 0x0c, 8 },
242 [
SCFDR] = { 0x0e, 16 },
253 [
SCSMR] = { 0x00, 16 },
254 [
SCBRR] = { 0x04, 8 },
255 [
SCSCR] = { 0x08, 16 },
257 [
SCxSR] = { 0x10, 16 },
259 [
SCFCR] = { 0x18, 16 },
260 [
SCFDR] = { 0x1c, 16 },
264 [
SCLSR] = { 0x24, 16 },
272 [
SCSMR] = { 0x00, 16 },
273 [
SCBRR] = { 0x04, 8 },
274 [
SCSCR] = { 0x08, 16 },
276 [
SCxSR] = { 0x10, 16 },
278 [
SCFCR] = { 0x18, 16 },
279 [
SCFDR] = { 0x1c, 16 },
283 [
SCLSR] = { 0x24, 16 },
291 [
SCSMR] = { 0x00, 16 },
292 [
SCBRR] = { 0x04, 8 },
293 [
SCSCR] = { 0x08, 16 },
295 [
SCxSR] = { 0x10, 16 },
297 [
SCFCR] = { 0x18, 16 },
298 [
SCFDR] = { 0x1c, 16 },
302 [
SCLSR] = { 0x28, 16 },
310 [
SCSMR] = { 0x00, 16 },
311 [
SCBRR] = { 0x04, 8 },
312 [
SCSCR] = { 0x08, 16 },
314 [
SCxSR] = { 0x14, 16 },
316 [
SCFCR] = { 0x18, 16 },
317 [
SCFDR] = { 0x1c, 16 },
325 #define sci_getreg(up, offset) (sci_regmap[to_sci_port(up)->cfg->regtype] + offset)
339 else if (reg->
size == 16)
342 WARN(1,
"Invalid register access\n");
353 else if (reg->
size == 16)
356 WARN(1,
"Invalid register access\n");
393 if (!sci_port->
port.dev)
396 pm_runtime_get_sync(sci_port->
port.dev);
403 static void sci_port_disable(
struct sci_port *sci_port)
405 if (!sci_port->
port.dev)
411 pm_runtime_put_sync(sci_port->
port.dev);
414 #if defined(CONFIG_CONSOLE_POLL) || defined(CONFIG_SERIAL_SH_SCI_CONSOLE)
416 #ifdef CONFIG_CONSOLE_POLL
423 status = serial_port_in(port,
SCxSR);
434 c = serial_port_in(port,
SCxRDR);
437 serial_port_in(port,
SCxSR);
444 static void sci_poll_put_char(
struct uart_port *port,
unsigned char c)
449 status = serial_port_in(port,
SCxSR);
452 serial_port_out(port,
SCxTDR, c);
457 static void sci_init_pins(
struct uart_port *port,
unsigned int cflag)
459 struct sci_port *
s = to_sci_port(port);
465 if (s->
cfg->ops && s->
cfg->ops->init_pins) {
466 s->
cfg->ops->init_pins(port, cflag);
481 status = serial_port_in(port, SCSPTR);
484 serial_port_out(port, SCSPTR, status);
488 static int sci_txfill(
struct uart_port *port)
494 return serial_port_in(port,
SCTFDR) & 0xff;
498 return serial_port_in(port,
SCFDR) >> 8;
503 static int sci_txroom(
struct uart_port *port)
505 return port->
fifosize - sci_txfill(port);
508 static int sci_rxfill(
struct uart_port *port)
514 return serial_port_in(port,
SCRFDR) & 0xff;
518 return serial_port_in(port,
SCFDR) & ((port->
fifosize << 1) - 1);
526 static inline int sci_rxd_in(
struct uart_port *port)
528 struct sci_port *s = to_sci_port(port);
530 if (s->
cfg->port_reg <= 0)
541 static void sci_transmit_chars(
struct uart_port *port)
544 unsigned int stopped = uart_tx_stopped(port);
549 status = serial_port_in(port,
SCxSR);
551 ctrl = serial_port_in(port,
SCSCR);
556 serial_port_out(port,
SCSCR, ctrl);
560 count = sci_txroom(port);
575 serial_port_out(port,
SCxTDR, c);
578 }
while (--count > 0);
587 ctrl = serial_port_in(port,
SCSCR);
590 serial_port_in(port,
SCxSR);
595 serial_port_out(port,
SCSCR, ctrl);
600 #define STEPFN(c) ({int __c = (c); (((__c-1)|(__c)) == -1); })
602 static void sci_receive_chars(
struct uart_port *port)
604 struct sci_port *sci_port = to_sci_port(port);
610 status = serial_port_in(port,
SCxSR);
623 char c = serial_port_in(port,
SCxRDR);
630 for (i = 0; i <
count; i++) {
631 char c = serial_port_in(port,
SCxRDR);
633 status = serial_port_in(port,
SCxSR);
634 #if defined(CONFIG_CPU_SH3)
662 dev_notice(port->
dev,
"frame error\n");
666 dev_notice(port->
dev,
"parity error\n");
670 tty_insert_flip_char(tty, c, flag);
674 serial_port_in(port,
SCxSR);
685 serial_port_in(port,
SCxSR);
690 #define SCI_BREAK_JIFFIES (HZ/20)
700 static inline void sci_schedule_break_timer(
struct sci_port *port)
706 static void sci_break_timer(
unsigned long data)
708 struct sci_port *port = (
struct sci_port *)data;
710 sci_port_enable(port);
712 if (sci_rxd_in(&port->
port) == 0) {
714 sci_schedule_break_timer(port);
718 sci_schedule_break_timer(port);
722 sci_port_disable(port);
725 static int sci_handle_errors(
struct uart_port *port)
728 unsigned short status = serial_port_in(port,
SCxSR);
730 struct sci_port *s = to_sci_port(port);
736 if (status & (1 << s->
cfg->overrun_bit)) {
743 dev_notice(port->
dev,
"overrun error");
748 if (sci_rxd_in(port) == 0) {
750 struct sci_port *sci_port = to_sci_port(port);
756 sci_schedule_break_timer(sci_port);
759 if (uart_handle_break(port))
764 if (tty_insert_flip_char(tty, 0,
TTY_BREAK))
772 if (tty_insert_flip_char(tty, 0,
TTY_FRAME))
775 dev_notice(port->
dev,
"frame error\n");
786 dev_notice(port->
dev,
"parity error");
795 static int sci_handle_fifo_overrun(
struct uart_port *port)
798 struct sci_port *s = to_sci_port(port);
806 if ((serial_port_in(port,
SCLSR) & (1 << s->
cfg->overrun_bit))) {
807 serial_port_out(port,
SCLSR, 0);
814 dev_notice(port->
dev,
"overrun error\n");
821 static int sci_handle_breaks(
struct uart_port *port)
824 unsigned short status = serial_port_in(port,
SCxSR);
826 struct sci_port *s = to_sci_port(port);
828 if (uart_handle_break(port))
832 #if defined(CONFIG_CPU_SH3)
840 if (tty_insert_flip_char(tty, 0,
TTY_BREAK))
849 copied += sci_handle_fifo_overrun(port);
856 #ifdef CONFIG_SERIAL_SH_SCI_DMA
858 struct sci_port *s = to_sci_port(port);
871 serial_port_out(port,
SCSCR, scr);
874 dev_dbg(port->
dev,
"Rx IRQ %lu: setup t-out in %u jiffies\n",
875 jiffies, s->rx_timeout);
876 mod_timer(&s->rx_timer, jiffies + s->rx_timeout);
886 sci_receive_chars(ptr);
891 static irqreturn_t sci_tx_interrupt(
int irq,
void *ptr)
897 sci_transmit_chars(port);
898 spin_unlock_irqrestore(&port->
lock, flags);
903 static irqreturn_t sci_er_interrupt(
int irq,
void *ptr)
909 if (sci_handle_errors(port)) {
911 serial_port_in(port,
SCxSR);
915 sci_handle_fifo_overrun(port);
916 sci_rx_interrupt(irq, ptr);
922 sci_tx_interrupt(irq, ptr);
927 static irqreturn_t sci_br_interrupt(
int irq,
void *ptr)
932 sci_handle_breaks(port);
938 static inline unsigned long port_rx_irq_mask(
struct uart_port *port)
950 static irqreturn_t sci_mpxed_interrupt(
int irq,
void *ptr)
952 unsigned short ssr_status, scr_status, err_enabled;
954 struct sci_port *s = to_sci_port(port);
957 ssr_status = serial_port_in(port,
SCxSR);
958 scr_status = serial_port_in(port,
SCSCR);
959 err_enabled = scr_status & port_rx_irq_mask(port);
964 ret = sci_tx_interrupt(irq, ptr);
972 ret = sci_rx_interrupt(irq, ptr);
976 ret = sci_er_interrupt(irq, ptr);
979 if ((ssr_status &
SCxSR_BRK(port)) && err_enabled)
980 ret = sci_br_interrupt(irq, ptr);
990 unsigned long phase,
void *p)
992 struct sci_port *sci_port;
1003 spin_unlock_irqrestore(&port->
lock, flags);
1009 static struct sci_irq_desc {
1012 } sci_irq_desc[] = {
1018 .handler = sci_er_interrupt,
1023 .handler = sci_rx_interrupt,
1028 .handler = sci_tx_interrupt,
1033 .handler = sci_br_interrupt,
1041 .handler = sci_mpxed_interrupt,
1045 static int sci_request_irq(
struct sci_port *port)
1051 struct sci_irq_desc *
desc;
1058 irq = port->
cfg->irqs[
i];
1068 desc = sci_irq_desc +
i;
1070 dev_name(up->
dev), desc->desc);
1072 dev_err(up->
dev,
"Failed to allocate %s IRQ string\n",
1080 dev_err(up->
dev,
"Can't allocate %s IRQ\n", desc->desc);
1098 static void sci_free_irq(
struct sci_port *port)
1107 unsigned int irq = port->
cfg->irqs[
i];
1126 static const char *sci_gpio_names[
SCIx_NR_FNS] = {
1127 "sck",
"rxd",
"txd",
"cts",
"rts",
1130 static const char *sci_gpio_str(
unsigned int index)
1132 return sci_gpio_names[
index];
1135 static void __devinit sci_init_gpios(
struct sci_port *port)
1147 if (!port->
cfg->gpios[i])
1150 desc = sci_gpio_str(i);
1153 dev_name(up->
dev), desc);
1160 dev_notice(up->
dev,
"%s string allocation failure\n",
1165 dev_notice(up->
dev,
"failed %s gpio request\n", desc);
1176 static void sci_free_gpios(
struct sci_port *port)
1181 if (port->
cfg->gpios[i]) {
1187 static unsigned int sci_tx_empty(
struct uart_port *port)
1189 unsigned short status = serial_port_in(port,
SCxSR);
1190 unsigned short in_tx_fifo = sci_txfill(port);
1207 static void sci_set_mctrl(
struct uart_port *port,
unsigned int mctrl)
1217 serial_port_out(port,
SCFCR, serial_port_in(port,
SCFCR) | 1);
1221 static unsigned int sci_get_mctrl(
struct uart_port *port)
1230 #ifdef CONFIG_SERIAL_SH_SCI_DMA
1231 static void sci_dma_tx_complete(
void *
arg)
1233 struct sci_port *s =
arg;
1236 unsigned long flags;
1247 async_tx_ack(s->desc_tx);
1259 u16 ctrl = serial_port_in(port,
SCSCR);
1260 serial_port_out(port,
SCSCR, ctrl & ~SCSCR_TIE);
1264 spin_unlock_irqrestore(&port->
lock, flags);
1268 static int sci_dma_rx_push(
struct sci_port *s,
struct tty_struct *tty,
1276 if (s->active_rx == s->cookie_rx[0]) {
1278 }
else if (s->active_rx == s->cookie_rx[1]) {
1281 dev_err(port->
dev,
"cookie %d not found!\n", s->active_rx);
1286 dev_warn(port->
dev,
"Rx overrun: dropping %u bytes\n",
1291 for (i = 0; i < room; i++)
1292 tty_insert_flip_char(tty, ((
u8 *)sg_virt(&s->sg_rx[active]))[i],
1300 static void sci_dma_rx_complete(
void *arg)
1302 struct sci_port *s =
arg;
1305 unsigned long flags;
1308 dev_dbg(port->
dev,
"%s(%d) active #%d\n", __func__, port->
line, s->active_rx);
1312 count = sci_dma_rx_push(s, tty, s->buf_len_rx);
1314 mod_timer(&s->rx_timer, jiffies + s->rx_timeout);
1316 spin_unlock_irqrestore(&port->
lock, flags);
1324 static void sci_rx_dma_release(
struct sci_port *s,
bool enable_pio)
1330 s->cookie_rx[0] = s->cookie_rx[1] = -
EINVAL;
1339 static void sci_tx_dma_release(
struct sci_port *s,
bool enable_pio)
1351 static void sci_submit_rx(
struct sci_port *s)
1356 for (i = 0; i < 2; i++) {
1360 desc = dmaengine_prep_slave_sg(chan,
1364 s->desc_rx[
i] = desc;
1365 desc->
callback = sci_dma_rx_complete;
1370 if (!desc || s->cookie_rx[i] < 0) {
1372 async_tx_ack(s->desc_rx[0]);
1373 s->cookie_rx[0] = -
EINVAL;
1380 "failed to re-start DMA, using PIO\n");
1381 sci_rx_dma_release(s,
true);
1384 dev_dbg(s->
port.dev,
"%s(): cookie %d to #%d\n", __func__,
1385 s->cookie_rx[i], i);
1388 s->active_rx = s->cookie_rx[0];
1390 dma_async_issue_pending(chan);
1395 struct sci_port *s =
container_of(work,
struct sci_port, work_rx);
1400 if (s->active_rx == s->cookie_rx[0]) {
1402 }
else if (s->active_rx == s->cookie_rx[1]) {
1405 dev_err(port->
dev,
"cookie %d not found!\n", s->active_rx);
1408 desc = s->desc_rx[
new];
1417 unsigned long flags;
1421 dev_dbg(port->
dev,
"Read %u bytes with cookie %d\n",
1425 count = sci_dma_rx_push(s, tty, sh_desc->
partial);
1426 spin_unlock_irqrestore(&port->
lock, flags);
1436 s->cookie_rx[
new] = desc->
tx_submit(desc);
1437 if (s->cookie_rx[
new] < 0) {
1438 dev_warn(port->
dev,
"Failed submitting Rx DMA descriptor\n");
1439 sci_rx_dma_release(s,
true);
1443 s->active_rx = s->cookie_rx[!
new];
1445 dev_dbg(port->
dev,
"%s: cookie %d #%d, new active #%d\n", __func__,
1446 s->cookie_rx[
new],
new, s->active_rx);
1451 struct sci_port *s =
container_of(work,
struct sci_port, work_tx);
1465 spin_lock_irq(&port->
lock);
1471 spin_unlock_irq(&port->
lock);
1475 desc = dmaengine_prep_slave_sg(chan,
1480 sci_tx_dma_release(s,
true);
1486 spin_lock_irq(&port->
lock);
1488 desc->
callback = sci_dma_tx_complete;
1490 spin_unlock_irq(&port->
lock);
1492 if (s->cookie_tx < 0) {
1493 dev_warn(port->
dev,
"Failed submitting Tx DMA descriptor\n");
1495 sci_tx_dma_release(s,
true);
1499 dev_dbg(port->
dev,
"%s: %p: %d...%d, cookie %d\n", __func__,
1502 dma_async_issue_pending(chan);
1506 static void sci_start_tx(
struct uart_port *port)
1508 struct sci_port *s = to_sci_port(port);
1509 unsigned short ctrl;
1511 #ifdef CONFIG_SERIAL_SH_SCI_DMA
1513 u16 new, scr = serial_port_in(port,
SCSCR);
1517 new = scr & ~0x8000;
1519 serial_port_out(port,
SCSCR,
new);
1531 ctrl = serial_port_in(port,
SCSCR);
1532 serial_port_out(port,
SCSCR, ctrl | SCSCR_TIE);
1536 static void sci_stop_tx(
struct uart_port *port)
1538 unsigned short ctrl;
1541 ctrl = serial_port_in(port,
SCSCR);
1548 serial_port_out(port,
SCSCR, ctrl);
1551 static void sci_start_rx(
struct uart_port *port)
1553 unsigned short ctrl;
1555 ctrl = serial_port_in(port,
SCSCR) | port_rx_irq_mask(port);
1560 serial_port_out(port,
SCSCR, ctrl);
1563 static void sci_stop_rx(
struct uart_port *port)
1565 unsigned short ctrl;
1567 ctrl = serial_port_in(port,
SCSCR);
1572 ctrl &= ~port_rx_irq_mask(port);
1574 serial_port_out(port,
SCSCR, ctrl);
1577 static void sci_enable_ms(
struct uart_port *port)
1584 static void sci_break_ctl(
struct uart_port *port,
int break_state)
1586 struct sci_port *s = to_sci_port(port);
1588 unsigned short scscr, scsptr;
1599 scsptr = serial_port_in(port, SCSPTR);
1600 scscr = serial_port_in(port,
SCSCR);
1602 if (break_state == -1) {
1610 serial_port_out(port, SCSPTR, scsptr);
1611 serial_port_out(port,
SCSCR, scscr);
1614 #ifdef CONFIG_SERIAL_SH_SCI_DMA
1626 static void rx_timer_fn(
unsigned long arg)
1628 struct sci_port *s = (
struct sci_port *)arg;
1630 u16 scr = serial_port_in(port,
SCSCR);
1636 serial_port_out(port,
SCSCR, scr | SCSCR_RIE);
1641 static void sci_request_dma(
struct uart_port *port)
1643 struct sci_port *s = to_sci_port(port);
1649 dev_dbg(port->
dev,
"%s: port %d\n", __func__,
1652 if (s->
cfg->dma_slave_tx <= 0 || s->
cfg->dma_slave_rx <= 0)
1658 param = &s->param_tx;
1665 dev_dbg(port->
dev,
"%s: TX: got channel %p\n", __func__, chan);
1675 sci_tx_dma_release(s,
false);
1677 dev_dbg(port->
dev,
"%s: mapped %d@%p to %x\n", __func__,
1681 s->sg_len_tx = nent;
1686 param = &s->param_rx;
1692 dev_dbg(port->
dev,
"%s: RX: got channel %p\n", __func__, chan);
1706 "failed to allocate dma buffer, using PIO\n");
1707 sci_rx_dma_release(s,
true);
1711 buf[1] = buf[0] + s->buf_len_rx;
1712 dma[1] = dma[0] + s->buf_len_rx;
1714 for (i = 0; i < 2; i++) {
1724 setup_timer(&s->rx_timer, rx_timer_fn, (
unsigned long)s);
1730 static void sci_free_dma(
struct uart_port *port)
1732 struct sci_port *s = to_sci_port(port);
1735 sci_tx_dma_release(s,
false);
1737 sci_rx_dma_release(s,
false);
1740 static inline void sci_request_dma(
struct uart_port *port)
1744 static inline void sci_free_dma(
struct uart_port *port)
1749 static int sci_startup(
struct uart_port *port)
1751 struct sci_port *s = to_sci_port(port);
1756 pm_runtime_put_noidle(port->
dev);
1760 ret = sci_request_irq(s);
1764 sci_request_dma(port);
1772 static void sci_shutdown(
struct uart_port *port)
1774 struct sci_port *s = to_sci_port(port);
1784 sci_port_disable(s);
1786 pm_runtime_get_noresume(port->
dev);
1789 static unsigned int sci_scbrr_calc(
unsigned int algo_id,
unsigned int bps,
1794 return ((freq + 16 * bps) / (16 * bps) - 1);
1796 return ((freq + 16 * bps) / (32 * bps) - 1);
1798 return (((freq * 2) + 16 * bps) / (16 * bps) - 1);
1800 return (((freq * 2) + 16 * bps) / (32 * bps) - 1);
1802 return (((freq * 1000 / 32) / bps) - 1);
1808 return ((freq + 16 * bps) / (32 * bps) - 1);
1811 static void sci_reset(
struct uart_port *port)
1817 status = serial_port_in(port,
SCxSR);
1820 serial_port_out(port,
SCSCR, 0x00);
1830 struct sci_port *s = to_sci_port(port);
1847 t = sci_scbrr_calc(s->
cfg->scbrr_algo_id, baud, port->
uartclk);
1853 smr_val = serial_port_in(port,
SCSMR) & 3;
1866 serial_port_out(port,
SCSMR, smr_val);
1868 dev_dbg(port->
dev,
"%s: SMR %x, t %x, SCSCR %x\n", __func__, smr_val, t,
1873 serial_port_out(port,
SCSMR, (serial_port_in(port,
SCSMR) & ~3) | 1);
1876 serial_port_out(port,
SCSMR, serial_port_in(port,
SCSMR) & ~3);
1878 serial_port_out(port,
SCBRR, t);
1879 udelay((1000000+(baud-1)) / baud);
1882 sci_init_pins(port, termios->
c_cflag);
1886 unsigned short ctrl = serial_port_in(port,
SCFCR);
1902 serial_port_out(port,
SCFCR, ctrl);
1905 serial_port_out(port,
SCSCR, s->
cfg->scscr);
1907 #ifdef CONFIG_SERIAL_SH_SCI_DMA
1919 s->rx_timeout = (port->
timeout -
HZ / 50) * s->buf_len_rx * 3 /
1922 "DMA Rx t-out %ums, tty t-out %u jiffies\n",
1923 s->rx_timeout * 1000 /
HZ, port->
timeout);
1932 sci_port_disable(s);
1935 static const char *sci_type(
struct uart_port *port)
1937 switch (port->
type) {
1953 static inline unsigned long sci_port_size(
struct uart_port *port)
1964 static int sci_remap_port(
struct uart_port *port)
1966 unsigned long size = sci_port_size(port);
1992 static void sci_release_port(
struct uart_port *port)
2002 static int sci_request_port(
struct uart_port *port)
2004 unsigned long size = sci_port_size(port);
2012 ret = sci_remap_port(port);
2021 static void sci_config_port(
struct uart_port *port,
int flags)
2024 struct sci_port *sport = to_sci_port(port);
2026 port->
type = sport->
cfg->type;
2027 sci_request_port(port);
2033 struct sci_port *s = to_sci_port(port);
2044 static struct uart_ops sci_uart_ops = {
2045 .tx_empty = sci_tx_empty,
2046 .set_mctrl = sci_set_mctrl,
2047 .get_mctrl = sci_get_mctrl,
2048 .start_tx = sci_start_tx,
2049 .stop_tx = sci_stop_tx,
2050 .stop_rx = sci_stop_rx,
2051 .enable_ms = sci_enable_ms,
2052 .break_ctl = sci_break_ctl,
2053 .startup = sci_startup,
2054 .shutdown = sci_shutdown,
2055 .set_termios = sci_set_termios,
2057 .release_port = sci_release_port,
2058 .request_port = sci_request_port,
2059 .config_port = sci_config_port,
2060 .verify_port = sci_verify_port,
2061 #ifdef CONFIG_CONSOLE_POLL
2062 .poll_get_char = sci_poll_get_char,
2063 .poll_put_char = sci_poll_put_char,
2068 struct sci_port *sci_port,
2077 port->
ops = &sci_uart_ops;
2097 ret = sci_probe_regmap(p);
2104 if (IS_ERR(sci_port->
iclk)) {
2106 if (IS_ERR(sci_port->
iclk)) {
2108 return PTR_ERR(sci_port->
iclk);
2117 if (IS_ERR(sci_port->
fclk))
2122 sci_init_gpios(sci_port);
2125 pm_runtime_get_noresume(&dev->
dev);
2184 static void sci_cleanup_single(
struct sci_port *port)
2186 sci_free_gpios(port);
2191 pm_runtime_disable(port->
port.dev);
2194 #ifdef CONFIG_SERIAL_SH_SCI_CONSOLE
2195 static void serial_console_putchar(
struct uart_port *port,
int ch)
2197 sci_poll_put_char(port, ch);
2204 static void serial_console_write(
struct console *co,
const char *s,
2207 struct sci_port *sci_port = &sci_ports[co->
index];
2209 unsigned short bits;
2211 sci_port_enable(sci_port);
2217 while ((serial_port_in(port,
SCxSR) & bits) != bits)
2220 sci_port_disable(sci_port);
2225 struct sci_port *sci_port;
2239 sci_port = &sci_ports[co->
index];
2240 port = &sci_port->
port;
2248 ret = sci_remap_port(port);
2252 sci_port_enable(sci_port);
2257 sci_port_disable(sci_port);
2262 static struct console serial_console = {
2265 .write = serial_console_write,
2266 .setup = serial_console_setup,
2269 .data = &sci_uart_driver,
2272 static struct console early_serial_console = {
2273 .
name =
"early_ttySC",
2274 .write = serial_console_write,
2279 static char early_serial_buf[32];
2285 if (early_serial_console.
data)
2288 early_serial_console.
index = pdev->
id;
2290 sci_init_single(
NULL, &sci_ports[pdev->
id], pdev->
id, cfg);
2292 serial_console_setup(&early_serial_console, early_serial_buf);
2294 if (!
strstr(early_serial_buf,
"keep"))
2301 #define uart_console(port) ((port)->cons->index == (port)->line)
2311 sci_port->saved_smr = serial_port_in(port,
SCSMR);
2312 sci_port->saved_brr = serial_port_in(port,
SCBRR);
2316 sci_port->saved_fcr = serial_port_in(port,
SCFCR);
2318 sci_port->saved_fcr = 0;
2330 serial_port_out(port,
SCSMR, sci_port->saved_smr);
2331 serial_port_out(port,
SCBRR, sci_port->saved_brr);
2333 if (sci_port->saved_fcr)
2334 serial_port_out(port,
SCFCR, sci_port->saved_fcr);
2336 serial_port_out(port,
SCSCR, sci_port->
cfg->scscr);
2341 #define SCI_CONSOLE (&serial_console)
2349 #define SCI_CONSOLE NULL
2350 #define sci_runtime_suspend NULL
2351 #define sci_runtime_resume NULL
2356 KERN_INFO "SuperH SCI(F) driver initialized\n";
2360 .driver_name =
"sci",
2361 .dev_name =
"ttySC",
2370 struct sci_port *port = platform_get_drvdata(dev);
2377 sci_cleanup_single(port);
2385 struct sci_port *sciport)
2391 dev_notice(&dev->
dev,
"Attempting to register port "
2392 "%d when only %d are available.\n",
2394 dev_notice(&dev->
dev,
"Consider bumping "
2395 "CONFIG_SERIAL_SH_SCI_NR_UARTS!\n");
2399 ret = sci_init_single(dev, sciport, index, p);
2405 sci_cleanup_single(sciport);
2415 struct sci_port *
sp = &sci_ports[dev->
id];
2423 if (is_early_platform_device(dev))
2424 return sci_probe_earlyprintk(dev);
2426 platform_set_drvdata(dev, sp);
2428 ret = sci_probe_single(dev, dev->
id, p, sp);
2437 sci_cleanup_single(sp);
2441 #ifdef CONFIG_SH_STANDARD_BIOS
2448 static int sci_suspend(
struct device *dev)
2458 static int sci_resume(
struct device *dev)
2468 static const struct dev_pm_ops sci_dev_pm_ops = {
2471 .suspend = sci_suspend,
2472 .resume = sci_resume,
2477 .remove = sci_remove,
2481 .pm = &sci_dev_pm_ops,
2485 static int __init sci_init(
void)
2501 static void __exit sci_exit(
void)
2507 #ifdef CONFIG_SERIAL_SH_SCI_CONSOLE
2509 early_serial_buf,
ARRAY_SIZE(early_serial_buf));