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)  * USB ConnectTech WhiteHEAT driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *	Copyright (C) 2002
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *	    Connect Tech Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *	Copyright (C) 1999 - 2001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *	    Greg Kroah-Hartman (greg@kroah.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * See Documentation/usb/usb-serial.rst for more information on using this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/tty.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/tty_driver.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/tty_flip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <asm/termbits.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/serial_reg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <linux/serial.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <linux/usb/serial.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <linux/usb/ezusb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include "whiteheat.h"			/* WhiteHEAT specific commands */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #ifndef CMSPAR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #define CMSPAR 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  * Version Information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>, Stuart MacDonald <stuartm@connecttech.com>"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #define DRIVER_DESC "USB ConnectTech WhiteHEAT driver"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #define CONNECT_TECH_VENDOR_ID		0x0710
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #define CONNECT_TECH_FAKE_WHITE_HEAT_ID	0x0001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #define CONNECT_TECH_WHITE_HEAT_ID	0x8001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)    ID tables for whiteheat are unusual, because we want to different
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)    things for different versions of the device.  Eventually, this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)    will be doable from a single table.  But, for now, we define two
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)    separate ID tables, and then a third table that combines them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)    just for the purpose of exporting the autoloading information.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) static const struct usb_device_id id_table_std[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	{ USB_DEVICE(CONNECT_TECH_VENDOR_ID, CONNECT_TECH_WHITE_HEAT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	{ }						/* Terminating entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) static const struct usb_device_id id_table_prerenumeration[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	{ USB_DEVICE(CONNECT_TECH_VENDOR_ID, CONNECT_TECH_FAKE_WHITE_HEAT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	{ }						/* Terminating entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) static const struct usb_device_id id_table_combined[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	{ USB_DEVICE(CONNECT_TECH_VENDOR_ID, CONNECT_TECH_WHITE_HEAT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	{ USB_DEVICE(CONNECT_TECH_VENDOR_ID, CONNECT_TECH_FAKE_WHITE_HEAT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	{ }						/* Terminating entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) MODULE_DEVICE_TABLE(usb, id_table_combined);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) /* function prototypes for the Connect Tech WhiteHEAT prerenumeration device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) static int  whiteheat_firmware_download(struct usb_serial *serial,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 					const struct usb_device_id *id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) static int  whiteheat_firmware_attach(struct usb_serial *serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) /* function prototypes for the Connect Tech WhiteHEAT serial converter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) static int  whiteheat_attach(struct usb_serial *serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) static void whiteheat_release(struct usb_serial *serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) static int  whiteheat_port_probe(struct usb_serial_port *port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) static int  whiteheat_port_remove(struct usb_serial_port *port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) static int  whiteheat_open(struct tty_struct *tty,
^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) static void whiteheat_close(struct usb_serial_port *port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) static int  whiteheat_get_serial(struct tty_struct *tty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 			struct serial_struct *ss);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) static void whiteheat_set_termios(struct tty_struct *tty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 			struct usb_serial_port *port, struct ktermios *old);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) static int  whiteheat_tiocmget(struct tty_struct *tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) static int  whiteheat_tiocmset(struct tty_struct *tty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 			unsigned int set, unsigned int clear);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) static void whiteheat_break_ctl(struct tty_struct *tty, int break_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) static struct usb_serial_driver whiteheat_fake_device = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		.owner =	THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		.name =		"whiteheatnofirm",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	.description =		"Connect Tech - WhiteHEAT - (prerenumeration)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	.id_table =		id_table_prerenumeration,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	.num_ports =		1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	.probe =		whiteheat_firmware_download,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	.attach =		whiteheat_firmware_attach,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static struct usb_serial_driver whiteheat_device = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		.owner =	THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		.name =		"whiteheat",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	.description =		"Connect Tech - WhiteHEAT",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	.id_table =		id_table_std,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	.num_ports =		4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	.num_bulk_in =		5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	.num_bulk_out =		5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	.attach =		whiteheat_attach,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	.release =		whiteheat_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	.port_probe =		whiteheat_port_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	.port_remove =		whiteheat_port_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	.open =			whiteheat_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	.close =		whiteheat_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	.get_serial =		whiteheat_get_serial,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	.set_termios =		whiteheat_set_termios,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	.break_ctl =		whiteheat_break_ctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	.tiocmget =		whiteheat_tiocmget,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	.tiocmset =		whiteheat_tiocmset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	.throttle =		usb_serial_generic_throttle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	.unthrottle =		usb_serial_generic_unthrottle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) static struct usb_serial_driver * const serial_drivers[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	&whiteheat_fake_device, &whiteheat_device, NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) struct whiteheat_command_private {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	struct mutex		mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	__u8			port_running;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	__u8			command_finished;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	wait_queue_head_t	wait_command; /* for handling sleeping whilst
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 						 waiting for a command to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 						 finish */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	__u8			result_buffer[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) struct whiteheat_private {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	__u8			mcr;		/* FIXME: no locking on mcr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) /* local function prototypes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) static int start_command_port(struct usb_serial *serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) static void stop_command_port(struct usb_serial *serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) static void command_port_write_callback(struct urb *urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) static void command_port_read_callback(struct urb *urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) static int firm_send_command(struct usb_serial_port *port, __u8 command,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 						__u8 *data, __u8 datasize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) static int firm_open(struct usb_serial_port *port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) static int firm_close(struct usb_serial_port *port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) static void firm_setup_port(struct tty_struct *tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) static int firm_set_rts(struct usb_serial_port *port, __u8 onoff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) static int firm_set_dtr(struct usb_serial_port *port, __u8 onoff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) static int firm_set_break(struct usb_serial_port *port, __u8 onoff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) static int firm_purge(struct usb_serial_port *port, __u8 rxtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) static int firm_get_dtr_rts(struct usb_serial_port *port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) static int firm_report_tx_done(struct usb_serial_port *port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) #define COMMAND_PORT		4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) #define COMMAND_TIMEOUT		(2*HZ)	/* 2 second timeout for a command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) #define	COMMAND_TIMEOUT_MS	2000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) #define CLOSING_DELAY		(30 * HZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) /*****************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)  * Connect Tech's White Heat prerenumeration driver functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)  *****************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) /* steps to download the firmware to the WhiteHEAT device:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)  - hold the reset (by writing to the reset bit of the CPUCS register)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)  - download the VEND_AX.HEX file to the chip using VENDOR_REQUEST-ANCHOR_LOAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)  - release the reset (by writing to the CPUCS register)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)  - download the WH.HEX file for all addresses greater than 0x1b3f using
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)    VENDOR_REQUEST-ANCHOR_EXTERNAL_RAM_LOAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)  - hold the reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)  - download the WH.HEX file for all addresses less than 0x1b40 using
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)    VENDOR_REQUEST_ANCHOR_LOAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)  - release the reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)  - device renumerated itself and comes up as new device id with all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)    firmware download completed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) static int whiteheat_firmware_download(struct usb_serial *serial,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 					const struct usb_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	int response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	response = ezusb_fx1_ihex_firmware_download(serial->dev, "whiteheat_loader.fw");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	if (response >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		response = ezusb_fx1_ihex_firmware_download(serial->dev, "whiteheat.fw");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		if (response >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) static int whiteheat_firmware_attach(struct usb_serial *serial)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	/* We want this device to fail to have a driver assigned to it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) /*****************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)  * Connect Tech's White Heat serial driver functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)  *****************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) static int whiteheat_attach(struct usb_serial *serial)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	struct usb_serial_port *command_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	struct whiteheat_command_private *command_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	struct whiteheat_hw_info *hw_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	int pipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	int alen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	__u8 *command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	__u8 *result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	command_port = serial->port[COMMAND_PORT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	pipe = usb_sndbulkpipe(serial->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 			command_port->bulk_out_endpointAddress);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	command = kmalloc(2, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	if (!command)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		goto no_command_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	command[0] = WHITEHEAT_GET_HW_INFO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	command[1] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	result = kmalloc(sizeof(*hw_info) + 1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	if (!result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		goto no_result_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	 * When the module is reloaded the firmware is still there and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	 * the endpoints are still in the usb core unchanged. This is the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	 * unlinking bug in disguise. Same for the call below.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	usb_clear_halt(serial->dev, pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	ret = usb_bulk_msg(serial->dev, pipe, command, 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 						&alen, COMMAND_TIMEOUT_MS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		dev_err(&serial->dev->dev, "%s: Couldn't send command [%d]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 			serial->type->description, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		goto no_firmware;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	} else if (alen != 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		dev_err(&serial->dev->dev, "%s: Send command incomplete [%d]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 			serial->type->description, alen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		goto no_firmware;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	pipe = usb_rcvbulkpipe(serial->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 				command_port->bulk_in_endpointAddress);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	/* See the comment on the usb_clear_halt() above */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	usb_clear_halt(serial->dev, pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	ret = usb_bulk_msg(serial->dev, pipe, result,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 			sizeof(*hw_info) + 1, &alen, COMMAND_TIMEOUT_MS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		dev_err(&serial->dev->dev, "%s: Couldn't get results [%d]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 			serial->type->description, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		goto no_firmware;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	} else if (alen != sizeof(*hw_info) + 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		dev_err(&serial->dev->dev, "%s: Get results incomplete [%d]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 			serial->type->description, alen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		goto no_firmware;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	} else if (result[0] != command[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		dev_err(&serial->dev->dev, "%s: Command failed [%d]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 			serial->type->description, result[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		goto no_firmware;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	hw_info = (struct whiteheat_hw_info *)&result[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	dev_info(&serial->dev->dev, "%s: Firmware v%d.%02d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		 serial->type->description,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		 hw_info->sw_major_rev, hw_info->sw_minor_rev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	command_info = kmalloc(sizeof(struct whiteheat_command_private),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 								GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	if (!command_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		goto no_command_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	mutex_init(&command_info->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	command_info->port_running = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	init_waitqueue_head(&command_info->wait_command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	usb_set_serial_port_data(command_port, command_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	command_port->write_urb->complete = command_port_write_callback;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	command_port->read_urb->complete = command_port_read_callback;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	kfree(result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	kfree(command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) no_firmware:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	/* Firmware likely not running */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	dev_err(&serial->dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		"%s: Unable to retrieve firmware version, try replugging\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		serial->type->description);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	dev_err(&serial->dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		"%s: If the firmware is not running (status led not blinking)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		serial->type->description);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	dev_err(&serial->dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		"%s: please contact support@connecttech.com\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		serial->type->description);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	kfree(result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	kfree(command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) no_command_private:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	kfree(result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) no_result_buffer:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	kfree(command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) no_command_buffer:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) static void whiteheat_release(struct usb_serial *serial)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	struct usb_serial_port *command_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	/* free up our private data for our command port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	command_port = serial->port[COMMAND_PORT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	kfree(usb_get_serial_port_data(command_port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) static int whiteheat_port_probe(struct usb_serial_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	struct whiteheat_private *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	info = kzalloc(sizeof(*info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	if (!info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	usb_set_serial_port_data(port, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) static int whiteheat_port_remove(struct usb_serial_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	struct whiteheat_private *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	info = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	kfree(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) static int whiteheat_open(struct tty_struct *tty, struct usb_serial_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	retval = start_command_port(port->serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	/* send an open port command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	retval = firm_open(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 		stop_command_port(port->serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 		goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	retval = firm_purge(port, WHITEHEAT_PURGE_RX | WHITEHEAT_PURGE_TX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 		firm_close(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 		stop_command_port(port->serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	if (tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 		firm_setup_port(tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	/* Work around HCD bugs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	usb_clear_halt(port->serial->dev, port->read_urb->pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	usb_clear_halt(port->serial->dev, port->write_urb->pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	retval = usb_serial_generic_open(tty, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 		firm_close(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 		stop_command_port(port->serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 		goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	return retval;
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) static void whiteheat_close(struct usb_serial_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	firm_report_tx_done(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	firm_close(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	usb_serial_generic_close(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	stop_command_port(port->serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) static int whiteheat_tiocmget(struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	struct usb_serial_port *port = tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	struct whiteheat_private *info = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	unsigned int modem_signals = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	firm_get_dtr_rts(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	if (info->mcr & UART_MCR_DTR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 		modem_signals |= TIOCM_DTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	if (info->mcr & UART_MCR_RTS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 		modem_signals |= TIOCM_RTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	return modem_signals;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) static int whiteheat_tiocmset(struct tty_struct *tty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 			       unsigned int set, unsigned int clear)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	struct usb_serial_port *port = tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	struct whiteheat_private *info = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	if (set & TIOCM_RTS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 		info->mcr |= UART_MCR_RTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	if (set & TIOCM_DTR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 		info->mcr |= UART_MCR_DTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	if (clear & TIOCM_RTS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 		info->mcr &= ~UART_MCR_RTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	if (clear & TIOCM_DTR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 		info->mcr &= ~UART_MCR_DTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	firm_set_dtr(port, info->mcr & UART_MCR_DTR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	firm_set_rts(port, info->mcr & UART_MCR_RTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) static int whiteheat_get_serial(struct tty_struct *tty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 				struct serial_struct *ss)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	struct usb_serial_port *port = tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	ss->type = PORT_16654;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	ss->line = port->minor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	ss->port = port->port_number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	ss->xmit_fifo_size = kfifo_size(&port->write_fifo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	ss->custom_divisor = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	ss->baud_base = 460800;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	ss->close_delay = CLOSING_DELAY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	ss->closing_wait = CLOSING_DELAY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) static void whiteheat_set_termios(struct tty_struct *tty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	struct usb_serial_port *port, struct ktermios *old_termios)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	firm_setup_port(tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) static void whiteheat_break_ctl(struct tty_struct *tty, int break_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	struct usb_serial_port *port = tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	firm_set_break(port, break_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) /*****************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)  * Connect Tech's White Heat callback routines
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478)  *****************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) static void command_port_write_callback(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	int status = urb->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	if (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 		dev_dbg(&urb->dev->dev, "nonzero urb status: %d\n", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) static void command_port_read_callback(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	struct usb_serial_port *command_port = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	struct whiteheat_command_private *command_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	int status = urb->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	unsigned char *data = urb->transfer_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 	command_info = usb_get_serial_port_data(command_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	if (!command_info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 		dev_dbg(&urb->dev->dev, "%s - command_info is NULL, exiting.\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	if (!urb->actual_length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 		dev_dbg(&urb->dev->dev, "%s - empty response, exiting.\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	if (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 		dev_dbg(&urb->dev->dev, "%s - nonzero urb status: %d\n", __func__, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 		if (status != -ENOENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 			command_info->command_finished = WHITEHEAT_CMD_FAILURE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 		wake_up(&command_info->wait_command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	usb_serial_debug_data(&command_port->dev, __func__, urb->actual_length, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	if (data[0] == WHITEHEAT_CMD_COMPLETE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 		command_info->command_finished = WHITEHEAT_CMD_COMPLETE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 		wake_up(&command_info->wait_command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	} else if (data[0] == WHITEHEAT_CMD_FAILURE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 		command_info->command_finished = WHITEHEAT_CMD_FAILURE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 		wake_up(&command_info->wait_command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	} else if (data[0] == WHITEHEAT_EVENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 		/* These are unsolicited reports from the firmware, hence no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 		   waiting command to wakeup */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 		dev_dbg(&urb->dev->dev, "%s - event received\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 	} else if ((data[0] == WHITEHEAT_GET_DTR_RTS) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 		(urb->actual_length - 1 <= sizeof(command_info->result_buffer))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 		memcpy(command_info->result_buffer, &data[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 						urb->actual_length - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 		command_info->command_finished = WHITEHEAT_CMD_COMPLETE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 		wake_up(&command_info->wait_command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 		dev_dbg(&urb->dev->dev, "%s - bad reply from firmware\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	/* Continue trying to always read */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 	result = usb_submit_urb(command_port->read_urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 	if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 		dev_dbg(&urb->dev->dev, "%s - failed resubmitting read urb, error %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 			__func__, result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) /*****************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)  * Connect Tech's White Heat firmware interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546)  *****************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) static int firm_send_command(struct usb_serial_port *port, __u8 command,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 						__u8 *data, __u8 datasize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 	struct usb_serial_port *command_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 	struct whiteheat_command_private *command_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 	struct whiteheat_private *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 	struct device *dev = &port->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 	__u8 *transfer_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	int retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	int t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 	dev_dbg(dev, "%s - command %d\n", __func__, command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	command_port = port->serial->port[COMMAND_PORT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 	command_info = usb_get_serial_port_data(command_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	if (command_port->bulk_out_size < datasize + 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 	mutex_lock(&command_info->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 	command_info->command_finished = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 	transfer_buffer = (__u8 *)command_port->write_urb->transfer_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 	transfer_buffer[0] = command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 	memcpy(&transfer_buffer[1], data, datasize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	command_port->write_urb->transfer_buffer_length = datasize + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 	retval = usb_submit_urb(command_port->write_urb, GFP_NOIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 		dev_dbg(dev, "%s - submit urb failed\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 		goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 	/* wait for the command to complete */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 	t = wait_event_timeout(command_info->wait_command,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 		(bool)command_info->command_finished, COMMAND_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 	if (!t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 		usb_kill_urb(command_port->write_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 	if (command_info->command_finished == false) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 		dev_dbg(dev, "%s - command timed out.\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 		retval = -ETIMEDOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 		goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 	if (command_info->command_finished == WHITEHEAT_CMD_FAILURE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 		dev_dbg(dev, "%s - command failed.\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 		retval = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 		goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 	if (command_info->command_finished == WHITEHEAT_CMD_COMPLETE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 		dev_dbg(dev, "%s - command completed.\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 		switch (command) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 		case WHITEHEAT_GET_DTR_RTS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 			info = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 			memcpy(&info->mcr, command_info->result_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 					sizeof(struct whiteheat_dr_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 	mutex_unlock(&command_info->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) static int firm_open(struct usb_serial_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 	struct whiteheat_simple open_command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 	open_command.port = port->port_number + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 	return firm_send_command(port, WHITEHEAT_OPEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 		(__u8 *)&open_command, sizeof(open_command));
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) static int firm_close(struct usb_serial_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 	struct whiteheat_simple close_command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 	close_command.port = port->port_number + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 	return firm_send_command(port, WHITEHEAT_CLOSE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 			(__u8 *)&close_command, sizeof(close_command));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) static void firm_setup_port(struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 	struct usb_serial_port *port = tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 	struct device *dev = &port->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 	struct whiteheat_port_settings port_settings;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 	unsigned int cflag = tty->termios.c_cflag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 	speed_t baud;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 	port_settings.port = port->port_number + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 	/* get the byte size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 	switch (cflag & CSIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 	case CS5:	port_settings.bits = 5;   break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 	case CS6:	port_settings.bits = 6;   break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 	case CS7:	port_settings.bits = 7;   break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 	case CS8:	port_settings.bits = 8;   break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 	dev_dbg(dev, "%s - data bits = %d\n", __func__, port_settings.bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 	/* determine the parity */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 	if (cflag & PARENB)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 		if (cflag & CMSPAR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 			if (cflag & PARODD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 				port_settings.parity = WHITEHEAT_PAR_MARK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 				port_settings.parity = WHITEHEAT_PAR_SPACE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 			if (cflag & PARODD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 				port_settings.parity = WHITEHEAT_PAR_ODD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 				port_settings.parity = WHITEHEAT_PAR_EVEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 		port_settings.parity = WHITEHEAT_PAR_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 	dev_dbg(dev, "%s - parity = %c\n", __func__, port_settings.parity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 	/* figure out the stop bits requested */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 	if (cflag & CSTOPB)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 		port_settings.stop = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 		port_settings.stop = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 	dev_dbg(dev, "%s - stop bits = %d\n", __func__, port_settings.stop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 	/* figure out the flow control settings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 	if (cflag & CRTSCTS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 		port_settings.hflow = (WHITEHEAT_HFLOW_CTS |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 						WHITEHEAT_HFLOW_RTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 		port_settings.hflow = WHITEHEAT_HFLOW_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 	dev_dbg(dev, "%s - hardware flow control = %s %s %s %s\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 	    (port_settings.hflow & WHITEHEAT_HFLOW_CTS) ? "CTS" : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 	    (port_settings.hflow & WHITEHEAT_HFLOW_RTS) ? "RTS" : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 	    (port_settings.hflow & WHITEHEAT_HFLOW_DSR) ? "DSR" : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 	    (port_settings.hflow & WHITEHEAT_HFLOW_DTR) ? "DTR" : "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 	/* determine software flow control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 	if (I_IXOFF(tty))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 		port_settings.sflow = WHITEHEAT_SFLOW_RXTX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 		port_settings.sflow = WHITEHEAT_SFLOW_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 	dev_dbg(dev, "%s - software flow control = %c\n", __func__, port_settings.sflow);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 	port_settings.xon = START_CHAR(tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 	port_settings.xoff = STOP_CHAR(tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 	dev_dbg(dev, "%s - XON = %2x, XOFF = %2x\n", __func__, port_settings.xon, port_settings.xoff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 	/* get the baud rate wanted */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 	baud = tty_get_baud_rate(tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 	port_settings.baud = cpu_to_le32(baud);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 	dev_dbg(dev, "%s - baud rate = %u\n", __func__, baud);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 	/* fixme: should set validated settings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 	tty_encode_baud_rate(tty, baud, baud);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 	/* handle any settings that aren't specified in the tty structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 	port_settings.lloop = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 	/* now send the message to the device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 	firm_send_command(port, WHITEHEAT_SETUP_PORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 			(__u8 *)&port_settings, sizeof(port_settings));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) static int firm_set_rts(struct usb_serial_port *port, __u8 onoff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) 	struct whiteheat_set_rdb rts_command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 	rts_command.port = port->port_number + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) 	rts_command.state = onoff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) 	return firm_send_command(port, WHITEHEAT_SET_RTS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) 			(__u8 *)&rts_command, sizeof(rts_command));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) static int firm_set_dtr(struct usb_serial_port *port, __u8 onoff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) 	struct whiteheat_set_rdb dtr_command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) 	dtr_command.port = port->port_number + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) 	dtr_command.state = onoff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) 	return firm_send_command(port, WHITEHEAT_SET_DTR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) 			(__u8 *)&dtr_command, sizeof(dtr_command));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) static int firm_set_break(struct usb_serial_port *port, __u8 onoff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) 	struct whiteheat_set_rdb break_command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) 	break_command.port = port->port_number + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) 	break_command.state = onoff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) 	return firm_send_command(port, WHITEHEAT_SET_BREAK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) 			(__u8 *)&break_command, sizeof(break_command));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) }
^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) static int firm_purge(struct usb_serial_port *port, __u8 rxtx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) 	struct whiteheat_purge purge_command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) 	purge_command.port = port->port_number + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) 	purge_command.what = rxtx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) 	return firm_send_command(port, WHITEHEAT_PURGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) 			(__u8 *)&purge_command, sizeof(purge_command));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) }
^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) static int firm_get_dtr_rts(struct usb_serial_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) 	struct whiteheat_simple get_dr_command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) 	get_dr_command.port = port->port_number + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) 	return firm_send_command(port, WHITEHEAT_GET_DTR_RTS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) 			(__u8 *)&get_dr_command, sizeof(get_dr_command));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) static int firm_report_tx_done(struct usb_serial_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) 	struct whiteheat_simple close_command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) 	close_command.port = port->port_number + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) 	return firm_send_command(port, WHITEHEAT_REPORT_TX_DONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) 			(__u8 *)&close_command, sizeof(close_command));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) }
^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) /*****************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781)  * Connect Tech's White Heat utility functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782)  *****************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) static int start_command_port(struct usb_serial *serial)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) 	struct usb_serial_port *command_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) 	struct whiteheat_command_private *command_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) 	int retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) 	command_port = serial->port[COMMAND_PORT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) 	command_info = usb_get_serial_port_data(command_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) 	mutex_lock(&command_info->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) 	if (!command_info->port_running) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) 		/* Work around HCD bugs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) 		usb_clear_halt(serial->dev, command_port->read_urb->pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) 		retval = usb_submit_urb(command_port->read_urb, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) 		if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) 			dev_err(&serial->dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) 				"%s - failed submitting read urb, error %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) 				__func__, retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) 			goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) 	command_info->port_running++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) 	mutex_unlock(&command_info->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) static void stop_command_port(struct usb_serial *serial)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) 	struct usb_serial_port *command_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) 	struct whiteheat_command_private *command_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) 	command_port = serial->port[COMMAND_PORT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) 	command_info = usb_get_serial_port_data(command_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) 	mutex_lock(&command_info->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) 	command_info->port_running--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) 	if (!command_info->port_running)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) 		usb_kill_urb(command_port->read_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) 	mutex_unlock(&command_info->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) module_usb_serial_driver(serial_drivers, id_table_combined);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) MODULE_AUTHOR(DRIVER_AUTHOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) MODULE_DESCRIPTION(DRIVER_DESC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) MODULE_FIRMWARE("whiteheat.fw");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) MODULE_FIRMWARE("whiteheat_loader.fw");