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