blob: 36126070d9af8ad10071600b4d53bdb9d947d661 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Driver for the PSC of the Freescale MPC52xx PSCs configured as UARTs.
3 *
4 * FIXME According to the usermanual the status bits in the status register
5 * are only updated when the peripherals access the FIFO and not when the
6 * CPU access them. So since we use this bits to know when we stop writing
7 * and reading, they may not be updated in-time and a race condition may
8 * exists. But I haven't be able to prove this and I don't care. But if
9 * any problem arises, it might worth checking. The TX/RX FIFO Stats
10 * registers should be used in addition.
11 * Update: Actually, they seem updated ... At least the bits we use.
12 *
13 *
14 * Maintainer : Sylvain Munaut <tnt@246tNt.com>
Grant Likely9b9129e2006-11-27 14:21:01 -070015 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070016 * Some of the code has been inspired/copied from the 2.4 code written
17 * by Dale Farnsworth <dfarnsworth@mvista.com>.
Grant Likely9b9129e2006-11-27 14:21:01 -070018 *
John Rigby25ae3a02008-01-29 04:28:56 +110019 * Copyright (C) 2008 Freescale Semiconductor Inc.
20 * John Rigby <jrigby@gmail.com>
21 * Added support for MPC5121
Grant Likelyb9272df2006-11-27 14:21:02 -070022 * Copyright (C) 2006 Secret Lab Technologies Ltd.
23 * Grant Likely <grant.likely@secretlab.ca>
24 * Copyright (C) 2004-2006 Sylvain Munaut <tnt@246tNt.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 * Copyright (C) 2003 MontaVista, Software, Inc.
Grant Likely9b9129e2006-11-27 14:21:01 -070026 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 * This file is licensed under the terms of the GNU General Public License
28 * version 2. This program is licensed "as is" without any warranty of any
29 * kind, whether express or implied.
30 */
Grant Likely9b9129e2006-11-27 14:21:01 -070031
Linus Torvalds1da177e2005-04-16 15:20:36 -070032/* Platform device Usage :
33 *
34 * Since PSCs can have multiple function, the correct driver for each one
35 * is selected by calling mpc52xx_match_psc_function(...). The function
36 * handled by this driver is "uart".
37 *
38 * The driver init all necessary registers to place the PSC in uart mode without
39 * DCD. However, the pin multiplexing aren't changed and should be set either
40 * by the bootloader or in the platform init code.
41 *
John Rigby406b7d42008-01-17 08:37:25 +110042 * The idx field must be equal to the PSC index (e.g. 0 for PSC1, 1 for PSC2,
Sylvain Munautd62de3a2006-01-06 00:11:32 -080043 * and so on). So the PSC1 is mapped to /dev/ttyPSC0, PSC2 to /dev/ttyPSC1 and
44 * so on. But be warned, it's an ABSOLUTE REQUIREMENT ! This is needed mainly
45 * fpr the console code : without this 1:1 mapping, at early boot time, when we
Uwe Zeisbergerc30fe7f2006-03-24 18:23:14 +010046 * are parsing the kernel args console=ttyPSC?, we wouldn't know which PSC it
Sylvain Munautd62de3a2006-01-06 00:11:32 -080047 * will be mapped to.
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 */
49
Grant Likelyb9272df2006-11-27 14:21:02 -070050/* OF Platform device Usage :
51 *
52 * This driver is only used for PSCs configured in uart mode. The device
53 * tree will have a node for each PSC in uart mode w/ device_type = "serial"
54 * and "mpc52xx-psc-uart" in the compatible string
55 *
56 * By default, PSC devices are enumerated in the order they are found. However
57 * a particular PSC number can be forces by adding 'device_no = <port#>'
58 * to the device node.
59 *
60 * The driver init all necessary registers to place the PSC in uart mode without
61 * DCD. However, the pin multiplexing aren't changed and should be set either
62 * by the bootloader or in the platform init code.
63 */
64
65#undef DEBUG
66
67#include <linux/device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070068#include <linux/module.h>
69#include <linux/tty.h>
70#include <linux/serial.h>
71#include <linux/sysrq.h>
72#include <linux/console.h>
John Rigby406b7d42008-01-17 08:37:25 +110073#include <linux/delay.h>
74#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
Grant Likelyb9272df2006-11-27 14:21:02 -070076#if defined(CONFIG_PPC_MERGE)
Grant Likely283029d2008-01-09 06:20:40 +110077#include <linux/of.h>
78#include <linux/of_platform.h>
Grant Likelyb9272df2006-11-27 14:21:02 -070079#else
80#include <linux/platform_device.h>
81#endif
82
Linus Torvalds1da177e2005-04-16 15:20:36 -070083#include <asm/mpc52xx.h>
John Rigby25ae3a02008-01-29 04:28:56 +110084#include <asm/mpc512x.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070085#include <asm/mpc52xx_psc.h>
86
87#if defined(CONFIG_SERIAL_MPC52xx_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
88#define SUPPORT_SYSRQ
89#endif
90
91#include <linux/serial_core.h>
92
93
Sylvain Munautd62de3a2006-01-06 00:11:32 -080094/* We've been assigned a range on the "Low-density serial ports" major */
95#define SERIAL_PSC_MAJOR 204
96#define SERIAL_PSC_MINOR 148
97
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
99#define ISR_PASS_LIMIT 256 /* Max number of iteration in the interrupt */
100
101
102static struct uart_port mpc52xx_uart_ports[MPC52xx_PSC_MAXNUM];
103 /* Rem: - We use the read_status_mask as a shadow of
104 * psc->mpc52xx_psc_imr
105 * - It's important that is array is all zero on start as we
106 * use it to know if it's initialized or not ! If it's not sure
107 * it's cleared, then a memset(...,0,...) should be added to
108 * the console_init
109 */
Grant Likelyb9272df2006-11-27 14:21:02 -0700110#if defined(CONFIG_PPC_MERGE)
111/* lookup table for matching device nodes to index numbers */
112static struct device_node *mpc52xx_uart_nodes[MPC52xx_PSC_MAXNUM];
113
114static void mpc52xx_uart_of_enumerate(void);
115#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
John Rigby599f0302008-01-29 04:28:55 +1100117
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118#define PSC(port) ((struct mpc52xx_psc __iomem *)((port)->membase))
119
120
121/* Forward declaration of the interruption handling routine */
John Rigby406b7d42008-01-17 08:37:25 +1100122static irqreturn_t mpc52xx_uart_int(int irq, void *dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
124
125/* Simple macro to test if a port is console or not. This one is taken
126 * for serial_core.c and maybe should be moved to serial_core.h ? */
127#ifdef CONFIG_SERIAL_CORE_CONSOLE
John Rigby406b7d42008-01-17 08:37:25 +1100128#define uart_console(port) \
129 ((port)->cons && (port)->cons->index == (port)->line)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130#else
131#define uart_console(port) (0)
132#endif
133
John Rigby599f0302008-01-29 04:28:55 +1100134/* ======================================================================== */
135/* PSC fifo operations for isolating differences between 52xx and 512x */
136/* ======================================================================== */
137
138struct psc_ops {
139 void (*fifo_init)(struct uart_port *port);
140 int (*raw_rx_rdy)(struct uart_port *port);
141 int (*raw_tx_rdy)(struct uart_port *port);
142 int (*rx_rdy)(struct uart_port *port);
143 int (*tx_rdy)(struct uart_port *port);
144 int (*tx_empty)(struct uart_port *port);
145 void (*stop_rx)(struct uart_port *port);
146 void (*start_tx)(struct uart_port *port);
147 void (*stop_tx)(struct uart_port *port);
148 void (*rx_clr_irq)(struct uart_port *port);
149 void (*tx_clr_irq)(struct uart_port *port);
150 void (*write_char)(struct uart_port *port, unsigned char c);
151 unsigned char (*read_char)(struct uart_port *port);
152 void (*cw_disable_ints)(struct uart_port *port);
153 void (*cw_restore_ints)(struct uart_port *port);
154 unsigned long (*getuartclk)(void *p);
155};
156
John Rigby25ae3a02008-01-29 04:28:56 +1100157#ifdef CONFIG_PPC_MPC52xx
John Rigby599f0302008-01-29 04:28:55 +1100158#define FIFO_52xx(port) ((struct mpc52xx_psc_fifo __iomem *)(PSC(port)+1))
159static void mpc52xx_psc_fifo_init(struct uart_port *port)
160{
161 struct mpc52xx_psc __iomem *psc = PSC(port);
162 struct mpc52xx_psc_fifo __iomem *fifo = FIFO_52xx(port);
163
164 /* /32 prescaler */
165 out_be16(&psc->mpc52xx_psc_clock_select, 0xdd00);
166
167 out_8(&fifo->rfcntl, 0x00);
168 out_be16(&fifo->rfalarm, 0x1ff);
169 out_8(&fifo->tfcntl, 0x07);
170 out_be16(&fifo->tfalarm, 0x80);
171
172 port->read_status_mask |= MPC52xx_PSC_IMR_RXRDY | MPC52xx_PSC_IMR_TXRDY;
173 out_be16(&psc->mpc52xx_psc_imr, port->read_status_mask);
174}
175
176static int mpc52xx_psc_raw_rx_rdy(struct uart_port *port)
177{
178 return in_be16(&PSC(port)->mpc52xx_psc_status)
179 & MPC52xx_PSC_SR_RXRDY;
180}
181
182static int mpc52xx_psc_raw_tx_rdy(struct uart_port *port)
183{
184 return in_be16(&PSC(port)->mpc52xx_psc_status)
185 & MPC52xx_PSC_SR_TXRDY;
186}
187
188
189static int mpc52xx_psc_rx_rdy(struct uart_port *port)
190{
191 return in_be16(&PSC(port)->mpc52xx_psc_isr)
192 & port->read_status_mask
193 & MPC52xx_PSC_IMR_RXRDY;
194}
195
196static int mpc52xx_psc_tx_rdy(struct uart_port *port)
197{
198 return in_be16(&PSC(port)->mpc52xx_psc_isr)
199 & port->read_status_mask
200 & MPC52xx_PSC_IMR_TXRDY;
201}
202
203static int mpc52xx_psc_tx_empty(struct uart_port *port)
204{
205 return in_be16(&PSC(port)->mpc52xx_psc_status)
206 & MPC52xx_PSC_SR_TXEMP;
207}
208
209static void mpc52xx_psc_start_tx(struct uart_port *port)
210{
211 port->read_status_mask |= MPC52xx_PSC_IMR_TXRDY;
212 out_be16(&PSC(port)->mpc52xx_psc_imr, port->read_status_mask);
213}
214
215static void mpc52xx_psc_stop_tx(struct uart_port *port)
216{
217 port->read_status_mask &= ~MPC52xx_PSC_IMR_TXRDY;
218 out_be16(&PSC(port)->mpc52xx_psc_imr, port->read_status_mask);
219}
220
221static void mpc52xx_psc_stop_rx(struct uart_port *port)
222{
223 port->read_status_mask &= ~MPC52xx_PSC_IMR_RXRDY;
224 out_be16(&PSC(port)->mpc52xx_psc_imr, port->read_status_mask);
225}
226
227static void mpc52xx_psc_rx_clr_irq(struct uart_port *port)
228{
229}
230
231static void mpc52xx_psc_tx_clr_irq(struct uart_port *port)
232{
233}
234
235static void mpc52xx_psc_write_char(struct uart_port *port, unsigned char c)
236{
237 out_8(&PSC(port)->mpc52xx_psc_buffer_8, c);
238}
239
240static unsigned char mpc52xx_psc_read_char(struct uart_port *port)
241{
242 return in_8(&PSC(port)->mpc52xx_psc_buffer_8);
243}
244
245static void mpc52xx_psc_cw_disable_ints(struct uart_port *port)
246{
247 out_be16(&PSC(port)->mpc52xx_psc_imr, 0);
248}
249
250static void mpc52xx_psc_cw_restore_ints(struct uart_port *port)
251{
252 out_be16(&PSC(port)->mpc52xx_psc_imr, port->read_status_mask);
253}
254
255/* Search for bus-frequency property in this node or a parent */
256static unsigned long mpc52xx_getuartclk(void *p)
257{
258#if defined(CONFIG_PPC_MERGE)
259 /*
260 * 5200 UARTs have a / 32 prescaler
261 * but the generic serial code assumes 16
262 * so return ipb freq / 2
263 */
264 return mpc52xx_find_ipb_freq(p) / 2;
265#else
266 pr_debug("unexpected call to mpc52xx_getuartclk with arch/ppc\n");
267 return NULL;
268#endif
269}
270
271static struct psc_ops mpc52xx_psc_ops = {
272 .fifo_init = mpc52xx_psc_fifo_init,
273 .raw_rx_rdy = mpc52xx_psc_raw_rx_rdy,
274 .raw_tx_rdy = mpc52xx_psc_raw_tx_rdy,
275 .rx_rdy = mpc52xx_psc_rx_rdy,
276 .tx_rdy = mpc52xx_psc_tx_rdy,
277 .tx_empty = mpc52xx_psc_tx_empty,
278 .stop_rx = mpc52xx_psc_stop_rx,
279 .start_tx = mpc52xx_psc_start_tx,
280 .stop_tx = mpc52xx_psc_stop_tx,
281 .rx_clr_irq = mpc52xx_psc_rx_clr_irq,
282 .tx_clr_irq = mpc52xx_psc_tx_clr_irq,
283 .write_char = mpc52xx_psc_write_char,
284 .read_char = mpc52xx_psc_read_char,
285 .cw_disable_ints = mpc52xx_psc_cw_disable_ints,
286 .cw_restore_ints = mpc52xx_psc_cw_restore_ints,
287 .getuartclk = mpc52xx_getuartclk,
288};
289
John Rigby25ae3a02008-01-29 04:28:56 +1100290#endif /* CONFIG_MPC52xx */
291
292#ifdef CONFIG_PPC_MPC512x
293#define FIFO_512x(port) ((struct mpc512x_psc_fifo __iomem *)(PSC(port)+1))
294static void mpc512x_psc_fifo_init(struct uart_port *port)
295{
296 out_be32(&FIFO_512x(port)->txcmd, MPC512x_PSC_FIFO_RESET_SLICE);
297 out_be32(&FIFO_512x(port)->txcmd, MPC512x_PSC_FIFO_ENABLE_SLICE);
298 out_be32(&FIFO_512x(port)->txalarm, 1);
299 out_be32(&FIFO_512x(port)->tximr, 0);
300
301 out_be32(&FIFO_512x(port)->rxcmd, MPC512x_PSC_FIFO_RESET_SLICE);
302 out_be32(&FIFO_512x(port)->rxcmd, MPC512x_PSC_FIFO_ENABLE_SLICE);
303 out_be32(&FIFO_512x(port)->rxalarm, 1);
304 out_be32(&FIFO_512x(port)->rximr, 0);
305
306 out_be32(&FIFO_512x(port)->tximr, MPC512x_PSC_FIFO_ALARM);
307 out_be32(&FIFO_512x(port)->rximr, MPC512x_PSC_FIFO_ALARM);
308}
309
310static int mpc512x_psc_raw_rx_rdy(struct uart_port *port)
311{
312 return !(in_be32(&FIFO_512x(port)->rxsr) & MPC512x_PSC_FIFO_EMPTY);
313}
314
315static int mpc512x_psc_raw_tx_rdy(struct uart_port *port)
316{
317 return !(in_be32(&FIFO_512x(port)->txsr) & MPC512x_PSC_FIFO_FULL);
318}
319
320static int mpc512x_psc_rx_rdy(struct uart_port *port)
321{
322 return in_be32(&FIFO_512x(port)->rxsr)
323 & in_be32(&FIFO_512x(port)->rximr)
324 & MPC512x_PSC_FIFO_ALARM;
325}
326
327static int mpc512x_psc_tx_rdy(struct uart_port *port)
328{
329 return in_be32(&FIFO_512x(port)->txsr)
330 & in_be32(&FIFO_512x(port)->tximr)
331 & MPC512x_PSC_FIFO_ALARM;
332}
333
334static int mpc512x_psc_tx_empty(struct uart_port *port)
335{
336 return in_be32(&FIFO_512x(port)->txsr)
337 & MPC512x_PSC_FIFO_EMPTY;
338}
339
340static void mpc512x_psc_stop_rx(struct uart_port *port)
341{
342 unsigned long rx_fifo_imr;
343
344 rx_fifo_imr = in_be32(&FIFO_512x(port)->rximr);
345 rx_fifo_imr &= ~MPC512x_PSC_FIFO_ALARM;
346 out_be32(&FIFO_512x(port)->rximr, rx_fifo_imr);
347}
348
349static void mpc512x_psc_start_tx(struct uart_port *port)
350{
351 unsigned long tx_fifo_imr;
352
353 tx_fifo_imr = in_be32(&FIFO_512x(port)->tximr);
354 tx_fifo_imr |= MPC512x_PSC_FIFO_ALARM;
355 out_be32(&FIFO_512x(port)->tximr, tx_fifo_imr);
356}
357
358static void mpc512x_psc_stop_tx(struct uart_port *port)
359{
360 unsigned long tx_fifo_imr;
361
362 tx_fifo_imr = in_be32(&FIFO_512x(port)->tximr);
363 tx_fifo_imr &= ~MPC512x_PSC_FIFO_ALARM;
364 out_be32(&FIFO_512x(port)->tximr, tx_fifo_imr);
365}
366
367static void mpc512x_psc_rx_clr_irq(struct uart_port *port)
368{
369 out_be32(&FIFO_512x(port)->rxisr, in_be32(&FIFO_512x(port)->rxisr));
370}
371
372static void mpc512x_psc_tx_clr_irq(struct uart_port *port)
373{
374 out_be32(&FIFO_512x(port)->txisr, in_be32(&FIFO_512x(port)->txisr));
375}
376
377static void mpc512x_psc_write_char(struct uart_port *port, unsigned char c)
378{
379 out_8(&FIFO_512x(port)->txdata_8, c);
380}
381
382static unsigned char mpc512x_psc_read_char(struct uart_port *port)
383{
384 return in_8(&FIFO_512x(port)->rxdata_8);
385}
386
387static void mpc512x_psc_cw_disable_ints(struct uart_port *port)
388{
389 port->read_status_mask =
390 in_be32(&FIFO_512x(port)->tximr) << 16 |
391 in_be32(&FIFO_512x(port)->rximr);
392 out_be32(&FIFO_512x(port)->tximr, 0);
393 out_be32(&FIFO_512x(port)->rximr, 0);
394}
395
396static void mpc512x_psc_cw_restore_ints(struct uart_port *port)
397{
398 out_be32(&FIFO_512x(port)->tximr,
399 (port->read_status_mask >> 16) & 0x7f);
400 out_be32(&FIFO_512x(port)->rximr, port->read_status_mask & 0x7f);
401}
402
403static unsigned long mpc512x_getuartclk(void *p)
404{
405 return mpc512x_find_ips_freq(p);
406}
407
408static struct psc_ops mpc512x_psc_ops = {
409 .fifo_init = mpc512x_psc_fifo_init,
410 .raw_rx_rdy = mpc512x_psc_raw_rx_rdy,
411 .raw_tx_rdy = mpc512x_psc_raw_tx_rdy,
412 .rx_rdy = mpc512x_psc_rx_rdy,
413 .tx_rdy = mpc512x_psc_tx_rdy,
414 .tx_empty = mpc512x_psc_tx_empty,
415 .stop_rx = mpc512x_psc_stop_rx,
416 .start_tx = mpc512x_psc_start_tx,
417 .stop_tx = mpc512x_psc_stop_tx,
418 .rx_clr_irq = mpc512x_psc_rx_clr_irq,
419 .tx_clr_irq = mpc512x_psc_tx_clr_irq,
420 .write_char = mpc512x_psc_write_char,
421 .read_char = mpc512x_psc_read_char,
422 .cw_disable_ints = mpc512x_psc_cw_disable_ints,
423 .cw_restore_ints = mpc512x_psc_cw_restore_ints,
424 .getuartclk = mpc512x_getuartclk,
425};
426#endif
427
428static struct psc_ops *psc_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
430/* ======================================================================== */
431/* UART operations */
432/* ======================================================================== */
433
Grant Likely9b9129e2006-11-27 14:21:01 -0700434static unsigned int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435mpc52xx_uart_tx_empty(struct uart_port *port)
436{
John Rigby599f0302008-01-29 04:28:55 +1100437 return psc_ops->tx_empty(port) ? TIOCSER_TEMT : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438}
439
Grant Likely9b9129e2006-11-27 14:21:01 -0700440static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441mpc52xx_uart_set_mctrl(struct uart_port *port, unsigned int mctrl)
442{
443 /* Not implemented */
444}
445
Grant Likely9b9129e2006-11-27 14:21:01 -0700446static unsigned int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447mpc52xx_uart_get_mctrl(struct uart_port *port)
448{
449 /* Not implemented */
450 return TIOCM_CTS | TIOCM_DSR | TIOCM_CAR;
451}
452
Grant Likely9b9129e2006-11-27 14:21:01 -0700453static void
Russell Kingb129a8c2005-08-31 10:12:14 +0100454mpc52xx_uart_stop_tx(struct uart_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455{
456 /* port->lock taken by caller */
John Rigby599f0302008-01-29 04:28:55 +1100457 psc_ops->stop_tx(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458}
459
Grant Likely9b9129e2006-11-27 14:21:01 -0700460static void
Russell Kingb129a8c2005-08-31 10:12:14 +0100461mpc52xx_uart_start_tx(struct uart_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462{
463 /* port->lock taken by caller */
John Rigby599f0302008-01-29 04:28:55 +1100464 psc_ops->start_tx(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465}
466
Grant Likely9b9129e2006-11-27 14:21:01 -0700467static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468mpc52xx_uart_send_xchar(struct uart_port *port, char ch)
469{
470 unsigned long flags;
471 spin_lock_irqsave(&port->lock, flags);
Grant Likely9b9129e2006-11-27 14:21:01 -0700472
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 port->x_char = ch;
474 if (ch) {
475 /* Make sure tx interrupts are on */
476 /* Truly necessary ??? They should be anyway */
John Rigby599f0302008-01-29 04:28:55 +1100477 psc_ops->start_tx(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 }
Grant Likely9b9129e2006-11-27 14:21:01 -0700479
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 spin_unlock_irqrestore(&port->lock, flags);
481}
482
483static void
484mpc52xx_uart_stop_rx(struct uart_port *port)
485{
486 /* port->lock taken by caller */
John Rigby599f0302008-01-29 04:28:55 +1100487 psc_ops->stop_rx(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488}
489
490static void
491mpc52xx_uart_enable_ms(struct uart_port *port)
492{
493 /* Not implemented */
494}
495
496static void
497mpc52xx_uart_break_ctl(struct uart_port *port, int ctl)
498{
499 unsigned long flags;
500 spin_lock_irqsave(&port->lock, flags);
501
John Rigby406b7d42008-01-17 08:37:25 +1100502 if (ctl == -1)
503 out_8(&PSC(port)->command, MPC52xx_PSC_START_BRK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 else
John Rigby406b7d42008-01-17 08:37:25 +1100505 out_8(&PSC(port)->command, MPC52xx_PSC_STOP_BRK);
Grant Likely9b9129e2006-11-27 14:21:01 -0700506
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 spin_unlock_irqrestore(&port->lock, flags);
508}
509
510static int
511mpc52xx_uart_startup(struct uart_port *port)
512{
513 struct mpc52xx_psc __iomem *psc = PSC(port);
514 int ret;
515
516 /* Request IRQ */
517 ret = request_irq(port->irq, mpc52xx_uart_int,
John Rigby25ae3a02008-01-29 04:28:56 +1100518 IRQF_DISABLED | IRQF_SAMPLE_RANDOM | IRQF_SHARED,
519 "mpc52xx_psc_uart", port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 if (ret)
521 return ret;
522
523 /* Reset/activate the port, clear and enable interrupts */
John Rigby406b7d42008-01-17 08:37:25 +1100524 out_8(&psc->command, MPC52xx_PSC_RST_RX);
525 out_8(&psc->command, MPC52xx_PSC_RST_TX);
Grant Likely9b9129e2006-11-27 14:21:01 -0700526
John Rigby406b7d42008-01-17 08:37:25 +1100527 out_be32(&psc->sicr, 0); /* UART mode DCD ignored */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
John Rigby599f0302008-01-29 04:28:55 +1100529 psc_ops->fifo_init(port);
Grant Likely9b9129e2006-11-27 14:21:01 -0700530
John Rigby406b7d42008-01-17 08:37:25 +1100531 out_8(&psc->command, MPC52xx_PSC_TX_ENABLE);
532 out_8(&psc->command, MPC52xx_PSC_RX_ENABLE);
Grant Likely9b9129e2006-11-27 14:21:01 -0700533
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 return 0;
535}
536
537static void
538mpc52xx_uart_shutdown(struct uart_port *port)
539{
540 struct mpc52xx_psc __iomem *psc = PSC(port);
Grant Likely9b9129e2006-11-27 14:21:01 -0700541
Grant Likelya3481192007-05-07 01:38:51 +1000542 /* Shut down the port. Leave TX active if on a console port */
John Rigby406b7d42008-01-17 08:37:25 +1100543 out_8(&psc->command, MPC52xx_PSC_RST_RX);
Grant Likelya3481192007-05-07 01:38:51 +1000544 if (!uart_console(port))
John Rigby406b7d42008-01-17 08:37:25 +1100545 out_8(&psc->command, MPC52xx_PSC_RST_TX);
Grant Likely9b9129e2006-11-27 14:21:01 -0700546
547 port->read_status_mask = 0;
John Rigby406b7d42008-01-17 08:37:25 +1100548 out_be16(&psc->mpc52xx_psc_imr, port->read_status_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
550 /* Release interrupt */
551 free_irq(port->irq, port);
552}
553
Grant Likely9b9129e2006-11-27 14:21:01 -0700554static void
Alan Cox606d0992006-12-08 02:38:45 -0800555mpc52xx_uart_set_termios(struct uart_port *port, struct ktermios *new,
John Rigby406b7d42008-01-17 08:37:25 +1100556 struct ktermios *old)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557{
558 struct mpc52xx_psc __iomem *psc = PSC(port);
559 unsigned long flags;
560 unsigned char mr1, mr2;
561 unsigned short ctr;
562 unsigned int j, baud, quot;
Grant Likely9b9129e2006-11-27 14:21:01 -0700563
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 /* Prepare what we're gonna write */
565 mr1 = 0;
Grant Likely9b9129e2006-11-27 14:21:01 -0700566
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 switch (new->c_cflag & CSIZE) {
John Rigby406b7d42008-01-17 08:37:25 +1100568 case CS5: mr1 |= MPC52xx_PSC_MODE_5_BITS;
569 break;
570 case CS6: mr1 |= MPC52xx_PSC_MODE_6_BITS;
571 break;
572 case CS7: mr1 |= MPC52xx_PSC_MODE_7_BITS;
573 break;
574 case CS8:
575 default: mr1 |= MPC52xx_PSC_MODE_8_BITS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 }
577
578 if (new->c_cflag & PARENB) {
579 mr1 |= (new->c_cflag & PARODD) ?
580 MPC52xx_PSC_MODE_PARODD : MPC52xx_PSC_MODE_PAREVEN;
581 } else
582 mr1 |= MPC52xx_PSC_MODE_PARNONE;
Grant Likely9b9129e2006-11-27 14:21:01 -0700583
584
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 mr2 = 0;
586
587 if (new->c_cflag & CSTOPB)
588 mr2 |= MPC52xx_PSC_MODE_TWO_STOP;
589 else
590 mr2 |= ((new->c_cflag & CSIZE) == CS5) ?
591 MPC52xx_PSC_MODE_ONE_STOP_5_BITS :
592 MPC52xx_PSC_MODE_ONE_STOP;
593
594
595 baud = uart_get_baud_rate(port, new, old, 0, port->uartclk/16);
596 quot = uart_get_divisor(port, baud);
597 ctr = quot & 0xffff;
Grant Likely9b9129e2006-11-27 14:21:01 -0700598
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 /* Get the lock */
600 spin_lock_irqsave(&port->lock, flags);
601
602 /* Update the per-port timeout */
603 uart_update_timeout(port, new->c_cflag, baud);
604
605 /* Do our best to flush TX & RX, so we don't loose anything */
606 /* But we don't wait indefinitly ! */
607 j = 5000000; /* Maximum wait */
608 /* FIXME Can't receive chars since set_termios might be called at early
609 * boot for the console, all stuff is not yet ready to receive at that
610 * time and that just makes the kernel oops */
611 /* while (j-- && mpc52xx_uart_int_rx_chars(port)); */
John Rigby599f0302008-01-29 04:28:55 +1100612 while (!mpc52xx_uart_tx_empty(port) && --j)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 udelay(1);
614
615 if (!j)
John Rigby406b7d42008-01-17 08:37:25 +1100616 printk(KERN_ERR "mpc52xx_uart.c: "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 "Unable to flush RX & TX fifos in-time in set_termios."
John Rigby406b7d42008-01-17 08:37:25 +1100618 "Some chars may have been lost.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
620 /* Reset the TX & RX */
John Rigby406b7d42008-01-17 08:37:25 +1100621 out_8(&psc->command, MPC52xx_PSC_RST_RX);
622 out_8(&psc->command, MPC52xx_PSC_RST_TX);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623
624 /* Send new mode settings */
John Rigby406b7d42008-01-17 08:37:25 +1100625 out_8(&psc->command, MPC52xx_PSC_SEL_MODE_REG_1);
626 out_8(&psc->mode, mr1);
627 out_8(&psc->mode, mr2);
628 out_8(&psc->ctur, ctr >> 8);
629 out_8(&psc->ctlr, ctr & 0xff);
Grant Likely9b9129e2006-11-27 14:21:01 -0700630
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 /* Reenable TX & RX */
John Rigby406b7d42008-01-17 08:37:25 +1100632 out_8(&psc->command, MPC52xx_PSC_TX_ENABLE);
633 out_8(&psc->command, MPC52xx_PSC_RX_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634
635 /* We're all set, release the lock */
636 spin_unlock_irqrestore(&port->lock, flags);
637}
638
639static const char *
640mpc52xx_uart_type(struct uart_port *port)
641{
642 return port->type == PORT_MPC52xx ? "MPC52xx PSC" : NULL;
643}
644
645static void
646mpc52xx_uart_release_port(struct uart_port *port)
647{
John Rigby406b7d42008-01-17 08:37:25 +1100648 /* remapped by us ? */
649 if (port->flags & UPF_IOREMAP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 iounmap(port->membase);
651 port->membase = NULL;
652 }
653
Grant Likelyb9272df2006-11-27 14:21:02 -0700654 release_mem_region(port->mapbase, sizeof(struct mpc52xx_psc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655}
656
657static int
658mpc52xx_uart_request_port(struct uart_port *port)
659{
Amol Ladbe618f52006-09-30 23:29:23 -0700660 int err;
661
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 if (port->flags & UPF_IOREMAP) /* Need to remap ? */
Grant Likelyb9272df2006-11-27 14:21:02 -0700663 port->membase = ioremap(port->mapbase,
John Rigby406b7d42008-01-17 08:37:25 +1100664 sizeof(struct mpc52xx_psc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665
666 if (!port->membase)
667 return -EINVAL;
668
Grant Likelyb9272df2006-11-27 14:21:02 -0700669 err = request_mem_region(port->mapbase, sizeof(struct mpc52xx_psc),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 "mpc52xx_psc_uart") != NULL ? 0 : -EBUSY;
Amol Ladbe618f52006-09-30 23:29:23 -0700671
672 if (err && (port->flags & UPF_IOREMAP)) {
673 iounmap(port->membase);
674 port->membase = NULL;
675 }
676
677 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678}
679
680static void
681mpc52xx_uart_config_port(struct uart_port *port, int flags)
682{
John Rigby406b7d42008-01-17 08:37:25 +1100683 if ((flags & UART_CONFIG_TYPE)
684 && (mpc52xx_uart_request_port(port) == 0))
685 port->type = PORT_MPC52xx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686}
687
688static int
689mpc52xx_uart_verify_port(struct uart_port *port, struct serial_struct *ser)
690{
John Rigby406b7d42008-01-17 08:37:25 +1100691 if (ser->type != PORT_UNKNOWN && ser->type != PORT_MPC52xx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 return -EINVAL;
693
John Rigby406b7d42008-01-17 08:37:25 +1100694 if ((ser->irq != port->irq) ||
695 (ser->io_type != SERIAL_IO_MEM) ||
696 (ser->baud_base != port->uartclk) ||
697 (ser->iomem_base != (void *)port->mapbase) ||
698 (ser->hub6 != 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 return -EINVAL;
700
701 return 0;
702}
703
704
705static struct uart_ops mpc52xx_uart_ops = {
706 .tx_empty = mpc52xx_uart_tx_empty,
707 .set_mctrl = mpc52xx_uart_set_mctrl,
708 .get_mctrl = mpc52xx_uart_get_mctrl,
709 .stop_tx = mpc52xx_uart_stop_tx,
710 .start_tx = mpc52xx_uart_start_tx,
711 .send_xchar = mpc52xx_uart_send_xchar,
712 .stop_rx = mpc52xx_uart_stop_rx,
713 .enable_ms = mpc52xx_uart_enable_ms,
714 .break_ctl = mpc52xx_uart_break_ctl,
715 .startup = mpc52xx_uart_startup,
716 .shutdown = mpc52xx_uart_shutdown,
717 .set_termios = mpc52xx_uart_set_termios,
718/* .pm = mpc52xx_uart_pm, Not supported yet */
719/* .set_wake = mpc52xx_uart_set_wake, Not supported yet */
720 .type = mpc52xx_uart_type,
721 .release_port = mpc52xx_uart_release_port,
722 .request_port = mpc52xx_uart_request_port,
723 .config_port = mpc52xx_uart_config_port,
724 .verify_port = mpc52xx_uart_verify_port
725};
726
Grant Likely9b9129e2006-11-27 14:21:01 -0700727
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728/* ======================================================================== */
729/* Interrupt handling */
730/* ======================================================================== */
Grant Likely9b9129e2006-11-27 14:21:01 -0700731
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732static inline int
David Howells7d12e782006-10-05 14:55:46 +0100733mpc52xx_uart_int_rx_chars(struct uart_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734{
Takashi Iwaia88487c2008-07-16 21:54:42 +0100735 struct tty_struct *tty = port->info->port.tty;
Alan Cox33f0f882006-01-09 20:54:13 -0800736 unsigned char ch, flag;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 unsigned short status;
738
739 /* While we can read, do so ! */
John Rigby599f0302008-01-29 04:28:55 +1100740 while (psc_ops->raw_rx_rdy(port)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 /* Get the char */
John Rigby599f0302008-01-29 04:28:55 +1100742 ch = psc_ops->read_char(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743
744 /* Handle sysreq char */
745#ifdef SUPPORT_SYSRQ
David Howells7d12e782006-10-05 14:55:46 +0100746 if (uart_handle_sysrq_char(port, ch)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 port->sysrq = 0;
748 continue;
749 }
750#endif
751
752 /* Store it */
Alan Cox33f0f882006-01-09 20:54:13 -0800753
754 flag = TTY_NORMAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 port->icount.rx++;
Grant Likely9b9129e2006-11-27 14:21:01 -0700756
John Rigby599f0302008-01-29 04:28:55 +1100757 status = in_be16(&PSC(port)->mpc52xx_psc_status);
758
John Rigby406b7d42008-01-17 08:37:25 +1100759 if (status & (MPC52xx_PSC_SR_PE |
760 MPC52xx_PSC_SR_FE |
761 MPC52xx_PSC_SR_RB)) {
Grant Likely9b9129e2006-11-27 14:21:01 -0700762
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 if (status & MPC52xx_PSC_SR_RB) {
Alan Cox33f0f882006-01-09 20:54:13 -0800764 flag = TTY_BREAK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 uart_handle_break(port);
766 } else if (status & MPC52xx_PSC_SR_PE)
Alan Cox33f0f882006-01-09 20:54:13 -0800767 flag = TTY_PARITY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 else if (status & MPC52xx_PSC_SR_FE)
Alan Cox33f0f882006-01-09 20:54:13 -0800769 flag = TTY_FRAME;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770
771 /* Clear error condition */
John Rigby406b7d42008-01-17 08:37:25 +1100772 out_8(&PSC(port)->command, MPC52xx_PSC_RST_ERR_STAT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773
774 }
Alan Cox33f0f882006-01-09 20:54:13 -0800775 tty_insert_flip_char(tty, ch, flag);
776 if (status & MPC52xx_PSC_SR_OE) {
777 /*
778 * Overrun is special, since it's
779 * reported immediately, and doesn't
780 * affect the current character
781 */
782 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
783 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 }
785
Andrew Liufbe543b2008-04-29 17:36:25 +1000786 spin_unlock(&port->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 tty_flip_buffer_push(tty);
Andrew Liufbe543b2008-04-29 17:36:25 +1000788 spin_lock(&port->lock);
Grant Likely9b9129e2006-11-27 14:21:01 -0700789
John Rigby599f0302008-01-29 04:28:55 +1100790 return psc_ops->raw_rx_rdy(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791}
792
793static inline int
794mpc52xx_uart_int_tx_chars(struct uart_port *port)
795{
796 struct circ_buf *xmit = &port->info->xmit;
797
798 /* Process out of band chars */
799 if (port->x_char) {
John Rigby599f0302008-01-29 04:28:55 +1100800 psc_ops->write_char(port, port->x_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 port->icount.tx++;
802 port->x_char = 0;
803 return 1;
804 }
805
806 /* Nothing to do ? */
807 if (uart_circ_empty(xmit) || uart_tx_stopped(port)) {
Russell Kingb129a8c2005-08-31 10:12:14 +0100808 mpc52xx_uart_stop_tx(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 return 0;
810 }
811
812 /* Send chars */
John Rigby599f0302008-01-29 04:28:55 +1100813 while (psc_ops->raw_tx_rdy(port)) {
814 psc_ops->write_char(port, xmit->buf[xmit->tail]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
816 port->icount.tx++;
817 if (uart_circ_empty(xmit))
818 break;
819 }
820
821 /* Wake up */
822 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
823 uart_write_wakeup(port);
824
825 /* Maybe we're done after all */
826 if (uart_circ_empty(xmit)) {
Russell Kingb129a8c2005-08-31 10:12:14 +0100827 mpc52xx_uart_stop_tx(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 return 0;
829 }
830
831 return 1;
832}
833
Grant Likely9b9129e2006-11-27 14:21:01 -0700834static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +0100835mpc52xx_uart_int(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836{
Jeff Garzikc7bec5a2006-10-06 15:00:58 -0400837 struct uart_port *port = dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 unsigned long pass = ISR_PASS_LIMIT;
839 unsigned int keepgoing;
Grant Likely9b9129e2006-11-27 14:21:01 -0700840
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 spin_lock(&port->lock);
Grant Likely9b9129e2006-11-27 14:21:01 -0700842
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 /* While we have stuff to do, we continue */
844 do {
845 /* If we don't find anything to do, we stop */
Grant Likely9b9129e2006-11-27 14:21:01 -0700846 keepgoing = 0;
847
John Rigby599f0302008-01-29 04:28:55 +1100848 psc_ops->rx_clr_irq(port);
849 if (psc_ops->rx_rdy(port))
David Howells7d12e782006-10-05 14:55:46 +0100850 keepgoing |= mpc52xx_uart_int_rx_chars(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851
John Rigby599f0302008-01-29 04:28:55 +1100852 psc_ops->tx_clr_irq(port);
853 if (psc_ops->tx_rdy(port))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 keepgoing |= mpc52xx_uart_int_tx_chars(port);
Grant Likely9b9129e2006-11-27 14:21:01 -0700855
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 /* Limit number of iteration */
John Rigby406b7d42008-01-17 08:37:25 +1100857 if (!(--pass))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 keepgoing = 0;
859
860 } while (keepgoing);
Grant Likely9b9129e2006-11-27 14:21:01 -0700861
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 spin_unlock(&port->lock);
Grant Likely9b9129e2006-11-27 14:21:01 -0700863
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 return IRQ_HANDLED;
865}
866
867
868/* ======================================================================== */
869/* Console ( if applicable ) */
870/* ======================================================================== */
871
872#ifdef CONFIG_SERIAL_MPC52xx_CONSOLE
873
874static void __init
875mpc52xx_console_get_options(struct uart_port *port,
John Rigby406b7d42008-01-17 08:37:25 +1100876 int *baud, int *parity, int *bits, int *flow)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877{
878 struct mpc52xx_psc __iomem *psc = PSC(port);
879 unsigned char mr1;
880
Grant Likelyb9272df2006-11-27 14:21:02 -0700881 pr_debug("mpc52xx_console_get_options(port=%p)\n", port);
882
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 /* Read the mode registers */
John Rigby406b7d42008-01-17 08:37:25 +1100884 out_8(&psc->command, MPC52xx_PSC_SEL_MODE_REG_1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 mr1 = in_8(&psc->mode);
Grant Likely9b9129e2006-11-27 14:21:01 -0700886
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 /* CT{U,L}R are write-only ! */
Grant Likelyb9272df2006-11-27 14:21:02 -0700888 *baud = CONFIG_SERIAL_MPC52xx_CONSOLE_BAUD;
889#if !defined(CONFIG_PPC_MERGE)
890 if (__res.bi_baudrate)
891 *baud = __res.bi_baudrate;
892#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893
894 /* Parse them */
895 switch (mr1 & MPC52xx_PSC_MODE_BITS_MASK) {
John Rigby406b7d42008-01-17 08:37:25 +1100896 case MPC52xx_PSC_MODE_5_BITS:
897 *bits = 5;
898 break;
899 case MPC52xx_PSC_MODE_6_BITS:
900 *bits = 6;
901 break;
902 case MPC52xx_PSC_MODE_7_BITS:
903 *bits = 7;
904 break;
905 case MPC52xx_PSC_MODE_8_BITS:
906 default:
907 *bits = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 }
Grant Likely9b9129e2006-11-27 14:21:01 -0700909
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 if (mr1 & MPC52xx_PSC_MODE_PARNONE)
911 *parity = 'n';
912 else
913 *parity = mr1 & MPC52xx_PSC_MODE_PARODD ? 'o' : 'e';
914}
915
Grant Likely9b9129e2006-11-27 14:21:01 -0700916static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917mpc52xx_console_write(struct console *co, const char *s, unsigned int count)
918{
919 struct uart_port *port = &mpc52xx_uart_ports[co->index];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 unsigned int i, j;
Grant Likely9b9129e2006-11-27 14:21:01 -0700921
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 /* Disable interrupts */
John Rigby599f0302008-01-29 04:28:55 +1100923 psc_ops->cw_disable_ints(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924
925 /* Wait the TX buffer to be empty */
Grant Likely9b9129e2006-11-27 14:21:01 -0700926 j = 5000000; /* Maximum wait */
John Rigby599f0302008-01-29 04:28:55 +1100927 while (!mpc52xx_uart_tx_empty(port) && --j)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 udelay(1);
929
930 /* Write all the chars */
Russell Kingd3587882006-03-20 20:00:09 +0000931 for (i = 0; i < count; i++, s++) {
932 /* Line return handling */
933 if (*s == '\n')
John Rigby599f0302008-01-29 04:28:55 +1100934 psc_ops->write_char(port, '\r');
Grant Likely9b9129e2006-11-27 14:21:01 -0700935
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 /* Send the char */
John Rigby599f0302008-01-29 04:28:55 +1100937 psc_ops->write_char(port, *s);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 /* Wait the TX buffer to be empty */
Grant Likely9b9129e2006-11-27 14:21:01 -0700940 j = 20000; /* Maximum wait */
John Rigby599f0302008-01-29 04:28:55 +1100941 while (!mpc52xx_uart_tx_empty(port) && --j)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 udelay(1);
943 }
944
945 /* Restore interrupt state */
John Rigby599f0302008-01-29 04:28:55 +1100946 psc_ops->cw_restore_ints(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947}
948
Grant Likelyb9272df2006-11-27 14:21:02 -0700949#if !defined(CONFIG_PPC_MERGE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950static int __init
951mpc52xx_console_setup(struct console *co, char *options)
952{
953 struct uart_port *port = &mpc52xx_uart_ports[co->index];
954
955 int baud = CONFIG_SERIAL_MPC52xx_CONSOLE_BAUD;
956 int bits = 8;
957 int parity = 'n';
958 int flow = 'n';
959
960 if (co->index < 0 || co->index >= MPC52xx_PSC_MAXNUM)
961 return -EINVAL;
Grant Likely9b9129e2006-11-27 14:21:01 -0700962
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 /* Basic port init. Needed since we use some uart_??? func before
964 * real init for early access */
965 spin_lock_init(&port->lock);
966 port->uartclk = __res.bi_ipbfreq / 2; /* Look at CTLR doc */
967 port->ops = &mpc52xx_uart_ops;
968 port->mapbase = MPC52xx_PA(MPC52xx_PSCx_OFFSET(co->index+1));
969
970 /* We ioremap ourself */
971 port->membase = ioremap(port->mapbase, MPC52xx_PSC_SIZE);
972 if (port->membase == NULL)
973 return -EINVAL;
974
975 /* Setup the port parameters accoding to options */
976 if (options)
977 uart_parse_options(options, &baud, &parity, &bits, &flow);
978 else
979 mpc52xx_console_get_options(port, &baud, &parity, &bits, &flow);
980
981 return uart_set_options(port, co, baud, parity, bits, flow);
982}
983
Grant Likelyb9272df2006-11-27 14:21:02 -0700984#else
985
986static int __init
987mpc52xx_console_setup(struct console *co, char *options)
988{
989 struct uart_port *port = &mpc52xx_uart_ports[co->index];
990 struct device_node *np = mpc52xx_uart_nodes[co->index];
John Rigby599f0302008-01-29 04:28:55 +1100991 unsigned int uartclk;
Grant Likelyb9272df2006-11-27 14:21:02 -0700992 struct resource res;
993 int ret;
994
995 int baud = CONFIG_SERIAL_MPC52xx_CONSOLE_BAUD;
996 int bits = 8;
997 int parity = 'n';
998 int flow = 'n';
999
1000 pr_debug("mpc52xx_console_setup co=%p, co->index=%i, options=%s\n",
1001 co, co->index, options);
1002
1003 if ((co->index < 0) || (co->index > MPC52xx_PSC_MAXNUM)) {
1004 pr_debug("PSC%x out of range\n", co->index);
1005 return -EINVAL;
1006 }
1007
1008 if (!np) {
1009 pr_debug("PSC%x not found in device tree\n", co->index);
1010 return -EINVAL;
1011 }
1012
1013 pr_debug("Console on ttyPSC%x is %s\n",
John Rigby406b7d42008-01-17 08:37:25 +11001014 co->index, mpc52xx_uart_nodes[co->index]->full_name);
Grant Likelyb9272df2006-11-27 14:21:02 -07001015
1016 /* Fetch register locations */
John Rigby406b7d42008-01-17 08:37:25 +11001017 ret = of_address_to_resource(np, 0, &res);
1018 if (ret) {
Grant Likelyb9272df2006-11-27 14:21:02 -07001019 pr_debug("Could not get resources for PSC%x\n", co->index);
1020 return ret;
1021 }
1022
John Rigby599f0302008-01-29 04:28:55 +11001023 uartclk = psc_ops->getuartclk(np);
1024 if (uartclk == 0) {
1025 pr_debug("Could not find uart clock frequency!\n");
Grant Likelyb9272df2006-11-27 14:21:02 -07001026 return -EINVAL;
1027 }
1028
1029 /* Basic port init. Needed since we use some uart_??? func before
1030 * real init for early access */
1031 spin_lock_init(&port->lock);
John Rigby599f0302008-01-29 04:28:55 +11001032 port->uartclk = uartclk;
Grant Likelyb9272df2006-11-27 14:21:02 -07001033 port->ops = &mpc52xx_uart_ops;
1034 port->mapbase = res.start;
1035 port->membase = ioremap(res.start, sizeof(struct mpc52xx_psc));
1036 port->irq = irq_of_parse_and_map(np, 0);
1037
1038 if (port->membase == NULL)
1039 return -EINVAL;
1040
Grant Likely5dd80d52007-10-13 22:37:02 -06001041 pr_debug("mpc52xx-psc uart at %p, mapped to %p, irq=%x, freq=%i\n",
John Rigby406b7d42008-01-17 08:37:25 +11001042 (void *)port->mapbase, port->membase,
1043 port->irq, port->uartclk);
Grant Likelyb9272df2006-11-27 14:21:02 -07001044
1045 /* Setup the port parameters accoding to options */
1046 if (options)
1047 uart_parse_options(options, &baud, &parity, &bits, &flow);
1048 else
1049 mpc52xx_console_get_options(port, &baud, &parity, &bits, &flow);
1050
1051 pr_debug("Setting console parameters: %i %i%c1 flow=%c\n",
John Rigby406b7d42008-01-17 08:37:25 +11001052 baud, bits, parity, flow);
Grant Likelyb9272df2006-11-27 14:21:02 -07001053
1054 return uart_set_options(port, co, baud, parity, bits, flow);
1055}
1056#endif /* defined(CONFIG_PPC_MERGE) */
1057
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058
Sylvain Munaut2d8179c2006-01-06 00:11:31 -08001059static struct uart_driver mpc52xx_uart_driver;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060
1061static struct console mpc52xx_console = {
Sylvain Munautd62de3a2006-01-06 00:11:32 -08001062 .name = "ttyPSC",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 .write = mpc52xx_console_write,
1064 .device = uart_console_device,
1065 .setup = mpc52xx_console_setup,
1066 .flags = CON_PRINTBUFFER,
John Rigby406b7d42008-01-17 08:37:25 +11001067 .index = -1, /* Specified on the cmdline (e.g. console=ttyPSC0) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 .data = &mpc52xx_uart_driver,
1069};
1070
Grant Likely9b9129e2006-11-27 14:21:01 -07001071
1072static int __init
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073mpc52xx_console_init(void)
1074{
Grant Likelyc98750c2007-01-02 15:45:37 -07001075#if defined(CONFIG_PPC_MERGE)
Grant Likelyb9272df2006-11-27 14:21:02 -07001076 mpc52xx_uart_of_enumerate();
Grant Likelyc98750c2007-01-02 15:45:37 -07001077#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 register_console(&mpc52xx_console);
1079 return 0;
1080}
1081
1082console_initcall(mpc52xx_console_init);
1083
1084#define MPC52xx_PSC_CONSOLE &mpc52xx_console
1085#else
1086#define MPC52xx_PSC_CONSOLE NULL
1087#endif
1088
1089
1090/* ======================================================================== */
1091/* UART Driver */
1092/* ======================================================================== */
1093
1094static struct uart_driver mpc52xx_uart_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 .driver_name = "mpc52xx_psc_uart",
Sylvain Munautd62de3a2006-01-06 00:11:32 -08001096 .dev_name = "ttyPSC",
Sylvain Munautd62de3a2006-01-06 00:11:32 -08001097 .major = SERIAL_PSC_MAJOR,
1098 .minor = SERIAL_PSC_MINOR,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 .nr = MPC52xx_PSC_MAXNUM,
1100 .cons = MPC52xx_PSC_CONSOLE,
1101};
1102
1103
Grant Likelyb9272df2006-11-27 14:21:02 -07001104#if !defined(CONFIG_PPC_MERGE)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105/* ======================================================================== */
1106/* Platform Driver */
1107/* ======================================================================== */
1108
1109static int __devinit
Russell King3ae5eae2005-11-09 22:32:44 +00001110mpc52xx_uart_probe(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111{
Russell King3ae5eae2005-11-09 22:32:44 +00001112 struct resource *res = dev->resource;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113
1114 struct uart_port *port = NULL;
1115 int i, idx, ret;
1116
1117 /* Check validity & presence */
Andrey Volkov38801e22005-11-12 22:04:06 +00001118 idx = dev->id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 if (idx < 0 || idx >= MPC52xx_PSC_MAXNUM)
1120 return -EINVAL;
1121
John Rigby406b7d42008-01-17 08:37:25 +11001122 if (!mpc52xx_match_psc_function(idx, "uart"))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 return -ENODEV;
1124
1125 /* Init the port structure */
1126 port = &mpc52xx_uart_ports[idx];
1127
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 spin_lock_init(&port->lock);
1129 port->uartclk = __res.bi_ipbfreq / 2; /* Look at CTLR doc */
Russell King947deee2006-07-02 20:45:51 +01001130 port->fifosize = 512;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 port->iotype = UPIO_MEM;
1132 port->flags = UPF_BOOT_AUTOCONF |
John Rigby406b7d42008-01-17 08:37:25 +11001133 (uart_console(port) ? 0 : UPF_IOREMAP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134 port->line = idx;
1135 port->ops = &mpc52xx_uart_ops;
Grant Likelyb9272df2006-11-27 14:21:02 -07001136 port->dev = &dev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137
1138 /* Search for IRQ and mapbase */
John Rigby406b7d42008-01-17 08:37:25 +11001139 for (i = 0 ; i < dev->num_resources ; i++, res++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 if (res->flags & IORESOURCE_MEM)
1141 port->mapbase = res->start;
1142 else if (res->flags & IORESOURCE_IRQ)
1143 port->irq = res->start;
1144 }
1145 if (!port->irq || !port->mapbase)
1146 return -EINVAL;
1147
1148 /* Add the port to the uart sub-system */
1149 ret = uart_add_one_port(&mpc52xx_uart_driver, port);
1150 if (!ret)
John Rigby406b7d42008-01-17 08:37:25 +11001151 platform_set_drvdata(dev, (void *)port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152
1153 return ret;
1154}
1155
1156static int
Russell King3ae5eae2005-11-09 22:32:44 +00001157mpc52xx_uart_remove(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158{
Russell King3ae5eae2005-11-09 22:32:44 +00001159 struct uart_port *port = (struct uart_port *) platform_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160
Russell King3ae5eae2005-11-09 22:32:44 +00001161 platform_set_drvdata(dev, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162
1163 if (port)
1164 uart_remove_one_port(&mpc52xx_uart_driver, port);
1165
1166 return 0;
1167}
1168
1169#ifdef CONFIG_PM
1170static int
Russell King3ae5eae2005-11-09 22:32:44 +00001171mpc52xx_uart_suspend(struct platform_device *dev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172{
Russell King3ae5eae2005-11-09 22:32:44 +00001173 struct uart_port *port = (struct uart_port *) platform_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174
Grant Likely9b9129e2006-11-27 14:21:01 -07001175 if (port)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176 uart_suspend_port(&mpc52xx_uart_driver, port);
1177
1178 return 0;
1179}
1180
1181static int
Russell King3ae5eae2005-11-09 22:32:44 +00001182mpc52xx_uart_resume(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183{
Russell King3ae5eae2005-11-09 22:32:44 +00001184 struct uart_port *port = (struct uart_port *) platform_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185
Russell King9480e302005-10-28 09:52:56 -07001186 if (port)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 uart_resume_port(&mpc52xx_uart_driver, port);
1188
1189 return 0;
1190}
1191#endif
1192
Kay Sieverse169c132008-04-15 14:34:35 -07001193/* work with hotplug and coldplug */
1194MODULE_ALIAS("platform:mpc52xx-psc");
Grant Likelyb9272df2006-11-27 14:21:02 -07001195
Russell King3ae5eae2005-11-09 22:32:44 +00001196static struct platform_driver mpc52xx_uart_platform_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197 .probe = mpc52xx_uart_probe,
1198 .remove = mpc52xx_uart_remove,
1199#ifdef CONFIG_PM
1200 .suspend = mpc52xx_uart_suspend,
1201 .resume = mpc52xx_uart_resume,
1202#endif
Russell King3ae5eae2005-11-09 22:32:44 +00001203 .driver = {
John Rigby406b7d42008-01-17 08:37:25 +11001204 .owner = THIS_MODULE,
Russell King3ae5eae2005-11-09 22:32:44 +00001205 .name = "mpc52xx-psc",
1206 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207};
Grant Likelyb9272df2006-11-27 14:21:02 -07001208#endif /* !defined(CONFIG_PPC_MERGE) */
1209
1210
1211#if defined(CONFIG_PPC_MERGE)
1212/* ======================================================================== */
1213/* OF Platform Driver */
1214/* ======================================================================== */
1215
Grant Likely52b80482008-02-06 22:29:25 -07001216static struct of_device_id mpc52xx_uart_of_match[] = {
1217#ifdef CONFIG_PPC_MPC52xx
1218 { .compatible = "fsl,mpc5200-psc-uart", .data = &mpc52xx_psc_ops, },
1219 /* binding used by old lite5200 device trees: */
1220 { .compatible = "mpc5200-psc-uart", .data = &mpc52xx_psc_ops, },
1221 /* binding used by efika: */
1222 { .compatible = "mpc5200-serial", .data = &mpc52xx_psc_ops, },
1223#endif
1224#ifdef CONFIG_PPC_MPC512x
1225 { .compatible = "fsl,mpc5121-psc-uart", .data = &mpc512x_psc_ops, },
Grant Likely52b80482008-02-06 22:29:25 -07001226#endif
Grant Likelybc775ea2008-04-29 06:40:37 -06001227 {},
Grant Likely52b80482008-02-06 22:29:25 -07001228};
1229
Grant Likelyb9272df2006-11-27 14:21:02 -07001230static int __devinit
1231mpc52xx_uart_of_probe(struct of_device *op, const struct of_device_id *match)
1232{
1233 int idx = -1;
John Rigby599f0302008-01-29 04:28:55 +11001234 unsigned int uartclk;
Grant Likelyb9272df2006-11-27 14:21:02 -07001235 struct uart_port *port = NULL;
1236 struct resource res;
1237 int ret;
1238
1239 dev_dbg(&op->dev, "mpc52xx_uart_probe(op=%p, match=%p)\n", op, match);
1240
1241 /* Check validity & presence */
1242 for (idx = 0; idx < MPC52xx_PSC_MAXNUM; idx++)
1243 if (mpc52xx_uart_nodes[idx] == op->node)
1244 break;
1245 if (idx >= MPC52xx_PSC_MAXNUM)
1246 return -EINVAL;
1247 pr_debug("Found %s assigned to ttyPSC%x\n",
John Rigby406b7d42008-01-17 08:37:25 +11001248 mpc52xx_uart_nodes[idx]->full_name, idx);
Grant Likelyb9272df2006-11-27 14:21:02 -07001249
John Rigby599f0302008-01-29 04:28:55 +11001250 uartclk = psc_ops->getuartclk(op->node);
1251 if (uartclk == 0) {
1252 dev_dbg(&op->dev, "Could not find uart clock frequency!\n");
Grant Likelyb9272df2006-11-27 14:21:02 -07001253 return -EINVAL;
1254 }
1255
1256 /* Init the port structure */
1257 port = &mpc52xx_uart_ports[idx];
1258
1259 spin_lock_init(&port->lock);
John Rigby599f0302008-01-29 04:28:55 +11001260 port->uartclk = uartclk;
Grant Likelyb9272df2006-11-27 14:21:02 -07001261 port->fifosize = 512;
1262 port->iotype = UPIO_MEM;
1263 port->flags = UPF_BOOT_AUTOCONF |
John Rigby406b7d42008-01-17 08:37:25 +11001264 (uart_console(port) ? 0 : UPF_IOREMAP);
Grant Likelyb9272df2006-11-27 14:21:02 -07001265 port->line = idx;
1266 port->ops = &mpc52xx_uart_ops;
1267 port->dev = &op->dev;
1268
1269 /* Search for IRQ and mapbase */
John Rigby406b7d42008-01-17 08:37:25 +11001270 ret = of_address_to_resource(op->node, 0, &res);
1271 if (ret)
Grant Likelyb9272df2006-11-27 14:21:02 -07001272 return ret;
1273
1274 port->mapbase = res.start;
1275 port->irq = irq_of_parse_and_map(op->node, 0);
1276
Grant Likely5dd80d52007-10-13 22:37:02 -06001277 dev_dbg(&op->dev, "mpc52xx-psc uart at %p, irq=%x, freq=%i\n",
John Rigby406b7d42008-01-17 08:37:25 +11001278 (void *)port->mapbase, port->irq, port->uartclk);
Grant Likelyb9272df2006-11-27 14:21:02 -07001279
John Rigby406b7d42008-01-17 08:37:25 +11001280 if ((port->irq == NO_IRQ) || !port->mapbase) {
Grant Likelyb9272df2006-11-27 14:21:02 -07001281 printk(KERN_ERR "Could not allocate resources for PSC\n");
1282 return -EINVAL;
1283 }
1284
1285 /* Add the port to the uart sub-system */
1286 ret = uart_add_one_port(&mpc52xx_uart_driver, port);
1287 if (!ret)
John Rigby406b7d42008-01-17 08:37:25 +11001288 dev_set_drvdata(&op->dev, (void *)port);
Grant Likelyb9272df2006-11-27 14:21:02 -07001289
1290 return ret;
1291}
1292
1293static int
1294mpc52xx_uart_of_remove(struct of_device *op)
1295{
1296 struct uart_port *port = dev_get_drvdata(&op->dev);
1297 dev_set_drvdata(&op->dev, NULL);
1298
Sylvain Munautfc7900b2007-02-15 23:18:08 +01001299 if (port) {
Grant Likelyb9272df2006-11-27 14:21:02 -07001300 uart_remove_one_port(&mpc52xx_uart_driver, port);
Sylvain Munautfc7900b2007-02-15 23:18:08 +01001301 irq_dispose_mapping(port->irq);
1302 }
Grant Likelyb9272df2006-11-27 14:21:02 -07001303
1304 return 0;
1305}
1306
1307#ifdef CONFIG_PM
1308static int
1309mpc52xx_uart_of_suspend(struct of_device *op, pm_message_t state)
1310{
1311 struct uart_port *port = (struct uart_port *) dev_get_drvdata(&op->dev);
1312
1313 if (port)
1314 uart_suspend_port(&mpc52xx_uart_driver, port);
1315
1316 return 0;
1317}
1318
1319static int
1320mpc52xx_uart_of_resume(struct of_device *op)
1321{
1322 struct uart_port *port = (struct uart_port *) dev_get_drvdata(&op->dev);
1323
1324 if (port)
1325 uart_resume_port(&mpc52xx_uart_driver, port);
1326
1327 return 0;
1328}
1329#endif
1330
1331static void
1332mpc52xx_uart_of_assign(struct device_node *np, int idx)
1333{
1334 int free_idx = -1;
1335 int i;
1336
1337 /* Find the first free node */
1338 for (i = 0; i < MPC52xx_PSC_MAXNUM; i++) {
1339 if (mpc52xx_uart_nodes[i] == NULL) {
1340 free_idx = i;
1341 break;
1342 }
1343 }
1344
1345 if ((idx < 0) || (idx >= MPC52xx_PSC_MAXNUM))
1346 idx = free_idx;
1347
1348 if (idx < 0)
1349 return; /* No free slot; abort */
1350
John Rigby406b7d42008-01-17 08:37:25 +11001351 of_node_get(np);
Grant Likelyb9272df2006-11-27 14:21:02 -07001352 /* If the slot is already occupied, then swap slots */
1353 if (mpc52xx_uart_nodes[idx] && (free_idx != -1))
1354 mpc52xx_uart_nodes[free_idx] = mpc52xx_uart_nodes[idx];
John Rigbyaf6a9aa2007-05-23 11:30:55 -06001355 mpc52xx_uart_nodes[idx] = np;
Grant Likelyb9272df2006-11-27 14:21:02 -07001356}
1357
1358static void
1359mpc52xx_uart_of_enumerate(void)
1360{
John Rigby406b7d42008-01-17 08:37:25 +11001361 static int enum_done;
Grant Likelyb9272df2006-11-27 14:21:02 -07001362 struct device_node *np;
1363 const unsigned int *devno;
John Rigby25ae3a02008-01-29 04:28:56 +11001364 const struct of_device_id *match;
Grant Likelyb9272df2006-11-27 14:21:02 -07001365 int i;
1366
1367 if (enum_done)
1368 return;
1369
1370 for_each_node_by_type(np, "serial") {
John Rigby25ae3a02008-01-29 04:28:56 +11001371 match = of_match_node(mpc52xx_uart_of_match, np);
1372 if (!match)
Grant Likelyb9272df2006-11-27 14:21:02 -07001373 continue;
1374
John Rigby25ae3a02008-01-29 04:28:56 +11001375 psc_ops = match->data;
1376
Grant Likelyb9272df2006-11-27 14:21:02 -07001377 /* Is a particular device number requested? */
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10001378 devno = of_get_property(np, "port-number", NULL);
John Rigby406b7d42008-01-17 08:37:25 +11001379 mpc52xx_uart_of_assign(np, devno ? *devno : -1);
Grant Likelyb9272df2006-11-27 14:21:02 -07001380 }
1381
1382 enum_done = 1;
1383
1384 for (i = 0; i < MPC52xx_PSC_MAXNUM; i++) {
1385 if (mpc52xx_uart_nodes[i])
1386 pr_debug("%s assigned to ttyPSC%x\n",
John Rigby406b7d42008-01-17 08:37:25 +11001387 mpc52xx_uart_nodes[i]->full_name, i);
Grant Likelyb9272df2006-11-27 14:21:02 -07001388 }
1389}
1390
1391MODULE_DEVICE_TABLE(of, mpc52xx_uart_of_match);
1392
1393static struct of_platform_driver mpc52xx_uart_of_driver = {
Grant Likelyb9272df2006-11-27 14:21:02 -07001394 .match_table = mpc52xx_uart_of_match,
1395 .probe = mpc52xx_uart_of_probe,
1396 .remove = mpc52xx_uart_of_remove,
1397#ifdef CONFIG_PM
1398 .suspend = mpc52xx_uart_of_suspend,
1399 .resume = mpc52xx_uart_of_resume,
1400#endif
1401 .driver = {
1402 .name = "mpc52xx-psc-uart",
1403 },
1404};
1405#endif /* defined(CONFIG_PPC_MERGE) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406
1407
1408/* ======================================================================== */
1409/* Module */
1410/* ======================================================================== */
1411
1412static int __init
1413mpc52xx_uart_init(void)
1414{
1415 int ret;
1416
Grant Likelyb9272df2006-11-27 14:21:02 -07001417 printk(KERN_INFO "Serial: MPC52xx PSC UART driver\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418
John Rigby406b7d42008-01-17 08:37:25 +11001419 ret = uart_register_driver(&mpc52xx_uart_driver);
1420 if (ret) {
Grant Likelyb9272df2006-11-27 14:21:02 -07001421 printk(KERN_ERR "%s: uart_register_driver failed (%i)\n",
1422 __FILE__, ret);
1423 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 }
1425
Grant Likelyb9272df2006-11-27 14:21:02 -07001426#if defined(CONFIG_PPC_MERGE)
1427 mpc52xx_uart_of_enumerate();
1428
1429 ret = of_register_platform_driver(&mpc52xx_uart_of_driver);
1430 if (ret) {
1431 printk(KERN_ERR "%s: of_register_platform_driver failed (%i)\n",
1432 __FILE__, ret);
1433 uart_unregister_driver(&mpc52xx_uart_driver);
1434 return ret;
1435 }
1436#else
John Rigby25ae3a02008-01-29 04:28:56 +11001437 psc_ops = &mpc52xx_psc_ops;
Grant Likelyb9272df2006-11-27 14:21:02 -07001438 ret = platform_driver_register(&mpc52xx_uart_platform_driver);
1439 if (ret) {
1440 printk(KERN_ERR "%s: platform_driver_register failed (%i)\n",
1441 __FILE__, ret);
1442 uart_unregister_driver(&mpc52xx_uart_driver);
1443 return ret;
1444 }
1445#endif
1446
1447 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448}
1449
1450static void __exit
1451mpc52xx_uart_exit(void)
1452{
Grant Likelyb9272df2006-11-27 14:21:02 -07001453#if defined(CONFIG_PPC_MERGE)
1454 of_unregister_platform_driver(&mpc52xx_uart_of_driver);
1455#else
Russell King3ae5eae2005-11-09 22:32:44 +00001456 platform_driver_unregister(&mpc52xx_uart_platform_driver);
Grant Likelyb9272df2006-11-27 14:21:02 -07001457#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 uart_unregister_driver(&mpc52xx_uart_driver);
1459}
1460
1461
1462module_init(mpc52xx_uart_init);
1463module_exit(mpc52xx_uart_exit);
1464
1465MODULE_AUTHOR("Sylvain Munaut <tnt@246tNt.com>");
1466MODULE_DESCRIPTION("Freescale MPC52xx PSC UART");
1467MODULE_LICENSE("GPL");