Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)   Keyspan USB to Serial Converter driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)   (C) Copyright (C) 2000-2001	Hugh Blemings <hugh@blemings.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)   (C) Copyright (C) 2002	Greg Kroah-Hartman <greg@kroah.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)   See http://blemings.org/hugh/keyspan.html for more information.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)   Code in this driver inspired by and in a number of places taken
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)   from Brian Warner's original Keyspan-PDA driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13)   This driver has been put together with the support of Innosys, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14)   and Keyspan, Inc the manufacturers of the Keyspan USB-serial products.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15)   Thanks Guys :)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17)   Thanks to Paulus for miscellaneous tidy ups, some largish chunks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18)   of much nicer and/or completely new code and (perhaps most uniquely)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19)   having the patience to sit down and explain why and where he'd changed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20)   stuff.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22)   Tip 'o the hat to IBM (and previously Linuxcare :) for supporting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23)   staff in their work on open source projects.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) #include <linux/tty.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #include <linux/tty_driver.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) #include <linux/tty_flip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) #include <linux/usb/serial.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) #include <linux/usb/ezusb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) #define DRIVER_AUTHOR "Hugh Blemings <hugh@misc.nu"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) #define DRIVER_DESC "Keyspan USB to Serial Converter Driver"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) /* Function prototypes for Keyspan serial converter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) static int keyspan_open(struct tty_struct *tty, struct usb_serial_port *port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) static void keyspan_close(struct usb_serial_port *port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) static void keyspan_dtr_rts(struct usb_serial_port *port, int on);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) static int keyspan_startup(struct usb_serial *serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) static void keyspan_disconnect(struct usb_serial *serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) static void keyspan_release(struct usb_serial *serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) static int keyspan_port_probe(struct usb_serial_port *port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) static int keyspan_port_remove(struct usb_serial_port *port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) static int keyspan_write_room(struct tty_struct *tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) static int keyspan_write(struct tty_struct *tty, struct usb_serial_port *port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) 			 const unsigned char *buf, int count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) static void keyspan_send_setup(struct usb_serial_port *port, int reset_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) static void keyspan_set_termios(struct tty_struct *tty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 				struct usb_serial_port *port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) 				struct ktermios *old);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) static void keyspan_break_ctl(struct tty_struct *tty, int break_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) static int keyspan_tiocmget(struct tty_struct *tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) static int keyspan_tiocmset(struct tty_struct *tty, unsigned int set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) 			    unsigned int clear);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) static int keyspan_fake_startup(struct usb_serial *serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) static int keyspan_usa19_calc_baud(struct usb_serial_port *port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) 				   u32 baud_rate, u32 baudclk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) 				   u8 *rate_hi, u8 *rate_low,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) 				   u8 *prescaler, int portnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) static int keyspan_usa19w_calc_baud(struct usb_serial_port *port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) 				    u32 baud_rate, u32 baudclk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 				    u8 *rate_hi, u8 *rate_low,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 				    u8 *prescaler, int portnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) static int keyspan_usa28_calc_baud(struct usb_serial_port *port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 				   u32 baud_rate, u32 baudclk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) 				   u8 *rate_hi, u8 *rate_low,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 				   u8 *prescaler, int portnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) static int keyspan_usa19hs_calc_baud(struct usb_serial_port *port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 				     u32 baud_rate, u32 baudclk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 				     u8 *rate_hi, u8 *rate_low,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 				     u8 *prescaler, int portnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) static int keyspan_usa28_send_setup(struct usb_serial *serial,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 				    struct usb_serial_port *port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 				    int reset_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) static int keyspan_usa26_send_setup(struct usb_serial *serial,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 				    struct usb_serial_port *port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 				    int reset_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) static int keyspan_usa49_send_setup(struct usb_serial *serial,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 				    struct usb_serial_port *port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 				    int reset_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) static int keyspan_usa90_send_setup(struct usb_serial *serial,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) 				    struct usb_serial_port *port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) 				    int reset_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) static int keyspan_usa67_send_setup(struct usb_serial *serial,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 				    struct usb_serial_port *port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 				    int reset_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) /* Values used for baud rate calculation - device specific */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) #define KEYSPAN_INVALID_BAUD_RATE		(-1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) #define KEYSPAN_BAUD_RATE_OK			(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) #define KEYSPAN_USA18X_BAUDCLK			(12000000L)	/* a guess */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) #define KEYSPAN_USA19_BAUDCLK			(12000000L)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) #define KEYSPAN_USA19W_BAUDCLK			(24000000L)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) #define KEYSPAN_USA19HS_BAUDCLK			(14769231L)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) #define KEYSPAN_USA28_BAUDCLK			(1843200L)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) #define KEYSPAN_USA28X_BAUDCLK			(12000000L)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) #define KEYSPAN_USA49W_BAUDCLK			(48000000L)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) /* Some constants used to characterise each device.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) #define KEYSPAN_MAX_NUM_PORTS			(4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) #define KEYSPAN_MAX_FLIPS			(2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115)  * Device info for the Keyspan serial converter, used by the overall
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116)  * usb-serial probe function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) #define KEYSPAN_VENDOR_ID			(0x06cd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) /* Product IDs for the products supported, pre-renumeration */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) #define keyspan_usa18x_pre_product_id		0x0105
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) #define keyspan_usa19_pre_product_id		0x0103
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) #define keyspan_usa19qi_pre_product_id		0x010b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) #define keyspan_mpr_pre_product_id		0x011b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) #define keyspan_usa19qw_pre_product_id		0x0118
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) #define keyspan_usa19w_pre_product_id		0x0106
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) #define keyspan_usa28_pre_product_id		0x0101
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) #define keyspan_usa28x_pre_product_id		0x0102
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) #define keyspan_usa28xa_pre_product_id		0x0114
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) #define keyspan_usa28xb_pre_product_id		0x0113
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) #define keyspan_usa49w_pre_product_id		0x0109
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) #define keyspan_usa49wlc_pre_product_id		0x011a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135)  * Product IDs post-renumeration.  Note that the 28x and 28xb have the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136)  * id's post-renumeration but behave identically so it's not an issue. As
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137)  * such, the 28xb is not listed in any of the device tables.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) #define keyspan_usa18x_product_id		0x0112
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) #define keyspan_usa19_product_id		0x0107
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) #define keyspan_usa19qi_product_id		0x010c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) #define keyspan_usa19hs_product_id		0x0121
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) #define keyspan_mpr_product_id			0x011c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) #define keyspan_usa19qw_product_id		0x0119
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) #define keyspan_usa19w_product_id		0x0108
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) #define keyspan_usa28_product_id		0x010f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) #define keyspan_usa28x_product_id		0x0110
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) #define keyspan_usa28xa_product_id		0x0115
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) #define keyspan_usa28xb_product_id		0x0110
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) #define keyspan_usa28xg_product_id		0x0135
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) #define keyspan_usa49w_product_id		0x010a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) #define keyspan_usa49wlc_product_id		0x012a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) #define keyspan_usa49wg_product_id		0x0131
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) struct keyspan_device_details {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 	/* product ID value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 	int	product_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 	enum	{msg_usa26, msg_usa28, msg_usa49, msg_usa90, msg_usa67} msg_format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 		/* Number of physical ports */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 	int	num_ports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 		/* 1 if endpoint flipping used on input, 0 if not */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 	int	indat_endp_flip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 		/* 1 if endpoint flipping used on output, 0 if not */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 	int	outdat_endp_flip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 		 * Table mapping input data endpoint IDs to physical port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 		 * number and flip if used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 	int	indat_endpoints[KEYSPAN_MAX_NUM_PORTS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 		/* Same for output endpoints */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 	int	outdat_endpoints[KEYSPAN_MAX_NUM_PORTS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 		/* Input acknowledge endpoints */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 	int	inack_endpoints[KEYSPAN_MAX_NUM_PORTS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 		/* Output control endpoints */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 	int	outcont_endpoints[KEYSPAN_MAX_NUM_PORTS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 		/* Endpoint used for input status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 	int	instat_endpoint;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 		/* Endpoint used for input data 49WG only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 	int	indat_endpoint;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 		/* Endpoint used for global control functions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 	int	glocont_endpoint;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 	int	(*calculate_baud_rate)(struct usb_serial_port *port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 				       u32 baud_rate, u32 baudclk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 				       u8 *rate_hi, u8 *rate_low, u8 *prescaler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 				       int portnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 	u32	baudclk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202)  * Now for each device type we setup the device detail structure with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203)  * appropriate information (provided in Keyspan's documentation)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) static const struct keyspan_device_details usa18x_device_details = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 	.product_id		= keyspan_usa18x_product_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 	.msg_format		= msg_usa26,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 	.num_ports		= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 	.indat_endp_flip	= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 	.outdat_endp_flip	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 	.indat_endpoints	= {0x81},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 	.outdat_endpoints	= {0x01},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 	.inack_endpoints	= {0x85},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	.outcont_endpoints	= {0x05},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 	.instat_endpoint	= 0x87,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 	.indat_endpoint		= -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 	.glocont_endpoint	= 0x07,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 	.calculate_baud_rate	= keyspan_usa19w_calc_baud,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 	.baudclk		= KEYSPAN_USA18X_BAUDCLK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) static const struct keyspan_device_details usa19_device_details = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 	.product_id		= keyspan_usa19_product_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 	.msg_format		= msg_usa28,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 	.num_ports		= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 	.indat_endp_flip	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 	.outdat_endp_flip	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 	.indat_endpoints	= {0x81},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 	.outdat_endpoints	= {0x01},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 	.inack_endpoints	= {0x83},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 	.outcont_endpoints	= {0x03},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	.instat_endpoint	= 0x84,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 	.indat_endpoint		= -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 	.glocont_endpoint	= -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 	.calculate_baud_rate	= keyspan_usa19_calc_baud,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 	.baudclk		= KEYSPAN_USA19_BAUDCLK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) static const struct keyspan_device_details usa19qi_device_details = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 	.product_id		= keyspan_usa19qi_product_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 	.msg_format		= msg_usa28,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 	.num_ports		= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 	.indat_endp_flip	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 	.outdat_endp_flip	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 	.indat_endpoints	= {0x81},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 	.outdat_endpoints	= {0x01},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 	.inack_endpoints	= {0x83},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 	.outcont_endpoints	= {0x03},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 	.instat_endpoint	= 0x84,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 	.indat_endpoint		= -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 	.glocont_endpoint	= -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 	.calculate_baud_rate	= keyspan_usa28_calc_baud,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 	.baudclk		= KEYSPAN_USA19_BAUDCLK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) static const struct keyspan_device_details mpr_device_details = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 	.product_id		= keyspan_mpr_product_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 	.msg_format		= msg_usa28,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 	.num_ports		= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 	.indat_endp_flip	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 	.outdat_endp_flip	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 	.indat_endpoints	= {0x81},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	.outdat_endpoints	= {0x01},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 	.inack_endpoints	= {0x83},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 	.outcont_endpoints	= {0x03},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 	.instat_endpoint	= 0x84,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 	.indat_endpoint		= -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 	.glocont_endpoint	= -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 	.calculate_baud_rate	= keyspan_usa28_calc_baud,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 	.baudclk		= KEYSPAN_USA19_BAUDCLK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) static const struct keyspan_device_details usa19qw_device_details = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 	.product_id		= keyspan_usa19qw_product_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 	.msg_format		= msg_usa26,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 	.num_ports		= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 	.indat_endp_flip	= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 	.outdat_endp_flip	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 	.indat_endpoints	= {0x81},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 	.outdat_endpoints	= {0x01},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 	.inack_endpoints	= {0x85},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 	.outcont_endpoints	= {0x05},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 	.instat_endpoint	= 0x87,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 	.indat_endpoint		= -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 	.glocont_endpoint	= 0x07,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 	.calculate_baud_rate	= keyspan_usa19w_calc_baud,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 	.baudclk		= KEYSPAN_USA19W_BAUDCLK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) static const struct keyspan_device_details usa19w_device_details = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 	.product_id		= keyspan_usa19w_product_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 	.msg_format		= msg_usa26,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 	.num_ports		= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 	.indat_endp_flip	= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 	.outdat_endp_flip	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 	.indat_endpoints	= {0x81},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 	.outdat_endpoints	= {0x01},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 	.inack_endpoints	= {0x85},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 	.outcont_endpoints	= {0x05},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 	.instat_endpoint	= 0x87,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 	.indat_endpoint		= -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 	.glocont_endpoint	= 0x07,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 	.calculate_baud_rate	= keyspan_usa19w_calc_baud,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 	.baudclk		= KEYSPAN_USA19W_BAUDCLK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) static const struct keyspan_device_details usa19hs_device_details = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 	.product_id		= keyspan_usa19hs_product_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 	.msg_format		= msg_usa90,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 	.num_ports		= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 	.indat_endp_flip	= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 	.outdat_endp_flip	= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 	.indat_endpoints	= {0x81},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 	.outdat_endpoints	= {0x01},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 	.inack_endpoints	= {-1},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 	.outcont_endpoints	= {0x02},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 	.instat_endpoint	= 0x82,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 	.indat_endpoint		= -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 	.glocont_endpoint	= -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 	.calculate_baud_rate	= keyspan_usa19hs_calc_baud,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 	.baudclk		= KEYSPAN_USA19HS_BAUDCLK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) static const struct keyspan_device_details usa28_device_details = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 	.product_id		= keyspan_usa28_product_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 	.msg_format		= msg_usa28,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 	.num_ports		= 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 	.indat_endp_flip	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 	.outdat_endp_flip	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 	.indat_endpoints	= {0x81, 0x83},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 	.outdat_endpoints	= {0x01, 0x03},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 	.inack_endpoints	= {0x85, 0x86},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 	.outcont_endpoints	= {0x05, 0x06},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 	.instat_endpoint	= 0x87,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 	.indat_endpoint		= -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 	.glocont_endpoint	= 0x07,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 	.calculate_baud_rate	= keyspan_usa28_calc_baud,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 	.baudclk		= KEYSPAN_USA28_BAUDCLK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) static const struct keyspan_device_details usa28x_device_details = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 	.product_id		= keyspan_usa28x_product_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 	.msg_format		= msg_usa26,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 	.num_ports		= 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 	.indat_endp_flip	= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 	.outdat_endp_flip	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 	.indat_endpoints	= {0x81, 0x83},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 	.outdat_endpoints	= {0x01, 0x03},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 	.inack_endpoints	= {0x85, 0x86},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 	.outcont_endpoints	= {0x05, 0x06},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 	.instat_endpoint	= 0x87,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 	.indat_endpoint		= -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 	.glocont_endpoint	= 0x07,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 	.calculate_baud_rate	= keyspan_usa19w_calc_baud,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 	.baudclk		= KEYSPAN_USA28X_BAUDCLK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) static const struct keyspan_device_details usa28xa_device_details = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 	.product_id		= keyspan_usa28xa_product_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 	.msg_format		= msg_usa26,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 	.num_ports		= 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 	.indat_endp_flip	= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 	.outdat_endp_flip	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 	.indat_endpoints	= {0x81, 0x83},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 	.outdat_endpoints	= {0x01, 0x03},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 	.inack_endpoints	= {0x85, 0x86},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 	.outcont_endpoints	= {0x05, 0x06},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 	.instat_endpoint	= 0x87,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 	.indat_endpoint		= -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 	.glocont_endpoint	= 0x07,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 	.calculate_baud_rate	= keyspan_usa19w_calc_baud,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 	.baudclk		= KEYSPAN_USA28X_BAUDCLK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) static const struct keyspan_device_details usa28xg_device_details = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 	.product_id		= keyspan_usa28xg_product_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 	.msg_format		= msg_usa67,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 	.num_ports		= 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 	.indat_endp_flip	= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 	.outdat_endp_flip	= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 	.indat_endpoints	= {0x84, 0x88},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 	.outdat_endpoints	= {0x02, 0x06},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 	.inack_endpoints	= {-1, -1},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 	.outcont_endpoints	= {-1, -1},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 	.instat_endpoint	= 0x81,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 	.indat_endpoint		= -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 	.glocont_endpoint	= 0x01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 	.calculate_baud_rate	= keyspan_usa19w_calc_baud,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 	.baudclk		= KEYSPAN_USA28X_BAUDCLK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393)  * We don't need a separate entry for the usa28xb as it appears as a 28x
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394)  * anyway.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) static const struct keyspan_device_details usa49w_device_details = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 	.product_id		= keyspan_usa49w_product_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 	.msg_format		= msg_usa49,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 	.num_ports		= 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 	.indat_endp_flip	= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 	.outdat_endp_flip	= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 	.indat_endpoints	= {0x81, 0x82, 0x83, 0x84},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 	.outdat_endpoints	= {0x01, 0x02, 0x03, 0x04},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 	.inack_endpoints	= {-1, -1, -1, -1},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 	.outcont_endpoints	= {-1, -1, -1, -1},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 	.instat_endpoint	= 0x87,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 	.indat_endpoint		= -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 	.glocont_endpoint	= 0x07,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 	.calculate_baud_rate	= keyspan_usa19w_calc_baud,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 	.baudclk		= KEYSPAN_USA49W_BAUDCLK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) static const struct keyspan_device_details usa49wlc_device_details = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 	.product_id		= keyspan_usa49wlc_product_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 	.msg_format		= msg_usa49,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 	.num_ports		= 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 	.indat_endp_flip	= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 	.outdat_endp_flip	= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 	.indat_endpoints	= {0x81, 0x82, 0x83, 0x84},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 	.outdat_endpoints	= {0x01, 0x02, 0x03, 0x04},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 	.inack_endpoints	= {-1, -1, -1, -1},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 	.outcont_endpoints	= {-1, -1, -1, -1},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 	.instat_endpoint	= 0x87,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 	.indat_endpoint		= -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 	.glocont_endpoint	= 0x07,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 	.calculate_baud_rate	= keyspan_usa19w_calc_baud,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 	.baudclk		= KEYSPAN_USA19W_BAUDCLK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) static const struct keyspan_device_details usa49wg_device_details = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 	.product_id		= keyspan_usa49wg_product_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 	.msg_format		= msg_usa49,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 	.num_ports		= 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 	.indat_endp_flip	= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 	.outdat_endp_flip	= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 	.indat_endpoints	= {-1, -1, -1, -1},	/* single 'global' data in EP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 	.outdat_endpoints	= {0x01, 0x02, 0x04, 0x06},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 	.inack_endpoints	= {-1, -1, -1, -1},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	.outcont_endpoints	= {-1, -1, -1, -1},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	.instat_endpoint	= 0x81,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 	.indat_endpoint		= 0x88,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 	.glocont_endpoint	= 0x00,			/* uses control EP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 	.calculate_baud_rate	= keyspan_usa19w_calc_baud,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 	.baudclk		= KEYSPAN_USA19W_BAUDCLK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) static const struct keyspan_device_details *keyspan_devices[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 	&usa18x_device_details,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 	&usa19_device_details,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 	&usa19qi_device_details,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 	&mpr_device_details,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 	&usa19qw_device_details,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 	&usa19w_device_details,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 	&usa19hs_device_details,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 	&usa28_device_details,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 	&usa28x_device_details,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 	&usa28xa_device_details,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 	&usa28xg_device_details,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 	/* 28xb not required as it renumerates as a 28x */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 	&usa49w_device_details,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 	&usa49wlc_device_details,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 	&usa49wg_device_details,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) static const struct usb_device_id keyspan_ids_combined[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa18x_pre_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19_pre_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19w_pre_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19qi_pre_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19qw_pre_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_mpr_pre_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28_pre_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28x_pre_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28xa_pre_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28xb_pre_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa49w_pre_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa49wlc_pre_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa18x_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19w_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19qi_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19qw_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19hs_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_mpr_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28x_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28xa_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28xg_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa49w_product_id)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa49wlc_product_id)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa49wg_product_id)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 	{ } /* Terminating entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) MODULE_DEVICE_TABLE(usb, keyspan_ids_combined);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) /* usb_device_id table for the pre-firmware download keyspan devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) static const struct usb_device_id keyspan_pre_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa18x_pre_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19_pre_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19qi_pre_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19qw_pre_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19w_pre_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_mpr_pre_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28_pre_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28x_pre_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28xa_pre_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28xb_pre_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa49w_pre_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa49wlc_pre_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 	{ } /* Terminating entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) static const struct usb_device_id keyspan_1port_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa18x_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19qi_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19qw_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19w_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19hs_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_mpr_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 	{ } /* Terminating entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) static const struct usb_device_id keyspan_2port_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28x_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28xa_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28xg_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 	{ } /* Terminating entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) static const struct usb_device_id keyspan_4port_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa49w_product_id) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa49wlc_product_id)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 	{ USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa49wg_product_id)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 	{ } /* Terminating entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) #define INSTAT_BUFLEN	32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) #define GLOCONT_BUFLEN	64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) #define INDAT49W_BUFLEN	512
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) #define IN_BUFLEN	64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) #define OUT_BUFLEN	64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) #define INACK_BUFLEN	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) #define OUTCONT_BUFLEN	64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 	/* Per device and per port private data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) struct keyspan_serial_private {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 	const struct keyspan_device_details	*device_details;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 	struct urb	*instat_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 	char		*instat_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 	/* added to support 49wg, where data from all 4 ports comes in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 	   on 1 EP and high-speed supported */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 	struct urb	*indat_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 	char		*indat_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 	/* XXX this one probably will need a lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	struct urb	*glocont_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 	char		*glocont_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 	char		*ctrl_buf;	/* for EP0 control message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) struct keyspan_port_private {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 	/* Keep track of which input & output endpoints to use */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 	int		in_flip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 	int		out_flip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 	/* Keep duplicate of device details in each port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 	   structure as well - simplifies some of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 	   callback functions etc. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 	const struct keyspan_device_details	*device_details;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 	/* Input endpoints and buffer for this port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 	struct urb	*in_urbs[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 	char		*in_buffer[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 	/* Output endpoints and buffer for this port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 	struct urb	*out_urbs[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 	char		*out_buffer[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 	/* Input ack endpoint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 	struct urb	*inack_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 	char		*inack_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 	/* Output control endpoint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 	struct urb	*outcont_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 	char		*outcont_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 	/* Settings for the port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 	int		baud;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 	int		old_baud;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 	unsigned int	cflag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 	unsigned int	old_cflag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 	enum		{flow_none, flow_cts, flow_xon} flow_control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 	int		rts_state;	/* Handshaking pins (outputs) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 	int		dtr_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 	int		cts_state;	/* Handshaking pins (inputs) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 	int		dsr_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 	int		dcd_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 	int		ri_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 	int		break_on;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 	unsigned long	tx_start_time[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 	int		resend_cont;	/* need to resend control packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) /* Include Keyspan message headers.  All current Keyspan Adapters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612)    make use of one of five message formats which are referred
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613)    to as USA-26, USA-28, USA-49, USA-90, USA-67 by Keyspan and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614)    within this driver. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) #include "keyspan_usa26msg.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) #include "keyspan_usa28msg.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) #include "keyspan_usa49msg.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) #include "keyspan_usa90msg.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) #include "keyspan_usa67msg.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) static void keyspan_break_ctl(struct tty_struct *tty, int break_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 	struct usb_serial_port *port = tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 	struct keyspan_port_private 	*p_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 	p_priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 	if (break_state == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 		p_priv->break_on = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 		p_priv->break_on = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 	keyspan_send_setup(port, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) static void keyspan_set_termios(struct tty_struct *tty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 		struct usb_serial_port *port, struct ktermios *old_termios)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 	int				baud_rate, device_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 	struct keyspan_port_private 	*p_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 	const struct keyspan_device_details	*d_details;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 	unsigned int 			cflag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 	p_priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 	d_details = p_priv->device_details;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 	cflag = tty->termios.c_cflag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 	device_port = port->port_number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 	/* Baud rate calculation takes baud rate as an integer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 	   so other rates can be generated if desired. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 	baud_rate = tty_get_baud_rate(tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 	/* If no match or invalid, don't change */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 	if (d_details->calculate_baud_rate(port, baud_rate, d_details->baudclk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 				NULL, NULL, NULL, device_port) == KEYSPAN_BAUD_RATE_OK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 		/* FIXME - more to do here to ensure rate changes cleanly */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 		/* FIXME - calculate exact rate from divisor ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 		p_priv->baud = baud_rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 		baud_rate = tty_termios_baud_rate(old_termios);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 	tty_encode_baud_rate(tty, baud_rate, baud_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 	/* set CTS/RTS handshake etc. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 	p_priv->cflag = cflag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 	p_priv->flow_control = (cflag & CRTSCTS) ? flow_cts : flow_none;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 	/* Mark/Space not supported */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 	tty->termios.c_cflag &= ~CMSPAR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 	keyspan_send_setup(port, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) static int keyspan_tiocmget(struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 	struct usb_serial_port *port = tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 	struct keyspan_port_private *p_priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 	unsigned int			value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 	value = ((p_priv->rts_state) ? TIOCM_RTS : 0) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 		((p_priv->dtr_state) ? TIOCM_DTR : 0) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 		((p_priv->cts_state) ? TIOCM_CTS : 0) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 		((p_priv->dsr_state) ? TIOCM_DSR : 0) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 		((p_priv->dcd_state) ? TIOCM_CAR : 0) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 		((p_priv->ri_state) ? TIOCM_RNG : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 	return value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) static int keyspan_tiocmset(struct tty_struct *tty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 			    unsigned int set, unsigned int clear)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 	struct usb_serial_port *port = tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 	struct keyspan_port_private *p_priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 	if (set & TIOCM_RTS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 		p_priv->rts_state = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 	if (set & TIOCM_DTR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 		p_priv->dtr_state = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 	if (clear & TIOCM_RTS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 		p_priv->rts_state = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 	if (clear & TIOCM_DTR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 		p_priv->dtr_state = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 	keyspan_send_setup(port, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) /* Write function is similar for the four protocols used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709)    with only a minor change for usa90 (usa19hs) required */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) static int keyspan_write(struct tty_struct *tty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 	struct usb_serial_port *port, const unsigned char *buf, int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 	struct keyspan_port_private 	*p_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 	const struct keyspan_device_details	*d_details;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 	int				flip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 	int 				left, todo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 	struct urb			*this_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 	int 				err, maxDataLen, dataOffset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 	p_priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 	d_details = p_priv->device_details;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 	if (d_details->msg_format == msg_usa90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 		maxDataLen = 64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 		dataOffset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 		maxDataLen = 63;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 		dataOffset = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 	dev_dbg(&port->dev, "%s - %d chars, flip=%d\n", __func__, count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 		p_priv->out_flip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 	for (left = count; left > 0; left -= todo) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 		todo = left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 		if (todo > maxDataLen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 			todo = maxDataLen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 		flip = p_priv->out_flip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 		/* Check we have a valid urb/endpoint before we use it... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 		this_urb = p_priv->out_urbs[flip];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 		if (this_urb == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 			/* no bulk out, so return 0 bytes written */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 			dev_dbg(&port->dev, "%s - no output urb :(\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 			return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 		dev_dbg(&port->dev, "%s - endpoint %x flip %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 			__func__, usb_pipeendpoint(this_urb->pipe), flip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 		if (this_urb->status == -EINPROGRESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 			if (time_before(jiffies,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 					p_priv->tx_start_time[flip] + 10 * HZ))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 			usb_unlink_urb(this_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 		/* First byte in buffer is "last flag" (except for usa19hx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 		   - unused so for now so set to zero */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 		((char *)this_urb->transfer_buffer)[0] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 		memcpy(this_urb->transfer_buffer + dataOffset, buf, todo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 		buf += todo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 		/* send the data out the bulk port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 		this_urb->transfer_buffer_length = todo + dataOffset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 		err = usb_submit_urb(this_urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 		if (err != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 			dev_dbg(&port->dev, "usb_submit_urb(write bulk) failed (%d)\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 		p_priv->tx_start_time[flip] = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 		/* Flip for next time if usa26 or usa28 interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 		   (not used on usa49) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 		p_priv->out_flip = (flip + 1) & d_details->outdat_endp_flip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 	return count - left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) static void	usa26_indat_callback(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 	int			i, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 	int			endpoint;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 	struct usb_serial_port	*port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 	unsigned char 		*data = urb->transfer_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 	int status = urb->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 	endpoint = usb_pipeendpoint(urb->pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 	if (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 		dev_dbg(&urb->dev->dev, "%s - nonzero status %d on endpoint %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 			__func__, status, endpoint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 	port =  urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 	if (urb->actual_length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 		/* 0x80 bit is error flag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 		if ((data[0] & 0x80) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 			/* no errors on individual bytes, only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 			   possible overrun err */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 			if (data[0] & RXERROR_OVERRUN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 				tty_insert_flip_char(&port->port, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 								TTY_OVERRUN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 			for (i = 1; i < urb->actual_length ; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 				tty_insert_flip_char(&port->port, data[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 								TTY_NORMAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 			/* some bytes had errors, every byte has status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 			dev_dbg(&port->dev, "%s - RX error!!!!\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 			for (i = 0; i + 1 < urb->actual_length; i += 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 				int stat = data[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 				int flag = TTY_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 				if (stat & RXERROR_OVERRUN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 					tty_insert_flip_char(&port->port, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 								TTY_OVERRUN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 				/* XXX should handle break (0x10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 				if (stat & RXERROR_PARITY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 					flag = TTY_PARITY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 				else if (stat & RXERROR_FRAMING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 					flag = TTY_FRAME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 				tty_insert_flip_char(&port->port, data[i+1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 						flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 		tty_flip_buffer_push(&port->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 	/* Resubmit urb so we continue receiving */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 	err = usb_submit_urb(urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 	if (err != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 		dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) /* Outdat handling is common for all devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) static void	usa2x_outdat_callback(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 	struct usb_serial_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 	struct keyspan_port_private *p_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 	port =  urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 	p_priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 	dev_dbg(&port->dev, "%s - urb %d\n", __func__, urb == p_priv->out_urbs[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 	usb_serial_port_softint(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) static void	usa26_inack_callback(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) static void	usa26_outcont_callback(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 	struct usb_serial_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 	struct keyspan_port_private *p_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 	port =  urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 	p_priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 	if (p_priv->resend_cont) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 		dev_dbg(&port->dev, "%s - sending setup\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 		keyspan_usa26_send_setup(port->serial, port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 						p_priv->resend_cont - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) static void	usa26_instat_callback(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 	unsigned char 				*data = urb->transfer_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 	struct keyspan_usa26_portStatusMessage	*msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 	struct usb_serial			*serial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	struct usb_serial_port			*port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 	struct keyspan_port_private	 	*p_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 	int old_dcd_state, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 	int status = urb->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 	serial =  urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 	if (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 		dev_dbg(&urb->dev->dev, "%s - nonzero status: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 				__func__, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 	if (urb->actual_length != 9) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 		dev_dbg(&urb->dev->dev, "%s - %d byte report??\n", __func__, urb->actual_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 		goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 	msg = (struct keyspan_usa26_portStatusMessage *)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 	/* Check port number from message and retrieve private data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 	if (msg->port >= serial->num_ports) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 		dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n", __func__, msg->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 		goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 	port = serial->port[msg->port];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 	p_priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 	if (!p_priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 		goto resubmit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 	/* Update handshaking pin state information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 	old_dcd_state = p_priv->dcd_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 	p_priv->cts_state = ((msg->hskia_cts) ? 1 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 	p_priv->dsr_state = ((msg->dsr) ? 1 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 	p_priv->dcd_state = ((msg->gpia_dcd) ? 1 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 	p_priv->ri_state = ((msg->ri) ? 1 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 	if (old_dcd_state != p_priv->dcd_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 		tty_port_tty_hangup(&port->port, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) resubmit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 	/* Resubmit urb so we continue receiving */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 	err = usb_submit_urb(urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 	if (err != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 		dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) exit: ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) static void	usa26_glocont_callback(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) static void usa28_indat_callback(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 	int                     err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 	struct usb_serial_port  *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 	unsigned char           *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 	struct keyspan_port_private             *p_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 	int status = urb->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 	port =  urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 	p_priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 	data = urb->transfer_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 	if (urb != p_priv->in_urbs[p_priv->in_flip])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 		if (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 			dev_dbg(&urb->dev->dev, "%s - nonzero status %d on endpoint %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 				__func__, status, usb_pipeendpoint(urb->pipe));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 		port =  urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 		p_priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 		data = urb->transfer_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 		if (urb->actual_length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 			tty_insert_flip_string(&port->port, data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 					urb->actual_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 			tty_flip_buffer_push(&port->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 		/* Resubmit urb so we continue receiving */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 		err = usb_submit_urb(urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 		if (err != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 			dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 							__func__, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 		p_priv->in_flip ^= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 		urb = p_priv->in_urbs[p_priv->in_flip];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 	} while (urb->status != -EINPROGRESS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) static void	usa28_inack_callback(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) static void	usa28_outcont_callback(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 	struct usb_serial_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 	struct keyspan_port_private *p_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 	port =  urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 	p_priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 	if (p_priv->resend_cont) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 		dev_dbg(&port->dev, "%s - sending setup\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 		keyspan_usa28_send_setup(port->serial, port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 						p_priv->resend_cont - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) static void	usa28_instat_callback(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	int					err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 	unsigned char 				*data = urb->transfer_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 	struct keyspan_usa28_portStatusMessage	*msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 	struct usb_serial			*serial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 	struct usb_serial_port			*port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 	struct keyspan_port_private	 	*p_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 	int old_dcd_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 	int status = urb->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 	serial =  urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 	if (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 		dev_dbg(&urb->dev->dev, "%s - nonzero status: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 				__func__, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 	if (urb->actual_length != sizeof(struct keyspan_usa28_portStatusMessage)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 		dev_dbg(&urb->dev->dev, "%s - bad length %d\n", __func__, urb->actual_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 		goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 	msg = (struct keyspan_usa28_portStatusMessage *)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 	/* Check port number from message and retrieve private data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 	if (msg->port >= serial->num_ports) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 		dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n", __func__, msg->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 		goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 	port = serial->port[msg->port];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 	p_priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 	if (!p_priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 		goto resubmit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 	/* Update handshaking pin state information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 	old_dcd_state = p_priv->dcd_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 	p_priv->cts_state = ((msg->cts) ? 1 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 	p_priv->dsr_state = ((msg->dsr) ? 1 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 	p_priv->dcd_state = ((msg->dcd) ? 1 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 	p_priv->ri_state = ((msg->ri) ? 1 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 	if (old_dcd_state != p_priv->dcd_state && old_dcd_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 		tty_port_tty_hangup(&port->port, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) resubmit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 		/* Resubmit urb so we continue receiving */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 	err = usb_submit_urb(urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 	if (err != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 		dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) exit: ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) static void	usa28_glocont_callback(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) static void	usa49_glocont_callback(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 	struct usb_serial *serial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 	struct usb_serial_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 	struct keyspan_port_private *p_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 	serial =  urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 	for (i = 0; i < serial->num_ports; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 		port = serial->port[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 		p_priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 		if (!p_priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 		if (p_priv->resend_cont) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 			dev_dbg(&port->dev, "%s - sending setup\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 			keyspan_usa49_send_setup(serial, port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 						p_priv->resend_cont - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 	/* This is actually called glostat in the Keyspan
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 	   doco */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) static void	usa49_instat_callback(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 	int					err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 	unsigned char 				*data = urb->transfer_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 	struct keyspan_usa49_portStatusMessage	*msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 	struct usb_serial			*serial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 	struct usb_serial_port			*port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 	struct keyspan_port_private	 	*p_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 	int old_dcd_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 	int status = urb->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 	serial =  urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 	if (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 		dev_dbg(&urb->dev->dev, "%s - nonzero status: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 				__func__, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 	if (urb->actual_length !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 			sizeof(struct keyspan_usa49_portStatusMessage)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 		dev_dbg(&urb->dev->dev, "%s - bad length %d\n", __func__, urb->actual_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 		goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 	msg = (struct keyspan_usa49_portStatusMessage *)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 	/* Check port number from message and retrieve private data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 	if (msg->portNumber >= serial->num_ports) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 		dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 			__func__, msg->portNumber);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 		goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 	port = serial->port[msg->portNumber];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 	p_priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 	if (!p_priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 		goto resubmit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 	/* Update handshaking pin state information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 	old_dcd_state = p_priv->dcd_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 	p_priv->cts_state = ((msg->cts) ? 1 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 	p_priv->dsr_state = ((msg->dsr) ? 1 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 	p_priv->dcd_state = ((msg->dcd) ? 1 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 	p_priv->ri_state = ((msg->ri) ? 1 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 	if (old_dcd_state != p_priv->dcd_state && old_dcd_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 		tty_port_tty_hangup(&port->port, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) resubmit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 	/* Resubmit urb so we continue receiving */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 	err = usb_submit_urb(urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 	if (err != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 		dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) exit:	;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) static void	usa49_inack_callback(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) static void	usa49_indat_callback(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 	int			i, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 	int			endpoint;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 	struct usb_serial_port	*port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 	unsigned char 		*data = urb->transfer_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 	int status = urb->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 	endpoint = usb_pipeendpoint(urb->pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 	if (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 		dev_dbg(&urb->dev->dev, "%s - nonzero status %d on endpoint %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 			__func__, status, endpoint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 	port =  urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 	if (urb->actual_length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 		/* 0x80 bit is error flag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 		if ((data[0] & 0x80) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 			/* no error on any byte */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 			tty_insert_flip_string(&port->port, data + 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 						urb->actual_length - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 			/* some bytes had errors, every byte has status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 			for (i = 0; i + 1 < urb->actual_length; i += 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 				int stat = data[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 				int flag = TTY_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 				if (stat & RXERROR_OVERRUN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 					tty_insert_flip_char(&port->port, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 								TTY_OVERRUN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 				/* XXX should handle break (0x10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 				if (stat & RXERROR_PARITY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 					flag = TTY_PARITY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 				else if (stat & RXERROR_FRAMING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 					flag = TTY_FRAME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 				tty_insert_flip_char(&port->port, data[i+1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 						flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 		tty_flip_buffer_push(&port->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 	/* Resubmit urb so we continue receiving */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 	err = usb_submit_urb(urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 	if (err != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 		dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) static void usa49wg_indat_callback(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 	int			i, len, x, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 	struct usb_serial	*serial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 	struct usb_serial_port	*port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 	unsigned char 		*data = urb->transfer_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 	int status = urb->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 	serial = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 	if (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 		dev_dbg(&urb->dev->dev, "%s - nonzero status: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 				__func__, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 	/* inbound data is in the form P#, len, status, data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 	i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 	len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 	while (i < urb->actual_length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 		/* Check port number from message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 		if (data[i] >= serial->num_ports) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 			dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 				__func__, data[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 		port = serial->port[data[i++]];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 		len = data[i++];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 		/* 0x80 bit is error flag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 		if ((data[i] & 0x80) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 			/* no error on any byte */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 			i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 			for (x = 1; x < len && i < urb->actual_length; ++x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 				tty_insert_flip_char(&port->port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 						data[i++], 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 			 * some bytes had errors, every byte has status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 			for (x = 0; x + 1 < len &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 				    i + 1 < urb->actual_length; x += 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 				int stat = data[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 				int flag = TTY_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 				if (stat & RXERROR_OVERRUN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 					tty_insert_flip_char(&port->port, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 								TTY_OVERRUN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 				/* XXX should handle break (0x10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 				if (stat & RXERROR_PARITY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 					flag = TTY_PARITY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 				else if (stat & RXERROR_FRAMING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 					flag = TTY_FRAME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 				tty_insert_flip_char(&port->port, data[i+1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 						     flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 				i += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 		tty_flip_buffer_push(&port->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 	/* Resubmit urb so we continue receiving */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 	err = usb_submit_urb(urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 	if (err != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 		dev_dbg(&urb->dev->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) /* not used, usa-49 doesn't have per-port control endpoints */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) static void usa49_outcont_callback(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) static void usa90_indat_callback(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 	int			i, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 	int			endpoint;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 	struct usb_serial_port	*port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 	struct keyspan_port_private	 	*p_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 	unsigned char 		*data = urb->transfer_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 	int status = urb->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 	endpoint = usb_pipeendpoint(urb->pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 	if (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 		dev_dbg(&urb->dev->dev, "%s - nonzero status %d on endpoint %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 			__func__, status, endpoint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 	port =  urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 	p_priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 	if (urb->actual_length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 		/* if current mode is DMA, looks like usa28 format
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 		   otherwise looks like usa26 data format */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 		if (p_priv->baud > 57600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 			tty_insert_flip_string(&port->port, data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 					urb->actual_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 		else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 			/* 0x80 bit is error flag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 			if ((data[0] & 0x80) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 				/* no errors on individual bytes, only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 				   possible overrun err*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) 				if (data[0] & RXERROR_OVERRUN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 					tty_insert_flip_char(&port->port, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 								TTY_OVERRUN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 				for (i = 1; i < urb->actual_length ; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 					tty_insert_flip_char(&port->port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 							data[i], TTY_NORMAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 			}  else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 			/* some bytes had errors, every byte has status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 				dev_dbg(&port->dev, "%s - RX error!!!!\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 				for (i = 0; i + 1 < urb->actual_length; i += 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 					int stat = data[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 					int flag = TTY_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 					if (stat & RXERROR_OVERRUN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 						tty_insert_flip_char(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 								&port->port, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 								TTY_OVERRUN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 					/* XXX should handle break (0x10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 					if (stat & RXERROR_PARITY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 						flag = TTY_PARITY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 					else if (stat & RXERROR_FRAMING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 						flag = TTY_FRAME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 					tty_insert_flip_char(&port->port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 							data[i+1], flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 		tty_flip_buffer_push(&port->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 	/* Resubmit urb so we continue receiving */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) 	err = usb_submit_urb(urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 	if (err != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 		dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) static void	usa90_instat_callback(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) 	unsigned char 				*data = urb->transfer_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) 	struct keyspan_usa90_portStatusMessage	*msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 	struct usb_serial			*serial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 	struct usb_serial_port			*port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 	struct keyspan_port_private	 	*p_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 	int old_dcd_state, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 	int status = urb->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 	serial =  urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 	if (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 		dev_dbg(&urb->dev->dev, "%s - nonzero status: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 				__func__, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 	if (urb->actual_length < 14) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 		dev_dbg(&urb->dev->dev, "%s - %d byte report??\n", __func__, urb->actual_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 		goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 	msg = (struct keyspan_usa90_portStatusMessage *)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 	/* Now do something useful with the data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 	port = serial->port[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 	p_priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 	if (!p_priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 		goto resubmit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 	/* Update handshaking pin state information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) 	old_dcd_state = p_priv->dcd_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) 	p_priv->cts_state = ((msg->cts) ? 1 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 	p_priv->dsr_state = ((msg->dsr) ? 1 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) 	p_priv->dcd_state = ((msg->dcd) ? 1 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 	p_priv->ri_state = ((msg->ri) ? 1 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 	if (old_dcd_state != p_priv->dcd_state && old_dcd_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) 		tty_port_tty_hangup(&port->port, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) resubmit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) 	/* Resubmit urb so we continue receiving */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) 	err = usb_submit_urb(urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) 	if (err != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) 		dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) 	;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) static void	usa90_outcont_callback(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 	struct usb_serial_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 	struct keyspan_port_private *p_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 	port =  urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 	p_priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 	if (p_priv->resend_cont) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 		dev_dbg(&urb->dev->dev, "%s - sending setup\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) 		keyspan_usa90_send_setup(port->serial, port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) 						p_priv->resend_cont - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) /* Status messages from the 28xg */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) static void	usa67_instat_callback(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) 	int					err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) 	unsigned char 				*data = urb->transfer_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) 	struct keyspan_usa67_portStatusMessage	*msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) 	struct usb_serial			*serial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 	struct usb_serial_port			*port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) 	struct keyspan_port_private	 	*p_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) 	int old_dcd_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 	int status = urb->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) 	serial = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) 	if (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) 		dev_dbg(&urb->dev->dev, "%s - nonzero status: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 				__func__, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) 	if (urb->actual_length !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) 			sizeof(struct keyspan_usa67_portStatusMessage)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) 		dev_dbg(&urb->dev->dev, "%s - bad length %d\n", __func__, urb->actual_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) 	/* Now do something useful with the data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) 	msg = (struct keyspan_usa67_portStatusMessage *)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) 	/* Check port number from message and retrieve private data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) 	if (msg->port >= serial->num_ports) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) 		dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n", __func__, msg->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) 	port = serial->port[msg->port];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 	p_priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) 	if (!p_priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 		goto resubmit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) 	/* Update handshaking pin state information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 	old_dcd_state = p_priv->dcd_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) 	p_priv->cts_state = ((msg->hskia_cts) ? 1 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 	p_priv->dcd_state = ((msg->gpia_dcd) ? 1 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) 	if (old_dcd_state != p_priv->dcd_state && old_dcd_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) 		tty_port_tty_hangup(&port->port, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) resubmit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) 	/* Resubmit urb so we continue receiving */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) 	err = usb_submit_urb(urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) 	if (err != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) 		dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) static void usa67_glocont_callback(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) 	struct usb_serial *serial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) 	struct usb_serial_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) 	struct keyspan_port_private *p_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) 	serial = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) 	for (i = 0; i < serial->num_ports; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) 		port = serial->port[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) 		p_priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) 		if (!p_priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) 		if (p_priv->resend_cont) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) 			dev_dbg(&port->dev, "%s - sending setup\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) 			keyspan_usa67_send_setup(serial, port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) 						p_priv->resend_cont - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) static int keyspan_write_room(struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) 	struct usb_serial_port *port = tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) 	struct keyspan_port_private	*p_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) 	const struct keyspan_device_details	*d_details;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) 	int				flip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 	int				data_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) 	struct urb			*this_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) 	p_priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) 	d_details = p_priv->device_details;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) 	/* FIXME: locking */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) 	if (d_details->msg_format == msg_usa90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) 		data_len = 64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) 		data_len = 63;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) 	flip = p_priv->out_flip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) 	/* Check both endpoints to see if any are available. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) 	this_urb = p_priv->out_urbs[flip];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) 	if (this_urb != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) 		if (this_urb->status != -EINPROGRESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) 			return data_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) 		flip = (flip + 1) & d_details->outdat_endp_flip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) 		this_urb = p_priv->out_urbs[flip];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) 		if (this_urb != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) 			if (this_urb->status != -EINPROGRESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) 				return data_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) static int keyspan_open(struct tty_struct *tty, struct usb_serial_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) 	struct keyspan_port_private 	*p_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) 	const struct keyspan_device_details	*d_details;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) 	int				i, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) 	int				baud_rate, device_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) 	struct urb			*urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) 	unsigned int			cflag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) 	p_priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) 	d_details = p_priv->device_details;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) 	/* Set some sane defaults */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) 	p_priv->rts_state = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) 	p_priv->dtr_state = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) 	p_priv->baud = 9600;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) 	/* force baud and lcr to be set on open */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) 	p_priv->old_baud = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) 	p_priv->old_cflag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) 	p_priv->out_flip = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) 	p_priv->in_flip = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) 	/* Reset low level data toggle and start reading from endpoints */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) 	for (i = 0; i < 2; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) 		urb = p_priv->in_urbs[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) 		if (urb == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) 		/* make sure endpoint data toggle is synchronized
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) 		   with the device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) 		usb_clear_halt(urb->dev, urb->pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) 		err = usb_submit_urb(urb, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) 		if (err != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) 			dev_dbg(&port->dev, "%s - submit urb %d failed (%d)\n", __func__, i, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) 	/* Reset low level data toggle on out endpoints */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) 	for (i = 0; i < 2; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) 		urb = p_priv->out_urbs[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) 		if (urb == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) 		/* usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) 						usb_pipeout(urb->pipe), 0); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) 	/* get the terminal config for the setup message now so we don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) 	 * need to send 2 of them */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) 	device_port = port->port_number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) 	if (tty) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) 		cflag = tty->termios.c_cflag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) 		/* Baud rate calculation takes baud rate as an integer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) 		   so other rates can be generated if desired. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) 		baud_rate = tty_get_baud_rate(tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) 		/* If no match or invalid, leave as default */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) 		if (baud_rate >= 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) 		    && d_details->calculate_baud_rate(port, baud_rate, d_details->baudclk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) 					NULL, NULL, NULL, device_port) == KEYSPAN_BAUD_RATE_OK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) 			p_priv->baud = baud_rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) 	/* set CTS/RTS handshake etc. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) 	p_priv->cflag = cflag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) 	p_priv->flow_control = (cflag & CRTSCTS) ? flow_cts : flow_none;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) 	keyspan_send_setup(port, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) 	/* mdelay(100); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) 	/* keyspan_set_termios(port, NULL); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) static void keyspan_dtr_rts(struct usb_serial_port *port, int on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) 	struct keyspan_port_private *p_priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) 	p_priv->rts_state = on;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) 	p_priv->dtr_state = on;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) 	keyspan_send_setup(port, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) static void keyspan_close(struct usb_serial_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) 	int			i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) 	struct keyspan_port_private 	*p_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) 	p_priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) 	p_priv->rts_state = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) 	p_priv->dtr_state = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) 	keyspan_send_setup(port, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) 	/* pilot-xfer seems to work best with this delay */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) 	mdelay(100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) 	p_priv->out_flip = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) 	p_priv->in_flip = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) 	usb_kill_urb(p_priv->inack_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) 	for (i = 0; i < 2; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) 		usb_kill_urb(p_priv->in_urbs[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) 		usb_kill_urb(p_priv->out_urbs[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) /* download the firmware to a pre-renumeration device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) static int keyspan_fake_startup(struct usb_serial *serial)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) 	char	*fw_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) 	dev_dbg(&serial->dev->dev, "Keyspan startup version %04x product %04x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) 		le16_to_cpu(serial->dev->descriptor.bcdDevice),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) 		le16_to_cpu(serial->dev->descriptor.idProduct));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) 	if ((le16_to_cpu(serial->dev->descriptor.bcdDevice) & 0x8000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) 								!= 0x8000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) 		dev_dbg(&serial->dev->dev, "Firmware already loaded.  Quitting.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) 		/* Select firmware image on the basis of idProduct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) 	switch (le16_to_cpu(serial->dev->descriptor.idProduct)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) 	case keyspan_usa28_pre_product_id:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) 		fw_name = "keyspan/usa28.fw";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) 	case keyspan_usa28x_pre_product_id:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) 		fw_name = "keyspan/usa28x.fw";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) 	case keyspan_usa28xa_pre_product_id:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) 		fw_name = "keyspan/usa28xa.fw";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) 	case keyspan_usa28xb_pre_product_id:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) 		fw_name = "keyspan/usa28xb.fw";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) 	case keyspan_usa19_pre_product_id:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) 		fw_name = "keyspan/usa19.fw";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) 	case keyspan_usa19qi_pre_product_id:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) 		fw_name = "keyspan/usa19qi.fw";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) 	case keyspan_mpr_pre_product_id:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) 		fw_name = "keyspan/mpr.fw";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) 	case keyspan_usa19qw_pre_product_id:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) 		fw_name = "keyspan/usa19qw.fw";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) 	case keyspan_usa18x_pre_product_id:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) 		fw_name = "keyspan/usa18x.fw";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) 	case keyspan_usa19w_pre_product_id:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) 		fw_name = "keyspan/usa19w.fw";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) 	case keyspan_usa49w_pre_product_id:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) 		fw_name = "keyspan/usa49w.fw";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) 	case keyspan_usa49wlc_pre_product_id:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) 		fw_name = "keyspan/usa49wlc.fw";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) 		dev_err(&serial->dev->dev, "Unknown product ID (%04x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) 			le16_to_cpu(serial->dev->descriptor.idProduct));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) 	dev_dbg(&serial->dev->dev, "Uploading Keyspan %s firmware.\n", fw_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) 	if (ezusb_fx1_ihex_firmware_download(serial->dev, fw_name) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) 		dev_err(&serial->dev->dev, "failed to load firmware \"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) 			fw_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) 		return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) 	/* after downloading firmware Renumeration will occur in a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) 	  moment and the new device will bind to the real driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) 	/* we don't want this device to have a driver assigned to it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) /* Helper functions used by keyspan_setup_urbs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) static struct usb_endpoint_descriptor const *find_ep(struct usb_serial const *serial,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) 						     int endpoint)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) 	struct usb_host_interface *iface_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) 	struct usb_endpoint_descriptor *ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) 	iface_desc = serial->interface->cur_altsetting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) 	for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) 		ep = &iface_desc->endpoint[i].desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) 		if (ep->bEndpointAddress == endpoint)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) 			return ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) 	dev_warn(&serial->interface->dev, "found no endpoint descriptor for endpoint %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) 			endpoint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) static struct urb *keyspan_setup_urb(struct usb_serial *serial, int endpoint,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) 				      int dir, void *ctx, char *buf, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) 				      void (*callback)(struct urb *))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) 	struct urb *urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) 	struct usb_endpoint_descriptor const *ep_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) 	char const *ep_type_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) 	if (endpoint == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) 		return NULL;		/* endpoint not needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) 	dev_dbg(&serial->interface->dev, "%s - alloc for endpoint %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) 			__func__, endpoint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) 	urb = usb_alloc_urb(0, GFP_KERNEL);		/* No ISO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) 	if (!urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) 	if (endpoint == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) 		/* control EP filled in when used */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) 		return urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) 	ep_desc = find_ep(serial, endpoint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) 	if (!ep_desc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) 		usb_free_urb(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) 	if (usb_endpoint_xfer_int(ep_desc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) 		ep_type_name = "INT";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) 		usb_fill_int_urb(urb, serial->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) 				 usb_sndintpipe(serial->dev, endpoint) | dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) 				 buf, len, callback, ctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) 				 ep_desc->bInterval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) 	} else if (usb_endpoint_xfer_bulk(ep_desc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) 		ep_type_name = "BULK";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) 		usb_fill_bulk_urb(urb, serial->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) 				  usb_sndbulkpipe(serial->dev, endpoint) | dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) 				  buf, len, callback, ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) 		dev_warn(&serial->interface->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) 			 "unsupported endpoint type %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) 			 usb_endpoint_type(ep_desc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) 		usb_free_urb(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) 	dev_dbg(&serial->interface->dev, "%s - using urb %p for %s endpoint %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) 	    __func__, urb, ep_type_name, endpoint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) 	return urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) static struct callbacks {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) 	void	(*instat_callback)(struct urb *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) 	void	(*glocont_callback)(struct urb *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) 	void	(*indat_callback)(struct urb *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) 	void	(*outdat_callback)(struct urb *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) 	void	(*inack_callback)(struct urb *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) 	void	(*outcont_callback)(struct urb *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) } keyspan_callbacks[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) 		/* msg_usa26 callbacks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) 		.instat_callback =	usa26_instat_callback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) 		.glocont_callback =	usa26_glocont_callback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) 		.indat_callback =	usa26_indat_callback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) 		.outdat_callback =	usa2x_outdat_callback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) 		.inack_callback =	usa26_inack_callback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) 		.outcont_callback =	usa26_outcont_callback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) 	}, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) 		/* msg_usa28 callbacks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) 		.instat_callback =	usa28_instat_callback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) 		.glocont_callback =	usa28_glocont_callback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) 		.indat_callback =	usa28_indat_callback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) 		.outdat_callback =	usa2x_outdat_callback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) 		.inack_callback =	usa28_inack_callback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) 		.outcont_callback =	usa28_outcont_callback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) 	}, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) 		/* msg_usa49 callbacks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) 		.instat_callback =	usa49_instat_callback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) 		.glocont_callback =	usa49_glocont_callback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) 		.indat_callback =	usa49_indat_callback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) 		.outdat_callback =	usa2x_outdat_callback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) 		.inack_callback =	usa49_inack_callback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) 		.outcont_callback =	usa49_outcont_callback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) 	}, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) 		/* msg_usa90 callbacks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) 		.instat_callback =	usa90_instat_callback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) 		.glocont_callback =	usa28_glocont_callback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) 		.indat_callback =	usa90_indat_callback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) 		.outdat_callback =	usa2x_outdat_callback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) 		.inack_callback =	usa28_inack_callback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) 		.outcont_callback =	usa90_outcont_callback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) 	}, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) 		/* msg_usa67 callbacks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) 		.instat_callback =	usa67_instat_callback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) 		.glocont_callback =	usa67_glocont_callback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) 		.indat_callback =	usa26_indat_callback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) 		.outdat_callback =	usa2x_outdat_callback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) 		.inack_callback =	usa26_inack_callback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) 		.outcont_callback =	usa26_outcont_callback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) 	/* Generic setup urbs function that uses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) 	   data in device_details */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) static void keyspan_setup_urbs(struct usb_serial *serial)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) 	struct keyspan_serial_private 	*s_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) 	const struct keyspan_device_details	*d_details;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) 	struct callbacks		*cback;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) 	s_priv = usb_get_serial_data(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) 	d_details = s_priv->device_details;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) 	/* Setup values for the various callback routines */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) 	cback = &keyspan_callbacks[d_details->msg_format];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) 	/* Allocate and set up urbs for each one that is in use,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) 	   starting with instat endpoints */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) 	s_priv->instat_urb = keyspan_setup_urb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) 		(serial, d_details->instat_endpoint, USB_DIR_IN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) 		 serial, s_priv->instat_buf, INSTAT_BUFLEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) 		 cback->instat_callback);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) 	s_priv->indat_urb = keyspan_setup_urb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) 		(serial, d_details->indat_endpoint, USB_DIR_IN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) 		 serial, s_priv->indat_buf, INDAT49W_BUFLEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) 		 usa49wg_indat_callback);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) 	s_priv->glocont_urb = keyspan_setup_urb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) 		(serial, d_details->glocont_endpoint, USB_DIR_OUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) 		 serial, s_priv->glocont_buf, GLOCONT_BUFLEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) 		 cback->glocont_callback);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) /* usa19 function doesn't require prescaler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) static int keyspan_usa19_calc_baud(struct usb_serial_port *port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) 				   u32 baud_rate, u32 baudclk, u8 *rate_hi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) 				   u8 *rate_low, u8 *prescaler, int portnum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) 	u32 	b16,	/* baud rate times 16 (actual rate used internally) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) 		div,	/* divisor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) 		cnt;	/* inverse of divisor (programmed into 8051) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) 	dev_dbg(&port->dev, "%s - %d.\n", __func__, baud_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) 	/* prevent divide by zero...  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) 	b16 = baud_rate * 16L;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) 	if (b16 == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) 		return KEYSPAN_INVALID_BAUD_RATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) 	/* Any "standard" rate over 57k6 is marginal on the USA-19
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) 	   as we run out of divisor resolution. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) 	if (baud_rate > 57600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) 		return KEYSPAN_INVALID_BAUD_RATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) 	/* calculate the divisor and the counter (its inverse) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) 	div = baudclk / b16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) 	if (div == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) 		return KEYSPAN_INVALID_BAUD_RATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) 		cnt = 0 - div;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) 	if (div > 0xffff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) 		return KEYSPAN_INVALID_BAUD_RATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) 	/* return the counter values if non-null */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) 	if (rate_low)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) 		*rate_low = (u8) (cnt & 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) 	if (rate_hi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) 		*rate_hi = (u8) ((cnt >> 8) & 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) 	if (rate_low && rate_hi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) 		dev_dbg(&port->dev, "%s - %d %02x %02x.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) 				__func__, baud_rate, *rate_hi, *rate_low);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) 	return KEYSPAN_BAUD_RATE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) /* usa19hs function doesn't require prescaler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) static int keyspan_usa19hs_calc_baud(struct usb_serial_port *port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) 				     u32 baud_rate, u32 baudclk, u8 *rate_hi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) 				     u8 *rate_low, u8 *prescaler, int portnum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) 	u32 	b16,	/* baud rate times 16 (actual rate used internally) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) 			div;	/* divisor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) 	dev_dbg(&port->dev, "%s - %d.\n", __func__, baud_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) 	/* prevent divide by zero...  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) 	b16 = baud_rate * 16L;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) 	if (b16 == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) 		return KEYSPAN_INVALID_BAUD_RATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) 	/* calculate the divisor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) 	div = baudclk / b16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) 	if (div == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) 		return KEYSPAN_INVALID_BAUD_RATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) 	if (div > 0xffff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) 		return KEYSPAN_INVALID_BAUD_RATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) 	/* return the counter values if non-null */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) 	if (rate_low)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) 		*rate_low = (u8) (div & 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) 	if (rate_hi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) 		*rate_hi = (u8) ((div >> 8) & 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) 	if (rate_low && rate_hi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) 		dev_dbg(&port->dev, "%s - %d %02x %02x.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) 			__func__, baud_rate, *rate_hi, *rate_low);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) 	return KEYSPAN_BAUD_RATE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) static int keyspan_usa19w_calc_baud(struct usb_serial_port *port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) 				    u32 baud_rate, u32 baudclk, u8 *rate_hi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) 				    u8 *rate_low, u8 *prescaler, int portnum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) 	u32 	b16,	/* baud rate times 16 (actual rate used internally) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) 		clk,	/* clock with 13/8 prescaler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) 		div,	/* divisor using 13/8 prescaler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) 		res,	/* resulting baud rate using 13/8 prescaler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) 		diff,	/* error using 13/8 prescaler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) 		smallest_diff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) 	u8	best_prescaler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) 	int	i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) 	dev_dbg(&port->dev, "%s - %d.\n", __func__, baud_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) 	/* prevent divide by zero */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) 	b16 = baud_rate * 16L;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) 	if (b16 == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) 		return KEYSPAN_INVALID_BAUD_RATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) 	/* Calculate prescaler by trying them all and looking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) 	   for best fit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) 	/* start with largest possible difference */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) 	smallest_diff = 0xffffffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) 		/* 0 is an invalid prescaler, used as a flag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) 	best_prescaler = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) 	for (i = 8; i <= 0xff; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) 		clk = (baudclk * 8) / (u32) i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) 		div = clk / b16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) 		if (div == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) 		res = clk / div;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) 		diff = (res > b16) ? (res-b16) : (b16-res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) 		if (diff < smallest_diff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) 			best_prescaler = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) 			smallest_diff = diff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) 	if (best_prescaler == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) 		return KEYSPAN_INVALID_BAUD_RATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) 	clk = (baudclk * 8) / (u32) best_prescaler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) 	div = clk / b16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) 	/* return the divisor and prescaler if non-null */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) 	if (rate_low)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) 		*rate_low = (u8) (div & 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) 	if (rate_hi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) 		*rate_hi = (u8) ((div >> 8) & 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) 	if (prescaler) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) 		*prescaler = best_prescaler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) 		/*  dev_dbg(&port->dev, "%s - %d %d\n", __func__, *prescaler, div); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) 	return KEYSPAN_BAUD_RATE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) 	/* USA-28 supports different maximum baud rates on each port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) static int keyspan_usa28_calc_baud(struct usb_serial_port *port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) 				   u32 baud_rate, u32 baudclk, u8 *rate_hi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) 				   u8 *rate_low, u8 *prescaler, int portnum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) 	u32 	b16,	/* baud rate times 16 (actual rate used internally) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) 		div,	/* divisor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) 		cnt;	/* inverse of divisor (programmed into 8051) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) 	dev_dbg(&port->dev, "%s - %d.\n", __func__, baud_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) 		/* prevent divide by zero */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) 	b16 = baud_rate * 16L;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) 	if (b16 == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) 		return KEYSPAN_INVALID_BAUD_RATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) 	/* calculate the divisor and the counter (its inverse) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) 	div = KEYSPAN_USA28_BAUDCLK / b16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) 	if (div == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) 		return KEYSPAN_INVALID_BAUD_RATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) 		cnt = 0 - div;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) 	/* check for out of range, based on portnum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) 	   and return result */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) 	if (portnum == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) 		if (div > 0xffff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) 			return KEYSPAN_INVALID_BAUD_RATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) 		if (portnum == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) 			if (div > 0xff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) 				return KEYSPAN_INVALID_BAUD_RATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) 			return KEYSPAN_INVALID_BAUD_RATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) 		/* return the counter values if not NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) 		   (port 1 will ignore retHi) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) 	if (rate_low)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) 		*rate_low = (u8) (cnt & 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) 	if (rate_hi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) 		*rate_hi = (u8) ((cnt >> 8) & 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) 	dev_dbg(&port->dev, "%s - %d OK.\n", __func__, baud_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) 	return KEYSPAN_BAUD_RATE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) static int keyspan_usa26_send_setup(struct usb_serial *serial,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) 				    struct usb_serial_port *port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) 				    int reset_port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) 	struct keyspan_usa26_portControlMessage	msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) 	struct keyspan_serial_private 		*s_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) 	struct keyspan_port_private 		*p_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) 	const struct keyspan_device_details	*d_details;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) 	struct urb				*this_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) 	int 					device_port, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) 	dev_dbg(&port->dev, "%s reset=%d\n", __func__, reset_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) 	s_priv = usb_get_serial_data(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) 	p_priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) 	d_details = s_priv->device_details;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) 	device_port = port->port_number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) 	this_urb = p_priv->outcont_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) 		/* Make sure we have an urb then send the message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) 	if (this_urb == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) 		dev_dbg(&port->dev, "%s - oops no urb.\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) 	dev_dbg(&port->dev, "%s - endpoint %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) 			__func__, usb_pipeendpoint(this_urb->pipe));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) 	/* Save reset port val for resend.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) 	   Don't overwrite resend for open/close condition. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) 	if ((reset_port + 1) > p_priv->resend_cont)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) 		p_priv->resend_cont = reset_port + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) 	if (this_urb->status == -EINPROGRESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) 		/*  dev_dbg(&port->dev, "%s - already writing\n", __func__); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) 		mdelay(5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) 	memset(&msg, 0, sizeof(struct keyspan_usa26_portControlMessage));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) 	/* Only set baud rate if it's changed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) 	if (p_priv->old_baud != p_priv->baud) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) 		p_priv->old_baud = p_priv->baud;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) 		msg.setClocking = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) 		if (d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) 						   &msg.baudHi, &msg.baudLo, &msg.prescaler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) 						   device_port) == KEYSPAN_INVALID_BAUD_RATE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) 			dev_dbg(&port->dev, "%s - Invalid baud rate %d requested, using 9600.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) 				__func__, p_priv->baud);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) 			msg.baudLo = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) 			msg.baudHi = 125;	/* Values for 9600 baud */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) 			msg.prescaler = 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) 		msg.setPrescaler = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) 	msg.lcr = (p_priv->cflag & CSTOPB) ? STOPBITS_678_2 : STOPBITS_5678_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) 	switch (p_priv->cflag & CSIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) 	case CS5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) 		msg.lcr |= USA_DATABITS_5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) 	case CS6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) 		msg.lcr |= USA_DATABITS_6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) 	case CS7:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) 		msg.lcr |= USA_DATABITS_7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) 	case CS8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) 		msg.lcr |= USA_DATABITS_8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) 	if (p_priv->cflag & PARENB) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) 		/* note USA_PARITY_NONE == 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) 		msg.lcr |= (p_priv->cflag & PARODD) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) 			USA_PARITY_ODD : USA_PARITY_EVEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) 	msg.setLcr = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) 	msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) 	msg.xonFlowControl = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) 	msg.setFlowControl = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) 	msg.forwardingLength = 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) 	msg.xonChar = 17;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) 	msg.xoffChar = 19;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) 	/* Opening port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) 	if (reset_port == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) 		msg._txOn = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) 		msg._txOff = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) 		msg.txFlush = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) 		msg.txBreak = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) 		msg.rxOn = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) 		msg.rxOff = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) 		msg.rxFlush = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) 		msg.rxForward = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) 		msg.returnStatus = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) 		msg.resetDataToggle = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) 	/* Closing port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) 	else if (reset_port == 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) 		msg._txOn = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) 		msg._txOff = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) 		msg.txFlush = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) 		msg.txBreak = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) 		msg.rxOn = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) 		msg.rxOff = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) 		msg.rxFlush = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) 		msg.rxForward = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) 		msg.returnStatus = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) 		msg.resetDataToggle = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) 	/* Sending intermediate configs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) 		msg._txOn = (!p_priv->break_on);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) 		msg._txOff = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) 		msg.txFlush = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) 		msg.txBreak = (p_priv->break_on);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) 		msg.rxOn = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) 		msg.rxOff = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) 		msg.rxFlush = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) 		msg.rxForward = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) 		msg.returnStatus = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) 		msg.resetDataToggle = 0x0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) 	/* Do handshaking outputs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) 	msg.setTxTriState_setRts = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) 	msg.txTriState_rts = p_priv->rts_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) 	msg.setHskoa_setDtr = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) 	msg.hskoa_dtr = p_priv->dtr_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) 	p_priv->resend_cont = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) 	memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) 	/* send the data out the device on control endpoint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) 	this_urb->transfer_buffer_length = sizeof(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) 	err = usb_submit_urb(this_urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) 	if (err != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) 		dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed (%d)\n", __func__, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) static int keyspan_usa28_send_setup(struct usb_serial *serial,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) 				    struct usb_serial_port *port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) 				    int reset_port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) 	struct keyspan_usa28_portControlMessage	msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) 	struct keyspan_serial_private	 	*s_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) 	struct keyspan_port_private 		*p_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) 	const struct keyspan_device_details	*d_details;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) 	struct urb				*this_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) 	int 					device_port, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) 	s_priv = usb_get_serial_data(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) 	p_priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) 	d_details = s_priv->device_details;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) 	device_port = port->port_number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) 	/* only do something if we have a bulk out endpoint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) 	this_urb = p_priv->outcont_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) 	if (this_urb == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) 		dev_dbg(&port->dev, "%s - oops no urb.\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) 	/* Save reset port val for resend.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216) 	   Don't overwrite resend for open/close condition. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) 	if ((reset_port + 1) > p_priv->resend_cont)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) 		p_priv->resend_cont = reset_port + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219) 	if (this_urb->status == -EINPROGRESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) 		dev_dbg(&port->dev, "%s already writing\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) 		mdelay(5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) 	memset(&msg, 0, sizeof(struct keyspan_usa28_portControlMessage));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) 	msg.setBaudRate = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) 	if (d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) 					   &msg.baudHi, &msg.baudLo, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) 					   device_port) == KEYSPAN_INVALID_BAUD_RATE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) 		dev_dbg(&port->dev, "%s - Invalid baud rate requested %d.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) 						__func__, p_priv->baud);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) 		msg.baudLo = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) 		msg.baudHi = 0xb2;	/* Values for 9600 baud */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) 	/* If parity is enabled, we must calculate it ourselves. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238) 	msg.parity = 0;		/* XXX for now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) 	msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) 	msg.xonFlowControl = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) 	/* Do handshaking outputs, DTR is inverted relative to RTS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) 	msg.rts = p_priv->rts_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245) 	msg.dtr = p_priv->dtr_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) 	msg.forwardingLength = 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248) 	msg.forwardMs = 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249) 	msg.breakThreshold = 45;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250) 	msg.xonChar = 17;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) 	msg.xoffChar = 19;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) 	/*msg.returnStatus = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) 	msg.resetDataToggle = 0xff;*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255) 	/* Opening port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) 	if (reset_port == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) 		msg._txOn = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) 		msg._txOff = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) 		msg.txFlush = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260) 		msg.txForceXoff = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261) 		msg.txBreak = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) 		msg.rxOn = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) 		msg.rxOff = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264) 		msg.rxFlush = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265) 		msg.rxForward = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) 		msg.returnStatus = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267) 		msg.resetDataToggle = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269) 	/* Closing port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) 	else if (reset_port == 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) 		msg._txOn = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) 		msg._txOff = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273) 		msg.txFlush = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274) 		msg.txForceXoff = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275) 		msg.txBreak = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) 		msg.rxOn = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) 		msg.rxOff = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) 		msg.rxFlush = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) 		msg.rxForward = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280) 		msg.returnStatus = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281) 		msg.resetDataToggle = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) 	/* Sending intermediate configs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285) 		msg._txOn = (!p_priv->break_on);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) 		msg._txOff = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287) 		msg.txFlush = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288) 		msg.txForceXoff = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) 		msg.txBreak = (p_priv->break_on);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290) 		msg.rxOn = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) 		msg.rxOff = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) 		msg.rxFlush = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293) 		msg.rxForward = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) 		msg.returnStatus = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) 		msg.resetDataToggle = 0x0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) 	p_priv->resend_cont = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) 	memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301) 	/* send the data out the device on control endpoint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) 	this_urb->transfer_buffer_length = sizeof(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) 	err = usb_submit_urb(this_urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) 	if (err != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) 		dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) static int keyspan_usa49_send_setup(struct usb_serial *serial,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312) 				    struct usb_serial_port *port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) 				    int reset_port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315) 	struct keyspan_usa49_portControlMessage	msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) 	struct usb_ctrlrequest 			*dr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317) 	struct keyspan_serial_private 		*s_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) 	struct keyspan_port_private 		*p_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) 	const struct keyspan_device_details	*d_details;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320) 	struct urb				*this_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) 	int 					err, device_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) 	s_priv = usb_get_serial_data(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) 	p_priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) 	d_details = s_priv->device_details;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) 	this_urb = s_priv->glocont_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) 	/* Work out which port within the device is being setup */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) 	device_port = port->port_number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) 	/* Make sure we have an urb then send the message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) 	if (this_urb == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) 		dev_dbg(&port->dev, "%s - oops no urb for port.\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) 	dev_dbg(&port->dev, "%s - endpoint %x (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) 		__func__, usb_pipeendpoint(this_urb->pipe), device_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) 	/* Save reset port val for resend.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) 	   Don't overwrite resend for open/close condition. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343) 	if ((reset_port + 1) > p_priv->resend_cont)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) 		p_priv->resend_cont = reset_port + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) 	if (this_urb->status == -EINPROGRESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347) 		/*  dev_dbg(&port->dev, "%s - already writing\n", __func__); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348) 		mdelay(5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) 	memset(&msg, 0, sizeof(struct keyspan_usa49_portControlMessage));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) 	msg.portNumber = device_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356) 	/* Only set baud rate if it's changed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357) 	if (p_priv->old_baud != p_priv->baud) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) 		p_priv->old_baud = p_priv->baud;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) 		msg.setClocking = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) 		if (d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361) 						   &msg.baudHi, &msg.baudLo, &msg.prescaler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362) 						   device_port) == KEYSPAN_INVALID_BAUD_RATE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) 			dev_dbg(&port->dev, "%s - Invalid baud rate %d requested, using 9600.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) 				__func__, p_priv->baud);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) 			msg.baudLo = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) 			msg.baudHi = 125;	/* Values for 9600 baud */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) 			msg.prescaler = 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369) 		/* msg.setPrescaler = 0xff; */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) 	msg.lcr = (p_priv->cflag & CSTOPB) ? STOPBITS_678_2 : STOPBITS_5678_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373) 	switch (p_priv->cflag & CSIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) 	case CS5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) 		msg.lcr |= USA_DATABITS_5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377) 	case CS6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378) 		msg.lcr |= USA_DATABITS_6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) 	case CS7:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) 		msg.lcr |= USA_DATABITS_7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) 	case CS8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384) 		msg.lcr |= USA_DATABITS_8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) 	if (p_priv->cflag & PARENB) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) 		/* note USA_PARITY_NONE == 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) 		msg.lcr |= (p_priv->cflag & PARODD) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390) 			USA_PARITY_ODD : USA_PARITY_EVEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) 	msg.setLcr = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394) 	msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) 	msg.xonFlowControl = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396) 	msg.setFlowControl = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) 	msg.forwardingLength = 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399) 	msg.xonChar = 17;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400) 	msg.xoffChar = 19;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402) 	/* Opening port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) 	if (reset_port == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404) 		msg._txOn = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405) 		msg._txOff = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406) 		msg.txFlush = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407) 		msg.txBreak = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) 		msg.rxOn = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409) 		msg.rxOff = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410) 		msg.rxFlush = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411) 		msg.rxForward = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412) 		msg.returnStatus = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413) 		msg.resetDataToggle = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414) 		msg.enablePort = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) 		msg.disablePort = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417) 	/* Closing port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418) 	else if (reset_port == 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419) 		msg._txOn = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420) 		msg._txOff = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421) 		msg.txFlush = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422) 		msg.txBreak = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423) 		msg.rxOn = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424) 		msg.rxOff = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) 		msg.rxFlush = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426) 		msg.rxForward = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427) 		msg.returnStatus = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) 		msg.resetDataToggle = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429) 		msg.enablePort = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430) 		msg.disablePort = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) 	/* Sending intermediate configs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) 		msg._txOn = (!p_priv->break_on);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435) 		msg._txOff = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436) 		msg.txFlush = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) 		msg.txBreak = (p_priv->break_on);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438) 		msg.rxOn = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) 		msg.rxOff = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) 		msg.rxFlush = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441) 		msg.rxForward = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) 		msg.returnStatus = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443) 		msg.resetDataToggle = 0x0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444) 		msg.enablePort = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445) 		msg.disablePort = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) 	/* Do handshaking outputs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449) 	msg.setRts = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450) 	msg.rts = p_priv->rts_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) 	msg.setDtr = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453) 	msg.dtr = p_priv->dtr_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455) 	p_priv->resend_cont = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457) 	/* if the device is a 49wg, we send control message on usb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) 	   control EP 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460) 	if (d_details->product_id == keyspan_usa49wg_product_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461) 		dr = (void *)(s_priv->ctrl_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462) 		dr->bRequestType = USB_TYPE_VENDOR | USB_DIR_OUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463) 		dr->bRequest = 0xB0;	/* 49wg control message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) 		dr->wValue = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465) 		dr->wIndex = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) 		dr->wLength = cpu_to_le16(sizeof(msg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468) 		memcpy(s_priv->glocont_buf, &msg, sizeof(msg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) 		usb_fill_control_urb(this_urb, serial->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471) 				usb_sndctrlpipe(serial->dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472) 				(unsigned char *)dr, s_priv->glocont_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473) 				sizeof(msg), usa49_glocont_callback, serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476) 		memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) 		/* send the data out the device on control endpoint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) 		this_urb->transfer_buffer_length = sizeof(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481) 	err = usb_submit_urb(this_urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482) 	if (err != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) 		dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed (%d)\n", __func__, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) static int keyspan_usa90_send_setup(struct usb_serial *serial,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) 				    struct usb_serial_port *port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490) 				    int reset_port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492) 	struct keyspan_usa90_portControlMessage	msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493) 	struct keyspan_serial_private 		*s_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494) 	struct keyspan_port_private 		*p_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495) 	const struct keyspan_device_details	*d_details;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) 	struct urb				*this_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497) 	int 					err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) 	u8						prescaler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500) 	s_priv = usb_get_serial_data(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501) 	p_priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) 	d_details = s_priv->device_details;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) 	/* only do something if we have a bulk out endpoint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) 	this_urb = p_priv->outcont_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506) 	if (this_urb == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507) 		dev_dbg(&port->dev, "%s - oops no urb.\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511) 	/* Save reset port val for resend.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512) 	   Don't overwrite resend for open/close condition. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513) 	if ((reset_port + 1) > p_priv->resend_cont)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514) 		p_priv->resend_cont = reset_port + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515) 	if (this_urb->status == -EINPROGRESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516) 		dev_dbg(&port->dev, "%s already writing\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517) 		mdelay(5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521) 	memset(&msg, 0, sizeof(struct keyspan_usa90_portControlMessage));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523) 	/* Only set baud rate if it's changed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524) 	if (p_priv->old_baud != p_priv->baud) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525) 		p_priv->old_baud = p_priv->baud;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526) 		msg.setClocking = 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527) 		if (d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528) 						   &msg.baudHi, &msg.baudLo, &prescaler, 0) == KEYSPAN_INVALID_BAUD_RATE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529) 			dev_dbg(&port->dev, "%s - Invalid baud rate %d requested, using 9600.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530) 				__func__, p_priv->baud);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531) 			p_priv->baud = 9600;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532) 			d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533) 				&msg.baudHi, &msg.baudLo, &prescaler, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535) 		msg.setRxMode = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536) 		msg.setTxMode = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539) 	/* modes must always be correctly specified */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540) 	if (p_priv->baud > 57600) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541) 		msg.rxMode = RXMODE_DMA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542) 		msg.txMode = TXMODE_DMA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544) 		msg.rxMode = RXMODE_BYHAND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545) 		msg.txMode = TXMODE_BYHAND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548) 	msg.lcr = (p_priv->cflag & CSTOPB) ? STOPBITS_678_2 : STOPBITS_5678_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549) 	switch (p_priv->cflag & CSIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550) 	case CS5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551) 		msg.lcr |= USA_DATABITS_5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553) 	case CS6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554) 		msg.lcr |= USA_DATABITS_6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556) 	case CS7:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557) 		msg.lcr |= USA_DATABITS_7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559) 	case CS8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560) 		msg.lcr |= USA_DATABITS_8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563) 	if (p_priv->cflag & PARENB) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564) 		/* note USA_PARITY_NONE == 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565) 		msg.lcr |= (p_priv->cflag & PARODD) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566) 			USA_PARITY_ODD : USA_PARITY_EVEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568) 	if (p_priv->old_cflag != p_priv->cflag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569) 		p_priv->old_cflag = p_priv->cflag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570) 		msg.setLcr = 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573) 	if (p_priv->flow_control == flow_cts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574) 		msg.txFlowControl = TXFLOW_CTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575) 	msg.setTxFlowControl = 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576) 	msg.setRxFlowControl = 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578) 	msg.rxForwardingLength = 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579) 	msg.rxForwardingTimeout = 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580) 	msg.txAckSetting = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581) 	msg.xonChar = 17;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582) 	msg.xoffChar = 19;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584) 	/* Opening port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585) 	if (reset_port == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586) 		msg.portEnabled = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587) 		msg.rxFlush = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588) 		msg.txBreak = (p_priv->break_on);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590) 	/* Closing port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591) 	else if (reset_port == 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592) 		msg.portEnabled = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593) 	/* Sending intermediate configs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595) 		msg.portEnabled = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596) 		msg.txBreak = (p_priv->break_on);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599) 	/* Do handshaking outputs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2600) 	msg.setRts = 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2601) 	msg.rts = p_priv->rts_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603) 	msg.setDtr = 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604) 	msg.dtr = p_priv->dtr_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606) 	p_priv->resend_cont = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607) 	memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609) 	/* send the data out the device on control endpoint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610) 	this_urb->transfer_buffer_length = sizeof(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612) 	err = usb_submit_urb(this_urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613) 	if (err != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614) 		dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed (%d)\n", __func__, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2615) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2616) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2617) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2618) static int keyspan_usa67_send_setup(struct usb_serial *serial,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2619) 				    struct usb_serial_port *port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2620) 				    int reset_port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2621) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2622) 	struct keyspan_usa67_portControlMessage	msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2623) 	struct keyspan_serial_private 		*s_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2624) 	struct keyspan_port_private 		*p_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2625) 	const struct keyspan_device_details	*d_details;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2626) 	struct urb				*this_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2627) 	int 					err, device_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2628) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2629) 	s_priv = usb_get_serial_data(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2630) 	p_priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2631) 	d_details = s_priv->device_details;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2632) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2633) 	this_urb = s_priv->glocont_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2635) 	/* Work out which port within the device is being setup */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2636) 	device_port = port->port_number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2638) 	/* Make sure we have an urb then send the message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2639) 	if (this_urb == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2640) 		dev_dbg(&port->dev, "%s - oops no urb for port.\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2641) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2642) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2643) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2644) 	/* Save reset port val for resend.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2645) 	   Don't overwrite resend for open/close condition. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2646) 	if ((reset_port + 1) > p_priv->resend_cont)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2647) 		p_priv->resend_cont = reset_port + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2648) 	if (this_urb->status == -EINPROGRESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2649) 		/*  dev_dbg(&port->dev, "%s - already writing\n", __func__); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2650) 		mdelay(5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2651) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2652) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2653) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2654) 	memset(&msg, 0, sizeof(struct keyspan_usa67_portControlMessage));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2655) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2656) 	msg.port = device_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2657) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2658) 	/* Only set baud rate if it's changed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2659) 	if (p_priv->old_baud != p_priv->baud) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2660) 		p_priv->old_baud = p_priv->baud;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2661) 		msg.setClocking = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2662) 		if (d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2663) 						   &msg.baudHi, &msg.baudLo, &msg.prescaler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2664) 						   device_port) == KEYSPAN_INVALID_BAUD_RATE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2665) 			dev_dbg(&port->dev, "%s - Invalid baud rate %d requested, using 9600.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2666) 				__func__, p_priv->baud);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2667) 			msg.baudLo = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2668) 			msg.baudHi = 125;	/* Values for 9600 baud */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2669) 			msg.prescaler = 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2670) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2671) 		msg.setPrescaler = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2672) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2673) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2674) 	msg.lcr = (p_priv->cflag & CSTOPB) ? STOPBITS_678_2 : STOPBITS_5678_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2675) 	switch (p_priv->cflag & CSIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2676) 	case CS5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2677) 		msg.lcr |= USA_DATABITS_5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2678) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2679) 	case CS6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2680) 		msg.lcr |= USA_DATABITS_6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2681) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2682) 	case CS7:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2683) 		msg.lcr |= USA_DATABITS_7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2684) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2685) 	case CS8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2686) 		msg.lcr |= USA_DATABITS_8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2687) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2688) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2689) 	if (p_priv->cflag & PARENB) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2690) 		/* note USA_PARITY_NONE == 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2691) 		msg.lcr |= (p_priv->cflag & PARODD) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2692) 					USA_PARITY_ODD : USA_PARITY_EVEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2693) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2694) 	msg.setLcr = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2695) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2696) 	msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2697) 	msg.xonFlowControl = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2698) 	msg.setFlowControl = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2699) 	msg.forwardingLength = 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2700) 	msg.xonChar = 17;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2701) 	msg.xoffChar = 19;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2702) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2703) 	if (reset_port == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2704) 		/* Opening port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2705) 		msg._txOn = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2706) 		msg._txOff = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2707) 		msg.txFlush = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2708) 		msg.txBreak = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2709) 		msg.rxOn = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2710) 		msg.rxOff = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2711) 		msg.rxFlush = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2712) 		msg.rxForward = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2713) 		msg.returnStatus = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2714) 		msg.resetDataToggle = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2715) 	} else if (reset_port == 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2716) 		/* Closing port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2717) 		msg._txOn = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2718) 		msg._txOff = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2719) 		msg.txFlush = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2720) 		msg.txBreak = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2721) 		msg.rxOn = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2722) 		msg.rxOff = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2723) 		msg.rxFlush = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2724) 		msg.rxForward = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2725) 		msg.returnStatus = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2726) 		msg.resetDataToggle = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2727) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2728) 		/* Sending intermediate configs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2729) 		msg._txOn = (!p_priv->break_on);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2730) 		msg._txOff = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2731) 		msg.txFlush = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2732) 		msg.txBreak = (p_priv->break_on);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2733) 		msg.rxOn = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2734) 		msg.rxOff = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2735) 		msg.rxFlush = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2736) 		msg.rxForward = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2737) 		msg.returnStatus = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2738) 		msg.resetDataToggle = 0x0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2739) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2740) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2741) 	/* Do handshaking outputs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2742) 	msg.setTxTriState_setRts = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2743) 	msg.txTriState_rts = p_priv->rts_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2744) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2745) 	msg.setHskoa_setDtr = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2746) 	msg.hskoa_dtr = p_priv->dtr_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2747) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2748) 	p_priv->resend_cont = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2749) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2750) 	memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2751) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2752) 	/* send the data out the device on control endpoint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2753) 	this_urb->transfer_buffer_length = sizeof(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2754) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2755) 	err = usb_submit_urb(this_urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2756) 	if (err != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2757) 		dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed (%d)\n", __func__, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2758) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2759) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2760) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2761) static void keyspan_send_setup(struct usb_serial_port *port, int reset_port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2762) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2763) 	struct usb_serial *serial = port->serial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2764) 	struct keyspan_serial_private *s_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2765) 	const struct keyspan_device_details *d_details;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2766) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2767) 	s_priv = usb_get_serial_data(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2768) 	d_details = s_priv->device_details;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2769) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2770) 	switch (d_details->msg_format) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2771) 	case msg_usa26:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2772) 		keyspan_usa26_send_setup(serial, port, reset_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2773) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2774) 	case msg_usa28:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2775) 		keyspan_usa28_send_setup(serial, port, reset_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2776) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2777) 	case msg_usa49:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2778) 		keyspan_usa49_send_setup(serial, port, reset_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2779) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2780) 	case msg_usa90:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2781) 		keyspan_usa90_send_setup(serial, port, reset_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2782) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2783) 	case msg_usa67:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2784) 		keyspan_usa67_send_setup(serial, port, reset_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2785) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2786) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2787) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2788) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2789) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2790) /* Gets called by the "real" driver (ie once firmware is loaded
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2791)    and renumeration has taken place. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2792) static int keyspan_startup(struct usb_serial *serial)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2793) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2794) 	int				i, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2795) 	struct keyspan_serial_private 	*s_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2796) 	const struct keyspan_device_details	*d_details;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2797) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2798) 	for (i = 0; (d_details = keyspan_devices[i]) != NULL; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2799) 		if (d_details->product_id ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2800) 				le16_to_cpu(serial->dev->descriptor.idProduct))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2801) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2802) 	if (d_details == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2803) 		dev_err(&serial->dev->dev, "%s - unknown product id %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2804) 		    __func__, le16_to_cpu(serial->dev->descriptor.idProduct));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2805) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2806) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2807) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2808) 	/* Setup private data for serial driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2809) 	s_priv = kzalloc(sizeof(struct keyspan_serial_private), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2810) 	if (!s_priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2811) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2812) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2813) 	s_priv->instat_buf = kzalloc(INSTAT_BUFLEN, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2814) 	if (!s_priv->instat_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2815) 		goto err_instat_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2816) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2817) 	s_priv->indat_buf = kzalloc(INDAT49W_BUFLEN, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2818) 	if (!s_priv->indat_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2819) 		goto err_indat_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2820) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2821) 	s_priv->glocont_buf = kzalloc(GLOCONT_BUFLEN, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2822) 	if (!s_priv->glocont_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2823) 		goto err_glocont_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2824) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2825) 	s_priv->ctrl_buf = kzalloc(sizeof(struct usb_ctrlrequest), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2826) 	if (!s_priv->ctrl_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2827) 		goto err_ctrl_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2828) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2829) 	s_priv->device_details = d_details;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2830) 	usb_set_serial_data(serial, s_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2831) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2832) 	keyspan_setup_urbs(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2833) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2834) 	if (s_priv->instat_urb != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2835) 		err = usb_submit_urb(s_priv->instat_urb, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2836) 		if (err != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2837) 			dev_dbg(&serial->dev->dev, "%s - submit instat urb failed %d\n", __func__, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2838) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2839) 	if (s_priv->indat_urb != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2840) 		err = usb_submit_urb(s_priv->indat_urb, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2841) 		if (err != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2842) 			dev_dbg(&serial->dev->dev, "%s - submit indat urb failed %d\n", __func__, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2843) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2844) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2845) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2846) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2847) err_ctrl_buf:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2848) 	kfree(s_priv->glocont_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2849) err_glocont_buf:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2850) 	kfree(s_priv->indat_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2851) err_indat_buf:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2852) 	kfree(s_priv->instat_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2853) err_instat_buf:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2854) 	kfree(s_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2855) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2856) 	return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2857) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2858) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2859) static void keyspan_disconnect(struct usb_serial *serial)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2860) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2861) 	struct keyspan_serial_private *s_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2862) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2863) 	s_priv = usb_get_serial_data(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2864) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2865) 	usb_kill_urb(s_priv->instat_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2866) 	usb_kill_urb(s_priv->glocont_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2867) 	usb_kill_urb(s_priv->indat_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2868) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2869) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2870) static void keyspan_release(struct usb_serial *serial)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2871) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2872) 	struct keyspan_serial_private *s_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2873) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2874) 	s_priv = usb_get_serial_data(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2875) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2876) 	/* Make sure to unlink the URBs submitted in attach. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2877) 	usb_kill_urb(s_priv->instat_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2878) 	usb_kill_urb(s_priv->indat_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2879) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2880) 	usb_free_urb(s_priv->instat_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2881) 	usb_free_urb(s_priv->indat_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2882) 	usb_free_urb(s_priv->glocont_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2883) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2884) 	kfree(s_priv->ctrl_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2885) 	kfree(s_priv->glocont_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2886) 	kfree(s_priv->indat_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2887) 	kfree(s_priv->instat_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2888) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2889) 	kfree(s_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2890) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2891) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2892) static int keyspan_port_probe(struct usb_serial_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2893) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2894) 	struct usb_serial *serial = port->serial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2895) 	struct keyspan_serial_private *s_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2896) 	struct keyspan_port_private *p_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2897) 	const struct keyspan_device_details *d_details;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2898) 	struct callbacks *cback;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2899) 	int endp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2900) 	int port_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2901) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2902) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2903) 	s_priv = usb_get_serial_data(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2904) 	d_details = s_priv->device_details;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2905) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2906) 	p_priv = kzalloc(sizeof(*p_priv), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2907) 	if (!p_priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2908) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2909) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2910) 	for (i = 0; i < ARRAY_SIZE(p_priv->in_buffer); ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2911) 		p_priv->in_buffer[i] = kzalloc(IN_BUFLEN, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2912) 		if (!p_priv->in_buffer[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2913) 			goto err_free_in_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2914) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2915) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2916) 	for (i = 0; i < ARRAY_SIZE(p_priv->out_buffer); ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2917) 		p_priv->out_buffer[i] = kzalloc(OUT_BUFLEN, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2918) 		if (!p_priv->out_buffer[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2919) 			goto err_free_out_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2920) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2921) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2922) 	p_priv->inack_buffer = kzalloc(INACK_BUFLEN, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2923) 	if (!p_priv->inack_buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2924) 		goto err_free_out_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2925) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2926) 	p_priv->outcont_buffer = kzalloc(OUTCONT_BUFLEN, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2927) 	if (!p_priv->outcont_buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2928) 		goto err_free_inack_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2929) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2930) 	p_priv->device_details = d_details;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2931) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2932) 	/* Setup values for the various callback routines */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2933) 	cback = &keyspan_callbacks[d_details->msg_format];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2934) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2935) 	port_num = port->port_number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2936) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2937) 	/* Do indat endpoints first, once for each flip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2938) 	endp = d_details->indat_endpoints[port_num];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2939) 	for (i = 0; i <= d_details->indat_endp_flip; ++i, ++endp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2940) 		p_priv->in_urbs[i] = keyspan_setup_urb(serial, endp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2941) 						USB_DIR_IN, port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2942) 						p_priv->in_buffer[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2943) 						IN_BUFLEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2944) 						cback->indat_callback);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2945) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2946) 	/* outdat endpoints also have flip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2947) 	endp = d_details->outdat_endpoints[port_num];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2948) 	for (i = 0; i <= d_details->outdat_endp_flip; ++i, ++endp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2949) 		p_priv->out_urbs[i] = keyspan_setup_urb(serial, endp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2950) 						USB_DIR_OUT, port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2951) 						p_priv->out_buffer[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2952) 						OUT_BUFLEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2953) 						cback->outdat_callback);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2954) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2955) 	/* inack endpoint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2956) 	p_priv->inack_urb = keyspan_setup_urb(serial,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2957) 					d_details->inack_endpoints[port_num],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2958) 					USB_DIR_IN, port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2959) 					p_priv->inack_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2960) 					INACK_BUFLEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2961) 					cback->inack_callback);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2962) 	/* outcont endpoint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2963) 	p_priv->outcont_urb = keyspan_setup_urb(serial,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2964) 					d_details->outcont_endpoints[port_num],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2965) 					USB_DIR_OUT, port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2966) 					p_priv->outcont_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2967) 					OUTCONT_BUFLEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2968) 					 cback->outcont_callback);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2969) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2970) 	usb_set_serial_port_data(port, p_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2971) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2972) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2973) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2974) err_free_inack_buffer:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2975) 	kfree(p_priv->inack_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2976) err_free_out_buffer:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2977) 	for (i = 0; i < ARRAY_SIZE(p_priv->out_buffer); ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2978) 		kfree(p_priv->out_buffer[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2979) err_free_in_buffer:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2980) 	for (i = 0; i < ARRAY_SIZE(p_priv->in_buffer); ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2981) 		kfree(p_priv->in_buffer[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2982) 	kfree(p_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2983) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2984) 	return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2985) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2986) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2987) static int keyspan_port_remove(struct usb_serial_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2988) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2989) 	struct keyspan_port_private *p_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2990) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2991) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2992) 	p_priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2993) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2994) 	usb_kill_urb(p_priv->inack_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2995) 	usb_kill_urb(p_priv->outcont_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2996) 	for (i = 0; i < 2; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2997) 		usb_kill_urb(p_priv->in_urbs[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2998) 		usb_kill_urb(p_priv->out_urbs[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2999) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3000) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3001) 	usb_free_urb(p_priv->inack_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3002) 	usb_free_urb(p_priv->outcont_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3003) 	for (i = 0; i < 2; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3004) 		usb_free_urb(p_priv->in_urbs[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3005) 		usb_free_urb(p_priv->out_urbs[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3006) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3007) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3008) 	kfree(p_priv->outcont_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3009) 	kfree(p_priv->inack_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3010) 	for (i = 0; i < ARRAY_SIZE(p_priv->out_buffer); ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3011) 		kfree(p_priv->out_buffer[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3012) 	for (i = 0; i < ARRAY_SIZE(p_priv->in_buffer); ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3013) 		kfree(p_priv->in_buffer[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3014) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3015) 	kfree(p_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3016) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3017) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3018) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3019) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3020) /* Structs for the devices, pre and post renumeration. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3021) static struct usb_serial_driver keyspan_pre_device = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3022) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3023) 		.owner		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3024) 		.name		= "keyspan_no_firm",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3025) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3026) 	.description		= "Keyspan - (without firmware)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3027) 	.id_table		= keyspan_pre_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3028) 	.num_ports		= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3029) 	.attach			= keyspan_fake_startup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3030) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3031) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3032) static struct usb_serial_driver keyspan_1port_device = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3033) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3034) 		.owner		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3035) 		.name		= "keyspan_1",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3036) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3037) 	.description		= "Keyspan 1 port adapter",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3038) 	.id_table		= keyspan_1port_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3039) 	.num_ports		= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3040) 	.open			= keyspan_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3041) 	.close			= keyspan_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3042) 	.dtr_rts		= keyspan_dtr_rts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3043) 	.write			= keyspan_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3044) 	.write_room		= keyspan_write_room,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3045) 	.set_termios		= keyspan_set_termios,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3046) 	.break_ctl		= keyspan_break_ctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3047) 	.tiocmget		= keyspan_tiocmget,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3048) 	.tiocmset		= keyspan_tiocmset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3049) 	.attach			= keyspan_startup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3050) 	.disconnect		= keyspan_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3051) 	.release		= keyspan_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3052) 	.port_probe		= keyspan_port_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3053) 	.port_remove		= keyspan_port_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3054) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3055) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3056) static struct usb_serial_driver keyspan_2port_device = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3057) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3058) 		.owner		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3059) 		.name		= "keyspan_2",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3060) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3061) 	.description		= "Keyspan 2 port adapter",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3062) 	.id_table		= keyspan_2port_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3063) 	.num_ports		= 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3064) 	.open			= keyspan_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3065) 	.close			= keyspan_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3066) 	.dtr_rts		= keyspan_dtr_rts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3067) 	.write			= keyspan_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3068) 	.write_room		= keyspan_write_room,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3069) 	.set_termios		= keyspan_set_termios,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3070) 	.break_ctl		= keyspan_break_ctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3071) 	.tiocmget		= keyspan_tiocmget,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3072) 	.tiocmset		= keyspan_tiocmset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3073) 	.attach			= keyspan_startup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3074) 	.disconnect		= keyspan_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3075) 	.release		= keyspan_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3076) 	.port_probe		= keyspan_port_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3077) 	.port_remove		= keyspan_port_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3078) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3079) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3080) static struct usb_serial_driver keyspan_4port_device = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3081) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3082) 		.owner		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3083) 		.name		= "keyspan_4",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3084) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3085) 	.description		= "Keyspan 4 port adapter",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3086) 	.id_table		= keyspan_4port_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3087) 	.num_ports		= 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3088) 	.open			= keyspan_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3089) 	.close			= keyspan_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3090) 	.dtr_rts		= keyspan_dtr_rts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3091) 	.write			= keyspan_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3092) 	.write_room		= keyspan_write_room,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3093) 	.set_termios		= keyspan_set_termios,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3094) 	.break_ctl		= keyspan_break_ctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3095) 	.tiocmget		= keyspan_tiocmget,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3096) 	.tiocmset		= keyspan_tiocmset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3097) 	.attach			= keyspan_startup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3098) 	.disconnect		= keyspan_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3099) 	.release		= keyspan_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3100) 	.port_probe		= keyspan_port_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3101) 	.port_remove		= keyspan_port_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3102) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3104) static struct usb_serial_driver * const serial_drivers[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3105) 	&keyspan_pre_device, &keyspan_1port_device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3106) 	&keyspan_2port_device, &keyspan_4port_device, NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3107) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3109) module_usb_serial_driver(serial_drivers, keyspan_ids_combined);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3111) MODULE_AUTHOR(DRIVER_AUTHOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3112) MODULE_DESCRIPTION(DRIVER_DESC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3113) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3115) MODULE_FIRMWARE("keyspan/usa28.fw");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3116) MODULE_FIRMWARE("keyspan/usa28x.fw");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3117) MODULE_FIRMWARE("keyspan/usa28xa.fw");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3118) MODULE_FIRMWARE("keyspan/usa28xb.fw");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3119) MODULE_FIRMWARE("keyspan/usa19.fw");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3120) MODULE_FIRMWARE("keyspan/usa19qi.fw");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3121) MODULE_FIRMWARE("keyspan/mpr.fw");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3122) MODULE_FIRMWARE("keyspan/usa19qw.fw");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3123) MODULE_FIRMWARE("keyspan/usa18x.fw");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3124) MODULE_FIRMWARE("keyspan/usa19w.fw");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3125) MODULE_FIRMWARE("keyspan/usa49w.fw");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3126) MODULE_FIRMWARE("keyspan/usa49wlc.fw");