Greg Kroah-Hartman | 5fd54ac | 2017-11-03 11:28:30 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 2 | /* |
| 3 | * mos7720.c |
Rahul Bedarkar | cd8c505 | 2014-01-02 19:29:24 +0530 | [diff] [blame] | 4 | * Controls the Moschip 7720 usb to dual port serial converter |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 5 | * |
| 6 | * Copyright 2006 Moschip Semiconductor Tech. Ltd. |
| 7 | * |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 8 | * Developed by: |
Greg Kroah-Hartman | 50d2dc7 | 2007-06-25 01:08:01 -0700 | [diff] [blame] | 9 | * Vijaya Kumar <vijaykumar.gn@gmail.com> |
| 10 | * Ajay Kumar <naanuajay@yahoo.com> |
| 11 | * Gurudeva <ngurudeva@yahoo.com> |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 12 | * |
| 13 | * Cleaned up from the original by: |
| 14 | * Greg Kroah-Hartman <gregkh@suse.de> |
| 15 | * |
| 16 | * Originally based on drivers/usb/serial/io_edgeport.c which is: |
| 17 | * Copyright (C) 2000 Inside Out Networks, All rights reserved. |
| 18 | * Copyright (C) 2001-2002 Greg Kroah-Hartman <greg@kroah.com> |
| 19 | */ |
| 20 | #include <linux/kernel.h> |
| 21 | #include <linux/errno.h> |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 22 | #include <linux/slab.h> |
| 23 | #include <linux/tty.h> |
| 24 | #include <linux/tty_driver.h> |
| 25 | #include <linux/tty_flip.h> |
| 26 | #include <linux/module.h> |
| 27 | #include <linux/spinlock.h> |
| 28 | #include <linux/serial.h> |
| 29 | #include <linux/serial_reg.h> |
| 30 | #include <linux/usb.h> |
| 31 | #include <linux/usb/serial.h> |
Alan Cox | 4da1a17 | 2008-07-22 11:16:21 +0100 | [diff] [blame] | 32 | #include <linux/uaccess.h> |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 33 | #include <linux/parport.h> |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 34 | |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 35 | #define DRIVER_AUTHOR "Aspire Communications pvt Ltd." |
| 36 | #define DRIVER_DESC "Moschip USB Serial Driver" |
| 37 | |
| 38 | /* default urb timeout */ |
Johan Hovold | 849513a | 2013-05-27 14:44:43 +0200 | [diff] [blame] | 39 | #define MOS_WDR_TIMEOUT 5000 |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 40 | |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 41 | #define MOS_MAX_PORT 0x02 |
| 42 | #define MOS_WRITE 0x0E |
| 43 | #define MOS_READ 0x0D |
| 44 | |
Rahul Bedarkar | cd8c505 | 2014-01-02 19:29:24 +0530 | [diff] [blame] | 45 | /* Interrupt Routines Defines */ |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 46 | #define SERIAL_IIR_RLS 0x06 |
| 47 | #define SERIAL_IIR_RDA 0x04 |
| 48 | #define SERIAL_IIR_CTI 0x0c |
| 49 | #define SERIAL_IIR_THR 0x02 |
| 50 | #define SERIAL_IIR_MS 0x00 |
| 51 | |
| 52 | #define NUM_URBS 16 /* URB Count */ |
| 53 | #define URB_TRANSFER_BUFFER_SIZE 32 /* URB Size */ |
| 54 | |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 55 | /* This structure holds all of the local serial port information */ |
Alan Cox | 4da1a17 | 2008-07-22 11:16:21 +0100 | [diff] [blame] | 56 | struct moschip_port { |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 57 | __u8 shadowLCR; /* last LCR value received */ |
| 58 | __u8 shadowMCR; /* last MCR value received */ |
| 59 | __u8 shadowMSR; /* last MSR value received */ |
| 60 | char open; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 61 | struct usb_serial_port *port; /* loop back to the owner */ |
| 62 | struct urb *write_urb_pool[NUM_URBS]; |
| 63 | }; |
| 64 | |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 65 | #define USB_VENDOR_ID_MOSCHIP 0x9710 |
| 66 | #define MOSCHIP_DEVICE_ID_7720 0x7720 |
| 67 | #define MOSCHIP_DEVICE_ID_7715 0x7715 |
| 68 | |
Greg Kroah-Hartman | 68e2411 | 2012-05-08 15:46:14 -0700 | [diff] [blame] | 69 | static const struct usb_device_id id_table[] = { |
Alan Cox | 4da1a17 | 2008-07-22 11:16:21 +0100 | [diff] [blame] | 70 | { USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7720) }, |
Mike Dunn | fb088e3 | 2010-01-26 12:12:12 -0500 | [diff] [blame] | 71 | { USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7715) }, |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 72 | { } /* terminating entry */ |
| 73 | }; |
Greg Kroah-Hartman | 68e2411 | 2012-05-08 15:46:14 -0700 | [diff] [blame] | 74 | MODULE_DEVICE_TABLE(usb, id_table); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 75 | |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 76 | #ifdef CONFIG_USB_SERIAL_MOS7715_PARPORT |
| 77 | |
| 78 | /* initial values for parport regs */ |
| 79 | #define DCR_INIT_VAL 0x0c /* SLCTIN, nINIT */ |
| 80 | #define ECR_INIT_VAL 0x00 /* SPP mode */ |
| 81 | |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 82 | enum mos7715_pp_modes { |
| 83 | SPP = 0<<5, |
| 84 | PS2 = 1<<5, /* moschip calls this 'NIBBLE' mode */ |
| 85 | PPF = 2<<5, /* moschip calls this 'CB-FIFO mode */ |
| 86 | }; |
| 87 | |
| 88 | struct mos7715_parport { |
| 89 | struct parport *pp; /* back to containing struct */ |
| 90 | struct kref ref_count; /* to instance of this struct */ |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 91 | bool msg_pending; /* usb sync call pending */ |
| 92 | struct completion syncmsg_compl; /* usb sync call completed */ |
Davidlohr Bueso | 053af9e | 2020-11-19 20:53:00 -0800 | [diff] [blame] | 93 | struct work_struct work; /* restore deferred writes */ |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 94 | struct usb_serial *serial; /* back to containing struct */ |
| 95 | __u8 shadowECR; /* parallel port regs... */ |
| 96 | __u8 shadowDCR; |
| 97 | atomic_t shadowDSR; /* updated in int-in callback */ |
| 98 | }; |
| 99 | |
| 100 | /* lock guards against dereferencing NULL ptr in parport ops callbacks */ |
| 101 | static DEFINE_SPINLOCK(release_lock); |
| 102 | |
Mike Dunn | 63b9176 | 2010-04-15 17:02:09 -0400 | [diff] [blame] | 103 | #endif /* CONFIG_USB_SERIAL_MOS7715_PARPORT */ |
| 104 | |
| 105 | static const unsigned int dummy; /* for clarity in register access fns */ |
| 106 | |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 107 | enum mos_regs { |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 108 | MOS7720_THR, /* serial port regs */ |
| 109 | MOS7720_RHR, |
| 110 | MOS7720_IER, |
| 111 | MOS7720_FCR, |
| 112 | MOS7720_ISR, |
| 113 | MOS7720_LCR, |
| 114 | MOS7720_MCR, |
| 115 | MOS7720_LSR, |
| 116 | MOS7720_MSR, |
| 117 | MOS7720_SPR, |
| 118 | MOS7720_DLL, |
| 119 | MOS7720_DLM, |
| 120 | MOS7720_DPR, /* parallel port regs */ |
| 121 | MOS7720_DSR, |
| 122 | MOS7720_DCR, |
| 123 | MOS7720_ECR, |
| 124 | MOS7720_SP1_REG, /* device control regs */ |
| 125 | MOS7720_SP2_REG, /* serial port 2 (7720 only) */ |
| 126 | MOS7720_PP_REG, |
| 127 | MOS7720_SP_CONTROL_REG, |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 128 | }; |
| 129 | |
| 130 | /* |
| 131 | * Return the correct value for the Windex field of the setup packet |
| 132 | * for a control endpoint message. See the 7715 datasheet. |
| 133 | */ |
| 134 | static inline __u16 get_reg_index(enum mos_regs reg) |
| 135 | { |
| 136 | static const __u16 mos7715_index_lookup_table[] = { |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 137 | 0x00, /* MOS7720_THR */ |
| 138 | 0x00, /* MOS7720_RHR */ |
| 139 | 0x01, /* MOS7720_IER */ |
| 140 | 0x02, /* MOS7720_FCR */ |
| 141 | 0x02, /* MOS7720_ISR */ |
| 142 | 0x03, /* MOS7720_LCR */ |
| 143 | 0x04, /* MOS7720_MCR */ |
| 144 | 0x05, /* MOS7720_LSR */ |
| 145 | 0x06, /* MOS7720_MSR */ |
| 146 | 0x07, /* MOS7720_SPR */ |
| 147 | 0x00, /* MOS7720_DLL */ |
| 148 | 0x01, /* MOS7720_DLM */ |
| 149 | 0x00, /* MOS7720_DPR */ |
| 150 | 0x01, /* MOS7720_DSR */ |
| 151 | 0x02, /* MOS7720_DCR */ |
| 152 | 0x0a, /* MOS7720_ECR */ |
| 153 | 0x01, /* MOS7720_SP1_REG */ |
| 154 | 0x02, /* MOS7720_SP2_REG (7720 only) */ |
| 155 | 0x04, /* MOS7720_PP_REG (7715 only) */ |
| 156 | 0x08, /* MOS7720_SP_CONTROL_REG */ |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 157 | }; |
| 158 | return mos7715_index_lookup_table[reg]; |
| 159 | } |
| 160 | |
| 161 | /* |
| 162 | * Return the correct value for the upper byte of the Wvalue field of |
| 163 | * the setup packet for a control endpoint message. |
| 164 | */ |
Mike Dunn | 63b9176 | 2010-04-15 17:02:09 -0400 | [diff] [blame] | 165 | static inline __u16 get_reg_value(enum mos_regs reg, |
| 166 | unsigned int serial_portnum) |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 167 | { |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 168 | if (reg >= MOS7720_SP1_REG) /* control reg */ |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 169 | return 0x0000; |
Mike Dunn | 63b9176 | 2010-04-15 17:02:09 -0400 | [diff] [blame] | 170 | |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 171 | else if (reg >= MOS7720_DPR) /* parallel port reg (7715 only) */ |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 172 | return 0x0100; |
Mike Dunn | 63b9176 | 2010-04-15 17:02:09 -0400 | [diff] [blame] | 173 | |
| 174 | else /* serial port reg */ |
| 175 | return (serial_portnum + 2) << 8; |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | /* |
| 179 | * Write data byte to the specified device register. The data is embedded in |
Mike Dunn | 63b9176 | 2010-04-15 17:02:09 -0400 | [diff] [blame] | 180 | * the value field of the setup packet. serial_portnum is ignored for registers |
| 181 | * not specific to a particular serial port. |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 182 | */ |
Mike Dunn | 63b9176 | 2010-04-15 17:02:09 -0400 | [diff] [blame] | 183 | static int write_mos_reg(struct usb_serial *serial, unsigned int serial_portnum, |
| 184 | enum mos_regs reg, __u8 data) |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 185 | { |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 186 | struct usb_device *usbdev = serial->dev; |
| 187 | unsigned int pipe = usb_sndctrlpipe(usbdev, 0); |
| 188 | __u8 request = (__u8)0x0e; |
| 189 | __u8 requesttype = (__u8)0x40; |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 190 | __u16 index = get_reg_index(reg); |
Mike Dunn | 63b9176 | 2010-04-15 17:02:09 -0400 | [diff] [blame] | 191 | __u16 value = get_reg_value(reg, serial_portnum) + data; |
| 192 | int status = usb_control_msg(usbdev, pipe, request, requesttype, value, |
| 193 | index, NULL, 0, MOS_WDR_TIMEOUT); |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 194 | if (status < 0) |
| 195 | dev_err(&usbdev->dev, |
Johan Hovold | d9a38a8 | 2014-03-12 19:09:42 +0100 | [diff] [blame] | 196 | "mos7720: usb_control_msg() failed: %d\n", status); |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 197 | return status; |
| 198 | } |
| 199 | |
| 200 | /* |
| 201 | * Read data byte from the specified device register. The data returned by the |
Mike Dunn | 63b9176 | 2010-04-15 17:02:09 -0400 | [diff] [blame] | 202 | * device is embedded in the value field of the setup packet. serial_portnum is |
| 203 | * ignored for registers that are not specific to a particular serial port. |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 204 | */ |
Mike Dunn | 63b9176 | 2010-04-15 17:02:09 -0400 | [diff] [blame] | 205 | static int read_mos_reg(struct usb_serial *serial, unsigned int serial_portnum, |
| 206 | enum mos_regs reg, __u8 *data) |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 207 | { |
Mike Dunn | 63b9176 | 2010-04-15 17:02:09 -0400 | [diff] [blame] | 208 | struct usb_device *usbdev = serial->dev; |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 209 | unsigned int pipe = usb_rcvctrlpipe(usbdev, 0); |
| 210 | __u8 request = (__u8)0x0d; |
| 211 | __u8 requesttype = (__u8)0xc0; |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 212 | __u16 index = get_reg_index(reg); |
Mike Dunn | 63b9176 | 2010-04-15 17:02:09 -0400 | [diff] [blame] | 213 | __u16 value = get_reg_value(reg, serial_portnum); |
Johan Hovold | 72ea18a | 2013-05-27 14:44:39 +0200 | [diff] [blame] | 214 | u8 *buf; |
| 215 | int status; |
| 216 | |
| 217 | buf = kmalloc(1, GFP_KERNEL); |
| 218 | if (!buf) |
| 219 | return -ENOMEM; |
| 220 | |
| 221 | status = usb_control_msg(usbdev, pipe, request, requesttype, value, |
| 222 | index, buf, 1, MOS_WDR_TIMEOUT); |
Johan Hovold | 0d13036 | 2017-01-12 14:56:17 +0100 | [diff] [blame] | 223 | if (status == 1) { |
Johan Hovold | 72ea18a | 2013-05-27 14:44:39 +0200 | [diff] [blame] | 224 | *data = *buf; |
Johan Hovold | 0d13036 | 2017-01-12 14:56:17 +0100 | [diff] [blame] | 225 | } else { |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 226 | dev_err(&usbdev->dev, |
Johan Hovold | d9a38a8 | 2014-03-12 19:09:42 +0100 | [diff] [blame] | 227 | "mos7720: usb_control_msg() failed: %d\n", status); |
Johan Hovold | 0d13036 | 2017-01-12 14:56:17 +0100 | [diff] [blame] | 228 | if (status >= 0) |
| 229 | status = -EIO; |
| 230 | *data = 0; |
| 231 | } |
| 232 | |
Johan Hovold | 72ea18a | 2013-05-27 14:44:39 +0200 | [diff] [blame] | 233 | kfree(buf); |
| 234 | |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 235 | return status; |
| 236 | } |
| 237 | |
Mike Dunn | 63b9176 | 2010-04-15 17:02:09 -0400 | [diff] [blame] | 238 | #ifdef CONFIG_USB_SERIAL_MOS7715_PARPORT |
| 239 | |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 240 | static inline int mos7715_change_mode(struct mos7715_parport *mos_parport, |
| 241 | enum mos7715_pp_modes mode) |
| 242 | { |
| 243 | mos_parport->shadowECR = mode; |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 244 | write_mos_reg(mos_parport->serial, dummy, MOS7720_ECR, |
| 245 | mos_parport->shadowECR); |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 246 | return 0; |
| 247 | } |
| 248 | |
| 249 | static void destroy_mos_parport(struct kref *kref) |
| 250 | { |
| 251 | struct mos7715_parport *mos_parport = |
| 252 | container_of(kref, struct mos7715_parport, ref_count); |
| 253 | |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 254 | kfree(mos_parport); |
| 255 | } |
| 256 | |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 257 | /* |
Davidlohr Bueso | 053af9e | 2020-11-19 20:53:00 -0800 | [diff] [blame] | 258 | * This is the common top part of all parallel port callback operations that |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 259 | * send synchronous messages to the device. This implements convoluted locking |
| 260 | * that avoids two scenarios: (1) a port operation is called after usbserial |
| 261 | * has called our release function, at which point struct mos7715_parport has |
| 262 | * been destroyed, and (2) the device has been disconnected, but usbserial has |
| 263 | * not called the release function yet because someone has a serial port open. |
| 264 | * The shared release_lock prevents the first, and the mutex and disconnected |
| 265 | * flag maintained by usbserial covers the second. We also use the msg_pending |
Rahul Bedarkar | cd8c505 | 2014-01-02 19:29:24 +0530 | [diff] [blame] | 266 | * flag to ensure that all synchronous usb message calls have completed before |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 267 | * our release function can return. |
| 268 | */ |
| 269 | static int parport_prologue(struct parport *pp) |
| 270 | { |
| 271 | struct mos7715_parport *mos_parport; |
| 272 | |
| 273 | spin_lock(&release_lock); |
| 274 | mos_parport = pp->private_data; |
| 275 | if (unlikely(mos_parport == NULL)) { |
| 276 | /* release fn called, port struct destroyed */ |
| 277 | spin_unlock(&release_lock); |
| 278 | return -1; |
| 279 | } |
| 280 | mos_parport->msg_pending = true; /* synch usb call pending */ |
Wolfram Sang | 16735d0 | 2013-11-14 14:32:02 -0800 | [diff] [blame] | 281 | reinit_completion(&mos_parport->syncmsg_compl); |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 282 | spin_unlock(&release_lock); |
| 283 | |
Davidlohr Bueso | 053af9e | 2020-11-19 20:53:00 -0800 | [diff] [blame] | 284 | /* ensure writes from restore are submitted before new requests */ |
| 285 | if (work_pending(&mos_parport->work)) |
| 286 | flush_work(&mos_parport->work); |
| 287 | |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 288 | mutex_lock(&mos_parport->serial->disc_mutex); |
| 289 | if (mos_parport->serial->disconnected) { |
| 290 | /* device disconnected */ |
| 291 | mutex_unlock(&mos_parport->serial->disc_mutex); |
| 292 | mos_parport->msg_pending = false; |
| 293 | complete(&mos_parport->syncmsg_compl); |
| 294 | return -1; |
| 295 | } |
| 296 | |
| 297 | return 0; |
| 298 | } |
| 299 | |
| 300 | /* |
Rahul Bedarkar | cd8c505 | 2014-01-02 19:29:24 +0530 | [diff] [blame] | 301 | * This is the common bottom part of all parallel port functions that send |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 302 | * synchronous messages to the device. |
| 303 | */ |
| 304 | static inline void parport_epilogue(struct parport *pp) |
| 305 | { |
| 306 | struct mos7715_parport *mos_parport = pp->private_data; |
| 307 | mutex_unlock(&mos_parport->serial->disc_mutex); |
| 308 | mos_parport->msg_pending = false; |
| 309 | complete(&mos_parport->syncmsg_compl); |
| 310 | } |
| 311 | |
Davidlohr Bueso | 053af9e | 2020-11-19 20:53:00 -0800 | [diff] [blame] | 312 | static void deferred_restore_writes(struct work_struct *work) |
| 313 | { |
| 314 | struct mos7715_parport *mos_parport; |
| 315 | |
| 316 | mos_parport = container_of(work, struct mos7715_parport, work); |
| 317 | |
| 318 | mutex_lock(&mos_parport->serial->disc_mutex); |
| 319 | |
| 320 | /* if device disconnected, game over */ |
| 321 | if (mos_parport->serial->disconnected) |
| 322 | goto done; |
| 323 | |
| 324 | write_mos_reg(mos_parport->serial, dummy, MOS7720_DCR, |
| 325 | mos_parport->shadowDCR); |
| 326 | write_mos_reg(mos_parport->serial, dummy, MOS7720_ECR, |
| 327 | mos_parport->shadowECR); |
| 328 | done: |
| 329 | mutex_unlock(&mos_parport->serial->disc_mutex); |
| 330 | } |
| 331 | |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 332 | static void parport_mos7715_write_data(struct parport *pp, unsigned char d) |
| 333 | { |
| 334 | struct mos7715_parport *mos_parport = pp->private_data; |
Greg Kroah-Hartman | ca09907 | 2012-05-03 16:44:31 -0700 | [diff] [blame] | 335 | |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 336 | if (parport_prologue(pp) < 0) |
| 337 | return; |
| 338 | mos7715_change_mode(mos_parport, SPP); |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 339 | write_mos_reg(mos_parport->serial, dummy, MOS7720_DPR, (__u8)d); |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 340 | parport_epilogue(pp); |
| 341 | } |
| 342 | |
| 343 | static unsigned char parport_mos7715_read_data(struct parport *pp) |
| 344 | { |
| 345 | struct mos7715_parport *mos_parport = pp->private_data; |
| 346 | unsigned char d; |
Greg Kroah-Hartman | ca09907 | 2012-05-03 16:44:31 -0700 | [diff] [blame] | 347 | |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 348 | if (parport_prologue(pp) < 0) |
| 349 | return 0; |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 350 | read_mos_reg(mos_parport->serial, dummy, MOS7720_DPR, &d); |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 351 | parport_epilogue(pp); |
| 352 | return d; |
| 353 | } |
| 354 | |
| 355 | static void parport_mos7715_write_control(struct parport *pp, unsigned char d) |
| 356 | { |
| 357 | struct mos7715_parport *mos_parport = pp->private_data; |
| 358 | __u8 data; |
Greg Kroah-Hartman | ca09907 | 2012-05-03 16:44:31 -0700 | [diff] [blame] | 359 | |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 360 | if (parport_prologue(pp) < 0) |
| 361 | return; |
| 362 | data = ((__u8)d & 0x0f) | (mos_parport->shadowDCR & 0xf0); |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 363 | write_mos_reg(mos_parport->serial, dummy, MOS7720_DCR, data); |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 364 | mos_parport->shadowDCR = data; |
| 365 | parport_epilogue(pp); |
| 366 | } |
| 367 | |
| 368 | static unsigned char parport_mos7715_read_control(struct parport *pp) |
| 369 | { |
Colin Ian King | f0b4198 | 2018-01-17 11:54:27 +0000 | [diff] [blame] | 370 | struct mos7715_parport *mos_parport; |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 371 | __u8 dcr; |
Greg Kroah-Hartman | ca09907 | 2012-05-03 16:44:31 -0700 | [diff] [blame] | 372 | |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 373 | spin_lock(&release_lock); |
| 374 | mos_parport = pp->private_data; |
| 375 | if (unlikely(mos_parport == NULL)) { |
| 376 | spin_unlock(&release_lock); |
| 377 | return 0; |
| 378 | } |
| 379 | dcr = mos_parport->shadowDCR & 0x0f; |
| 380 | spin_unlock(&release_lock); |
| 381 | return dcr; |
| 382 | } |
| 383 | |
| 384 | static unsigned char parport_mos7715_frob_control(struct parport *pp, |
| 385 | unsigned char mask, |
| 386 | unsigned char val) |
| 387 | { |
| 388 | struct mos7715_parport *mos_parport = pp->private_data; |
| 389 | __u8 dcr; |
Greg Kroah-Hartman | ca09907 | 2012-05-03 16:44:31 -0700 | [diff] [blame] | 390 | |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 391 | mask &= 0x0f; |
| 392 | val &= 0x0f; |
| 393 | if (parport_prologue(pp) < 0) |
| 394 | return 0; |
| 395 | mos_parport->shadowDCR = (mos_parport->shadowDCR & (~mask)) ^ val; |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 396 | write_mos_reg(mos_parport->serial, dummy, MOS7720_DCR, |
| 397 | mos_parport->shadowDCR); |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 398 | dcr = mos_parport->shadowDCR & 0x0f; |
| 399 | parport_epilogue(pp); |
| 400 | return dcr; |
| 401 | } |
| 402 | |
| 403 | static unsigned char parport_mos7715_read_status(struct parport *pp) |
| 404 | { |
| 405 | unsigned char status; |
Colin Ian King | f0b4198 | 2018-01-17 11:54:27 +0000 | [diff] [blame] | 406 | struct mos7715_parport *mos_parport; |
Greg Kroah-Hartman | ca09907 | 2012-05-03 16:44:31 -0700 | [diff] [blame] | 407 | |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 408 | spin_lock(&release_lock); |
| 409 | mos_parport = pp->private_data; |
| 410 | if (unlikely(mos_parport == NULL)) { /* release called */ |
| 411 | spin_unlock(&release_lock); |
| 412 | return 0; |
| 413 | } |
| 414 | status = atomic_read(&mos_parport->shadowDSR) & 0xf8; |
| 415 | spin_unlock(&release_lock); |
| 416 | return status; |
| 417 | } |
| 418 | |
| 419 | static void parport_mos7715_enable_irq(struct parport *pp) |
| 420 | { |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 421 | } |
Greg Kroah-Hartman | ca09907 | 2012-05-03 16:44:31 -0700 | [diff] [blame] | 422 | |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 423 | static void parport_mos7715_disable_irq(struct parport *pp) |
| 424 | { |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | static void parport_mos7715_data_forward(struct parport *pp) |
| 428 | { |
| 429 | struct mos7715_parport *mos_parport = pp->private_data; |
Greg Kroah-Hartman | ca09907 | 2012-05-03 16:44:31 -0700 | [diff] [blame] | 430 | |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 431 | if (parport_prologue(pp) < 0) |
| 432 | return; |
| 433 | mos7715_change_mode(mos_parport, PS2); |
| 434 | mos_parport->shadowDCR &= ~0x20; |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 435 | write_mos_reg(mos_parport->serial, dummy, MOS7720_DCR, |
| 436 | mos_parport->shadowDCR); |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 437 | parport_epilogue(pp); |
| 438 | } |
| 439 | |
| 440 | static void parport_mos7715_data_reverse(struct parport *pp) |
| 441 | { |
| 442 | struct mos7715_parport *mos_parport = pp->private_data; |
Greg Kroah-Hartman | ca09907 | 2012-05-03 16:44:31 -0700 | [diff] [blame] | 443 | |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 444 | if (parport_prologue(pp) < 0) |
| 445 | return; |
| 446 | mos7715_change_mode(mos_parport, PS2); |
| 447 | mos_parport->shadowDCR |= 0x20; |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 448 | write_mos_reg(mos_parport->serial, dummy, MOS7720_DCR, |
| 449 | mos_parport->shadowDCR); |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 450 | parport_epilogue(pp); |
| 451 | } |
| 452 | |
| 453 | static void parport_mos7715_init_state(struct pardevice *dev, |
| 454 | struct parport_state *s) |
| 455 | { |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 456 | s->u.pc.ctr = DCR_INIT_VAL; |
| 457 | s->u.pc.ecr = ECR_INIT_VAL; |
| 458 | } |
| 459 | |
| 460 | /* N.B. Parport core code requires that this function not block */ |
| 461 | static void parport_mos7715_save_state(struct parport *pp, |
| 462 | struct parport_state *s) |
| 463 | { |
| 464 | struct mos7715_parport *mos_parport; |
Greg Kroah-Hartman | ca09907 | 2012-05-03 16:44:31 -0700 | [diff] [blame] | 465 | |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 466 | spin_lock(&release_lock); |
| 467 | mos_parport = pp->private_data; |
| 468 | if (unlikely(mos_parport == NULL)) { /* release called */ |
| 469 | spin_unlock(&release_lock); |
| 470 | return; |
| 471 | } |
| 472 | s->u.pc.ctr = mos_parport->shadowDCR; |
| 473 | s->u.pc.ecr = mos_parport->shadowECR; |
| 474 | spin_unlock(&release_lock); |
| 475 | } |
| 476 | |
| 477 | /* N.B. Parport core code requires that this function not block */ |
| 478 | static void parport_mos7715_restore_state(struct parport *pp, |
| 479 | struct parport_state *s) |
| 480 | { |
| 481 | struct mos7715_parport *mos_parport; |
Greg Kroah-Hartman | ca09907 | 2012-05-03 16:44:31 -0700 | [diff] [blame] | 482 | |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 483 | spin_lock(&release_lock); |
| 484 | mos_parport = pp->private_data; |
| 485 | if (unlikely(mos_parport == NULL)) { /* release called */ |
| 486 | spin_unlock(&release_lock); |
| 487 | return; |
| 488 | } |
Johan Hovold | 975323a | 2020-11-04 17:47:27 +0100 | [diff] [blame] | 489 | mos_parport->shadowDCR = s->u.pc.ctr; |
| 490 | mos_parport->shadowECR = s->u.pc.ecr; |
Davidlohr Bueso | 053af9e | 2020-11-19 20:53:00 -0800 | [diff] [blame] | 491 | |
| 492 | schedule_work(&mos_parport->work); |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 493 | spin_unlock(&release_lock); |
| 494 | } |
| 495 | |
| 496 | static size_t parport_mos7715_write_compat(struct parport *pp, |
| 497 | const void *buffer, |
| 498 | size_t len, int flags) |
| 499 | { |
| 500 | int retval; |
| 501 | struct mos7715_parport *mos_parport = pp->private_data; |
| 502 | int actual_len; |
Greg Kroah-Hartman | ca09907 | 2012-05-03 16:44:31 -0700 | [diff] [blame] | 503 | |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 504 | if (parport_prologue(pp) < 0) |
| 505 | return 0; |
| 506 | mos7715_change_mode(mos_parport, PPF); |
| 507 | retval = usb_bulk_msg(mos_parport->serial->dev, |
| 508 | usb_sndbulkpipe(mos_parport->serial->dev, 2), |
| 509 | (void *)buffer, len, &actual_len, |
| 510 | MOS_WDR_TIMEOUT); |
| 511 | parport_epilogue(pp); |
| 512 | if (retval) { |
| 513 | dev_err(&mos_parport->serial->dev->dev, |
Johan Hovold | d9a38a8 | 2014-03-12 19:09:42 +0100 | [diff] [blame] | 514 | "mos7720: usb_bulk_msg() failed: %d\n", retval); |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 515 | return 0; |
| 516 | } |
| 517 | return actual_len; |
| 518 | } |
| 519 | |
| 520 | static struct parport_operations parport_mos7715_ops = { |
| 521 | .owner = THIS_MODULE, |
| 522 | .write_data = parport_mos7715_write_data, |
| 523 | .read_data = parport_mos7715_read_data, |
| 524 | |
| 525 | .write_control = parport_mos7715_write_control, |
| 526 | .read_control = parport_mos7715_read_control, |
| 527 | .frob_control = parport_mos7715_frob_control, |
| 528 | |
| 529 | .read_status = parport_mos7715_read_status, |
| 530 | |
| 531 | .enable_irq = parport_mos7715_enable_irq, |
| 532 | .disable_irq = parport_mos7715_disable_irq, |
| 533 | |
| 534 | .data_forward = parport_mos7715_data_forward, |
| 535 | .data_reverse = parport_mos7715_data_reverse, |
| 536 | |
| 537 | .init_state = parport_mos7715_init_state, |
| 538 | .save_state = parport_mos7715_save_state, |
| 539 | .restore_state = parport_mos7715_restore_state, |
| 540 | |
| 541 | .compat_write_data = parport_mos7715_write_compat, |
| 542 | |
| 543 | .nibble_read_data = parport_ieee1284_read_nibble, |
| 544 | .byte_read_data = parport_ieee1284_read_byte, |
| 545 | }; |
| 546 | |
| 547 | /* |
| 548 | * Allocate and initialize parallel port control struct, initialize |
| 549 | * the parallel port hardware device, and register with the parport subsystem. |
| 550 | */ |
| 551 | static int mos7715_parport_init(struct usb_serial *serial) |
| 552 | { |
| 553 | struct mos7715_parport *mos_parport; |
| 554 | |
| 555 | /* allocate and initialize parallel port control struct */ |
| 556 | mos_parport = kzalloc(sizeof(struct mos7715_parport), GFP_KERNEL); |
Johan Hovold | 10c642d | 2013-12-29 19:22:56 +0100 | [diff] [blame] | 557 | if (!mos_parport) |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 558 | return -ENOMEM; |
Johan Hovold | 10c642d | 2013-12-29 19:22:56 +0100 | [diff] [blame] | 559 | |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 560 | mos_parport->msg_pending = false; |
| 561 | kref_init(&mos_parport->ref_count); |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 562 | usb_set_serial_data(serial, mos_parport); /* hijack private pointer */ |
| 563 | mos_parport->serial = serial; |
Davidlohr Bueso | 053af9e | 2020-11-19 20:53:00 -0800 | [diff] [blame] | 564 | INIT_WORK(&mos_parport->work, deferred_restore_writes); |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 565 | init_completion(&mos_parport->syncmsg_compl); |
| 566 | |
| 567 | /* cycle parallel port reset bit */ |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 568 | write_mos_reg(mos_parport->serial, dummy, MOS7720_PP_REG, (__u8)0x80); |
| 569 | write_mos_reg(mos_parport->serial, dummy, MOS7720_PP_REG, (__u8)0x00); |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 570 | |
| 571 | /* initialize device registers */ |
| 572 | mos_parport->shadowDCR = DCR_INIT_VAL; |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 573 | write_mos_reg(mos_parport->serial, dummy, MOS7720_DCR, |
| 574 | mos_parport->shadowDCR); |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 575 | mos_parport->shadowECR = ECR_INIT_VAL; |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 576 | write_mos_reg(mos_parport->serial, dummy, MOS7720_ECR, |
| 577 | mos_parport->shadowECR); |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 578 | |
| 579 | /* register with parport core */ |
| 580 | mos_parport->pp = parport_register_port(0, PARPORT_IRQ_NONE, |
| 581 | PARPORT_DMA_NONE, |
| 582 | &parport_mos7715_ops); |
| 583 | if (mos_parport->pp == NULL) { |
| 584 | dev_err(&serial->interface->dev, |
| 585 | "Could not register parport\n"); |
| 586 | kref_put(&mos_parport->ref_count, destroy_mos_parport); |
| 587 | return -EIO; |
| 588 | } |
| 589 | mos_parport->pp->private_data = mos_parport; |
| 590 | mos_parport->pp->modes = PARPORT_MODE_COMPAT | PARPORT_MODE_PCSPP; |
| 591 | mos_parport->pp->dev = &serial->interface->dev; |
| 592 | parport_announce_port(mos_parport->pp); |
| 593 | |
| 594 | return 0; |
| 595 | } |
| 596 | #endif /* CONFIG_USB_SERIAL_MOS7715_PARPORT */ |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 597 | |
| 598 | /* |
| 599 | * mos7720_interrupt_callback |
| 600 | * this is the callback function for when we have received data on the |
| 601 | * interrupt endpoint. |
| 602 | */ |
| 603 | static void mos7720_interrupt_callback(struct urb *urb) |
| 604 | { |
| 605 | int result; |
| 606 | int length; |
Greg Kroah-Hartman | 8110598 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 607 | int status = urb->status; |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 608 | struct device *dev = &urb->dev->dev; |
Oliver Neukum | 325b70c | 2007-03-19 13:58:29 +0100 | [diff] [blame] | 609 | __u8 *data; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 610 | __u8 sp1; |
| 611 | __u8 sp2; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 612 | |
Greg Kroah-Hartman | 8110598 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 613 | switch (status) { |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 614 | case 0: |
| 615 | /* success */ |
| 616 | break; |
| 617 | case -ECONNRESET: |
| 618 | case -ENOENT: |
| 619 | case -ESHUTDOWN: |
| 620 | /* this urb is terminated, clean up */ |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 621 | dev_dbg(dev, "%s - urb shutting down with status: %d\n", __func__, status); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 622 | return; |
| 623 | default: |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 624 | dev_dbg(dev, "%s - nonzero urb status received: %d\n", __func__, status); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 625 | goto exit; |
| 626 | } |
| 627 | |
| 628 | length = urb->actual_length; |
| 629 | data = urb->transfer_buffer; |
| 630 | |
| 631 | /* Moschip get 4 bytes |
| 632 | * Byte 1 IIR Port 1 (port.number is 0) |
| 633 | * Byte 2 IIR Port 2 (port.number is 1) |
| 634 | * Byte 3 -------------- |
| 635 | * Byte 4 FIFO status for both */ |
Oliver Neukum | 325b70c | 2007-03-19 13:58:29 +0100 | [diff] [blame] | 636 | |
| 637 | /* the above description is inverted |
| 638 | * oneukum 2007-03-14 */ |
| 639 | |
| 640 | if (unlikely(length != 4)) { |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 641 | dev_dbg(dev, "Wrong data !!!\n"); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 642 | return; |
| 643 | } |
| 644 | |
Oliver Neukum | 325b70c | 2007-03-19 13:58:29 +0100 | [diff] [blame] | 645 | sp1 = data[3]; |
| 646 | sp2 = data[2]; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 647 | |
Oliver Neukum | 325b70c | 2007-03-19 13:58:29 +0100 | [diff] [blame] | 648 | if ((sp1 | sp2) & 0x01) { |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 649 | /* No Interrupt Pending in both the ports */ |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 650 | dev_dbg(dev, "No Interrupt !!!\n"); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 651 | } else { |
| 652 | switch (sp1 & 0x0f) { |
| 653 | case SERIAL_IIR_RLS: |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 654 | dev_dbg(dev, "Serial Port 1: Receiver status error or address bit detected in 9-bit mode\n"); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 655 | break; |
| 656 | case SERIAL_IIR_CTI: |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 657 | dev_dbg(dev, "Serial Port 1: Receiver time out\n"); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 658 | break; |
| 659 | case SERIAL_IIR_MS: |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 660 | /* dev_dbg(dev, "Serial Port 1: Modem status change\n"); */ |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 661 | break; |
| 662 | } |
| 663 | |
| 664 | switch (sp2 & 0x0f) { |
| 665 | case SERIAL_IIR_RLS: |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 666 | dev_dbg(dev, "Serial Port 2: Receiver status error or address bit detected in 9-bit mode\n"); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 667 | break; |
| 668 | case SERIAL_IIR_CTI: |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 669 | dev_dbg(dev, "Serial Port 2: Receiver time out\n"); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 670 | break; |
| 671 | case SERIAL_IIR_MS: |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 672 | /* dev_dbg(dev, "Serial Port 2: Modem status change\n"); */ |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 673 | break; |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | exit: |
| 678 | result = usb_submit_urb(urb, GFP_ATOMIC); |
| 679 | if (result) |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 680 | dev_err(dev, "%s - Error %d submitting control urb\n", __func__, result); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | /* |
Mike Dunn | fb088e3 | 2010-01-26 12:12:12 -0500 | [diff] [blame] | 684 | * mos7715_interrupt_callback |
| 685 | * this is the 7715's callback function for when we have received data on |
| 686 | * the interrupt endpoint. |
| 687 | */ |
| 688 | static void mos7715_interrupt_callback(struct urb *urb) |
| 689 | { |
| 690 | int result; |
| 691 | int length; |
| 692 | int status = urb->status; |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 693 | struct device *dev = &urb->dev->dev; |
Mike Dunn | fb088e3 | 2010-01-26 12:12:12 -0500 | [diff] [blame] | 694 | __u8 *data; |
| 695 | __u8 iir; |
| 696 | |
| 697 | switch (status) { |
| 698 | case 0: |
| 699 | /* success */ |
| 700 | break; |
| 701 | case -ECONNRESET: |
| 702 | case -ENOENT: |
| 703 | case -ESHUTDOWN: |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 704 | case -ENODEV: |
Mike Dunn | fb088e3 | 2010-01-26 12:12:12 -0500 | [diff] [blame] | 705 | /* this urb is terminated, clean up */ |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 706 | dev_dbg(dev, "%s - urb shutting down with status: %d\n", __func__, status); |
Mike Dunn | fb088e3 | 2010-01-26 12:12:12 -0500 | [diff] [blame] | 707 | return; |
| 708 | default: |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 709 | dev_dbg(dev, "%s - nonzero urb status received: %d\n", __func__, status); |
Mike Dunn | fb088e3 | 2010-01-26 12:12:12 -0500 | [diff] [blame] | 710 | goto exit; |
| 711 | } |
| 712 | |
| 713 | length = urb->actual_length; |
| 714 | data = urb->transfer_buffer; |
| 715 | |
| 716 | /* Structure of data from 7715 device: |
| 717 | * Byte 1: IIR serial Port |
| 718 | * Byte 2: unused |
| 719 | * Byte 2: DSR parallel port |
| 720 | * Byte 4: FIFO status for both */ |
| 721 | |
| 722 | if (unlikely(length != 4)) { |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 723 | dev_dbg(dev, "Wrong data !!!\n"); |
Mike Dunn | fb088e3 | 2010-01-26 12:12:12 -0500 | [diff] [blame] | 724 | return; |
| 725 | } |
| 726 | |
| 727 | iir = data[0]; |
| 728 | if (!(iir & 0x01)) { /* serial port interrupt pending */ |
| 729 | switch (iir & 0x0f) { |
| 730 | case SERIAL_IIR_RLS: |
Johan Hovold | d9a38a8 | 2014-03-12 19:09:42 +0100 | [diff] [blame] | 731 | dev_dbg(dev, "Serial Port: Receiver status error or address bit detected in 9-bit mode\n"); |
Mike Dunn | fb088e3 | 2010-01-26 12:12:12 -0500 | [diff] [blame] | 732 | break; |
| 733 | case SERIAL_IIR_CTI: |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 734 | dev_dbg(dev, "Serial Port: Receiver time out\n"); |
Mike Dunn | fb088e3 | 2010-01-26 12:12:12 -0500 | [diff] [blame] | 735 | break; |
| 736 | case SERIAL_IIR_MS: |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 737 | /* dev_dbg(dev, "Serial Port: Modem status change\n"); */ |
Mike Dunn | fb088e3 | 2010-01-26 12:12:12 -0500 | [diff] [blame] | 738 | break; |
| 739 | } |
| 740 | } |
| 741 | |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 742 | #ifdef CONFIG_USB_SERIAL_MOS7715_PARPORT |
| 743 | { /* update local copy of DSR reg */ |
| 744 | struct usb_serial_port *port = urb->context; |
| 745 | struct mos7715_parport *mos_parport = port->serial->private; |
| 746 | if (unlikely(mos_parport == NULL)) |
| 747 | return; |
| 748 | atomic_set(&mos_parport->shadowDSR, data[2]); |
| 749 | } |
| 750 | #endif |
| 751 | |
Mike Dunn | fb088e3 | 2010-01-26 12:12:12 -0500 | [diff] [blame] | 752 | exit: |
| 753 | result = usb_submit_urb(urb, GFP_ATOMIC); |
| 754 | if (result) |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 755 | dev_err(dev, "%s - Error %d submitting control urb\n", __func__, result); |
Mike Dunn | fb088e3 | 2010-01-26 12:12:12 -0500 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | /* |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 759 | * mos7720_bulk_in_callback |
| 760 | * this is the callback function for when we have received data on the |
| 761 | * bulk in endpoint. |
| 762 | */ |
| 763 | static void mos7720_bulk_in_callback(struct urb *urb) |
| 764 | { |
Greg Kroah-Hartman | 8110598 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 765 | int retval; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 766 | unsigned char *data ; |
| 767 | struct usb_serial_port *port; |
Greg Kroah-Hartman | 8110598 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 768 | int status = urb->status; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 769 | |
Greg Kroah-Hartman | 8110598 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 770 | if (status) { |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 771 | dev_dbg(&urb->dev->dev, "nonzero read bulk status received: %d\n", status); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 772 | return; |
| 773 | } |
| 774 | |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 775 | port = urb->context; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 776 | |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 777 | dev_dbg(&port->dev, "Entering...%s\n", __func__); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 778 | |
| 779 | data = urb->transfer_buffer; |
| 780 | |
Jiri Slaby | 2e124b4 | 2013-01-03 15:53:06 +0100 | [diff] [blame] | 781 | if (urb->actual_length) { |
Jiri Slaby | 05c7cd3 | 2013-01-03 15:53:04 +0100 | [diff] [blame] | 782 | tty_insert_flip_string(&port->port, data, urb->actual_length); |
Jiri Slaby | 2e124b4 | 2013-01-03 15:53:06 +0100 | [diff] [blame] | 783 | tty_flip_buffer_push(&port->port); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 784 | } |
| 785 | |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 786 | if (port->read_urb->status != -EINPROGRESS) { |
Greg Kroah-Hartman | 8110598 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 787 | retval = usb_submit_urb(port->read_urb, GFP_ATOMIC); |
| 788 | if (retval) |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 789 | dev_dbg(&port->dev, "usb_submit_urb(read bulk) failed, retval = %d\n", retval); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 790 | } |
| 791 | } |
| 792 | |
| 793 | /* |
| 794 | * mos7720_bulk_out_data_callback |
| 795 | * this is the callback function for when we have finished sending serial |
| 796 | * data on the bulk out endpoint. |
| 797 | */ |
| 798 | static void mos7720_bulk_out_data_callback(struct urb *urb) |
| 799 | { |
| 800 | struct moschip_port *mos7720_port; |
Greg Kroah-Hartman | 8110598 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 801 | int status = urb->status; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 802 | |
Greg Kroah-Hartman | 8110598 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 803 | if (status) { |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 804 | dev_dbg(&urb->dev->dev, "nonzero write bulk status received:%d\n", status); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 805 | return; |
| 806 | } |
| 807 | |
| 808 | mos7720_port = urb->context; |
| 809 | if (!mos7720_port) { |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 810 | dev_dbg(&urb->dev->dev, "NULL mos7720_port pointer\n"); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 811 | return ; |
| 812 | } |
| 813 | |
Jiri Slaby | 6aad04f | 2013-03-07 13:12:29 +0100 | [diff] [blame] | 814 | if (mos7720_port->open) |
| 815 | tty_port_tty_wakeup(&mos7720_port->port->port); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 816 | } |
| 817 | |
Johan Hovold | 0781424 | 2017-03-16 17:13:30 +0100 | [diff] [blame] | 818 | static int mos77xx_calc_num_ports(struct usb_serial *serial, |
| 819 | struct usb_serial_endpoints *epds) |
Mike Dunn | fb088e3 | 2010-01-26 12:12:12 -0500 | [diff] [blame] | 820 | { |
| 821 | u16 product = le16_to_cpu(serial->dev->descriptor.idProduct); |
Johan Hovold | d760557 | 2017-03-16 17:13:45 +0100 | [diff] [blame] | 822 | |
| 823 | if (product == MOSCHIP_DEVICE_ID_7715) { |
| 824 | /* |
| 825 | * The 7715 uses the first bulk in/out endpoint pair for the |
| 826 | * parallel port, and the second for the serial port. We swap |
| 827 | * the endpoint descriptors here so that the the first and |
| 828 | * only registered port structure uses the serial-port |
| 829 | * endpoints. |
| 830 | */ |
| 831 | swap(epds->bulk_in[0], epds->bulk_in[1]); |
| 832 | swap(epds->bulk_out[0], epds->bulk_out[1]); |
| 833 | |
Mike Dunn | fb088e3 | 2010-01-26 12:12:12 -0500 | [diff] [blame] | 834 | return 1; |
Johan Hovold | d760557 | 2017-03-16 17:13:45 +0100 | [diff] [blame] | 835 | } |
Mike Dunn | fb088e3 | 2010-01-26 12:12:12 -0500 | [diff] [blame] | 836 | |
| 837 | return 2; |
| 838 | } |
| 839 | |
Alan Cox | a509a7e | 2009-09-19 13:13:26 -0700 | [diff] [blame] | 840 | static int mos7720_open(struct tty_struct *tty, struct usb_serial_port *port) |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 841 | { |
| 842 | struct usb_serial *serial; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 843 | struct urb *urb; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 844 | struct moschip_port *mos7720_port; |
| 845 | int response; |
| 846 | int port_number; |
Mike Dunn | 63b9176 | 2010-04-15 17:02:09 -0400 | [diff] [blame] | 847 | __u8 data; |
Oliver Neukum | fe4b65e | 2007-03-14 15:22:25 +0100 | [diff] [blame] | 848 | int allocated_urbs = 0; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 849 | int j; |
| 850 | |
| 851 | serial = port->serial; |
| 852 | |
| 853 | mos7720_port = usb_get_serial_port_data(port); |
| 854 | if (mos7720_port == NULL) |
| 855 | return -ENODEV; |
| 856 | |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 857 | usb_clear_halt(serial->dev, port->write_urb->pipe); |
| 858 | usb_clear_halt(serial->dev, port->read_urb->pipe); |
| 859 | |
| 860 | /* Initialising the write urb pool */ |
| 861 | for (j = 0; j < NUM_URBS; ++j) { |
Alan Cox | 4da1a17 | 2008-07-22 11:16:21 +0100 | [diff] [blame] | 862 | urb = usb_alloc_urb(0, GFP_KERNEL); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 863 | mos7720_port->write_urb_pool[j] = urb; |
Johan Hovold | 10c642d | 2013-12-29 19:22:56 +0100 | [diff] [blame] | 864 | if (!urb) |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 865 | continue; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 866 | |
| 867 | urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE, |
| 868 | GFP_KERNEL); |
| 869 | if (!urb->transfer_buffer) { |
Oliver Neukum | fe4b65e | 2007-03-14 15:22:25 +0100 | [diff] [blame] | 870 | usb_free_urb(mos7720_port->write_urb_pool[j]); |
| 871 | mos7720_port->write_urb_pool[j] = NULL; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 872 | continue; |
| 873 | } |
Oliver Neukum | fe4b65e | 2007-03-14 15:22:25 +0100 | [diff] [blame] | 874 | allocated_urbs++; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 875 | } |
| 876 | |
Oliver Neukum | fe4b65e | 2007-03-14 15:22:25 +0100 | [diff] [blame] | 877 | if (!allocated_urbs) |
| 878 | return -ENOMEM; |
| 879 | |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 880 | /* Initialize MCS7720 -- Write Init values to corresponding Registers |
| 881 | * |
| 882 | * Register Index |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 883 | * 0 : MOS7720_THR/MOS7720_RHR |
| 884 | * 1 : MOS7720_IER |
| 885 | * 2 : MOS7720_FCR |
| 886 | * 3 : MOS7720_LCR |
| 887 | * 4 : MOS7720_MCR |
| 888 | * 5 : MOS7720_LSR |
| 889 | * 6 : MOS7720_MSR |
| 890 | * 7 : MOS7720_SPR |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 891 | * |
| 892 | * 0x08 : SP1/2 Control Reg |
| 893 | */ |
Greg Kroah-Hartman | 1143832 | 2013-06-06 10:32:00 -0700 | [diff] [blame] | 894 | port_number = port->port_number; |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 895 | read_mos_reg(serial, port_number, MOS7720_LSR, &data); |
Mike Dunn | 63b9176 | 2010-04-15 17:02:09 -0400 | [diff] [blame] | 896 | |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 897 | dev_dbg(&port->dev, "SS::%p LSR:%x\n", mos7720_port, data); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 898 | |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 899 | write_mos_reg(serial, dummy, MOS7720_SP1_REG, 0x02); |
| 900 | write_mos_reg(serial, dummy, MOS7720_SP2_REG, 0x02); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 901 | |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 902 | write_mos_reg(serial, port_number, MOS7720_IER, 0x00); |
| 903 | write_mos_reg(serial, port_number, MOS7720_FCR, 0x00); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 904 | |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 905 | write_mos_reg(serial, port_number, MOS7720_FCR, 0xcf); |
Mike Dunn | 63b9176 | 2010-04-15 17:02:09 -0400 | [diff] [blame] | 906 | mos7720_port->shadowLCR = 0x03; |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 907 | write_mos_reg(serial, port_number, MOS7720_LCR, |
| 908 | mos7720_port->shadowLCR); |
Mike Dunn | 63b9176 | 2010-04-15 17:02:09 -0400 | [diff] [blame] | 909 | mos7720_port->shadowMCR = 0x0b; |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 910 | write_mos_reg(serial, port_number, MOS7720_MCR, |
| 911 | mos7720_port->shadowMCR); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 912 | |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 913 | write_mos_reg(serial, port_number, MOS7720_SP_CONTROL_REG, 0x00); |
| 914 | read_mos_reg(serial, dummy, MOS7720_SP_CONTROL_REG, &data); |
Greg Kroah-Hartman | 1143832 | 2013-06-06 10:32:00 -0700 | [diff] [blame] | 915 | data = data | (port->port_number + 1); |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 916 | write_mos_reg(serial, dummy, MOS7720_SP_CONTROL_REG, data); |
Mike Dunn | 63b9176 | 2010-04-15 17:02:09 -0400 | [diff] [blame] | 917 | mos7720_port->shadowLCR = 0x83; |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 918 | write_mos_reg(serial, port_number, MOS7720_LCR, |
| 919 | mos7720_port->shadowLCR); |
| 920 | write_mos_reg(serial, port_number, MOS7720_THR, 0x0c); |
| 921 | write_mos_reg(serial, port_number, MOS7720_IER, 0x00); |
Mike Dunn | 63b9176 | 2010-04-15 17:02:09 -0400 | [diff] [blame] | 922 | mos7720_port->shadowLCR = 0x03; |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 923 | write_mos_reg(serial, port_number, MOS7720_LCR, |
| 924 | mos7720_port->shadowLCR); |
| 925 | write_mos_reg(serial, port_number, MOS7720_IER, 0x0c); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 926 | |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 927 | response = usb_submit_urb(port->read_urb, GFP_KERNEL); |
| 928 | if (response) |
Alan Cox | 4da1a17 | 2008-07-22 11:16:21 +0100 | [diff] [blame] | 929 | dev_err(&port->dev, "%s - Error %d submitting read urb\n", |
| 930 | __func__, response); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 931 | |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 932 | /* initialize our port settings */ |
| 933 | mos7720_port->shadowMCR = UART_MCR_OUT2; /* Must set to enable ints! */ |
| 934 | |
| 935 | /* send a open port command */ |
| 936 | mos7720_port->open = 1; |
| 937 | |
| 938 | return 0; |
| 939 | } |
| 940 | |
| 941 | /* |
| 942 | * mos7720_chars_in_buffer |
| 943 | * this function is called by the tty driver when it wants to know how many |
| 944 | * bytes of data we currently have outstanding in the port (data that has |
| 945 | * been written, but hasn't made it out the port yet) |
| 946 | * If successful, we return the number of bytes left to be written in the |
| 947 | * system, |
| 948 | * Otherwise we return a negative error number. |
| 949 | */ |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 950 | static int mos7720_chars_in_buffer(struct tty_struct *tty) |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 951 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 952 | struct usb_serial_port *port = tty->driver_data; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 953 | int i; |
| 954 | int chars = 0; |
| 955 | struct moschip_port *mos7720_port; |
| 956 | |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 957 | mos7720_port = usb_get_serial_port_data(port); |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 958 | if (mos7720_port == NULL) |
Alan Cox | 23198fd | 2009-07-20 16:05:27 +0100 | [diff] [blame] | 959 | return 0; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 960 | |
| 961 | for (i = 0; i < NUM_URBS; ++i) { |
Alan Cox | 4da1a17 | 2008-07-22 11:16:21 +0100 | [diff] [blame] | 962 | if (mos7720_port->write_urb_pool[i] && |
| 963 | mos7720_port->write_urb_pool[i]->status == -EINPROGRESS) |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 964 | chars += URB_TRANSFER_BUFFER_SIZE; |
| 965 | } |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 966 | dev_dbg(&port->dev, "%s - returns %d\n", __func__, chars); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 967 | return chars; |
| 968 | } |
| 969 | |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 970 | static void mos7720_close(struct usb_serial_port *port) |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 971 | { |
| 972 | struct usb_serial *serial; |
| 973 | struct moschip_port *mos7720_port; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 974 | int j; |
| 975 | |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 976 | serial = port->serial; |
| 977 | |
| 978 | mos7720_port = usb_get_serial_port_data(port); |
| 979 | if (mos7720_port == NULL) |
| 980 | return; |
| 981 | |
| 982 | for (j = 0; j < NUM_URBS; ++j) |
| 983 | usb_kill_urb(mos7720_port->write_urb_pool[j]); |
| 984 | |
| 985 | /* Freeing Write URBs */ |
| 986 | for (j = 0; j < NUM_URBS; ++j) { |
| 987 | if (mos7720_port->write_urb_pool[j]) { |
| 988 | kfree(mos7720_port->write_urb_pool[j]->transfer_buffer); |
| 989 | usb_free_urb(mos7720_port->write_urb_pool[j]); |
| 990 | } |
| 991 | } |
| 992 | |
| 993 | /* While closing port, shutdown all bulk read, write * |
Oliver Neukum | a1cd7e9 | 2008-01-16 17:18:52 +0100 | [diff] [blame] | 994 | * and interrupt read if they exists, otherwise nop */ |
Oliver Neukum | a1cd7e9 | 2008-01-16 17:18:52 +0100 | [diff] [blame] | 995 | usb_kill_urb(port->write_urb); |
Oliver Neukum | a1cd7e9 | 2008-01-16 17:18:52 +0100 | [diff] [blame] | 996 | usb_kill_urb(port->read_urb); |
| 997 | |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 998 | write_mos_reg(serial, port->port_number, MOS7720_MCR, 0x00); |
| 999 | write_mos_reg(serial, port->port_number, MOS7720_IER, 0x00); |
Johan Hovold | cf41aa9 | 2013-03-21 12:37:41 +0100 | [diff] [blame] | 1000 | |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1001 | mos7720_port->open = 0; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1002 | } |
| 1003 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1004 | static void mos7720_break(struct tty_struct *tty, int break_state) |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1005 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1006 | struct usb_serial_port *port = tty->driver_data; |
Alan Cox | 4da1a17 | 2008-07-22 11:16:21 +0100 | [diff] [blame] | 1007 | unsigned char data; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1008 | struct usb_serial *serial; |
| 1009 | struct moschip_port *mos7720_port; |
| 1010 | |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1011 | serial = port->serial; |
| 1012 | |
| 1013 | mos7720_port = usb_get_serial_port_data(port); |
| 1014 | if (mos7720_port == NULL) |
| 1015 | return; |
| 1016 | |
| 1017 | if (break_state == -1) |
| 1018 | data = mos7720_port->shadowLCR | UART_LCR_SBC; |
| 1019 | else |
| 1020 | data = mos7720_port->shadowLCR & ~UART_LCR_SBC; |
| 1021 | |
| 1022 | mos7720_port->shadowLCR = data; |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 1023 | write_mos_reg(serial, port->port_number, MOS7720_LCR, |
| 1024 | mos7720_port->shadowLCR); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | /* |
| 1028 | * mos7720_write_room |
| 1029 | * this function is called by the tty driver when it wants to know how many |
| 1030 | * bytes of data we can accept for a specific port. |
| 1031 | * If successful, we return the amount of room that we have for this port |
| 1032 | * Otherwise we return a negative error number. |
| 1033 | */ |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1034 | static int mos7720_write_room(struct tty_struct *tty) |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1035 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1036 | struct usb_serial_port *port = tty->driver_data; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1037 | struct moschip_port *mos7720_port; |
| 1038 | int room = 0; |
| 1039 | int i; |
| 1040 | |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1041 | mos7720_port = usb_get_serial_port_data(port); |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 1042 | if (mos7720_port == NULL) |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1043 | return -ENODEV; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1044 | |
Alan Cox | a5b6f60 | 2008-04-08 17:16:06 +0100 | [diff] [blame] | 1045 | /* FIXME: Locking */ |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1046 | for (i = 0; i < NUM_URBS; ++i) { |
Alan Cox | 4da1a17 | 2008-07-22 11:16:21 +0100 | [diff] [blame] | 1047 | if (mos7720_port->write_urb_pool[i] && |
| 1048 | mos7720_port->write_urb_pool[i]->status != -EINPROGRESS) |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1049 | room += URB_TRANSFER_BUFFER_SIZE; |
| 1050 | } |
| 1051 | |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 1052 | dev_dbg(&port->dev, "%s - returns %d\n", __func__, room); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1053 | return room; |
| 1054 | } |
| 1055 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1056 | static int mos7720_write(struct tty_struct *tty, struct usb_serial_port *port, |
| 1057 | const unsigned char *data, int count) |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1058 | { |
| 1059 | int status; |
| 1060 | int i; |
| 1061 | int bytes_sent = 0; |
| 1062 | int transfer_size; |
| 1063 | |
| 1064 | struct moschip_port *mos7720_port; |
| 1065 | struct usb_serial *serial; |
| 1066 | struct urb *urb; |
| 1067 | const unsigned char *current_position = data; |
| 1068 | |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1069 | serial = port->serial; |
| 1070 | |
| 1071 | mos7720_port = usb_get_serial_port_data(port); |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 1072 | if (mos7720_port == NULL) |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1073 | return -ENODEV; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1074 | |
| 1075 | /* try to find a free urb in the list */ |
| 1076 | urb = NULL; |
| 1077 | |
| 1078 | for (i = 0; i < NUM_URBS; ++i) { |
Alan Cox | 4da1a17 | 2008-07-22 11:16:21 +0100 | [diff] [blame] | 1079 | if (mos7720_port->write_urb_pool[i] && |
| 1080 | mos7720_port->write_urb_pool[i]->status != -EINPROGRESS) { |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1081 | urb = mos7720_port->write_urb_pool[i]; |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 1082 | dev_dbg(&port->dev, "URB:%d\n", i); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1083 | break; |
| 1084 | } |
| 1085 | } |
| 1086 | |
| 1087 | if (urb == NULL) { |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 1088 | dev_dbg(&port->dev, "%s - no more free urbs\n", __func__); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1089 | goto exit; |
| 1090 | } |
| 1091 | |
| 1092 | if (urb->transfer_buffer == NULL) { |
| 1093 | urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE, |
Alexey Khoroshilov | 5a5a1d6 | 2016-08-12 01:05:08 +0300 | [diff] [blame] | 1094 | GFP_ATOMIC); |
Johan Hovold | 10c642d | 2013-12-29 19:22:56 +0100 | [diff] [blame] | 1095 | if (!urb->transfer_buffer) |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1096 | goto exit; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1097 | } |
Alan Cox | 4da1a17 | 2008-07-22 11:16:21 +0100 | [diff] [blame] | 1098 | transfer_size = min(count, URB_TRANSFER_BUFFER_SIZE); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1099 | |
| 1100 | memcpy(urb->transfer_buffer, current_position, transfer_size); |
Greg Kroah-Hartman | 59d33f2 | 2012-09-18 09:58:57 +0100 | [diff] [blame] | 1101 | usb_serial_debug_data(&port->dev, __func__, transfer_size, |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1102 | urb->transfer_buffer); |
| 1103 | |
| 1104 | /* fill urb with data and submit */ |
| 1105 | usb_fill_bulk_urb(urb, serial->dev, |
| 1106 | usb_sndbulkpipe(serial->dev, |
Alan Cox | 4da1a17 | 2008-07-22 11:16:21 +0100 | [diff] [blame] | 1107 | port->bulk_out_endpointAddress), |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1108 | urb->transfer_buffer, transfer_size, |
| 1109 | mos7720_bulk_out_data_callback, mos7720_port); |
| 1110 | |
| 1111 | /* send it down the pipe */ |
Alan Cox | 4da1a17 | 2008-07-22 11:16:21 +0100 | [diff] [blame] | 1112 | status = usb_submit_urb(urb, GFP_ATOMIC); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1113 | if (status) { |
Johan Hovold | 22a416c | 2012-02-10 13:20:51 +0100 | [diff] [blame] | 1114 | dev_err_console(port, "%s - usb_submit_urb(write bulk) failed " |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 1115 | "with status = %d\n", __func__, status); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1116 | bytes_sent = status; |
| 1117 | goto exit; |
| 1118 | } |
| 1119 | bytes_sent = transfer_size; |
| 1120 | |
| 1121 | exit: |
| 1122 | return bytes_sent; |
| 1123 | } |
| 1124 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1125 | static void mos7720_throttle(struct tty_struct *tty) |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1126 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1127 | struct usb_serial_port *port = tty->driver_data; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1128 | struct moschip_port *mos7720_port; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1129 | int status; |
| 1130 | |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1131 | mos7720_port = usb_get_serial_port_data(port); |
| 1132 | |
| 1133 | if (mos7720_port == NULL) |
| 1134 | return; |
| 1135 | |
| 1136 | if (!mos7720_port->open) { |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 1137 | dev_dbg(&port->dev, "%s - port not opened\n", __func__); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1138 | return; |
| 1139 | } |
| 1140 | |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1141 | /* if we are implementing XON/XOFF, send the stop character */ |
| 1142 | if (I_IXOFF(tty)) { |
| 1143 | unsigned char stop_char = STOP_CHAR(tty); |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1144 | status = mos7720_write(tty, port, &stop_char, 1); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1145 | if (status <= 0) |
| 1146 | return; |
| 1147 | } |
| 1148 | |
| 1149 | /* if we are implementing RTS/CTS, toggle that line */ |
Peter Hurley | 9db276f | 2016-01-10 20:36:15 -0800 | [diff] [blame] | 1150 | if (C_CRTSCTS(tty)) { |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1151 | mos7720_port->shadowMCR &= ~UART_MCR_RTS; |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 1152 | write_mos_reg(port->serial, port->port_number, MOS7720_MCR, |
Greg Kroah-Hartman | 1143832 | 2013-06-06 10:32:00 -0700 | [diff] [blame] | 1153 | mos7720_port->shadowMCR); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1154 | } |
| 1155 | } |
| 1156 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1157 | static void mos7720_unthrottle(struct tty_struct *tty) |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1158 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1159 | struct usb_serial_port *port = tty->driver_data; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1160 | struct moschip_port *mos7720_port = usb_get_serial_port_data(port); |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1161 | int status; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1162 | |
| 1163 | if (mos7720_port == NULL) |
| 1164 | return; |
| 1165 | |
| 1166 | if (!mos7720_port->open) { |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 1167 | dev_dbg(&port->dev, "%s - port not opened\n", __func__); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1168 | return; |
| 1169 | } |
| 1170 | |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1171 | /* if we are implementing XON/XOFF, send the start character */ |
| 1172 | if (I_IXOFF(tty)) { |
| 1173 | unsigned char start_char = START_CHAR(tty); |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1174 | status = mos7720_write(tty, port, &start_char, 1); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1175 | if (status <= 0) |
| 1176 | return; |
| 1177 | } |
| 1178 | |
| 1179 | /* if we are implementing RTS/CTS, toggle that line */ |
Peter Hurley | 9db276f | 2016-01-10 20:36:15 -0800 | [diff] [blame] | 1180 | if (C_CRTSCTS(tty)) { |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1181 | mos7720_port->shadowMCR |= UART_MCR_RTS; |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 1182 | write_mos_reg(port->serial, port->port_number, MOS7720_MCR, |
Greg Kroah-Hartman | 1143832 | 2013-06-06 10:32:00 -0700 | [diff] [blame] | 1183 | mos7720_port->shadowMCR); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1184 | } |
| 1185 | } |
| 1186 | |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 1187 | /* FIXME: this function does not work */ |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1188 | static int set_higher_rates(struct moschip_port *mos7720_port, |
| 1189 | unsigned int baud) |
| 1190 | { |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1191 | struct usb_serial_port *port; |
| 1192 | struct usb_serial *serial; |
| 1193 | int port_number; |
Mike Dunn | 63b9176 | 2010-04-15 17:02:09 -0400 | [diff] [blame] | 1194 | enum mos_regs sp_reg; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1195 | if (mos7720_port == NULL) |
| 1196 | return -EINVAL; |
| 1197 | |
| 1198 | port = mos7720_port->port; |
| 1199 | serial = port->serial; |
| 1200 | |
Alan Cox | 4da1a17 | 2008-07-22 11:16:21 +0100 | [diff] [blame] | 1201 | /*********************************************** |
| 1202 | * Init Sequence for higher rates |
| 1203 | ***********************************************/ |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 1204 | dev_dbg(&port->dev, "Sending Setting Commands ..........\n"); |
Greg Kroah-Hartman | 1143832 | 2013-06-06 10:32:00 -0700 | [diff] [blame] | 1205 | port_number = port->port_number; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1206 | |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 1207 | write_mos_reg(serial, port_number, MOS7720_IER, 0x00); |
| 1208 | write_mos_reg(serial, port_number, MOS7720_FCR, 0x00); |
| 1209 | write_mos_reg(serial, port_number, MOS7720_FCR, 0xcf); |
Mike Dunn | 63b9176 | 2010-04-15 17:02:09 -0400 | [diff] [blame] | 1210 | mos7720_port->shadowMCR = 0x0b; |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 1211 | write_mos_reg(serial, port_number, MOS7720_MCR, |
| 1212 | mos7720_port->shadowMCR); |
| 1213 | write_mos_reg(serial, dummy, MOS7720_SP_CONTROL_REG, 0x00); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1214 | |
Alan Cox | 4da1a17 | 2008-07-22 11:16:21 +0100 | [diff] [blame] | 1215 | /*********************************************** |
| 1216 | * Set for higher rates * |
| 1217 | ***********************************************/ |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 1218 | /* writing baud rate verbatum into uart clock field clearly not right */ |
Mike Dunn | 63b9176 | 2010-04-15 17:02:09 -0400 | [diff] [blame] | 1219 | if (port_number == 0) |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 1220 | sp_reg = MOS7720_SP1_REG; |
Mike Dunn | 63b9176 | 2010-04-15 17:02:09 -0400 | [diff] [blame] | 1221 | else |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 1222 | sp_reg = MOS7720_SP2_REG; |
Mike Dunn | 63b9176 | 2010-04-15 17:02:09 -0400 | [diff] [blame] | 1223 | write_mos_reg(serial, dummy, sp_reg, baud * 0x10); |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 1224 | write_mos_reg(serial, dummy, MOS7720_SP_CONTROL_REG, 0x03); |
Mike Dunn | 63b9176 | 2010-04-15 17:02:09 -0400 | [diff] [blame] | 1225 | mos7720_port->shadowMCR = 0x2b; |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 1226 | write_mos_reg(serial, port_number, MOS7720_MCR, |
| 1227 | mos7720_port->shadowMCR); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1228 | |
Alan Cox | 4da1a17 | 2008-07-22 11:16:21 +0100 | [diff] [blame] | 1229 | /*********************************************** |
| 1230 | * Set DLL/DLM |
| 1231 | ***********************************************/ |
Mike Dunn | 63b9176 | 2010-04-15 17:02:09 -0400 | [diff] [blame] | 1232 | mos7720_port->shadowLCR = mos7720_port->shadowLCR | UART_LCR_DLAB; |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 1233 | write_mos_reg(serial, port_number, MOS7720_LCR, |
| 1234 | mos7720_port->shadowLCR); |
| 1235 | write_mos_reg(serial, port_number, MOS7720_DLL, 0x01); |
| 1236 | write_mos_reg(serial, port_number, MOS7720_DLM, 0x00); |
Mike Dunn | 63b9176 | 2010-04-15 17:02:09 -0400 | [diff] [blame] | 1237 | mos7720_port->shadowLCR = mos7720_port->shadowLCR & ~UART_LCR_DLAB; |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 1238 | write_mos_reg(serial, port_number, MOS7720_LCR, |
| 1239 | mos7720_port->shadowLCR); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1240 | |
| 1241 | return 0; |
| 1242 | } |
| 1243 | |
| 1244 | /* baud rate information */ |
Alan Cox | 4da1a17 | 2008-07-22 11:16:21 +0100 | [diff] [blame] | 1245 | struct divisor_table_entry { |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1246 | __u32 baudrate; |
| 1247 | __u16 divisor; |
| 1248 | }; |
| 1249 | |
| 1250 | /* Define table of divisors for moschip 7720 hardware * |
| 1251 | * These assume a 3.6864MHz crystal, the standard /16, and * |
| 1252 | * MCR.7 = 0. */ |
Johan Hovold | 4f37fa5 | 2017-04-18 14:42:28 +0200 | [diff] [blame] | 1253 | static const struct divisor_table_entry divisor_table[] = { |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1254 | { 50, 2304}, |
| 1255 | { 110, 1047}, /* 2094.545455 => 230450 => .0217 % over */ |
| 1256 | { 134, 857}, /* 1713.011152 => 230398.5 => .00065% under */ |
| 1257 | { 150, 768}, |
| 1258 | { 300, 384}, |
| 1259 | { 600, 192}, |
| 1260 | { 1200, 96}, |
| 1261 | { 1800, 64}, |
| 1262 | { 2400, 48}, |
| 1263 | { 4800, 24}, |
| 1264 | { 7200, 16}, |
| 1265 | { 9600, 12}, |
| 1266 | { 19200, 6}, |
| 1267 | { 38400, 3}, |
| 1268 | { 57600, 2}, |
| 1269 | { 115200, 1}, |
| 1270 | }; |
| 1271 | |
| 1272 | /***************************************************************************** |
| 1273 | * calc_baud_rate_divisor |
| 1274 | * this function calculates the proper baud rate divisor for the specified |
| 1275 | * baud rate. |
| 1276 | *****************************************************************************/ |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 1277 | static int calc_baud_rate_divisor(struct usb_serial_port *port, int baudrate, int *divisor) |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1278 | { |
| 1279 | int i; |
| 1280 | __u16 custom; |
| 1281 | __u16 round1; |
| 1282 | __u16 round; |
| 1283 | |
| 1284 | |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 1285 | dev_dbg(&port->dev, "%s - %d\n", __func__, baudrate); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1286 | |
| 1287 | for (i = 0; i < ARRAY_SIZE(divisor_table); i++) { |
| 1288 | if (divisor_table[i].baudrate == baudrate) { |
| 1289 | *divisor = divisor_table[i].divisor; |
| 1290 | return 0; |
| 1291 | } |
| 1292 | } |
| 1293 | |
Alan Cox | 4da1a17 | 2008-07-22 11:16:21 +0100 | [diff] [blame] | 1294 | /* After trying for all the standard baud rates * |
| 1295 | * Try calculating the divisor for this baud rate */ |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1296 | if (baudrate > 75 && baudrate < 230400) { |
| 1297 | /* get the divisor */ |
| 1298 | custom = (__u16)(230400L / baudrate); |
| 1299 | |
| 1300 | /* Check for round off */ |
| 1301 | round1 = (__u16)(2304000L / baudrate); |
| 1302 | round = (__u16)(round1 - (custom * 10)); |
| 1303 | if (round > 4) |
| 1304 | custom++; |
| 1305 | *divisor = custom; |
| 1306 | |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 1307 | dev_dbg(&port->dev, "Baud %d = %d\n", baudrate, custom); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1308 | return 0; |
| 1309 | } |
| 1310 | |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 1311 | dev_dbg(&port->dev, "Baud calculation Failed...\n"); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1312 | return -EINVAL; |
| 1313 | } |
| 1314 | |
| 1315 | /* |
| 1316 | * send_cmd_write_baud_rate |
| 1317 | * this function sends the proper command to change the baud rate of the |
| 1318 | * specified port. |
| 1319 | */ |
| 1320 | static int send_cmd_write_baud_rate(struct moschip_port *mos7720_port, |
| 1321 | int baudrate) |
| 1322 | { |
| 1323 | struct usb_serial_port *port; |
| 1324 | struct usb_serial *serial; |
| 1325 | int divisor; |
| 1326 | int status; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1327 | unsigned char number; |
| 1328 | |
| 1329 | if (mos7720_port == NULL) |
| 1330 | return -1; |
| 1331 | |
| 1332 | port = mos7720_port->port; |
| 1333 | serial = port->serial; |
| 1334 | |
Greg Kroah-Hartman | 1143832 | 2013-06-06 10:32:00 -0700 | [diff] [blame] | 1335 | number = port->port_number; |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 1336 | dev_dbg(&port->dev, "%s - baud = %d\n", __func__, baudrate); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1337 | |
Alan Cox | 4da1a17 | 2008-07-22 11:16:21 +0100 | [diff] [blame] | 1338 | /* Calculate the Divisor */ |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 1339 | status = calc_baud_rate_divisor(port, baudrate, &divisor); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1340 | if (status) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 1341 | dev_err(&port->dev, "%s - bad baud rate\n", __func__); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1342 | return status; |
| 1343 | } |
| 1344 | |
Alan Cox | 4da1a17 | 2008-07-22 11:16:21 +0100 | [diff] [blame] | 1345 | /* Enable access to divisor latch */ |
Mike Dunn | 63b9176 | 2010-04-15 17:02:09 -0400 | [diff] [blame] | 1346 | mos7720_port->shadowLCR = mos7720_port->shadowLCR | UART_LCR_DLAB; |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 1347 | write_mos_reg(serial, number, MOS7720_LCR, mos7720_port->shadowLCR); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1348 | |
| 1349 | /* Write the divisor */ |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 1350 | write_mos_reg(serial, number, MOS7720_DLL, (__u8)(divisor & 0xff)); |
| 1351 | write_mos_reg(serial, number, MOS7720_DLM, |
| 1352 | (__u8)((divisor & 0xff00) >> 8)); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1353 | |
Alan Cox | 4da1a17 | 2008-07-22 11:16:21 +0100 | [diff] [blame] | 1354 | /* Disable access to divisor latch */ |
Mike Dunn | 63b9176 | 2010-04-15 17:02:09 -0400 | [diff] [blame] | 1355 | mos7720_port->shadowLCR = mos7720_port->shadowLCR & ~UART_LCR_DLAB; |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 1356 | write_mos_reg(serial, number, MOS7720_LCR, mos7720_port->shadowLCR); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1357 | |
| 1358 | return status; |
| 1359 | } |
| 1360 | |
| 1361 | /* |
| 1362 | * change_port_settings |
| 1363 | * This routine is called to set the UART on the device to match |
| 1364 | * the specified new settings. |
| 1365 | */ |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1366 | static void change_port_settings(struct tty_struct *tty, |
| 1367 | struct moschip_port *mos7720_port, |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 1368 | struct ktermios *old_termios) |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1369 | { |
| 1370 | struct usb_serial_port *port; |
| 1371 | struct usb_serial *serial; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1372 | int baud; |
| 1373 | unsigned cflag; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1374 | __u8 lData; |
| 1375 | __u8 lParity; |
| 1376 | __u8 lStop; |
| 1377 | int status; |
| 1378 | int port_number; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1379 | |
| 1380 | if (mos7720_port == NULL) |
| 1381 | return ; |
| 1382 | |
| 1383 | port = mos7720_port->port; |
| 1384 | serial = port->serial; |
Greg Kroah-Hartman | 1143832 | 2013-06-06 10:32:00 -0700 | [diff] [blame] | 1385 | port_number = port->port_number; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1386 | |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1387 | if (!mos7720_port->open) { |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 1388 | dev_dbg(&port->dev, "%s - port not opened\n", __func__); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1389 | return; |
| 1390 | } |
| 1391 | |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1392 | lData = UART_LCR_WLEN8; |
| 1393 | lStop = 0x00; /* 1 stop bit */ |
| 1394 | lParity = 0x00; /* No parity */ |
| 1395 | |
Alan Cox | adc8d74 | 2012-07-14 15:31:47 +0100 | [diff] [blame] | 1396 | cflag = tty->termios.c_cflag; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1397 | |
| 1398 | /* Change the number of bits */ |
| 1399 | switch (cflag & CSIZE) { |
| 1400 | case CS5: |
| 1401 | lData = UART_LCR_WLEN5; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1402 | break; |
| 1403 | |
| 1404 | case CS6: |
| 1405 | lData = UART_LCR_WLEN6; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1406 | break; |
| 1407 | |
| 1408 | case CS7: |
| 1409 | lData = UART_LCR_WLEN7; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1410 | break; |
| 1411 | default: |
| 1412 | case CS8: |
| 1413 | lData = UART_LCR_WLEN8; |
| 1414 | break; |
| 1415 | } |
| 1416 | |
| 1417 | /* Change the Parity bit */ |
| 1418 | if (cflag & PARENB) { |
| 1419 | if (cflag & PARODD) { |
| 1420 | lParity = UART_LCR_PARITY; |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 1421 | dev_dbg(&port->dev, "%s - parity = odd\n", __func__); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1422 | } else { |
| 1423 | lParity = (UART_LCR_EPAR | UART_LCR_PARITY); |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 1424 | dev_dbg(&port->dev, "%s - parity = even\n", __func__); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1425 | } |
| 1426 | |
| 1427 | } else { |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 1428 | dev_dbg(&port->dev, "%s - parity = none\n", __func__); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1429 | } |
| 1430 | |
| 1431 | if (cflag & CMSPAR) |
| 1432 | lParity = lParity | 0x20; |
| 1433 | |
| 1434 | /* Change the Stop bit */ |
| 1435 | if (cflag & CSTOPB) { |
| 1436 | lStop = UART_LCR_STOP; |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 1437 | dev_dbg(&port->dev, "%s - stop bits = 2\n", __func__); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1438 | } else { |
| 1439 | lStop = 0x00; |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 1440 | dev_dbg(&port->dev, "%s - stop bits = 1\n", __func__); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1441 | } |
| 1442 | |
| 1443 | #define LCR_BITS_MASK 0x03 /* Mask for bits/char field */ |
| 1444 | #define LCR_STOP_MASK 0x04 /* Mask for stop bits field */ |
| 1445 | #define LCR_PAR_MASK 0x38 /* Mask for parity field */ |
| 1446 | |
| 1447 | /* Update the LCR with the correct value */ |
Alan Cox | 4da1a17 | 2008-07-22 11:16:21 +0100 | [diff] [blame] | 1448 | mos7720_port->shadowLCR &= |
Mike Dunn | 63b9176 | 2010-04-15 17:02:09 -0400 | [diff] [blame] | 1449 | ~(LCR_BITS_MASK | LCR_STOP_MASK | LCR_PAR_MASK); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1450 | mos7720_port->shadowLCR |= (lData | lParity | lStop); |
| 1451 | |
| 1452 | |
| 1453 | /* Disable Interrupts */ |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 1454 | write_mos_reg(serial, port_number, MOS7720_IER, 0x00); |
| 1455 | write_mos_reg(serial, port_number, MOS7720_FCR, 0x00); |
| 1456 | write_mos_reg(serial, port_number, MOS7720_FCR, 0xcf); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1457 | |
| 1458 | /* Send the updated LCR value to the mos7720 */ |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 1459 | write_mos_reg(serial, port_number, MOS7720_LCR, |
| 1460 | mos7720_port->shadowLCR); |
Mike Dunn | 63b9176 | 2010-04-15 17:02:09 -0400 | [diff] [blame] | 1461 | mos7720_port->shadowMCR = 0x0b; |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 1462 | write_mos_reg(serial, port_number, MOS7720_MCR, |
| 1463 | mos7720_port->shadowMCR); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1464 | |
| 1465 | /* set up the MCR register and send it to the mos7720 */ |
| 1466 | mos7720_port->shadowMCR = UART_MCR_OUT2; |
| 1467 | if (cflag & CBAUD) |
| 1468 | mos7720_port->shadowMCR |= (UART_MCR_DTR | UART_MCR_RTS); |
| 1469 | |
| 1470 | if (cflag & CRTSCTS) { |
| 1471 | mos7720_port->shadowMCR |= (UART_MCR_XONANY); |
Alan Cox | 4da1a17 | 2008-07-22 11:16:21 +0100 | [diff] [blame] | 1472 | /* To set hardware flow control to the specified * |
| 1473 | * serial port, in SP1/2_CONTROL_REG */ |
Johan Hovold | a26f009 | 2013-06-04 18:50:31 +0200 | [diff] [blame] | 1474 | if (port_number) |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 1475 | write_mos_reg(serial, dummy, MOS7720_SP_CONTROL_REG, |
| 1476 | 0x01); |
Mike Dunn | 63b9176 | 2010-04-15 17:02:09 -0400 | [diff] [blame] | 1477 | else |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 1478 | write_mos_reg(serial, dummy, MOS7720_SP_CONTROL_REG, |
| 1479 | 0x02); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1480 | |
Mike Dunn | 63b9176 | 2010-04-15 17:02:09 -0400 | [diff] [blame] | 1481 | } else |
| 1482 | mos7720_port->shadowMCR &= ~(UART_MCR_XONANY); |
| 1483 | |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 1484 | write_mos_reg(serial, port_number, MOS7720_MCR, |
| 1485 | mos7720_port->shadowMCR); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1486 | |
| 1487 | /* Determine divisor based on baud rate */ |
| 1488 | baud = tty_get_baud_rate(tty); |
| 1489 | if (!baud) { |
| 1490 | /* pick a default, any default... */ |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 1491 | dev_dbg(&port->dev, "Picked default baud...\n"); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1492 | baud = 9600; |
| 1493 | } |
| 1494 | |
| 1495 | if (baud >= 230400) { |
| 1496 | set_higher_rates(mos7720_port, baud); |
| 1497 | /* Enable Interrupts */ |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 1498 | write_mos_reg(serial, port_number, MOS7720_IER, 0x0c); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1499 | return; |
| 1500 | } |
| 1501 | |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 1502 | dev_dbg(&port->dev, "%s - baud rate = %d\n", __func__, baud); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1503 | status = send_cmd_write_baud_rate(mos7720_port, baud); |
Alan Cox | 65d063ab | 2008-01-03 17:01:18 +0000 | [diff] [blame] | 1504 | /* FIXME: needs to write actual resulting baud back not just |
| 1505 | blindly do so */ |
| 1506 | if (cflag & CBAUD) |
| 1507 | tty_encode_baud_rate(tty, baud, baud); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1508 | /* Enable Interrupts */ |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 1509 | write_mos_reg(serial, port_number, MOS7720_IER, 0x0c); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1510 | |
| 1511 | if (port->read_urb->status != -EINPROGRESS) { |
Johan Hovold | 1dbd11b | 2014-10-29 09:07:33 +0100 | [diff] [blame] | 1512 | status = usb_submit_urb(port->read_urb, GFP_KERNEL); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1513 | if (status) |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 1514 | dev_dbg(&port->dev, "usb_submit_urb(read bulk) failed, status = %d\n", status); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1515 | } |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1516 | } |
| 1517 | |
| 1518 | /* |
| 1519 | * mos7720_set_termios |
| 1520 | * this function is called by the tty driver when it wants to change the |
| 1521 | * termios structure. |
| 1522 | */ |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1523 | static void mos7720_set_termios(struct tty_struct *tty, |
| 1524 | struct usb_serial_port *port, struct ktermios *old_termios) |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1525 | { |
| 1526 | int status; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1527 | struct moschip_port *mos7720_port; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1528 | |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1529 | mos7720_port = usb_get_serial_port_data(port); |
| 1530 | |
| 1531 | if (mos7720_port == NULL) |
| 1532 | return; |
| 1533 | |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1534 | if (!mos7720_port->open) { |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 1535 | dev_dbg(&port->dev, "%s - port not opened\n", __func__); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1536 | return; |
| 1537 | } |
| 1538 | |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1539 | /* change the port settings to the new ones specified */ |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1540 | change_port_settings(tty, mos7720_port, old_termios); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1541 | |
Alan Cox | 4da1a17 | 2008-07-22 11:16:21 +0100 | [diff] [blame] | 1542 | if (port->read_urb->status != -EINPROGRESS) { |
Johan Hovold | 1dbd11b | 2014-10-29 09:07:33 +0100 | [diff] [blame] | 1543 | status = usb_submit_urb(port->read_urb, GFP_KERNEL); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1544 | if (status) |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 1545 | dev_dbg(&port->dev, "usb_submit_urb(read bulk) failed, status = %d\n", status); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1546 | } |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1547 | } |
| 1548 | |
| 1549 | /* |
| 1550 | * get_lsr_info - get line status register info |
| 1551 | * |
| 1552 | * Purpose: Let user call ioctl() to get info when the UART physically |
| 1553 | * is emptied. On bus types like RS485, the transmitter must |
| 1554 | * release the bus after transmitting. This must be done when |
| 1555 | * the transmit shift register is empty, not be done when the |
| 1556 | * transmit holding register is empty. This functionality |
| 1557 | * allows an RS485 driver to be written in user space. |
| 1558 | */ |
Alan Cox | 4da1a17 | 2008-07-22 11:16:21 +0100 | [diff] [blame] | 1559 | static int get_lsr_info(struct tty_struct *tty, |
| 1560 | struct moschip_port *mos7720_port, unsigned int __user *value) |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1561 | { |
Kees Schoenmakers | 2f9ea55 | 2009-09-19 13:13:18 -0700 | [diff] [blame] | 1562 | struct usb_serial_port *port = tty->driver_data; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1563 | unsigned int result = 0; |
Kees Schoenmakers | 2f9ea55 | 2009-09-19 13:13:18 -0700 | [diff] [blame] | 1564 | unsigned char data = 0; |
Greg Kroah-Hartman | 1143832 | 2013-06-06 10:32:00 -0700 | [diff] [blame] | 1565 | int port_number = port->port_number; |
Kees Schoenmakers | 2f9ea55 | 2009-09-19 13:13:18 -0700 | [diff] [blame] | 1566 | int count; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1567 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1568 | count = mos7720_chars_in_buffer(tty); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1569 | if (count == 0) { |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 1570 | read_mos_reg(port->serial, port_number, MOS7720_LSR, &data); |
Kees Schoenmakers | 2f9ea55 | 2009-09-19 13:13:18 -0700 | [diff] [blame] | 1571 | if ((data & (UART_LSR_TEMT | UART_LSR_THRE)) |
| 1572 | == (UART_LSR_TEMT | UART_LSR_THRE)) { |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 1573 | dev_dbg(&port->dev, "%s -- Empty\n", __func__); |
Kees Schoenmakers | 2f9ea55 | 2009-09-19 13:13:18 -0700 | [diff] [blame] | 1574 | result = TIOCSER_TEMT; |
| 1575 | } |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1576 | } |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1577 | if (copy_to_user(value, &result, sizeof(int))) |
| 1578 | return -EFAULT; |
| 1579 | return 0; |
| 1580 | } |
| 1581 | |
Alan Cox | 60b33c1 | 2011-02-14 16:26:14 +0000 | [diff] [blame] | 1582 | static int mos7720_tiocmget(struct tty_struct *tty) |
Kees Schoenmakers | 0f608f8 | 2009-09-19 13:13:18 -0700 | [diff] [blame] | 1583 | { |
| 1584 | struct usb_serial_port *port = tty->driver_data; |
| 1585 | struct moschip_port *mos7720_port = usb_get_serial_port_data(port); |
| 1586 | unsigned int result = 0; |
| 1587 | unsigned int mcr ; |
| 1588 | unsigned int msr ; |
| 1589 | |
Kees Schoenmakers | 0f608f8 | 2009-09-19 13:13:18 -0700 | [diff] [blame] | 1590 | mcr = mos7720_port->shadowMCR; |
| 1591 | msr = mos7720_port->shadowMSR; |
| 1592 | |
| 1593 | result = ((mcr & UART_MCR_DTR) ? TIOCM_DTR : 0) /* 0x002 */ |
| 1594 | | ((mcr & UART_MCR_RTS) ? TIOCM_RTS : 0) /* 0x004 */ |
| 1595 | | ((msr & UART_MSR_CTS) ? TIOCM_CTS : 0) /* 0x020 */ |
| 1596 | | ((msr & UART_MSR_DCD) ? TIOCM_CAR : 0) /* 0x040 */ |
| 1597 | | ((msr & UART_MSR_RI) ? TIOCM_RI : 0) /* 0x080 */ |
| 1598 | | ((msr & UART_MSR_DSR) ? TIOCM_DSR : 0); /* 0x100 */ |
| 1599 | |
Kees Schoenmakers | 0f608f8 | 2009-09-19 13:13:18 -0700 | [diff] [blame] | 1600 | return result; |
| 1601 | } |
| 1602 | |
Alan Cox | 20b9d17 | 2011-02-14 16:26:50 +0000 | [diff] [blame] | 1603 | static int mos7720_tiocmset(struct tty_struct *tty, |
Mike Dunn | 63b9176 | 2010-04-15 17:02:09 -0400 | [diff] [blame] | 1604 | unsigned int set, unsigned int clear) |
Kees Schoenmakers | 0f608f8 | 2009-09-19 13:13:18 -0700 | [diff] [blame] | 1605 | { |
| 1606 | struct usb_serial_port *port = tty->driver_data; |
| 1607 | struct moschip_port *mos7720_port = usb_get_serial_port_data(port); |
| 1608 | unsigned int mcr ; |
Kees Schoenmakers | 0f608f8 | 2009-09-19 13:13:18 -0700 | [diff] [blame] | 1609 | |
| 1610 | mcr = mos7720_port->shadowMCR; |
| 1611 | |
| 1612 | if (set & TIOCM_RTS) |
| 1613 | mcr |= UART_MCR_RTS; |
| 1614 | if (set & TIOCM_DTR) |
| 1615 | mcr |= UART_MCR_DTR; |
| 1616 | if (set & TIOCM_LOOP) |
| 1617 | mcr |= UART_MCR_LOOP; |
| 1618 | |
| 1619 | if (clear & TIOCM_RTS) |
| 1620 | mcr &= ~UART_MCR_RTS; |
| 1621 | if (clear & TIOCM_DTR) |
| 1622 | mcr &= ~UART_MCR_DTR; |
| 1623 | if (clear & TIOCM_LOOP) |
| 1624 | mcr &= ~UART_MCR_LOOP; |
| 1625 | |
| 1626 | mos7720_port->shadowMCR = mcr; |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 1627 | write_mos_reg(port->serial, port->port_number, MOS7720_MCR, |
Greg Kroah-Hartman | 1143832 | 2013-06-06 10:32:00 -0700 | [diff] [blame] | 1628 | mos7720_port->shadowMCR); |
Kees Schoenmakers | 0f608f8 | 2009-09-19 13:13:18 -0700 | [diff] [blame] | 1629 | |
| 1630 | return 0; |
| 1631 | } |
| 1632 | |
Al Viro | 7cf3e60 | 2018-09-12 00:20:17 -0400 | [diff] [blame] | 1633 | static int get_serial_info(struct tty_struct *tty, |
| 1634 | struct serial_struct *ss) |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1635 | { |
Al Viro | 7cf3e60 | 2018-09-12 00:20:17 -0400 | [diff] [blame] | 1636 | struct usb_serial_port *port = tty->driver_data; |
| 1637 | struct moschip_port *mos7720_port = usb_get_serial_port_data(port); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1638 | |
Al Viro | 7cf3e60 | 2018-09-12 00:20:17 -0400 | [diff] [blame] | 1639 | ss->type = PORT_16550A; |
| 1640 | ss->line = mos7720_port->port->minor; |
| 1641 | ss->port = mos7720_port->port->port_number; |
| 1642 | ss->irq = 0; |
| 1643 | ss->xmit_fifo_size = NUM_URBS * URB_TRANSFER_BUFFER_SIZE; |
| 1644 | ss->baud_base = 9600; |
| 1645 | ss->close_delay = 5*HZ; |
| 1646 | ss->closing_wait = 30*HZ; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1647 | return 0; |
| 1648 | } |
| 1649 | |
Alan Cox | 00a0d0d | 2011-02-14 16:27:06 +0000 | [diff] [blame] | 1650 | static int mos7720_ioctl(struct tty_struct *tty, |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1651 | unsigned int cmd, unsigned long arg) |
| 1652 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1653 | struct usb_serial_port *port = tty->driver_data; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1654 | struct moschip_port *mos7720_port; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1655 | |
| 1656 | mos7720_port = usb_get_serial_port_data(port); |
| 1657 | if (mos7720_port == NULL) |
| 1658 | return -ENODEV; |
| 1659 | |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1660 | switch (cmd) { |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1661 | case TIOCSERGETLSR: |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 1662 | dev_dbg(&port->dev, "%s TIOCSERGETLSR\n", __func__); |
Alan Cox | 4da1a17 | 2008-07-22 11:16:21 +0100 | [diff] [blame] | 1663 | return get_lsr_info(tty, mos7720_port, |
| 1664 | (unsigned int __user *)arg); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1665 | } |
| 1666 | |
| 1667 | return -ENOIOCTLCMD; |
| 1668 | } |
| 1669 | |
| 1670 | static int mos7720_startup(struct usb_serial *serial) |
| 1671 | { |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1672 | struct usb_device *dev; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1673 | char data; |
Huzaifa Sidhpurwala | 91f58ae | 2011-02-21 12:58:45 +0530 | [diff] [blame] | 1674 | u16 product; |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 1675 | int ret_val; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1676 | |
Huzaifa Sidhpurwala | 91f58ae | 2011-02-21 12:58:45 +0530 | [diff] [blame] | 1677 | product = le16_to_cpu(serial->dev->descriptor.idProduct); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1678 | dev = serial->dev; |
| 1679 | |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 1680 | if (product == MOSCHIP_DEVICE_ID_7715) { |
Johan Hovold | d760557 | 2017-03-16 17:13:45 +0100 | [diff] [blame] | 1681 | struct urb *urb = serial->port[0]->interrupt_in_urb; |
| 1682 | |
Johan Hovold | 6a1eaf1 | 2017-03-16 17:13:46 +0100 | [diff] [blame] | 1683 | urb->complete = mos7715_interrupt_callback; |
Johan Hovold | d760557 | 2017-03-16 17:13:45 +0100 | [diff] [blame] | 1684 | |
| 1685 | #ifdef CONFIG_USB_SERIAL_MOS7715_PARPORT |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 1686 | ret_val = mos7715_parport_init(serial); |
Johan Hovold | 75dd211 | 2017-01-03 16:39:52 +0100 | [diff] [blame] | 1687 | if (ret_val < 0) |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 1688 | return ret_val; |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 1689 | #endif |
Johan Hovold | d760557 | 2017-03-16 17:13:45 +0100 | [diff] [blame] | 1690 | } |
Johan Hovold | 75dd211 | 2017-01-03 16:39:52 +0100 | [diff] [blame] | 1691 | /* start the interrupt urb */ |
| 1692 | ret_val = usb_submit_urb(serial->port[0]->interrupt_in_urb, GFP_KERNEL); |
| 1693 | if (ret_val) { |
| 1694 | dev_err(&dev->dev, "failed to submit interrupt urb: %d\n", |
| 1695 | ret_val); |
| 1696 | } |
| 1697 | |
Alan Cox | 4da1a17 | 2008-07-22 11:16:21 +0100 | [diff] [blame] | 1698 | /* LSR For Port 1 */ |
Sudip Mukherjee | ee5729e | 2015-06-23 18:59:40 +0530 | [diff] [blame] | 1699 | read_mos_reg(serial, 0, MOS7720_LSR, &data); |
Greg Kroah-Hartman | 9eecf80 | 2012-09-14 15:08:33 -0700 | [diff] [blame] | 1700 | dev_dbg(&dev->dev, "LSR:%x\n", data); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1701 | |
| 1702 | return 0; |
| 1703 | } |
| 1704 | |
Alan Stern | f9c99bb | 2009-06-02 11:53:55 -0400 | [diff] [blame] | 1705 | static void mos7720_release(struct usb_serial *serial) |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1706 | { |
Johan Hovold | 91a1ff4 | 2017-01-03 16:39:51 +0100 | [diff] [blame] | 1707 | usb_kill_urb(serial->port[0]->interrupt_in_urb); |
| 1708 | |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 1709 | #ifdef CONFIG_USB_SERIAL_MOS7715_PARPORT |
| 1710 | /* close the parallel port */ |
| 1711 | |
| 1712 | if (le16_to_cpu(serial->dev->descriptor.idProduct) |
| 1713 | == MOSCHIP_DEVICE_ID_7715) { |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 1714 | struct mos7715_parport *mos_parport = |
| 1715 | usb_get_serial_data(serial); |
| 1716 | |
| 1717 | /* prevent NULL ptr dereference in port callbacks */ |
| 1718 | spin_lock(&release_lock); |
| 1719 | mos_parport->pp->private_data = NULL; |
| 1720 | spin_unlock(&release_lock); |
| 1721 | |
| 1722 | /* wait for synchronous usb calls to return */ |
| 1723 | if (mos_parport->msg_pending) |
| 1724 | wait_for_completion_timeout(&mos_parport->syncmsg_compl, |
Johan Hovold | 849513a | 2013-05-27 14:44:43 +0200 | [diff] [blame] | 1725 | msecs_to_jiffies(MOS_WDR_TIMEOUT)); |
Davidlohr Bueso | 053af9e | 2020-11-19 20:53:00 -0800 | [diff] [blame] | 1726 | /* |
| 1727 | * If delayed work is currently scheduled, wait for it to |
| 1728 | * complete. This also implies barriers that ensure the |
| 1729 | * below serial clearing is not hoisted above the ->work. |
| 1730 | */ |
| 1731 | cancel_work_sync(&mos_parport->work); |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 1732 | |
| 1733 | parport_remove_port(mos_parport->pp); |
| 1734 | usb_set_serial_data(serial, NULL); |
| 1735 | mos_parport->serial = NULL; |
| 1736 | |
Sudip Mukherjee | dcb21ad | 2016-05-30 19:16:33 +0530 | [diff] [blame] | 1737 | parport_del_port(mos_parport->pp); |
Mike Dunn | b69578d | 2010-04-15 17:01:33 -0400 | [diff] [blame] | 1738 | |
| 1739 | kref_put(&mos_parport->ref_count, destroy_mos_parport); |
| 1740 | } |
| 1741 | #endif |
Johan Hovold | 4230af5 | 2012-10-25 10:29:05 +0200 | [diff] [blame] | 1742 | } |
| 1743 | |
| 1744 | static int mos7720_port_probe(struct usb_serial_port *port) |
| 1745 | { |
| 1746 | struct moschip_port *mos7720_port; |
| 1747 | |
| 1748 | mos7720_port = kzalloc(sizeof(*mos7720_port), GFP_KERNEL); |
| 1749 | if (!mos7720_port) |
| 1750 | return -ENOMEM; |
| 1751 | |
Johan Hovold | 4230af5 | 2012-10-25 10:29:05 +0200 | [diff] [blame] | 1752 | mos7720_port->port = port; |
| 1753 | |
| 1754 | usb_set_serial_port_data(port, mos7720_port); |
| 1755 | |
| 1756 | return 0; |
| 1757 | } |
| 1758 | |
| 1759 | static int mos7720_port_remove(struct usb_serial_port *port) |
| 1760 | { |
| 1761 | struct moschip_port *mos7720_port; |
| 1762 | |
| 1763 | mos7720_port = usb_get_serial_port_data(port); |
| 1764 | kfree(mos7720_port); |
| 1765 | |
| 1766 | return 0; |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1767 | } |
| 1768 | |
| 1769 | static struct usb_serial_driver moschip7720_2port_driver = { |
| 1770 | .driver = { |
| 1771 | .owner = THIS_MODULE, |
| 1772 | .name = "moschip7720", |
| 1773 | }, |
| 1774 | .description = "Moschip 2 port adapter", |
Greg Kroah-Hartman | 68e2411 | 2012-05-08 15:46:14 -0700 | [diff] [blame] | 1775 | .id_table = id_table, |
Johan Hovold | 206ff83 | 2017-03-02 12:51:27 +0100 | [diff] [blame] | 1776 | .num_bulk_in = 2, |
| 1777 | .num_bulk_out = 2, |
Johan Hovold | 6a1eaf1 | 2017-03-16 17:13:46 +0100 | [diff] [blame] | 1778 | .num_interrupt_in = 1, |
Mike Dunn | fb088e3 | 2010-01-26 12:12:12 -0500 | [diff] [blame] | 1779 | .calc_num_ports = mos77xx_calc_num_ports, |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1780 | .open = mos7720_open, |
| 1781 | .close = mos7720_close, |
| 1782 | .throttle = mos7720_throttle, |
| 1783 | .unthrottle = mos7720_unthrottle, |
| 1784 | .attach = mos7720_startup, |
Alan Stern | f9c99bb | 2009-06-02 11:53:55 -0400 | [diff] [blame] | 1785 | .release = mos7720_release, |
Johan Hovold | 4230af5 | 2012-10-25 10:29:05 +0200 | [diff] [blame] | 1786 | .port_probe = mos7720_port_probe, |
| 1787 | .port_remove = mos7720_port_remove, |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1788 | .ioctl = mos7720_ioctl, |
Kees Schoenmakers | 0f608f8 | 2009-09-19 13:13:18 -0700 | [diff] [blame] | 1789 | .tiocmget = mos7720_tiocmget, |
| 1790 | .tiocmset = mos7720_tiocmset, |
Al Viro | 7cf3e60 | 2018-09-12 00:20:17 -0400 | [diff] [blame] | 1791 | .get_serial = get_serial_info, |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1792 | .set_termios = mos7720_set_termios, |
| 1793 | .write = mos7720_write, |
| 1794 | .write_room = mos7720_write_room, |
| 1795 | .chars_in_buffer = mos7720_chars_in_buffer, |
| 1796 | .break_ctl = mos7720_break, |
| 1797 | .read_bulk_callback = mos7720_bulk_in_callback, |
Johan Hovold | fde1faf | 2017-01-03 16:39:53 +0100 | [diff] [blame] | 1798 | .read_int_callback = mos7720_interrupt_callback, |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1799 | }; |
| 1800 | |
Alan Stern | 4d2a7af | 2012-02-23 14:57:09 -0500 | [diff] [blame] | 1801 | static struct usb_serial_driver * const serial_drivers[] = { |
| 1802 | &moschip7720_2port_driver, NULL |
| 1803 | }; |
| 1804 | |
Greg Kroah-Hartman | 68e2411 | 2012-05-08 15:46:14 -0700 | [diff] [blame] | 1805 | module_usb_serial_driver(serial_drivers, id_table); |
Greg Kroah-Hartman | 0f64478 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1806 | |
Alan Cox | 4da1a17 | 2008-07-22 11:16:21 +0100 | [diff] [blame] | 1807 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 1808 | MODULE_DESCRIPTION(DRIVER_DESC); |
Johan Hovold | 627cfa8 | 2017-11-03 18:12:08 +0100 | [diff] [blame] | 1809 | MODULE_LICENSE("GPL v2"); |