1e3b3d0f5SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
2ab4382d2SGreg Kroah-Hartman /*
3ab4382d2SGreg Kroah-Hartman * Driver for the serial port on the 21285 StrongArm-110 core logic chip.
4ab4382d2SGreg Kroah-Hartman *
5ab4382d2SGreg Kroah-Hartman * Based on drivers/char/serial.c
6ab4382d2SGreg Kroah-Hartman */
7ab4382d2SGreg Kroah-Hartman #include <linux/module.h>
8ab4382d2SGreg Kroah-Hartman #include <linux/tty.h>
9ab4382d2SGreg Kroah-Hartman #include <linux/ioport.h>
10ab4382d2SGreg Kroah-Hartman #include <linux/init.h>
11ab4382d2SGreg Kroah-Hartman #include <linux/console.h>
12ab4382d2SGreg Kroah-Hartman #include <linux/device.h>
13ab4382d2SGreg Kroah-Hartman #include <linux/tty_flip.h>
14ab4382d2SGreg Kroah-Hartman #include <linux/serial_core.h>
15ab4382d2SGreg Kroah-Hartman #include <linux/serial.h>
16ab4382d2SGreg Kroah-Hartman #include <linux/io.h>
17ab4382d2SGreg Kroah-Hartman
18ab4382d2SGreg Kroah-Hartman #include <asm/irq.h>
19ab4382d2SGreg Kroah-Hartman #include <asm/mach-types.h>
209f97da78SDavid Howells #include <asm/system_info.h>
21ab4382d2SGreg Kroah-Hartman #include <asm/hardware/dec21285.h>
22ab4382d2SGreg Kroah-Hartman #include <mach/hardware.h>
23ab4382d2SGreg Kroah-Hartman
24ab4382d2SGreg Kroah-Hartman #define BAUD_BASE (mem_fclk_21285/64)
25ab4382d2SGreg Kroah-Hartman
26ab4382d2SGreg Kroah-Hartman #define SERIAL_21285_NAME "ttyFB"
27ab4382d2SGreg Kroah-Hartman #define SERIAL_21285_MAJOR 204
28ab4382d2SGreg Kroah-Hartman #define SERIAL_21285_MINOR 4
29ab4382d2SGreg Kroah-Hartman
30ab4382d2SGreg Kroah-Hartman #define RXSTAT_DUMMY_READ 0x80000000
31ab4382d2SGreg Kroah-Hartman #define RXSTAT_FRAME (1 << 0)
32ab4382d2SGreg Kroah-Hartman #define RXSTAT_PARITY (1 << 1)
33ab4382d2SGreg Kroah-Hartman #define RXSTAT_OVERRUN (1 << 2)
34ab4382d2SGreg Kroah-Hartman #define RXSTAT_ANYERR (RXSTAT_FRAME|RXSTAT_PARITY|RXSTAT_OVERRUN)
35ab4382d2SGreg Kroah-Hartman
36ab4382d2SGreg Kroah-Hartman #define H_UBRLCR_BREAK (1 << 0)
37ab4382d2SGreg Kroah-Hartman #define H_UBRLCR_PARENB (1 << 1)
38ab4382d2SGreg Kroah-Hartman #define H_UBRLCR_PAREVN (1 << 2)
39ab4382d2SGreg Kroah-Hartman #define H_UBRLCR_STOPB (1 << 3)
40ab4382d2SGreg Kroah-Hartman #define H_UBRLCR_FIFO (1 << 4)
41ab4382d2SGreg Kroah-Hartman
42ab4382d2SGreg Kroah-Hartman static const char serial21285_name[] = "Footbridge UART";
43ab4382d2SGreg Kroah-Hartman
44293f8995SGreg Kroah-Hartman /*
45293f8995SGreg Kroah-Hartman * We only need 2 bits of data, so instead of creating a whole structure for
46293f8995SGreg Kroah-Hartman * this, use bits of the private_data pointer of the uart port structure.
47293f8995SGreg Kroah-Hartman */
48293f8995SGreg Kroah-Hartman #define tx_enabled_bit 0
49293f8995SGreg Kroah-Hartman #define rx_enabled_bit 1
50293f8995SGreg Kroah-Hartman
is_enabled(struct uart_port * port,int bit)51293f8995SGreg Kroah-Hartman static bool is_enabled(struct uart_port *port, int bit)
52293f8995SGreg Kroah-Hartman {
5382776f6cSRussell King unsigned long *private_data = (unsigned long *)&port->private_data;
54293f8995SGreg Kroah-Hartman
5582776f6cSRussell King if (test_bit(bit, private_data))
56293f8995SGreg Kroah-Hartman return true;
57293f8995SGreg Kroah-Hartman return false;
58293f8995SGreg Kroah-Hartman }
59293f8995SGreg Kroah-Hartman
enable(struct uart_port * port,int bit)60293f8995SGreg Kroah-Hartman static void enable(struct uart_port *port, int bit)
61293f8995SGreg Kroah-Hartman {
6282776f6cSRussell King unsigned long *private_data = (unsigned long *)&port->private_data;
63293f8995SGreg Kroah-Hartman
6482776f6cSRussell King set_bit(bit, private_data);
65293f8995SGreg Kroah-Hartman }
66293f8995SGreg Kroah-Hartman
disable(struct uart_port * port,int bit)67293f8995SGreg Kroah-Hartman static void disable(struct uart_port *port, int bit)
68293f8995SGreg Kroah-Hartman {
6982776f6cSRussell King unsigned long *private_data = (unsigned long *)&port->private_data;
70293f8995SGreg Kroah-Hartman
7182776f6cSRussell King clear_bit(bit, private_data);
72293f8995SGreg Kroah-Hartman }
73293f8995SGreg Kroah-Hartman
74293f8995SGreg Kroah-Hartman #define is_tx_enabled(port) is_enabled(port, tx_enabled_bit)
75293f8995SGreg Kroah-Hartman #define tx_enable(port) enable(port, tx_enabled_bit)
76293f8995SGreg Kroah-Hartman #define tx_disable(port) disable(port, tx_enabled_bit)
77293f8995SGreg Kroah-Hartman
78293f8995SGreg Kroah-Hartman #define is_rx_enabled(port) is_enabled(port, rx_enabled_bit)
79293f8995SGreg Kroah-Hartman #define rx_enable(port) enable(port, rx_enabled_bit)
80293f8995SGreg Kroah-Hartman #define rx_disable(port) disable(port, rx_enabled_bit)
81ab4382d2SGreg Kroah-Hartman
82ab4382d2SGreg Kroah-Hartman /*
83ab4382d2SGreg Kroah-Hartman * The documented expression for selecting the divisor is:
84ab4382d2SGreg Kroah-Hartman * BAUD_BASE / baud - 1
85ab4382d2SGreg Kroah-Hartman * However, typically BAUD_BASE is not divisible by baud, so
86ab4382d2SGreg Kroah-Hartman * we want to select the divisor that gives us the minimum
87ab4382d2SGreg Kroah-Hartman * error. Therefore, we want:
88ab4382d2SGreg Kroah-Hartman * int(BAUD_BASE / baud - 0.5) ->
89ab4382d2SGreg Kroah-Hartman * int(BAUD_BASE / baud - (baud >> 1) / baud) ->
90ab4382d2SGreg Kroah-Hartman * int((BAUD_BASE - (baud >> 1)) / baud)
91ab4382d2SGreg Kroah-Hartman */
92ab4382d2SGreg Kroah-Hartman
serial21285_stop_tx(struct uart_port * port)93ab4382d2SGreg Kroah-Hartman static void serial21285_stop_tx(struct uart_port *port)
94ab4382d2SGreg Kroah-Hartman {
95293f8995SGreg Kroah-Hartman if (is_tx_enabled(port)) {
96ab4382d2SGreg Kroah-Hartman disable_irq_nosync(IRQ_CONTX);
97293f8995SGreg Kroah-Hartman tx_disable(port);
98ab4382d2SGreg Kroah-Hartman }
99ab4382d2SGreg Kroah-Hartman }
100ab4382d2SGreg Kroah-Hartman
serial21285_start_tx(struct uart_port * port)101ab4382d2SGreg Kroah-Hartman static void serial21285_start_tx(struct uart_port *port)
102ab4382d2SGreg Kroah-Hartman {
103293f8995SGreg Kroah-Hartman if (!is_tx_enabled(port)) {
104ab4382d2SGreg Kroah-Hartman enable_irq(IRQ_CONTX);
105293f8995SGreg Kroah-Hartman tx_enable(port);
106ab4382d2SGreg Kroah-Hartman }
107ab4382d2SGreg Kroah-Hartman }
108ab4382d2SGreg Kroah-Hartman
serial21285_stop_rx(struct uart_port * port)109ab4382d2SGreg Kroah-Hartman static void serial21285_stop_rx(struct uart_port *port)
110ab4382d2SGreg Kroah-Hartman {
111293f8995SGreg Kroah-Hartman if (is_rx_enabled(port)) {
112ab4382d2SGreg Kroah-Hartman disable_irq_nosync(IRQ_CONRX);
113293f8995SGreg Kroah-Hartman rx_disable(port);
114ab4382d2SGreg Kroah-Hartman }
115ab4382d2SGreg Kroah-Hartman }
116ab4382d2SGreg Kroah-Hartman
serial21285_rx_chars(int irq,void * dev_id)117ab4382d2SGreg Kroah-Hartman static irqreturn_t serial21285_rx_chars(int irq, void *dev_id)
118ab4382d2SGreg Kroah-Hartman {
119ab4382d2SGreg Kroah-Hartman struct uart_port *port = dev_id;
120*fd2b55f8SJiri Slaby unsigned int status, rxs, max_count = 256;
121*fd2b55f8SJiri Slaby u8 ch, flag;
122ab4382d2SGreg Kroah-Hartman
123ab4382d2SGreg Kroah-Hartman status = *CSR_UARTFLG;
124ab4382d2SGreg Kroah-Hartman while (!(status & 0x10) && max_count--) {
125ab4382d2SGreg Kroah-Hartman ch = *CSR_UARTDR;
126ab4382d2SGreg Kroah-Hartman flag = TTY_NORMAL;
127ab4382d2SGreg Kroah-Hartman port->icount.rx++;
128ab4382d2SGreg Kroah-Hartman
129ab4382d2SGreg Kroah-Hartman rxs = *CSR_RXSTAT | RXSTAT_DUMMY_READ;
130ab4382d2SGreg Kroah-Hartman if (unlikely(rxs & RXSTAT_ANYERR)) {
131ab4382d2SGreg Kroah-Hartman if (rxs & RXSTAT_PARITY)
132ab4382d2SGreg Kroah-Hartman port->icount.parity++;
133ab4382d2SGreg Kroah-Hartman else if (rxs & RXSTAT_FRAME)
134ab4382d2SGreg Kroah-Hartman port->icount.frame++;
135ab4382d2SGreg Kroah-Hartman if (rxs & RXSTAT_OVERRUN)
136ab4382d2SGreg Kroah-Hartman port->icount.overrun++;
137ab4382d2SGreg Kroah-Hartman
138ab4382d2SGreg Kroah-Hartman rxs &= port->read_status_mask;
139ab4382d2SGreg Kroah-Hartman
140ab4382d2SGreg Kroah-Hartman if (rxs & RXSTAT_PARITY)
141ab4382d2SGreg Kroah-Hartman flag = TTY_PARITY;
142ab4382d2SGreg Kroah-Hartman else if (rxs & RXSTAT_FRAME)
143ab4382d2SGreg Kroah-Hartman flag = TTY_FRAME;
144ab4382d2SGreg Kroah-Hartman }
145ab4382d2SGreg Kroah-Hartman
146ab4382d2SGreg Kroah-Hartman uart_insert_char(port, rxs, RXSTAT_OVERRUN, ch, flag);
147ab4382d2SGreg Kroah-Hartman
148ab4382d2SGreg Kroah-Hartman status = *CSR_UARTFLG;
149ab4382d2SGreg Kroah-Hartman }
1502e124b4aSJiri Slaby tty_flip_buffer_push(&port->state->port);
151ab4382d2SGreg Kroah-Hartman
152ab4382d2SGreg Kroah-Hartman return IRQ_HANDLED;
153ab4382d2SGreg Kroah-Hartman }
154ab4382d2SGreg Kroah-Hartman
serial21285_tx_chars(int irq,void * dev_id)155ab4382d2SGreg Kroah-Hartman static irqreturn_t serial21285_tx_chars(int irq, void *dev_id)
156ab4382d2SGreg Kroah-Hartman {
157ab4382d2SGreg Kroah-Hartman struct uart_port *port = dev_id;
158d11cc8c3SJiri Slaby (SUSE) u8 ch;
159ab4382d2SGreg Kroah-Hartman
160d11cc8c3SJiri Slaby (SUSE) uart_port_tx_limited(port, ch, 256,
161d11cc8c3SJiri Slaby (SUSE) !(*CSR_UARTFLG & 0x20),
162d11cc8c3SJiri Slaby (SUSE) *CSR_UARTDR = ch,
163d11cc8c3SJiri Slaby (SUSE) ({}));
164ab4382d2SGreg Kroah-Hartman
165ab4382d2SGreg Kroah-Hartman return IRQ_HANDLED;
166ab4382d2SGreg Kroah-Hartman }
167ab4382d2SGreg Kroah-Hartman
serial21285_tx_empty(struct uart_port * port)168ab4382d2SGreg Kroah-Hartman static unsigned int serial21285_tx_empty(struct uart_port *port)
169ab4382d2SGreg Kroah-Hartman {
170ab4382d2SGreg Kroah-Hartman return (*CSR_UARTFLG & 8) ? 0 : TIOCSER_TEMT;
171ab4382d2SGreg Kroah-Hartman }
172ab4382d2SGreg Kroah-Hartman
173ab4382d2SGreg Kroah-Hartman /* no modem control lines */
serial21285_get_mctrl(struct uart_port * port)174ab4382d2SGreg Kroah-Hartman static unsigned int serial21285_get_mctrl(struct uart_port *port)
175ab4382d2SGreg Kroah-Hartman {
176ab4382d2SGreg Kroah-Hartman return TIOCM_CAR | TIOCM_DSR | TIOCM_CTS;
177ab4382d2SGreg Kroah-Hartman }
178ab4382d2SGreg Kroah-Hartman
serial21285_set_mctrl(struct uart_port * port,unsigned int mctrl)179ab4382d2SGreg Kroah-Hartman static void serial21285_set_mctrl(struct uart_port *port, unsigned int mctrl)
180ab4382d2SGreg Kroah-Hartman {
181ab4382d2SGreg Kroah-Hartman }
182ab4382d2SGreg Kroah-Hartman
serial21285_break_ctl(struct uart_port * port,int break_state)183ab4382d2SGreg Kroah-Hartman static void serial21285_break_ctl(struct uart_port *port, int break_state)
184ab4382d2SGreg Kroah-Hartman {
185ab4382d2SGreg Kroah-Hartman unsigned long flags;
186ab4382d2SGreg Kroah-Hartman unsigned int h_lcr;
187ab4382d2SGreg Kroah-Hartman
188ab4382d2SGreg Kroah-Hartman spin_lock_irqsave(&port->lock, flags);
189ab4382d2SGreg Kroah-Hartman h_lcr = *CSR_H_UBRLCR;
190ab4382d2SGreg Kroah-Hartman if (break_state)
191ab4382d2SGreg Kroah-Hartman h_lcr |= H_UBRLCR_BREAK;
192ab4382d2SGreg Kroah-Hartman else
193ab4382d2SGreg Kroah-Hartman h_lcr &= ~H_UBRLCR_BREAK;
194ab4382d2SGreg Kroah-Hartman *CSR_H_UBRLCR = h_lcr;
195ab4382d2SGreg Kroah-Hartman spin_unlock_irqrestore(&port->lock, flags);
196ab4382d2SGreg Kroah-Hartman }
197ab4382d2SGreg Kroah-Hartman
serial21285_startup(struct uart_port * port)198ab4382d2SGreg Kroah-Hartman static int serial21285_startup(struct uart_port *port)
199ab4382d2SGreg Kroah-Hartman {
200ab4382d2SGreg Kroah-Hartman int ret;
201ab4382d2SGreg Kroah-Hartman
202293f8995SGreg Kroah-Hartman tx_enable(port);
203293f8995SGreg Kroah-Hartman rx_enable(port);
204ab4382d2SGreg Kroah-Hartman
205ab4382d2SGreg Kroah-Hartman ret = request_irq(IRQ_CONRX, serial21285_rx_chars, 0,
206ab4382d2SGreg Kroah-Hartman serial21285_name, port);
207ab4382d2SGreg Kroah-Hartman if (ret == 0) {
208ab4382d2SGreg Kroah-Hartman ret = request_irq(IRQ_CONTX, serial21285_tx_chars, 0,
209ab4382d2SGreg Kroah-Hartman serial21285_name, port);
210ab4382d2SGreg Kroah-Hartman if (ret)
211ab4382d2SGreg Kroah-Hartman free_irq(IRQ_CONRX, port);
212ab4382d2SGreg Kroah-Hartman }
213ab4382d2SGreg Kroah-Hartman
214ab4382d2SGreg Kroah-Hartman return ret;
215ab4382d2SGreg Kroah-Hartman }
216ab4382d2SGreg Kroah-Hartman
serial21285_shutdown(struct uart_port * port)217ab4382d2SGreg Kroah-Hartman static void serial21285_shutdown(struct uart_port *port)
218ab4382d2SGreg Kroah-Hartman {
219ab4382d2SGreg Kroah-Hartman free_irq(IRQ_CONTX, port);
220ab4382d2SGreg Kroah-Hartman free_irq(IRQ_CONRX, port);
221ab4382d2SGreg Kroah-Hartman }
222ab4382d2SGreg Kroah-Hartman
223ab4382d2SGreg Kroah-Hartman static void
serial21285_set_termios(struct uart_port * port,struct ktermios * termios,const struct ktermios * old)224ab4382d2SGreg Kroah-Hartman serial21285_set_termios(struct uart_port *port, struct ktermios *termios,
225bec5b814SIlpo Järvinen const struct ktermios *old)
226ab4382d2SGreg Kroah-Hartman {
227ab4382d2SGreg Kroah-Hartman unsigned long flags;
228ab4382d2SGreg Kroah-Hartman unsigned int baud, quot, h_lcr, b;
229ab4382d2SGreg Kroah-Hartman
230ab4382d2SGreg Kroah-Hartman /*
231ab4382d2SGreg Kroah-Hartman * We don't support modem control lines.
232ab4382d2SGreg Kroah-Hartman */
233ab4382d2SGreg Kroah-Hartman termios->c_cflag &= ~(HUPCL | CRTSCTS | CMSPAR);
234ab4382d2SGreg Kroah-Hartman termios->c_cflag |= CLOCAL;
235ab4382d2SGreg Kroah-Hartman
236ab4382d2SGreg Kroah-Hartman /*
237ab4382d2SGreg Kroah-Hartman * We don't support BREAK character recognition.
238ab4382d2SGreg Kroah-Hartman */
239ab4382d2SGreg Kroah-Hartman termios->c_iflag &= ~(IGNBRK | BRKINT);
240ab4382d2SGreg Kroah-Hartman
241ab4382d2SGreg Kroah-Hartman /*
242ab4382d2SGreg Kroah-Hartman * Ask the core to calculate the divisor for us.
243ab4382d2SGreg Kroah-Hartman */
244ab4382d2SGreg Kroah-Hartman baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16);
245ab4382d2SGreg Kroah-Hartman quot = uart_get_divisor(port, baud);
246ab4382d2SGreg Kroah-Hartman b = port->uartclk / (16 * quot);
247ab4382d2SGreg Kroah-Hartman tty_termios_encode_baud_rate(termios, b, b);
248ab4382d2SGreg Kroah-Hartman
249ab4382d2SGreg Kroah-Hartman switch (termios->c_cflag & CSIZE) {
250ab4382d2SGreg Kroah-Hartman case CS5:
251ab4382d2SGreg Kroah-Hartman h_lcr = 0x00;
252ab4382d2SGreg Kroah-Hartman break;
253ab4382d2SGreg Kroah-Hartman case CS6:
254ab4382d2SGreg Kroah-Hartman h_lcr = 0x20;
255ab4382d2SGreg Kroah-Hartman break;
256ab4382d2SGreg Kroah-Hartman case CS7:
257ab4382d2SGreg Kroah-Hartman h_lcr = 0x40;
258ab4382d2SGreg Kroah-Hartman break;
259ab4382d2SGreg Kroah-Hartman default: /* CS8 */
260ab4382d2SGreg Kroah-Hartman h_lcr = 0x60;
261ab4382d2SGreg Kroah-Hartman break;
262ab4382d2SGreg Kroah-Hartman }
263ab4382d2SGreg Kroah-Hartman
264ab4382d2SGreg Kroah-Hartman if (termios->c_cflag & CSTOPB)
265ab4382d2SGreg Kroah-Hartman h_lcr |= H_UBRLCR_STOPB;
266ab4382d2SGreg Kroah-Hartman if (termios->c_cflag & PARENB) {
267ab4382d2SGreg Kroah-Hartman h_lcr |= H_UBRLCR_PARENB;
268ab4382d2SGreg Kroah-Hartman if (!(termios->c_cflag & PARODD))
269ab4382d2SGreg Kroah-Hartman h_lcr |= H_UBRLCR_PAREVN;
270ab4382d2SGreg Kroah-Hartman }
271ab4382d2SGreg Kroah-Hartman
272ab4382d2SGreg Kroah-Hartman if (port->fifosize)
273ab4382d2SGreg Kroah-Hartman h_lcr |= H_UBRLCR_FIFO;
274ab4382d2SGreg Kroah-Hartman
275ab4382d2SGreg Kroah-Hartman spin_lock_irqsave(&port->lock, flags);
276ab4382d2SGreg Kroah-Hartman
277ab4382d2SGreg Kroah-Hartman /*
278ab4382d2SGreg Kroah-Hartman * Update the per-port timeout.
279ab4382d2SGreg Kroah-Hartman */
280ab4382d2SGreg Kroah-Hartman uart_update_timeout(port, termios->c_cflag, baud);
281ab4382d2SGreg Kroah-Hartman
282ab4382d2SGreg Kroah-Hartman /*
283ab4382d2SGreg Kroah-Hartman * Which character status flags are we interested in?
284ab4382d2SGreg Kroah-Hartman */
285ab4382d2SGreg Kroah-Hartman port->read_status_mask = RXSTAT_OVERRUN;
286ab4382d2SGreg Kroah-Hartman if (termios->c_iflag & INPCK)
287ab4382d2SGreg Kroah-Hartman port->read_status_mask |= RXSTAT_FRAME | RXSTAT_PARITY;
288ab4382d2SGreg Kroah-Hartman
289ab4382d2SGreg Kroah-Hartman /*
290ab4382d2SGreg Kroah-Hartman * Which character status flags should we ignore?
291ab4382d2SGreg Kroah-Hartman */
292ab4382d2SGreg Kroah-Hartman port->ignore_status_mask = 0;
293ab4382d2SGreg Kroah-Hartman if (termios->c_iflag & IGNPAR)
294ab4382d2SGreg Kroah-Hartman port->ignore_status_mask |= RXSTAT_FRAME | RXSTAT_PARITY;
295ab4382d2SGreg Kroah-Hartman if (termios->c_iflag & IGNBRK && termios->c_iflag & IGNPAR)
296ab4382d2SGreg Kroah-Hartman port->ignore_status_mask |= RXSTAT_OVERRUN;
297ab4382d2SGreg Kroah-Hartman
298ab4382d2SGreg Kroah-Hartman /*
299ab4382d2SGreg Kroah-Hartman * Ignore all characters if CREAD is not set.
300ab4382d2SGreg Kroah-Hartman */
301ab4382d2SGreg Kroah-Hartman if ((termios->c_cflag & CREAD) == 0)
302ab4382d2SGreg Kroah-Hartman port->ignore_status_mask |= RXSTAT_DUMMY_READ;
303ab4382d2SGreg Kroah-Hartman
304ab4382d2SGreg Kroah-Hartman quot -= 1;
305ab4382d2SGreg Kroah-Hartman
306ab4382d2SGreg Kroah-Hartman *CSR_UARTCON = 0;
307ab4382d2SGreg Kroah-Hartman *CSR_L_UBRLCR = quot & 0xff;
308ab4382d2SGreg Kroah-Hartman *CSR_M_UBRLCR = (quot >> 8) & 0x0f;
309ab4382d2SGreg Kroah-Hartman *CSR_H_UBRLCR = h_lcr;
310ab4382d2SGreg Kroah-Hartman *CSR_UARTCON = 1;
311ab4382d2SGreg Kroah-Hartman
312ab4382d2SGreg Kroah-Hartman spin_unlock_irqrestore(&port->lock, flags);
313ab4382d2SGreg Kroah-Hartman }
314ab4382d2SGreg Kroah-Hartman
serial21285_type(struct uart_port * port)315ab4382d2SGreg Kroah-Hartman static const char *serial21285_type(struct uart_port *port)
316ab4382d2SGreg Kroah-Hartman {
317ab4382d2SGreg Kroah-Hartman return port->type == PORT_21285 ? "DC21285" : NULL;
318ab4382d2SGreg Kroah-Hartman }
319ab4382d2SGreg Kroah-Hartman
serial21285_release_port(struct uart_port * port)320ab4382d2SGreg Kroah-Hartman static void serial21285_release_port(struct uart_port *port)
321ab4382d2SGreg Kroah-Hartman {
322ab4382d2SGreg Kroah-Hartman release_mem_region(port->mapbase, 32);
323ab4382d2SGreg Kroah-Hartman }
324ab4382d2SGreg Kroah-Hartman
serial21285_request_port(struct uart_port * port)325ab4382d2SGreg Kroah-Hartman static int serial21285_request_port(struct uart_port *port)
326ab4382d2SGreg Kroah-Hartman {
327ab4382d2SGreg Kroah-Hartman return request_mem_region(port->mapbase, 32, serial21285_name)
328ab4382d2SGreg Kroah-Hartman != NULL ? 0 : -EBUSY;
329ab4382d2SGreg Kroah-Hartman }
330ab4382d2SGreg Kroah-Hartman
serial21285_config_port(struct uart_port * port,int flags)331ab4382d2SGreg Kroah-Hartman static void serial21285_config_port(struct uart_port *port, int flags)
332ab4382d2SGreg Kroah-Hartman {
333ab4382d2SGreg Kroah-Hartman if (flags & UART_CONFIG_TYPE && serial21285_request_port(port) == 0)
334ab4382d2SGreg Kroah-Hartman port->type = PORT_21285;
335ab4382d2SGreg Kroah-Hartman }
336ab4382d2SGreg Kroah-Hartman
337ab4382d2SGreg Kroah-Hartman /*
338ab4382d2SGreg Kroah-Hartman * verify the new serial_struct (for TIOCSSERIAL).
339ab4382d2SGreg Kroah-Hartman */
serial21285_verify_port(struct uart_port * port,struct serial_struct * ser)340ab4382d2SGreg Kroah-Hartman static int serial21285_verify_port(struct uart_port *port, struct serial_struct *ser)
341ab4382d2SGreg Kroah-Hartman {
342ab4382d2SGreg Kroah-Hartman int ret = 0;
343ab4382d2SGreg Kroah-Hartman if (ser->type != PORT_UNKNOWN && ser->type != PORT_21285)
344ab4382d2SGreg Kroah-Hartman ret = -EINVAL;
345d4e33facSAlan Cox if (ser->irq <= 0)
346ab4382d2SGreg Kroah-Hartman ret = -EINVAL;
347ab4382d2SGreg Kroah-Hartman if (ser->baud_base != port->uartclk / 16)
348ab4382d2SGreg Kroah-Hartman ret = -EINVAL;
349ab4382d2SGreg Kroah-Hartman return ret;
350ab4382d2SGreg Kroah-Hartman }
351ab4382d2SGreg Kroah-Hartman
352ccb47a33SJulia Lawall static const struct uart_ops serial21285_ops = {
353ab4382d2SGreg Kroah-Hartman .tx_empty = serial21285_tx_empty,
354ab4382d2SGreg Kroah-Hartman .get_mctrl = serial21285_get_mctrl,
355ab4382d2SGreg Kroah-Hartman .set_mctrl = serial21285_set_mctrl,
356ab4382d2SGreg Kroah-Hartman .stop_tx = serial21285_stop_tx,
357ab4382d2SGreg Kroah-Hartman .start_tx = serial21285_start_tx,
358ab4382d2SGreg Kroah-Hartman .stop_rx = serial21285_stop_rx,
359ab4382d2SGreg Kroah-Hartman .break_ctl = serial21285_break_ctl,
360ab4382d2SGreg Kroah-Hartman .startup = serial21285_startup,
361ab4382d2SGreg Kroah-Hartman .shutdown = serial21285_shutdown,
362ab4382d2SGreg Kroah-Hartman .set_termios = serial21285_set_termios,
363ab4382d2SGreg Kroah-Hartman .type = serial21285_type,
364ab4382d2SGreg Kroah-Hartman .release_port = serial21285_release_port,
365ab4382d2SGreg Kroah-Hartman .request_port = serial21285_request_port,
366ab4382d2SGreg Kroah-Hartman .config_port = serial21285_config_port,
367ab4382d2SGreg Kroah-Hartman .verify_port = serial21285_verify_port,
368ab4382d2SGreg Kroah-Hartman };
369ab4382d2SGreg Kroah-Hartman
370ab4382d2SGreg Kroah-Hartman static struct uart_port serial21285_port = {
371ab4382d2SGreg Kroah-Hartman .mapbase = 0x42000160,
372ab4382d2SGreg Kroah-Hartman .iotype = UPIO_MEM,
373d4e33facSAlan Cox .irq = 0,
374ab4382d2SGreg Kroah-Hartman .fifosize = 16,
375ab4382d2SGreg Kroah-Hartman .ops = &serial21285_ops,
376ab4382d2SGreg Kroah-Hartman .flags = UPF_BOOT_AUTOCONF,
377ab4382d2SGreg Kroah-Hartman };
378ab4382d2SGreg Kroah-Hartman
serial21285_setup_ports(void)379ab4382d2SGreg Kroah-Hartman static void serial21285_setup_ports(void)
380ab4382d2SGreg Kroah-Hartman {
381ab4382d2SGreg Kroah-Hartman serial21285_port.uartclk = mem_fclk_21285 / 4;
382ab4382d2SGreg Kroah-Hartman }
383ab4382d2SGreg Kroah-Hartman
384ab4382d2SGreg Kroah-Hartman #ifdef CONFIG_SERIAL_21285_CONSOLE
serial21285_console_putchar(struct uart_port * port,unsigned char ch)3853f8bab17SJiri Slaby static void serial21285_console_putchar(struct uart_port *port, unsigned char ch)
386ab4382d2SGreg Kroah-Hartman {
387ab4382d2SGreg Kroah-Hartman while (*CSR_UARTFLG & 0x20)
388ab4382d2SGreg Kroah-Hartman barrier();
389ab4382d2SGreg Kroah-Hartman *CSR_UARTDR = ch;
390ab4382d2SGreg Kroah-Hartman }
391ab4382d2SGreg Kroah-Hartman
392ab4382d2SGreg Kroah-Hartman static void
serial21285_console_write(struct console * co,const char * s,unsigned int count)393ab4382d2SGreg Kroah-Hartman serial21285_console_write(struct console *co, const char *s,
394ab4382d2SGreg Kroah-Hartman unsigned int count)
395ab4382d2SGreg Kroah-Hartman {
396ab4382d2SGreg Kroah-Hartman uart_console_write(&serial21285_port, s, count, serial21285_console_putchar);
397ab4382d2SGreg Kroah-Hartman }
398ab4382d2SGreg Kroah-Hartman
399ab4382d2SGreg Kroah-Hartman static void __init
serial21285_get_options(struct uart_port * port,int * baud,int * parity,int * bits)400ab4382d2SGreg Kroah-Hartman serial21285_get_options(struct uart_port *port, int *baud,
401ab4382d2SGreg Kroah-Hartman int *parity, int *bits)
402ab4382d2SGreg Kroah-Hartman {
403ab4382d2SGreg Kroah-Hartman if (*CSR_UARTCON == 1) {
404ab4382d2SGreg Kroah-Hartman unsigned int tmp;
405ab4382d2SGreg Kroah-Hartman
406ab4382d2SGreg Kroah-Hartman tmp = *CSR_H_UBRLCR;
407ab4382d2SGreg Kroah-Hartman switch (tmp & 0x60) {
408ab4382d2SGreg Kroah-Hartman case 0x00:
409ab4382d2SGreg Kroah-Hartman *bits = 5;
410ab4382d2SGreg Kroah-Hartman break;
411ab4382d2SGreg Kroah-Hartman case 0x20:
412ab4382d2SGreg Kroah-Hartman *bits = 6;
413ab4382d2SGreg Kroah-Hartman break;
414ab4382d2SGreg Kroah-Hartman case 0x40:
415ab4382d2SGreg Kroah-Hartman *bits = 7;
416ab4382d2SGreg Kroah-Hartman break;
417ab4382d2SGreg Kroah-Hartman default:
418ab4382d2SGreg Kroah-Hartman case 0x60:
419ab4382d2SGreg Kroah-Hartman *bits = 8;
420ab4382d2SGreg Kroah-Hartman break;
421ab4382d2SGreg Kroah-Hartman }
422ab4382d2SGreg Kroah-Hartman
423ab4382d2SGreg Kroah-Hartman if (tmp & H_UBRLCR_PARENB) {
424ab4382d2SGreg Kroah-Hartman *parity = 'o';
425ab4382d2SGreg Kroah-Hartman if (tmp & H_UBRLCR_PAREVN)
426ab4382d2SGreg Kroah-Hartman *parity = 'e';
427ab4382d2SGreg Kroah-Hartman }
428ab4382d2SGreg Kroah-Hartman
429ab4382d2SGreg Kroah-Hartman tmp = *CSR_L_UBRLCR | (*CSR_M_UBRLCR << 8);
430ab4382d2SGreg Kroah-Hartman
431ab4382d2SGreg Kroah-Hartman *baud = port->uartclk / (16 * (tmp + 1));
432ab4382d2SGreg Kroah-Hartman }
433ab4382d2SGreg Kroah-Hartman }
434ab4382d2SGreg Kroah-Hartman
serial21285_console_setup(struct console * co,char * options)435ab4382d2SGreg Kroah-Hartman static int __init serial21285_console_setup(struct console *co, char *options)
436ab4382d2SGreg Kroah-Hartman {
437ab4382d2SGreg Kroah-Hartman struct uart_port *port = &serial21285_port;
438ab4382d2SGreg Kroah-Hartman int baud = 9600;
439ab4382d2SGreg Kroah-Hartman int bits = 8;
440ab4382d2SGreg Kroah-Hartman int parity = 'n';
441ab4382d2SGreg Kroah-Hartman int flow = 'n';
442ab4382d2SGreg Kroah-Hartman
443ab4382d2SGreg Kroah-Hartman /*
444ab4382d2SGreg Kroah-Hartman * Check whether an invalid uart number has been specified, and
445ab4382d2SGreg Kroah-Hartman * if so, search for the first available port that does have
446ab4382d2SGreg Kroah-Hartman * console support.
447ab4382d2SGreg Kroah-Hartman */
448ab4382d2SGreg Kroah-Hartman if (options)
449ab4382d2SGreg Kroah-Hartman uart_parse_options(options, &baud, &parity, &bits, &flow);
450ab4382d2SGreg Kroah-Hartman else
451ab4382d2SGreg Kroah-Hartman serial21285_get_options(port, &baud, &parity, &bits);
452ab4382d2SGreg Kroah-Hartman
453ab4382d2SGreg Kroah-Hartman return uart_set_options(port, co, baud, parity, bits, flow);
454ab4382d2SGreg Kroah-Hartman }
455ab4382d2SGreg Kroah-Hartman
456ab4382d2SGreg Kroah-Hartman static struct uart_driver serial21285_reg;
457ab4382d2SGreg Kroah-Hartman
458ab4382d2SGreg Kroah-Hartman static struct console serial21285_console =
459ab4382d2SGreg Kroah-Hartman {
460ab4382d2SGreg Kroah-Hartman .name = SERIAL_21285_NAME,
461ab4382d2SGreg Kroah-Hartman .write = serial21285_console_write,
462ab4382d2SGreg Kroah-Hartman .device = uart_console_device,
463ab4382d2SGreg Kroah-Hartman .setup = serial21285_console_setup,
464ab4382d2SGreg Kroah-Hartman .flags = CON_PRINTBUFFER,
465ab4382d2SGreg Kroah-Hartman .index = -1,
466ab4382d2SGreg Kroah-Hartman .data = &serial21285_reg,
467ab4382d2SGreg Kroah-Hartman };
468ab4382d2SGreg Kroah-Hartman
rs285_console_init(void)469ab4382d2SGreg Kroah-Hartman static int __init rs285_console_init(void)
470ab4382d2SGreg Kroah-Hartman {
471ab4382d2SGreg Kroah-Hartman serial21285_setup_ports();
472ab4382d2SGreg Kroah-Hartman register_console(&serial21285_console);
473ab4382d2SGreg Kroah-Hartman return 0;
474ab4382d2SGreg Kroah-Hartman }
475ab4382d2SGreg Kroah-Hartman console_initcall(rs285_console_init);
476ab4382d2SGreg Kroah-Hartman
477ab4382d2SGreg Kroah-Hartman #define SERIAL_21285_CONSOLE &serial21285_console
478ab4382d2SGreg Kroah-Hartman #else
479ab4382d2SGreg Kroah-Hartman #define SERIAL_21285_CONSOLE NULL
480ab4382d2SGreg Kroah-Hartman #endif
481ab4382d2SGreg Kroah-Hartman
482ab4382d2SGreg Kroah-Hartman static struct uart_driver serial21285_reg = {
483ab4382d2SGreg Kroah-Hartman .owner = THIS_MODULE,
484ab4382d2SGreg Kroah-Hartman .driver_name = "ttyFB",
485ab4382d2SGreg Kroah-Hartman .dev_name = "ttyFB",
486ab4382d2SGreg Kroah-Hartman .major = SERIAL_21285_MAJOR,
487ab4382d2SGreg Kroah-Hartman .minor = SERIAL_21285_MINOR,
488ab4382d2SGreg Kroah-Hartman .nr = 1,
489ab4382d2SGreg Kroah-Hartman .cons = SERIAL_21285_CONSOLE,
490ab4382d2SGreg Kroah-Hartman };
491ab4382d2SGreg Kroah-Hartman
serial21285_init(void)492ab4382d2SGreg Kroah-Hartman static int __init serial21285_init(void)
493ab4382d2SGreg Kroah-Hartman {
494ab4382d2SGreg Kroah-Hartman int ret;
495ab4382d2SGreg Kroah-Hartman
496ab4382d2SGreg Kroah-Hartman printk(KERN_INFO "Serial: 21285 driver\n");
497ab4382d2SGreg Kroah-Hartman
498ab4382d2SGreg Kroah-Hartman serial21285_setup_ports();
499ab4382d2SGreg Kroah-Hartman
500ab4382d2SGreg Kroah-Hartman ret = uart_register_driver(&serial21285_reg);
501ab4382d2SGreg Kroah-Hartman if (ret == 0)
502ab4382d2SGreg Kroah-Hartman uart_add_one_port(&serial21285_reg, &serial21285_port);
503ab4382d2SGreg Kroah-Hartman
504ab4382d2SGreg Kroah-Hartman return ret;
505ab4382d2SGreg Kroah-Hartman }
506ab4382d2SGreg Kroah-Hartman
serial21285_exit(void)507ab4382d2SGreg Kroah-Hartman static void __exit serial21285_exit(void)
508ab4382d2SGreg Kroah-Hartman {
509ab4382d2SGreg Kroah-Hartman uart_remove_one_port(&serial21285_reg, &serial21285_port);
510ab4382d2SGreg Kroah-Hartman uart_unregister_driver(&serial21285_reg);
511ab4382d2SGreg Kroah-Hartman }
512ab4382d2SGreg Kroah-Hartman
513ab4382d2SGreg Kroah-Hartman module_init(serial21285_init);
514ab4382d2SGreg Kroah-Hartman module_exit(serial21285_exit);
515ab4382d2SGreg Kroah-Hartman
516ab4382d2SGreg Kroah-Hartman MODULE_LICENSE("GPL");
517ab4382d2SGreg Kroah-Hartman MODULE_DESCRIPTION("Intel Footbridge (21285) serial driver");
518ab4382d2SGreg Kroah-Hartman MODULE_ALIAS_CHARDEV(SERIAL_21285_MAJOR, SERIAL_21285_MINOR);
519