Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 1 | /* |
| 2 | * uartlite.c: Serial driver for Xilinx uartlite serial controller |
| 3 | * |
Grant Likely | 852e1ea | 2007-10-02 12:16:04 +1000 | [diff] [blame] | 4 | * Copyright (C) 2006 Peter Korsgaard <jacmet@sunsite.dk> |
| 5 | * Copyright (C) 2007 Secret Lab Technologies Ltd. |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 6 | * |
| 7 | * This file is licensed under the terms of the GNU General Public License |
| 8 | * version 2. This program is licensed "as is" without any warranty of any |
| 9 | * kind, whether express or implied. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/platform_device.h> |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/console.h> |
| 15 | #include <linux/serial.h> |
| 16 | #include <linux/serial_core.h> |
| 17 | #include <linux/tty.h> |
Jiri Slaby | ee160a3 | 2011-09-01 16:20:57 +0200 | [diff] [blame] | 18 | #include <linux/tty_flip.h> |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 19 | #include <linux/delay.h> |
| 20 | #include <linux/interrupt.h> |
Stephen Neuendorffer | 0e349b0 | 2008-01-09 06:35:05 +1100 | [diff] [blame] | 21 | #include <linux/init.h> |
Michal Simek | 3240b48d | 2013-02-11 19:04:33 +0100 | [diff] [blame] | 22 | #include <linux/io.h> |
Stephen Neuendorffer | 0e349b0 | 2008-01-09 06:35:05 +1100 | [diff] [blame] | 23 | #include <linux/of.h> |
Grant Likely | 22ae782 | 2010-07-29 11:49:01 -0600 | [diff] [blame] | 24 | #include <linux/of_address.h> |
Grant Likely | 852e1ea | 2007-10-02 12:16:04 +1000 | [diff] [blame] | 25 | #include <linux/of_device.h> |
| 26 | #include <linux/of_platform.h> |
Stephen Neuendorffer | 0e349b0 | 2008-01-09 06:35:05 +1100 | [diff] [blame] | 27 | |
Grant Likely | 0077582 | 2007-10-02 12:15:49 +1000 | [diff] [blame] | 28 | #define ULITE_NAME "ttyUL" |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 29 | #define ULITE_MAJOR 204 |
| 30 | #define ULITE_MINOR 187 |
Maarten Brock | acf5e6c | 2016-02-16 18:59:01 +0100 | [diff] [blame] | 31 | #define ULITE_NR_UARTS 16 |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 32 | |
Grant Likely | 435706b | 2007-10-02 12:15:59 +1000 | [diff] [blame] | 33 | /* --------------------------------------------------------------------- |
| 34 | * Register definitions |
| 35 | * |
| 36 | * For register details see datasheet: |
Michal Simek | 6d53c3b | 2013-02-11 19:04:34 +0100 | [diff] [blame] | 37 | * http://www.xilinx.com/support/documentation/ip_documentation/opb_uartlite.pdf |
Grant Likely | 435706b | 2007-10-02 12:15:59 +1000 | [diff] [blame] | 38 | */ |
| 39 | |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 40 | #define ULITE_RX 0x00 |
| 41 | #define ULITE_TX 0x04 |
| 42 | #define ULITE_STATUS 0x08 |
| 43 | #define ULITE_CONTROL 0x0c |
| 44 | |
| 45 | #define ULITE_REGION 16 |
| 46 | |
| 47 | #define ULITE_STATUS_RXVALID 0x01 |
| 48 | #define ULITE_STATUS_RXFULL 0x02 |
| 49 | #define ULITE_STATUS_TXEMPTY 0x04 |
| 50 | #define ULITE_STATUS_TXFULL 0x08 |
| 51 | #define ULITE_STATUS_IE 0x10 |
| 52 | #define ULITE_STATUS_OVERRUN 0x20 |
| 53 | #define ULITE_STATUS_FRAME 0x40 |
| 54 | #define ULITE_STATUS_PARITY 0x80 |
| 55 | |
| 56 | #define ULITE_CONTROL_RST_TX 0x01 |
| 57 | #define ULITE_CONTROL_RST_RX 0x02 |
| 58 | #define ULITE_CONTROL_IE 0x10 |
| 59 | |
Michal Simek | 6d53c3b | 2013-02-11 19:04:34 +0100 | [diff] [blame] | 60 | struct uartlite_reg_ops { |
| 61 | u32 (*in)(void __iomem *addr); |
| 62 | void (*out)(u32 val, void __iomem *addr); |
| 63 | }; |
| 64 | |
| 65 | static u32 uartlite_inbe32(void __iomem *addr) |
| 66 | { |
| 67 | return ioread32be(addr); |
| 68 | } |
| 69 | |
| 70 | static void uartlite_outbe32(u32 val, void __iomem *addr) |
| 71 | { |
| 72 | iowrite32be(val, addr); |
| 73 | } |
| 74 | |
Maarten Brock | 2905697 | 2016-02-16 18:59:02 +0100 | [diff] [blame] | 75 | static const struct uartlite_reg_ops uartlite_be = { |
Michal Simek | 6d53c3b | 2013-02-11 19:04:34 +0100 | [diff] [blame] | 76 | .in = uartlite_inbe32, |
| 77 | .out = uartlite_outbe32, |
| 78 | }; |
| 79 | |
| 80 | static u32 uartlite_inle32(void __iomem *addr) |
| 81 | { |
| 82 | return ioread32(addr); |
| 83 | } |
| 84 | |
| 85 | static void uartlite_outle32(u32 val, void __iomem *addr) |
| 86 | { |
| 87 | iowrite32(val, addr); |
| 88 | } |
| 89 | |
Maarten Brock | 2905697 | 2016-02-16 18:59:02 +0100 | [diff] [blame] | 90 | static const struct uartlite_reg_ops uartlite_le = { |
Michal Simek | 6d53c3b | 2013-02-11 19:04:34 +0100 | [diff] [blame] | 91 | .in = uartlite_inle32, |
| 92 | .out = uartlite_outle32, |
| 93 | }; |
| 94 | |
| 95 | static inline u32 uart_in32(u32 offset, struct uart_port *port) |
| 96 | { |
Maarten Brock | 2905697 | 2016-02-16 18:59:02 +0100 | [diff] [blame] | 97 | const struct uartlite_reg_ops *reg_ops = port->private_data; |
Michal Simek | 6d53c3b | 2013-02-11 19:04:34 +0100 | [diff] [blame] | 98 | |
| 99 | return reg_ops->in(port->membase + offset); |
| 100 | } |
| 101 | |
| 102 | static inline void uart_out32(u32 val, u32 offset, struct uart_port *port) |
| 103 | { |
Maarten Brock | 2905697 | 2016-02-16 18:59:02 +0100 | [diff] [blame] | 104 | const struct uartlite_reg_ops *reg_ops = port->private_data; |
Michal Simek | 6d53c3b | 2013-02-11 19:04:34 +0100 | [diff] [blame] | 105 | |
| 106 | reg_ops->out(val, port->membase + offset); |
| 107 | } |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 108 | |
Grant Likely | 483c79d | 2007-10-02 12:15:44 +1000 | [diff] [blame] | 109 | static struct uart_port ulite_ports[ULITE_NR_UARTS]; |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 110 | |
Grant Likely | 435706b | 2007-10-02 12:15:59 +1000 | [diff] [blame] | 111 | /* --------------------------------------------------------------------- |
| 112 | * Core UART driver operations |
| 113 | */ |
| 114 | |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 115 | static int ulite_receive(struct uart_port *port, int stat) |
| 116 | { |
Jiri Slaby | 92a19f9 | 2013-01-03 15:53:03 +0100 | [diff] [blame] | 117 | struct tty_port *tport = &port->state->port; |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 118 | unsigned char ch = 0; |
| 119 | char flag = TTY_NORMAL; |
| 120 | |
| 121 | if ((stat & (ULITE_STATUS_RXVALID | ULITE_STATUS_OVERRUN |
| 122 | | ULITE_STATUS_FRAME)) == 0) |
| 123 | return 0; |
| 124 | |
| 125 | /* stats */ |
| 126 | if (stat & ULITE_STATUS_RXVALID) { |
| 127 | port->icount.rx++; |
Michal Simek | 6d53c3b | 2013-02-11 19:04:34 +0100 | [diff] [blame] | 128 | ch = uart_in32(ULITE_RX, port); |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 129 | |
| 130 | if (stat & ULITE_STATUS_PARITY) |
| 131 | port->icount.parity++; |
| 132 | } |
| 133 | |
| 134 | if (stat & ULITE_STATUS_OVERRUN) |
| 135 | port->icount.overrun++; |
| 136 | |
| 137 | if (stat & ULITE_STATUS_FRAME) |
| 138 | port->icount.frame++; |
| 139 | |
| 140 | |
| 141 | /* drop byte with parity error if IGNPAR specificed */ |
| 142 | if (stat & port->ignore_status_mask & ULITE_STATUS_PARITY) |
| 143 | stat &= ~ULITE_STATUS_RXVALID; |
| 144 | |
| 145 | stat &= port->read_status_mask; |
| 146 | |
| 147 | if (stat & ULITE_STATUS_PARITY) |
| 148 | flag = TTY_PARITY; |
| 149 | |
| 150 | |
| 151 | stat &= ~port->ignore_status_mask; |
| 152 | |
| 153 | if (stat & ULITE_STATUS_RXVALID) |
Jiri Slaby | 92a19f9 | 2013-01-03 15:53:03 +0100 | [diff] [blame] | 154 | tty_insert_flip_char(tport, ch, flag); |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 155 | |
| 156 | if (stat & ULITE_STATUS_FRAME) |
Jiri Slaby | 92a19f9 | 2013-01-03 15:53:03 +0100 | [diff] [blame] | 157 | tty_insert_flip_char(tport, 0, TTY_FRAME); |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 158 | |
| 159 | if (stat & ULITE_STATUS_OVERRUN) |
Jiri Slaby | 92a19f9 | 2013-01-03 15:53:03 +0100 | [diff] [blame] | 160 | tty_insert_flip_char(tport, 0, TTY_OVERRUN); |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 161 | |
| 162 | return 1; |
| 163 | } |
| 164 | |
| 165 | static int ulite_transmit(struct uart_port *port, int stat) |
| 166 | { |
Alan Cox | ebd2c8f | 2009-09-19 13:13:28 -0700 | [diff] [blame] | 167 | struct circ_buf *xmit = &port->state->xmit; |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 168 | |
| 169 | if (stat & ULITE_STATUS_TXFULL) |
| 170 | return 0; |
| 171 | |
| 172 | if (port->x_char) { |
Michal Simek | 6d53c3b | 2013-02-11 19:04:34 +0100 | [diff] [blame] | 173 | uart_out32(port->x_char, ULITE_TX, port); |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 174 | port->x_char = 0; |
| 175 | port->icount.tx++; |
| 176 | return 1; |
| 177 | } |
| 178 | |
| 179 | if (uart_circ_empty(xmit) || uart_tx_stopped(port)) |
| 180 | return 0; |
| 181 | |
Michal Simek | 6d53c3b | 2013-02-11 19:04:34 +0100 | [diff] [blame] | 182 | uart_out32(xmit->buf[xmit->tail], ULITE_TX, port); |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 183 | xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE-1); |
| 184 | port->icount.tx++; |
| 185 | |
| 186 | /* wake up */ |
| 187 | if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) |
| 188 | uart_write_wakeup(port); |
| 189 | |
| 190 | return 1; |
| 191 | } |
| 192 | |
| 193 | static irqreturn_t ulite_isr(int irq, void *dev_id) |
| 194 | { |
Jeff Garzik | 15aafa2 | 2008-02-06 01:36:20 -0800 | [diff] [blame] | 195 | struct uart_port *port = dev_id; |
Maarten Brock | 19606ea | 2016-02-16 18:59:03 +0100 | [diff] [blame^] | 196 | int stat, busy, n = 0; |
Rich Felker | 9e370d2 | 2016-01-08 15:33:50 -0500 | [diff] [blame] | 197 | unsigned long flags; |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 198 | |
| 199 | do { |
Maarten Brock | 19606ea | 2016-02-16 18:59:03 +0100 | [diff] [blame^] | 200 | spin_lock_irqsave(&port->lock, flags); |
| 201 | stat = uart_in32(ULITE_STATUS, port); |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 202 | busy = ulite_receive(port, stat); |
| 203 | busy |= ulite_transmit(port, stat); |
Maarten Brock | 19606ea | 2016-02-16 18:59:03 +0100 | [diff] [blame^] | 204 | spin_unlock_irqrestore(&port->lock, flags); |
Peter Korsgaard | d2cfe96 | 2009-09-09 16:54:04 +0200 | [diff] [blame] | 205 | n++; |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 206 | } while (busy); |
| 207 | |
Peter Korsgaard | d2cfe96 | 2009-09-09 16:54:04 +0200 | [diff] [blame] | 208 | /* work done? */ |
| 209 | if (n > 1) { |
Jiri Slaby | 2e124b4 | 2013-01-03 15:53:06 +0100 | [diff] [blame] | 210 | tty_flip_buffer_push(&port->state->port); |
Peter Korsgaard | d2cfe96 | 2009-09-09 16:54:04 +0200 | [diff] [blame] | 211 | return IRQ_HANDLED; |
| 212 | } else { |
| 213 | return IRQ_NONE; |
| 214 | } |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | static unsigned int ulite_tx_empty(struct uart_port *port) |
| 218 | { |
| 219 | unsigned long flags; |
| 220 | unsigned int ret; |
| 221 | |
| 222 | spin_lock_irqsave(&port->lock, flags); |
Michal Simek | 6d53c3b | 2013-02-11 19:04:34 +0100 | [diff] [blame] | 223 | ret = uart_in32(ULITE_STATUS, port); |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 224 | spin_unlock_irqrestore(&port->lock, flags); |
| 225 | |
| 226 | return ret & ULITE_STATUS_TXEMPTY ? TIOCSER_TEMT : 0; |
| 227 | } |
| 228 | |
| 229 | static unsigned int ulite_get_mctrl(struct uart_port *port) |
| 230 | { |
| 231 | return TIOCM_CTS | TIOCM_DSR | TIOCM_CAR; |
| 232 | } |
| 233 | |
| 234 | static void ulite_set_mctrl(struct uart_port *port, unsigned int mctrl) |
| 235 | { |
| 236 | /* N/A */ |
| 237 | } |
| 238 | |
| 239 | static void ulite_stop_tx(struct uart_port *port) |
| 240 | { |
| 241 | /* N/A */ |
| 242 | } |
| 243 | |
| 244 | static void ulite_start_tx(struct uart_port *port) |
| 245 | { |
Michal Simek | 6d53c3b | 2013-02-11 19:04:34 +0100 | [diff] [blame] | 246 | ulite_transmit(port, uart_in32(ULITE_STATUS, port)); |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | static void ulite_stop_rx(struct uart_port *port) |
| 250 | { |
| 251 | /* don't forward any more data (like !CREAD) */ |
| 252 | port->ignore_status_mask = ULITE_STATUS_RXVALID | ULITE_STATUS_PARITY |
| 253 | | ULITE_STATUS_FRAME | ULITE_STATUS_OVERRUN; |
| 254 | } |
| 255 | |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 256 | static void ulite_break_ctl(struct uart_port *port, int ctl) |
| 257 | { |
| 258 | /* N/A */ |
| 259 | } |
| 260 | |
| 261 | static int ulite_startup(struct uart_port *port) |
| 262 | { |
| 263 | int ret; |
| 264 | |
Theodore Ts'o | fc4b186 | 2012-07-17 13:51:51 -0400 | [diff] [blame] | 265 | ret = request_irq(port->irq, ulite_isr, IRQF_SHARED, "uartlite", port); |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 266 | if (ret) |
| 267 | return ret; |
| 268 | |
Michal Simek | 6d53c3b | 2013-02-11 19:04:34 +0100 | [diff] [blame] | 269 | uart_out32(ULITE_CONTROL_RST_RX | ULITE_CONTROL_RST_TX, |
| 270 | ULITE_CONTROL, port); |
| 271 | uart_out32(ULITE_CONTROL_IE, ULITE_CONTROL, port); |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 272 | |
| 273 | return 0; |
| 274 | } |
| 275 | |
| 276 | static void ulite_shutdown(struct uart_port *port) |
| 277 | { |
Michal Simek | 6d53c3b | 2013-02-11 19:04:34 +0100 | [diff] [blame] | 278 | uart_out32(0, ULITE_CONTROL, port); |
| 279 | uart_in32(ULITE_CONTROL, port); /* dummy */ |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 280 | free_irq(port->irq, port); |
| 281 | } |
| 282 | |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 283 | static void ulite_set_termios(struct uart_port *port, struct ktermios *termios, |
| 284 | struct ktermios *old) |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 285 | { |
| 286 | unsigned long flags; |
| 287 | unsigned int baud; |
| 288 | |
| 289 | spin_lock_irqsave(&port->lock, flags); |
| 290 | |
| 291 | port->read_status_mask = ULITE_STATUS_RXVALID | ULITE_STATUS_OVERRUN |
| 292 | | ULITE_STATUS_TXFULL; |
| 293 | |
| 294 | if (termios->c_iflag & INPCK) |
| 295 | port->read_status_mask |= |
| 296 | ULITE_STATUS_PARITY | ULITE_STATUS_FRAME; |
| 297 | |
| 298 | port->ignore_status_mask = 0; |
| 299 | if (termios->c_iflag & IGNPAR) |
| 300 | port->ignore_status_mask |= ULITE_STATUS_PARITY |
| 301 | | ULITE_STATUS_FRAME | ULITE_STATUS_OVERRUN; |
| 302 | |
| 303 | /* ignore all characters if CREAD is not set */ |
| 304 | if ((termios->c_cflag & CREAD) == 0) |
| 305 | port->ignore_status_mask |= |
| 306 | ULITE_STATUS_RXVALID | ULITE_STATUS_PARITY |
| 307 | | ULITE_STATUS_FRAME | ULITE_STATUS_OVERRUN; |
| 308 | |
| 309 | /* update timeout */ |
| 310 | baud = uart_get_baud_rate(port, termios, old, 0, 460800); |
| 311 | uart_update_timeout(port, termios->c_cflag, baud); |
| 312 | |
| 313 | spin_unlock_irqrestore(&port->lock, flags); |
| 314 | } |
| 315 | |
| 316 | static const char *ulite_type(struct uart_port *port) |
| 317 | { |
| 318 | return port->type == PORT_UARTLITE ? "uartlite" : NULL; |
| 319 | } |
| 320 | |
| 321 | static void ulite_release_port(struct uart_port *port) |
| 322 | { |
| 323 | release_mem_region(port->mapbase, ULITE_REGION); |
| 324 | iounmap(port->membase); |
Al Viro | b81831c6 | 2007-02-09 16:38:25 +0000 | [diff] [blame] | 325 | port->membase = NULL; |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | static int ulite_request_port(struct uart_port *port) |
| 329 | { |
Michal Simek | 6d53c3b | 2013-02-11 19:04:34 +0100 | [diff] [blame] | 330 | int ret; |
| 331 | |
Grant Likely | a108096 | 2008-11-14 09:59:48 -0700 | [diff] [blame] | 332 | pr_debug("ulite console: port=%p; port->mapbase=%llx\n", |
| 333 | port, (unsigned long long) port->mapbase); |
Stephen Neuendorffer | 0e349b0 | 2008-01-09 06:35:05 +1100 | [diff] [blame] | 334 | |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 335 | if (!request_mem_region(port->mapbase, ULITE_REGION, "uartlite")) { |
| 336 | dev_err(port->dev, "Memory region busy\n"); |
| 337 | return -EBUSY; |
| 338 | } |
| 339 | |
| 340 | port->membase = ioremap(port->mapbase, ULITE_REGION); |
| 341 | if (!port->membase) { |
| 342 | dev_err(port->dev, "Unable to map registers\n"); |
| 343 | release_mem_region(port->mapbase, ULITE_REGION); |
| 344 | return -EBUSY; |
| 345 | } |
| 346 | |
Michal Simek | 6d53c3b | 2013-02-11 19:04:34 +0100 | [diff] [blame] | 347 | port->private_data = &uartlite_be; |
| 348 | ret = uart_in32(ULITE_CONTROL, port); |
| 349 | uart_out32(ULITE_CONTROL_RST_TX, ULITE_CONTROL, port); |
| 350 | ret = uart_in32(ULITE_STATUS, port); |
| 351 | /* Endianess detection */ |
| 352 | if ((ret & ULITE_STATUS_TXEMPTY) != ULITE_STATUS_TXEMPTY) |
| 353 | port->private_data = &uartlite_le; |
| 354 | |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 355 | return 0; |
| 356 | } |
| 357 | |
| 358 | static void ulite_config_port(struct uart_port *port, int flags) |
| 359 | { |
Peter Korsgaard | e21654a | 2006-12-22 16:38:40 +0100 | [diff] [blame] | 360 | if (!ulite_request_port(port)) |
| 361 | port->type = PORT_UARTLITE; |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | static int ulite_verify_port(struct uart_port *port, struct serial_struct *ser) |
| 365 | { |
| 366 | /* we don't want the core code to modify any port params */ |
| 367 | return -EINVAL; |
| 368 | } |
| 369 | |
Michal Simek | 8a28af7f | 2010-08-17 10:42:05 +0200 | [diff] [blame] | 370 | #ifdef CONFIG_CONSOLE_POLL |
| 371 | static int ulite_get_poll_char(struct uart_port *port) |
| 372 | { |
Michal Simek | 6d53c3b | 2013-02-11 19:04:34 +0100 | [diff] [blame] | 373 | if (!(uart_in32(ULITE_STATUS, port) & ULITE_STATUS_RXVALID)) |
Michal Simek | 8a28af7f | 2010-08-17 10:42:05 +0200 | [diff] [blame] | 374 | return NO_POLL_CHAR; |
| 375 | |
Michal Simek | 6d53c3b | 2013-02-11 19:04:34 +0100 | [diff] [blame] | 376 | return uart_in32(ULITE_RX, port); |
Michal Simek | 8a28af7f | 2010-08-17 10:42:05 +0200 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | static void ulite_put_poll_char(struct uart_port *port, unsigned char ch) |
| 380 | { |
Michal Simek | 6d53c3b | 2013-02-11 19:04:34 +0100 | [diff] [blame] | 381 | while (uart_in32(ULITE_STATUS, port) & ULITE_STATUS_TXFULL) |
Michal Simek | 8a28af7f | 2010-08-17 10:42:05 +0200 | [diff] [blame] | 382 | cpu_relax(); |
| 383 | |
| 384 | /* write char to device */ |
Michal Simek | 6d53c3b | 2013-02-11 19:04:34 +0100 | [diff] [blame] | 385 | uart_out32(ch, ULITE_TX, port); |
Michal Simek | 8a28af7f | 2010-08-17 10:42:05 +0200 | [diff] [blame] | 386 | } |
| 387 | #endif |
| 388 | |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 389 | static struct uart_ops ulite_ops = { |
| 390 | .tx_empty = ulite_tx_empty, |
| 391 | .set_mctrl = ulite_set_mctrl, |
| 392 | .get_mctrl = ulite_get_mctrl, |
| 393 | .stop_tx = ulite_stop_tx, |
| 394 | .start_tx = ulite_start_tx, |
| 395 | .stop_rx = ulite_stop_rx, |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 396 | .break_ctl = ulite_break_ctl, |
| 397 | .startup = ulite_startup, |
| 398 | .shutdown = ulite_shutdown, |
| 399 | .set_termios = ulite_set_termios, |
| 400 | .type = ulite_type, |
| 401 | .release_port = ulite_release_port, |
| 402 | .request_port = ulite_request_port, |
| 403 | .config_port = ulite_config_port, |
Michal Simek | 8a28af7f | 2010-08-17 10:42:05 +0200 | [diff] [blame] | 404 | .verify_port = ulite_verify_port, |
| 405 | #ifdef CONFIG_CONSOLE_POLL |
| 406 | .poll_get_char = ulite_get_poll_char, |
| 407 | .poll_put_char = ulite_put_poll_char, |
| 408 | #endif |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 409 | }; |
| 410 | |
Grant Likely | 435706b | 2007-10-02 12:15:59 +1000 | [diff] [blame] | 411 | /* --------------------------------------------------------------------- |
| 412 | * Console driver operations |
| 413 | */ |
| 414 | |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 415 | #ifdef CONFIG_SERIAL_UARTLITE_CONSOLE |
| 416 | static void ulite_console_wait_tx(struct uart_port *port) |
| 417 | { |
Grant Likely | 1d6b698 | 2007-10-23 14:27:46 +1000 | [diff] [blame] | 418 | u8 val; |
Michal Simek | d335215 | 2014-05-06 06:46:15 +0200 | [diff] [blame] | 419 | unsigned long timeout; |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 420 | |
Michal Simek | d335215 | 2014-05-06 06:46:15 +0200 | [diff] [blame] | 421 | /* |
| 422 | * Spin waiting for TX fifo to have space available. |
| 423 | * When using the Microblaze Debug Module this can take up to 1s |
| 424 | */ |
| 425 | timeout = jiffies + msecs_to_jiffies(1000); |
| 426 | while (1) { |
Michal Simek | 6d53c3b | 2013-02-11 19:04:34 +0100 | [diff] [blame] | 427 | val = uart_in32(ULITE_STATUS, port); |
Grant Likely | 1d6b698 | 2007-10-23 14:27:46 +1000 | [diff] [blame] | 428 | if ((val & ULITE_STATUS_TXFULL) == 0) |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 429 | break; |
Michal Simek | d335215 | 2014-05-06 06:46:15 +0200 | [diff] [blame] | 430 | if (time_after(jiffies, timeout)) { |
| 431 | dev_warn(port->dev, |
| 432 | "timeout waiting for TX buffer empty\n"); |
| 433 | break; |
| 434 | } |
Grant Likely | 1d6b698 | 2007-10-23 14:27:46 +1000 | [diff] [blame] | 435 | cpu_relax(); |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 436 | } |
| 437 | } |
| 438 | |
| 439 | static void ulite_console_putchar(struct uart_port *port, int ch) |
| 440 | { |
| 441 | ulite_console_wait_tx(port); |
Michal Simek | 6d53c3b | 2013-02-11 19:04:34 +0100 | [diff] [blame] | 442 | uart_out32(ch, ULITE_TX, port); |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | static void ulite_console_write(struct console *co, const char *s, |
| 446 | unsigned int count) |
| 447 | { |
Grant Likely | 483c79d | 2007-10-02 12:15:44 +1000 | [diff] [blame] | 448 | struct uart_port *port = &ulite_ports[co->index]; |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 449 | unsigned long flags; |
| 450 | unsigned int ier; |
| 451 | int locked = 1; |
| 452 | |
| 453 | if (oops_in_progress) { |
| 454 | locked = spin_trylock_irqsave(&port->lock, flags); |
| 455 | } else |
| 456 | spin_lock_irqsave(&port->lock, flags); |
| 457 | |
| 458 | /* save and disable interrupt */ |
Michal Simek | 6d53c3b | 2013-02-11 19:04:34 +0100 | [diff] [blame] | 459 | ier = uart_in32(ULITE_STATUS, port) & ULITE_STATUS_IE; |
| 460 | uart_out32(0, ULITE_CONTROL, port); |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 461 | |
| 462 | uart_console_write(port, s, count, ulite_console_putchar); |
| 463 | |
| 464 | ulite_console_wait_tx(port); |
| 465 | |
| 466 | /* restore interrupt state */ |
| 467 | if (ier) |
Michal Simek | 6d53c3b | 2013-02-11 19:04:34 +0100 | [diff] [blame] | 468 | uart_out32(ULITE_CONTROL_IE, ULITE_CONTROL, port); |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 469 | |
| 470 | if (locked) |
| 471 | spin_unlock_irqrestore(&port->lock, flags); |
| 472 | } |
| 473 | |
Bill Pemberton | 9671f09 | 2012-11-19 13:21:50 -0500 | [diff] [blame] | 474 | static int ulite_console_setup(struct console *co, char *options) |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 475 | { |
| 476 | struct uart_port *port; |
| 477 | int baud = 9600; |
| 478 | int bits = 8; |
| 479 | int parity = 'n'; |
| 480 | int flow = 'n'; |
| 481 | |
| 482 | if (co->index < 0 || co->index >= ULITE_NR_UARTS) |
| 483 | return -EINVAL; |
| 484 | |
Grant Likely | 483c79d | 2007-10-02 12:15:44 +1000 | [diff] [blame] | 485 | port = &ulite_ports[co->index]; |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 486 | |
Grant Likely | 3de66a1 | 2008-02-06 10:23:41 -0700 | [diff] [blame] | 487 | /* Has the device been initialized yet? */ |
Grant Likely | fb4e6e6 | 2007-10-02 12:16:09 +1000 | [diff] [blame] | 488 | if (!port->mapbase) { |
| 489 | pr_debug("console on ttyUL%i not present\n", co->index); |
| 490 | return -ENODEV; |
| 491 | } |
| 492 | |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 493 | /* not initialized yet? */ |
Grant Likely | 852e1ea | 2007-10-02 12:16:04 +1000 | [diff] [blame] | 494 | if (!port->membase) { |
Grant Likely | fb4e6e6 | 2007-10-02 12:16:09 +1000 | [diff] [blame] | 495 | if (ulite_request_port(port)) |
| 496 | return -ENODEV; |
Grant Likely | 852e1ea | 2007-10-02 12:16:04 +1000 | [diff] [blame] | 497 | } |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 498 | |
| 499 | if (options) |
| 500 | uart_parse_options(options, &baud, &parity, &bits, &flow); |
| 501 | |
| 502 | return uart_set_options(port, co, baud, parity, bits, flow); |
| 503 | } |
| 504 | |
| 505 | static struct uart_driver ulite_uart_driver; |
| 506 | |
| 507 | static struct console ulite_console = { |
Grant Likely | 0077582 | 2007-10-02 12:15:49 +1000 | [diff] [blame] | 508 | .name = ULITE_NAME, |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 509 | .write = ulite_console_write, |
| 510 | .device = uart_console_device, |
| 511 | .setup = ulite_console_setup, |
| 512 | .flags = CON_PRINTBUFFER, |
| 513 | .index = -1, /* Specified on the cmdline (e.g. console=ttyUL0 ) */ |
| 514 | .data = &ulite_uart_driver, |
| 515 | }; |
| 516 | |
| 517 | static int __init ulite_console_init(void) |
| 518 | { |
| 519 | register_console(&ulite_console); |
| 520 | return 0; |
| 521 | } |
| 522 | |
| 523 | console_initcall(ulite_console_init); |
| 524 | |
Rich Felker | 7cdcc29 | 2016-01-08 15:34:05 -0500 | [diff] [blame] | 525 | static void early_uartlite_putc(struct uart_port *port, int c) |
| 526 | { |
| 527 | /* |
| 528 | * Limit how many times we'll spin waiting for TX FIFO status. |
| 529 | * This will prevent lockups if the base address is incorrectly |
| 530 | * set, or any other issue on the UARTLITE. |
| 531 | * This limit is pretty arbitrary, unless we are at about 10 baud |
| 532 | * we'll never timeout on a working UART. |
| 533 | */ |
| 534 | |
| 535 | unsigned retries = 1000000; |
| 536 | /* read status bit - 0x8 offset */ |
| 537 | while (--retries && (readl(port->membase + 8) & (1 << 3))) |
| 538 | ; |
| 539 | |
| 540 | /* Only attempt the iowrite if we didn't timeout */ |
| 541 | /* write to TX_FIFO - 0x4 offset */ |
| 542 | if (retries) |
| 543 | writel(c & 0xff, port->membase + 4); |
| 544 | } |
| 545 | |
| 546 | static void early_uartlite_write(struct console *console, |
| 547 | const char *s, unsigned n) |
| 548 | { |
| 549 | struct earlycon_device *device = console->data; |
| 550 | uart_console_write(&device->port, s, n, early_uartlite_putc); |
| 551 | } |
| 552 | |
| 553 | static int __init early_uartlite_setup(struct earlycon_device *device, |
| 554 | const char *options) |
| 555 | { |
| 556 | if (!device->port.membase) |
| 557 | return -ENODEV; |
| 558 | |
| 559 | device->con->write = early_uartlite_write; |
| 560 | return 0; |
| 561 | } |
| 562 | EARLYCON_DECLARE(uartlite, early_uartlite_setup); |
| 563 | OF_EARLYCON_DECLARE(uartlite_b, "xlnx,opb-uartlite-1.00.b", early_uartlite_setup); |
| 564 | OF_EARLYCON_DECLARE(uartlite_a, "xlnx,xps-uartlite-1.00.a", early_uartlite_setup); |
| 565 | |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 566 | #endif /* CONFIG_SERIAL_UARTLITE_CONSOLE */ |
| 567 | |
| 568 | static struct uart_driver ulite_uart_driver = { |
| 569 | .owner = THIS_MODULE, |
| 570 | .driver_name = "uartlite", |
Grant Likely | 0077582 | 2007-10-02 12:15:49 +1000 | [diff] [blame] | 571 | .dev_name = ULITE_NAME, |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 572 | .major = ULITE_MAJOR, |
| 573 | .minor = ULITE_MINOR, |
| 574 | .nr = ULITE_NR_UARTS, |
| 575 | #ifdef CONFIG_SERIAL_UARTLITE_CONSOLE |
| 576 | .cons = &ulite_console, |
| 577 | #endif |
| 578 | }; |
| 579 | |
Grant Likely | 435706b | 2007-10-02 12:15:59 +1000 | [diff] [blame] | 580 | /* --------------------------------------------------------------------- |
| 581 | * Port assignment functions (mapping devices to uart_port structures) |
| 582 | */ |
| 583 | |
| 584 | /** ulite_assign: register a uartlite device with the driver |
| 585 | * |
| 586 | * @dev: pointer to device structure |
| 587 | * @id: requested id number. Pass -1 for automatic port assignment |
| 588 | * @base: base address of uartlite registers |
| 589 | * @irq: irq number for uartlite |
| 590 | * |
| 591 | * Returns: 0 on success, <0 otherwise |
| 592 | */ |
Bill Pemberton | 9671f09 | 2012-11-19 13:21:50 -0500 | [diff] [blame] | 593 | static int ulite_assign(struct device *dev, int id, u32 base, int irq) |
Grant Likely | 8fa7b61 | 2007-10-02 12:15:54 +1000 | [diff] [blame] | 594 | { |
| 595 | struct uart_port *port; |
| 596 | int rc; |
| 597 | |
| 598 | /* if id = -1; then scan for a free id and use that */ |
| 599 | if (id < 0) { |
| 600 | for (id = 0; id < ULITE_NR_UARTS; id++) |
| 601 | if (ulite_ports[id].mapbase == 0) |
| 602 | break; |
| 603 | } |
| 604 | if (id < 0 || id >= ULITE_NR_UARTS) { |
| 605 | dev_err(dev, "%s%i too large\n", ULITE_NAME, id); |
| 606 | return -EINVAL; |
| 607 | } |
| 608 | |
Grant Likely | fb4e6e6 | 2007-10-02 12:16:09 +1000 | [diff] [blame] | 609 | if ((ulite_ports[id].mapbase) && (ulite_ports[id].mapbase != base)) { |
Grant Likely | 8fa7b61 | 2007-10-02 12:15:54 +1000 | [diff] [blame] | 610 | dev_err(dev, "cannot assign to %s%i; it is already in use\n", |
| 611 | ULITE_NAME, id); |
| 612 | return -EBUSY; |
| 613 | } |
| 614 | |
| 615 | port = &ulite_ports[id]; |
| 616 | |
| 617 | spin_lock_init(&port->lock); |
| 618 | port->fifosize = 16; |
| 619 | port->regshift = 2; |
| 620 | port->iotype = UPIO_MEM; |
| 621 | port->iobase = 1; /* mark port in use */ |
| 622 | port->mapbase = base; |
| 623 | port->membase = NULL; |
| 624 | port->ops = &ulite_ops; |
| 625 | port->irq = irq; |
| 626 | port->flags = UPF_BOOT_AUTOCONF; |
| 627 | port->dev = dev; |
| 628 | port->type = PORT_UNKNOWN; |
| 629 | port->line = id; |
| 630 | |
| 631 | dev_set_drvdata(dev, port); |
| 632 | |
| 633 | /* Register the port */ |
| 634 | rc = uart_add_one_port(&ulite_uart_driver, port); |
| 635 | if (rc) { |
| 636 | dev_err(dev, "uart_add_one_port() failed; err=%i\n", rc); |
| 637 | port->mapbase = 0; |
| 638 | dev_set_drvdata(dev, NULL); |
| 639 | return rc; |
| 640 | } |
| 641 | |
| 642 | return 0; |
| 643 | } |
| 644 | |
Grant Likely | 435706b | 2007-10-02 12:15:59 +1000 | [diff] [blame] | 645 | /** ulite_release: register a uartlite device with the driver |
| 646 | * |
| 647 | * @dev: pointer to device structure |
| 648 | */ |
Bill Pemberton | ae8d8a1 | 2012-11-19 13:26:18 -0500 | [diff] [blame] | 649 | static int ulite_release(struct device *dev) |
Grant Likely | 8fa7b61 | 2007-10-02 12:15:54 +1000 | [diff] [blame] | 650 | { |
| 651 | struct uart_port *port = dev_get_drvdata(dev); |
| 652 | int rc = 0; |
| 653 | |
| 654 | if (port) { |
| 655 | rc = uart_remove_one_port(&ulite_uart_driver, port); |
| 656 | dev_set_drvdata(dev, NULL); |
| 657 | port->mapbase = 0; |
| 658 | } |
| 659 | |
| 660 | return rc; |
| 661 | } |
| 662 | |
Grant Likely | 435706b | 2007-10-02 12:15:59 +1000 | [diff] [blame] | 663 | /* --------------------------------------------------------------------- |
| 664 | * Platform bus binding |
| 665 | */ |
| 666 | |
Grant Likely | e5263a5 | 2011-02-22 20:16:13 -0700 | [diff] [blame] | 667 | #if defined(CONFIG_OF) |
| 668 | /* Match table for of_platform binding */ |
Fabian Frederick | ed0bb23 | 2015-03-16 20:17:11 +0100 | [diff] [blame] | 669 | static const struct of_device_id ulite_of_match[] = { |
Grant Likely | e5263a5 | 2011-02-22 20:16:13 -0700 | [diff] [blame] | 670 | { .compatible = "xlnx,opb-uartlite-1.00.b", }, |
| 671 | { .compatible = "xlnx,xps-uartlite-1.00.a", }, |
| 672 | {} |
| 673 | }; |
| 674 | MODULE_DEVICE_TABLE(of, ulite_of_match); |
Grant Likely | e5263a5 | 2011-02-22 20:16:13 -0700 | [diff] [blame] | 675 | #endif /* CONFIG_OF */ |
| 676 | |
Bill Pemberton | 9671f09 | 2012-11-19 13:21:50 -0500 | [diff] [blame] | 677 | static int ulite_probe(struct platform_device *pdev) |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 678 | { |
Michal Simek | 5c90c07 | 2015-04-13 16:34:21 +0200 | [diff] [blame] | 679 | struct resource *res; |
| 680 | int irq; |
Grant Likely | e5263a5 | 2011-02-22 20:16:13 -0700 | [diff] [blame] | 681 | int id = pdev->id; |
| 682 | #ifdef CONFIG_OF |
| 683 | const __be32 *prop; |
| 684 | |
| 685 | prop = of_get_property(pdev->dev.of_node, "port-number", NULL); |
| 686 | if (prop) |
| 687 | id = be32_to_cpup(prop); |
| 688 | #endif |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 689 | |
| 690 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 691 | if (!res) |
| 692 | return -ENODEV; |
| 693 | |
Michal Simek | 5c90c07 | 2015-04-13 16:34:21 +0200 | [diff] [blame] | 694 | irq = platform_get_irq(pdev, 0); |
| 695 | if (irq <= 0) |
| 696 | return -ENXIO; |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 697 | |
Michal Simek | 5c90c07 | 2015-04-13 16:34:21 +0200 | [diff] [blame] | 698 | return ulite_assign(&pdev->dev, id, res->start, irq); |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 699 | } |
| 700 | |
Bill Pemberton | ae8d8a1 | 2012-11-19 13:26:18 -0500 | [diff] [blame] | 701 | static int ulite_remove(struct platform_device *pdev) |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 702 | { |
Grant Likely | 8fa7b61 | 2007-10-02 12:15:54 +1000 | [diff] [blame] | 703 | return ulite_release(&pdev->dev); |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 704 | } |
| 705 | |
Kay Sievers | e169c13 | 2008-04-15 14:34:35 -0700 | [diff] [blame] | 706 | /* work with hotplug and coldplug */ |
| 707 | MODULE_ALIAS("platform:uartlite"); |
| 708 | |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 709 | static struct platform_driver ulite_platform_driver = { |
Grant Likely | e5263a5 | 2011-02-22 20:16:13 -0700 | [diff] [blame] | 710 | .probe = ulite_probe, |
Bill Pemberton | 2d47b71 | 2012-11-19 13:21:34 -0500 | [diff] [blame] | 711 | .remove = ulite_remove, |
Grant Likely | 852e1ea | 2007-10-02 12:16:04 +1000 | [diff] [blame] | 712 | .driver = { |
Grant Likely | e5263a5 | 2011-02-22 20:16:13 -0700 | [diff] [blame] | 713 | .name = "uartlite", |
Ben Dooks | 8588806 | 2011-08-03 10:11:43 +0100 | [diff] [blame] | 714 | .of_match_table = of_match_ptr(ulite_of_match), |
Grant Likely | 852e1ea | 2007-10-02 12:16:04 +1000 | [diff] [blame] | 715 | }, |
| 716 | }; |
| 717 | |
Grant Likely | 852e1ea | 2007-10-02 12:16:04 +1000 | [diff] [blame] | 718 | /* --------------------------------------------------------------------- |
Grant Likely | 435706b | 2007-10-02 12:15:59 +1000 | [diff] [blame] | 719 | * Module setup/teardown |
| 720 | */ |
| 721 | |
Michal Simek | 3240b48d | 2013-02-11 19:04:33 +0100 | [diff] [blame] | 722 | static int __init ulite_init(void) |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 723 | { |
| 724 | int ret; |
| 725 | |
Grant Likely | 852e1ea | 2007-10-02 12:16:04 +1000 | [diff] [blame] | 726 | pr_debug("uartlite: calling uart_register_driver()\n"); |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 727 | ret = uart_register_driver(&ulite_uart_driver); |
| 728 | if (ret) |
Grant Likely | 852e1ea | 2007-10-02 12:16:04 +1000 | [diff] [blame] | 729 | goto err_uart; |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 730 | |
Grant Likely | 852e1ea | 2007-10-02 12:16:04 +1000 | [diff] [blame] | 731 | pr_debug("uartlite: calling platform_driver_register()\n"); |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 732 | ret = platform_driver_register(&ulite_platform_driver); |
| 733 | if (ret) |
Grant Likely | 852e1ea | 2007-10-02 12:16:04 +1000 | [diff] [blame] | 734 | goto err_plat; |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 735 | |
Grant Likely | 852e1ea | 2007-10-02 12:16:04 +1000 | [diff] [blame] | 736 | return 0; |
| 737 | |
| 738 | err_plat: |
Grant Likely | 852e1ea | 2007-10-02 12:16:04 +1000 | [diff] [blame] | 739 | uart_unregister_driver(&ulite_uart_driver); |
| 740 | err_uart: |
Michal Simek | 3240b48d | 2013-02-11 19:04:33 +0100 | [diff] [blame] | 741 | pr_err("registering uartlite driver failed: err=%i", ret); |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 742 | return ret; |
| 743 | } |
| 744 | |
Michal Simek | 3240b48d | 2013-02-11 19:04:33 +0100 | [diff] [blame] | 745 | static void __exit ulite_exit(void) |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 746 | { |
| 747 | platform_driver_unregister(&ulite_platform_driver); |
Peter Korsgaard | 238b872 | 2006-12-06 20:35:17 -0800 | [diff] [blame] | 748 | uart_unregister_driver(&ulite_uart_driver); |
| 749 | } |
| 750 | |
| 751 | module_init(ulite_init); |
| 752 | module_exit(ulite_exit); |
| 753 | |
| 754 | MODULE_AUTHOR("Peter Korsgaard <jacmet@sunsite.dk>"); |
| 755 | MODULE_DESCRIPTION("Xilinx uartlite serial driver"); |
| 756 | MODULE_LICENSE("GPL"); |