xref: /openbmc/linux/drivers/tty/serial/st-asc.c (revision a406c4b8097473a1294ab056e65df801382b8f28)
1e3b3d0f5SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0+
2c4b05856SSrinivas Kandagatla /*
3c4b05856SSrinivas Kandagatla  * st-asc.c: ST Asynchronous serial controller (ASC) driver
4c4b05856SSrinivas Kandagatla  *
5c4b05856SSrinivas Kandagatla  * Copyright (C) 2003-2013 STMicroelectronics (R&D) Limited
6c4b05856SSrinivas Kandagatla  */
7c4b05856SSrinivas Kandagatla 
8c4b05856SSrinivas Kandagatla #if defined(CONFIG_SERIAL_ST_ASC_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
9c4b05856SSrinivas Kandagatla #define SUPPORT_SYSRQ
10c4b05856SSrinivas Kandagatla #endif
11c4b05856SSrinivas Kandagatla 
12c4b05856SSrinivas Kandagatla #include <linux/module.h>
13c4b05856SSrinivas Kandagatla #include <linux/serial.h>
14c4b05856SSrinivas Kandagatla #include <linux/console.h>
15c4b05856SSrinivas Kandagatla #include <linux/sysrq.h>
166929cb00SLee Jones #include <linux/pinctrl/consumer.h>
17c4b05856SSrinivas Kandagatla #include <linux/platform_device.h>
18c4b05856SSrinivas Kandagatla #include <linux/io.h>
19c4b05856SSrinivas Kandagatla #include <linux/irq.h>
20c4b05856SSrinivas Kandagatla #include <linux/tty.h>
21c4b05856SSrinivas Kandagatla #include <linux/tty_flip.h>
22c4b05856SSrinivas Kandagatla #include <linux/delay.h>
23c4b05856SSrinivas Kandagatla #include <linux/spinlock.h>
24c4b05856SSrinivas Kandagatla #include <linux/pm_runtime.h>
25c4b05856SSrinivas Kandagatla #include <linux/of.h>
26c4b05856SSrinivas Kandagatla #include <linux/of_platform.h>
27c4b05856SSrinivas Kandagatla #include <linux/serial_core.h>
28c4b05856SSrinivas Kandagatla #include <linux/clk.h>
29a4f6072fSLee Jones #include <linux/gpio/consumer.h>
30c4b05856SSrinivas Kandagatla 
31c4b05856SSrinivas Kandagatla #define DRIVER_NAME "st-asc"
32c4b05856SSrinivas Kandagatla #define ASC_SERIAL_NAME "ttyAS"
33c4b05856SSrinivas Kandagatla #define ASC_FIFO_SIZE 16
34c4b05856SSrinivas Kandagatla #define ASC_MAX_PORTS 8
35c4b05856SSrinivas Kandagatla 
366929cb00SLee Jones /* Pinctrl states */
376929cb00SLee Jones #define DEFAULT		0
386929cb00SLee Jones #define NO_HW_FLOWCTRL	1
396929cb00SLee Jones 
40c4b05856SSrinivas Kandagatla struct asc_port {
41c4b05856SSrinivas Kandagatla 	struct uart_port port;
42a4f6072fSLee Jones 	struct gpio_desc *rts;
43c4b05856SSrinivas Kandagatla 	struct clk *clk;
446929cb00SLee Jones 	struct pinctrl *pinctrl;
456929cb00SLee Jones 	struct pinctrl_state *states[2];
46c4b05856SSrinivas Kandagatla 	unsigned int hw_flow_control:1;
47c4b05856SSrinivas Kandagatla 	unsigned int force_m1:1;
48c4b05856SSrinivas Kandagatla };
49c4b05856SSrinivas Kandagatla 
50c4b05856SSrinivas Kandagatla static struct asc_port asc_ports[ASC_MAX_PORTS];
51c4b05856SSrinivas Kandagatla static struct uart_driver asc_uart_driver;
52c4b05856SSrinivas Kandagatla 
53c4b05856SSrinivas Kandagatla /*---- UART Register definitions ------------------------------*/
54c4b05856SSrinivas Kandagatla 
55c4b05856SSrinivas Kandagatla /* Register offsets */
56c4b05856SSrinivas Kandagatla 
57c4b05856SSrinivas Kandagatla #define ASC_BAUDRATE			0x00
58c4b05856SSrinivas Kandagatla #define ASC_TXBUF			0x04
59c4b05856SSrinivas Kandagatla #define ASC_RXBUF			0x08
60c4b05856SSrinivas Kandagatla #define ASC_CTL				0x0C
61c4b05856SSrinivas Kandagatla #define ASC_INTEN			0x10
62c4b05856SSrinivas Kandagatla #define ASC_STA				0x14
63c4b05856SSrinivas Kandagatla #define ASC_GUARDTIME			0x18
64c4b05856SSrinivas Kandagatla #define ASC_TIMEOUT			0x1C
65c4b05856SSrinivas Kandagatla #define ASC_TXRESET			0x20
66c4b05856SSrinivas Kandagatla #define ASC_RXRESET			0x24
67c4b05856SSrinivas Kandagatla #define ASC_RETRIES			0x28
68c4b05856SSrinivas Kandagatla 
69c4b05856SSrinivas Kandagatla /* ASC_RXBUF */
70c4b05856SSrinivas Kandagatla #define ASC_RXBUF_PE			0x100
71c4b05856SSrinivas Kandagatla #define ASC_RXBUF_FE			0x200
72c4b05856SSrinivas Kandagatla /**
73c4b05856SSrinivas Kandagatla  * Some of status comes from higher bits of the character and some come from
74c4b05856SSrinivas Kandagatla  * the status register. Combining both of them in to single status using dummy
75c4b05856SSrinivas Kandagatla  * bits.
76c4b05856SSrinivas Kandagatla  */
77c4b05856SSrinivas Kandagatla #define ASC_RXBUF_DUMMY_RX		0x10000
78c4b05856SSrinivas Kandagatla #define ASC_RXBUF_DUMMY_BE		0x20000
79c4b05856SSrinivas Kandagatla #define ASC_RXBUF_DUMMY_OE		0x40000
80c4b05856SSrinivas Kandagatla 
81c4b05856SSrinivas Kandagatla /* ASC_CTL */
82c4b05856SSrinivas Kandagatla 
83c4b05856SSrinivas Kandagatla #define ASC_CTL_MODE_MSK		0x0007
84c4b05856SSrinivas Kandagatla #define  ASC_CTL_MODE_8BIT		0x0001
85c4b05856SSrinivas Kandagatla #define  ASC_CTL_MODE_7BIT_PAR		0x0003
86c4b05856SSrinivas Kandagatla #define  ASC_CTL_MODE_9BIT		0x0004
87c4b05856SSrinivas Kandagatla #define  ASC_CTL_MODE_8BIT_WKUP		0x0005
88c4b05856SSrinivas Kandagatla #define  ASC_CTL_MODE_8BIT_PAR		0x0007
89c4b05856SSrinivas Kandagatla #define ASC_CTL_STOP_MSK		0x0018
90c4b05856SSrinivas Kandagatla #define  ASC_CTL_STOP_HALFBIT		0x0000
91c4b05856SSrinivas Kandagatla #define  ASC_CTL_STOP_1BIT		0x0008
92c4b05856SSrinivas Kandagatla #define  ASC_CTL_STOP_1_HALFBIT		0x0010
93c4b05856SSrinivas Kandagatla #define  ASC_CTL_STOP_2BIT		0x0018
94c4b05856SSrinivas Kandagatla #define ASC_CTL_PARITYODD		0x0020
95c4b05856SSrinivas Kandagatla #define ASC_CTL_LOOPBACK		0x0040
96c4b05856SSrinivas Kandagatla #define ASC_CTL_RUN			0x0080
97c4b05856SSrinivas Kandagatla #define ASC_CTL_RXENABLE		0x0100
98c4b05856SSrinivas Kandagatla #define ASC_CTL_SCENABLE		0x0200
99c4b05856SSrinivas Kandagatla #define ASC_CTL_FIFOENABLE		0x0400
100c4b05856SSrinivas Kandagatla #define ASC_CTL_CTSENABLE		0x0800
101c4b05856SSrinivas Kandagatla #define ASC_CTL_BAUDMODE		0x1000
102c4b05856SSrinivas Kandagatla 
103c4b05856SSrinivas Kandagatla /* ASC_GUARDTIME */
104c4b05856SSrinivas Kandagatla 
105c4b05856SSrinivas Kandagatla #define ASC_GUARDTIME_MSK		0x00FF
106c4b05856SSrinivas Kandagatla 
107c4b05856SSrinivas Kandagatla /* ASC_INTEN */
108c4b05856SSrinivas Kandagatla 
109c4b05856SSrinivas Kandagatla #define ASC_INTEN_RBE			0x0001
110c4b05856SSrinivas Kandagatla #define ASC_INTEN_TE			0x0002
111c4b05856SSrinivas Kandagatla #define ASC_INTEN_THE			0x0004
112c4b05856SSrinivas Kandagatla #define ASC_INTEN_PE			0x0008
113c4b05856SSrinivas Kandagatla #define ASC_INTEN_FE			0x0010
114c4b05856SSrinivas Kandagatla #define ASC_INTEN_OE			0x0020
115c4b05856SSrinivas Kandagatla #define ASC_INTEN_TNE			0x0040
116c4b05856SSrinivas Kandagatla #define ASC_INTEN_TOI			0x0080
117c4b05856SSrinivas Kandagatla #define ASC_INTEN_RHF			0x0100
118c4b05856SSrinivas Kandagatla 
119c4b05856SSrinivas Kandagatla /* ASC_RETRIES */
120c4b05856SSrinivas Kandagatla 
121c4b05856SSrinivas Kandagatla #define ASC_RETRIES_MSK			0x00FF
122c4b05856SSrinivas Kandagatla 
123c4b05856SSrinivas Kandagatla /* ASC_RXBUF */
124c4b05856SSrinivas Kandagatla 
125c4b05856SSrinivas Kandagatla #define ASC_RXBUF_MSK			0x03FF
126c4b05856SSrinivas Kandagatla 
127c4b05856SSrinivas Kandagatla /* ASC_STA */
128c4b05856SSrinivas Kandagatla 
129c4b05856SSrinivas Kandagatla #define ASC_STA_RBF			0x0001
130c4b05856SSrinivas Kandagatla #define ASC_STA_TE			0x0002
131c4b05856SSrinivas Kandagatla #define ASC_STA_THE			0x0004
132c4b05856SSrinivas Kandagatla #define ASC_STA_PE			0x0008
133c4b05856SSrinivas Kandagatla #define ASC_STA_FE			0x0010
134c4b05856SSrinivas Kandagatla #define ASC_STA_OE			0x0020
135c4b05856SSrinivas Kandagatla #define ASC_STA_TNE			0x0040
136c4b05856SSrinivas Kandagatla #define ASC_STA_TOI			0x0080
137c4b05856SSrinivas Kandagatla #define ASC_STA_RHF			0x0100
138c4b05856SSrinivas Kandagatla #define ASC_STA_TF			0x0200
139c4b05856SSrinivas Kandagatla #define ASC_STA_NKD			0x0400
140c4b05856SSrinivas Kandagatla 
141c4b05856SSrinivas Kandagatla /* ASC_TIMEOUT */
142c4b05856SSrinivas Kandagatla 
143c4b05856SSrinivas Kandagatla #define ASC_TIMEOUT_MSK			0x00FF
144c4b05856SSrinivas Kandagatla 
145c4b05856SSrinivas Kandagatla /* ASC_TXBUF */
146c4b05856SSrinivas Kandagatla 
147c4b05856SSrinivas Kandagatla #define ASC_TXBUF_MSK			0x01FF
148c4b05856SSrinivas Kandagatla 
149c4b05856SSrinivas Kandagatla /*---- Inline function definitions ---------------------------*/
150c4b05856SSrinivas Kandagatla 
151c4b05856SSrinivas Kandagatla static inline struct asc_port *to_asc_port(struct uart_port *port)
152c4b05856SSrinivas Kandagatla {
153c4b05856SSrinivas Kandagatla 	return container_of(port, struct asc_port, port);
154c4b05856SSrinivas Kandagatla }
155c4b05856SSrinivas Kandagatla 
156c4b05856SSrinivas Kandagatla static inline u32 asc_in(struct uart_port *port, u32 offset)
157c4b05856SSrinivas Kandagatla {
158daea65a7SDaniel Thompson #ifdef readl_relaxed
15908177eceSDaniel Thompson 	return readl_relaxed(port->membase + offset);
160daea65a7SDaniel Thompson #else
161daea65a7SDaniel Thompson 	return readl(port->membase + offset);
162daea65a7SDaniel Thompson #endif
163c4b05856SSrinivas Kandagatla }
164c4b05856SSrinivas Kandagatla 
165c4b05856SSrinivas Kandagatla static inline void asc_out(struct uart_port *port, u32 offset, u32 value)
166c4b05856SSrinivas Kandagatla {
16708177eceSDaniel Thompson #ifdef writel_relaxed
16808177eceSDaniel Thompson 	writel_relaxed(value, port->membase + offset);
16908177eceSDaniel Thompson #else
170c4b05856SSrinivas Kandagatla 	writel(value, port->membase + offset);
17108177eceSDaniel Thompson #endif
172c4b05856SSrinivas Kandagatla }
173c4b05856SSrinivas Kandagatla 
174c4b05856SSrinivas Kandagatla /*
175c4b05856SSrinivas Kandagatla  * Some simple utility functions to enable and disable interrupts.
176c4b05856SSrinivas Kandagatla  * Note that these need to be called with interrupts disabled.
177c4b05856SSrinivas Kandagatla  */
178c4b05856SSrinivas Kandagatla static inline void asc_disable_tx_interrupts(struct uart_port *port)
179c4b05856SSrinivas Kandagatla {
180c4b05856SSrinivas Kandagatla 	u32 intenable = asc_in(port, ASC_INTEN) & ~ASC_INTEN_THE;
181c4b05856SSrinivas Kandagatla 	asc_out(port, ASC_INTEN, intenable);
182c4b05856SSrinivas Kandagatla 	(void)asc_in(port, ASC_INTEN);	/* Defeat bus write posting */
183c4b05856SSrinivas Kandagatla }
184c4b05856SSrinivas Kandagatla 
185c4b05856SSrinivas Kandagatla static inline void asc_enable_tx_interrupts(struct uart_port *port)
186c4b05856SSrinivas Kandagatla {
187c4b05856SSrinivas Kandagatla 	u32 intenable = asc_in(port, ASC_INTEN) | ASC_INTEN_THE;
188c4b05856SSrinivas Kandagatla 	asc_out(port, ASC_INTEN, intenable);
189c4b05856SSrinivas Kandagatla }
190c4b05856SSrinivas Kandagatla 
191c4b05856SSrinivas Kandagatla static inline void asc_disable_rx_interrupts(struct uart_port *port)
192c4b05856SSrinivas Kandagatla {
193c4b05856SSrinivas Kandagatla 	u32 intenable = asc_in(port, ASC_INTEN) & ~ASC_INTEN_RBE;
194c4b05856SSrinivas Kandagatla 	asc_out(port, ASC_INTEN, intenable);
195c4b05856SSrinivas Kandagatla 	(void)asc_in(port, ASC_INTEN);	/* Defeat bus write posting */
196c4b05856SSrinivas Kandagatla }
197c4b05856SSrinivas Kandagatla 
198c4b05856SSrinivas Kandagatla static inline void asc_enable_rx_interrupts(struct uart_port *port)
199c4b05856SSrinivas Kandagatla {
200c4b05856SSrinivas Kandagatla 	u32 intenable = asc_in(port, ASC_INTEN) | ASC_INTEN_RBE;
201c4b05856SSrinivas Kandagatla 	asc_out(port, ASC_INTEN, intenable);
202c4b05856SSrinivas Kandagatla }
203c4b05856SSrinivas Kandagatla 
204c4b05856SSrinivas Kandagatla static inline u32 asc_txfifo_is_empty(struct uart_port *port)
205c4b05856SSrinivas Kandagatla {
206c4b05856SSrinivas Kandagatla 	return asc_in(port, ASC_STA) & ASC_STA_TE;
207c4b05856SSrinivas Kandagatla }
208c4b05856SSrinivas Kandagatla 
2091ffcd67dSDaniel Thompson static inline u32 asc_txfifo_is_half_empty(struct uart_port *port)
210c4b05856SSrinivas Kandagatla {
2111ffcd67dSDaniel Thompson 	return asc_in(port, ASC_STA) & ASC_STA_THE;
212c4b05856SSrinivas Kandagatla }
213c4b05856SSrinivas Kandagatla 
214c4b05856SSrinivas Kandagatla static inline const char *asc_port_name(struct uart_port *port)
215c4b05856SSrinivas Kandagatla {
216c4b05856SSrinivas Kandagatla 	return to_platform_device(port->dev)->name;
217c4b05856SSrinivas Kandagatla }
218c4b05856SSrinivas Kandagatla 
219c4b05856SSrinivas Kandagatla /*----------------------------------------------------------------------*/
220c4b05856SSrinivas Kandagatla 
221c4b05856SSrinivas Kandagatla /*
222c4b05856SSrinivas Kandagatla  * This section contains code to support the use of the ASC as a
223c4b05856SSrinivas Kandagatla  * generic serial port.
224c4b05856SSrinivas Kandagatla  */
225c4b05856SSrinivas Kandagatla 
226c4b05856SSrinivas Kandagatla static inline unsigned asc_hw_txroom(struct uart_port *port)
227c4b05856SSrinivas Kandagatla {
228c4b05856SSrinivas Kandagatla 	u32 status = asc_in(port, ASC_STA);
229c4b05856SSrinivas Kandagatla 
230c4b05856SSrinivas Kandagatla 	if (status & ASC_STA_THE)
231c4b05856SSrinivas Kandagatla 		return port->fifosize / 2;
232c4b05856SSrinivas Kandagatla 	else if (!(status & ASC_STA_TF))
233c4b05856SSrinivas Kandagatla 		return 1;
234c4b05856SSrinivas Kandagatla 
235c4b05856SSrinivas Kandagatla 	return 0;
236c4b05856SSrinivas Kandagatla }
237c4b05856SSrinivas Kandagatla 
238c4b05856SSrinivas Kandagatla /*
239c4b05856SSrinivas Kandagatla  * Start transmitting chars.
240c4b05856SSrinivas Kandagatla  * This is called from both interrupt and task level.
241c4b05856SSrinivas Kandagatla  * Either way interrupts are disabled.
242c4b05856SSrinivas Kandagatla  */
243c4b05856SSrinivas Kandagatla static void asc_transmit_chars(struct uart_port *port)
244c4b05856SSrinivas Kandagatla {
245c4b05856SSrinivas Kandagatla 	struct circ_buf *xmit = &port->state->xmit;
246c4b05856SSrinivas Kandagatla 	int txroom;
247c4b05856SSrinivas Kandagatla 	unsigned char c;
248c4b05856SSrinivas Kandagatla 
249c4b05856SSrinivas Kandagatla 	txroom = asc_hw_txroom(port);
250c4b05856SSrinivas Kandagatla 
251c4b05856SSrinivas Kandagatla 	if ((txroom != 0) && port->x_char) {
252c4b05856SSrinivas Kandagatla 		c = port->x_char;
253c4b05856SSrinivas Kandagatla 		port->x_char = 0;
254c4b05856SSrinivas Kandagatla 		asc_out(port, ASC_TXBUF, c);
255c4b05856SSrinivas Kandagatla 		port->icount.tx++;
256c4b05856SSrinivas Kandagatla 		txroom = asc_hw_txroom(port);
257c4b05856SSrinivas Kandagatla 	}
258c4b05856SSrinivas Kandagatla 
259c4b05856SSrinivas Kandagatla 	if (uart_tx_stopped(port)) {
260c4b05856SSrinivas Kandagatla 		/*
261c4b05856SSrinivas Kandagatla 		 * We should try and stop the hardware here, but I
262c4b05856SSrinivas Kandagatla 		 * don't think the ASC has any way to do that.
263c4b05856SSrinivas Kandagatla 		 */
264c4b05856SSrinivas Kandagatla 		asc_disable_tx_interrupts(port);
265c4b05856SSrinivas Kandagatla 		return;
266c4b05856SSrinivas Kandagatla 	}
267c4b05856SSrinivas Kandagatla 
268c4b05856SSrinivas Kandagatla 	if (uart_circ_empty(xmit)) {
269c4b05856SSrinivas Kandagatla 		asc_disable_tx_interrupts(port);
270c4b05856SSrinivas Kandagatla 		return;
271c4b05856SSrinivas Kandagatla 	}
272c4b05856SSrinivas Kandagatla 
273c4b05856SSrinivas Kandagatla 	if (txroom == 0)
274c4b05856SSrinivas Kandagatla 		return;
275c4b05856SSrinivas Kandagatla 
276c4b05856SSrinivas Kandagatla 	do {
277c4b05856SSrinivas Kandagatla 		c = xmit->buf[xmit->tail];
278c4b05856SSrinivas Kandagatla 		xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
279c4b05856SSrinivas Kandagatla 		asc_out(port, ASC_TXBUF, c);
280c4b05856SSrinivas Kandagatla 		port->icount.tx++;
281c4b05856SSrinivas Kandagatla 		txroom--;
282c4b05856SSrinivas Kandagatla 	} while ((txroom > 0) && (!uart_circ_empty(xmit)));
283c4b05856SSrinivas Kandagatla 
284c4b05856SSrinivas Kandagatla 	if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
285c4b05856SSrinivas Kandagatla 		uart_write_wakeup(port);
286c4b05856SSrinivas Kandagatla 
287c4b05856SSrinivas Kandagatla 	if (uart_circ_empty(xmit))
288c4b05856SSrinivas Kandagatla 		asc_disable_tx_interrupts(port);
289c4b05856SSrinivas Kandagatla }
290c4b05856SSrinivas Kandagatla 
291c4b05856SSrinivas Kandagatla static void asc_receive_chars(struct uart_port *port)
292c4b05856SSrinivas Kandagatla {
293c4b05856SSrinivas Kandagatla 	struct tty_port *tport = &port->state->port;
2945ab066e5SLee Jones 	unsigned long status, mode;
295c4b05856SSrinivas Kandagatla 	unsigned long c = 0;
296c4b05856SSrinivas Kandagatla 	char flag;
2975ab066e5SLee Jones 	bool ignore_pe = false;
2985ab066e5SLee Jones 
2995ab066e5SLee Jones 	/*
3005ab066e5SLee Jones 	 * Datasheet states: If the MODE field selects an 8-bit frame then
3015ab066e5SLee Jones 	 * this [parity error] bit is undefined. Software should ignore this
3025ab066e5SLee Jones 	 * bit when reading 8-bit frames.
3035ab066e5SLee Jones 	 */
3045ab066e5SLee Jones 	mode = asc_in(port, ASC_CTL) & ASC_CTL_MODE_MSK;
3055ab066e5SLee Jones 	if (mode == ASC_CTL_MODE_8BIT || mode == ASC_CTL_MODE_8BIT_PAR)
3065ab066e5SLee Jones 		ignore_pe = true;
307c4b05856SSrinivas Kandagatla 
3087b8a0353SAndy Shevchenko 	if (irqd_is_wakeup_set(irq_get_irq_data(port->irq)))
309c4b05856SSrinivas Kandagatla 		pm_wakeup_event(tport->tty->dev, 0);
310c4b05856SSrinivas Kandagatla 
311c4b05856SSrinivas Kandagatla 	while ((status = asc_in(port, ASC_STA)) & ASC_STA_RBF) {
312c4b05856SSrinivas Kandagatla 		c = asc_in(port, ASC_RXBUF) | ASC_RXBUF_DUMMY_RX;
313c4b05856SSrinivas Kandagatla 		flag = TTY_NORMAL;
314c4b05856SSrinivas Kandagatla 		port->icount.rx++;
315c4b05856SSrinivas Kandagatla 
3165ab066e5SLee Jones 		if (status & ASC_STA_OE || c & ASC_RXBUF_FE ||
3175ab066e5SLee Jones 		    (c & ASC_RXBUF_PE && !ignore_pe)) {
318c4b05856SSrinivas Kandagatla 
319c4b05856SSrinivas Kandagatla 			if (c & ASC_RXBUF_FE) {
320c3c00b6fSDaniel Thompson 				if (c == (ASC_RXBUF_FE | ASC_RXBUF_DUMMY_RX)) {
321c4b05856SSrinivas Kandagatla 					port->icount.brk++;
322c4b05856SSrinivas Kandagatla 					if (uart_handle_break(port))
323c4b05856SSrinivas Kandagatla 						continue;
324c4b05856SSrinivas Kandagatla 					c |= ASC_RXBUF_DUMMY_BE;
325c4b05856SSrinivas Kandagatla 				} else {
326c4b05856SSrinivas Kandagatla 					port->icount.frame++;
327c4b05856SSrinivas Kandagatla 				}
328c4b05856SSrinivas Kandagatla 			} else if (c & ASC_RXBUF_PE) {
329c4b05856SSrinivas Kandagatla 				port->icount.parity++;
330c4b05856SSrinivas Kandagatla 			}
331c4b05856SSrinivas Kandagatla 			/*
332c4b05856SSrinivas Kandagatla 			 * Reading any data from the RX FIFO clears the
333c4b05856SSrinivas Kandagatla 			 * overflow error condition.
334c4b05856SSrinivas Kandagatla 			 */
335c4b05856SSrinivas Kandagatla 			if (status & ASC_STA_OE) {
336c4b05856SSrinivas Kandagatla 				port->icount.overrun++;
337c4b05856SSrinivas Kandagatla 				c |= ASC_RXBUF_DUMMY_OE;
338c4b05856SSrinivas Kandagatla 			}
339c4b05856SSrinivas Kandagatla 
340c4b05856SSrinivas Kandagatla 			c &= port->read_status_mask;
341c4b05856SSrinivas Kandagatla 
342c4b05856SSrinivas Kandagatla 			if (c & ASC_RXBUF_DUMMY_BE)
343c4b05856SSrinivas Kandagatla 				flag = TTY_BREAK;
344c4b05856SSrinivas Kandagatla 			else if (c & ASC_RXBUF_PE)
345c4b05856SSrinivas Kandagatla 				flag = TTY_PARITY;
346c4b05856SSrinivas Kandagatla 			else if (c & ASC_RXBUF_FE)
347c4b05856SSrinivas Kandagatla 				flag = TTY_FRAME;
348c4b05856SSrinivas Kandagatla 		}
349c4b05856SSrinivas Kandagatla 
350c3c00b6fSDaniel Thompson 		if (uart_handle_sysrq_char(port, c & 0xff))
351c4b05856SSrinivas Kandagatla 			continue;
352c4b05856SSrinivas Kandagatla 
353c4b05856SSrinivas Kandagatla 		uart_insert_char(port, c, ASC_RXBUF_DUMMY_OE, c & 0xff, flag);
354c4b05856SSrinivas Kandagatla 	}
355c4b05856SSrinivas Kandagatla 
356c4b05856SSrinivas Kandagatla 	/* Tell the rest of the system the news. New characters! */
357c4b05856SSrinivas Kandagatla 	tty_flip_buffer_push(tport);
358c4b05856SSrinivas Kandagatla }
359c4b05856SSrinivas Kandagatla 
360c4b05856SSrinivas Kandagatla static irqreturn_t asc_interrupt(int irq, void *ptr)
361c4b05856SSrinivas Kandagatla {
362c4b05856SSrinivas Kandagatla 	struct uart_port *port = ptr;
363c4b05856SSrinivas Kandagatla 	u32 status;
364c4b05856SSrinivas Kandagatla 
365c4b05856SSrinivas Kandagatla 	spin_lock(&port->lock);
366c4b05856SSrinivas Kandagatla 
367c4b05856SSrinivas Kandagatla 	status = asc_in(port, ASC_STA);
368c4b05856SSrinivas Kandagatla 
369c4b05856SSrinivas Kandagatla 	if (status & ASC_STA_RBF) {
370c4b05856SSrinivas Kandagatla 		/* Receive FIFO not empty */
371c4b05856SSrinivas Kandagatla 		asc_receive_chars(port);
372c4b05856SSrinivas Kandagatla 	}
373c4b05856SSrinivas Kandagatla 
374c4b05856SSrinivas Kandagatla 	if ((status & ASC_STA_THE) &&
375c4b05856SSrinivas Kandagatla 	    (asc_in(port, ASC_INTEN) & ASC_INTEN_THE)) {
376c4b05856SSrinivas Kandagatla 		/* Transmitter FIFO at least half empty */
377c4b05856SSrinivas Kandagatla 		asc_transmit_chars(port);
378c4b05856SSrinivas Kandagatla 	}
379c4b05856SSrinivas Kandagatla 
380c4b05856SSrinivas Kandagatla 	spin_unlock(&port->lock);
381c4b05856SSrinivas Kandagatla 
382c4b05856SSrinivas Kandagatla 	return IRQ_HANDLED;
383c4b05856SSrinivas Kandagatla }
384c4b05856SSrinivas Kandagatla 
385c4b05856SSrinivas Kandagatla /*----------------------------------------------------------------------*/
386c4b05856SSrinivas Kandagatla 
387c4b05856SSrinivas Kandagatla /*
388c4b05856SSrinivas Kandagatla  * UART Functions
389c4b05856SSrinivas Kandagatla  */
390c4b05856SSrinivas Kandagatla 
391c4b05856SSrinivas Kandagatla static unsigned int asc_tx_empty(struct uart_port *port)
392c4b05856SSrinivas Kandagatla {
393c4b05856SSrinivas Kandagatla 	return asc_txfifo_is_empty(port) ? TIOCSER_TEMT : 0;
394c4b05856SSrinivas Kandagatla }
395c4b05856SSrinivas Kandagatla 
396c4b05856SSrinivas Kandagatla static void asc_set_mctrl(struct uart_port *port, unsigned int mctrl)
397c4b05856SSrinivas Kandagatla {
398a4f6072fSLee Jones 	struct asc_port *ascport = to_asc_port(port);
399a4f6072fSLee Jones 
400c4b05856SSrinivas Kandagatla 	/*
401a4f6072fSLee Jones 	 * This routine is used for seting signals of: DTR, DCD, CTS and RTS.
402a4f6072fSLee Jones 	 * We use ASC's hardware for CTS/RTS when hardware flow-control is
403a4f6072fSLee Jones 	 * enabled, however if the RTS line is required for another purpose,
404a4f6072fSLee Jones 	 * commonly controlled using HUP from userspace, then we need to toggle
405a4f6072fSLee Jones 	 * it manually, using GPIO.
406a4f6072fSLee Jones 	 *
407a4f6072fSLee Jones 	 * Some boards also have DTR and DCD implemented using PIO pins, code to
408a4f6072fSLee Jones 	 * do this should be hooked in here.
409c4b05856SSrinivas Kandagatla 	 */
410a4f6072fSLee Jones 
411a4f6072fSLee Jones 	if (!ascport->rts)
412a4f6072fSLee Jones 		return;
413a4f6072fSLee Jones 
414a4f6072fSLee Jones 	/* If HW flow-control is enabled, we can't fiddle with the RTS line */
415a4f6072fSLee Jones 	if (asc_in(port, ASC_CTL) & ASC_CTL_CTSENABLE)
416a4f6072fSLee Jones 		return;
417a4f6072fSLee Jones 
418a4f6072fSLee Jones 	gpiod_set_value(ascport->rts, mctrl & TIOCM_RTS);
419c4b05856SSrinivas Kandagatla }
420c4b05856SSrinivas Kandagatla 
421c4b05856SSrinivas Kandagatla static unsigned int asc_get_mctrl(struct uart_port *port)
422c4b05856SSrinivas Kandagatla {
423c4b05856SSrinivas Kandagatla 	/*
424c4b05856SSrinivas Kandagatla 	 * This routine is used for geting signals of: DTR, DCD, DSR, RI,
425c4b05856SSrinivas Kandagatla 	 * and CTS/RTS
426c4b05856SSrinivas Kandagatla 	 */
427c4b05856SSrinivas Kandagatla 	return TIOCM_CAR | TIOCM_DSR | TIOCM_CTS;
428c4b05856SSrinivas Kandagatla }
429c4b05856SSrinivas Kandagatla 
430c4b05856SSrinivas Kandagatla /* There are probably characters waiting to be transmitted. */
431c4b05856SSrinivas Kandagatla static void asc_start_tx(struct uart_port *port)
432c4b05856SSrinivas Kandagatla {
433c4b05856SSrinivas Kandagatla 	struct circ_buf *xmit = &port->state->xmit;
434c4b05856SSrinivas Kandagatla 
435c4b05856SSrinivas Kandagatla 	if (!uart_circ_empty(xmit))
436c4b05856SSrinivas Kandagatla 		asc_enable_tx_interrupts(port);
437c4b05856SSrinivas Kandagatla }
438c4b05856SSrinivas Kandagatla 
439c4b05856SSrinivas Kandagatla /* Transmit stop */
440c4b05856SSrinivas Kandagatla static void asc_stop_tx(struct uart_port *port)
441c4b05856SSrinivas Kandagatla {
442c4b05856SSrinivas Kandagatla 	asc_disable_tx_interrupts(port);
443c4b05856SSrinivas Kandagatla }
444c4b05856SSrinivas Kandagatla 
445c4b05856SSrinivas Kandagatla /* Receive stop */
446c4b05856SSrinivas Kandagatla static void asc_stop_rx(struct uart_port *port)
447c4b05856SSrinivas Kandagatla {
448c4b05856SSrinivas Kandagatla 	asc_disable_rx_interrupts(port);
449c4b05856SSrinivas Kandagatla }
450c4b05856SSrinivas Kandagatla 
451c4b05856SSrinivas Kandagatla /* Handle breaks - ignored by us */
452c4b05856SSrinivas Kandagatla static void asc_break_ctl(struct uart_port *port, int break_state)
453c4b05856SSrinivas Kandagatla {
454c4b05856SSrinivas Kandagatla 	/* Nothing here yet .. */
455c4b05856SSrinivas Kandagatla }
456c4b05856SSrinivas Kandagatla 
457c4b05856SSrinivas Kandagatla /*
458c4b05856SSrinivas Kandagatla  * Enable port for reception.
459c4b05856SSrinivas Kandagatla  */
460c4b05856SSrinivas Kandagatla static int asc_startup(struct uart_port *port)
461c4b05856SSrinivas Kandagatla {
462616ea8d2SSudeep Holla 	if (request_irq(port->irq, asc_interrupt, 0,
463c4b05856SSrinivas Kandagatla 			asc_port_name(port), port)) {
464c4b05856SSrinivas Kandagatla 		dev_err(port->dev, "cannot allocate irq.\n");
465c4b05856SSrinivas Kandagatla 		return -ENODEV;
466c4b05856SSrinivas Kandagatla 	}
467c4b05856SSrinivas Kandagatla 
468c4b05856SSrinivas Kandagatla 	asc_transmit_chars(port);
469c4b05856SSrinivas Kandagatla 	asc_enable_rx_interrupts(port);
470c4b05856SSrinivas Kandagatla 
471c4b05856SSrinivas Kandagatla 	return 0;
472c4b05856SSrinivas Kandagatla }
473c4b05856SSrinivas Kandagatla 
474c4b05856SSrinivas Kandagatla static void asc_shutdown(struct uart_port *port)
475c4b05856SSrinivas Kandagatla {
476c4b05856SSrinivas Kandagatla 	asc_disable_tx_interrupts(port);
477c4b05856SSrinivas Kandagatla 	asc_disable_rx_interrupts(port);
478c4b05856SSrinivas Kandagatla 	free_irq(port->irq, port);
479c4b05856SSrinivas Kandagatla }
480c4b05856SSrinivas Kandagatla 
481c4b05856SSrinivas Kandagatla static void asc_pm(struct uart_port *port, unsigned int state,
482c4b05856SSrinivas Kandagatla 		unsigned int oldstate)
483c4b05856SSrinivas Kandagatla {
484c4b05856SSrinivas Kandagatla 	struct asc_port *ascport = to_asc_port(port);
485c4b05856SSrinivas Kandagatla 	unsigned long flags = 0;
486c4b05856SSrinivas Kandagatla 	u32 ctl;
487c4b05856SSrinivas Kandagatla 
488c4b05856SSrinivas Kandagatla 	switch (state) {
489c4b05856SSrinivas Kandagatla 	case UART_PM_STATE_ON:
490c4b05856SSrinivas Kandagatla 		clk_prepare_enable(ascport->clk);
491c4b05856SSrinivas Kandagatla 		break;
492c4b05856SSrinivas Kandagatla 	case UART_PM_STATE_OFF:
493c4b05856SSrinivas Kandagatla 		/*
494c4b05856SSrinivas Kandagatla 		 * Disable the ASC baud rate generator, which is as close as
495c4b05856SSrinivas Kandagatla 		 * we can come to turning it off. Note this is not called with
496c4b05856SSrinivas Kandagatla 		 * the port spinlock held.
497c4b05856SSrinivas Kandagatla 		 */
498c4b05856SSrinivas Kandagatla 		spin_lock_irqsave(&port->lock, flags);
499c4b05856SSrinivas Kandagatla 		ctl = asc_in(port, ASC_CTL) & ~ASC_CTL_RUN;
500c4b05856SSrinivas Kandagatla 		asc_out(port, ASC_CTL, ctl);
501c4b05856SSrinivas Kandagatla 		spin_unlock_irqrestore(&port->lock, flags);
502c4b05856SSrinivas Kandagatla 		clk_disable_unprepare(ascport->clk);
503c4b05856SSrinivas Kandagatla 		break;
504c4b05856SSrinivas Kandagatla 	}
505c4b05856SSrinivas Kandagatla }
506c4b05856SSrinivas Kandagatla 
507c4b05856SSrinivas Kandagatla static void asc_set_termios(struct uart_port *port, struct ktermios *termios,
508c4b05856SSrinivas Kandagatla 			    struct ktermios *old)
509c4b05856SSrinivas Kandagatla {
510c4b05856SSrinivas Kandagatla 	struct asc_port *ascport = to_asc_port(port);
511d7356256SLee Jones 	struct device_node *np = port->dev->of_node;
512d7356256SLee Jones 	struct gpio_desc *gpiod;
513c4b05856SSrinivas Kandagatla 	unsigned int baud;
514c4b05856SSrinivas Kandagatla 	u32 ctrl_val;
515c4b05856SSrinivas Kandagatla 	tcflag_t cflag;
516c4b05856SSrinivas Kandagatla 	unsigned long flags;
517c4b05856SSrinivas Kandagatla 
518c4b05856SSrinivas Kandagatla 	/* Update termios to reflect hardware capabilities */
519c4b05856SSrinivas Kandagatla 	termios->c_cflag &= ~(CMSPAR |
520c4b05856SSrinivas Kandagatla 			 (ascport->hw_flow_control ? 0 : CRTSCTS));
521c4b05856SSrinivas Kandagatla 
522c4b05856SSrinivas Kandagatla 	port->uartclk = clk_get_rate(ascport->clk);
523c4b05856SSrinivas Kandagatla 
524c4b05856SSrinivas Kandagatla 	baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16);
525c4b05856SSrinivas Kandagatla 	cflag = termios->c_cflag;
526c4b05856SSrinivas Kandagatla 
527c4b05856SSrinivas Kandagatla 	spin_lock_irqsave(&port->lock, flags);
528c4b05856SSrinivas Kandagatla 
529c4b05856SSrinivas Kandagatla 	/* read control register */
530c4b05856SSrinivas Kandagatla 	ctrl_val = asc_in(port, ASC_CTL);
531c4b05856SSrinivas Kandagatla 
532c4b05856SSrinivas Kandagatla 	/* stop serial port and reset value */
533c4b05856SSrinivas Kandagatla 	asc_out(port, ASC_CTL, (ctrl_val & ~ASC_CTL_RUN));
534c4b05856SSrinivas Kandagatla 	ctrl_val = ASC_CTL_RXENABLE | ASC_CTL_FIFOENABLE;
535c4b05856SSrinivas Kandagatla 
536c4b05856SSrinivas Kandagatla 	/* reset fifo rx & tx */
537c4b05856SSrinivas Kandagatla 	asc_out(port, ASC_TXRESET, 1);
538c4b05856SSrinivas Kandagatla 	asc_out(port, ASC_RXRESET, 1);
539c4b05856SSrinivas Kandagatla 
540c4b05856SSrinivas Kandagatla 	/* set character length */
541c4b05856SSrinivas Kandagatla 	if ((cflag & CSIZE) == CS7) {
542c4b05856SSrinivas Kandagatla 		ctrl_val |= ASC_CTL_MODE_7BIT_PAR;
543c4b05856SSrinivas Kandagatla 	} else {
544c4b05856SSrinivas Kandagatla 		ctrl_val |= (cflag & PARENB) ?  ASC_CTL_MODE_8BIT_PAR :
545c4b05856SSrinivas Kandagatla 						ASC_CTL_MODE_8BIT;
546c4b05856SSrinivas Kandagatla 	}
547c4b05856SSrinivas Kandagatla 
548c4b05856SSrinivas Kandagatla 	/* set stop bit */
549c4b05856SSrinivas Kandagatla 	ctrl_val |= (cflag & CSTOPB) ? ASC_CTL_STOP_2BIT : ASC_CTL_STOP_1BIT;
550c4b05856SSrinivas Kandagatla 
551c4b05856SSrinivas Kandagatla 	/* odd parity */
552c4b05856SSrinivas Kandagatla 	if (cflag & PARODD)
553c4b05856SSrinivas Kandagatla 		ctrl_val |= ASC_CTL_PARITYODD;
554c4b05856SSrinivas Kandagatla 
555c4b05856SSrinivas Kandagatla 	/* hardware flow control */
556d7356256SLee Jones 	if ((cflag & CRTSCTS)) {
557c4b05856SSrinivas Kandagatla 		ctrl_val |= ASC_CTL_CTSENABLE;
558c4b05856SSrinivas Kandagatla 
559d7356256SLee Jones 		/* If flow-control selected, stop handling RTS manually */
560d7356256SLee Jones 		if (ascport->rts) {
561d7356256SLee Jones 			devm_gpiod_put(port->dev, ascport->rts);
562d7356256SLee Jones 			ascport->rts = NULL;
563d7356256SLee Jones 
564d7356256SLee Jones 			pinctrl_select_state(ascport->pinctrl,
565d7356256SLee Jones 					     ascport->states[DEFAULT]);
566d7356256SLee Jones 		}
567d7356256SLee Jones 	} else {
568d7356256SLee Jones 		/* If flow-control disabled, it's safe to handle RTS manually */
569d7356256SLee Jones 		if (!ascport->rts && ascport->states[NO_HW_FLOWCTRL]) {
570d7356256SLee Jones 			pinctrl_select_state(ascport->pinctrl,
571d7356256SLee Jones 					     ascport->states[NO_HW_FLOWCTRL]);
572d7356256SLee Jones 
5730043c1dfSLee Jones 			gpiod = devm_fwnode_get_gpiod_from_child(port->dev,
5740043c1dfSLee Jones 								 "rts",
5750043c1dfSLee Jones 								 &np->fwnode,
5760043c1dfSLee Jones 								 GPIOD_OUT_LOW,
5770043c1dfSLee Jones 								 np->name);
5780043c1dfSLee Jones 			if (!IS_ERR(gpiod))
579d7356256SLee Jones 				ascport->rts = gpiod;
580d7356256SLee Jones 		}
581d7356256SLee Jones 	}
582d7356256SLee Jones 
583c4b05856SSrinivas Kandagatla 	if ((baud < 19200) && !ascport->force_m1) {
584c4b05856SSrinivas Kandagatla 		asc_out(port, ASC_BAUDRATE, (port->uartclk / (16 * baud)));
585c4b05856SSrinivas Kandagatla 	} else {
586c4b05856SSrinivas Kandagatla 		/*
587c4b05856SSrinivas Kandagatla 		 * MODE 1: recommended for high bit rates (above 19.2K)
588c4b05856SSrinivas Kandagatla 		 *
589c4b05856SSrinivas Kandagatla 		 *                   baudrate * 16 * 2^16
590c4b05856SSrinivas Kandagatla 		 * ASCBaudRate =   ------------------------
591c4b05856SSrinivas Kandagatla 		 *                          inputclock
592c4b05856SSrinivas Kandagatla 		 *
5931d6ba284SMaxime COQUELIN 		 * To keep maths inside 64bits, we divide inputclock by 16.
594c4b05856SSrinivas Kandagatla 		 */
5951d6ba284SMaxime COQUELIN 		u64 dividend = (u64)baud * (1 << 16);
5961d6ba284SMaxime COQUELIN 
5971d6ba284SMaxime COQUELIN 		do_div(dividend, port->uartclk / 16);
5981d6ba284SMaxime COQUELIN 		asc_out(port, ASC_BAUDRATE, dividend);
599c4b05856SSrinivas Kandagatla 		ctrl_val |= ASC_CTL_BAUDMODE;
600c4b05856SSrinivas Kandagatla 	}
601c4b05856SSrinivas Kandagatla 
602c4b05856SSrinivas Kandagatla 	uart_update_timeout(port, cflag, baud);
603c4b05856SSrinivas Kandagatla 
604c4b05856SSrinivas Kandagatla 	ascport->port.read_status_mask = ASC_RXBUF_DUMMY_OE;
605c4b05856SSrinivas Kandagatla 	if (termios->c_iflag & INPCK)
606c4b05856SSrinivas Kandagatla 		ascport->port.read_status_mask |= ASC_RXBUF_FE | ASC_RXBUF_PE;
607ef8b9ddcSPeter Hurley 	if (termios->c_iflag & (IGNBRK | BRKINT | PARMRK))
608c4b05856SSrinivas Kandagatla 		ascport->port.read_status_mask |= ASC_RXBUF_DUMMY_BE;
609c4b05856SSrinivas Kandagatla 
610c4b05856SSrinivas Kandagatla 	/*
611c4b05856SSrinivas Kandagatla 	 * Characters to ignore
612c4b05856SSrinivas Kandagatla 	 */
613c4b05856SSrinivas Kandagatla 	ascport->port.ignore_status_mask = 0;
614c4b05856SSrinivas Kandagatla 	if (termios->c_iflag & IGNPAR)
615c4b05856SSrinivas Kandagatla 		ascport->port.ignore_status_mask |= ASC_RXBUF_FE | ASC_RXBUF_PE;
616c4b05856SSrinivas Kandagatla 	if (termios->c_iflag & IGNBRK) {
617c4b05856SSrinivas Kandagatla 		ascport->port.ignore_status_mask |= ASC_RXBUF_DUMMY_BE;
618c4b05856SSrinivas Kandagatla 		/*
619c4b05856SSrinivas Kandagatla 		 * If we're ignoring parity and break indicators,
620c4b05856SSrinivas Kandagatla 		 * ignore overruns too (for real raw support).
621c4b05856SSrinivas Kandagatla 		 */
622c4b05856SSrinivas Kandagatla 		if (termios->c_iflag & IGNPAR)
623c4b05856SSrinivas Kandagatla 			ascport->port.ignore_status_mask |= ASC_RXBUF_DUMMY_OE;
624c4b05856SSrinivas Kandagatla 	}
625c4b05856SSrinivas Kandagatla 
626c4b05856SSrinivas Kandagatla 	/*
627c4b05856SSrinivas Kandagatla 	 * Ignore all characters if CREAD is not set.
628c4b05856SSrinivas Kandagatla 	 */
629c4b05856SSrinivas Kandagatla 	if (!(termios->c_cflag & CREAD))
630c4b05856SSrinivas Kandagatla 		ascport->port.ignore_status_mask |= ASC_RXBUF_DUMMY_RX;
631c4b05856SSrinivas Kandagatla 
632c4b05856SSrinivas Kandagatla 	/* Set the timeout */
633c4b05856SSrinivas Kandagatla 	asc_out(port, ASC_TIMEOUT, 20);
634c4b05856SSrinivas Kandagatla 
635c4b05856SSrinivas Kandagatla 	/* write final value and enable port */
636c4b05856SSrinivas Kandagatla 	asc_out(port, ASC_CTL, (ctrl_val | ASC_CTL_RUN));
637c4b05856SSrinivas Kandagatla 
638c4b05856SSrinivas Kandagatla 	spin_unlock_irqrestore(&port->lock, flags);
639c4b05856SSrinivas Kandagatla }
640c4b05856SSrinivas Kandagatla 
641c4b05856SSrinivas Kandagatla static const char *asc_type(struct uart_port *port)
642c4b05856SSrinivas Kandagatla {
643c4b05856SSrinivas Kandagatla 	return (port->type == PORT_ASC) ? DRIVER_NAME : NULL;
644c4b05856SSrinivas Kandagatla }
645c4b05856SSrinivas Kandagatla 
646c4b05856SSrinivas Kandagatla static void asc_release_port(struct uart_port *port)
647c4b05856SSrinivas Kandagatla {
648c4b05856SSrinivas Kandagatla }
649c4b05856SSrinivas Kandagatla 
650c4b05856SSrinivas Kandagatla static int asc_request_port(struct uart_port *port)
651c4b05856SSrinivas Kandagatla {
652c4b05856SSrinivas Kandagatla 	return 0;
653c4b05856SSrinivas Kandagatla }
654c4b05856SSrinivas Kandagatla 
655c4b05856SSrinivas Kandagatla /*
656c4b05856SSrinivas Kandagatla  * Called when the port is opened, and UPF_BOOT_AUTOCONF flag is set
657c4b05856SSrinivas Kandagatla  * Set type field if successful
658c4b05856SSrinivas Kandagatla  */
659c4b05856SSrinivas Kandagatla static void asc_config_port(struct uart_port *port, int flags)
660c4b05856SSrinivas Kandagatla {
661c4b05856SSrinivas Kandagatla 	if ((flags & UART_CONFIG_TYPE))
662c4b05856SSrinivas Kandagatla 		port->type = PORT_ASC;
663c4b05856SSrinivas Kandagatla }
664c4b05856SSrinivas Kandagatla 
665c4b05856SSrinivas Kandagatla static int
666c4b05856SSrinivas Kandagatla asc_verify_port(struct uart_port *port, struct serial_struct *ser)
667c4b05856SSrinivas Kandagatla {
668c4b05856SSrinivas Kandagatla 	/* No user changeable parameters */
669c4b05856SSrinivas Kandagatla 	return -EINVAL;
670c4b05856SSrinivas Kandagatla }
671c4b05856SSrinivas Kandagatla 
672c4b05856SSrinivas Kandagatla #ifdef CONFIG_CONSOLE_POLL
673c4b05856SSrinivas Kandagatla /*
674c4b05856SSrinivas Kandagatla  * Console polling routines for writing and reading from the uart while
675c4b05856SSrinivas Kandagatla  * in an interrupt or debug context (i.e. kgdb).
676c4b05856SSrinivas Kandagatla  */
677c4b05856SSrinivas Kandagatla 
678c4b05856SSrinivas Kandagatla static int asc_get_poll_char(struct uart_port *port)
679c4b05856SSrinivas Kandagatla {
680c4b05856SSrinivas Kandagatla 	if (!(asc_in(port, ASC_STA) & ASC_STA_RBF))
681c4b05856SSrinivas Kandagatla 		return NO_POLL_CHAR;
682c4b05856SSrinivas Kandagatla 
683c4b05856SSrinivas Kandagatla 	return asc_in(port, ASC_RXBUF);
684c4b05856SSrinivas Kandagatla }
685c4b05856SSrinivas Kandagatla 
686c4b05856SSrinivas Kandagatla static void asc_put_poll_char(struct uart_port *port, unsigned char c)
687c4b05856SSrinivas Kandagatla {
6881ffcd67dSDaniel Thompson 	while (!asc_txfifo_is_half_empty(port))
689c4b05856SSrinivas Kandagatla 		cpu_relax();
690c4b05856SSrinivas Kandagatla 	asc_out(port, ASC_TXBUF, c);
691c4b05856SSrinivas Kandagatla }
692c4b05856SSrinivas Kandagatla 
693c4b05856SSrinivas Kandagatla #endif /* CONFIG_CONSOLE_POLL */
694c4b05856SSrinivas Kandagatla 
695c4b05856SSrinivas Kandagatla /*---------------------------------------------------------------------*/
696c4b05856SSrinivas Kandagatla 
697eeb8bc1aSJulia Lawall static const struct uart_ops asc_uart_ops = {
698c4b05856SSrinivas Kandagatla 	.tx_empty	= asc_tx_empty,
699c4b05856SSrinivas Kandagatla 	.set_mctrl	= asc_set_mctrl,
700c4b05856SSrinivas Kandagatla 	.get_mctrl	= asc_get_mctrl,
701c4b05856SSrinivas Kandagatla 	.start_tx	= asc_start_tx,
702c4b05856SSrinivas Kandagatla 	.stop_tx	= asc_stop_tx,
703c4b05856SSrinivas Kandagatla 	.stop_rx	= asc_stop_rx,
704c4b05856SSrinivas Kandagatla 	.break_ctl	= asc_break_ctl,
705c4b05856SSrinivas Kandagatla 	.startup	= asc_startup,
706c4b05856SSrinivas Kandagatla 	.shutdown	= asc_shutdown,
707c4b05856SSrinivas Kandagatla 	.set_termios	= asc_set_termios,
708c4b05856SSrinivas Kandagatla 	.type		= asc_type,
709c4b05856SSrinivas Kandagatla 	.release_port	= asc_release_port,
710c4b05856SSrinivas Kandagatla 	.request_port	= asc_request_port,
711c4b05856SSrinivas Kandagatla 	.config_port	= asc_config_port,
712c4b05856SSrinivas Kandagatla 	.verify_port	= asc_verify_port,
713c4b05856SSrinivas Kandagatla 	.pm		= asc_pm,
714c4b05856SSrinivas Kandagatla #ifdef CONFIG_CONSOLE_POLL
715c4b05856SSrinivas Kandagatla 	.poll_get_char = asc_get_poll_char,
716c4b05856SSrinivas Kandagatla 	.poll_put_char = asc_put_poll_char,
717c4b05856SSrinivas Kandagatla #endif /* CONFIG_CONSOLE_POLL */
718c4b05856SSrinivas Kandagatla };
719c4b05856SSrinivas Kandagatla 
720c4b05856SSrinivas Kandagatla static int asc_init_port(struct asc_port *ascport,
721c4b05856SSrinivas Kandagatla 			  struct platform_device *pdev)
722c4b05856SSrinivas Kandagatla {
723c4b05856SSrinivas Kandagatla 	struct uart_port *port = &ascport->port;
7243abeff77SJulia Lawall 	struct resource *res;
7256929cb00SLee Jones 	int ret;
726c4b05856SSrinivas Kandagatla 
727c4b05856SSrinivas Kandagatla 	port->iotype	= UPIO_MEM;
728c4b05856SSrinivas Kandagatla 	port->flags	= UPF_BOOT_AUTOCONF;
729c4b05856SSrinivas Kandagatla 	port->ops	= &asc_uart_ops;
730c4b05856SSrinivas Kandagatla 	port->fifosize	= ASC_FIFO_SIZE;
731c4b05856SSrinivas Kandagatla 	port->dev	= &pdev->dev;
732c4b05856SSrinivas Kandagatla 	port->irq	= platform_get_irq(pdev, 0);
733c4b05856SSrinivas Kandagatla 
7343abeff77SJulia Lawall 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
7353abeff77SJulia Lawall 	port->membase = devm_ioremap_resource(&pdev->dev, res);
7363abeff77SJulia Lawall 	if (IS_ERR(port->membase))
7373abeff77SJulia Lawall 		return PTR_ERR(port->membase);
7383abeff77SJulia Lawall 	port->mapbase = res->start;
739c4b05856SSrinivas Kandagatla 
740c4b05856SSrinivas Kandagatla 	spin_lock_init(&port->lock);
741c4b05856SSrinivas Kandagatla 
742c4b05856SSrinivas Kandagatla 	ascport->clk = devm_clk_get(&pdev->dev, NULL);
743c4b05856SSrinivas Kandagatla 
744c4b05856SSrinivas Kandagatla 	if (WARN_ON(IS_ERR(ascport->clk)))
745c4b05856SSrinivas Kandagatla 		return -EINVAL;
746c4b05856SSrinivas Kandagatla 	/* ensure that clk rate is correct by enabling the clk */
747c4b05856SSrinivas Kandagatla 	clk_prepare_enable(ascport->clk);
748c4b05856SSrinivas Kandagatla 	ascport->port.uartclk = clk_get_rate(ascport->clk);
749c4b05856SSrinivas Kandagatla 	WARN_ON(ascport->port.uartclk == 0);
750c4b05856SSrinivas Kandagatla 	clk_disable_unprepare(ascport->clk);
751c4b05856SSrinivas Kandagatla 
7526929cb00SLee Jones 	ascport->pinctrl = devm_pinctrl_get(&pdev->dev);
7536929cb00SLee Jones 	if (IS_ERR(ascport->pinctrl)) {
7546929cb00SLee Jones 		ret = PTR_ERR(ascport->pinctrl);
7556929cb00SLee Jones 		dev_err(&pdev->dev, "Failed to get Pinctrl: %d\n", ret);
7562b01bfaeSDan Carpenter 		return ret;
7576929cb00SLee Jones 	}
7586929cb00SLee Jones 
7596929cb00SLee Jones 	ascport->states[DEFAULT] =
7606929cb00SLee Jones 		pinctrl_lookup_state(ascport->pinctrl, "default");
7616929cb00SLee Jones 	if (IS_ERR(ascport->states[DEFAULT])) {
7626929cb00SLee Jones 		ret = PTR_ERR(ascport->states[DEFAULT]);
7636929cb00SLee Jones 		dev_err(&pdev->dev,
7646929cb00SLee Jones 			"Failed to look up Pinctrl state 'default': %d\n", ret);
7656929cb00SLee Jones 		return ret;
7666929cb00SLee Jones 	}
7676929cb00SLee Jones 
7686929cb00SLee Jones 	/* "no-hw-flowctrl" state is optional */
7696929cb00SLee Jones 	ascport->states[NO_HW_FLOWCTRL] =
7706929cb00SLee Jones 		pinctrl_lookup_state(ascport->pinctrl, "no-hw-flowctrl");
7716929cb00SLee Jones 	if (IS_ERR(ascport->states[NO_HW_FLOWCTRL]))
7726929cb00SLee Jones 		ascport->states[NO_HW_FLOWCTRL] = NULL;
7736929cb00SLee Jones 
774c4b05856SSrinivas Kandagatla 	return 0;
775c4b05856SSrinivas Kandagatla }
776c4b05856SSrinivas Kandagatla 
777c4b05856SSrinivas Kandagatla static struct asc_port *asc_of_get_asc_port(struct platform_device *pdev)
778c4b05856SSrinivas Kandagatla {
779c4b05856SSrinivas Kandagatla 	struct device_node *np = pdev->dev.of_node;
780c4b05856SSrinivas Kandagatla 	int id;
781c4b05856SSrinivas Kandagatla 
782c4b05856SSrinivas Kandagatla 	if (!np)
783c4b05856SSrinivas Kandagatla 		return NULL;
784c4b05856SSrinivas Kandagatla 
785dfd9190cSPatrice Chotard 	id = of_alias_get_id(np, "serial");
786dfd9190cSPatrice Chotard 	if (id < 0)
787c4b05856SSrinivas Kandagatla 		id = of_alias_get_id(np, ASC_SERIAL_NAME);
788c4b05856SSrinivas Kandagatla 
789c4b05856SSrinivas Kandagatla 	if (id < 0)
790c4b05856SSrinivas Kandagatla 		id = 0;
791c4b05856SSrinivas Kandagatla 
792c4b05856SSrinivas Kandagatla 	if (WARN_ON(id >= ASC_MAX_PORTS))
793c4b05856SSrinivas Kandagatla 		return NULL;
794c4b05856SSrinivas Kandagatla 
795c4b05856SSrinivas Kandagatla 	asc_ports[id].hw_flow_control = of_property_read_bool(np,
796233680a2SLee Jones 							"uart-has-rtscts");
797c4b05856SSrinivas Kandagatla 	asc_ports[id].force_m1 =  of_property_read_bool(np, "st,force_m1");
798c4b05856SSrinivas Kandagatla 	asc_ports[id].port.line = id;
799a4f6072fSLee Jones 	asc_ports[id].rts = NULL;
800a4f6072fSLee Jones 
801c4b05856SSrinivas Kandagatla 	return &asc_ports[id];
802c4b05856SSrinivas Kandagatla }
803c4b05856SSrinivas Kandagatla 
804a4f2dc9eSSrinivas Kandagatla #ifdef CONFIG_OF
805ed0bb232SFabian Frederick static const struct of_device_id asc_match[] = {
806c4b05856SSrinivas Kandagatla 	{ .compatible = "st,asc", },
807c4b05856SSrinivas Kandagatla 	{},
808c4b05856SSrinivas Kandagatla };
809c4b05856SSrinivas Kandagatla 
810c4b05856SSrinivas Kandagatla MODULE_DEVICE_TABLE(of, asc_match);
811a4f2dc9eSSrinivas Kandagatla #endif
812c4b05856SSrinivas Kandagatla 
813c4b05856SSrinivas Kandagatla static int asc_serial_probe(struct platform_device *pdev)
814c4b05856SSrinivas Kandagatla {
815c4b05856SSrinivas Kandagatla 	int ret;
816c4b05856SSrinivas Kandagatla 	struct asc_port *ascport;
817c4b05856SSrinivas Kandagatla 
818c4b05856SSrinivas Kandagatla 	ascport = asc_of_get_asc_port(pdev);
819c4b05856SSrinivas Kandagatla 	if (!ascport)
820c4b05856SSrinivas Kandagatla 		return -ENODEV;
821c4b05856SSrinivas Kandagatla 
822c4b05856SSrinivas Kandagatla 	ret = asc_init_port(ascport, pdev);
823c4b05856SSrinivas Kandagatla 	if (ret)
824c4b05856SSrinivas Kandagatla 		return ret;
825c4b05856SSrinivas Kandagatla 
826c4b05856SSrinivas Kandagatla 	ret = uart_add_one_port(&asc_uart_driver, &ascport->port);
827c4b05856SSrinivas Kandagatla 	if (ret)
828c4b05856SSrinivas Kandagatla 		return ret;
829c4b05856SSrinivas Kandagatla 
830c4b05856SSrinivas Kandagatla 	platform_set_drvdata(pdev, &ascport->port);
831c4b05856SSrinivas Kandagatla 
832c4b05856SSrinivas Kandagatla 	return 0;
833c4b05856SSrinivas Kandagatla }
834c4b05856SSrinivas Kandagatla 
835c4b05856SSrinivas Kandagatla static int asc_serial_remove(struct platform_device *pdev)
836c4b05856SSrinivas Kandagatla {
837c4b05856SSrinivas Kandagatla 	struct uart_port *port = platform_get_drvdata(pdev);
838c4b05856SSrinivas Kandagatla 
839c4b05856SSrinivas Kandagatla 	return uart_remove_one_port(&asc_uart_driver, port);
840c4b05856SSrinivas Kandagatla }
841c4b05856SSrinivas Kandagatla 
842c4b05856SSrinivas Kandagatla #ifdef CONFIG_PM_SLEEP
843c4b05856SSrinivas Kandagatla static int asc_serial_suspend(struct device *dev)
844c4b05856SSrinivas Kandagatla {
845*a406c4b8SWolfram Sang 	struct uart_port *port = dev_get_drvdata(dev);
846c4b05856SSrinivas Kandagatla 
847c4b05856SSrinivas Kandagatla 	return uart_suspend_port(&asc_uart_driver, port);
848c4b05856SSrinivas Kandagatla }
849c4b05856SSrinivas Kandagatla 
850c4b05856SSrinivas Kandagatla static int asc_serial_resume(struct device *dev)
851c4b05856SSrinivas Kandagatla {
852*a406c4b8SWolfram Sang 	struct uart_port *port = dev_get_drvdata(dev);
853c4b05856SSrinivas Kandagatla 
854c4b05856SSrinivas Kandagatla 	return uart_resume_port(&asc_uart_driver, port);
855c4b05856SSrinivas Kandagatla }
856c4b05856SSrinivas Kandagatla 
857c4b05856SSrinivas Kandagatla #endif /* CONFIG_PM_SLEEP */
858c4b05856SSrinivas Kandagatla 
859c4b05856SSrinivas Kandagatla /*----------------------------------------------------------------------*/
860c4b05856SSrinivas Kandagatla 
861c4b05856SSrinivas Kandagatla #ifdef CONFIG_SERIAL_ST_ASC_CONSOLE
862c4b05856SSrinivas Kandagatla static void asc_console_putchar(struct uart_port *port, int ch)
863c4b05856SSrinivas Kandagatla {
864c4b05856SSrinivas Kandagatla 	unsigned int timeout = 1000000;
865c4b05856SSrinivas Kandagatla 
866c4b05856SSrinivas Kandagatla 	/* Wait for upto 1 second in case flow control is stopping us. */
8671ffcd67dSDaniel Thompson 	while (--timeout && !asc_txfifo_is_half_empty(port))
868c4b05856SSrinivas Kandagatla 		udelay(1);
869c4b05856SSrinivas Kandagatla 
870c4b05856SSrinivas Kandagatla 	asc_out(port, ASC_TXBUF, ch);
871c4b05856SSrinivas Kandagatla }
872c4b05856SSrinivas Kandagatla 
873c4b05856SSrinivas Kandagatla /*
874c4b05856SSrinivas Kandagatla  *  Print a string to the serial port trying not to disturb
875c4b05856SSrinivas Kandagatla  *  any possible real use of the port...
876c4b05856SSrinivas Kandagatla  */
877c4b05856SSrinivas Kandagatla 
878c4b05856SSrinivas Kandagatla static void asc_console_write(struct console *co, const char *s, unsigned count)
879c4b05856SSrinivas Kandagatla {
880c4b05856SSrinivas Kandagatla 	struct uart_port *port = &asc_ports[co->index].port;
881c4b05856SSrinivas Kandagatla 	unsigned long flags;
882c4b05856SSrinivas Kandagatla 	unsigned long timeout = 1000000;
883c4b05856SSrinivas Kandagatla 	int locked = 1;
884c4b05856SSrinivas Kandagatla 	u32 intenable;
885c4b05856SSrinivas Kandagatla 
886c4b05856SSrinivas Kandagatla 	if (port->sysrq)
887c4b05856SSrinivas Kandagatla 		locked = 0; /* asc_interrupt has already claimed the lock */
888c4b05856SSrinivas Kandagatla 	else if (oops_in_progress)
889ef49ffd8SLionel Debieve 		locked = spin_trylock_irqsave(&port->lock, flags);
890c4b05856SSrinivas Kandagatla 	else
891ef49ffd8SLionel Debieve 		spin_lock_irqsave(&port->lock, flags);
892c4b05856SSrinivas Kandagatla 
893c4b05856SSrinivas Kandagatla 	/*
894c4b05856SSrinivas Kandagatla 	 * Disable interrupts so we don't get the IRQ line bouncing
895c4b05856SSrinivas Kandagatla 	 * up and down while interrupts are disabled.
896c4b05856SSrinivas Kandagatla 	 */
897c4b05856SSrinivas Kandagatla 	intenable = asc_in(port, ASC_INTEN);
898c4b05856SSrinivas Kandagatla 	asc_out(port, ASC_INTEN, 0);
899c4b05856SSrinivas Kandagatla 	(void)asc_in(port, ASC_INTEN);	/* Defeat bus write posting */
900c4b05856SSrinivas Kandagatla 
901c4b05856SSrinivas Kandagatla 	uart_console_write(port, s, count, asc_console_putchar);
902c4b05856SSrinivas Kandagatla 
903c4b05856SSrinivas Kandagatla 	while (--timeout && !asc_txfifo_is_empty(port))
904c4b05856SSrinivas Kandagatla 		udelay(1);
905c4b05856SSrinivas Kandagatla 
906c4b05856SSrinivas Kandagatla 	asc_out(port, ASC_INTEN, intenable);
907c4b05856SSrinivas Kandagatla 
908c4b05856SSrinivas Kandagatla 	if (locked)
909ef49ffd8SLionel Debieve 		spin_unlock_irqrestore(&port->lock, flags);
910c4b05856SSrinivas Kandagatla }
911c4b05856SSrinivas Kandagatla 
912c4b05856SSrinivas Kandagatla static int asc_console_setup(struct console *co, char *options)
913c4b05856SSrinivas Kandagatla {
914c4b05856SSrinivas Kandagatla 	struct asc_port *ascport;
915b5090cb4SLee Jones 	int baud = 115200;
916c4b05856SSrinivas Kandagatla 	int bits = 8;
917c4b05856SSrinivas Kandagatla 	int parity = 'n';
918c4b05856SSrinivas Kandagatla 	int flow = 'n';
919c4b05856SSrinivas Kandagatla 
920c4b05856SSrinivas Kandagatla 	if (co->index >= ASC_MAX_PORTS)
921c4b05856SSrinivas Kandagatla 		return -ENODEV;
922c4b05856SSrinivas Kandagatla 
923c4b05856SSrinivas Kandagatla 	ascport = &asc_ports[co->index];
924c4b05856SSrinivas Kandagatla 
925c4b05856SSrinivas Kandagatla 	/*
926c4b05856SSrinivas Kandagatla 	 * This driver does not support early console initialization
927c4b05856SSrinivas Kandagatla 	 * (use ARM early printk support instead), so we only expect
928c4b05856SSrinivas Kandagatla 	 * this to be called during the uart port registration when the
929c4b05856SSrinivas Kandagatla 	 * driver gets probed and the port should be mapped at that point.
930c4b05856SSrinivas Kandagatla 	 */
9315b4e79aeSMaxime COQUELIN 	if (ascport->port.mapbase == 0 || ascport->port.membase == NULL)
9325b4e79aeSMaxime COQUELIN 		return -ENXIO;
933c4b05856SSrinivas Kandagatla 
934c4b05856SSrinivas Kandagatla 	if (options)
935c4b05856SSrinivas Kandagatla 		uart_parse_options(options, &baud, &parity, &bits, &flow);
936c4b05856SSrinivas Kandagatla 
937c4b05856SSrinivas Kandagatla 	return uart_set_options(&ascport->port, co, baud, parity, bits, flow);
938c4b05856SSrinivas Kandagatla }
939c4b05856SSrinivas Kandagatla 
940c4b05856SSrinivas Kandagatla static struct console asc_console = {
941c4b05856SSrinivas Kandagatla 	.name		= ASC_SERIAL_NAME,
942c4b05856SSrinivas Kandagatla 	.device		= uart_console_device,
943c4b05856SSrinivas Kandagatla 	.write		= asc_console_write,
944c4b05856SSrinivas Kandagatla 	.setup		= asc_console_setup,
945c4b05856SSrinivas Kandagatla 	.flags		= CON_PRINTBUFFER,
946c4b05856SSrinivas Kandagatla 	.index		= -1,
947c4b05856SSrinivas Kandagatla 	.data		= &asc_uart_driver,
948c4b05856SSrinivas Kandagatla };
949c4b05856SSrinivas Kandagatla 
950c4b05856SSrinivas Kandagatla #define ASC_SERIAL_CONSOLE (&asc_console)
951c4b05856SSrinivas Kandagatla 
952c4b05856SSrinivas Kandagatla #else
953c4b05856SSrinivas Kandagatla #define ASC_SERIAL_CONSOLE NULL
954c4b05856SSrinivas Kandagatla #endif /* CONFIG_SERIAL_ST_ASC_CONSOLE */
955c4b05856SSrinivas Kandagatla 
956c4b05856SSrinivas Kandagatla static struct uart_driver asc_uart_driver = {
957c4b05856SSrinivas Kandagatla 	.owner		= THIS_MODULE,
958c4b05856SSrinivas Kandagatla 	.driver_name	= DRIVER_NAME,
959c4b05856SSrinivas Kandagatla 	.dev_name	= ASC_SERIAL_NAME,
960c4b05856SSrinivas Kandagatla 	.major		= 0,
961c4b05856SSrinivas Kandagatla 	.minor		= 0,
962c4b05856SSrinivas Kandagatla 	.nr		= ASC_MAX_PORTS,
963c4b05856SSrinivas Kandagatla 	.cons		= ASC_SERIAL_CONSOLE,
964c4b05856SSrinivas Kandagatla };
965c4b05856SSrinivas Kandagatla 
966c4b05856SSrinivas Kandagatla static const struct dev_pm_ops asc_serial_pm_ops = {
967c4b05856SSrinivas Kandagatla 	SET_SYSTEM_SLEEP_PM_OPS(asc_serial_suspend, asc_serial_resume)
968c4b05856SSrinivas Kandagatla };
969c4b05856SSrinivas Kandagatla 
970c4b05856SSrinivas Kandagatla static struct platform_driver asc_serial_driver = {
971c4b05856SSrinivas Kandagatla 	.probe		= asc_serial_probe,
972c4b05856SSrinivas Kandagatla 	.remove		= asc_serial_remove,
973c4b05856SSrinivas Kandagatla 	.driver	= {
974c4b05856SSrinivas Kandagatla 		.name	= DRIVER_NAME,
975c4b05856SSrinivas Kandagatla 		.pm	= &asc_serial_pm_ops,
976c4b05856SSrinivas Kandagatla 		.of_match_table = of_match_ptr(asc_match),
977c4b05856SSrinivas Kandagatla 	},
978c4b05856SSrinivas Kandagatla };
979c4b05856SSrinivas Kandagatla 
980c4b05856SSrinivas Kandagatla static int __init asc_init(void)
981c4b05856SSrinivas Kandagatla {
982c4b05856SSrinivas Kandagatla 	int ret;
98306324664SKees Cook 	static const char banner[] __initconst =
984c4b05856SSrinivas Kandagatla 		KERN_INFO "STMicroelectronics ASC driver initialized\n";
985c4b05856SSrinivas Kandagatla 
986c4b05856SSrinivas Kandagatla 	printk(banner);
987c4b05856SSrinivas Kandagatla 
988c4b05856SSrinivas Kandagatla 	ret = uart_register_driver(&asc_uart_driver);
989c4b05856SSrinivas Kandagatla 	if (ret)
990c4b05856SSrinivas Kandagatla 		return ret;
991c4b05856SSrinivas Kandagatla 
992c4b05856SSrinivas Kandagatla 	ret = platform_driver_register(&asc_serial_driver);
993c4b05856SSrinivas Kandagatla 	if (ret)
994c4b05856SSrinivas Kandagatla 		uart_unregister_driver(&asc_uart_driver);
995c4b05856SSrinivas Kandagatla 
996c4b05856SSrinivas Kandagatla 	return ret;
997c4b05856SSrinivas Kandagatla }
998c4b05856SSrinivas Kandagatla 
999c4b05856SSrinivas Kandagatla static void __exit asc_exit(void)
1000c4b05856SSrinivas Kandagatla {
1001c4b05856SSrinivas Kandagatla 	platform_driver_unregister(&asc_serial_driver);
1002c4b05856SSrinivas Kandagatla 	uart_unregister_driver(&asc_uart_driver);
1003c4b05856SSrinivas Kandagatla }
1004c4b05856SSrinivas Kandagatla 
1005c4b05856SSrinivas Kandagatla module_init(asc_init);
1006c4b05856SSrinivas Kandagatla module_exit(asc_exit);
1007c4b05856SSrinivas Kandagatla 
1008c4b05856SSrinivas Kandagatla MODULE_ALIAS("platform:" DRIVER_NAME);
1009c4b05856SSrinivas Kandagatla MODULE_AUTHOR("STMicroelectronics (R&D) Limited");
1010c4b05856SSrinivas Kandagatla MODULE_DESCRIPTION("STMicroelectronics ASC serial port driver");
1011c4b05856SSrinivas Kandagatla MODULE_LICENSE("GPL");
1012