summaryrefslogtreecommitdiffstats
path: root/drivers/staging/sb105x/sb_pci_mp.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/staging/sb105x/sb_pci_mp.c')
-rw-r--r--drivers/staging/sb105x/sb_pci_mp.c3196
1 files changed, 3196 insertions, 0 deletions
diff --git a/drivers/staging/sb105x/sb_pci_mp.c b/drivers/staging/sb105x/sb_pci_mp.c
new file mode 100644
index 000000000000..edb2a85b9d52
--- /dev/null
+++ b/drivers/staging/sb105x/sb_pci_mp.c
@@ -0,0 +1,3196 @@
+#include "sb_pci_mp.h"
+#include <linux/module.h>
+#include <linux/parport.h>
+
+extern struct parport *parport_pc_probe_port(unsigned long base_lo,
+ unsigned long base_hi,
+ int irq, int dma,
+ struct device *dev,
+ int irqflags);
+
+static struct mp_device_t mp_devs[MAX_MP_DEV];
+static int mp_nrpcibrds = sizeof(mp_pciboards)/sizeof(mppcibrd_t);
+static int NR_BOARD=0;
+static int NR_PORTS=0;
+static struct mp_port multi_ports[MAX_MP_PORT];
+static struct irq_info irq_lists[NR_IRQS];
+
+static _INLINE_ unsigned int serial_in(struct mp_port *mtpt, int offset);
+static _INLINE_ void serial_out(struct mp_port *mtpt, int offset, int value);
+static _INLINE_ unsigned int read_option_register(struct mp_port *mtpt, int offset);
+static int sb1054_get_register(struct sb_uart_port * port, int page, int reg);
+static int sb1054_set_register(struct sb_uart_port * port, int page, int reg, int value);
+static void SendATCommand(struct mp_port * mtpt);
+static int set_deep_fifo(struct sb_uart_port * port, int status);
+static int get_deep_fifo(struct sb_uart_port * port);
+static int get_device_type(int arg);
+static int set_auto_rts(struct sb_uart_port *port, int status);
+static void mp_stop(struct tty_struct *tty);
+static void __mp_start(struct tty_struct *tty);
+static void mp_start(struct tty_struct *tty);
+static void mp_tasklet_action(unsigned long data);
+static inline void mp_update_mctrl(struct sb_uart_port *port, unsigned int set, unsigned int clear);
+static int mp_startup(struct sb_uart_state *state, int init_hw);
+static void mp_shutdown(struct sb_uart_state *state);
+static void mp_change_speed(struct sb_uart_state *state, struct MP_TERMIOS *old_termios);
+
+static inline int __mp_put_char(struct sb_uart_port *port, struct circ_buf *circ, unsigned char c);
+static int mp_put_char(struct tty_struct *tty, unsigned char ch);
+
+static void mp_put_chars(struct tty_struct *tty);
+static int mp_write(struct tty_struct *tty, const unsigned char * buf, int count);
+static int mp_write_room(struct tty_struct *tty);
+static int mp_chars_in_buffer(struct tty_struct *tty);
+static void mp_flush_buffer(struct tty_struct *tty);
+static void mp_send_xchar(struct tty_struct *tty, char ch);
+static void mp_throttle(struct tty_struct *tty);
+static void mp_unthrottle(struct tty_struct *tty);
+static int mp_get_info(struct sb_uart_state *state, struct serial_struct *retinfo);
+static int mp_set_info(struct sb_uart_state *state, struct serial_struct *newinfo);
+static int mp_get_lsr_info(struct sb_uart_state *state, unsigned int *value);
+
+static int mp_tiocmget(struct tty_struct *tty);
+static int mp_tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear);
+static int mp_break_ctl(struct tty_struct *tty, int break_state);
+static int mp_do_autoconfig(struct sb_uart_state *state);
+static int mp_wait_modem_status(struct sb_uart_state *state, unsigned long arg);
+static int mp_get_count(struct sb_uart_state *state, struct serial_icounter_struct *icnt);
+static int mp_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg);
+static void mp_set_termios(struct tty_struct *tty, struct MP_TERMIOS *old_termios);
+static void mp_close(struct tty_struct *tty, struct file *filp);
+static void mp_wait_until_sent(struct tty_struct *tty, int timeout);
+static void mp_hangup(struct tty_struct *tty);
+static void mp_update_termios(struct sb_uart_state *state);
+static int mp_block_til_ready(struct file *filp, struct sb_uart_state *state);
+static struct sb_uart_state *uart_get(struct uart_driver *drv, int line);
+static int mp_open(struct tty_struct *tty, struct file *filp);
+static const char *mp_type(struct sb_uart_port *port);
+static void mp_change_pm(struct sb_uart_state *state, int pm_state);
+static inline void mp_report_port(struct uart_driver *drv, struct sb_uart_port *port);
+static void mp_configure_port(struct uart_driver *drv, struct sb_uart_state *state, struct sb_uart_port *port);
+static void mp_unconfigure_port(struct uart_driver *drv, struct sb_uart_state *state);
+static int mp_register_driver(struct uart_driver *drv);
+static void mp_unregister_driver(struct uart_driver *drv);
+static int mp_add_one_port(struct uart_driver *drv, struct sb_uart_port *port);
+static int mp_remove_one_port(struct uart_driver *drv, struct sb_uart_port *port);
+static void autoconfig(struct mp_port *mtpt, unsigned int probeflags);
+static void autoconfig_irq(struct mp_port *mtpt);
+static void multi_stop_tx(struct sb_uart_port *port);
+static void multi_start_tx(struct sb_uart_port *port);
+static void multi_stop_rx(struct sb_uart_port *port);
+static void multi_enable_ms(struct sb_uart_port *port);
+static _INLINE_ void receive_chars(struct mp_port *mtpt, int *status );
+static _INLINE_ void transmit_chars(struct mp_port *mtpt);
+static _INLINE_ void check_modem_status(struct mp_port *mtpt);
+static inline void multi_handle_port(struct mp_port *mtpt);
+static irqreturn_t multi_interrupt(int irq, void *dev_id);
+static void serial_do_unlink(struct irq_info *i, struct mp_port *mtpt);
+static int serial_link_irq_chain(struct mp_port *mtpt);
+static void serial_unlink_irq_chain(struct mp_port *mtpt);
+static void multi_timeout(unsigned long data);
+static unsigned int multi_tx_empty(struct sb_uart_port *port);
+static unsigned int multi_get_mctrl(struct sb_uart_port *port);
+static void multi_set_mctrl(struct sb_uart_port *port, unsigned int mctrl);
+static void multi_break_ctl(struct sb_uart_port *port, int break_state);
+static int multi_startup(struct sb_uart_port *port);
+static void multi_shutdown(struct sb_uart_port *port);
+static unsigned int multi_get_divisor(struct sb_uart_port *port, unsigned int baud);
+static void multi_set_termios(struct sb_uart_port *port, struct MP_TERMIOS *termios, struct MP_TERMIOS *old);
+static void multi_pm(struct sb_uart_port *port, unsigned int state, unsigned int oldstate);
+static void multi_release_std_resource(struct mp_port *mtpt);
+static void multi_release_port(struct sb_uart_port *port);
+static int multi_request_port(struct sb_uart_port *port);
+static void multi_config_port(struct sb_uart_port *port, int flags);
+static int multi_verify_port(struct sb_uart_port *port, struct serial_struct *ser);
+static const char * multi_type(struct sb_uart_port *port);
+static void __init multi_init_ports(void);
+static void __init multi_register_ports(struct uart_driver *drv);
+static int init_mp_dev(struct pci_dev *pcidev, mppcibrd_t brd);
+
+static int deep[256];
+static int deep_count;
+static int fcr_arr[256];
+static int fcr_count;
+static int ttr[256];
+static int ttr_count;
+static int rtr[256];
+static int rtr_count;
+
+module_param_array(deep,int,&deep_count,0);
+module_param_array(fcr_arr,int,&fcr_count,0);
+module_param_array(ttr,int,&ttr_count,0);
+module_param_array(rtr,int,&rtr_count,0);
+
+static _INLINE_ unsigned int serial_in(struct mp_port *mtpt, int offset)
+{
+ return inb(mtpt->port.iobase + offset);
+}
+
+static _INLINE_ void serial_out(struct mp_port *mtpt, int offset, int value)
+{
+ outb(value, mtpt->port.iobase + offset);
+}
+
+static _INLINE_ unsigned int read_option_register(struct mp_port *mtpt, int offset)
+{
+ return inb(mtpt->option_base_addr + offset);
+}
+
+static int sb1053a_get_interface(struct mp_port *mtpt, int port_num)
+{
+ unsigned long option_base_addr = mtpt->option_base_addr;
+ unsigned int interface = 0;
+
+ switch (port_num)
+ {
+ case 0:
+ case 1:
+ /* set GPO[1:0] = 00 */
+ outb(0x00, option_base_addr + MP_OPTR_GPODR);
+ break;
+ case 2:
+ case 3:
+ /* set GPO[1:0] = 01 */
+ outb(0x01, option_base_addr + MP_OPTR_GPODR);
+ break;
+ case 4:
+ case 5:
+ /* set GPO[1:0] = 10 */
+ outb(0x02, option_base_addr + MP_OPTR_GPODR);
+ break;
+ default:
+ break;
+ }
+
+ port_num &= 0x1;
+
+ /* get interface */
+ interface = inb(option_base_addr + MP_OPTR_IIR0 + port_num);
+
+ /* set GPO[1:0] = 11 */
+ outb(0x03, option_base_addr + MP_OPTR_GPODR);
+
+ return (interface);
+}
+
+static int sb1054_get_register(struct sb_uart_port * port, int page, int reg)
+{
+ int ret = 0;
+ unsigned int lcr = 0;
+ unsigned int mcr = 0;
+ unsigned int tmp = 0;
+
+ if( page <= 0)
+ {
+ printk(" page 0 can not use this fuction\n");
+ return -1;
+ }
+
+ switch(page)
+ {
+ case 1:
+ lcr = SB105X_GET_LCR(port);
+ tmp = lcr | SB105X_LCR_DLAB;
+ SB105X_PUT_LCR(port, tmp);
+
+ tmp = SB105X_GET_LCR(port);
+
+ ret = SB105X_GET_REG(port,reg);
+ SB105X_PUT_LCR(port,lcr);
+ break;
+ case 2:
+ mcr = SB105X_GET_MCR(port);
+ tmp = mcr | SB105X_MCR_P2S;
+ SB105X_PUT_MCR(port,tmp);
+
+ ret = SB105X_GET_REG(port,reg);
+
+ SB105X_PUT_MCR(port,mcr);
+ break;
+ case 3:
+ lcr = SB105X_GET_LCR(port);
+ tmp = lcr | SB105X_LCR_BF;
+ SB105X_PUT_LCR(port,tmp);
+ SB105X_PUT_REG(port,SB105X_PSR,SB105X_PSR_P3KEY);
+
+ ret = SB105X_GET_REG(port,reg);
+
+ SB105X_PUT_LCR(port,lcr);
+ break;
+ case 4:
+ lcr = SB105X_GET_LCR(port);
+ tmp = lcr | SB105X_LCR_BF;
+ SB105X_PUT_LCR(port,tmp);
+ SB105X_PUT_REG(port,SB105X_PSR,SB105X_PSR_P4KEY);
+
+ ret = SB105X_GET_REG(port,reg);
+
+ SB105X_PUT_LCR(port,lcr);
+ break;
+ default:
+ printk(" error invalid page number \n");
+ return -1;
+ }
+
+ return ret;
+}
+
+static int sb1054_set_register(struct sb_uart_port * port, int page, int reg, int value)
+{
+ int lcr = 0;
+ int mcr = 0;
+ int ret = 0;
+
+ if( page <= 0)
+ {
+ printk(" page 0 can not use this fuction\n");
+ return -1;
+ }
+ switch(page)
+ {
+ case 1:
+ lcr = SB105X_GET_LCR(port);
+ SB105X_PUT_LCR(port, lcr | SB105X_LCR_DLAB);
+
+ SB105X_PUT_REG(port,reg,value);
+
+ SB105X_PUT_LCR(port, lcr);
+ ret = 1;
+ break;
+ case 2:
+ mcr = SB105X_GET_MCR(port);
+ SB105X_PUT_MCR(port, mcr | SB105X_MCR_P2S);
+
+ SB105X_PUT_REG(port,reg,value);
+
+ SB105X_PUT_MCR(port, mcr);
+ ret = 1;
+ break;
+ case 3:
+ lcr = SB105X_GET_LCR(port);
+ SB105X_PUT_LCR(port, lcr | SB105X_LCR_BF);
+ SB105X_PUT_PSR(port, SB105X_PSR_P3KEY);
+
+ SB105X_PUT_REG(port,reg,value);
+
+ SB105X_PUT_LCR(port, lcr);
+ ret = 1;
+ break;
+ case 4:
+ lcr = SB105X_GET_LCR(port);
+ SB105X_PUT_LCR(port, lcr | SB105X_LCR_BF);
+ SB105X_PUT_PSR(port, SB105X_PSR_P4KEY);
+
+ SB105X_PUT_REG(port,reg,value);
+
+ SB105X_PUT_LCR(port, lcr);
+ ret = 1;
+ break;
+ default:
+ printk(" error invalid page number \n");
+ return -1;
+ }
+
+ return ret;
+}
+
+static int set_multidrop_mode(struct sb_uart_port *port, unsigned int mode)
+{
+ int mdr = SB105XA_MDR_NPS;
+
+ if (mode & MDMODE_ENABLE)
+ {
+ mdr |= SB105XA_MDR_MDE;
+ }
+
+ if (1) //(mode & MDMODE_AUTO)
+ {
+ int efr = 0;
+ mdr |= SB105XA_MDR_AME;
+ efr = sb1054_get_register(port, PAGE_3, SB105X_EFR);
+ efr |= SB105X_EFR_SCD;
+ sb1054_set_register(port, PAGE_3, SB105X_EFR, efr);
+ }
+
+ sb1054_set_register(port, PAGE_1, SB105XA_MDR, mdr);
+ port->mdmode &= ~0x6;
+ port->mdmode |= mode;
+ printk("[%d] multidrop init: %x\n", port->line, port->mdmode);
+
+ return 0;
+}
+
+static int get_multidrop_addr(struct sb_uart_port *port)
+{
+ return sb1054_get_register(port, PAGE_3, SB105X_XOFF2);
+}
+
+static int set_multidrop_addr(struct sb_uart_port *port, unsigned int addr)
+{
+ sb1054_set_register(port, PAGE_3, SB105X_XOFF2, addr);
+
+ return 0;
+}
+
+static void SendATCommand(struct mp_port * mtpt)
+{
+ // a t cr lf
+ unsigned char ch[] = {0x61,0x74,0x0d,0x0a,0x0};
+ unsigned char lineControl;
+ unsigned char i=0;
+ unsigned char Divisor = 0xc;
+
+ lineControl = serial_inp(mtpt,UART_LCR);
+ serial_outp(mtpt,UART_LCR,(lineControl | UART_LCR_DLAB));
+ serial_outp(mtpt,UART_DLL,(Divisor & 0xff));
+ serial_outp(mtpt,UART_DLM,(Divisor & 0xff00)>>8); //baudrate is 4800
+
+
+ serial_outp(mtpt,UART_LCR,lineControl);
+ serial_outp(mtpt,UART_LCR,0x03); // N-8-1
+ serial_outp(mtpt,UART_FCR,7);
+ serial_outp(mtpt,UART_MCR,0x3);
+ while(ch[i]){
+ while((serial_inp(mtpt,UART_LSR) & 0x60) !=0x60){
+ ;
+ }
+ serial_outp(mtpt,0,ch[i++]);
+ }
+
+
+}// end of SendATCommand()
+
+static int set_deep_fifo(struct sb_uart_port * port, int status)
+{
+ int afr_status = 0;
+ afr_status = sb1054_get_register(port, PAGE_4, SB105X_AFR);
+
+ if(status == ENABLE)
+ {
+ afr_status |= SB105X_AFR_AFEN;
+ }
+ else
+ {
+ afr_status &= ~SB105X_AFR_AFEN;
+ }
+
+ sb1054_set_register(port,PAGE_4,SB105X_AFR,afr_status);
+ sb1054_set_register(port,PAGE_4,SB105X_TTR,ttr[port->line]);
+ sb1054_set_register(port,PAGE_4,SB105X_RTR,rtr[port->line]);
+ afr_status = sb1054_get_register(port, PAGE_4, SB105X_AFR);
+
+ return afr_status;
+}
+
+static int get_device_type(int arg)
+{
+ int ret;
+ ret = inb(mp_devs[arg].option_reg_addr+MP_OPTR_DIR0);
+ ret = (ret & 0xf0) >> 4;
+ switch (ret)
+ {
+ case DIR_UART_16C550:
+ return PORT_16C55X;
+ case DIR_UART_16C1050:
+ return PORT_16C105X;
+ case DIR_UART_16C1050A:
+ /*
+ if (mtpt->port.line < 2)
+ {
+ return PORT_16C105XA;
+ }
+ else
+ {
+ if (mtpt->device->device_id & 0x50)
+ {
+ return PORT_16C55X;
+ }
+ else
+ {
+ return PORT_16C105X;
+ }
+ }*/
+ return PORT_16C105XA;
+ default:
+ return PORT_UNKNOWN;
+ }
+
+}
+static int get_deep_fifo(struct sb_uart_port * port)
+{
+ int afr_status = 0;
+ afr_status = sb1054_get_register(port, PAGE_4, SB105X_AFR);
+ return afr_status;
+}
+
+static int set_auto_rts(struct sb_uart_port *port, int status)
+{
+ int atr_status = 0;
+
+#if 0
+ int efr_status = 0;
+
+ efr_status = sb1054_get_register(port, PAGE_3, SB105X_EFR);
+ if(status == ENABLE)
+ efr_status |= SB105X_EFR_ARTS;
+ else
+ efr_status &= ~SB105X_EFR_ARTS;
+ sb1054_set_register(port,PAGE_3,SB105X_EFR,efr_status);
+ efr_status = sb1054_get_register(port, PAGE_3, SB105X_EFR);
+#endif
+
+//ATR
+ atr_status = sb1054_get_register(port, PAGE_3, SB105X_ATR);
+ switch(status)
+ {
+ case RS422PTP:
+ atr_status = (SB105X_ATR_TPS) | (SB105X_ATR_A80);
+ break;
+ case RS422MD:
+ atr_status = (SB105X_ATR_TPS) | (SB105X_ATR_TCMS) | (SB105X_ATR_A80);
+ break;
+ case RS485NE:
+ atr_status = (SB105X_ATR_RCMS) | (SB105X_ATR_TPS) | (SB105X_ATR_TCMS) | (SB105X_ATR_A80);
+ break;
+ case RS485ECHO:
+ atr_status = (SB105X_ATR_TPS) | (SB105X_ATR_TCMS) | (SB105X_ATR_A80);
+ break;
+ }
+
+ sb1054_set_register(port,PAGE_3,SB105X_ATR,atr_status);
+ atr_status = sb1054_get_register(port, PAGE_3, SB105X_ATR);
+
+ return atr_status;
+}
+
+static void mp_stop(struct tty_struct *tty)
+{
+ struct sb_uart_state *state = tty->driver_data;
+ struct sb_uart_port *port = state->port;
+ unsigned long flags;
+
+ spin_lock_irqsave(&port->lock, flags);
+ port->ops->stop_tx(port);
+ spin_unlock_irqrestore(&port->lock, flags);
+}
+
+static void __mp_start(struct tty_struct *tty)
+{
+ struct sb_uart_state *state = tty->driver_data;
+ struct sb_uart_port *port = state->port;
+
+ if (!uart_circ_empty(&state->info->xmit) && state->info->xmit.buf &&
+ !tty->stopped && !tty->hw_stopped)
+ port->ops->start_tx(port);
+}
+
+static void mp_start(struct tty_struct *tty)
+{
+ __mp_start(tty);
+}
+
+static void mp_tasklet_action(unsigned long data)
+{
+ struct sb_uart_state *state = (struct sb_uart_state *)data;
+ struct tty_struct *tty;
+
+ printk("tasklet is called!\n");
+ tty = state->info->tty;
+ tty_wakeup(tty);
+}
+
+static inline void mp_update_mctrl(struct sb_uart_port *port, unsigned int set, unsigned int clear)
+{
+ unsigned int old;
+
+ old = port->mctrl;
+ port->mctrl = (old & ~clear) | set;
+ if (old != port->mctrl)
+ port->ops->set_mctrl(port, port->mctrl);
+}
+
+#define uart_set_mctrl(port,set) mp_update_mctrl(port,set,0)
+#define uart_clear_mctrl(port,clear) mp_update_mctrl(port,0,clear)
+
+static int mp_startup(struct sb_uart_state *state, int init_hw)
+{
+ struct sb_uart_info *info = state->info;
+ struct sb_uart_port *port = state->port;
+ unsigned long page;
+ int retval = 0;
+
+ if (info->flags & UIF_INITIALIZED)
+ return 0;
+
+ if (info->tty)
+ set_bit(TTY_IO_ERROR, &info->tty->flags);
+
+ if (port->type == PORT_UNKNOWN)
+ return 0;
+
+ if (!info->xmit.buf) {
+ page = get_zeroed_page(GFP_KERNEL);
+ if (!page)
+ return -ENOMEM;
+
+ info->xmit.buf = (unsigned char *) page;
+
+ uart_circ_clear(&info->xmit);
+ }
+
+ retval = port->ops->startup(port);
+ if (retval == 0) {
+ if (init_hw) {
+ mp_change_speed(state, NULL);
+
+ if (info->tty->termios.c_cflag & CBAUD)
+ uart_set_mctrl(port, TIOCM_RTS | TIOCM_DTR);
+ }
+
+ info->flags |= UIF_INITIALIZED;
+
+
+ clear_bit(TTY_IO_ERROR, &info->tty->flags);
+ }
+
+ if (retval && capable(CAP_SYS_ADMIN))
+ retval = 0;
+
+ return retval;
+}
+
+static void mp_shutdown(struct sb_uart_state *state)
+{
+ struct sb_uart_info *info = state->info;
+ struct sb_uart_port *port = state->port;
+
+ if (info->tty)
+ set_bit(TTY_IO_ERROR, &info->tty->flags);
+
+ if (info->flags & UIF_INITIALIZED) {
+ info->flags &= ~UIF_INITIALIZED;
+
+ if (!info->tty || (info->tty->termios.c_cflag & HUPCL))
+ uart_clear_mctrl(port, TIOCM_DTR | TIOCM_RTS);
+
+ wake_up_interruptible(&info->delta_msr_wait);
+
+ port->ops->shutdown(port);
+
+ synchronize_irq(port->irq);
+ }
+ tasklet_kill(&info->tlet);
+
+ if (info->xmit.buf) {
+ free_page((unsigned long)info->xmit.buf);
+ info->xmit.buf = NULL;
+ }
+}
+
+static void mp_change_speed(struct sb_uart_state *state, struct MP_TERMIOS *old_termios)
+{
+ struct tty_struct *tty = state->info->tty;
+ struct sb_uart_port *port = state->port;
+
+ if (!tty || port->type == PORT_UNKNOWN)
+ return;
+
+ if (tty->termios.c_cflag & CRTSCTS)
+ state->info->flags |= UIF_CTS_FLOW;
+ else
+ state->info->flags &= ~UIF_CTS_FLOW;
+
+ if (tty->termios.c_cflag & CLOCAL)
+ state->info->flags &= ~UIF_CHECK_CD;
+ else
+ state->info->flags |= UIF_CHECK_CD;
+
+ port->ops->set_termios(port, &tty->termios, old_termios);
+}
+
+static inline int __mp_put_char(struct sb_uart_port *port, struct circ_buf *circ, unsigned char c)
+{
+ unsigned long flags;
+ int ret = 0;
+
+ if (!circ->buf)
+ return 0;
+
+ spin_lock_irqsave(&port->lock, flags);
+ if (uart_circ_chars_free(circ) != 0) {
+ circ->buf[circ->head] = c;
+ circ->head = (circ->head + 1) & (UART_XMIT_SIZE - 1);
+ ret = 1;
+ }
+ spin_unlock_irqrestore(&port->lock, flags);
+ return ret;
+}
+
+static int mp_put_char(struct tty_struct *tty, unsigned char ch)
+{
+ struct sb_uart_state *state = tty->driver_data;
+
+ return __mp_put_char(state->port, &state->info->xmit, ch);
+}
+
+static void mp_put_chars(struct tty_struct *tty)
+{
+ mp_start(tty);
+}
+
+static int mp_write(struct tty_struct *tty, const unsigned char * buf, int count)
+{
+ struct sb_uart_state *state = tty->driver_data;
+ struct sb_uart_port *port;
+ struct circ_buf *circ;
+ int c, ret = 0;
+
+ if (!state || !state->info) {
+ return -EL3HLT;
+ }
+
+ port = state->port;
+ circ = &state->info->xmit;
+
+ if (!circ->buf)
+ return 0;
+
+ while (1) {
+ c = CIRC_SPACE_TO_END(circ->head, circ->tail, UART_XMIT_SIZE);
+ if (count < c)
+ c = count;
+ if (c <= 0)
+ break;
+ memcpy(circ->buf + circ->head, buf, c);
+
+ circ->head = (circ->head + c) & (UART_XMIT_SIZE - 1);
+ buf += c;
+ count -= c;
+ ret += c;
+ }
+ mp_start(tty);
+ return ret;
+}
+
+static int mp_write_room(struct tty_struct *tty)
+{
+ struct sb_uart_state *state = tty->driver_data;
+
+ return uart_circ_chars_free(&state->info->xmit);
+}
+
+static int mp_chars_in_buffer(struct tty_struct *tty)
+{
+ struct sb_uart_state *state = tty->driver_data;
+
+ return uart_circ_chars_pending(&state->info->xmit);
+}
+
+static void mp_flush_buffer(struct tty_struct *tty)
+{
+ struct sb_uart_state *state = tty->driver_data;
+ struct sb_uart_port *port;
+ unsigned long flags;
+
+ if (!state || !state->info) {
+ return;
+ }
+
+ port = state->port;
+ spin_lock_irqsave(&port->lock, flags);
+ uart_circ_clear(&state->info->xmit);
+ spin_unlock_irqrestore(&port->lock, flags);
+ wake_up_interruptible(&tty->write_wait);
+ tty_wakeup(tty);
+}
+
+static void mp_send_xchar(struct tty_struct *tty, char ch)
+{
+ struct sb_uart_state *state = tty->driver_data;
+ struct sb_uart_port *port = state->port;
+ unsigned long flags;
+
+ if (port->ops->send_xchar)
+ port->ops->send_xchar(port, ch);
+ else {
+ port->x_char = ch;
+ if (ch) {
+ spin_lock_irqsave(&port->lock, flags);
+ port->ops->start_tx(port);
+ spin_unlock_irqrestore(&port->lock, flags);
+ }
+ }
+}
+
+static void mp_throttle(struct tty_struct *tty)
+{
+ struct sb_uart_state *state = tty->driver_data;
+
+ if (I_IXOFF(tty))
+ mp_send_xchar(tty, STOP_CHAR(tty));
+
+ if (tty->termios.c_cflag & CRTSCTS)
+ uart_clear_mctrl(state->port, TIOCM_RTS);
+}
+
+static void mp_unthrottle(struct tty_struct *tty)
+{
+ struct sb_uart_state *state = tty->driver_data;
+ struct sb_uart_port *port = state->port;
+
+ if (I_IXOFF(tty)) {
+ if (port->x_char)
+ port->x_char = 0;
+ else
+ mp_send_xchar(tty, START_CHAR(tty));
+ }
+
+ if (tty->termios.c_cflag & CRTSCTS)
+ uart_set_mctrl(port, TIOCM_RTS);
+}
+
+static int mp_get_info(struct sb_uart_state *state, struct serial_struct *retinfo)
+{
+ struct sb_uart_port *port = state->port;
+ struct serial_struct tmp;
+
+ memset(&tmp, 0, sizeof(tmp));
+ tmp.type = port->type;
+ tmp.line = port->line;
+ tmp.port = port->iobase;
+ if (HIGH_BITS_OFFSET)
+ tmp.port_high = (long) port->iobase >> HIGH_BITS_OFFSET;
+ tmp.irq = port->irq;
+ tmp.flags = port->flags;
+ tmp.xmit_fifo_size = port->fifosize;
+ tmp.baud_base = port->uartclk / 16;
+ tmp.close_delay = state->close_delay;
+ tmp.closing_wait = state->closing_wait == USF_CLOSING_WAIT_NONE ?
+ ASYNC_CLOSING_WAIT_NONE :
+ state->closing_wait;
+ tmp.custom_divisor = port->custom_divisor;
+ tmp.hub6 = port->hub6;
+ tmp.io_type = port->iotype;
+ tmp.iomem_reg_shift = port->regshift;
+ tmp.iomem_base = (void *)port->mapbase;
+
+ if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
+ return -EFAULT;
+ return 0;
+}
+
+static int mp_set_info(struct sb_uart_state *state, struct serial_struct *newinfo)
+{
+ struct serial_struct new_serial;
+ struct sb_uart_port *port = state->port;
+ unsigned long new_port;
+ unsigned int change_irq, change_port, closing_wait;
+ unsigned int old_custom_divisor;
+ unsigned int old_flags, new_flags;
+ int retval = 0;
+
+ if (copy_from_user(&new_serial, newinfo, sizeof(new_serial)))
+ return -EFAULT;
+
+ new_port = new_serial.port;
+ if (HIGH_BITS_OFFSET)
+ new_port += (unsigned long) new_serial.port_high << HIGH_BITS_OFFSET;
+
+ new_serial.irq = irq_canonicalize(new_serial.irq);
+
+ closing_wait = new_serial.closing_wait == ASYNC_CLOSING_WAIT_NONE ?
+ USF_CLOSING_WAIT_NONE : new_serial.closing_wait;
+ MP_STATE_LOCK(state);
+
+ change_irq = new_serial.irq != port->irq;
+ change_port = new_port != port->iobase ||
+ (unsigned long)new_serial.iomem_base != port->mapbase ||
+ new_serial.hub6 != port->hub6 ||
+ new_serial.io_type != port->iotype ||
+ new_serial.iomem_reg_shift != port->regshift ||
+ new_serial.type != port->type;
+ old_flags = port->flags;
+ new_flags = new_serial.flags;
+ old_custom_divisor = port->custom_divisor;
+
+ if (!capable(CAP_SYS_ADMIN)) {
+ retval = -EPERM;
+ if (change_irq || change_port ||
+ (new_serial.baud_base != port->uartclk / 16) ||
+ (new_serial.close_delay != state->close_delay) ||
+ (closing_wait != state->closing_wait) ||
+ (new_serial.xmit_fifo_size != port->fifosize) ||
+ (((new_flags ^ old_flags) & ~UPF_USR_MASK) != 0))
+ goto exit;
+ port->flags = ((port->flags & ~UPF_USR_MASK) |
+ (new_flags & UPF_USR_MASK));
+ port->custom_divisor = new_serial.custom_divisor;
+ goto check_and_exit;
+ }
+
+ if (port->ops->verify_port)
+ retval = port->ops->verify_port(port, &new_serial);
+
+ if ((new_serial.irq >= NR_IRQS) || (new_serial.irq < 0) ||
+ (new_serial.baud_base < 9600))
+ retval = -EINVAL;
+
+ if (retval)
+ goto exit;
+
+ if (change_port || change_irq) {
+ retval = -EBUSY;
+
+ if (uart_users(state) > 1)
+ goto exit;
+
+ mp_shutdown(state);
+ }
+
+ if (change_port) {
+ unsigned long old_iobase, old_mapbase;
+ unsigned int old_type, old_iotype, old_hub6, old_shift;
+
+ old_iobase = port->iobase;
+ old_mapbase = port->mapbase;
+ old_type = port->type;
+ old_hub6 = port->hub6;
+ old_iotype = port->iotype;
+ old_shift = port->regshift;
+
+ if (old_type != PORT_UNKNOWN)
+ port->ops->release_port(port);
+
+ port->iobase = new_port;
+ port->type = new_serial.type;
+ port->hub6 = new_serial.hub6;
+ port->iotype = new_serial.io_type;
+ port->regshift = new_serial.iomem_reg_shift;
+ port->mapbase = (unsigned long)new_serial.iomem_base;
+
+ if (port->type != PORT_UNKNOWN) {
+ retval = port->ops->request_port(port);
+ } else {
+ retval = 0;
+ }
+
+ if (retval && old_type != PORT_UNKNOWN) {
+ port->iobase = old_iobase;
+ port->type = old_type;
+ port->hub6 = old_hub6;
+ port->iotype = old_iotype;
+ port->regshift = old_shift;
+ port->mapbase = old_mapbase;
+ retval = port->ops->request_port(port);
+ if (retval)
+ port->type = PORT_UNKNOWN;
+
+ retval = -EBUSY;
+ }
+ }
+
+ port->irq = new_serial.irq;
+ port->uartclk = new_serial.baud_base * 16;
+ port->flags = (port->flags & ~UPF_CHANGE_MASK) |
+ (new_flags & UPF_CHANGE_MASK);
+ port->custom_divisor = new_serial.custom_divisor;
+ state->close_delay = new_serial.close_delay;
+ state->closing_wait = closing_wait;
+ port->fifosize = new_serial.xmit_fifo_size;
+ if (state->info->tty)
+ state->info->tty->low_latency =
+ (port->flags & UPF_LOW_LATENCY) ? 1 : 0;
+
+check_and_exit:
+ retval = 0;
+ if (port->type == PORT_UNKNOWN)
+ goto exit;
+ if (state->info->flags & UIF_INITIALIZED) {
+ if (((old_flags ^ port->flags) & UPF_SPD_MASK) ||
+ old_custom_divisor != port->custom_divisor) {
+ if (port->flags & UPF_SPD_MASK) {
+ printk(KERN_NOTICE
+ "%s sets custom speed on ttyMP%d. This "
+ "is deprecated.\n", current->comm,
+ port->line);
+ }
+ mp_change_speed(state, NULL);
+ }
+ } else
+ retval = mp_startup(state, 1);
+exit:
+ MP_STATE_UNLOCK(state);
+ return retval;
+}
+
+
+static int mp_get_lsr_info(struct sb_uart_state *state, unsigned int *value)
+{
+ struct sb_uart_port *port = state->port;
+ unsigned int result;
+
+ result = port->ops->tx_empty(port);
+
+ if (port->x_char ||
+ ((uart_circ_chars_pending(&state->info->xmit) > 0) &&
+ !state->info->tty->stopped && !state->info->tty->hw_stopped))
+ result &= ~TIOCSER_TEMT;
+
+ return put_user(result, value);
+}
+
+static int mp_tiocmget(struct tty_struct *tty)
+{
+ struct sb_uart_state *state = tty->driver_data;
+ struct sb_uart_port *port = state->port;
+ int result = -EIO;
+
+ MP_STATE_LOCK(state);
+ if (!(tty->flags & (1 << TTY_IO_ERROR))) {
+ result = port->mctrl;
+ spin_lock_irq(&port->lock);
+ result |= port->ops->get_mctrl(port);
+ spin_unlock_irq(&port->lock);
+ }
+ MP_STATE_UNLOCK(state);
+ return result;
+}
+
+static int mp_tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear)
+{
+ struct sb_uart_state *state = tty->driver_data;
+ struct sb_uart_port *port = state->port;
+ int ret = -EIO;
+
+
+ MP_STATE_LOCK(state);
+ if (!(tty->flags & (1 << TTY_IO_ERROR))) {
+ mp_update_mctrl(port, set, clear);
+ ret = 0;
+ }
+ MP_STATE_UNLOCK(state);
+
+ return ret;
+}
+
+static int mp_break_ctl(struct tty_struct *tty, int break_state)
+{
+ struct sb_uart_state *state = tty->driver_data;
+ struct sb_uart_port *port = state->port;
+
+ MP_STATE_LOCK(state);
+
+ if (port->type != PORT_UNKNOWN)
+ port->ops->break_ctl(port, break_state);
+
+ MP_STATE_UNLOCK(state);
+ return 0;
+}
+
+static int mp_do_autoconfig(struct sb_uart_state *state)
+{
+ struct sb_uart_port *port = state->port;
+ int flags, ret;
+
+ if (!capable(CAP_SYS_ADMIN))
+ return -EPERM;
+
+ if (mutex_lock_interruptible(&state->mutex))
+ return -ERESTARTSYS;
+ ret = -EBUSY;
+ if (uart_users(state) == 1) {
+ mp_shutdown(state);
+
+ if (port->type != PORT_UNKNOWN)
+ port->ops->release_port(port);
+
+ flags = UART_CONFIG_TYPE;
+ if (port->flags & UPF_AUTO_IRQ)
+ flags |= UART_CONFIG_IRQ;
+
+ port->ops->config_port(port, flags);
+
+ ret = mp_startup(state, 1);
+ }
+ MP_STATE_UNLOCK(state);
+ return ret;
+}
+
+static int mp_wait_modem_status(struct sb_uart_state *state, unsigned long arg)
+{
+ struct sb_uart_port *port = state->port;
+ DECLARE_WAITQUEUE(wait, current);
+ struct sb_uart_icount cprev, cnow;
+ int ret;
+
+ spin_lock_irq(&port->lock);
+ memcpy(&cprev, &port->icount, sizeof(struct sb_uart_icount));
+
+ port->ops->enable_ms(port);
+ spin_unlock_irq(&port->lock);
+
+ add_wait_queue(&state->info->delta_msr_wait, &wait);
+ for (;;) {
+ spin_lock_irq(&port->lock);
+ memcpy(&cnow, &port->icount, sizeof(struct sb_uart_icount));
+ spin_unlock_irq(&port->lock);
+
+ set_current_state(TASK_INTERRUPTIBLE);
+
+ if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
+ ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
+ ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
+ ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
+ ret = 0;
+ break;
+ }
+
+ schedule();
+
+ if (signal_pending(current)) {
+ ret = -ERESTARTSYS;
+ break;
+ }
+
+ cprev = cnow;
+ }
+
+ current->state = TASK_RUNNING;
+ remove_wait_queue(&state->info->delta_msr_wait, &wait);
+
+ return ret;
+}
+
+static int mp_get_count(struct sb_uart_state *state, struct serial_icounter_struct *icnt)
+{
+ struct serial_icounter_struct icount;
+ struct sb_uart_icount cnow;
+ struct sb_uart_port *port = state->port;
+
+ spin_lock_irq(&port->lock);
+ memcpy(&cnow, &port->icount, sizeof(struct sb_uart_icount));
+ spin_unlock_irq(&port->lock);
+
+ icount.cts = cnow.cts;
+ icount.dsr = cnow.dsr;
+ icount.rng = cnow.rng;
+ icount.dcd = cnow.dcd;
+ icount.rx = cnow.rx;
+ icount.tx = cnow.tx;
+ icount.frame = cnow.frame;
+ icount.overrun = cnow.overrun;
+ icount.parity = cnow.parity;
+ icount.brk = cnow.brk;
+ icount.buf_overrun = cnow.buf_overrun;
+
+ return copy_to_user(icnt, &icount, sizeof(icount)) ? -EFAULT : 0;
+}
+
+static int mp_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg)
+{
+ struct sb_uart_state *state = tty->driver_data;
+ struct mp_port *info = (struct mp_port *)state->port;
+ int ret = -ENOIOCTLCMD;
+
+
+ switch (cmd) {
+ case TIOCSMULTIDROP:
+ /* set multi-drop mode enable or disable, and default operation mode is H/W mode */
+ if (info->port.type == PORT_16C105XA)
+ {
+ //arg &= ~0x6;
+ //state->port->mdmode = 0;
+ return set_multidrop_mode((struct sb_uart_port *)info, (unsigned int)arg);
+ }
+ ret = -ENOTSUPP;
+ break;
+ case GETDEEPFIFO:
+ ret = get_deep_fifo(state->port);
+ return ret;
+ case SETDEEPFIFO:
+ ret = set_deep_fifo(state->port,arg);
+ deep[state->port->line] = arg;
+ return ret;
+ case SETTTR:
+ if (info->port.type == PORT_16C105X || info->port.type == PORT_16C105XA){
+ ret = sb1054_set_register(state->port,PAGE_4,SB105X_TTR,arg);
+ ttr[state->port->line] = arg;
+ }
+ return ret;
+ case SETRTR:
+ if (info->port.type == PORT_16C105X || info->port.type == PORT_16C105XA){
+ ret = sb1054_set_register(state->port,PAGE_4,SB105X_RTR,arg);
+ rtr[state->port->line] = arg;
+ }
+ return ret;
+ case GETTTR:
+ if (info->port.type == PORT_16C105X || info->port.type == PORT_16C105XA){
+ ret = sb1054_get_register(state->port,PAGE_4,SB105X_TTR);
+ }
+ return ret;
+ case GETRTR:
+ if (info->port.type == PORT_16C105X || info->port.type == PORT_16C105XA){
+ ret = sb1054_get_register(state->port,PAGE_4,SB105X_RTR);
+ }
+ return ret;
+
+ case SETFCR:
+ if (info->port.type == PORT_16C105X || info->port.type == PORT_16C105XA){
+ ret = sb1054_set_register(state->port,PAGE_1,SB105X_FCR,arg);
+ }
+ else{
+ serial_out(info,2,arg);
+ }
+
+ return ret;
+ case TIOCSMDADDR:
+ /* set multi-drop address */
+ if (info->port.type == PORT_16C105XA)
+ {
+ state->port->mdmode |= MDMODE_ADDR;
+ return set_multidrop_addr((struct sb_uart_port *)info, (unsigned int)arg);
+ }
+ ret = -ENOTSUPP;
+ break;
+
+ case TIOCGMDADDR:
+ /* set multi-drop address */
+ if ((info->port.type == PORT_16C105XA) && (state->port->mdmode & MDMODE_ADDR))