1 #if defined(CONFIG_SERIAL_EFM32_UART_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
5 #include <linux/kernel.h>
6 #include <linux/module.h>
8 #include <linux/platform_device.h>
9 #include <linux/console.h>
10 #include <linux/sysrq.h>
11 #include <linux/serial_core.h>
12 #include <linux/tty_flip.h>
13 #include <linux/slab.h>
14 #include <linux/clk.h>
16 #include <linux/of_device.h>
18 #include <linux/platform_data/efm32-uart.h>
20 #define DRIVER_NAME "efm32-uart"
21 #define DEV_NAME "ttyefm"
23 #define UARTn_CTRL 0x00
24 #define UARTn_CTRL_SYNC 0x0001
25 #define UARTn_CTRL_TXBIL 0x1000
27 #define UARTn_FRAME 0x04
28 #define UARTn_FRAME_DATABITS__MASK 0x000f
29 #define UARTn_FRAME_DATABITS(n) ((n) - 3)
30 #define UARTn_FRAME_PARITY__MASK 0x0300
31 #define UARTn_FRAME_PARITY_NONE 0x0000
32 #define UARTn_FRAME_PARITY_EVEN 0x0200
33 #define UARTn_FRAME_PARITY_ODD 0x0300
34 #define UARTn_FRAME_STOPBITS_HALF 0x0000
35 #define UARTn_FRAME_STOPBITS_ONE 0x1000
36 #define UARTn_FRAME_STOPBITS_TWO 0x3000
38 #define UARTn_CMD 0x0c
39 #define UARTn_CMD_RXEN 0x0001
40 #define UARTn_CMD_RXDIS 0x0002
41 #define UARTn_CMD_TXEN 0x0004
42 #define UARTn_CMD_TXDIS 0x0008
44 #define UARTn_STATUS 0x10
45 #define UARTn_STATUS_TXENS 0x0002
46 #define UARTn_STATUS_TXC 0x0020
47 #define UARTn_STATUS_TXBL 0x0040
48 #define UARTn_STATUS_RXDATAV 0x0080
50 #define UARTn_CLKDIV 0x14
52 #define UARTn_RXDATAX 0x18
53 #define UARTn_RXDATAX_RXDATA__MASK 0x01ff
54 #define UARTn_RXDATAX_PERR 0x4000
55 #define UARTn_RXDATAX_FERR 0x8000
57 * This is a software only flag used for ignore_status_mask and
58 * read_status_mask! It's used for breaks that the hardware doesn't report
61 #define SW_UARTn_RXDATAX_BERR 0x2000
63 #define UARTn_TXDATA 0x34
66 #define UARTn_IF_TXC 0x0001
67 #define UARTn_IF_TXBL 0x0002
68 #define UARTn_IF_RXDATAV 0x0004
69 #define UARTn_IF_RXOF 0x0010
71 #define UARTn_IFS 0x44
72 #define UARTn_IFC 0x48
73 #define UARTn_IEN 0x4c
75 #define UARTn_ROUTE 0x54
76 #define UARTn_ROUTE_LOCATION__MASK 0x0700
77 #define UARTn_ROUTE_LOCATION(n) (((n) << 8) & UARTn_ROUTE_LOCATION__MASK)
78 #define UARTn_ROUTE_RXPEN 0x0001
79 #define UARTn_ROUTE_TXPEN 0x0002
81 struct efm32_uart_port
{
82 struct uart_port port
;
85 struct efm32_uart_pdata pdata
;
87 #define to_efm_port(_port) container_of(_port, struct efm32_uart_port, port)
88 #define efm_debug(efm_port, format, arg...) \
89 dev_dbg(efm_port->port.dev, format, ##arg)
91 static void efm32_uart_write32(struct efm32_uart_port
*efm_port
,
92 u32 value
, unsigned offset
)
94 writel_relaxed(value
, efm_port
->port
.membase
+ offset
);
97 static u32
efm32_uart_read32(struct efm32_uart_port
*efm_port
,
100 return readl_relaxed(efm_port
->port
.membase
+ offset
);
103 static unsigned int efm32_uart_tx_empty(struct uart_port
*port
)
105 struct efm32_uart_port
*efm_port
= to_efm_port(port
);
106 u32 status
= efm32_uart_read32(efm_port
, UARTn_STATUS
);
108 if (status
& UARTn_STATUS_TXC
)
114 static void efm32_uart_set_mctrl(struct uart_port
*port
, unsigned int mctrl
)
116 /* sorry, neither handshaking lines nor loop functionallity */
119 static unsigned int efm32_uart_get_mctrl(struct uart_port
*port
)
121 /* sorry, no handshaking lines available */
122 return TIOCM_CAR
| TIOCM_CTS
| TIOCM_DSR
;
125 static void efm32_uart_stop_tx(struct uart_port
*port
)
127 struct efm32_uart_port
*efm_port
= to_efm_port(port
);
128 u32 ien
= efm32_uart_read32(efm_port
, UARTn_IEN
);
130 efm32_uart_write32(efm_port
, UARTn_CMD_TXDIS
, UARTn_CMD
);
131 ien
&= ~(UARTn_IF_TXC
| UARTn_IF_TXBL
);
132 efm32_uart_write32(efm_port
, ien
, UARTn_IEN
);
135 static void efm32_uart_tx_chars(struct efm32_uart_port
*efm_port
)
137 struct uart_port
*port
= &efm_port
->port
;
138 struct circ_buf
*xmit
= &port
->state
->xmit
;
140 while (efm32_uart_read32(efm_port
, UARTn_STATUS
) &
144 efm32_uart_write32(efm_port
, port
->x_char
,
149 if (!uart_circ_empty(xmit
) && !uart_tx_stopped(port
)) {
151 efm32_uart_write32(efm_port
, xmit
->buf
[xmit
->tail
],
153 xmit
->tail
= (xmit
->tail
+ 1) & (UART_XMIT_SIZE
- 1);
158 if (uart_circ_chars_pending(xmit
) < WAKEUP_CHARS
)
159 uart_write_wakeup(port
);
161 if (!port
->x_char
&& uart_circ_empty(xmit
) &&
162 efm32_uart_read32(efm_port
, UARTn_STATUS
) &
164 efm32_uart_stop_tx(port
);
167 static void efm32_uart_start_tx(struct uart_port
*port
)
169 struct efm32_uart_port
*efm_port
= to_efm_port(port
);
172 efm32_uart_write32(efm_port
,
173 UARTn_IF_TXBL
| UARTn_IF_TXC
, UARTn_IFC
);
174 ien
= efm32_uart_read32(efm_port
, UARTn_IEN
);
175 efm32_uart_write32(efm_port
,
176 ien
| UARTn_IF_TXBL
| UARTn_IF_TXC
, UARTn_IEN
);
177 efm32_uart_write32(efm_port
, UARTn_CMD_TXEN
, UARTn_CMD
);
179 efm32_uart_tx_chars(efm_port
);
182 static void efm32_uart_stop_rx(struct uart_port
*port
)
184 struct efm32_uart_port
*efm_port
= to_efm_port(port
);
186 efm32_uart_write32(efm_port
, UARTn_CMD_RXDIS
, UARTn_CMD
);
189 static void efm32_uart_break_ctl(struct uart_port
*port
, int ctl
)
191 /* not possible without fiddling with gpios */
194 static void efm32_uart_rx_chars(struct efm32_uart_port
*efm_port
)
196 struct uart_port
*port
= &efm_port
->port
;
198 while (efm32_uart_read32(efm_port
, UARTn_STATUS
) &
199 UARTn_STATUS_RXDATAV
) {
200 u32 rxdata
= efm32_uart_read32(efm_port
, UARTn_RXDATAX
);
204 * This is a reserved bit and I only saw it read as 0. But to be
205 * sure not to be confused too much by new devices adhere to the
206 * warning in the reference manual that reserverd bits might
207 * read as 1 in the future.
209 rxdata
&= ~SW_UARTn_RXDATAX_BERR
;
213 if ((rxdata
& UARTn_RXDATAX_FERR
) &&
214 !(rxdata
& UARTn_RXDATAX_RXDATA__MASK
)) {
215 rxdata
|= SW_UARTn_RXDATAX_BERR
;
217 if (uart_handle_break(port
))
219 } else if (rxdata
& UARTn_RXDATAX_PERR
)
220 port
->icount
.parity
++;
221 else if (rxdata
& UARTn_RXDATAX_FERR
)
222 port
->icount
.frame
++;
224 rxdata
&= port
->read_status_mask
;
226 if (rxdata
& SW_UARTn_RXDATAX_BERR
)
228 else if (rxdata
& UARTn_RXDATAX_PERR
)
230 else if (rxdata
& UARTn_RXDATAX_FERR
)
232 else if (uart_handle_sysrq_char(port
,
233 rxdata
& UARTn_RXDATAX_RXDATA__MASK
))
236 if ((rxdata
& port
->ignore_status_mask
) == 0)
237 tty_insert_flip_char(&port
->state
->port
,
238 rxdata
& UARTn_RXDATAX_RXDATA__MASK
, flag
);
242 static irqreturn_t
efm32_uart_rxirq(int irq
, void *data
)
244 struct efm32_uart_port
*efm_port
= data
;
245 u32 irqflag
= efm32_uart_read32(efm_port
, UARTn_IF
);
246 int handled
= IRQ_NONE
;
247 struct uart_port
*port
= &efm_port
->port
;
248 struct tty_port
*tport
= &port
->state
->port
;
250 spin_lock(&port
->lock
);
252 if (irqflag
& UARTn_IF_RXDATAV
) {
253 efm32_uart_write32(efm_port
, UARTn_IF_RXDATAV
, UARTn_IFC
);
254 efm32_uart_rx_chars(efm_port
);
256 handled
= IRQ_HANDLED
;
259 if (irqflag
& UARTn_IF_RXOF
) {
260 efm32_uart_write32(efm_port
, UARTn_IF_RXOF
, UARTn_IFC
);
261 port
->icount
.overrun
++;
262 tty_insert_flip_char(tport
, 0, TTY_OVERRUN
);
264 handled
= IRQ_HANDLED
;
267 spin_unlock(&port
->lock
);
269 tty_flip_buffer_push(tport
);
274 static irqreturn_t
efm32_uart_txirq(int irq
, void *data
)
276 struct efm32_uart_port
*efm_port
= data
;
277 u32 irqflag
= efm32_uart_read32(efm_port
, UARTn_IF
);
279 /* TXBL doesn't need to be cleared */
280 if (irqflag
& UARTn_IF_TXC
)
281 efm32_uart_write32(efm_port
, UARTn_IF_TXC
, UARTn_IFC
);
283 if (irqflag
& (UARTn_IF_TXC
| UARTn_IF_TXBL
)) {
284 efm32_uart_tx_chars(efm_port
);
290 static int efm32_uart_startup(struct uart_port
*port
)
292 struct efm32_uart_port
*efm_port
= to_efm_port(port
);
295 ret
= clk_enable(efm_port
->clk
);
297 efm_debug(efm_port
, "failed to enable clk\n");
300 port
->uartclk
= clk_get_rate(efm_port
->clk
);
302 /* Enable pins at configured location */
303 efm32_uart_write32(efm_port
,
304 UARTn_ROUTE_LOCATION(efm_port
->pdata
.location
) |
305 UARTn_ROUTE_RXPEN
| UARTn_ROUTE_TXPEN
,
308 ret
= request_irq(port
->irq
, efm32_uart_rxirq
, 0,
309 DRIVER_NAME
, efm_port
);
311 efm_debug(efm_port
, "failed to register rxirq\n");
312 goto err_request_irq_rx
;
315 /* disable all irqs */
316 efm32_uart_write32(efm_port
, 0, UARTn_IEN
);
318 ret
= request_irq(efm_port
->txirq
, efm32_uart_txirq
, 0,
319 DRIVER_NAME
, efm_port
);
321 efm_debug(efm_port
, "failed to register txirq\n");
322 free_irq(port
->irq
, efm_port
);
325 clk_disable(efm_port
->clk
);
327 efm32_uart_write32(efm_port
,
328 UARTn_IF_RXDATAV
| UARTn_IF_RXOF
, UARTn_IEN
);
329 efm32_uart_write32(efm_port
, UARTn_CMD_RXEN
, UARTn_CMD
);
336 static void efm32_uart_shutdown(struct uart_port
*port
)
338 struct efm32_uart_port
*efm_port
= to_efm_port(port
);
340 efm32_uart_write32(efm_port
, 0, UARTn_IEN
);
341 free_irq(port
->irq
, efm_port
);
343 clk_disable(efm_port
->clk
);
346 static void efm32_uart_set_termios(struct uart_port
*port
,
347 struct ktermios
*new, struct ktermios
*old
)
349 struct efm32_uart_port
*efm_port
= to_efm_port(port
);
355 /* no modem control lines */
356 new->c_cflag
&= ~(CRTSCTS
| CMSPAR
);
358 baud
= uart_get_baud_rate(port
, new, old
,
359 DIV_ROUND_CLOSEST(port
->uartclk
, 16 * 8192),
360 DIV_ROUND_CLOSEST(port
->uartclk
, 16));
362 switch (new->c_cflag
& CSIZE
) {
364 frame
|= UARTn_FRAME_DATABITS(5);
367 frame
|= UARTn_FRAME_DATABITS(6);
370 frame
|= UARTn_FRAME_DATABITS(7);
373 frame
|= UARTn_FRAME_DATABITS(8);
377 if (new->c_cflag
& CSTOPB
)
378 /* the receiver only verifies the first stop bit */
379 frame
|= UARTn_FRAME_STOPBITS_TWO
;
381 frame
|= UARTn_FRAME_STOPBITS_ONE
;
383 if (new->c_cflag
& PARENB
) {
384 if (new->c_cflag
& PARODD
)
385 frame
|= UARTn_FRAME_PARITY_ODD
;
387 frame
|= UARTn_FRAME_PARITY_EVEN
;
389 frame
|= UARTn_FRAME_PARITY_NONE
;
392 * the 6 lowest bits of CLKDIV are dc, bit 6 has value 0.25.
393 * port->uartclk <= 14e6, so 4 * port->uartclk doesn't overflow.
395 clkdiv
= (DIV_ROUND_CLOSEST(4 * port
->uartclk
, 16 * baud
) - 4) << 6;
397 spin_lock_irqsave(&port
->lock
, flags
);
399 efm32_uart_write32(efm_port
,
400 UARTn_CMD_TXDIS
| UARTn_CMD_RXDIS
, UARTn_CMD
);
402 port
->read_status_mask
= UARTn_RXDATAX_RXDATA__MASK
;
403 if (new->c_iflag
& INPCK
)
404 port
->read_status_mask
|=
405 UARTn_RXDATAX_FERR
| UARTn_RXDATAX_PERR
;
406 if (new->c_iflag
& (IGNBRK
| BRKINT
| PARMRK
))
407 port
->read_status_mask
|= SW_UARTn_RXDATAX_BERR
;
409 port
->ignore_status_mask
= 0;
410 if (new->c_iflag
& IGNPAR
)
411 port
->ignore_status_mask
|=
412 UARTn_RXDATAX_FERR
| UARTn_RXDATAX_PERR
;
413 if (new->c_iflag
& IGNBRK
)
414 port
->ignore_status_mask
|= SW_UARTn_RXDATAX_BERR
;
416 uart_update_timeout(port
, new->c_cflag
, baud
);
418 efm32_uart_write32(efm_port
, UARTn_CTRL_TXBIL
, UARTn_CTRL
);
419 efm32_uart_write32(efm_port
, frame
, UARTn_FRAME
);
420 efm32_uart_write32(efm_port
, clkdiv
, UARTn_CLKDIV
);
422 efm32_uart_write32(efm_port
, UARTn_CMD_TXEN
| UARTn_CMD_RXEN
,
425 spin_unlock_irqrestore(&port
->lock
, flags
);
428 static const char *efm32_uart_type(struct uart_port
*port
)
430 return port
->type
== PORT_EFMUART
? "efm32-uart" : NULL
;
433 static void efm32_uart_release_port(struct uart_port
*port
)
435 struct efm32_uart_port
*efm_port
= to_efm_port(port
);
437 clk_unprepare(efm_port
->clk
);
438 clk_put(efm_port
->clk
);
439 iounmap(port
->membase
);
442 static int efm32_uart_request_port(struct uart_port
*port
)
444 struct efm32_uart_port
*efm_port
= to_efm_port(port
);
447 port
->membase
= ioremap(port
->mapbase
, 60);
448 if (!efm_port
->port
.membase
) {
450 efm_debug(efm_port
, "failed to remap\n");
454 efm_port
->clk
= clk_get(port
->dev
, NULL
);
455 if (IS_ERR(efm_port
->clk
)) {
456 ret
= PTR_ERR(efm_port
->clk
);
457 efm_debug(efm_port
, "failed to get clock\n");
461 ret
= clk_prepare(efm_port
->clk
);
463 clk_put(efm_port
->clk
);
466 iounmap(port
->membase
);
473 static void efm32_uart_config_port(struct uart_port
*port
, int type
)
475 if (type
& UART_CONFIG_TYPE
&&
476 !efm32_uart_request_port(port
))
477 port
->type
= PORT_EFMUART
;
480 static int efm32_uart_verify_port(struct uart_port
*port
,
481 struct serial_struct
*serinfo
)
485 if (serinfo
->type
!= PORT_UNKNOWN
&& serinfo
->type
!= PORT_EFMUART
)
491 static struct uart_ops efm32_uart_pops
= {
492 .tx_empty
= efm32_uart_tx_empty
,
493 .set_mctrl
= efm32_uart_set_mctrl
,
494 .get_mctrl
= efm32_uart_get_mctrl
,
495 .stop_tx
= efm32_uart_stop_tx
,
496 .start_tx
= efm32_uart_start_tx
,
497 .stop_rx
= efm32_uart_stop_rx
,
498 .break_ctl
= efm32_uart_break_ctl
,
499 .startup
= efm32_uart_startup
,
500 .shutdown
= efm32_uart_shutdown
,
501 .set_termios
= efm32_uart_set_termios
,
502 .type
= efm32_uart_type
,
503 .release_port
= efm32_uart_release_port
,
504 .request_port
= efm32_uart_request_port
,
505 .config_port
= efm32_uart_config_port
,
506 .verify_port
= efm32_uart_verify_port
,
509 static struct efm32_uart_port
*efm32_uart_ports
[5];
511 #ifdef CONFIG_SERIAL_EFM32_UART_CONSOLE
512 static void efm32_uart_console_putchar(struct uart_port
*port
, int ch
)
514 struct efm32_uart_port
*efm_port
= to_efm_port(port
);
515 unsigned int timeout
= 0x400;
519 status
= efm32_uart_read32(efm_port
, UARTn_STATUS
);
521 if (status
& UARTn_STATUS_TXBL
)
526 efm32_uart_write32(efm_port
, ch
, UARTn_TXDATA
);
529 static void efm32_uart_console_write(struct console
*co
, const char *s
,
532 struct efm32_uart_port
*efm_port
= efm32_uart_ports
[co
->index
];
533 u32 status
= efm32_uart_read32(efm_port
, UARTn_STATUS
);
534 unsigned int timeout
= 0x400;
536 if (!(status
& UARTn_STATUS_TXENS
))
537 efm32_uart_write32(efm_port
, UARTn_CMD_TXEN
, UARTn_CMD
);
539 uart_console_write(&efm_port
->port
, s
, count
,
540 efm32_uart_console_putchar
);
542 /* Wait for the transmitter to become empty */
544 u32 status
= efm32_uart_read32(efm_port
, UARTn_STATUS
);
545 if (status
& UARTn_STATUS_TXC
)
551 if (!(status
& UARTn_STATUS_TXENS
))
552 efm32_uart_write32(efm_port
, UARTn_CMD_TXDIS
, UARTn_CMD
);
555 static void efm32_uart_console_get_options(struct efm32_uart_port
*efm_port
,
556 int *baud
, int *parity
, int *bits
)
558 u32 ctrl
= efm32_uart_read32(efm_port
, UARTn_CTRL
);
559 u32 route
, clkdiv
, frame
;
561 if (ctrl
& UARTn_CTRL_SYNC
)
562 /* not operating in async mode */
565 route
= efm32_uart_read32(efm_port
, UARTn_ROUTE
);
566 if (!(route
& UARTn_ROUTE_TXPEN
))
567 /* tx pin not routed */
570 clkdiv
= efm32_uart_read32(efm_port
, UARTn_CLKDIV
);
572 *baud
= DIV_ROUND_CLOSEST(4 * efm_port
->port
.uartclk
,
573 16 * (4 + (clkdiv
>> 6)));
575 frame
= efm32_uart_read32(efm_port
, UARTn_FRAME
);
576 switch (frame
& UARTn_FRAME_PARITY__MASK
) {
577 case UARTn_FRAME_PARITY_ODD
:
580 case UARTn_FRAME_PARITY_EVEN
:
587 *bits
= (frame
& UARTn_FRAME_DATABITS__MASK
) -
588 UARTn_FRAME_DATABITS(4) + 4;
590 efm_debug(efm_port
, "get_opts: options=%d%c%d\n",
591 *baud
, *parity
, *bits
);
594 static int efm32_uart_console_setup(struct console
*co
, char *options
)
596 struct efm32_uart_port
*efm_port
;
603 if (co
->index
< 0 || co
->index
>= ARRAY_SIZE(efm32_uart_ports
)) {
605 for (i
= 0; i
< ARRAY_SIZE(efm32_uart_ports
); ++i
) {
606 if (efm32_uart_ports
[i
]) {
607 pr_warn("efm32-console: fall back to console index %u (from %hhi)\n",
615 efm_port
= efm32_uart_ports
[co
->index
];
617 pr_warn("efm32-console: No port at %d\n", co
->index
);
621 ret
= clk_prepare(efm_port
->clk
);
623 dev_warn(efm_port
->port
.dev
,
624 "console: clk_prepare failed: %d\n", ret
);
628 efm_port
->port
.uartclk
= clk_get_rate(efm_port
->clk
);
631 uart_parse_options(options
, &baud
, &parity
, &bits
, &flow
);
633 efm32_uart_console_get_options(efm_port
,
634 &baud
, &parity
, &bits
);
636 return uart_set_options(&efm_port
->port
, co
, baud
, parity
, bits
, flow
);
639 static struct uart_driver efm32_uart_reg
;
641 static struct console efm32_uart_console
= {
643 .write
= efm32_uart_console_write
,
644 .device
= uart_console_device
,
645 .setup
= efm32_uart_console_setup
,
646 .flags
= CON_PRINTBUFFER
,
648 .data
= &efm32_uart_reg
,
652 #define efm32_uart_console (*(struct console *)NULL)
653 #endif /* ifdef CONFIG_SERIAL_EFM32_UART_CONSOLE / else */
655 static struct uart_driver efm32_uart_reg
= {
656 .owner
= THIS_MODULE
,
657 .driver_name
= DRIVER_NAME
,
658 .dev_name
= DEV_NAME
,
659 .nr
= ARRAY_SIZE(efm32_uart_ports
),
660 .cons
= &efm32_uart_console
,
663 static int efm32_uart_probe_dt(struct platform_device
*pdev
,
664 struct efm32_uart_port
*efm_port
)
666 struct device_node
*np
= pdev
->dev
.of_node
;
673 ret
= of_property_read_u32(np
, "energymicro,location", &location
);
676 /* fall back to wrongly namespaced property */
677 ret
= of_property_read_u32(np
, "efm32,location", &location
);
680 /* fall back to old and (wrongly) generic property "location" */
681 ret
= of_property_read_u32(np
, "location", &location
);
685 dev_err(&pdev
->dev
, "invalid location\n");
688 efm_debug(efm_port
, "using location %u\n", location
);
689 efm_port
->pdata
.location
= location
;
691 efm_debug(efm_port
, "fall back to location 0\n");
694 ret
= of_alias_get_id(np
, "serial");
696 dev_err(&pdev
->dev
, "failed to get alias id: %d\n", ret
);
699 efm_port
->port
.line
= ret
;
705 static int efm32_uart_probe(struct platform_device
*pdev
)
707 struct efm32_uart_port
*efm_port
;
708 struct resource
*res
;
712 efm_port
= kzalloc(sizeof(*efm_port
), GFP_KERNEL
);
714 dev_dbg(&pdev
->dev
, "failed to allocate private data\n");
718 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
721 dev_dbg(&pdev
->dev
, "failed to determine base address\n");
725 if (resource_size(res
) < 60) {
727 dev_dbg(&pdev
->dev
, "memory resource too small\n");
731 ret
= platform_get_irq(pdev
, 0);
733 dev_dbg(&pdev
->dev
, "failed to get rx irq\n");
737 efm_port
->port
.irq
= ret
;
739 ret
= platform_get_irq(pdev
, 1);
741 ret
= efm_port
->port
.irq
+ 1;
743 efm_port
->txirq
= ret
;
745 efm_port
->port
.dev
= &pdev
->dev
;
746 efm_port
->port
.mapbase
= res
->start
;
747 efm_port
->port
.type
= PORT_EFMUART
;
748 efm_port
->port
.iotype
= UPIO_MEM32
;
749 efm_port
->port
.fifosize
= 2;
750 efm_port
->port
.ops
= &efm32_uart_pops
;
751 efm_port
->port
.flags
= UPF_BOOT_AUTOCONF
;
753 ret
= efm32_uart_probe_dt(pdev
, efm_port
);
755 /* not created by device tree */
756 const struct efm32_uart_pdata
*pdata
= dev_get_platdata(&pdev
->dev
);
758 efm_port
->port
.line
= pdev
->id
;
761 efm_port
->pdata
= *pdata
;
765 line
= efm_port
->port
.line
;
767 if (line
>= 0 && line
< ARRAY_SIZE(efm32_uart_ports
))
768 efm32_uart_ports
[line
] = efm_port
;
770 ret
= uart_add_one_port(&efm32_uart_reg
, &efm_port
->port
);
772 dev_dbg(&pdev
->dev
, "failed to add port: %d\n", ret
);
774 if (line
>= 0 && line
< ARRAY_SIZE(efm32_uart_ports
))
775 efm32_uart_ports
[line
] = NULL
;
782 platform_set_drvdata(pdev
, efm_port
);
783 dev_dbg(&pdev
->dev
, "\\o/\n");
789 static int efm32_uart_remove(struct platform_device
*pdev
)
791 struct efm32_uart_port
*efm_port
= platform_get_drvdata(pdev
);
792 unsigned int line
= efm_port
->port
.line
;
794 uart_remove_one_port(&efm32_uart_reg
, &efm_port
->port
);
796 if (line
>= 0 && line
< ARRAY_SIZE(efm32_uart_ports
))
797 efm32_uart_ports
[line
] = NULL
;
804 static const struct of_device_id efm32_uart_dt_ids
[] = {
806 .compatible
= "energymicro,efm32-uart",
808 /* doesn't follow the "vendor,device" scheme, don't use */
809 .compatible
= "efm32,uart",
814 MODULE_DEVICE_TABLE(of
, efm32_uart_dt_ids
);
816 static struct platform_driver efm32_uart_driver
= {
817 .probe
= efm32_uart_probe
,
818 .remove
= efm32_uart_remove
,
822 .of_match_table
= efm32_uart_dt_ids
,
826 static int __init
efm32_uart_init(void)
830 ret
= uart_register_driver(&efm32_uart_reg
);
834 ret
= platform_driver_register(&efm32_uart_driver
);
836 uart_unregister_driver(&efm32_uart_reg
);
838 pr_info("EFM32 UART/USART driver\n");
842 module_init(efm32_uart_init
);
844 static void __exit
efm32_uart_exit(void)
846 platform_driver_unregister(&efm32_uart_driver
);
847 uart_unregister_driver(&efm32_uart_reg
);
849 module_exit(efm32_uart_exit
);
851 MODULE_AUTHOR("Uwe Kleine-Koenig <u.kleine-koenig@pengutronix.de>");
852 MODULE_DESCRIPTION("EFM32 UART/USART driver");
853 MODULE_LICENSE("GPL v2");
854 MODULE_ALIAS("platform:" DRIVER_NAME
);