2 * MEN 16z135 High Speed UART
4 * Copyright (C) 2014 MEN Mikroelektronik GmbH (www.men.de)
5 * Author: Johannes Thumshirn <johannes.thumshirn@men.de>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; version 2 of the License.
11 #define pr_fmt(fmt) KBUILD_MODNAME ":" fmt
13 #include <linux/kernel.h>
14 #include <linux/module.h>
15 #include <linux/interrupt.h>
16 #include <linux/serial_core.h>
17 #include <linux/ioport.h>
19 #include <linux/tty_flip.h>
20 #include <linux/bitops.h>
21 #include <linux/mcb.h>
23 #define MEN_Z135_MAX_PORTS 12
24 #define MEN_Z135_BASECLK 29491200
25 #define MEN_Z135_FIFO_SIZE 1024
26 #define MEN_Z135_FIFO_WATERMARK 1020
28 #define MEN_Z135_STAT_REG 0x0
29 #define MEN_Z135_RX_RAM 0x4
30 #define MEN_Z135_TX_RAM 0x400
31 #define MEN_Z135_RX_CTRL 0x800
32 #define MEN_Z135_TX_CTRL 0x804
33 #define MEN_Z135_CONF_REG 0x808
34 #define MEN_Z135_UART_FREQ 0x80c
35 #define MEN_Z135_BAUD_REG 0x810
36 #define MEN_Z135_TIMEOUT 0x814
38 #define IRQ_ID(x) ((x) & 0x1f)
40 #define MEN_Z135_IER_RXCIEN BIT(0) /* RX Space IRQ */
41 #define MEN_Z135_IER_TXCIEN BIT(1) /* TX Space IRQ */
42 #define MEN_Z135_IER_RLSIEN BIT(2) /* Receiver Line Status IRQ */
43 #define MEN_Z135_IER_MSIEN BIT(3) /* Modem Status IRQ */
44 #define MEN_Z135_ALL_IRQS (MEN_Z135_IER_RXCIEN \
45 | MEN_Z135_IER_RLSIEN \
46 | MEN_Z135_IER_MSIEN \
47 | MEN_Z135_IER_TXCIEN)
49 #define MEN_Z135_MCR_DTR BIT(24)
50 #define MEN_Z135_MCR_RTS BIT(25)
51 #define MEN_Z135_MCR_OUT1 BIT(26)
52 #define MEN_Z135_MCR_OUT2 BIT(27)
53 #define MEN_Z135_MCR_LOOP BIT(28)
54 #define MEN_Z135_MCR_RCFC BIT(29)
56 #define MEN_Z135_MSR_DCTS BIT(0)
57 #define MEN_Z135_MSR_DDSR BIT(1)
58 #define MEN_Z135_MSR_DRI BIT(2)
59 #define MEN_Z135_MSR_DDCD BIT(3)
60 #define MEN_Z135_MSR_CTS BIT(4)
61 #define MEN_Z135_MSR_DSR BIT(5)
62 #define MEN_Z135_MSR_RI BIT(6)
63 #define MEN_Z135_MSR_DCD BIT(7)
65 #define MEN_Z135_LCR_SHIFT 8 /* LCR shift mask */
67 #define MEN_Z135_WL5 0 /* CS5 */
68 #define MEN_Z135_WL6 1 /* CS6 */
69 #define MEN_Z135_WL7 2 /* CS7 */
70 #define MEN_Z135_WL8 3 /* CS8 */
72 #define MEN_Z135_STB_SHIFT 2 /* Stopbits */
73 #define MEN_Z135_NSTB1 0
74 #define MEN_Z135_NSTB2 1
76 #define MEN_Z135_PEN_SHIFT 3 /* Parity enable */
77 #define MEN_Z135_PAR_DIS 0
78 #define MEN_Z135_PAR_ENA 1
80 #define MEN_Z135_PTY_SHIFT 4 /* Parity type */
81 #define MEN_Z135_PTY_ODD 0
82 #define MEN_Z135_PTY_EVN 1
84 #define MEN_Z135_LSR_DR BIT(0)
85 #define MEN_Z135_LSR_OE BIT(1)
86 #define MEN_Z135_LSR_PE BIT(2)
87 #define MEN_Z135_LSR_FE BIT(3)
88 #define MEN_Z135_LSR_BI BIT(4)
89 #define MEN_Z135_LSR_THEP BIT(5)
90 #define MEN_Z135_LSR_TEXP BIT(6)
91 #define MEN_Z135_LSR_RXFIFOERR BIT(7)
93 #define MEN_Z135_IRQ_ID_RLS BIT(0)
94 #define MEN_Z135_IRQ_ID_RDA BIT(1)
95 #define MEN_Z135_IRQ_ID_CTI BIT(2)
96 #define MEN_Z135_IRQ_ID_TSA BIT(3)
97 #define MEN_Z135_IRQ_ID_MST BIT(4)
99 #define LCR(x) (((x) >> MEN_Z135_LCR_SHIFT) & 0xff)
101 #define BYTES_TO_ALIGN(x) ((x) & 0x3)
105 static int txlvl
= 5;
106 module_param(txlvl
, int, S_IRUGO
);
107 MODULE_PARM_DESC(txlvl
, "TX IRQ trigger level 0-7, default 5 (128 byte)");
109 static int rxlvl
= 6;
110 module_param(rxlvl
, int, S_IRUGO
);
111 MODULE_PARM_DESC(rxlvl
, "RX IRQ trigger level 0-7, default 6 (256 byte)");
114 module_param(align
, int, S_IRUGO
);
115 MODULE_PARM_DESC(align
, "Keep hardware FIFO write pointer aligned, default 0");
117 static uint rx_timeout
;
118 module_param(rx_timeout
, uint
, S_IRUGO
);
119 MODULE_PARM_DESC(rx_timeout
, "RX timeout. "
120 "Timeout in seconds = (timeout_reg * baud_reg * 4) / freq_reg");
122 struct men_z135_port
{
123 struct uart_port port
;
124 struct mcb_device
*mdev
;
125 struct resource
*mem
;
126 unsigned char *rxbuf
;
131 #define to_men_z135(port) container_of((port), struct men_z135_port, port)
134 * men_z135_reg_set() - Set value in register
135 * @uart: The UART port
136 * @addr: Register address
139 static inline void men_z135_reg_set(struct men_z135_port
*uart
,
142 struct uart_port
*port
= &uart
->port
;
146 spin_lock_irqsave(&uart
->lock
, flags
);
148 reg
= ioread32(port
->membase
+ addr
);
150 iowrite32(reg
, port
->membase
+ addr
);
152 spin_unlock_irqrestore(&uart
->lock
, flags
);
156 * men_z135_reg_clr() - Unset value in register
157 * @uart: The UART port
158 * @addr: Register address
159 * @val: value to clear
161 static void men_z135_reg_clr(struct men_z135_port
*uart
,
164 struct uart_port
*port
= &uart
->port
;
168 spin_lock_irqsave(&uart
->lock
, flags
);
170 reg
= ioread32(port
->membase
+ addr
);
172 iowrite32(reg
, port
->membase
+ addr
);
174 spin_unlock_irqrestore(&uart
->lock
, flags
);
178 * men_z135_handle_modem_status() - Handle change of modem status
179 * @port: The UART port
181 * Handle change of modem status register. This is done by reading the "delta"
182 * versions of DCD (Data Carrier Detect) and CTS (Clear To Send).
184 static void men_z135_handle_modem_status(struct men_z135_port
*uart
)
188 msr
= (uart
->stat_reg
>> 8) & 0xff;
190 if (msr
& MEN_Z135_MSR_DDCD
)
191 uart_handle_dcd_change(&uart
->port
,
192 msr
& MEN_Z135_MSR_DCD
);
193 if (msr
& MEN_Z135_MSR_DCTS
)
194 uart_handle_cts_change(&uart
->port
,
195 msr
& MEN_Z135_MSR_CTS
);
198 static void men_z135_handle_lsr(struct men_z135_port
*uart
)
200 struct uart_port
*port
= &uart
->port
;
203 lsr
= (uart
->stat_reg
>> 16) & 0xff;
205 if (lsr
& MEN_Z135_LSR_OE
)
206 port
->icount
.overrun
++;
207 if (lsr
& MEN_Z135_LSR_PE
)
208 port
->icount
.parity
++;
209 if (lsr
& MEN_Z135_LSR_FE
)
210 port
->icount
.frame
++;
211 if (lsr
& MEN_Z135_LSR_BI
) {
213 uart_handle_break(port
);
218 * get_rx_fifo_content() - Get the number of bytes in RX FIFO
219 * @uart: The UART port
221 * Read RXC register from hardware and return current FIFO fill size.
223 static u16
get_rx_fifo_content(struct men_z135_port
*uart
)
225 struct uart_port
*port
= &uart
->port
;
231 stat_reg
= ioread32(port
->membase
+ MEN_Z135_STAT_REG
);
232 rxc_lo
= stat_reg
>> 24;
233 rxc_hi
= (stat_reg
& 0xC0) >> 6;
235 rxc
= rxc_lo
| (rxc_hi
<< 8);
241 * men_z135_handle_rx() - RX tasklet routine
242 * @arg: Pointer to struct men_z135_port
244 * Copy from RX FIFO and acknowledge number of bytes copied.
246 static void men_z135_handle_rx(struct men_z135_port
*uart
)
248 struct uart_port
*port
= &uart
->port
;
249 struct tty_port
*tport
= &port
->state
->port
;
254 size
= get_rx_fifo_content(uart
);
259 /* Avoid accidently accessing TX FIFO instead of RX FIFO. Last
260 * longword in RX FIFO cannot be read.(0x004-0x3FF)
262 if (size
> MEN_Z135_FIFO_WATERMARK
)
263 size
= MEN_Z135_FIFO_WATERMARK
;
265 room
= tty_buffer_request_room(tport
, size
);
267 dev_warn(&uart
->mdev
->dev
,
268 "Not enough room in flip buffer, truncating to %d\n",
274 memcpy_fromio(uart
->rxbuf
, port
->membase
+ MEN_Z135_RX_RAM
, room
);
275 /* Be sure to first copy all data and then acknowledge it */
277 iowrite32(room
, port
->membase
+ MEN_Z135_RX_CTRL
);
279 copied
= tty_insert_flip_string(tport
, uart
->rxbuf
, room
);
281 dev_warn(&uart
->mdev
->dev
,
282 "Only copied %d instead of %d bytes\n",
285 port
->icount
.rx
+= copied
;
287 tty_flip_buffer_push(tport
);
292 * men_z135_handle_tx() - TX tasklet routine
293 * @arg: Pointer to struct men_z135_port
296 static void men_z135_handle_tx(struct men_z135_port
*uart
)
298 struct uart_port
*port
= &uart
->port
;
299 struct circ_buf
*xmit
= &port
->state
->xmit
;
309 if (uart_circ_empty(xmit
))
312 if (uart_tx_stopped(port
))
318 /* calculate bytes to copy */
319 qlen
= uart_circ_chars_pending(xmit
);
323 wptr
= ioread32(port
->membase
+ MEN_Z135_TX_CTRL
);
324 txc
= (wptr
>> 16) & 0x3ff;
327 if (txc
> MEN_Z135_FIFO_WATERMARK
)
328 txc
= MEN_Z135_FIFO_WATERMARK
;
330 txfree
= MEN_Z135_FIFO_WATERMARK
- txc
;
332 dev_err(&uart
->mdev
->dev
,
333 "Not enough room in TX FIFO have %d, need %d\n",
338 /* if we're not aligned, it's better to copy only 1 or 2 bytes and
341 if (align
&& qlen
>= 3 && BYTES_TO_ALIGN(wptr
))
342 n
= 4 - BYTES_TO_ALIGN(wptr
);
343 else if (qlen
> txfree
)
351 head
= xmit
->head
& (UART_XMIT_SIZE
- 1);
352 tail
= xmit
->tail
& (UART_XMIT_SIZE
- 1);
354 s
= ((head
>= tail
) ? head
: UART_XMIT_SIZE
) - tail
;
357 memcpy_toio(port
->membase
+ MEN_Z135_TX_RAM
, &xmit
->buf
[xmit
->tail
], n
);
358 xmit
->tail
= (xmit
->tail
+ n
) & (UART_XMIT_SIZE
- 1);
361 iowrite32(n
& 0x3ff, port
->membase
+ MEN_Z135_TX_CTRL
);
363 port
->icount
.tx
+= n
;
365 if (uart_circ_chars_pending(xmit
) < WAKEUP_CHARS
)
366 uart_write_wakeup(port
);
369 if (!uart_circ_empty(xmit
))
370 men_z135_reg_set(uart
, MEN_Z135_CONF_REG
, MEN_Z135_IER_TXCIEN
);
372 men_z135_reg_clr(uart
, MEN_Z135_CONF_REG
, MEN_Z135_IER_TXCIEN
);
380 * men_z135_intr() - Handle legacy IRQs
381 * @irq: The IRQ number
382 * @data: Pointer to UART port
384 * Check IIR register to find the cause of the interrupt and handle it.
385 * It is possible that multiple interrupts reason bits are set and reading
386 * the IIR is a destructive read, so we always need to check for all possible
387 * interrupts and handle them.
389 static irqreturn_t
men_z135_intr(int irq
, void *data
)
391 struct men_z135_port
*uart
= (struct men_z135_port
*)data
;
392 struct uart_port
*port
= &uart
->port
;
393 bool handled
= false;
396 uart
->stat_reg
= ioread32(port
->membase
+ MEN_Z135_STAT_REG
);
397 irq_id
= IRQ_ID(uart
->stat_reg
);
402 spin_lock(&port
->lock
);
403 /* It's save to write to IIR[7:6] RXC[9:8] */
404 iowrite8(irq_id
, port
->membase
+ MEN_Z135_STAT_REG
);
406 if (irq_id
& MEN_Z135_IRQ_ID_RLS
) {
407 men_z135_handle_lsr(uart
);
411 if (irq_id
& (MEN_Z135_IRQ_ID_RDA
| MEN_Z135_IRQ_ID_CTI
)) {
412 if (irq_id
& MEN_Z135_IRQ_ID_CTI
)
413 dev_dbg(&uart
->mdev
->dev
, "Character Timeout Indication\n");
414 men_z135_handle_rx(uart
);
418 if (irq_id
& MEN_Z135_IRQ_ID_TSA
) {
419 men_z135_handle_tx(uart
);
423 if (irq_id
& MEN_Z135_IRQ_ID_MST
) {
424 men_z135_handle_modem_status(uart
);
428 spin_unlock(&port
->lock
);
430 return IRQ_RETVAL(handled
);
434 * men_z135_request_irq() - Request IRQ for 16z135 core
435 * @uart: z135 private uart port structure
437 * Request an IRQ for 16z135 to use. First try using MSI, if it fails
438 * fall back to using legacy interrupts.
440 static int men_z135_request_irq(struct men_z135_port
*uart
)
442 struct device
*dev
= &uart
->mdev
->dev
;
443 struct uart_port
*port
= &uart
->port
;
446 err
= request_irq(port
->irq
, men_z135_intr
, IRQF_SHARED
,
447 "men_z135_intr", uart
);
449 dev_err(dev
, "Error %d getting interrupt\n", err
);
455 * men_z135_tx_empty() - Handle tx_empty call
456 * @port: The UART port
458 * This function tests whether the TX FIFO and shifter for the port
459 * described by @port is empty.
461 static unsigned int men_z135_tx_empty(struct uart_port
*port
)
466 wptr
= ioread32(port
->membase
+ MEN_Z135_TX_CTRL
);
467 txc
= (wptr
>> 16) & 0x3ff;
476 * men_z135_set_mctrl() - Set modem control lines
477 * @port: The UART port
478 * @mctrl: The modem control lines
480 * This function sets the modem control lines for a port described by @port
481 * to the state described by @mctrl
483 static void men_z135_set_mctrl(struct uart_port
*port
, unsigned int mctrl
)
488 conf_reg
= old
= ioread32(port
->membase
+ MEN_Z135_CONF_REG
);
489 if (mctrl
& TIOCM_RTS
)
490 conf_reg
|= MEN_Z135_MCR_RTS
;
492 conf_reg
&= ~MEN_Z135_MCR_RTS
;
494 if (mctrl
& TIOCM_DTR
)
495 conf_reg
|= MEN_Z135_MCR_DTR
;
497 conf_reg
&= ~MEN_Z135_MCR_DTR
;
499 if (mctrl
& TIOCM_OUT1
)
500 conf_reg
|= MEN_Z135_MCR_OUT1
;
502 conf_reg
&= ~MEN_Z135_MCR_OUT1
;
504 if (mctrl
& TIOCM_OUT2
)
505 conf_reg
|= MEN_Z135_MCR_OUT2
;
507 conf_reg
&= ~MEN_Z135_MCR_OUT2
;
509 if (mctrl
& TIOCM_LOOP
)
510 conf_reg
|= MEN_Z135_MCR_LOOP
;
512 conf_reg
&= ~MEN_Z135_MCR_LOOP
;
515 iowrite32(conf_reg
, port
->membase
+ MEN_Z135_CONF_REG
);
519 * men_z135_get_mctrl() - Get modem control lines
520 * @port: The UART port
522 * Retruns the current state of modem control inputs.
524 static unsigned int men_z135_get_mctrl(struct uart_port
*port
)
526 unsigned int mctrl
= 0;
529 msr
= ioread8(port
->membase
+ MEN_Z135_STAT_REG
+ 1);
531 if (msr
& MEN_Z135_MSR_CTS
)
533 if (msr
& MEN_Z135_MSR_DSR
)
535 if (msr
& MEN_Z135_MSR_RI
)
537 if (msr
& MEN_Z135_MSR_DCD
)
544 * men_z135_stop_tx() - Stop transmitting characters
545 * @port: The UART port
547 * Stop transmitting characters. This might be due to CTS line becomming
548 * inactive or the tty layer indicating we want to stop transmission due to
551 static void men_z135_stop_tx(struct uart_port
*port
)
553 struct men_z135_port
*uart
= to_men_z135(port
);
555 men_z135_reg_clr(uart
, MEN_Z135_CONF_REG
, MEN_Z135_IER_TXCIEN
);
559 * men_z135_disable_ms() - Disable Modem Status
560 * port: The UART port
562 * Enable Modem Status IRQ.
564 static void men_z135_disable_ms(struct uart_port
*port
)
566 struct men_z135_port
*uart
= to_men_z135(port
);
568 men_z135_reg_clr(uart
, MEN_Z135_CONF_REG
, MEN_Z135_IER_MSIEN
);
572 * men_z135_start_tx() - Start transmitting characters
573 * @port: The UART port
575 * Start transmitting character. This actually doesn't transmit anything, but
576 * fires off the TX tasklet.
578 static void men_z135_start_tx(struct uart_port
*port
)
580 struct men_z135_port
*uart
= to_men_z135(port
);
583 men_z135_disable_ms(port
);
585 men_z135_handle_tx(uart
);
589 * men_z135_stop_rx() - Stop receiving characters
590 * @port: The UART port
592 * Stop receiving characters; the port is in the process of being closed.
594 static void men_z135_stop_rx(struct uart_port
*port
)
596 struct men_z135_port
*uart
= to_men_z135(port
);
598 men_z135_reg_clr(uart
, MEN_Z135_CONF_REG
, MEN_Z135_IER_RXCIEN
);
602 * men_z135_enable_ms() - Enable Modem Status
605 * Enable Modem Status IRQ.
607 static void men_z135_enable_ms(struct uart_port
*port
)
609 struct men_z135_port
*uart
= to_men_z135(port
);
611 men_z135_reg_set(uart
, MEN_Z135_CONF_REG
, MEN_Z135_IER_MSIEN
);
614 static int men_z135_startup(struct uart_port
*port
)
616 struct men_z135_port
*uart
= to_men_z135(port
);
620 err
= men_z135_request_irq(uart
);
624 conf_reg
= ioread32(port
->membase
+ MEN_Z135_CONF_REG
);
626 /* Activate all but TX space available IRQ */
627 conf_reg
|= MEN_Z135_ALL_IRQS
& ~MEN_Z135_IER_TXCIEN
;
628 conf_reg
&= ~(0xff << 16);
629 conf_reg
|= (txlvl
<< 16);
630 conf_reg
|= (rxlvl
<< 20);
632 iowrite32(conf_reg
, port
->membase
+ MEN_Z135_CONF_REG
);
635 iowrite32(rx_timeout
, port
->membase
+ MEN_Z135_TIMEOUT
);
640 static void men_z135_shutdown(struct uart_port
*port
)
642 struct men_z135_port
*uart
= to_men_z135(port
);
645 conf_reg
|= MEN_Z135_ALL_IRQS
;
647 men_z135_reg_clr(uart
, MEN_Z135_CONF_REG
, conf_reg
);
649 free_irq(uart
->port
.irq
, uart
);
652 static void men_z135_set_termios(struct uart_port
*port
,
653 struct ktermios
*termios
,
654 struct ktermios
*old
)
656 struct men_z135_port
*uart
= to_men_z135(port
);
663 conf_reg
= ioread32(port
->membase
+ MEN_Z135_CONF_REG
);
667 switch (termios
->c_cflag
& CSIZE
) {
683 if (termios
->c_cflag
& CSTOPB
)
684 lcr
|= MEN_Z135_NSTB2
<< MEN_Z135_STB_SHIFT
;
687 if (termios
->c_cflag
& PARENB
) {
688 lcr
|= MEN_Z135_PAR_ENA
<< MEN_Z135_PEN_SHIFT
;
690 if (termios
->c_cflag
& PARODD
)
691 lcr
|= MEN_Z135_PTY_ODD
<< MEN_Z135_PTY_SHIFT
;
693 lcr
|= MEN_Z135_PTY_EVN
<< MEN_Z135_PTY_SHIFT
;
695 lcr
|= MEN_Z135_PAR_DIS
<< MEN_Z135_PEN_SHIFT
;
697 conf_reg
|= MEN_Z135_IER_MSIEN
;
698 if (termios
->c_cflag
& CRTSCTS
) {
699 conf_reg
|= MEN_Z135_MCR_RCFC
;
700 uart
->automode
= true;
701 termios
->c_cflag
&= ~CLOCAL
;
703 conf_reg
&= ~MEN_Z135_MCR_RCFC
;
704 uart
->automode
= false;
707 termios
->c_cflag
&= ~CMSPAR
; /* Mark/Space parity is not supported */
709 conf_reg
|= lcr
<< MEN_Z135_LCR_SHIFT
;
710 iowrite32(conf_reg
, port
->membase
+ MEN_Z135_CONF_REG
);
712 uart_freq
= ioread32(port
->membase
+ MEN_Z135_UART_FREQ
);
714 uart_freq
= MEN_Z135_BASECLK
;
716 baud
= uart_get_baud_rate(port
, termios
, old
, 0, uart_freq
/ 16);
718 spin_lock_irq(&port
->lock
);
719 if (tty_termios_baud_rate(termios
))
720 tty_termios_encode_baud_rate(termios
, baud
, baud
);
722 bd_reg
= uart_freq
/ (4 * baud
);
723 iowrite32(bd_reg
, port
->membase
+ MEN_Z135_BAUD_REG
);
725 uart_update_timeout(port
, termios
->c_cflag
, baud
);
726 spin_unlock_irq(&port
->lock
);
729 static const char *men_z135_type(struct uart_port
*port
)
731 return KBUILD_MODNAME
;
734 static void men_z135_release_port(struct uart_port
*port
)
736 struct men_z135_port
*uart
= to_men_z135(port
);
738 iounmap(port
->membase
);
739 port
->membase
= NULL
;
741 mcb_release_mem(uart
->mem
);
744 static int men_z135_request_port(struct uart_port
*port
)
746 struct men_z135_port
*uart
= to_men_z135(port
);
747 struct mcb_device
*mdev
= uart
->mdev
;
748 struct resource
*mem
;
750 mem
= mcb_request_mem(uart
->mdev
, dev_name(&mdev
->dev
));
754 port
->mapbase
= mem
->start
;
757 port
->membase
= ioremap(mem
->start
, resource_size(mem
));
758 if (port
->membase
== NULL
) {
759 mcb_release_mem(mem
);
766 static void men_z135_config_port(struct uart_port
*port
, int type
)
768 port
->type
= PORT_MEN_Z135
;
769 men_z135_request_port(port
);
772 static int men_z135_verify_port(struct uart_port
*port
,
773 struct serial_struct
*serinfo
)
778 static const struct uart_ops men_z135_ops
= {
779 .tx_empty
= men_z135_tx_empty
,
780 .set_mctrl
= men_z135_set_mctrl
,
781 .get_mctrl
= men_z135_get_mctrl
,
782 .stop_tx
= men_z135_stop_tx
,
783 .start_tx
= men_z135_start_tx
,
784 .stop_rx
= men_z135_stop_rx
,
785 .enable_ms
= men_z135_enable_ms
,
786 .startup
= men_z135_startup
,
787 .shutdown
= men_z135_shutdown
,
788 .set_termios
= men_z135_set_termios
,
789 .type
= men_z135_type
,
790 .release_port
= men_z135_release_port
,
791 .request_port
= men_z135_request_port
,
792 .config_port
= men_z135_config_port
,
793 .verify_port
= men_z135_verify_port
,
796 static struct uart_driver men_z135_driver
= {
797 .owner
= THIS_MODULE
,
798 .driver_name
= KBUILD_MODNAME
,
799 .dev_name
= "ttyHSU",
802 .nr
= MEN_Z135_MAX_PORTS
,
806 * men_z135_probe() - Probe a z135 instance
807 * @mdev: The MCB device
808 * @id: The MCB device ID
810 * men_z135_probe does the basic setup of hardware resources and registers the
811 * new uart port to the tty layer.
813 static int men_z135_probe(struct mcb_device
*mdev
,
814 const struct mcb_device_id
*id
)
816 struct men_z135_port
*uart
;
817 struct resource
*mem
;
823 uart
= devm_kzalloc(dev
, sizeof(struct men_z135_port
), GFP_KERNEL
);
827 uart
->rxbuf
= (unsigned char *)__get_free_page(GFP_KERNEL
);
833 mcb_set_drvdata(mdev
, uart
);
835 uart
->port
.uartclk
= MEN_Z135_BASECLK
* 16;
836 uart
->port
.fifosize
= MEN_Z135_FIFO_SIZE
;
837 uart
->port
.iotype
= UPIO_MEM
;
838 uart
->port
.ops
= &men_z135_ops
;
839 uart
->port
.irq
= mcb_get_irq(mdev
);
840 uart
->port
.iotype
= UPIO_MEM
;
841 uart
->port
.flags
= UPF_BOOT_AUTOCONF
| UPF_IOREMAP
;
842 uart
->port
.line
= line
++;
843 uart
->port
.dev
= dev
;
844 uart
->port
.type
= PORT_MEN_Z135
;
845 uart
->port
.mapbase
= mem
->start
;
846 uart
->port
.membase
= NULL
;
849 spin_lock_init(&uart
->lock
);
851 err
= uart_add_one_port(&men_z135_driver
, &uart
->port
);
858 free_page((unsigned long) uart
->rxbuf
);
859 dev_err(dev
, "Failed to add UART: %d\n", err
);
865 * men_z135_remove() - Remove a z135 instance from the system
867 * @mdev: The MCB device
869 static void men_z135_remove(struct mcb_device
*mdev
)
871 struct men_z135_port
*uart
= mcb_get_drvdata(mdev
);
874 uart_remove_one_port(&men_z135_driver
, &uart
->port
);
875 free_page((unsigned long) uart
->rxbuf
);
878 static const struct mcb_device_id men_z135_ids
[] = {
882 MODULE_DEVICE_TABLE(mcb
, men_z135_ids
);
884 static struct mcb_driver mcb_driver
= {
887 .owner
= THIS_MODULE
,
889 .probe
= men_z135_probe
,
890 .remove
= men_z135_remove
,
891 .id_table
= men_z135_ids
,
895 * men_z135_init() - Driver Registration Routine
897 * men_z135_init is the first routine called when the driver is loaded. All it
898 * does is register with the legacy MEN Chameleon subsystem.
900 static int __init
men_z135_init(void)
904 err
= uart_register_driver(&men_z135_driver
);
906 pr_err("Failed to register UART: %d\n", err
);
910 err
= mcb_register_driver(&mcb_driver
);
912 pr_err("Failed to register MCB driver: %d\n", err
);
913 uart_unregister_driver(&men_z135_driver
);
919 module_init(men_z135_init
);
922 * men_z135_exit() - Driver Exit Routine
924 * men_z135_exit is called just before the driver is removed from memory.
926 static void __exit
men_z135_exit(void)
928 mcb_unregister_driver(&mcb_driver
);
929 uart_unregister_driver(&men_z135_driver
);
931 module_exit(men_z135_exit
);
933 MODULE_AUTHOR("Johannes Thumshirn <johannes.thumshirn@men.de>");
934 MODULE_LICENSE("GPL v2");
935 MODULE_DESCRIPTION("MEN 16z135 High Speed UART");
936 MODULE_ALIAS("mcb:16z135");