Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at v2.6.19-rc3 839 lines 22 kB view raw
1/* 2 * drivers/serial/mpc52xx_uart.c 3 * 4 * Driver for the PSC of the Freescale MPC52xx PSCs configured as UARTs. 5 * 6 * FIXME According to the usermanual the status bits in the status register 7 * are only updated when the peripherals access the FIFO and not when the 8 * CPU access them. So since we use this bits to know when we stop writing 9 * and reading, they may not be updated in-time and a race condition may 10 * exists. But I haven't be able to prove this and I don't care. But if 11 * any problem arises, it might worth checking. The TX/RX FIFO Stats 12 * registers should be used in addition. 13 * Update: Actually, they seem updated ... At least the bits we use. 14 * 15 * 16 * Maintainer : Sylvain Munaut <tnt@246tNt.com> 17 * 18 * Some of the code has been inspired/copied from the 2.4 code written 19 * by Dale Farnsworth <dfarnsworth@mvista.com>. 20 * 21 * Copyright (C) 2004-2005 Sylvain Munaut <tnt@246tNt.com> 22 * Copyright (C) 2003 MontaVista, Software, Inc. 23 * 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 */ 28 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, 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 43 * are parsing the kernel args console=ttyPSC?, we wouldn't know which PSC it 44 * will be mapped to. 45 */ 46 47#include <linux/platform_device.h> 48#include <linux/module.h> 49#include <linux/tty.h> 50#include <linux/serial.h> 51#include <linux/sysrq.h> 52#include <linux/console.h> 53 54#include <asm/delay.h> 55#include <asm/io.h> 56 57#include <asm/mpc52xx.h> 58#include <asm/mpc52xx_psc.h> 59 60#if defined(CONFIG_SERIAL_MPC52xx_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) 61#define SUPPORT_SYSRQ 62#endif 63 64#include <linux/serial_core.h> 65 66 67/* We've been assigned a range on the "Low-density serial ports" major */ 68#define SERIAL_PSC_MAJOR 204 69#define SERIAL_PSC_MINOR 148 70 71 72#define ISR_PASS_LIMIT 256 /* Max number of iteration in the interrupt */ 73 74 75static struct uart_port mpc52xx_uart_ports[MPC52xx_PSC_MAXNUM]; 76 /* Rem: - We use the read_status_mask as a shadow of 77 * psc->mpc52xx_psc_imr 78 * - It's important that is array is all zero on start as we 79 * use it to know if it's initialized or not ! If it's not sure 80 * it's cleared, then a memset(...,0,...) should be added to 81 * the console_init 82 */ 83 84#define PSC(port) ((struct mpc52xx_psc __iomem *)((port)->membase)) 85 86 87/* Forward declaration of the interruption handling routine */ 88static irqreturn_t mpc52xx_uart_int(int irq,void *dev_id); 89 90 91/* Simple macro to test if a port is console or not. This one is taken 92 * for serial_core.c and maybe should be moved to serial_core.h ? */ 93#ifdef CONFIG_SERIAL_CORE_CONSOLE 94#define uart_console(port) ((port)->cons && (port)->cons->index == (port)->line) 95#else 96#define uart_console(port) (0) 97#endif 98 99 100/* ======================================================================== */ 101/* UART operations */ 102/* ======================================================================== */ 103 104static unsigned int 105mpc52xx_uart_tx_empty(struct uart_port *port) 106{ 107 int status = in_be16(&PSC(port)->mpc52xx_psc_status); 108 return (status & MPC52xx_PSC_SR_TXEMP) ? TIOCSER_TEMT : 0; 109} 110 111static void 112mpc52xx_uart_set_mctrl(struct uart_port *port, unsigned int mctrl) 113{ 114 /* Not implemented */ 115} 116 117static unsigned int 118mpc52xx_uart_get_mctrl(struct uart_port *port) 119{ 120 /* Not implemented */ 121 return TIOCM_CTS | TIOCM_DSR | TIOCM_CAR; 122} 123 124static void 125mpc52xx_uart_stop_tx(struct uart_port *port) 126{ 127 /* port->lock taken by caller */ 128 port->read_status_mask &= ~MPC52xx_PSC_IMR_TXRDY; 129 out_be16(&PSC(port)->mpc52xx_psc_imr,port->read_status_mask); 130} 131 132static void 133mpc52xx_uart_start_tx(struct uart_port *port) 134{ 135 /* port->lock taken by caller */ 136 port->read_status_mask |= MPC52xx_PSC_IMR_TXRDY; 137 out_be16(&PSC(port)->mpc52xx_psc_imr,port->read_status_mask); 138} 139 140static void 141mpc52xx_uart_send_xchar(struct uart_port *port, char ch) 142{ 143 unsigned long flags; 144 spin_lock_irqsave(&port->lock, flags); 145 146 port->x_char = ch; 147 if (ch) { 148 /* Make sure tx interrupts are on */ 149 /* Truly necessary ??? They should be anyway */ 150 port->read_status_mask |= MPC52xx_PSC_IMR_TXRDY; 151 out_be16(&PSC(port)->mpc52xx_psc_imr,port->read_status_mask); 152 } 153 154 spin_unlock_irqrestore(&port->lock, flags); 155} 156 157static void 158mpc52xx_uart_stop_rx(struct uart_port *port) 159{ 160 /* port->lock taken by caller */ 161 port->read_status_mask &= ~MPC52xx_PSC_IMR_RXRDY; 162 out_be16(&PSC(port)->mpc52xx_psc_imr,port->read_status_mask); 163} 164 165static void 166mpc52xx_uart_enable_ms(struct uart_port *port) 167{ 168 /* Not implemented */ 169} 170 171static void 172mpc52xx_uart_break_ctl(struct uart_port *port, int ctl) 173{ 174 unsigned long flags; 175 spin_lock_irqsave(&port->lock, flags); 176 177 if ( ctl == -1 ) 178 out_8(&PSC(port)->command,MPC52xx_PSC_START_BRK); 179 else 180 out_8(&PSC(port)->command,MPC52xx_PSC_STOP_BRK); 181 182 spin_unlock_irqrestore(&port->lock, flags); 183} 184 185static int 186mpc52xx_uart_startup(struct uart_port *port) 187{ 188 struct mpc52xx_psc __iomem *psc = PSC(port); 189 int ret; 190 191 /* Request IRQ */ 192 ret = request_irq(port->irq, mpc52xx_uart_int, 193 IRQF_DISABLED | IRQF_SAMPLE_RANDOM, "mpc52xx_psc_uart", port); 194 if (ret) 195 return ret; 196 197 /* Reset/activate the port, clear and enable interrupts */ 198 out_8(&psc->command,MPC52xx_PSC_RST_RX); 199 out_8(&psc->command,MPC52xx_PSC_RST_TX); 200 201 out_be32(&psc->sicr,0); /* UART mode DCD ignored */ 202 203 out_be16(&psc->mpc52xx_psc_clock_select, 0xdd00); /* /16 prescaler on */ 204 205 out_8(&psc->rfcntl, 0x00); 206 out_be16(&psc->rfalarm, 0x1ff); 207 out_8(&psc->tfcntl, 0x07); 208 out_be16(&psc->tfalarm, 0x80); 209 210 port->read_status_mask |= MPC52xx_PSC_IMR_RXRDY | MPC52xx_PSC_IMR_TXRDY; 211 out_be16(&psc->mpc52xx_psc_imr,port->read_status_mask); 212 213 out_8(&psc->command,MPC52xx_PSC_TX_ENABLE); 214 out_8(&psc->command,MPC52xx_PSC_RX_ENABLE); 215 216 return 0; 217} 218 219static void 220mpc52xx_uart_shutdown(struct uart_port *port) 221{ 222 struct mpc52xx_psc __iomem *psc = PSC(port); 223 224 /* Shut down the port, interrupt and all */ 225 out_8(&psc->command,MPC52xx_PSC_RST_RX); 226 out_8(&psc->command,MPC52xx_PSC_RST_TX); 227 228 port->read_status_mask = 0; 229 out_be16(&psc->mpc52xx_psc_imr,port->read_status_mask); 230 231 /* Release interrupt */ 232 free_irq(port->irq, port); 233} 234 235static void 236mpc52xx_uart_set_termios(struct uart_port *port, struct termios *new, 237 struct termios *old) 238{ 239 struct mpc52xx_psc __iomem *psc = PSC(port); 240 unsigned long flags; 241 unsigned char mr1, mr2; 242 unsigned short ctr; 243 unsigned int j, baud, quot; 244 245 /* Prepare what we're gonna write */ 246 mr1 = 0; 247 248 switch (new->c_cflag & CSIZE) { 249 case CS5: mr1 |= MPC52xx_PSC_MODE_5_BITS; 250 break; 251 case CS6: mr1 |= MPC52xx_PSC_MODE_6_BITS; 252 break; 253 case CS7: mr1 |= MPC52xx_PSC_MODE_7_BITS; 254 break; 255 case CS8: 256 default: mr1 |= MPC52xx_PSC_MODE_8_BITS; 257 } 258 259 if (new->c_cflag & PARENB) { 260 mr1 |= (new->c_cflag & PARODD) ? 261 MPC52xx_PSC_MODE_PARODD : MPC52xx_PSC_MODE_PAREVEN; 262 } else 263 mr1 |= MPC52xx_PSC_MODE_PARNONE; 264 265 266 mr2 = 0; 267 268 if (new->c_cflag & CSTOPB) 269 mr2 |= MPC52xx_PSC_MODE_TWO_STOP; 270 else 271 mr2 |= ((new->c_cflag & CSIZE) == CS5) ? 272 MPC52xx_PSC_MODE_ONE_STOP_5_BITS : 273 MPC52xx_PSC_MODE_ONE_STOP; 274 275 276 baud = uart_get_baud_rate(port, new, old, 0, port->uartclk/16); 277 quot = uart_get_divisor(port, baud); 278 ctr = quot & 0xffff; 279 280 /* Get the lock */ 281 spin_lock_irqsave(&port->lock, flags); 282 283 /* Update the per-port timeout */ 284 uart_update_timeout(port, new->c_cflag, baud); 285 286 /* Do our best to flush TX & RX, so we don't loose anything */ 287 /* But we don't wait indefinitly ! */ 288 j = 5000000; /* Maximum wait */ 289 /* FIXME Can't receive chars since set_termios might be called at early 290 * boot for the console, all stuff is not yet ready to receive at that 291 * time and that just makes the kernel oops */ 292 /* while (j-- && mpc52xx_uart_int_rx_chars(port)); */ 293 while (!(in_be16(&psc->mpc52xx_psc_status) & MPC52xx_PSC_SR_TXEMP) && 294 --j) 295 udelay(1); 296 297 if (!j) 298 printk( KERN_ERR "mpc52xx_uart.c: " 299 "Unable to flush RX & TX fifos in-time in set_termios." 300 "Some chars may have been lost.\n" ); 301 302 /* Reset the TX & RX */ 303 out_8(&psc->command,MPC52xx_PSC_RST_RX); 304 out_8(&psc->command,MPC52xx_PSC_RST_TX); 305 306 /* Send new mode settings */ 307 out_8(&psc->command,MPC52xx_PSC_SEL_MODE_REG_1); 308 out_8(&psc->mode,mr1); 309 out_8(&psc->mode,mr2); 310 out_8(&psc->ctur,ctr >> 8); 311 out_8(&psc->ctlr,ctr & 0xff); 312 313 /* Reenable TX & RX */ 314 out_8(&psc->command,MPC52xx_PSC_TX_ENABLE); 315 out_8(&psc->command,MPC52xx_PSC_RX_ENABLE); 316 317 /* We're all set, release the lock */ 318 spin_unlock_irqrestore(&port->lock, flags); 319} 320 321static const char * 322mpc52xx_uart_type(struct uart_port *port) 323{ 324 return port->type == PORT_MPC52xx ? "MPC52xx PSC" : NULL; 325} 326 327static void 328mpc52xx_uart_release_port(struct uart_port *port) 329{ 330 if (port->flags & UPF_IOREMAP) { /* remapped by us ? */ 331 iounmap(port->membase); 332 port->membase = NULL; 333 } 334 335 release_mem_region(port->mapbase, MPC52xx_PSC_SIZE); 336} 337 338static int 339mpc52xx_uart_request_port(struct uart_port *port) 340{ 341 int err; 342 343 if (port->flags & UPF_IOREMAP) /* Need to remap ? */ 344 port->membase = ioremap(port->mapbase, MPC52xx_PSC_SIZE); 345 346 if (!port->membase) 347 return -EINVAL; 348 349 err = request_mem_region(port->mapbase, MPC52xx_PSC_SIZE, 350 "mpc52xx_psc_uart") != NULL ? 0 : -EBUSY; 351 352 if (err && (port->flags & UPF_IOREMAP)) { 353 iounmap(port->membase); 354 port->membase = NULL; 355 } 356 357 return err; 358} 359 360static void 361mpc52xx_uart_config_port(struct uart_port *port, int flags) 362{ 363 if ( (flags & UART_CONFIG_TYPE) && 364 (mpc52xx_uart_request_port(port) == 0) ) 365 port->type = PORT_MPC52xx; 366} 367 368static int 369mpc52xx_uart_verify_port(struct uart_port *port, struct serial_struct *ser) 370{ 371 if ( ser->type != PORT_UNKNOWN && ser->type != PORT_MPC52xx ) 372 return -EINVAL; 373 374 if ( (ser->irq != port->irq) || 375 (ser->io_type != SERIAL_IO_MEM) || 376 (ser->baud_base != port->uartclk) || 377 (ser->iomem_base != (void*)port->mapbase) || 378 (ser->hub6 != 0 ) ) 379 return -EINVAL; 380 381 return 0; 382} 383 384 385static struct uart_ops mpc52xx_uart_ops = { 386 .tx_empty = mpc52xx_uart_tx_empty, 387 .set_mctrl = mpc52xx_uart_set_mctrl, 388 .get_mctrl = mpc52xx_uart_get_mctrl, 389 .stop_tx = mpc52xx_uart_stop_tx, 390 .start_tx = mpc52xx_uart_start_tx, 391 .send_xchar = mpc52xx_uart_send_xchar, 392 .stop_rx = mpc52xx_uart_stop_rx, 393 .enable_ms = mpc52xx_uart_enable_ms, 394 .break_ctl = mpc52xx_uart_break_ctl, 395 .startup = mpc52xx_uart_startup, 396 .shutdown = mpc52xx_uart_shutdown, 397 .set_termios = mpc52xx_uart_set_termios, 398/* .pm = mpc52xx_uart_pm, Not supported yet */ 399/* .set_wake = mpc52xx_uart_set_wake, Not supported yet */ 400 .type = mpc52xx_uart_type, 401 .release_port = mpc52xx_uart_release_port, 402 .request_port = mpc52xx_uart_request_port, 403 .config_port = mpc52xx_uart_config_port, 404 .verify_port = mpc52xx_uart_verify_port 405}; 406 407 408/* ======================================================================== */ 409/* Interrupt handling */ 410/* ======================================================================== */ 411 412static inline int 413mpc52xx_uart_int_rx_chars(struct uart_port *port) 414{ 415 struct tty_struct *tty = port->info->tty; 416 unsigned char ch, flag; 417 unsigned short status; 418 419 /* While we can read, do so ! */ 420 while ( (status = in_be16(&PSC(port)->mpc52xx_psc_status)) & 421 MPC52xx_PSC_SR_RXRDY) { 422 423 /* Get the char */ 424 ch = in_8(&PSC(port)->mpc52xx_psc_buffer_8); 425 426 /* Handle sysreq char */ 427#ifdef SUPPORT_SYSRQ 428 if (uart_handle_sysrq_char(port, ch)) { 429 port->sysrq = 0; 430 continue; 431 } 432#endif 433 434 /* Store it */ 435 436 flag = TTY_NORMAL; 437 port->icount.rx++; 438 439 if ( status & (MPC52xx_PSC_SR_PE | 440 MPC52xx_PSC_SR_FE | 441 MPC52xx_PSC_SR_RB) ) { 442 443 if (status & MPC52xx_PSC_SR_RB) { 444 flag = TTY_BREAK; 445 uart_handle_break(port); 446 } else if (status & MPC52xx_PSC_SR_PE) 447 flag = TTY_PARITY; 448 else if (status & MPC52xx_PSC_SR_FE) 449 flag = TTY_FRAME; 450 451 /* Clear error condition */ 452 out_8(&PSC(port)->command,MPC52xx_PSC_RST_ERR_STAT); 453 454 } 455 tty_insert_flip_char(tty, ch, flag); 456 if (status & MPC52xx_PSC_SR_OE) { 457 /* 458 * Overrun is special, since it's 459 * reported immediately, and doesn't 460 * affect the current character 461 */ 462 tty_insert_flip_char(tty, 0, TTY_OVERRUN); 463 } 464 } 465 466 tty_flip_buffer_push(tty); 467 468 return in_be16(&PSC(port)->mpc52xx_psc_status) & MPC52xx_PSC_SR_RXRDY; 469} 470 471static inline int 472mpc52xx_uart_int_tx_chars(struct uart_port *port) 473{ 474 struct circ_buf *xmit = &port->info->xmit; 475 476 /* Process out of band chars */ 477 if (port->x_char) { 478 out_8(&PSC(port)->mpc52xx_psc_buffer_8, port->x_char); 479 port->icount.tx++; 480 port->x_char = 0; 481 return 1; 482 } 483 484 /* Nothing to do ? */ 485 if (uart_circ_empty(xmit) || uart_tx_stopped(port)) { 486 mpc52xx_uart_stop_tx(port); 487 return 0; 488 } 489 490 /* Send chars */ 491 while (in_be16(&PSC(port)->mpc52xx_psc_status) & MPC52xx_PSC_SR_TXRDY) { 492 out_8(&PSC(port)->mpc52xx_psc_buffer_8, xmit->buf[xmit->tail]); 493 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); 494 port->icount.tx++; 495 if (uart_circ_empty(xmit)) 496 break; 497 } 498 499 /* Wake up */ 500 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) 501 uart_write_wakeup(port); 502 503 /* Maybe we're done after all */ 504 if (uart_circ_empty(xmit)) { 505 mpc52xx_uart_stop_tx(port); 506 return 0; 507 } 508 509 return 1; 510} 511 512static irqreturn_t 513mpc52xx_uart_int(int irq, void *dev_id) 514{ 515 struct uart_port *port = dev_id; 516 unsigned long pass = ISR_PASS_LIMIT; 517 unsigned int keepgoing; 518 unsigned short status; 519 520 spin_lock(&port->lock); 521 522 /* While we have stuff to do, we continue */ 523 do { 524 /* If we don't find anything to do, we stop */ 525 keepgoing = 0; 526 527 /* Read status */ 528 status = in_be16(&PSC(port)->mpc52xx_psc_isr); 529 status &= port->read_status_mask; 530 531 /* Do we need to receive chars ? */ 532 /* For this RX interrupts must be on and some chars waiting */ 533 if ( status & MPC52xx_PSC_IMR_RXRDY ) 534 keepgoing |= mpc52xx_uart_int_rx_chars(port); 535 536 /* Do we need to send chars ? */ 537 /* For this, TX must be ready and TX interrupt enabled */ 538 if ( status & MPC52xx_PSC_IMR_TXRDY ) 539 keepgoing |= mpc52xx_uart_int_tx_chars(port); 540 541 /* Limit number of iteration */ 542 if ( !(--pass) ) 543 keepgoing = 0; 544 545 } while (keepgoing); 546 547 spin_unlock(&port->lock); 548 549 return IRQ_HANDLED; 550} 551 552 553/* ======================================================================== */ 554/* Console ( if applicable ) */ 555/* ======================================================================== */ 556 557#ifdef CONFIG_SERIAL_MPC52xx_CONSOLE 558 559static void __init 560mpc52xx_console_get_options(struct uart_port *port, 561 int *baud, int *parity, int *bits, int *flow) 562{ 563 struct mpc52xx_psc __iomem *psc = PSC(port); 564 unsigned char mr1; 565 566 /* Read the mode registers */ 567 out_8(&psc->command,MPC52xx_PSC_SEL_MODE_REG_1); 568 mr1 = in_8(&psc->mode); 569 570 /* CT{U,L}R are write-only ! */ 571 *baud = __res.bi_baudrate ? 572 __res.bi_baudrate : CONFIG_SERIAL_MPC52xx_CONSOLE_BAUD; 573 574 /* Parse them */ 575 switch (mr1 & MPC52xx_PSC_MODE_BITS_MASK) { 576 case MPC52xx_PSC_MODE_5_BITS: *bits = 5; break; 577 case MPC52xx_PSC_MODE_6_BITS: *bits = 6; break; 578 case MPC52xx_PSC_MODE_7_BITS: *bits = 7; break; 579 case MPC52xx_PSC_MODE_8_BITS: 580 default: *bits = 8; 581 } 582 583 if (mr1 & MPC52xx_PSC_MODE_PARNONE) 584 *parity = 'n'; 585 else 586 *parity = mr1 & MPC52xx_PSC_MODE_PARODD ? 'o' : 'e'; 587} 588 589static void 590mpc52xx_console_write(struct console *co, const char *s, unsigned int count) 591{ 592 struct uart_port *port = &mpc52xx_uart_ports[co->index]; 593 struct mpc52xx_psc __iomem *psc = PSC(port); 594 unsigned int i, j; 595 596 /* Disable interrupts */ 597 out_be16(&psc->mpc52xx_psc_imr, 0); 598 599 /* Wait the TX buffer to be empty */ 600 j = 5000000; /* Maximum wait */ 601 while (!(in_be16(&psc->mpc52xx_psc_status) & MPC52xx_PSC_SR_TXEMP) && 602 --j) 603 udelay(1); 604 605 /* Write all the chars */ 606 for (i = 0; i < count; i++, s++) { 607 /* Line return handling */ 608 if (*s == '\n') 609 out_8(&psc->mpc52xx_psc_buffer_8, '\r'); 610 611 /* Send the char */ 612 out_8(&psc->mpc52xx_psc_buffer_8, *s); 613 614 /* Wait the TX buffer to be empty */ 615 j = 20000; /* Maximum wait */ 616 while (!(in_be16(&psc->mpc52xx_psc_status) & 617 MPC52xx_PSC_SR_TXEMP) && --j) 618 udelay(1); 619 } 620 621 /* Restore interrupt state */ 622 out_be16(&psc->mpc52xx_psc_imr, port->read_status_mask); 623} 624 625static int __init 626mpc52xx_console_setup(struct console *co, char *options) 627{ 628 struct uart_port *port = &mpc52xx_uart_ports[co->index]; 629 630 int baud = CONFIG_SERIAL_MPC52xx_CONSOLE_BAUD; 631 int bits = 8; 632 int parity = 'n'; 633 int flow = 'n'; 634 635 if (co->index < 0 || co->index >= MPC52xx_PSC_MAXNUM) 636 return -EINVAL; 637 638 /* Basic port init. Needed since we use some uart_??? func before 639 * real init for early access */ 640 spin_lock_init(&port->lock); 641 port->uartclk = __res.bi_ipbfreq / 2; /* Look at CTLR doc */ 642 port->ops = &mpc52xx_uart_ops; 643 port->mapbase = MPC52xx_PA(MPC52xx_PSCx_OFFSET(co->index+1)); 644 645 /* We ioremap ourself */ 646 port->membase = ioremap(port->mapbase, MPC52xx_PSC_SIZE); 647 if (port->membase == NULL) 648 return -EINVAL; 649 650 /* Setup the port parameters accoding to options */ 651 if (options) 652 uart_parse_options(options, &baud, &parity, &bits, &flow); 653 else 654 mpc52xx_console_get_options(port, &baud, &parity, &bits, &flow); 655 656 return uart_set_options(port, co, baud, parity, bits, flow); 657} 658 659 660static struct uart_driver mpc52xx_uart_driver; 661 662static struct console mpc52xx_console = { 663 .name = "ttyPSC", 664 .write = mpc52xx_console_write, 665 .device = uart_console_device, 666 .setup = mpc52xx_console_setup, 667 .flags = CON_PRINTBUFFER, 668 .index = -1, /* Specified on the cmdline (e.g. console=ttyPSC0 ) */ 669 .data = &mpc52xx_uart_driver, 670}; 671 672 673static int __init 674mpc52xx_console_init(void) 675{ 676 register_console(&mpc52xx_console); 677 return 0; 678} 679 680console_initcall(mpc52xx_console_init); 681 682#define MPC52xx_PSC_CONSOLE &mpc52xx_console 683#else 684#define MPC52xx_PSC_CONSOLE NULL 685#endif 686 687 688/* ======================================================================== */ 689/* UART Driver */ 690/* ======================================================================== */ 691 692static struct uart_driver mpc52xx_uart_driver = { 693 .owner = THIS_MODULE, 694 .driver_name = "mpc52xx_psc_uart", 695 .dev_name = "ttyPSC", 696 .major = SERIAL_PSC_MAJOR, 697 .minor = SERIAL_PSC_MINOR, 698 .nr = MPC52xx_PSC_MAXNUM, 699 .cons = MPC52xx_PSC_CONSOLE, 700}; 701 702 703/* ======================================================================== */ 704/* Platform Driver */ 705/* ======================================================================== */ 706 707static int __devinit 708mpc52xx_uart_probe(struct platform_device *dev) 709{ 710 struct resource *res = dev->resource; 711 712 struct uart_port *port = NULL; 713 int i, idx, ret; 714 715 /* Check validity & presence */ 716 idx = dev->id; 717 if (idx < 0 || idx >= MPC52xx_PSC_MAXNUM) 718 return -EINVAL; 719 720 if (!mpc52xx_match_psc_function(idx,"uart")) 721 return -ENODEV; 722 723 /* Init the port structure */ 724 port = &mpc52xx_uart_ports[idx]; 725 726 memset(port, 0x00, sizeof(struct uart_port)); 727 728 spin_lock_init(&port->lock); 729 port->uartclk = __res.bi_ipbfreq / 2; /* Look at CTLR doc */ 730 port->fifosize = 512; 731 port->iotype = UPIO_MEM; 732 port->flags = UPF_BOOT_AUTOCONF | 733 ( uart_console(port) ? 0 : UPF_IOREMAP ); 734 port->line = idx; 735 port->ops = &mpc52xx_uart_ops; 736 737 /* Search for IRQ and mapbase */ 738 for (i=0 ; i<dev->num_resources ; i++, res++) { 739 if (res->flags & IORESOURCE_MEM) 740 port->mapbase = res->start; 741 else if (res->flags & IORESOURCE_IRQ) 742 port->irq = res->start; 743 } 744 if (!port->irq || !port->mapbase) 745 return -EINVAL; 746 747 /* Add the port to the uart sub-system */ 748 ret = uart_add_one_port(&mpc52xx_uart_driver, port); 749 if (!ret) 750 platform_set_drvdata(dev, (void*)port); 751 752 return ret; 753} 754 755static int 756mpc52xx_uart_remove(struct platform_device *dev) 757{ 758 struct uart_port *port = (struct uart_port *) platform_get_drvdata(dev); 759 760 platform_set_drvdata(dev, NULL); 761 762 if (port) 763 uart_remove_one_port(&mpc52xx_uart_driver, port); 764 765 return 0; 766} 767 768#ifdef CONFIG_PM 769static int 770mpc52xx_uart_suspend(struct platform_device *dev, pm_message_t state) 771{ 772 struct uart_port *port = (struct uart_port *) platform_get_drvdata(dev); 773 774 if (sport) 775 uart_suspend_port(&mpc52xx_uart_driver, port); 776 777 return 0; 778} 779 780static int 781mpc52xx_uart_resume(struct platform_device *dev) 782{ 783 struct uart_port *port = (struct uart_port *) platform_get_drvdata(dev); 784 785 if (port) 786 uart_resume_port(&mpc52xx_uart_driver, port); 787 788 return 0; 789} 790#endif 791 792static struct platform_driver mpc52xx_uart_platform_driver = { 793 .probe = mpc52xx_uart_probe, 794 .remove = mpc52xx_uart_remove, 795#ifdef CONFIG_PM 796 .suspend = mpc52xx_uart_suspend, 797 .resume = mpc52xx_uart_resume, 798#endif 799 .driver = { 800 .name = "mpc52xx-psc", 801 }, 802}; 803 804 805/* ======================================================================== */ 806/* Module */ 807/* ======================================================================== */ 808 809static int __init 810mpc52xx_uart_init(void) 811{ 812 int ret; 813 814 printk(KERN_INFO "Serial: MPC52xx PSC driver\n"); 815 816 ret = uart_register_driver(&mpc52xx_uart_driver); 817 if (ret == 0) { 818 ret = platform_driver_register(&mpc52xx_uart_platform_driver); 819 if (ret) 820 uart_unregister_driver(&mpc52xx_uart_driver); 821 } 822 823 return ret; 824} 825 826static void __exit 827mpc52xx_uart_exit(void) 828{ 829 platform_driver_unregister(&mpc52xx_uart_platform_driver); 830 uart_unregister_driver(&mpc52xx_uart_driver); 831} 832 833 834module_init(mpc52xx_uart_init); 835module_exit(mpc52xx_uart_exit); 836 837MODULE_AUTHOR("Sylvain Munaut <tnt@246tNt.com>"); 838MODULE_DESCRIPTION("Freescale MPC52xx PSC UART"); 839MODULE_LICENSE("GPL");