Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1 | /* |
| 2 | * This program is free software; you can redistribute it and/or modify |
| 3 | * it under the terms of the GNU General Public License as published by |
| 4 | * the Free Software Foundation; either version 2 of the License, or |
| 5 | * (at your option) any later version. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | * |
| 12 | * You should have received a copy of the GNU General Public License |
| 13 | * along with this program; if not, write to the Free Software |
| 14 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 15 | * |
| 16 | * Clean ups from Moschip version and a few ioctl implementations by: |
| 17 | * Paul B Schroeder <pschroeder "at" uplogix "dot" com> |
| 18 | * |
| 19 | * Originally based on drivers/usb/serial/io_edgeport.c which is: |
| 20 | * Copyright (C) 2000 Inside Out Networks, All rights reserved. |
| 21 | * Copyright (C) 2001-2002 Greg Kroah-Hartman <greg@kroah.com> |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | #include <linux/kernel.h> |
| 26 | #include <linux/errno.h> |
| 27 | #include <linux/init.h> |
| 28 | #include <linux/slab.h> |
| 29 | #include <linux/tty.h> |
| 30 | #include <linux/tty_driver.h> |
| 31 | #include <linux/tty_flip.h> |
| 32 | #include <linux/module.h> |
| 33 | #include <linux/serial.h> |
| 34 | #include <linux/usb.h> |
| 35 | #include <linux/usb/serial.h> |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 36 | #include <linux/uaccess.h> |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 37 | |
| 38 | /* |
| 39 | * Version Information |
| 40 | */ |
Tony Cook | 37768ad | 2009-04-18 22:42:18 +0930 | [diff] [blame] | 41 | #define DRIVER_VERSION "1.3.2" |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 42 | #define DRIVER_DESC "Moschip 7840/7820 USB Serial Driver" |
| 43 | |
| 44 | /* |
| 45 | * 16C50 UART register defines |
| 46 | */ |
| 47 | |
| 48 | #define LCR_BITS_5 0x00 /* 5 bits/char */ |
| 49 | #define LCR_BITS_6 0x01 /* 6 bits/char */ |
| 50 | #define LCR_BITS_7 0x02 /* 7 bits/char */ |
| 51 | #define LCR_BITS_8 0x03 /* 8 bits/char */ |
| 52 | #define LCR_BITS_MASK 0x03 /* Mask for bits/char field */ |
| 53 | |
| 54 | #define LCR_STOP_1 0x00 /* 1 stop bit */ |
| 55 | #define LCR_STOP_1_5 0x04 /* 1.5 stop bits (if 5 bits/char) */ |
| 56 | #define LCR_STOP_2 0x04 /* 2 stop bits (if 6-8 bits/char) */ |
| 57 | #define LCR_STOP_MASK 0x04 /* Mask for stop bits field */ |
| 58 | |
| 59 | #define LCR_PAR_NONE 0x00 /* No parity */ |
| 60 | #define LCR_PAR_ODD 0x08 /* Odd parity */ |
| 61 | #define LCR_PAR_EVEN 0x18 /* Even parity */ |
| 62 | #define LCR_PAR_MARK 0x28 /* Force parity bit to 1 */ |
| 63 | #define LCR_PAR_SPACE 0x38 /* Force parity bit to 0 */ |
| 64 | #define LCR_PAR_MASK 0x38 /* Mask for parity field */ |
| 65 | |
| 66 | #define LCR_SET_BREAK 0x40 /* Set Break condition */ |
| 67 | #define LCR_DL_ENABLE 0x80 /* Enable access to divisor latch */ |
| 68 | |
| 69 | #define MCR_DTR 0x01 /* Assert DTR */ |
| 70 | #define MCR_RTS 0x02 /* Assert RTS */ |
| 71 | #define MCR_OUT1 0x04 /* Loopback only: Sets state of RI */ |
| 72 | #define MCR_MASTER_IE 0x08 /* Enable interrupt outputs */ |
| 73 | #define MCR_LOOPBACK 0x10 /* Set internal (digital) loopback mode */ |
| 74 | #define MCR_XON_ANY 0x20 /* Enable any char to exit XOFF mode */ |
| 75 | |
| 76 | #define MOS7840_MSR_CTS 0x10 /* Current state of CTS */ |
| 77 | #define MOS7840_MSR_DSR 0x20 /* Current state of DSR */ |
| 78 | #define MOS7840_MSR_RI 0x40 /* Current state of RI */ |
| 79 | #define MOS7840_MSR_CD 0x80 /* Current state of CD */ |
| 80 | |
| 81 | /* |
| 82 | * Defines used for sending commands to port |
| 83 | */ |
| 84 | |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 85 | #define WAIT_FOR_EVER (HZ * 0) /* timeout urb is wait for ever */ |
| 86 | #define MOS_WDR_TIMEOUT (HZ * 5) /* default urb timeout */ |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 87 | |
| 88 | #define MOS_PORT1 0x0200 |
| 89 | #define MOS_PORT2 0x0300 |
| 90 | #define MOS_VENREG 0x0000 |
| 91 | #define MOS_MAX_PORT 0x02 |
| 92 | #define MOS_WRITE 0x0E |
| 93 | #define MOS_READ 0x0D |
| 94 | |
| 95 | /* Requests */ |
| 96 | #define MCS_RD_RTYPE 0xC0 |
| 97 | #define MCS_WR_RTYPE 0x40 |
| 98 | #define MCS_RDREQ 0x0D |
| 99 | #define MCS_WRREQ 0x0E |
| 100 | #define MCS_CTRL_TIMEOUT 500 |
| 101 | #define VENDOR_READ_LENGTH (0x01) |
| 102 | |
| 103 | #define MAX_NAME_LEN 64 |
| 104 | |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 105 | #define ZLP_REG1 0x3A /* Zero_Flag_Reg1 58 */ |
| 106 | #define ZLP_REG5 0x3E /* Zero_Flag_Reg5 62 */ |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 107 | |
| 108 | /* For higher baud Rates use TIOCEXBAUD */ |
| 109 | #define TIOCEXBAUD 0x5462 |
| 110 | |
| 111 | /* vendor id and device id defines */ |
| 112 | |
David Ludlow | 11e1abb | 2008-02-25 17:30:52 -0500 | [diff] [blame] | 113 | /* The native mos7840/7820 component */ |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 114 | #define USB_VENDOR_ID_MOSCHIP 0x9710 |
| 115 | #define MOSCHIP_DEVICE_ID_7840 0x7840 |
| 116 | #define MOSCHIP_DEVICE_ID_7820 0x7820 |
David Ludlow | 11e1abb | 2008-02-25 17:30:52 -0500 | [diff] [blame] | 117 | /* The native component can have its vendor/device id's overridden |
| 118 | * in vendor-specific implementations. Such devices can be handled |
| 119 | * by making a change here, in moschip_port_id_table, and in |
| 120 | * moschip_id_table_combined |
| 121 | */ |
Dave Ludlow | 870408c | 2010-09-01 12:33:30 -0400 | [diff] [blame] | 122 | #define USB_VENDOR_ID_BANDB 0x0856 |
| 123 | #define BANDB_DEVICE_ID_USO9ML2_2 0xAC22 |
| 124 | #define BANDB_DEVICE_ID_USO9ML2_2P 0xBC00 |
| 125 | #define BANDB_DEVICE_ID_USO9ML2_4 0xAC24 |
| 126 | #define BANDB_DEVICE_ID_USO9ML2_4P 0xBC01 |
| 127 | #define BANDB_DEVICE_ID_US9ML2_2 0xAC29 |
| 128 | #define BANDB_DEVICE_ID_US9ML2_4 0xAC30 |
| 129 | #define BANDB_DEVICE_ID_USPTL4_2 0xAC31 |
| 130 | #define BANDB_DEVICE_ID_USPTL4_4 0xAC32 |
| 131 | #define BANDB_DEVICE_ID_USOPTL4_2 0xAC42 |
| 132 | #define BANDB_DEVICE_ID_USOPTL4_2P 0xBC02 |
| 133 | #define BANDB_DEVICE_ID_USOPTL4_4 0xAC44 |
| 134 | #define BANDB_DEVICE_ID_USOPTL4_4P 0xBC03 |
| 135 | #define BANDB_DEVICE_ID_USOPTL2_4 0xAC24 |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 136 | |
Russell Lang | 9d498be | 2009-07-17 19:29:20 +1000 | [diff] [blame] | 137 | /* This driver also supports |
| 138 | * ATEN UC2324 device using Moschip MCS7840 |
| 139 | * ATEN UC2322 device using Moschip MCS7820 |
| 140 | */ |
Tony Cook | e9b8cff | 2009-04-18 22:42:18 +0930 | [diff] [blame] | 141 | #define USB_VENDOR_ID_ATENINTL 0x0557 |
| 142 | #define ATENINTL_DEVICE_ID_UC2324 0x2011 |
Russell Lang | 9d498be | 2009-07-17 19:29:20 +1000 | [diff] [blame] | 143 | #define ATENINTL_DEVICE_ID_UC2322 0x7820 |
Tony Cook | e9b8cff | 2009-04-18 22:42:18 +0930 | [diff] [blame] | 144 | |
David Ludlow | 11e1abb | 2008-02-25 17:30:52 -0500 | [diff] [blame] | 145 | /* Interrupt Routine Defines */ |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 146 | |
| 147 | #define SERIAL_IIR_RLS 0x06 |
| 148 | #define SERIAL_IIR_MS 0x00 |
| 149 | |
| 150 | /* |
| 151 | * Emulation of the bit mask on the LINE STATUS REGISTER. |
| 152 | */ |
| 153 | #define SERIAL_LSR_DR 0x0001 |
| 154 | #define SERIAL_LSR_OE 0x0002 |
| 155 | #define SERIAL_LSR_PE 0x0004 |
| 156 | #define SERIAL_LSR_FE 0x0008 |
| 157 | #define SERIAL_LSR_BI 0x0010 |
| 158 | |
| 159 | #define MOS_MSR_DELTA_CTS 0x10 |
| 160 | #define MOS_MSR_DELTA_DSR 0x20 |
| 161 | #define MOS_MSR_DELTA_RI 0x40 |
| 162 | #define MOS_MSR_DELTA_CD 0x80 |
| 163 | |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 164 | /* Serial Port register Address */ |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 165 | #define INTERRUPT_ENABLE_REGISTER ((__u16)(0x01)) |
| 166 | #define FIFO_CONTROL_REGISTER ((__u16)(0x02)) |
| 167 | #define LINE_CONTROL_REGISTER ((__u16)(0x03)) |
| 168 | #define MODEM_CONTROL_REGISTER ((__u16)(0x04)) |
| 169 | #define LINE_STATUS_REGISTER ((__u16)(0x05)) |
| 170 | #define MODEM_STATUS_REGISTER ((__u16)(0x06)) |
| 171 | #define SCRATCH_PAD_REGISTER ((__u16)(0x07)) |
| 172 | #define DIVISOR_LATCH_LSB ((__u16)(0x00)) |
| 173 | #define DIVISOR_LATCH_MSB ((__u16)(0x01)) |
| 174 | |
| 175 | #define CLK_MULTI_REGISTER ((__u16)(0x02)) |
| 176 | #define CLK_START_VALUE_REGISTER ((__u16)(0x03)) |
Donald Lee | 093ea2d | 2012-03-14 15:26:33 +0800 | [diff] [blame] | 177 | #define GPIO_REGISTER ((__u16)(0x07)) |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 178 | |
| 179 | #define SERIAL_LCR_DLAB ((__u16)(0x0080)) |
| 180 | |
| 181 | /* |
| 182 | * URB POOL related defines |
| 183 | */ |
| 184 | #define NUM_URBS 16 /* URB Count */ |
| 185 | #define URB_TRANSFER_BUFFER_SIZE 32 /* URB Size */ |
| 186 | |
| 187 | |
Németh Márton | 7d40d7e | 2010-01-10 15:34:24 +0100 | [diff] [blame] | 188 | static const struct usb_device_id moschip_port_id_table[] = { |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 189 | {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7840)}, |
| 190 | {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7820)}, |
Cliff Brake | acf509a | 2009-12-01 09:53:43 -0500 | [diff] [blame] | 191 | {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_2)}, |
Dave Ludlow | 870408c | 2010-09-01 12:33:30 -0400 | [diff] [blame] | 192 | {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_2P)}, |
Cliff Brake | acf509a | 2009-12-01 09:53:43 -0500 | [diff] [blame] | 193 | {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_4)}, |
Dave Ludlow | 870408c | 2010-09-01 12:33:30 -0400 | [diff] [blame] | 194 | {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_4P)}, |
Cliff Brake | acf509a | 2009-12-01 09:53:43 -0500 | [diff] [blame] | 195 | {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_US9ML2_2)}, |
| 196 | {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_US9ML2_4)}, |
| 197 | {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USPTL4_2)}, |
| 198 | {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USPTL4_4)}, |
David Ludlow | 11e1abb | 2008-02-25 17:30:52 -0500 | [diff] [blame] | 199 | {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_2)}, |
Dave Ludlow | 870408c | 2010-09-01 12:33:30 -0400 | [diff] [blame] | 200 | {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_2P)}, |
Cliff Brake | acf509a | 2009-12-01 09:53:43 -0500 | [diff] [blame] | 201 | {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_4)}, |
Dave Ludlow | 870408c | 2010-09-01 12:33:30 -0400 | [diff] [blame] | 202 | {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_4P)}, |
Blaise Gassend | 27f1281 | 2009-12-18 15:23:38 -0800 | [diff] [blame] | 203 | {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL2_4)}, |
Tony Cook | e9b8cff | 2009-04-18 22:42:18 +0930 | [diff] [blame] | 204 | {USB_DEVICE(USB_VENDOR_ID_ATENINTL, ATENINTL_DEVICE_ID_UC2324)}, |
Russell Lang | 9d498be | 2009-07-17 19:29:20 +1000 | [diff] [blame] | 205 | {USB_DEVICE(USB_VENDOR_ID_ATENINTL, ATENINTL_DEVICE_ID_UC2322)}, |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 206 | {} /* terminating entry */ |
| 207 | }; |
| 208 | |
Németh Márton | 7d40d7e | 2010-01-10 15:34:24 +0100 | [diff] [blame] | 209 | static const struct usb_device_id moschip_id_table_combined[] __devinitconst = { |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 210 | {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7840)}, |
| 211 | {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7820)}, |
Cliff Brake | acf509a | 2009-12-01 09:53:43 -0500 | [diff] [blame] | 212 | {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_2)}, |
Dave Ludlow | 870408c | 2010-09-01 12:33:30 -0400 | [diff] [blame] | 213 | {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_2P)}, |
Cliff Brake | acf509a | 2009-12-01 09:53:43 -0500 | [diff] [blame] | 214 | {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_4)}, |
Dave Ludlow | 870408c | 2010-09-01 12:33:30 -0400 | [diff] [blame] | 215 | {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_4P)}, |
Cliff Brake | acf509a | 2009-12-01 09:53:43 -0500 | [diff] [blame] | 216 | {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_US9ML2_2)}, |
| 217 | {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_US9ML2_4)}, |
| 218 | {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USPTL4_2)}, |
| 219 | {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USPTL4_4)}, |
David Ludlow | 11e1abb | 2008-02-25 17:30:52 -0500 | [diff] [blame] | 220 | {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_2)}, |
Dave Ludlow | 870408c | 2010-09-01 12:33:30 -0400 | [diff] [blame] | 221 | {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_2P)}, |
Cliff Brake | acf509a | 2009-12-01 09:53:43 -0500 | [diff] [blame] | 222 | {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_4)}, |
Dave Ludlow | 870408c | 2010-09-01 12:33:30 -0400 | [diff] [blame] | 223 | {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_4P)}, |
Blaise Gassend | 27f1281 | 2009-12-18 15:23:38 -0800 | [diff] [blame] | 224 | {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL2_4)}, |
Tony Cook | e9b8cff | 2009-04-18 22:42:18 +0930 | [diff] [blame] | 225 | {USB_DEVICE(USB_VENDOR_ID_ATENINTL, ATENINTL_DEVICE_ID_UC2324)}, |
Russell Lang | 9d498be | 2009-07-17 19:29:20 +1000 | [diff] [blame] | 226 | {USB_DEVICE(USB_VENDOR_ID_ATENINTL, ATENINTL_DEVICE_ID_UC2322)}, |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 227 | {} /* terminating entry */ |
| 228 | }; |
| 229 | |
| 230 | MODULE_DEVICE_TABLE(usb, moschip_id_table_combined); |
| 231 | |
| 232 | /* This structure holds all of the local port information */ |
| 233 | |
| 234 | struct moschip_port { |
| 235 | int port_num; /*Actual port number in the device(1,2,etc) */ |
| 236 | struct urb *write_urb; /* write URB for this port */ |
| 237 | struct urb *read_urb; /* read URB for this port */ |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 238 | struct urb *int_urb; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 239 | __u8 shadowLCR; /* last LCR value received */ |
| 240 | __u8 shadowMCR; /* last MCR value received */ |
| 241 | char open; |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 242 | char open_ports; |
| 243 | char zombie; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 244 | wait_queue_head_t wait_chase; /* for handling sleeping while waiting for chase to finish */ |
| 245 | wait_queue_head_t delta_msr_wait; /* for handling sleeping while waiting for msr change to happen */ |
| 246 | int delta_msr_cond; |
| 247 | struct async_icount icount; |
| 248 | struct usb_serial_port *port; /* loop back to the owner of this object */ |
| 249 | |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 250 | /* Offsets */ |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 251 | __u8 SpRegOffset; |
| 252 | __u8 ControlRegOffset; |
| 253 | __u8 DcrRegOffset; |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 254 | /* for processing control URBS in interrupt context */ |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 255 | struct urb *control_urb; |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 256 | struct usb_ctrlrequest *dr; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 257 | char *ctrl_buf; |
| 258 | int MsrLsr; |
| 259 | |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 260 | spinlock_t pool_lock; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 261 | struct urb *write_urb_pool[NUM_URBS]; |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 262 | char busy[NUM_URBS]; |
Greg Kroah-Hartman | 50de36f | 2008-12-10 16:00:30 -0800 | [diff] [blame] | 263 | bool read_urb_busy; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 264 | }; |
| 265 | |
| 266 | |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 267 | static bool debug; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 268 | |
| 269 | /* |
| 270 | * mos7840_set_reg_sync |
| 271 | * To set the Control register by calling usb_fill_control_urb function |
| 272 | * by passing usb_sndctrlpipe function as parameter. |
| 273 | */ |
| 274 | |
| 275 | static int mos7840_set_reg_sync(struct usb_serial_port *port, __u16 reg, |
| 276 | __u16 val) |
| 277 | { |
| 278 | struct usb_device *dev = port->serial->dev; |
| 279 | val = val & 0x00ff; |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 280 | dbg("mos7840_set_reg_sync offset is %x, value %x", reg, val); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 281 | |
| 282 | return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), MCS_WRREQ, |
| 283 | MCS_WR_RTYPE, val, reg, NULL, 0, |
| 284 | MOS_WDR_TIMEOUT); |
| 285 | } |
| 286 | |
| 287 | /* |
| 288 | * mos7840_get_reg_sync |
| 289 | * To set the Uart register by calling usb_fill_control_urb function by |
| 290 | * passing usb_rcvctrlpipe function as parameter. |
| 291 | */ |
| 292 | |
| 293 | static int mos7840_get_reg_sync(struct usb_serial_port *port, __u16 reg, |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 294 | __u16 *val) |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 295 | { |
| 296 | struct usb_device *dev = port->serial->dev; |
| 297 | int ret = 0; |
Johan Hovold | 9e221a3 | 2009-12-28 23:01:55 +0100 | [diff] [blame] | 298 | u8 *buf; |
| 299 | |
| 300 | buf = kmalloc(VENDOR_READ_LENGTH, GFP_KERNEL); |
| 301 | if (!buf) |
| 302 | return -ENOMEM; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 303 | |
| 304 | ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), MCS_RDREQ, |
Johan Hovold | 9e221a3 | 2009-12-28 23:01:55 +0100 | [diff] [blame] | 305 | MCS_RD_RTYPE, 0, reg, buf, VENDOR_READ_LENGTH, |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 306 | MOS_WDR_TIMEOUT); |
Johan Hovold | 9e221a3 | 2009-12-28 23:01:55 +0100 | [diff] [blame] | 307 | *val = buf[0]; |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 308 | dbg("mos7840_get_reg_sync offset is %x, return val %x", reg, *val); |
Johan Hovold | 9e221a3 | 2009-12-28 23:01:55 +0100 | [diff] [blame] | 309 | |
| 310 | kfree(buf); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 311 | return ret; |
| 312 | } |
| 313 | |
| 314 | /* |
| 315 | * mos7840_set_uart_reg |
| 316 | * To set the Uart register by calling usb_fill_control_urb function by |
| 317 | * passing usb_sndctrlpipe function as parameter. |
| 318 | */ |
| 319 | |
| 320 | static int mos7840_set_uart_reg(struct usb_serial_port *port, __u16 reg, |
| 321 | __u16 val) |
| 322 | { |
| 323 | |
| 324 | struct usb_device *dev = port->serial->dev; |
| 325 | val = val & 0x00ff; |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 326 | /* For the UART control registers, the application number need |
| 327 | to be Or'ed */ |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 328 | if (port->serial->num_ports == 4) { |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 329 | val |= (((__u16) port->number - |
| 330 | (__u16) (port->serial->minor)) + 1) << 8; |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 331 | dbg("mos7840_set_uart_reg application number is %x", val); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 332 | } else { |
| 333 | if (((__u16) port->number - (__u16) (port->serial->minor)) == 0) { |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 334 | val |= (((__u16) port->number - |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 335 | (__u16) (port->serial->minor)) + 1) << 8; |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 336 | dbg("mos7840_set_uart_reg application number is %x", |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 337 | val); |
| 338 | } else { |
| 339 | val |= |
| 340 | (((__u16) port->number - |
| 341 | (__u16) (port->serial->minor)) + 2) << 8; |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 342 | dbg("mos7840_set_uart_reg application number is %x", |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 343 | val); |
| 344 | } |
| 345 | } |
| 346 | return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), MCS_WRREQ, |
| 347 | MCS_WR_RTYPE, val, reg, NULL, 0, |
| 348 | MOS_WDR_TIMEOUT); |
| 349 | |
| 350 | } |
| 351 | |
| 352 | /* |
| 353 | * mos7840_get_uart_reg |
| 354 | * To set the Control register by calling usb_fill_control_urb function |
| 355 | * by passing usb_rcvctrlpipe function as parameter. |
| 356 | */ |
| 357 | static int mos7840_get_uart_reg(struct usb_serial_port *port, __u16 reg, |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 358 | __u16 *val) |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 359 | { |
| 360 | struct usb_device *dev = port->serial->dev; |
| 361 | int ret = 0; |
| 362 | __u16 Wval; |
Johan Hovold | 9e221a3 | 2009-12-28 23:01:55 +0100 | [diff] [blame] | 363 | u8 *buf; |
| 364 | |
| 365 | buf = kmalloc(VENDOR_READ_LENGTH, GFP_KERNEL); |
| 366 | if (!buf) |
| 367 | return -ENOMEM; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 368 | |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 369 | /* dbg("application number is %4x", |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 370 | (((__u16)port->number - (__u16)(port->serial->minor))+1)<<8); */ |
| 371 | /* Wval is same as application number */ |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 372 | if (port->serial->num_ports == 4) { |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 373 | Wval = |
| 374 | (((__u16) port->number - (__u16) (port->serial->minor)) + |
| 375 | 1) << 8; |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 376 | dbg("mos7840_get_uart_reg application number is %x", Wval); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 377 | } else { |
| 378 | if (((__u16) port->number - (__u16) (port->serial->minor)) == 0) { |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 379 | Wval = (((__u16) port->number - |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 380 | (__u16) (port->serial->minor)) + 1) << 8; |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 381 | dbg("mos7840_get_uart_reg application number is %x", |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 382 | Wval); |
| 383 | } else { |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 384 | Wval = (((__u16) port->number - |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 385 | (__u16) (port->serial->minor)) + 2) << 8; |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 386 | dbg("mos7840_get_uart_reg application number is %x", |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 387 | Wval); |
| 388 | } |
| 389 | } |
| 390 | ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), MCS_RDREQ, |
Johan Hovold | 9e221a3 | 2009-12-28 23:01:55 +0100 | [diff] [blame] | 391 | MCS_RD_RTYPE, Wval, reg, buf, VENDOR_READ_LENGTH, |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 392 | MOS_WDR_TIMEOUT); |
Johan Hovold | 9e221a3 | 2009-12-28 23:01:55 +0100 | [diff] [blame] | 393 | *val = buf[0]; |
| 394 | |
| 395 | kfree(buf); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 396 | return ret; |
| 397 | } |
| 398 | |
| 399 | static void mos7840_dump_serial_port(struct moschip_port *mos7840_port) |
| 400 | { |
| 401 | |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 402 | dbg("***************************************"); |
| 403 | dbg("SpRegOffset is %2x", mos7840_port->SpRegOffset); |
| 404 | dbg("ControlRegOffset is %2x", mos7840_port->ControlRegOffset); |
| 405 | dbg("DCRRegOffset is %2x", mos7840_port->DcrRegOffset); |
| 406 | dbg("***************************************"); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 407 | |
| 408 | } |
| 409 | |
| 410 | /************************************************************************/ |
| 411 | /************************************************************************/ |
| 412 | /* I N T E R F A C E F U N C T I O N S */ |
| 413 | /* I N T E R F A C E F U N C T I O N S */ |
| 414 | /************************************************************************/ |
| 415 | /************************************************************************/ |
| 416 | |
| 417 | static inline void mos7840_set_port_private(struct usb_serial_port *port, |
| 418 | struct moschip_port *data) |
| 419 | { |
| 420 | usb_set_serial_port_data(port, (void *)data); |
| 421 | } |
| 422 | |
| 423 | static inline struct moschip_port *mos7840_get_port_private(struct |
| 424 | usb_serial_port |
| 425 | *port) |
| 426 | { |
| 427 | return (struct moschip_port *)usb_get_serial_port_data(port); |
| 428 | } |
| 429 | |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 430 | static void mos7840_handle_new_msr(struct moschip_port *port, __u8 new_msr) |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 431 | { |
| 432 | struct moschip_port *mos7840_port; |
| 433 | struct async_icount *icount; |
| 434 | mos7840_port = port; |
| 435 | icount = &mos7840_port->icount; |
| 436 | if (new_msr & |
| 437 | (MOS_MSR_DELTA_CTS | MOS_MSR_DELTA_DSR | MOS_MSR_DELTA_RI | |
| 438 | MOS_MSR_DELTA_CD)) { |
| 439 | icount = &mos7840_port->icount; |
| 440 | |
| 441 | /* update input line counters */ |
| 442 | if (new_msr & MOS_MSR_DELTA_CTS) { |
| 443 | icount->cts++; |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 444 | smp_wmb(); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 445 | } |
| 446 | if (new_msr & MOS_MSR_DELTA_DSR) { |
| 447 | icount->dsr++; |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 448 | smp_wmb(); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 449 | } |
| 450 | if (new_msr & MOS_MSR_DELTA_CD) { |
| 451 | icount->dcd++; |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 452 | smp_wmb(); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 453 | } |
| 454 | if (new_msr & MOS_MSR_DELTA_RI) { |
| 455 | icount->rng++; |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 456 | smp_wmb(); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 457 | } |
| 458 | } |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 459 | } |
| 460 | |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 461 | static void mos7840_handle_new_lsr(struct moschip_port *port, __u8 new_lsr) |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 462 | { |
| 463 | struct async_icount *icount; |
| 464 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 465 | dbg("%s - %02x", __func__, new_lsr); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 466 | |
| 467 | if (new_lsr & SERIAL_LSR_BI) { |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 468 | /* |
| 469 | * Parity and Framing errors only count if they |
| 470 | * occur exclusive of a break being |
| 471 | * received. |
| 472 | */ |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 473 | new_lsr &= (__u8) (SERIAL_LSR_OE | SERIAL_LSR_BI); |
| 474 | } |
| 475 | |
| 476 | /* update input line counters */ |
| 477 | icount = &port->icount; |
| 478 | if (new_lsr & SERIAL_LSR_BI) { |
| 479 | icount->brk++; |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 480 | smp_wmb(); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 481 | } |
| 482 | if (new_lsr & SERIAL_LSR_OE) { |
| 483 | icount->overrun++; |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 484 | smp_wmb(); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 485 | } |
| 486 | if (new_lsr & SERIAL_LSR_PE) { |
| 487 | icount->parity++; |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 488 | smp_wmb(); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 489 | } |
| 490 | if (new_lsr & SERIAL_LSR_FE) { |
| 491 | icount->frame++; |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 492 | smp_wmb(); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 493 | } |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | /************************************************************************/ |
| 497 | /************************************************************************/ |
| 498 | /* U S B C A L L B A C K F U N C T I O N S */ |
| 499 | /* U S B C A L L B A C K F U N C T I O N S */ |
| 500 | /************************************************************************/ |
| 501 | /************************************************************************/ |
| 502 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 503 | static void mos7840_control_callback(struct urb *urb) |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 504 | { |
| 505 | unsigned char *data; |
| 506 | struct moschip_port *mos7840_port; |
| 507 | __u8 regval = 0x0; |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 508 | int result = 0; |
Greg Kroah-Hartman | 0643c72 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 509 | int status = urb->status; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 510 | |
Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 511 | mos7840_port = urb->context; |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 512 | |
Greg Kroah-Hartman | 0643c72 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 513 | switch (status) { |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 514 | case 0: |
| 515 | /* success */ |
| 516 | break; |
| 517 | case -ECONNRESET: |
| 518 | case -ENOENT: |
| 519 | case -ESHUTDOWN: |
| 520 | /* this urb is terminated, clean up */ |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 521 | dbg("%s - urb shutting down with status: %d", __func__, |
Greg Kroah-Hartman | 0643c72 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 522 | status); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 523 | return; |
| 524 | default: |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 525 | dbg("%s - nonzero urb status received: %d", __func__, |
Greg Kroah-Hartman | 0643c72 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 526 | status); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 527 | goto exit; |
| 528 | } |
| 529 | |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 530 | dbg("%s urb buffer size is %d", __func__, urb->actual_length); |
| 531 | dbg("%s mos7840_port->MsrLsr is %d port %d", __func__, |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 532 | mos7840_port->MsrLsr, mos7840_port->port_num); |
| 533 | data = urb->transfer_buffer; |
| 534 | regval = (__u8) data[0]; |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 535 | dbg("%s data is %x", __func__, regval); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 536 | if (mos7840_port->MsrLsr == 0) |
| 537 | mos7840_handle_new_msr(mos7840_port, regval); |
| 538 | else if (mos7840_port->MsrLsr == 1) |
| 539 | mos7840_handle_new_lsr(mos7840_port, regval); |
| 540 | |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 541 | exit: |
| 542 | spin_lock(&mos7840_port->pool_lock); |
| 543 | if (!mos7840_port->zombie) |
| 544 | result = usb_submit_urb(mos7840_port->int_urb, GFP_ATOMIC); |
| 545 | spin_unlock(&mos7840_port->pool_lock); |
| 546 | if (result) { |
| 547 | dev_err(&urb->dev->dev, |
| 548 | "%s - Error %d submitting interrupt urb\n", |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 549 | __func__, result); |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 550 | } |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | static int mos7840_get_reg(struct moschip_port *mcs, __u16 Wval, __u16 reg, |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 554 | __u16 *val) |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 555 | { |
| 556 | struct usb_device *dev = mcs->port->serial->dev; |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 557 | struct usb_ctrlrequest *dr = mcs->dr; |
| 558 | unsigned char *buffer = mcs->ctrl_buf; |
| 559 | int ret; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 560 | |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 561 | dr->bRequestType = MCS_RD_RTYPE; |
| 562 | dr->bRequest = MCS_RDREQ; |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 563 | dr->wValue = cpu_to_le16(Wval); /* 0 */ |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 564 | dr->wIndex = cpu_to_le16(reg); |
| 565 | dr->wLength = cpu_to_le16(2); |
| 566 | |
| 567 | usb_fill_control_urb(mcs->control_urb, dev, usb_rcvctrlpipe(dev, 0), |
| 568 | (unsigned char *)dr, buffer, 2, |
| 569 | mos7840_control_callback, mcs); |
| 570 | mcs->control_urb->transfer_buffer_length = 2; |
| 571 | ret = usb_submit_urb(mcs->control_urb, GFP_ATOMIC); |
| 572 | return ret; |
| 573 | } |
| 574 | |
| 575 | /***************************************************************************** |
| 576 | * mos7840_interrupt_callback |
| 577 | * this is the callback function for when we have received data on the |
| 578 | * interrupt endpoint. |
| 579 | *****************************************************************************/ |
| 580 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 581 | static void mos7840_interrupt_callback(struct urb *urb) |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 582 | { |
| 583 | int result; |
| 584 | int length; |
| 585 | struct moschip_port *mos7840_port; |
| 586 | struct usb_serial *serial; |
| 587 | __u16 Data; |
| 588 | unsigned char *data; |
| 589 | __u8 sp[5], st; |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 590 | int i, rv = 0; |
| 591 | __u16 wval, wreg = 0; |
Greg Kroah-Hartman | 0643c72 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 592 | int status = urb->status; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 593 | |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 594 | dbg("%s", " : Entering"); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 595 | |
Greg Kroah-Hartman | 0643c72 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 596 | switch (status) { |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 597 | case 0: |
| 598 | /* success */ |
| 599 | break; |
| 600 | case -ECONNRESET: |
| 601 | case -ENOENT: |
| 602 | case -ESHUTDOWN: |
| 603 | /* this urb is terminated, clean up */ |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 604 | dbg("%s - urb shutting down with status: %d", __func__, |
Greg Kroah-Hartman | 0643c72 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 605 | status); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 606 | return; |
| 607 | default: |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 608 | dbg("%s - nonzero urb status received: %d", __func__, |
Greg Kroah-Hartman | 0643c72 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 609 | status); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 610 | goto exit; |
| 611 | } |
| 612 | |
| 613 | length = urb->actual_length; |
| 614 | data = urb->transfer_buffer; |
| 615 | |
Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 616 | serial = urb->context; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 617 | |
| 618 | /* Moschip get 5 bytes |
| 619 | * Byte 1 IIR Port 1 (port.number is 0) |
| 620 | * Byte 2 IIR Port 2 (port.number is 1) |
| 621 | * Byte 3 IIR Port 3 (port.number is 2) |
| 622 | * Byte 4 IIR Port 4 (port.number is 3) |
| 623 | * Byte 5 FIFO status for both */ |
| 624 | |
| 625 | if (length && length > 5) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 626 | dbg("%s", "Wrong data !!!"); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 627 | return; |
| 628 | } |
| 629 | |
| 630 | sp[0] = (__u8) data[0]; |
| 631 | sp[1] = (__u8) data[1]; |
| 632 | sp[2] = (__u8) data[2]; |
| 633 | sp[3] = (__u8) data[3]; |
| 634 | st = (__u8) data[4]; |
| 635 | |
| 636 | for (i = 0; i < serial->num_ports; i++) { |
| 637 | mos7840_port = mos7840_get_port_private(serial->port[i]); |
| 638 | wval = |
| 639 | (((__u16) serial->port[i]->number - |
| 640 | (__u16) (serial->minor)) + 1) << 8; |
| 641 | if (mos7840_port->open) { |
| 642 | if (sp[i] & 0x01) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 643 | dbg("SP%d No Interrupt !!!", i); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 644 | } else { |
| 645 | switch (sp[i] & 0x0f) { |
| 646 | case SERIAL_IIR_RLS: |
| 647 | dbg("Serial Port %d: Receiver status error or ", i); |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 648 | dbg("address bit detected in 9-bit mode"); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 649 | mos7840_port->MsrLsr = 1; |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 650 | wreg = LINE_STATUS_REGISTER; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 651 | break; |
| 652 | case SERIAL_IIR_MS: |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 653 | dbg("Serial Port %d: Modem status change", i); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 654 | mos7840_port->MsrLsr = 0; |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 655 | wreg = MODEM_STATUS_REGISTER; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 656 | break; |
| 657 | } |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 658 | spin_lock(&mos7840_port->pool_lock); |
| 659 | if (!mos7840_port->zombie) { |
| 660 | rv = mos7840_get_reg(mos7840_port, wval, wreg, &Data); |
| 661 | } else { |
| 662 | spin_unlock(&mos7840_port->pool_lock); |
| 663 | return; |
| 664 | } |
| 665 | spin_unlock(&mos7840_port->pool_lock); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 666 | } |
| 667 | } |
| 668 | } |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 669 | if (!(rv < 0)) |
| 670 | /* the completion handler for the control urb will resubmit */ |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 671 | return; |
| 672 | exit: |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 673 | result = usb_submit_urb(urb, GFP_ATOMIC); |
| 674 | if (result) { |
| 675 | dev_err(&urb->dev->dev, |
| 676 | "%s - Error %d submitting interrupt urb\n", |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 677 | __func__, result); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 678 | } |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | static int mos7840_port_paranoia_check(struct usb_serial_port *port, |
| 682 | const char *function) |
| 683 | { |
| 684 | if (!port) { |
| 685 | dbg("%s - port == NULL", function); |
| 686 | return -1; |
| 687 | } |
| 688 | if (!port->serial) { |
| 689 | dbg("%s - port->serial == NULL", function); |
| 690 | return -1; |
| 691 | } |
| 692 | |
| 693 | return 0; |
| 694 | } |
| 695 | |
| 696 | /* Inline functions to check the sanity of a pointer that is passed to us */ |
| 697 | static int mos7840_serial_paranoia_check(struct usb_serial *serial, |
| 698 | const char *function) |
| 699 | { |
| 700 | if (!serial) { |
| 701 | dbg("%s - serial == NULL", function); |
| 702 | return -1; |
| 703 | } |
| 704 | if (!serial->type) { |
| 705 | dbg("%s - serial->type == NULL!", function); |
| 706 | return -1; |
| 707 | } |
| 708 | |
| 709 | return 0; |
| 710 | } |
| 711 | |
| 712 | static struct usb_serial *mos7840_get_usb_serial(struct usb_serial_port *port, |
| 713 | const char *function) |
| 714 | { |
| 715 | /* if no port was specified, or it fails a paranoia check */ |
| 716 | if (!port || |
| 717 | mos7840_port_paranoia_check(port, function) || |
| 718 | mos7840_serial_paranoia_check(port->serial, function)) { |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 719 | /* then say that we don't have a valid usb_serial thing, |
| 720 | * which will end up genrating -ENODEV return values */ |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 721 | return NULL; |
| 722 | } |
| 723 | |
| 724 | return port->serial; |
| 725 | } |
| 726 | |
| 727 | /***************************************************************************** |
| 728 | * mos7840_bulk_in_callback |
| 729 | * this is the callback function for when we have received data on the |
| 730 | * bulk in endpoint. |
| 731 | *****************************************************************************/ |
| 732 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 733 | static void mos7840_bulk_in_callback(struct urb *urb) |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 734 | { |
Greg Kroah-Hartman | 0643c72 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 735 | int retval; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 736 | unsigned char *data; |
| 737 | struct usb_serial *serial; |
| 738 | struct usb_serial_port *port; |
| 739 | struct moschip_port *mos7840_port; |
| 740 | struct tty_struct *tty; |
Greg Kroah-Hartman | 0643c72 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 741 | int status = urb->status; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 742 | |
Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 743 | mos7840_port = urb->context; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 744 | if (!mos7840_port) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 745 | dbg("%s", "NULL mos7840_port pointer"); |
Greg Kroah-Hartman | 50de36f | 2008-12-10 16:00:30 -0800 | [diff] [blame] | 746 | return; |
| 747 | } |
| 748 | |
| 749 | if (status) { |
| 750 | dbg("nonzero read bulk status received: %d", status); |
| 751 | mos7840_port->read_urb_busy = false; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 752 | return; |
| 753 | } |
| 754 | |
| 755 | port = (struct usb_serial_port *)mos7840_port->port; |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 756 | if (mos7840_port_paranoia_check(port, __func__)) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 757 | dbg("%s", "Port Paranoia failed"); |
Greg Kroah-Hartman | 50de36f | 2008-12-10 16:00:30 -0800 | [diff] [blame] | 758 | mos7840_port->read_urb_busy = false; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 759 | return; |
| 760 | } |
| 761 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 762 | serial = mos7840_get_usb_serial(port, __func__); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 763 | if (!serial) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 764 | dbg("%s", "Bad serial pointer"); |
Greg Kroah-Hartman | 50de36f | 2008-12-10 16:00:30 -0800 | [diff] [blame] | 765 | mos7840_port->read_urb_busy = false; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 766 | return; |
| 767 | } |
| 768 | |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 769 | dbg("%s", "Entering... "); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 770 | |
| 771 | data = urb->transfer_buffer; |
| 772 | |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 773 | dbg("%s", "Entering ..........."); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 774 | |
| 775 | if (urb->actual_length) { |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 776 | tty = tty_port_tty_get(&mos7840_port->port->port); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 777 | if (tty) { |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 778 | tty_insert_flip_string(tty, data, urb->actual_length); |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 779 | dbg(" %s ", data); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 780 | tty_flip_buffer_push(tty); |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 781 | tty_kref_put(tty); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 782 | } |
| 783 | mos7840_port->icount.rx += urb->actual_length; |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 784 | smp_wmb(); |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 785 | dbg("mos7840_port->icount.rx is %d:", |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 786 | mos7840_port->icount.rx); |
| 787 | } |
| 788 | |
| 789 | if (!mos7840_port->read_urb) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 790 | dbg("%s", "URB KILLED !!!"); |
Greg Kroah-Hartman | 50de36f | 2008-12-10 16:00:30 -0800 | [diff] [blame] | 791 | mos7840_port->read_urb_busy = false; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 792 | return; |
| 793 | } |
| 794 | |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 795 | |
Greg Kroah-Hartman | 50de36f | 2008-12-10 16:00:30 -0800 | [diff] [blame] | 796 | mos7840_port->read_urb_busy = true; |
Greg Kroah-Hartman | 0643c72 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 797 | retval = usb_submit_urb(mos7840_port->read_urb, GFP_ATOMIC); |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 798 | |
Greg Kroah-Hartman | 0643c72 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 799 | if (retval) { |
Greg Kroah-Hartman | 50de36f | 2008-12-10 16:00:30 -0800 | [diff] [blame] | 800 | dbg("usb_submit_urb(read bulk) failed, retval = %d", retval); |
| 801 | mos7840_port->read_urb_busy = false; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 802 | } |
| 803 | } |
| 804 | |
| 805 | /***************************************************************************** |
| 806 | * mos7840_bulk_out_data_callback |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 807 | * this is the callback function for when we have finished sending |
| 808 | * serial data on the bulk out endpoint. |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 809 | *****************************************************************************/ |
| 810 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 811 | static void mos7840_bulk_out_data_callback(struct urb *urb) |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 812 | { |
| 813 | struct moschip_port *mos7840_port; |
| 814 | struct tty_struct *tty; |
Greg Kroah-Hartman | 0643c72 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 815 | int status = urb->status; |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 816 | int i; |
| 817 | |
Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 818 | mos7840_port = urb->context; |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 819 | spin_lock(&mos7840_port->pool_lock); |
| 820 | for (i = 0; i < NUM_URBS; i++) { |
| 821 | if (urb == mos7840_port->write_urb_pool[i]) { |
| 822 | mos7840_port->busy[i] = 0; |
| 823 | break; |
| 824 | } |
| 825 | } |
| 826 | spin_unlock(&mos7840_port->pool_lock); |
| 827 | |
Greg Kroah-Hartman | 0643c72 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 828 | if (status) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 829 | dbg("nonzero write bulk status received:%d", status); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 830 | return; |
| 831 | } |
| 832 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 833 | if (mos7840_port_paranoia_check(mos7840_port->port, __func__)) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 834 | dbg("%s", "Port Paranoia failed"); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 835 | return; |
| 836 | } |
| 837 | |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 838 | dbg("%s", "Entering ........."); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 839 | |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 840 | tty = tty_port_tty_get(&mos7840_port->port->port); |
Jiri Slaby | b963a84 | 2007-02-10 01:44:55 -0800 | [diff] [blame] | 841 | if (tty && mos7840_port->open) |
| 842 | tty_wakeup(tty); |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 843 | tty_kref_put(tty); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 844 | |
| 845 | } |
| 846 | |
| 847 | /************************************************************************/ |
| 848 | /* 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 */ |
| 849 | /************************************************************************/ |
| 850 | #ifdef MCSSerialProbe |
| 851 | static int mos7840_serial_probe(struct usb_serial *serial, |
| 852 | const struct usb_device_id *id) |
| 853 | { |
| 854 | |
| 855 | /*need to implement the mode_reg reading and updating\ |
| 856 | structures usb_serial_ device_type\ |
| 857 | (i.e num_ports, num_bulkin,bulkout etc) */ |
| 858 | /* Also we can update the changes attach */ |
| 859 | return 1; |
| 860 | } |
| 861 | #endif |
| 862 | |
| 863 | /***************************************************************************** |
| 864 | * mos7840_open |
| 865 | * this function is called by the tty driver when a port is opened |
| 866 | * If successful, we return 0 |
| 867 | * Otherwise we return a negative error number. |
| 868 | *****************************************************************************/ |
| 869 | |
Alan Cox | a509a7e | 2009-09-19 13:13:26 -0700 | [diff] [blame] | 870 | static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port) |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 871 | { |
| 872 | int response; |
| 873 | int j; |
| 874 | struct usb_serial *serial; |
| 875 | struct urb *urb; |
| 876 | __u16 Data; |
| 877 | int status; |
| 878 | struct moschip_port *mos7840_port; |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 879 | struct moschip_port *port0; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 880 | |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 881 | dbg ("%s enter", __func__); |
| 882 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 883 | if (mos7840_port_paranoia_check(port, __func__)) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 884 | dbg("%s", "Port Paranoia failed"); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 885 | return -ENODEV; |
| 886 | } |
| 887 | |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 888 | serial = port->serial; |
| 889 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 890 | if (mos7840_serial_paranoia_check(serial, __func__)) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 891 | dbg("%s", "Serial Paranoia failed"); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 892 | return -ENODEV; |
| 893 | } |
| 894 | |
| 895 | mos7840_port = mos7840_get_port_private(port); |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 896 | port0 = mos7840_get_port_private(serial->port[0]); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 897 | |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 898 | if (mos7840_port == NULL || port0 == NULL) |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 899 | return -ENODEV; |
| 900 | |
| 901 | usb_clear_halt(serial->dev, port->write_urb->pipe); |
| 902 | usb_clear_halt(serial->dev, port->read_urb->pipe); |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 903 | port0->open_ports++; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 904 | |
| 905 | /* Initialising the write urb pool */ |
| 906 | for (j = 0; j < NUM_URBS; ++j) { |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 907 | urb = usb_alloc_urb(0, GFP_KERNEL); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 908 | mos7840_port->write_urb_pool[j] = urb; |
| 909 | |
| 910 | if (urb == NULL) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 911 | dev_err(&port->dev, "No more urbs???\n"); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 912 | continue; |
| 913 | } |
| 914 | |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 915 | urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE, |
| 916 | GFP_KERNEL); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 917 | if (!urb->transfer_buffer) { |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 918 | usb_free_urb(urb); |
| 919 | mos7840_port->write_urb_pool[j] = NULL; |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 920 | dev_err(&port->dev, |
| 921 | "%s-out of memory for urb buffers.\n", |
| 922 | __func__); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 923 | continue; |
| 924 | } |
| 925 | } |
| 926 | |
| 927 | /***************************************************************************** |
| 928 | * Initialize MCS7840 -- Write Init values to corresponding Registers |
| 929 | * |
| 930 | * Register Index |
| 931 | * 1 : IER |
| 932 | * 2 : FCR |
| 933 | * 3 : LCR |
| 934 | * 4 : MCR |
| 935 | * |
| 936 | * 0x08 : SP1/2 Control Reg |
| 937 | *****************************************************************************/ |
| 938 | |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 939 | /* NEED to check the following Block */ |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 940 | |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 941 | Data = 0x0; |
| 942 | status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, &Data); |
| 943 | if (status < 0) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 944 | dbg("Reading Spreg failed"); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 945 | return -1; |
| 946 | } |
| 947 | Data |= 0x80; |
| 948 | status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data); |
| 949 | if (status < 0) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 950 | dbg("writing Spreg failed"); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 951 | return -1; |
| 952 | } |
| 953 | |
| 954 | Data &= ~0x80; |
| 955 | status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data); |
| 956 | if (status < 0) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 957 | dbg("writing Spreg failed"); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 958 | return -1; |
| 959 | } |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 960 | /* End of block to be checked */ |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 961 | |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 962 | Data = 0x0; |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 963 | status = mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset, |
| 964 | &Data); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 965 | if (status < 0) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 966 | dbg("Reading Controlreg failed"); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 967 | return -1; |
| 968 | } |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 969 | Data |= 0x08; /* Driver done bit */ |
| 970 | Data |= 0x20; /* rx_disable */ |
| 971 | status = mos7840_set_reg_sync(port, |
| 972 | mos7840_port->ControlRegOffset, Data); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 973 | if (status < 0) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 974 | dbg("writing Controlreg failed"); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 975 | return -1; |
| 976 | } |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 977 | /* do register settings here */ |
| 978 | /* Set all regs to the device default values. */ |
| 979 | /*********************************** |
| 980 | * First Disable all interrupts. |
| 981 | ***********************************/ |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 982 | Data = 0x00; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 983 | status = mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data); |
| 984 | if (status < 0) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 985 | dbg("disabling interrupts failed"); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 986 | return -1; |
| 987 | } |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 988 | /* Set FIFO_CONTROL_REGISTER to the default value */ |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 989 | Data = 0x00; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 990 | status = mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data); |
| 991 | if (status < 0) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 992 | dbg("Writing FIFO_CONTROL_REGISTER failed"); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 993 | return -1; |
| 994 | } |
| 995 | |
| 996 | Data = 0xcf; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 997 | status = mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data); |
| 998 | if (status < 0) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 999 | dbg("Writing FIFO_CONTROL_REGISTER failed"); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1000 | return -1; |
| 1001 | } |
| 1002 | |
| 1003 | Data = 0x03; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1004 | status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); |
| 1005 | mos7840_port->shadowLCR = Data; |
| 1006 | |
| 1007 | Data = 0x0b; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1008 | status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); |
| 1009 | mos7840_port->shadowMCR = Data; |
| 1010 | |
| 1011 | Data = 0x00; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1012 | status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data); |
| 1013 | mos7840_port->shadowLCR = Data; |
| 1014 | |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 1015 | Data |= SERIAL_LCR_DLAB; /* data latch enable in LCR 0x80 */ |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1016 | status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); |
| 1017 | |
| 1018 | Data = 0x0c; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1019 | status = mos7840_set_uart_reg(port, DIVISOR_LATCH_LSB, Data); |
| 1020 | |
| 1021 | Data = 0x0; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1022 | status = mos7840_set_uart_reg(port, DIVISOR_LATCH_MSB, Data); |
| 1023 | |
| 1024 | Data = 0x00; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1025 | status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data); |
| 1026 | |
| 1027 | Data = Data & ~SERIAL_LCR_DLAB; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1028 | status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); |
| 1029 | mos7840_port->shadowLCR = Data; |
| 1030 | |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 1031 | /* clearing Bulkin and Bulkout Fifo */ |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1032 | Data = 0x0; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1033 | status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, &Data); |
| 1034 | |
| 1035 | Data = Data | 0x0c; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1036 | status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data); |
| 1037 | |
| 1038 | Data = Data & ~0x0c; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1039 | status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data); |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 1040 | /* Finally enable all interrupts */ |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1041 | Data = 0x0c; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1042 | status = mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data); |
| 1043 | |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 1044 | /* clearing rx_disable */ |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1045 | Data = 0x0; |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 1046 | status = mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset, |
| 1047 | &Data); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1048 | Data = Data & ~0x20; |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 1049 | status = mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset, |
| 1050 | Data); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1051 | |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 1052 | /* rx_negate */ |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1053 | Data = 0x0; |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 1054 | status = mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset, |
| 1055 | &Data); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1056 | Data = Data | 0x10; |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 1057 | status = mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset, |
| 1058 | Data); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1059 | |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 1060 | /* Check to see if we've set up our endpoint info yet * |
| 1061 | * (can't set it up in mos7840_startup as the structures * |
| 1062 | * were not set up at that time.) */ |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 1063 | if (port0->open_ports == 1) { |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1064 | if (serial->port[0]->interrupt_in_buffer == NULL) { |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1065 | /* set up interrupt urb */ |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1066 | usb_fill_int_urb(serial->port[0]->interrupt_in_urb, |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 1067 | serial->dev, |
| 1068 | usb_rcvintpipe(serial->dev, |
| 1069 | serial->port[0]->interrupt_in_endpointAddress), |
| 1070 | serial->port[0]->interrupt_in_buffer, |
| 1071 | serial->port[0]->interrupt_in_urb-> |
| 1072 | transfer_buffer_length, |
| 1073 | mos7840_interrupt_callback, |
| 1074 | serial, |
| 1075 | serial->port[0]->interrupt_in_urb->interval); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1076 | |
| 1077 | /* start interrupt read for mos7840 * |
| 1078 | * will continue as long as mos7840 is connected */ |
| 1079 | |
| 1080 | response = |
| 1081 | usb_submit_urb(serial->port[0]->interrupt_in_urb, |
| 1082 | GFP_KERNEL); |
| 1083 | if (response) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 1084 | dev_err(&port->dev, "%s - Error %d submitting " |
| 1085 | "interrupt urb\n", __func__, response); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1086 | } |
| 1087 | |
| 1088 | } |
| 1089 | |
| 1090 | } |
| 1091 | |
| 1092 | /* see if we've set up our endpoint info yet * |
| 1093 | * (can't set it up in mos7840_startup as the * |
| 1094 | * structures were not set up at that time.) */ |
| 1095 | |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1096 | dbg("port number is %d", port->number); |
| 1097 | dbg("serial number is %d", port->serial->minor); |
| 1098 | dbg("Bulkin endpoint is %d", port->bulk_in_endpointAddress); |
| 1099 | dbg("BulkOut endpoint is %d", port->bulk_out_endpointAddress); |
| 1100 | dbg("Interrupt endpoint is %d", port->interrupt_in_endpointAddress); |
| 1101 | dbg("port's number in the device is %d", mos7840_port->port_num); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1102 | mos7840_port->read_urb = port->read_urb; |
| 1103 | |
| 1104 | /* set up our bulk in urb */ |
Donald Lee | 093ea2d | 2012-03-14 15:26:33 +0800 | [diff] [blame] | 1105 | if ((serial->num_ports == 2) |
| 1106 | && ((((__u16)port->number - |
| 1107 | (__u16)(port->serial->minor)) % 2) != 0)) { |
| 1108 | usb_fill_bulk_urb(mos7840_port->read_urb, |
| 1109 | serial->dev, |
| 1110 | usb_rcvbulkpipe(serial->dev, |
| 1111 | (port->bulk_in_endpointAddress) + 2), |
| 1112 | port->bulk_in_buffer, |
| 1113 | mos7840_port->read_urb->transfer_buffer_length, |
| 1114 | mos7840_bulk_in_callback, mos7840_port); |
| 1115 | } else { |
| 1116 | usb_fill_bulk_urb(mos7840_port->read_urb, |
| 1117 | serial->dev, |
| 1118 | usb_rcvbulkpipe(serial->dev, |
| 1119 | port->bulk_in_endpointAddress), |
| 1120 | port->bulk_in_buffer, |
| 1121 | mos7840_port->read_urb->transfer_buffer_length, |
| 1122 | mos7840_bulk_in_callback, mos7840_port); |
| 1123 | } |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1124 | |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1125 | dbg("mos7840_open: bulkin endpoint is %d", |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1126 | port->bulk_in_endpointAddress); |
Greg Kroah-Hartman | 50de36f | 2008-12-10 16:00:30 -0800 | [diff] [blame] | 1127 | mos7840_port->read_urb_busy = true; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1128 | response = usb_submit_urb(mos7840_port->read_urb, GFP_KERNEL); |
| 1129 | if (response) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 1130 | dev_err(&port->dev, "%s - Error %d submitting control urb\n", |
| 1131 | __func__, response); |
Greg Kroah-Hartman | 50de36f | 2008-12-10 16:00:30 -0800 | [diff] [blame] | 1132 | mos7840_port->read_urb_busy = false; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1133 | } |
| 1134 | |
| 1135 | /* initialize our wait queues */ |
| 1136 | init_waitqueue_head(&mos7840_port->wait_chase); |
| 1137 | init_waitqueue_head(&mos7840_port->delta_msr_wait); |
| 1138 | |
| 1139 | /* initialize our icount structure */ |
| 1140 | memset(&(mos7840_port->icount), 0x00, sizeof(mos7840_port->icount)); |
| 1141 | |
| 1142 | /* initialize our port settings */ |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 1143 | /* Must set to enable ints! */ |
| 1144 | mos7840_port->shadowMCR = MCR_MASTER_IE; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1145 | /* send a open port command */ |
| 1146 | mos7840_port->open = 1; |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 1147 | /* mos7840_change_port_settings(mos7840_port,old_termios); */ |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1148 | mos7840_port->icount.tx = 0; |
| 1149 | mos7840_port->icount.rx = 0; |
| 1150 | |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1151 | dbg("usb_serial serial:%p mos7840_port:%p\n usb_serial_port port:%p", |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 1152 | serial, mos7840_port, port); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1153 | |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1154 | dbg ("%s leave", __func__); |
| 1155 | |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1156 | return 0; |
| 1157 | |
| 1158 | } |
| 1159 | |
| 1160 | /***************************************************************************** |
| 1161 | * mos7840_chars_in_buffer |
| 1162 | * this function is called by the tty driver when it wants to know how many |
| 1163 | * bytes of data we currently have outstanding in the port (data that has |
| 1164 | * been written, but hasn't made it out the port yet) |
| 1165 | * If successful, we return the number of bytes left to be written in the |
| 1166 | * system, |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1167 | * Otherwise we return zero. |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1168 | *****************************************************************************/ |
| 1169 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1170 | static int mos7840_chars_in_buffer(struct tty_struct *tty) |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1171 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1172 | struct usb_serial_port *port = tty->driver_data; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1173 | int i; |
| 1174 | int chars = 0; |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 1175 | unsigned long flags; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1176 | struct moschip_port *mos7840_port; |
| 1177 | |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1178 | dbg("%s", " mos7840_chars_in_buffer:entering ..........."); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1179 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1180 | if (mos7840_port_paranoia_check(port, __func__)) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1181 | dbg("%s", "Invalid port"); |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1182 | return 0; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1183 | } |
| 1184 | |
| 1185 | mos7840_port = mos7840_get_port_private(port); |
| 1186 | if (mos7840_port == NULL) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1187 | dbg("%s", "mos7840_break:leaving ..........."); |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1188 | return 0; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1189 | } |
| 1190 | |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 1191 | spin_lock_irqsave(&mos7840_port->pool_lock, flags); |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1192 | for (i = 0; i < NUM_URBS; ++i) |
| 1193 | if (mos7840_port->busy[i]) |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1194 | chars += URB_TRANSFER_BUFFER_SIZE; |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 1195 | spin_unlock_irqrestore(&mos7840_port->pool_lock, flags); |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1196 | dbg("%s - returns %d", __func__, chars); |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 1197 | return chars; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1198 | |
| 1199 | } |
| 1200 | |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1201 | /***************************************************************************** |
| 1202 | * mos7840_close |
| 1203 | * this function is called by the tty driver when a port is closed |
| 1204 | *****************************************************************************/ |
| 1205 | |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 1206 | static void mos7840_close(struct usb_serial_port *port) |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1207 | { |
| 1208 | struct usb_serial *serial; |
| 1209 | struct moschip_port *mos7840_port; |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 1210 | struct moschip_port *port0; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1211 | int j; |
| 1212 | __u16 Data; |
| 1213 | |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1214 | dbg("%s", "mos7840_close:entering..."); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1215 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1216 | if (mos7840_port_paranoia_check(port, __func__)) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1217 | dbg("%s", "Port Paranoia failed"); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1218 | return; |
| 1219 | } |
| 1220 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1221 | serial = mos7840_get_usb_serial(port, __func__); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1222 | if (!serial) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1223 | dbg("%s", "Serial Paranoia failed"); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1224 | return; |
| 1225 | } |
| 1226 | |
| 1227 | mos7840_port = mos7840_get_port_private(port); |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 1228 | port0 = mos7840_get_port_private(serial->port[0]); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1229 | |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 1230 | if (mos7840_port == NULL || port0 == NULL) |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1231 | return; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1232 | |
| 1233 | for (j = 0; j < NUM_URBS; ++j) |
| 1234 | usb_kill_urb(mos7840_port->write_urb_pool[j]); |
| 1235 | |
| 1236 | /* Freeing Write URBs */ |
| 1237 | for (j = 0; j < NUM_URBS; ++j) { |
| 1238 | if (mos7840_port->write_urb_pool[j]) { |
| 1239 | if (mos7840_port->write_urb_pool[j]->transfer_buffer) |
| 1240 | kfree(mos7840_port->write_urb_pool[j]-> |
| 1241 | transfer_buffer); |
| 1242 | |
| 1243 | usb_free_urb(mos7840_port->write_urb_pool[j]); |
| 1244 | } |
| 1245 | } |
| 1246 | |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1247 | /* While closing port, shutdown all bulk read, write * |
| 1248 | * and interrupt read if they exists */ |
| 1249 | if (serial->dev) { |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1250 | if (mos7840_port->write_urb) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1251 | dbg("%s", "Shutdown bulk write"); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1252 | usb_kill_urb(mos7840_port->write_urb); |
| 1253 | } |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1254 | if (mos7840_port->read_urb) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1255 | dbg("%s", "Shutdown bulk read"); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1256 | usb_kill_urb(mos7840_port->read_urb); |
Greg Kroah-Hartman | 50de36f | 2008-12-10 16:00:30 -0800 | [diff] [blame] | 1257 | mos7840_port->read_urb_busy = false; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1258 | } |
| 1259 | if ((&mos7840_port->control_urb)) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1260 | dbg("%s", "Shutdown control read"); |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 1261 | /*/ usb_kill_urb (mos7840_port->control_urb); */ |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1262 | } |
| 1263 | } |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 1264 | /* if(mos7840_port->ctrl_buf != NULL) */ |
| 1265 | /* kfree(mos7840_port->ctrl_buf); */ |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 1266 | port0->open_ports--; |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1267 | dbg("mos7840_num_open_ports in close%d:in port%d", |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 1268 | port0->open_ports, port->number); |
| 1269 | if (port0->open_ports == 0) { |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1270 | if (serial->port[0]->interrupt_in_urb) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1271 | dbg("%s", "Shutdown interrupt_in_urb"); |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 1272 | usb_kill_urb(serial->port[0]->interrupt_in_urb); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1273 | } |
| 1274 | } |
| 1275 | |
| 1276 | if (mos7840_port->write_urb) { |
| 1277 | /* if this urb had a transfer buffer already (old tx) free it */ |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 1278 | if (mos7840_port->write_urb->transfer_buffer != NULL) |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1279 | kfree(mos7840_port->write_urb->transfer_buffer); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1280 | usb_free_urb(mos7840_port->write_urb); |
| 1281 | } |
| 1282 | |
| 1283 | Data = 0x0; |
| 1284 | mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); |
| 1285 | |
| 1286 | Data = 0x00; |
| 1287 | mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data); |
| 1288 | |
| 1289 | mos7840_port->open = 0; |
| 1290 | |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1291 | dbg("%s", "Leaving ............"); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1292 | } |
| 1293 | |
| 1294 | /************************************************************************ |
| 1295 | * |
| 1296 | * mos7840_block_until_chase_response |
| 1297 | * |
| 1298 | * This function will block the close until one of the following: |
| 1299 | * 1. Response to our Chase comes from mos7840 |
Joe Perches | dc0d5c1 | 2007-12-17 11:40:18 -0800 | [diff] [blame] | 1300 | * 2. A timeout of 10 seconds without activity has expired |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1301 | * (1K of mos7840 data @ 2400 baud ==> 4 sec to empty) |
| 1302 | * |
| 1303 | ************************************************************************/ |
| 1304 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1305 | static void mos7840_block_until_chase_response(struct tty_struct *tty, |
| 1306 | struct moschip_port *mos7840_port) |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1307 | { |
| 1308 | int timeout = 1 * HZ; |
| 1309 | int wait = 10; |
| 1310 | int count; |
| 1311 | |
| 1312 | while (1) { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1313 | count = mos7840_chars_in_buffer(tty); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1314 | |
| 1315 | /* Check for Buffer status */ |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 1316 | if (count <= 0) |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1317 | return; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1318 | |
| 1319 | /* Block the thread for a while */ |
| 1320 | interruptible_sleep_on_timeout(&mos7840_port->wait_chase, |
| 1321 | timeout); |
| 1322 | /* No activity.. count down section */ |
| 1323 | wait--; |
| 1324 | if (wait == 0) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1325 | dbg("%s - TIMEOUT", __func__); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1326 | return; |
| 1327 | } else { |
Joe Perches | dc0d5c1 | 2007-12-17 11:40:18 -0800 | [diff] [blame] | 1328 | /* Reset timeout value back to seconds */ |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1329 | wait = 10; |
| 1330 | } |
| 1331 | } |
| 1332 | |
| 1333 | } |
| 1334 | |
| 1335 | /***************************************************************************** |
| 1336 | * mos7840_break |
| 1337 | * this function sends a break to the port |
| 1338 | *****************************************************************************/ |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1339 | static void mos7840_break(struct tty_struct *tty, int break_state) |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1340 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1341 | struct usb_serial_port *port = tty->driver_data; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1342 | unsigned char data; |
| 1343 | struct usb_serial *serial; |
| 1344 | struct moschip_port *mos7840_port; |
| 1345 | |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1346 | dbg("%s", "Entering ..........."); |
| 1347 | dbg("mos7840_break: Start"); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1348 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1349 | if (mos7840_port_paranoia_check(port, __func__)) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1350 | dbg("%s", "Port Paranoia failed"); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1351 | return; |
| 1352 | } |
| 1353 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1354 | serial = mos7840_get_usb_serial(port, __func__); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1355 | if (!serial) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1356 | dbg("%s", "Serial Paranoia failed"); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1357 | return; |
| 1358 | } |
| 1359 | |
| 1360 | mos7840_port = mos7840_get_port_private(port); |
| 1361 | |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 1362 | if (mos7840_port == NULL) |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1363 | return; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1364 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1365 | if (serial->dev) |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1366 | /* flush and block until tx is empty */ |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1367 | mos7840_block_until_chase_response(tty, mos7840_port); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1368 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1369 | if (break_state == -1) |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1370 | data = mos7840_port->shadowLCR | LCR_SET_BREAK; |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1371 | else |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1372 | data = mos7840_port->shadowLCR & ~LCR_SET_BREAK; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1373 | |
Alan Cox | 6b447f04 | 2009-01-02 13:48:56 +0000 | [diff] [blame] | 1374 | /* FIXME: no locking on shadowLCR anywhere in driver */ |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1375 | mos7840_port->shadowLCR = data; |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1376 | dbg("mcs7840_break mos7840_port->shadowLCR is %x", |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1377 | mos7840_port->shadowLCR); |
| 1378 | mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, |
| 1379 | mos7840_port->shadowLCR); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1380 | } |
| 1381 | |
| 1382 | /***************************************************************************** |
| 1383 | * mos7840_write_room |
| 1384 | * this function is called by the tty driver when it wants to know how many |
| 1385 | * bytes of data we can accept for a specific port. |
| 1386 | * If successful, we return the amount of room that we have for this port |
| 1387 | * Otherwise we return a negative error number. |
| 1388 | *****************************************************************************/ |
| 1389 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1390 | static int mos7840_write_room(struct tty_struct *tty) |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1391 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1392 | struct usb_serial_port *port = tty->driver_data; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1393 | int i; |
| 1394 | int room = 0; |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 1395 | unsigned long flags; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1396 | struct moschip_port *mos7840_port; |
| 1397 | |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1398 | dbg("%s", " mos7840_write_room:entering ..........."); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1399 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1400 | if (mos7840_port_paranoia_check(port, __func__)) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1401 | dbg("%s", "Invalid port"); |
| 1402 | dbg("%s", " mos7840_write_room:leaving ..........."); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1403 | return -1; |
| 1404 | } |
| 1405 | |
| 1406 | mos7840_port = mos7840_get_port_private(port); |
| 1407 | if (mos7840_port == NULL) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1408 | dbg("%s", "mos7840_break:leaving ..........."); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1409 | return -1; |
| 1410 | } |
| 1411 | |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 1412 | spin_lock_irqsave(&mos7840_port->pool_lock, flags); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1413 | for (i = 0; i < NUM_URBS; ++i) { |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 1414 | if (!mos7840_port->busy[i]) |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1415 | room += URB_TRANSFER_BUFFER_SIZE; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1416 | } |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 1417 | spin_unlock_irqrestore(&mos7840_port->pool_lock, flags); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1418 | |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 1419 | room = (room == 0) ? 0 : room - URB_TRANSFER_BUFFER_SIZE + 1; |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1420 | dbg("%s - returns %d", __func__, room); |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 1421 | return room; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1422 | |
| 1423 | } |
| 1424 | |
| 1425 | /***************************************************************************** |
| 1426 | * mos7840_write |
| 1427 | * this function is called by the tty driver when data should be written to |
| 1428 | * the port. |
| 1429 | * If successful, we return the number of bytes written, otherwise we |
| 1430 | * return a negative error number. |
| 1431 | *****************************************************************************/ |
| 1432 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1433 | static int mos7840_write(struct tty_struct *tty, struct usb_serial_port *port, |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1434 | const unsigned char *data, int count) |
| 1435 | { |
| 1436 | int status; |
| 1437 | int i; |
| 1438 | int bytes_sent = 0; |
| 1439 | int transfer_size; |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 1440 | unsigned long flags; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1441 | |
| 1442 | struct moschip_port *mos7840_port; |
| 1443 | struct usb_serial *serial; |
| 1444 | struct urb *urb; |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 1445 | /* __u16 Data; */ |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1446 | const unsigned char *current_position = data; |
| 1447 | unsigned char *data1; |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1448 | dbg("%s", "entering ..........."); |
| 1449 | /* dbg("mos7840_write: mos7840_port->shadowLCR is %x", |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 1450 | mos7840_port->shadowLCR); */ |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1451 | |
| 1452 | #ifdef NOTMOS7840 |
| 1453 | Data = 0x00; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1454 | status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data); |
| 1455 | mos7840_port->shadowLCR = Data; |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1456 | dbg("mos7840_write: LINE_CONTROL_REGISTER is %x", Data); |
| 1457 | dbg("mos7840_write: mos7840_port->shadowLCR is %x", |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1458 | mos7840_port->shadowLCR); |
| 1459 | |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 1460 | /* Data = 0x03; */ |
| 1461 | /* status = mos7840_set_uart_reg(port,LINE_CONTROL_REGISTER,Data); */ |
| 1462 | /* mos7840_port->shadowLCR=Data;//Need to add later */ |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1463 | |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 1464 | Data |= SERIAL_LCR_DLAB; /* data latch enable in LCR 0x80 */ |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1465 | status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); |
| 1466 | |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 1467 | /* Data = 0x0c; */ |
| 1468 | /* status = mos7840_set_uart_reg(port,DIVISOR_LATCH_LSB,Data); */ |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1469 | Data = 0x00; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1470 | status = mos7840_get_uart_reg(port, DIVISOR_LATCH_LSB, &Data); |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1471 | dbg("mos7840_write:DLL value is %x", Data); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1472 | |
| 1473 | Data = 0x0; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1474 | status = mos7840_get_uart_reg(port, DIVISOR_LATCH_MSB, &Data); |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1475 | dbg("mos7840_write:DLM value is %x", Data); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1476 | |
| 1477 | Data = Data & ~SERIAL_LCR_DLAB; |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1478 | dbg("mos7840_write: mos7840_port->shadowLCR is %x", |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1479 | mos7840_port->shadowLCR); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1480 | status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); |
| 1481 | #endif |
| 1482 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1483 | if (mos7840_port_paranoia_check(port, __func__)) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1484 | dbg("%s", "Port Paranoia failed"); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1485 | return -1; |
| 1486 | } |
| 1487 | |
| 1488 | serial = port->serial; |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1489 | if (mos7840_serial_paranoia_check(serial, __func__)) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1490 | dbg("%s", "Serial Paranoia failed"); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1491 | return -1; |
| 1492 | } |
| 1493 | |
| 1494 | mos7840_port = mos7840_get_port_private(port); |
| 1495 | if (mos7840_port == NULL) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1496 | dbg("%s", "mos7840_port is NULL"); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1497 | return -1; |
| 1498 | } |
| 1499 | |
| 1500 | /* try to find a free urb in the list */ |
| 1501 | urb = NULL; |
| 1502 | |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 1503 | spin_lock_irqsave(&mos7840_port->pool_lock, flags); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1504 | for (i = 0; i < NUM_URBS; ++i) { |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 1505 | if (!mos7840_port->busy[i]) { |
| 1506 | mos7840_port->busy[i] = 1; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1507 | urb = mos7840_port->write_urb_pool[i]; |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1508 | dbg("URB:%d", i); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1509 | break; |
| 1510 | } |
| 1511 | } |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 1512 | spin_unlock_irqrestore(&mos7840_port->pool_lock, flags); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1513 | |
| 1514 | if (urb == NULL) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1515 | dbg("%s - no more free urbs", __func__); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1516 | goto exit; |
| 1517 | } |
| 1518 | |
| 1519 | if (urb->transfer_buffer == NULL) { |
| 1520 | urb->transfer_buffer = |
| 1521 | kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL); |
| 1522 | |
| 1523 | if (urb->transfer_buffer == NULL) { |
Johan Hovold | 22a416c | 2012-02-10 13:20:51 +0100 | [diff] [blame] | 1524 | dev_err_console(port, "%s no more kernel memory...\n", |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 1525 | __func__); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1526 | goto exit; |
| 1527 | } |
| 1528 | } |
| 1529 | transfer_size = min(count, URB_TRANSFER_BUFFER_SIZE); |
| 1530 | |
Al Viro | 97c4965 | 2006-10-09 20:29:03 +0100 | [diff] [blame] | 1531 | memcpy(urb->transfer_buffer, current_position, transfer_size); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1532 | |
| 1533 | /* fill urb with data and submit */ |
Donald Lee | 093ea2d | 2012-03-14 15:26:33 +0800 | [diff] [blame] | 1534 | if ((serial->num_ports == 2) |
| 1535 | && ((((__u16)port->number - |
| 1536 | (__u16)(port->serial->minor)) % 2) != 0)) { |
| 1537 | usb_fill_bulk_urb(urb, |
| 1538 | serial->dev, |
| 1539 | usb_sndbulkpipe(serial->dev, |
| 1540 | (port->bulk_out_endpointAddress) + 2), |
| 1541 | urb->transfer_buffer, |
| 1542 | transfer_size, |
| 1543 | mos7840_bulk_out_data_callback, mos7840_port); |
| 1544 | } else { |
| 1545 | usb_fill_bulk_urb(urb, |
| 1546 | serial->dev, |
| 1547 | usb_sndbulkpipe(serial->dev, |
| 1548 | port->bulk_out_endpointAddress), |
| 1549 | urb->transfer_buffer, |
| 1550 | transfer_size, |
| 1551 | mos7840_bulk_out_data_callback, mos7840_port); |
| 1552 | } |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1553 | |
| 1554 | data1 = urb->transfer_buffer; |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1555 | dbg("bulkout endpoint is %d", port->bulk_out_endpointAddress); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1556 | |
| 1557 | /* send it down the pipe */ |
| 1558 | status = usb_submit_urb(urb, GFP_ATOMIC); |
| 1559 | |
| 1560 | if (status) { |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 1561 | mos7840_port->busy[i] = 0; |
Johan Hovold | 22a416c | 2012-02-10 13:20:51 +0100 | [diff] [blame] | 1562 | dev_err_console(port, "%s - usb_submit_urb(write bulk) failed " |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 1563 | "with status = %d\n", __func__, status); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1564 | bytes_sent = status; |
| 1565 | goto exit; |
| 1566 | } |
| 1567 | bytes_sent = transfer_size; |
| 1568 | mos7840_port->icount.tx += transfer_size; |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 1569 | smp_wmb(); |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1570 | dbg("mos7840_port->icount.tx is %d:", mos7840_port->icount.tx); |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1571 | exit: |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1572 | return bytes_sent; |
| 1573 | |
| 1574 | } |
| 1575 | |
| 1576 | /***************************************************************************** |
| 1577 | * mos7840_throttle |
| 1578 | * this function is called by the tty driver when it wants to stop the data |
| 1579 | * being read from the port. |
| 1580 | *****************************************************************************/ |
| 1581 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1582 | static void mos7840_throttle(struct tty_struct *tty) |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1583 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1584 | struct usb_serial_port *port = tty->driver_data; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1585 | struct moschip_port *mos7840_port; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1586 | int status; |
| 1587 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1588 | if (mos7840_port_paranoia_check(port, __func__)) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1589 | dbg("%s", "Invalid port"); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1590 | return; |
| 1591 | } |
| 1592 | |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1593 | dbg("- port %d", port->number); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1594 | |
| 1595 | mos7840_port = mos7840_get_port_private(port); |
| 1596 | |
| 1597 | if (mos7840_port == NULL) |
| 1598 | return; |
| 1599 | |
| 1600 | if (!mos7840_port->open) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1601 | dbg("%s", "port not opened"); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1602 | return; |
| 1603 | } |
| 1604 | |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1605 | dbg("%s", "Entering .........."); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1606 | |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1607 | /* if we are implementing XON/XOFF, send the stop character */ |
| 1608 | if (I_IXOFF(tty)) { |
| 1609 | unsigned char stop_char = STOP_CHAR(tty); |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1610 | status = mos7840_write(tty, port, &stop_char, 1); |
| 1611 | if (status <= 0) |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1612 | return; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1613 | } |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1614 | /* if we are implementing RTS/CTS, toggle that line */ |
| 1615 | if (tty->termios->c_cflag & CRTSCTS) { |
| 1616 | mos7840_port->shadowMCR &= ~MCR_RTS; |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1617 | status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1618 | mos7840_port->shadowMCR); |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1619 | if (status < 0) |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1620 | return; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1621 | } |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1622 | } |
| 1623 | |
| 1624 | /***************************************************************************** |
| 1625 | * mos7840_unthrottle |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 1626 | * this function is called by the tty driver when it wants to resume |
| 1627 | * the data being read from the port (called after mos7840_throttle is |
| 1628 | * called) |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1629 | *****************************************************************************/ |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1630 | static void mos7840_unthrottle(struct tty_struct *tty) |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1631 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1632 | struct usb_serial_port *port = tty->driver_data; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1633 | int status; |
| 1634 | struct moschip_port *mos7840_port = mos7840_get_port_private(port); |
| 1635 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1636 | if (mos7840_port_paranoia_check(port, __func__)) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1637 | dbg("%s", "Invalid port"); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1638 | return; |
| 1639 | } |
| 1640 | |
| 1641 | if (mos7840_port == NULL) |
| 1642 | return; |
| 1643 | |
| 1644 | if (!mos7840_port->open) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1645 | dbg("%s - port not opened", __func__); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1646 | return; |
| 1647 | } |
| 1648 | |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1649 | dbg("%s", "Entering .........."); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1650 | |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1651 | /* if we are implementing XON/XOFF, send the start character */ |
| 1652 | if (I_IXOFF(tty)) { |
| 1653 | unsigned char start_char = START_CHAR(tty); |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1654 | status = mos7840_write(tty, port, &start_char, 1); |
| 1655 | if (status <= 0) |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1656 | return; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1657 | } |
| 1658 | |
| 1659 | /* if we are implementing RTS/CTS, toggle that line */ |
| 1660 | if (tty->termios->c_cflag & CRTSCTS) { |
| 1661 | mos7840_port->shadowMCR |= MCR_RTS; |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1662 | status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1663 | mos7840_port->shadowMCR); |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1664 | if (status < 0) |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1665 | return; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1666 | } |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1667 | } |
| 1668 | |
Alan Cox | 60b33c1 | 2011-02-14 16:26:14 +0000 | [diff] [blame] | 1669 | static int mos7840_tiocmget(struct tty_struct *tty) |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1670 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1671 | struct usb_serial_port *port = tty->driver_data; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1672 | struct moschip_port *mos7840_port; |
| 1673 | unsigned int result; |
| 1674 | __u16 msr; |
| 1675 | __u16 mcr; |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 1676 | int status; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1677 | mos7840_port = mos7840_get_port_private(port); |
| 1678 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1679 | dbg("%s - port %d", __func__, port->number); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1680 | |
| 1681 | if (mos7840_port == NULL) |
| 1682 | return -ENODEV; |
| 1683 | |
| 1684 | status = mos7840_get_uart_reg(port, MODEM_STATUS_REGISTER, &msr); |
| 1685 | status = mos7840_get_uart_reg(port, MODEM_CONTROL_REGISTER, &mcr); |
| 1686 | result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0) |
| 1687 | | ((mcr & MCR_RTS) ? TIOCM_RTS : 0) |
| 1688 | | ((mcr & MCR_LOOPBACK) ? TIOCM_LOOP : 0) |
| 1689 | | ((msr & MOS7840_MSR_CTS) ? TIOCM_CTS : 0) |
| 1690 | | ((msr & MOS7840_MSR_CD) ? TIOCM_CAR : 0) |
| 1691 | | ((msr & MOS7840_MSR_RI) ? TIOCM_RI : 0) |
| 1692 | | ((msr & MOS7840_MSR_DSR) ? TIOCM_DSR : 0); |
| 1693 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1694 | dbg("%s - 0x%04X", __func__, result); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1695 | |
| 1696 | return result; |
| 1697 | } |
| 1698 | |
Alan Cox | 20b9d17 | 2011-02-14 16:26:50 +0000 | [diff] [blame] | 1699 | static int mos7840_tiocmset(struct tty_struct *tty, |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1700 | unsigned int set, unsigned int clear) |
| 1701 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1702 | struct usb_serial_port *port = tty->driver_data; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1703 | struct moschip_port *mos7840_port; |
| 1704 | unsigned int mcr; |
Roel Kluin | 87521c4 | 2008-04-17 06:16:24 +0200 | [diff] [blame] | 1705 | int status; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1706 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1707 | dbg("%s - port %d", __func__, port->number); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1708 | |
| 1709 | mos7840_port = mos7840_get_port_private(port); |
| 1710 | |
| 1711 | if (mos7840_port == NULL) |
| 1712 | return -ENODEV; |
| 1713 | |
Alan Cox | e298449 | 2008-02-20 20:51:45 +0000 | [diff] [blame] | 1714 | /* FIXME: What locks the port registers ? */ |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1715 | mcr = mos7840_port->shadowMCR; |
| 1716 | if (clear & TIOCM_RTS) |
| 1717 | mcr &= ~MCR_RTS; |
| 1718 | if (clear & TIOCM_DTR) |
| 1719 | mcr &= ~MCR_DTR; |
| 1720 | if (clear & TIOCM_LOOP) |
| 1721 | mcr &= ~MCR_LOOPBACK; |
| 1722 | |
| 1723 | if (set & TIOCM_RTS) |
| 1724 | mcr |= MCR_RTS; |
| 1725 | if (set & TIOCM_DTR) |
| 1726 | mcr |= MCR_DTR; |
| 1727 | if (set & TIOCM_LOOP) |
| 1728 | mcr |= MCR_LOOPBACK; |
| 1729 | |
| 1730 | mos7840_port->shadowMCR = mcr; |
| 1731 | |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1732 | status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, mcr); |
| 1733 | if (status < 0) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1734 | dbg("setting MODEM_CONTROL_REGISTER Failed"); |
Roel Kluin | 87521c4 | 2008-04-17 06:16:24 +0200 | [diff] [blame] | 1735 | return status; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1736 | } |
| 1737 | |
| 1738 | return 0; |
| 1739 | } |
| 1740 | |
| 1741 | /***************************************************************************** |
| 1742 | * mos7840_calc_baud_rate_divisor |
| 1743 | * this function calculates the proper baud rate divisor for the specified |
| 1744 | * baud rate. |
| 1745 | *****************************************************************************/ |
| 1746 | static int mos7840_calc_baud_rate_divisor(int baudRate, int *divisor, |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 1747 | __u16 *clk_sel_val) |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1748 | { |
| 1749 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1750 | dbg("%s - %d", __func__, baudRate); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1751 | |
| 1752 | if (baudRate <= 115200) { |
| 1753 | *divisor = 115200 / baudRate; |
| 1754 | *clk_sel_val = 0x0; |
| 1755 | } |
| 1756 | if ((baudRate > 115200) && (baudRate <= 230400)) { |
| 1757 | *divisor = 230400 / baudRate; |
| 1758 | *clk_sel_val = 0x10; |
| 1759 | } else if ((baudRate > 230400) && (baudRate <= 403200)) { |
| 1760 | *divisor = 403200 / baudRate; |
| 1761 | *clk_sel_val = 0x20; |
| 1762 | } else if ((baudRate > 403200) && (baudRate <= 460800)) { |
| 1763 | *divisor = 460800 / baudRate; |
| 1764 | *clk_sel_val = 0x30; |
| 1765 | } else if ((baudRate > 460800) && (baudRate <= 806400)) { |
| 1766 | *divisor = 806400 / baudRate; |
| 1767 | *clk_sel_val = 0x40; |
| 1768 | } else if ((baudRate > 806400) && (baudRate <= 921600)) { |
| 1769 | *divisor = 921600 / baudRate; |
| 1770 | *clk_sel_val = 0x50; |
| 1771 | } else if ((baudRate > 921600) && (baudRate <= 1572864)) { |
| 1772 | *divisor = 1572864 / baudRate; |
| 1773 | *clk_sel_val = 0x60; |
| 1774 | } else if ((baudRate > 1572864) && (baudRate <= 3145728)) { |
| 1775 | *divisor = 3145728 / baudRate; |
| 1776 | *clk_sel_val = 0x70; |
| 1777 | } |
| 1778 | return 0; |
| 1779 | |
| 1780 | #ifdef NOTMCS7840 |
| 1781 | |
| 1782 | for (i = 0; i < ARRAY_SIZE(mos7840_divisor_table); i++) { |
| 1783 | if (mos7840_divisor_table[i].BaudRate == baudrate) { |
| 1784 | *divisor = mos7840_divisor_table[i].Divisor; |
| 1785 | return 0; |
| 1786 | } |
| 1787 | } |
| 1788 | |
| 1789 | /* After trying for all the standard baud rates * |
| 1790 | * Try calculating the divisor for this baud rate */ |
| 1791 | |
| 1792 | if (baudrate > 75 && baudrate < 230400) { |
| 1793 | /* get the divisor */ |
| 1794 | custom = (__u16) (230400L / baudrate); |
| 1795 | |
| 1796 | /* Check for round off */ |
| 1797 | round1 = (__u16) (2304000L / baudrate); |
| 1798 | round = (__u16) (round1 - (custom * 10)); |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 1799 | if (round > 4) |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1800 | custom++; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1801 | *divisor = custom; |
| 1802 | |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1803 | dbg(" Baud %d = %d", baudrate, custom); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1804 | return 0; |
| 1805 | } |
| 1806 | |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1807 | dbg("%s", " Baud calculation Failed..."); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1808 | return -1; |
| 1809 | #endif |
| 1810 | } |
| 1811 | |
| 1812 | /***************************************************************************** |
| 1813 | * mos7840_send_cmd_write_baud_rate |
| 1814 | * this function sends the proper command to change the baud rate of the |
| 1815 | * specified port. |
| 1816 | *****************************************************************************/ |
| 1817 | |
| 1818 | static int mos7840_send_cmd_write_baud_rate(struct moschip_port *mos7840_port, |
| 1819 | int baudRate) |
| 1820 | { |
| 1821 | int divisor = 0; |
| 1822 | int status; |
| 1823 | __u16 Data; |
| 1824 | unsigned char number; |
| 1825 | __u16 clk_sel_val; |
| 1826 | struct usb_serial_port *port; |
| 1827 | |
| 1828 | if (mos7840_port == NULL) |
| 1829 | return -1; |
| 1830 | |
| 1831 | port = (struct usb_serial_port *)mos7840_port->port; |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1832 | if (mos7840_port_paranoia_check(port, __func__)) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1833 | dbg("%s", "Invalid port"); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1834 | return -1; |
| 1835 | } |
| 1836 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1837 | if (mos7840_serial_paranoia_check(port->serial, __func__)) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1838 | dbg("%s", "Invalid Serial"); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1839 | return -1; |
| 1840 | } |
| 1841 | |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1842 | dbg("%s", "Entering .........."); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1843 | |
| 1844 | number = mos7840_port->port->number - mos7840_port->port->serial->minor; |
| 1845 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1846 | dbg("%s - port = %d, baud = %d", __func__, |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1847 | mos7840_port->port->number, baudRate); |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 1848 | /* reset clk_uart_sel in spregOffset */ |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1849 | if (baudRate > 115200) { |
| 1850 | #ifdef HW_flow_control |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 1851 | /* NOTE: need to see the pther register to modify */ |
| 1852 | /* setting h/w flow control bit to 1 */ |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1853 | Data = 0x2b; |
| 1854 | mos7840_port->shadowMCR = Data; |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 1855 | status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, |
| 1856 | Data); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1857 | if (status < 0) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1858 | dbg("Writing spreg failed in set_serial_baud"); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1859 | return -1; |
| 1860 | } |
| 1861 | #endif |
| 1862 | |
| 1863 | } else { |
| 1864 | #ifdef HW_flow_control |
Donald Lee | 093ea2d | 2012-03-14 15:26:33 +0800 | [diff] [blame] | 1865 | /* setting h/w flow control bit to 0 */ |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1866 | Data = 0xb; |
| 1867 | mos7840_port->shadowMCR = Data; |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 1868 | status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, |
| 1869 | Data); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1870 | if (status < 0) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1871 | dbg("Writing spreg failed in set_serial_baud"); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1872 | return -1; |
| 1873 | } |
| 1874 | #endif |
| 1875 | |
| 1876 | } |
| 1877 | |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 1878 | if (1) { /* baudRate <= 115200) */ |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1879 | clk_sel_val = 0x0; |
| 1880 | Data = 0x0; |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 1881 | status = mos7840_calc_baud_rate_divisor(baudRate, &divisor, |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1882 | &clk_sel_val); |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 1883 | status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, |
| 1884 | &Data); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1885 | if (status < 0) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1886 | dbg("reading spreg failed in set_serial_baud"); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1887 | return -1; |
| 1888 | } |
| 1889 | Data = (Data & 0x8f) | clk_sel_val; |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 1890 | status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, |
| 1891 | Data); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1892 | if (status < 0) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1893 | dbg("Writing spreg failed in set_serial_baud"); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1894 | return -1; |
| 1895 | } |
| 1896 | /* Calculate the Divisor */ |
| 1897 | |
| 1898 | if (status) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 1899 | dev_err(&port->dev, "%s - bad baud rate\n", __func__); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1900 | return status; |
| 1901 | } |
| 1902 | /* Enable access to divisor latch */ |
| 1903 | Data = mos7840_port->shadowLCR | SERIAL_LCR_DLAB; |
| 1904 | mos7840_port->shadowLCR = Data; |
| 1905 | mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); |
| 1906 | |
| 1907 | /* Write the divisor */ |
| 1908 | Data = (unsigned char)(divisor & 0xff); |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1909 | dbg("set_serial_baud Value to write DLL is %x", Data); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1910 | mos7840_set_uart_reg(port, DIVISOR_LATCH_LSB, Data); |
| 1911 | |
| 1912 | Data = (unsigned char)((divisor & 0xff00) >> 8); |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1913 | dbg("set_serial_baud Value to write DLM is %x", Data); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1914 | mos7840_set_uart_reg(port, DIVISOR_LATCH_MSB, Data); |
| 1915 | |
| 1916 | /* Disable access to divisor latch */ |
| 1917 | Data = mos7840_port->shadowLCR & ~SERIAL_LCR_DLAB; |
| 1918 | mos7840_port->shadowLCR = Data; |
| 1919 | mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); |
| 1920 | |
| 1921 | } |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1922 | return status; |
| 1923 | } |
| 1924 | |
| 1925 | /***************************************************************************** |
| 1926 | * mos7840_change_port_settings |
| 1927 | * This routine is called to set the UART on the device to match |
| 1928 | * the specified new settings. |
| 1929 | *****************************************************************************/ |
| 1930 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1931 | static void mos7840_change_port_settings(struct tty_struct *tty, |
| 1932 | struct moschip_port *mos7840_port, struct ktermios *old_termios) |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1933 | { |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1934 | int baud; |
| 1935 | unsigned cflag; |
| 1936 | unsigned iflag; |
| 1937 | __u8 lData; |
| 1938 | __u8 lParity; |
| 1939 | __u8 lStop; |
| 1940 | int status; |
| 1941 | __u16 Data; |
| 1942 | struct usb_serial_port *port; |
| 1943 | struct usb_serial *serial; |
| 1944 | |
| 1945 | if (mos7840_port == NULL) |
| 1946 | return; |
| 1947 | |
| 1948 | port = (struct usb_serial_port *)mos7840_port->port; |
| 1949 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1950 | if (mos7840_port_paranoia_check(port, __func__)) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1951 | dbg("%s", "Invalid port"); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1952 | return; |
| 1953 | } |
| 1954 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1955 | if (mos7840_serial_paranoia_check(port->serial, __func__)) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1956 | dbg("%s", "Invalid Serial"); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1957 | return; |
| 1958 | } |
| 1959 | |
| 1960 | serial = port->serial; |
| 1961 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1962 | dbg("%s - port %d", __func__, mos7840_port->port->number); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1963 | |
| 1964 | if (!mos7840_port->open) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1965 | dbg("%s - port not opened", __func__); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1966 | return; |
| 1967 | } |
| 1968 | |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 1969 | dbg("%s", "Entering .........."); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 1970 | |
| 1971 | lData = LCR_BITS_8; |
| 1972 | lStop = LCR_STOP_1; |
| 1973 | lParity = LCR_PAR_NONE; |
| 1974 | |
| 1975 | cflag = tty->termios->c_cflag; |
| 1976 | iflag = tty->termios->c_iflag; |
| 1977 | |
| 1978 | /* Change the number of bits */ |
| 1979 | if (cflag & CSIZE) { |
| 1980 | switch (cflag & CSIZE) { |
| 1981 | case CS5: |
| 1982 | lData = LCR_BITS_5; |
| 1983 | break; |
| 1984 | |
| 1985 | case CS6: |
| 1986 | lData = LCR_BITS_6; |
| 1987 | break; |
| 1988 | |
| 1989 | case CS7: |
| 1990 | lData = LCR_BITS_7; |
| 1991 | break; |
| 1992 | default: |
| 1993 | case CS8: |
| 1994 | lData = LCR_BITS_8; |
| 1995 | break; |
| 1996 | } |
| 1997 | } |
| 1998 | /* Change the Parity bit */ |
| 1999 | if (cflag & PARENB) { |
| 2000 | if (cflag & PARODD) { |
| 2001 | lParity = LCR_PAR_ODD; |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2002 | dbg("%s - parity = odd", __func__); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2003 | } else { |
| 2004 | lParity = LCR_PAR_EVEN; |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2005 | dbg("%s - parity = even", __func__); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2006 | } |
| 2007 | |
| 2008 | } else { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2009 | dbg("%s - parity = none", __func__); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2010 | } |
| 2011 | |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 2012 | if (cflag & CMSPAR) |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2013 | lParity = lParity | 0x20; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2014 | |
| 2015 | /* Change the Stop bit */ |
| 2016 | if (cflag & CSTOPB) { |
| 2017 | lStop = LCR_STOP_2; |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2018 | dbg("%s - stop bits = 2", __func__); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2019 | } else { |
| 2020 | lStop = LCR_STOP_1; |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2021 | dbg("%s - stop bits = 1", __func__); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2022 | } |
| 2023 | |
| 2024 | /* Update the LCR with the correct value */ |
| 2025 | mos7840_port->shadowLCR &= |
| 2026 | ~(LCR_BITS_MASK | LCR_STOP_MASK | LCR_PAR_MASK); |
| 2027 | mos7840_port->shadowLCR |= (lData | lParity | lStop); |
| 2028 | |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 2029 | dbg("mos7840_change_port_settings mos7840_port->shadowLCR is %x", |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2030 | mos7840_port->shadowLCR); |
| 2031 | /* Disable Interrupts */ |
| 2032 | Data = 0x00; |
| 2033 | mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data); |
| 2034 | |
| 2035 | Data = 0x00; |
| 2036 | mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data); |
| 2037 | |
| 2038 | Data = 0xcf; |
| 2039 | mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data); |
| 2040 | |
| 2041 | /* Send the updated LCR value to the mos7840 */ |
| 2042 | Data = mos7840_port->shadowLCR; |
| 2043 | |
| 2044 | mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); |
| 2045 | |
| 2046 | Data = 0x00b; |
| 2047 | mos7840_port->shadowMCR = Data; |
| 2048 | mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); |
| 2049 | Data = 0x00b; |
| 2050 | mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); |
| 2051 | |
| 2052 | /* set up the MCR register and send it to the mos7840 */ |
| 2053 | |
| 2054 | mos7840_port->shadowMCR = MCR_MASTER_IE; |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 2055 | if (cflag & CBAUD) |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2056 | mos7840_port->shadowMCR |= (MCR_DTR | MCR_RTS); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2057 | |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 2058 | if (cflag & CRTSCTS) |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2059 | mos7840_port->shadowMCR |= (MCR_XON_ANY); |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 2060 | else |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2061 | mos7840_port->shadowMCR &= ~(MCR_XON_ANY); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2062 | |
| 2063 | Data = mos7840_port->shadowMCR; |
| 2064 | mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); |
| 2065 | |
| 2066 | /* Determine divisor based on baud rate */ |
| 2067 | baud = tty_get_baud_rate(tty); |
| 2068 | |
| 2069 | if (!baud) { |
| 2070 | /* pick a default, any default... */ |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 2071 | dbg("%s", "Picked default baud..."); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2072 | baud = 9600; |
| 2073 | } |
| 2074 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2075 | dbg("%s - baud rate = %d", __func__, baud); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2076 | status = mos7840_send_cmd_write_baud_rate(mos7840_port, baud); |
| 2077 | |
| 2078 | /* Enable Interrupts */ |
| 2079 | Data = 0x0c; |
| 2080 | mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data); |
| 2081 | |
Greg Kroah-Hartman | 50de36f | 2008-12-10 16:00:30 -0800 | [diff] [blame] | 2082 | if (mos7840_port->read_urb_busy == false) { |
Greg Kroah-Hartman | 50de36f | 2008-12-10 16:00:30 -0800 | [diff] [blame] | 2083 | mos7840_port->read_urb_busy = true; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2084 | status = usb_submit_urb(mos7840_port->read_urb, GFP_ATOMIC); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2085 | if (status) { |
Greg Kroah-Hartman | 50de36f | 2008-12-10 16:00:30 -0800 | [diff] [blame] | 2086 | dbg("usb_submit_urb(read bulk) failed, status = %d", |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2087 | status); |
Greg Kroah-Hartman | 50de36f | 2008-12-10 16:00:30 -0800 | [diff] [blame] | 2088 | mos7840_port->read_urb_busy = false; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2089 | } |
| 2090 | } |
| 2091 | wake_up(&mos7840_port->delta_msr_wait); |
| 2092 | mos7840_port->delta_msr_cond = 1; |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 2093 | dbg("mos7840_change_port_settings mos7840_port->shadowLCR is End %x", |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2094 | mos7840_port->shadowLCR); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2095 | } |
| 2096 | |
| 2097 | /***************************************************************************** |
| 2098 | * mos7840_set_termios |
| 2099 | * this function is called by the tty driver when it wants to change |
| 2100 | * the termios structure |
| 2101 | *****************************************************************************/ |
| 2102 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 2103 | static void mos7840_set_termios(struct tty_struct *tty, |
| 2104 | struct usb_serial_port *port, |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 2105 | struct ktermios *old_termios) |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2106 | { |
| 2107 | int status; |
| 2108 | unsigned int cflag; |
| 2109 | struct usb_serial *serial; |
| 2110 | struct moschip_port *mos7840_port; |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 2111 | dbg("mos7840_set_termios: START"); |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2112 | if (mos7840_port_paranoia_check(port, __func__)) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 2113 | dbg("%s", "Invalid port"); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2114 | return; |
| 2115 | } |
| 2116 | |
| 2117 | serial = port->serial; |
| 2118 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2119 | if (mos7840_serial_paranoia_check(serial, __func__)) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 2120 | dbg("%s", "Invalid Serial"); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2121 | return; |
| 2122 | } |
| 2123 | |
| 2124 | mos7840_port = mos7840_get_port_private(port); |
| 2125 | |
| 2126 | if (mos7840_port == NULL) |
| 2127 | return; |
| 2128 | |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2129 | if (!mos7840_port->open) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2130 | dbg("%s - port not opened", __func__); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2131 | return; |
| 2132 | } |
| 2133 | |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 2134 | dbg("%s", "setting termios - "); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2135 | |
| 2136 | cflag = tty->termios->c_cflag; |
| 2137 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2138 | dbg("%s - clfag %08x iflag %08x", __func__, |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2139 | tty->termios->c_cflag, RELEVANT_IFLAG(tty->termios->c_iflag)); |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2140 | dbg("%s - old clfag %08x old iflag %08x", __func__, |
Alan Cox | 3d3ddce | 2007-10-15 20:53:35 +0100 | [diff] [blame] | 2141 | old_termios->c_cflag, RELEVANT_IFLAG(old_termios->c_iflag)); |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2142 | dbg("%s - port %d", __func__, port->number); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2143 | |
| 2144 | /* change the port settings to the new ones specified */ |
| 2145 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 2146 | mos7840_change_port_settings(tty, mos7840_port, old_termios); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2147 | |
| 2148 | if (!mos7840_port->read_urb) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 2149 | dbg("%s", "URB KILLED !!!!!"); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2150 | return; |
| 2151 | } |
| 2152 | |
Greg Kroah-Hartman | 50de36f | 2008-12-10 16:00:30 -0800 | [diff] [blame] | 2153 | if (mos7840_port->read_urb_busy == false) { |
Greg Kroah-Hartman | 50de36f | 2008-12-10 16:00:30 -0800 | [diff] [blame] | 2154 | mos7840_port->read_urb_busy = true; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2155 | status = usb_submit_urb(mos7840_port->read_urb, GFP_ATOMIC); |
| 2156 | if (status) { |
Greg Kroah-Hartman | 50de36f | 2008-12-10 16:00:30 -0800 | [diff] [blame] | 2157 | dbg("usb_submit_urb(read bulk) failed, status = %d", |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2158 | status); |
Greg Kroah-Hartman | 50de36f | 2008-12-10 16:00:30 -0800 | [diff] [blame] | 2159 | mos7840_port->read_urb_busy = false; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2160 | } |
| 2161 | } |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2162 | } |
| 2163 | |
| 2164 | /***************************************************************************** |
| 2165 | * mos7840_get_lsr_info - get line status register info |
| 2166 | * |
| 2167 | * Purpose: Let user call ioctl() to get info when the UART physically |
| 2168 | * is emptied. On bus types like RS485, the transmitter must |
| 2169 | * release the bus after transmitting. This must be done when |
| 2170 | * the transmit shift register is empty, not be done when the |
| 2171 | * transmit holding register is empty. This functionality |
| 2172 | * allows an RS485 driver to be written in user space. |
| 2173 | *****************************************************************************/ |
| 2174 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 2175 | static int mos7840_get_lsr_info(struct tty_struct *tty, |
Al Viro | 97c4965 | 2006-10-09 20:29:03 +0100 | [diff] [blame] | 2176 | unsigned int __user *value) |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2177 | { |
| 2178 | int count; |
| 2179 | unsigned int result = 0; |
| 2180 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 2181 | count = mos7840_chars_in_buffer(tty); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2182 | if (count == 0) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2183 | dbg("%s -- Empty", __func__); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2184 | result = TIOCSER_TEMT; |
| 2185 | } |
| 2186 | |
| 2187 | if (copy_to_user(value, &result, sizeof(int))) |
| 2188 | return -EFAULT; |
| 2189 | return 0; |
| 2190 | } |
| 2191 | |
| 2192 | /***************************************************************************** |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2193 | * mos7840_get_serial_info |
| 2194 | * function to get information about serial port |
| 2195 | *****************************************************************************/ |
| 2196 | |
| 2197 | static int mos7840_get_serial_info(struct moschip_port *mos7840_port, |
Al Viro | 97c4965 | 2006-10-09 20:29:03 +0100 | [diff] [blame] | 2198 | struct serial_struct __user *retinfo) |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2199 | { |
| 2200 | struct serial_struct tmp; |
| 2201 | |
| 2202 | if (mos7840_port == NULL) |
| 2203 | return -1; |
| 2204 | |
| 2205 | if (!retinfo) |
| 2206 | return -EFAULT; |
| 2207 | |
| 2208 | memset(&tmp, 0, sizeof(tmp)); |
| 2209 | |
| 2210 | tmp.type = PORT_16550A; |
| 2211 | tmp.line = mos7840_port->port->serial->minor; |
| 2212 | tmp.port = mos7840_port->port->number; |
| 2213 | tmp.irq = 0; |
| 2214 | tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ; |
| 2215 | tmp.xmit_fifo_size = NUM_URBS * URB_TRANSFER_BUFFER_SIZE; |
| 2216 | tmp.baud_base = 9600; |
| 2217 | tmp.close_delay = 5 * HZ; |
| 2218 | tmp.closing_wait = 30 * HZ; |
| 2219 | |
| 2220 | if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) |
| 2221 | return -EFAULT; |
| 2222 | return 0; |
| 2223 | } |
| 2224 | |
Alan Cox | 0bca1b9 | 2010-09-16 18:21:40 +0100 | [diff] [blame] | 2225 | static int mos7840_get_icount(struct tty_struct *tty, |
| 2226 | struct serial_icounter_struct *icount) |
| 2227 | { |
| 2228 | struct usb_serial_port *port = tty->driver_data; |
| 2229 | struct moschip_port *mos7840_port; |
| 2230 | struct async_icount cnow; |
| 2231 | |
| 2232 | mos7840_port = mos7840_get_port_private(port); |
| 2233 | cnow = mos7840_port->icount; |
| 2234 | |
| 2235 | smp_rmb(); |
| 2236 | icount->cts = cnow.cts; |
| 2237 | icount->dsr = cnow.dsr; |
| 2238 | icount->rng = cnow.rng; |
| 2239 | icount->dcd = cnow.dcd; |
| 2240 | icount->rx = cnow.rx; |
| 2241 | icount->tx = cnow.tx; |
| 2242 | icount->frame = cnow.frame; |
| 2243 | icount->overrun = cnow.overrun; |
| 2244 | icount->parity = cnow.parity; |
| 2245 | icount->brk = cnow.brk; |
| 2246 | icount->buf_overrun = cnow.buf_overrun; |
| 2247 | |
| 2248 | dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d", __func__, |
| 2249 | port->number, icount->rx, icount->tx); |
| 2250 | return 0; |
| 2251 | } |
| 2252 | |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2253 | /***************************************************************************** |
| 2254 | * SerialIoctl |
| 2255 | * this function handles any ioctl calls to the driver |
| 2256 | *****************************************************************************/ |
| 2257 | |
Alan Cox | 00a0d0d | 2011-02-14 16:27:06 +0000 | [diff] [blame] | 2258 | static int mos7840_ioctl(struct tty_struct *tty, |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2259 | unsigned int cmd, unsigned long arg) |
| 2260 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 2261 | struct usb_serial_port *port = tty->driver_data; |
Al Viro | 97c4965 | 2006-10-09 20:29:03 +0100 | [diff] [blame] | 2262 | void __user *argp = (void __user *)arg; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2263 | struct moschip_port *mos7840_port; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2264 | |
| 2265 | struct async_icount cnow; |
| 2266 | struct async_icount cprev; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2267 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2268 | if (mos7840_port_paranoia_check(port, __func__)) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 2269 | dbg("%s", "Invalid port"); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2270 | return -1; |
| 2271 | } |
| 2272 | |
| 2273 | mos7840_port = mos7840_get_port_private(port); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2274 | |
| 2275 | if (mos7840_port == NULL) |
| 2276 | return -1; |
| 2277 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2278 | dbg("%s - port %d, cmd = 0x%x", __func__, port->number, cmd); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2279 | |
| 2280 | switch (cmd) { |
| 2281 | /* return number of bytes available */ |
| 2282 | |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2283 | case TIOCSERGETLSR: |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2284 | dbg("%s (%d) TIOCSERGETLSR", __func__, port->number); |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 2285 | return mos7840_get_lsr_info(tty, argp); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2286 | |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2287 | case TIOCGSERIAL: |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2288 | dbg("%s (%d) TIOCGSERIAL", __func__, port->number); |
Al Viro | 97c4965 | 2006-10-09 20:29:03 +0100 | [diff] [blame] | 2289 | return mos7840_get_serial_info(mos7840_port, argp); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2290 | |
| 2291 | case TIOCSSERIAL: |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2292 | dbg("%s (%d) TIOCSSERIAL", __func__, port->number); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2293 | break; |
| 2294 | |
| 2295 | case TIOCMIWAIT: |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2296 | dbg("%s (%d) TIOCMIWAIT", __func__, port->number); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2297 | cprev = mos7840_port->icount; |
| 2298 | while (1) { |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 2299 | /* interruptible_sleep_on(&mos7840_port->delta_msr_wait); */ |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2300 | mos7840_port->delta_msr_cond = 0; |
| 2301 | wait_event_interruptible(mos7840_port->delta_msr_wait, |
| 2302 | (mos7840_port-> |
| 2303 | delta_msr_cond == 1)); |
| 2304 | |
| 2305 | /* see if a signal did it */ |
| 2306 | if (signal_pending(current)) |
| 2307 | return -ERESTARTSYS; |
| 2308 | cnow = mos7840_port->icount; |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 2309 | smp_rmb(); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2310 | if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr && |
| 2311 | cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) |
| 2312 | return -EIO; /* no change => error */ |
| 2313 | if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) || |
| 2314 | ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) || |
| 2315 | ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) || |
| 2316 | ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) { |
| 2317 | return 0; |
| 2318 | } |
| 2319 | cprev = cnow; |
| 2320 | } |
| 2321 | /* NOTREACHED */ |
| 2322 | break; |
| 2323 | |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2324 | default: |
| 2325 | break; |
| 2326 | } |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2327 | return -ENOIOCTLCMD; |
| 2328 | } |
| 2329 | |
| 2330 | static int mos7840_calc_num_ports(struct usb_serial *serial) |
| 2331 | { |
Donald Lee | 093ea2d | 2012-03-14 15:26:33 +0800 | [diff] [blame] | 2332 | __u16 Data = 0x00; |
| 2333 | int ret = 0; |
| 2334 | int mos7840_num_ports; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2335 | |
Donald Lee | 093ea2d | 2012-03-14 15:26:33 +0800 | [diff] [blame] | 2336 | ret = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), |
| 2337 | MCS_RDREQ, MCS_RD_RTYPE, 0, GPIO_REGISTER, &Data, |
| 2338 | VENDOR_READ_LENGTH, MOS_WDR_TIMEOUT); |
| 2339 | |
| 2340 | if ((Data & 0x01) == 0) { |
| 2341 | mos7840_num_ports = 2; |
| 2342 | serial->num_bulk_in = 2; |
| 2343 | serial->num_bulk_out = 2; |
| 2344 | serial->num_ports = 2; |
| 2345 | } else { |
| 2346 | mos7840_num_ports = 4; |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 2347 | serial->num_bulk_in = 4; |
| 2348 | serial->num_bulk_out = 4; |
Donald Lee | 093ea2d | 2012-03-14 15:26:33 +0800 | [diff] [blame] | 2349 | serial->num_ports = 4; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2350 | } |
Donald Lee | 093ea2d | 2012-03-14 15:26:33 +0800 | [diff] [blame] | 2351 | |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2352 | return mos7840_num_ports; |
| 2353 | } |
| 2354 | |
| 2355 | /**************************************************************************** |
| 2356 | * mos7840_startup |
| 2357 | ****************************************************************************/ |
| 2358 | |
| 2359 | static int mos7840_startup(struct usb_serial *serial) |
| 2360 | { |
| 2361 | struct moschip_port *mos7840_port; |
| 2362 | struct usb_device *dev; |
| 2363 | int i, status; |
| 2364 | |
| 2365 | __u16 Data; |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 2366 | dbg("%s", "mos7840_startup :Entering.........."); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2367 | |
| 2368 | if (!serial) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 2369 | dbg("%s", "Invalid Handler"); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2370 | return -1; |
| 2371 | } |
| 2372 | |
| 2373 | dev = serial->dev; |
| 2374 | |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 2375 | dbg("%s", "Entering..."); |
| 2376 | dbg ("mos7840_startup: serial = %p", serial); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2377 | |
| 2378 | /* we set up the pointers to the endpoints in the mos7840_open * |
| 2379 | * function, as the structures aren't created yet. */ |
| 2380 | |
| 2381 | /* set up port private structures */ |
| 2382 | for (i = 0; i < serial->num_ports; ++i) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 2383 | dbg ("mos7840_startup: configuring port %d............", i); |
Burman Yan | 7ac9da1 | 2006-11-22 20:54:38 +0200 | [diff] [blame] | 2384 | mos7840_port = kzalloc(sizeof(struct moschip_port), GFP_KERNEL); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2385 | if (mos7840_port == NULL) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 2386 | dev_err(&dev->dev, "%s - Out of memory\n", __func__); |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 2387 | status = -ENOMEM; |
| 2388 | i--; /* don't follow NULL pointer cleaning up */ |
| 2389 | goto error; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2390 | } |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2391 | |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 2392 | /* Initialize all port interrupt end point to port 0 int |
| 2393 | * endpoint. Our device has only one interrupt end point |
| 2394 | * common to all port */ |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2395 | |
| 2396 | mos7840_port->port = serial->port[i]; |
| 2397 | mos7840_set_port_private(serial->port[i], mos7840_port); |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 2398 | spin_lock_init(&mos7840_port->pool_lock); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2399 | |
Tony Cook | 37768ad | 2009-04-18 22:42:18 +0930 | [diff] [blame] | 2400 | /* minor is not initialised until later by |
| 2401 | * usb-serial.c:get_free_serial() and cannot therefore be used |
| 2402 | * to index device instances */ |
| 2403 | mos7840_port->port_num = i + 1; |
| 2404 | dbg ("serial->port[i]->number = %d", serial->port[i]->number); |
| 2405 | dbg ("serial->port[i]->serial->minor = %d", serial->port[i]->serial->minor); |
| 2406 | dbg ("mos7840_port->port_num = %d", mos7840_port->port_num); |
| 2407 | dbg ("serial->minor = %d", serial->minor); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2408 | |
| 2409 | if (mos7840_port->port_num == 1) { |
| 2410 | mos7840_port->SpRegOffset = 0x0; |
| 2411 | mos7840_port->ControlRegOffset = 0x1; |
| 2412 | mos7840_port->DcrRegOffset = 0x4; |
| 2413 | } else if ((mos7840_port->port_num == 2) |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 2414 | && (serial->num_ports == 4)) { |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2415 | mos7840_port->SpRegOffset = 0x8; |
| 2416 | mos7840_port->ControlRegOffset = 0x9; |
| 2417 | mos7840_port->DcrRegOffset = 0x16; |
| 2418 | } else if ((mos7840_port->port_num == 2) |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 2419 | && (serial->num_ports == 2)) { |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2420 | mos7840_port->SpRegOffset = 0xa; |
| 2421 | mos7840_port->ControlRegOffset = 0xb; |
| 2422 | mos7840_port->DcrRegOffset = 0x19; |
| 2423 | } else if ((mos7840_port->port_num == 3) |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 2424 | && (serial->num_ports == 4)) { |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2425 | mos7840_port->SpRegOffset = 0xa; |
| 2426 | mos7840_port->ControlRegOffset = 0xb; |
| 2427 | mos7840_port->DcrRegOffset = 0x19; |
| 2428 | } else if ((mos7840_port->port_num == 4) |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 2429 | && (serial->num_ports == 4)) { |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2430 | mos7840_port->SpRegOffset = 0xc; |
| 2431 | mos7840_port->ControlRegOffset = 0xd; |
| 2432 | mos7840_port->DcrRegOffset = 0x1c; |
| 2433 | } |
| 2434 | mos7840_dump_serial_port(mos7840_port); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2435 | mos7840_set_port_private(serial->port[i], mos7840_port); |
| 2436 | |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 2437 | /* enable rx_disable bit in control register */ |
| 2438 | status = mos7840_get_reg_sync(serial->port[i], |
| 2439 | mos7840_port->ControlRegOffset, &Data); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2440 | if (status < 0) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 2441 | dbg("Reading ControlReg failed status-0x%x", status); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2442 | break; |
| 2443 | } else |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 2444 | dbg("ControlReg Reading success val is %x, status%d", |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2445 | Data, status); |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 2446 | Data |= 0x08; /* setting driver done bit */ |
| 2447 | Data |= 0x04; /* sp1_bit to have cts change reflect in |
| 2448 | modem status reg */ |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2449 | |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 2450 | /* Data |= 0x20; //rx_disable bit */ |
| 2451 | status = mos7840_set_reg_sync(serial->port[i], |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2452 | mos7840_port->ControlRegOffset, Data); |
| 2453 | if (status < 0) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 2454 | dbg("Writing ControlReg failed(rx_disable) status-0x%x", status); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2455 | break; |
| 2456 | } else |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 2457 | dbg("ControlReg Writing success(rx_disable) status%d", |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2458 | status); |
| 2459 | |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 2460 | /* Write default values in DCR (i.e 0x01 in DCR0, 0x05 in DCR2 |
| 2461 | and 0x24 in DCR3 */ |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2462 | Data = 0x01; |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 2463 | status = mos7840_set_reg_sync(serial->port[i], |
| 2464 | (__u16) (mos7840_port->DcrRegOffset + 0), Data); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2465 | if (status < 0) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 2466 | dbg("Writing DCR0 failed status-0x%x", status); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2467 | break; |
| 2468 | } else |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 2469 | dbg("DCR0 Writing success status%d", status); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2470 | |
| 2471 | Data = 0x05; |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 2472 | status = mos7840_set_reg_sync(serial->port[i], |
| 2473 | (__u16) (mos7840_port->DcrRegOffset + 1), Data); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2474 | if (status < 0) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 2475 | dbg("Writing DCR1 failed status-0x%x", status); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2476 | break; |
| 2477 | } else |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 2478 | dbg("DCR1 Writing success status%d", status); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2479 | |
| 2480 | Data = 0x24; |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 2481 | status = mos7840_set_reg_sync(serial->port[i], |
| 2482 | (__u16) (mos7840_port->DcrRegOffset + 2), Data); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2483 | if (status < 0) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 2484 | dbg("Writing DCR2 failed status-0x%x", status); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2485 | break; |
| 2486 | } else |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 2487 | dbg("DCR2 Writing success status%d", status); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2488 | |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 2489 | /* write values in clkstart0x0 and clkmulti 0x20 */ |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2490 | Data = 0x0; |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 2491 | status = mos7840_set_reg_sync(serial->port[i], |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2492 | CLK_START_VALUE_REGISTER, Data); |
| 2493 | if (status < 0) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 2494 | dbg("Writing CLK_START_VALUE_REGISTER failed status-0x%x", status); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2495 | break; |
| 2496 | } else |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 2497 | dbg("CLK_START_VALUE_REGISTER Writing success status%d", status); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2498 | |
| 2499 | Data = 0x20; |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 2500 | status = mos7840_set_reg_sync(serial->port[i], |
| 2501 | CLK_MULTI_REGISTER, Data); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2502 | if (status < 0) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 2503 | dbg("Writing CLK_MULTI_REGISTER failed status-0x%x", |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2504 | status); |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 2505 | goto error; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2506 | } else |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 2507 | dbg("CLK_MULTI_REGISTER Writing success status%d", |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2508 | status); |
| 2509 | |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 2510 | /* write value 0x0 to scratchpad register */ |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2511 | Data = 0x00; |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 2512 | status = mos7840_set_uart_reg(serial->port[i], |
| 2513 | SCRATCH_PAD_REGISTER, Data); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2514 | if (status < 0) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 2515 | dbg("Writing SCRATCH_PAD_REGISTER failed status-0x%x", |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2516 | status); |
| 2517 | break; |
| 2518 | } else |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 2519 | dbg("SCRATCH_PAD_REGISTER Writing success status%d", |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2520 | status); |
| 2521 | |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 2522 | /* Zero Length flag register */ |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2523 | if ((mos7840_port->port_num != 1) |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 2524 | && (serial->num_ports == 2)) { |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2525 | |
| 2526 | Data = 0xff; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2527 | status = mos7840_set_reg_sync(serial->port[i], |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 2528 | (__u16) (ZLP_REG1 + |
| 2529 | ((__u16)mos7840_port->port_num)), Data); |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 2530 | dbg("ZLIP offset %x", |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2531 | (__u16) (ZLP_REG1 + |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 2532 | ((__u16) mos7840_port->port_num))); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2533 | if (status < 0) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 2534 | dbg("Writing ZLP_REG%d failed status-0x%x", |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2535 | i + 2, status); |
| 2536 | break; |
| 2537 | } else |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 2538 | dbg("ZLP_REG%d Writing success status%d", |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2539 | i + 2, status); |
| 2540 | } else { |
| 2541 | Data = 0xff; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2542 | status = mos7840_set_reg_sync(serial->port[i], |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 2543 | (__u16) (ZLP_REG1 + |
| 2544 | ((__u16)mos7840_port->port_num) - 0x1), Data); |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 2545 | dbg("ZLIP offset %x", |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2546 | (__u16) (ZLP_REG1 + |
| 2547 | ((__u16) mos7840_port->port_num) - 0x1)); |
| 2548 | if (status < 0) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 2549 | dbg("Writing ZLP_REG%d failed status-0x%x", |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2550 | i + 1, status); |
| 2551 | break; |
| 2552 | } else |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 2553 | dbg("ZLP_REG%d Writing success status%d", |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2554 | i + 1, status); |
| 2555 | |
| 2556 | } |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 2557 | mos7840_port->control_urb = usb_alloc_urb(0, GFP_KERNEL); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2558 | mos7840_port->ctrl_buf = kmalloc(16, GFP_KERNEL); |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 2559 | mos7840_port->dr = kmalloc(sizeof(struct usb_ctrlrequest), |
| 2560 | GFP_KERNEL); |
| 2561 | if (!mos7840_port->control_urb || !mos7840_port->ctrl_buf || |
| 2562 | !mos7840_port->dr) { |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 2563 | status = -ENOMEM; |
| 2564 | goto error; |
| 2565 | } |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2566 | } |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 2567 | dbg ("mos7840_startup: all ports configured..........."); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2568 | |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 2569 | /* Zero Length flag enable */ |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2570 | Data = 0x0f; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2571 | status = mos7840_set_reg_sync(serial->port[0], ZLP_REG5, Data); |
| 2572 | if (status < 0) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 2573 | dbg("Writing ZLP_REG5 failed status-0x%x", status); |
Roel Kluin | 7ced46c | 2007-10-27 03:36:37 +0200 | [diff] [blame] | 2574 | goto error; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2575 | } else |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 2576 | dbg("ZLP_REG5 Writing success status%d", status); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2577 | |
| 2578 | /* setting configuration feature to one */ |
| 2579 | usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), |
Al Viro | 97c4965 | 2006-10-09 20:29:03 +0100 | [diff] [blame] | 2580 | (__u8) 0x03, 0x00, 0x01, 0x00, NULL, 0x00, 5 * HZ); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2581 | return 0; |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 2582 | error: |
| 2583 | for (/* nothing */; i >= 0; i--) { |
| 2584 | mos7840_port = mos7840_get_port_private(serial->port[i]); |
| 2585 | |
| 2586 | kfree(mos7840_port->dr); |
| 2587 | kfree(mos7840_port->ctrl_buf); |
| 2588 | usb_free_urb(mos7840_port->control_urb); |
| 2589 | kfree(mos7840_port); |
| 2590 | serial->port[i] = NULL; |
| 2591 | } |
| 2592 | return status; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2593 | } |
| 2594 | |
| 2595 | /**************************************************************************** |
Alan Stern | f9c99bb | 2009-06-02 11:53:55 -0400 | [diff] [blame] | 2596 | * mos7840_disconnect |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2597 | * This function is called whenever the device is removed from the usb bus. |
| 2598 | ****************************************************************************/ |
| 2599 | |
Alan Stern | f9c99bb | 2009-06-02 11:53:55 -0400 | [diff] [blame] | 2600 | static void mos7840_disconnect(struct usb_serial *serial) |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2601 | { |
| 2602 | int i; |
Oliver Neukum | 0de9a70 | 2007-03-16 20:28:28 +0100 | [diff] [blame] | 2603 | unsigned long flags; |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2604 | struct moschip_port *mos7840_port; |
Alan Stern | f9c99bb | 2009-06-02 11:53:55 -0400 | [diff] [blame] | 2605 | dbg("%s", " disconnect :entering.........."); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2606 | |
| 2607 | if (!serial) { |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 2608 | dbg("%s", "Invalid Handler"); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2609 | return; |
| 2610 | } |
| 2611 | |
Alan Cox | 880af9d | 2008-07-22 11:16:12 +0100 | [diff] [blame] | 2612 | /* check for the ports to be closed,close the ports and disconnect */ |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2613 | |
| 2614 | /* free private structure allocated for serial port * |
| 2615 | * stop reads and writes on all ports */ |
| 2616 | |
| 2617 | for (i = 0; i < serial->num_ports; ++i) { |
| 2618 | mos7840_port = mos7840_get_port_private(serial->port[i]); |
Tony Cook | 37768ad | 2009-04-18 22:42:18 +0930 | [diff] [blame] | 2619 | dbg ("mos7840_port %d = %p", i, mos7840_port); |
| 2620 | if (mos7840_port) { |
| 2621 | spin_lock_irqsave(&mos7840_port->pool_lock, flags); |
| 2622 | mos7840_port->zombie = 1; |
| 2623 | spin_unlock_irqrestore(&mos7840_port->pool_lock, flags); |
| 2624 | usb_kill_urb(mos7840_port->control_urb); |
Alan Stern | f9c99bb | 2009-06-02 11:53:55 -0400 | [diff] [blame] | 2625 | } |
| 2626 | } |
| 2627 | |
| 2628 | dbg("%s", "Thank u :: "); |
| 2629 | |
| 2630 | } |
| 2631 | |
| 2632 | /**************************************************************************** |
| 2633 | * mos7840_release |
| 2634 | * This function is called when the usb_serial structure is freed. |
| 2635 | ****************************************************************************/ |
| 2636 | |
| 2637 | static void mos7840_release(struct usb_serial *serial) |
| 2638 | { |
| 2639 | int i; |
| 2640 | struct moschip_port *mos7840_port; |
| 2641 | dbg("%s", " release :entering.........."); |
| 2642 | |
| 2643 | if (!serial) { |
| 2644 | dbg("%s", "Invalid Handler"); |
| 2645 | return; |
| 2646 | } |
| 2647 | |
| 2648 | /* check for the ports to be closed,close the ports and disconnect */ |
| 2649 | |
| 2650 | /* free private structure allocated for serial port * |
| 2651 | * stop reads and writes on all ports */ |
| 2652 | |
| 2653 | for (i = 0; i < serial->num_ports; ++i) { |
| 2654 | mos7840_port = mos7840_get_port_private(serial->port[i]); |
| 2655 | dbg("mos7840_port %d = %p", i, mos7840_port); |
| 2656 | if (mos7840_port) { |
Tony Cook | 37768ad | 2009-04-18 22:42:18 +0930 | [diff] [blame] | 2657 | kfree(mos7840_port->ctrl_buf); |
| 2658 | kfree(mos7840_port->dr); |
| 2659 | kfree(mos7840_port); |
| 2660 | } |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2661 | } |
| 2662 | |
Tony Cook | 84fe6e7 | 2009-04-18 22:55:06 +0930 | [diff] [blame] | 2663 | dbg("%s", "Thank u :: "); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2664 | |
| 2665 | } |
| 2666 | |
Johannes Hölzl | d9b1b78 | 2006-12-17 21:50:24 +0100 | [diff] [blame] | 2667 | static struct usb_driver io_driver = { |
| 2668 | .name = "mos7840", |
| 2669 | .probe = usb_serial_probe, |
| 2670 | .disconnect = usb_serial_disconnect, |
| 2671 | .id_table = moschip_id_table_combined, |
Johannes Hölzl | d9b1b78 | 2006-12-17 21:50:24 +0100 | [diff] [blame] | 2672 | }; |
| 2673 | |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2674 | static struct usb_serial_driver moschip7840_4port_device = { |
| 2675 | .driver = { |
| 2676 | .owner = THIS_MODULE, |
| 2677 | .name = "mos7840", |
| 2678 | }, |
| 2679 | .description = DRIVER_DESC, |
| 2680 | .id_table = moschip_port_id_table, |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2681 | .num_ports = 4, |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2682 | .open = mos7840_open, |
| 2683 | .close = mos7840_close, |
| 2684 | .write = mos7840_write, |
| 2685 | .write_room = mos7840_write_room, |
| 2686 | .chars_in_buffer = mos7840_chars_in_buffer, |
| 2687 | .throttle = mos7840_throttle, |
| 2688 | .unthrottle = mos7840_unthrottle, |
| 2689 | .calc_num_ports = mos7840_calc_num_ports, |
| 2690 | #ifdef MCSSerialProbe |
| 2691 | .probe = mos7840_serial_probe, |
| 2692 | #endif |
| 2693 | .ioctl = mos7840_ioctl, |
| 2694 | .set_termios = mos7840_set_termios, |
| 2695 | .break_ctl = mos7840_break, |
| 2696 | .tiocmget = mos7840_tiocmget, |
| 2697 | .tiocmset = mos7840_tiocmset, |
Alan Cox | 0bca1b9 | 2010-09-16 18:21:40 +0100 | [diff] [blame] | 2698 | .get_icount = mos7840_get_icount, |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2699 | .attach = mos7840_startup, |
Alan Stern | f9c99bb | 2009-06-02 11:53:55 -0400 | [diff] [blame] | 2700 | .disconnect = mos7840_disconnect, |
| 2701 | .release = mos7840_release, |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2702 | .read_bulk_callback = mos7840_bulk_in_callback, |
| 2703 | .read_int_callback = mos7840_interrupt_callback, |
| 2704 | }; |
| 2705 | |
Alan Stern | 4d2a7af | 2012-02-23 14:57:09 -0500 | [diff] [blame] | 2706 | static struct usb_serial_driver * const serial_drivers[] = { |
| 2707 | &moschip7840_4port_device, NULL |
| 2708 | }; |
| 2709 | |
Greg Kroah-Hartman | e7414d9 | 2012-02-28 13:12:10 -0800 | [diff] [blame] | 2710 | module_usb_serial_driver(io_driver, serial_drivers); |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2711 | |
Paul B Schroeder | 3f54297 | 2006-08-31 19:41:47 -0500 | [diff] [blame] | 2712 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 2713 | MODULE_LICENSE("GPL"); |
| 2714 | |
| 2715 | module_param(debug, bool, S_IRUGO | S_IWUSR); |
| 2716 | MODULE_PARM_DESC(debug, "Debug enabled or not"); |