Greg Kroah-Hartman | e3b3d0f | 2017-11-06 18:11:51 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Driver for CLPS711x serial ports |
| 4 | * |
| 5 | * Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o. |
| 6 | * |
| 7 | * Copyright 1999 ARM Limited |
| 8 | * Copyright (C) 2000 Deep Blue Solutions Ltd. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/device.h> |
Alexander Shiyan | a1c25f2 | 2012-10-14 11:05:34 +0400 | [diff] [blame] | 13 | #include <linux/console.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/serial_core.h> |
| 15 | #include <linux/serial.h> |
Alexander Shiyan | c08f015 | 2012-10-14 11:05:26 +0400 | [diff] [blame] | 16 | #include <linux/clk.h> |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 17 | #include <linux/io.h> |
Alexander Shiyan | a1c25f2 | 2012-10-14 11:05:34 +0400 | [diff] [blame] | 18 | #include <linux/tty.h> |
| 19 | #include <linux/tty_flip.h> |
| 20 | #include <linux/ioport.h> |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 21 | #include <linux/of.h> |
Alexander Shiyan | 9511372 | 2012-10-14 11:05:23 +0400 | [diff] [blame] | 22 | #include <linux/platform_device.h> |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 23 | #include <linux/regmap.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 25 | #include <linux/mfd/syscon.h> |
| 26 | #include <linux/mfd/syscon/clps711x.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
Alexander Shiyan | 62b0a1b | 2014-09-06 07:20:15 +0400 | [diff] [blame] | 28 | #include "serial_mctrl_gpio.h" |
| 29 | |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 30 | #define UART_CLPS711X_DEVNAME "ttyCL" |
Alexander Shiyan | 117d5d4 | 2012-10-14 11:05:24 +0400 | [diff] [blame] | 31 | #define UART_CLPS711X_NR 2 |
| 32 | #define UART_CLPS711X_MAJOR 204 |
| 33 | #define UART_CLPS711X_MINOR 40 |
Alexander Shiyan | 9511372 | 2012-10-14 11:05:23 +0400 | [diff] [blame] | 34 | |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 35 | #define UARTDR_OFFSET (0x00) |
| 36 | #define UBRLCR_OFFSET (0x40) |
| 37 | |
| 38 | #define UARTDR_FRMERR (1 << 8) |
| 39 | #define UARTDR_PARERR (1 << 9) |
| 40 | #define UARTDR_OVERR (1 << 10) |
| 41 | |
| 42 | #define UBRLCR_BAUD_MASK ((1 << 12) - 1) |
| 43 | #define UBRLCR_BREAK (1 << 12) |
| 44 | #define UBRLCR_PRTEN (1 << 13) |
| 45 | #define UBRLCR_EVENPRT (1 << 14) |
| 46 | #define UBRLCR_XSTOP (1 << 15) |
| 47 | #define UBRLCR_FIFOEN (1 << 16) |
| 48 | #define UBRLCR_WRDLEN5 (0 << 17) |
| 49 | #define UBRLCR_WRDLEN6 (1 << 17) |
| 50 | #define UBRLCR_WRDLEN7 (2 << 17) |
| 51 | #define UBRLCR_WRDLEN8 (3 << 17) |
| 52 | #define UBRLCR_WRDLEN_MASK (3 << 17) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
Alexander Shiyan | 117d5d4 | 2012-10-14 11:05:24 +0400 | [diff] [blame] | 54 | struct clps711x_port { |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 55 | struct uart_port port; |
| 56 | unsigned int tx_enabled; |
| 57 | int rx_irq; |
| 58 | struct regmap *syscon; |
Alexander Shiyan | 62b0a1b | 2014-09-06 07:20:15 +0400 | [diff] [blame] | 59 | struct mctrl_gpios *gpios; |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | static struct uart_driver clps711x_uart = { |
| 63 | .owner = THIS_MODULE, |
| 64 | .driver_name = UART_CLPS711X_DEVNAME, |
| 65 | .dev_name = UART_CLPS711X_DEVNAME, |
| 66 | .major = UART_CLPS711X_MAJOR, |
| 67 | .minor = UART_CLPS711X_MINOR, |
| 68 | .nr = UART_CLPS711X_NR, |
Alexander Shiyan | 117d5d4 | 2012-10-14 11:05:24 +0400 | [diff] [blame] | 69 | }; |
| 70 | |
Alexander Shiyan | a1c25f2 | 2012-10-14 11:05:34 +0400 | [diff] [blame] | 71 | static void uart_clps711x_stop_tx(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | { |
Alexander Shiyan | 3c7e9eb | 2012-10-14 11:05:25 +0400 | [diff] [blame] | 73 | struct clps711x_port *s = dev_get_drvdata(port->dev); |
| 74 | |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 75 | if (s->tx_enabled) { |
| 76 | disable_irq(port->irq); |
| 77 | s->tx_enabled = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | } |
| 79 | } |
| 80 | |
Alexander Shiyan | a1c25f2 | 2012-10-14 11:05:34 +0400 | [diff] [blame] | 81 | static void uart_clps711x_start_tx(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | { |
Alexander Shiyan | 3c7e9eb | 2012-10-14 11:05:25 +0400 | [diff] [blame] | 83 | struct clps711x_port *s = dev_get_drvdata(port->dev); |
| 84 | |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 85 | if (!s->tx_enabled) { |
| 86 | s->tx_enabled = 1; |
| 87 | enable_irq(port->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | } |
| 89 | } |
| 90 | |
Alexander Shiyan | 135cc79 | 2012-10-14 11:05:31 +0400 | [diff] [blame] | 91 | static irqreturn_t uart_clps711x_int_rx(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | { |
| 93 | struct uart_port *port = dev_id; |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 94 | struct clps711x_port *s = dev_get_drvdata(port->dev); |
| 95 | unsigned int status, flg; |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 96 | u16 ch; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
Alexander Shiyan | f27de95 | 2012-10-14 11:05:30 +0400 | [diff] [blame] | 98 | for (;;) { |
Alexander Shiyan | 093a9e2 | 2013-12-31 20:49:42 +0400 | [diff] [blame] | 99 | u32 sysflg = 0; |
| 100 | |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 101 | regmap_read(s->syscon, SYSFLG_OFFSET, &sysflg); |
| 102 | if (sysflg & SYSFLG_URXFE) |
Alexander Shiyan | f27de95 | 2012-10-14 11:05:30 +0400 | [diff] [blame] | 103 | break; |
| 104 | |
Alexander Shiyan | 093a9e2 | 2013-12-31 20:49:42 +0400 | [diff] [blame] | 105 | ch = readw(port->membase + UARTDR_OFFSET); |
Alexander Shiyan | f27de95 | 2012-10-14 11:05:30 +0400 | [diff] [blame] | 106 | status = ch & (UARTDR_FRMERR | UARTDR_PARERR | UARTDR_OVERR); |
| 107 | ch &= 0xff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | port->icount.rx++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | flg = TTY_NORMAL; |
| 111 | |
Alexander Shiyan | f27de95 | 2012-10-14 11:05:30 +0400 | [diff] [blame] | 112 | if (unlikely(status)) { |
| 113 | if (status & UARTDR_PARERR) |
Russell King | 2a9604b | 2005-04-26 15:32:00 +0100 | [diff] [blame] | 114 | port->icount.parity++; |
Alexander Shiyan | f27de95 | 2012-10-14 11:05:30 +0400 | [diff] [blame] | 115 | else if (status & UARTDR_FRMERR) |
Russell King | 2a9604b | 2005-04-26 15:32:00 +0100 | [diff] [blame] | 116 | port->icount.frame++; |
Alexander Shiyan | f27de95 | 2012-10-14 11:05:30 +0400 | [diff] [blame] | 117 | else if (status & UARTDR_OVERR) |
Russell King | 2a9604b | 2005-04-26 15:32:00 +0100 | [diff] [blame] | 118 | port->icount.overrun++; |
| 119 | |
Alexander Shiyan | f27de95 | 2012-10-14 11:05:30 +0400 | [diff] [blame] | 120 | status &= port->read_status_mask; |
Russell King | 2a9604b | 2005-04-26 15:32:00 +0100 | [diff] [blame] | 121 | |
Alexander Shiyan | f27de95 | 2012-10-14 11:05:30 +0400 | [diff] [blame] | 122 | if (status & UARTDR_PARERR) |
Russell King | 2a9604b | 2005-04-26 15:32:00 +0100 | [diff] [blame] | 123 | flg = TTY_PARITY; |
Alexander Shiyan | f27de95 | 2012-10-14 11:05:30 +0400 | [diff] [blame] | 124 | else if (status & UARTDR_FRMERR) |
Russell King | 2a9604b | 2005-04-26 15:32:00 +0100 | [diff] [blame] | 125 | flg = TTY_FRAME; |
Alexander Shiyan | f27de95 | 2012-10-14 11:05:30 +0400 | [diff] [blame] | 126 | else if (status & UARTDR_OVERR) |
| 127 | flg = TTY_OVERRUN; |
Russell King | 2a9604b | 2005-04-26 15:32:00 +0100 | [diff] [blame] | 128 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 130 | if (uart_handle_sysrq_char(port, ch)) |
Alexander Shiyan | f27de95 | 2012-10-14 11:05:30 +0400 | [diff] [blame] | 131 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
Alexander Shiyan | f27de95 | 2012-10-14 11:05:30 +0400 | [diff] [blame] | 133 | if (status & port->ignore_status_mask) |
| 134 | continue; |
Russell King | 2a9604b | 2005-04-26 15:32:00 +0100 | [diff] [blame] | 135 | |
Alexander Shiyan | f27de95 | 2012-10-14 11:05:30 +0400 | [diff] [blame] | 136 | uart_insert_char(port, status, UARTDR_OVERR, ch, flg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | } |
Alexander Shiyan | f27de95 | 2012-10-14 11:05:30 +0400 | [diff] [blame] | 138 | |
Jiri Slaby | 2e124b4 | 2013-01-03 15:53:06 +0100 | [diff] [blame] | 139 | tty_flip_buffer_push(&port->state->port); |
Alexander Shiyan | f27de95 | 2012-10-14 11:05:30 +0400 | [diff] [blame] | 140 | |
Russell King | 2a9604b | 2005-04-26 15:32:00 +0100 | [diff] [blame] | 141 | return IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | } |
| 143 | |
Alexander Shiyan | 135cc79 | 2012-10-14 11:05:31 +0400 | [diff] [blame] | 144 | static irqreturn_t uart_clps711x_int_tx(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | { |
| 146 | struct uart_port *port = dev_id; |
Alexander Shiyan | 3c7e9eb | 2012-10-14 11:05:25 +0400 | [diff] [blame] | 147 | struct clps711x_port *s = dev_get_drvdata(port->dev); |
Alan Cox | ebd2c8f | 2009-09-19 13:13:28 -0700 | [diff] [blame] | 148 | struct circ_buf *xmit = &port->state->xmit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | |
| 150 | if (port->x_char) { |
Alexander Shiyan | 093a9e2 | 2013-12-31 20:49:42 +0400 | [diff] [blame] | 151 | writew(port->x_char, port->membase + UARTDR_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | port->icount.tx++; |
| 153 | port->x_char = 0; |
| 154 | return IRQ_HANDLED; |
| 155 | } |
Alexander Shiyan | 7a6fbc9 | 2012-03-27 12:22:49 +0400 | [diff] [blame] | 156 | |
Alexander Shiyan | 3c7e9eb | 2012-10-14 11:05:25 +0400 | [diff] [blame] | 157 | if (uart_circ_empty(xmit) || uart_tx_stopped(port)) { |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 158 | if (s->tx_enabled) { |
| 159 | disable_irq_nosync(port->irq); |
| 160 | s->tx_enabled = 0; |
| 161 | } |
Alexander Shiyan | 3c7e9eb | 2012-10-14 11:05:25 +0400 | [diff] [blame] | 162 | return IRQ_HANDLED; |
| 163 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | |
Alexander Shiyan | cf03a88 | 2012-10-14 11:05:27 +0400 | [diff] [blame] | 165 | while (!uart_circ_empty(xmit)) { |
Alexander Shiyan | 093a9e2 | 2013-12-31 20:49:42 +0400 | [diff] [blame] | 166 | u32 sysflg = 0; |
| 167 | |
| 168 | writew(xmit->buf[xmit->tail], port->membase + UARTDR_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); |
| 170 | port->icount.tx++; |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 171 | |
| 172 | regmap_read(s->syscon, SYSFLG_OFFSET, &sysflg); |
| 173 | if (sysflg & SYSFLG_UTXFF) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | break; |
Alexander Shiyan | cf03a88 | 2012-10-14 11:05:27 +0400 | [diff] [blame] | 175 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | |
| 177 | if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) |
| 178 | uart_write_wakeup(port); |
| 179 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | return IRQ_HANDLED; |
| 181 | } |
| 182 | |
Alexander Shiyan | a1c25f2 | 2012-10-14 11:05:34 +0400 | [diff] [blame] | 183 | static unsigned int uart_clps711x_tx_empty(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | { |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 185 | struct clps711x_port *s = dev_get_drvdata(port->dev); |
Alexander Shiyan | 093a9e2 | 2013-12-31 20:49:42 +0400 | [diff] [blame] | 186 | u32 sysflg = 0; |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 187 | |
| 188 | regmap_read(s->syscon, SYSFLG_OFFSET, &sysflg); |
| 189 | |
| 190 | return (sysflg & SYSFLG_UBUSY) ? 0 : TIOCSER_TEMT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | } |
| 192 | |
Alexander Shiyan | a1c25f2 | 2012-10-14 11:05:34 +0400 | [diff] [blame] | 193 | static unsigned int uart_clps711x_get_mctrl(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | { |
Alexander Shiyan | 62b0a1b | 2014-09-06 07:20:15 +0400 | [diff] [blame] | 195 | unsigned int result = TIOCM_DSR | TIOCM_CTS | TIOCM_CAR; |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 196 | struct clps711x_port *s = dev_get_drvdata(port->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | |
Alexander Shiyan | 62b0a1b | 2014-09-06 07:20:15 +0400 | [diff] [blame] | 198 | return mctrl_gpio_get(s->gpios, &result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Alexander Shiyan | a1c25f2 | 2012-10-14 11:05:34 +0400 | [diff] [blame] | 201 | static void uart_clps711x_set_mctrl(struct uart_port *port, unsigned int mctrl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | { |
Alexander Shiyan | 62b0a1b | 2014-09-06 07:20:15 +0400 | [diff] [blame] | 203 | struct clps711x_port *s = dev_get_drvdata(port->dev); |
| 204 | |
| 205 | mctrl_gpio_set(s->gpios, mctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Alexander Shiyan | a1c25f2 | 2012-10-14 11:05:34 +0400 | [diff] [blame] | 208 | static void uart_clps711x_break_ctl(struct uart_port *port, int break_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | unsigned int ubrlcr; |
| 211 | |
Alexander Shiyan | 093a9e2 | 2013-12-31 20:49:42 +0400 | [diff] [blame] | 212 | ubrlcr = readl(port->membase + UBRLCR_OFFSET); |
Alexander Shiyan | ec33552 | 2012-10-14 11:05:29 +0400 | [diff] [blame] | 213 | if (break_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | ubrlcr |= UBRLCR_BREAK; |
| 215 | else |
| 216 | ubrlcr &= ~UBRLCR_BREAK; |
Alexander Shiyan | 093a9e2 | 2013-12-31 20:49:42 +0400 | [diff] [blame] | 217 | writel(ubrlcr, port->membase + UBRLCR_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | } |
| 219 | |
Peter Hurley | 732a84a | 2014-11-05 13:11:43 -0500 | [diff] [blame] | 220 | static void uart_clps711x_set_ldisc(struct uart_port *port, |
| 221 | struct ktermios *termios) |
Alexander Shiyan | 71b9e8c | 2013-12-31 20:49:41 +0400 | [diff] [blame] | 222 | { |
| 223 | if (!port->line) { |
| 224 | struct clps711x_port *s = dev_get_drvdata(port->dev); |
| 225 | |
| 226 | regmap_update_bits(s->syscon, SYSCON_OFFSET, SYSCON1_SIREN, |
Peter Hurley | 732a84a | 2014-11-05 13:11:43 -0500 | [diff] [blame] | 227 | (termios->c_line == N_IRDA) ? SYSCON1_SIREN : 0); |
Alexander Shiyan | 71b9e8c | 2013-12-31 20:49:41 +0400 | [diff] [blame] | 228 | } |
| 229 | } |
| 230 | |
Alexander Shiyan | a1c25f2 | 2012-10-14 11:05:34 +0400 | [diff] [blame] | 231 | static int uart_clps711x_startup(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | { |
Alexander Shiyan | 3c7e9eb | 2012-10-14 11:05:25 +0400 | [diff] [blame] | 233 | struct clps711x_port *s = dev_get_drvdata(port->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | |
Alexander Shiyan | f52ede2 | 2012-10-14 11:05:32 +0400 | [diff] [blame] | 235 | /* Disable break */ |
Alexander Shiyan | 093a9e2 | 2013-12-31 20:49:42 +0400 | [diff] [blame] | 236 | writel(readl(port->membase + UBRLCR_OFFSET) & ~UBRLCR_BREAK, |
| 237 | port->membase + UBRLCR_OFFSET); |
Alexander Shiyan | f52ede2 | 2012-10-14 11:05:32 +0400 | [diff] [blame] | 238 | |
| 239 | /* Enable the port */ |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 240 | return regmap_update_bits(s->syscon, SYSCON_OFFSET, |
| 241 | SYSCON_UARTEN, SYSCON_UARTEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | } |
| 243 | |
Alexander Shiyan | a1c25f2 | 2012-10-14 11:05:34 +0400 | [diff] [blame] | 244 | static void uart_clps711x_shutdown(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | { |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 246 | struct clps711x_port *s = dev_get_drvdata(port->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | |
Alexander Shiyan | f52ede2 | 2012-10-14 11:05:32 +0400 | [diff] [blame] | 248 | /* Disable the port */ |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 249 | regmap_update_bits(s->syscon, SYSCON_OFFSET, SYSCON_UARTEN, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | } |
| 251 | |
Alexander Shiyan | a1c25f2 | 2012-10-14 11:05:34 +0400 | [diff] [blame] | 252 | static void uart_clps711x_set_termios(struct uart_port *port, |
| 253 | struct ktermios *termios, |
| 254 | struct ktermios *old) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | { |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 256 | u32 ubrlcr; |
| 257 | unsigned int baud, quot; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | |
Alexander Shiyan | 7ae75e9 | 2012-10-14 11:05:33 +0400 | [diff] [blame] | 259 | /* Mask termios capabilities we don't support */ |
| 260 | termios->c_cflag &= ~CMSPAR; |
| 261 | termios->c_iflag &= ~(BRKINT | IGNBRK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | |
Alexander Shiyan | c08f015 | 2012-10-14 11:05:26 +0400 | [diff] [blame] | 263 | /* Ask the core to calculate the divisor for us */ |
| 264 | baud = uart_get_baud_rate(port, termios, old, port->uartclk / 4096, |
| 265 | port->uartclk / 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | quot = uart_get_divisor(port, baud); |
| 267 | |
| 268 | switch (termios->c_cflag & CSIZE) { |
| 269 | case CS5: |
| 270 | ubrlcr = UBRLCR_WRDLEN5; |
| 271 | break; |
| 272 | case CS6: |
| 273 | ubrlcr = UBRLCR_WRDLEN6; |
| 274 | break; |
| 275 | case CS7: |
| 276 | ubrlcr = UBRLCR_WRDLEN7; |
| 277 | break; |
Alexander Shiyan | a1c25f2 | 2012-10-14 11:05:34 +0400 | [diff] [blame] | 278 | case CS8: |
| 279 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | ubrlcr = UBRLCR_WRDLEN8; |
| 281 | break; |
| 282 | } |
Alexander Shiyan | 7ae75e9 | 2012-10-14 11:05:33 +0400 | [diff] [blame] | 283 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | if (termios->c_cflag & CSTOPB) |
| 285 | ubrlcr |= UBRLCR_XSTOP; |
Alexander Shiyan | 7ae75e9 | 2012-10-14 11:05:33 +0400 | [diff] [blame] | 286 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | if (termios->c_cflag & PARENB) { |
| 288 | ubrlcr |= UBRLCR_PRTEN; |
| 289 | if (!(termios->c_cflag & PARODD)) |
| 290 | ubrlcr |= UBRLCR_EVENPRT; |
| 291 | } |
Alexander Shiyan | cf03a88 | 2012-10-14 11:05:27 +0400 | [diff] [blame] | 292 | |
| 293 | /* Enable FIFO */ |
| 294 | ubrlcr |= UBRLCR_FIFOEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | |
Alexander Shiyan | 7ae75e9 | 2012-10-14 11:05:33 +0400 | [diff] [blame] | 296 | /* Set read status mask */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | port->read_status_mask = UARTDR_OVERR; |
| 298 | if (termios->c_iflag & INPCK) |
| 299 | port->read_status_mask |= UARTDR_PARERR | UARTDR_FRMERR; |
| 300 | |
Alexander Shiyan | 7ae75e9 | 2012-10-14 11:05:33 +0400 | [diff] [blame] | 301 | /* Set status ignore mask */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | port->ignore_status_mask = 0; |
Alexander Shiyan | 7ae75e9 | 2012-10-14 11:05:33 +0400 | [diff] [blame] | 303 | if (!(termios->c_cflag & CREAD)) |
| 304 | port->ignore_status_mask |= UARTDR_OVERR | UARTDR_PARERR | |
| 305 | UARTDR_FRMERR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | |
Alexander Shiyan | 7ae75e9 | 2012-10-14 11:05:33 +0400 | [diff] [blame] | 307 | uart_update_timeout(port, termios->c_cflag, baud); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | |
Alexander Shiyan | 093a9e2 | 2013-12-31 20:49:42 +0400 | [diff] [blame] | 309 | writel(ubrlcr | (quot - 1), port->membase + UBRLCR_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | } |
| 311 | |
Alexander Shiyan | a1c25f2 | 2012-10-14 11:05:34 +0400 | [diff] [blame] | 312 | static const char *uart_clps711x_type(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | { |
Alexander Shiyan | a1c25f2 | 2012-10-14 11:05:34 +0400 | [diff] [blame] | 314 | return (port->type == PORT_CLPS711X) ? "CLPS711X" : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | } |
| 316 | |
Alexander Shiyan | a1c25f2 | 2012-10-14 11:05:34 +0400 | [diff] [blame] | 317 | static void uart_clps711x_config_port(struct uart_port *port, int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | { |
| 319 | if (flags & UART_CONFIG_TYPE) |
| 320 | port->type = PORT_CLPS711X; |
| 321 | } |
| 322 | |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 323 | static void uart_clps711x_nop_void(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | { |
| 325 | } |
| 326 | |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 327 | static int uart_clps711x_nop_int(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | { |
| 329 | return 0; |
| 330 | } |
| 331 | |
Alexander Shiyan | a1c25f2 | 2012-10-14 11:05:34 +0400 | [diff] [blame] | 332 | static const struct uart_ops uart_clps711x_ops = { |
| 333 | .tx_empty = uart_clps711x_tx_empty, |
| 334 | .set_mctrl = uart_clps711x_set_mctrl, |
| 335 | .get_mctrl = uart_clps711x_get_mctrl, |
| 336 | .stop_tx = uart_clps711x_stop_tx, |
| 337 | .start_tx = uart_clps711x_start_tx, |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 338 | .stop_rx = uart_clps711x_nop_void, |
Alexander Shiyan | a1c25f2 | 2012-10-14 11:05:34 +0400 | [diff] [blame] | 339 | .break_ctl = uart_clps711x_break_ctl, |
Alexander Shiyan | 71b9e8c | 2013-12-31 20:49:41 +0400 | [diff] [blame] | 340 | .set_ldisc = uart_clps711x_set_ldisc, |
Alexander Shiyan | a1c25f2 | 2012-10-14 11:05:34 +0400 | [diff] [blame] | 341 | .startup = uart_clps711x_startup, |
| 342 | .shutdown = uart_clps711x_shutdown, |
| 343 | .set_termios = uart_clps711x_set_termios, |
| 344 | .type = uart_clps711x_type, |
| 345 | .config_port = uart_clps711x_config_port, |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 346 | .release_port = uart_clps711x_nop_void, |
| 347 | .request_port = uart_clps711x_nop_int, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | }; |
| 349 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | #ifdef CONFIG_SERIAL_CLPS711X_CONSOLE |
Alexander Shiyan | 117d5d4 | 2012-10-14 11:05:24 +0400 | [diff] [blame] | 351 | static void uart_clps711x_console_putchar(struct uart_port *port, int ch) |
Russell King | d358788 | 2006-03-20 20:00:09 +0000 | [diff] [blame] | 352 | { |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 353 | struct clps711x_port *s = dev_get_drvdata(port->dev); |
Alexander Shiyan | 2f310b8 | 2014-03-27 13:38:19 +0400 | [diff] [blame] | 354 | u32 sysflg = 0; |
Alexander Shiyan | 117d5d4 | 2012-10-14 11:05:24 +0400 | [diff] [blame] | 355 | |
Alexander Shiyan | 63e3ad3 | 2014-03-11 15:30:01 +0400 | [diff] [blame] | 356 | /* Wait for FIFO is not full */ |
Alexander Shiyan | 2f310b8 | 2014-03-27 13:38:19 +0400 | [diff] [blame] | 357 | do { |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 358 | regmap_read(s->syscon, SYSFLG_OFFSET, &sysflg); |
Alexander Shiyan | 2f310b8 | 2014-03-27 13:38:19 +0400 | [diff] [blame] | 359 | } while (sysflg & SYSFLG_UTXFF); |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 360 | |
Alexander Shiyan | 093a9e2 | 2013-12-31 20:49:42 +0400 | [diff] [blame] | 361 | writew(ch, port->membase + UARTDR_OFFSET); |
Russell King | d358788 | 2006-03-20 20:00:09 +0000 | [diff] [blame] | 362 | } |
| 363 | |
Alexander Shiyan | 117d5d4 | 2012-10-14 11:05:24 +0400 | [diff] [blame] | 364 | static void uart_clps711x_console_write(struct console *co, const char *c, |
| 365 | unsigned n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | { |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 367 | struct uart_port *port = clps711x_uart.state[co->index].uart_port; |
| 368 | struct clps711x_port *s = dev_get_drvdata(port->dev); |
Alexander Shiyan | 2f310b8 | 2014-03-27 13:38:19 +0400 | [diff] [blame] | 369 | u32 sysflg = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | |
Alexander Shiyan | 117d5d4 | 2012-10-14 11:05:24 +0400 | [diff] [blame] | 371 | uart_console_write(port, c, n, uart_clps711x_console_putchar); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | |
Alexander Shiyan | 117d5d4 | 2012-10-14 11:05:24 +0400 | [diff] [blame] | 373 | /* Wait for transmitter to become empty */ |
Alexander Shiyan | 2f310b8 | 2014-03-27 13:38:19 +0400 | [diff] [blame] | 374 | do { |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 375 | regmap_read(s->syscon, SYSFLG_OFFSET, &sysflg); |
Alexander Shiyan | 2f310b8 | 2014-03-27 13:38:19 +0400 | [diff] [blame] | 376 | } while (sysflg & SYSFLG_UBUSY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | } |
| 378 | |
Alexander Shiyan | 117d5d4 | 2012-10-14 11:05:24 +0400 | [diff] [blame] | 379 | static int uart_clps711x_console_setup(struct console *co, char *options) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | { |
Alexander Shiyan | 117d5d4 | 2012-10-14 11:05:24 +0400 | [diff] [blame] | 381 | int baud = 38400, bits = 8, parity = 'n', flow = 'n'; |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 382 | int ret, index = co->index; |
| 383 | struct clps711x_port *s; |
| 384 | struct uart_port *port; |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 385 | unsigned int quot; |
Alexander Shiyan | 093a9e2 | 2013-12-31 20:49:42 +0400 | [diff] [blame] | 386 | u32 ubrlcr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 388 | if (index < 0 || index >= UART_CLPS711X_NR) |
| 389 | return -EINVAL; |
| 390 | |
| 391 | port = clps711x_uart.state[index].uart_port; |
| 392 | if (!port) |
| 393 | return -ENODEV; |
| 394 | |
| 395 | s = dev_get_drvdata(port->dev); |
| 396 | |
| 397 | if (!options) { |
Alexander Shiyan | 093a9e2 | 2013-12-31 20:49:42 +0400 | [diff] [blame] | 398 | u32 syscon = 0; |
| 399 | |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 400 | regmap_read(s->syscon, SYSCON_OFFSET, &syscon); |
| 401 | if (syscon & SYSCON_UARTEN) { |
Alexander Shiyan | 093a9e2 | 2013-12-31 20:49:42 +0400 | [diff] [blame] | 402 | ubrlcr = readl(port->membase + UBRLCR_OFFSET); |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 403 | |
| 404 | if (ubrlcr & UBRLCR_PRTEN) { |
| 405 | if (ubrlcr & UBRLCR_EVENPRT) |
| 406 | parity = 'e'; |
| 407 | else |
| 408 | parity = 'o'; |
| 409 | } |
| 410 | |
| 411 | if ((ubrlcr & UBRLCR_WRDLEN_MASK) == UBRLCR_WRDLEN7) |
| 412 | bits = 7; |
| 413 | |
| 414 | quot = ubrlcr & UBRLCR_BAUD_MASK; |
| 415 | baud = port->uartclk / (16 * (quot + 1)); |
| 416 | } |
| 417 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | uart_parse_options(options, &baud, &parity, &bits, &flow); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 420 | ret = uart_set_options(port, co, baud, parity, bits, flow); |
| 421 | if (ret) |
| 422 | return ret; |
| 423 | |
| 424 | return regmap_update_bits(s->syscon, SYSCON_OFFSET, |
| 425 | SYSCON_UARTEN, SYSCON_UARTEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | } |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 427 | |
| 428 | static struct console clps711x_console = { |
| 429 | .name = UART_CLPS711X_DEVNAME, |
| 430 | .device = uart_console_device, |
| 431 | .write = uart_clps711x_console_write, |
| 432 | .setup = uart_clps711x_console_setup, |
| 433 | .flags = CON_PRINTBUFFER, |
| 434 | .index = -1, |
| 435 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | #endif |
| 437 | |
Bill Pemberton | 9671f09 | 2012-11-19 13:21:50 -0500 | [diff] [blame] | 438 | static int uart_clps711x_probe(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | { |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 440 | struct device_node *np = pdev->dev.of_node; |
Alexander Shiyan | 117d5d4 | 2012-10-14 11:05:24 +0400 | [diff] [blame] | 441 | struct clps711x_port *s; |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 442 | struct resource *res; |
| 443 | struct clk *uart_clk; |
Alexander Shiyan | db4a6cb | 2018-12-21 14:10:23 +0300 | [diff] [blame] | 444 | int irq, ret; |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 445 | |
| 446 | s = devm_kzalloc(&pdev->dev, sizeof(*s), GFP_KERNEL); |
| 447 | if (!s) |
Alexander Shiyan | 117d5d4 | 2012-10-14 11:05:24 +0400 | [diff] [blame] | 448 | return -ENOMEM; |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 449 | |
| 450 | uart_clk = devm_clk_get(&pdev->dev, NULL); |
| 451 | if (IS_ERR(uart_clk)) |
| 452 | return PTR_ERR(uart_clk); |
| 453 | |
| 454 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 455 | s->port.membase = devm_ioremap_resource(&pdev->dev, res); |
| 456 | if (IS_ERR(s->port.membase)) |
| 457 | return PTR_ERR(s->port.membase); |
| 458 | |
Guenter Roeck | 8f5405c | 2016-02-09 07:06:47 -0800 | [diff] [blame] | 459 | irq = platform_get_irq(pdev, 0); |
| 460 | if (irq < 0) |
| 461 | return irq; |
| 462 | s->port.irq = irq; |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 463 | |
| 464 | s->rx_irq = platform_get_irq(pdev, 1); |
Guenter Roeck | 8f5405c | 2016-02-09 07:06:47 -0800 | [diff] [blame] | 465 | if (s->rx_irq < 0) |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 466 | return s->rx_irq; |
| 467 | |
Alexander Shiyan | db4a6cb | 2018-12-21 14:10:23 +0300 | [diff] [blame] | 468 | s->syscon = syscon_regmap_lookup_by_phandle(np, "syscon"); |
| 469 | if (IS_ERR(s->syscon)) |
| 470 | return PTR_ERR(s->syscon); |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 471 | |
Alexander Shiyan | db4a6cb | 2018-12-21 14:10:23 +0300 | [diff] [blame] | 472 | s->port.line = of_alias_get_id(np, "serial"); |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 473 | s->port.dev = &pdev->dev; |
| 474 | s->port.iotype = UPIO_MEM32; |
| 475 | s->port.mapbase = res->start; |
| 476 | s->port.type = PORT_CLPS711X; |
| 477 | s->port.fifosize = 16; |
Dmitry Safonov | 76f82db | 2019-12-13 00:06:12 +0000 | [diff] [blame] | 478 | s->port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_CLPS711X_CONSOLE); |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 479 | s->port.flags = UPF_SKIP_TEST | UPF_FIXED_TYPE; |
| 480 | s->port.uartclk = clk_get_rate(uart_clk); |
| 481 | s->port.ops = &uart_clps711x_ops; |
| 482 | |
Alexander Shiyan | 117d5d4 | 2012-10-14 11:05:24 +0400 | [diff] [blame] | 483 | platform_set_drvdata(pdev, s); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | |
Uwe Kleine-König | 7d8c70d | 2015-09-30 10:19:40 +0200 | [diff] [blame] | 485 | s->gpios = mctrl_gpio_init_noauto(&pdev->dev, 0); |
Uwe Kleine-König | f059a45 | 2015-02-12 15:24:39 +0100 | [diff] [blame] | 486 | if (IS_ERR(s->gpios)) |
| 487 | return PTR_ERR(s->gpios); |
Alexander Shiyan | 62b0a1b | 2014-09-06 07:20:15 +0400 | [diff] [blame] | 488 | |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 489 | ret = uart_add_one_port(&clps711x_uart, &s->port); |
| 490 | if (ret) |
| 491 | return ret; |
Alexander Shiyan | c08f015 | 2012-10-14 11:05:26 +0400 | [diff] [blame] | 492 | |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 493 | /* Disable port */ |
| 494 | if (!uart_console(&s->port)) |
| 495 | regmap_update_bits(s->syscon, SYSCON_OFFSET, SYSCON_UARTEN, 0); |
| 496 | |
| 497 | s->tx_enabled = 1; |
| 498 | |
| 499 | ret = devm_request_irq(&pdev->dev, s->port.irq, uart_clps711x_int_tx, 0, |
| 500 | dev_name(&pdev->dev), &s->port); |
Alexander Shiyan | 117d5d4 | 2012-10-14 11:05:24 +0400 | [diff] [blame] | 501 | if (ret) { |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 502 | uart_remove_one_port(&clps711x_uart, &s->port); |
Jingoo Han | 43b829b | 2013-06-25 10:08:49 +0900 | [diff] [blame] | 503 | return ret; |
Alexander Shiyan | 117d5d4 | 2012-10-14 11:05:24 +0400 | [diff] [blame] | 504 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 506 | ret = devm_request_irq(&pdev->dev, s->rx_irq, uart_clps711x_int_rx, 0, |
| 507 | dev_name(&pdev->dev), &s->port); |
| 508 | if (ret) |
| 509 | uart_remove_one_port(&clps711x_uart, &s->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 511 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | } |
| 513 | |
Bill Pemberton | ae8d8a1 | 2012-11-19 13:26:18 -0500 | [diff] [blame] | 514 | static int uart_clps711x_remove(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | { |
Alexander Shiyan | 117d5d4 | 2012-10-14 11:05:24 +0400 | [diff] [blame] | 516 | struct clps711x_port *s = platform_get_drvdata(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 518 | return uart_remove_one_port(&clps711x_uart, &s->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | } |
| 520 | |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 521 | static const struct of_device_id __maybe_unused clps711x_uart_dt_ids[] = { |
Alexander Shiyan | d305345 | 2016-06-04 10:09:57 +0300 | [diff] [blame] | 522 | { .compatible = "cirrus,ep7209-uart", }, |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 523 | { } |
| 524 | }; |
| 525 | MODULE_DEVICE_TABLE(of, clps711x_uart_dt_ids); |
| 526 | |
| 527 | static struct platform_driver clps711x_uart_platform = { |
Alexander Shiyan | 9511372 | 2012-10-14 11:05:23 +0400 | [diff] [blame] | 528 | .driver = { |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 529 | .name = "clps711x-uart", |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 530 | .of_match_table = of_match_ptr(clps711x_uart_dt_ids), |
Alexander Shiyan | 9511372 | 2012-10-14 11:05:23 +0400 | [diff] [blame] | 531 | }, |
| 532 | .probe = uart_clps711x_probe, |
Bill Pemberton | 2d47b71 | 2012-11-19 13:21:34 -0500 | [diff] [blame] | 533 | .remove = uart_clps711x_remove, |
Alexander Shiyan | 9511372 | 2012-10-14 11:05:23 +0400 | [diff] [blame] | 534 | }; |
Alexander Shiyan | 9511372 | 2012-10-14 11:05:23 +0400 | [diff] [blame] | 535 | |
| 536 | static int __init uart_clps711x_init(void) |
| 537 | { |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 538 | int ret; |
| 539 | |
| 540 | #ifdef CONFIG_SERIAL_CLPS711X_CONSOLE |
| 541 | clps711x_uart.cons = &clps711x_console; |
| 542 | clps711x_console.data = &clps711x_uart; |
| 543 | #endif |
| 544 | |
| 545 | ret = uart_register_driver(&clps711x_uart); |
| 546 | if (ret) |
| 547 | return ret; |
| 548 | |
| 549 | return platform_driver_register(&clps711x_uart_platform); |
Alexander Shiyan | 9511372 | 2012-10-14 11:05:23 +0400 | [diff] [blame] | 550 | } |
| 551 | module_init(uart_clps711x_init); |
| 552 | |
| 553 | static void __exit uart_clps711x_exit(void) |
| 554 | { |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 555 | platform_driver_unregister(&clps711x_uart_platform); |
| 556 | uart_unregister_driver(&clps711x_uart); |
Alexander Shiyan | 9511372 | 2012-10-14 11:05:23 +0400 | [diff] [blame] | 557 | } |
| 558 | module_exit(uart_clps711x_exit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | |
| 560 | MODULE_AUTHOR("Deep Blue Solutions Ltd"); |
Alexander Shiyan | 9511372 | 2012-10-14 11:05:23 +0400 | [diff] [blame] | 561 | MODULE_DESCRIPTION("CLPS711X serial driver"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | MODULE_LICENSE("GPL"); |