Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * 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 Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 15 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | * Some of the code has been inspired/copied from the 2.4 code written |
| 17 | * by Dale Farnsworth <dfarnsworth@mvista.com>. |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 18 | * |
Grant Likely | b9272df | 2006-11-27 14:21:02 -0700 | [diff] [blame] | 19 | * Copyright (C) 2006 Secret Lab Technologies Ltd. |
| 20 | * Grant Likely <grant.likely@secretlab.ca> |
| 21 | * Copyright (C) 2004-2006 Sylvain Munaut <tnt@246tNt.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | * Copyright (C) 2003 MontaVista, Software, Inc. |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 23 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | * This file is licensed under the terms of the GNU General Public License |
| 25 | * version 2. This program is licensed "as is" without any warranty of any |
| 26 | * kind, whether express or implied. |
| 27 | */ |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 28 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | /* Platform device Usage : |
| 30 | * |
| 31 | * Since PSCs can have multiple function, the correct driver for each one |
| 32 | * is selected by calling mpc52xx_match_psc_function(...). The function |
| 33 | * handled by this driver is "uart". |
| 34 | * |
| 35 | * The driver init all necessary registers to place the PSC in uart mode without |
| 36 | * DCD. However, the pin multiplexing aren't changed and should be set either |
| 37 | * by the bootloader or in the platform init code. |
| 38 | * |
| 39 | * The idx field must be equal to the PSC index ( e.g. 0 for PSC1, 1 for PSC2, |
Sylvain Munaut | d62de3a | 2006-01-06 00:11:32 -0800 | [diff] [blame] | 40 | * and so on). So the PSC1 is mapped to /dev/ttyPSC0, PSC2 to /dev/ttyPSC1 and |
| 41 | * so on. But be warned, it's an ABSOLUTE REQUIREMENT ! This is needed mainly |
| 42 | * fpr the console code : without this 1:1 mapping, at early boot time, when we |
Uwe Zeisberger | c30fe7f | 2006-03-24 18:23:14 +0100 | [diff] [blame] | 43 | * are parsing the kernel args console=ttyPSC?, we wouldn't know which PSC it |
Sylvain Munaut | d62de3a | 2006-01-06 00:11:32 -0800 | [diff] [blame] | 44 | * will be mapped to. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | */ |
| 46 | |
Grant Likely | b9272df | 2006-11-27 14:21:02 -0700 | [diff] [blame] | 47 | /* OF Platform device Usage : |
| 48 | * |
| 49 | * This driver is only used for PSCs configured in uart mode. The device |
| 50 | * tree will have a node for each PSC in uart mode w/ device_type = "serial" |
| 51 | * and "mpc52xx-psc-uart" in the compatible string |
| 52 | * |
| 53 | * By default, PSC devices are enumerated in the order they are found. However |
| 54 | * a particular PSC number can be forces by adding 'device_no = <port#>' |
| 55 | * to the device node. |
| 56 | * |
| 57 | * The driver init all necessary registers to place the PSC in uart mode without |
| 58 | * DCD. However, the pin multiplexing aren't changed and should be set either |
| 59 | * by the bootloader or in the platform init code. |
| 60 | */ |
| 61 | |
| 62 | #undef DEBUG |
| 63 | |
| 64 | #include <linux/device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | #include <linux/module.h> |
| 66 | #include <linux/tty.h> |
| 67 | #include <linux/serial.h> |
| 68 | #include <linux/sysrq.h> |
| 69 | #include <linux/console.h> |
| 70 | |
| 71 | #include <asm/delay.h> |
| 72 | #include <asm/io.h> |
| 73 | |
Grant Likely | b9272df | 2006-11-27 14:21:02 -0700 | [diff] [blame] | 74 | #if defined(CONFIG_PPC_MERGE) |
Grant Likely | 283029d | 2008-01-09 06:20:40 +1100 | [diff] [blame] | 75 | #include <linux/of.h> |
| 76 | #include <linux/of_platform.h> |
Grant Likely | b9272df | 2006-11-27 14:21:02 -0700 | [diff] [blame] | 77 | #else |
| 78 | #include <linux/platform_device.h> |
| 79 | #endif |
| 80 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | #include <asm/mpc52xx.h> |
| 82 | #include <asm/mpc52xx_psc.h> |
| 83 | |
| 84 | #if defined(CONFIG_SERIAL_MPC52xx_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) |
| 85 | #define SUPPORT_SYSRQ |
| 86 | #endif |
| 87 | |
| 88 | #include <linux/serial_core.h> |
| 89 | |
| 90 | |
Sylvain Munaut | d62de3a | 2006-01-06 00:11:32 -0800 | [diff] [blame] | 91 | /* We've been assigned a range on the "Low-density serial ports" major */ |
| 92 | #define SERIAL_PSC_MAJOR 204 |
| 93 | #define SERIAL_PSC_MINOR 148 |
| 94 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
| 96 | #define ISR_PASS_LIMIT 256 /* Max number of iteration in the interrupt */ |
| 97 | |
| 98 | |
| 99 | static struct uart_port mpc52xx_uart_ports[MPC52xx_PSC_MAXNUM]; |
| 100 | /* Rem: - We use the read_status_mask as a shadow of |
| 101 | * psc->mpc52xx_psc_imr |
| 102 | * - It's important that is array is all zero on start as we |
| 103 | * use it to know if it's initialized or not ! If it's not sure |
| 104 | * it's cleared, then a memset(...,0,...) should be added to |
| 105 | * the console_init |
| 106 | */ |
Grant Likely | b9272df | 2006-11-27 14:21:02 -0700 | [diff] [blame] | 107 | #if defined(CONFIG_PPC_MERGE) |
| 108 | /* lookup table for matching device nodes to index numbers */ |
| 109 | static struct device_node *mpc52xx_uart_nodes[MPC52xx_PSC_MAXNUM]; |
| 110 | |
| 111 | static void mpc52xx_uart_of_enumerate(void); |
| 112 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
| 114 | #define PSC(port) ((struct mpc52xx_psc __iomem *)((port)->membase)) |
John Rigby | 94f3894 | 2008-01-17 08:37:24 +1100 | [diff] [blame^] | 115 | #define FIFO(port) ((struct mpc52xx_psc_fifo __iomem *)(PSC(port)+1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | |
| 117 | |
| 118 | /* Forward declaration of the interruption handling routine */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 119 | static irqreturn_t mpc52xx_uart_int(int irq,void *dev_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | |
| 121 | |
| 122 | /* Simple macro to test if a port is console or not. This one is taken |
| 123 | * for serial_core.c and maybe should be moved to serial_core.h ? */ |
| 124 | #ifdef CONFIG_SERIAL_CORE_CONSOLE |
| 125 | #define uart_console(port) ((port)->cons && (port)->cons->index == (port)->line) |
| 126 | #else |
| 127 | #define uart_console(port) (0) |
| 128 | #endif |
| 129 | |
Grant Likely | b9272df | 2006-11-27 14:21:02 -0700 | [diff] [blame] | 130 | #if defined(CONFIG_PPC_MERGE) |
| 131 | static struct of_device_id mpc52xx_uart_of_match[] = { |
Grant Likely | e3aba81 | 2007-02-12 13:36:55 -0700 | [diff] [blame] | 132 | { .type = "serial", .compatible = "mpc5200-psc-uart", }, |
Grant Likely | b9272df | 2006-11-27 14:21:02 -0700 | [diff] [blame] | 133 | {}, |
| 134 | }; |
| 135 | #endif |
| 136 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
| 138 | /* ======================================================================== */ |
| 139 | /* UART operations */ |
| 140 | /* ======================================================================== */ |
| 141 | |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 142 | static unsigned int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | mpc52xx_uart_tx_empty(struct uart_port *port) |
| 144 | { |
| 145 | int status = in_be16(&PSC(port)->mpc52xx_psc_status); |
| 146 | return (status & MPC52xx_PSC_SR_TXEMP) ? TIOCSER_TEMT : 0; |
| 147 | } |
| 148 | |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 149 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | mpc52xx_uart_set_mctrl(struct uart_port *port, unsigned int mctrl) |
| 151 | { |
| 152 | /* Not implemented */ |
| 153 | } |
| 154 | |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 155 | static unsigned int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | mpc52xx_uart_get_mctrl(struct uart_port *port) |
| 157 | { |
| 158 | /* Not implemented */ |
| 159 | return TIOCM_CTS | TIOCM_DSR | TIOCM_CAR; |
| 160 | } |
| 161 | |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 162 | static void |
Russell King | b129a8c | 2005-08-31 10:12:14 +0100 | [diff] [blame] | 163 | mpc52xx_uart_stop_tx(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | { |
| 165 | /* port->lock taken by caller */ |
| 166 | port->read_status_mask &= ~MPC52xx_PSC_IMR_TXRDY; |
| 167 | out_be16(&PSC(port)->mpc52xx_psc_imr,port->read_status_mask); |
| 168 | } |
| 169 | |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 170 | static void |
Russell King | b129a8c | 2005-08-31 10:12:14 +0100 | [diff] [blame] | 171 | mpc52xx_uart_start_tx(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | { |
| 173 | /* port->lock taken by caller */ |
| 174 | port->read_status_mask |= MPC52xx_PSC_IMR_TXRDY; |
| 175 | out_be16(&PSC(port)->mpc52xx_psc_imr,port->read_status_mask); |
| 176 | } |
| 177 | |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 178 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | mpc52xx_uart_send_xchar(struct uart_port *port, char ch) |
| 180 | { |
| 181 | unsigned long flags; |
| 182 | spin_lock_irqsave(&port->lock, flags); |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 183 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | port->x_char = ch; |
| 185 | if (ch) { |
| 186 | /* Make sure tx interrupts are on */ |
| 187 | /* Truly necessary ??? They should be anyway */ |
| 188 | port->read_status_mask |= MPC52xx_PSC_IMR_TXRDY; |
| 189 | out_be16(&PSC(port)->mpc52xx_psc_imr,port->read_status_mask); |
| 190 | } |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 191 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | spin_unlock_irqrestore(&port->lock, flags); |
| 193 | } |
| 194 | |
| 195 | static void |
| 196 | mpc52xx_uart_stop_rx(struct uart_port *port) |
| 197 | { |
| 198 | /* port->lock taken by caller */ |
| 199 | port->read_status_mask &= ~MPC52xx_PSC_IMR_RXRDY; |
| 200 | out_be16(&PSC(port)->mpc52xx_psc_imr,port->read_status_mask); |
| 201 | } |
| 202 | |
| 203 | static void |
| 204 | mpc52xx_uart_enable_ms(struct uart_port *port) |
| 205 | { |
| 206 | /* Not implemented */ |
| 207 | } |
| 208 | |
| 209 | static void |
| 210 | mpc52xx_uart_break_ctl(struct uart_port *port, int ctl) |
| 211 | { |
| 212 | unsigned long flags; |
| 213 | spin_lock_irqsave(&port->lock, flags); |
| 214 | |
| 215 | if ( ctl == -1 ) |
| 216 | out_8(&PSC(port)->command,MPC52xx_PSC_START_BRK); |
| 217 | else |
| 218 | out_8(&PSC(port)->command,MPC52xx_PSC_STOP_BRK); |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 219 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | spin_unlock_irqrestore(&port->lock, flags); |
| 221 | } |
| 222 | |
| 223 | static int |
| 224 | mpc52xx_uart_startup(struct uart_port *port) |
| 225 | { |
| 226 | struct mpc52xx_psc __iomem *psc = PSC(port); |
John Rigby | 94f3894 | 2008-01-17 08:37:24 +1100 | [diff] [blame^] | 227 | struct mpc52xx_psc_fifo __iomem *fifo = FIFO(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | int ret; |
| 229 | |
| 230 | /* Request IRQ */ |
| 231 | ret = request_irq(port->irq, mpc52xx_uart_int, |
Thomas Gleixner | 40663cc | 2006-07-01 19:29:43 -0700 | [diff] [blame] | 232 | IRQF_DISABLED | IRQF_SAMPLE_RANDOM, "mpc52xx_psc_uart", port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | if (ret) |
| 234 | return ret; |
| 235 | |
| 236 | /* Reset/activate the port, clear and enable interrupts */ |
| 237 | out_8(&psc->command,MPC52xx_PSC_RST_RX); |
| 238 | out_8(&psc->command,MPC52xx_PSC_RST_TX); |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 239 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | out_be32(&psc->sicr,0); /* UART mode DCD ignored */ |
| 241 | |
| 242 | out_be16(&psc->mpc52xx_psc_clock_select, 0xdd00); /* /16 prescaler on */ |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 243 | |
John Rigby | 94f3894 | 2008-01-17 08:37:24 +1100 | [diff] [blame^] | 244 | out_8(&fifo->rfcntl, 0x00); |
| 245 | out_be16(&fifo->rfalarm, 0x1ff); |
| 246 | out_8(&fifo->tfcntl, 0x07); |
| 247 | out_be16(&fifo->tfalarm, 0x80); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | |
| 249 | port->read_status_mask |= MPC52xx_PSC_IMR_RXRDY | MPC52xx_PSC_IMR_TXRDY; |
| 250 | out_be16(&psc->mpc52xx_psc_imr,port->read_status_mask); |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 251 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | out_8(&psc->command,MPC52xx_PSC_TX_ENABLE); |
| 253 | out_8(&psc->command,MPC52xx_PSC_RX_ENABLE); |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 254 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | return 0; |
| 256 | } |
| 257 | |
| 258 | static void |
| 259 | mpc52xx_uart_shutdown(struct uart_port *port) |
| 260 | { |
| 261 | struct mpc52xx_psc __iomem *psc = PSC(port); |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 262 | |
Grant Likely | a348119 | 2007-05-07 01:38:51 +1000 | [diff] [blame] | 263 | /* Shut down the port. Leave TX active if on a console port */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | out_8(&psc->command,MPC52xx_PSC_RST_RX); |
Grant Likely | a348119 | 2007-05-07 01:38:51 +1000 | [diff] [blame] | 265 | if (!uart_console(port)) |
| 266 | out_8(&psc->command,MPC52xx_PSC_RST_TX); |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 267 | |
| 268 | port->read_status_mask = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | out_be16(&psc->mpc52xx_psc_imr,port->read_status_mask); |
| 270 | |
| 271 | /* Release interrupt */ |
| 272 | free_irq(port->irq, port); |
| 273 | } |
| 274 | |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 275 | static void |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 276 | mpc52xx_uart_set_termios(struct uart_port *port, struct ktermios *new, |
| 277 | struct ktermios *old) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | { |
| 279 | struct mpc52xx_psc __iomem *psc = PSC(port); |
| 280 | unsigned long flags; |
| 281 | unsigned char mr1, mr2; |
| 282 | unsigned short ctr; |
| 283 | unsigned int j, baud, quot; |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 284 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | /* Prepare what we're gonna write */ |
| 286 | mr1 = 0; |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 287 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | switch (new->c_cflag & CSIZE) { |
| 289 | case CS5: mr1 |= MPC52xx_PSC_MODE_5_BITS; |
| 290 | break; |
| 291 | case CS6: mr1 |= MPC52xx_PSC_MODE_6_BITS; |
| 292 | break; |
| 293 | case CS7: mr1 |= MPC52xx_PSC_MODE_7_BITS; |
| 294 | break; |
| 295 | case CS8: |
| 296 | default: mr1 |= MPC52xx_PSC_MODE_8_BITS; |
| 297 | } |
| 298 | |
| 299 | if (new->c_cflag & PARENB) { |
| 300 | mr1 |= (new->c_cflag & PARODD) ? |
| 301 | MPC52xx_PSC_MODE_PARODD : MPC52xx_PSC_MODE_PAREVEN; |
| 302 | } else |
| 303 | mr1 |= MPC52xx_PSC_MODE_PARNONE; |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 304 | |
| 305 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | mr2 = 0; |
| 307 | |
| 308 | if (new->c_cflag & CSTOPB) |
| 309 | mr2 |= MPC52xx_PSC_MODE_TWO_STOP; |
| 310 | else |
| 311 | mr2 |= ((new->c_cflag & CSIZE) == CS5) ? |
| 312 | MPC52xx_PSC_MODE_ONE_STOP_5_BITS : |
| 313 | MPC52xx_PSC_MODE_ONE_STOP; |
| 314 | |
| 315 | |
| 316 | baud = uart_get_baud_rate(port, new, old, 0, port->uartclk/16); |
| 317 | quot = uart_get_divisor(port, baud); |
| 318 | ctr = quot & 0xffff; |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 319 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | /* Get the lock */ |
| 321 | spin_lock_irqsave(&port->lock, flags); |
| 322 | |
| 323 | /* Update the per-port timeout */ |
| 324 | uart_update_timeout(port, new->c_cflag, baud); |
| 325 | |
| 326 | /* Do our best to flush TX & RX, so we don't loose anything */ |
| 327 | /* But we don't wait indefinitly ! */ |
| 328 | j = 5000000; /* Maximum wait */ |
| 329 | /* FIXME Can't receive chars since set_termios might be called at early |
| 330 | * boot for the console, all stuff is not yet ready to receive at that |
| 331 | * time and that just makes the kernel oops */ |
| 332 | /* while (j-- && mpc52xx_uart_int_rx_chars(port)); */ |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 333 | while (!(in_be16(&psc->mpc52xx_psc_status) & MPC52xx_PSC_SR_TXEMP) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | --j) |
| 335 | udelay(1); |
| 336 | |
| 337 | if (!j) |
| 338 | printk( KERN_ERR "mpc52xx_uart.c: " |
| 339 | "Unable to flush RX & TX fifos in-time in set_termios." |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 340 | "Some chars may have been lost.\n" ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | |
| 342 | /* Reset the TX & RX */ |
| 343 | out_8(&psc->command,MPC52xx_PSC_RST_RX); |
| 344 | out_8(&psc->command,MPC52xx_PSC_RST_TX); |
| 345 | |
| 346 | /* Send new mode settings */ |
| 347 | out_8(&psc->command,MPC52xx_PSC_SEL_MODE_REG_1); |
| 348 | out_8(&psc->mode,mr1); |
| 349 | out_8(&psc->mode,mr2); |
| 350 | out_8(&psc->ctur,ctr >> 8); |
| 351 | out_8(&psc->ctlr,ctr & 0xff); |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 352 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | /* Reenable TX & RX */ |
| 354 | out_8(&psc->command,MPC52xx_PSC_TX_ENABLE); |
| 355 | out_8(&psc->command,MPC52xx_PSC_RX_ENABLE); |
| 356 | |
| 357 | /* We're all set, release the lock */ |
| 358 | spin_unlock_irqrestore(&port->lock, flags); |
| 359 | } |
| 360 | |
| 361 | static const char * |
| 362 | mpc52xx_uart_type(struct uart_port *port) |
| 363 | { |
| 364 | return port->type == PORT_MPC52xx ? "MPC52xx PSC" : NULL; |
| 365 | } |
| 366 | |
| 367 | static void |
| 368 | mpc52xx_uart_release_port(struct uart_port *port) |
| 369 | { |
| 370 | if (port->flags & UPF_IOREMAP) { /* remapped by us ? */ |
| 371 | iounmap(port->membase); |
| 372 | port->membase = NULL; |
| 373 | } |
| 374 | |
Grant Likely | b9272df | 2006-11-27 14:21:02 -0700 | [diff] [blame] | 375 | release_mem_region(port->mapbase, sizeof(struct mpc52xx_psc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | static int |
| 379 | mpc52xx_uart_request_port(struct uart_port *port) |
| 380 | { |
Amol Lad | be618f5 | 2006-09-30 23:29:23 -0700 | [diff] [blame] | 381 | int err; |
| 382 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | if (port->flags & UPF_IOREMAP) /* Need to remap ? */ |
Grant Likely | b9272df | 2006-11-27 14:21:02 -0700 | [diff] [blame] | 384 | port->membase = ioremap(port->mapbase, |
| 385 | sizeof(struct mpc52xx_psc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | |
| 387 | if (!port->membase) |
| 388 | return -EINVAL; |
| 389 | |
Grant Likely | b9272df | 2006-11-27 14:21:02 -0700 | [diff] [blame] | 390 | err = request_mem_region(port->mapbase, sizeof(struct mpc52xx_psc), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | "mpc52xx_psc_uart") != NULL ? 0 : -EBUSY; |
Amol Lad | be618f5 | 2006-09-30 23:29:23 -0700 | [diff] [blame] | 392 | |
| 393 | if (err && (port->flags & UPF_IOREMAP)) { |
| 394 | iounmap(port->membase); |
| 395 | port->membase = NULL; |
| 396 | } |
| 397 | |
| 398 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | static void |
| 402 | mpc52xx_uart_config_port(struct uart_port *port, int flags) |
| 403 | { |
| 404 | if ( (flags & UART_CONFIG_TYPE) && |
| 405 | (mpc52xx_uart_request_port(port) == 0) ) |
| 406 | port->type = PORT_MPC52xx; |
| 407 | } |
| 408 | |
| 409 | static int |
| 410 | mpc52xx_uart_verify_port(struct uart_port *port, struct serial_struct *ser) |
| 411 | { |
| 412 | if ( ser->type != PORT_UNKNOWN && ser->type != PORT_MPC52xx ) |
| 413 | return -EINVAL; |
| 414 | |
| 415 | if ( (ser->irq != port->irq) || |
| 416 | (ser->io_type != SERIAL_IO_MEM) || |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 417 | (ser->baud_base != port->uartclk) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | (ser->iomem_base != (void*)port->mapbase) || |
| 419 | (ser->hub6 != 0 ) ) |
| 420 | return -EINVAL; |
| 421 | |
| 422 | return 0; |
| 423 | } |
| 424 | |
| 425 | |
| 426 | static struct uart_ops mpc52xx_uart_ops = { |
| 427 | .tx_empty = mpc52xx_uart_tx_empty, |
| 428 | .set_mctrl = mpc52xx_uart_set_mctrl, |
| 429 | .get_mctrl = mpc52xx_uart_get_mctrl, |
| 430 | .stop_tx = mpc52xx_uart_stop_tx, |
| 431 | .start_tx = mpc52xx_uart_start_tx, |
| 432 | .send_xchar = mpc52xx_uart_send_xchar, |
| 433 | .stop_rx = mpc52xx_uart_stop_rx, |
| 434 | .enable_ms = mpc52xx_uart_enable_ms, |
| 435 | .break_ctl = mpc52xx_uart_break_ctl, |
| 436 | .startup = mpc52xx_uart_startup, |
| 437 | .shutdown = mpc52xx_uart_shutdown, |
| 438 | .set_termios = mpc52xx_uart_set_termios, |
| 439 | /* .pm = mpc52xx_uart_pm, Not supported yet */ |
| 440 | /* .set_wake = mpc52xx_uart_set_wake, Not supported yet */ |
| 441 | .type = mpc52xx_uart_type, |
| 442 | .release_port = mpc52xx_uart_release_port, |
| 443 | .request_port = mpc52xx_uart_request_port, |
| 444 | .config_port = mpc52xx_uart_config_port, |
| 445 | .verify_port = mpc52xx_uart_verify_port |
| 446 | }; |
| 447 | |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 448 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | /* ======================================================================== */ |
| 450 | /* Interrupt handling */ |
| 451 | /* ======================================================================== */ |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 452 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | static inline int |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 454 | mpc52xx_uart_int_rx_chars(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | { |
| 456 | struct tty_struct *tty = port->info->tty; |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 457 | unsigned char ch, flag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | unsigned short status; |
| 459 | |
| 460 | /* While we can read, do so ! */ |
| 461 | while ( (status = in_be16(&PSC(port)->mpc52xx_psc_status)) & |
| 462 | MPC52xx_PSC_SR_RXRDY) { |
| 463 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | /* Get the char */ |
| 465 | ch = in_8(&PSC(port)->mpc52xx_psc_buffer_8); |
| 466 | |
| 467 | /* Handle sysreq char */ |
| 468 | #ifdef SUPPORT_SYSRQ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 469 | if (uart_handle_sysrq_char(port, ch)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | port->sysrq = 0; |
| 471 | continue; |
| 472 | } |
| 473 | #endif |
| 474 | |
| 475 | /* Store it */ |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 476 | |
| 477 | flag = TTY_NORMAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | port->icount.rx++; |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 479 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | if ( status & (MPC52xx_PSC_SR_PE | |
| 481 | MPC52xx_PSC_SR_FE | |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 482 | MPC52xx_PSC_SR_RB) ) { |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 483 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | if (status & MPC52xx_PSC_SR_RB) { |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 485 | flag = TTY_BREAK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | uart_handle_break(port); |
| 487 | } else if (status & MPC52xx_PSC_SR_PE) |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 488 | flag = TTY_PARITY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | else if (status & MPC52xx_PSC_SR_FE) |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 490 | flag = TTY_FRAME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | |
| 492 | /* Clear error condition */ |
| 493 | out_8(&PSC(port)->command,MPC52xx_PSC_RST_ERR_STAT); |
| 494 | |
| 495 | } |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 496 | tty_insert_flip_char(tty, ch, flag); |
| 497 | if (status & MPC52xx_PSC_SR_OE) { |
| 498 | /* |
| 499 | * Overrun is special, since it's |
| 500 | * reported immediately, and doesn't |
| 501 | * affect the current character |
| 502 | */ |
| 503 | tty_insert_flip_char(tty, 0, TTY_OVERRUN); |
| 504 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | tty_flip_buffer_push(tty); |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 508 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | return in_be16(&PSC(port)->mpc52xx_psc_status) & MPC52xx_PSC_SR_RXRDY; |
| 510 | } |
| 511 | |
| 512 | static inline int |
| 513 | mpc52xx_uart_int_tx_chars(struct uart_port *port) |
| 514 | { |
| 515 | struct circ_buf *xmit = &port->info->xmit; |
| 516 | |
| 517 | /* Process out of band chars */ |
| 518 | if (port->x_char) { |
| 519 | out_8(&PSC(port)->mpc52xx_psc_buffer_8, port->x_char); |
| 520 | port->icount.tx++; |
| 521 | port->x_char = 0; |
| 522 | return 1; |
| 523 | } |
| 524 | |
| 525 | /* Nothing to do ? */ |
| 526 | if (uart_circ_empty(xmit) || uart_tx_stopped(port)) { |
Russell King | b129a8c | 2005-08-31 10:12:14 +0100 | [diff] [blame] | 527 | mpc52xx_uart_stop_tx(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | return 0; |
| 529 | } |
| 530 | |
| 531 | /* Send chars */ |
| 532 | while (in_be16(&PSC(port)->mpc52xx_psc_status) & MPC52xx_PSC_SR_TXRDY) { |
| 533 | out_8(&PSC(port)->mpc52xx_psc_buffer_8, xmit->buf[xmit->tail]); |
| 534 | xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); |
| 535 | port->icount.tx++; |
| 536 | if (uart_circ_empty(xmit)) |
| 537 | break; |
| 538 | } |
| 539 | |
| 540 | /* Wake up */ |
| 541 | if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) |
| 542 | uart_write_wakeup(port); |
| 543 | |
| 544 | /* Maybe we're done after all */ |
| 545 | if (uart_circ_empty(xmit)) { |
Russell King | b129a8c | 2005-08-31 10:12:14 +0100 | [diff] [blame] | 546 | mpc52xx_uart_stop_tx(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | return 0; |
| 548 | } |
| 549 | |
| 550 | return 1; |
| 551 | } |
| 552 | |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 553 | static irqreturn_t |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 554 | mpc52xx_uart_int(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | { |
Jeff Garzik | c7bec5a | 2006-10-06 15:00:58 -0400 | [diff] [blame] | 556 | struct uart_port *port = dev_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | unsigned long pass = ISR_PASS_LIMIT; |
| 558 | unsigned int keepgoing; |
| 559 | unsigned short status; |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 560 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | spin_lock(&port->lock); |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 562 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | /* While we have stuff to do, we continue */ |
| 564 | do { |
| 565 | /* If we don't find anything to do, we stop */ |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 566 | keepgoing = 0; |
| 567 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | /* Read status */ |
| 569 | status = in_be16(&PSC(port)->mpc52xx_psc_isr); |
| 570 | status &= port->read_status_mask; |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 571 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | /* Do we need to receive chars ? */ |
| 573 | /* For this RX interrupts must be on and some chars waiting */ |
| 574 | if ( status & MPC52xx_PSC_IMR_RXRDY ) |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 575 | keepgoing |= mpc52xx_uart_int_rx_chars(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | |
| 577 | /* Do we need to send chars ? */ |
| 578 | /* For this, TX must be ready and TX interrupt enabled */ |
| 579 | if ( status & MPC52xx_PSC_IMR_TXRDY ) |
| 580 | keepgoing |= mpc52xx_uart_int_tx_chars(port); |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 581 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | /* Limit number of iteration */ |
| 583 | if ( !(--pass) ) |
| 584 | keepgoing = 0; |
| 585 | |
| 586 | } while (keepgoing); |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 587 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | spin_unlock(&port->lock); |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 589 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | return IRQ_HANDLED; |
| 591 | } |
| 592 | |
| 593 | |
| 594 | /* ======================================================================== */ |
| 595 | /* Console ( if applicable ) */ |
| 596 | /* ======================================================================== */ |
| 597 | |
| 598 | #ifdef CONFIG_SERIAL_MPC52xx_CONSOLE |
| 599 | |
| 600 | static void __init |
| 601 | mpc52xx_console_get_options(struct uart_port *port, |
| 602 | int *baud, int *parity, int *bits, int *flow) |
| 603 | { |
| 604 | struct mpc52xx_psc __iomem *psc = PSC(port); |
| 605 | unsigned char mr1; |
| 606 | |
Grant Likely | b9272df | 2006-11-27 14:21:02 -0700 | [diff] [blame] | 607 | pr_debug("mpc52xx_console_get_options(port=%p)\n", port); |
| 608 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | /* Read the mode registers */ |
| 610 | out_8(&psc->command,MPC52xx_PSC_SEL_MODE_REG_1); |
| 611 | mr1 = in_8(&psc->mode); |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 612 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | /* CT{U,L}R are write-only ! */ |
Grant Likely | b9272df | 2006-11-27 14:21:02 -0700 | [diff] [blame] | 614 | *baud = CONFIG_SERIAL_MPC52xx_CONSOLE_BAUD; |
| 615 | #if !defined(CONFIG_PPC_MERGE) |
| 616 | if (__res.bi_baudrate) |
| 617 | *baud = __res.bi_baudrate; |
| 618 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | |
| 620 | /* Parse them */ |
| 621 | switch (mr1 & MPC52xx_PSC_MODE_BITS_MASK) { |
| 622 | case MPC52xx_PSC_MODE_5_BITS: *bits = 5; break; |
| 623 | case MPC52xx_PSC_MODE_6_BITS: *bits = 6; break; |
| 624 | case MPC52xx_PSC_MODE_7_BITS: *bits = 7; break; |
| 625 | case MPC52xx_PSC_MODE_8_BITS: |
| 626 | default: *bits = 8; |
| 627 | } |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 628 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | if (mr1 & MPC52xx_PSC_MODE_PARNONE) |
| 630 | *parity = 'n'; |
| 631 | else |
| 632 | *parity = mr1 & MPC52xx_PSC_MODE_PARODD ? 'o' : 'e'; |
| 633 | } |
| 634 | |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 635 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | mpc52xx_console_write(struct console *co, const char *s, unsigned int count) |
| 637 | { |
| 638 | struct uart_port *port = &mpc52xx_uart_ports[co->index]; |
| 639 | struct mpc52xx_psc __iomem *psc = PSC(port); |
| 640 | unsigned int i, j; |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 641 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | /* Disable interrupts */ |
| 643 | out_be16(&psc->mpc52xx_psc_imr, 0); |
| 644 | |
| 645 | /* Wait the TX buffer to be empty */ |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 646 | j = 5000000; /* Maximum wait */ |
| 647 | while (!(in_be16(&psc->mpc52xx_psc_status) & MPC52xx_PSC_SR_TXEMP) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | --j) |
| 649 | udelay(1); |
| 650 | |
| 651 | /* Write all the chars */ |
Russell King | d358788 | 2006-03-20 20:00:09 +0000 | [diff] [blame] | 652 | for (i = 0; i < count; i++, s++) { |
| 653 | /* Line return handling */ |
| 654 | if (*s == '\n') |
| 655 | out_8(&psc->mpc52xx_psc_buffer_8, '\r'); |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 656 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | /* Send the char */ |
| 658 | out_8(&psc->mpc52xx_psc_buffer_8, *s); |
| 659 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | /* Wait the TX buffer to be empty */ |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 661 | j = 20000; /* Maximum wait */ |
| 662 | while (!(in_be16(&psc->mpc52xx_psc_status) & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | MPC52xx_PSC_SR_TXEMP) && --j) |
| 664 | udelay(1); |
| 665 | } |
| 666 | |
| 667 | /* Restore interrupt state */ |
| 668 | out_be16(&psc->mpc52xx_psc_imr, port->read_status_mask); |
| 669 | } |
| 670 | |
Grant Likely | b9272df | 2006-11-27 14:21:02 -0700 | [diff] [blame] | 671 | #if !defined(CONFIG_PPC_MERGE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | static int __init |
| 673 | mpc52xx_console_setup(struct console *co, char *options) |
| 674 | { |
| 675 | struct uart_port *port = &mpc52xx_uart_ports[co->index]; |
| 676 | |
| 677 | int baud = CONFIG_SERIAL_MPC52xx_CONSOLE_BAUD; |
| 678 | int bits = 8; |
| 679 | int parity = 'n'; |
| 680 | int flow = 'n'; |
| 681 | |
| 682 | if (co->index < 0 || co->index >= MPC52xx_PSC_MAXNUM) |
| 683 | return -EINVAL; |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 684 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | /* Basic port init. Needed since we use some uart_??? func before |
| 686 | * real init for early access */ |
| 687 | spin_lock_init(&port->lock); |
| 688 | port->uartclk = __res.bi_ipbfreq / 2; /* Look at CTLR doc */ |
| 689 | port->ops = &mpc52xx_uart_ops; |
| 690 | port->mapbase = MPC52xx_PA(MPC52xx_PSCx_OFFSET(co->index+1)); |
| 691 | |
| 692 | /* We ioremap ourself */ |
| 693 | port->membase = ioremap(port->mapbase, MPC52xx_PSC_SIZE); |
| 694 | if (port->membase == NULL) |
| 695 | return -EINVAL; |
| 696 | |
| 697 | /* Setup the port parameters accoding to options */ |
| 698 | if (options) |
| 699 | uart_parse_options(options, &baud, &parity, &bits, &flow); |
| 700 | else |
| 701 | mpc52xx_console_get_options(port, &baud, &parity, &bits, &flow); |
| 702 | |
| 703 | return uart_set_options(port, co, baud, parity, bits, flow); |
| 704 | } |
| 705 | |
Grant Likely | b9272df | 2006-11-27 14:21:02 -0700 | [diff] [blame] | 706 | #else |
| 707 | |
| 708 | static int __init |
| 709 | mpc52xx_console_setup(struct console *co, char *options) |
| 710 | { |
| 711 | struct uart_port *port = &mpc52xx_uart_ports[co->index]; |
| 712 | struct device_node *np = mpc52xx_uart_nodes[co->index]; |
| 713 | unsigned int ipb_freq; |
| 714 | struct resource res; |
| 715 | int ret; |
| 716 | |
| 717 | int baud = CONFIG_SERIAL_MPC52xx_CONSOLE_BAUD; |
| 718 | int bits = 8; |
| 719 | int parity = 'n'; |
| 720 | int flow = 'n'; |
| 721 | |
| 722 | pr_debug("mpc52xx_console_setup co=%p, co->index=%i, options=%s\n", |
| 723 | co, co->index, options); |
| 724 | |
| 725 | if ((co->index < 0) || (co->index > MPC52xx_PSC_MAXNUM)) { |
| 726 | pr_debug("PSC%x out of range\n", co->index); |
| 727 | return -EINVAL; |
| 728 | } |
| 729 | |
| 730 | if (!np) { |
| 731 | pr_debug("PSC%x not found in device tree\n", co->index); |
| 732 | return -EINVAL; |
| 733 | } |
| 734 | |
| 735 | pr_debug("Console on ttyPSC%x is %s\n", |
| 736 | co->index, mpc52xx_uart_nodes[co->index]->full_name); |
| 737 | |
| 738 | /* Fetch register locations */ |
| 739 | if ((ret = of_address_to_resource(np, 0, &res)) != 0) { |
| 740 | pr_debug("Could not get resources for PSC%x\n", co->index); |
| 741 | return ret; |
| 742 | } |
| 743 | |
| 744 | /* Search for bus-frequency property in this node or a parent */ |
| 745 | if ((ipb_freq = mpc52xx_find_ipb_freq(np)) == 0) { |
| 746 | pr_debug("Could not find IPB bus frequency!\n"); |
| 747 | return -EINVAL; |
| 748 | } |
| 749 | |
| 750 | /* Basic port init. Needed since we use some uart_??? func before |
| 751 | * real init for early access */ |
| 752 | spin_lock_init(&port->lock); |
| 753 | port->uartclk = ipb_freq / 2; |
| 754 | port->ops = &mpc52xx_uart_ops; |
| 755 | port->mapbase = res.start; |
| 756 | port->membase = ioremap(res.start, sizeof(struct mpc52xx_psc)); |
| 757 | port->irq = irq_of_parse_and_map(np, 0); |
| 758 | |
| 759 | if (port->membase == NULL) |
| 760 | return -EINVAL; |
| 761 | |
Grant Likely | 5dd80d5 | 2007-10-13 22:37:02 -0600 | [diff] [blame] | 762 | pr_debug("mpc52xx-psc uart at %p, mapped to %p, irq=%x, freq=%i\n", |
| 763 | (void*)port->mapbase, port->membase, port->irq, port->uartclk); |
Grant Likely | b9272df | 2006-11-27 14:21:02 -0700 | [diff] [blame] | 764 | |
| 765 | /* Setup the port parameters accoding to options */ |
| 766 | if (options) |
| 767 | uart_parse_options(options, &baud, &parity, &bits, &flow); |
| 768 | else |
| 769 | mpc52xx_console_get_options(port, &baud, &parity, &bits, &flow); |
| 770 | |
| 771 | pr_debug("Setting console parameters: %i %i%c1 flow=%c\n", |
| 772 | baud, bits, parity, flow); |
| 773 | |
| 774 | return uart_set_options(port, co, baud, parity, bits, flow); |
| 775 | } |
| 776 | #endif /* defined(CONFIG_PPC_MERGE) */ |
| 777 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | |
Sylvain Munaut | 2d8179c | 2006-01-06 00:11:31 -0800 | [diff] [blame] | 779 | static struct uart_driver mpc52xx_uart_driver; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | |
| 781 | static struct console mpc52xx_console = { |
Sylvain Munaut | d62de3a | 2006-01-06 00:11:32 -0800 | [diff] [blame] | 782 | .name = "ttyPSC", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | .write = mpc52xx_console_write, |
| 784 | .device = uart_console_device, |
| 785 | .setup = mpc52xx_console_setup, |
| 786 | .flags = CON_PRINTBUFFER, |
Sylvain Munaut | d62de3a | 2006-01-06 00:11:32 -0800 | [diff] [blame] | 787 | .index = -1, /* Specified on the cmdline (e.g. console=ttyPSC0 ) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | .data = &mpc52xx_uart_driver, |
| 789 | }; |
| 790 | |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 791 | |
| 792 | static int __init |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | mpc52xx_console_init(void) |
| 794 | { |
Grant Likely | c98750c | 2007-01-02 15:45:37 -0700 | [diff] [blame] | 795 | #if defined(CONFIG_PPC_MERGE) |
Grant Likely | b9272df | 2006-11-27 14:21:02 -0700 | [diff] [blame] | 796 | mpc52xx_uart_of_enumerate(); |
Grant Likely | c98750c | 2007-01-02 15:45:37 -0700 | [diff] [blame] | 797 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | register_console(&mpc52xx_console); |
| 799 | return 0; |
| 800 | } |
| 801 | |
| 802 | console_initcall(mpc52xx_console_init); |
| 803 | |
| 804 | #define MPC52xx_PSC_CONSOLE &mpc52xx_console |
| 805 | #else |
| 806 | #define MPC52xx_PSC_CONSOLE NULL |
| 807 | #endif |
| 808 | |
| 809 | |
| 810 | /* ======================================================================== */ |
| 811 | /* UART Driver */ |
| 812 | /* ======================================================================== */ |
| 813 | |
| 814 | static struct uart_driver mpc52xx_uart_driver = { |
| 815 | .owner = THIS_MODULE, |
| 816 | .driver_name = "mpc52xx_psc_uart", |
Sylvain Munaut | d62de3a | 2006-01-06 00:11:32 -0800 | [diff] [blame] | 817 | .dev_name = "ttyPSC", |
Sylvain Munaut | d62de3a | 2006-01-06 00:11:32 -0800 | [diff] [blame] | 818 | .major = SERIAL_PSC_MAJOR, |
| 819 | .minor = SERIAL_PSC_MINOR, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | .nr = MPC52xx_PSC_MAXNUM, |
| 821 | .cons = MPC52xx_PSC_CONSOLE, |
| 822 | }; |
| 823 | |
| 824 | |
Grant Likely | b9272df | 2006-11-27 14:21:02 -0700 | [diff] [blame] | 825 | #if !defined(CONFIG_PPC_MERGE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | /* ======================================================================== */ |
| 827 | /* Platform Driver */ |
| 828 | /* ======================================================================== */ |
| 829 | |
| 830 | static int __devinit |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 831 | mpc52xx_uart_probe(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 833 | struct resource *res = dev->resource; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | |
| 835 | struct uart_port *port = NULL; |
| 836 | int i, idx, ret; |
| 837 | |
| 838 | /* Check validity & presence */ |
Andrey Volkov | 38801e2 | 2005-11-12 22:04:06 +0000 | [diff] [blame] | 839 | idx = dev->id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | if (idx < 0 || idx >= MPC52xx_PSC_MAXNUM) |
| 841 | return -EINVAL; |
| 842 | |
| 843 | if (!mpc52xx_match_psc_function(idx,"uart")) |
| 844 | return -ENODEV; |
| 845 | |
| 846 | /* Init the port structure */ |
| 847 | port = &mpc52xx_uart_ports[idx]; |
| 848 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | spin_lock_init(&port->lock); |
| 850 | port->uartclk = __res.bi_ipbfreq / 2; /* Look at CTLR doc */ |
Russell King | 947deee | 2006-07-02 20:45:51 +0100 | [diff] [blame] | 851 | port->fifosize = 512; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | port->iotype = UPIO_MEM; |
| 853 | port->flags = UPF_BOOT_AUTOCONF | |
| 854 | ( uart_console(port) ? 0 : UPF_IOREMAP ); |
| 855 | port->line = idx; |
| 856 | port->ops = &mpc52xx_uart_ops; |
Grant Likely | b9272df | 2006-11-27 14:21:02 -0700 | [diff] [blame] | 857 | port->dev = &dev->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | |
| 859 | /* Search for IRQ and mapbase */ |
Andrey Volkov | 38801e2 | 2005-11-12 22:04:06 +0000 | [diff] [blame] | 860 | for (i=0 ; i<dev->num_resources ; i++, res++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | if (res->flags & IORESOURCE_MEM) |
| 862 | port->mapbase = res->start; |
| 863 | else if (res->flags & IORESOURCE_IRQ) |
| 864 | port->irq = res->start; |
| 865 | } |
| 866 | if (!port->irq || !port->mapbase) |
| 867 | return -EINVAL; |
| 868 | |
| 869 | /* Add the port to the uart sub-system */ |
| 870 | ret = uart_add_one_port(&mpc52xx_uart_driver, port); |
| 871 | if (!ret) |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 872 | platform_set_drvdata(dev, (void*)port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | |
| 874 | return ret; |
| 875 | } |
| 876 | |
| 877 | static int |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 878 | mpc52xx_uart_remove(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 880 | struct uart_port *port = (struct uart_port *) platform_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 882 | platform_set_drvdata(dev, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | |
| 884 | if (port) |
| 885 | uart_remove_one_port(&mpc52xx_uart_driver, port); |
| 886 | |
| 887 | return 0; |
| 888 | } |
| 889 | |
| 890 | #ifdef CONFIG_PM |
| 891 | static int |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 892 | mpc52xx_uart_suspend(struct platform_device *dev, pm_message_t state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 894 | struct uart_port *port = (struct uart_port *) platform_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | |
Grant Likely | 9b9129e | 2006-11-27 14:21:01 -0700 | [diff] [blame] | 896 | if (port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | uart_suspend_port(&mpc52xx_uart_driver, port); |
| 898 | |
| 899 | return 0; |
| 900 | } |
| 901 | |
| 902 | static int |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 903 | mpc52xx_uart_resume(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 905 | struct uart_port *port = (struct uart_port *) platform_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | |
Russell King | 9480e30 | 2005-10-28 09:52:56 -0700 | [diff] [blame] | 907 | if (port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | uart_resume_port(&mpc52xx_uart_driver, port); |
| 909 | |
| 910 | return 0; |
| 911 | } |
| 912 | #endif |
| 913 | |
Grant Likely | b9272df | 2006-11-27 14:21:02 -0700 | [diff] [blame] | 914 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 915 | static struct platform_driver mpc52xx_uart_platform_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | .probe = mpc52xx_uart_probe, |
| 917 | .remove = mpc52xx_uart_remove, |
| 918 | #ifdef CONFIG_PM |
| 919 | .suspend = mpc52xx_uart_suspend, |
| 920 | .resume = mpc52xx_uart_resume, |
| 921 | #endif |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 922 | .driver = { |
| 923 | .name = "mpc52xx-psc", |
| 924 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | }; |
Grant Likely | b9272df | 2006-11-27 14:21:02 -0700 | [diff] [blame] | 926 | #endif /* !defined(CONFIG_PPC_MERGE) */ |
| 927 | |
| 928 | |
| 929 | #if defined(CONFIG_PPC_MERGE) |
| 930 | /* ======================================================================== */ |
| 931 | /* OF Platform Driver */ |
| 932 | /* ======================================================================== */ |
| 933 | |
| 934 | static int __devinit |
| 935 | mpc52xx_uart_of_probe(struct of_device *op, const struct of_device_id *match) |
| 936 | { |
| 937 | int idx = -1; |
| 938 | unsigned int ipb_freq; |
| 939 | struct uart_port *port = NULL; |
| 940 | struct resource res; |
| 941 | int ret; |
| 942 | |
| 943 | dev_dbg(&op->dev, "mpc52xx_uart_probe(op=%p, match=%p)\n", op, match); |
| 944 | |
| 945 | /* Check validity & presence */ |
| 946 | for (idx = 0; idx < MPC52xx_PSC_MAXNUM; idx++) |
| 947 | if (mpc52xx_uart_nodes[idx] == op->node) |
| 948 | break; |
| 949 | if (idx >= MPC52xx_PSC_MAXNUM) |
| 950 | return -EINVAL; |
| 951 | pr_debug("Found %s assigned to ttyPSC%x\n", |
| 952 | mpc52xx_uart_nodes[idx]->full_name, idx); |
| 953 | |
| 954 | /* Search for bus-frequency property in this node or a parent */ |
| 955 | if ((ipb_freq = mpc52xx_find_ipb_freq(op->node)) == 0) { |
| 956 | dev_dbg(&op->dev, "Could not find IPB bus frequency!\n"); |
| 957 | return -EINVAL; |
| 958 | } |
| 959 | |
| 960 | /* Init the port structure */ |
| 961 | port = &mpc52xx_uart_ports[idx]; |
| 962 | |
| 963 | spin_lock_init(&port->lock); |
| 964 | port->uartclk = ipb_freq / 2; |
| 965 | port->fifosize = 512; |
| 966 | port->iotype = UPIO_MEM; |
| 967 | port->flags = UPF_BOOT_AUTOCONF | |
| 968 | ( uart_console(port) ? 0 : UPF_IOREMAP ); |
| 969 | port->line = idx; |
| 970 | port->ops = &mpc52xx_uart_ops; |
| 971 | port->dev = &op->dev; |
| 972 | |
| 973 | /* Search for IRQ and mapbase */ |
| 974 | if ((ret = of_address_to_resource(op->node, 0, &res)) != 0) |
| 975 | return ret; |
| 976 | |
| 977 | port->mapbase = res.start; |
| 978 | port->irq = irq_of_parse_and_map(op->node, 0); |
| 979 | |
Grant Likely | 5dd80d5 | 2007-10-13 22:37:02 -0600 | [diff] [blame] | 980 | dev_dbg(&op->dev, "mpc52xx-psc uart at %p, irq=%x, freq=%i\n", |
| 981 | (void*)port->mapbase, port->irq, port->uartclk); |
Grant Likely | b9272df | 2006-11-27 14:21:02 -0700 | [diff] [blame] | 982 | |
| 983 | if ((port->irq==NO_IRQ) || !port->mapbase) { |
| 984 | printk(KERN_ERR "Could not allocate resources for PSC\n"); |
| 985 | return -EINVAL; |
| 986 | } |
| 987 | |
| 988 | /* Add the port to the uart sub-system */ |
| 989 | ret = uart_add_one_port(&mpc52xx_uart_driver, port); |
| 990 | if (!ret) |
| 991 | dev_set_drvdata(&op->dev, (void*)port); |
| 992 | |
| 993 | return ret; |
| 994 | } |
| 995 | |
| 996 | static int |
| 997 | mpc52xx_uart_of_remove(struct of_device *op) |
| 998 | { |
| 999 | struct uart_port *port = dev_get_drvdata(&op->dev); |
| 1000 | dev_set_drvdata(&op->dev, NULL); |
| 1001 | |
Sylvain Munaut | fc7900b | 2007-02-15 23:18:08 +0100 | [diff] [blame] | 1002 | if (port) { |
Grant Likely | b9272df | 2006-11-27 14:21:02 -0700 | [diff] [blame] | 1003 | uart_remove_one_port(&mpc52xx_uart_driver, port); |
Sylvain Munaut | fc7900b | 2007-02-15 23:18:08 +0100 | [diff] [blame] | 1004 | irq_dispose_mapping(port->irq); |
| 1005 | } |
Grant Likely | b9272df | 2006-11-27 14:21:02 -0700 | [diff] [blame] | 1006 | |
| 1007 | return 0; |
| 1008 | } |
| 1009 | |
| 1010 | #ifdef CONFIG_PM |
| 1011 | static int |
| 1012 | mpc52xx_uart_of_suspend(struct of_device *op, pm_message_t state) |
| 1013 | { |
| 1014 | struct uart_port *port = (struct uart_port *) dev_get_drvdata(&op->dev); |
| 1015 | |
| 1016 | if (port) |
| 1017 | uart_suspend_port(&mpc52xx_uart_driver, port); |
| 1018 | |
| 1019 | return 0; |
| 1020 | } |
| 1021 | |
| 1022 | static int |
| 1023 | mpc52xx_uart_of_resume(struct of_device *op) |
| 1024 | { |
| 1025 | struct uart_port *port = (struct uart_port *) dev_get_drvdata(&op->dev); |
| 1026 | |
| 1027 | if (port) |
| 1028 | uart_resume_port(&mpc52xx_uart_driver, port); |
| 1029 | |
| 1030 | return 0; |
| 1031 | } |
| 1032 | #endif |
| 1033 | |
| 1034 | static void |
| 1035 | mpc52xx_uart_of_assign(struct device_node *np, int idx) |
| 1036 | { |
| 1037 | int free_idx = -1; |
| 1038 | int i; |
| 1039 | |
| 1040 | /* Find the first free node */ |
| 1041 | for (i = 0; i < MPC52xx_PSC_MAXNUM; i++) { |
| 1042 | if (mpc52xx_uart_nodes[i] == NULL) { |
| 1043 | free_idx = i; |
| 1044 | break; |
| 1045 | } |
| 1046 | } |
| 1047 | |
| 1048 | if ((idx < 0) || (idx >= MPC52xx_PSC_MAXNUM)) |
| 1049 | idx = free_idx; |
| 1050 | |
| 1051 | if (idx < 0) |
| 1052 | return; /* No free slot; abort */ |
| 1053 | |
| 1054 | /* If the slot is already occupied, then swap slots */ |
| 1055 | if (mpc52xx_uart_nodes[idx] && (free_idx != -1)) |
| 1056 | mpc52xx_uart_nodes[free_idx] = mpc52xx_uart_nodes[idx]; |
John Rigby | af6a9aa | 2007-05-23 11:30:55 -0600 | [diff] [blame] | 1057 | mpc52xx_uart_nodes[idx] = np; |
Grant Likely | b9272df | 2006-11-27 14:21:02 -0700 | [diff] [blame] | 1058 | } |
| 1059 | |
| 1060 | static void |
| 1061 | mpc52xx_uart_of_enumerate(void) |
| 1062 | { |
| 1063 | static int enum_done = 0; |
| 1064 | struct device_node *np; |
| 1065 | const unsigned int *devno; |
| 1066 | int i; |
| 1067 | |
| 1068 | if (enum_done) |
| 1069 | return; |
| 1070 | |
| 1071 | for_each_node_by_type(np, "serial") { |
| 1072 | if (!of_match_node(mpc52xx_uart_of_match, np)) |
| 1073 | continue; |
| 1074 | |
| 1075 | /* Is a particular device number requested? */ |
Stephen Rothwell | 40cd3a4 | 2007-05-01 13:54:02 +1000 | [diff] [blame] | 1076 | devno = of_get_property(np, "port-number", NULL); |
Grant Likely | b9272df | 2006-11-27 14:21:02 -0700 | [diff] [blame] | 1077 | mpc52xx_uart_of_assign(of_node_get(np), devno ? *devno : -1); |
| 1078 | } |
| 1079 | |
| 1080 | enum_done = 1; |
| 1081 | |
| 1082 | for (i = 0; i < MPC52xx_PSC_MAXNUM; i++) { |
| 1083 | if (mpc52xx_uart_nodes[i]) |
| 1084 | pr_debug("%s assigned to ttyPSC%x\n", |
| 1085 | mpc52xx_uart_nodes[i]->full_name, i); |
| 1086 | } |
| 1087 | } |
| 1088 | |
| 1089 | MODULE_DEVICE_TABLE(of, mpc52xx_uart_of_match); |
| 1090 | |
| 1091 | static struct of_platform_driver mpc52xx_uart_of_driver = { |
| 1092 | .owner = THIS_MODULE, |
| 1093 | .name = "mpc52xx-psc-uart", |
| 1094 | .match_table = mpc52xx_uart_of_match, |
| 1095 | .probe = mpc52xx_uart_of_probe, |
| 1096 | .remove = mpc52xx_uart_of_remove, |
| 1097 | #ifdef CONFIG_PM |
| 1098 | .suspend = mpc52xx_uart_of_suspend, |
| 1099 | .resume = mpc52xx_uart_of_resume, |
| 1100 | #endif |
| 1101 | .driver = { |
| 1102 | .name = "mpc52xx-psc-uart", |
| 1103 | }, |
| 1104 | }; |
| 1105 | #endif /* defined(CONFIG_PPC_MERGE) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | |
| 1107 | |
| 1108 | /* ======================================================================== */ |
| 1109 | /* Module */ |
| 1110 | /* ======================================================================== */ |
| 1111 | |
| 1112 | static int __init |
| 1113 | mpc52xx_uart_init(void) |
| 1114 | { |
| 1115 | int ret; |
| 1116 | |
Grant Likely | b9272df | 2006-11-27 14:21:02 -0700 | [diff] [blame] | 1117 | printk(KERN_INFO "Serial: MPC52xx PSC UART driver\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1118 | |
Grant Likely | b9272df | 2006-11-27 14:21:02 -0700 | [diff] [blame] | 1119 | if ((ret = uart_register_driver(&mpc52xx_uart_driver)) != 0) { |
| 1120 | printk(KERN_ERR "%s: uart_register_driver failed (%i)\n", |
| 1121 | __FILE__, ret); |
| 1122 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | } |
| 1124 | |
Grant Likely | b9272df | 2006-11-27 14:21:02 -0700 | [diff] [blame] | 1125 | #if defined(CONFIG_PPC_MERGE) |
| 1126 | mpc52xx_uart_of_enumerate(); |
| 1127 | |
| 1128 | ret = of_register_platform_driver(&mpc52xx_uart_of_driver); |
| 1129 | if (ret) { |
| 1130 | printk(KERN_ERR "%s: of_register_platform_driver failed (%i)\n", |
| 1131 | __FILE__, ret); |
| 1132 | uart_unregister_driver(&mpc52xx_uart_driver); |
| 1133 | return ret; |
| 1134 | } |
| 1135 | #else |
| 1136 | ret = platform_driver_register(&mpc52xx_uart_platform_driver); |
| 1137 | if (ret) { |
| 1138 | printk(KERN_ERR "%s: platform_driver_register failed (%i)\n", |
| 1139 | __FILE__, ret); |
| 1140 | uart_unregister_driver(&mpc52xx_uart_driver); |
| 1141 | return ret; |
| 1142 | } |
| 1143 | #endif |
| 1144 | |
| 1145 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1146 | } |
| 1147 | |
| 1148 | static void __exit |
| 1149 | mpc52xx_uart_exit(void) |
| 1150 | { |
Grant Likely | b9272df | 2006-11-27 14:21:02 -0700 | [diff] [blame] | 1151 | #if defined(CONFIG_PPC_MERGE) |
| 1152 | of_unregister_platform_driver(&mpc52xx_uart_of_driver); |
| 1153 | #else |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1154 | platform_driver_unregister(&mpc52xx_uart_platform_driver); |
Grant Likely | b9272df | 2006-11-27 14:21:02 -0700 | [diff] [blame] | 1155 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 | uart_unregister_driver(&mpc52xx_uart_driver); |
| 1157 | } |
| 1158 | |
| 1159 | |
| 1160 | module_init(mpc52xx_uart_init); |
| 1161 | module_exit(mpc52xx_uart_exit); |
| 1162 | |
| 1163 | MODULE_AUTHOR("Sylvain Munaut <tnt@246tNt.com>"); |
| 1164 | MODULE_DESCRIPTION("Freescale MPC52xx PSC UART"); |
| 1165 | MODULE_LICENSE("GPL"); |