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