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