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 MEN_Z135_MEM_SIZE 0x818
40 #define IRQ_ID(x) ((x) & 0x1f)
42 #define MEN_Z135_IER_RXCIEN BIT(0) /* RX Space IRQ */
43 #define MEN_Z135_IER_TXCIEN BIT(1) /* TX Space IRQ */
44 #define MEN_Z135_IER_RLSIEN BIT(2) /* Receiver Line Status IRQ */
45 #define MEN_Z135_IER_MSIEN BIT(3) /* Modem Status IRQ */
46 #define MEN_Z135_ALL_IRQS (MEN_Z135_IER_RXCIEN \
47 | MEN_Z135_IER_RLSIEN \
48 | MEN_Z135_IER_MSIEN \
49 | MEN_Z135_IER_TXCIEN)
51 #define MEN_Z135_MCR_DTR BIT(24)
52 #define MEN_Z135_MCR_RTS BIT(25)
53 #define MEN_Z135_MCR_OUT1 BIT(26)
54 #define MEN_Z135_MCR_OUT2 BIT(27)
55 #define MEN_Z135_MCR_LOOP BIT(28)
56 #define MEN_Z135_MCR_RCFC BIT(29)
58 #define MEN_Z135_MSR_DCTS BIT(0)
59 #define MEN_Z135_MSR_DDSR BIT(1)
60 #define MEN_Z135_MSR_DRI BIT(2)
61 #define MEN_Z135_MSR_DDCD BIT(3)
62 #define MEN_Z135_MSR_CTS BIT(4)
63 #define MEN_Z135_MSR_DSR BIT(5)
64 #define MEN_Z135_MSR_RI BIT(6)
65 #define MEN_Z135_MSR_DCD BIT(7)
67 #define MEN_Z135_LCR_SHIFT 8 /* LCR shift mask */
69 #define MEN_Z135_WL5 0 /* CS5 */
70 #define MEN_Z135_WL6 1 /* CS6 */
71 #define MEN_Z135_WL7 2 /* CS7 */
72 #define MEN_Z135_WL8 3 /* CS8 */
74 #define MEN_Z135_STB_SHIFT 2 /* Stopbits */
75 #define MEN_Z135_NSTB1 0
76 #define MEN_Z135_NSTB2 1
78 #define MEN_Z135_PEN_SHIFT 3 /* Parity enable */
79 #define MEN_Z135_PAR_DIS 0
80 #define MEN_Z135_PAR_ENA 1
82 #define MEN_Z135_PTY_SHIFT 4 /* Parity type */
83 #define MEN_Z135_PTY_ODD 0
84 #define MEN_Z135_PTY_EVN 1
86 #define MEN_Z135_LSR_DR BIT(0)
87 #define MEN_Z135_LSR_OE BIT(1)
88 #define MEN_Z135_LSR_PE BIT(2)
89 #define MEN_Z135_LSR_FE BIT(3)
90 #define MEN_Z135_LSR_BI BIT(4)
91 #define MEN_Z135_LSR_THEP BIT(5)
92 #define MEN_Z135_LSR_TEXP BIT(6)
93 #define MEN_Z135_LSR_RXFIFOERR BIT(7)
95 #define MEN_Z135_IRQ_ID_RLS BIT(0)
96 #define MEN_Z135_IRQ_ID_RDA BIT(1)
97 #define MEN_Z135_IRQ_ID_CTI BIT(2)
98 #define MEN_Z135_IRQ_ID_TSA BIT(3)
99 #define MEN_Z135_IRQ_ID_MST BIT(4)
101 #define LCR(x) (((x) >> MEN_Z135_LCR_SHIFT) & 0xff)
103 #define BYTES_TO_ALIGN(x) ((x) & 0x3)
107 static int txlvl
= 5;
108 module_param(txlvl
, int, S_IRUGO
);
109 MODULE_PARM_DESC(txlvl
, "TX IRQ trigger level 0-7, default 5 (128 byte)");
111 static int rxlvl
= 6;
112 module_param(rxlvl
, int, S_IRUGO
);
113 MODULE_PARM_DESC(rxlvl
, "RX IRQ trigger level 0-7, default 6 (256 byte)");
116 module_param(align
, int, S_IRUGO
);
117 MODULE_PARM_DESC(align
, "Keep hardware FIFO write pointer aligned, default 0");
119 static uint rx_timeout
;
120 module_param(rx_timeout
, uint
, S_IRUGO
);
121 MODULE_PARM_DESC(rx_timeout
, "RX timeout. "
122 "Timeout in seconds = (timeout_reg * baud_reg * 4) / freq_reg");
124 struct men_z135_port
{
125 struct uart_port port
;
126 struct mcb_device
*mdev
;
127 unsigned char *rxbuf
;
132 #define to_men_z135(port) container_of((port), struct men_z135_port, port)
135 * men_z135_reg_set() - Set value in register
136 * @uart: The UART port
137 * @addr: Register address
140 static inline void men_z135_reg_set(struct men_z135_port
*uart
,
143 struct uart_port
*port
= &uart
->port
;
147 spin_lock_irqsave(&uart
->lock
, flags
);
149 reg
= ioread32(port
->membase
+ addr
);
151 iowrite32(reg
, port
->membase
+ addr
);
153 spin_unlock_irqrestore(&uart
->lock
, flags
);
157 * men_z135_reg_clr() - Unset value in register
158 * @uart: The UART port
159 * @addr: Register address
160 * @val: value to clear
162 static inline void men_z135_reg_clr(struct men_z135_port
*uart
,
165 struct uart_port
*port
= &uart
->port
;
169 spin_lock_irqsave(&uart
->lock
, flags
);
171 reg
= ioread32(port
->membase
+ addr
);
173 iowrite32(reg
, port
->membase
+ addr
);
175 spin_unlock_irqrestore(&uart
->lock
, flags
);
179 * men_z135_handle_modem_status() - Handle change of modem status
180 * @port: The UART port
182 * Handle change of modem status register. This is done by reading the "delta"
183 * versions of DCD (Data Carrier Detect) and CTS (Clear To Send).
185 static void men_z135_handle_modem_status(struct men_z135_port
*uart
)
189 msr
= (uart
->stat_reg
>> 8) & 0xff;
191 if (msr
& MEN_Z135_MSR_DDCD
)
192 uart_handle_dcd_change(&uart
->port
,
193 msr
& MEN_Z135_MSR_DCD
);
194 if (msr
& MEN_Z135_MSR_DCTS
)
195 uart_handle_cts_change(&uart
->port
,
196 msr
& MEN_Z135_MSR_CTS
);
199 static void men_z135_handle_lsr(struct men_z135_port
*uart
)
201 struct uart_port
*port
= &uart
->port
;
204 lsr
= (uart
->stat_reg
>> 16) & 0xff;
206 if (lsr
& MEN_Z135_LSR_OE
)
207 port
->icount
.overrun
++;
208 if (lsr
& MEN_Z135_LSR_PE
)
209 port
->icount
.parity
++;
210 if (lsr
& MEN_Z135_LSR_FE
)
211 port
->icount
.frame
++;
212 if (lsr
& MEN_Z135_LSR_BI
) {
214 uart_handle_break(port
);
219 * get_rx_fifo_content() - Get the number of bytes in RX FIFO
220 * @uart: The UART port
222 * Read RXC register from hardware and return current FIFO fill size.
224 static u16
get_rx_fifo_content(struct men_z135_port
*uart
)
226 struct uart_port
*port
= &uart
->port
;
232 stat_reg
= ioread32(port
->membase
+ MEN_Z135_STAT_REG
);
233 rxc_lo
= stat_reg
>> 24;
234 rxc_hi
= (stat_reg
& 0xC0) >> 6;
236 rxc
= rxc_lo
| (rxc_hi
<< 8);
242 * men_z135_handle_rx() - RX tasklet routine
243 * @arg: Pointer to struct men_z135_port
245 * Copy from RX FIFO and acknowledge number of bytes copied.
247 static void men_z135_handle_rx(struct men_z135_port
*uart
)
249 struct uart_port
*port
= &uart
->port
;
250 struct tty_port
*tport
= &port
->state
->port
;
255 size
= get_rx_fifo_content(uart
);
260 /* Avoid accidently accessing TX FIFO instead of RX FIFO. Last
261 * longword in RX FIFO cannot be read.(0x004-0x3FF)
263 if (size
> MEN_Z135_FIFO_WATERMARK
)
264 size
= MEN_Z135_FIFO_WATERMARK
;
266 room
= tty_buffer_request_room(tport
, size
);
268 dev_warn(&uart
->mdev
->dev
,
269 "Not enough room in flip buffer, truncating to %d\n",
275 memcpy_fromio(uart
->rxbuf
, port
->membase
+ MEN_Z135_RX_RAM
, room
);
276 /* Be sure to first copy all data and then acknowledge it */
278 iowrite32(room
, port
->membase
+ MEN_Z135_RX_CTRL
);
280 copied
= tty_insert_flip_string(tport
, uart
->rxbuf
, room
);
282 dev_warn(&uart
->mdev
->dev
,
283 "Only copied %d instead of %d bytes\n",
286 port
->icount
.rx
+= copied
;
288 tty_flip_buffer_push(tport
);
293 * men_z135_handle_tx() - TX tasklet routine
294 * @arg: Pointer to struct men_z135_port
297 static void men_z135_handle_tx(struct men_z135_port
*uart
)
299 struct uart_port
*port
= &uart
->port
;
300 struct circ_buf
*xmit
= &port
->state
->xmit
;
310 if (uart_circ_empty(xmit
))
313 if (uart_tx_stopped(port
))
319 /* calculate bytes to copy */
320 qlen
= uart_circ_chars_pending(xmit
);
324 wptr
= ioread32(port
->membase
+ MEN_Z135_TX_CTRL
);
325 txc
= (wptr
>> 16) & 0x3ff;
328 if (txc
> MEN_Z135_FIFO_WATERMARK
)
329 txc
= MEN_Z135_FIFO_WATERMARK
;
331 txfree
= MEN_Z135_FIFO_WATERMARK
- txc
;
333 dev_err(&uart
->mdev
->dev
,
334 "Not enough room in TX FIFO have %d, need %d\n",
339 /* if we're not aligned, it's better to copy only 1 or 2 bytes and
342 if (align
&& qlen
>= 3 && BYTES_TO_ALIGN(wptr
))
343 n
= 4 - BYTES_TO_ALIGN(wptr
);
344 else if (qlen
> txfree
)
352 head
= xmit
->head
& (UART_XMIT_SIZE
- 1);
353 tail
= xmit
->tail
& (UART_XMIT_SIZE
- 1);
355 s
= ((head
>= tail
) ? head
: UART_XMIT_SIZE
) - tail
;
358 memcpy_toio(port
->membase
+ MEN_Z135_TX_RAM
, &xmit
->buf
[xmit
->tail
], n
);
359 xmit
->tail
= (xmit
->tail
+ n
) & (UART_XMIT_SIZE
- 1);
362 iowrite32(n
& 0x3ff, port
->membase
+ MEN_Z135_TX_CTRL
);
364 port
->icount
.tx
+= n
;
366 if (uart_circ_chars_pending(xmit
) < WAKEUP_CHARS
)
367 uart_write_wakeup(port
);
370 if (!uart_circ_empty(xmit
))
371 men_z135_reg_set(uart
, MEN_Z135_CONF_REG
, MEN_Z135_IER_TXCIEN
);
373 men_z135_reg_clr(uart
, MEN_Z135_CONF_REG
, MEN_Z135_IER_TXCIEN
);
381 * men_z135_intr() - Handle legacy IRQs
382 * @irq: The IRQ number
383 * @data: Pointer to UART port
385 * Check IIR register to find the cause of the interrupt and handle it.
386 * It is possible that multiple interrupts reason bits are set and reading
387 * the IIR is a destructive read, so we always need to check for all possible
388 * interrupts and handle them.
390 static irqreturn_t
men_z135_intr(int irq
, void *data
)
392 struct men_z135_port
*uart
= (struct men_z135_port
*)data
;
393 struct uart_port
*port
= &uart
->port
;
394 bool handled
= false;
398 uart
->stat_reg
= ioread32(port
->membase
+ MEN_Z135_STAT_REG
);
399 irq_id
= IRQ_ID(uart
->stat_reg
);
404 spin_lock_irqsave(&port
->lock
, flags
);
405 /* It's save to write to IIR[7:6] RXC[9:8] */
406 iowrite8(irq_id
, port
->membase
+ MEN_Z135_STAT_REG
);
408 if (irq_id
& MEN_Z135_IRQ_ID_RLS
) {
409 men_z135_handle_lsr(uart
);
413 if (irq_id
& (MEN_Z135_IRQ_ID_RDA
| MEN_Z135_IRQ_ID_CTI
)) {
414 if (irq_id
& MEN_Z135_IRQ_ID_CTI
)
415 dev_dbg(&uart
->mdev
->dev
, "Character Timeout Indication\n");
416 men_z135_handle_rx(uart
);
420 if (irq_id
& MEN_Z135_IRQ_ID_TSA
) {
421 men_z135_handle_tx(uart
);
425 if (irq_id
& MEN_Z135_IRQ_ID_MST
) {
426 men_z135_handle_modem_status(uart
);
430 spin_unlock_irqrestore(&port
->lock
, flags
);
432 return IRQ_RETVAL(handled
);
436 * men_z135_request_irq() - Request IRQ for 16z135 core
437 * @uart: z135 private uart port structure
439 * Request an IRQ for 16z135 to use. First try using MSI, if it fails
440 * fall back to using legacy interrupts.
442 static int men_z135_request_irq(struct men_z135_port
*uart
)
444 struct device
*dev
= &uart
->mdev
->dev
;
445 struct uart_port
*port
= &uart
->port
;
448 err
= request_irq(port
->irq
, men_z135_intr
, IRQF_SHARED
,
449 "men_z135_intr", uart
);
451 dev_err(dev
, "Error %d getting interrupt\n", err
);
457 * men_z135_tx_empty() - Handle tx_empty call
458 * @port: The UART port
460 * This function tests whether the TX FIFO and shifter for the port
461 * described by @port is empty.
463 static unsigned int men_z135_tx_empty(struct uart_port
*port
)
468 wptr
= ioread32(port
->membase
+ MEN_Z135_TX_CTRL
);
469 txc
= (wptr
>> 16) & 0x3ff;
478 * men_z135_set_mctrl() - Set modem control lines
479 * @port: The UART port
480 * @mctrl: The modem control lines
482 * This function sets the modem control lines for a port described by @port
483 * to the state described by @mctrl
485 static void men_z135_set_mctrl(struct uart_port
*port
, unsigned int mctrl
)
490 conf_reg
= old
= ioread32(port
->membase
+ MEN_Z135_CONF_REG
);
491 if (mctrl
& TIOCM_RTS
)
492 conf_reg
|= MEN_Z135_MCR_RTS
;
494 conf_reg
&= ~MEN_Z135_MCR_RTS
;
496 if (mctrl
& TIOCM_DTR
)
497 conf_reg
|= MEN_Z135_MCR_DTR
;
499 conf_reg
&= ~MEN_Z135_MCR_DTR
;
501 if (mctrl
& TIOCM_OUT1
)
502 conf_reg
|= MEN_Z135_MCR_OUT1
;
504 conf_reg
&= ~MEN_Z135_MCR_OUT1
;
506 if (mctrl
& TIOCM_OUT2
)
507 conf_reg
|= MEN_Z135_MCR_OUT2
;
509 conf_reg
&= ~MEN_Z135_MCR_OUT2
;
511 if (mctrl
& TIOCM_LOOP
)
512 conf_reg
|= MEN_Z135_MCR_LOOP
;
514 conf_reg
&= ~MEN_Z135_MCR_LOOP
;
517 iowrite32(conf_reg
, port
->membase
+ MEN_Z135_CONF_REG
);
521 * men_z135_get_mctrl() - Get modem control lines
522 * @port: The UART port
524 * Retruns the current state of modem control inputs.
526 static unsigned int men_z135_get_mctrl(struct uart_port
*port
)
528 unsigned int mctrl
= 0;
531 msr
= ioread8(port
->membase
+ MEN_Z135_STAT_REG
+ 1);
533 if (msr
& MEN_Z135_MSR_CTS
)
535 if (msr
& MEN_Z135_MSR_DSR
)
537 if (msr
& MEN_Z135_MSR_RI
)
539 if (msr
& MEN_Z135_MSR_DCD
)
546 * men_z135_stop_tx() - Stop transmitting characters
547 * @port: The UART port
549 * Stop transmitting characters. This might be due to CTS line becomming
550 * inactive or the tty layer indicating we want to stop transmission due to
553 static void men_z135_stop_tx(struct uart_port
*port
)
555 struct men_z135_port
*uart
= to_men_z135(port
);
557 men_z135_reg_clr(uart
, MEN_Z135_CONF_REG
, MEN_Z135_IER_TXCIEN
);
561 * men_z135_disable_ms() - Disable Modem Status
562 * port: The UART port
564 * Enable Modem Status IRQ.
566 static void men_z135_disable_ms(struct uart_port
*port
)
568 struct men_z135_port
*uart
= to_men_z135(port
);
570 men_z135_reg_clr(uart
, MEN_Z135_CONF_REG
, MEN_Z135_IER_MSIEN
);
574 * men_z135_start_tx() - Start transmitting characters
575 * @port: The UART port
577 * Start transmitting character. This actually doesn't transmit anything, but
578 * fires off the TX tasklet.
580 static void men_z135_start_tx(struct uart_port
*port
)
582 struct men_z135_port
*uart
= to_men_z135(port
);
585 men_z135_disable_ms(port
);
587 men_z135_handle_tx(uart
);
591 * men_z135_stop_rx() - Stop receiving characters
592 * @port: The UART port
594 * Stop receiving characters; the port is in the process of being closed.
596 static void men_z135_stop_rx(struct uart_port
*port
)
598 struct men_z135_port
*uart
= to_men_z135(port
);
600 men_z135_reg_clr(uart
, MEN_Z135_CONF_REG
, MEN_Z135_IER_RXCIEN
);
604 * men_z135_enable_ms() - Enable Modem Status
607 * Enable Modem Status IRQ.
609 static void men_z135_enable_ms(struct uart_port
*port
)
611 struct men_z135_port
*uart
= to_men_z135(port
);
613 men_z135_reg_set(uart
, MEN_Z135_CONF_REG
, MEN_Z135_IER_MSIEN
);
616 static int men_z135_startup(struct uart_port
*port
)
618 struct men_z135_port
*uart
= to_men_z135(port
);
622 err
= men_z135_request_irq(uart
);
626 conf_reg
= ioread32(port
->membase
+ MEN_Z135_CONF_REG
);
628 /* Activate all but TX space available IRQ */
629 conf_reg
|= MEN_Z135_ALL_IRQS
& ~MEN_Z135_IER_TXCIEN
;
630 conf_reg
&= ~(0xff << 16);
631 conf_reg
|= (txlvl
<< 16);
632 conf_reg
|= (rxlvl
<< 20);
634 iowrite32(conf_reg
, port
->membase
+ MEN_Z135_CONF_REG
);
637 iowrite32(rx_timeout
, port
->membase
+ MEN_Z135_TIMEOUT
);
642 static void men_z135_shutdown(struct uart_port
*port
)
644 struct men_z135_port
*uart
= to_men_z135(port
);
647 conf_reg
|= MEN_Z135_ALL_IRQS
;
649 men_z135_reg_clr(uart
, MEN_Z135_CONF_REG
, conf_reg
);
651 free_irq(uart
->port
.irq
, uart
);
654 static void men_z135_set_termios(struct uart_port
*port
,
655 struct ktermios
*termios
,
656 struct ktermios
*old
)
658 struct men_z135_port
*uart
= to_men_z135(port
);
665 conf_reg
= ioread32(port
->membase
+ MEN_Z135_CONF_REG
);
669 switch (termios
->c_cflag
& CSIZE
) {
685 if (termios
->c_cflag
& CSTOPB
)
686 lcr
|= MEN_Z135_NSTB2
<< MEN_Z135_STB_SHIFT
;
689 if (termios
->c_cflag
& PARENB
) {
690 lcr
|= MEN_Z135_PAR_ENA
<< MEN_Z135_PEN_SHIFT
;
692 if (termios
->c_cflag
& PARODD
)
693 lcr
|= MEN_Z135_PTY_ODD
<< MEN_Z135_PTY_SHIFT
;
695 lcr
|= MEN_Z135_PTY_EVN
<< MEN_Z135_PTY_SHIFT
;
697 lcr
|= MEN_Z135_PAR_DIS
<< MEN_Z135_PEN_SHIFT
;
699 conf_reg
|= MEN_Z135_IER_MSIEN
;
700 if (termios
->c_cflag
& CRTSCTS
) {
701 conf_reg
|= MEN_Z135_MCR_RCFC
;
702 uart
->automode
= true;
703 termios
->c_cflag
&= ~CLOCAL
;
705 conf_reg
&= ~MEN_Z135_MCR_RCFC
;
706 uart
->automode
= false;
709 termios
->c_cflag
&= ~CMSPAR
; /* Mark/Space parity is not supported */
711 conf_reg
|= lcr
<< MEN_Z135_LCR_SHIFT
;
712 iowrite32(conf_reg
, port
->membase
+ MEN_Z135_CONF_REG
);
714 uart_freq
= ioread32(port
->membase
+ MEN_Z135_UART_FREQ
);
716 uart_freq
= MEN_Z135_BASECLK
;
718 baud
= uart_get_baud_rate(port
, termios
, old
, 0, uart_freq
/ 16);
720 spin_lock(&port
->lock
);
721 if (tty_termios_baud_rate(termios
))
722 tty_termios_encode_baud_rate(termios
, baud
, baud
);
724 bd_reg
= uart_freq
/ (4 * baud
);
725 iowrite32(bd_reg
, port
->membase
+ MEN_Z135_BAUD_REG
);
727 uart_update_timeout(port
, termios
->c_cflag
, baud
);
728 spin_unlock(&port
->lock
);
731 static const char *men_z135_type(struct uart_port
*port
)
733 return KBUILD_MODNAME
;
736 static void men_z135_release_port(struct uart_port
*port
)
738 iounmap(port
->membase
);
739 port
->membase
= NULL
;
741 release_mem_region(port
->mapbase
, MEN_Z135_MEM_SIZE
);
744 static int men_z135_request_port(struct uart_port
*port
)
746 int size
= MEN_Z135_MEM_SIZE
;
748 if (!request_mem_region(port
->mapbase
, size
, "men_z135_port"))
751 port
->membase
= ioremap(port
->mapbase
, MEN_Z135_MEM_SIZE
);
752 if (port
->membase
== NULL
) {
753 release_mem_region(port
->mapbase
, MEN_Z135_MEM_SIZE
);
760 static void men_z135_config_port(struct uart_port
*port
, int type
)
762 port
->type
= PORT_MEN_Z135
;
763 men_z135_request_port(port
);
766 static int men_z135_verify_port(struct uart_port
*port
,
767 struct serial_struct
*serinfo
)
772 static struct uart_ops men_z135_ops
= {
773 .tx_empty
= men_z135_tx_empty
,
774 .set_mctrl
= men_z135_set_mctrl
,
775 .get_mctrl
= men_z135_get_mctrl
,
776 .stop_tx
= men_z135_stop_tx
,
777 .start_tx
= men_z135_start_tx
,
778 .stop_rx
= men_z135_stop_rx
,
779 .enable_ms
= men_z135_enable_ms
,
780 .startup
= men_z135_startup
,
781 .shutdown
= men_z135_shutdown
,
782 .set_termios
= men_z135_set_termios
,
783 .type
= men_z135_type
,
784 .release_port
= men_z135_release_port
,
785 .request_port
= men_z135_request_port
,
786 .config_port
= men_z135_config_port
,
787 .verify_port
= men_z135_verify_port
,
790 static struct uart_driver men_z135_driver
= {
791 .owner
= THIS_MODULE
,
792 .driver_name
= KBUILD_MODNAME
,
793 .dev_name
= "ttyHSU",
796 .nr
= MEN_Z135_MAX_PORTS
,
800 * men_z135_probe() - Probe a z135 instance
801 * @mdev: The MCB device
802 * @id: The MCB device ID
804 * men_z135_probe does the basic setup of hardware resources and registers the
805 * new uart port to the tty layer.
807 static int men_z135_probe(struct mcb_device
*mdev
,
808 const struct mcb_device_id
*id
)
810 struct men_z135_port
*uart
;
811 struct resource
*mem
;
817 uart
= devm_kzalloc(dev
, sizeof(struct men_z135_port
), GFP_KERNEL
);
821 uart
->rxbuf
= (unsigned char *)__get_free_page(GFP_KERNEL
);
827 mcb_set_drvdata(mdev
, uart
);
829 uart
->port
.uartclk
= MEN_Z135_BASECLK
* 16;
830 uart
->port
.fifosize
= MEN_Z135_FIFO_SIZE
;
831 uart
->port
.iotype
= UPIO_MEM
;
832 uart
->port
.ops
= &men_z135_ops
;
833 uart
->port
.irq
= mcb_get_irq(mdev
);
834 uart
->port
.iotype
= UPIO_MEM
;
835 uart
->port
.flags
= UPF_BOOT_AUTOCONF
| UPF_IOREMAP
;
836 uart
->port
.line
= line
++;
837 uart
->port
.dev
= dev
;
838 uart
->port
.type
= PORT_MEN_Z135
;
839 uart
->port
.mapbase
= mem
->start
;
840 uart
->port
.membase
= NULL
;
843 spin_lock_init(&uart
->port
.lock
);
844 spin_lock_init(&uart
->lock
);
846 err
= uart_add_one_port(&men_z135_driver
, &uart
->port
);
853 free_page((unsigned long) uart
->rxbuf
);
854 dev_err(dev
, "Failed to add UART: %d\n", err
);
860 * men_z135_remove() - Remove a z135 instance from the system
862 * @mdev: The MCB device
864 static void men_z135_remove(struct mcb_device
*mdev
)
866 struct men_z135_port
*uart
= mcb_get_drvdata(mdev
);
869 uart_remove_one_port(&men_z135_driver
, &uart
->port
);
870 free_page((unsigned long) uart
->rxbuf
);
873 static const struct mcb_device_id men_z135_ids
[] = {
877 MODULE_DEVICE_TABLE(mcb
, men_z135_ids
);
879 static struct mcb_driver mcb_driver
= {
882 .owner
= THIS_MODULE
,
884 .probe
= men_z135_probe
,
885 .remove
= men_z135_remove
,
886 .id_table
= men_z135_ids
,
890 * men_z135_init() - Driver Registration Routine
892 * men_z135_init is the first routine called when the driver is loaded. All it
893 * does is register with the legacy MEN Chameleon subsystem.
895 static int __init
men_z135_init(void)
899 err
= uart_register_driver(&men_z135_driver
);
901 pr_err("Failed to register UART: %d\n", err
);
905 err
= mcb_register_driver(&mcb_driver
);
907 pr_err("Failed to register MCB driver: %d\n", err
);
908 uart_unregister_driver(&men_z135_driver
);
914 module_init(men_z135_init
);
917 * men_z135_exit() - Driver Exit Routine
919 * men_z135_exit is called just before the driver is removed from memory.
921 static void __exit
men_z135_exit(void)
923 mcb_unregister_driver(&mcb_driver
);
924 uart_unregister_driver(&men_z135_driver
);
926 module_exit(men_z135_exit
);
928 MODULE_AUTHOR("Johannes Thumshirn <johannes.thumshirn@men.de>");
929 MODULE_LICENSE("GPL v2");
930 MODULE_DESCRIPTION("MEN 16z135 High Speed UART");
931 MODULE_ALIAS("mcb:16z135");