blob: 0884939d29cf3922093eefc3253f382493d32966 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Driver for CLPS711x serial ports
3 *
4 * Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o.
5 *
6 * Copyright 1999 ARM Limited
7 * Copyright (C) 2000 Deep Blue Solutions Ltd.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
24#if defined(CONFIG_SERIAL_CLPS711X_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
25#define SUPPORT_SYSRQ
26#endif
27
28#include <linux/module.h>
29#include <linux/ioport.h>
30#include <linux/init.h>
31#include <linux/console.h>
32#include <linux/sysrq.h>
33#include <linux/spinlock.h>
34#include <linux/device.h>
35#include <linux/tty.h>
36#include <linux/tty_flip.h>
37#include <linux/serial_core.h>
38#include <linux/serial.h>
Russell King99730222009-03-25 10:21:35 +000039#include <linux/io.h>
Alexander Shiyanc08f0152012-10-14 11:05:26 +040040#include <linux/clk.h>
Alexander Shiyan95113722012-10-14 11:05:23 +040041#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
Russell Kinga09e64f2008-08-05 16:14:15 +010043#include <mach/hardware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <asm/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
Alexander Shiyan95113722012-10-14 11:05:23 +040046#define UART_CLPS711X_NAME "uart-clps711x"
Alexander Shiyan117d5d42012-10-14 11:05:24 +040047#define UART_CLPS711X_NR 2
48#define UART_CLPS711X_MAJOR 204
49#define UART_CLPS711X_MINOR 40
Alexander Shiyan95113722012-10-14 11:05:23 +040050
Alexander Shiyan117d5d42012-10-14 11:05:24 +040051#define UBRLCR(port) ((port)->line ? UBRLCR2 : UBRLCR1)
52#define UARTDR(port) ((port)->line ? UARTDR2 : UARTDR1)
53#define SYSFLG(port) ((port)->line ? SYSFLG2 : SYSFLG1)
54#define SYSCON(port) ((port)->line ? SYSCON2 : SYSCON1)
55#define TX_IRQ(port) ((port)->line ? IRQ_UTXINT2 : IRQ_UTXINT1)
56#define RX_IRQ(port) ((port)->line ? IRQ_URXINT2 : IRQ_URXINT1)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58#define UART_ANY_ERR (UARTDR_FRMERR | UARTDR_PARERR | UARTDR_OVERR)
59
Alexander Shiyan117d5d42012-10-14 11:05:24 +040060struct clps711x_port {
61 struct uart_driver uart;
Alexander Shiyanc08f0152012-10-14 11:05:26 +040062 struct clk *uart_clk;
Alexander Shiyan117d5d42012-10-14 11:05:24 +040063 struct uart_port port[UART_CLPS711X_NR];
Alexander Shiyan3c7e9eb2012-10-14 11:05:25 +040064 int tx_enabled[UART_CLPS711X_NR];
Alexander Shiyan117d5d42012-10-14 11:05:24 +040065#ifdef CONFIG_SERIAL_CLPS711X_CONSOLE
66 struct console console;
67#endif
68};
69
Russell Kingb129a8c2005-08-31 10:12:14 +010070static void clps711xuart_stop_tx(struct uart_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -070071{
Alexander Shiyan3c7e9eb2012-10-14 11:05:25 +040072 struct clps711x_port *s = dev_get_drvdata(port->dev);
73
74 if (s->tx_enabled[port->line]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 disable_irq(TX_IRQ(port));
Alexander Shiyan3c7e9eb2012-10-14 11:05:25 +040076 s->tx_enabled[port->line] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 }
78}
79
Russell Kingb129a8c2005-08-31 10:12:14 +010080static void clps711xuart_start_tx(struct uart_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -070081{
Alexander Shiyan3c7e9eb2012-10-14 11:05:25 +040082 struct clps711x_port *s = dev_get_drvdata(port->dev);
83
84 if (!s->tx_enabled[port->line]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 enable_irq(TX_IRQ(port));
Alexander Shiyan3c7e9eb2012-10-14 11:05:25 +040086 s->tx_enabled[port->line] = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 }
88}
89
90static void clps711xuart_stop_rx(struct uart_port *port)
91{
92 disable_irq(RX_IRQ(port));
93}
94
95static void clps711xuart_enable_ms(struct uart_port *port)
96{
97}
98
David Howells7d12e782006-10-05 14:55:46 +010099static irqreturn_t clps711xuart_int_rx(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100{
101 struct uart_port *port = dev_id;
Alan Coxebd2c8f2009-09-19 13:13:28 -0700102 struct tty_struct *tty = port->state->port.tty;
Russell Kingf9937242005-09-24 10:12:47 +0100103 unsigned int status, ch, flg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
105 status = clps_readl(SYSFLG(port));
106 while (!(status & SYSFLG_URXFE)) {
107 ch = clps_readl(UARTDR(port));
108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 port->icount.rx++;
110
111 flg = TTY_NORMAL;
112
113 /*
114 * Note that the error handling code is
115 * out of the main execution path
116 */
Russell King2a9604b2005-04-26 15:32:00 +0100117 if (unlikely(ch & UART_ANY_ERR)) {
118 if (ch & UARTDR_PARERR)
119 port->icount.parity++;
120 else if (ch & UARTDR_FRMERR)
121 port->icount.frame++;
122 if (ch & UARTDR_OVERR)
123 port->icount.overrun++;
124
125 ch &= port->read_status_mask;
126
127 if (ch & UARTDR_PARERR)
128 flg = TTY_PARITY;
129 else if (ch & UARTDR_FRMERR)
130 flg = TTY_FRAME;
131
132#ifdef SUPPORT_SYSRQ
133 port->sysrq = 0;
134#endif
135 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
David Howells7d12e782006-10-05 14:55:46 +0100137 if (uart_handle_sysrq_char(port, ch))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 goto ignore_char;
139
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 /*
141 * CHECK: does overrun affect the current character?
142 * ASSUMPTION: it does not.
143 */
Russell King05ab3012005-05-09 23:21:59 +0100144 uart_insert_char(port, ch, UARTDR_OVERR, ch, flg);
Russell King2a9604b2005-04-26 15:32:00 +0100145
146 ignore_char:
147 status = clps_readl(SYSFLG(port));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 }
Russell King2a9604b2005-04-26 15:32:00 +0100149 tty_flip_buffer_push(tty);
150 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151}
152
David Howells7d12e782006-10-05 14:55:46 +0100153static irqreturn_t clps711xuart_int_tx(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154{
155 struct uart_port *port = dev_id;
Alexander Shiyan3c7e9eb2012-10-14 11:05:25 +0400156 struct clps711x_port *s = dev_get_drvdata(port->dev);
Alan Coxebd2c8f2009-09-19 13:13:28 -0700157 struct circ_buf *xmit = &port->state->xmit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 int count;
159
160 if (port->x_char) {
161 clps_writel(port->x_char, UARTDR(port));
162 port->icount.tx++;
163 port->x_char = 0;
164 return IRQ_HANDLED;
165 }
Alexander Shiyan7a6fbc92012-03-27 12:22:49 +0400166
Alexander Shiyan3c7e9eb2012-10-14 11:05:25 +0400167 if (uart_circ_empty(xmit) || uart_tx_stopped(port)) {
168 disable_irq_nosync(TX_IRQ(port));
169 s->tx_enabled[port->line] = 0;
170 return IRQ_HANDLED;
171 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
173 count = port->fifosize >> 1;
174 do {
175 clps_writel(xmit->buf[xmit->tail], UARTDR(port));
176 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
177 port->icount.tx++;
178 if (uart_circ_empty(xmit))
179 break;
180 } while (--count > 0);
181
182 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
183 uart_write_wakeup(port);
184
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 return IRQ_HANDLED;
186}
187
188static unsigned int clps711xuart_tx_empty(struct uart_port *port)
189{
190 unsigned int status = clps_readl(SYSFLG(port));
191 return status & SYSFLG_UBUSY ? 0 : TIOCSER_TEMT;
192}
193
194static unsigned int clps711xuart_get_mctrl(struct uart_port *port)
195{
196 unsigned int port_addr;
197 unsigned int result = 0;
198 unsigned int status;
199
200 port_addr = SYSFLG(port);
201 if (port_addr == SYSFLG1) {
202 status = clps_readl(SYSFLG1);
203 if (status & SYSFLG1_DCD)
204 result |= TIOCM_CAR;
205 if (status & SYSFLG1_DSR)
206 result |= TIOCM_DSR;
207 if (status & SYSFLG1_CTS)
208 result |= TIOCM_CTS;
209 }
210
211 return result;
212}
213
214static void
215clps711xuart_set_mctrl_null(struct uart_port *port, unsigned int mctrl)
216{
217}
218
219static void clps711xuart_break_ctl(struct uart_port *port, int break_state)
220{
221 unsigned long flags;
222 unsigned int ubrlcr;
223
224 spin_lock_irqsave(&port->lock, flags);
225 ubrlcr = clps_readl(UBRLCR(port));
226 if (break_state == -1)
227 ubrlcr |= UBRLCR_BREAK;
228 else
229 ubrlcr &= ~UBRLCR_BREAK;
230 clps_writel(ubrlcr, UBRLCR(port));
231 spin_unlock_irqrestore(&port->lock, flags);
232}
233
234static int clps711xuart_startup(struct uart_port *port)
235{
Alexander Shiyan3c7e9eb2012-10-14 11:05:25 +0400236 struct clps711x_port *s = dev_get_drvdata(port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 unsigned int syscon;
238 int retval;
239
Alexander Shiyan3c7e9eb2012-10-14 11:05:25 +0400240 s->tx_enabled[port->line] = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241
242 /*
243 * Allocate the IRQs
244 */
245 retval = request_irq(TX_IRQ(port), clps711xuart_int_tx, 0,
246 "clps711xuart_tx", port);
247 if (retval)
248 return retval;
249
250 retval = request_irq(RX_IRQ(port), clps711xuart_int_rx, 0,
251 "clps711xuart_rx", port);
252 if (retval) {
253 free_irq(TX_IRQ(port), port);
254 return retval;
255 }
256
257 /*
258 * enable the port
259 */
260 syscon = clps_readl(SYSCON(port));
261 syscon |= SYSCON_UARTEN;
262 clps_writel(syscon, SYSCON(port));
263
264 return 0;
265}
266
267static void clps711xuart_shutdown(struct uart_port *port)
268{
269 unsigned int ubrlcr, syscon;
270
271 /*
272 * Free the interrupt
273 */
274 free_irq(TX_IRQ(port), port); /* TX interrupt */
275 free_irq(RX_IRQ(port), port); /* RX interrupt */
276
277 /*
278 * disable the port
279 */
280 syscon = clps_readl(SYSCON(port));
281 syscon &= ~SYSCON_UARTEN;
282 clps_writel(syscon, SYSCON(port));
283
284 /*
285 * disable break condition and fifos
286 */
287 ubrlcr = clps_readl(UBRLCR(port));
288 ubrlcr &= ~(UBRLCR_FIFOEN | UBRLCR_BREAK);
289 clps_writel(ubrlcr, UBRLCR(port));
290}
291
292static void
Alan Cox606d0992006-12-08 02:38:45 -0800293clps711xuart_set_termios(struct uart_port *port, struct ktermios *termios,
294 struct ktermios *old)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295{
296 unsigned int ubrlcr, baud, quot;
297 unsigned long flags;
298
299 /*
300 * We don't implement CREAD.
301 */
302 termios->c_cflag |= CREAD;
303
Alexander Shiyanc08f0152012-10-14 11:05:26 +0400304 /* Ask the core to calculate the divisor for us */
305 baud = uart_get_baud_rate(port, termios, old, port->uartclk / 4096,
306 port->uartclk / 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 quot = uart_get_divisor(port, baud);
308
309 switch (termios->c_cflag & CSIZE) {
310 case CS5:
311 ubrlcr = UBRLCR_WRDLEN5;
312 break;
313 case CS6:
314 ubrlcr = UBRLCR_WRDLEN6;
315 break;
316 case CS7:
317 ubrlcr = UBRLCR_WRDLEN7;
318 break;
319 default: // CS8
320 ubrlcr = UBRLCR_WRDLEN8;
321 break;
322 }
323 if (termios->c_cflag & CSTOPB)
324 ubrlcr |= UBRLCR_XSTOP;
325 if (termios->c_cflag & PARENB) {
326 ubrlcr |= UBRLCR_PRTEN;
327 if (!(termios->c_cflag & PARODD))
328 ubrlcr |= UBRLCR_EVENPRT;
329 }
330 if (port->fifosize > 1)
331 ubrlcr |= UBRLCR_FIFOEN;
332
333 spin_lock_irqsave(&port->lock, flags);
334
335 /*
336 * Update the per-port timeout.
337 */
338 uart_update_timeout(port, termios->c_cflag, baud);
339
340 port->read_status_mask = UARTDR_OVERR;
341 if (termios->c_iflag & INPCK)
342 port->read_status_mask |= UARTDR_PARERR | UARTDR_FRMERR;
343
344 /*
345 * Characters to ignore
346 */
347 port->ignore_status_mask = 0;
348 if (termios->c_iflag & IGNPAR)
349 port->ignore_status_mask |= UARTDR_FRMERR | UARTDR_PARERR;
350 if (termios->c_iflag & IGNBRK) {
351 /*
352 * If we're ignoring parity and break indicators,
353 * ignore overruns to (for real raw support).
354 */
355 if (termios->c_iflag & IGNPAR)
356 port->ignore_status_mask |= UARTDR_OVERR;
357 }
358
359 quot -= 1;
360
361 clps_writel(ubrlcr | quot, UBRLCR(port));
362
363 spin_unlock_irqrestore(&port->lock, flags);
364}
365
366static const char *clps711xuart_type(struct uart_port *port)
367{
368 return port->type == PORT_CLPS711X ? "CLPS711x" : NULL;
369}
370
371/*
372 * Configure/autoconfigure the port.
373 */
374static void clps711xuart_config_port(struct uart_port *port, int flags)
375{
376 if (flags & UART_CONFIG_TYPE)
377 port->type = PORT_CLPS711X;
378}
379
380static void clps711xuart_release_port(struct uart_port *port)
381{
382}
383
384static int clps711xuart_request_port(struct uart_port *port)
385{
386 return 0;
387}
388
Alexander Shiyan117d5d42012-10-14 11:05:24 +0400389static struct uart_ops uart_clps711x_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 .tx_empty = clps711xuart_tx_empty,
391 .set_mctrl = clps711xuart_set_mctrl_null,
392 .get_mctrl = clps711xuart_get_mctrl,
393 .stop_tx = clps711xuart_stop_tx,
394 .start_tx = clps711xuart_start_tx,
395 .stop_rx = clps711xuart_stop_rx,
396 .enable_ms = clps711xuart_enable_ms,
397 .break_ctl = clps711xuart_break_ctl,
398 .startup = clps711xuart_startup,
399 .shutdown = clps711xuart_shutdown,
400 .set_termios = clps711xuart_set_termios,
401 .type = clps711xuart_type,
402 .config_port = clps711xuart_config_port,
403 .release_port = clps711xuart_release_port,
404 .request_port = clps711xuart_request_port,
405};
406
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407#ifdef CONFIG_SERIAL_CLPS711X_CONSOLE
Alexander Shiyan117d5d42012-10-14 11:05:24 +0400408static void uart_clps711x_console_putchar(struct uart_port *port, int ch)
Russell Kingd3587882006-03-20 20:00:09 +0000409{
410 while (clps_readl(SYSFLG(port)) & SYSFLG_UTXFF)
411 barrier();
Alexander Shiyan117d5d42012-10-14 11:05:24 +0400412
413 clps_writew(ch, UARTDR(port));
Russell Kingd3587882006-03-20 20:00:09 +0000414}
415
Alexander Shiyan117d5d42012-10-14 11:05:24 +0400416static void uart_clps711x_console_write(struct console *co, const char *c,
417 unsigned n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418{
Alexander Shiyan117d5d42012-10-14 11:05:24 +0400419 struct clps711x_port *s = (struct clps711x_port *)co->data;
420 struct uart_port *port = &s->port[co->index];
421 u32 syscon;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
Alexander Shiyan117d5d42012-10-14 11:05:24 +0400423 /* Ensure that the port is enabled */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 syscon = clps_readl(SYSCON(port));
425 clps_writel(syscon | SYSCON_UARTEN, SYSCON(port));
426
Alexander Shiyan117d5d42012-10-14 11:05:24 +0400427 uart_console_write(port, c, n, uart_clps711x_console_putchar);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
Alexander Shiyan117d5d42012-10-14 11:05:24 +0400429 /* Wait for transmitter to become empty */
430 while (clps_readl(SYSFLG(port)) & SYSFLG_UBUSY)
431 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432
Alexander Shiyan117d5d42012-10-14 11:05:24 +0400433 /* Restore the uart state */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 clps_writel(syscon, SYSCON(port));
435}
436
Alexander Shiyan117d5d42012-10-14 11:05:24 +0400437static void uart_clps711x_console_get_options(struct uart_port *port,
438 int *baud, int *parity,
439 int *bits)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440{
441 if (clps_readl(SYSCON(port)) & SYSCON_UARTEN) {
442 unsigned int ubrlcr, quot;
443
444 ubrlcr = clps_readl(UBRLCR(port));
445
446 *parity = 'n';
447 if (ubrlcr & UBRLCR_PRTEN) {
448 if (ubrlcr & UBRLCR_EVENPRT)
449 *parity = 'e';
450 else
451 *parity = 'o';
452 }
453
454 if ((ubrlcr & UBRLCR_WRDLEN_MASK) == UBRLCR_WRDLEN7)
455 *bits = 7;
456 else
457 *bits = 8;
458
459 quot = ubrlcr & UBRLCR_BAUD_MASK;
460 *baud = port->uartclk / (16 * (quot + 1));
461 }
462}
463
Alexander Shiyan117d5d42012-10-14 11:05:24 +0400464static int uart_clps711x_console_setup(struct console *co, char *options)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465{
Alexander Shiyan117d5d42012-10-14 11:05:24 +0400466 int baud = 38400, bits = 8, parity = 'n', flow = 'n';
467 struct clps711x_port *s = (struct clps711x_port *)co->data;
468 struct uart_port *port = &s->port[(co->index > 0) ? co->index : 0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469
470 if (options)
471 uart_parse_options(options, &baud, &parity, &bits, &flow);
472 else
Alexander Shiyan117d5d42012-10-14 11:05:24 +0400473 uart_clps711x_console_get_options(port, &baud, &parity, &bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474
475 return uart_set_options(port, co, baud, parity, bits, flow);
476}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477#endif
478
Alexander Shiyan95113722012-10-14 11:05:23 +0400479static int __devinit uart_clps711x_probe(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480{
Alexander Shiyan117d5d42012-10-14 11:05:24 +0400481 struct clps711x_port *s;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 int ret, i;
483
Alexander Shiyan117d5d42012-10-14 11:05:24 +0400484 s = devm_kzalloc(&pdev->dev, sizeof(struct clps711x_port), GFP_KERNEL);
485 if (!s) {
486 dev_err(&pdev->dev, "Error allocating port structure\n");
487 return -ENOMEM;
488 }
489 platform_set_drvdata(pdev, s);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
Alexander Shiyanc08f0152012-10-14 11:05:26 +0400491 s->uart_clk = devm_clk_get(&pdev->dev, "uart");
492 if (IS_ERR(s->uart_clk)) {
493 dev_err(&pdev->dev, "Can't get UART clocks\n");
494 ret = PTR_ERR(s->uart_clk);
495 goto err_out;
496 }
497
Alexander Shiyan117d5d42012-10-14 11:05:24 +0400498 s->uart.owner = THIS_MODULE;
499 s->uart.dev_name = "ttyCL";
500 s->uart.major = UART_CLPS711X_MAJOR;
501 s->uart.minor = UART_CLPS711X_MINOR;
502 s->uart.nr = UART_CLPS711X_NR;
503#ifdef CONFIG_SERIAL_CLPS711X_CONSOLE
504 s->uart.cons = &s->console;
505 s->uart.cons->device = uart_console_device;
506 s->uart.cons->write = uart_clps711x_console_write;
507 s->uart.cons->setup = uart_clps711x_console_setup;
508 s->uart.cons->flags = CON_PRINTBUFFER;
509 s->uart.cons->index = -1;
510 s->uart.cons->data = s;
511 strcpy(s->uart.cons->name, "ttyCL");
512#endif
513 ret = uart_register_driver(&s->uart);
514 if (ret) {
515 dev_err(&pdev->dev, "Registering UART driver failed\n");
Alexander Shiyanc08f0152012-10-14 11:05:26 +0400516 devm_clk_put(&pdev->dev, s->uart_clk);
Alexander Shiyan117d5d42012-10-14 11:05:24 +0400517 goto err_out;
518 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
Alexander Shiyan117d5d42012-10-14 11:05:24 +0400520 for (i = 0; i < UART_CLPS711X_NR; i++) {
521 s->port[i].line = i;
522 s->port[i].dev = &pdev->dev;
523 s->port[i].irq = TX_IRQ(&s->port[i]);
524 s->port[i].iobase = SYSCON(&s->port[i]);
525 s->port[i].type = PORT_CLPS711X;
526 s->port[i].fifosize = 16;
527 s->port[i].flags = UPF_SKIP_TEST | UPF_FIXED_TYPE;
Alexander Shiyanc08f0152012-10-14 11:05:26 +0400528 s->port[i].uartclk = clk_get_rate(s->uart_clk);
Alexander Shiyan117d5d42012-10-14 11:05:24 +0400529 s->port[i].ops = &uart_clps711x_ops;
530 WARN_ON(uart_add_one_port(&s->uart, &s->port[i]));
531 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
533 return 0;
Alexander Shiyan117d5d42012-10-14 11:05:24 +0400534
535err_out:
536 platform_set_drvdata(pdev, NULL);
537
538 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539}
540
Alexander Shiyan95113722012-10-14 11:05:23 +0400541static int __devexit uart_clps711x_remove(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542{
Alexander Shiyan117d5d42012-10-14 11:05:24 +0400543 struct clps711x_port *s = platform_get_drvdata(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 int i;
545
Alexander Shiyan117d5d42012-10-14 11:05:24 +0400546 for (i = 0; i < UART_CLPS711X_NR; i++)
547 uart_remove_one_port(&s->uart, &s->port[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548
Alexander Shiyanc08f0152012-10-14 11:05:26 +0400549 devm_clk_put(&pdev->dev, s->uart_clk);
Alexander Shiyan117d5d42012-10-14 11:05:24 +0400550 uart_unregister_driver(&s->uart);
551 platform_set_drvdata(pdev, NULL);
Alexander Shiyan95113722012-10-14 11:05:23 +0400552
553 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554}
555
Alexander Shiyan95113722012-10-14 11:05:23 +0400556static struct platform_driver clps711x_uart_driver = {
557 .driver = {
558 .name = UART_CLPS711X_NAME,
559 .owner = THIS_MODULE,
560 },
561 .probe = uart_clps711x_probe,
562 .remove = __devexit_p(uart_clps711x_remove),
563};
564module_platform_driver(clps711x_uart_driver);
565
566static struct platform_device clps711x_uart_device = {
567 .name = UART_CLPS711X_NAME,
568};
569
570static int __init uart_clps711x_init(void)
571{
572 return platform_device_register(&clps711x_uart_device);
573}
574module_init(uart_clps711x_init);
575
576static void __exit uart_clps711x_exit(void)
577{
578 platform_device_unregister(&clps711x_uart_device);
579}
580module_exit(uart_clps711x_exit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581
582MODULE_AUTHOR("Deep Blue Solutions Ltd");
Alexander Shiyan95113722012-10-14 11:05:23 +0400583MODULE_DESCRIPTION("CLPS711X serial driver");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584MODULE_LICENSE("GPL");