13f542974SPaul B Schroeder /* 23f542974SPaul B Schroeder * This program is free software; you can redistribute it and/or modify 33f542974SPaul B Schroeder * it under the terms of the GNU General Public License as published by 43f542974SPaul B Schroeder * the Free Software Foundation; either version 2 of the License, or 53f542974SPaul B Schroeder * (at your option) any later version. 63f542974SPaul B Schroeder * 73f542974SPaul B Schroeder * This program is distributed in the hope that it will be useful, 83f542974SPaul B Schroeder * but WITHOUT ANY WARRANTY; without even the implied warranty of 93f542974SPaul B Schroeder * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 103f542974SPaul B Schroeder * GNU General Public License for more details. 113f542974SPaul B Schroeder * 123f542974SPaul B Schroeder * You should have received a copy of the GNU General Public License 133f542974SPaul B Schroeder * along with this program; if not, write to the Free Software 143f542974SPaul B Schroeder * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 153f542974SPaul B Schroeder * 163f542974SPaul B Schroeder * Clean ups from Moschip version and a few ioctl implementations by: 173f542974SPaul B Schroeder * Paul B Schroeder <pschroeder "at" uplogix "dot" com> 183f542974SPaul B Schroeder * 193f542974SPaul B Schroeder * Originally based on drivers/usb/serial/io_edgeport.c which is: 203f542974SPaul B Schroeder * Copyright (C) 2000 Inside Out Networks, All rights reserved. 213f542974SPaul B Schroeder * Copyright (C) 2001-2002 Greg Kroah-Hartman <greg@kroah.com> 223f542974SPaul B Schroeder * 233f542974SPaul B Schroeder */ 243f542974SPaul B Schroeder 253f542974SPaul B Schroeder #include <linux/kernel.h> 263f542974SPaul B Schroeder #include <linux/errno.h> 273f542974SPaul B Schroeder #include <linux/init.h> 283f542974SPaul B Schroeder #include <linux/slab.h> 293f542974SPaul B Schroeder #include <linux/tty.h> 303f542974SPaul B Schroeder #include <linux/tty_driver.h> 313f542974SPaul B Schroeder #include <linux/tty_flip.h> 323f542974SPaul B Schroeder #include <linux/module.h> 333f542974SPaul B Schroeder #include <linux/serial.h> 343f542974SPaul B Schroeder #include <linux/usb.h> 353f542974SPaul B Schroeder #include <linux/usb/serial.h> 36880af9dbSAlan Cox #include <linux/uaccess.h> 373f542974SPaul B Schroeder 383f542974SPaul B Schroeder #define DRIVER_DESC "Moschip 7840/7820 USB Serial Driver" 393f542974SPaul B Schroeder 403f542974SPaul B Schroeder /* 413f542974SPaul B Schroeder * 16C50 UART register defines 423f542974SPaul B Schroeder */ 433f542974SPaul B Schroeder 443f542974SPaul B Schroeder #define LCR_BITS_5 0x00 /* 5 bits/char */ 453f542974SPaul B Schroeder #define LCR_BITS_6 0x01 /* 6 bits/char */ 463f542974SPaul B Schroeder #define LCR_BITS_7 0x02 /* 7 bits/char */ 473f542974SPaul B Schroeder #define LCR_BITS_8 0x03 /* 8 bits/char */ 483f542974SPaul B Schroeder #define LCR_BITS_MASK 0x03 /* Mask for bits/char field */ 493f542974SPaul B Schroeder 503f542974SPaul B Schroeder #define LCR_STOP_1 0x00 /* 1 stop bit */ 513f542974SPaul B Schroeder #define LCR_STOP_1_5 0x04 /* 1.5 stop bits (if 5 bits/char) */ 523f542974SPaul B Schroeder #define LCR_STOP_2 0x04 /* 2 stop bits (if 6-8 bits/char) */ 533f542974SPaul B Schroeder #define LCR_STOP_MASK 0x04 /* Mask for stop bits field */ 543f542974SPaul B Schroeder 553f542974SPaul B Schroeder #define LCR_PAR_NONE 0x00 /* No parity */ 563f542974SPaul B Schroeder #define LCR_PAR_ODD 0x08 /* Odd parity */ 573f542974SPaul B Schroeder #define LCR_PAR_EVEN 0x18 /* Even parity */ 583f542974SPaul B Schroeder #define LCR_PAR_MARK 0x28 /* Force parity bit to 1 */ 593f542974SPaul B Schroeder #define LCR_PAR_SPACE 0x38 /* Force parity bit to 0 */ 603f542974SPaul B Schroeder #define LCR_PAR_MASK 0x38 /* Mask for parity field */ 613f542974SPaul B Schroeder 623f542974SPaul B Schroeder #define LCR_SET_BREAK 0x40 /* Set Break condition */ 633f542974SPaul B Schroeder #define LCR_DL_ENABLE 0x80 /* Enable access to divisor latch */ 643f542974SPaul B Schroeder 653f542974SPaul B Schroeder #define MCR_DTR 0x01 /* Assert DTR */ 663f542974SPaul B Schroeder #define MCR_RTS 0x02 /* Assert RTS */ 673f542974SPaul B Schroeder #define MCR_OUT1 0x04 /* Loopback only: Sets state of RI */ 683f542974SPaul B Schroeder #define MCR_MASTER_IE 0x08 /* Enable interrupt outputs */ 693f542974SPaul B Schroeder #define MCR_LOOPBACK 0x10 /* Set internal (digital) loopback mode */ 703f542974SPaul B Schroeder #define MCR_XON_ANY 0x20 /* Enable any char to exit XOFF mode */ 713f542974SPaul B Schroeder 723f542974SPaul B Schroeder #define MOS7840_MSR_CTS 0x10 /* Current state of CTS */ 733f542974SPaul B Schroeder #define MOS7840_MSR_DSR 0x20 /* Current state of DSR */ 743f542974SPaul B Schroeder #define MOS7840_MSR_RI 0x40 /* Current state of RI */ 753f542974SPaul B Schroeder #define MOS7840_MSR_CD 0x80 /* Current state of CD */ 763f542974SPaul B Schroeder 773f542974SPaul B Schroeder /* 783f542974SPaul B Schroeder * Defines used for sending commands to port 793f542974SPaul B Schroeder */ 803f542974SPaul B Schroeder 811e658489SMark Ferrell #define MOS_WDR_TIMEOUT 5000 /* default urb timeout */ 823f542974SPaul B Schroeder 833f542974SPaul B Schroeder #define MOS_PORT1 0x0200 843f542974SPaul B Schroeder #define MOS_PORT2 0x0300 853f542974SPaul B Schroeder #define MOS_VENREG 0x0000 863f542974SPaul B Schroeder #define MOS_MAX_PORT 0x02 873f542974SPaul B Schroeder #define MOS_WRITE 0x0E 883f542974SPaul B Schroeder #define MOS_READ 0x0D 893f542974SPaul B Schroeder 903f542974SPaul B Schroeder /* Requests */ 913f542974SPaul B Schroeder #define MCS_RD_RTYPE 0xC0 923f542974SPaul B Schroeder #define MCS_WR_RTYPE 0x40 933f542974SPaul B Schroeder #define MCS_RDREQ 0x0D 943f542974SPaul B Schroeder #define MCS_WRREQ 0x0E 953f542974SPaul B Schroeder #define MCS_CTRL_TIMEOUT 500 963f542974SPaul B Schroeder #define VENDOR_READ_LENGTH (0x01) 973f542974SPaul B Schroeder 983f542974SPaul B Schroeder #define MAX_NAME_LEN 64 993f542974SPaul B Schroeder 100880af9dbSAlan Cox #define ZLP_REG1 0x3A /* Zero_Flag_Reg1 58 */ 101880af9dbSAlan Cox #define ZLP_REG5 0x3E /* Zero_Flag_Reg5 62 */ 1023f542974SPaul B Schroeder 1033f542974SPaul B Schroeder /* For higher baud Rates use TIOCEXBAUD */ 1043f542974SPaul B Schroeder #define TIOCEXBAUD 0x5462 1053f542974SPaul B Schroeder 1063f542974SPaul B Schroeder /* vendor id and device id defines */ 1073f542974SPaul B Schroeder 10811e1abb4SDavid Ludlow /* The native mos7840/7820 component */ 1093f542974SPaul B Schroeder #define USB_VENDOR_ID_MOSCHIP 0x9710 1103f542974SPaul B Schroeder #define MOSCHIP_DEVICE_ID_7840 0x7840 1113f542974SPaul B Schroeder #define MOSCHIP_DEVICE_ID_7820 0x7820 1120eafe4deSDonald #define MOSCHIP_DEVICE_ID_7810 0x7810 11311e1abb4SDavid Ludlow /* The native component can have its vendor/device id's overridden 11411e1abb4SDavid Ludlow * in vendor-specific implementations. Such devices can be handled 11568e24113SGreg Kroah-Hartman * by making a change here, in id_table. 11611e1abb4SDavid Ludlow */ 11711e1abb4SDavid Ludlow #define USB_VENDOR_ID_BANDB 0x0856 118acf509aeSCliff Brake #define BANDB_DEVICE_ID_USO9ML2_2 0xAC22 119870408c8SDave Ludlow #define BANDB_DEVICE_ID_USO9ML2_2P 0xBC00 120acf509aeSCliff Brake #define BANDB_DEVICE_ID_USO9ML2_4 0xAC24 121870408c8SDave Ludlow #define BANDB_DEVICE_ID_USO9ML2_4P 0xBC01 122acf509aeSCliff Brake #define BANDB_DEVICE_ID_US9ML2_2 0xAC29 123acf509aeSCliff Brake #define BANDB_DEVICE_ID_US9ML2_4 0xAC30 124acf509aeSCliff Brake #define BANDB_DEVICE_ID_USPTL4_2 0xAC31 125acf509aeSCliff Brake #define BANDB_DEVICE_ID_USPTL4_4 0xAC32 12611e1abb4SDavid Ludlow #define BANDB_DEVICE_ID_USOPTL4_2 0xAC42 127caf3a636SDave Ludlow #define BANDB_DEVICE_ID_USOPTL4_2P 0xBC02 128870408c8SDave Ludlow #define BANDB_DEVICE_ID_USOPTL4_4 0xAC44 129870408c8SDave Ludlow #define BANDB_DEVICE_ID_USOPTL4_4P 0xBC03 130870408c8SDave Ludlow #define BANDB_DEVICE_ID_USOPTL2_4 0xAC24 1313f542974SPaul B Schroeder 1329d498beaSRussell Lang /* This driver also supports 1339d498beaSRussell Lang * ATEN UC2324 device using Moschip MCS7840 1349d498beaSRussell Lang * ATEN UC2322 device using Moschip MCS7820 1359d498beaSRussell Lang */ 136e9b8cffaSTony Cook #define USB_VENDOR_ID_ATENINTL 0x0557 137e9b8cffaSTony Cook #define ATENINTL_DEVICE_ID_UC2324 0x2011 1389d498beaSRussell Lang #define ATENINTL_DEVICE_ID_UC2322 0x7820 139e9b8cffaSTony Cook 14011e1abb4SDavid Ludlow /* Interrupt Routine Defines */ 1413f542974SPaul B Schroeder 1423f542974SPaul B Schroeder #define SERIAL_IIR_RLS 0x06 1433f542974SPaul B Schroeder #define SERIAL_IIR_MS 0x00 1443f542974SPaul B Schroeder 1453f542974SPaul B Schroeder /* 1463f542974SPaul B Schroeder * Emulation of the bit mask on the LINE STATUS REGISTER. 1473f542974SPaul B Schroeder */ 1483f542974SPaul B Schroeder #define SERIAL_LSR_DR 0x0001 1493f542974SPaul B Schroeder #define SERIAL_LSR_OE 0x0002 1503f542974SPaul B Schroeder #define SERIAL_LSR_PE 0x0004 1513f542974SPaul B Schroeder #define SERIAL_LSR_FE 0x0008 1523f542974SPaul B Schroeder #define SERIAL_LSR_BI 0x0010 1533f542974SPaul B Schroeder 1543f542974SPaul B Schroeder #define MOS_MSR_DELTA_CTS 0x10 1553f542974SPaul B Schroeder #define MOS_MSR_DELTA_DSR 0x20 1563f542974SPaul B Schroeder #define MOS_MSR_DELTA_RI 0x40 1573f542974SPaul B Schroeder #define MOS_MSR_DELTA_CD 0x80 1583f542974SPaul B Schroeder 159880af9dbSAlan Cox /* Serial Port register Address */ 1603f542974SPaul B Schroeder #define INTERRUPT_ENABLE_REGISTER ((__u16)(0x01)) 1613f542974SPaul B Schroeder #define FIFO_CONTROL_REGISTER ((__u16)(0x02)) 1623f542974SPaul B Schroeder #define LINE_CONTROL_REGISTER ((__u16)(0x03)) 1633f542974SPaul B Schroeder #define MODEM_CONTROL_REGISTER ((__u16)(0x04)) 1643f542974SPaul B Schroeder #define LINE_STATUS_REGISTER ((__u16)(0x05)) 1653f542974SPaul B Schroeder #define MODEM_STATUS_REGISTER ((__u16)(0x06)) 1663f542974SPaul B Schroeder #define SCRATCH_PAD_REGISTER ((__u16)(0x07)) 1673f542974SPaul B Schroeder #define DIVISOR_LATCH_LSB ((__u16)(0x00)) 1683f542974SPaul B Schroeder #define DIVISOR_LATCH_MSB ((__u16)(0x01)) 1693f542974SPaul B Schroeder 1703f542974SPaul B Schroeder #define CLK_MULTI_REGISTER ((__u16)(0x02)) 1713f542974SPaul B Schroeder #define CLK_START_VALUE_REGISTER ((__u16)(0x03)) 172093ea2d3SDonald Lee #define GPIO_REGISTER ((__u16)(0x07)) 1733f542974SPaul B Schroeder 1743f542974SPaul B Schroeder #define SERIAL_LCR_DLAB ((__u16)(0x0080)) 1753f542974SPaul B Schroeder 1763f542974SPaul B Schroeder /* 1773f542974SPaul B Schroeder * URB POOL related defines 1783f542974SPaul B Schroeder */ 1793f542974SPaul B Schroeder #define NUM_URBS 16 /* URB Count */ 1803f542974SPaul B Schroeder #define URB_TRANSFER_BUFFER_SIZE 32 /* URB Size */ 1813f542974SPaul B Schroeder 1820eafe4deSDonald /* LED on/off milliseconds*/ 1830eafe4deSDonald #define LED_ON_MS 500 1840eafe4deSDonald #define LED_OFF_MS 500 1850eafe4deSDonald 1860eafe4deSDonald static int device_type; 1873f542974SPaul B Schroeder 188b9c87663STony Zelenoff static const struct usb_device_id id_table[] = { 1893f542974SPaul B Schroeder {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7840)}, 1903f542974SPaul B Schroeder {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7820)}, 1910eafe4deSDonald {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7810)}, 192acf509aeSCliff Brake {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_2)}, 193870408c8SDave Ludlow {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_2P)}, 194acf509aeSCliff Brake {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_4)}, 195870408c8SDave Ludlow {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_4P)}, 196acf509aeSCliff Brake {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_US9ML2_2)}, 197acf509aeSCliff Brake {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_US9ML2_4)}, 198acf509aeSCliff Brake {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USPTL4_2)}, 199acf509aeSCliff Brake {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USPTL4_4)}, 20011e1abb4SDavid Ludlow {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_2)}, 201870408c8SDave Ludlow {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_2P)}, 202acf509aeSCliff Brake {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_4)}, 203870408c8SDave Ludlow {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_4P)}, 20427f1281dSBlaise Gassend {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL2_4)}, 205e9b8cffaSTony Cook {USB_DEVICE(USB_VENDOR_ID_ATENINTL, ATENINTL_DEVICE_ID_UC2324)}, 2069d498beaSRussell Lang {USB_DEVICE(USB_VENDOR_ID_ATENINTL, ATENINTL_DEVICE_ID_UC2322)}, 2073f542974SPaul B Schroeder {} /* terminating entry */ 2083f542974SPaul B Schroeder }; 20968e24113SGreg Kroah-Hartman MODULE_DEVICE_TABLE(usb, id_table); 2103f542974SPaul B Schroeder 2113f542974SPaul B Schroeder /* This structure holds all of the local port information */ 2123f542974SPaul B Schroeder 2133f542974SPaul B Schroeder struct moschip_port { 2143f542974SPaul B Schroeder int port_num; /*Actual port number in the device(1,2,etc) */ 2153f542974SPaul B Schroeder struct urb *write_urb; /* write URB for this port */ 2163f542974SPaul B Schroeder struct urb *read_urb; /* read URB for this port */ 2173f542974SPaul B Schroeder __u8 shadowLCR; /* last LCR value received */ 2183f542974SPaul B Schroeder __u8 shadowMCR; /* last MCR value received */ 2193f542974SPaul B Schroeder char open; 2200de9a702SOliver Neukum char open_ports; 2213f542974SPaul B Schroeder wait_queue_head_t wait_chase; /* for handling sleeping while waiting for chase to finish */ 2223f542974SPaul B Schroeder int delta_msr_cond; 2233f542974SPaul B Schroeder struct async_icount icount; 2243f542974SPaul B Schroeder struct usb_serial_port *port; /* loop back to the owner of this object */ 2253f542974SPaul B Schroeder 2263f542974SPaul B Schroeder /* Offsets */ 2273f542974SPaul B Schroeder __u8 SpRegOffset; 2283f542974SPaul B Schroeder __u8 ControlRegOffset; 2293f542974SPaul B Schroeder __u8 DcrRegOffset; 230880af9dbSAlan Cox /* for processing control URBS in interrupt context */ 2313f542974SPaul B Schroeder struct urb *control_urb; 2320de9a702SOliver Neukum struct usb_ctrlrequest *dr; 2333f542974SPaul B Schroeder char *ctrl_buf; 2343f542974SPaul B Schroeder int MsrLsr; 2353f542974SPaul B Schroeder 2360de9a702SOliver Neukum spinlock_t pool_lock; 2373f542974SPaul B Schroeder struct urb *write_urb_pool[NUM_URBS]; 2380de9a702SOliver Neukum char busy[NUM_URBS]; 23950de36f7SGreg Kroah-Hartman bool read_urb_busy; 2403f542974SPaul B Schroeder 2410eafe4deSDonald /* For device(s) with LED indicator */ 2420eafe4deSDonald bool has_led; 2430eafe4deSDonald bool led_flag; 2440eafe4deSDonald struct timer_list led_timer1; /* Timer for LED on */ 2450eafe4deSDonald struct timer_list led_timer2; /* Timer for LED off */ 2460eafe4deSDonald }; 2473f542974SPaul B Schroeder 2483f542974SPaul B Schroeder /* 2493f542974SPaul B Schroeder * mos7840_set_reg_sync 2503f542974SPaul B Schroeder * To set the Control register by calling usb_fill_control_urb function 2513f542974SPaul B Schroeder * by passing usb_sndctrlpipe function as parameter. 2523f542974SPaul B Schroeder */ 2533f542974SPaul B Schroeder 2543f542974SPaul B Schroeder static int mos7840_set_reg_sync(struct usb_serial_port *port, __u16 reg, 2553f542974SPaul B Schroeder __u16 val) 2563f542974SPaul B Schroeder { 2573f542974SPaul B Schroeder struct usb_device *dev = port->serial->dev; 2583f542974SPaul B Schroeder val = val & 0x00ff; 2599c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "mos7840_set_reg_sync offset is %x, value %x\n", reg, val); 2603f542974SPaul B Schroeder 2613f542974SPaul B Schroeder return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), MCS_WRREQ, 2623f542974SPaul B Schroeder MCS_WR_RTYPE, val, reg, NULL, 0, 2633f542974SPaul B Schroeder MOS_WDR_TIMEOUT); 2643f542974SPaul B Schroeder } 2653f542974SPaul B Schroeder 2663f542974SPaul B Schroeder /* 2673f542974SPaul B Schroeder * mos7840_get_reg_sync 2683f542974SPaul B Schroeder * To set the Uart register by calling usb_fill_control_urb function by 2693f542974SPaul B Schroeder * passing usb_rcvctrlpipe function as parameter. 2703f542974SPaul B Schroeder */ 2713f542974SPaul B Schroeder 2723f542974SPaul B Schroeder static int mos7840_get_reg_sync(struct usb_serial_port *port, __u16 reg, 2733f542974SPaul B Schroeder __u16 *val) 2743f542974SPaul B Schroeder { 2753f542974SPaul B Schroeder struct usb_device *dev = port->serial->dev; 2763f542974SPaul B Schroeder int ret = 0; 2779e221a35SJohan Hovold u8 *buf; 2789e221a35SJohan Hovold 2799e221a35SJohan Hovold buf = kmalloc(VENDOR_READ_LENGTH, GFP_KERNEL); 2809e221a35SJohan Hovold if (!buf) 2819e221a35SJohan Hovold return -ENOMEM; 2823f542974SPaul B Schroeder 2833f542974SPaul B Schroeder ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), MCS_RDREQ, 2849e221a35SJohan Hovold MCS_RD_RTYPE, 0, reg, buf, VENDOR_READ_LENGTH, 2853f542974SPaul B Schroeder MOS_WDR_TIMEOUT); 2869e221a35SJohan Hovold *val = buf[0]; 2879c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s offset is %x, return val %x\n", __func__, reg, *val); 2889e221a35SJohan Hovold 2899e221a35SJohan Hovold kfree(buf); 2903f542974SPaul B Schroeder return ret; 2913f542974SPaul B Schroeder } 2923f542974SPaul B Schroeder 2933f542974SPaul B Schroeder /* 2943f542974SPaul B Schroeder * mos7840_set_uart_reg 2953f542974SPaul B Schroeder * To set the Uart register by calling usb_fill_control_urb function by 2963f542974SPaul B Schroeder * passing usb_sndctrlpipe function as parameter. 2973f542974SPaul B Schroeder */ 2983f542974SPaul B Schroeder 2993f542974SPaul B Schroeder static int mos7840_set_uart_reg(struct usb_serial_port *port, __u16 reg, 3003f542974SPaul B Schroeder __u16 val) 3013f542974SPaul B Schroeder { 3023f542974SPaul B Schroeder 3033f542974SPaul B Schroeder struct usb_device *dev = port->serial->dev; 3043f542974SPaul B Schroeder val = val & 0x00ff; 305880af9dbSAlan Cox /* For the UART control registers, the application number need 306880af9dbSAlan Cox to be Or'ed */ 3070de9a702SOliver Neukum if (port->serial->num_ports == 4) { 308880af9dbSAlan Cox val |= (((__u16) port->number - 309880af9dbSAlan Cox (__u16) (port->serial->minor)) + 1) << 8; 3103f542974SPaul B Schroeder } else { 3113f542974SPaul B Schroeder if (((__u16) port->number - (__u16) (port->serial->minor)) == 0) { 312880af9dbSAlan Cox val |= (((__u16) port->number - 3133f542974SPaul B Schroeder (__u16) (port->serial->minor)) + 1) << 8; 3143f542974SPaul B Schroeder } else { 3159c134a14SGreg Kroah-Hartman val |= (((__u16) port->number - 3163f542974SPaul B Schroeder (__u16) (port->serial->minor)) + 2) << 8; 3173f542974SPaul B Schroeder } 3183f542974SPaul B Schroeder } 3199c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s application number is %x\n", __func__, val); 3203f542974SPaul B Schroeder return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), MCS_WRREQ, 3213f542974SPaul B Schroeder MCS_WR_RTYPE, val, reg, NULL, 0, 3223f542974SPaul B Schroeder MOS_WDR_TIMEOUT); 3233f542974SPaul B Schroeder 3243f542974SPaul B Schroeder } 3253f542974SPaul B Schroeder 3263f542974SPaul B Schroeder /* 3273f542974SPaul B Schroeder * mos7840_get_uart_reg 3283f542974SPaul B Schroeder * To set the Control register by calling usb_fill_control_urb function 3293f542974SPaul B Schroeder * by passing usb_rcvctrlpipe function as parameter. 3303f542974SPaul B Schroeder */ 3313f542974SPaul B Schroeder static int mos7840_get_uart_reg(struct usb_serial_port *port, __u16 reg, 3323f542974SPaul B Schroeder __u16 *val) 3333f542974SPaul B Schroeder { 3343f542974SPaul B Schroeder struct usb_device *dev = port->serial->dev; 3353f542974SPaul B Schroeder int ret = 0; 3363f542974SPaul B Schroeder __u16 Wval; 3379e221a35SJohan Hovold u8 *buf; 3389e221a35SJohan Hovold 3399e221a35SJohan Hovold buf = kmalloc(VENDOR_READ_LENGTH, GFP_KERNEL); 3409e221a35SJohan Hovold if (!buf) 3419e221a35SJohan Hovold return -ENOMEM; 3423f542974SPaul B Schroeder 3433f542974SPaul B Schroeder /* Wval is same as application number */ 3440de9a702SOliver Neukum if (port->serial->num_ports == 4) { 3453f542974SPaul B Schroeder Wval = 3463f542974SPaul B Schroeder (((__u16) port->number - (__u16) (port->serial->minor)) + 3473f542974SPaul B Schroeder 1) << 8; 3483f542974SPaul B Schroeder } else { 3493f542974SPaul B Schroeder if (((__u16) port->number - (__u16) (port->serial->minor)) == 0) { 350880af9dbSAlan Cox Wval = (((__u16) port->number - 3513f542974SPaul B Schroeder (__u16) (port->serial->minor)) + 1) << 8; 3523f542974SPaul B Schroeder } else { 353880af9dbSAlan Cox Wval = (((__u16) port->number - 3543f542974SPaul B Schroeder (__u16) (port->serial->minor)) + 2) << 8; 3553f542974SPaul B Schroeder } 3563f542974SPaul B Schroeder } 3579c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s application number is %x\n", __func__, Wval); 3583f542974SPaul B Schroeder ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), MCS_RDREQ, 3599e221a35SJohan Hovold MCS_RD_RTYPE, Wval, reg, buf, VENDOR_READ_LENGTH, 3603f542974SPaul B Schroeder MOS_WDR_TIMEOUT); 3619e221a35SJohan Hovold *val = buf[0]; 3629e221a35SJohan Hovold 3639e221a35SJohan Hovold kfree(buf); 3643f542974SPaul B Schroeder return ret; 3653f542974SPaul B Schroeder } 3663f542974SPaul B Schroeder 3679c134a14SGreg Kroah-Hartman static void mos7840_dump_serial_port(struct usb_serial_port *port, 3689c134a14SGreg Kroah-Hartman struct moschip_port *mos7840_port) 3693f542974SPaul B Schroeder { 3703f542974SPaul B Schroeder 3719c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "SpRegOffset is %2x\n", mos7840_port->SpRegOffset); 3729c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "ControlRegOffset is %2x\n", mos7840_port->ControlRegOffset); 3739c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "DCRRegOffset is %2x\n", mos7840_port->DcrRegOffset); 3743f542974SPaul B Schroeder 3753f542974SPaul B Schroeder } 3763f542974SPaul B Schroeder 3773f542974SPaul B Schroeder /************************************************************************/ 3783f542974SPaul B Schroeder /************************************************************************/ 3793f542974SPaul B Schroeder /* I N T E R F A C E F U N C T I O N S */ 3803f542974SPaul B Schroeder /* I N T E R F A C E F U N C T I O N S */ 3813f542974SPaul B Schroeder /************************************************************************/ 3823f542974SPaul B Schroeder /************************************************************************/ 3833f542974SPaul B Schroeder 3843f542974SPaul B Schroeder static inline void mos7840_set_port_private(struct usb_serial_port *port, 3853f542974SPaul B Schroeder struct moschip_port *data) 3863f542974SPaul B Schroeder { 3873f542974SPaul B Schroeder usb_set_serial_port_data(port, (void *)data); 3883f542974SPaul B Schroeder } 3893f542974SPaul B Schroeder 3903f542974SPaul B Schroeder static inline struct moschip_port *mos7840_get_port_private(struct 3913f542974SPaul B Schroeder usb_serial_port 3923f542974SPaul B Schroeder *port) 3933f542974SPaul B Schroeder { 3943f542974SPaul B Schroeder return (struct moschip_port *)usb_get_serial_port_data(port); 3953f542974SPaul B Schroeder } 3963f542974SPaul B Schroeder 3970de9a702SOliver Neukum static void mos7840_handle_new_msr(struct moschip_port *port, __u8 new_msr) 3983f542974SPaul B Schroeder { 3993f542974SPaul B Schroeder struct moschip_port *mos7840_port; 4003f542974SPaul B Schroeder struct async_icount *icount; 4013f542974SPaul B Schroeder mos7840_port = port; 4023f542974SPaul B Schroeder icount = &mos7840_port->icount; 4033f542974SPaul B Schroeder if (new_msr & 4043f542974SPaul B Schroeder (MOS_MSR_DELTA_CTS | MOS_MSR_DELTA_DSR | MOS_MSR_DELTA_RI | 4053f542974SPaul B Schroeder MOS_MSR_DELTA_CD)) { 4063f542974SPaul B Schroeder icount = &mos7840_port->icount; 4073f542974SPaul B Schroeder 4083f542974SPaul B Schroeder /* update input line counters */ 4093f542974SPaul B Schroeder if (new_msr & MOS_MSR_DELTA_CTS) { 4103f542974SPaul B Schroeder icount->cts++; 4110de9a702SOliver Neukum smp_wmb(); 4123f542974SPaul B Schroeder } 4133f542974SPaul B Schroeder if (new_msr & MOS_MSR_DELTA_DSR) { 4143f542974SPaul B Schroeder icount->dsr++; 4150de9a702SOliver Neukum smp_wmb(); 4163f542974SPaul B Schroeder } 4173f542974SPaul B Schroeder if (new_msr & MOS_MSR_DELTA_CD) { 4183f542974SPaul B Schroeder icount->dcd++; 4190de9a702SOliver Neukum smp_wmb(); 4203f542974SPaul B Schroeder } 4213f542974SPaul B Schroeder if (new_msr & MOS_MSR_DELTA_RI) { 4223f542974SPaul B Schroeder icount->rng++; 4230de9a702SOliver Neukum smp_wmb(); 4240de9a702SOliver Neukum } 425e670c6afSJohan Hovold 426e670c6afSJohan Hovold mos7840_port->delta_msr_cond = 1; 427a14430dbSJohan Hovold wake_up_interruptible(&port->port->delta_msr_wait); 4283f542974SPaul B Schroeder } 4293f542974SPaul B Schroeder } 4303f542974SPaul B Schroeder 4310de9a702SOliver Neukum static void mos7840_handle_new_lsr(struct moschip_port *port, __u8 new_lsr) 4323f542974SPaul B Schroeder { 4333f542974SPaul B Schroeder struct async_icount *icount; 4343f542974SPaul B Schroeder 4353f542974SPaul B Schroeder if (new_lsr & SERIAL_LSR_BI) { 436880af9dbSAlan Cox /* 437880af9dbSAlan Cox * Parity and Framing errors only count if they 438880af9dbSAlan Cox * occur exclusive of a break being 439880af9dbSAlan Cox * received. 440880af9dbSAlan Cox */ 4413f542974SPaul B Schroeder new_lsr &= (__u8) (SERIAL_LSR_OE | SERIAL_LSR_BI); 4423f542974SPaul B Schroeder } 4433f542974SPaul B Schroeder 4443f542974SPaul B Schroeder /* update input line counters */ 4453f542974SPaul B Schroeder icount = &port->icount; 4463f542974SPaul B Schroeder if (new_lsr & SERIAL_LSR_BI) { 4473f542974SPaul B Schroeder icount->brk++; 4480de9a702SOliver Neukum smp_wmb(); 4493f542974SPaul B Schroeder } 4503f542974SPaul B Schroeder if (new_lsr & SERIAL_LSR_OE) { 4513f542974SPaul B Schroeder icount->overrun++; 4520de9a702SOliver Neukum smp_wmb(); 4533f542974SPaul B Schroeder } 4543f542974SPaul B Schroeder if (new_lsr & SERIAL_LSR_PE) { 4553f542974SPaul B Schroeder icount->parity++; 4560de9a702SOliver Neukum smp_wmb(); 4573f542974SPaul B Schroeder } 4583f542974SPaul B Schroeder if (new_lsr & SERIAL_LSR_FE) { 4593f542974SPaul B Schroeder icount->frame++; 4600de9a702SOliver Neukum smp_wmb(); 4613f542974SPaul B Schroeder } 4623f542974SPaul B Schroeder } 4633f542974SPaul B Schroeder 4643f542974SPaul B Schroeder /************************************************************************/ 4653f542974SPaul B Schroeder /************************************************************************/ 4663f542974SPaul B Schroeder /* U S B C A L L B A C K F U N C T I O N S */ 4673f542974SPaul B Schroeder /* U S B C A L L B A C K F U N C T I O N S */ 4683f542974SPaul B Schroeder /************************************************************************/ 4693f542974SPaul B Schroeder /************************************************************************/ 4703f542974SPaul B Schroeder 4717d12e780SDavid Howells static void mos7840_control_callback(struct urb *urb) 4723f542974SPaul B Schroeder { 4733f542974SPaul B Schroeder unsigned char *data; 4743f542974SPaul B Schroeder struct moschip_port *mos7840_port; 4759c134a14SGreg Kroah-Hartman struct device *dev = &urb->dev->dev; 4763f542974SPaul B Schroeder __u8 regval = 0x0; 4770643c724SGreg Kroah-Hartman int status = urb->status; 4783f542974SPaul B Schroeder 479cdc97792SMing Lei mos7840_port = urb->context; 4800de9a702SOliver Neukum 4810643c724SGreg Kroah-Hartman switch (status) { 4823f542974SPaul B Schroeder case 0: 4833f542974SPaul B Schroeder /* success */ 4843f542974SPaul B Schroeder break; 4853f542974SPaul B Schroeder case -ECONNRESET: 4863f542974SPaul B Schroeder case -ENOENT: 4873f542974SPaul B Schroeder case -ESHUTDOWN: 4883f542974SPaul B Schroeder /* this urb is terminated, clean up */ 4899c134a14SGreg Kroah-Hartman dev_dbg(dev, "%s - urb shutting down with status: %d\n", __func__, status); 4903f542974SPaul B Schroeder return; 4913f542974SPaul B Schroeder default: 4929c134a14SGreg Kroah-Hartman dev_dbg(dev, "%s - nonzero urb status received: %d\n", __func__, status); 49328c3ae9aSJohan Hovold return; 4943f542974SPaul B Schroeder } 4953f542974SPaul B Schroeder 4969c134a14SGreg Kroah-Hartman dev_dbg(dev, "%s urb buffer size is %d\n", __func__, urb->actual_length); 4979c134a14SGreg Kroah-Hartman dev_dbg(dev, "%s mos7840_port->MsrLsr is %d port %d\n", __func__, 4983f542974SPaul B Schroeder mos7840_port->MsrLsr, mos7840_port->port_num); 4993f542974SPaul B Schroeder data = urb->transfer_buffer; 5003f542974SPaul B Schroeder regval = (__u8) data[0]; 5019c134a14SGreg Kroah-Hartman dev_dbg(dev, "%s data is %x\n", __func__, regval); 5023f542974SPaul B Schroeder if (mos7840_port->MsrLsr == 0) 5033f542974SPaul B Schroeder mos7840_handle_new_msr(mos7840_port, regval); 5043f542974SPaul B Schroeder else if (mos7840_port->MsrLsr == 1) 5053f542974SPaul B Schroeder mos7840_handle_new_lsr(mos7840_port, regval); 5063f542974SPaul B Schroeder } 5073f542974SPaul B Schroeder 5083f542974SPaul B Schroeder static int mos7840_get_reg(struct moschip_port *mcs, __u16 Wval, __u16 reg, 5093f542974SPaul B Schroeder __u16 *val) 5103f542974SPaul B Schroeder { 5113f542974SPaul B Schroeder struct usb_device *dev = mcs->port->serial->dev; 5120de9a702SOliver Neukum struct usb_ctrlrequest *dr = mcs->dr; 5130de9a702SOliver Neukum unsigned char *buffer = mcs->ctrl_buf; 5140de9a702SOliver Neukum int ret; 5153f542974SPaul B Schroeder 5163f542974SPaul B Schroeder dr->bRequestType = MCS_RD_RTYPE; 5173f542974SPaul B Schroeder dr->bRequest = MCS_RDREQ; 518880af9dbSAlan Cox dr->wValue = cpu_to_le16(Wval); /* 0 */ 5193f542974SPaul B Schroeder dr->wIndex = cpu_to_le16(reg); 5203f542974SPaul B Schroeder dr->wLength = cpu_to_le16(2); 5213f542974SPaul B Schroeder 5223f542974SPaul B Schroeder usb_fill_control_urb(mcs->control_urb, dev, usb_rcvctrlpipe(dev, 0), 5233f542974SPaul B Schroeder (unsigned char *)dr, buffer, 2, 5243f542974SPaul B Schroeder mos7840_control_callback, mcs); 5253f542974SPaul B Schroeder mcs->control_urb->transfer_buffer_length = 2; 5263f542974SPaul B Schroeder ret = usb_submit_urb(mcs->control_urb, GFP_ATOMIC); 5273f542974SPaul B Schroeder return ret; 5283f542974SPaul B Schroeder } 5293f542974SPaul B Schroeder 5300eafe4deSDonald static void mos7840_set_led_callback(struct urb *urb) 5310eafe4deSDonald { 5320eafe4deSDonald switch (urb->status) { 5330eafe4deSDonald case 0: 5340eafe4deSDonald /* Success */ 5350eafe4deSDonald break; 5360eafe4deSDonald case -ECONNRESET: 5370eafe4deSDonald case -ENOENT: 5380eafe4deSDonald case -ESHUTDOWN: 5390eafe4deSDonald /* This urb is terminated, clean up */ 5409c134a14SGreg Kroah-Hartman dev_dbg(&urb->dev->dev, "%s - urb shutting down with status: %d", 5419c134a14SGreg Kroah-Hartman __func__, urb->status); 5420eafe4deSDonald break; 5430eafe4deSDonald default: 5449c134a14SGreg Kroah-Hartman dev_dbg(&urb->dev->dev, "%s - nonzero urb status received: %d", 5459c134a14SGreg Kroah-Hartman __func__, urb->status); 5460eafe4deSDonald } 5470eafe4deSDonald } 5480eafe4deSDonald 5490eafe4deSDonald static void mos7840_set_led_async(struct moschip_port *mcs, __u16 wval, 5500eafe4deSDonald __u16 reg) 5510eafe4deSDonald { 5520eafe4deSDonald struct usb_device *dev = mcs->port->serial->dev; 5530eafe4deSDonald struct usb_ctrlrequest *dr = mcs->dr; 5540eafe4deSDonald 5550eafe4deSDonald dr->bRequestType = MCS_WR_RTYPE; 5560eafe4deSDonald dr->bRequest = MCS_WRREQ; 5570eafe4deSDonald dr->wValue = cpu_to_le16(wval); 5580eafe4deSDonald dr->wIndex = cpu_to_le16(reg); 5590eafe4deSDonald dr->wLength = cpu_to_le16(0); 5600eafe4deSDonald 5610eafe4deSDonald usb_fill_control_urb(mcs->control_urb, dev, usb_sndctrlpipe(dev, 0), 5620eafe4deSDonald (unsigned char *)dr, NULL, 0, mos7840_set_led_callback, NULL); 5630eafe4deSDonald 5640eafe4deSDonald usb_submit_urb(mcs->control_urb, GFP_ATOMIC); 5650eafe4deSDonald } 5660eafe4deSDonald 5670eafe4deSDonald static void mos7840_set_led_sync(struct usb_serial_port *port, __u16 reg, 5680eafe4deSDonald __u16 val) 5690eafe4deSDonald { 5700eafe4deSDonald struct usb_device *dev = port->serial->dev; 5710eafe4deSDonald 5720eafe4deSDonald usb_control_msg(dev, usb_sndctrlpipe(dev, 0), MCS_WRREQ, MCS_WR_RTYPE, 5730eafe4deSDonald val, reg, NULL, 0, MOS_WDR_TIMEOUT); 5740eafe4deSDonald } 5750eafe4deSDonald 5760eafe4deSDonald static void mos7840_led_off(unsigned long arg) 5770eafe4deSDonald { 5780eafe4deSDonald struct moschip_port *mcs = (struct moschip_port *) arg; 5790eafe4deSDonald 5800eafe4deSDonald /* Turn off LED */ 5810eafe4deSDonald mos7840_set_led_async(mcs, 0x0300, MODEM_CONTROL_REGISTER); 5820eafe4deSDonald mod_timer(&mcs->led_timer2, 5830eafe4deSDonald jiffies + msecs_to_jiffies(LED_OFF_MS)); 5840eafe4deSDonald } 5850eafe4deSDonald 5860eafe4deSDonald static void mos7840_led_flag_off(unsigned long arg) 5870eafe4deSDonald { 5880eafe4deSDonald struct moschip_port *mcs = (struct moschip_port *) arg; 5890eafe4deSDonald 5900eafe4deSDonald mcs->led_flag = false; 5910eafe4deSDonald } 5920eafe4deSDonald 5933f542974SPaul B Schroeder /***************************************************************************** 5943f542974SPaul B Schroeder * mos7840_interrupt_callback 5953f542974SPaul B Schroeder * this is the callback function for when we have received data on the 5963f542974SPaul B Schroeder * interrupt endpoint. 5973f542974SPaul B Schroeder *****************************************************************************/ 5983f542974SPaul B Schroeder 5997d12e780SDavid Howells static void mos7840_interrupt_callback(struct urb *urb) 6003f542974SPaul B Schroeder { 6013f542974SPaul B Schroeder int result; 6023f542974SPaul B Schroeder int length; 6033f542974SPaul B Schroeder struct moschip_port *mos7840_port; 6043f542974SPaul B Schroeder struct usb_serial *serial; 6053f542974SPaul B Schroeder __u16 Data; 6063f542974SPaul B Schroeder unsigned char *data; 6073f542974SPaul B Schroeder __u8 sp[5], st; 6080de9a702SOliver Neukum int i, rv = 0; 6090de9a702SOliver Neukum __u16 wval, wreg = 0; 6100643c724SGreg Kroah-Hartman int status = urb->status; 6113f542974SPaul B Schroeder 6120643c724SGreg Kroah-Hartman switch (status) { 6133f542974SPaul B Schroeder case 0: 6143f542974SPaul B Schroeder /* success */ 6153f542974SPaul B Schroeder break; 6163f542974SPaul B Schroeder case -ECONNRESET: 6173f542974SPaul B Schroeder case -ENOENT: 6183f542974SPaul B Schroeder case -ESHUTDOWN: 6193f542974SPaul B Schroeder /* this urb is terminated, clean up */ 6209c134a14SGreg Kroah-Hartman dev_dbg(&urb->dev->dev, "%s - urb shutting down with status: %d\n", 6219c134a14SGreg Kroah-Hartman __func__, status); 6223f542974SPaul B Schroeder return; 6233f542974SPaul B Schroeder default: 6249c134a14SGreg Kroah-Hartman dev_dbg(&urb->dev->dev, "%s - nonzero urb status received: %d\n", 6259c134a14SGreg Kroah-Hartman __func__, status); 6263f542974SPaul B Schroeder goto exit; 6273f542974SPaul B Schroeder } 6283f542974SPaul B Schroeder 6293f542974SPaul B Schroeder length = urb->actual_length; 6303f542974SPaul B Schroeder data = urb->transfer_buffer; 6313f542974SPaul B Schroeder 632cdc97792SMing Lei serial = urb->context; 6333f542974SPaul B Schroeder 6343f542974SPaul B Schroeder /* Moschip get 5 bytes 6353f542974SPaul B Schroeder * Byte 1 IIR Port 1 (port.number is 0) 6363f542974SPaul B Schroeder * Byte 2 IIR Port 2 (port.number is 1) 6373f542974SPaul B Schroeder * Byte 3 IIR Port 3 (port.number is 2) 6383f542974SPaul B Schroeder * Byte 4 IIR Port 4 (port.number is 3) 6393f542974SPaul B Schroeder * Byte 5 FIFO status for both */ 6403f542974SPaul B Schroeder 6413f542974SPaul B Schroeder if (length && length > 5) { 6429c134a14SGreg Kroah-Hartman dev_dbg(&urb->dev->dev, "%s", "Wrong data !!!\n"); 6433f542974SPaul B Schroeder return; 6443f542974SPaul B Schroeder } 6453f542974SPaul B Schroeder 6463f542974SPaul B Schroeder sp[0] = (__u8) data[0]; 6473f542974SPaul B Schroeder sp[1] = (__u8) data[1]; 6483f542974SPaul B Schroeder sp[2] = (__u8) data[2]; 6493f542974SPaul B Schroeder sp[3] = (__u8) data[3]; 6503f542974SPaul B Schroeder st = (__u8) data[4]; 6513f542974SPaul B Schroeder 6523f542974SPaul B Schroeder for (i = 0; i < serial->num_ports; i++) { 6533f542974SPaul B Schroeder mos7840_port = mos7840_get_port_private(serial->port[i]); 6543f542974SPaul B Schroeder wval = 6553f542974SPaul B Schroeder (((__u16) serial->port[i]->number - 6563f542974SPaul B Schroeder (__u16) (serial->minor)) + 1) << 8; 6573f542974SPaul B Schroeder if (mos7840_port->open) { 6583f542974SPaul B Schroeder if (sp[i] & 0x01) { 6599c134a14SGreg Kroah-Hartman dev_dbg(&urb->dev->dev, "SP%d No Interrupt !!!\n", i); 6603f542974SPaul B Schroeder } else { 6613f542974SPaul B Schroeder switch (sp[i] & 0x0f) { 6623f542974SPaul B Schroeder case SERIAL_IIR_RLS: 6639c134a14SGreg Kroah-Hartman dev_dbg(&urb->dev->dev, "Serial Port %d: Receiver status error or \n", i); 6649c134a14SGreg Kroah-Hartman dev_dbg(&urb->dev->dev, "address bit detected in 9-bit mode\n"); 6653f542974SPaul B Schroeder mos7840_port->MsrLsr = 1; 6660de9a702SOliver Neukum wreg = LINE_STATUS_REGISTER; 6673f542974SPaul B Schroeder break; 6683f542974SPaul B Schroeder case SERIAL_IIR_MS: 6699c134a14SGreg Kroah-Hartman dev_dbg(&urb->dev->dev, "Serial Port %d: Modem status change\n", i); 6703f542974SPaul B Schroeder mos7840_port->MsrLsr = 0; 6710de9a702SOliver Neukum wreg = MODEM_STATUS_REGISTER; 6723f542974SPaul B Schroeder break; 6733f542974SPaul B Schroeder } 6740de9a702SOliver Neukum rv = mos7840_get_reg(mos7840_port, wval, wreg, &Data); 6753f542974SPaul B Schroeder } 6763f542974SPaul B Schroeder } 6773f542974SPaul B Schroeder } 678880af9dbSAlan Cox if (!(rv < 0)) 679880af9dbSAlan Cox /* the completion handler for the control urb will resubmit */ 6800de9a702SOliver Neukum return; 6813f542974SPaul B Schroeder exit: 6823f542974SPaul B Schroeder result = usb_submit_urb(urb, GFP_ATOMIC); 6833f542974SPaul B Schroeder if (result) { 6843f542974SPaul B Schroeder dev_err(&urb->dev->dev, 6853f542974SPaul B Schroeder "%s - Error %d submitting interrupt urb\n", 686441b62c1SHarvey Harrison __func__, result); 6873f542974SPaul B Schroeder } 6883f542974SPaul B Schroeder } 6893f542974SPaul B Schroeder 6903f542974SPaul B Schroeder static int mos7840_port_paranoia_check(struct usb_serial_port *port, 6913f542974SPaul B Schroeder const char *function) 6923f542974SPaul B Schroeder { 6933f542974SPaul B Schroeder if (!port) { 6949c134a14SGreg Kroah-Hartman pr_debug("%s - port == NULL\n", function); 6953f542974SPaul B Schroeder return -1; 6963f542974SPaul B Schroeder } 6973f542974SPaul B Schroeder if (!port->serial) { 6989c134a14SGreg Kroah-Hartman pr_debug("%s - port->serial == NULL\n", function); 6993f542974SPaul B Schroeder return -1; 7003f542974SPaul B Schroeder } 7013f542974SPaul B Schroeder 7023f542974SPaul B Schroeder return 0; 7033f542974SPaul B Schroeder } 7043f542974SPaul B Schroeder 7053f542974SPaul B Schroeder /* Inline functions to check the sanity of a pointer that is passed to us */ 7063f542974SPaul B Schroeder static int mos7840_serial_paranoia_check(struct usb_serial *serial, 7073f542974SPaul B Schroeder const char *function) 7083f542974SPaul B Schroeder { 7093f542974SPaul B Schroeder if (!serial) { 7109c134a14SGreg Kroah-Hartman pr_debug("%s - serial == NULL\n", function); 7113f542974SPaul B Schroeder return -1; 7123f542974SPaul B Schroeder } 7133f542974SPaul B Schroeder if (!serial->type) { 7149c134a14SGreg Kroah-Hartman pr_debug("%s - serial->type == NULL!\n", function); 7153f542974SPaul B Schroeder return -1; 7163f542974SPaul B Schroeder } 7173f542974SPaul B Schroeder 7183f542974SPaul B Schroeder return 0; 7193f542974SPaul B Schroeder } 7203f542974SPaul B Schroeder 7213f542974SPaul B Schroeder static struct usb_serial *mos7840_get_usb_serial(struct usb_serial_port *port, 7223f542974SPaul B Schroeder const char *function) 7233f542974SPaul B Schroeder { 7243f542974SPaul B Schroeder /* if no port was specified, or it fails a paranoia check */ 7253f542974SPaul B Schroeder if (!port || 7263f542974SPaul B Schroeder mos7840_port_paranoia_check(port, function) || 7273f542974SPaul B Schroeder mos7840_serial_paranoia_check(port->serial, function)) { 728880af9dbSAlan Cox /* then say that we don't have a valid usb_serial thing, 729880af9dbSAlan Cox * which will end up genrating -ENODEV return values */ 7303f542974SPaul B Schroeder return NULL; 7313f542974SPaul B Schroeder } 7323f542974SPaul B Schroeder 7333f542974SPaul B Schroeder return port->serial; 7343f542974SPaul B Schroeder } 7353f542974SPaul B Schroeder 7363f542974SPaul B Schroeder /***************************************************************************** 7373f542974SPaul B Schroeder * mos7840_bulk_in_callback 7383f542974SPaul B Schroeder * this is the callback function for when we have received data on the 7393f542974SPaul B Schroeder * bulk in endpoint. 7403f542974SPaul B Schroeder *****************************************************************************/ 7413f542974SPaul B Schroeder 7427d12e780SDavid Howells static void mos7840_bulk_in_callback(struct urb *urb) 7433f542974SPaul B Schroeder { 7440643c724SGreg Kroah-Hartman int retval; 7453f542974SPaul B Schroeder unsigned char *data; 7463f542974SPaul B Schroeder struct usb_serial *serial; 7473f542974SPaul B Schroeder struct usb_serial_port *port; 7483f542974SPaul B Schroeder struct moschip_port *mos7840_port; 7490643c724SGreg Kroah-Hartman int status = urb->status; 7503f542974SPaul B Schroeder 751cdc97792SMing Lei mos7840_port = urb->context; 7529c134a14SGreg Kroah-Hartman if (!mos7840_port) 75350de36f7SGreg Kroah-Hartman return; 75450de36f7SGreg Kroah-Hartman 75550de36f7SGreg Kroah-Hartman if (status) { 7569c134a14SGreg Kroah-Hartman dev_dbg(&urb->dev->dev, "nonzero read bulk status received: %d\n", status); 75750de36f7SGreg Kroah-Hartman mos7840_port->read_urb_busy = false; 7583f542974SPaul B Schroeder return; 7593f542974SPaul B Schroeder } 7603f542974SPaul B Schroeder 7619c134a14SGreg Kroah-Hartman port = mos7840_port->port; 762441b62c1SHarvey Harrison if (mos7840_port_paranoia_check(port, __func__)) { 76350de36f7SGreg Kroah-Hartman mos7840_port->read_urb_busy = false; 7643f542974SPaul B Schroeder return; 7653f542974SPaul B Schroeder } 7663f542974SPaul B Schroeder 767441b62c1SHarvey Harrison serial = mos7840_get_usb_serial(port, __func__); 7683f542974SPaul B Schroeder if (!serial) { 76950de36f7SGreg Kroah-Hartman mos7840_port->read_urb_busy = false; 7703f542974SPaul B Schroeder return; 7713f542974SPaul B Schroeder } 7723f542974SPaul B Schroeder 7733f542974SPaul B Schroeder data = urb->transfer_buffer; 77459d33f2fSGreg Kroah-Hartman usb_serial_debug_data(&port->dev, __func__, urb->actual_length, data); 7753f542974SPaul B Schroeder 7763f542974SPaul B Schroeder if (urb->actual_length) { 77705c7cd39SJiri Slaby struct tty_port *tport = &mos7840_port->port->port; 77805c7cd39SJiri Slaby tty_insert_flip_string(tport, data, urb->actual_length); 7792e124b4aSJiri Slaby tty_flip_buffer_push(tport); 7803f542974SPaul B Schroeder mos7840_port->icount.rx += urb->actual_length; 7810de9a702SOliver Neukum smp_wmb(); 7829c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "mos7840_port->icount.rx is %d:\n", mos7840_port->icount.rx); 7833f542974SPaul B Schroeder } 7843f542974SPaul B Schroeder 7853f542974SPaul B Schroeder if (!mos7840_port->read_urb) { 7869c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s", "URB KILLED !!!\n"); 78750de36f7SGreg Kroah-Hartman mos7840_port->read_urb_busy = false; 7883f542974SPaul B Schroeder return; 7893f542974SPaul B Schroeder } 7903f542974SPaul B Schroeder 7910eafe4deSDonald /* Turn on LED */ 7920eafe4deSDonald if (mos7840_port->has_led && !mos7840_port->led_flag) { 7930eafe4deSDonald mos7840_port->led_flag = true; 7940eafe4deSDonald mos7840_set_led_async(mos7840_port, 0x0301, 7950eafe4deSDonald MODEM_CONTROL_REGISTER); 7960eafe4deSDonald mod_timer(&mos7840_port->led_timer1, 7970eafe4deSDonald jiffies + msecs_to_jiffies(LED_ON_MS)); 7980eafe4deSDonald } 7990de9a702SOliver Neukum 80050de36f7SGreg Kroah-Hartman mos7840_port->read_urb_busy = true; 8010643c724SGreg Kroah-Hartman retval = usb_submit_urb(mos7840_port->read_urb, GFP_ATOMIC); 8023f542974SPaul B Schroeder 8030643c724SGreg Kroah-Hartman if (retval) { 8049c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "usb_submit_urb(read bulk) failed, retval = %d\n", retval); 80550de36f7SGreg Kroah-Hartman mos7840_port->read_urb_busy = false; 8063f542974SPaul B Schroeder } 8073f542974SPaul B Schroeder } 8083f542974SPaul B Schroeder 8093f542974SPaul B Schroeder /***************************************************************************** 8103f542974SPaul B Schroeder * mos7840_bulk_out_data_callback 811880af9dbSAlan Cox * this is the callback function for when we have finished sending 812880af9dbSAlan Cox * serial data on the bulk out endpoint. 8133f542974SPaul B Schroeder *****************************************************************************/ 8143f542974SPaul B Schroeder 8157d12e780SDavid Howells static void mos7840_bulk_out_data_callback(struct urb *urb) 8163f542974SPaul B Schroeder { 8173f542974SPaul B Schroeder struct moschip_port *mos7840_port; 8189c134a14SGreg Kroah-Hartman struct usb_serial_port *port; 8193f542974SPaul B Schroeder struct tty_struct *tty; 8200643c724SGreg Kroah-Hartman int status = urb->status; 8210de9a702SOliver Neukum int i; 8220de9a702SOliver Neukum 823cdc97792SMing Lei mos7840_port = urb->context; 8249c134a14SGreg Kroah-Hartman port = mos7840_port->port; 8250de9a702SOliver Neukum spin_lock(&mos7840_port->pool_lock); 8260de9a702SOliver Neukum for (i = 0; i < NUM_URBS; i++) { 8270de9a702SOliver Neukum if (urb == mos7840_port->write_urb_pool[i]) { 8280de9a702SOliver Neukum mos7840_port->busy[i] = 0; 8290de9a702SOliver Neukum break; 8300de9a702SOliver Neukum } 8310de9a702SOliver Neukum } 8320de9a702SOliver Neukum spin_unlock(&mos7840_port->pool_lock); 8330de9a702SOliver Neukum 8340643c724SGreg Kroah-Hartman if (status) { 8359c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "nonzero write bulk status received:%d\n", status); 8363f542974SPaul B Schroeder return; 8373f542974SPaul B Schroeder } 8383f542974SPaul B Schroeder 8399c134a14SGreg Kroah-Hartman if (mos7840_port_paranoia_check(port, __func__)) 8403f542974SPaul B Schroeder return; 8413f542974SPaul B Schroeder 8429c134a14SGreg Kroah-Hartman tty = tty_port_tty_get(&port->port); 843b963a844SJiri Slaby if (tty && mos7840_port->open) 844b963a844SJiri Slaby tty_wakeup(tty); 8454a90f09bSAlan Cox tty_kref_put(tty); 8463f542974SPaul B Schroeder 8473f542974SPaul B Schroeder } 8483f542974SPaul B Schroeder 8493f542974SPaul B Schroeder /************************************************************************/ 8503f542974SPaul B Schroeder /* D R I V E R T T Y I N T E R F A C E F U N C T I O N S */ 8513f542974SPaul B Schroeder /************************************************************************/ 8523f542974SPaul B Schroeder #ifdef MCSSerialProbe 8533f542974SPaul B Schroeder static int mos7840_serial_probe(struct usb_serial *serial, 8543f542974SPaul B Schroeder const struct usb_device_id *id) 8553f542974SPaul B Schroeder { 8563f542974SPaul B Schroeder 8573f542974SPaul B Schroeder /*need to implement the mode_reg reading and updating\ 8583f542974SPaul B Schroeder structures usb_serial_ device_type\ 8593f542974SPaul B Schroeder (i.e num_ports, num_bulkin,bulkout etc) */ 8603f542974SPaul B Schroeder /* Also we can update the changes attach */ 8613f542974SPaul B Schroeder return 1; 8623f542974SPaul B Schroeder } 8633f542974SPaul B Schroeder #endif 8643f542974SPaul B Schroeder 8653f542974SPaul B Schroeder /***************************************************************************** 8663f542974SPaul B Schroeder * mos7840_open 8673f542974SPaul B Schroeder * this function is called by the tty driver when a port is opened 8683f542974SPaul B Schroeder * If successful, we return 0 8693f542974SPaul B Schroeder * Otherwise we return a negative error number. 8703f542974SPaul B Schroeder *****************************************************************************/ 8713f542974SPaul B Schroeder 872a509a7e4SAlan Cox static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port) 8733f542974SPaul B Schroeder { 8743f542974SPaul B Schroeder int response; 8753f542974SPaul B Schroeder int j; 8763f542974SPaul B Schroeder struct usb_serial *serial; 8773f542974SPaul B Schroeder struct urb *urb; 8783f542974SPaul B Schroeder __u16 Data; 8793f542974SPaul B Schroeder int status; 8803f542974SPaul B Schroeder struct moschip_port *mos7840_port; 8810de9a702SOliver Neukum struct moschip_port *port0; 8823f542974SPaul B Schroeder 8839c134a14SGreg Kroah-Hartman if (mos7840_port_paranoia_check(port, __func__)) 8843f542974SPaul B Schroeder return -ENODEV; 8853f542974SPaul B Schroeder 8863f542974SPaul B Schroeder serial = port->serial; 8873f542974SPaul B Schroeder 8889c134a14SGreg Kroah-Hartman if (mos7840_serial_paranoia_check(serial, __func__)) 8893f542974SPaul B Schroeder return -ENODEV; 8903f542974SPaul B Schroeder 8913f542974SPaul B Schroeder mos7840_port = mos7840_get_port_private(port); 8920de9a702SOliver Neukum port0 = mos7840_get_port_private(serial->port[0]); 8933f542974SPaul B Schroeder 8940de9a702SOliver Neukum if (mos7840_port == NULL || port0 == NULL) 8953f542974SPaul B Schroeder return -ENODEV; 8963f542974SPaul B Schroeder 8973f542974SPaul B Schroeder usb_clear_halt(serial->dev, port->write_urb->pipe); 8983f542974SPaul B Schroeder usb_clear_halt(serial->dev, port->read_urb->pipe); 8990de9a702SOliver Neukum port0->open_ports++; 9003f542974SPaul B Schroeder 9013f542974SPaul B Schroeder /* Initialising the write urb pool */ 9023f542974SPaul B Schroeder for (j = 0; j < NUM_URBS; ++j) { 9030de9a702SOliver Neukum urb = usb_alloc_urb(0, GFP_KERNEL); 9043f542974SPaul B Schroeder mos7840_port->write_urb_pool[j] = urb; 9053f542974SPaul B Schroeder 9063f542974SPaul B Schroeder if (urb == NULL) { 907194343d9SGreg Kroah-Hartman dev_err(&port->dev, "No more urbs???\n"); 9083f542974SPaul B Schroeder continue; 9093f542974SPaul B Schroeder } 9103f542974SPaul B Schroeder 911880af9dbSAlan Cox urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE, 912880af9dbSAlan Cox GFP_KERNEL); 9133f542974SPaul B Schroeder if (!urb->transfer_buffer) { 9140de9a702SOliver Neukum usb_free_urb(urb); 9150de9a702SOliver Neukum mos7840_port->write_urb_pool[j] = NULL; 916194343d9SGreg Kroah-Hartman dev_err(&port->dev, 917194343d9SGreg Kroah-Hartman "%s-out of memory for urb buffers.\n", 918194343d9SGreg Kroah-Hartman __func__); 9193f542974SPaul B Schroeder continue; 9203f542974SPaul B Schroeder } 9213f542974SPaul B Schroeder } 9223f542974SPaul B Schroeder 9233f542974SPaul B Schroeder /***************************************************************************** 9243f542974SPaul B Schroeder * Initialize MCS7840 -- Write Init values to corresponding Registers 9253f542974SPaul B Schroeder * 9263f542974SPaul B Schroeder * Register Index 9273f542974SPaul B Schroeder * 1 : IER 9283f542974SPaul B Schroeder * 2 : FCR 9293f542974SPaul B Schroeder * 3 : LCR 9303f542974SPaul B Schroeder * 4 : MCR 9313f542974SPaul B Schroeder * 9323f542974SPaul B Schroeder * 0x08 : SP1/2 Control Reg 9333f542974SPaul B Schroeder *****************************************************************************/ 9343f542974SPaul B Schroeder 935880af9dbSAlan Cox /* NEED to check the following Block */ 9363f542974SPaul B Schroeder 9373f542974SPaul B Schroeder Data = 0x0; 9383f542974SPaul B Schroeder status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, &Data); 9393f542974SPaul B Schroeder if (status < 0) { 9409c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "Reading Spreg failed\n"); 9413f542974SPaul B Schroeder return -1; 9423f542974SPaul B Schroeder } 9433f542974SPaul B Schroeder Data |= 0x80; 9443f542974SPaul B Schroeder status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data); 9453f542974SPaul B Schroeder if (status < 0) { 9469c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "writing Spreg failed\n"); 9473f542974SPaul B Schroeder return -1; 9483f542974SPaul B Schroeder } 9493f542974SPaul B Schroeder 9503f542974SPaul B Schroeder Data &= ~0x80; 9513f542974SPaul B Schroeder status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data); 9523f542974SPaul B Schroeder if (status < 0) { 9539c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "writing Spreg failed\n"); 9543f542974SPaul B Schroeder return -1; 9553f542974SPaul B Schroeder } 956880af9dbSAlan Cox /* End of block to be checked */ 9573f542974SPaul B Schroeder 9583f542974SPaul B Schroeder Data = 0x0; 959880af9dbSAlan Cox status = mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset, 960880af9dbSAlan Cox &Data); 9613f542974SPaul B Schroeder if (status < 0) { 9629c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "Reading Controlreg failed\n"); 9633f542974SPaul B Schroeder return -1; 9643f542974SPaul B Schroeder } 965880af9dbSAlan Cox Data |= 0x08; /* Driver done bit */ 966880af9dbSAlan Cox Data |= 0x20; /* rx_disable */ 967880af9dbSAlan Cox status = mos7840_set_reg_sync(port, 968880af9dbSAlan Cox mos7840_port->ControlRegOffset, Data); 9693f542974SPaul B Schroeder if (status < 0) { 9709c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "writing Controlreg failed\n"); 9713f542974SPaul B Schroeder return -1; 9723f542974SPaul B Schroeder } 973880af9dbSAlan Cox /* do register settings here */ 974880af9dbSAlan Cox /* Set all regs to the device default values. */ 975880af9dbSAlan Cox /*********************************** 976880af9dbSAlan Cox * First Disable all interrupts. 977880af9dbSAlan Cox ***********************************/ 9783f542974SPaul B Schroeder Data = 0x00; 9793f542974SPaul B Schroeder status = mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data); 9803f542974SPaul B Schroeder if (status < 0) { 9819c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "disabling interrupts failed\n"); 9823f542974SPaul B Schroeder return -1; 9833f542974SPaul B Schroeder } 984880af9dbSAlan Cox /* Set FIFO_CONTROL_REGISTER to the default value */ 9853f542974SPaul B Schroeder Data = 0x00; 9863f542974SPaul B Schroeder status = mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data); 9873f542974SPaul B Schroeder if (status < 0) { 9889c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "Writing FIFO_CONTROL_REGISTER failed\n"); 9893f542974SPaul B Schroeder return -1; 9903f542974SPaul B Schroeder } 9913f542974SPaul B Schroeder 9923f542974SPaul B Schroeder Data = 0xcf; 9933f542974SPaul B Schroeder status = mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data); 9943f542974SPaul B Schroeder if (status < 0) { 9959c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "Writing FIFO_CONTROL_REGISTER failed\n"); 9963f542974SPaul B Schroeder return -1; 9973f542974SPaul B Schroeder } 9983f542974SPaul B Schroeder 9993f542974SPaul B Schroeder Data = 0x03; 10003f542974SPaul B Schroeder status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); 10013f542974SPaul B Schroeder mos7840_port->shadowLCR = Data; 10023f542974SPaul B Schroeder 10033f542974SPaul B Schroeder Data = 0x0b; 10043f542974SPaul B Schroeder status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); 10053f542974SPaul B Schroeder mos7840_port->shadowMCR = Data; 10063f542974SPaul B Schroeder 10073f542974SPaul B Schroeder Data = 0x00; 10083f542974SPaul B Schroeder status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data); 10093f542974SPaul B Schroeder mos7840_port->shadowLCR = Data; 10103f542974SPaul B Schroeder 1011880af9dbSAlan Cox Data |= SERIAL_LCR_DLAB; /* data latch enable in LCR 0x80 */ 10123f542974SPaul B Schroeder status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); 10133f542974SPaul B Schroeder 10143f542974SPaul B Schroeder Data = 0x0c; 10153f542974SPaul B Schroeder status = mos7840_set_uart_reg(port, DIVISOR_LATCH_LSB, Data); 10163f542974SPaul B Schroeder 10173f542974SPaul B Schroeder Data = 0x0; 10183f542974SPaul B Schroeder status = mos7840_set_uart_reg(port, DIVISOR_LATCH_MSB, Data); 10193f542974SPaul B Schroeder 10203f542974SPaul B Schroeder Data = 0x00; 10213f542974SPaul B Schroeder status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data); 10223f542974SPaul B Schroeder 10233f542974SPaul B Schroeder Data = Data & ~SERIAL_LCR_DLAB; 10243f542974SPaul B Schroeder status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); 10253f542974SPaul B Schroeder mos7840_port->shadowLCR = Data; 10263f542974SPaul B Schroeder 1027880af9dbSAlan Cox /* clearing Bulkin and Bulkout Fifo */ 10283f542974SPaul B Schroeder Data = 0x0; 10293f542974SPaul B Schroeder status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, &Data); 10303f542974SPaul B Schroeder 10313f542974SPaul B Schroeder Data = Data | 0x0c; 10323f542974SPaul B Schroeder status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data); 10333f542974SPaul B Schroeder 10343f542974SPaul B Schroeder Data = Data & ~0x0c; 10353f542974SPaul B Schroeder status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data); 1036880af9dbSAlan Cox /* Finally enable all interrupts */ 10373f542974SPaul B Schroeder Data = 0x0c; 10383f542974SPaul B Schroeder status = mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data); 10393f542974SPaul B Schroeder 1040880af9dbSAlan Cox /* clearing rx_disable */ 10413f542974SPaul B Schroeder Data = 0x0; 1042880af9dbSAlan Cox status = mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset, 1043880af9dbSAlan Cox &Data); 10443f542974SPaul B Schroeder Data = Data & ~0x20; 1045880af9dbSAlan Cox status = mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset, 1046880af9dbSAlan Cox Data); 10473f542974SPaul B Schroeder 1048880af9dbSAlan Cox /* rx_negate */ 10493f542974SPaul B Schroeder Data = 0x0; 1050880af9dbSAlan Cox status = mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset, 1051880af9dbSAlan Cox &Data); 10523f542974SPaul B Schroeder Data = Data | 0x10; 1053880af9dbSAlan Cox status = mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset, 1054880af9dbSAlan Cox Data); 10553f542974SPaul B Schroeder 10563f542974SPaul B Schroeder /* Check to see if we've set up our endpoint info yet * 10573f542974SPaul B Schroeder * (can't set it up in mos7840_startup as the structures * 10583f542974SPaul B Schroeder * were not set up at that time.) */ 10590de9a702SOliver Neukum if (port0->open_ports == 1) { 10603f542974SPaul B Schroeder if (serial->port[0]->interrupt_in_buffer == NULL) { 10613f542974SPaul B Schroeder /* set up interrupt urb */ 10623f542974SPaul B Schroeder usb_fill_int_urb(serial->port[0]->interrupt_in_urb, 10633f542974SPaul B Schroeder serial->dev, 10643f542974SPaul B Schroeder usb_rcvintpipe(serial->dev, 1065880af9dbSAlan Cox serial->port[0]->interrupt_in_endpointAddress), 10663f542974SPaul B Schroeder serial->port[0]->interrupt_in_buffer, 10673f542974SPaul B Schroeder serial->port[0]->interrupt_in_urb-> 10683f542974SPaul B Schroeder transfer_buffer_length, 10693f542974SPaul B Schroeder mos7840_interrupt_callback, 10703f542974SPaul B Schroeder serial, 1071880af9dbSAlan Cox serial->port[0]->interrupt_in_urb->interval); 10723f542974SPaul B Schroeder 10733f542974SPaul B Schroeder /* start interrupt read for mos7840 * 10743f542974SPaul B Schroeder * will continue as long as mos7840 is connected */ 10753f542974SPaul B Schroeder 10763f542974SPaul B Schroeder response = 10773f542974SPaul B Schroeder usb_submit_urb(serial->port[0]->interrupt_in_urb, 10783f542974SPaul B Schroeder GFP_KERNEL); 10793f542974SPaul B Schroeder if (response) { 1080194343d9SGreg Kroah-Hartman dev_err(&port->dev, "%s - Error %d submitting " 1081194343d9SGreg Kroah-Hartman "interrupt urb\n", __func__, response); 10823f542974SPaul B Schroeder } 10833f542974SPaul B Schroeder 10843f542974SPaul B Schroeder } 10853f542974SPaul B Schroeder 10863f542974SPaul B Schroeder } 10873f542974SPaul B Schroeder 10883f542974SPaul B Schroeder /* see if we've set up our endpoint info yet * 10893f542974SPaul B Schroeder * (can't set it up in mos7840_startup as the * 10903f542974SPaul B Schroeder * structures were not set up at that time.) */ 10913f542974SPaul B Schroeder 10929c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "port number is %d\n", port->number); 10939c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "serial number is %d\n", port->serial->minor); 10949c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "Bulkin endpoint is %d\n", port->bulk_in_endpointAddress); 10959c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "BulkOut endpoint is %d\n", port->bulk_out_endpointAddress); 10969c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "Interrupt endpoint is %d\n", port->interrupt_in_endpointAddress); 10979c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "port's number in the device is %d\n", mos7840_port->port_num); 10983f542974SPaul B Schroeder mos7840_port->read_urb = port->read_urb; 10993f542974SPaul B Schroeder 11003f542974SPaul B Schroeder /* set up our bulk in urb */ 1101093ea2d3SDonald Lee if ((serial->num_ports == 2) 1102093ea2d3SDonald Lee && ((((__u16)port->number - 1103093ea2d3SDonald Lee (__u16)(port->serial->minor)) % 2) != 0)) { 1104093ea2d3SDonald Lee usb_fill_bulk_urb(mos7840_port->read_urb, 1105093ea2d3SDonald Lee serial->dev, 1106093ea2d3SDonald Lee usb_rcvbulkpipe(serial->dev, 1107093ea2d3SDonald Lee (port->bulk_in_endpointAddress) + 2), 1108093ea2d3SDonald Lee port->bulk_in_buffer, 1109093ea2d3SDonald Lee mos7840_port->read_urb->transfer_buffer_length, 1110093ea2d3SDonald Lee mos7840_bulk_in_callback, mos7840_port); 1111093ea2d3SDonald Lee } else { 11123f542974SPaul B Schroeder usb_fill_bulk_urb(mos7840_port->read_urb, 11133f542974SPaul B Schroeder serial->dev, 11143f542974SPaul B Schroeder usb_rcvbulkpipe(serial->dev, 11153f542974SPaul B Schroeder port->bulk_in_endpointAddress), 11163f542974SPaul B Schroeder port->bulk_in_buffer, 11173f542974SPaul B Schroeder mos7840_port->read_urb->transfer_buffer_length, 11183f542974SPaul B Schroeder mos7840_bulk_in_callback, mos7840_port); 1119093ea2d3SDonald Lee } 11203f542974SPaul B Schroeder 11219c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s: bulkin endpoint is %d\n", __func__, port->bulk_in_endpointAddress); 112250de36f7SGreg Kroah-Hartman mos7840_port->read_urb_busy = true; 11233f542974SPaul B Schroeder response = usb_submit_urb(mos7840_port->read_urb, GFP_KERNEL); 11243f542974SPaul B Schroeder if (response) { 1125194343d9SGreg Kroah-Hartman dev_err(&port->dev, "%s - Error %d submitting control urb\n", 1126194343d9SGreg Kroah-Hartman __func__, response); 112750de36f7SGreg Kroah-Hartman mos7840_port->read_urb_busy = false; 11283f542974SPaul B Schroeder } 11293f542974SPaul B Schroeder 11303f542974SPaul B Schroeder /* initialize our wait queues */ 11313f542974SPaul B Schroeder init_waitqueue_head(&mos7840_port->wait_chase); 11323f542974SPaul B Schroeder 11333f542974SPaul B Schroeder /* initialize our icount structure */ 11343f542974SPaul B Schroeder memset(&(mos7840_port->icount), 0x00, sizeof(mos7840_port->icount)); 11353f542974SPaul B Schroeder 11363f542974SPaul B Schroeder /* initialize our port settings */ 1137880af9dbSAlan Cox /* Must set to enable ints! */ 1138880af9dbSAlan Cox mos7840_port->shadowMCR = MCR_MASTER_IE; 11393f542974SPaul B Schroeder /* send a open port command */ 11403f542974SPaul B Schroeder mos7840_port->open = 1; 1141880af9dbSAlan Cox /* mos7840_change_port_settings(mos7840_port,old_termios); */ 11423f542974SPaul B Schroeder mos7840_port->icount.tx = 0; 11433f542974SPaul B Schroeder mos7840_port->icount.rx = 0; 11443f542974SPaul B Schroeder 11453f542974SPaul B Schroeder return 0; 11463f542974SPaul B Schroeder } 11473f542974SPaul B Schroeder 11483f542974SPaul B Schroeder /***************************************************************************** 11493f542974SPaul B Schroeder * mos7840_chars_in_buffer 11503f542974SPaul B Schroeder * this function is called by the tty driver when it wants to know how many 11513f542974SPaul B Schroeder * bytes of data we currently have outstanding in the port (data that has 11523f542974SPaul B Schroeder * been written, but hasn't made it out the port yet) 11533f542974SPaul B Schroeder * If successful, we return the number of bytes left to be written in the 11543f542974SPaul B Schroeder * system, 115595da310eSAlan Cox * Otherwise we return zero. 11563f542974SPaul B Schroeder *****************************************************************************/ 11573f542974SPaul B Schroeder 115895da310eSAlan Cox static int mos7840_chars_in_buffer(struct tty_struct *tty) 11593f542974SPaul B Schroeder { 116095da310eSAlan Cox struct usb_serial_port *port = tty->driver_data; 11613f542974SPaul B Schroeder int i; 11623f542974SPaul B Schroeder int chars = 0; 11630de9a702SOliver Neukum unsigned long flags; 11643f542974SPaul B Schroeder struct moschip_port *mos7840_port; 11653f542974SPaul B Schroeder 11669c134a14SGreg Kroah-Hartman if (mos7840_port_paranoia_check(port, __func__)) 116795da310eSAlan Cox return 0; 11683f542974SPaul B Schroeder 11693f542974SPaul B Schroeder mos7840_port = mos7840_get_port_private(port); 11703363155bSGreg Kroah-Hartman if (mos7840_port == NULL) 117195da310eSAlan Cox return 0; 11723f542974SPaul B Schroeder 11730de9a702SOliver Neukum spin_lock_irqsave(&mos7840_port->pool_lock, flags); 11745c263b92SMark Ferrell for (i = 0; i < NUM_URBS; ++i) { 11755c263b92SMark Ferrell if (mos7840_port->busy[i]) { 11765c263b92SMark Ferrell struct urb *urb = mos7840_port->write_urb_pool[i]; 11775c263b92SMark Ferrell chars += urb->transfer_buffer_length; 11785c263b92SMark Ferrell } 11795c263b92SMark Ferrell } 11800de9a702SOliver Neukum spin_unlock_irqrestore(&mos7840_port->pool_lock, flags); 11819c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s - returns %d\n", __func__, chars); 11820de9a702SOliver Neukum return chars; 11833f542974SPaul B Schroeder 11843f542974SPaul B Schroeder } 11853f542974SPaul B Schroeder 11863f542974SPaul B Schroeder /***************************************************************************** 11873f542974SPaul B Schroeder * mos7840_close 11883f542974SPaul B Schroeder * this function is called by the tty driver when a port is closed 11893f542974SPaul B Schroeder *****************************************************************************/ 11903f542974SPaul B Schroeder 1191335f8514SAlan Cox static void mos7840_close(struct usb_serial_port *port) 11923f542974SPaul B Schroeder { 11933f542974SPaul B Schroeder struct usb_serial *serial; 11943f542974SPaul B Schroeder struct moschip_port *mos7840_port; 11950de9a702SOliver Neukum struct moschip_port *port0; 11963f542974SPaul B Schroeder int j; 11973f542974SPaul B Schroeder __u16 Data; 11983f542974SPaul B Schroeder 11999c134a14SGreg Kroah-Hartman if (mos7840_port_paranoia_check(port, __func__)) 12003f542974SPaul B Schroeder return; 12013f542974SPaul B Schroeder 1202441b62c1SHarvey Harrison serial = mos7840_get_usb_serial(port, __func__); 12039c134a14SGreg Kroah-Hartman if (!serial) 12043f542974SPaul B Schroeder return; 12053f542974SPaul B Schroeder 12063f542974SPaul B Schroeder mos7840_port = mos7840_get_port_private(port); 12070de9a702SOliver Neukum port0 = mos7840_get_port_private(serial->port[0]); 12083f542974SPaul B Schroeder 12090de9a702SOliver Neukum if (mos7840_port == NULL || port0 == NULL) 12103f542974SPaul B Schroeder return; 12113f542974SPaul B Schroeder 12123f542974SPaul B Schroeder for (j = 0; j < NUM_URBS; ++j) 12133f542974SPaul B Schroeder usb_kill_urb(mos7840_port->write_urb_pool[j]); 12143f542974SPaul B Schroeder 12153f542974SPaul B Schroeder /* Freeing Write URBs */ 12163f542974SPaul B Schroeder for (j = 0; j < NUM_URBS; ++j) { 12173f542974SPaul B Schroeder if (mos7840_port->write_urb_pool[j]) { 12183f542974SPaul B Schroeder if (mos7840_port->write_urb_pool[j]->transfer_buffer) 12193f542974SPaul B Schroeder kfree(mos7840_port->write_urb_pool[j]-> 12203f542974SPaul B Schroeder transfer_buffer); 12213f542974SPaul B Schroeder 12223f542974SPaul B Schroeder usb_free_urb(mos7840_port->write_urb_pool[j]); 12233f542974SPaul B Schroeder } 12243f542974SPaul B Schroeder } 12253f542974SPaul B Schroeder 12263f542974SPaul B Schroeder usb_kill_urb(mos7840_port->write_urb); 12273f542974SPaul B Schroeder usb_kill_urb(mos7840_port->read_urb); 122850de36f7SGreg Kroah-Hartman mos7840_port->read_urb_busy = false; 1229*bb3529c6SJohan Hovold 12300de9a702SOliver Neukum port0->open_ports--; 12319c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s in close%d:in port%d\n", __func__, port0->open_ports, port->number); 12320de9a702SOliver Neukum if (port0->open_ports == 0) { 12333f542974SPaul B Schroeder if (serial->port[0]->interrupt_in_urb) { 12349c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "Shutdown interrupt_in_urb\n"); 12350de9a702SOliver Neukum usb_kill_urb(serial->port[0]->interrupt_in_urb); 12363f542974SPaul B Schroeder } 12373f542974SPaul B Schroeder } 12383f542974SPaul B Schroeder 12393f542974SPaul B Schroeder if (mos7840_port->write_urb) { 12403f542974SPaul B Schroeder /* if this urb had a transfer buffer already (old tx) free it */ 12413f542974SPaul B Schroeder kfree(mos7840_port->write_urb->transfer_buffer); 12423f542974SPaul B Schroeder usb_free_urb(mos7840_port->write_urb); 12433f542974SPaul B Schroeder } 12443f542974SPaul B Schroeder 12453f542974SPaul B Schroeder Data = 0x0; 12463f542974SPaul B Schroeder mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); 12473f542974SPaul B Schroeder 12483f542974SPaul B Schroeder Data = 0x00; 12493f542974SPaul B Schroeder mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data); 12503f542974SPaul B Schroeder 12513f542974SPaul B Schroeder mos7840_port->open = 0; 12523f542974SPaul B Schroeder } 12533f542974SPaul B Schroeder 12543f542974SPaul B Schroeder /************************************************************************ 12553f542974SPaul B Schroeder * 12563f542974SPaul B Schroeder * mos7840_block_until_chase_response 12573f542974SPaul B Schroeder * 12583f542974SPaul B Schroeder * This function will block the close until one of the following: 12593f542974SPaul B Schroeder * 1. Response to our Chase comes from mos7840 1260dc0d5c1eSJoe Perches * 2. A timeout of 10 seconds without activity has expired 12613f542974SPaul B Schroeder * (1K of mos7840 data @ 2400 baud ==> 4 sec to empty) 12623f542974SPaul B Schroeder * 12633f542974SPaul B Schroeder ************************************************************************/ 12643f542974SPaul B Schroeder 126595da310eSAlan Cox static void mos7840_block_until_chase_response(struct tty_struct *tty, 126695da310eSAlan Cox struct moschip_port *mos7840_port) 12673f542974SPaul B Schroeder { 12681e658489SMark Ferrell int timeout = msecs_to_jiffies(1000); 12693f542974SPaul B Schroeder int wait = 10; 12703f542974SPaul B Schroeder int count; 12713f542974SPaul B Schroeder 12723f542974SPaul B Schroeder while (1) { 127395da310eSAlan Cox count = mos7840_chars_in_buffer(tty); 12743f542974SPaul B Schroeder 12753f542974SPaul B Schroeder /* Check for Buffer status */ 1276880af9dbSAlan Cox if (count <= 0) 12773f542974SPaul B Schroeder return; 12783f542974SPaul B Schroeder 12793f542974SPaul B Schroeder /* Block the thread for a while */ 12803f542974SPaul B Schroeder interruptible_sleep_on_timeout(&mos7840_port->wait_chase, 12813f542974SPaul B Schroeder timeout); 12823f542974SPaul B Schroeder /* No activity.. count down section */ 12833f542974SPaul B Schroeder wait--; 12843f542974SPaul B Schroeder if (wait == 0) { 12859c134a14SGreg Kroah-Hartman dev_dbg(&mos7840_port->port->dev, "%s - TIMEOUT\n", __func__); 12863f542974SPaul B Schroeder return; 12873f542974SPaul B Schroeder } else { 1288dc0d5c1eSJoe Perches /* Reset timeout value back to seconds */ 12893f542974SPaul B Schroeder wait = 10; 12903f542974SPaul B Schroeder } 12913f542974SPaul B Schroeder } 12923f542974SPaul B Schroeder 12933f542974SPaul B Schroeder } 12943f542974SPaul B Schroeder 12953f542974SPaul B Schroeder /***************************************************************************** 12963f542974SPaul B Schroeder * mos7840_break 12973f542974SPaul B Schroeder * this function sends a break to the port 12983f542974SPaul B Schroeder *****************************************************************************/ 129995da310eSAlan Cox static void mos7840_break(struct tty_struct *tty, int break_state) 13003f542974SPaul B Schroeder { 130195da310eSAlan Cox struct usb_serial_port *port = tty->driver_data; 13023f542974SPaul B Schroeder unsigned char data; 13033f542974SPaul B Schroeder struct usb_serial *serial; 13043f542974SPaul B Schroeder struct moschip_port *mos7840_port; 13053f542974SPaul B Schroeder 13069c134a14SGreg Kroah-Hartman if (mos7840_port_paranoia_check(port, __func__)) 13073f542974SPaul B Schroeder return; 13083f542974SPaul B Schroeder 1309441b62c1SHarvey Harrison serial = mos7840_get_usb_serial(port, __func__); 13109c134a14SGreg Kroah-Hartman if (!serial) 13113f542974SPaul B Schroeder return; 13123f542974SPaul B Schroeder 13133f542974SPaul B Schroeder mos7840_port = mos7840_get_port_private(port); 13143f542974SPaul B Schroeder 1315880af9dbSAlan Cox if (mos7840_port == NULL) 13163f542974SPaul B Schroeder return; 13173f542974SPaul B Schroeder 13183f542974SPaul B Schroeder /* flush and block until tx is empty */ 131995da310eSAlan Cox mos7840_block_until_chase_response(tty, mos7840_port); 13203f542974SPaul B Schroeder 132195da310eSAlan Cox if (break_state == -1) 13223f542974SPaul B Schroeder data = mos7840_port->shadowLCR | LCR_SET_BREAK; 132395da310eSAlan Cox else 13243f542974SPaul B Schroeder data = mos7840_port->shadowLCR & ~LCR_SET_BREAK; 13253f542974SPaul B Schroeder 13266b447f04SAlan Cox /* FIXME: no locking on shadowLCR anywhere in driver */ 13273f542974SPaul B Schroeder mos7840_port->shadowLCR = data; 13289c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s mos7840_port->shadowLCR is %x\n", __func__, mos7840_port->shadowLCR); 13293f542974SPaul B Schroeder mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, 13303f542974SPaul B Schroeder mos7840_port->shadowLCR); 13313f542974SPaul B Schroeder } 13323f542974SPaul B Schroeder 13333f542974SPaul B Schroeder /***************************************************************************** 13343f542974SPaul B Schroeder * mos7840_write_room 13353f542974SPaul B Schroeder * this function is called by the tty driver when it wants to know how many 13363f542974SPaul B Schroeder * bytes of data we can accept for a specific port. 13373f542974SPaul B Schroeder * If successful, we return the amount of room that we have for this port 13383f542974SPaul B Schroeder * Otherwise we return a negative error number. 13393f542974SPaul B Schroeder *****************************************************************************/ 13403f542974SPaul B Schroeder 134195da310eSAlan Cox static int mos7840_write_room(struct tty_struct *tty) 13423f542974SPaul B Schroeder { 134395da310eSAlan Cox struct usb_serial_port *port = tty->driver_data; 13443f542974SPaul B Schroeder int i; 13453f542974SPaul B Schroeder int room = 0; 13460de9a702SOliver Neukum unsigned long flags; 13473f542974SPaul B Schroeder struct moschip_port *mos7840_port; 13483f542974SPaul B Schroeder 13499c134a14SGreg Kroah-Hartman if (mos7840_port_paranoia_check(port, __func__)) 13503f542974SPaul B Schroeder return -1; 13513f542974SPaul B Schroeder 13523f542974SPaul B Schroeder mos7840_port = mos7840_get_port_private(port); 13539c134a14SGreg Kroah-Hartman if (mos7840_port == NULL) 13543f542974SPaul B Schroeder return -1; 13553f542974SPaul B Schroeder 13560de9a702SOliver Neukum spin_lock_irqsave(&mos7840_port->pool_lock, flags); 13573f542974SPaul B Schroeder for (i = 0; i < NUM_URBS; ++i) { 1358880af9dbSAlan Cox if (!mos7840_port->busy[i]) 13593f542974SPaul B Schroeder room += URB_TRANSFER_BUFFER_SIZE; 13603f542974SPaul B Schroeder } 13610de9a702SOliver Neukum spin_unlock_irqrestore(&mos7840_port->pool_lock, flags); 13623f542974SPaul B Schroeder 13630de9a702SOliver Neukum room = (room == 0) ? 0 : room - URB_TRANSFER_BUFFER_SIZE + 1; 13649c134a14SGreg Kroah-Hartman dev_dbg(&mos7840_port->port->dev, "%s - returns %d\n", __func__, room); 13650de9a702SOliver Neukum return room; 13663f542974SPaul B Schroeder 13673f542974SPaul B Schroeder } 13683f542974SPaul B Schroeder 13693f542974SPaul B Schroeder /***************************************************************************** 13703f542974SPaul B Schroeder * mos7840_write 13713f542974SPaul B Schroeder * this function is called by the tty driver when data should be written to 13723f542974SPaul B Schroeder * the port. 13733f542974SPaul B Schroeder * If successful, we return the number of bytes written, otherwise we 13743f542974SPaul B Schroeder * return a negative error number. 13753f542974SPaul B Schroeder *****************************************************************************/ 13763f542974SPaul B Schroeder 137795da310eSAlan Cox static int mos7840_write(struct tty_struct *tty, struct usb_serial_port *port, 13783f542974SPaul B Schroeder const unsigned char *data, int count) 13793f542974SPaul B Schroeder { 13803f542974SPaul B Schroeder int status; 13813f542974SPaul B Schroeder int i; 13823f542974SPaul B Schroeder int bytes_sent = 0; 13833f542974SPaul B Schroeder int transfer_size; 13840de9a702SOliver Neukum unsigned long flags; 13853f542974SPaul B Schroeder 13863f542974SPaul B Schroeder struct moschip_port *mos7840_port; 13873f542974SPaul B Schroeder struct usb_serial *serial; 13883f542974SPaul B Schroeder struct urb *urb; 1389880af9dbSAlan Cox /* __u16 Data; */ 13903f542974SPaul B Schroeder const unsigned char *current_position = data; 13913f542974SPaul B Schroeder unsigned char *data1; 13923f542974SPaul B Schroeder 13933f542974SPaul B Schroeder #ifdef NOTMOS7840 13943f542974SPaul B Schroeder Data = 0x00; 13953f542974SPaul B Schroeder status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data); 13963f542974SPaul B Schroeder mos7840_port->shadowLCR = Data; 13979c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s: LINE_CONTROL_REGISTER is %x\n", __func__, Data); 13989c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s: mos7840_port->shadowLCR is %x\n", __func__, mos7840_port->shadowLCR); 13993f542974SPaul B Schroeder 1400880af9dbSAlan Cox /* Data = 0x03; */ 1401880af9dbSAlan Cox /* status = mos7840_set_uart_reg(port,LINE_CONTROL_REGISTER,Data); */ 1402880af9dbSAlan Cox /* mos7840_port->shadowLCR=Data;//Need to add later */ 14033f542974SPaul B Schroeder 1404880af9dbSAlan Cox Data |= SERIAL_LCR_DLAB; /* data latch enable in LCR 0x80 */ 14053f542974SPaul B Schroeder status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); 14063f542974SPaul B Schroeder 1407880af9dbSAlan Cox /* Data = 0x0c; */ 1408880af9dbSAlan Cox /* status = mos7840_set_uart_reg(port,DIVISOR_LATCH_LSB,Data); */ 14093f542974SPaul B Schroeder Data = 0x00; 14103f542974SPaul B Schroeder status = mos7840_get_uart_reg(port, DIVISOR_LATCH_LSB, &Data); 14119c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s: DLL value is %x\n", __func__, Data); 14123f542974SPaul B Schroeder 14133f542974SPaul B Schroeder Data = 0x0; 14143f542974SPaul B Schroeder status = mos7840_get_uart_reg(port, DIVISOR_LATCH_MSB, &Data); 14159c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s: DLM value is %x\n", __func__, Data); 14163f542974SPaul B Schroeder 14173f542974SPaul B Schroeder Data = Data & ~SERIAL_LCR_DLAB; 14189c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s: mos7840_port->shadowLCR is %x\n", __func__, mos7840_port->shadowLCR); 14193f542974SPaul B Schroeder status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); 14203f542974SPaul B Schroeder #endif 14213f542974SPaul B Schroeder 14229c134a14SGreg Kroah-Hartman if (mos7840_port_paranoia_check(port, __func__)) 14233f542974SPaul B Schroeder return -1; 14243f542974SPaul B Schroeder 14253f542974SPaul B Schroeder serial = port->serial; 14269c134a14SGreg Kroah-Hartman if (mos7840_serial_paranoia_check(serial, __func__)) 14273f542974SPaul B Schroeder return -1; 14283f542974SPaul B Schroeder 14293f542974SPaul B Schroeder mos7840_port = mos7840_get_port_private(port); 14309c134a14SGreg Kroah-Hartman if (mos7840_port == NULL) 14313f542974SPaul B Schroeder return -1; 14323f542974SPaul B Schroeder 14333f542974SPaul B Schroeder /* try to find a free urb in the list */ 14343f542974SPaul B Schroeder urb = NULL; 14353f542974SPaul B Schroeder 14360de9a702SOliver Neukum spin_lock_irqsave(&mos7840_port->pool_lock, flags); 14373f542974SPaul B Schroeder for (i = 0; i < NUM_URBS; ++i) { 14380de9a702SOliver Neukum if (!mos7840_port->busy[i]) { 14390de9a702SOliver Neukum mos7840_port->busy[i] = 1; 14403f542974SPaul B Schroeder urb = mos7840_port->write_urb_pool[i]; 14419c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "URB:%d\n", i); 14423f542974SPaul B Schroeder break; 14433f542974SPaul B Schroeder } 14443f542974SPaul B Schroeder } 14450de9a702SOliver Neukum spin_unlock_irqrestore(&mos7840_port->pool_lock, flags); 14463f542974SPaul B Schroeder 14473f542974SPaul B Schroeder if (urb == NULL) { 14489c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s - no more free urbs\n", __func__); 14493f542974SPaul B Schroeder goto exit; 14503f542974SPaul B Schroeder } 14513f542974SPaul B Schroeder 14523f542974SPaul B Schroeder if (urb->transfer_buffer == NULL) { 14533f542974SPaul B Schroeder urb->transfer_buffer = 14543f542974SPaul B Schroeder kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL); 14553f542974SPaul B Schroeder 14563f542974SPaul B Schroeder if (urb->transfer_buffer == NULL) { 145722a416c4SJohan Hovold dev_err_console(port, "%s no more kernel memory...\n", 1458194343d9SGreg Kroah-Hartman __func__); 14593f542974SPaul B Schroeder goto exit; 14603f542974SPaul B Schroeder } 14613f542974SPaul B Schroeder } 14623f542974SPaul B Schroeder transfer_size = min(count, URB_TRANSFER_BUFFER_SIZE); 14633f542974SPaul B Schroeder 14643f542974SPaul B Schroeder memcpy(urb->transfer_buffer, current_position, transfer_size); 14653f542974SPaul B Schroeder 14663f542974SPaul B Schroeder /* fill urb with data and submit */ 1467093ea2d3SDonald Lee if ((serial->num_ports == 2) 1468093ea2d3SDonald Lee && ((((__u16)port->number - 1469093ea2d3SDonald Lee (__u16)(port->serial->minor)) % 2) != 0)) { 1470093ea2d3SDonald Lee usb_fill_bulk_urb(urb, 1471093ea2d3SDonald Lee serial->dev, 1472093ea2d3SDonald Lee usb_sndbulkpipe(serial->dev, 1473093ea2d3SDonald Lee (port->bulk_out_endpointAddress) + 2), 1474093ea2d3SDonald Lee urb->transfer_buffer, 1475093ea2d3SDonald Lee transfer_size, 1476093ea2d3SDonald Lee mos7840_bulk_out_data_callback, mos7840_port); 1477093ea2d3SDonald Lee } else { 14783f542974SPaul B Schroeder usb_fill_bulk_urb(urb, 14793f542974SPaul B Schroeder serial->dev, 14803f542974SPaul B Schroeder usb_sndbulkpipe(serial->dev, 14813f542974SPaul B Schroeder port->bulk_out_endpointAddress), 14823f542974SPaul B Schroeder urb->transfer_buffer, 14833f542974SPaul B Schroeder transfer_size, 14843f542974SPaul B Schroeder mos7840_bulk_out_data_callback, mos7840_port); 1485093ea2d3SDonald Lee } 14863f542974SPaul B Schroeder 14873f542974SPaul B Schroeder data1 = urb->transfer_buffer; 14889c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "bulkout endpoint is %d\n", port->bulk_out_endpointAddress); 14893f542974SPaul B Schroeder 14900eafe4deSDonald /* Turn on LED */ 14910eafe4deSDonald if (mos7840_port->has_led && !mos7840_port->led_flag) { 14920eafe4deSDonald mos7840_port->led_flag = true; 14930eafe4deSDonald mos7840_set_led_sync(port, MODEM_CONTROL_REGISTER, 0x0301); 14940eafe4deSDonald mod_timer(&mos7840_port->led_timer1, 14950eafe4deSDonald jiffies + msecs_to_jiffies(LED_ON_MS)); 14960eafe4deSDonald } 14970eafe4deSDonald 14983f542974SPaul B Schroeder /* send it down the pipe */ 14993f542974SPaul B Schroeder status = usb_submit_urb(urb, GFP_ATOMIC); 15003f542974SPaul B Schroeder 15013f542974SPaul B Schroeder if (status) { 15020de9a702SOliver Neukum mos7840_port->busy[i] = 0; 150322a416c4SJohan Hovold dev_err_console(port, "%s - usb_submit_urb(write bulk) failed " 1504194343d9SGreg Kroah-Hartman "with status = %d\n", __func__, status); 15053f542974SPaul B Schroeder bytes_sent = status; 15063f542974SPaul B Schroeder goto exit; 15073f542974SPaul B Schroeder } 15083f542974SPaul B Schroeder bytes_sent = transfer_size; 15093f542974SPaul B Schroeder mos7840_port->icount.tx += transfer_size; 15100de9a702SOliver Neukum smp_wmb(); 15119c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "mos7840_port->icount.tx is %d:\n", mos7840_port->icount.tx); 15123f542974SPaul B Schroeder exit: 15133f542974SPaul B Schroeder return bytes_sent; 15143f542974SPaul B Schroeder 15153f542974SPaul B Schroeder } 15163f542974SPaul B Schroeder 15173f542974SPaul B Schroeder /***************************************************************************** 15183f542974SPaul B Schroeder * mos7840_throttle 15193f542974SPaul B Schroeder * this function is called by the tty driver when it wants to stop the data 15203f542974SPaul B Schroeder * being read from the port. 15213f542974SPaul B Schroeder *****************************************************************************/ 15223f542974SPaul B Schroeder 152395da310eSAlan Cox static void mos7840_throttle(struct tty_struct *tty) 15243f542974SPaul B Schroeder { 152595da310eSAlan Cox struct usb_serial_port *port = tty->driver_data; 15263f542974SPaul B Schroeder struct moschip_port *mos7840_port; 15273f542974SPaul B Schroeder int status; 15283f542974SPaul B Schroeder 15299c134a14SGreg Kroah-Hartman if (mos7840_port_paranoia_check(port, __func__)) 15303f542974SPaul B Schroeder return; 15313f542974SPaul B Schroeder 15323f542974SPaul B Schroeder mos7840_port = mos7840_get_port_private(port); 15333f542974SPaul B Schroeder 15343f542974SPaul B Schroeder if (mos7840_port == NULL) 15353f542974SPaul B Schroeder return; 15363f542974SPaul B Schroeder 15373f542974SPaul B Schroeder if (!mos7840_port->open) { 15389c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s", "port not opened\n"); 15393f542974SPaul B Schroeder return; 15403f542974SPaul B Schroeder } 15413f542974SPaul B Schroeder 15423f542974SPaul B Schroeder /* if we are implementing XON/XOFF, send the stop character */ 15433f542974SPaul B Schroeder if (I_IXOFF(tty)) { 15443f542974SPaul B Schroeder unsigned char stop_char = STOP_CHAR(tty); 154595da310eSAlan Cox status = mos7840_write(tty, port, &stop_char, 1); 154695da310eSAlan Cox if (status <= 0) 15473f542974SPaul B Schroeder return; 15483f542974SPaul B Schroeder } 15493f542974SPaul B Schroeder /* if we are implementing RTS/CTS, toggle that line */ 1550adc8d746SAlan Cox if (tty->termios.c_cflag & CRTSCTS) { 15513f542974SPaul B Schroeder mos7840_port->shadowMCR &= ~MCR_RTS; 155295da310eSAlan Cox status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, 15533f542974SPaul B Schroeder mos7840_port->shadowMCR); 155495da310eSAlan Cox if (status < 0) 15553f542974SPaul B Schroeder return; 15563f542974SPaul B Schroeder } 15573f542974SPaul B Schroeder } 15583f542974SPaul B Schroeder 15593f542974SPaul B Schroeder /***************************************************************************** 15603f542974SPaul B Schroeder * mos7840_unthrottle 1561880af9dbSAlan Cox * this function is called by the tty driver when it wants to resume 1562880af9dbSAlan Cox * the data being read from the port (called after mos7840_throttle is 1563880af9dbSAlan Cox * called) 15643f542974SPaul B Schroeder *****************************************************************************/ 156595da310eSAlan Cox static void mos7840_unthrottle(struct tty_struct *tty) 15663f542974SPaul B Schroeder { 156795da310eSAlan Cox struct usb_serial_port *port = tty->driver_data; 15683f542974SPaul B Schroeder int status; 15693f542974SPaul B Schroeder struct moschip_port *mos7840_port = mos7840_get_port_private(port); 15703f542974SPaul B Schroeder 15719c134a14SGreg Kroah-Hartman if (mos7840_port_paranoia_check(port, __func__)) 15723f542974SPaul B Schroeder return; 15733f542974SPaul B Schroeder 15743f542974SPaul B Schroeder if (mos7840_port == NULL) 15753f542974SPaul B Schroeder return; 15763f542974SPaul B Schroeder 15773f542974SPaul B Schroeder if (!mos7840_port->open) { 15789c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s - port not opened\n", __func__); 15793f542974SPaul B Schroeder return; 15803f542974SPaul B Schroeder } 15813f542974SPaul B Schroeder 15823f542974SPaul B Schroeder /* if we are implementing XON/XOFF, send the start character */ 15833f542974SPaul B Schroeder if (I_IXOFF(tty)) { 15843f542974SPaul B Schroeder unsigned char start_char = START_CHAR(tty); 158595da310eSAlan Cox status = mos7840_write(tty, port, &start_char, 1); 158695da310eSAlan Cox if (status <= 0) 15873f542974SPaul B Schroeder return; 15883f542974SPaul B Schroeder } 15893f542974SPaul B Schroeder 15903f542974SPaul B Schroeder /* if we are implementing RTS/CTS, toggle that line */ 1591adc8d746SAlan Cox if (tty->termios.c_cflag & CRTSCTS) { 15923f542974SPaul B Schroeder mos7840_port->shadowMCR |= MCR_RTS; 159395da310eSAlan Cox status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, 15943f542974SPaul B Schroeder mos7840_port->shadowMCR); 159595da310eSAlan Cox if (status < 0) 15963f542974SPaul B Schroeder return; 15973f542974SPaul B Schroeder } 15983f542974SPaul B Schroeder } 15993f542974SPaul B Schroeder 160060b33c13SAlan Cox static int mos7840_tiocmget(struct tty_struct *tty) 16013f542974SPaul B Schroeder { 160295da310eSAlan Cox struct usb_serial_port *port = tty->driver_data; 16033f542974SPaul B Schroeder struct moschip_port *mos7840_port; 16043f542974SPaul B Schroeder unsigned int result; 16053f542974SPaul B Schroeder __u16 msr; 16063f542974SPaul B Schroeder __u16 mcr; 1607880af9dbSAlan Cox int status; 16083f542974SPaul B Schroeder mos7840_port = mos7840_get_port_private(port); 16093f542974SPaul B Schroeder 16103f542974SPaul B Schroeder if (mos7840_port == NULL) 16113f542974SPaul B Schroeder return -ENODEV; 16123f542974SPaul B Schroeder 16133f542974SPaul B Schroeder status = mos7840_get_uart_reg(port, MODEM_STATUS_REGISTER, &msr); 16143f542974SPaul B Schroeder status = mos7840_get_uart_reg(port, MODEM_CONTROL_REGISTER, &mcr); 16153f542974SPaul B Schroeder result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0) 16163f542974SPaul B Schroeder | ((mcr & MCR_RTS) ? TIOCM_RTS : 0) 16173f542974SPaul B Schroeder | ((mcr & MCR_LOOPBACK) ? TIOCM_LOOP : 0) 16183f542974SPaul B Schroeder | ((msr & MOS7840_MSR_CTS) ? TIOCM_CTS : 0) 16193f542974SPaul B Schroeder | ((msr & MOS7840_MSR_CD) ? TIOCM_CAR : 0) 16203f542974SPaul B Schroeder | ((msr & MOS7840_MSR_RI) ? TIOCM_RI : 0) 16213f542974SPaul B Schroeder | ((msr & MOS7840_MSR_DSR) ? TIOCM_DSR : 0); 16223f542974SPaul B Schroeder 16239c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s - 0x%04X\n", __func__, result); 16243f542974SPaul B Schroeder 16253f542974SPaul B Schroeder return result; 16263f542974SPaul B Schroeder } 16273f542974SPaul B Schroeder 162820b9d177SAlan Cox static int mos7840_tiocmset(struct tty_struct *tty, 16293f542974SPaul B Schroeder unsigned int set, unsigned int clear) 16303f542974SPaul B Schroeder { 163195da310eSAlan Cox struct usb_serial_port *port = tty->driver_data; 16323f542974SPaul B Schroeder struct moschip_port *mos7840_port; 16333f542974SPaul B Schroeder unsigned int mcr; 163487521c46SRoel Kluin int status; 16353f542974SPaul B Schroeder 16363f542974SPaul B Schroeder mos7840_port = mos7840_get_port_private(port); 16373f542974SPaul B Schroeder 16383f542974SPaul B Schroeder if (mos7840_port == NULL) 16393f542974SPaul B Schroeder return -ENODEV; 16403f542974SPaul B Schroeder 1641e2984494SAlan Cox /* FIXME: What locks the port registers ? */ 16423f542974SPaul B Schroeder mcr = mos7840_port->shadowMCR; 16433f542974SPaul B Schroeder if (clear & TIOCM_RTS) 16443f542974SPaul B Schroeder mcr &= ~MCR_RTS; 16453f542974SPaul B Schroeder if (clear & TIOCM_DTR) 16463f542974SPaul B Schroeder mcr &= ~MCR_DTR; 16473f542974SPaul B Schroeder if (clear & TIOCM_LOOP) 16483f542974SPaul B Schroeder mcr &= ~MCR_LOOPBACK; 16493f542974SPaul B Schroeder 16503f542974SPaul B Schroeder if (set & TIOCM_RTS) 16513f542974SPaul B Schroeder mcr |= MCR_RTS; 16523f542974SPaul B Schroeder if (set & TIOCM_DTR) 16533f542974SPaul B Schroeder mcr |= MCR_DTR; 16543f542974SPaul B Schroeder if (set & TIOCM_LOOP) 16553f542974SPaul B Schroeder mcr |= MCR_LOOPBACK; 16563f542974SPaul B Schroeder 16573f542974SPaul B Schroeder mos7840_port->shadowMCR = mcr; 16583f542974SPaul B Schroeder 16593f542974SPaul B Schroeder status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, mcr); 16603f542974SPaul B Schroeder if (status < 0) { 16619c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "setting MODEM_CONTROL_REGISTER Failed\n"); 166287521c46SRoel Kluin return status; 16633f542974SPaul B Schroeder } 16643f542974SPaul B Schroeder 16653f542974SPaul B Schroeder return 0; 16663f542974SPaul B Schroeder } 16673f542974SPaul B Schroeder 16683f542974SPaul B Schroeder /***************************************************************************** 16693f542974SPaul B Schroeder * mos7840_calc_baud_rate_divisor 16703f542974SPaul B Schroeder * this function calculates the proper baud rate divisor for the specified 16713f542974SPaul B Schroeder * baud rate. 16723f542974SPaul B Schroeder *****************************************************************************/ 16739c134a14SGreg Kroah-Hartman static int mos7840_calc_baud_rate_divisor(struct usb_serial_port *port, 16749c134a14SGreg Kroah-Hartman int baudRate, int *divisor, 16753f542974SPaul B Schroeder __u16 *clk_sel_val) 16763f542974SPaul B Schroeder { 16779c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s - %d\n", __func__, baudRate); 16783f542974SPaul B Schroeder 16793f542974SPaul B Schroeder if (baudRate <= 115200) { 16803f542974SPaul B Schroeder *divisor = 115200 / baudRate; 16813f542974SPaul B Schroeder *clk_sel_val = 0x0; 16823f542974SPaul B Schroeder } 16833f542974SPaul B Schroeder if ((baudRate > 115200) && (baudRate <= 230400)) { 16843f542974SPaul B Schroeder *divisor = 230400 / baudRate; 16853f542974SPaul B Schroeder *clk_sel_val = 0x10; 16863f542974SPaul B Schroeder } else if ((baudRate > 230400) && (baudRate <= 403200)) { 16873f542974SPaul B Schroeder *divisor = 403200 / baudRate; 16883f542974SPaul B Schroeder *clk_sel_val = 0x20; 16893f542974SPaul B Schroeder } else if ((baudRate > 403200) && (baudRate <= 460800)) { 16903f542974SPaul B Schroeder *divisor = 460800 / baudRate; 16913f542974SPaul B Schroeder *clk_sel_val = 0x30; 16923f542974SPaul B Schroeder } else if ((baudRate > 460800) && (baudRate <= 806400)) { 16933f542974SPaul B Schroeder *divisor = 806400 / baudRate; 16943f542974SPaul B Schroeder *clk_sel_val = 0x40; 16953f542974SPaul B Schroeder } else if ((baudRate > 806400) && (baudRate <= 921600)) { 16963f542974SPaul B Schroeder *divisor = 921600 / baudRate; 16973f542974SPaul B Schroeder *clk_sel_val = 0x50; 16983f542974SPaul B Schroeder } else if ((baudRate > 921600) && (baudRate <= 1572864)) { 16993f542974SPaul B Schroeder *divisor = 1572864 / baudRate; 17003f542974SPaul B Schroeder *clk_sel_val = 0x60; 17013f542974SPaul B Schroeder } else if ((baudRate > 1572864) && (baudRate <= 3145728)) { 17023f542974SPaul B Schroeder *divisor = 3145728 / baudRate; 17033f542974SPaul B Schroeder *clk_sel_val = 0x70; 17043f542974SPaul B Schroeder } 17053f542974SPaul B Schroeder return 0; 17063f542974SPaul B Schroeder 17073f542974SPaul B Schroeder #ifdef NOTMCS7840 17083f542974SPaul B Schroeder 17093f542974SPaul B Schroeder for (i = 0; i < ARRAY_SIZE(mos7840_divisor_table); i++) { 17103f542974SPaul B Schroeder if (mos7840_divisor_table[i].BaudRate == baudrate) { 17113f542974SPaul B Schroeder *divisor = mos7840_divisor_table[i].Divisor; 17123f542974SPaul B Schroeder return 0; 17133f542974SPaul B Schroeder } 17143f542974SPaul B Schroeder } 17153f542974SPaul B Schroeder 17163f542974SPaul B Schroeder /* After trying for all the standard baud rates * 17173f542974SPaul B Schroeder * Try calculating the divisor for this baud rate */ 17183f542974SPaul B Schroeder 17193f542974SPaul B Schroeder if (baudrate > 75 && baudrate < 230400) { 17203f542974SPaul B Schroeder /* get the divisor */ 17213f542974SPaul B Schroeder custom = (__u16) (230400L / baudrate); 17223f542974SPaul B Schroeder 17233f542974SPaul B Schroeder /* Check for round off */ 17243f542974SPaul B Schroeder round1 = (__u16) (2304000L / baudrate); 17253f542974SPaul B Schroeder round = (__u16) (round1 - (custom * 10)); 1726880af9dbSAlan Cox if (round > 4) 17273f542974SPaul B Schroeder custom++; 17283f542974SPaul B Schroeder *divisor = custom; 17293f542974SPaul B Schroeder 17309c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, " Baud %d = %d\n", baudrate, custom); 17313f542974SPaul B Schroeder return 0; 17323f542974SPaul B Schroeder } 17333f542974SPaul B Schroeder 17349c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s", " Baud calculation Failed...\n"); 17353f542974SPaul B Schroeder return -1; 17363f542974SPaul B Schroeder #endif 17373f542974SPaul B Schroeder } 17383f542974SPaul B Schroeder 17393f542974SPaul B Schroeder /***************************************************************************** 17403f542974SPaul B Schroeder * mos7840_send_cmd_write_baud_rate 17413f542974SPaul B Schroeder * this function sends the proper command to change the baud rate of the 17423f542974SPaul B Schroeder * specified port. 17433f542974SPaul B Schroeder *****************************************************************************/ 17443f542974SPaul B Schroeder 17453f542974SPaul B Schroeder static int mos7840_send_cmd_write_baud_rate(struct moschip_port *mos7840_port, 17463f542974SPaul B Schroeder int baudRate) 17473f542974SPaul B Schroeder { 17483f542974SPaul B Schroeder int divisor = 0; 17493f542974SPaul B Schroeder int status; 17503f542974SPaul B Schroeder __u16 Data; 17513f542974SPaul B Schroeder unsigned char number; 17523f542974SPaul B Schroeder __u16 clk_sel_val; 17533f542974SPaul B Schroeder struct usb_serial_port *port; 17543f542974SPaul B Schroeder 17553f542974SPaul B Schroeder if (mos7840_port == NULL) 17563f542974SPaul B Schroeder return -1; 17573f542974SPaul B Schroeder 17589c134a14SGreg Kroah-Hartman port = mos7840_port->port; 17599c134a14SGreg Kroah-Hartman if (mos7840_port_paranoia_check(port, __func__)) 17603f542974SPaul B Schroeder return -1; 17613f542974SPaul B Schroeder 17629c134a14SGreg Kroah-Hartman if (mos7840_serial_paranoia_check(port->serial, __func__)) 17633f542974SPaul B Schroeder return -1; 17643f542974SPaul B Schroeder 17653f542974SPaul B Schroeder number = mos7840_port->port->number - mos7840_port->port->serial->minor; 17663f542974SPaul B Schroeder 17679c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s - port = %d, baud = %d\n", __func__, 17683f542974SPaul B Schroeder mos7840_port->port->number, baudRate); 1769880af9dbSAlan Cox /* reset clk_uart_sel in spregOffset */ 17703f542974SPaul B Schroeder if (baudRate > 115200) { 17713f542974SPaul B Schroeder #ifdef HW_flow_control 1772880af9dbSAlan Cox /* NOTE: need to see the pther register to modify */ 1773880af9dbSAlan Cox /* setting h/w flow control bit to 1 */ 17743f542974SPaul B Schroeder Data = 0x2b; 17753f542974SPaul B Schroeder mos7840_port->shadowMCR = Data; 1776880af9dbSAlan Cox status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, 1777880af9dbSAlan Cox Data); 17783f542974SPaul B Schroeder if (status < 0) { 17799c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "Writing spreg failed in set_serial_baud\n"); 17803f542974SPaul B Schroeder return -1; 17813f542974SPaul B Schroeder } 17823f542974SPaul B Schroeder #endif 17833f542974SPaul B Schroeder 17843f542974SPaul B Schroeder } else { 17853f542974SPaul B Schroeder #ifdef HW_flow_control 1786880af9dbSAlan Cox /* setting h/w flow control bit to 0 */ 17873f542974SPaul B Schroeder Data = 0xb; 17883f542974SPaul B Schroeder mos7840_port->shadowMCR = Data; 1789880af9dbSAlan Cox status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, 1790880af9dbSAlan Cox Data); 17913f542974SPaul B Schroeder if (status < 0) { 17929c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "Writing spreg failed in set_serial_baud\n"); 17933f542974SPaul B Schroeder return -1; 17943f542974SPaul B Schroeder } 17953f542974SPaul B Schroeder #endif 17963f542974SPaul B Schroeder 17973f542974SPaul B Schroeder } 17983f542974SPaul B Schroeder 1799880af9dbSAlan Cox if (1) { /* baudRate <= 115200) */ 18003f542974SPaul B Schroeder clk_sel_val = 0x0; 18013f542974SPaul B Schroeder Data = 0x0; 18029c134a14SGreg Kroah-Hartman status = mos7840_calc_baud_rate_divisor(port, baudRate, &divisor, 18033f542974SPaul B Schroeder &clk_sel_val); 1804880af9dbSAlan Cox status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, 18053f542974SPaul B Schroeder &Data); 18063f542974SPaul B Schroeder if (status < 0) { 18079c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "reading spreg failed in set_serial_baud\n"); 18083f542974SPaul B Schroeder return -1; 18093f542974SPaul B Schroeder } 18103f542974SPaul B Schroeder Data = (Data & 0x8f) | clk_sel_val; 1811880af9dbSAlan Cox status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, 1812880af9dbSAlan Cox Data); 18133f542974SPaul B Schroeder if (status < 0) { 18149c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "Writing spreg failed in set_serial_baud\n"); 18153f542974SPaul B Schroeder return -1; 18163f542974SPaul B Schroeder } 18173f542974SPaul B Schroeder /* Calculate the Divisor */ 18183f542974SPaul B Schroeder 18193f542974SPaul B Schroeder if (status) { 1820194343d9SGreg Kroah-Hartman dev_err(&port->dev, "%s - bad baud rate\n", __func__); 18213f542974SPaul B Schroeder return status; 18223f542974SPaul B Schroeder } 18233f542974SPaul B Schroeder /* Enable access to divisor latch */ 18243f542974SPaul B Schroeder Data = mos7840_port->shadowLCR | SERIAL_LCR_DLAB; 18253f542974SPaul B Schroeder mos7840_port->shadowLCR = Data; 18263f542974SPaul B Schroeder mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); 18273f542974SPaul B Schroeder 18283f542974SPaul B Schroeder /* Write the divisor */ 18293f542974SPaul B Schroeder Data = (unsigned char)(divisor & 0xff); 18309c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "set_serial_baud Value to write DLL is %x\n", Data); 18313f542974SPaul B Schroeder mos7840_set_uart_reg(port, DIVISOR_LATCH_LSB, Data); 18323f542974SPaul B Schroeder 18333f542974SPaul B Schroeder Data = (unsigned char)((divisor & 0xff00) >> 8); 18349c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "set_serial_baud Value to write DLM is %x\n", Data); 18353f542974SPaul B Schroeder mos7840_set_uart_reg(port, DIVISOR_LATCH_MSB, Data); 18363f542974SPaul B Schroeder 18373f542974SPaul B Schroeder /* Disable access to divisor latch */ 18383f542974SPaul B Schroeder Data = mos7840_port->shadowLCR & ~SERIAL_LCR_DLAB; 18393f542974SPaul B Schroeder mos7840_port->shadowLCR = Data; 18403f542974SPaul B Schroeder mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); 18413f542974SPaul B Schroeder 18423f542974SPaul B Schroeder } 18433f542974SPaul B Schroeder return status; 18443f542974SPaul B Schroeder } 18453f542974SPaul B Schroeder 18463f542974SPaul B Schroeder /***************************************************************************** 18473f542974SPaul B Schroeder * mos7840_change_port_settings 18483f542974SPaul B Schroeder * This routine is called to set the UART on the device to match 18493f542974SPaul B Schroeder * the specified new settings. 18503f542974SPaul B Schroeder *****************************************************************************/ 18513f542974SPaul B Schroeder 185295da310eSAlan Cox static void mos7840_change_port_settings(struct tty_struct *tty, 185395da310eSAlan Cox struct moschip_port *mos7840_port, struct ktermios *old_termios) 18543f542974SPaul B Schroeder { 18553f542974SPaul B Schroeder int baud; 18563f542974SPaul B Schroeder unsigned cflag; 18573f542974SPaul B Schroeder unsigned iflag; 18583f542974SPaul B Schroeder __u8 lData; 18593f542974SPaul B Schroeder __u8 lParity; 18603f542974SPaul B Schroeder __u8 lStop; 18613f542974SPaul B Schroeder int status; 18623f542974SPaul B Schroeder __u16 Data; 18633f542974SPaul B Schroeder struct usb_serial_port *port; 18643f542974SPaul B Schroeder struct usb_serial *serial; 18653f542974SPaul B Schroeder 18663f542974SPaul B Schroeder if (mos7840_port == NULL) 18673f542974SPaul B Schroeder return; 18683f542974SPaul B Schroeder 18699c134a14SGreg Kroah-Hartman port = mos7840_port->port; 18703f542974SPaul B Schroeder 18719c134a14SGreg Kroah-Hartman if (mos7840_port_paranoia_check(port, __func__)) 18723f542974SPaul B Schroeder return; 18733f542974SPaul B Schroeder 18749c134a14SGreg Kroah-Hartman if (mos7840_serial_paranoia_check(port->serial, __func__)) 18753f542974SPaul B Schroeder return; 18763f542974SPaul B Schroeder 18773f542974SPaul B Schroeder serial = port->serial; 18783f542974SPaul B Schroeder 18793f542974SPaul B Schroeder if (!mos7840_port->open) { 18809c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s - port not opened\n", __func__); 18813f542974SPaul B Schroeder return; 18823f542974SPaul B Schroeder } 18833f542974SPaul B Schroeder 18843f542974SPaul B Schroeder lData = LCR_BITS_8; 18853f542974SPaul B Schroeder lStop = LCR_STOP_1; 18863f542974SPaul B Schroeder lParity = LCR_PAR_NONE; 18873f542974SPaul B Schroeder 1888adc8d746SAlan Cox cflag = tty->termios.c_cflag; 1889adc8d746SAlan Cox iflag = tty->termios.c_iflag; 18903f542974SPaul B Schroeder 18913f542974SPaul B Schroeder /* Change the number of bits */ 18923f542974SPaul B Schroeder if (cflag & CSIZE) { 18933f542974SPaul B Schroeder switch (cflag & CSIZE) { 18943f542974SPaul B Schroeder case CS5: 18953f542974SPaul B Schroeder lData = LCR_BITS_5; 18963f542974SPaul B Schroeder break; 18973f542974SPaul B Schroeder 18983f542974SPaul B Schroeder case CS6: 18993f542974SPaul B Schroeder lData = LCR_BITS_6; 19003f542974SPaul B Schroeder break; 19013f542974SPaul B Schroeder 19023f542974SPaul B Schroeder case CS7: 19033f542974SPaul B Schroeder lData = LCR_BITS_7; 19043f542974SPaul B Schroeder break; 19053f542974SPaul B Schroeder default: 19063f542974SPaul B Schroeder case CS8: 19073f542974SPaul B Schroeder lData = LCR_BITS_8; 19083f542974SPaul B Schroeder break; 19093f542974SPaul B Schroeder } 19103f542974SPaul B Schroeder } 19113f542974SPaul B Schroeder /* Change the Parity bit */ 19123f542974SPaul B Schroeder if (cflag & PARENB) { 19133f542974SPaul B Schroeder if (cflag & PARODD) { 19143f542974SPaul B Schroeder lParity = LCR_PAR_ODD; 19159c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s - parity = odd\n", __func__); 19163f542974SPaul B Schroeder } else { 19173f542974SPaul B Schroeder lParity = LCR_PAR_EVEN; 19189c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s - parity = even\n", __func__); 19193f542974SPaul B Schroeder } 19203f542974SPaul B Schroeder 19213f542974SPaul B Schroeder } else { 19229c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s - parity = none\n", __func__); 19233f542974SPaul B Schroeder } 19243f542974SPaul B Schroeder 1925880af9dbSAlan Cox if (cflag & CMSPAR) 19263f542974SPaul B Schroeder lParity = lParity | 0x20; 19273f542974SPaul B Schroeder 19283f542974SPaul B Schroeder /* Change the Stop bit */ 19293f542974SPaul B Schroeder if (cflag & CSTOPB) { 19303f542974SPaul B Schroeder lStop = LCR_STOP_2; 19319c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s - stop bits = 2\n", __func__); 19323f542974SPaul B Schroeder } else { 19333f542974SPaul B Schroeder lStop = LCR_STOP_1; 19349c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s - stop bits = 1\n", __func__); 19353f542974SPaul B Schroeder } 19363f542974SPaul B Schroeder 19373f542974SPaul B Schroeder /* Update the LCR with the correct value */ 19383f542974SPaul B Schroeder mos7840_port->shadowLCR &= 19393f542974SPaul B Schroeder ~(LCR_BITS_MASK | LCR_STOP_MASK | LCR_PAR_MASK); 19403f542974SPaul B Schroeder mos7840_port->shadowLCR |= (lData | lParity | lStop); 19413f542974SPaul B Schroeder 19429c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s - mos7840_port->shadowLCR is %x\n", __func__, 19433f542974SPaul B Schroeder mos7840_port->shadowLCR); 19443f542974SPaul B Schroeder /* Disable Interrupts */ 19453f542974SPaul B Schroeder Data = 0x00; 19463f542974SPaul B Schroeder mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data); 19473f542974SPaul B Schroeder 19483f542974SPaul B Schroeder Data = 0x00; 19493f542974SPaul B Schroeder mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data); 19503f542974SPaul B Schroeder 19513f542974SPaul B Schroeder Data = 0xcf; 19523f542974SPaul B Schroeder mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data); 19533f542974SPaul B Schroeder 19543f542974SPaul B Schroeder /* Send the updated LCR value to the mos7840 */ 19553f542974SPaul B Schroeder Data = mos7840_port->shadowLCR; 19563f542974SPaul B Schroeder 19573f542974SPaul B Schroeder mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); 19583f542974SPaul B Schroeder 19593f542974SPaul B Schroeder Data = 0x00b; 19603f542974SPaul B Schroeder mos7840_port->shadowMCR = Data; 19613f542974SPaul B Schroeder mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); 19623f542974SPaul B Schroeder Data = 0x00b; 19633f542974SPaul B Schroeder mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); 19643f542974SPaul B Schroeder 19653f542974SPaul B Schroeder /* set up the MCR register and send it to the mos7840 */ 19663f542974SPaul B Schroeder 19673f542974SPaul B Schroeder mos7840_port->shadowMCR = MCR_MASTER_IE; 1968880af9dbSAlan Cox if (cflag & CBAUD) 19693f542974SPaul B Schroeder mos7840_port->shadowMCR |= (MCR_DTR | MCR_RTS); 19703f542974SPaul B Schroeder 1971880af9dbSAlan Cox if (cflag & CRTSCTS) 19723f542974SPaul B Schroeder mos7840_port->shadowMCR |= (MCR_XON_ANY); 1973880af9dbSAlan Cox else 19743f542974SPaul B Schroeder mos7840_port->shadowMCR &= ~(MCR_XON_ANY); 19753f542974SPaul B Schroeder 19763f542974SPaul B Schroeder Data = mos7840_port->shadowMCR; 19773f542974SPaul B Schroeder mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); 19783f542974SPaul B Schroeder 19793f542974SPaul B Schroeder /* Determine divisor based on baud rate */ 19803f542974SPaul B Schroeder baud = tty_get_baud_rate(tty); 19813f542974SPaul B Schroeder 19823f542974SPaul B Schroeder if (!baud) { 19833f542974SPaul B Schroeder /* pick a default, any default... */ 19849c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s", "Picked default baud...\n"); 19853f542974SPaul B Schroeder baud = 9600; 19863f542974SPaul B Schroeder } 19873f542974SPaul B Schroeder 19889c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s - baud rate = %d\n", __func__, baud); 19893f542974SPaul B Schroeder status = mos7840_send_cmd_write_baud_rate(mos7840_port, baud); 19903f542974SPaul B Schroeder 19913f542974SPaul B Schroeder /* Enable Interrupts */ 19923f542974SPaul B Schroeder Data = 0x0c; 19933f542974SPaul B Schroeder mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data); 19943f542974SPaul B Schroeder 199550de36f7SGreg Kroah-Hartman if (mos7840_port->read_urb_busy == false) { 199650de36f7SGreg Kroah-Hartman mos7840_port->read_urb_busy = true; 19973f542974SPaul B Schroeder status = usb_submit_urb(mos7840_port->read_urb, GFP_ATOMIC); 19983f542974SPaul B Schroeder if (status) { 19999c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "usb_submit_urb(read bulk) failed, status = %d\n", 20003f542974SPaul B Schroeder status); 200150de36f7SGreg Kroah-Hartman mos7840_port->read_urb_busy = false; 20023f542974SPaul B Schroeder } 20033f542974SPaul B Schroeder } 20049c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s - mos7840_port->shadowLCR is End %x\n", __func__, 20053f542974SPaul B Schroeder mos7840_port->shadowLCR); 20063f542974SPaul B Schroeder } 20073f542974SPaul B Schroeder 20083f542974SPaul B Schroeder /***************************************************************************** 20093f542974SPaul B Schroeder * mos7840_set_termios 20103f542974SPaul B Schroeder * this function is called by the tty driver when it wants to change 20113f542974SPaul B Schroeder * the termios structure 20123f542974SPaul B Schroeder *****************************************************************************/ 20133f542974SPaul B Schroeder 201495da310eSAlan Cox static void mos7840_set_termios(struct tty_struct *tty, 201595da310eSAlan Cox struct usb_serial_port *port, 2016606d099cSAlan Cox struct ktermios *old_termios) 20173f542974SPaul B Schroeder { 20183f542974SPaul B Schroeder int status; 20193f542974SPaul B Schroeder unsigned int cflag; 20203f542974SPaul B Schroeder struct usb_serial *serial; 20213f542974SPaul B Schroeder struct moschip_port *mos7840_port; 20223363155bSGreg Kroah-Hartman 20239c134a14SGreg Kroah-Hartman if (mos7840_port_paranoia_check(port, __func__)) 20243f542974SPaul B Schroeder return; 20253f542974SPaul B Schroeder 20263f542974SPaul B Schroeder serial = port->serial; 20273f542974SPaul B Schroeder 20289c134a14SGreg Kroah-Hartman if (mos7840_serial_paranoia_check(serial, __func__)) 20293f542974SPaul B Schroeder return; 20303f542974SPaul B Schroeder 20313f542974SPaul B Schroeder mos7840_port = mos7840_get_port_private(port); 20323f542974SPaul B Schroeder 20333f542974SPaul B Schroeder if (mos7840_port == NULL) 20343f542974SPaul B Schroeder return; 20353f542974SPaul B Schroeder 20363f542974SPaul B Schroeder if (!mos7840_port->open) { 20379c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s - port not opened\n", __func__); 20383f542974SPaul B Schroeder return; 20393f542974SPaul B Schroeder } 20403f542974SPaul B Schroeder 20419c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s", "setting termios - \n"); 20423f542974SPaul B Schroeder 2043adc8d746SAlan Cox cflag = tty->termios.c_cflag; 20443f542974SPaul B Schroeder 20459c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s - clfag %08x iflag %08x\n", __func__, 2046adc8d746SAlan Cox tty->termios.c_cflag, RELEVANT_IFLAG(tty->termios.c_iflag)); 20479c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s - old clfag %08x old iflag %08x\n", __func__, 20483f542974SPaul B Schroeder old_termios->c_cflag, RELEVANT_IFLAG(old_termios->c_iflag)); 20499c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s - port %d\n", __func__, port->number); 20503f542974SPaul B Schroeder 20513f542974SPaul B Schroeder /* change the port settings to the new ones specified */ 20523f542974SPaul B Schroeder 205395da310eSAlan Cox mos7840_change_port_settings(tty, mos7840_port, old_termios); 20543f542974SPaul B Schroeder 20553f542974SPaul B Schroeder if (!mos7840_port->read_urb) { 20569c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s", "URB KILLED !!!!!\n"); 20573f542974SPaul B Schroeder return; 20583f542974SPaul B Schroeder } 20593f542974SPaul B Schroeder 206050de36f7SGreg Kroah-Hartman if (mos7840_port->read_urb_busy == false) { 206150de36f7SGreg Kroah-Hartman mos7840_port->read_urb_busy = true; 20623f542974SPaul B Schroeder status = usb_submit_urb(mos7840_port->read_urb, GFP_ATOMIC); 20633f542974SPaul B Schroeder if (status) { 20649c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "usb_submit_urb(read bulk) failed, status = %d\n", 20653f542974SPaul B Schroeder status); 206650de36f7SGreg Kroah-Hartman mos7840_port->read_urb_busy = false; 20673f542974SPaul B Schroeder } 20683f542974SPaul B Schroeder } 20693f542974SPaul B Schroeder } 20703f542974SPaul B Schroeder 20713f542974SPaul B Schroeder /***************************************************************************** 20723f542974SPaul B Schroeder * mos7840_get_lsr_info - get line status register info 20733f542974SPaul B Schroeder * 20743f542974SPaul B Schroeder * Purpose: Let user call ioctl() to get info when the UART physically 20753f542974SPaul B Schroeder * is emptied. On bus types like RS485, the transmitter must 20763f542974SPaul B Schroeder * release the bus after transmitting. This must be done when 20773f542974SPaul B Schroeder * the transmit shift register is empty, not be done when the 20783f542974SPaul B Schroeder * transmit holding register is empty. This functionality 20793f542974SPaul B Schroeder * allows an RS485 driver to be written in user space. 20803f542974SPaul B Schroeder *****************************************************************************/ 20813f542974SPaul B Schroeder 208295da310eSAlan Cox static int mos7840_get_lsr_info(struct tty_struct *tty, 208397c4965dSAl Viro unsigned int __user *value) 20843f542974SPaul B Schroeder { 20853f542974SPaul B Schroeder int count; 20863f542974SPaul B Schroeder unsigned int result = 0; 20873f542974SPaul B Schroeder 208895da310eSAlan Cox count = mos7840_chars_in_buffer(tty); 20899c134a14SGreg Kroah-Hartman if (count == 0) 20903f542974SPaul B Schroeder result = TIOCSER_TEMT; 20913f542974SPaul B Schroeder 20923f542974SPaul B Schroeder if (copy_to_user(value, &result, sizeof(int))) 20933f542974SPaul B Schroeder return -EFAULT; 20943f542974SPaul B Schroeder return 0; 20953f542974SPaul B Schroeder } 20963f542974SPaul B Schroeder 20973f542974SPaul B Schroeder /***************************************************************************** 20983f542974SPaul B Schroeder * mos7840_get_serial_info 20993f542974SPaul B Schroeder * function to get information about serial port 21003f542974SPaul B Schroeder *****************************************************************************/ 21013f542974SPaul B Schroeder 21023f542974SPaul B Schroeder static int mos7840_get_serial_info(struct moschip_port *mos7840_port, 210397c4965dSAl Viro struct serial_struct __user *retinfo) 21043f542974SPaul B Schroeder { 21053f542974SPaul B Schroeder struct serial_struct tmp; 21063f542974SPaul B Schroeder 21073f542974SPaul B Schroeder if (mos7840_port == NULL) 21083f542974SPaul B Schroeder return -1; 21093f542974SPaul B Schroeder 21103f542974SPaul B Schroeder if (!retinfo) 21113f542974SPaul B Schroeder return -EFAULT; 21123f542974SPaul B Schroeder 21133f542974SPaul B Schroeder memset(&tmp, 0, sizeof(tmp)); 21143f542974SPaul B Schroeder 21153f542974SPaul B Schroeder tmp.type = PORT_16550A; 21163f542974SPaul B Schroeder tmp.line = mos7840_port->port->serial->minor; 21173f542974SPaul B Schroeder tmp.port = mos7840_port->port->number; 21183f542974SPaul B Schroeder tmp.irq = 0; 21193f542974SPaul B Schroeder tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ; 21203f542974SPaul B Schroeder tmp.xmit_fifo_size = NUM_URBS * URB_TRANSFER_BUFFER_SIZE; 21213f542974SPaul B Schroeder tmp.baud_base = 9600; 21223f542974SPaul B Schroeder tmp.close_delay = 5 * HZ; 21233f542974SPaul B Schroeder tmp.closing_wait = 30 * HZ; 21243f542974SPaul B Schroeder 21253f542974SPaul B Schroeder if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) 21263f542974SPaul B Schroeder return -EFAULT; 21273f542974SPaul B Schroeder return 0; 21283f542974SPaul B Schroeder } 21293f542974SPaul B Schroeder 21300bca1b91SAlan Cox static int mos7840_get_icount(struct tty_struct *tty, 21310bca1b91SAlan Cox struct serial_icounter_struct *icount) 21320bca1b91SAlan Cox { 21330bca1b91SAlan Cox struct usb_serial_port *port = tty->driver_data; 21340bca1b91SAlan Cox struct moschip_port *mos7840_port; 21350bca1b91SAlan Cox struct async_icount cnow; 21360bca1b91SAlan Cox 21370bca1b91SAlan Cox mos7840_port = mos7840_get_port_private(port); 21380bca1b91SAlan Cox cnow = mos7840_port->icount; 21390bca1b91SAlan Cox 21400bca1b91SAlan Cox smp_rmb(); 21410bca1b91SAlan Cox icount->cts = cnow.cts; 21420bca1b91SAlan Cox icount->dsr = cnow.dsr; 21430bca1b91SAlan Cox icount->rng = cnow.rng; 21440bca1b91SAlan Cox icount->dcd = cnow.dcd; 21450bca1b91SAlan Cox icount->rx = cnow.rx; 21460bca1b91SAlan Cox icount->tx = cnow.tx; 21470bca1b91SAlan Cox icount->frame = cnow.frame; 21480bca1b91SAlan Cox icount->overrun = cnow.overrun; 21490bca1b91SAlan Cox icount->parity = cnow.parity; 21500bca1b91SAlan Cox icount->brk = cnow.brk; 21510bca1b91SAlan Cox icount->buf_overrun = cnow.buf_overrun; 21520bca1b91SAlan Cox 21539c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s TIOCGICOUNT RX=%d, TX=%d\n", __func__, 21549c134a14SGreg Kroah-Hartman icount->rx, icount->tx); 21550bca1b91SAlan Cox return 0; 21560bca1b91SAlan Cox } 21570bca1b91SAlan Cox 21583f542974SPaul B Schroeder /***************************************************************************** 21593f542974SPaul B Schroeder * SerialIoctl 21603f542974SPaul B Schroeder * this function handles any ioctl calls to the driver 21613f542974SPaul B Schroeder *****************************************************************************/ 21623f542974SPaul B Schroeder 216300a0d0d6SAlan Cox static int mos7840_ioctl(struct tty_struct *tty, 21643f542974SPaul B Schroeder unsigned int cmd, unsigned long arg) 21653f542974SPaul B Schroeder { 216695da310eSAlan Cox struct usb_serial_port *port = tty->driver_data; 216797c4965dSAl Viro void __user *argp = (void __user *)arg; 21683f542974SPaul B Schroeder struct moschip_port *mos7840_port; 21693f542974SPaul B Schroeder 21703f542974SPaul B Schroeder struct async_icount cnow; 21713f542974SPaul B Schroeder struct async_icount cprev; 21723f542974SPaul B Schroeder 21739c134a14SGreg Kroah-Hartman if (mos7840_port_paranoia_check(port, __func__)) 21743f542974SPaul B Schroeder return -1; 21753f542974SPaul B Schroeder 21763f542974SPaul B Schroeder mos7840_port = mos7840_get_port_private(port); 21773f542974SPaul B Schroeder 21783f542974SPaul B Schroeder if (mos7840_port == NULL) 21793f542974SPaul B Schroeder return -1; 21803f542974SPaul B Schroeder 21819c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s - cmd = 0x%x\n", __func__, cmd); 21823f542974SPaul B Schroeder 21833f542974SPaul B Schroeder switch (cmd) { 21843f542974SPaul B Schroeder /* return number of bytes available */ 21853f542974SPaul B Schroeder 21863f542974SPaul B Schroeder case TIOCSERGETLSR: 21879c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s TIOCSERGETLSR\n", __func__); 218895da310eSAlan Cox return mos7840_get_lsr_info(tty, argp); 21893f542974SPaul B Schroeder 21903f542974SPaul B Schroeder case TIOCGSERIAL: 21919c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s TIOCGSERIAL\n", __func__); 219297c4965dSAl Viro return mos7840_get_serial_info(mos7840_port, argp); 21933f542974SPaul B Schroeder 21943f542974SPaul B Schroeder case TIOCSSERIAL: 21959c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s TIOCSSERIAL\n", __func__); 21963f542974SPaul B Schroeder break; 21973f542974SPaul B Schroeder 21983f542974SPaul B Schroeder case TIOCMIWAIT: 21999c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s TIOCMIWAIT\n", __func__); 22003f542974SPaul B Schroeder cprev = mos7840_port->icount; 22013f542974SPaul B Schroeder while (1) { 2202880af9dbSAlan Cox /* interruptible_sleep_on(&mos7840_port->delta_msr_wait); */ 22033f542974SPaul B Schroeder mos7840_port->delta_msr_cond = 0; 2204a14430dbSJohan Hovold wait_event_interruptible(port->delta_msr_wait, 2205a14430dbSJohan Hovold (port->serial->disconnected || 2206a14430dbSJohan Hovold mos7840_port-> 22073f542974SPaul B Schroeder delta_msr_cond == 1)); 22083f542974SPaul B Schroeder 22093f542974SPaul B Schroeder /* see if a signal did it */ 22103f542974SPaul B Schroeder if (signal_pending(current)) 22113f542974SPaul B Schroeder return -ERESTARTSYS; 2212a14430dbSJohan Hovold 2213a14430dbSJohan Hovold if (port->serial->disconnected) 2214a14430dbSJohan Hovold return -EIO; 2215a14430dbSJohan Hovold 22163f542974SPaul B Schroeder cnow = mos7840_port->icount; 22170de9a702SOliver Neukum smp_rmb(); 22183f542974SPaul B Schroeder if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr && 22193f542974SPaul B Schroeder cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) 22203f542974SPaul B Schroeder return -EIO; /* no change => error */ 22213f542974SPaul B Schroeder if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) || 22223f542974SPaul B Schroeder ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) || 22233f542974SPaul B Schroeder ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) || 22243f542974SPaul B Schroeder ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) { 22253f542974SPaul B Schroeder return 0; 22263f542974SPaul B Schroeder } 22273f542974SPaul B Schroeder cprev = cnow; 22283f542974SPaul B Schroeder } 22293f542974SPaul B Schroeder /* NOTREACHED */ 22303f542974SPaul B Schroeder break; 22313f542974SPaul B Schroeder 22323f542974SPaul B Schroeder default: 22333f542974SPaul B Schroeder break; 22343f542974SPaul B Schroeder } 22353f542974SPaul B Schroeder return -ENOIOCTLCMD; 22363f542974SPaul B Schroeder } 22373f542974SPaul B Schroeder 22380eafe4deSDonald static int mos7810_check(struct usb_serial *serial) 22393f542974SPaul B Schroeder { 22400eafe4deSDonald int i, pass_count = 0; 22410eafe4deSDonald __u16 data = 0, mcr_data = 0; 22420eafe4deSDonald __u16 test_pattern = 0x55AA; 22433f542974SPaul B Schroeder 22440eafe4deSDonald /* Store MCR setting */ 22450eafe4deSDonald usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), 22460eafe4deSDonald MCS_RDREQ, MCS_RD_RTYPE, 0x0300, MODEM_CONTROL_REGISTER, 22470eafe4deSDonald &mcr_data, VENDOR_READ_LENGTH, MOS_WDR_TIMEOUT); 22480eafe4deSDonald 22490eafe4deSDonald for (i = 0; i < 16; i++) { 22500eafe4deSDonald /* Send the 1-bit test pattern out to MCS7810 test pin */ 22510eafe4deSDonald usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 22520eafe4deSDonald MCS_WRREQ, MCS_WR_RTYPE, 22530eafe4deSDonald (0x0300 | (((test_pattern >> i) & 0x0001) << 1)), 22540eafe4deSDonald MODEM_CONTROL_REGISTER, NULL, 0, MOS_WDR_TIMEOUT); 22550eafe4deSDonald 22560eafe4deSDonald /* Read the test pattern back */ 22570eafe4deSDonald usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), 22580eafe4deSDonald MCS_RDREQ, MCS_RD_RTYPE, 0, GPIO_REGISTER, &data, 2259093ea2d3SDonald Lee VENDOR_READ_LENGTH, MOS_WDR_TIMEOUT); 2260093ea2d3SDonald Lee 22610eafe4deSDonald /* If this is a MCS7810 device, both test patterns must match */ 22620eafe4deSDonald if (((test_pattern >> i) ^ (~data >> 1)) & 0x0001) 22630eafe4deSDonald break; 22640eafe4deSDonald 22650eafe4deSDonald pass_count++; 22663f542974SPaul B Schroeder } 2267093ea2d3SDonald Lee 22680eafe4deSDonald /* Restore MCR setting */ 22690eafe4deSDonald usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), MCS_WRREQ, 22700eafe4deSDonald MCS_WR_RTYPE, 0x0300 | mcr_data, MODEM_CONTROL_REGISTER, NULL, 22710eafe4deSDonald 0, MOS_WDR_TIMEOUT); 22720eafe4deSDonald 22730eafe4deSDonald if (pass_count == 16) 22740eafe4deSDonald return 1; 22750eafe4deSDonald 22760eafe4deSDonald return 0; 22770eafe4deSDonald } 22780eafe4deSDonald 22790eafe4deSDonald static int mos7840_calc_num_ports(struct usb_serial *serial) 22800eafe4deSDonald { 22810eafe4deSDonald __u16 data = 0x00; 22820eafe4deSDonald int mos7840_num_ports; 22830eafe4deSDonald 22840eafe4deSDonald usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), 22850eafe4deSDonald MCS_RDREQ, MCS_RD_RTYPE, 0, GPIO_REGISTER, &data, 22860eafe4deSDonald VENDOR_READ_LENGTH, MOS_WDR_TIMEOUT); 22870eafe4deSDonald 22880eafe4deSDonald if (serial->dev->descriptor.idProduct == MOSCHIP_DEVICE_ID_7810 || 22890eafe4deSDonald serial->dev->descriptor.idProduct == MOSCHIP_DEVICE_ID_7820) { 22900eafe4deSDonald device_type = serial->dev->descriptor.idProduct; 22910eafe4deSDonald } else { 22920eafe4deSDonald /* For a MCS7840 device GPIO0 must be set to 1 */ 22930eafe4deSDonald if ((data & 0x01) == 1) 22940eafe4deSDonald device_type = MOSCHIP_DEVICE_ID_7840; 22950eafe4deSDonald else if (mos7810_check(serial)) 22960eafe4deSDonald device_type = MOSCHIP_DEVICE_ID_7810; 22970eafe4deSDonald else 22980eafe4deSDonald device_type = MOSCHIP_DEVICE_ID_7820; 22990eafe4deSDonald } 23000eafe4deSDonald 23010eafe4deSDonald mos7840_num_ports = (device_type >> 4) & 0x000F; 23020eafe4deSDonald serial->num_bulk_in = mos7840_num_ports; 23030eafe4deSDonald serial->num_bulk_out = mos7840_num_ports; 23040eafe4deSDonald serial->num_ports = mos7840_num_ports; 23050eafe4deSDonald 23063f542974SPaul B Schroeder return mos7840_num_ports; 23073f542974SPaul B Schroeder } 23083f542974SPaul B Schroeder 230980c00750SJohan Hovold static int mos7840_port_probe(struct usb_serial_port *port) 23103f542974SPaul B Schroeder { 231180c00750SJohan Hovold struct usb_serial *serial = port->serial; 23123f542974SPaul B Schroeder struct moschip_port *mos7840_port; 231380c00750SJohan Hovold int status; 231480c00750SJohan Hovold int pnum; 23153f542974SPaul B Schroeder __u16 Data; 23163f542974SPaul B Schroeder 23173f542974SPaul B Schroeder /* we set up the pointers to the endpoints in the mos7840_open * 23183f542974SPaul B Schroeder * function, as the structures aren't created yet. */ 23193f542974SPaul B Schroeder 232080c00750SJohan Hovold pnum = port->number - serial->minor; 232180c00750SJohan Hovold 2322ae685effSJohan Hovold dev_dbg(&port->dev, "mos7840_startup: configuring port %d\n", pnum); 23237ac9da10SBurman Yan mos7840_port = kzalloc(sizeof(struct moschip_port), GFP_KERNEL); 23243f542974SPaul B Schroeder if (mos7840_port == NULL) { 232580c00750SJohan Hovold dev_err(&port->dev, "%s - Out of memory\n", __func__); 232680c00750SJohan Hovold return -ENOMEM; 23273f542974SPaul B Schroeder } 23283f542974SPaul B Schroeder 2329880af9dbSAlan Cox /* Initialize all port interrupt end point to port 0 int 2330880af9dbSAlan Cox * endpoint. Our device has only one interrupt end point 2331880af9dbSAlan Cox * common to all port */ 23323f542974SPaul B Schroeder 233380c00750SJohan Hovold mos7840_port->port = port; 233480c00750SJohan Hovold mos7840_set_port_private(port, mos7840_port); 23350de9a702SOliver Neukum spin_lock_init(&mos7840_port->pool_lock); 23363f542974SPaul B Schroeder 233737768adfSTony Cook /* minor is not initialised until later by 233837768adfSTony Cook * usb-serial.c:get_free_serial() and cannot therefore be used 233937768adfSTony Cook * to index device instances */ 234080c00750SJohan Hovold mos7840_port->port_num = pnum + 1; 234180c00750SJohan Hovold dev_dbg(&port->dev, "port->number = %d\n", port->number); 234280c00750SJohan Hovold dev_dbg(&port->dev, "port->serial->minor = %d\n", port->serial->minor); 234380c00750SJohan Hovold dev_dbg(&port->dev, "mos7840_port->port_num = %d\n", mos7840_port->port_num); 234480c00750SJohan Hovold dev_dbg(&port->dev, "serial->minor = %d\n", serial->minor); 23453f542974SPaul B Schroeder 23463f542974SPaul B Schroeder if (mos7840_port->port_num == 1) { 23473f542974SPaul B Schroeder mos7840_port->SpRegOffset = 0x0; 23483f542974SPaul B Schroeder mos7840_port->ControlRegOffset = 0x1; 23493f542974SPaul B Schroeder mos7840_port->DcrRegOffset = 0x4; 2350ae685effSJohan Hovold } else if ((mos7840_port->port_num == 2) && (serial->num_ports == 4)) { 23513f542974SPaul B Schroeder mos7840_port->SpRegOffset = 0x8; 23523f542974SPaul B Schroeder mos7840_port->ControlRegOffset = 0x9; 23533f542974SPaul B Schroeder mos7840_port->DcrRegOffset = 0x16; 2354ae685effSJohan Hovold } else if ((mos7840_port->port_num == 2) && (serial->num_ports == 2)) { 23553f542974SPaul B Schroeder mos7840_port->SpRegOffset = 0xa; 23563f542974SPaul B Schroeder mos7840_port->ControlRegOffset = 0xb; 23573f542974SPaul B Schroeder mos7840_port->DcrRegOffset = 0x19; 2358ae685effSJohan Hovold } else if ((mos7840_port->port_num == 3) && (serial->num_ports == 4)) { 23593f542974SPaul B Schroeder mos7840_port->SpRegOffset = 0xa; 23603f542974SPaul B Schroeder mos7840_port->ControlRegOffset = 0xb; 23613f542974SPaul B Schroeder mos7840_port->DcrRegOffset = 0x19; 2362ae685effSJohan Hovold } else if ((mos7840_port->port_num == 4) && (serial->num_ports == 4)) { 23633f542974SPaul B Schroeder mos7840_port->SpRegOffset = 0xc; 23643f542974SPaul B Schroeder mos7840_port->ControlRegOffset = 0xd; 23653f542974SPaul B Schroeder mos7840_port->DcrRegOffset = 0x1c; 23663f542974SPaul B Schroeder } 236780c00750SJohan Hovold mos7840_dump_serial_port(port, mos7840_port); 236880c00750SJohan Hovold mos7840_set_port_private(port, mos7840_port); 23693f542974SPaul B Schroeder 2370880af9dbSAlan Cox /* enable rx_disable bit in control register */ 237180c00750SJohan Hovold status = mos7840_get_reg_sync(port, 23723f542974SPaul B Schroeder mos7840_port->ControlRegOffset, &Data); 23733f542974SPaul B Schroeder if (status < 0) { 237480c00750SJohan Hovold dev_dbg(&port->dev, "Reading ControlReg failed status-0x%x\n", status); 2375ae685effSJohan Hovold goto out; 23763f542974SPaul B Schroeder } else 237780c00750SJohan Hovold dev_dbg(&port->dev, "ControlReg Reading success val is %x, status%d\n", Data, status); 2378880af9dbSAlan Cox Data |= 0x08; /* setting driver done bit */ 2379880af9dbSAlan Cox Data |= 0x04; /* sp1_bit to have cts change reflect in 2380880af9dbSAlan Cox modem status reg */ 23813f542974SPaul B Schroeder 2382880af9dbSAlan Cox /* Data |= 0x20; //rx_disable bit */ 238380c00750SJohan Hovold status = mos7840_set_reg_sync(port, 23843f542974SPaul B Schroeder mos7840_port->ControlRegOffset, Data); 23853f542974SPaul B Schroeder if (status < 0) { 238680c00750SJohan Hovold dev_dbg(&port->dev, "Writing ControlReg failed(rx_disable) status-0x%x\n", status); 2387ae685effSJohan Hovold goto out; 23883f542974SPaul B Schroeder } else 238980c00750SJohan Hovold dev_dbg(&port->dev, "ControlReg Writing success(rx_disable) status%d\n", status); 23903f542974SPaul B Schroeder 2391880af9dbSAlan Cox /* Write default values in DCR (i.e 0x01 in DCR0, 0x05 in DCR2 2392880af9dbSAlan Cox and 0x24 in DCR3 */ 23933f542974SPaul B Schroeder Data = 0x01; 239480c00750SJohan Hovold status = mos7840_set_reg_sync(port, 2395880af9dbSAlan Cox (__u16) (mos7840_port->DcrRegOffset + 0), Data); 23963f542974SPaul B Schroeder if (status < 0) { 239780c00750SJohan Hovold dev_dbg(&port->dev, "Writing DCR0 failed status-0x%x\n", status); 2398ae685effSJohan Hovold goto out; 23993f542974SPaul B Schroeder } else 240080c00750SJohan Hovold dev_dbg(&port->dev, "DCR0 Writing success status%d\n", status); 24013f542974SPaul B Schroeder 24023f542974SPaul B Schroeder Data = 0x05; 240380c00750SJohan Hovold status = mos7840_set_reg_sync(port, 2404880af9dbSAlan Cox (__u16) (mos7840_port->DcrRegOffset + 1), Data); 24053f542974SPaul B Schroeder if (status < 0) { 240680c00750SJohan Hovold dev_dbg(&port->dev, "Writing DCR1 failed status-0x%x\n", status); 2407ae685effSJohan Hovold goto out; 24083f542974SPaul B Schroeder } else 240980c00750SJohan Hovold dev_dbg(&port->dev, "DCR1 Writing success status%d\n", status); 24103f542974SPaul B Schroeder 24113f542974SPaul B Schroeder Data = 0x24; 241280c00750SJohan Hovold status = mos7840_set_reg_sync(port, 2413880af9dbSAlan Cox (__u16) (mos7840_port->DcrRegOffset + 2), Data); 24143f542974SPaul B Schroeder if (status < 0) { 241580c00750SJohan Hovold dev_dbg(&port->dev, "Writing DCR2 failed status-0x%x\n", status); 2416ae685effSJohan Hovold goto out; 24173f542974SPaul B Schroeder } else 241880c00750SJohan Hovold dev_dbg(&port->dev, "DCR2 Writing success status%d\n", status); 24193f542974SPaul B Schroeder 2420880af9dbSAlan Cox /* write values in clkstart0x0 and clkmulti 0x20 */ 24213f542974SPaul B Schroeder Data = 0x0; 2422ae685effSJohan Hovold status = mos7840_set_reg_sync(port, CLK_START_VALUE_REGISTER, Data); 24233f542974SPaul B Schroeder if (status < 0) { 242480c00750SJohan Hovold dev_dbg(&port->dev, "Writing CLK_START_VALUE_REGISTER failed status-0x%x\n", status); 2425ae685effSJohan Hovold goto out; 24263f542974SPaul B Schroeder } else 242780c00750SJohan Hovold dev_dbg(&port->dev, "CLK_START_VALUE_REGISTER Writing success status%d\n", status); 24283f542974SPaul B Schroeder 24293f542974SPaul B Schroeder Data = 0x20; 2430ae685effSJohan Hovold status = mos7840_set_reg_sync(port, CLK_MULTI_REGISTER, Data); 24313f542974SPaul B Schroeder if (status < 0) { 243280c00750SJohan Hovold dev_dbg(&port->dev, "Writing CLK_MULTI_REGISTER failed status-0x%x\n", status); 24330de9a702SOliver Neukum goto error; 24343f542974SPaul B Schroeder } else 243580c00750SJohan Hovold dev_dbg(&port->dev, "CLK_MULTI_REGISTER Writing success status%d\n", status); 24363f542974SPaul B Schroeder 2437880af9dbSAlan Cox /* write value 0x0 to scratchpad register */ 24383f542974SPaul B Schroeder Data = 0x00; 2439ae685effSJohan Hovold status = mos7840_set_uart_reg(port, SCRATCH_PAD_REGISTER, Data); 24403f542974SPaul B Schroeder if (status < 0) { 244180c00750SJohan Hovold dev_dbg(&port->dev, "Writing SCRATCH_PAD_REGISTER failed status-0x%x\n", status); 2442ae685effSJohan Hovold goto out; 24433f542974SPaul B Schroeder } else 244480c00750SJohan Hovold dev_dbg(&port->dev, "SCRATCH_PAD_REGISTER Writing success status%d\n", status); 24453f542974SPaul B Schroeder 2446880af9dbSAlan Cox /* Zero Length flag register */ 2447ae685effSJohan Hovold if ((mos7840_port->port_num != 1) && (serial->num_ports == 2)) { 24483f542974SPaul B Schroeder Data = 0xff; 244980c00750SJohan Hovold status = mos7840_set_reg_sync(port, 24503f542974SPaul B Schroeder (__u16) (ZLP_REG1 + 2451880af9dbSAlan Cox ((__u16)mos7840_port->port_num)), Data); 245280c00750SJohan Hovold dev_dbg(&port->dev, "ZLIP offset %x\n", 24539c134a14SGreg Kroah-Hartman (__u16)(ZLP_REG1 + ((__u16) mos7840_port->port_num))); 24543f542974SPaul B Schroeder if (status < 0) { 245580c00750SJohan Hovold dev_dbg(&port->dev, "Writing ZLP_REG%d failed status-0x%x\n", pnum + 2, status); 2456ae685effSJohan Hovold goto out; 24573f542974SPaul B Schroeder } else 245880c00750SJohan Hovold dev_dbg(&port->dev, "ZLP_REG%d Writing success status%d\n", pnum + 2, status); 24593f542974SPaul B Schroeder } else { 24603f542974SPaul B Schroeder Data = 0xff; 246180c00750SJohan Hovold status = mos7840_set_reg_sync(port, 24623f542974SPaul B Schroeder (__u16) (ZLP_REG1 + 2463880af9dbSAlan Cox ((__u16)mos7840_port->port_num) - 0x1), Data); 246480c00750SJohan Hovold dev_dbg(&port->dev, "ZLIP offset %x\n", 24659c134a14SGreg Kroah-Hartman (__u16)(ZLP_REG1 + ((__u16) mos7840_port->port_num) - 0x1)); 24663f542974SPaul B Schroeder if (status < 0) { 246780c00750SJohan Hovold dev_dbg(&port->dev, "Writing ZLP_REG%d failed status-0x%x\n", pnum + 1, status); 2468ae685effSJohan Hovold goto out; 24693f542974SPaul B Schroeder } else 247080c00750SJohan Hovold dev_dbg(&port->dev, "ZLP_REG%d Writing success status%d\n", pnum + 1, status); 24713f542974SPaul B Schroeder 24723f542974SPaul B Schroeder } 24730de9a702SOliver Neukum mos7840_port->control_urb = usb_alloc_urb(0, GFP_KERNEL); 24743f542974SPaul B Schroeder mos7840_port->ctrl_buf = kmalloc(16, GFP_KERNEL); 2475880af9dbSAlan Cox mos7840_port->dr = kmalloc(sizeof(struct usb_ctrlrequest), 2476880af9dbSAlan Cox GFP_KERNEL); 2477880af9dbSAlan Cox if (!mos7840_port->control_urb || !mos7840_port->ctrl_buf || 2478880af9dbSAlan Cox !mos7840_port->dr) { 24790de9a702SOliver Neukum status = -ENOMEM; 24800de9a702SOliver Neukum goto error; 24810de9a702SOliver Neukum } 24820eafe4deSDonald 24830eafe4deSDonald mos7840_port->has_led = false; 24840eafe4deSDonald 24850eafe4deSDonald /* Initialize LED timers */ 24860eafe4deSDonald if (device_type == MOSCHIP_DEVICE_ID_7810) { 24870eafe4deSDonald mos7840_port->has_led = true; 24880eafe4deSDonald 24890eafe4deSDonald init_timer(&mos7840_port->led_timer1); 24900eafe4deSDonald mos7840_port->led_timer1.function = mos7840_led_off; 24910eafe4deSDonald mos7840_port->led_timer1.expires = 24920eafe4deSDonald jiffies + msecs_to_jiffies(LED_ON_MS); 2493ae685effSJohan Hovold mos7840_port->led_timer1.data = (unsigned long)mos7840_port; 24940eafe4deSDonald 24950eafe4deSDonald init_timer(&mos7840_port->led_timer2); 2496ae685effSJohan Hovold mos7840_port->led_timer2.function = mos7840_led_flag_off; 24970eafe4deSDonald mos7840_port->led_timer2.expires = 24980eafe4deSDonald jiffies + msecs_to_jiffies(LED_OFF_MS); 2499ae685effSJohan Hovold mos7840_port->led_timer2.data = (unsigned long)mos7840_port; 25000eafe4deSDonald 25010eafe4deSDonald mos7840_port->led_flag = false; 25020eafe4deSDonald 25030eafe4deSDonald /* Turn off LED */ 2504ae685effSJohan Hovold mos7840_set_led_sync(port, MODEM_CONTROL_REGISTER, 0x0300); 25050eafe4deSDonald } 2506ae685effSJohan Hovold out: 250780c00750SJohan Hovold if (pnum == serial->num_ports - 1) { 2508880af9dbSAlan Cox /* Zero Length flag enable */ 25093f542974SPaul B Schroeder Data = 0x0f; 25103f542974SPaul B Schroeder status = mos7840_set_reg_sync(serial->port[0], ZLP_REG5, Data); 25113f542974SPaul B Schroeder if (status < 0) { 251280c00750SJohan Hovold dev_dbg(&port->dev, "Writing ZLP_REG5 failed status-0x%x\n", status); 25137ced46c3SRoel Kluin goto error; 25143f542974SPaul B Schroeder } else 251580c00750SJohan Hovold dev_dbg(&port->dev, "ZLP_REG5 Writing success status%d\n", status); 25163f542974SPaul B Schroeder 25173f542974SPaul B Schroeder /* setting configuration feature to one */ 25183f542974SPaul B Schroeder usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 251980c00750SJohan Hovold 0x03, 0x00, 0x01, 0x00, NULL, 0x00, 252080c00750SJohan Hovold MOS_WDR_TIMEOUT); 252180c00750SJohan Hovold } 25223f542974SPaul B Schroeder return 0; 25230de9a702SOliver Neukum error: 25240de9a702SOliver Neukum kfree(mos7840_port->dr); 25250de9a702SOliver Neukum kfree(mos7840_port->ctrl_buf); 25260de9a702SOliver Neukum usb_free_urb(mos7840_port->control_urb); 25270de9a702SOliver Neukum kfree(mos7840_port); 252880c00750SJohan Hovold 25290de9a702SOliver Neukum return status; 25303f542974SPaul B Schroeder } 25313f542974SPaul B Schroeder 253280c00750SJohan Hovold static int mos7840_port_remove(struct usb_serial_port *port) 25333f542974SPaul B Schroeder { 25343f542974SPaul B Schroeder struct moschip_port *mos7840_port; 25353f542974SPaul B Schroeder 253680c00750SJohan Hovold mos7840_port = mos7840_get_port_private(port); 25373f542974SPaul B Schroeder 25380eafe4deSDonald if (mos7840_port->has_led) { 25390eafe4deSDonald /* Turn off LED */ 254080c00750SJohan Hovold mos7840_set_led_sync(port, MODEM_CONTROL_REGISTER, 0x0300); 25410eafe4deSDonald 25420eafe4deSDonald del_timer_sync(&mos7840_port->led_timer1); 25430eafe4deSDonald del_timer_sync(&mos7840_port->led_timer2); 25440eafe4deSDonald } 254580c00750SJohan Hovold usb_kill_urb(mos7840_port->control_urb); 254665a4cdbbSJohan Hovold usb_free_urb(mos7840_port->control_urb); 25470de9a702SOliver Neukum kfree(mos7840_port->ctrl_buf); 25480de9a702SOliver Neukum kfree(mos7840_port->dr); 25493f542974SPaul B Schroeder kfree(mos7840_port); 255080c00750SJohan Hovold 255180c00750SJohan Hovold return 0; 25523f542974SPaul B Schroeder } 25533f542974SPaul B Schroeder 25543f542974SPaul B Schroeder static struct usb_serial_driver moschip7840_4port_device = { 25553f542974SPaul B Schroeder .driver = { 25563f542974SPaul B Schroeder .owner = THIS_MODULE, 25573f542974SPaul B Schroeder .name = "mos7840", 25583f542974SPaul B Schroeder }, 25593f542974SPaul B Schroeder .description = DRIVER_DESC, 256068e24113SGreg Kroah-Hartman .id_table = id_table, 25613f542974SPaul B Schroeder .num_ports = 4, 25623f542974SPaul B Schroeder .open = mos7840_open, 25633f542974SPaul B Schroeder .close = mos7840_close, 25643f542974SPaul B Schroeder .write = mos7840_write, 25653f542974SPaul B Schroeder .write_room = mos7840_write_room, 25663f542974SPaul B Schroeder .chars_in_buffer = mos7840_chars_in_buffer, 25673f542974SPaul B Schroeder .throttle = mos7840_throttle, 25683f542974SPaul B Schroeder .unthrottle = mos7840_unthrottle, 25693f542974SPaul B Schroeder .calc_num_ports = mos7840_calc_num_ports, 25703f542974SPaul B Schroeder #ifdef MCSSerialProbe 25713f542974SPaul B Schroeder .probe = mos7840_serial_probe, 25723f542974SPaul B Schroeder #endif 25733f542974SPaul B Schroeder .ioctl = mos7840_ioctl, 25743f542974SPaul B Schroeder .set_termios = mos7840_set_termios, 25753f542974SPaul B Schroeder .break_ctl = mos7840_break, 25763f542974SPaul B Schroeder .tiocmget = mos7840_tiocmget, 25773f542974SPaul B Schroeder .tiocmset = mos7840_tiocmset, 25780bca1b91SAlan Cox .get_icount = mos7840_get_icount, 257980c00750SJohan Hovold .port_probe = mos7840_port_probe, 258080c00750SJohan Hovold .port_remove = mos7840_port_remove, 25813f542974SPaul B Schroeder .read_bulk_callback = mos7840_bulk_in_callback, 25823f542974SPaul B Schroeder .read_int_callback = mos7840_interrupt_callback, 25833f542974SPaul B Schroeder }; 25843f542974SPaul B Schroeder 25854d2a7affSAlan Stern static struct usb_serial_driver * const serial_drivers[] = { 25864d2a7affSAlan Stern &moschip7840_4port_device, NULL 25874d2a7affSAlan Stern }; 25884d2a7affSAlan Stern 258968e24113SGreg Kroah-Hartman module_usb_serial_driver(serial_drivers, id_table); 25903f542974SPaul B Schroeder 25913f542974SPaul B Schroeder MODULE_DESCRIPTION(DRIVER_DESC); 25923f542974SPaul B Schroeder MODULE_LICENSE("GPL"); 2593