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 186*d8a083ccSJohan Hovold enum mos7840_flag { 187*d8a083ccSJohan Hovold MOS7840_FLAG_CTRL_BUSY, 188*d8a083ccSJohan Hovold }; 189*d8a083ccSJohan Hovold 1900eafe4deSDonald static int device_type; 1913f542974SPaul B Schroeder 192b9c87663STony Zelenoff static const struct usb_device_id id_table[] = { 1933f542974SPaul B Schroeder {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7840)}, 1943f542974SPaul B Schroeder {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7820)}, 1950eafe4deSDonald {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7810)}, 196acf509aeSCliff Brake {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_2)}, 197870408c8SDave Ludlow {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_2P)}, 198acf509aeSCliff Brake {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_4)}, 199870408c8SDave Ludlow {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_4P)}, 200acf509aeSCliff Brake {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_US9ML2_2)}, 201acf509aeSCliff Brake {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_US9ML2_4)}, 202acf509aeSCliff Brake {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USPTL4_2)}, 203acf509aeSCliff Brake {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USPTL4_4)}, 20411e1abb4SDavid Ludlow {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_2)}, 205870408c8SDave Ludlow {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_2P)}, 206acf509aeSCliff Brake {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_4)}, 207870408c8SDave Ludlow {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_4P)}, 20827f1281dSBlaise Gassend {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL2_4)}, 209e9b8cffaSTony Cook {USB_DEVICE(USB_VENDOR_ID_ATENINTL, ATENINTL_DEVICE_ID_UC2324)}, 2109d498beaSRussell Lang {USB_DEVICE(USB_VENDOR_ID_ATENINTL, ATENINTL_DEVICE_ID_UC2322)}, 2113f542974SPaul B Schroeder {} /* terminating entry */ 2123f542974SPaul B Schroeder }; 21368e24113SGreg Kroah-Hartman MODULE_DEVICE_TABLE(usb, id_table); 2143f542974SPaul B Schroeder 2153f542974SPaul B Schroeder /* This structure holds all of the local port information */ 2163f542974SPaul B Schroeder 2173f542974SPaul B Schroeder struct moschip_port { 2183f542974SPaul B Schroeder int port_num; /*Actual port number in the device(1,2,etc) */ 2193f542974SPaul B Schroeder struct urb *write_urb; /* write URB for this port */ 2203f542974SPaul B Schroeder struct urb *read_urb; /* read URB for this port */ 2213f542974SPaul B Schroeder __u8 shadowLCR; /* last LCR value received */ 2223f542974SPaul B Schroeder __u8 shadowMCR; /* last MCR value received */ 2233f542974SPaul B Schroeder char open; 2240de9a702SOliver Neukum char open_ports; 2253f542974SPaul B Schroeder wait_queue_head_t wait_chase; /* for handling sleeping while waiting for chase to finish */ 2263f542974SPaul B Schroeder struct usb_serial_port *port; /* loop back to the owner of this object */ 2273f542974SPaul B Schroeder 2283f542974SPaul B Schroeder /* Offsets */ 2293f542974SPaul B Schroeder __u8 SpRegOffset; 2303f542974SPaul B Schroeder __u8 ControlRegOffset; 2313f542974SPaul B Schroeder __u8 DcrRegOffset; 232880af9dbSAlan Cox /* for processing control URBS in interrupt context */ 2333f542974SPaul B Schroeder struct urb *control_urb; 2340de9a702SOliver Neukum struct usb_ctrlrequest *dr; 2353f542974SPaul B Schroeder char *ctrl_buf; 2363f542974SPaul B Schroeder int MsrLsr; 2373f542974SPaul B Schroeder 2380de9a702SOliver Neukum spinlock_t pool_lock; 2393f542974SPaul B Schroeder struct urb *write_urb_pool[NUM_URBS]; 2400de9a702SOliver Neukum char busy[NUM_URBS]; 24150de36f7SGreg Kroah-Hartman bool read_urb_busy; 2423f542974SPaul B Schroeder 2430eafe4deSDonald /* For device(s) with LED indicator */ 2440eafe4deSDonald bool has_led; 2450eafe4deSDonald bool led_flag; 2460eafe4deSDonald struct timer_list led_timer1; /* Timer for LED on */ 2470eafe4deSDonald struct timer_list led_timer2; /* Timer for LED off */ 248*d8a083ccSJohan Hovold 249*d8a083ccSJohan Hovold unsigned long flags; 2500eafe4deSDonald }; 2513f542974SPaul B Schroeder 2523f542974SPaul B Schroeder /* 2533f542974SPaul B Schroeder * mos7840_set_reg_sync 2543f542974SPaul B Schroeder * To set the Control register by calling usb_fill_control_urb function 2553f542974SPaul B Schroeder * by passing usb_sndctrlpipe function as parameter. 2563f542974SPaul B Schroeder */ 2573f542974SPaul B Schroeder 2583f542974SPaul B Schroeder static int mos7840_set_reg_sync(struct usb_serial_port *port, __u16 reg, 2593f542974SPaul B Schroeder __u16 val) 2603f542974SPaul B Schroeder { 2613f542974SPaul B Schroeder struct usb_device *dev = port->serial->dev; 2623f542974SPaul B Schroeder val = val & 0x00ff; 2639c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "mos7840_set_reg_sync offset is %x, value %x\n", reg, val); 2643f542974SPaul B Schroeder 2653f542974SPaul B Schroeder return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), MCS_WRREQ, 2663f542974SPaul B Schroeder MCS_WR_RTYPE, val, reg, NULL, 0, 2673f542974SPaul B Schroeder MOS_WDR_TIMEOUT); 2683f542974SPaul B Schroeder } 2693f542974SPaul B Schroeder 2703f542974SPaul B Schroeder /* 2713f542974SPaul B Schroeder * mos7840_get_reg_sync 2723f542974SPaul B Schroeder * To set the Uart register by calling usb_fill_control_urb function by 2733f542974SPaul B Schroeder * passing usb_rcvctrlpipe function as parameter. 2743f542974SPaul B Schroeder */ 2753f542974SPaul B Schroeder 2763f542974SPaul B Schroeder static int mos7840_get_reg_sync(struct usb_serial_port *port, __u16 reg, 2773f542974SPaul B Schroeder __u16 *val) 2783f542974SPaul B Schroeder { 2793f542974SPaul B Schroeder struct usb_device *dev = port->serial->dev; 2803f542974SPaul B Schroeder int ret = 0; 2819e221a35SJohan Hovold u8 *buf; 2829e221a35SJohan Hovold 2839e221a35SJohan Hovold buf = kmalloc(VENDOR_READ_LENGTH, GFP_KERNEL); 2849e221a35SJohan Hovold if (!buf) 2859e221a35SJohan Hovold return -ENOMEM; 2863f542974SPaul B Schroeder 2873f542974SPaul B Schroeder ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), MCS_RDREQ, 2889e221a35SJohan Hovold MCS_RD_RTYPE, 0, reg, buf, VENDOR_READ_LENGTH, 2893f542974SPaul B Schroeder MOS_WDR_TIMEOUT); 2909e221a35SJohan Hovold *val = buf[0]; 2919c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s offset is %x, return val %x\n", __func__, reg, *val); 2929e221a35SJohan Hovold 2939e221a35SJohan Hovold kfree(buf); 2943f542974SPaul B Schroeder return ret; 2953f542974SPaul B Schroeder } 2963f542974SPaul B Schroeder 2973f542974SPaul B Schroeder /* 2983f542974SPaul B Schroeder * mos7840_set_uart_reg 2993f542974SPaul B Schroeder * To set the Uart register by calling usb_fill_control_urb function by 3003f542974SPaul B Schroeder * passing usb_sndctrlpipe function as parameter. 3013f542974SPaul B Schroeder */ 3023f542974SPaul B Schroeder 3033f542974SPaul B Schroeder static int mos7840_set_uart_reg(struct usb_serial_port *port, __u16 reg, 3043f542974SPaul B Schroeder __u16 val) 3053f542974SPaul B Schroeder { 3063f542974SPaul B Schroeder 3073f542974SPaul B Schroeder struct usb_device *dev = port->serial->dev; 3083f542974SPaul B Schroeder val = val & 0x00ff; 309880af9dbSAlan Cox /* For the UART control registers, the application number need 310880af9dbSAlan Cox to be Or'ed */ 3110de9a702SOliver Neukum if (port->serial->num_ports == 4) { 3121143832eSGreg Kroah-Hartman val |= ((__u16)port->port_number + 1) << 8; 3133f542974SPaul B Schroeder } else { 3141143832eSGreg Kroah-Hartman if (port->port_number == 0) { 3151143832eSGreg Kroah-Hartman val |= ((__u16)port->port_number + 1) << 8; 3163f542974SPaul B Schroeder } else { 3171143832eSGreg Kroah-Hartman val |= ((__u16)port->port_number + 2) << 8; 3183f542974SPaul B Schroeder } 3193f542974SPaul B Schroeder } 3209c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s application number is %x\n", __func__, val); 3213f542974SPaul B Schroeder return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), MCS_WRREQ, 3223f542974SPaul B Schroeder MCS_WR_RTYPE, val, reg, NULL, 0, 3233f542974SPaul B Schroeder MOS_WDR_TIMEOUT); 3243f542974SPaul B Schroeder 3253f542974SPaul B Schroeder } 3263f542974SPaul B Schroeder 3273f542974SPaul B Schroeder /* 3283f542974SPaul B Schroeder * mos7840_get_uart_reg 3293f542974SPaul B Schroeder * To set the Control register by calling usb_fill_control_urb function 3303f542974SPaul B Schroeder * by passing usb_rcvctrlpipe function as parameter. 3313f542974SPaul B Schroeder */ 3323f542974SPaul B Schroeder static int mos7840_get_uart_reg(struct usb_serial_port *port, __u16 reg, 3333f542974SPaul B Schroeder __u16 *val) 3343f542974SPaul B Schroeder { 3353f542974SPaul B Schroeder struct usb_device *dev = port->serial->dev; 3363f542974SPaul B Schroeder int ret = 0; 3373f542974SPaul B Schroeder __u16 Wval; 3389e221a35SJohan Hovold u8 *buf; 3399e221a35SJohan Hovold 3409e221a35SJohan Hovold buf = kmalloc(VENDOR_READ_LENGTH, GFP_KERNEL); 3419e221a35SJohan Hovold if (!buf) 3429e221a35SJohan Hovold return -ENOMEM; 3433f542974SPaul B Schroeder 3443f542974SPaul B Schroeder /* Wval is same as application number */ 3450de9a702SOliver Neukum if (port->serial->num_ports == 4) { 3461143832eSGreg Kroah-Hartman Wval = ((__u16)port->port_number + 1) << 8; 3473f542974SPaul B Schroeder } else { 3481143832eSGreg Kroah-Hartman if (port->port_number == 0) { 3491143832eSGreg Kroah-Hartman Wval = ((__u16)port->port_number + 1) << 8; 3503f542974SPaul B Schroeder } else { 3511143832eSGreg Kroah-Hartman Wval = ((__u16)port->port_number + 2) << 8; 3523f542974SPaul B Schroeder } 3533f542974SPaul B Schroeder } 3549c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s application number is %x\n", __func__, Wval); 3553f542974SPaul B Schroeder ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), MCS_RDREQ, 3569e221a35SJohan Hovold MCS_RD_RTYPE, Wval, reg, buf, VENDOR_READ_LENGTH, 3573f542974SPaul B Schroeder MOS_WDR_TIMEOUT); 3589e221a35SJohan Hovold *val = buf[0]; 3599e221a35SJohan Hovold 3609e221a35SJohan Hovold kfree(buf); 3613f542974SPaul B Schroeder return ret; 3623f542974SPaul B Schroeder } 3633f542974SPaul B Schroeder 3649c134a14SGreg Kroah-Hartman static void mos7840_dump_serial_port(struct usb_serial_port *port, 3659c134a14SGreg Kroah-Hartman struct moschip_port *mos7840_port) 3663f542974SPaul B Schroeder { 3673f542974SPaul B Schroeder 3689c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "SpRegOffset is %2x\n", mos7840_port->SpRegOffset); 3699c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "ControlRegOffset is %2x\n", mos7840_port->ControlRegOffset); 3709c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "DCRRegOffset is %2x\n", mos7840_port->DcrRegOffset); 3713f542974SPaul B Schroeder 3723f542974SPaul B Schroeder } 3733f542974SPaul B Schroeder 3743f542974SPaul B Schroeder /************************************************************************/ 3753f542974SPaul B Schroeder /************************************************************************/ 3763f542974SPaul B Schroeder /* I N T E R F A C E F U N C T I O N S */ 3773f542974SPaul B Schroeder /* I N T E R F A C E F U N C T I O N S */ 3783f542974SPaul B Schroeder /************************************************************************/ 3793f542974SPaul B Schroeder /************************************************************************/ 3803f542974SPaul B Schroeder 3813f542974SPaul B Schroeder static inline void mos7840_set_port_private(struct usb_serial_port *port, 3823f542974SPaul B Schroeder struct moschip_port *data) 3833f542974SPaul B Schroeder { 3843f542974SPaul B Schroeder usb_set_serial_port_data(port, (void *)data); 3853f542974SPaul B Schroeder } 3863f542974SPaul B Schroeder 3873f542974SPaul B Schroeder static inline struct moschip_port *mos7840_get_port_private(struct 3883f542974SPaul B Schroeder usb_serial_port 3893f542974SPaul B Schroeder *port) 3903f542974SPaul B Schroeder { 3913f542974SPaul B Schroeder return (struct moschip_port *)usb_get_serial_port_data(port); 3923f542974SPaul B Schroeder } 3933f542974SPaul B Schroeder 3940de9a702SOliver Neukum static void mos7840_handle_new_msr(struct moschip_port *port, __u8 new_msr) 3953f542974SPaul B Schroeder { 3963f542974SPaul B Schroeder struct moschip_port *mos7840_port; 3973f542974SPaul B Schroeder struct async_icount *icount; 3983f542974SPaul B Schroeder mos7840_port = port; 3993f542974SPaul B Schroeder if (new_msr & 4003f542974SPaul B Schroeder (MOS_MSR_DELTA_CTS | MOS_MSR_DELTA_DSR | MOS_MSR_DELTA_RI | 4013f542974SPaul B Schroeder MOS_MSR_DELTA_CD)) { 4028c1a07ffSJohan Hovold icount = &mos7840_port->port->icount; 4033f542974SPaul B Schroeder 4043f542974SPaul B Schroeder /* update input line counters */ 405c9fac853SJohan Hovold if (new_msr & MOS_MSR_DELTA_CTS) 4063f542974SPaul B Schroeder icount->cts++; 407c9fac853SJohan Hovold if (new_msr & MOS_MSR_DELTA_DSR) 4083f542974SPaul B Schroeder icount->dsr++; 409c9fac853SJohan Hovold if (new_msr & MOS_MSR_DELTA_CD) 4103f542974SPaul B Schroeder icount->dcd++; 411c9fac853SJohan Hovold if (new_msr & MOS_MSR_DELTA_RI) 4123f542974SPaul B Schroeder icount->rng++; 413e670c6afSJohan Hovold 4140c613371SJohan Hovold wake_up_interruptible(&port->port->port.delta_msr_wait); 4153f542974SPaul B Schroeder } 4163f542974SPaul B Schroeder } 4173f542974SPaul B Schroeder 4180de9a702SOliver Neukum static void mos7840_handle_new_lsr(struct moschip_port *port, __u8 new_lsr) 4193f542974SPaul B Schroeder { 4203f542974SPaul B Schroeder struct async_icount *icount; 4213f542974SPaul B Schroeder 4223f542974SPaul B Schroeder if (new_lsr & SERIAL_LSR_BI) { 423880af9dbSAlan Cox /* 424880af9dbSAlan Cox * Parity and Framing errors only count if they 425880af9dbSAlan Cox * occur exclusive of a break being 426880af9dbSAlan Cox * received. 427880af9dbSAlan Cox */ 4283f542974SPaul B Schroeder new_lsr &= (__u8) (SERIAL_LSR_OE | SERIAL_LSR_BI); 4293f542974SPaul B Schroeder } 4303f542974SPaul B Schroeder 4313f542974SPaul B Schroeder /* update input line counters */ 4328c1a07ffSJohan Hovold icount = &port->port->icount; 433c9fac853SJohan Hovold if (new_lsr & SERIAL_LSR_BI) 4343f542974SPaul B Schroeder icount->brk++; 435c9fac853SJohan Hovold if (new_lsr & SERIAL_LSR_OE) 4363f542974SPaul B Schroeder icount->overrun++; 437c9fac853SJohan Hovold if (new_lsr & SERIAL_LSR_PE) 4383f542974SPaul B Schroeder icount->parity++; 439c9fac853SJohan Hovold if (new_lsr & SERIAL_LSR_FE) 4403f542974SPaul B Schroeder icount->frame++; 4413f542974SPaul B Schroeder } 4423f542974SPaul B Schroeder 4433f542974SPaul B Schroeder /************************************************************************/ 4443f542974SPaul B Schroeder /************************************************************************/ 4453f542974SPaul B Schroeder /* U S B C A L L B A C K F U N C T I O N S */ 4463f542974SPaul B Schroeder /* U S B C A L L B A C K F U N C T I O N S */ 4473f542974SPaul B Schroeder /************************************************************************/ 4483f542974SPaul B Schroeder /************************************************************************/ 4493f542974SPaul B Schroeder 4507d12e780SDavid Howells static void mos7840_control_callback(struct urb *urb) 4513f542974SPaul B Schroeder { 4523f542974SPaul B Schroeder unsigned char *data; 4533f542974SPaul B Schroeder struct moschip_port *mos7840_port; 4549c134a14SGreg Kroah-Hartman struct device *dev = &urb->dev->dev; 4553f542974SPaul B Schroeder __u8 regval = 0x0; 4560643c724SGreg Kroah-Hartman int status = urb->status; 4573f542974SPaul B Schroeder 458cdc97792SMing Lei mos7840_port = urb->context; 4590de9a702SOliver Neukum 4600643c724SGreg Kroah-Hartman switch (status) { 4613f542974SPaul B Schroeder case 0: 4623f542974SPaul B Schroeder /* success */ 4633f542974SPaul B Schroeder break; 4643f542974SPaul B Schroeder case -ECONNRESET: 4653f542974SPaul B Schroeder case -ENOENT: 4663f542974SPaul B Schroeder case -ESHUTDOWN: 4673f542974SPaul B Schroeder /* this urb is terminated, clean up */ 4689c134a14SGreg Kroah-Hartman dev_dbg(dev, "%s - urb shutting down with status: %d\n", __func__, status); 469*d8a083ccSJohan Hovold goto out; 4703f542974SPaul B Schroeder default: 4719c134a14SGreg Kroah-Hartman dev_dbg(dev, "%s - nonzero urb status received: %d\n", __func__, status); 472*d8a083ccSJohan Hovold goto out; 4733f542974SPaul B Schroeder } 4743f542974SPaul B Schroeder 4759c134a14SGreg Kroah-Hartman dev_dbg(dev, "%s urb buffer size is %d\n", __func__, urb->actual_length); 4769c134a14SGreg Kroah-Hartman dev_dbg(dev, "%s mos7840_port->MsrLsr is %d port %d\n", __func__, 4773f542974SPaul B Schroeder mos7840_port->MsrLsr, mos7840_port->port_num); 4783f542974SPaul B Schroeder data = urb->transfer_buffer; 4793f542974SPaul B Schroeder regval = (__u8) data[0]; 4809c134a14SGreg Kroah-Hartman dev_dbg(dev, "%s data is %x\n", __func__, regval); 4813f542974SPaul B Schroeder if (mos7840_port->MsrLsr == 0) 4823f542974SPaul B Schroeder mos7840_handle_new_msr(mos7840_port, regval); 4833f542974SPaul B Schroeder else if (mos7840_port->MsrLsr == 1) 4843f542974SPaul B Schroeder mos7840_handle_new_lsr(mos7840_port, regval); 485*d8a083ccSJohan Hovold out: 486*d8a083ccSJohan Hovold clear_bit_unlock(MOS7840_FLAG_CTRL_BUSY, &mos7840_port->flags); 4873f542974SPaul B Schroeder } 4883f542974SPaul B Schroeder 4893f542974SPaul B Schroeder static int mos7840_get_reg(struct moschip_port *mcs, __u16 Wval, __u16 reg, 4903f542974SPaul B Schroeder __u16 *val) 4913f542974SPaul B Schroeder { 4923f542974SPaul B Schroeder struct usb_device *dev = mcs->port->serial->dev; 4930de9a702SOliver Neukum struct usb_ctrlrequest *dr = mcs->dr; 4940de9a702SOliver Neukum unsigned char *buffer = mcs->ctrl_buf; 4950de9a702SOliver Neukum int ret; 4963f542974SPaul B Schroeder 497*d8a083ccSJohan Hovold if (test_and_set_bit_lock(MOS7840_FLAG_CTRL_BUSY, &mcs->flags)) 498*d8a083ccSJohan Hovold return -EBUSY; 499*d8a083ccSJohan Hovold 5003f542974SPaul B Schroeder dr->bRequestType = MCS_RD_RTYPE; 5013f542974SPaul B Schroeder dr->bRequest = MCS_RDREQ; 502880af9dbSAlan Cox dr->wValue = cpu_to_le16(Wval); /* 0 */ 5033f542974SPaul B Schroeder dr->wIndex = cpu_to_le16(reg); 5043f542974SPaul B Schroeder dr->wLength = cpu_to_le16(2); 5053f542974SPaul B Schroeder 5063f542974SPaul B Schroeder usb_fill_control_urb(mcs->control_urb, dev, usb_rcvctrlpipe(dev, 0), 5073f542974SPaul B Schroeder (unsigned char *)dr, buffer, 2, 5083f542974SPaul B Schroeder mos7840_control_callback, mcs); 5093f542974SPaul B Schroeder mcs->control_urb->transfer_buffer_length = 2; 5103f542974SPaul B Schroeder ret = usb_submit_urb(mcs->control_urb, GFP_ATOMIC); 511*d8a083ccSJohan Hovold if (ret) 512*d8a083ccSJohan Hovold clear_bit_unlock(MOS7840_FLAG_CTRL_BUSY, &mcs->flags); 513*d8a083ccSJohan Hovold 5143f542974SPaul B Schroeder return ret; 5153f542974SPaul B Schroeder } 5163f542974SPaul B Schroeder 5170eafe4deSDonald static void mos7840_set_led_callback(struct urb *urb) 5180eafe4deSDonald { 5190eafe4deSDonald switch (urb->status) { 5200eafe4deSDonald case 0: 5210eafe4deSDonald /* Success */ 5220eafe4deSDonald break; 5230eafe4deSDonald case -ECONNRESET: 5240eafe4deSDonald case -ENOENT: 5250eafe4deSDonald case -ESHUTDOWN: 5260eafe4deSDonald /* This urb is terminated, clean up */ 5279c134a14SGreg Kroah-Hartman dev_dbg(&urb->dev->dev, "%s - urb shutting down with status: %d", 5289c134a14SGreg Kroah-Hartman __func__, urb->status); 5290eafe4deSDonald break; 5300eafe4deSDonald default: 5319c134a14SGreg Kroah-Hartman dev_dbg(&urb->dev->dev, "%s - nonzero urb status received: %d", 5329c134a14SGreg Kroah-Hartman __func__, urb->status); 5330eafe4deSDonald } 5340eafe4deSDonald } 5350eafe4deSDonald 5360eafe4deSDonald static void mos7840_set_led_async(struct moschip_port *mcs, __u16 wval, 5370eafe4deSDonald __u16 reg) 5380eafe4deSDonald { 5390eafe4deSDonald struct usb_device *dev = mcs->port->serial->dev; 5400eafe4deSDonald struct usb_ctrlrequest *dr = mcs->dr; 5410eafe4deSDonald 5420eafe4deSDonald dr->bRequestType = MCS_WR_RTYPE; 5430eafe4deSDonald dr->bRequest = MCS_WRREQ; 5440eafe4deSDonald dr->wValue = cpu_to_le16(wval); 5450eafe4deSDonald dr->wIndex = cpu_to_le16(reg); 5460eafe4deSDonald dr->wLength = cpu_to_le16(0); 5470eafe4deSDonald 5480eafe4deSDonald usb_fill_control_urb(mcs->control_urb, dev, usb_sndctrlpipe(dev, 0), 5490eafe4deSDonald (unsigned char *)dr, NULL, 0, mos7840_set_led_callback, NULL); 5500eafe4deSDonald 5510eafe4deSDonald usb_submit_urb(mcs->control_urb, GFP_ATOMIC); 5520eafe4deSDonald } 5530eafe4deSDonald 5540eafe4deSDonald static void mos7840_set_led_sync(struct usb_serial_port *port, __u16 reg, 5550eafe4deSDonald __u16 val) 5560eafe4deSDonald { 5570eafe4deSDonald struct usb_device *dev = port->serial->dev; 5580eafe4deSDonald 5590eafe4deSDonald usb_control_msg(dev, usb_sndctrlpipe(dev, 0), MCS_WRREQ, MCS_WR_RTYPE, 5600eafe4deSDonald val, reg, NULL, 0, MOS_WDR_TIMEOUT); 5610eafe4deSDonald } 5620eafe4deSDonald 5630eafe4deSDonald static void mos7840_led_off(unsigned long arg) 5640eafe4deSDonald { 5650eafe4deSDonald struct moschip_port *mcs = (struct moschip_port *) arg; 5660eafe4deSDonald 5670eafe4deSDonald /* Turn off LED */ 5680eafe4deSDonald mos7840_set_led_async(mcs, 0x0300, MODEM_CONTROL_REGISTER); 5690eafe4deSDonald mod_timer(&mcs->led_timer2, 5700eafe4deSDonald jiffies + msecs_to_jiffies(LED_OFF_MS)); 5710eafe4deSDonald } 5720eafe4deSDonald 5730eafe4deSDonald static void mos7840_led_flag_off(unsigned long arg) 5740eafe4deSDonald { 5750eafe4deSDonald struct moschip_port *mcs = (struct moschip_port *) arg; 5760eafe4deSDonald 5770eafe4deSDonald mcs->led_flag = false; 5780eafe4deSDonald } 5790eafe4deSDonald 5803f542974SPaul B Schroeder /***************************************************************************** 5813f542974SPaul B Schroeder * mos7840_interrupt_callback 5823f542974SPaul B Schroeder * this is the callback function for when we have received data on the 5833f542974SPaul B Schroeder * interrupt endpoint. 5843f542974SPaul B Schroeder *****************************************************************************/ 5853f542974SPaul B Schroeder 5867d12e780SDavid Howells static void mos7840_interrupt_callback(struct urb *urb) 5873f542974SPaul B Schroeder { 5883f542974SPaul B Schroeder int result; 5893f542974SPaul B Schroeder int length; 5903f542974SPaul B Schroeder struct moschip_port *mos7840_port; 5913f542974SPaul B Schroeder struct usb_serial *serial; 5923f542974SPaul B Schroeder __u16 Data; 5933f542974SPaul B Schroeder unsigned char *data; 5943f542974SPaul B Schroeder __u8 sp[5], st; 5950de9a702SOliver Neukum int i, rv = 0; 5960de9a702SOliver Neukum __u16 wval, wreg = 0; 5970643c724SGreg Kroah-Hartman int status = urb->status; 5983f542974SPaul B Schroeder 5990643c724SGreg Kroah-Hartman switch (status) { 6003f542974SPaul B Schroeder case 0: 6013f542974SPaul B Schroeder /* success */ 6023f542974SPaul B Schroeder break; 6033f542974SPaul B Schroeder case -ECONNRESET: 6043f542974SPaul B Schroeder case -ENOENT: 6053f542974SPaul B Schroeder case -ESHUTDOWN: 6063f542974SPaul B Schroeder /* this urb is terminated, clean up */ 6079c134a14SGreg Kroah-Hartman dev_dbg(&urb->dev->dev, "%s - urb shutting down with status: %d\n", 6089c134a14SGreg Kroah-Hartman __func__, status); 6093f542974SPaul B Schroeder return; 6103f542974SPaul B Schroeder default: 6119c134a14SGreg Kroah-Hartman dev_dbg(&urb->dev->dev, "%s - nonzero urb status received: %d\n", 6129c134a14SGreg Kroah-Hartman __func__, status); 6133f542974SPaul B Schroeder goto exit; 6143f542974SPaul B Schroeder } 6153f542974SPaul B Schroeder 6163f542974SPaul B Schroeder length = urb->actual_length; 6173f542974SPaul B Schroeder data = urb->transfer_buffer; 6183f542974SPaul B Schroeder 619cdc97792SMing Lei serial = urb->context; 6203f542974SPaul B Schroeder 6213f542974SPaul B Schroeder /* Moschip get 5 bytes 6223f542974SPaul B Schroeder * Byte 1 IIR Port 1 (port.number is 0) 6233f542974SPaul B Schroeder * Byte 2 IIR Port 2 (port.number is 1) 6243f542974SPaul B Schroeder * Byte 3 IIR Port 3 (port.number is 2) 6253f542974SPaul B Schroeder * Byte 4 IIR Port 4 (port.number is 3) 6263f542974SPaul B Schroeder * Byte 5 FIFO status for both */ 6273f542974SPaul B Schroeder 6283f542974SPaul B Schroeder if (length && length > 5) { 6299c134a14SGreg Kroah-Hartman dev_dbg(&urb->dev->dev, "%s", "Wrong data !!!\n"); 6303f542974SPaul B Schroeder return; 6313f542974SPaul B Schroeder } 6323f542974SPaul B Schroeder 6333f542974SPaul B Schroeder sp[0] = (__u8) data[0]; 6343f542974SPaul B Schroeder sp[1] = (__u8) data[1]; 6353f542974SPaul B Schroeder sp[2] = (__u8) data[2]; 6363f542974SPaul B Schroeder sp[3] = (__u8) data[3]; 6373f542974SPaul B Schroeder st = (__u8) data[4]; 6383f542974SPaul B Schroeder 6393f542974SPaul B Schroeder for (i = 0; i < serial->num_ports; i++) { 6403f542974SPaul B Schroeder mos7840_port = mos7840_get_port_private(serial->port[i]); 6411143832eSGreg Kroah-Hartman wval = ((__u16)serial->port[i]->port_number + 1) << 8; 6423f542974SPaul B Schroeder if (mos7840_port->open) { 6433f542974SPaul B Schroeder if (sp[i] & 0x01) { 6449c134a14SGreg Kroah-Hartman dev_dbg(&urb->dev->dev, "SP%d No Interrupt !!!\n", i); 6453f542974SPaul B Schroeder } else { 6463f542974SPaul B Schroeder switch (sp[i] & 0x0f) { 6473f542974SPaul B Schroeder case SERIAL_IIR_RLS: 6489c134a14SGreg Kroah-Hartman dev_dbg(&urb->dev->dev, "Serial Port %d: Receiver status error or \n", i); 6499c134a14SGreg Kroah-Hartman dev_dbg(&urb->dev->dev, "address bit detected in 9-bit mode\n"); 6503f542974SPaul B Schroeder mos7840_port->MsrLsr = 1; 6510de9a702SOliver Neukum wreg = LINE_STATUS_REGISTER; 6523f542974SPaul B Schroeder break; 6533f542974SPaul B Schroeder case SERIAL_IIR_MS: 6549c134a14SGreg Kroah-Hartman dev_dbg(&urb->dev->dev, "Serial Port %d: Modem status change\n", i); 6553f542974SPaul B Schroeder mos7840_port->MsrLsr = 0; 6560de9a702SOliver Neukum wreg = MODEM_STATUS_REGISTER; 6573f542974SPaul B Schroeder break; 6583f542974SPaul B Schroeder } 6590de9a702SOliver Neukum rv = mos7840_get_reg(mos7840_port, wval, wreg, &Data); 6603f542974SPaul B Schroeder } 6613f542974SPaul B Schroeder } 6623f542974SPaul B Schroeder } 663880af9dbSAlan Cox if (!(rv < 0)) 664880af9dbSAlan Cox /* the completion handler for the control urb will resubmit */ 6650de9a702SOliver Neukum return; 6663f542974SPaul B Schroeder exit: 6673f542974SPaul B Schroeder result = usb_submit_urb(urb, GFP_ATOMIC); 6683f542974SPaul B Schroeder if (result) { 6693f542974SPaul B Schroeder dev_err(&urb->dev->dev, 6703f542974SPaul B Schroeder "%s - Error %d submitting interrupt urb\n", 671441b62c1SHarvey Harrison __func__, result); 6723f542974SPaul B Schroeder } 6733f542974SPaul B Schroeder } 6743f542974SPaul B Schroeder 6753f542974SPaul B Schroeder static int mos7840_port_paranoia_check(struct usb_serial_port *port, 6763f542974SPaul B Schroeder const char *function) 6773f542974SPaul B Schroeder { 6783f542974SPaul B Schroeder if (!port) { 6799c134a14SGreg Kroah-Hartman pr_debug("%s - port == NULL\n", function); 6803f542974SPaul B Schroeder return -1; 6813f542974SPaul B Schroeder } 6823f542974SPaul B Schroeder if (!port->serial) { 6839c134a14SGreg Kroah-Hartman pr_debug("%s - port->serial == NULL\n", function); 6843f542974SPaul B Schroeder return -1; 6853f542974SPaul B Schroeder } 6863f542974SPaul B Schroeder 6873f542974SPaul B Schroeder return 0; 6883f542974SPaul B Schroeder } 6893f542974SPaul B Schroeder 6903f542974SPaul B Schroeder /* Inline functions to check the sanity of a pointer that is passed to us */ 6913f542974SPaul B Schroeder static int mos7840_serial_paranoia_check(struct usb_serial *serial, 6923f542974SPaul B Schroeder const char *function) 6933f542974SPaul B Schroeder { 6943f542974SPaul B Schroeder if (!serial) { 6959c134a14SGreg Kroah-Hartman pr_debug("%s - serial == NULL\n", function); 6963f542974SPaul B Schroeder return -1; 6973f542974SPaul B Schroeder } 6983f542974SPaul B Schroeder if (!serial->type) { 6999c134a14SGreg Kroah-Hartman pr_debug("%s - serial->type == NULL!\n", function); 7003f542974SPaul B Schroeder return -1; 7013f542974SPaul B Schroeder } 7023f542974SPaul B Schroeder 7033f542974SPaul B Schroeder return 0; 7043f542974SPaul B Schroeder } 7053f542974SPaul B Schroeder 7063f542974SPaul B Schroeder static struct usb_serial *mos7840_get_usb_serial(struct usb_serial_port *port, 7073f542974SPaul B Schroeder const char *function) 7083f542974SPaul B Schroeder { 7093f542974SPaul B Schroeder /* if no port was specified, or it fails a paranoia check */ 7103f542974SPaul B Schroeder if (!port || 7113f542974SPaul B Schroeder mos7840_port_paranoia_check(port, function) || 7123f542974SPaul B Schroeder mos7840_serial_paranoia_check(port->serial, function)) { 713880af9dbSAlan Cox /* then say that we don't have a valid usb_serial thing, 714880af9dbSAlan Cox * which will end up genrating -ENODEV return values */ 7153f542974SPaul B Schroeder return NULL; 7163f542974SPaul B Schroeder } 7173f542974SPaul B Schroeder 7183f542974SPaul B Schroeder return port->serial; 7193f542974SPaul B Schroeder } 7203f542974SPaul B Schroeder 7213f542974SPaul B Schroeder /***************************************************************************** 7223f542974SPaul B Schroeder * mos7840_bulk_in_callback 7233f542974SPaul B Schroeder * this is the callback function for when we have received data on the 7243f542974SPaul B Schroeder * bulk in endpoint. 7253f542974SPaul B Schroeder *****************************************************************************/ 7263f542974SPaul B Schroeder 7277d12e780SDavid Howells static void mos7840_bulk_in_callback(struct urb *urb) 7283f542974SPaul B Schroeder { 7290643c724SGreg Kroah-Hartman int retval; 7303f542974SPaul B Schroeder unsigned char *data; 7313f542974SPaul B Schroeder struct usb_serial *serial; 7323f542974SPaul B Schroeder struct usb_serial_port *port; 7333f542974SPaul B Schroeder struct moschip_port *mos7840_port; 7340643c724SGreg Kroah-Hartman int status = urb->status; 7353f542974SPaul B Schroeder 736cdc97792SMing Lei mos7840_port = urb->context; 7379c134a14SGreg Kroah-Hartman if (!mos7840_port) 73850de36f7SGreg Kroah-Hartman return; 73950de36f7SGreg Kroah-Hartman 74050de36f7SGreg Kroah-Hartman if (status) { 7419c134a14SGreg Kroah-Hartman dev_dbg(&urb->dev->dev, "nonzero read bulk status received: %d\n", status); 74250de36f7SGreg Kroah-Hartman mos7840_port->read_urb_busy = false; 7433f542974SPaul B Schroeder return; 7443f542974SPaul B Schroeder } 7453f542974SPaul B Schroeder 7469c134a14SGreg Kroah-Hartman port = mos7840_port->port; 747441b62c1SHarvey Harrison if (mos7840_port_paranoia_check(port, __func__)) { 74850de36f7SGreg Kroah-Hartman mos7840_port->read_urb_busy = false; 7493f542974SPaul B Schroeder return; 7503f542974SPaul B Schroeder } 7513f542974SPaul B Schroeder 752441b62c1SHarvey Harrison serial = mos7840_get_usb_serial(port, __func__); 7533f542974SPaul B Schroeder if (!serial) { 75450de36f7SGreg Kroah-Hartman mos7840_port->read_urb_busy = false; 7553f542974SPaul B Schroeder return; 7563f542974SPaul B Schroeder } 7573f542974SPaul B Schroeder 7583f542974SPaul B Schroeder data = urb->transfer_buffer; 75959d33f2fSGreg Kroah-Hartman usb_serial_debug_data(&port->dev, __func__, urb->actual_length, data); 7603f542974SPaul B Schroeder 7613f542974SPaul B Schroeder if (urb->actual_length) { 76205c7cd39SJiri Slaby struct tty_port *tport = &mos7840_port->port->port; 76305c7cd39SJiri Slaby tty_insert_flip_string(tport, data, urb->actual_length); 7642e124b4aSJiri Slaby tty_flip_buffer_push(tport); 7658c1a07ffSJohan Hovold port->icount.rx += urb->actual_length; 7668c1a07ffSJohan Hovold dev_dbg(&port->dev, "icount.rx is %d:\n", port->icount.rx); 7673f542974SPaul B Schroeder } 7683f542974SPaul B Schroeder 7693f542974SPaul B Schroeder if (!mos7840_port->read_urb) { 7709c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s", "URB KILLED !!!\n"); 77150de36f7SGreg Kroah-Hartman mos7840_port->read_urb_busy = false; 7723f542974SPaul B Schroeder return; 7733f542974SPaul B Schroeder } 7743f542974SPaul B Schroeder 7750eafe4deSDonald /* Turn on LED */ 7760eafe4deSDonald if (mos7840_port->has_led && !mos7840_port->led_flag) { 7770eafe4deSDonald mos7840_port->led_flag = true; 7780eafe4deSDonald mos7840_set_led_async(mos7840_port, 0x0301, 7790eafe4deSDonald MODEM_CONTROL_REGISTER); 7800eafe4deSDonald mod_timer(&mos7840_port->led_timer1, 7810eafe4deSDonald jiffies + msecs_to_jiffies(LED_ON_MS)); 7820eafe4deSDonald } 7830de9a702SOliver Neukum 78450de36f7SGreg Kroah-Hartman mos7840_port->read_urb_busy = true; 7850643c724SGreg Kroah-Hartman retval = usb_submit_urb(mos7840_port->read_urb, GFP_ATOMIC); 7863f542974SPaul B Schroeder 7870643c724SGreg Kroah-Hartman if (retval) { 7889c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "usb_submit_urb(read bulk) failed, retval = %d\n", retval); 78950de36f7SGreg Kroah-Hartman mos7840_port->read_urb_busy = false; 7903f542974SPaul B Schroeder } 7913f542974SPaul B Schroeder } 7923f542974SPaul B Schroeder 7933f542974SPaul B Schroeder /***************************************************************************** 7943f542974SPaul B Schroeder * mos7840_bulk_out_data_callback 795880af9dbSAlan Cox * this is the callback function for when we have finished sending 796880af9dbSAlan Cox * serial data on the bulk out endpoint. 7973f542974SPaul B Schroeder *****************************************************************************/ 7983f542974SPaul B Schroeder 7997d12e780SDavid Howells static void mos7840_bulk_out_data_callback(struct urb *urb) 8003f542974SPaul B Schroeder { 8013f542974SPaul B Schroeder struct moschip_port *mos7840_port; 8029c134a14SGreg Kroah-Hartman struct usb_serial_port *port; 8030643c724SGreg Kroah-Hartman int status = urb->status; 8040de9a702SOliver Neukum int i; 8050de9a702SOliver Neukum 806cdc97792SMing Lei mos7840_port = urb->context; 8079c134a14SGreg Kroah-Hartman port = mos7840_port->port; 8080de9a702SOliver Neukum spin_lock(&mos7840_port->pool_lock); 8090de9a702SOliver Neukum for (i = 0; i < NUM_URBS; i++) { 8100de9a702SOliver Neukum if (urb == mos7840_port->write_urb_pool[i]) { 8110de9a702SOliver Neukum mos7840_port->busy[i] = 0; 8120de9a702SOliver Neukum break; 8130de9a702SOliver Neukum } 8140de9a702SOliver Neukum } 8150de9a702SOliver Neukum spin_unlock(&mos7840_port->pool_lock); 8160de9a702SOliver Neukum 8170643c724SGreg Kroah-Hartman if (status) { 8189c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "nonzero write bulk status received:%d\n", status); 8193f542974SPaul B Schroeder return; 8203f542974SPaul B Schroeder } 8213f542974SPaul B Schroeder 8229c134a14SGreg Kroah-Hartman if (mos7840_port_paranoia_check(port, __func__)) 8233f542974SPaul B Schroeder return; 8243f542974SPaul B Schroeder 8256aad04f2SJiri Slaby if (mos7840_port->open) 8266aad04f2SJiri Slaby tty_port_tty_wakeup(&port->port); 8273f542974SPaul B Schroeder 8283f542974SPaul B Schroeder } 8293f542974SPaul B Schroeder 8303f542974SPaul B Schroeder /************************************************************************/ 8313f542974SPaul 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 */ 8323f542974SPaul B Schroeder /************************************************************************/ 8333f542974SPaul B Schroeder #ifdef MCSSerialProbe 8343f542974SPaul B Schroeder static int mos7840_serial_probe(struct usb_serial *serial, 8353f542974SPaul B Schroeder const struct usb_device_id *id) 8363f542974SPaul B Schroeder { 8373f542974SPaul B Schroeder 8383f542974SPaul B Schroeder /*need to implement the mode_reg reading and updating\ 8393f542974SPaul B Schroeder structures usb_serial_ device_type\ 8403f542974SPaul B Schroeder (i.e num_ports, num_bulkin,bulkout etc) */ 8413f542974SPaul B Schroeder /* Also we can update the changes attach */ 8423f542974SPaul B Schroeder return 1; 8433f542974SPaul B Schroeder } 8443f542974SPaul B Schroeder #endif 8453f542974SPaul B Schroeder 8463f542974SPaul B Schroeder /***************************************************************************** 8473f542974SPaul B Schroeder * mos7840_open 8483f542974SPaul B Schroeder * this function is called by the tty driver when a port is opened 8493f542974SPaul B Schroeder * If successful, we return 0 8503f542974SPaul B Schroeder * Otherwise we return a negative error number. 8513f542974SPaul B Schroeder *****************************************************************************/ 8523f542974SPaul B Schroeder 853a509a7e4SAlan Cox static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port) 8543f542974SPaul B Schroeder { 8553f542974SPaul B Schroeder int response; 8563f542974SPaul B Schroeder int j; 8573f542974SPaul B Schroeder struct usb_serial *serial; 8583f542974SPaul B Schroeder struct urb *urb; 8593f542974SPaul B Schroeder __u16 Data; 8603f542974SPaul B Schroeder int status; 8613f542974SPaul B Schroeder struct moschip_port *mos7840_port; 8620de9a702SOliver Neukum struct moschip_port *port0; 8633f542974SPaul B Schroeder 8649c134a14SGreg Kroah-Hartman if (mos7840_port_paranoia_check(port, __func__)) 8653f542974SPaul B Schroeder return -ENODEV; 8663f542974SPaul B Schroeder 8673f542974SPaul B Schroeder serial = port->serial; 8683f542974SPaul B Schroeder 8699c134a14SGreg Kroah-Hartman if (mos7840_serial_paranoia_check(serial, __func__)) 8703f542974SPaul B Schroeder return -ENODEV; 8713f542974SPaul B Schroeder 8723f542974SPaul B Schroeder mos7840_port = mos7840_get_port_private(port); 8730de9a702SOliver Neukum port0 = mos7840_get_port_private(serial->port[0]); 8743f542974SPaul B Schroeder 8750de9a702SOliver Neukum if (mos7840_port == NULL || port0 == NULL) 8763f542974SPaul B Schroeder return -ENODEV; 8773f542974SPaul B Schroeder 8783f542974SPaul B Schroeder usb_clear_halt(serial->dev, port->write_urb->pipe); 8793f542974SPaul B Schroeder usb_clear_halt(serial->dev, port->read_urb->pipe); 8800de9a702SOliver Neukum port0->open_ports++; 8813f542974SPaul B Schroeder 8823f542974SPaul B Schroeder /* Initialising the write urb pool */ 8833f542974SPaul B Schroeder for (j = 0; j < NUM_URBS; ++j) { 8840de9a702SOliver Neukum urb = usb_alloc_urb(0, GFP_KERNEL); 8853f542974SPaul B Schroeder mos7840_port->write_urb_pool[j] = urb; 8863f542974SPaul B Schroeder 8873f542974SPaul B Schroeder if (urb == NULL) { 888194343d9SGreg Kroah-Hartman dev_err(&port->dev, "No more urbs???\n"); 8893f542974SPaul B Schroeder continue; 8903f542974SPaul B Schroeder } 8913f542974SPaul B Schroeder 892880af9dbSAlan Cox urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE, 893880af9dbSAlan Cox GFP_KERNEL); 8943f542974SPaul B Schroeder if (!urb->transfer_buffer) { 8950de9a702SOliver Neukum usb_free_urb(urb); 8960de9a702SOliver Neukum mos7840_port->write_urb_pool[j] = NULL; 897194343d9SGreg Kroah-Hartman dev_err(&port->dev, 898194343d9SGreg Kroah-Hartman "%s-out of memory for urb buffers.\n", 899194343d9SGreg Kroah-Hartman __func__); 9003f542974SPaul B Schroeder continue; 9013f542974SPaul B Schroeder } 9023f542974SPaul B Schroeder } 9033f542974SPaul B Schroeder 9043f542974SPaul B Schroeder /***************************************************************************** 9053f542974SPaul B Schroeder * Initialize MCS7840 -- Write Init values to corresponding Registers 9063f542974SPaul B Schroeder * 9073f542974SPaul B Schroeder * Register Index 9083f542974SPaul B Schroeder * 1 : IER 9093f542974SPaul B Schroeder * 2 : FCR 9103f542974SPaul B Schroeder * 3 : LCR 9113f542974SPaul B Schroeder * 4 : MCR 9123f542974SPaul B Schroeder * 9133f542974SPaul B Schroeder * 0x08 : SP1/2 Control Reg 9143f542974SPaul B Schroeder *****************************************************************************/ 9153f542974SPaul B Schroeder 916880af9dbSAlan Cox /* NEED to check the following Block */ 9173f542974SPaul B Schroeder 9183f542974SPaul B Schroeder Data = 0x0; 9193f542974SPaul B Schroeder status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, &Data); 9203f542974SPaul B Schroeder if (status < 0) { 9219c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "Reading Spreg failed\n"); 9225f8a2e68SJohan Hovold goto err; 9233f542974SPaul B Schroeder } 9243f542974SPaul B Schroeder Data |= 0x80; 9253f542974SPaul B Schroeder status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data); 9263f542974SPaul B Schroeder if (status < 0) { 9279c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "writing Spreg failed\n"); 9285f8a2e68SJohan Hovold goto err; 9293f542974SPaul B Schroeder } 9303f542974SPaul B Schroeder 9313f542974SPaul B Schroeder Data &= ~0x80; 9323f542974SPaul B Schroeder status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data); 9333f542974SPaul B Schroeder if (status < 0) { 9349c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "writing Spreg failed\n"); 9355f8a2e68SJohan Hovold goto err; 9363f542974SPaul B Schroeder } 937880af9dbSAlan Cox /* End of block to be checked */ 9383f542974SPaul B Schroeder 9393f542974SPaul B Schroeder Data = 0x0; 940880af9dbSAlan Cox status = mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset, 941880af9dbSAlan Cox &Data); 9423f542974SPaul B Schroeder if (status < 0) { 9439c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "Reading Controlreg failed\n"); 9445f8a2e68SJohan Hovold goto err; 9453f542974SPaul B Schroeder } 946880af9dbSAlan Cox Data |= 0x08; /* Driver done bit */ 947880af9dbSAlan Cox Data |= 0x20; /* rx_disable */ 948880af9dbSAlan Cox status = mos7840_set_reg_sync(port, 949880af9dbSAlan Cox mos7840_port->ControlRegOffset, Data); 9503f542974SPaul B Schroeder if (status < 0) { 9519c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "writing Controlreg failed\n"); 9525f8a2e68SJohan Hovold goto err; 9533f542974SPaul B Schroeder } 954880af9dbSAlan Cox /* do register settings here */ 955880af9dbSAlan Cox /* Set all regs to the device default values. */ 956880af9dbSAlan Cox /*********************************** 957880af9dbSAlan Cox * First Disable all interrupts. 958880af9dbSAlan Cox ***********************************/ 9593f542974SPaul B Schroeder Data = 0x00; 9603f542974SPaul B Schroeder status = mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data); 9613f542974SPaul B Schroeder if (status < 0) { 9629c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "disabling interrupts failed\n"); 9635f8a2e68SJohan Hovold goto err; 9643f542974SPaul B Schroeder } 965880af9dbSAlan Cox /* Set FIFO_CONTROL_REGISTER to the default value */ 9663f542974SPaul B Schroeder Data = 0x00; 9673f542974SPaul B Schroeder status = mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data); 9683f542974SPaul B Schroeder if (status < 0) { 9699c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "Writing FIFO_CONTROL_REGISTER failed\n"); 9705f8a2e68SJohan Hovold goto err; 9713f542974SPaul B Schroeder } 9723f542974SPaul B Schroeder 9733f542974SPaul B Schroeder Data = 0xcf; 9743f542974SPaul B Schroeder status = mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data); 9753f542974SPaul B Schroeder if (status < 0) { 9769c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "Writing FIFO_CONTROL_REGISTER failed\n"); 9775f8a2e68SJohan Hovold goto err; 9783f542974SPaul B Schroeder } 9793f542974SPaul B Schroeder 9803f542974SPaul B Schroeder Data = 0x03; 9813f542974SPaul B Schroeder status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); 9823f542974SPaul B Schroeder mos7840_port->shadowLCR = Data; 9833f542974SPaul B Schroeder 9843f542974SPaul B Schroeder Data = 0x0b; 9853f542974SPaul B Schroeder status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); 9863f542974SPaul B Schroeder mos7840_port->shadowMCR = Data; 9873f542974SPaul B Schroeder 9883f542974SPaul B Schroeder Data = 0x00; 9893f542974SPaul B Schroeder status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data); 9903f542974SPaul B Schroeder mos7840_port->shadowLCR = Data; 9913f542974SPaul B Schroeder 992880af9dbSAlan Cox Data |= SERIAL_LCR_DLAB; /* data latch enable in LCR 0x80 */ 9933f542974SPaul B Schroeder status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); 9943f542974SPaul B Schroeder 9953f542974SPaul B Schroeder Data = 0x0c; 9963f542974SPaul B Schroeder status = mos7840_set_uart_reg(port, DIVISOR_LATCH_LSB, Data); 9973f542974SPaul B Schroeder 9983f542974SPaul B Schroeder Data = 0x0; 9993f542974SPaul B Schroeder status = mos7840_set_uart_reg(port, DIVISOR_LATCH_MSB, Data); 10003f542974SPaul B Schroeder 10013f542974SPaul B Schroeder Data = 0x00; 10023f542974SPaul B Schroeder status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data); 10033f542974SPaul B Schroeder 10043f542974SPaul B Schroeder Data = Data & ~SERIAL_LCR_DLAB; 10053f542974SPaul B Schroeder status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); 10063f542974SPaul B Schroeder mos7840_port->shadowLCR = Data; 10073f542974SPaul B Schroeder 1008880af9dbSAlan Cox /* clearing Bulkin and Bulkout Fifo */ 10093f542974SPaul B Schroeder Data = 0x0; 10103f542974SPaul B Schroeder status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, &Data); 10113f542974SPaul B Schroeder 10123f542974SPaul B Schroeder Data = Data | 0x0c; 10133f542974SPaul B Schroeder status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data); 10143f542974SPaul B Schroeder 10153f542974SPaul B Schroeder Data = Data & ~0x0c; 10163f542974SPaul B Schroeder status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data); 1017880af9dbSAlan Cox /* Finally enable all interrupts */ 10183f542974SPaul B Schroeder Data = 0x0c; 10193f542974SPaul B Schroeder status = mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data); 10203f542974SPaul B Schroeder 1021880af9dbSAlan Cox /* clearing rx_disable */ 10223f542974SPaul B Schroeder Data = 0x0; 1023880af9dbSAlan Cox status = mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset, 1024880af9dbSAlan Cox &Data); 10253f542974SPaul B Schroeder Data = Data & ~0x20; 1026880af9dbSAlan Cox status = mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset, 1027880af9dbSAlan Cox Data); 10283f542974SPaul B Schroeder 1029880af9dbSAlan Cox /* rx_negate */ 10303f542974SPaul B Schroeder Data = 0x0; 1031880af9dbSAlan Cox status = mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset, 1032880af9dbSAlan Cox &Data); 10333f542974SPaul B Schroeder Data = Data | 0x10; 1034880af9dbSAlan Cox status = mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset, 1035880af9dbSAlan Cox Data); 10363f542974SPaul B Schroeder 10373f542974SPaul B Schroeder /* Check to see if we've set up our endpoint info yet * 10383f542974SPaul B Schroeder * (can't set it up in mos7840_startup as the structures * 10393f542974SPaul B Schroeder * were not set up at that time.) */ 10400de9a702SOliver Neukum if (port0->open_ports == 1) { 10413f542974SPaul B Schroeder if (serial->port[0]->interrupt_in_buffer == NULL) { 10423f542974SPaul B Schroeder /* set up interrupt urb */ 10433f542974SPaul B Schroeder usb_fill_int_urb(serial->port[0]->interrupt_in_urb, 10443f542974SPaul B Schroeder serial->dev, 10453f542974SPaul B Schroeder usb_rcvintpipe(serial->dev, 1046880af9dbSAlan Cox serial->port[0]->interrupt_in_endpointAddress), 10473f542974SPaul B Schroeder serial->port[0]->interrupt_in_buffer, 10483f542974SPaul B Schroeder serial->port[0]->interrupt_in_urb-> 10493f542974SPaul B Schroeder transfer_buffer_length, 10503f542974SPaul B Schroeder mos7840_interrupt_callback, 10513f542974SPaul B Schroeder serial, 1052880af9dbSAlan Cox serial->port[0]->interrupt_in_urb->interval); 10533f542974SPaul B Schroeder 10543f542974SPaul B Schroeder /* start interrupt read for mos7840 * 10553f542974SPaul B Schroeder * will continue as long as mos7840 is connected */ 10563f542974SPaul B Schroeder 10573f542974SPaul B Schroeder response = 10583f542974SPaul B Schroeder usb_submit_urb(serial->port[0]->interrupt_in_urb, 10593f542974SPaul B Schroeder GFP_KERNEL); 10603f542974SPaul B Schroeder if (response) { 1061194343d9SGreg Kroah-Hartman dev_err(&port->dev, "%s - Error %d submitting " 1062194343d9SGreg Kroah-Hartman "interrupt urb\n", __func__, response); 10633f542974SPaul B Schroeder } 10643f542974SPaul B Schroeder 10653f542974SPaul B Schroeder } 10663f542974SPaul B Schroeder 10673f542974SPaul B Schroeder } 10683f542974SPaul B Schroeder 10693f542974SPaul B Schroeder /* see if we've set up our endpoint info yet * 10703f542974SPaul B Schroeder * (can't set it up in mos7840_startup as the * 10713f542974SPaul B Schroeder * structures were not set up at that time.) */ 10723f542974SPaul B Schroeder 10731143832eSGreg Kroah-Hartman dev_dbg(&port->dev, "port number is %d\n", port->port_number); 1074e5b1e206SGreg Kroah-Hartman dev_dbg(&port->dev, "minor number is %d\n", port->minor); 10759c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "Bulkin endpoint is %d\n", port->bulk_in_endpointAddress); 10769c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "BulkOut endpoint is %d\n", port->bulk_out_endpointAddress); 10779c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "Interrupt endpoint is %d\n", port->interrupt_in_endpointAddress); 10789c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "port's number in the device is %d\n", mos7840_port->port_num); 10793f542974SPaul B Schroeder mos7840_port->read_urb = port->read_urb; 10803f542974SPaul B Schroeder 10813f542974SPaul B Schroeder /* set up our bulk in urb */ 10821143832eSGreg Kroah-Hartman if ((serial->num_ports == 2) && (((__u16)port->port_number % 2) != 0)) { 1083093ea2d3SDonald Lee usb_fill_bulk_urb(mos7840_port->read_urb, 1084093ea2d3SDonald Lee serial->dev, 1085093ea2d3SDonald Lee usb_rcvbulkpipe(serial->dev, 1086093ea2d3SDonald Lee (port->bulk_in_endpointAddress) + 2), 1087093ea2d3SDonald Lee port->bulk_in_buffer, 1088093ea2d3SDonald Lee mos7840_port->read_urb->transfer_buffer_length, 1089093ea2d3SDonald Lee mos7840_bulk_in_callback, mos7840_port); 1090093ea2d3SDonald Lee } else { 10913f542974SPaul B Schroeder usb_fill_bulk_urb(mos7840_port->read_urb, 10923f542974SPaul B Schroeder serial->dev, 10933f542974SPaul B Schroeder usb_rcvbulkpipe(serial->dev, 10943f542974SPaul B Schroeder port->bulk_in_endpointAddress), 10953f542974SPaul B Schroeder port->bulk_in_buffer, 10963f542974SPaul B Schroeder mos7840_port->read_urb->transfer_buffer_length, 10973f542974SPaul B Schroeder mos7840_bulk_in_callback, mos7840_port); 1098093ea2d3SDonald Lee } 10993f542974SPaul B Schroeder 11009c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s: bulkin endpoint is %d\n", __func__, port->bulk_in_endpointAddress); 110150de36f7SGreg Kroah-Hartman mos7840_port->read_urb_busy = true; 11023f542974SPaul B Schroeder response = usb_submit_urb(mos7840_port->read_urb, GFP_KERNEL); 11033f542974SPaul B Schroeder if (response) { 1104194343d9SGreg Kroah-Hartman dev_err(&port->dev, "%s - Error %d submitting control urb\n", 1105194343d9SGreg Kroah-Hartman __func__, response); 110650de36f7SGreg Kroah-Hartman mos7840_port->read_urb_busy = false; 11073f542974SPaul B Schroeder } 11083f542974SPaul B Schroeder 11093f542974SPaul B Schroeder /* initialize our wait queues */ 11103f542974SPaul B Schroeder init_waitqueue_head(&mos7840_port->wait_chase); 11113f542974SPaul B Schroeder 11123f542974SPaul B Schroeder /* initialize our port settings */ 1113880af9dbSAlan Cox /* Must set to enable ints! */ 1114880af9dbSAlan Cox mos7840_port->shadowMCR = MCR_MASTER_IE; 11153f542974SPaul B Schroeder /* send a open port command */ 11163f542974SPaul B Schroeder mos7840_port->open = 1; 1117880af9dbSAlan Cox /* mos7840_change_port_settings(mos7840_port,old_termios); */ 11183f542974SPaul B Schroeder 11193f542974SPaul B Schroeder return 0; 11205f8a2e68SJohan Hovold err: 11215f8a2e68SJohan Hovold for (j = 0; j < NUM_URBS; ++j) { 11225f8a2e68SJohan Hovold urb = mos7840_port->write_urb_pool[j]; 11235f8a2e68SJohan Hovold if (!urb) 11245f8a2e68SJohan Hovold continue; 11255f8a2e68SJohan Hovold kfree(urb->transfer_buffer); 11265f8a2e68SJohan Hovold usb_free_urb(urb); 11275f8a2e68SJohan Hovold } 11285f8a2e68SJohan Hovold return status; 11293f542974SPaul B Schroeder } 11303f542974SPaul B Schroeder 11313f542974SPaul B Schroeder /***************************************************************************** 11323f542974SPaul B Schroeder * mos7840_chars_in_buffer 11333f542974SPaul B Schroeder * this function is called by the tty driver when it wants to know how many 11343f542974SPaul B Schroeder * bytes of data we currently have outstanding in the port (data that has 11353f542974SPaul B Schroeder * been written, but hasn't made it out the port yet) 11363f542974SPaul B Schroeder * If successful, we return the number of bytes left to be written in the 11373f542974SPaul B Schroeder * system, 113895da310eSAlan Cox * Otherwise we return zero. 11393f542974SPaul B Schroeder *****************************************************************************/ 11403f542974SPaul B Schroeder 114195da310eSAlan Cox static int mos7840_chars_in_buffer(struct tty_struct *tty) 11423f542974SPaul B Schroeder { 114395da310eSAlan Cox struct usb_serial_port *port = tty->driver_data; 11443f542974SPaul B Schroeder int i; 11453f542974SPaul B Schroeder int chars = 0; 11460de9a702SOliver Neukum unsigned long flags; 11473f542974SPaul B Schroeder struct moschip_port *mos7840_port; 11483f542974SPaul B Schroeder 11499c134a14SGreg Kroah-Hartman if (mos7840_port_paranoia_check(port, __func__)) 115095da310eSAlan Cox return 0; 11513f542974SPaul B Schroeder 11523f542974SPaul B Schroeder mos7840_port = mos7840_get_port_private(port); 11533363155bSGreg Kroah-Hartman if (mos7840_port == NULL) 115495da310eSAlan Cox return 0; 11553f542974SPaul B Schroeder 11560de9a702SOliver Neukum spin_lock_irqsave(&mos7840_port->pool_lock, flags); 11575c263b92SMark Ferrell for (i = 0; i < NUM_URBS; ++i) { 11585c263b92SMark Ferrell if (mos7840_port->busy[i]) { 11595c263b92SMark Ferrell struct urb *urb = mos7840_port->write_urb_pool[i]; 11605c263b92SMark Ferrell chars += urb->transfer_buffer_length; 11615c263b92SMark Ferrell } 11625c263b92SMark Ferrell } 11630de9a702SOliver Neukum spin_unlock_irqrestore(&mos7840_port->pool_lock, flags); 11649c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s - returns %d\n", __func__, chars); 11650de9a702SOliver Neukum return chars; 11663f542974SPaul B Schroeder 11673f542974SPaul B Schroeder } 11683f542974SPaul B Schroeder 11693f542974SPaul B Schroeder /***************************************************************************** 11703f542974SPaul B Schroeder * mos7840_close 11713f542974SPaul B Schroeder * this function is called by the tty driver when a port is closed 11723f542974SPaul B Schroeder *****************************************************************************/ 11733f542974SPaul B Schroeder 1174335f8514SAlan Cox static void mos7840_close(struct usb_serial_port *port) 11753f542974SPaul B Schroeder { 11763f542974SPaul B Schroeder struct usb_serial *serial; 11773f542974SPaul B Schroeder struct moschip_port *mos7840_port; 11780de9a702SOliver Neukum struct moschip_port *port0; 11793f542974SPaul B Schroeder int j; 11803f542974SPaul B Schroeder __u16 Data; 11813f542974SPaul B Schroeder 11829c134a14SGreg Kroah-Hartman if (mos7840_port_paranoia_check(port, __func__)) 11833f542974SPaul B Schroeder return; 11843f542974SPaul B Schroeder 1185441b62c1SHarvey Harrison serial = mos7840_get_usb_serial(port, __func__); 11869c134a14SGreg Kroah-Hartman if (!serial) 11873f542974SPaul B Schroeder return; 11883f542974SPaul B Schroeder 11893f542974SPaul B Schroeder mos7840_port = mos7840_get_port_private(port); 11900de9a702SOliver Neukum port0 = mos7840_get_port_private(serial->port[0]); 11913f542974SPaul B Schroeder 11920de9a702SOliver Neukum if (mos7840_port == NULL || port0 == NULL) 11933f542974SPaul B Schroeder return; 11943f542974SPaul B Schroeder 11953f542974SPaul B Schroeder for (j = 0; j < NUM_URBS; ++j) 11963f542974SPaul B Schroeder usb_kill_urb(mos7840_port->write_urb_pool[j]); 11973f542974SPaul B Schroeder 11983f542974SPaul B Schroeder /* Freeing Write URBs */ 11993f542974SPaul B Schroeder for (j = 0; j < NUM_URBS; ++j) { 12003f542974SPaul B Schroeder if (mos7840_port->write_urb_pool[j]) { 12013f542974SPaul B Schroeder if (mos7840_port->write_urb_pool[j]->transfer_buffer) 12023f542974SPaul B Schroeder kfree(mos7840_port->write_urb_pool[j]-> 12033f542974SPaul B Schroeder transfer_buffer); 12043f542974SPaul B Schroeder 12053f542974SPaul B Schroeder usb_free_urb(mos7840_port->write_urb_pool[j]); 12063f542974SPaul B Schroeder } 12073f542974SPaul B Schroeder } 12083f542974SPaul B Schroeder 12093f542974SPaul B Schroeder usb_kill_urb(mos7840_port->write_urb); 12103f542974SPaul B Schroeder usb_kill_urb(mos7840_port->read_urb); 121150de36f7SGreg Kroah-Hartman mos7840_port->read_urb_busy = false; 1212bb3529c6SJohan Hovold 12130de9a702SOliver Neukum port0->open_ports--; 12141143832eSGreg Kroah-Hartman dev_dbg(&port->dev, "%s in close%d\n", __func__, port0->open_ports); 12150de9a702SOliver Neukum if (port0->open_ports == 0) { 12163f542974SPaul B Schroeder if (serial->port[0]->interrupt_in_urb) { 12179c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "Shutdown interrupt_in_urb\n"); 12180de9a702SOliver Neukum usb_kill_urb(serial->port[0]->interrupt_in_urb); 12193f542974SPaul B Schroeder } 12203f542974SPaul B Schroeder } 12213f542974SPaul B Schroeder 12223f542974SPaul B Schroeder if (mos7840_port->write_urb) { 12233f542974SPaul B Schroeder /* if this urb had a transfer buffer already (old tx) free it */ 12243f542974SPaul B Schroeder kfree(mos7840_port->write_urb->transfer_buffer); 12253f542974SPaul B Schroeder usb_free_urb(mos7840_port->write_urb); 12263f542974SPaul B Schroeder } 12273f542974SPaul B Schroeder 12283f542974SPaul B Schroeder Data = 0x0; 12293f542974SPaul B Schroeder mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); 12303f542974SPaul B Schroeder 12313f542974SPaul B Schroeder Data = 0x00; 12323f542974SPaul B Schroeder mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data); 12333f542974SPaul B Schroeder 12343f542974SPaul B Schroeder mos7840_port->open = 0; 12353f542974SPaul B Schroeder } 12363f542974SPaul B Schroeder 12373f542974SPaul B Schroeder /************************************************************************ 12383f542974SPaul B Schroeder * 12393f542974SPaul B Schroeder * mos7840_block_until_chase_response 12403f542974SPaul B Schroeder * 12413f542974SPaul B Schroeder * This function will block the close until one of the following: 12423f542974SPaul B Schroeder * 1. Response to our Chase comes from mos7840 1243dc0d5c1eSJoe Perches * 2. A timeout of 10 seconds without activity has expired 12443f542974SPaul B Schroeder * (1K of mos7840 data @ 2400 baud ==> 4 sec to empty) 12453f542974SPaul B Schroeder * 12463f542974SPaul B Schroeder ************************************************************************/ 12473f542974SPaul B Schroeder 124895da310eSAlan Cox static void mos7840_block_until_chase_response(struct tty_struct *tty, 124995da310eSAlan Cox struct moschip_port *mos7840_port) 12503f542974SPaul B Schroeder { 12511e658489SMark Ferrell int timeout = msecs_to_jiffies(1000); 12523f542974SPaul B Schroeder int wait = 10; 12533f542974SPaul B Schroeder int count; 12543f542974SPaul B Schroeder 12553f542974SPaul B Schroeder while (1) { 125695da310eSAlan Cox count = mos7840_chars_in_buffer(tty); 12573f542974SPaul B Schroeder 12583f542974SPaul B Schroeder /* Check for Buffer status */ 1259880af9dbSAlan Cox if (count <= 0) 12603f542974SPaul B Schroeder return; 12613f542974SPaul B Schroeder 12623f542974SPaul B Schroeder /* Block the thread for a while */ 12633f542974SPaul B Schroeder interruptible_sleep_on_timeout(&mos7840_port->wait_chase, 12643f542974SPaul B Schroeder timeout); 12653f542974SPaul B Schroeder /* No activity.. count down section */ 12663f542974SPaul B Schroeder wait--; 12673f542974SPaul B Schroeder if (wait == 0) { 12689c134a14SGreg Kroah-Hartman dev_dbg(&mos7840_port->port->dev, "%s - TIMEOUT\n", __func__); 12693f542974SPaul B Schroeder return; 12703f542974SPaul B Schroeder } else { 1271dc0d5c1eSJoe Perches /* Reset timeout value back to seconds */ 12723f542974SPaul B Schroeder wait = 10; 12733f542974SPaul B Schroeder } 12743f542974SPaul B Schroeder } 12753f542974SPaul B Schroeder 12763f542974SPaul B Schroeder } 12773f542974SPaul B Schroeder 12783f542974SPaul B Schroeder /***************************************************************************** 12793f542974SPaul B Schroeder * mos7840_break 12803f542974SPaul B Schroeder * this function sends a break to the port 12813f542974SPaul B Schroeder *****************************************************************************/ 128295da310eSAlan Cox static void mos7840_break(struct tty_struct *tty, int break_state) 12833f542974SPaul B Schroeder { 128495da310eSAlan Cox struct usb_serial_port *port = tty->driver_data; 12853f542974SPaul B Schroeder unsigned char data; 12863f542974SPaul B Schroeder struct usb_serial *serial; 12873f542974SPaul B Schroeder struct moschip_port *mos7840_port; 12883f542974SPaul B Schroeder 12899c134a14SGreg Kroah-Hartman if (mos7840_port_paranoia_check(port, __func__)) 12903f542974SPaul B Schroeder return; 12913f542974SPaul B Schroeder 1292441b62c1SHarvey Harrison serial = mos7840_get_usb_serial(port, __func__); 12939c134a14SGreg Kroah-Hartman if (!serial) 12943f542974SPaul B Schroeder return; 12953f542974SPaul B Schroeder 12963f542974SPaul B Schroeder mos7840_port = mos7840_get_port_private(port); 12973f542974SPaul B Schroeder 1298880af9dbSAlan Cox if (mos7840_port == NULL) 12993f542974SPaul B Schroeder return; 13003f542974SPaul B Schroeder 13013f542974SPaul B Schroeder /* flush and block until tx is empty */ 130295da310eSAlan Cox mos7840_block_until_chase_response(tty, mos7840_port); 13033f542974SPaul B Schroeder 130495da310eSAlan Cox if (break_state == -1) 13053f542974SPaul B Schroeder data = mos7840_port->shadowLCR | LCR_SET_BREAK; 130695da310eSAlan Cox else 13073f542974SPaul B Schroeder data = mos7840_port->shadowLCR & ~LCR_SET_BREAK; 13083f542974SPaul B Schroeder 13096b447f04SAlan Cox /* FIXME: no locking on shadowLCR anywhere in driver */ 13103f542974SPaul B Schroeder mos7840_port->shadowLCR = data; 13119c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s mos7840_port->shadowLCR is %x\n", __func__, mos7840_port->shadowLCR); 13123f542974SPaul B Schroeder mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, 13133f542974SPaul B Schroeder mos7840_port->shadowLCR); 13143f542974SPaul B Schroeder } 13153f542974SPaul B Schroeder 13163f542974SPaul B Schroeder /***************************************************************************** 13173f542974SPaul B Schroeder * mos7840_write_room 13183f542974SPaul B Schroeder * this function is called by the tty driver when it wants to know how many 13193f542974SPaul B Schroeder * bytes of data we can accept for a specific port. 13203f542974SPaul B Schroeder * If successful, we return the amount of room that we have for this port 13213f542974SPaul B Schroeder * Otherwise we return a negative error number. 13223f542974SPaul B Schroeder *****************************************************************************/ 13233f542974SPaul B Schroeder 132495da310eSAlan Cox static int mos7840_write_room(struct tty_struct *tty) 13253f542974SPaul B Schroeder { 132695da310eSAlan Cox struct usb_serial_port *port = tty->driver_data; 13273f542974SPaul B Schroeder int i; 13283f542974SPaul B Schroeder int room = 0; 13290de9a702SOliver Neukum unsigned long flags; 13303f542974SPaul B Schroeder struct moschip_port *mos7840_port; 13313f542974SPaul B Schroeder 13329c134a14SGreg Kroah-Hartman if (mos7840_port_paranoia_check(port, __func__)) 13333f542974SPaul B Schroeder return -1; 13343f542974SPaul B Schroeder 13353f542974SPaul B Schroeder mos7840_port = mos7840_get_port_private(port); 13369c134a14SGreg Kroah-Hartman if (mos7840_port == NULL) 13373f542974SPaul B Schroeder return -1; 13383f542974SPaul B Schroeder 13390de9a702SOliver Neukum spin_lock_irqsave(&mos7840_port->pool_lock, flags); 13403f542974SPaul B Schroeder for (i = 0; i < NUM_URBS; ++i) { 1341880af9dbSAlan Cox if (!mos7840_port->busy[i]) 13423f542974SPaul B Schroeder room += URB_TRANSFER_BUFFER_SIZE; 13433f542974SPaul B Schroeder } 13440de9a702SOliver Neukum spin_unlock_irqrestore(&mos7840_port->pool_lock, flags); 13453f542974SPaul B Schroeder 13460de9a702SOliver Neukum room = (room == 0) ? 0 : room - URB_TRANSFER_BUFFER_SIZE + 1; 13479c134a14SGreg Kroah-Hartman dev_dbg(&mos7840_port->port->dev, "%s - returns %d\n", __func__, room); 13480de9a702SOliver Neukum return room; 13493f542974SPaul B Schroeder 13503f542974SPaul B Schroeder } 13513f542974SPaul B Schroeder 13523f542974SPaul B Schroeder /***************************************************************************** 13533f542974SPaul B Schroeder * mos7840_write 13543f542974SPaul B Schroeder * this function is called by the tty driver when data should be written to 13553f542974SPaul B Schroeder * the port. 13563f542974SPaul B Schroeder * If successful, we return the number of bytes written, otherwise we 13573f542974SPaul B Schroeder * return a negative error number. 13583f542974SPaul B Schroeder *****************************************************************************/ 13593f542974SPaul B Schroeder 136095da310eSAlan Cox static int mos7840_write(struct tty_struct *tty, struct usb_serial_port *port, 13613f542974SPaul B Schroeder const unsigned char *data, int count) 13623f542974SPaul B Schroeder { 13633f542974SPaul B Schroeder int status; 13643f542974SPaul B Schroeder int i; 13653f542974SPaul B Schroeder int bytes_sent = 0; 13663f542974SPaul B Schroeder int transfer_size; 13670de9a702SOliver Neukum unsigned long flags; 13683f542974SPaul B Schroeder 13693f542974SPaul B Schroeder struct moschip_port *mos7840_port; 13703f542974SPaul B Schroeder struct usb_serial *serial; 13713f542974SPaul B Schroeder struct urb *urb; 1372880af9dbSAlan Cox /* __u16 Data; */ 13733f542974SPaul B Schroeder const unsigned char *current_position = data; 13743f542974SPaul B Schroeder unsigned char *data1; 13753f542974SPaul B Schroeder 13763f542974SPaul B Schroeder #ifdef NOTMOS7840 13773f542974SPaul B Schroeder Data = 0x00; 13783f542974SPaul B Schroeder status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data); 13793f542974SPaul B Schroeder mos7840_port->shadowLCR = Data; 13809c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s: LINE_CONTROL_REGISTER is %x\n", __func__, Data); 13819c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s: mos7840_port->shadowLCR is %x\n", __func__, mos7840_port->shadowLCR); 13823f542974SPaul B Schroeder 1383880af9dbSAlan Cox /* Data = 0x03; */ 1384880af9dbSAlan Cox /* status = mos7840_set_uart_reg(port,LINE_CONTROL_REGISTER,Data); */ 1385880af9dbSAlan Cox /* mos7840_port->shadowLCR=Data;//Need to add later */ 13863f542974SPaul B Schroeder 1387880af9dbSAlan Cox Data |= SERIAL_LCR_DLAB; /* data latch enable in LCR 0x80 */ 13883f542974SPaul B Schroeder status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); 13893f542974SPaul B Schroeder 1390880af9dbSAlan Cox /* Data = 0x0c; */ 1391880af9dbSAlan Cox /* status = mos7840_set_uart_reg(port,DIVISOR_LATCH_LSB,Data); */ 13923f542974SPaul B Schroeder Data = 0x00; 13933f542974SPaul B Schroeder status = mos7840_get_uart_reg(port, DIVISOR_LATCH_LSB, &Data); 13949c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s: DLL value is %x\n", __func__, Data); 13953f542974SPaul B Schroeder 13963f542974SPaul B Schroeder Data = 0x0; 13973f542974SPaul B Schroeder status = mos7840_get_uart_reg(port, DIVISOR_LATCH_MSB, &Data); 13989c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s: DLM value is %x\n", __func__, Data); 13993f542974SPaul B Schroeder 14003f542974SPaul B Schroeder Data = Data & ~SERIAL_LCR_DLAB; 14019c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s: mos7840_port->shadowLCR is %x\n", __func__, mos7840_port->shadowLCR); 14023f542974SPaul B Schroeder status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); 14033f542974SPaul B Schroeder #endif 14043f542974SPaul B Schroeder 14059c134a14SGreg Kroah-Hartman if (mos7840_port_paranoia_check(port, __func__)) 14063f542974SPaul B Schroeder return -1; 14073f542974SPaul B Schroeder 14083f542974SPaul B Schroeder serial = port->serial; 14099c134a14SGreg Kroah-Hartman if (mos7840_serial_paranoia_check(serial, __func__)) 14103f542974SPaul B Schroeder return -1; 14113f542974SPaul B Schroeder 14123f542974SPaul B Schroeder mos7840_port = mos7840_get_port_private(port); 14139c134a14SGreg Kroah-Hartman if (mos7840_port == NULL) 14143f542974SPaul B Schroeder return -1; 14153f542974SPaul B Schroeder 14163f542974SPaul B Schroeder /* try to find a free urb in the list */ 14173f542974SPaul B Schroeder urb = NULL; 14183f542974SPaul B Schroeder 14190de9a702SOliver Neukum spin_lock_irqsave(&mos7840_port->pool_lock, flags); 14203f542974SPaul B Schroeder for (i = 0; i < NUM_URBS; ++i) { 14210de9a702SOliver Neukum if (!mos7840_port->busy[i]) { 14220de9a702SOliver Neukum mos7840_port->busy[i] = 1; 14233f542974SPaul B Schroeder urb = mos7840_port->write_urb_pool[i]; 14249c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "URB:%d\n", i); 14253f542974SPaul B Schroeder break; 14263f542974SPaul B Schroeder } 14273f542974SPaul B Schroeder } 14280de9a702SOliver Neukum spin_unlock_irqrestore(&mos7840_port->pool_lock, flags); 14293f542974SPaul B Schroeder 14303f542974SPaul B Schroeder if (urb == NULL) { 14319c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s - no more free urbs\n", __func__); 14323f542974SPaul B Schroeder goto exit; 14333f542974SPaul B Schroeder } 14343f542974SPaul B Schroeder 14353f542974SPaul B Schroeder if (urb->transfer_buffer == NULL) { 14363f542974SPaul B Schroeder urb->transfer_buffer = 14373f542974SPaul B Schroeder kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL); 14383f542974SPaul B Schroeder 14393f542974SPaul B Schroeder if (urb->transfer_buffer == NULL) { 144022a416c4SJohan Hovold dev_err_console(port, "%s no more kernel memory...\n", 1441194343d9SGreg Kroah-Hartman __func__); 14423f542974SPaul B Schroeder goto exit; 14433f542974SPaul B Schroeder } 14443f542974SPaul B Schroeder } 14453f542974SPaul B Schroeder transfer_size = min(count, URB_TRANSFER_BUFFER_SIZE); 14463f542974SPaul B Schroeder 14473f542974SPaul B Schroeder memcpy(urb->transfer_buffer, current_position, transfer_size); 14483f542974SPaul B Schroeder 14493f542974SPaul B Schroeder /* fill urb with data and submit */ 14501143832eSGreg Kroah-Hartman if ((serial->num_ports == 2) && (((__u16)port->port_number % 2) != 0)) { 1451093ea2d3SDonald Lee usb_fill_bulk_urb(urb, 1452093ea2d3SDonald Lee serial->dev, 1453093ea2d3SDonald Lee usb_sndbulkpipe(serial->dev, 1454093ea2d3SDonald Lee (port->bulk_out_endpointAddress) + 2), 1455093ea2d3SDonald Lee urb->transfer_buffer, 1456093ea2d3SDonald Lee transfer_size, 1457093ea2d3SDonald Lee mos7840_bulk_out_data_callback, mos7840_port); 1458093ea2d3SDonald Lee } else { 14593f542974SPaul B Schroeder usb_fill_bulk_urb(urb, 14603f542974SPaul B Schroeder serial->dev, 14613f542974SPaul B Schroeder usb_sndbulkpipe(serial->dev, 14623f542974SPaul B Schroeder port->bulk_out_endpointAddress), 14633f542974SPaul B Schroeder urb->transfer_buffer, 14643f542974SPaul B Schroeder transfer_size, 14653f542974SPaul B Schroeder mos7840_bulk_out_data_callback, mos7840_port); 1466093ea2d3SDonald Lee } 14673f542974SPaul B Schroeder 14683f542974SPaul B Schroeder data1 = urb->transfer_buffer; 14699c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "bulkout endpoint is %d\n", port->bulk_out_endpointAddress); 14703f542974SPaul B Schroeder 14710eafe4deSDonald /* Turn on LED */ 14720eafe4deSDonald if (mos7840_port->has_led && !mos7840_port->led_flag) { 14730eafe4deSDonald mos7840_port->led_flag = true; 14740eafe4deSDonald mos7840_set_led_sync(port, MODEM_CONTROL_REGISTER, 0x0301); 14750eafe4deSDonald mod_timer(&mos7840_port->led_timer1, 14760eafe4deSDonald jiffies + msecs_to_jiffies(LED_ON_MS)); 14770eafe4deSDonald } 14780eafe4deSDonald 14793f542974SPaul B Schroeder /* send it down the pipe */ 14803f542974SPaul B Schroeder status = usb_submit_urb(urb, GFP_ATOMIC); 14813f542974SPaul B Schroeder 14823f542974SPaul B Schroeder if (status) { 14830de9a702SOliver Neukum mos7840_port->busy[i] = 0; 148422a416c4SJohan Hovold dev_err_console(port, "%s - usb_submit_urb(write bulk) failed " 1485194343d9SGreg Kroah-Hartman "with status = %d\n", __func__, status); 14863f542974SPaul B Schroeder bytes_sent = status; 14873f542974SPaul B Schroeder goto exit; 14883f542974SPaul B Schroeder } 14893f542974SPaul B Schroeder bytes_sent = transfer_size; 14908c1a07ffSJohan Hovold port->icount.tx += transfer_size; 14918c1a07ffSJohan Hovold dev_dbg(&port->dev, "icount.tx is %d:\n", port->icount.tx); 14923f542974SPaul B Schroeder exit: 14933f542974SPaul B Schroeder return bytes_sent; 14943f542974SPaul B Schroeder 14953f542974SPaul B Schroeder } 14963f542974SPaul B Schroeder 14973f542974SPaul B Schroeder /***************************************************************************** 14983f542974SPaul B Schroeder * mos7840_throttle 14993f542974SPaul B Schroeder * this function is called by the tty driver when it wants to stop the data 15003f542974SPaul B Schroeder * being read from the port. 15013f542974SPaul B Schroeder *****************************************************************************/ 15023f542974SPaul B Schroeder 150395da310eSAlan Cox static void mos7840_throttle(struct tty_struct *tty) 15043f542974SPaul B Schroeder { 150595da310eSAlan Cox struct usb_serial_port *port = tty->driver_data; 15063f542974SPaul B Schroeder struct moschip_port *mos7840_port; 15073f542974SPaul B Schroeder int status; 15083f542974SPaul B Schroeder 15099c134a14SGreg Kroah-Hartman if (mos7840_port_paranoia_check(port, __func__)) 15103f542974SPaul B Schroeder return; 15113f542974SPaul B Schroeder 15123f542974SPaul B Schroeder mos7840_port = mos7840_get_port_private(port); 15133f542974SPaul B Schroeder 15143f542974SPaul B Schroeder if (mos7840_port == NULL) 15153f542974SPaul B Schroeder return; 15163f542974SPaul B Schroeder 15173f542974SPaul B Schroeder if (!mos7840_port->open) { 15189c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s", "port not opened\n"); 15193f542974SPaul B Schroeder return; 15203f542974SPaul B Schroeder } 15213f542974SPaul B Schroeder 15223f542974SPaul B Schroeder /* if we are implementing XON/XOFF, send the stop character */ 15233f542974SPaul B Schroeder if (I_IXOFF(tty)) { 15243f542974SPaul B Schroeder unsigned char stop_char = STOP_CHAR(tty); 152595da310eSAlan Cox status = mos7840_write(tty, port, &stop_char, 1); 152695da310eSAlan Cox if (status <= 0) 15273f542974SPaul B Schroeder return; 15283f542974SPaul B Schroeder } 15293f542974SPaul B Schroeder /* if we are implementing RTS/CTS, toggle that line */ 1530adc8d746SAlan Cox if (tty->termios.c_cflag & CRTSCTS) { 15313f542974SPaul B Schroeder mos7840_port->shadowMCR &= ~MCR_RTS; 153295da310eSAlan Cox status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, 15333f542974SPaul B Schroeder mos7840_port->shadowMCR); 153495da310eSAlan Cox if (status < 0) 15353f542974SPaul B Schroeder return; 15363f542974SPaul B Schroeder } 15373f542974SPaul B Schroeder } 15383f542974SPaul B Schroeder 15393f542974SPaul B Schroeder /***************************************************************************** 15403f542974SPaul B Schroeder * mos7840_unthrottle 1541880af9dbSAlan Cox * this function is called by the tty driver when it wants to resume 1542880af9dbSAlan Cox * the data being read from the port (called after mos7840_throttle is 1543880af9dbSAlan Cox * called) 15443f542974SPaul B Schroeder *****************************************************************************/ 154595da310eSAlan Cox static void mos7840_unthrottle(struct tty_struct *tty) 15463f542974SPaul B Schroeder { 154795da310eSAlan Cox struct usb_serial_port *port = tty->driver_data; 15483f542974SPaul B Schroeder int status; 15493f542974SPaul B Schroeder struct moschip_port *mos7840_port = mos7840_get_port_private(port); 15503f542974SPaul B Schroeder 15519c134a14SGreg Kroah-Hartman if (mos7840_port_paranoia_check(port, __func__)) 15523f542974SPaul B Schroeder return; 15533f542974SPaul B Schroeder 15543f542974SPaul B Schroeder if (mos7840_port == NULL) 15553f542974SPaul B Schroeder return; 15563f542974SPaul B Schroeder 15573f542974SPaul B Schroeder if (!mos7840_port->open) { 15589c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s - port not opened\n", __func__); 15593f542974SPaul B Schroeder return; 15603f542974SPaul B Schroeder } 15613f542974SPaul B Schroeder 15623f542974SPaul B Schroeder /* if we are implementing XON/XOFF, send the start character */ 15633f542974SPaul B Schroeder if (I_IXOFF(tty)) { 15643f542974SPaul B Schroeder unsigned char start_char = START_CHAR(tty); 156595da310eSAlan Cox status = mos7840_write(tty, port, &start_char, 1); 156695da310eSAlan Cox if (status <= 0) 15673f542974SPaul B Schroeder return; 15683f542974SPaul B Schroeder } 15693f542974SPaul B Schroeder 15703f542974SPaul B Schroeder /* if we are implementing RTS/CTS, toggle that line */ 1571adc8d746SAlan Cox if (tty->termios.c_cflag & CRTSCTS) { 15723f542974SPaul B Schroeder mos7840_port->shadowMCR |= MCR_RTS; 157395da310eSAlan Cox status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, 15743f542974SPaul B Schroeder mos7840_port->shadowMCR); 157595da310eSAlan Cox if (status < 0) 15763f542974SPaul B Schroeder return; 15773f542974SPaul B Schroeder } 15783f542974SPaul B Schroeder } 15793f542974SPaul B Schroeder 158060b33c13SAlan Cox static int mos7840_tiocmget(struct tty_struct *tty) 15813f542974SPaul B Schroeder { 158295da310eSAlan Cox struct usb_serial_port *port = tty->driver_data; 15833f542974SPaul B Schroeder struct moschip_port *mos7840_port; 15843f542974SPaul B Schroeder unsigned int result; 15853f542974SPaul B Schroeder __u16 msr; 15863f542974SPaul B Schroeder __u16 mcr; 1587880af9dbSAlan Cox int status; 15883f542974SPaul B Schroeder mos7840_port = mos7840_get_port_private(port); 15893f542974SPaul B Schroeder 15903f542974SPaul B Schroeder if (mos7840_port == NULL) 15913f542974SPaul B Schroeder return -ENODEV; 15923f542974SPaul B Schroeder 15933f542974SPaul B Schroeder status = mos7840_get_uart_reg(port, MODEM_STATUS_REGISTER, &msr); 15943f542974SPaul B Schroeder status = mos7840_get_uart_reg(port, MODEM_CONTROL_REGISTER, &mcr); 15953f542974SPaul B Schroeder result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0) 15963f542974SPaul B Schroeder | ((mcr & MCR_RTS) ? TIOCM_RTS : 0) 15973f542974SPaul B Schroeder | ((mcr & MCR_LOOPBACK) ? TIOCM_LOOP : 0) 15983f542974SPaul B Schroeder | ((msr & MOS7840_MSR_CTS) ? TIOCM_CTS : 0) 15993f542974SPaul B Schroeder | ((msr & MOS7840_MSR_CD) ? TIOCM_CAR : 0) 16003f542974SPaul B Schroeder | ((msr & MOS7840_MSR_RI) ? TIOCM_RI : 0) 16013f542974SPaul B Schroeder | ((msr & MOS7840_MSR_DSR) ? TIOCM_DSR : 0); 16023f542974SPaul B Schroeder 16039c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s - 0x%04X\n", __func__, result); 16043f542974SPaul B Schroeder 16053f542974SPaul B Schroeder return result; 16063f542974SPaul B Schroeder } 16073f542974SPaul B Schroeder 160820b9d177SAlan Cox static int mos7840_tiocmset(struct tty_struct *tty, 16093f542974SPaul B Schroeder unsigned int set, unsigned int clear) 16103f542974SPaul B Schroeder { 161195da310eSAlan Cox struct usb_serial_port *port = tty->driver_data; 16123f542974SPaul B Schroeder struct moschip_port *mos7840_port; 16133f542974SPaul B Schroeder unsigned int mcr; 161487521c46SRoel Kluin int status; 16153f542974SPaul B Schroeder 16163f542974SPaul B Schroeder mos7840_port = mos7840_get_port_private(port); 16173f542974SPaul B Schroeder 16183f542974SPaul B Schroeder if (mos7840_port == NULL) 16193f542974SPaul B Schroeder return -ENODEV; 16203f542974SPaul B Schroeder 1621e2984494SAlan Cox /* FIXME: What locks the port registers ? */ 16223f542974SPaul B Schroeder mcr = mos7840_port->shadowMCR; 16233f542974SPaul B Schroeder if (clear & TIOCM_RTS) 16243f542974SPaul B Schroeder mcr &= ~MCR_RTS; 16253f542974SPaul B Schroeder if (clear & TIOCM_DTR) 16263f542974SPaul B Schroeder mcr &= ~MCR_DTR; 16273f542974SPaul B Schroeder if (clear & TIOCM_LOOP) 16283f542974SPaul B Schroeder mcr &= ~MCR_LOOPBACK; 16293f542974SPaul B Schroeder 16303f542974SPaul B Schroeder if (set & TIOCM_RTS) 16313f542974SPaul B Schroeder mcr |= MCR_RTS; 16323f542974SPaul B Schroeder if (set & TIOCM_DTR) 16333f542974SPaul B Schroeder mcr |= MCR_DTR; 16343f542974SPaul B Schroeder if (set & TIOCM_LOOP) 16353f542974SPaul B Schroeder mcr |= MCR_LOOPBACK; 16363f542974SPaul B Schroeder 16373f542974SPaul B Schroeder mos7840_port->shadowMCR = mcr; 16383f542974SPaul B Schroeder 16393f542974SPaul B Schroeder status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, mcr); 16403f542974SPaul B Schroeder if (status < 0) { 16419c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "setting MODEM_CONTROL_REGISTER Failed\n"); 164287521c46SRoel Kluin return status; 16433f542974SPaul B Schroeder } 16443f542974SPaul B Schroeder 16453f542974SPaul B Schroeder return 0; 16463f542974SPaul B Schroeder } 16473f542974SPaul B Schroeder 16483f542974SPaul B Schroeder /***************************************************************************** 16493f542974SPaul B Schroeder * mos7840_calc_baud_rate_divisor 16503f542974SPaul B Schroeder * this function calculates the proper baud rate divisor for the specified 16513f542974SPaul B Schroeder * baud rate. 16523f542974SPaul B Schroeder *****************************************************************************/ 16539c134a14SGreg Kroah-Hartman static int mos7840_calc_baud_rate_divisor(struct usb_serial_port *port, 16549c134a14SGreg Kroah-Hartman int baudRate, int *divisor, 16553f542974SPaul B Schroeder __u16 *clk_sel_val) 16563f542974SPaul B Schroeder { 16579c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s - %d\n", __func__, baudRate); 16583f542974SPaul B Schroeder 16593f542974SPaul B Schroeder if (baudRate <= 115200) { 16603f542974SPaul B Schroeder *divisor = 115200 / baudRate; 16613f542974SPaul B Schroeder *clk_sel_val = 0x0; 16623f542974SPaul B Schroeder } 16633f542974SPaul B Schroeder if ((baudRate > 115200) && (baudRate <= 230400)) { 16643f542974SPaul B Schroeder *divisor = 230400 / baudRate; 16653f542974SPaul B Schroeder *clk_sel_val = 0x10; 16663f542974SPaul B Schroeder } else if ((baudRate > 230400) && (baudRate <= 403200)) { 16673f542974SPaul B Schroeder *divisor = 403200 / baudRate; 16683f542974SPaul B Schroeder *clk_sel_val = 0x20; 16693f542974SPaul B Schroeder } else if ((baudRate > 403200) && (baudRate <= 460800)) { 16703f542974SPaul B Schroeder *divisor = 460800 / baudRate; 16713f542974SPaul B Schroeder *clk_sel_val = 0x30; 16723f542974SPaul B Schroeder } else if ((baudRate > 460800) && (baudRate <= 806400)) { 16733f542974SPaul B Schroeder *divisor = 806400 / baudRate; 16743f542974SPaul B Schroeder *clk_sel_val = 0x40; 16753f542974SPaul B Schroeder } else if ((baudRate > 806400) && (baudRate <= 921600)) { 16763f542974SPaul B Schroeder *divisor = 921600 / baudRate; 16773f542974SPaul B Schroeder *clk_sel_val = 0x50; 16783f542974SPaul B Schroeder } else if ((baudRate > 921600) && (baudRate <= 1572864)) { 16793f542974SPaul B Schroeder *divisor = 1572864 / baudRate; 16803f542974SPaul B Schroeder *clk_sel_val = 0x60; 16813f542974SPaul B Schroeder } else if ((baudRate > 1572864) && (baudRate <= 3145728)) { 16823f542974SPaul B Schroeder *divisor = 3145728 / baudRate; 16833f542974SPaul B Schroeder *clk_sel_val = 0x70; 16843f542974SPaul B Schroeder } 16853f542974SPaul B Schroeder return 0; 16863f542974SPaul B Schroeder 16873f542974SPaul B Schroeder #ifdef NOTMCS7840 16883f542974SPaul B Schroeder 16893f542974SPaul B Schroeder for (i = 0; i < ARRAY_SIZE(mos7840_divisor_table); i++) { 16903f542974SPaul B Schroeder if (mos7840_divisor_table[i].BaudRate == baudrate) { 16913f542974SPaul B Schroeder *divisor = mos7840_divisor_table[i].Divisor; 16923f542974SPaul B Schroeder return 0; 16933f542974SPaul B Schroeder } 16943f542974SPaul B Schroeder } 16953f542974SPaul B Schroeder 16963f542974SPaul B Schroeder /* After trying for all the standard baud rates * 16973f542974SPaul B Schroeder * Try calculating the divisor for this baud rate */ 16983f542974SPaul B Schroeder 16993f542974SPaul B Schroeder if (baudrate > 75 && baudrate < 230400) { 17003f542974SPaul B Schroeder /* get the divisor */ 17013f542974SPaul B Schroeder custom = (__u16) (230400L / baudrate); 17023f542974SPaul B Schroeder 17033f542974SPaul B Schroeder /* Check for round off */ 17043f542974SPaul B Schroeder round1 = (__u16) (2304000L / baudrate); 17053f542974SPaul B Schroeder round = (__u16) (round1 - (custom * 10)); 1706880af9dbSAlan Cox if (round > 4) 17073f542974SPaul B Schroeder custom++; 17083f542974SPaul B Schroeder *divisor = custom; 17093f542974SPaul B Schroeder 17109c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, " Baud %d = %d\n", baudrate, custom); 17113f542974SPaul B Schroeder return 0; 17123f542974SPaul B Schroeder } 17133f542974SPaul B Schroeder 17149c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s", " Baud calculation Failed...\n"); 17153f542974SPaul B Schroeder return -1; 17163f542974SPaul B Schroeder #endif 17173f542974SPaul B Schroeder } 17183f542974SPaul B Schroeder 17193f542974SPaul B Schroeder /***************************************************************************** 17203f542974SPaul B Schroeder * mos7840_send_cmd_write_baud_rate 17213f542974SPaul B Schroeder * this function sends the proper command to change the baud rate of the 17223f542974SPaul B Schroeder * specified port. 17233f542974SPaul B Schroeder *****************************************************************************/ 17243f542974SPaul B Schroeder 17253f542974SPaul B Schroeder static int mos7840_send_cmd_write_baud_rate(struct moschip_port *mos7840_port, 17263f542974SPaul B Schroeder int baudRate) 17273f542974SPaul B Schroeder { 17283f542974SPaul B Schroeder int divisor = 0; 17293f542974SPaul B Schroeder int status; 17303f542974SPaul B Schroeder __u16 Data; 17313f542974SPaul B Schroeder unsigned char number; 17323f542974SPaul B Schroeder __u16 clk_sel_val; 17333f542974SPaul B Schroeder struct usb_serial_port *port; 17343f542974SPaul B Schroeder 17353f542974SPaul B Schroeder if (mos7840_port == NULL) 17363f542974SPaul B Schroeder return -1; 17373f542974SPaul B Schroeder 17389c134a14SGreg Kroah-Hartman port = mos7840_port->port; 17399c134a14SGreg Kroah-Hartman if (mos7840_port_paranoia_check(port, __func__)) 17403f542974SPaul B Schroeder return -1; 17413f542974SPaul B Schroeder 17429c134a14SGreg Kroah-Hartman if (mos7840_serial_paranoia_check(port->serial, __func__)) 17433f542974SPaul B Schroeder return -1; 17443f542974SPaul B Schroeder 17451143832eSGreg Kroah-Hartman number = mos7840_port->port->port_number; 17463f542974SPaul B Schroeder 17471143832eSGreg Kroah-Hartman dev_dbg(&port->dev, "%s - baud = %d\n", __func__, baudRate); 1748880af9dbSAlan Cox /* reset clk_uart_sel in spregOffset */ 17493f542974SPaul B Schroeder if (baudRate > 115200) { 17503f542974SPaul B Schroeder #ifdef HW_flow_control 1751880af9dbSAlan Cox /* NOTE: need to see the pther register to modify */ 1752880af9dbSAlan Cox /* setting h/w flow control bit to 1 */ 17533f542974SPaul B Schroeder Data = 0x2b; 17543f542974SPaul B Schroeder mos7840_port->shadowMCR = Data; 1755880af9dbSAlan Cox status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, 1756880af9dbSAlan Cox Data); 17573f542974SPaul B Schroeder if (status < 0) { 17589c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "Writing spreg failed in set_serial_baud\n"); 17593f542974SPaul B Schroeder return -1; 17603f542974SPaul B Schroeder } 17613f542974SPaul B Schroeder #endif 17623f542974SPaul B Schroeder 17633f542974SPaul B Schroeder } else { 17643f542974SPaul B Schroeder #ifdef HW_flow_control 1765880af9dbSAlan Cox /* setting h/w flow control bit to 0 */ 17663f542974SPaul B Schroeder Data = 0xb; 17673f542974SPaul B Schroeder mos7840_port->shadowMCR = Data; 1768880af9dbSAlan Cox status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, 1769880af9dbSAlan Cox Data); 17703f542974SPaul B Schroeder if (status < 0) { 17719c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "Writing spreg failed in set_serial_baud\n"); 17723f542974SPaul B Schroeder return -1; 17733f542974SPaul B Schroeder } 17743f542974SPaul B Schroeder #endif 17753f542974SPaul B Schroeder 17763f542974SPaul B Schroeder } 17773f542974SPaul B Schroeder 1778880af9dbSAlan Cox if (1) { /* baudRate <= 115200) */ 17793f542974SPaul B Schroeder clk_sel_val = 0x0; 17803f542974SPaul B Schroeder Data = 0x0; 17819c134a14SGreg Kroah-Hartman status = mos7840_calc_baud_rate_divisor(port, baudRate, &divisor, 17823f542974SPaul B Schroeder &clk_sel_val); 1783880af9dbSAlan Cox status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, 17843f542974SPaul B Schroeder &Data); 17853f542974SPaul B Schroeder if (status < 0) { 17869c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "reading spreg failed in set_serial_baud\n"); 17873f542974SPaul B Schroeder return -1; 17883f542974SPaul B Schroeder } 17893f542974SPaul B Schroeder Data = (Data & 0x8f) | clk_sel_val; 1790880af9dbSAlan Cox status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, 1791880af9dbSAlan Cox Data); 17923f542974SPaul B Schroeder if (status < 0) { 17939c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "Writing spreg failed in set_serial_baud\n"); 17943f542974SPaul B Schroeder return -1; 17953f542974SPaul B Schroeder } 17963f542974SPaul B Schroeder /* Calculate the Divisor */ 17973f542974SPaul B Schroeder 17983f542974SPaul B Schroeder if (status) { 1799194343d9SGreg Kroah-Hartman dev_err(&port->dev, "%s - bad baud rate\n", __func__); 18003f542974SPaul B Schroeder return status; 18013f542974SPaul B Schroeder } 18023f542974SPaul B Schroeder /* Enable access to divisor latch */ 18033f542974SPaul B Schroeder Data = mos7840_port->shadowLCR | SERIAL_LCR_DLAB; 18043f542974SPaul B Schroeder mos7840_port->shadowLCR = Data; 18053f542974SPaul B Schroeder mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); 18063f542974SPaul B Schroeder 18073f542974SPaul B Schroeder /* Write the divisor */ 18083f542974SPaul B Schroeder Data = (unsigned char)(divisor & 0xff); 18099c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "set_serial_baud Value to write DLL is %x\n", Data); 18103f542974SPaul B Schroeder mos7840_set_uart_reg(port, DIVISOR_LATCH_LSB, Data); 18113f542974SPaul B Schroeder 18123f542974SPaul B Schroeder Data = (unsigned char)((divisor & 0xff00) >> 8); 18139c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "set_serial_baud Value to write DLM is %x\n", Data); 18143f542974SPaul B Schroeder mos7840_set_uart_reg(port, DIVISOR_LATCH_MSB, Data); 18153f542974SPaul B Schroeder 18163f542974SPaul B Schroeder /* Disable access to divisor latch */ 18173f542974SPaul B Schroeder Data = mos7840_port->shadowLCR & ~SERIAL_LCR_DLAB; 18183f542974SPaul B Schroeder mos7840_port->shadowLCR = Data; 18193f542974SPaul B Schroeder mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); 18203f542974SPaul B Schroeder 18213f542974SPaul B Schroeder } 18223f542974SPaul B Schroeder return status; 18233f542974SPaul B Schroeder } 18243f542974SPaul B Schroeder 18253f542974SPaul B Schroeder /***************************************************************************** 18263f542974SPaul B Schroeder * mos7840_change_port_settings 18273f542974SPaul B Schroeder * This routine is called to set the UART on the device to match 18283f542974SPaul B Schroeder * the specified new settings. 18293f542974SPaul B Schroeder *****************************************************************************/ 18303f542974SPaul B Schroeder 183195da310eSAlan Cox static void mos7840_change_port_settings(struct tty_struct *tty, 183295da310eSAlan Cox struct moschip_port *mos7840_port, struct ktermios *old_termios) 18333f542974SPaul B Schroeder { 18343f542974SPaul B Schroeder int baud; 18353f542974SPaul B Schroeder unsigned cflag; 18363f542974SPaul B Schroeder unsigned iflag; 18373f542974SPaul B Schroeder __u8 lData; 18383f542974SPaul B Schroeder __u8 lParity; 18393f542974SPaul B Schroeder __u8 lStop; 18403f542974SPaul B Schroeder int status; 18413f542974SPaul B Schroeder __u16 Data; 18423f542974SPaul B Schroeder struct usb_serial_port *port; 18433f542974SPaul B Schroeder struct usb_serial *serial; 18443f542974SPaul B Schroeder 18453f542974SPaul B Schroeder if (mos7840_port == NULL) 18463f542974SPaul B Schroeder return; 18473f542974SPaul B Schroeder 18489c134a14SGreg Kroah-Hartman port = mos7840_port->port; 18493f542974SPaul B Schroeder 18509c134a14SGreg Kroah-Hartman if (mos7840_port_paranoia_check(port, __func__)) 18513f542974SPaul B Schroeder return; 18523f542974SPaul B Schroeder 18539c134a14SGreg Kroah-Hartman if (mos7840_serial_paranoia_check(port->serial, __func__)) 18543f542974SPaul B Schroeder return; 18553f542974SPaul B Schroeder 18563f542974SPaul B Schroeder serial = port->serial; 18573f542974SPaul B Schroeder 18583f542974SPaul B Schroeder if (!mos7840_port->open) { 18599c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s - port not opened\n", __func__); 18603f542974SPaul B Schroeder return; 18613f542974SPaul B Schroeder } 18623f542974SPaul B Schroeder 18633f542974SPaul B Schroeder lData = LCR_BITS_8; 18643f542974SPaul B Schroeder lStop = LCR_STOP_1; 18653f542974SPaul B Schroeder lParity = LCR_PAR_NONE; 18663f542974SPaul B Schroeder 1867adc8d746SAlan Cox cflag = tty->termios.c_cflag; 1868adc8d746SAlan Cox iflag = tty->termios.c_iflag; 18693f542974SPaul B Schroeder 18703f542974SPaul B Schroeder /* Change the number of bits */ 18713f542974SPaul B Schroeder if (cflag & CSIZE) { 18723f542974SPaul B Schroeder switch (cflag & CSIZE) { 18733f542974SPaul B Schroeder case CS5: 18743f542974SPaul B Schroeder lData = LCR_BITS_5; 18753f542974SPaul B Schroeder break; 18763f542974SPaul B Schroeder 18773f542974SPaul B Schroeder case CS6: 18783f542974SPaul B Schroeder lData = LCR_BITS_6; 18793f542974SPaul B Schroeder break; 18803f542974SPaul B Schroeder 18813f542974SPaul B Schroeder case CS7: 18823f542974SPaul B Schroeder lData = LCR_BITS_7; 18833f542974SPaul B Schroeder break; 18843f542974SPaul B Schroeder default: 18853f542974SPaul B Schroeder case CS8: 18863f542974SPaul B Schroeder lData = LCR_BITS_8; 18873f542974SPaul B Schroeder break; 18883f542974SPaul B Schroeder } 18893f542974SPaul B Schroeder } 18903f542974SPaul B Schroeder /* Change the Parity bit */ 18913f542974SPaul B Schroeder if (cflag & PARENB) { 18923f542974SPaul B Schroeder if (cflag & PARODD) { 18933f542974SPaul B Schroeder lParity = LCR_PAR_ODD; 18949c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s - parity = odd\n", __func__); 18953f542974SPaul B Schroeder } else { 18963f542974SPaul B Schroeder lParity = LCR_PAR_EVEN; 18979c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s - parity = even\n", __func__); 18983f542974SPaul B Schroeder } 18993f542974SPaul B Schroeder 19003f542974SPaul B Schroeder } else { 19019c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s - parity = none\n", __func__); 19023f542974SPaul B Schroeder } 19033f542974SPaul B Schroeder 1904880af9dbSAlan Cox if (cflag & CMSPAR) 19053f542974SPaul B Schroeder lParity = lParity | 0x20; 19063f542974SPaul B Schroeder 19073f542974SPaul B Schroeder /* Change the Stop bit */ 19083f542974SPaul B Schroeder if (cflag & CSTOPB) { 19093f542974SPaul B Schroeder lStop = LCR_STOP_2; 19109c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s - stop bits = 2\n", __func__); 19113f542974SPaul B Schroeder } else { 19123f542974SPaul B Schroeder lStop = LCR_STOP_1; 19139c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s - stop bits = 1\n", __func__); 19143f542974SPaul B Schroeder } 19153f542974SPaul B Schroeder 19163f542974SPaul B Schroeder /* Update the LCR with the correct value */ 19173f542974SPaul B Schroeder mos7840_port->shadowLCR &= 19183f542974SPaul B Schroeder ~(LCR_BITS_MASK | LCR_STOP_MASK | LCR_PAR_MASK); 19193f542974SPaul B Schroeder mos7840_port->shadowLCR |= (lData | lParity | lStop); 19203f542974SPaul B Schroeder 19219c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s - mos7840_port->shadowLCR is %x\n", __func__, 19223f542974SPaul B Schroeder mos7840_port->shadowLCR); 19233f542974SPaul B Schroeder /* Disable Interrupts */ 19243f542974SPaul B Schroeder Data = 0x00; 19253f542974SPaul B Schroeder mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data); 19263f542974SPaul B Schroeder 19273f542974SPaul B Schroeder Data = 0x00; 19283f542974SPaul B Schroeder mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data); 19293f542974SPaul B Schroeder 19303f542974SPaul B Schroeder Data = 0xcf; 19313f542974SPaul B Schroeder mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data); 19323f542974SPaul B Schroeder 19333f542974SPaul B Schroeder /* Send the updated LCR value to the mos7840 */ 19343f542974SPaul B Schroeder Data = mos7840_port->shadowLCR; 19353f542974SPaul B Schroeder 19363f542974SPaul B Schroeder mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); 19373f542974SPaul B Schroeder 19383f542974SPaul B Schroeder Data = 0x00b; 19393f542974SPaul B Schroeder mos7840_port->shadowMCR = Data; 19403f542974SPaul B Schroeder mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); 19413f542974SPaul B Schroeder Data = 0x00b; 19423f542974SPaul B Schroeder mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); 19433f542974SPaul B Schroeder 19443f542974SPaul B Schroeder /* set up the MCR register and send it to the mos7840 */ 19453f542974SPaul B Schroeder 19463f542974SPaul B Schroeder mos7840_port->shadowMCR = MCR_MASTER_IE; 1947880af9dbSAlan Cox if (cflag & CBAUD) 19483f542974SPaul B Schroeder mos7840_port->shadowMCR |= (MCR_DTR | MCR_RTS); 19493f542974SPaul B Schroeder 1950880af9dbSAlan Cox if (cflag & CRTSCTS) 19513f542974SPaul B Schroeder mos7840_port->shadowMCR |= (MCR_XON_ANY); 1952880af9dbSAlan Cox else 19533f542974SPaul B Schroeder mos7840_port->shadowMCR &= ~(MCR_XON_ANY); 19543f542974SPaul B Schroeder 19553f542974SPaul B Schroeder Data = mos7840_port->shadowMCR; 19563f542974SPaul B Schroeder mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); 19573f542974SPaul B Schroeder 19583f542974SPaul B Schroeder /* Determine divisor based on baud rate */ 19593f542974SPaul B Schroeder baud = tty_get_baud_rate(tty); 19603f542974SPaul B Schroeder 19613f542974SPaul B Schroeder if (!baud) { 19623f542974SPaul B Schroeder /* pick a default, any default... */ 19639c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s", "Picked default baud...\n"); 19643f542974SPaul B Schroeder baud = 9600; 19653f542974SPaul B Schroeder } 19663f542974SPaul B Schroeder 19679c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s - baud rate = %d\n", __func__, baud); 19683f542974SPaul B Schroeder status = mos7840_send_cmd_write_baud_rate(mos7840_port, baud); 19693f542974SPaul B Schroeder 19703f542974SPaul B Schroeder /* Enable Interrupts */ 19713f542974SPaul B Schroeder Data = 0x0c; 19723f542974SPaul B Schroeder mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data); 19733f542974SPaul B Schroeder 197450de36f7SGreg Kroah-Hartman if (mos7840_port->read_urb_busy == false) { 197550de36f7SGreg Kroah-Hartman mos7840_port->read_urb_busy = true; 19763f542974SPaul B Schroeder status = usb_submit_urb(mos7840_port->read_urb, GFP_ATOMIC); 19773f542974SPaul B Schroeder if (status) { 19789c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "usb_submit_urb(read bulk) failed, status = %d\n", 19793f542974SPaul B Schroeder status); 198050de36f7SGreg Kroah-Hartman mos7840_port->read_urb_busy = false; 19813f542974SPaul B Schroeder } 19823f542974SPaul B Schroeder } 19839c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s - mos7840_port->shadowLCR is End %x\n", __func__, 19843f542974SPaul B Schroeder mos7840_port->shadowLCR); 19853f542974SPaul B Schroeder } 19863f542974SPaul B Schroeder 19873f542974SPaul B Schroeder /***************************************************************************** 19883f542974SPaul B Schroeder * mos7840_set_termios 19893f542974SPaul B Schroeder * this function is called by the tty driver when it wants to change 19903f542974SPaul B Schroeder * the termios structure 19913f542974SPaul B Schroeder *****************************************************************************/ 19923f542974SPaul B Schroeder 199395da310eSAlan Cox static void mos7840_set_termios(struct tty_struct *tty, 199495da310eSAlan Cox struct usb_serial_port *port, 1995606d099cSAlan Cox struct ktermios *old_termios) 19963f542974SPaul B Schroeder { 19973f542974SPaul B Schroeder int status; 19983f542974SPaul B Schroeder unsigned int cflag; 19993f542974SPaul B Schroeder struct usb_serial *serial; 20003f542974SPaul B Schroeder struct moschip_port *mos7840_port; 20013363155bSGreg Kroah-Hartman 20029c134a14SGreg Kroah-Hartman if (mos7840_port_paranoia_check(port, __func__)) 20033f542974SPaul B Schroeder return; 20043f542974SPaul B Schroeder 20053f542974SPaul B Schroeder serial = port->serial; 20063f542974SPaul B Schroeder 20079c134a14SGreg Kroah-Hartman if (mos7840_serial_paranoia_check(serial, __func__)) 20083f542974SPaul B Schroeder return; 20093f542974SPaul B Schroeder 20103f542974SPaul B Schroeder mos7840_port = mos7840_get_port_private(port); 20113f542974SPaul B Schroeder 20123f542974SPaul B Schroeder if (mos7840_port == NULL) 20133f542974SPaul B Schroeder return; 20143f542974SPaul B Schroeder 20153f542974SPaul B Schroeder if (!mos7840_port->open) { 20169c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s - port not opened\n", __func__); 20173f542974SPaul B Schroeder return; 20183f542974SPaul B Schroeder } 20193f542974SPaul B Schroeder 20209c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s", "setting termios - \n"); 20213f542974SPaul B Schroeder 2022adc8d746SAlan Cox cflag = tty->termios.c_cflag; 20233f542974SPaul B Schroeder 20249c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s - clfag %08x iflag %08x\n", __func__, 2025adc8d746SAlan Cox tty->termios.c_cflag, RELEVANT_IFLAG(tty->termios.c_iflag)); 20269c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s - old clfag %08x old iflag %08x\n", __func__, 20273f542974SPaul B Schroeder old_termios->c_cflag, RELEVANT_IFLAG(old_termios->c_iflag)); 20283f542974SPaul B Schroeder 20293f542974SPaul B Schroeder /* change the port settings to the new ones specified */ 20303f542974SPaul B Schroeder 203195da310eSAlan Cox mos7840_change_port_settings(tty, mos7840_port, old_termios); 20323f542974SPaul B Schroeder 20333f542974SPaul B Schroeder if (!mos7840_port->read_urb) { 20349c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s", "URB KILLED !!!!!\n"); 20353f542974SPaul B Schroeder return; 20363f542974SPaul B Schroeder } 20373f542974SPaul B Schroeder 203850de36f7SGreg Kroah-Hartman if (mos7840_port->read_urb_busy == false) { 203950de36f7SGreg Kroah-Hartman mos7840_port->read_urb_busy = true; 20403f542974SPaul B Schroeder status = usb_submit_urb(mos7840_port->read_urb, GFP_ATOMIC); 20413f542974SPaul B Schroeder if (status) { 20429c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "usb_submit_urb(read bulk) failed, status = %d\n", 20433f542974SPaul B Schroeder status); 204450de36f7SGreg Kroah-Hartman mos7840_port->read_urb_busy = false; 20453f542974SPaul B Schroeder } 20463f542974SPaul B Schroeder } 20473f542974SPaul B Schroeder } 20483f542974SPaul B Schroeder 20493f542974SPaul B Schroeder /***************************************************************************** 20503f542974SPaul B Schroeder * mos7840_get_lsr_info - get line status register info 20513f542974SPaul B Schroeder * 20523f542974SPaul B Schroeder * Purpose: Let user call ioctl() to get info when the UART physically 20533f542974SPaul B Schroeder * is emptied. On bus types like RS485, the transmitter must 20543f542974SPaul B Schroeder * release the bus after transmitting. This must be done when 20553f542974SPaul B Schroeder * the transmit shift register is empty, not be done when the 20563f542974SPaul B Schroeder * transmit holding register is empty. This functionality 20573f542974SPaul B Schroeder * allows an RS485 driver to be written in user space. 20583f542974SPaul B Schroeder *****************************************************************************/ 20593f542974SPaul B Schroeder 206095da310eSAlan Cox static int mos7840_get_lsr_info(struct tty_struct *tty, 206197c4965dSAl Viro unsigned int __user *value) 20623f542974SPaul B Schroeder { 20633f542974SPaul B Schroeder int count; 20643f542974SPaul B Schroeder unsigned int result = 0; 20653f542974SPaul B Schroeder 206695da310eSAlan Cox count = mos7840_chars_in_buffer(tty); 20679c134a14SGreg Kroah-Hartman if (count == 0) 20683f542974SPaul B Schroeder result = TIOCSER_TEMT; 20693f542974SPaul B Schroeder 20703f542974SPaul B Schroeder if (copy_to_user(value, &result, sizeof(int))) 20713f542974SPaul B Schroeder return -EFAULT; 20723f542974SPaul B Schroeder return 0; 20733f542974SPaul B Schroeder } 20743f542974SPaul B Schroeder 20753f542974SPaul B Schroeder /***************************************************************************** 20763f542974SPaul B Schroeder * mos7840_get_serial_info 20773f542974SPaul B Schroeder * function to get information about serial port 20783f542974SPaul B Schroeder *****************************************************************************/ 20793f542974SPaul B Schroeder 20803f542974SPaul B Schroeder static int mos7840_get_serial_info(struct moschip_port *mos7840_port, 208197c4965dSAl Viro struct serial_struct __user *retinfo) 20823f542974SPaul B Schroeder { 20833f542974SPaul B Schroeder struct serial_struct tmp; 20843f542974SPaul B Schroeder 20853f542974SPaul B Schroeder if (mos7840_port == NULL) 20863f542974SPaul B Schroeder return -1; 20873f542974SPaul B Schroeder 20883f542974SPaul B Schroeder if (!retinfo) 20893f542974SPaul B Schroeder return -EFAULT; 20903f542974SPaul B Schroeder 20913f542974SPaul B Schroeder memset(&tmp, 0, sizeof(tmp)); 20923f542974SPaul B Schroeder 20933f542974SPaul B Schroeder tmp.type = PORT_16550A; 2094e5b1e206SGreg Kroah-Hartman tmp.line = mos7840_port->port->minor; 20951143832eSGreg Kroah-Hartman tmp.port = mos7840_port->port->port_number; 20963f542974SPaul B Schroeder tmp.irq = 0; 20973f542974SPaul B Schroeder tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ; 20983f542974SPaul B Schroeder tmp.xmit_fifo_size = NUM_URBS * URB_TRANSFER_BUFFER_SIZE; 20993f542974SPaul B Schroeder tmp.baud_base = 9600; 21003f542974SPaul B Schroeder tmp.close_delay = 5 * HZ; 21013f542974SPaul B Schroeder tmp.closing_wait = 30 * HZ; 21023f542974SPaul B Schroeder 21033f542974SPaul B Schroeder if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) 21043f542974SPaul B Schroeder return -EFAULT; 21053f542974SPaul B Schroeder return 0; 21063f542974SPaul B Schroeder } 21073f542974SPaul B Schroeder 21083f542974SPaul B Schroeder /***************************************************************************** 21093f542974SPaul B Schroeder * SerialIoctl 21103f542974SPaul B Schroeder * this function handles any ioctl calls to the driver 21113f542974SPaul B Schroeder *****************************************************************************/ 21123f542974SPaul B Schroeder 211300a0d0d6SAlan Cox static int mos7840_ioctl(struct tty_struct *tty, 21143f542974SPaul B Schroeder unsigned int cmd, unsigned long arg) 21153f542974SPaul B Schroeder { 211695da310eSAlan Cox struct usb_serial_port *port = tty->driver_data; 211797c4965dSAl Viro void __user *argp = (void __user *)arg; 21183f542974SPaul B Schroeder struct moschip_port *mos7840_port; 21193f542974SPaul B Schroeder 21209c134a14SGreg Kroah-Hartman if (mos7840_port_paranoia_check(port, __func__)) 21213f542974SPaul B Schroeder return -1; 21223f542974SPaul B Schroeder 21233f542974SPaul B Schroeder mos7840_port = mos7840_get_port_private(port); 21243f542974SPaul B Schroeder 21253f542974SPaul B Schroeder if (mos7840_port == NULL) 21263f542974SPaul B Schroeder return -1; 21273f542974SPaul B Schroeder 21289c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s - cmd = 0x%x\n", __func__, cmd); 21293f542974SPaul B Schroeder 21303f542974SPaul B Schroeder switch (cmd) { 21313f542974SPaul B Schroeder /* return number of bytes available */ 21323f542974SPaul B Schroeder 21333f542974SPaul B Schroeder case TIOCSERGETLSR: 21349c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s TIOCSERGETLSR\n", __func__); 213595da310eSAlan Cox return mos7840_get_lsr_info(tty, argp); 21363f542974SPaul B Schroeder 21373f542974SPaul B Schroeder case TIOCGSERIAL: 21389c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s TIOCGSERIAL\n", __func__); 213997c4965dSAl Viro return mos7840_get_serial_info(mos7840_port, argp); 21403f542974SPaul B Schroeder 21413f542974SPaul B Schroeder case TIOCSSERIAL: 21429c134a14SGreg Kroah-Hartman dev_dbg(&port->dev, "%s TIOCSSERIAL\n", __func__); 21433f542974SPaul B Schroeder break; 21443f542974SPaul B Schroeder default: 21453f542974SPaul B Schroeder break; 21463f542974SPaul B Schroeder } 21473f542974SPaul B Schroeder return -ENOIOCTLCMD; 21483f542974SPaul B Schroeder } 21493f542974SPaul B Schroeder 21500eafe4deSDonald static int mos7810_check(struct usb_serial *serial) 21513f542974SPaul B Schroeder { 21520eafe4deSDonald int i, pass_count = 0; 215315ee89c3SJohan Hovold u8 *buf; 21540eafe4deSDonald __u16 data = 0, mcr_data = 0; 21550eafe4deSDonald __u16 test_pattern = 0x55AA; 215615ee89c3SJohan Hovold int res; 215715ee89c3SJohan Hovold 215815ee89c3SJohan Hovold buf = kmalloc(VENDOR_READ_LENGTH, GFP_KERNEL); 215915ee89c3SJohan Hovold if (!buf) 216015ee89c3SJohan Hovold return 0; /* failed to identify 7810 */ 21613f542974SPaul B Schroeder 21620eafe4deSDonald /* Store MCR setting */ 216315ee89c3SJohan Hovold res = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), 21640eafe4deSDonald MCS_RDREQ, MCS_RD_RTYPE, 0x0300, MODEM_CONTROL_REGISTER, 216515ee89c3SJohan Hovold buf, VENDOR_READ_LENGTH, MOS_WDR_TIMEOUT); 216615ee89c3SJohan Hovold if (res == VENDOR_READ_LENGTH) 216715ee89c3SJohan Hovold mcr_data = *buf; 21680eafe4deSDonald 21690eafe4deSDonald for (i = 0; i < 16; i++) { 21700eafe4deSDonald /* Send the 1-bit test pattern out to MCS7810 test pin */ 21710eafe4deSDonald usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 21720eafe4deSDonald MCS_WRREQ, MCS_WR_RTYPE, 21730eafe4deSDonald (0x0300 | (((test_pattern >> i) & 0x0001) << 1)), 21740eafe4deSDonald MODEM_CONTROL_REGISTER, NULL, 0, MOS_WDR_TIMEOUT); 21750eafe4deSDonald 21760eafe4deSDonald /* Read the test pattern back */ 217715ee89c3SJohan Hovold res = usb_control_msg(serial->dev, 217815ee89c3SJohan Hovold usb_rcvctrlpipe(serial->dev, 0), MCS_RDREQ, 217915ee89c3SJohan Hovold MCS_RD_RTYPE, 0, GPIO_REGISTER, buf, 2180093ea2d3SDonald Lee VENDOR_READ_LENGTH, MOS_WDR_TIMEOUT); 218115ee89c3SJohan Hovold if (res == VENDOR_READ_LENGTH) 218215ee89c3SJohan Hovold data = *buf; 2183093ea2d3SDonald Lee 21840eafe4deSDonald /* If this is a MCS7810 device, both test patterns must match */ 21850eafe4deSDonald if (((test_pattern >> i) ^ (~data >> 1)) & 0x0001) 21860eafe4deSDonald break; 21870eafe4deSDonald 21880eafe4deSDonald pass_count++; 21893f542974SPaul B Schroeder } 2190093ea2d3SDonald Lee 21910eafe4deSDonald /* Restore MCR setting */ 21920eafe4deSDonald usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), MCS_WRREQ, 21930eafe4deSDonald MCS_WR_RTYPE, 0x0300 | mcr_data, MODEM_CONTROL_REGISTER, NULL, 21940eafe4deSDonald 0, MOS_WDR_TIMEOUT); 21950eafe4deSDonald 219615ee89c3SJohan Hovold kfree(buf); 219715ee89c3SJohan Hovold 21980eafe4deSDonald if (pass_count == 16) 21990eafe4deSDonald return 1; 22000eafe4deSDonald 22010eafe4deSDonald return 0; 22020eafe4deSDonald } 22030eafe4deSDonald 22040eafe4deSDonald static int mos7840_calc_num_ports(struct usb_serial *serial) 22050eafe4deSDonald { 22060eafe4deSDonald __u16 data = 0x00; 220715ee89c3SJohan Hovold u8 *buf; 22080eafe4deSDonald int mos7840_num_ports; 22090eafe4deSDonald 221015ee89c3SJohan Hovold buf = kzalloc(VENDOR_READ_LENGTH, GFP_KERNEL); 221115ee89c3SJohan Hovold if (buf) { 22120eafe4deSDonald usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), 221315ee89c3SJohan Hovold MCS_RDREQ, MCS_RD_RTYPE, 0, GPIO_REGISTER, buf, 22140eafe4deSDonald VENDOR_READ_LENGTH, MOS_WDR_TIMEOUT); 221515ee89c3SJohan Hovold data = *buf; 221615ee89c3SJohan Hovold kfree(buf); 221715ee89c3SJohan Hovold } 22180eafe4deSDonald 22190eafe4deSDonald if (serial->dev->descriptor.idProduct == MOSCHIP_DEVICE_ID_7810 || 22200eafe4deSDonald serial->dev->descriptor.idProduct == MOSCHIP_DEVICE_ID_7820) { 22210eafe4deSDonald device_type = serial->dev->descriptor.idProduct; 22220eafe4deSDonald } else { 22230eafe4deSDonald /* For a MCS7840 device GPIO0 must be set to 1 */ 22240eafe4deSDonald if ((data & 0x01) == 1) 22250eafe4deSDonald device_type = MOSCHIP_DEVICE_ID_7840; 22260eafe4deSDonald else if (mos7810_check(serial)) 22270eafe4deSDonald device_type = MOSCHIP_DEVICE_ID_7810; 22280eafe4deSDonald else 22290eafe4deSDonald device_type = MOSCHIP_DEVICE_ID_7820; 22300eafe4deSDonald } 22310eafe4deSDonald 22320eafe4deSDonald mos7840_num_ports = (device_type >> 4) & 0x000F; 22330eafe4deSDonald serial->num_bulk_in = mos7840_num_ports; 22340eafe4deSDonald serial->num_bulk_out = mos7840_num_ports; 22350eafe4deSDonald serial->num_ports = mos7840_num_ports; 22360eafe4deSDonald 22373f542974SPaul B Schroeder return mos7840_num_ports; 22383f542974SPaul B Schroeder } 22393f542974SPaul B Schroeder 224080c00750SJohan Hovold static int mos7840_port_probe(struct usb_serial_port *port) 22413f542974SPaul B Schroeder { 224280c00750SJohan Hovold struct usb_serial *serial = port->serial; 22433f542974SPaul B Schroeder struct moschip_port *mos7840_port; 224480c00750SJohan Hovold int status; 224580c00750SJohan Hovold int pnum; 22463f542974SPaul B Schroeder __u16 Data; 22473f542974SPaul B Schroeder 22483f542974SPaul B Schroeder /* we set up the pointers to the endpoints in the mos7840_open * 22493f542974SPaul B Schroeder * function, as the structures aren't created yet. */ 22503f542974SPaul B Schroeder 22511143832eSGreg Kroah-Hartman pnum = port->port_number; 225280c00750SJohan Hovold 2253ae685effSJohan Hovold dev_dbg(&port->dev, "mos7840_startup: configuring port %d\n", pnum); 22547ac9da10SBurman Yan mos7840_port = kzalloc(sizeof(struct moschip_port), GFP_KERNEL); 22553f542974SPaul B Schroeder if (mos7840_port == NULL) { 225680c00750SJohan Hovold dev_err(&port->dev, "%s - Out of memory\n", __func__); 225780c00750SJohan Hovold return -ENOMEM; 22583f542974SPaul B Schroeder } 22593f542974SPaul B Schroeder 2260880af9dbSAlan Cox /* Initialize all port interrupt end point to port 0 int 2261880af9dbSAlan Cox * endpoint. Our device has only one interrupt end point 2262880af9dbSAlan Cox * common to all port */ 22633f542974SPaul B Schroeder 226480c00750SJohan Hovold mos7840_port->port = port; 226580c00750SJohan Hovold mos7840_set_port_private(port, mos7840_port); 22660de9a702SOliver Neukum spin_lock_init(&mos7840_port->pool_lock); 22673f542974SPaul B Schroeder 226837768adfSTony Cook /* minor is not initialised until later by 226937768adfSTony Cook * usb-serial.c:get_free_serial() and cannot therefore be used 227037768adfSTony Cook * to index device instances */ 227180c00750SJohan Hovold mos7840_port->port_num = pnum + 1; 2272e5b1e206SGreg Kroah-Hartman dev_dbg(&port->dev, "port->minor = %d\n", port->minor); 227380c00750SJohan Hovold dev_dbg(&port->dev, "mos7840_port->port_num = %d\n", mos7840_port->port_num); 22743f542974SPaul B Schroeder 22753f542974SPaul B Schroeder if (mos7840_port->port_num == 1) { 22763f542974SPaul B Schroeder mos7840_port->SpRegOffset = 0x0; 22773f542974SPaul B Schroeder mos7840_port->ControlRegOffset = 0x1; 22783f542974SPaul B Schroeder mos7840_port->DcrRegOffset = 0x4; 2279ae685effSJohan Hovold } else if ((mos7840_port->port_num == 2) && (serial->num_ports == 4)) { 22803f542974SPaul B Schroeder mos7840_port->SpRegOffset = 0x8; 22813f542974SPaul B Schroeder mos7840_port->ControlRegOffset = 0x9; 22823f542974SPaul B Schroeder mos7840_port->DcrRegOffset = 0x16; 2283ae685effSJohan Hovold } else if ((mos7840_port->port_num == 2) && (serial->num_ports == 2)) { 22843f542974SPaul B Schroeder mos7840_port->SpRegOffset = 0xa; 22853f542974SPaul B Schroeder mos7840_port->ControlRegOffset = 0xb; 22863f542974SPaul B Schroeder mos7840_port->DcrRegOffset = 0x19; 2287ae685effSJohan Hovold } else if ((mos7840_port->port_num == 3) && (serial->num_ports == 4)) { 22883f542974SPaul B Schroeder mos7840_port->SpRegOffset = 0xa; 22893f542974SPaul B Schroeder mos7840_port->ControlRegOffset = 0xb; 22903f542974SPaul B Schroeder mos7840_port->DcrRegOffset = 0x19; 2291ae685effSJohan Hovold } else if ((mos7840_port->port_num == 4) && (serial->num_ports == 4)) { 22923f542974SPaul B Schroeder mos7840_port->SpRegOffset = 0xc; 22933f542974SPaul B Schroeder mos7840_port->ControlRegOffset = 0xd; 22943f542974SPaul B Schroeder mos7840_port->DcrRegOffset = 0x1c; 22953f542974SPaul B Schroeder } 229680c00750SJohan Hovold mos7840_dump_serial_port(port, mos7840_port); 229780c00750SJohan Hovold mos7840_set_port_private(port, mos7840_port); 22983f542974SPaul B Schroeder 2299880af9dbSAlan Cox /* enable rx_disable bit in control register */ 230080c00750SJohan Hovold status = mos7840_get_reg_sync(port, 23013f542974SPaul B Schroeder mos7840_port->ControlRegOffset, &Data); 23023f542974SPaul B Schroeder if (status < 0) { 230380c00750SJohan Hovold dev_dbg(&port->dev, "Reading ControlReg failed status-0x%x\n", status); 2304ae685effSJohan Hovold goto out; 23053f542974SPaul B Schroeder } else 230680c00750SJohan Hovold dev_dbg(&port->dev, "ControlReg Reading success val is %x, status%d\n", Data, status); 2307880af9dbSAlan Cox Data |= 0x08; /* setting driver done bit */ 2308880af9dbSAlan Cox Data |= 0x04; /* sp1_bit to have cts change reflect in 2309880af9dbSAlan Cox modem status reg */ 23103f542974SPaul B Schroeder 2311880af9dbSAlan Cox /* Data |= 0x20; //rx_disable bit */ 231280c00750SJohan Hovold status = mos7840_set_reg_sync(port, 23133f542974SPaul B Schroeder mos7840_port->ControlRegOffset, Data); 23143f542974SPaul B Schroeder if (status < 0) { 231580c00750SJohan Hovold dev_dbg(&port->dev, "Writing ControlReg failed(rx_disable) status-0x%x\n", status); 2316ae685effSJohan Hovold goto out; 23173f542974SPaul B Schroeder } else 231880c00750SJohan Hovold dev_dbg(&port->dev, "ControlReg Writing success(rx_disable) status%d\n", status); 23193f542974SPaul B Schroeder 2320880af9dbSAlan Cox /* Write default values in DCR (i.e 0x01 in DCR0, 0x05 in DCR2 2321880af9dbSAlan Cox and 0x24 in DCR3 */ 23223f542974SPaul B Schroeder Data = 0x01; 232380c00750SJohan Hovold status = mos7840_set_reg_sync(port, 2324880af9dbSAlan Cox (__u16) (mos7840_port->DcrRegOffset + 0), Data); 23253f542974SPaul B Schroeder if (status < 0) { 232680c00750SJohan Hovold dev_dbg(&port->dev, "Writing DCR0 failed status-0x%x\n", status); 2327ae685effSJohan Hovold goto out; 23283f542974SPaul B Schroeder } else 232980c00750SJohan Hovold dev_dbg(&port->dev, "DCR0 Writing success status%d\n", status); 23303f542974SPaul B Schroeder 23313f542974SPaul B Schroeder Data = 0x05; 233280c00750SJohan Hovold status = mos7840_set_reg_sync(port, 2333880af9dbSAlan Cox (__u16) (mos7840_port->DcrRegOffset + 1), Data); 23343f542974SPaul B Schroeder if (status < 0) { 233580c00750SJohan Hovold dev_dbg(&port->dev, "Writing DCR1 failed status-0x%x\n", status); 2336ae685effSJohan Hovold goto out; 23373f542974SPaul B Schroeder } else 233880c00750SJohan Hovold dev_dbg(&port->dev, "DCR1 Writing success status%d\n", status); 23393f542974SPaul B Schroeder 23403f542974SPaul B Schroeder Data = 0x24; 234180c00750SJohan Hovold status = mos7840_set_reg_sync(port, 2342880af9dbSAlan Cox (__u16) (mos7840_port->DcrRegOffset + 2), Data); 23433f542974SPaul B Schroeder if (status < 0) { 234480c00750SJohan Hovold dev_dbg(&port->dev, "Writing DCR2 failed status-0x%x\n", status); 2345ae685effSJohan Hovold goto out; 23463f542974SPaul B Schroeder } else 234780c00750SJohan Hovold dev_dbg(&port->dev, "DCR2 Writing success status%d\n", status); 23483f542974SPaul B Schroeder 2349880af9dbSAlan Cox /* write values in clkstart0x0 and clkmulti 0x20 */ 23503f542974SPaul B Schroeder Data = 0x0; 2351ae685effSJohan Hovold status = mos7840_set_reg_sync(port, CLK_START_VALUE_REGISTER, Data); 23523f542974SPaul B Schroeder if (status < 0) { 235380c00750SJohan Hovold dev_dbg(&port->dev, "Writing CLK_START_VALUE_REGISTER failed status-0x%x\n", status); 2354ae685effSJohan Hovold goto out; 23553f542974SPaul B Schroeder } else 235680c00750SJohan Hovold dev_dbg(&port->dev, "CLK_START_VALUE_REGISTER Writing success status%d\n", status); 23573f542974SPaul B Schroeder 23583f542974SPaul B Schroeder Data = 0x20; 2359ae685effSJohan Hovold status = mos7840_set_reg_sync(port, CLK_MULTI_REGISTER, Data); 23603f542974SPaul B Schroeder if (status < 0) { 236180c00750SJohan Hovold dev_dbg(&port->dev, "Writing CLK_MULTI_REGISTER failed status-0x%x\n", status); 23620de9a702SOliver Neukum goto error; 23633f542974SPaul B Schroeder } else 236480c00750SJohan Hovold dev_dbg(&port->dev, "CLK_MULTI_REGISTER Writing success status%d\n", status); 23653f542974SPaul B Schroeder 2366880af9dbSAlan Cox /* write value 0x0 to scratchpad register */ 23673f542974SPaul B Schroeder Data = 0x00; 2368ae685effSJohan Hovold status = mos7840_set_uart_reg(port, SCRATCH_PAD_REGISTER, Data); 23693f542974SPaul B Schroeder if (status < 0) { 237080c00750SJohan Hovold dev_dbg(&port->dev, "Writing SCRATCH_PAD_REGISTER failed status-0x%x\n", status); 2371ae685effSJohan Hovold goto out; 23723f542974SPaul B Schroeder } else 237380c00750SJohan Hovold dev_dbg(&port->dev, "SCRATCH_PAD_REGISTER Writing success status%d\n", status); 23743f542974SPaul B Schroeder 2375880af9dbSAlan Cox /* Zero Length flag register */ 2376ae685effSJohan Hovold if ((mos7840_port->port_num != 1) && (serial->num_ports == 2)) { 23773f542974SPaul B Schroeder Data = 0xff; 237880c00750SJohan Hovold status = mos7840_set_reg_sync(port, 23793f542974SPaul B Schroeder (__u16) (ZLP_REG1 + 2380880af9dbSAlan Cox ((__u16)mos7840_port->port_num)), Data); 238180c00750SJohan Hovold dev_dbg(&port->dev, "ZLIP offset %x\n", 23829c134a14SGreg Kroah-Hartman (__u16)(ZLP_REG1 + ((__u16) mos7840_port->port_num))); 23833f542974SPaul B Schroeder if (status < 0) { 238480c00750SJohan Hovold dev_dbg(&port->dev, "Writing ZLP_REG%d failed status-0x%x\n", pnum + 2, status); 2385ae685effSJohan Hovold goto out; 23863f542974SPaul B Schroeder } else 238780c00750SJohan Hovold dev_dbg(&port->dev, "ZLP_REG%d Writing success status%d\n", pnum + 2, status); 23883f542974SPaul B Schroeder } else { 23893f542974SPaul B Schroeder Data = 0xff; 239080c00750SJohan Hovold status = mos7840_set_reg_sync(port, 23913f542974SPaul B Schroeder (__u16) (ZLP_REG1 + 2392880af9dbSAlan Cox ((__u16)mos7840_port->port_num) - 0x1), Data); 239380c00750SJohan Hovold dev_dbg(&port->dev, "ZLIP offset %x\n", 23949c134a14SGreg Kroah-Hartman (__u16)(ZLP_REG1 + ((__u16) mos7840_port->port_num) - 0x1)); 23953f542974SPaul B Schroeder if (status < 0) { 239680c00750SJohan Hovold dev_dbg(&port->dev, "Writing ZLP_REG%d failed status-0x%x\n", pnum + 1, status); 2397ae685effSJohan Hovold goto out; 23983f542974SPaul B Schroeder } else 239980c00750SJohan Hovold dev_dbg(&port->dev, "ZLP_REG%d Writing success status%d\n", pnum + 1, status); 24003f542974SPaul B Schroeder 24013f542974SPaul B Schroeder } 24020de9a702SOliver Neukum mos7840_port->control_urb = usb_alloc_urb(0, GFP_KERNEL); 24033f542974SPaul B Schroeder mos7840_port->ctrl_buf = kmalloc(16, GFP_KERNEL); 2404880af9dbSAlan Cox mos7840_port->dr = kmalloc(sizeof(struct usb_ctrlrequest), 2405880af9dbSAlan Cox GFP_KERNEL); 2406880af9dbSAlan Cox if (!mos7840_port->control_urb || !mos7840_port->ctrl_buf || 2407880af9dbSAlan Cox !mos7840_port->dr) { 24080de9a702SOliver Neukum status = -ENOMEM; 24090de9a702SOliver Neukum goto error; 24100de9a702SOliver Neukum } 24110eafe4deSDonald 24120eafe4deSDonald mos7840_port->has_led = false; 24130eafe4deSDonald 24140eafe4deSDonald /* Initialize LED timers */ 24150eafe4deSDonald if (device_type == MOSCHIP_DEVICE_ID_7810) { 24160eafe4deSDonald mos7840_port->has_led = true; 24170eafe4deSDonald 24180eafe4deSDonald init_timer(&mos7840_port->led_timer1); 24190eafe4deSDonald mos7840_port->led_timer1.function = mos7840_led_off; 24200eafe4deSDonald mos7840_port->led_timer1.expires = 24210eafe4deSDonald jiffies + msecs_to_jiffies(LED_ON_MS); 2422ae685effSJohan Hovold mos7840_port->led_timer1.data = (unsigned long)mos7840_port; 24230eafe4deSDonald 24240eafe4deSDonald init_timer(&mos7840_port->led_timer2); 2425ae685effSJohan Hovold mos7840_port->led_timer2.function = mos7840_led_flag_off; 24260eafe4deSDonald mos7840_port->led_timer2.expires = 24270eafe4deSDonald jiffies + msecs_to_jiffies(LED_OFF_MS); 2428ae685effSJohan Hovold mos7840_port->led_timer2.data = (unsigned long)mos7840_port; 24290eafe4deSDonald 24300eafe4deSDonald mos7840_port->led_flag = false; 24310eafe4deSDonald 24320eafe4deSDonald /* Turn off LED */ 2433ae685effSJohan Hovold mos7840_set_led_sync(port, MODEM_CONTROL_REGISTER, 0x0300); 24340eafe4deSDonald } 2435ae685effSJohan Hovold out: 243680c00750SJohan Hovold if (pnum == serial->num_ports - 1) { 2437880af9dbSAlan Cox /* Zero Length flag enable */ 24383f542974SPaul B Schroeder Data = 0x0f; 24393f542974SPaul B Schroeder status = mos7840_set_reg_sync(serial->port[0], ZLP_REG5, Data); 24403f542974SPaul B Schroeder if (status < 0) { 244180c00750SJohan Hovold dev_dbg(&port->dev, "Writing ZLP_REG5 failed status-0x%x\n", status); 24427ced46c3SRoel Kluin goto error; 24433f542974SPaul B Schroeder } else 244480c00750SJohan Hovold dev_dbg(&port->dev, "ZLP_REG5 Writing success status%d\n", status); 24453f542974SPaul B Schroeder 24463f542974SPaul B Schroeder /* setting configuration feature to one */ 24473f542974SPaul B Schroeder usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 244880c00750SJohan Hovold 0x03, 0x00, 0x01, 0x00, NULL, 0x00, 244980c00750SJohan Hovold MOS_WDR_TIMEOUT); 245080c00750SJohan Hovold } 24513f542974SPaul B Schroeder return 0; 24520de9a702SOliver Neukum error: 24530de9a702SOliver Neukum kfree(mos7840_port->dr); 24540de9a702SOliver Neukum kfree(mos7840_port->ctrl_buf); 24550de9a702SOliver Neukum usb_free_urb(mos7840_port->control_urb); 24560de9a702SOliver Neukum kfree(mos7840_port); 245780c00750SJohan Hovold 24580de9a702SOliver Neukum return status; 24593f542974SPaul B Schroeder } 24603f542974SPaul B Schroeder 246180c00750SJohan Hovold static int mos7840_port_remove(struct usb_serial_port *port) 24623f542974SPaul B Schroeder { 24633f542974SPaul B Schroeder struct moschip_port *mos7840_port; 24643f542974SPaul B Schroeder 246580c00750SJohan Hovold mos7840_port = mos7840_get_port_private(port); 24663f542974SPaul B Schroeder 24670eafe4deSDonald if (mos7840_port->has_led) { 24680eafe4deSDonald /* Turn off LED */ 246980c00750SJohan Hovold mos7840_set_led_sync(port, MODEM_CONTROL_REGISTER, 0x0300); 24700eafe4deSDonald 24710eafe4deSDonald del_timer_sync(&mos7840_port->led_timer1); 24720eafe4deSDonald del_timer_sync(&mos7840_port->led_timer2); 24730eafe4deSDonald } 247480c00750SJohan Hovold usb_kill_urb(mos7840_port->control_urb); 247565a4cdbbSJohan Hovold usb_free_urb(mos7840_port->control_urb); 24760de9a702SOliver Neukum kfree(mos7840_port->ctrl_buf); 24770de9a702SOliver Neukum kfree(mos7840_port->dr); 24783f542974SPaul B Schroeder kfree(mos7840_port); 247980c00750SJohan Hovold 248080c00750SJohan Hovold return 0; 24813f542974SPaul B Schroeder } 24823f542974SPaul B Schroeder 24833f542974SPaul B Schroeder static struct usb_serial_driver moschip7840_4port_device = { 24843f542974SPaul B Schroeder .driver = { 24853f542974SPaul B Schroeder .owner = THIS_MODULE, 24863f542974SPaul B Schroeder .name = "mos7840", 24873f542974SPaul B Schroeder }, 24883f542974SPaul B Schroeder .description = DRIVER_DESC, 248968e24113SGreg Kroah-Hartman .id_table = id_table, 24903f542974SPaul B Schroeder .num_ports = 4, 24913f542974SPaul B Schroeder .open = mos7840_open, 24923f542974SPaul B Schroeder .close = mos7840_close, 24933f542974SPaul B Schroeder .write = mos7840_write, 24943f542974SPaul B Schroeder .write_room = mos7840_write_room, 24953f542974SPaul B Schroeder .chars_in_buffer = mos7840_chars_in_buffer, 24963f542974SPaul B Schroeder .throttle = mos7840_throttle, 24973f542974SPaul B Schroeder .unthrottle = mos7840_unthrottle, 24983f542974SPaul B Schroeder .calc_num_ports = mos7840_calc_num_ports, 24993f542974SPaul B Schroeder #ifdef MCSSerialProbe 25003f542974SPaul B Schroeder .probe = mos7840_serial_probe, 25013f542974SPaul B Schroeder #endif 25023f542974SPaul B Schroeder .ioctl = mos7840_ioctl, 25033f542974SPaul B Schroeder .set_termios = mos7840_set_termios, 25043f542974SPaul B Schroeder .break_ctl = mos7840_break, 25053f542974SPaul B Schroeder .tiocmget = mos7840_tiocmget, 25063f542974SPaul B Schroeder .tiocmset = mos7840_tiocmset, 25070c613371SJohan Hovold .tiocmiwait = usb_serial_generic_tiocmiwait, 25088c1a07ffSJohan Hovold .get_icount = usb_serial_generic_get_icount, 250980c00750SJohan Hovold .port_probe = mos7840_port_probe, 251080c00750SJohan Hovold .port_remove = mos7840_port_remove, 25113f542974SPaul B Schroeder .read_bulk_callback = mos7840_bulk_in_callback, 25123f542974SPaul B Schroeder .read_int_callback = mos7840_interrupt_callback, 25133f542974SPaul B Schroeder }; 25143f542974SPaul B Schroeder 25154d2a7affSAlan Stern static struct usb_serial_driver * const serial_drivers[] = { 25164d2a7affSAlan Stern &moschip7840_4port_device, NULL 25174d2a7affSAlan Stern }; 25184d2a7affSAlan Stern 251968e24113SGreg Kroah-Hartman module_usb_serial_driver(serial_drivers, id_table); 25203f542974SPaul B Schroeder 25213f542974SPaul B Schroeder MODULE_DESCRIPTION(DRIVER_DESC); 25223f542974SPaul B Schroeder MODULE_LICENSE("GPL"); 2523