2017-11-03 10:28:30 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Edgeport USB Serial Converter driver
|
|
|
|
*
|
|
|
|
* Copyright (C) 2000-2002 Inside Out Networks, All rights reserved.
|
|
|
|
* Copyright (C) 2001-2002 Greg Kroah-Hartman <greg@kroah.com>
|
|
|
|
*
|
|
|
|
* Supports the following devices:
|
|
|
|
* EP/1 EP/2 EP/4 EP/21 EP/22 EP/221 EP/42 EP/421 WATCHPORT
|
|
|
|
*
|
|
|
|
* For questions or problems with this driver, contact Inside Out
|
|
|
|
* Networks technical support, or Peter Berger <pberger@brimson.com>,
|
|
|
|
* or Al Borchers <alborchers@steinerpoint.com>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/jiffies.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/tty.h>
|
|
|
|
#include <linux/tty_driver.h>
|
|
|
|
#include <linux/tty_flip.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/spinlock.h>
|
2007-12-04 15:15:40 +00:00
|
|
|
#include <linux/mutex.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/serial.h>
|
2014-04-25 13:23:03 +00:00
|
|
|
#include <linux/swab.h>
|
2010-05-18 22:01:37 +00:00
|
|
|
#include <linux/kfifo.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/ioctl.h>
|
2008-07-04 17:36:09 +00:00
|
|
|
#include <linux/firmware.h>
|
2008-04-29 13:45:15 +00:00
|
|
|
#include <linux/uaccess.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/usb.h>
|
2006-07-12 04:22:58 +00:00
|
|
|
#include <linux/usb/serial.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#include "io_16654.h"
|
|
|
|
#include "io_usbvend.h"
|
|
|
|
#include "io_ti.h"
|
|
|
|
|
|
|
|
#define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com> and David Iacovelli"
|
|
|
|
#define DRIVER_DESC "Edgeport USB Serial Driver"
|
|
|
|
|
|
|
|
#define EPROM_PAGE_SIZE 64
|
|
|
|
|
|
|
|
|
|
|
|
/* different hardware types */
|
|
|
|
#define HARDWARE_TYPE_930 0
|
|
|
|
#define HARDWARE_TYPE_TIUMP 1
|
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
/* IOCTL_PRIVATE_TI_GET_MODE Definitions */
|
|
|
|
#define TI_MODE_CONFIGURING 0 /* Device has not entered start device */
|
|
|
|
#define TI_MODE_BOOT 1 /* Staying in boot mode */
|
|
|
|
#define TI_MODE_DOWNLOAD 2 /* Made it to download mode */
|
2015-09-16 08:13:02 +00:00
|
|
|
#define TI_MODE_TRANSITIONING 3 /*
|
|
|
|
* Currently in boot mode but
|
|
|
|
* transitioning to download mode
|
|
|
|
*/
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* read urb state */
|
|
|
|
#define EDGE_READ_URB_RUNNING 0
|
|
|
|
#define EDGE_READ_URB_STOPPING 1
|
|
|
|
#define EDGE_READ_URB_STOPPED 2
|
|
|
|
|
|
|
|
|
|
|
|
/* Product information read from the Edgeport */
|
2008-04-29 13:45:15 +00:00
|
|
|
struct product_info {
|
|
|
|
int TiMode; /* Current TI Mode */
|
2021-04-12 09:47:32 +00:00
|
|
|
u8 hardware_type; /* Type of hardware */
|
2021-04-12 09:47:33 +00:00
|
|
|
} __packed;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2015-07-31 06:55:06 +00:00
|
|
|
/*
|
|
|
|
* Edgeport firmware header
|
|
|
|
*
|
|
|
|
* "build_number" has been set to 0 in all three of the images I have
|
|
|
|
* seen, and Digi Tech Support suggests that it is safe to ignore it.
|
|
|
|
*
|
|
|
|
* "length" is the number of bytes of actual data following the header.
|
|
|
|
*
|
|
|
|
* "checksum" is the low order byte resulting from adding the values of
|
|
|
|
* all the data bytes.
|
|
|
|
*/
|
|
|
|
struct edgeport_fw_hdr {
|
|
|
|
u8 major_version;
|
|
|
|
u8 minor_version;
|
|
|
|
__le16 build_number;
|
|
|
|
__le16 length;
|
|
|
|
u8 checksum;
|
|
|
|
} __packed;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
struct edgeport_port {
|
2021-04-12 09:47:32 +00:00
|
|
|
u16 uart_base;
|
|
|
|
u16 dma_address;
|
|
|
|
u8 shadow_msr;
|
|
|
|
u8 shadow_mcr;
|
|
|
|
u8 shadow_lsr;
|
|
|
|
u8 lsr_mask;
|
|
|
|
u32 ump_read_timeout; /*
|
2015-09-16 08:13:02 +00:00
|
|
|
* Number of milliseconds the UMP will
|
|
|
|
* wait without data before completing
|
|
|
|
* a read short
|
|
|
|
*/
|
2005-04-16 22:20:36 +00:00
|
|
|
int baud_rate;
|
|
|
|
int close_pending;
|
|
|
|
int lsr_event;
|
2013-03-21 11:37:10 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
struct edgeport_serial *edge_serial;
|
|
|
|
struct usb_serial_port *port;
|
2021-04-12 09:47:32 +00:00
|
|
|
u8 bUartMode; /* Port type, 0: RS232, etc. */
|
2005-04-16 22:20:36 +00:00
|
|
|
spinlock_t ep_lock;
|
|
|
|
int ep_read_urb_state;
|
|
|
|
int ep_write_urb_in_use;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct edgeport_serial {
|
|
|
|
struct product_info product_info;
|
2008-04-29 13:45:15 +00:00
|
|
|
u8 TI_I2C_Type; /* Type of I2C in UMP */
|
2015-09-16 08:13:02 +00:00
|
|
|
u8 TiReadI2C; /*
|
|
|
|
* Set to TRUE if we have read the
|
|
|
|
* I2c in Boot Mode
|
|
|
|
*/
|
2007-12-04 15:15:40 +00:00
|
|
|
struct mutex es_lock;
|
2005-04-16 22:20:36 +00:00
|
|
|
int num_ports_open;
|
|
|
|
struct usb_serial *serial;
|
2015-07-31 06:55:08 +00:00
|
|
|
struct delayed_work heartbeat_work;
|
2015-07-31 06:55:06 +00:00
|
|
|
int fw_version;
|
2015-07-31 06:55:08 +00:00
|
|
|
bool use_heartbeat;
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Devices that this driver supports */
|
2010-01-10 14:34:24 +00:00
|
|
|
static const struct usb_device_id edgeport_1port_id_table[] = {
|
2005-04-16 22:20:36 +00:00
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_1) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1I) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_PROXIMITY) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_MOTION) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_MOISTURE) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_TEMPERATURE) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_HUMIDITY) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_POWER) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_LIGHT) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_RADIATION) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_DISTANCE) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_ACCELERATION) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_PROX_DIST) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_PLUS_PWR_HP4CD) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_PLUS_PWR_PCI) },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2010-01-10 14:34:24 +00:00
|
|
|
static const struct usb_device_id edgeport_2port_id_table[] = {
|
2005-04-16 22:20:36 +00:00
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2C) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2I) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_421) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_42) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4I) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_22I) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_221C) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_22C) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21C) },
|
2007-05-22 19:57:04 +00:00
|
|
|
/* The 4, 8 and 16 port devices show up as multiple 2 port devices */
|
2005-04-16 22:20:36 +00:00
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4S) },
|
2007-05-22 19:57:04 +00:00
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_8) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_8S) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_416) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_416B) },
|
2022-05-21 14:08:08 +00:00
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_E5805A) },
|
2005-04-16 22:20:36 +00:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Devices that this driver supports */
|
2010-01-10 14:34:24 +00:00
|
|
|
static const struct usb_device_id id_table_combined[] = {
|
2005-04-16 22:20:36 +00:00
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_1) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1I) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_PROXIMITY) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_MOTION) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_MOISTURE) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_TEMPERATURE) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_HUMIDITY) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_POWER) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_LIGHT) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_RADIATION) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_DISTANCE) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_ACCELERATION) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_PROX_DIST) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_PLUS_PWR_HP4CD) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_PLUS_PWR_PCI) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2C) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2I) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_421) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_42) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4I) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_22I) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_221C) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_22C) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21C) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4S) },
|
2007-05-22 19:57:04 +00:00
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_8) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_8S) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_416) },
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_416B) },
|
2022-05-21 14:08:08 +00:00
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_E5805A) },
|
2005-04-16 22:20:36 +00:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
MODULE_DEVICE_TABLE(usb, id_table_combined);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-01-12 23:02:20 +00:00
|
|
|
static bool ignore_cpu_rev;
|
2008-04-29 13:45:15 +00:00
|
|
|
static int default_uart_mode; /* RS232 */
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2013-01-03 14:53:06 +00:00
|
|
|
static void edge_tty_recv(struct usb_serial_port *port, unsigned char *data,
|
|
|
|
int length);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
static void stop_read(struct edgeport_port *edge_port);
|
|
|
|
static int restart_read(struct edgeport_port *edge_port);
|
|
|
|
|
2008-07-22 10:09:07 +00:00
|
|
|
static void edge_set_termios(struct tty_struct *tty,
|
|
|
|
struct usb_serial_port *port, struct ktermios *old_termios);
|
2013-04-04 20:41:01 +00:00
|
|
|
static void edge_send(struct usb_serial_port *port, struct tty_struct *tty);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2015-09-16 08:13:00 +00:00
|
|
|
static int do_download_mode(struct edgeport_serial *serial,
|
|
|
|
const struct firmware *fw);
|
|
|
|
static int do_boot_mode(struct edgeport_serial *serial,
|
|
|
|
const struct firmware *fw);
|
|
|
|
|
2007-05-22 19:57:04 +00:00
|
|
|
/* sysfs attributes */
|
|
|
|
static int edge_create_sysfs_attrs(struct usb_serial_port *port);
|
|
|
|
static int edge_remove_sysfs_attrs(struct usb_serial_port *port);
|
|
|
|
|
2015-07-31 06:55:08 +00:00
|
|
|
/*
|
|
|
|
* Some release of Edgeport firmware "down3.bin" after version 4.80
|
|
|
|
* introduced code to automatically disconnect idle devices on some
|
|
|
|
* Edgeport models after periods of inactivity, typically ~60 seconds.
|
|
|
|
* This occurs without regard to whether ports on the device are open
|
|
|
|
* or not. Digi International Tech Support suggested:
|
|
|
|
*
|
|
|
|
* 1. Adding driver "heartbeat" code to reset the firmware timer by
|
|
|
|
* requesting a descriptor record every 15 seconds, which should be
|
|
|
|
* effective with newer firmware versions that require it, and benign
|
|
|
|
* with older versions that do not. In practice 40 seconds seems often
|
|
|
|
* enough.
|
|
|
|
* 2. The heartbeat code is currently required only on Edgeport/416 models.
|
|
|
|
*/
|
|
|
|
#define FW_HEARTBEAT_VERSION_CUTOFF ((4 << 8) + 80)
|
|
|
|
#define FW_HEARTBEAT_SECS 40
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2015-07-31 06:55:05 +00:00
|
|
|
/* Timeouts in msecs: firmware downloads take longer */
|
|
|
|
#define TI_VSEND_TIMEOUT_DEFAULT 1000
|
|
|
|
#define TI_VSEND_TIMEOUT_FW_DOWNLOAD 10000
|
|
|
|
|
2021-04-12 09:47:29 +00:00
|
|
|
static int ti_vread_sync(struct usb_device *dev, u8 request, u16 value,
|
|
|
|
u16 index, void *data, int size)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int status;
|
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
status = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), request,
|
|
|
|
(USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN),
|
|
|
|
value, index, data, size, 1000);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (status < 0)
|
|
|
|
return status;
|
|
|
|
if (status != size) {
|
2021-01-18 11:14:24 +00:00
|
|
|
dev_dbg(&dev->dev, "%s - wanted to read %d, but only read %d\n",
|
2012-09-14 23:58:58 +00:00
|
|
|
__func__, size, status);
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ECOMM;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-07-31 06:55:05 +00:00
|
|
|
static int ti_vsend_sync(struct usb_device *dev, u8 request, u16 value,
|
2021-04-12 09:47:29 +00:00
|
|
|
u16 index, void *data, int size, int timeout)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int status;
|
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
status = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), request,
|
|
|
|
(USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT),
|
2015-07-31 06:55:05 +00:00
|
|
|
value, index, data, size, timeout);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (status < 0)
|
|
|
|
return status;
|
2021-01-18 11:14:23 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-04-12 09:47:31 +00:00
|
|
|
static int read_port_cmd(struct usb_serial_port *port, u8 command, u16 value,
|
|
|
|
void *data, int size)
|
|
|
|
{
|
|
|
|
return ti_vread_sync(port->serial->dev, command, value,
|
|
|
|
UMPM_UART1_PORT + port->port_number,
|
|
|
|
data, size);
|
|
|
|
}
|
|
|
|
|
2021-04-12 09:47:30 +00:00
|
|
|
static int send_port_cmd(struct usb_serial_port *port, u8 command, u16 value,
|
|
|
|
void *data, int size)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2021-04-12 09:47:30 +00:00
|
|
|
return ti_vsend_sync(port->serial->dev, command, value,
|
|
|
|
UMPM_UART1_PORT + port->port_number,
|
|
|
|
data, size, TI_VSEND_TIMEOUT_DEFAULT);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* clear tx/rx buffers and fifo in TI UMP */
|
2021-04-12 09:47:32 +00:00
|
|
|
static int purge_port(struct usb_serial_port *port, u16 mask)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2013-06-06 17:32:00 +00:00
|
|
|
int port_number = port->port_number;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(&port->dev, "%s - port %d, mask %x\n", __func__, port_number, mask);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-04-12 09:47:30 +00:00
|
|
|
return send_port_cmd(port, UMPC_PURGE_PORT, mask, NULL, 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-04-29 13:45:15 +00:00
|
|
|
* read_download_mem - Read edgeport memory from TI chip
|
2005-04-16 22:20:36 +00:00
|
|
|
* @dev: usb device pointer
|
|
|
|
* @start_address: Device CPU address at which to read
|
|
|
|
* @length: Length of above data
|
|
|
|
* @address_type: Can read both XDATA and I2C
|
|
|
|
* @buffer: pointer to input data buffer
|
|
|
|
*/
|
2008-04-29 13:45:15 +00:00
|
|
|
static int read_download_mem(struct usb_device *dev, int start_address,
|
2021-04-12 09:47:32 +00:00
|
|
|
int length, u8 address_type, u8 *buffer)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int status = 0;
|
2021-04-12 09:47:32 +00:00
|
|
|
u8 read_length;
|
2014-04-25 13:23:03 +00:00
|
|
|
u16 be_start_address;
|
2008-04-29 13:45:15 +00:00
|
|
|
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(&dev->dev, "%s - @ %x for %d\n", __func__, start_address, length);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2015-09-16 08:13:02 +00:00
|
|
|
/*
|
|
|
|
* Read in blocks of 64 bytes
|
2005-04-16 22:20:36 +00:00
|
|
|
* (TI firmware can't handle more than 64 byte reads)
|
|
|
|
*/
|
|
|
|
while (length) {
|
|
|
|
if (length > 64)
|
2008-04-29 13:45:15 +00:00
|
|
|
read_length = 64;
|
2005-04-16 22:20:36 +00:00
|
|
|
else
|
2021-04-12 09:47:32 +00:00
|
|
|
read_length = (u8)length;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (read_length > 1) {
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(&dev->dev, "%s - @ %x for %d\n", __func__, start_address, read_length);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2014-04-25 13:23:03 +00:00
|
|
|
/*
|
|
|
|
* NOTE: Must use swab as wIndex is sent in little-endian
|
|
|
|
* byte order regardless of host byte order.
|
|
|
|
*/
|
|
|
|
be_start_address = swab16((u16)start_address);
|
2008-04-29 13:45:15 +00:00
|
|
|
status = ti_vread_sync(dev, UMPC_MEMORY_READ,
|
2021-04-12 09:47:32 +00:00
|
|
|
(u16)address_type,
|
2014-04-25 13:23:03 +00:00
|
|
|
be_start_address,
|
2008-04-29 13:45:15 +00:00
|
|
|
buffer, read_length);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (status) {
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(&dev->dev, "%s - ERROR %x\n", __func__, status);
|
2005-04-16 22:20:36 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
if (read_length > 1)
|
2012-09-18 08:58:57 +00:00
|
|
|
usb_serial_debug_data(&dev->dev, __func__, read_length, buffer);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* Update pointers/length */
|
|
|
|
start_address += read_length;
|
|
|
|
buffer += read_length;
|
|
|
|
length -= read_length;
|
|
|
|
}
|
2008-04-29 13:45:15 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
static int read_ram(struct usb_device *dev, int start_address,
|
2021-04-12 09:47:32 +00:00
|
|
|
int length, u8 *buffer)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-04-29 13:45:15 +00:00
|
|
|
return read_download_mem(dev, start_address, length,
|
|
|
|
DTK_ADDR_SPACE_XDATA, buffer);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Read edgeport memory to a given block */
|
2008-04-29 13:45:15 +00:00
|
|
|
static int read_boot_mem(struct edgeport_serial *serial,
|
2021-04-12 09:47:32 +00:00
|
|
|
int start_address, int length, u8 *buffer)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int status = 0;
|
|
|
|
int i;
|
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
for (i = 0; i < length; i++) {
|
|
|
|
status = ti_vread_sync(serial->serial->dev,
|
|
|
|
UMPC_MEMORY_READ, serial->TI_I2C_Type,
|
2021-04-12 09:47:32 +00:00
|
|
|
(u16)(start_address+i), &buffer[i], 0x01);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (status) {
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(&serial->serial->dev->dev, "%s - ERROR %x\n", __func__, status);
|
2005-04-16 22:20:36 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(&serial->serial->dev->dev, "%s - start_address = %x, length = %d\n",
|
|
|
|
__func__, start_address, length);
|
2012-09-18 08:58:57 +00:00
|
|
|
usb_serial_debug_data(&serial->serial->dev->dev, __func__, length, buffer);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
serial->TiReadI2C = 1;
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write given block to TI EPROM memory */
|
2008-04-29 13:45:15 +00:00
|
|
|
static int write_boot_mem(struct edgeport_serial *serial,
|
2021-04-12 09:47:32 +00:00
|
|
|
int start_address, int length, u8 *buffer)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int status = 0;
|
|
|
|
int i;
|
2009-12-28 22:01:50 +00:00
|
|
|
u8 *temp;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* Must do a read before write */
|
|
|
|
if (!serial->TiReadI2C) {
|
2009-12-28 22:01:50 +00:00
|
|
|
temp = kmalloc(1, GFP_KERNEL);
|
2013-12-29 18:22:56 +00:00
|
|
|
if (!temp)
|
2009-12-28 22:01:50 +00:00
|
|
|
return -ENOMEM;
|
2013-12-29 18:22:56 +00:00
|
|
|
|
2009-12-28 22:01:50 +00:00
|
|
|
status = read_boot_mem(serial, 0, 1, temp);
|
|
|
|
kfree(temp);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
for (i = 0; i < length; ++i) {
|
2015-07-31 06:55:05 +00:00
|
|
|
status = ti_vsend_sync(serial->serial->dev, UMPC_MEMORY_WRITE,
|
|
|
|
buffer[i], (u16)(i + start_address), NULL,
|
|
|
|
0, TI_VSEND_TIMEOUT_DEFAULT);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(&serial->serial->dev->dev, "%s - start_sddr = %x, length = %d\n", __func__, start_address, length);
|
2012-09-18 08:58:57 +00:00
|
|
|
usb_serial_debug_data(&serial->serial->dev->dev, __func__, length, buffer);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write edgeport I2C memory to TI chip */
|
2008-04-29 13:45:15 +00:00
|
|
|
static int write_i2c_mem(struct edgeport_serial *serial,
|
2021-04-12 09:47:32 +00:00
|
|
|
int start_address, int length, u8 address_type, u8 *buffer)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2012-09-14 23:58:58 +00:00
|
|
|
struct device *dev = &serial->serial->dev->dev;
|
2005-04-16 22:20:36 +00:00
|
|
|
int status = 0;
|
|
|
|
int write_length;
|
2014-04-25 13:23:03 +00:00
|
|
|
u16 be_start_address;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* We can only send a maximum of 1 aligned byte page at a time */
|
2008-04-29 13:45:15 +00:00
|
|
|
|
2011-03-31 01:57:33 +00:00
|
|
|
/* calculate the number of bytes left in the first page */
|
2008-04-29 13:45:15 +00:00
|
|
|
write_length = EPROM_PAGE_SIZE -
|
|
|
|
(start_address & (EPROM_PAGE_SIZE - 1));
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (write_length > length)
|
|
|
|
write_length = length;
|
|
|
|
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s - BytesInFirstPage Addr = %x, length = %d\n",
|
|
|
|
__func__, start_address, write_length);
|
2012-09-18 08:58:57 +00:00
|
|
|
usb_serial_debug_data(dev, __func__, write_length, buffer);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2014-04-25 13:23:03 +00:00
|
|
|
/*
|
|
|
|
* Write first page.
|
|
|
|
*
|
|
|
|
* NOTE: Must use swab as wIndex is sent in little-endian byte order
|
|
|
|
* regardless of host byte order.
|
|
|
|
*/
|
|
|
|
be_start_address = swab16((u16)start_address);
|
2015-07-31 06:55:05 +00:00
|
|
|
status = ti_vsend_sync(serial->serial->dev, UMPC_MEMORY_WRITE,
|
|
|
|
(u16)address_type, be_start_address,
|
|
|
|
buffer, write_length, TI_VSEND_TIMEOUT_DEFAULT);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (status) {
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s - ERROR %d\n", __func__, status);
|
2005-04-16 22:20:36 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
length -= write_length;
|
|
|
|
start_address += write_length;
|
|
|
|
buffer += write_length;
|
|
|
|
|
2015-09-16 08:13:02 +00:00
|
|
|
/*
|
|
|
|
* We should be aligned now -- can write max page size bytes at a
|
|
|
|
* time.
|
|
|
|
*/
|
2005-04-16 22:20:36 +00:00
|
|
|
while (length) {
|
|
|
|
if (length > EPROM_PAGE_SIZE)
|
|
|
|
write_length = EPROM_PAGE_SIZE;
|
|
|
|
else
|
|
|
|
write_length = length;
|
|
|
|
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s - Page Write Addr = %x, length = %d\n",
|
|
|
|
__func__, start_address, write_length);
|
2012-09-18 08:58:57 +00:00
|
|
|
usb_serial_debug_data(dev, __func__, write_length, buffer);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2014-04-25 13:23:03 +00:00
|
|
|
/*
|
|
|
|
* Write next page.
|
|
|
|
*
|
|
|
|
* NOTE: Must use swab as wIndex is sent in little-endian byte
|
|
|
|
* order regardless of host byte order.
|
|
|
|
*/
|
|
|
|
be_start_address = swab16((u16)start_address);
|
2008-04-29 13:45:15 +00:00
|
|
|
status = ti_vsend_sync(serial->serial->dev, UMPC_MEMORY_WRITE,
|
2015-07-31 06:55:05 +00:00
|
|
|
(u16)address_type, be_start_address, buffer,
|
|
|
|
write_length, TI_VSEND_TIMEOUT_DEFAULT);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (status) {
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_err(dev, "%s - ERROR %d\n", __func__, status);
|
2005-04-16 22:20:36 +00:00
|
|
|
return status;
|
|
|
|
}
|
2008-04-29 13:45:15 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
length -= write_length;
|
|
|
|
start_address += write_length;
|
|
|
|
buffer += write_length;
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2015-09-16 08:13:02 +00:00
|
|
|
/*
|
|
|
|
* Examine the UMP DMA registers and LSR
|
2008-04-29 13:45:15 +00:00
|
|
|
*
|
2005-04-16 22:20:36 +00:00
|
|
|
* Check the MSBit of the X and Y DMA byte count registers.
|
|
|
|
* A zero in this bit indicates that the TX DMA buffers are empty
|
|
|
|
* then check the TX Empty bit in the UART.
|
|
|
|
*/
|
2008-04-29 13:45:15 +00:00
|
|
|
static int tx_active(struct edgeport_port *port)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int status;
|
|
|
|
struct out_endpoint_desc_block *oedb;
|
2021-04-12 09:47:32 +00:00
|
|
|
u8 *lsr;
|
2005-04-16 22:20:36 +00:00
|
|
|
int bytes_left = 0;
|
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
oedb = kmalloc(sizeof(*oedb), GFP_KERNEL);
|
2013-12-29 18:22:56 +00:00
|
|
|
if (!oedb)
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2015-09-16 08:13:02 +00:00
|
|
|
/*
|
|
|
|
* Sigh, that's right, just one byte, as not all platforms can
|
|
|
|
* do DMA from stack
|
|
|
|
*/
|
|
|
|
lsr = kmalloc(1, GFP_KERNEL);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!lsr) {
|
|
|
|
kfree(oedb);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
/* Read the DMA Count Registers */
|
2008-04-29 13:45:15 +00:00
|
|
|
status = read_ram(port->port->serial->dev, port->dma_address,
|
|
|
|
sizeof(*oedb), (void *)oedb);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (status)
|
|
|
|
goto exit_is_tx_active;
|
|
|
|
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(&port->port->dev, "%s - XByteCount 0x%X\n", __func__, oedb->XByteCount);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* and the LSR */
|
2008-04-29 13:45:15 +00:00
|
|
|
status = read_ram(port->port->serial->dev,
|
|
|
|
port->uart_base + UMPMEM_OFFS_UART_LSR, 1, lsr);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (status)
|
|
|
|
goto exit_is_tx_active;
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(&port->port->dev, "%s - LSR = 0x%X\n", __func__, *lsr);
|
2008-04-29 13:45:15 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* If either buffer has data or we are transmitting then return TRUE */
|
2008-04-29 13:45:15 +00:00
|
|
|
if ((oedb->XByteCount & 0x80) != 0)
|
2005-04-16 22:20:36 +00:00
|
|
|
bytes_left += 64;
|
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
if ((*lsr & UMP_UART_LSR_TX_MASK) == 0)
|
2005-04-16 22:20:36 +00:00
|
|
|
bytes_left += 1;
|
|
|
|
|
|
|
|
/* We return Not Active if we get any kind of error */
|
|
|
|
exit_is_tx_active:
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(&port->port->dev, "%s - return %d\n", __func__, bytes_left);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
kfree(lsr);
|
|
|
|
kfree(oedb);
|
|
|
|
return bytes_left;
|
|
|
|
}
|
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
static int choose_config(struct usb_device *dev)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-04-29 13:45:15 +00:00
|
|
|
/*
|
|
|
|
* There may be multiple configurations on this device, in which case
|
|
|
|
* we would need to read and parse all of them to find out which one
|
|
|
|
* we want. However, we just support one config at this point,
|
|
|
|
* configuration # 1, which is Config Descriptor 0.
|
|
|
|
*/
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(&dev->dev, "%s - Number of Interfaces = %d\n",
|
|
|
|
__func__, dev->config->desc.bNumInterfaces);
|
|
|
|
dev_dbg(&dev->dev, "%s - MAX Power = %d\n",
|
|
|
|
__func__, dev->config->desc.bMaxPower * 2);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (dev->config->desc.bNumInterfaces != 1) {
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_err(&dev->dev, "%s - bNumInterfaces is not 1, ERROR!\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
static int read_rom(struct edgeport_serial *serial,
|
2021-04-12 09:47:32 +00:00
|
|
|
int start_address, int length, u8 *buffer)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int status;
|
|
|
|
|
|
|
|
if (serial->product_info.TiMode == TI_MODE_DOWNLOAD) {
|
2008-04-29 13:45:15 +00:00
|
|
|
status = read_download_mem(serial->serial->dev,
|
2005-04-16 22:20:36 +00:00
|
|
|
start_address,
|
|
|
|
length,
|
|
|
|
serial->TI_I2C_Type,
|
|
|
|
buffer);
|
|
|
|
} else {
|
2008-04-29 13:45:15 +00:00
|
|
|
status = read_boot_mem(serial, start_address, length,
|
|
|
|
buffer);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
static int write_rom(struct edgeport_serial *serial, int start_address,
|
2021-04-12 09:47:32 +00:00
|
|
|
int length, u8 *buffer)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
if (serial->product_info.TiMode == TI_MODE_BOOT)
|
2008-04-29 13:45:15 +00:00
|
|
|
return write_boot_mem(serial, start_address, length,
|
|
|
|
buffer);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (serial->product_info.TiMode == TI_MODE_DOWNLOAD)
|
2008-04-29 13:45:15 +00:00
|
|
|
return write_i2c_mem(serial, start_address, length,
|
|
|
|
serial->TI_I2C_Type, buffer);
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read a descriptor header from I2C based on type */
|
2008-04-29 13:45:15 +00:00
|
|
|
static int get_descriptor_addr(struct edgeport_serial *serial,
|
|
|
|
int desc_type, struct ti_i2c_desc *rom_desc)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int start_address;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
/* Search for requested descriptor in I2C */
|
|
|
|
start_address = 2;
|
|
|
|
do {
|
2008-04-29 13:45:15 +00:00
|
|
|
status = read_rom(serial,
|
2005-04-16 22:20:36 +00:00
|
|
|
start_address,
|
|
|
|
sizeof(struct ti_i2c_desc),
|
2021-04-12 09:47:32 +00:00
|
|
|
(u8 *)rom_desc);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (status)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (rom_desc->Type == desc_type)
|
|
|
|
return start_address;
|
|
|
|
|
2014-04-25 13:23:03 +00:00
|
|
|
start_address = start_address + sizeof(struct ti_i2c_desc) +
|
|
|
|
le16_to_cpu(rom_desc->Size);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
} while ((start_address < TI_MAX_I2C_SIZE) && rom_desc->Type);
|
2008-04-29 13:45:15 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Validate descriptor checksum */
|
2021-04-12 09:47:32 +00:00
|
|
|
static int valid_csum(struct ti_i2c_desc *rom_desc, u8 *buffer)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2021-04-12 09:47:32 +00:00
|
|
|
u16 i;
|
|
|
|
u8 cs = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2014-04-25 13:23:03 +00:00
|
|
|
for (i = 0; i < le16_to_cpu(rom_desc->Size); i++)
|
2021-04-12 09:47:32 +00:00
|
|
|
cs = (u8)(cs + buffer[i]);
|
2008-04-29 13:45:15 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
if (cs != rom_desc->CheckSum) {
|
2012-09-14 23:58:58 +00:00
|
|
|
pr_debug("%s - Mismatch %x - %x", __func__, rom_desc->CheckSum, cs);
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure that the I2C image is good */
|
2008-04-29 13:45:15 +00:00
|
|
|
static int check_i2c_image(struct edgeport_serial *serial)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct device *dev = &serial->serial->dev->dev;
|
|
|
|
int status = 0;
|
|
|
|
struct ti_i2c_desc *rom_desc;
|
|
|
|
int start_address = 2;
|
2021-04-12 09:47:32 +00:00
|
|
|
u8 *buffer;
|
|
|
|
u16 ttype;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
rom_desc = kmalloc(sizeof(*rom_desc), GFP_KERNEL);
|
2013-12-29 18:22:56 +00:00
|
|
|
if (!rom_desc)
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENOMEM;
|
2013-12-29 18:22:56 +00:00
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
buffer = kmalloc(TI_MAX_I2C_SIZE, GFP_KERNEL);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!buffer) {
|
2008-04-29 13:45:15 +00:00
|
|
|
kfree(rom_desc);
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
/* Read the first byte (Signature0) must be 0x52 or 0x10 */
|
|
|
|
status = read_rom(serial, 0, 1, buffer);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (status)
|
2008-04-29 13:45:15 +00:00
|
|
|
goto out;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (*buffer != UMP5152 && *buffer != UMP3410) {
|
2008-04-29 13:45:15 +00:00
|
|
|
dev_err(dev, "%s - invalid buffer signature\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
status = -ENODEV;
|
2008-04-29 13:45:15 +00:00
|
|
|
goto out;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
2008-04-29 13:45:15 +00:00
|
|
|
/* Validate the I2C */
|
|
|
|
status = read_rom(serial,
|
2005-04-16 22:20:36 +00:00
|
|
|
start_address,
|
|
|
|
sizeof(struct ti_i2c_desc),
|
2021-04-12 09:47:32 +00:00
|
|
|
(u8 *)rom_desc);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (status)
|
|
|
|
break;
|
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
if ((start_address + sizeof(struct ti_i2c_desc) +
|
2014-04-25 13:23:03 +00:00
|
|
|
le16_to_cpu(rom_desc->Size)) > TI_MAX_I2C_SIZE) {
|
2005-04-16 22:20:36 +00:00
|
|
|
status = -ENODEV;
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s - structure too big, erroring out.\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s Type = 0x%x\n", __func__, rom_desc->Type);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
/* Skip type 2 record */
|
2005-04-16 22:20:36 +00:00
|
|
|
ttype = rom_desc->Type & 0x0f;
|
2008-04-29 13:45:15 +00:00
|
|
|
if (ttype != I2C_DESC_TYPE_FIRMWARE_BASIC
|
|
|
|
&& ttype != I2C_DESC_TYPE_FIRMWARE_AUTO) {
|
|
|
|
/* Read the descriptor data */
|
|
|
|
status = read_rom(serial, start_address +
|
|
|
|
sizeof(struct ti_i2c_desc),
|
2014-04-25 13:23:03 +00:00
|
|
|
le16_to_cpu(rom_desc->Size),
|
|
|
|
buffer);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (status)
|
|
|
|
break;
|
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
status = valid_csum(rom_desc, buffer);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (status)
|
|
|
|
break;
|
|
|
|
}
|
2008-04-29 13:45:15 +00:00
|
|
|
start_address = start_address + sizeof(struct ti_i2c_desc) +
|
2014-04-25 13:23:03 +00:00
|
|
|
le16_to_cpu(rom_desc->Size);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
} while ((rom_desc->Type != I2C_DESC_TYPE_ION) &&
|
|
|
|
(start_address < TI_MAX_I2C_SIZE));
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
if ((rom_desc->Type != I2C_DESC_TYPE_ION) ||
|
|
|
|
(start_address > TI_MAX_I2C_SIZE))
|
2005-04-16 22:20:36 +00:00
|
|
|
status = -ENODEV;
|
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
out:
|
|
|
|
kfree(buffer);
|
|
|
|
kfree(rom_desc);
|
2005-04-16 22:20:36 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2021-04-12 09:47:32 +00:00
|
|
|
static int get_manuf_info(struct edgeport_serial *serial, u8 *buffer)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int status;
|
|
|
|
int start_address;
|
|
|
|
struct ti_i2c_desc *rom_desc;
|
|
|
|
struct edge_ti_manuf_descriptor *desc;
|
2012-09-14 23:58:58 +00:00
|
|
|
struct device *dev = &serial->serial->dev->dev;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
rom_desc = kmalloc(sizeof(*rom_desc), GFP_KERNEL);
|
2013-12-29 18:22:56 +00:00
|
|
|
if (!rom_desc)
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENOMEM;
|
2013-12-29 18:22:56 +00:00
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
start_address = get_descriptor_addr(serial, I2C_DESC_TYPE_ION,
|
|
|
|
rom_desc);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (!start_address) {
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s - Edge Descriptor not found in I2C\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
status = -ENODEV;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
/* Read the descriptor data */
|
|
|
|
status = read_rom(serial, start_address+sizeof(struct ti_i2c_desc),
|
2014-04-25 13:23:03 +00:00
|
|
|
le16_to_cpu(rom_desc->Size), buffer);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (status)
|
|
|
|
goto exit;
|
2008-04-29 13:45:15 +00:00
|
|
|
|
|
|
|
status = valid_csum(rom_desc, buffer);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
desc = (struct edge_ti_manuf_descriptor *)buffer;
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s - IonConfig 0x%x\n", __func__, desc->IonConfig);
|
|
|
|
dev_dbg(dev, "%s - Version %d\n", __func__, desc->Version);
|
|
|
|
dev_dbg(dev, "%s - Cpu/Board 0x%x\n", __func__, desc->CpuRev_BoardRev);
|
|
|
|
dev_dbg(dev, "%s - NumPorts %d\n", __func__, desc->NumPorts);
|
|
|
|
dev_dbg(dev, "%s - NumVirtualPorts %d\n", __func__, desc->NumVirtualPorts);
|
|
|
|
dev_dbg(dev, "%s - TotalPorts %d\n", __func__, desc->TotalPorts);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
exit:
|
2008-04-29 13:45:15 +00:00
|
|
|
kfree(rom_desc);
|
2005-04-16 22:20:36 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Build firmware header used for firmware update */
|
2015-09-16 08:12:58 +00:00
|
|
|
static int build_i2c_fw_hdr(u8 *header, const struct firmware *fw)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2021-04-12 09:47:32 +00:00
|
|
|
u8 *buffer;
|
2005-04-16 22:20:36 +00:00
|
|
|
int buffer_size;
|
|
|
|
int i;
|
2021-04-12 09:47:32 +00:00
|
|
|
u8 cs = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct ti_i2c_desc *i2c_header;
|
|
|
|
struct ti_i2c_image_header *img_header;
|
|
|
|
struct ti_i2c_firmware_rec *firmware_rec;
|
2015-07-31 06:55:06 +00:00
|
|
|
struct edgeport_fw_hdr *fw_hdr = (struct edgeport_fw_hdr *)fw->data;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2015-09-16 08:13:02 +00:00
|
|
|
/*
|
|
|
|
* In order to update the I2C firmware we must change the type 2 record
|
2008-04-29 13:45:15 +00:00
|
|
|
* to type 0xF2. This will force the UMP to come up in Boot Mode.
|
|
|
|
* Then while in boot mode, the driver will download the latest
|
|
|
|
* firmware (padded to 15.5k) into the UMP ram. And finally when the
|
|
|
|
* device comes back up in download mode the driver will cause the new
|
|
|
|
* firmware to be copied from the UMP Ram to I2C and the firmware will
|
|
|
|
* update the record type from 0xf2 to 0x02.
|
|
|
|
*/
|
|
|
|
|
2015-09-16 08:13:02 +00:00
|
|
|
/*
|
|
|
|
* Allocate a 15.5k buffer + 2 bytes for version number (Firmware
|
|
|
|
* Record)
|
|
|
|
*/
|
2008-04-29 13:45:15 +00:00
|
|
|
buffer_size = (((1024 * 16) - 512 ) +
|
|
|
|
sizeof(struct ti_i2c_firmware_rec));
|
|
|
|
|
|
|
|
buffer = kmalloc(buffer_size, GFP_KERNEL);
|
2013-12-29 18:22:56 +00:00
|
|
|
if (!buffer)
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENOMEM;
|
2008-04-29 13:45:15 +00:00
|
|
|
|
2015-09-16 08:13:02 +00:00
|
|
|
/* Set entire image of 0xffs */
|
2008-04-29 13:45:15 +00:00
|
|
|
memset(buffer, 0xff, buffer_size);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
/* Copy version number into firmware record */
|
2005-04-16 22:20:36 +00:00
|
|
|
firmware_rec = (struct ti_i2c_firmware_rec *)buffer;
|
|
|
|
|
2015-07-31 06:55:06 +00:00
|
|
|
firmware_rec->Ver_Major = fw_hdr->major_version;
|
|
|
|
firmware_rec->Ver_Minor = fw_hdr->minor_version;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
/* Pointer to fw_down memory image */
|
2008-07-04 17:36:09 +00:00
|
|
|
img_header = (struct ti_i2c_image_header *)&fw->data[4];
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
memcpy(buffer + sizeof(struct ti_i2c_firmware_rec),
|
2008-07-04 17:36:09 +00:00
|
|
|
&fw->data[4 + sizeof(struct ti_i2c_image_header)],
|
2005-04-16 22:20:36 +00:00
|
|
|
le16_to_cpu(img_header->Length));
|
|
|
|
|
|
|
|
for (i=0; i < buffer_size; i++) {
|
2021-04-12 09:47:32 +00:00
|
|
|
cs = (u8)(cs + buffer[i]);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
kfree(buffer);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
/* Build new header */
|
2005-04-16 22:20:36 +00:00
|
|
|
i2c_header = (struct ti_i2c_desc *)header;
|
|
|
|
firmware_rec = (struct ti_i2c_firmware_rec*)i2c_header->Data;
|
2008-04-29 13:45:15 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
i2c_header->Type = I2C_DESC_TYPE_FIRMWARE_BLANK;
|
2014-04-26 09:53:44 +00:00
|
|
|
i2c_header->Size = cpu_to_le16(buffer_size);
|
2005-04-16 22:20:36 +00:00
|
|
|
i2c_header->CheckSum = cs;
|
2015-07-31 06:55:06 +00:00
|
|
|
firmware_rec->Ver_Major = fw_hdr->major_version;
|
|
|
|
firmware_rec->Ver_Minor = fw_hdr->minor_version;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Try to figure out what type of I2c we have */
|
2008-04-29 13:45:15 +00:00
|
|
|
static int i2c_type_bootmode(struct edgeport_serial *serial)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2012-09-14 23:58:58 +00:00
|
|
|
struct device *dev = &serial->serial->dev->dev;
|
2005-04-16 22:20:36 +00:00
|
|
|
int status;
|
2009-12-28 22:01:50 +00:00
|
|
|
u8 *data;
|
|
|
|
|
|
|
|
data = kmalloc(1, GFP_KERNEL);
|
2013-12-29 18:22:56 +00:00
|
|
|
if (!data)
|
2009-12-28 22:01:50 +00:00
|
|
|
return -ENOMEM;
|
2008-04-29 13:45:15 +00:00
|
|
|
|
|
|
|
/* Try to read type 2 */
|
|
|
|
status = ti_vread_sync(serial->serial->dev, UMPC_MEMORY_READ,
|
2009-12-28 22:01:50 +00:00
|
|
|
DTK_ADDR_SPACE_I2C_TYPE_II, 0, data, 0x01);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (status)
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s - read 2 status error = %d\n", __func__, status);
|
2005-04-16 22:20:36 +00:00
|
|
|
else
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s - read 2 data = 0x%x\n", __func__, *data);
|
2009-12-28 22:01:50 +00:00
|
|
|
if ((!status) && (*data == UMP5152 || *data == UMP3410)) {
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s - ROM_TYPE_II\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
|
2009-12-28 22:01:50 +00:00
|
|
|
goto out;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
/* Try to read type 3 */
|
|
|
|
status = ti_vread_sync(serial->serial->dev, UMPC_MEMORY_READ,
|
2009-12-28 22:01:50 +00:00
|
|
|
DTK_ADDR_SPACE_I2C_TYPE_III, 0, data, 0x01);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (status)
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s - read 3 status error = %d\n", __func__, status);
|
2005-04-16 22:20:36 +00:00
|
|
|
else
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s - read 2 data = 0x%x\n", __func__, *data);
|
2009-12-28 22:01:50 +00:00
|
|
|
if ((!status) && (*data == UMP5152 || *data == UMP3410)) {
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s - ROM_TYPE_III\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_III;
|
2009-12-28 22:01:50 +00:00
|
|
|
goto out;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s - Unknown\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
|
2009-12-28 22:01:50 +00:00
|
|
|
status = -ENODEV;
|
|
|
|
out:
|
|
|
|
kfree(data);
|
|
|
|
return status;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
static int bulk_xfer(struct usb_serial *serial, void *buffer,
|
|
|
|
int length, int *num_sent)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int status;
|
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
status = usb_bulk_msg(serial->dev,
|
|
|
|
usb_sndbulkpipe(serial->dev,
|
|
|
|
serial->port[0]->bulk_out_endpointAddress),
|
|
|
|
buffer, length, num_sent, 1000);
|
2005-04-16 22:20:36 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Download given firmware image to the device (IN BOOT MODE) */
|
2021-04-12 09:47:32 +00:00
|
|
|
static int download_code(struct edgeport_serial *serial, u8 *image,
|
2008-04-29 13:45:15 +00:00
|
|
|
int image_length)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int status = 0;
|
|
|
|
int pos;
|
|
|
|
int transfer;
|
|
|
|
int done;
|
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
/* Transfer firmware image */
|
2005-04-16 22:20:36 +00:00
|
|
|
for (pos = 0; pos < image_length; ) {
|
2008-04-29 13:45:15 +00:00
|
|
|
/* Read the next buffer from file */
|
2005-04-16 22:20:36 +00:00
|
|
|
transfer = image_length - pos;
|
|
|
|
if (transfer > EDGE_FW_BULK_MAX_PACKET_SIZE)
|
|
|
|
transfer = EDGE_FW_BULK_MAX_PACKET_SIZE;
|
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
/* Transfer data */
|
|
|
|
status = bulk_xfer(serial->serial, &image[pos],
|
|
|
|
transfer, &done);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (status)
|
|
|
|
break;
|
2008-04-29 13:45:15 +00:00
|
|
|
/* Advance buffer pointer */
|
2005-04-16 22:20:36 +00:00
|
|
|
pos += done;
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
/* FIXME!!! */
|
|
|
|
static int config_boot_dev(struct usb_device *dev)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
static int ti_cpu_rev(struct edge_ti_manuf_descriptor *desc)
|
|
|
|
{
|
|
|
|
return TI_GET_CPU_REVISION(desc->CpuRev_BoardRev);
|
|
|
|
}
|
|
|
|
|
2015-07-31 06:55:07 +00:00
|
|
|
static int check_fw_sanity(struct edgeport_serial *serial,
|
|
|
|
const struct firmware *fw)
|
|
|
|
{
|
|
|
|
u16 length_total;
|
|
|
|
u8 checksum = 0;
|
|
|
|
int pos;
|
|
|
|
struct device *dev = &serial->serial->interface->dev;
|
|
|
|
struct edgeport_fw_hdr *fw_hdr = (struct edgeport_fw_hdr *)fw->data;
|
|
|
|
|
|
|
|
if (fw->size < sizeof(struct edgeport_fw_hdr)) {
|
|
|
|
dev_err(dev, "incomplete fw header\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
length_total = le16_to_cpu(fw_hdr->length) +
|
|
|
|
sizeof(struct edgeport_fw_hdr);
|
|
|
|
|
|
|
|
if (fw->size != length_total) {
|
|
|
|
dev_err(dev, "bad fw size (expected: %u, got: %zu)\n",
|
|
|
|
length_total, fw->size);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (pos = sizeof(struct edgeport_fw_hdr); pos < fw->size; ++pos)
|
|
|
|
checksum += fw->data[pos];
|
|
|
|
|
|
|
|
if (checksum != fw_hdr->checksum) {
|
|
|
|
dev_err(dev, "bad fw checksum (expected: 0x%x, got: 0x%x)\n",
|
|
|
|
fw_hdr->checksum, checksum);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-09-16 08:13:02 +00:00
|
|
|
/*
|
2005-04-16 22:20:36 +00:00
|
|
|
* DownloadTIFirmware - Download run-time operating firmware to the TI5052
|
2008-04-29 13:45:15 +00:00
|
|
|
*
|
2005-04-16 22:20:36 +00:00
|
|
|
* This routine downloads the main operating code into the TI5052, using the
|
|
|
|
* boot code already burned into E2PROM or ROM.
|
|
|
|
*/
|
2015-09-16 08:13:01 +00:00
|
|
|
static int download_fw(struct edgeport_serial *serial)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2015-09-16 08:12:59 +00:00
|
|
|
struct device *dev = &serial->serial->interface->dev;
|
2005-04-16 22:20:36 +00:00
|
|
|
int status = 0;
|
|
|
|
struct usb_interface_descriptor *interface;
|
2015-09-16 08:13:01 +00:00
|
|
|
const struct firmware *fw;
|
|
|
|
const char *fw_name = "edgeport/down3.bin";
|
|
|
|
struct edgeport_fw_hdr *fw_hdr;
|
2015-07-31 06:55:06 +00:00
|
|
|
|
2015-09-16 08:13:01 +00:00
|
|
|
status = request_firmware(&fw, fw_name, dev);
|
|
|
|
if (status) {
|
|
|
|
dev_err(dev, "Failed to load image \"%s\" err %d\n",
|
|
|
|
fw_name, status);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (check_fw_sanity(serial, fw)) {
|
|
|
|
status = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
2015-07-31 06:55:06 +00:00
|
|
|
|
2015-09-16 08:13:01 +00:00
|
|
|
fw_hdr = (struct edgeport_fw_hdr *)fw->data;
|
|
|
|
|
|
|
|
/* If on-board version is newer, "fw_version" will be updated later. */
|
2015-07-31 06:55:06 +00:00
|
|
|
serial->fw_version = (fw_hdr->major_version << 8) +
|
|
|
|
fw_hdr->minor_version;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2015-09-16 08:13:02 +00:00
|
|
|
/*
|
|
|
|
* This routine is entered by both the BOOT mode and the Download mode
|
2005-04-16 22:20:36 +00:00
|
|
|
* We can determine which code is running by the reading the config
|
|
|
|
* descriptor and if we have only one bulk pipe it is in boot mode
|
|
|
|
*/
|
|
|
|
serial->product_info.hardware_type = HARDWARE_TYPE_TIUMP;
|
|
|
|
|
|
|
|
/* Default to type 2 i2c */
|
|
|
|
serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
|
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
status = choose_config(serial->serial->dev);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (status)
|
2015-09-16 08:13:01 +00:00
|
|
|
goto out;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
interface = &serial->serial->interface->cur_altsetting->desc;
|
|
|
|
if (!interface) {
|
2008-04-29 13:45:15 +00:00
|
|
|
dev_err(dev, "%s - no interface set, error!\n", __func__);
|
2015-09-16 08:13:01 +00:00
|
|
|
status = -ENODEV;
|
|
|
|
goto out;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
/*
|
|
|
|
* Setup initial mode -- the default mode 0 is TI_MODE_CONFIGURING
|
|
|
|
* if we have more than one endpoint we are definitely in download
|
|
|
|
* mode
|
|
|
|
*/
|
2015-09-16 08:13:00 +00:00
|
|
|
if (interface->bNumEndpoints > 1) {
|
2005-04-16 22:20:36 +00:00
|
|
|
serial->product_info.TiMode = TI_MODE_DOWNLOAD;
|
2015-09-16 08:13:01 +00:00
|
|
|
status = do_download_mode(serial, fw);
|
|
|
|
} else {
|
|
|
|
/* Otherwise we will remain in configuring mode */
|
|
|
|
serial->product_info.TiMode = TI_MODE_CONFIGURING;
|
|
|
|
status = do_boot_mode(serial, fw);
|
2015-09-16 08:13:00 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2015-09-16 08:13:01 +00:00
|
|
|
out:
|
|
|
|
release_firmware(fw);
|
|
|
|
return status;
|
2015-09-16 08:13:00 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2015-09-16 08:13:00 +00:00
|
|
|
static int do_download_mode(struct edgeport_serial *serial,
|
|
|
|
const struct firmware *fw)
|
|
|
|
{
|
|
|
|
struct device *dev = &serial->serial->interface->dev;
|
|
|
|
int status = 0;
|
|
|
|
int start_address;
|
|
|
|
struct edge_ti_manuf_descriptor *ti_manuf_desc;
|
|
|
|
int download_cur_ver;
|
|
|
|
int download_new_ver;
|
|
|
|
struct edgeport_fw_hdr *fw_hdr = (struct edgeport_fw_hdr *)fw->data;
|
|
|
|
struct ti_i2c_desc *rom_desc;
|
2008-04-29 13:45:15 +00:00
|
|
|
|
2015-09-16 08:13:00 +00:00
|
|
|
dev_dbg(dev, "%s - RUNNING IN DOWNLOAD MODE\n", __func__);
|
2013-12-29 18:22:56 +00:00
|
|
|
|
2015-09-16 08:13:00 +00:00
|
|
|
status = check_i2c_image(serial);
|
|
|
|
if (status) {
|
|
|
|
dev_dbg(dev, "%s - DOWNLOAD MODE -- BAD I2C\n", __func__);
|
|
|
|
return status;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2015-09-16 08:13:02 +00:00
|
|
|
/*
|
|
|
|
* Validate Hardware version number
|
2015-09-16 08:13:00 +00:00
|
|
|
* Read Manufacturing Descriptor from TI Based Edgeport
|
|
|
|
*/
|
|
|
|
ti_manuf_desc = kmalloc(sizeof(*ti_manuf_desc), GFP_KERNEL);
|
|
|
|
if (!ti_manuf_desc)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2021-04-12 09:47:32 +00:00
|
|
|
status = get_manuf_info(serial, (u8 *)ti_manuf_desc);
|
2015-09-16 08:13:00 +00:00
|
|
|
if (status) {
|
|
|
|
kfree(ti_manuf_desc);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check version number of ION descriptor */
|
|
|
|
if (!ignore_cpu_rev && ti_cpu_rev(ti_manuf_desc) < 2) {
|
|
|
|
dev_dbg(dev, "%s - Wrong CPU Rev %d (Must be 2)\n",
|
|
|
|
__func__, ti_cpu_rev(ti_manuf_desc));
|
|
|
|
kfree(ti_manuf_desc);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
rom_desc = kmalloc(sizeof(*rom_desc), GFP_KERNEL);
|
|
|
|
if (!rom_desc) {
|
|
|
|
kfree(ti_manuf_desc);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Search for type 2 record (firmware record) */
|
|
|
|
start_address = get_descriptor_addr(serial,
|
|
|
|
I2C_DESC_TYPE_FIRMWARE_BASIC, rom_desc);
|
|
|
|
if (start_address != 0) {
|
|
|
|
struct ti_i2c_firmware_rec *firmware_version;
|
|
|
|
u8 *record;
|
|
|
|
|
|
|
|
dev_dbg(dev, "%s - Found Type FIRMWARE (Type 2) record\n",
|
|
|
|
__func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2015-09-16 08:13:00 +00:00
|
|
|
firmware_version = kmalloc(sizeof(*firmware_version),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!firmware_version) {
|
|
|
|
kfree(rom_desc);
|
2008-04-29 13:45:15 +00:00
|
|
|
kfree(ti_manuf_desc);
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2015-09-16 08:13:02 +00:00
|
|
|
/*
|
|
|
|
* Validate version number
|
2015-09-16 08:13:00 +00:00
|
|
|
* Read the descriptor data
|
|
|
|
*/
|
|
|
|
status = read_rom(serial, start_address +
|
|
|
|
sizeof(struct ti_i2c_desc),
|
|
|
|
sizeof(struct ti_i2c_firmware_rec),
|
2021-04-12 09:47:32 +00:00
|
|
|
(u8 *)firmware_version);
|
2015-09-16 08:13:00 +00:00
|
|
|
if (status) {
|
|
|
|
kfree(firmware_version);
|
|
|
|
kfree(rom_desc);
|
|
|
|
kfree(ti_manuf_desc);
|
|
|
|
return status;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2015-09-16 08:13:02 +00:00
|
|
|
/*
|
|
|
|
* Check version number of download with current
|
|
|
|
* version in I2c
|
|
|
|
*/
|
2015-09-16 08:13:00 +00:00
|
|
|
download_cur_ver = (firmware_version->Ver_Major << 8) +
|
|
|
|
(firmware_version->Ver_Minor);
|
|
|
|
download_new_ver = (fw_hdr->major_version << 8) +
|
|
|
|
(fw_hdr->minor_version);
|
|
|
|
|
|
|
|
dev_dbg(dev, "%s - >> FW Versions Device %d.%d Driver %d.%d\n",
|
|
|
|
__func__, firmware_version->Ver_Major,
|
|
|
|
firmware_version->Ver_Minor,
|
|
|
|
fw_hdr->major_version, fw_hdr->minor_version);
|
|
|
|
|
2015-09-16 08:13:02 +00:00
|
|
|
/*
|
|
|
|
* Check if we have an old version in the I2C and
|
|
|
|
* update if necessary
|
|
|
|
*/
|
2015-09-16 08:13:00 +00:00
|
|
|
if (download_cur_ver < download_new_ver) {
|
|
|
|
dev_dbg(dev, "%s - Update I2C dld from %d.%d to %d.%d\n",
|
|
|
|
__func__,
|
|
|
|
firmware_version->Ver_Major,
|
|
|
|
firmware_version->Ver_Minor,
|
|
|
|
fw_hdr->major_version,
|
|
|
|
fw_hdr->minor_version);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2015-09-16 08:13:00 +00:00
|
|
|
record = kmalloc(1, GFP_KERNEL);
|
|
|
|
if (!record) {
|
|
|
|
kfree(firmware_version);
|
2008-04-29 13:45:15 +00:00
|
|
|
kfree(rom_desc);
|
|
|
|
kfree(ti_manuf_desc);
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2015-09-16 08:13:00 +00:00
|
|
|
/*
|
|
|
|
* In order to update the I2C firmware we must
|
|
|
|
* change the type 2 record to type 0xF2. This
|
|
|
|
* will force the UMP to come up in Boot Mode.
|
|
|
|
* Then while in boot mode, the driver will
|
|
|
|
* download the latest firmware (padded to
|
|
|
|
* 15.5k) into the UMP ram. Finally when the
|
|
|
|
* device comes back up in download mode the
|
|
|
|
* driver will cause the new firmware to be
|
|
|
|
* copied from the UMP Ram to I2C and the
|
|
|
|
* firmware will update the record type from
|
|
|
|
* 0xf2 to 0x02.
|
2008-04-29 13:45:15 +00:00
|
|
|
*/
|
2015-09-16 08:13:00 +00:00
|
|
|
*record = I2C_DESC_TYPE_FIRMWARE_BLANK;
|
|
|
|
|
2015-09-16 08:13:02 +00:00
|
|
|
/*
|
|
|
|
* Change the I2C Firmware record type to
|
|
|
|
* 0xf2 to trigger an update
|
|
|
|
*/
|
2015-09-16 08:13:00 +00:00
|
|
|
status = write_rom(serial, start_address,
|
|
|
|
sizeof(*record), record);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (status) {
|
2015-09-16 08:13:00 +00:00
|
|
|
kfree(record);
|
2008-04-29 13:45:15 +00:00
|
|
|
kfree(firmware_version);
|
|
|
|
kfree(rom_desc);
|
|
|
|
kfree(ti_manuf_desc);
|
2005-04-16 22:20:36 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2015-09-16 08:13:02 +00:00
|
|
|
/*
|
|
|
|
* verify the write -- must do this in order
|
2015-09-16 08:13:00 +00:00
|
|
|
* for write to complete before we do the
|
|
|
|
* hardware reset
|
|
|
|
*/
|
|
|
|
status = read_rom(serial,
|
|
|
|
start_address,
|
|
|
|
sizeof(*record),
|
|
|
|
record);
|
|
|
|
if (status) {
|
|
|
|
kfree(record);
|
|
|
|
kfree(firmware_version);
|
|
|
|
kfree(rom_desc);
|
|
|
|
kfree(ti_manuf_desc);
|
|
|
|
return status;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2015-09-16 08:13:00 +00:00
|
|
|
if (*record != I2C_DESC_TYPE_FIRMWARE_BLANK) {
|
|
|
|
dev_err(dev, "%s - error resetting device\n",
|
|
|
|
__func__);
|
2009-12-28 22:01:50 +00:00
|
|
|
kfree(record);
|
2008-04-29 13:45:15 +00:00
|
|
|
kfree(firmware_version);
|
|
|
|
kfree(rom_desc);
|
|
|
|
kfree(ti_manuf_desc);
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
2015-09-16 08:13:00 +00:00
|
|
|
|
|
|
|
dev_dbg(dev, "%s - HARDWARE RESET\n", __func__);
|
|
|
|
|
|
|
|
/* Reset UMP -- Back to BOOT MODE */
|
|
|
|
status = ti_vsend_sync(serial->serial->dev,
|
|
|
|
UMPC_HARDWARE_RESET,
|
|
|
|
0, 0, NULL, 0,
|
|
|
|
TI_VSEND_TIMEOUT_DEFAULT);
|
|
|
|
|
|
|
|
dev_dbg(dev, "%s - HARDWARE RESET return %d\n",
|
|
|
|
__func__, status);
|
|
|
|
|
|
|
|
/* return an error on purpose. */
|
|
|
|
kfree(record);
|
2008-04-29 13:45:15 +00:00
|
|
|
kfree(firmware_version);
|
2015-09-16 08:13:00 +00:00
|
|
|
kfree(rom_desc);
|
|
|
|
kfree(ti_manuf_desc);
|
|
|
|
return -ENODEV;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2015-09-16 08:13:00 +00:00
|
|
|
/* Same or newer fw version is already loaded */
|
|
|
|
serial->fw_version = download_cur_ver;
|
|
|
|
kfree(firmware_version);
|
|
|
|
}
|
|
|
|
/* Search for type 0xF2 record (firmware blank record) */
|
|
|
|
else {
|
|
|
|
start_address = get_descriptor_addr(serial,
|
|
|
|
I2C_DESC_TYPE_FIRMWARE_BLANK, rom_desc);
|
|
|
|
if (start_address != 0) {
|
2008-04-29 13:45:15 +00:00
|
|
|
#define HEADER_SIZE (sizeof(struct ti_i2c_desc) + \
|
2015-09-16 08:13:00 +00:00
|
|
|
sizeof(struct ti_i2c_firmware_rec))
|
2021-04-12 09:47:32 +00:00
|
|
|
u8 *header;
|
|
|
|
u8 *vheader;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
header = kmalloc(HEADER_SIZE, GFP_KERNEL);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!header) {
|
2008-04-29 13:45:15 +00:00
|
|
|
kfree(rom_desc);
|
|
|
|
kfree(ti_manuf_desc);
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2008-04-29 13:45:15 +00:00
|
|
|
|
|
|
|
vheader = kmalloc(HEADER_SIZE, GFP_KERNEL);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!vheader) {
|
2008-04-29 13:45:15 +00:00
|
|
|
kfree(header);
|
|
|
|
kfree(rom_desc);
|
|
|
|
kfree(ti_manuf_desc);
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2008-04-29 13:45:15 +00:00
|
|
|
|
2015-09-16 08:13:00 +00:00
|
|
|
dev_dbg(dev, "%s - Found Type BLANK FIRMWARE (Type F2) record\n",
|
|
|
|
__func__);
|
2008-04-29 13:45:15 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* In order to update the I2C firmware we must change
|
|
|
|
* the type 2 record to type 0xF2. This will force the
|
|
|
|
* UMP to come up in Boot Mode. Then while in boot
|
|
|
|
* mode, the driver will download the latest firmware
|
|
|
|
* (padded to 15.5k) into the UMP ram. Finally when the
|
|
|
|
* device comes back up in download mode the driver
|
|
|
|
* will cause the new firmware to be copied from the
|
|
|
|
* UMP Ram to I2C and the firmware will update the
|
|
|
|
* record type from 0xf2 to 0x02.
|
|
|
|
*/
|
2015-09-16 08:12:58 +00:00
|
|
|
status = build_i2c_fw_hdr(header, fw);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (status) {
|
2008-04-29 13:45:15 +00:00
|
|
|
kfree(vheader);
|
|
|
|
kfree(header);
|
|
|
|
kfree(rom_desc);
|
|
|
|
kfree(ti_manuf_desc);
|
2010-08-10 21:29:19 +00:00
|
|
|
return -EINVAL;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2015-09-16 08:13:02 +00:00
|
|
|
/*
|
|
|
|
* Update I2C with type 0xf2 record with correct
|
|
|
|
* size and checksum
|
|
|
|
*/
|
2008-04-29 13:45:15 +00:00
|
|
|
status = write_rom(serial,
|
2005-04-16 22:20:36 +00:00
|
|
|
start_address,
|
|
|
|
HEADER_SIZE,
|
|
|
|
header);
|
|
|
|
if (status) {
|
2008-04-29 13:45:15 +00:00
|
|
|
kfree(vheader);
|
|
|
|
kfree(header);
|
|
|
|
kfree(rom_desc);
|
|
|
|
kfree(ti_manuf_desc);
|
2010-07-20 22:29:08 +00:00
|
|
|
return -EINVAL;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2015-09-16 08:13:02 +00:00
|
|
|
/*
|
|
|
|
* verify the write -- must do this in order for
|
|
|
|
* write to complete before we do the hardware reset
|
|
|
|
*/
|
2008-04-29 13:45:15 +00:00
|
|
|
status = read_rom(serial, start_address,
|
|
|
|
HEADER_SIZE, vheader);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (status) {
|
2015-09-16 08:13:00 +00:00
|
|
|
dev_dbg(dev, "%s - can't read header back\n",
|
|
|
|
__func__);
|
2008-04-29 13:45:15 +00:00
|
|
|
kfree(vheader);
|
|
|
|
kfree(header);
|
|
|
|
kfree(rom_desc);
|
|
|
|
kfree(ti_manuf_desc);
|
2005-04-16 22:20:36 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
if (memcmp(vheader, header, HEADER_SIZE)) {
|
2015-09-16 08:13:00 +00:00
|
|
|
dev_dbg(dev, "%s - write download record failed\n",
|
|
|
|
__func__);
|
2008-04-29 13:45:15 +00:00
|
|
|
kfree(vheader);
|
|
|
|
kfree(header);
|
|
|
|
kfree(rom_desc);
|
|
|
|
kfree(ti_manuf_desc);
|
2010-07-01 22:36:43 +00:00
|
|
|
return -EINVAL;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
kfree(vheader);
|
|
|
|
kfree(header);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s - Start firmware update\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
/* Tell firmware to copy download image into I2C */
|
|
|
|
status = ti_vsend_sync(serial->serial->dev,
|
2015-07-31 06:55:05 +00:00
|
|
|
UMPC_COPY_DNLD_TO_I2C,
|
|
|
|
0, 0, NULL, 0,
|
|
|
|
TI_VSEND_TIMEOUT_FW_DOWNLOAD);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2015-09-16 08:13:00 +00:00
|
|
|
dev_dbg(dev, "%s - Update complete 0x%x\n", __func__,
|
|
|
|
status);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (status) {
|
2008-04-29 13:45:15 +00:00
|
|
|
dev_err(dev,
|
|
|
|
"%s - UMPC_COPY_DNLD_TO_I2C failed\n",
|
2015-09-16 08:13:00 +00:00
|
|
|
__func__);
|
2008-04-29 13:45:15 +00:00
|
|
|
kfree(rom_desc);
|
|
|
|
kfree(ti_manuf_desc);
|
2005-04-16 22:20:36 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-16 08:13:00 +00:00
|
|
|
/* The device is running the download code */
|
|
|
|
kfree(rom_desc);
|
|
|
|
kfree(ti_manuf_desc);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int do_boot_mode(struct edgeport_serial *serial,
|
|
|
|
const struct firmware *fw)
|
|
|
|
{
|
|
|
|
struct device *dev = &serial->serial->interface->dev;
|
|
|
|
int status = 0;
|
|
|
|
struct edge_ti_manuf_descriptor *ti_manuf_desc;
|
|
|
|
struct edgeport_fw_hdr *fw_hdr = (struct edgeport_fw_hdr *)fw->data;
|
|
|
|
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s - RUNNING IN BOOT MODE\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
/* Configure the TI device so we can use the BULK pipes for download */
|
|
|
|
status = config_boot_dev(serial->serial->dev);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
if (le16_to_cpu(serial->serial->dev->descriptor.idVendor)
|
|
|
|
!= USB_VENDOR_ID_ION) {
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s - VID = 0x%x\n", __func__,
|
|
|
|
le16_to_cpu(serial->serial->dev->descriptor.idVendor));
|
2005-04-16 22:20:36 +00:00
|
|
|
serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
|
2008-04-29 13:45:15 +00:00
|
|
|
goto stayinbootmode;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2015-09-16 08:13:02 +00:00
|
|
|
/*
|
|
|
|
* We have an ION device (I2c Must be programmed)
|
|
|
|
* Determine I2C image type
|
|
|
|
*/
|
2008-04-29 13:45:15 +00:00
|
|
|
if (i2c_type_bootmode(serial))
|
|
|
|
goto stayinbootmode;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
/* Check for ION Vendor ID and that the I2C is valid */
|
|
|
|
if (!check_i2c_image(serial)) {
|
2005-04-16 22:20:36 +00:00
|
|
|
struct ti_i2c_image_header *header;
|
|
|
|
int i;
|
2021-04-12 09:47:32 +00:00
|
|
|
u8 cs = 0;
|
|
|
|
u8 *buffer;
|
2005-04-16 22:20:36 +00:00
|
|
|
int buffer_size;
|
|
|
|
|
2015-09-16 08:13:02 +00:00
|
|
|
/*
|
|
|
|
* Validate Hardware version number
|
2005-04-16 22:20:36 +00:00
|
|
|
* Read Manufacturing Descriptor from TI Based Edgeport
|
|
|
|
*/
|
2008-04-29 13:45:15 +00:00
|
|
|
ti_manuf_desc = kmalloc(sizeof(*ti_manuf_desc), GFP_KERNEL);
|
2013-12-29 18:22:56 +00:00
|
|
|
if (!ti_manuf_desc)
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENOMEM;
|
2013-12-29 18:22:56 +00:00
|
|
|
|
2021-04-12 09:47:32 +00:00
|
|
|
status = get_manuf_info(serial, (u8 *)ti_manuf_desc);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (status) {
|
2008-04-29 13:45:15 +00:00
|
|
|
kfree(ti_manuf_desc);
|
|
|
|
goto stayinbootmode;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
/* Check for version 2 */
|
|
|
|
if (!ignore_cpu_rev && ti_cpu_rev(ti_manuf_desc) < 2) {
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s - Wrong CPU Rev %d (Must be 2)\n",
|
|
|
|
__func__, ti_cpu_rev(ti_manuf_desc));
|
2008-04-29 13:45:15 +00:00
|
|
|
kfree(ti_manuf_desc);
|
|
|
|
goto stayinbootmode;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
kfree(ti_manuf_desc);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
2008-04-29 13:45:15 +00:00
|
|
|
* In order to update the I2C firmware we must change the type
|
|
|
|
* 2 record to type 0xF2. This will force the UMP to come up
|
|
|
|
* in Boot Mode. Then while in boot mode, the driver will
|
|
|
|
* download the latest firmware (padded to 15.5k) into the
|
|
|
|
* UMP ram. Finally when the device comes back up in download
|
|
|
|
* mode the driver will cause the new firmware to be copied
|
|
|
|
* from the UMP Ram to I2C and the firmware will update the
|
|
|
|
* record type from 0xf2 to 0x02.
|
|
|
|
*
|
2005-04-16 22:20:36 +00:00
|
|
|
* Do we really have to copy the whole firmware image,
|
|
|
|
* or could we do this in place!
|
|
|
|
*/
|
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
/* Allocate a 15.5k buffer + 3 byte header */
|
|
|
|
buffer_size = (((1024 * 16) - 512) +
|
|
|
|
sizeof(struct ti_i2c_image_header));
|
|
|
|
buffer = kmalloc(buffer_size, GFP_KERNEL);
|
2013-12-29 18:22:56 +00:00
|
|
|
if (!buffer)
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENOMEM;
|
2008-04-29 13:45:15 +00:00
|
|
|
|
|
|
|
/* Initialize the buffer to 0xff (pad the buffer) */
|
|
|
|
memset(buffer, 0xff, buffer_size);
|
2008-07-04 17:36:09 +00:00
|
|
|
memcpy(buffer, &fw->data[4], fw->size - 4);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
for (i = sizeof(struct ti_i2c_image_header);
|
|
|
|
i < buffer_size; i++) {
|
2021-04-12 09:47:32 +00:00
|
|
|
cs = (u8)(cs + buffer[i]);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2008-04-29 13:45:15 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
header = (struct ti_i2c_image_header *)buffer;
|
2008-04-29 13:45:15 +00:00
|
|
|
|
|
|
|
/* update length and checksum after padding */
|
2021-04-12 09:47:32 +00:00
|
|
|
header->Length = cpu_to_le16((u16)(buffer_size -
|
2008-04-29 13:45:15 +00:00
|
|
|
sizeof(struct ti_i2c_image_header)));
|
2005-04-16 22:20:36 +00:00
|
|
|
header->CheckSum = cs;
|
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
/* Download the operational code */
|
2015-07-31 06:55:06 +00:00
|
|
|
dev_dbg(dev, "%s - Downloading operational code image version %d.%d (TI UMP)\n",
|
|
|
|
__func__,
|
|
|
|
fw_hdr->major_version, fw_hdr->minor_version);
|
2008-04-29 13:45:15 +00:00
|
|
|
status = download_code(serial, buffer, buffer_size);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
kfree(buffer);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (status) {
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s - Error downloading operational code image\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
/* Device will reboot */
|
2005-04-16 22:20:36 +00:00
|
|
|
serial->product_info.TiMode = TI_MODE_TRANSITIONING;
|
|
|
|
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s - Download successful -- Device rebooting...\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2017-01-03 15:39:46 +00:00
|
|
|
return 1;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
stayinbootmode:
|
|
|
|
/* Eprom is invalid or blank stay in boot mode */
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s - STAYING IN BOOT MODE\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
serial->product_info.TiMode = TI_MODE_BOOT;
|
|
|
|
|
2017-01-03 15:39:44 +00:00
|
|
|
return 1;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
static int ti_do_config(struct edgeport_port *port, int feature, int on)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-04-29 13:45:15 +00:00
|
|
|
on = !!on; /* 1 or 0 not bitmask */
|
2021-04-12 09:47:30 +00:00
|
|
|
|
|
|
|
return send_port_cmd(port->port, feature, on, NULL, 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2021-04-12 09:47:32 +00:00
|
|
|
static int restore_mcr(struct edgeport_port *port, u8 mcr)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int status = 0;
|
|
|
|
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(&port->port->dev, "%s - %x\n", __func__, mcr);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
status = ti_do_config(port, UMPC_SET_CLR_DTR, mcr & MCR_DTR);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (status)
|
|
|
|
return status;
|
2008-04-29 13:45:15 +00:00
|
|
|
status = ti_do_config(port, UMPC_SET_CLR_RTS, mcr & MCR_RTS);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (status)
|
|
|
|
return status;
|
2008-04-29 13:45:15 +00:00
|
|
|
return ti_do_config(port, UMPC_SET_CLR_LOOPBACK, mcr & MCR_LOOPBACK);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Convert TI LSR to standard UART flags */
|
2021-04-12 09:47:32 +00:00
|
|
|
static u8 map_line_status(u8 ti_lsr)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2021-04-12 09:47:32 +00:00
|
|
|
u8 lsr = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#define MAP_FLAG(flagUmp, flagUart) \
|
|
|
|
if (ti_lsr & flagUmp) \
|
|
|
|
lsr |= flagUart;
|
|
|
|
|
|
|
|
MAP_FLAG(UMP_UART_LSR_OV_MASK, LSR_OVER_ERR) /* overrun */
|
|
|
|
MAP_FLAG(UMP_UART_LSR_PE_MASK, LSR_PAR_ERR) /* parity error */
|
|
|
|
MAP_FLAG(UMP_UART_LSR_FE_MASK, LSR_FRM_ERR) /* framing error */
|
|
|
|
MAP_FLAG(UMP_UART_LSR_BR_MASK, LSR_BREAK) /* break detected */
|
2008-04-29 13:45:15 +00:00
|
|
|
MAP_FLAG(UMP_UART_LSR_RX_MASK, LSR_RX_AVAIL) /* rx data available */
|
|
|
|
MAP_FLAG(UMP_UART_LSR_TX_MASK, LSR_TX_EMPTY) /* tx hold reg empty */
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#undef MAP_FLAG
|
|
|
|
|
|
|
|
return lsr;
|
|
|
|
}
|
|
|
|
|
2021-04-12 09:47:32 +00:00
|
|
|
static void handle_new_msr(struct edgeport_port *edge_port, u8 msr)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct async_icount *icount;
|
|
|
|
struct tty_struct *tty;
|
|
|
|
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(&edge_port->port->dev, "%s - %02x\n", __func__, msr);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
if (msr & (EDGEPORT_MSR_DELTA_CTS | EDGEPORT_MSR_DELTA_DSR |
|
|
|
|
EDGEPORT_MSR_DELTA_RI | EDGEPORT_MSR_DELTA_CD)) {
|
2013-03-21 11:37:09 +00:00
|
|
|
icount = &edge_port->port->icount;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* update input line counters */
|
|
|
|
if (msr & EDGEPORT_MSR_DELTA_CTS)
|
|
|
|
icount->cts++;
|
|
|
|
if (msr & EDGEPORT_MSR_DELTA_DSR)
|
|
|
|
icount->dsr++;
|
|
|
|
if (msr & EDGEPORT_MSR_DELTA_CD)
|
|
|
|
icount->dcd++;
|
|
|
|
if (msr & EDGEPORT_MSR_DELTA_RI)
|
|
|
|
icount->rng++;
|
2013-03-21 11:37:10 +00:00
|
|
|
wake_up_interruptible(&edge_port->port->port.delta_msr_wait);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Save the new modem status */
|
|
|
|
edge_port->shadow_msr = msr & 0xf0;
|
|
|
|
|
2008-10-13 09:39:46 +00:00
|
|
|
tty = tty_port_tty_get(&edge_port->port->port);
|
2005-04-16 22:20:36 +00:00
|
|
|
/* handle CTS flow control */
|
|
|
|
if (tty && C_CRTSCTS(tty)) {
|
2014-09-10 19:06:27 +00:00
|
|
|
if (msr & EDGEPORT_MSR_CTS)
|
2005-04-16 22:20:36 +00:00
|
|
|
tty_wakeup(tty);
|
|
|
|
}
|
2008-10-13 09:39:46 +00:00
|
|
|
tty_kref_put(tty);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
static void handle_new_lsr(struct edgeport_port *edge_port, int lsr_data,
|
2021-04-12 09:47:32 +00:00
|
|
|
u8 lsr, u8 data)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct async_icount *icount;
|
2021-04-12 09:47:32 +00:00
|
|
|
u8 new_lsr = (u8)(lsr & (u8)(LSR_OVER_ERR | LSR_PAR_ERR |
|
2008-04-29 13:45:15 +00:00
|
|
|
LSR_FRM_ERR | LSR_BREAK));
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(&edge_port->port->dev, "%s - %02x\n", __func__, new_lsr);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
edge_port->shadow_lsr = lsr;
|
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
if (new_lsr & LSR_BREAK)
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Parity and Framing errors only count if they
|
|
|
|
* occur exclusive of a break being received.
|
|
|
|
*/
|
2021-04-12 09:47:32 +00:00
|
|
|
new_lsr &= (u8)(LSR_OVER_ERR | LSR_BREAK);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* Place LSR data byte into Rx buffer */
|
2013-01-03 14:53:06 +00:00
|
|
|
if (lsr_data)
|
|
|
|
edge_tty_recv(edge_port->port, &data, 1);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* update input line counters */
|
2013-03-21 11:37:09 +00:00
|
|
|
icount = &edge_port->port->icount;
|
2005-04-16 22:20:36 +00:00
|
|
|
if (new_lsr & LSR_BREAK)
|
|
|
|
icount->brk++;
|
|
|
|
if (new_lsr & LSR_OVER_ERR)
|
|
|
|
icount->overrun++;
|
|
|
|
if (new_lsr & LSR_PAR_ERR)
|
|
|
|
icount->parity++;
|
|
|
|
if (new_lsr & LSR_FRM_ERR)
|
|
|
|
icount->frame++;
|
|
|
|
}
|
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
static void edge_interrupt_callback(struct urb *urb)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-02-24 10:41:47 +00:00
|
|
|
struct edgeport_serial *edge_serial = urb->context;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct usb_serial_port *port;
|
|
|
|
struct edgeport_port *edge_port;
|
2012-09-14 23:58:58 +00:00
|
|
|
struct device *dev;
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned char *data = urb->transfer_buffer;
|
|
|
|
int length = urb->actual_length;
|
|
|
|
int port_number;
|
|
|
|
int function;
|
2007-06-15 22:44:13 +00:00
|
|
|
int retval;
|
2021-04-12 09:47:32 +00:00
|
|
|
u8 lsr;
|
|
|
|
u8 msr;
|
2007-06-15 22:44:13 +00:00
|
|
|
int status = urb->status;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-06-15 22:44:13 +00:00
|
|
|
switch (status) {
|
2005-04-16 22:20:36 +00:00
|
|
|
case 0:
|
|
|
|
/* success */
|
|
|
|
break;
|
|
|
|
case -ECONNRESET:
|
|
|
|
case -ENOENT:
|
|
|
|
case -ESHUTDOWN:
|
|
|
|
/* this urb is terminated, clean up */
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(&urb->dev->dev, "%s - urb shutting down with status: %d\n",
|
2008-03-04 00:08:34 +00:00
|
|
|
__func__, status);
|
2005-04-16 22:20:36 +00:00
|
|
|
return;
|
|
|
|
default:
|
2007-06-15 22:44:13 +00:00
|
|
|
dev_err(&urb->dev->dev, "%s - nonzero urb status received: "
|
2008-03-04 00:08:34 +00:00
|
|
|
"%d\n", __func__, status);
|
2005-04-16 22:20:36 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!length) {
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(&urb->dev->dev, "%s - no data in urb\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
2008-04-29 13:45:15 +00:00
|
|
|
|
2012-09-14 23:58:58 +00:00
|
|
|
dev = &edge_serial->serial->dev->dev;
|
2012-09-18 08:58:57 +00:00
|
|
|
usb_serial_debug_data(dev, __func__, length, data);
|
2008-04-29 13:45:15 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
if (length != 2) {
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s - expecting packet of size 2, got %d\n", __func__, length);
|
2005-04-16 22:20:36 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
port_number = TIUMP_GET_PORT_FROM_CODE(data[0]);
|
|
|
|
function = TIUMP_GET_FUNC_FROM_CODE(data[0]);
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s - port_number %d, function %d, info 0x%x\n", __func__,
|
|
|
|
port_number, function, data[1]);
|
2017-03-06 16:36:37 +00:00
|
|
|
|
|
|
|
if (port_number >= edge_serial->serial->num_ports) {
|
|
|
|
dev_err(dev, "bad port number %d\n", port_number);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
port = edge_serial->serial->port[port_number];
|
|
|
|
edge_port = usb_get_serial_port_data(port);
|
|
|
|
if (!edge_port) {
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s - edge_port not found\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch (function) {
|
|
|
|
case TIUMP_INTERRUPT_CODE_LSR:
|
2008-04-29 13:45:15 +00:00
|
|
|
lsr = map_line_status(data[1]);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (lsr & UMP_UART_LSR_DATA_MASK) {
|
2015-09-16 08:13:02 +00:00
|
|
|
/*
|
|
|
|
* Save the LSR event for bulk read completion routine
|
|
|
|
*/
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s - LSR Event Port %u LSR Status = %02x\n",
|
|
|
|
__func__, port_number, lsr);
|
2005-04-16 22:20:36 +00:00
|
|
|
edge_port->lsr_event = 1;
|
|
|
|
edge_port->lsr_mask = lsr;
|
|
|
|
} else {
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s - ===== Port %d LSR Status = %02x ======\n",
|
|
|
|
__func__, port_number, lsr);
|
2008-04-29 13:45:15 +00:00
|
|
|
handle_new_lsr(edge_port, 0, lsr, 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
case TIUMP_INTERRUPT_CODE_MSR: /* MSR */
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Copy MSR from UMP */
|
|
|
|
msr = data[1];
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s - ===== Port %u MSR Status = %02x ======\n",
|
|
|
|
__func__, port_number, msr);
|
2008-04-29 13:45:15 +00:00
|
|
|
handle_new_msr(edge_port, msr);
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2008-04-29 13:45:15 +00:00
|
|
|
dev_err(&urb->dev->dev,
|
|
|
|
"%s - Unknown Interrupt code from UMP %x\n",
|
|
|
|
__func__, data[1]);
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
2008-04-29 13:45:15 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
exit:
|
2008-04-29 13:45:15 +00:00
|
|
|
retval = usb_submit_urb(urb, GFP_ATOMIC);
|
2007-06-15 22:44:13 +00:00
|
|
|
if (retval)
|
2008-04-29 13:45:15 +00:00
|
|
|
dev_err(&urb->dev->dev,
|
|
|
|
"%s - usb_submit_urb failed with result %d\n",
|
2008-03-04 00:08:34 +00:00
|
|
|
__func__, retval);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
static void edge_bulk_in_callback(struct urb *urb)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-02-24 10:41:47 +00:00
|
|
|
struct edgeport_port *edge_port = urb->context;
|
2012-09-14 23:58:58 +00:00
|
|
|
struct device *dev = &edge_port->port->dev;
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned char *data = urb->transfer_buffer;
|
2018-06-23 22:32:07 +00:00
|
|
|
unsigned long flags;
|
2007-06-15 22:44:13 +00:00
|
|
|
int retval = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
int port_number;
|
2007-06-15 22:44:13 +00:00
|
|
|
int status = urb->status;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-06-15 22:44:13 +00:00
|
|
|
switch (status) {
|
2005-04-16 22:20:36 +00:00
|
|
|
case 0:
|
|
|
|
/* success */
|
|
|
|
break;
|
|
|
|
case -ECONNRESET:
|
|
|
|
case -ENOENT:
|
|
|
|
case -ESHUTDOWN:
|
|
|
|
/* this urb is terminated, clean up */
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(&urb->dev->dev, "%s - urb shutting down with status: %d\n", __func__, status);
|
2005-04-16 22:20:36 +00:00
|
|
|
return;
|
|
|
|
default:
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_err(&urb->dev->dev, "%s - nonzero read bulk status received: %d\n", __func__, status);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2007-06-15 22:44:13 +00:00
|
|
|
if (status == -EPIPE)
|
2005-04-16 22:20:36 +00:00
|
|
|
goto exit;
|
|
|
|
|
2007-06-15 22:44:13 +00:00
|
|
|
if (status) {
|
2008-04-29 13:45:15 +00:00
|
|
|
dev_err(&urb->dev->dev, "%s - stopping read!\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-06 17:32:00 +00:00
|
|
|
port_number = edge_port->port->port_number;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2017-03-06 16:36:40 +00:00
|
|
|
if (urb->actual_length > 0 && edge_port->lsr_event) {
|
2005-04-16 22:20:36 +00:00
|
|
|
edge_port->lsr_event = 0;
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s ===== Port %u LSR Status = %02x, Data = %02x ======\n",
|
|
|
|
__func__, port_number, edge_port->lsr_mask, *data);
|
2008-04-29 13:45:15 +00:00
|
|
|
handle_new_lsr(edge_port, 1, edge_port->lsr_mask, *data);
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Adjust buffer length/pointer */
|
|
|
|
--urb->actual_length;
|
|
|
|
++data;
|
|
|
|
}
|
|
|
|
|
2013-01-03 14:53:06 +00:00
|
|
|
if (urb->actual_length) {
|
2012-09-18 08:58:57 +00:00
|
|
|
usb_serial_debug_data(dev, __func__, urb->actual_length, data);
|
2008-04-29 13:45:15 +00:00
|
|
|
if (edge_port->close_pending)
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s - close pending, dropping data on the floor\n",
|
2008-04-29 13:45:15 +00:00
|
|
|
__func__);
|
|
|
|
else
|
2013-01-03 14:53:06 +00:00
|
|
|
edge_tty_recv(edge_port->port, data,
|
2013-01-03 14:53:04 +00:00
|
|
|
urb->actual_length);
|
2013-03-21 11:37:09 +00:00
|
|
|
edge_port->port->icount.rx += urb->actual_length;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
exit:
|
|
|
|
/* continue read unless stopped */
|
2018-06-23 22:32:07 +00:00
|
|
|
spin_lock_irqsave(&edge_port->ep_lock, flags);
|
2011-11-06 18:06:28 +00:00
|
|
|
if (edge_port->ep_read_urb_state == EDGE_READ_URB_RUNNING)
|
2007-06-15 22:44:13 +00:00
|
|
|
retval = usb_submit_urb(urb, GFP_ATOMIC);
|
2011-11-06 18:06:28 +00:00
|
|
|
else if (edge_port->ep_read_urb_state == EDGE_READ_URB_STOPPING)
|
2005-04-16 22:20:36 +00:00
|
|
|
edge_port->ep_read_urb_state = EDGE_READ_URB_STOPPED;
|
2011-11-06 18:06:28 +00:00
|
|
|
|
2018-06-23 22:32:07 +00:00
|
|
|
spin_unlock_irqrestore(&edge_port->ep_lock, flags);
|
2007-06-15 22:44:13 +00:00
|
|
|
if (retval)
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_err(dev, "%s - usb_submit_urb failed with result %d\n", __func__, retval);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2013-01-03 14:53:06 +00:00
|
|
|
static void edge_tty_recv(struct usb_serial_port *port, unsigned char *data,
|
|
|
|
int length)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-04-29 13:45:15 +00:00
|
|
|
int queued;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2013-01-03 14:53:04 +00:00
|
|
|
queued = tty_insert_flip_string(&port->port, data, length);
|
2008-04-29 13:45:15 +00:00
|
|
|
if (queued < length)
|
2013-01-03 14:53:04 +00:00
|
|
|
dev_err(&port->dev, "%s - dropping data, %d bytes lost\n",
|
2008-04-29 13:45:15 +00:00
|
|
|
__func__, length - queued);
|
2013-01-03 14:53:06 +00:00
|
|
|
tty_flip_buffer_push(&port->port);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
static void edge_bulk_out_callback(struct urb *urb)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-02-24 10:41:47 +00:00
|
|
|
struct usb_serial_port *port = urb->context;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct edgeport_port *edge_port = usb_get_serial_port_data(port);
|
2007-06-15 22:44:13 +00:00
|
|
|
int status = urb->status;
|
2008-10-13 09:39:46 +00:00
|
|
|
struct tty_struct *tty;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
edge_port->ep_write_urb_in_use = 0;
|
|
|
|
|
2007-06-15 22:44:13 +00:00
|
|
|
switch (status) {
|
2005-04-16 22:20:36 +00:00
|
|
|
case 0:
|
|
|
|
/* success */
|
|
|
|
break;
|
|
|
|
case -ECONNRESET:
|
|
|
|
case -ENOENT:
|
|
|
|
case -ESHUTDOWN:
|
|
|
|
/* this urb is terminated, clean up */
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(&urb->dev->dev, "%s - urb shutting down with status: %d\n",
|
2008-03-04 00:08:34 +00:00
|
|
|
__func__, status);
|
2005-04-16 22:20:36 +00:00
|
|
|
return;
|
|
|
|
default:
|
2012-02-10 12:20:51 +00:00
|
|
|
dev_err_console(port, "%s - nonzero write bulk status "
|
2008-03-04 00:08:34 +00:00
|
|
|
"received: %d\n", __func__, status);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* send any buffered data */
|
2008-10-13 09:39:46 +00:00
|
|
|
tty = tty_port_tty_get(&port->port);
|
2013-04-04 20:41:01 +00:00
|
|
|
edge_send(port, tty);
|
2008-10-13 09:39:46 +00:00
|
|
|
tty_kref_put(tty);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2009-09-19 20:13:26 +00:00
|
|
|
static int edge_open(struct tty_struct *tty, struct usb_serial_port *port)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct edgeport_port *edge_port = usb_get_serial_port_data(port);
|
|
|
|
struct edgeport_serial *edge_serial;
|
|
|
|
struct usb_device *dev;
|
|
|
|
struct urb *urb;
|
|
|
|
int status;
|
|
|
|
u16 open_settings;
|
|
|
|
u8 transaction_timeout;
|
|
|
|
|
|
|
|
if (edge_port == NULL)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
dev = port->serial->dev;
|
|
|
|
|
|
|
|
/* turn off loopback */
|
2008-04-29 13:45:15 +00:00
|
|
|
status = ti_do_config(edge_port, UMPC_SET_CLR_LOOPBACK, 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (status) {
|
2008-04-29 13:45:15 +00:00
|
|
|
dev_err(&port->dev,
|
|
|
|
"%s - cannot send clear loopback command, %d\n",
|
2008-03-04 00:08:34 +00:00
|
|
|
__func__, status);
|
2005-04-16 22:20:36 +00:00
|
|
|
return status;
|
|
|
|
}
|
2008-04-29 13:45:15 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* set up the port settings */
|
2008-07-22 10:09:07 +00:00
|
|
|
if (tty)
|
2012-07-14 14:31:47 +00:00
|
|
|
edge_set_termios(tty, port, &tty->termios);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* open up the port */
|
|
|
|
|
|
|
|
/* milliseconds to timeout for DMA transfer */
|
|
|
|
transaction_timeout = 2;
|
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
edge_port->ump_read_timeout =
|
|
|
|
max(20, ((transaction_timeout * 3) / 2));
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
/* milliseconds to timeout for DMA transfer */
|
|
|
|
open_settings = (u8)(UMP_DMA_MODE_CONTINOUS |
|
|
|
|
UMP_PIPE_TRANS_TIMEOUT_ENA |
|
2005-04-16 22:20:36 +00:00
|
|
|
(transaction_timeout << 2));
|
|
|
|
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(&port->dev, "%s - Sending UMPC_OPEN_PORT\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* Tell TI to open and start the port */
|
2021-04-12 09:47:30 +00:00
|
|
|
status = send_port_cmd(port, UMPC_OPEN_PORT, open_settings, NULL, 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (status) {
|
2008-04-29 13:45:15 +00:00
|
|
|
dev_err(&port->dev, "%s - cannot send open command, %d\n",
|
|
|
|
__func__, status);
|
2005-04-16 22:20:36 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Start the DMA? */
|
2021-04-12 09:47:30 +00:00
|
|
|
status = send_port_cmd(port, UMPC_START_PORT, 0, NULL, 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (status) {
|
2008-04-29 13:45:15 +00:00
|
|
|
dev_err(&port->dev, "%s - cannot send start DMA command, %d\n",
|
|
|
|
__func__, status);
|
2005-04-16 22:20:36 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear TX and RX buffers in UMP */
|
2008-04-29 13:45:15 +00:00
|
|
|
status = purge_port(port, UMP_PORT_DIR_OUT | UMP_PORT_DIR_IN);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (status) {
|
2008-04-29 13:45:15 +00:00
|
|
|
dev_err(&port->dev,
|
|
|
|
"%s - cannot send clear buffers command, %d\n",
|
|
|
|
__func__, status);
|
2005-04-16 22:20:36 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read Initial MSR */
|
2021-04-12 09:47:31 +00:00
|
|
|
status = read_port_cmd(port, UMPC_READ_MSR, 0, &edge_port->shadow_msr, 1);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (status) {
|
2008-04-29 13:45:15 +00:00
|
|
|
dev_err(&port->dev, "%s - cannot send read MSR command, %d\n",
|
|
|
|
__func__, status);
|
2005-04-16 22:20:36 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(&port->dev, "ShadowMSR 0x%X\n", edge_port->shadow_msr);
|
2008-04-29 13:45:15 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Set Initial MCR */
|
|
|
|
edge_port->shadow_mcr = MCR_RTS | MCR_DTR;
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(&port->dev, "ShadowMCR 0x%X\n", edge_port->shadow_mcr);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
edge_serial = edge_port->edge_serial;
|
2007-12-04 15:15:40 +00:00
|
|
|
if (mutex_lock_interruptible(&edge_serial->es_lock))
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ERESTARTSYS;
|
|
|
|
if (edge_serial->num_ports_open == 0) {
|
2008-04-29 13:45:15 +00:00
|
|
|
/* we are the first port to open, post the interrupt urb */
|
2005-04-16 22:20:36 +00:00
|
|
|
urb = edge_serial->serial->port[0]->interrupt_in_urb;
|
|
|
|
urb->context = edge_serial;
|
2008-04-29 13:45:15 +00:00
|
|
|
status = usb_submit_urb(urb, GFP_KERNEL);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (status) {
|
2008-04-29 13:45:15 +00:00
|
|
|
dev_err(&port->dev,
|
|
|
|
"%s - usb_submit_urb failed with value %d\n",
|
|
|
|
__func__, status);
|
2007-12-04 15:15:40 +00:00
|
|
|
goto release_es_lock;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* reset the data toggle on the bulk endpoints to work around bug in
|
|
|
|
* host controllers where things get out of sync some times
|
|
|
|
*/
|
2008-04-29 13:45:15 +00:00
|
|
|
usb_clear_halt(dev, port->write_urb->pipe);
|
|
|
|
usb_clear_halt(dev, port->read_urb->pipe);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* start up our bulk read urb */
|
|
|
|
urb = port->read_urb;
|
|
|
|
edge_port->ep_read_urb_state = EDGE_READ_URB_RUNNING;
|
|
|
|
urb->context = edge_port;
|
2008-04-29 13:45:15 +00:00
|
|
|
status = usb_submit_urb(urb, GFP_KERNEL);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (status) {
|
2008-04-29 13:45:15 +00:00
|
|
|
dev_err(&port->dev,
|
|
|
|
"%s - read bulk usb_submit_urb failed with value %d\n",
|
|
|
|
__func__, status);
|
2005-04-16 22:20:36 +00:00
|
|
|
goto unlink_int_urb;
|
|
|
|
}
|
|
|
|
|
|
|
|
++edge_serial->num_ports_open;
|
|
|
|
|
2007-12-04 15:15:40 +00:00
|
|
|
goto release_es_lock;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
unlink_int_urb:
|
|
|
|
if (edge_port->edge_serial->num_ports_open == 0)
|
|
|
|
usb_kill_urb(port->serial->port[0]->interrupt_in_urb);
|
2007-12-04 15:15:40 +00:00
|
|
|
release_es_lock:
|
|
|
|
mutex_unlock(&edge_serial->es_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2009-06-11 11:26:29 +00:00
|
|
|
static void edge_close(struct usb_serial_port *port)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct edgeport_serial *edge_serial;
|
|
|
|
struct edgeport_port *edge_port;
|
2013-01-14 15:52:54 +00:00
|
|
|
unsigned long flags;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
edge_serial = usb_get_serial_data(port->serial);
|
|
|
|
edge_port = usb_get_serial_port_data(port);
|
2008-04-29 13:45:15 +00:00
|
|
|
if (edge_serial == NULL || edge_port == NULL)
|
2005-04-16 22:20:36 +00:00
|
|
|
return;
|
2008-04-29 13:45:15 +00:00
|
|
|
|
2015-09-16 08:13:02 +00:00
|
|
|
/*
|
|
|
|
* The bulkreadcompletion routine will check
|
|
|
|
* this flag and dump add read data
|
|
|
|
*/
|
2005-04-16 22:20:36 +00:00
|
|
|
edge_port->close_pending = 1;
|
|
|
|
|
|
|
|
usb_kill_urb(port->read_urb);
|
|
|
|
usb_kill_urb(port->write_urb);
|
|
|
|
edge_port->ep_write_urb_in_use = 0;
|
2013-01-14 15:52:54 +00:00
|
|
|
spin_lock_irqsave(&edge_port->ep_lock, flags);
|
2013-06-26 14:47:37 +00:00
|
|
|
kfifo_reset_out(&port->write_fifo);
|
2013-01-14 15:52:54 +00:00
|
|
|
spin_unlock_irqrestore(&edge_port->ep_lock, flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(&port->dev, "%s - send umpc_close_port\n", __func__);
|
2021-04-12 09:47:30 +00:00
|
|
|
send_port_cmd(port, UMPC_CLOSE_PORT, 0, NULL, 0);
|
2012-03-26 18:31:38 +00:00
|
|
|
|
2007-12-04 15:15:40 +00:00
|
|
|
mutex_lock(&edge_serial->es_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
--edge_port->edge_serial->num_ports_open;
|
|
|
|
if (edge_port->edge_serial->num_ports_open <= 0) {
|
|
|
|
/* last port is now closed, let's shut down our interrupt urb */
|
|
|
|
usb_kill_urb(port->serial->port[0]->interrupt_in_urb);
|
|
|
|
edge_port->edge_serial->num_ports_open = 0;
|
|
|
|
}
|
2007-12-04 15:15:40 +00:00
|
|
|
mutex_unlock(&edge_serial->es_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
edge_port->close_pending = 0;
|
|
|
|
}
|
|
|
|
|
2008-07-22 10:09:07 +00:00
|
|
|
static int edge_write(struct tty_struct *tty, struct usb_serial_port *port,
|
|
|
|
const unsigned char *data, int count)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct edgeport_port *edge_port = usb_get_serial_port_data(port);
|
|
|
|
|
|
|
|
if (count == 0) {
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(&port->dev, "%s - write request of 0 bytes\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (edge_port == NULL)
|
|
|
|
return -ENODEV;
|
|
|
|
if (edge_port->close_pending == 1)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2013-06-26 14:47:37 +00:00
|
|
|
count = kfifo_in_locked(&port->write_fifo, data, count,
|
2010-05-18 22:01:37 +00:00
|
|
|
&edge_port->ep_lock);
|
2013-04-04 20:41:01 +00:00
|
|
|
edge_send(port, tty);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2013-04-04 20:41:01 +00:00
|
|
|
static void edge_send(struct usb_serial_port *port, struct tty_struct *tty)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int count, result;
|
|
|
|
struct edgeport_port *edge_port = usb_get_serial_port_data(port);
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&edge_port->ep_lock, flags);
|
|
|
|
|
|
|
|
if (edge_port->ep_write_urb_in_use) {
|
|
|
|
spin_unlock_irqrestore(&edge_port->ep_lock, flags);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-26 14:47:37 +00:00
|
|
|
count = kfifo_out(&port->write_fifo,
|
2005-04-16 22:20:36 +00:00
|
|
|
port->write_urb->transfer_buffer,
|
|
|
|
port->bulk_out_size);
|
|
|
|
|
|
|
|
if (count == 0) {
|
|
|
|
spin_unlock_irqrestore(&edge_port->ep_lock, flags);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
edge_port->ep_write_urb_in_use = 1;
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&edge_port->ep_lock, flags);
|
|
|
|
|
2012-09-18 08:58:57 +00:00
|
|
|
usb_serial_debug_data(&port->dev, __func__, count, port->write_urb->transfer_buffer);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* set up our urb */
|
2011-11-06 18:06:30 +00:00
|
|
|
port->write_urb->transfer_buffer_length = count;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* send the data out the bulk port */
|
|
|
|
result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
|
|
|
|
if (result) {
|
2012-02-10 12:20:51 +00:00
|
|
|
dev_err_console(port,
|
2008-04-29 13:45:15 +00:00
|
|
|
"%s - failed submitting write urb, error %d\n",
|
|
|
|
__func__, result);
|
2005-04-16 22:20:36 +00:00
|
|
|
edge_port->ep_write_urb_in_use = 0;
|
2008-04-29 13:45:15 +00:00
|
|
|
/* TODO: reschedule edge_send */
|
|
|
|
} else
|
2013-03-21 11:37:09 +00:00
|
|
|
edge_port->port->icount.tx += count;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2015-09-16 08:13:02 +00:00
|
|
|
/*
|
|
|
|
* wakeup any process waiting for writes to complete
|
|
|
|
* there is now more room in the buffer for new writes
|
|
|
|
*/
|
2008-04-29 13:45:15 +00:00
|
|
|
if (tty)
|
2005-04-16 22:20:36 +00:00
|
|
|
tty_wakeup(tty);
|
|
|
|
}
|
|
|
|
|
2021-05-05 09:19:16 +00:00
|
|
|
static unsigned int edge_write_room(struct tty_struct *tty)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-07-22 10:09:07 +00:00
|
|
|
struct usb_serial_port *port = tty->driver_data;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct edgeport_port *edge_port = usb_get_serial_port_data(port);
|
2021-05-05 09:19:16 +00:00
|
|
|
unsigned int room;
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
if (edge_port == NULL)
|
2008-04-29 13:45:15 +00:00
|
|
|
return 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
if (edge_port->close_pending == 1)
|
2008-04-29 13:45:15 +00:00
|
|
|
return 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
spin_lock_irqsave(&edge_port->ep_lock, flags);
|
2013-06-26 14:47:37 +00:00
|
|
|
room = kfifo_avail(&port->write_fifo);
|
2005-04-16 22:20:36 +00:00
|
|
|
spin_unlock_irqrestore(&edge_port->ep_lock, flags);
|
|
|
|
|
2021-05-05 09:19:16 +00:00
|
|
|
dev_dbg(&port->dev, "%s - returns %u\n", __func__, room);
|
2005-04-16 22:20:36 +00:00
|
|
|
return room;
|
|
|
|
}
|
|
|
|
|
2021-05-05 09:19:20 +00:00
|
|
|
static unsigned int edge_chars_in_buffer(struct tty_struct *tty)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-07-22 10:09:07 +00:00
|
|
|
struct usb_serial_port *port = tty->driver_data;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct edgeport_port *edge_port = usb_get_serial_port_data(port);
|
2021-05-05 09:19:20 +00:00
|
|
|
unsigned int chars;
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned long flags;
|
|
|
|
if (edge_port == NULL)
|
2008-04-29 13:45:15 +00:00
|
|
|
return 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
spin_lock_irqsave(&edge_port->ep_lock, flags);
|
2013-06-26 14:47:37 +00:00
|
|
|
chars = kfifo_len(&port->write_fifo);
|
2005-04-16 22:20:36 +00:00
|
|
|
spin_unlock_irqrestore(&edge_port->ep_lock, flags);
|
|
|
|
|
2021-05-05 09:19:20 +00:00
|
|
|
dev_dbg(&port->dev, "%s - returns %u\n", __func__, chars);
|
2005-04-16 22:20:36 +00:00
|
|
|
return chars;
|
|
|
|
}
|
|
|
|
|
2013-05-05 18:32:31 +00:00
|
|
|
static bool edge_tx_empty(struct usb_serial_port *port)
|
|
|
|
{
|
|
|
|
struct edgeport_port *edge_port = usb_get_serial_port_data(port);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = tx_active(edge_port);
|
|
|
|
if (ret > 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-07-22 10:09:07 +00:00
|
|
|
static void edge_throttle(struct tty_struct *tty)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-07-22 10:09:07 +00:00
|
|
|
struct usb_serial_port *port = tty->driver_data;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct edgeport_port *edge_port = usb_get_serial_port_data(port);
|
|
|
|
int status;
|
|
|
|
|
|
|
|
if (edge_port == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* if we are implementing XON/XOFF, send the stop character */
|
|
|
|
if (I_IXOFF(tty)) {
|
|
|
|
unsigned char stop_char = STOP_CHAR(tty);
|
2008-07-22 10:09:07 +00:00
|
|
|
status = edge_write(tty, port, &stop_char, 1);
|
|
|
|
if (status <= 0) {
|
|
|
|
dev_err(&port->dev, "%s - failed to write stop character, %d\n", __func__, status);
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2015-09-16 08:13:02 +00:00
|
|
|
/*
|
|
|
|
* if we are implementing RTS/CTS, stop reads
|
|
|
|
* and the Edgeport will clear the RTS line
|
|
|
|
*/
|
2005-04-16 22:20:36 +00:00
|
|
|
if (C_CRTSCTS(tty))
|
|
|
|
stop_read(edge_port);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-07-22 10:09:07 +00:00
|
|
|
static void edge_unthrottle(struct tty_struct *tty)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-07-22 10:09:07 +00:00
|
|
|
struct usb_serial_port *port = tty->driver_data;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct edgeport_port *edge_port = usb_get_serial_port_data(port);
|
|
|
|
int status;
|
|
|
|
|
|
|
|
if (edge_port == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* if we are implementing XON/XOFF, send the start character */
|
|
|
|
if (I_IXOFF(tty)) {
|
|
|
|
unsigned char start_char = START_CHAR(tty);
|
2008-07-22 10:09:07 +00:00
|
|
|
status = edge_write(tty, port, &start_char, 1);
|
|
|
|
if (status <= 0) {
|
|
|
|
dev_err(&port->dev, "%s - failed to write start character, %d\n", __func__, status);
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2015-09-16 08:13:02 +00:00
|
|
|
/*
|
|
|
|
* if we are implementing RTS/CTS, restart reads
|
|
|
|
* are the Edgeport will assert the RTS line
|
|
|
|
*/
|
2005-04-16 22:20:36 +00:00
|
|
|
if (C_CRTSCTS(tty)) {
|
|
|
|
status = restart_read(edge_port);
|
|
|
|
if (status)
|
2008-04-29 13:45:15 +00:00
|
|
|
dev_err(&port->dev,
|
|
|
|
"%s - read bulk usb_submit_urb failed: %d\n",
|
|
|
|
__func__, status);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void stop_read(struct edgeport_port *edge_port)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&edge_port->ep_lock, flags);
|
|
|
|
|
|
|
|
if (edge_port->ep_read_urb_state == EDGE_READ_URB_RUNNING)
|
|
|
|
edge_port->ep_read_urb_state = EDGE_READ_URB_STOPPING;
|
|
|
|
edge_port->shadow_mcr &= ~MCR_RTS;
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&edge_port->ep_lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int restart_read(struct edgeport_port *edge_port)
|
|
|
|
{
|
|
|
|
struct urb *urb;
|
|
|
|
int status = 0;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&edge_port->ep_lock, flags);
|
|
|
|
|
|
|
|
if (edge_port->ep_read_urb_state == EDGE_READ_URB_STOPPED) {
|
|
|
|
urb = edge_port->port->read_urb;
|
2007-06-05 08:50:48 +00:00
|
|
|
status = usb_submit_urb(urb, GFP_ATOMIC);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
edge_port->ep_read_urb_state = EDGE_READ_URB_RUNNING;
|
|
|
|
edge_port->shadow_mcr |= MCR_RTS;
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&edge_port->ep_lock, flags);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2008-07-22 10:09:07 +00:00
|
|
|
static void change_port_settings(struct tty_struct *tty,
|
|
|
|
struct edgeport_port *edge_port, struct ktermios *old_termios)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2012-09-14 23:58:58 +00:00
|
|
|
struct device *dev = &edge_port->port->dev;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct ump_uart_config *config;
|
|
|
|
int baud;
|
|
|
|
unsigned cflag;
|
|
|
|
int status;
|
|
|
|
|
2008-07-22 10:09:07 +00:00
|
|
|
config = kmalloc (sizeof (*config), GFP_KERNEL);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!config) {
|
2012-07-14 14:31:47 +00:00
|
|
|
tty->termios = *old_termios;
|
2005-04-16 22:20:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-14 14:31:47 +00:00
|
|
|
cflag = tty->termios.c_cflag;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
config->wFlags = 0;
|
|
|
|
|
|
|
|
/* These flags must be set */
|
|
|
|
config->wFlags |= UMP_MASK_UART_FLAGS_RECEIVE_MS_INT;
|
|
|
|
config->wFlags |= UMP_MASK_UART_FLAGS_AUTO_START_ON_ERR;
|
2021-04-12 09:47:32 +00:00
|
|
|
config->bUartMode = (u8)(edge_port->bUartMode);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
switch (cflag & CSIZE) {
|
2008-04-29 13:45:15 +00:00
|
|
|
case CS5:
|
|
|
|
config->bDataBits = UMP_UART_CHAR5BITS;
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s - data bits = 5\n", __func__);
|
2008-04-29 13:45:15 +00:00
|
|
|
break;
|
|
|
|
case CS6:
|
|
|
|
config->bDataBits = UMP_UART_CHAR6BITS;
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s - data bits = 6\n", __func__);
|
2008-04-29 13:45:15 +00:00
|
|
|
break;
|
|
|
|
case CS7:
|
|
|
|
config->bDataBits = UMP_UART_CHAR7BITS;
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s - data bits = 7\n", __func__);
|
2008-04-29 13:45:15 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case CS8:
|
|
|
|
config->bDataBits = UMP_UART_CHAR8BITS;
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s - data bits = 8\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cflag & PARENB) {
|
|
|
|
if (cflag & PARODD) {
|
|
|
|
config->wFlags |= UMP_MASK_UART_FLAGS_PARITY;
|
|
|
|
config->bParity = UMP_UART_ODDPARITY;
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s - parity = odd\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
} else {
|
|
|
|
config->wFlags |= UMP_MASK_UART_FLAGS_PARITY;
|
|
|
|
config->bParity = UMP_UART_EVENPARITY;
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s - parity = even\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
} else {
|
2008-04-29 13:45:15 +00:00
|
|
|
config->bParity = UMP_UART_NOPARITY;
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s - parity = none\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cflag & CSTOPB) {
|
|
|
|
config->bStopBits = UMP_UART_STOPBIT2;
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s - stop bits = 2\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
} else {
|
|
|
|
config->bStopBits = UMP_UART_STOPBIT1;
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s - stop bits = 1\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* figure out the flow control settings */
|
|
|
|
if (cflag & CRTSCTS) {
|
|
|
|
config->wFlags |= UMP_MASK_UART_FLAGS_OUT_X_CTS_FLOW;
|
|
|
|
config->wFlags |= UMP_MASK_UART_FLAGS_RTS_FLOW;
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s - RTS/CTS is enabled\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
} else {
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s - RTS/CTS is disabled\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
restart_read(edge_port);
|
|
|
|
}
|
|
|
|
|
2015-09-16 08:13:02 +00:00
|
|
|
/*
|
|
|
|
* if we are implementing XON/XOFF, set the start and stop
|
|
|
|
* character in the device
|
|
|
|
*/
|
2008-04-29 13:45:15 +00:00
|
|
|
config->cXon = START_CHAR(tty);
|
|
|
|
config->cXoff = STOP_CHAR(tty);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
/* if we are implementing INBOUND XON/XOFF */
|
|
|
|
if (I_IXOFF(tty)) {
|
|
|
|
config->wFlags |= UMP_MASK_UART_FLAGS_IN_X;
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s - INBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x\n",
|
|
|
|
__func__, config->cXon, config->cXoff);
|
2008-04-29 13:45:15 +00:00
|
|
|
} else
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s - INBOUND XON/XOFF is disabled\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
/* if we are implementing OUTBOUND XON/XOFF */
|
|
|
|
if (I_IXON(tty)) {
|
|
|
|
config->wFlags |= UMP_MASK_UART_FLAGS_OUT_X;
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s - OUTBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x\n",
|
|
|
|
__func__, config->cXon, config->cXoff);
|
2008-04-29 13:45:15 +00:00
|
|
|
} else
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s - OUTBOUND XON/XOFF is disabled\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-07-14 14:31:47 +00:00
|
|
|
tty->termios.c_cflag &= ~CMSPAR;
|
2008-01-03 16:57:33 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Round the baud rate */
|
|
|
|
baud = tty_get_baud_rate(tty);
|
|
|
|
if (!baud) {
|
|
|
|
/* pick a default, any default... */
|
|
|
|
baud = 9600;
|
2017-05-11 09:41:21 +00:00
|
|
|
} else {
|
|
|
|
/* Avoid a zero divisor. */
|
|
|
|
baud = min(baud, 461550);
|
2008-01-03 16:57:33 +00:00
|
|
|
tty_encode_baud_rate(tty, baud, baud);
|
2017-05-11 09:41:21 +00:00
|
|
|
}
|
2008-01-03 16:57:33 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
edge_port->baud_rate = baud;
|
2021-04-12 09:47:32 +00:00
|
|
|
config->wBaudRate = (u16)((461550L + baud/2) / baud);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-01-03 16:57:33 +00:00
|
|
|
/* FIXME: Recompute actual baud from divisor here */
|
|
|
|
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s - baud rate = %d, wBaudRate = %d\n", __func__, baud, config->wBaudRate);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "wBaudRate: %d\n", (int)(461550L / config->wBaudRate));
|
|
|
|
dev_dbg(dev, "wFlags: 0x%x\n", config->wFlags);
|
|
|
|
dev_dbg(dev, "bDataBits: %d\n", config->bDataBits);
|
|
|
|
dev_dbg(dev, "bParity: %d\n", config->bParity);
|
|
|
|
dev_dbg(dev, "bStopBits: %d\n", config->bStopBits);
|
|
|
|
dev_dbg(dev, "cXon: %d\n", config->cXon);
|
|
|
|
dev_dbg(dev, "cXoff: %d\n", config->cXoff);
|
|
|
|
dev_dbg(dev, "bUartMode: %d\n", config->bUartMode);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* move the word values into big endian mode */
|
2008-04-29 13:45:15 +00:00
|
|
|
cpu_to_be16s(&config->wFlags);
|
|
|
|
cpu_to_be16s(&config->wBaudRate);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-04-12 09:47:30 +00:00
|
|
|
status = send_port_cmd(edge_port->port, UMPC_SET_CONFIG, 0, config,
|
|
|
|
sizeof(*config));
|
2008-04-29 13:45:15 +00:00
|
|
|
if (status)
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s - error %d when trying to write config to device\n",
|
|
|
|
__func__, status);
|
2008-04-29 13:45:15 +00:00
|
|
|
kfree(config);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-07-22 10:12:33 +00:00
|
|
|
static void edge_set_termios(struct tty_struct *tty,
|
2008-07-22 10:09:07 +00:00
|
|
|
struct usb_serial_port *port, struct ktermios *old_termios)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct edgeport_port *edge_port = usb_get_serial_port_data(port);
|
|
|
|
|
|
|
|
if (edge_port == NULL)
|
|
|
|
return;
|
|
|
|
/* change the port settings to the new ones specified */
|
2008-07-22 10:09:07 +00:00
|
|
|
change_port_settings(tty, edge_port, old_termios);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2011-02-14 16:26:50 +00:00
|
|
|
static int edge_tiocmset(struct tty_struct *tty,
|
2008-04-29 13:45:15 +00:00
|
|
|
unsigned int set, unsigned int clear)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-07-22 10:09:07 +00:00
|
|
|
struct usb_serial_port *port = tty->driver_data;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct edgeport_port *edge_port = usb_get_serial_port_data(port);
|
|
|
|
unsigned int mcr;
|
2008-02-20 21:38:32 +00:00
|
|
|
unsigned long flags;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-20 21:38:32 +00:00
|
|
|
spin_lock_irqsave(&edge_port->ep_lock, flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
mcr = edge_port->shadow_mcr;
|
|
|
|
if (set & TIOCM_RTS)
|
|
|
|
mcr |= MCR_RTS;
|
|
|
|
if (set & TIOCM_DTR)
|
|
|
|
mcr |= MCR_DTR;
|
|
|
|
if (set & TIOCM_LOOP)
|
|
|
|
mcr |= MCR_LOOPBACK;
|
|
|
|
|
|
|
|
if (clear & TIOCM_RTS)
|
|
|
|
mcr &= ~MCR_RTS;
|
|
|
|
if (clear & TIOCM_DTR)
|
|
|
|
mcr &= ~MCR_DTR;
|
|
|
|
if (clear & TIOCM_LOOP)
|
|
|
|
mcr &= ~MCR_LOOPBACK;
|
|
|
|
|
|
|
|
edge_port->shadow_mcr = mcr;
|
2008-02-20 21:38:32 +00:00
|
|
|
spin_unlock_irqrestore(&edge_port->ep_lock, flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-04-29 13:45:15 +00:00
|
|
|
restore_mcr(edge_port, mcr);
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-02-14 16:26:14 +00:00
|
|
|
static int edge_tiocmget(struct tty_struct *tty)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-07-22 10:09:07 +00:00
|
|
|
struct usb_serial_port *port = tty->driver_data;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct edgeport_port *edge_port = usb_get_serial_port_data(port);
|
|
|
|
unsigned int result = 0;
|
|
|
|
unsigned int msr;
|
|
|
|
unsigned int mcr;
|
2008-02-20 21:38:32 +00:00
|
|
|
unsigned long flags;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-20 21:38:32 +00:00
|
|
|
spin_lock_irqsave(&edge_port->ep_lock, flags);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
msr = edge_port->shadow_msr;
|
|
|
|
mcr = edge_port->shadow_mcr;
|
|
|
|
result = ((mcr & MCR_DTR) ? TIOCM_DTR: 0) /* 0x002 */
|
|
|
|
| ((mcr & MCR_RTS) ? TIOCM_RTS: 0) /* 0x004 */
|
|
|
|
| ((msr & EDGEPORT_MSR_CTS) ? TIOCM_CTS: 0) /* 0x020 */
|
|
|
|
| ((msr & EDGEPORT_MSR_CD) ? TIOCM_CAR: 0) /* 0x040 */
|
|
|
|
| ((msr & EDGEPORT_MSR_RI) ? TIOCM_RI: 0) /* 0x080 */
|
|
|
|
| ((msr & EDGEPORT_MSR_DSR) ? TIOCM_DSR: 0); /* 0x100 */
|
|
|
|
|
|
|
|
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(&port->dev, "%s -- %x\n", __func__, result);
|
2008-02-20 21:38:32 +00:00
|
|
|
spin_unlock_irqrestore(&edge_port->ep_lock, flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2008-07-22 10:09:07 +00:00
|
|
|
static void edge_break(struct tty_struct *tty, int break_state)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-07-22 10:09:07 +00:00
|
|
|
struct usb_serial_port *port = tty->driver_data;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct edgeport_port *edge_port = usb_get_serial_port_data(port);
|
|
|
|
int status;
|
2008-04-29 13:45:15 +00:00
|
|
|
int bv = 0; /* Off */
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-07-22 10:09:07 +00:00
|
|
|
if (break_state == -1)
|
2008-04-29 13:45:15 +00:00
|
|
|
bv = 1; /* On */
|
|
|
|
status = ti_do_config(edge_port, UMPC_SET_CLR_BREAK, bv);
|
|
|
|
if (status)
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(&port->dev, "%s - error %d sending break set/clear command.\n",
|
|
|
|
__func__, status);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2015-07-31 06:55:08 +00:00
|
|
|
static void edge_heartbeat_schedule(struct edgeport_serial *edge_serial)
|
|
|
|
{
|
|
|
|
if (!edge_serial->use_heartbeat)
|
|
|
|
return;
|
|
|
|
|
|
|
|
schedule_delayed_work(&edge_serial->heartbeat_work,
|
|
|
|
FW_HEARTBEAT_SECS * HZ);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void edge_heartbeat_work(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct edgeport_serial *serial;
|
|
|
|
struct ti_i2c_desc *rom_desc;
|
|
|
|
|
|
|
|
serial = container_of(work, struct edgeport_serial,
|
|
|
|
heartbeat_work.work);
|
|
|
|
|
|
|
|
rom_desc = kmalloc(sizeof(*rom_desc), GFP_KERNEL);
|
|
|
|
|
|
|
|
/* Descriptor address request is enough to reset the firmware timer */
|
|
|
|
if (!rom_desc || !get_descriptor_addr(serial, I2C_DESC_TYPE_ION,
|
|
|
|
rom_desc)) {
|
|
|
|
dev_err(&serial->serial->interface->dev,
|
|
|
|
"%s - Incomplete heartbeat\n", __func__);
|
|
|
|
}
|
|
|
|
kfree(rom_desc);
|
|
|
|
|
|
|
|
edge_heartbeat_schedule(serial);
|
|
|
|
}
|
|
|
|
|
2017-03-16 16:13:41 +00:00
|
|
|
static int edge_calc_num_ports(struct usb_serial *serial,
|
|
|
|
struct usb_serial_endpoints *epds)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2017-03-16 16:13:41 +00:00
|
|
|
struct device *dev = &serial->interface->dev;
|
|
|
|
unsigned char num_ports = serial->type->num_ports;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2017-01-03 15:39:43 +00:00
|
|
|
/* Make sure we have the required endpoints when in download mode. */
|
|
|
|
if (serial->interface->cur_altsetting->desc.bNumEndpoints > 1) {
|
2017-03-16 16:13:41 +00:00
|
|
|
if (epds->num_bulk_in < num_ports ||
|
2017-03-16 16:13:43 +00:00
|
|
|
epds->num_bulk_out < num_ports ||
|
|
|
|
epds->num_interrupt_in < 1) {
|
2017-03-16 16:13:41 +00:00
|
|
|
dev_err(dev, "required endpoints missing\n");
|
2017-01-03 15:39:43 +00:00
|
|
|
return -ENODEV;
|
2017-03-16 16:13:41 +00:00
|
|
|
}
|
2017-01-03 15:39:43 +00:00
|
|
|
}
|
|
|
|
|
2017-03-16 16:13:41 +00:00
|
|
|
return num_ports;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int edge_startup(struct usb_serial *serial)
|
|
|
|
{
|
|
|
|
struct edgeport_serial *edge_serial;
|
|
|
|
int status;
|
|
|
|
u16 product_id;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* create our private serial structure */
|
2006-02-27 20:29:43 +00:00
|
|
|
edge_serial = kzalloc(sizeof(struct edgeport_serial), GFP_KERNEL);
|
2013-12-29 18:22:56 +00:00
|
|
|
if (!edge_serial)
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENOMEM;
|
2013-12-29 18:22:56 +00:00
|
|
|
|
2007-12-04 15:15:40 +00:00
|
|
|
mutex_init(&edge_serial->es_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
edge_serial->serial = serial;
|
2017-01-03 15:39:44 +00:00
|
|
|
INIT_DELAYED_WORK(&edge_serial->heartbeat_work, edge_heartbeat_work);
|
2005-04-16 22:20:36 +00:00
|
|
|
usb_set_serial_data(serial, edge_serial);
|
|
|
|
|
2015-09-16 08:13:01 +00:00
|
|
|
status = download_fw(edge_serial);
|
2017-01-03 15:39:44 +00:00
|
|
|
if (status < 0) {
|
2008-04-29 13:45:15 +00:00
|
|
|
kfree(edge_serial);
|
2005-04-16 22:20:36 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2017-01-03 15:39:44 +00:00
|
|
|
if (status > 0)
|
|
|
|
return 1; /* bind but do not register any ports */
|
|
|
|
|
2015-07-31 06:55:08 +00:00
|
|
|
product_id = le16_to_cpu(
|
|
|
|
edge_serial->serial->dev->descriptor.idProduct);
|
|
|
|
|
|
|
|
/* Currently only the EP/416 models require heartbeat support */
|
|
|
|
if (edge_serial->fw_version > FW_HEARTBEAT_VERSION_CUTOFF) {
|
|
|
|
if (product_id == ION_DEVICE_ID_TI_EDGEPORT_416 ||
|
|
|
|
product_id == ION_DEVICE_ID_TI_EDGEPORT_416B) {
|
|
|
|
edge_serial->use_heartbeat = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
edge_heartbeat_schedule(edge_serial);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-06-02 15:53:55 +00:00
|
|
|
static void edge_disconnect(struct usb_serial *serial)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2017-01-03 15:39:45 +00:00
|
|
|
struct edgeport_serial *edge_serial = usb_get_serial_data(serial);
|
|
|
|
|
|
|
|
cancel_delayed_work_sync(&edge_serial->heartbeat_work);
|
2009-06-02 15:53:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void edge_release(struct usb_serial *serial)
|
|
|
|
{
|
2015-07-31 06:55:08 +00:00
|
|
|
struct edgeport_serial *edge_serial = usb_get_serial_data(serial);
|
|
|
|
|
|
|
|
cancel_delayed_work_sync(&edge_serial->heartbeat_work);
|
|
|
|
kfree(edge_serial);
|
2012-10-17 11:34:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int edge_port_probe(struct usb_serial_port *port)
|
|
|
|
{
|
2009-06-02 15:53:55 +00:00
|
|
|
struct edgeport_port *edge_port;
|
2012-10-17 11:34:58 +00:00
|
|
|
int ret;
|
2009-06-02 15:53:55 +00:00
|
|
|
|
2012-10-17 11:34:58 +00:00
|
|
|
edge_port = kzalloc(sizeof(*edge_port), GFP_KERNEL);
|
|
|
|
if (!edge_port)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
spin_lock_init(&edge_port->ep_lock);
|
|
|
|
edge_port->port = port;
|
|
|
|
edge_port->edge_serial = usb_get_serial_data(port->serial);
|
|
|
|
edge_port->bUartMode = default_uart_mode;
|
|
|
|
|
2013-06-26 14:47:38 +00:00
|
|
|
switch (port->port_number) {
|
|
|
|
case 0:
|
|
|
|
edge_port->uart_base = UMPMEM_BASE_UART1;
|
|
|
|
edge_port->dma_address = UMPD_OEDB1_ADDRESS;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
edge_port->uart_base = UMPMEM_BASE_UART2;
|
|
|
|
edge_port->dma_address = UMPD_OEDB2_ADDRESS;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dev_err(&port->dev, "unknown port number\n");
|
|
|
|
ret = -ENODEV;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev_dbg(&port->dev,
|
|
|
|
"%s - port_number = %d, uart_base = %04x, dma_address = %04x\n",
|
|
|
|
__func__, port->port_number, edge_port->uart_base,
|
|
|
|
edge_port->dma_address);
|
|
|
|
|
2012-10-17 11:34:58 +00:00
|
|
|
usb_set_serial_port_data(port, edge_port);
|
|
|
|
|
2012-10-18 09:43:28 +00:00
|
|
|
ret = edge_create_sysfs_attrs(port);
|
2013-06-26 14:47:38 +00:00
|
|
|
if (ret)
|
|
|
|
goto err;
|
2012-10-18 09:43:28 +00:00
|
|
|
|
2021-04-12 09:38:13 +00:00
|
|
|
/*
|
|
|
|
* The LSR does not tell when the transmitter shift register has
|
|
|
|
* emptied so add a one-character drain delay.
|
|
|
|
*/
|
2013-06-26 14:47:23 +00:00
|
|
|
port->port.drain_delay = 1;
|
2013-01-14 15:52:58 +00:00
|
|
|
|
2012-10-17 11:34:58 +00:00
|
|
|
return 0;
|
2013-06-26 14:47:38 +00:00
|
|
|
err:
|
|
|
|
kfree(edge_port);
|
|
|
|
|
|
|
|
return ret;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2021-02-08 14:31:49 +00:00
|
|
|
static void edge_port_remove(struct usb_serial_port *port)
|
2012-10-17 11:34:58 +00:00
|
|
|
{
|
|
|
|
struct edgeport_port *edge_port;
|
|
|
|
|
|
|
|
edge_port = usb_get_serial_port_data(port);
|
|
|
|
edge_remove_sysfs_attrs(port);
|
|
|
|
kfree(edge_port);
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-05-22 19:57:04 +00:00
|
|
|
/* Sysfs Attributes */
|
|
|
|
|
2013-08-23 23:18:34 +00:00
|
|
|
static ssize_t uart_mode_show(struct device *dev,
|
2007-05-22 19:57:04 +00:00
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct usb_serial_port *port = to_usb_serial_port(dev);
|
|
|
|
struct edgeport_port *edge_port = usb_get_serial_port_data(port);
|
|
|
|
|
|
|
|
return sprintf(buf, "%d\n", edge_port->bUartMode);
|
|
|
|
}
|
|
|
|
|
2013-08-23 23:18:34 +00:00
|
|
|
static ssize_t uart_mode_store(struct device *dev,
|
2007-05-22 19:57:04 +00:00
|
|
|
struct device_attribute *attr, const char *valbuf, size_t count)
|
|
|
|
{
|
|
|
|
struct usb_serial_port *port = to_usb_serial_port(dev);
|
|
|
|
struct edgeport_port *edge_port = usb_get_serial_port_data(port);
|
|
|
|
unsigned int v = simple_strtoul(valbuf, NULL, 0);
|
|
|
|
|
2012-09-14 23:58:58 +00:00
|
|
|
dev_dbg(dev, "%s: setting uart_mode = %d\n", __func__, v);
|
2007-05-22 19:57:04 +00:00
|
|
|
|
|
|
|
if (v < 256)
|
|
|
|
edge_port->bUartMode = v;
|
|
|
|
else
|
2008-03-04 00:08:34 +00:00
|
|
|
dev_err(dev, "%s - uart_mode %d is invalid\n", __func__, v);
|
2007-05-22 19:57:04 +00:00
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
2013-08-23 23:18:34 +00:00
|
|
|
static DEVICE_ATTR_RW(uart_mode);
|
2007-05-22 19:57:04 +00:00
|
|
|
|
|
|
|
static int edge_create_sysfs_attrs(struct usb_serial_port *port)
|
|
|
|
{
|
|
|
|
return device_create_file(&port->dev, &dev_attr_uart_mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int edge_remove_sysfs_attrs(struct usb_serial_port *port)
|
|
|
|
{
|
|
|
|
device_remove_file(&port->dev, &dev_attr_uart_mode);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-07-31 06:55:08 +00:00
|
|
|
#ifdef CONFIG_PM
|
|
|
|
static int edge_suspend(struct usb_serial *serial, pm_message_t message)
|
|
|
|
{
|
|
|
|
struct edgeport_serial *edge_serial = usb_get_serial_data(serial);
|
|
|
|
|
|
|
|
cancel_delayed_work_sync(&edge_serial->heartbeat_work);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int edge_resume(struct usb_serial *serial)
|
|
|
|
{
|
|
|
|
struct edgeport_serial *edge_serial = usb_get_serial_data(serial);
|
|
|
|
|
|
|
|
edge_heartbeat_schedule(edge_serial);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2007-05-22 19:57:04 +00:00
|
|
|
|
2005-06-21 04:15:16 +00:00
|
|
|
static struct usb_serial_driver edgeport_1port_device = {
|
2005-06-21 04:15:16 +00:00
|
|
|
.driver = {
|
2005-06-21 04:15:16 +00:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.name = "edgeport_ti_1",
|
2005-06-21 04:15:16 +00:00
|
|
|
},
|
2005-06-21 04:15:16 +00:00
|
|
|
.description = "Edgeport TI 1 port adapter",
|
2005-04-16 22:20:36 +00:00
|
|
|
.id_table = edgeport_1port_id_table,
|
|
|
|
.num_ports = 1,
|
2017-03-16 16:13:42 +00:00
|
|
|
.num_bulk_out = 1,
|
2005-04-16 22:20:36 +00:00
|
|
|
.open = edge_open,
|
|
|
|
.close = edge_close,
|
|
|
|
.throttle = edge_throttle,
|
|
|
|
.unthrottle = edge_unthrottle,
|
|
|
|
.attach = edge_startup,
|
2017-03-16 16:13:41 +00:00
|
|
|
.calc_num_ports = edge_calc_num_ports,
|
2009-06-02 15:53:55 +00:00
|
|
|
.disconnect = edge_disconnect,
|
|
|
|
.release = edge_release,
|
2012-10-17 11:34:58 +00:00
|
|
|
.port_probe = edge_port_probe,
|
|
|
|
.port_remove = edge_port_remove,
|
2005-04-16 22:20:36 +00:00
|
|
|
.set_termios = edge_set_termios,
|
|
|
|
.tiocmget = edge_tiocmget,
|
|
|
|
.tiocmset = edge_tiocmset,
|
2013-03-21 11:37:10 +00:00
|
|
|
.tiocmiwait = usb_serial_generic_tiocmiwait,
|
2013-03-21 11:37:09 +00:00
|
|
|
.get_icount = usb_serial_generic_get_icount,
|
2005-04-16 22:20:36 +00:00
|
|
|
.write = edge_write,
|
|
|
|
.write_room = edge_write_room,
|
|
|
|
.chars_in_buffer = edge_chars_in_buffer,
|
2013-05-05 18:32:31 +00:00
|
|
|
.tx_empty = edge_tx_empty,
|
2005-04-16 22:20:36 +00:00
|
|
|
.break_ctl = edge_break,
|
|
|
|
.read_int_callback = edge_interrupt_callback,
|
|
|
|
.read_bulk_callback = edge_bulk_in_callback,
|
|
|
|
.write_bulk_callback = edge_bulk_out_callback,
|
2015-07-31 06:55:08 +00:00
|
|
|
#ifdef CONFIG_PM
|
|
|
|
.suspend = edge_suspend,
|
|
|
|
.resume = edge_resume,
|
|
|
|
#endif
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
2005-06-21 04:15:16 +00:00
|
|
|
static struct usb_serial_driver edgeport_2port_device = {
|
2005-06-21 04:15:16 +00:00
|
|
|
.driver = {
|
2005-06-21 04:15:16 +00:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.name = "edgeport_ti_2",
|
2005-06-21 04:15:16 +00:00
|
|
|
},
|
2005-06-21 04:15:16 +00:00
|
|
|
.description = "Edgeport TI 2 port adapter",
|
2005-04-16 22:20:36 +00:00
|
|
|
.id_table = edgeport_2port_id_table,
|
|
|
|
.num_ports = 2,
|
2017-03-16 16:13:42 +00:00
|
|
|
.num_bulk_out = 1,
|
2005-04-16 22:20:36 +00:00
|
|
|
.open = edge_open,
|
|
|
|
.close = edge_close,
|
|
|
|
.throttle = edge_throttle,
|
|
|
|
.unthrottle = edge_unthrottle,
|
|
|
|
.attach = edge_startup,
|
2017-03-16 16:13:41 +00:00
|
|
|
.calc_num_ports = edge_calc_num_ports,
|
2009-06-02 15:53:55 +00:00
|
|
|
.disconnect = edge_disconnect,
|
|
|
|
.release = edge_release,
|
2012-10-17 11:34:58 +00:00
|
|
|
.port_probe = edge_port_probe,
|
|
|
|
.port_remove = edge_port_remove,
|
2005-04-16 22:20:36 +00:00
|
|
|
.set_termios = edge_set_termios,
|
|
|
|
.tiocmget = edge_tiocmget,
|
|
|
|
.tiocmset = edge_tiocmset,
|
2013-03-21 11:37:10 +00:00
|
|
|
.tiocmiwait = usb_serial_generic_tiocmiwait,
|
2013-03-21 11:37:09 +00:00
|
|
|
.get_icount = usb_serial_generic_get_icount,
|
2005-04-16 22:20:36 +00:00
|
|
|
.write = edge_write,
|
|
|
|
.write_room = edge_write_room,
|
|
|
|
.chars_in_buffer = edge_chars_in_buffer,
|
2013-05-05 18:32:31 +00:00
|
|
|
.tx_empty = edge_tx_empty,
|
2005-04-16 22:20:36 +00:00
|
|
|
.break_ctl = edge_break,
|
|
|
|
.read_int_callback = edge_interrupt_callback,
|
|
|
|
.read_bulk_callback = edge_bulk_in_callback,
|
|
|
|
.write_bulk_callback = edge_bulk_out_callback,
|
2015-07-31 06:55:08 +00:00
|
|
|
#ifdef CONFIG_PM
|
|
|
|
.suspend = edge_suspend,
|
|
|
|
.resume = edge_resume,
|
|
|
|
#endif
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
2012-02-23 19:56:57 +00:00
|
|
|
static struct usb_serial_driver * const serial_drivers[] = {
|
|
|
|
&edgeport_1port_device, &edgeport_2port_device, NULL
|
|
|
|
};
|
|
|
|
|
2012-05-08 22:46:14 +00:00
|
|
|
module_usb_serial_driver(serial_drivers, id_table_combined);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
MODULE_AUTHOR(DRIVER_AUTHOR);
|
|
|
|
MODULE_DESCRIPTION(DRIVER_DESC);
|
|
|
|
MODULE_LICENSE("GPL");
|
2008-07-04 17:36:09 +00:00
|
|
|
MODULE_FIRMWARE("edgeport/down3.bin");
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-08-25 16:23:02 +00:00
|
|
|
module_param(ignore_cpu_rev, bool, 0644);
|
2008-04-29 13:45:15 +00:00
|
|
|
MODULE_PARM_DESC(ignore_cpu_rev,
|
|
|
|
"Ignore the cpu revision when connecting to a device");
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-08-25 16:23:02 +00:00
|
|
|
module_param(default_uart_mode, int, 0644);
|
2007-05-22 19:57:04 +00:00
|
|
|
MODULE_PARM_DESC(default_uart_mode, "Default uart_mode, 0=RS232, ...");
|