| /* |
| * drivers/tty/serial/ambarella_uart.c |
| * |
| * Author: Anthony Ginger <hfjiang@ambarella.com> |
| * |
| * Copyright (C) 2004-2011, Ambarella, Inc. |
| * |
| * This program is free software; you can redistribute it and/or modify |
| * it under the terms of the GNU General Public License as published by |
| * the Free Software Foundation; either version 2 of the License, or |
| * (at your option) any later version. |
| * |
| * This program is distributed in the hope that it will be useful, |
| * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| * GNU General Public License for more details. |
| * |
| * You should have received a copy of the GNU General Public License |
| * along with this program; if not, write to the Free Software |
| * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| * |
| */ |
| |
| #if defined(CONFIG_SERIAL_AMBARELLA_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) |
| #define SUPPORT_SYSRQ |
| #endif |
| |
| #include <linux/kernel.h> |
| #include <linux/module.h> |
| #include <linux/init.h> |
| #include <linux/io.h> |
| #include <linux/ioport.h> |
| #include <linux/interrupt.h> |
| #include <linux/platform_device.h> |
| #include <linux/delay.h> |
| #include <linux/dma-mapping.h> |
| #include <asm/dma.h> |
| |
| #include <linux/console.h> |
| #include <linux/sysrq.h> |
| #include <linux/circ_buf.h> |
| #include <linux/serial_reg.h> |
| #include <linux/tty.h> |
| #include <linux/tty_flip.h> |
| #include <linux/serial.h> |
| #include <linux/serial_core.h> |
| |
| #include <mach/hardware.h> |
| #include <plat/uart.h> |
| |
| /* ==========================================================================*/ |
| static void __serial_ambarella_enable_ms(struct uart_port *port) |
| { |
| amba_setbitsl(port->membase + UART_IE_OFFSET, UART_IE_EDSSI); |
| } |
| |
| static void __serial_ambarella_disable_ms(struct uart_port *port) |
| { |
| amba_clrbitsl(port->membase + UART_IE_OFFSET, UART_IE_EDSSI); |
| } |
| |
| static inline void wait_for_tx(struct uart_port *port) |
| { |
| u32 ls; |
| |
| ls = amba_readl(port->membase + UART_LS_OFFSET); |
| while ((ls & UART_LS_TEMT) != UART_LS_TEMT) { |
| cpu_relax(); |
| ls = amba_readl(port->membase + UART_LS_OFFSET); |
| } |
| } |
| |
| static inline void wait_for_rx(struct uart_port *port) |
| { |
| u32 ls; |
| |
| ls = amba_readl(port->membase + UART_LS_OFFSET); |
| while ((ls & UART_LS_DR) != UART_LS_DR) { |
| cpu_relax(); |
| ls = amba_readl(port->membase + UART_LS_OFFSET); |
| } |
| } |
| |
| /* ==========================================================================*/ |
| static inline void serial_ambarella_receive_chars(struct uart_port *port, |
| u32 tmo) |
| { |
| struct tty_struct *tty = port->state->port.tty; |
| u32 ch; |
| u32 flag; |
| int max_count; |
| u32 ls; |
| |
| ls = amba_readl(port->membase + UART_LS_OFFSET); |
| max_count = port->fifosize; |
| |
| do { |
| flag = TTY_NORMAL; |
| if (unlikely(ls & (UART_LS_BI | UART_LS_PE | |
| UART_LS_FE | UART_LS_OE))) { |
| if (ls & UART_LS_BI) { |
| ls &= ~(UART_LS_FE | UART_LS_PE); |
| port->icount.brk++; |
| |
| if (uart_handle_break(port)) |
| goto ignore_char; |
| } |
| if (ls & UART_LS_FE) |
| port->icount.frame++; |
| if (ls & UART_LS_PE) |
| port->icount.parity++; |
| if (ls & UART_LS_OE) |
| port->icount.overrun++; |
| |
| ls &= port->read_status_mask; |
| |
| if (ls & UART_LS_BI) |
| flag = TTY_BREAK; |
| else if (ls & UART_LS_FE) |
| flag = TTY_FRAME; |
| else if (ls & UART_LS_PE) |
| flag = TTY_PARITY; |
| else if (ls & UART_LS_OE) |
| flag = TTY_OVERRUN; |
| |
| if (ls & UART_LS_OE) { |
| printk(KERN_DEBUG "%s: OVERFLOW\n", __func__); |
| } |
| } |
| |
| if (likely(ls & UART_LS_DR)) { |
| ch = amba_readl(port->membase + UART_RB_OFFSET); |
| port->icount.rx++; |
| tmo = 0; |
| |
| if (uart_handle_sysrq_char(port, ch)) |
| goto ignore_char; |
| |
| uart_insert_char(port, ls, UART_LS_OE, ch, flag); |
| } else { |
| if (tmo) { |
| ch = amba_readl(port->membase + UART_RB_OFFSET); |
| printk(KERN_DEBUG "False TMO get %d\n", ch); |
| } |
| } |
| |
| ignore_char: |
| ls = amba_readl(port->membase + UART_LS_OFFSET); |
| } while ((ls & UART_LS_DR) && (max_count-- > 0)); |
| |
| spin_unlock(&port->lock); |
| tty_flip_buffer_push(tty); |
| spin_lock(&port->lock); |
| } |
| |
| static void serial_ambarella_transmit_chars(struct uart_port *port) |
| { |
| struct circ_buf *xmit = &port->state->xmit; |
| int count; |
| struct ambarella_uart_port_info *port_info; |
| |
| port_info = (struct ambarella_uart_port_info *)(port->private_data); |
| |
| if (port->x_char) { |
| amba_writel(port->membase + UART_TH_OFFSET, port->x_char); |
| port->icount.tx++; |
| port->x_char = 0; |
| return; |
| } |
| |
| if (uart_tx_stopped(port) || uart_circ_empty(xmit)) { |
| port_info->stop_tx(port->membase); |
| return; |
| } |
| |
| count = port->fifosize; |
| while (count-- > 0) { |
| amba_writel(port->membase + UART_TH_OFFSET, |
| xmit->buf[xmit->tail]); |
| xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); |
| port->icount.tx++; |
| if (uart_circ_empty(xmit)) |
| break; |
| } |
| if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) |
| uart_write_wakeup(port); |
| if (uart_circ_empty(xmit)) |
| port_info->stop_tx(port->membase); |
| } |
| |
| static inline void serial_ambarella_check_modem_status(struct uart_port *port) |
| { |
| struct ambarella_uart_port_info *port_info; |
| u32 ms; |
| |
| port_info = (struct ambarella_uart_port_info *)(port->private_data); |
| |
| if (port_info->get_ms) { |
| ms = port_info->get_ms(port->membase); |
| |
| if (ms & UART_MS_RI) |
| port->icount.rng++; |
| if (ms & UART_MS_DSR) |
| port->icount.dsr++; |
| if (ms & UART_MS_DCTS) |
| uart_handle_cts_change(port, (ms & UART_MS_CTS)); |
| if (ms & UART_MS_DDCD) |
| uart_handle_dcd_change(port, (ms & UART_MS_DCD)); |
| |
| wake_up_interruptible(&port->state->port.delta_msr_wait); |
| } |
| } |
| |
| static irqreturn_t serial_ambarella_irq(int irq, void *dev_id) |
| { |
| struct uart_port *port = dev_id; |
| int rval = IRQ_HANDLED; |
| u32 ii; |
| unsigned long flags; |
| |
| spin_lock_irqsave(&port->lock, flags); |
| |
| ii = amba_readl(port->membase + UART_II_OFFSET); |
| switch (ii & 0x0F) { |
| case UART_II_MODEM_STATUS_CHANGED: |
| serial_ambarella_check_modem_status(port); |
| break; |
| |
| case UART_II_THR_EMPTY: |
| serial_ambarella_transmit_chars(port); |
| break; |
| |
| case UART_II_RCV_STATUS: |
| case UART_II_RCV_DATA_AVAIL: |
| serial_ambarella_receive_chars(port, 0); |
| break; |
| case UART_II_CHAR_TIMEOUT: |
| serial_ambarella_receive_chars(port, 1); |
| break; |
| |
| case UART_II_NO_INT_PENDING: |
| default: |
| printk(KERN_DEBUG "%s: 0x%x\n", __func__, ii); |
| rval = IRQ_NONE; |
| break; |
| } |
| |
| spin_unlock_irqrestore(&port->lock, flags); |
| |
| return rval; |
| } |
| |
| /* ==========================================================================*/ |
| static void serial_ambarella_enable_ms(struct uart_port *port) |
| { |
| __serial_ambarella_enable_ms(port); |
| } |
| |
| static void serial_ambarella_start_tx(struct uart_port *port) |
| { |
| amba_setbitsl(port->membase + UART_IE_OFFSET, UART_IE_ETBEI); |
| } |
| |
| static void serial_ambarella_stop_tx(struct uart_port *port) |
| { |
| struct ambarella_uart_port_info *port_info; |
| |
| port_info = (struct ambarella_uart_port_info *)(port->private_data); |
| |
| port_info->stop_tx(port->membase); |
| } |
| |
| static void serial_ambarella_stop_rx(struct uart_port *port) |
| { |
| amba_clrbitsl(port->membase + UART_IE_OFFSET, UART_IE_ERBFI); |
| } |
| |
| static unsigned int serial_ambarella_tx_empty(struct uart_port *port) |
| { |
| unsigned long flags; |
| unsigned int lsr; |
| |
| spin_lock_irqsave(&port->lock, flags); |
| lsr = amba_readl(port->membase + UART_LS_OFFSET); |
| spin_unlock_irqrestore(&port->lock, flags); |
| |
| return ((lsr & (UART_LS_TEMT | UART_LS_THRE)) == |
| (UART_LS_TEMT | UART_LS_THRE)) ? TIOCSER_TEMT : 0; |
| } |
| |
| static unsigned int serial_ambarella_get_mctrl(struct uart_port *port) |
| { |
| unsigned int mctrl = 0; |
| struct ambarella_uart_port_info *port_info; |
| u32 ms; |
| |
| port_info = (struct ambarella_uart_port_info *)(port->private_data); |
| |
| if (port_info->get_ms) { |
| ms = port_info->get_ms(port->membase); |
| |
| if (ms & UART_MS_CTS) |
| mctrl |= TIOCM_CTS; |
| if (ms & UART_MS_DSR) |
| mctrl |= TIOCM_DSR; |
| if (ms & UART_MS_RI) |
| mctrl |= TIOCM_RI; |
| if (ms & UART_MS_DCD) |
| mctrl |= TIOCM_CD; |
| } |
| |
| return mctrl; |
| } |
| |
| static void serial_ambarella_set_mctrl(struct uart_port *port, |
| unsigned int mctrl) |
| { |
| struct ambarella_uart_port_info *port_info; |
| u32 mcr; |
| u32 mcr_new = 0; |
| |
| port_info = (struct ambarella_uart_port_info *)(port->private_data); |
| |
| if (port_info->get_ms) { |
| mcr = amba_readl(port->membase + UART_MC_OFFSET); |
| |
| if (mctrl & TIOCM_DTR) |
| mcr_new |= UART_MC_DTR; |
| if (mctrl & TIOCM_RTS) |
| mcr_new |= UART_MC_RTS; |
| if (mctrl & TIOCM_OUT1) |
| mcr_new |= UART_MC_OUT1; |
| if (mctrl & TIOCM_OUT2) |
| mcr_new |= UART_MC_OUT2; |
| if (mctrl & TIOCM_LOOP) |
| mcr_new |= UART_MC_LB; |
| |
| mcr_new |= port_info->mcr; |
| if (mcr_new != mcr) { |
| if ((mcr & UART_MC_AFCE) == UART_MC_AFCE) { |
| mcr &= ~UART_MC_AFCE; |
| amba_writel(port->membase + UART_MC_OFFSET, |
| mcr); |
| } |
| amba_writel(port->membase + UART_MC_OFFSET, mcr_new); |
| } |
| } |
| } |
| |
| static void serial_ambarella_break_ctl(struct uart_port *port, int break_state) |
| { |
| unsigned long flags; |
| |
| spin_lock_irqsave(&port->lock, flags); |
| if (break_state != 0) |
| amba_setbitsl(port->membase + UART_LC_OFFSET, UART_LC_BRK); |
| else |
| amba_clrbitsl(port->membase + UART_LC_OFFSET, UART_LC_BRK); |
| spin_unlock_irqrestore(&port->lock, flags); |
| } |
| |
| static int serial_ambarella_startup(struct uart_port *port) |
| { |
| int retval = 0; |
| struct ambarella_uart_port_info *port_info; |
| unsigned long flags; |
| |
| port_info = (struct ambarella_uart_port_info *)(port->private_data); |
| |
| spin_lock_irqsave(&port->lock, flags); |
| amba_setbitsl(port->membase + UART_SRR_OFFSET, 0x00); |
| amba_writel(port->membase + UART_IE_OFFSET, port_info->ier | |
| UART_IE_PTIME); |
| amba_writel(port->membase + UART_FC_OFFSET, (port_info->fcr | |
| UART_FC_XMITR | UART_FC_RCVRR)); |
| amba_writel(port->membase + UART_IE_OFFSET, port_info->ier); |
| spin_unlock_irqrestore(&port->lock, flags); |
| retval = request_irq(port->irq, serial_ambarella_irq, |
| IRQF_TRIGGER_HIGH, dev_name(port->dev), port); |
| |
| return retval; |
| } |
| |
| static void serial_ambarella_shutdown(struct uart_port *port) |
| { |
| unsigned long flags; |
| |
| free_irq(port->irq, port); |
| |
| spin_lock_irqsave(&port->lock, flags); |
| amba_clrbitsl(port->membase + UART_LC_OFFSET, UART_LC_BRK); |
| amba_setbitsl(port->membase + UART_SRR_OFFSET, 0x01); |
| spin_unlock_irqrestore(&port->lock, flags); |
| } |
| |
| static void serial_ambarella_set_termios(struct uart_port *port, |
| struct ktermios *termios, struct ktermios *old) |
| { |
| struct ambarella_uart_port_info *port_info; |
| unsigned int baud, quot; |
| u32 lc = 0x0; |
| |
| port_info = (struct ambarella_uart_port_info *)(port->private_data); |
| |
| port->uartclk = port_info->get_pll(); |
| switch (termios->c_cflag & CSIZE) { |
| case CS5: |
| lc |= UART_LC_CLS_5_BITS; |
| break; |
| case CS6: |
| lc |= UART_LC_CLS_6_BITS; |
| break; |
| case CS7: |
| lc |= UART_LC_CLS_7_BITS; |
| break; |
| case CS8: |
| default: |
| lc |= UART_LC_CLS_8_BITS; |
| break; |
| } |
| |
| if (termios->c_cflag & CSTOPB) |
| lc |= UART_LC_STOP_2BIT; |
| else |
| lc |= UART_LC_STOP_1BIT; |
| |
| if (termios->c_cflag & PARENB) { |
| if (termios->c_cflag & PARODD) |
| lc |= (UART_LC_PEN | UART_LC_ODD_PARITY); |
| else |
| lc |= (UART_LC_PEN | UART_LC_EVEN_PARITY); |
| } |
| |
| baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk / 16); |
| quot = uart_get_divisor(port, baud); |
| |
| disable_irq(port->irq); |
| uart_update_timeout(port, termios->c_cflag, baud); |
| |
| port->read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR; |
| if (termios->c_iflag & INPCK) |
| port->read_status_mask |= UART_LSR_FE | UART_LSR_PE; |
| if (termios->c_iflag & (BRKINT | PARMRK)) |
| port->read_status_mask |= UART_LSR_BI; |
| |
| port->ignore_status_mask = 0; |
| if (termios->c_iflag & IGNPAR) |
| port->ignore_status_mask |= UART_LSR_PE | UART_LSR_FE; |
| if (termios->c_iflag & IGNBRK) { |
| port->ignore_status_mask |= UART_LSR_BI; |
| if (termios->c_iflag & IGNPAR) |
| port->ignore_status_mask |= UART_LSR_OE; |
| } |
| if ((termios->c_cflag & CREAD) == 0) |
| port->ignore_status_mask |= UART_LSR_DR; |
| |
| if ((termios->c_cflag & CRTSCTS) == 0) |
| port_info->mcr &= ~UART_MC_AFCE; |
| else |
| port_info->mcr |= UART_MC_AFCE; |
| |
| amba_writel(port->membase + UART_LC_OFFSET, UART_LC_DLAB); |
| amba_writel(port->membase + UART_DLL_OFFSET, quot & 0xff); |
| amba_writel(port->membase + UART_DLH_OFFSET, (quot >> 8) & 0xff); |
| amba_writel(port->membase + UART_LC_OFFSET, lc); |
| if (UART_ENABLE_MS(port, termios->c_cflag)) |
| __serial_ambarella_enable_ms(port); |
| else |
| __serial_ambarella_disable_ms(port); |
| serial_ambarella_set_mctrl(port, port->mctrl); |
| |
| enable_irq(port->irq); |
| } |
| |
| static void serial_ambarella_pm(struct uart_port *port, |
| unsigned int state, unsigned int oldstate) |
| { |
| } |
| |
| static void serial_ambarella_release_port(struct uart_port *port) |
| { |
| } |
| |
| static int serial_ambarella_request_port(struct uart_port *port) |
| { |
| return 0; |
| } |
| |
| static void serial_ambarella_config_port(struct uart_port *port, int flags) |
| { |
| } |
| |
| static int serial_ambarella_verify_port(struct uart_port *port, |
| struct serial_struct *ser) |
| { |
| int retval = 0; |
| |
| if (ser->type != PORT_UNKNOWN && ser->type != PORT_UART00) |
| retval = -EINVAL; |
| if (port->irq != ser->irq) |
| retval = -EINVAL; |
| if (ser->io_type != SERIAL_IO_MEM) |
| retval = -EINVAL; |
| |
| return retval; |
| } |
| |
| static const char *serial_ambarella_type(struct uart_port *port) |
| { |
| return "ambuart"; |
| } |
| |
| #ifdef CONFIG_CONSOLE_POLL |
| static void serial_ambarella_poll_put_char(struct uart_port *port, |
| unsigned char chr) |
| { |
| struct ambarella_uart_port_info *port_info; |
| |
| port_info = (struct ambarella_uart_port_info *)(port->private_data); |
| if (!port->suspended) { |
| wait_for_tx(port); |
| amba_writel(port->membase + UART_TH_OFFSET, chr); |
| } |
| } |
| |
| static int serial_ambarella_poll_get_char(struct uart_port *port) |
| { |
| struct ambarella_uart_port_info *port_info; |
| |
| port_info = (struct ambarella_uart_port_info *)(port->private_data); |
| if (!port->suspended) { |
| wait_for_rx(port); |
| return amba_readl(port->membase + UART_RB_OFFSET); |
| } |
| return 0; |
| } |
| #endif |
| |
| struct uart_ops serial_ambarella_pops = { |
| .tx_empty = serial_ambarella_tx_empty, |
| .set_mctrl = serial_ambarella_set_mctrl, |
| .get_mctrl = serial_ambarella_get_mctrl, |
| .stop_tx = serial_ambarella_stop_tx, |
| .start_tx = serial_ambarella_start_tx, |
| .stop_rx = serial_ambarella_stop_rx, |
| .enable_ms = serial_ambarella_enable_ms, |
| .break_ctl = serial_ambarella_break_ctl, |
| .startup = serial_ambarella_startup, |
| .shutdown = serial_ambarella_shutdown, |
| .set_termios = serial_ambarella_set_termios, |
| .pm = serial_ambarella_pm, |
| .type = serial_ambarella_type, |
| .release_port = serial_ambarella_release_port, |
| .request_port = serial_ambarella_request_port, |
| .config_port = serial_ambarella_config_port, |
| .verify_port = serial_ambarella_verify_port, |
| #ifdef CONFIG_CONSOLE_POLL |
| .poll_put_char = serial_ambarella_poll_put_char, |
| .poll_get_char = serial_ambarella_poll_get_char, |
| #endif |
| }; |
| |
| /* ==========================================================================*/ |
| #if defined(CONFIG_SERIAL_AMBARELLA_CONSOLE) |
| static struct uart_driver serial_ambarella_reg; |
| |
| static void serial_ambarella_console_putchar(struct uart_port *port, int ch) |
| { |
| wait_for_tx(port); |
| amba_writel(port->membase + UART_TH_OFFSET, ch); |
| } |
| |
| static void serial_ambarella_console_write(struct console *co, |
| const char *s, unsigned int count) |
| { |
| u32 ie; |
| struct uart_port *port; |
| unsigned long flags; |
| int locked = 1; |
| |
| port = (struct uart_port *)( |
| ambarella_uart_ports.amba_port[co->index].port); |
| |
| if (!port->suspended) { |
| local_irq_save(flags); |
| if (port->sysrq) { |
| locked = 0; |
| } else if (oops_in_progress) { |
| locked = spin_trylock(&port->lock); |
| } else { |
| spin_lock(&port->lock); |
| locked = 1; |
| } |
| |
| ie = amba_readl(port->membase + UART_IE_OFFSET); |
| amba_writel(port->membase + UART_IE_OFFSET, |
| ie & ~UART_IE_ETBEI); |
| |
| uart_console_write(port, s, count, |
| serial_ambarella_console_putchar); |
| |
| wait_for_tx(port); |
| amba_writel(port->membase + UART_IE_OFFSET, ie); |
| |
| if (locked) |
| spin_unlock(&port->lock); |
| local_irq_restore(flags); |
| } |
| } |
| |
| static int __init serial_ambarella_console_setup(struct console *co, |
| char *options) |
| { |
| struct uart_port *port; |
| int baud = 115200; |
| int bits = 8; |
| int parity = 'n'; |
| int flow = 'n'; |
| |
| if (co->index < 0 || co->index >= ambarella_uart_ports.total_port_num) |
| co->index = 0; |
| port = (struct uart_port *)( |
| ambarella_uart_ports.amba_port[co->index].port); |
| ambarella_uart_ports.amba_port[co->index].set_pll(); |
| port->uartclk = ambarella_uart_ports.amba_port[co->index].get_pll(); |
| port->ops = &serial_ambarella_pops; |
| port->private_data = &(ambarella_uart_ports.amba_port[co->index]); |
| port->line = co->index; |
| |
| if (options) |
| uart_parse_options(options, &baud, &parity, &bits, &flow); |
| |
| return uart_set_options(port, co, baud, parity, bits, flow); |
| } |
| |
| static struct console serial_ambarella_console = { |
| .name = "ttyS", |
| .write = serial_ambarella_console_write, |
| .device = uart_console_device, |
| .setup = serial_ambarella_console_setup, |
| .flags = CON_PRINTBUFFER | CON_ANYTIME, |
| .index = -1, |
| .data = &serial_ambarella_reg, |
| }; |
| |
| static int __init serial_ambarella_console_init(void) |
| { |
| if (serial_ambarella_reg.nr == -1) |
| serial_ambarella_reg.nr = ambarella_uart_ports.total_port_num; |
| |
| register_console(&serial_ambarella_console); |
| |
| return 0; |
| } |
| |
| console_initcall(serial_ambarella_console_init); |
| |
| #define AMBARELLA_CONSOLE &serial_ambarella_console |
| #else |
| #define AMBARELLA_CONSOLE NULL |
| #endif |
| |
| /* ==========================================================================*/ |
| static struct uart_driver serial_ambarella_reg = { |
| .owner = THIS_MODULE, |
| .driver_name = "ambarella-uart", |
| .dev_name = "ttyS", |
| .major = TTY_MAJOR, |
| .minor = 64, |
| .nr = -1, |
| .cons = AMBARELLA_CONSOLE, |
| }; |
| |
| static int __devinit serial_ambarella_probe(struct platform_device *pdev) |
| { |
| int retval = 0; |
| struct ambarella_uart_platform_info *pinfo; |
| struct uart_port *port; |
| |
| pinfo = (struct ambarella_uart_platform_info *)pdev->dev.platform_data; |
| if (pinfo == NULL) { |
| dev_err(&pdev->dev, "Can't get UART platform data!\n"); |
| retval = -ENXIO; |
| goto serial_ambarella_probe_exit; |
| } |
| |
| if ((pdev->id < 0) || (pdev->id >= pinfo->total_port_num)) { |
| dev_err(&pdev->dev, "Wrong UART ID %d!\n", pdev->id); |
| retval = -ENXIO; |
| goto serial_ambarella_probe_exit; |
| } |
| |
| port = (struct uart_port *)(pinfo->amba_port[pdev->id].port); |
| pinfo->amba_port[pdev->id].set_pll(); |
| port->uartclk = pinfo->amba_port[pdev->id].get_pll(); |
| port->ops = &serial_ambarella_pops; |
| port->dev = &pdev->dev; |
| port->private_data = &(pinfo->amba_port[pdev->id]); |
| port->line = pdev->id; |
| |
| if (pinfo->registed_port_num == 0) { |
| if (serial_ambarella_reg.nr != pinfo->total_port_num) |
| serial_ambarella_reg.nr = pinfo->total_port_num; |
| |
| retval = uart_register_driver(&serial_ambarella_reg); |
| if (retval) { |
| dev_err(&pdev->dev, |
| "uart_register_driver fail %d!\n", |
| retval); |
| goto serial_ambarella_probe_exit; |
| } |
| } |
| |
| retval = uart_add_one_port(&serial_ambarella_reg, port); |
| if (retval) { |
| dev_err(&pdev->dev, |
| "uart_add_one_port %d fail %d!\n", |
| pdev->id, retval); |
| goto serial_ambarella_probe_unregister_driver; |
| } else { |
| pinfo->registed_port_num++; |
| } |
| |
| goto serial_ambarella_probe_exit; |
| |
| serial_ambarella_probe_unregister_driver: |
| if (pinfo->registed_port_num == 0) |
| uart_unregister_driver(&serial_ambarella_reg); |
| |
| serial_ambarella_probe_exit: |
| return retval; |
| } |
| |
| static int __devexit serial_ambarella_remove(struct platform_device *pdev) |
| { |
| int retval = 0; |
| struct ambarella_uart_platform_info *pinfo; |
| struct uart_port *port; |
| |
| pinfo = (struct ambarella_uart_platform_info *)pdev->dev.platform_data; |
| |
| if (pinfo) { |
| port = (struct uart_port *)(pinfo->amba_port[pdev->id].port); |
| retval = uart_remove_one_port(&serial_ambarella_reg, port); |
| if (retval) { |
| dev_err(&pdev->dev, |
| "uart_remove_one_port %d fail %d!\n", |
| pdev->id, retval); |
| } else { |
| pinfo->registed_port_num--; |
| } |
| |
| if (pinfo->registed_port_num == 0) |
| uart_unregister_driver(&serial_ambarella_reg); |
| |
| dev_notice(&pdev->dev, |
| "Remove Ambarella Media Processor UART.\n"); |
| } |
| |
| return retval; |
| } |
| |
| #ifdef CONFIG_PM |
| static int serial_ambarella_suspend(struct platform_device *pdev, |
| pm_message_t state) |
| { |
| int retval = 0; |
| struct ambarella_uart_platform_info *pinfo; |
| struct uart_port *port; |
| |
| pinfo = (struct ambarella_uart_platform_info *)pdev->dev.platform_data; |
| if (pinfo) { |
| port = (struct uart_port *)(pinfo->amba_port[pdev->id].port); |
| retval = uart_suspend_port(&serial_ambarella_reg, port); |
| } |
| dev_dbg(&pdev->dev, "%s exit with %d @ %d\n", |
| __func__, retval, state.event); |
| |
| return retval; |
| } |
| |
| static int serial_ambarella_resume(struct platform_device *pdev) |
| { |
| int retval = 0; |
| struct ambarella_uart_platform_info *pinfo; |
| struct uart_port *port; |
| |
| pinfo = (struct ambarella_uart_platform_info *)pdev->dev.platform_data; |
| if (pinfo) { |
| port = (struct uart_port *)(pinfo->amba_port[pdev->id].port); |
| retval = uart_resume_port(&serial_ambarella_reg, port); |
| } |
| dev_dbg(&pdev->dev, "%s exit with %d\n", __func__, retval); |
| |
| return retval; |
| } |
| #endif |
| |
| static struct platform_driver serial_ambarella_driver = { |
| .probe = serial_ambarella_probe, |
| .remove = __devexit_p(serial_ambarella_remove), |
| #ifdef CONFIG_PM |
| .suspend = serial_ambarella_suspend, |
| .resume = serial_ambarella_resume, |
| #endif |
| .driver = { |
| .name = "ambarella-uart", |
| }, |
| }; |
| |
| int __init serial_ambarella_init(void) |
| { |
| return platform_driver_register(&serial_ambarella_driver); |
| } |
| |
| void __exit serial_ambarella_exit(void) |
| { |
| platform_driver_unregister(&serial_ambarella_driver); |
| } |
| |
| module_init(serial_ambarella_init); |
| module_exit(serial_ambarella_exit); |
| |
| MODULE_AUTHOR("Anthony Ginger"); |
| MODULE_DESCRIPTION("Ambarella Media Processor UART driver"); |
| MODULE_LICENSE("GPL"); |
| MODULE_ALIAS("platform:ambarella-uart"); |
| |