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