linux/drivers/usb/serial/f81534.c

// SPDX-License-Identifier: GPL-2.0+
/*
 * F81532/F81534 USB to Serial Ports Bridge
 *
 * F81532 => 2 Serial Ports
 * F81534 => 4 Serial Ports
 *
 * Copyright (C) 2016 Feature Integration Technology Inc., (Fintek)
 * Copyright (C) 2016 Tom Tsai ([email protected])
 * Copyright (C) 2016 Peter Hong ([email protected])
 *
 * The F81532/F81534 had 1 control endpoint for setting, 1 endpoint bulk-out
 * for all serial port TX and 1 endpoint bulk-in for all serial port read in
 * (Read Data/MSR/LSR).
 *
 * Write URB is fixed with 512bytes, per serial port used 128Bytes.
 * It can be described by f81534_prepare_write_buffer()
 *
 * Read URB is 512Bytes max, per serial port used 128Bytes.
 * It can be described by f81534_process_read_urb() and maybe received with
 * 128x1,2,3,4 bytes.
 *
 */
#include <linux/slab.h>
#include <linux/tty.h>
#include <linux/tty_flip.h>
#include <linux/usb.h>
#include <linux/usb/serial.h>
#include <linux/serial_reg.h>
#include <linux/module.h>
#include <linux/uaccess.h>

/* Serial Port register Address */
#define F81534_UART_BASE_ADDRESS
#define F81534_UART_OFFSET
#define F81534_DIVISOR_LSB_REG
#define F81534_DIVISOR_MSB_REG
#define F81534_INTERRUPT_ENABLE_REG
#define F81534_FIFO_CONTROL_REG
#define F81534_LINE_CONTROL_REG
#define F81534_MODEM_CONTROL_REG
#define F81534_LINE_STATUS_REG
#define F81534_MODEM_STATUS_REG
#define F81534_CLOCK_REG
#define F81534_CONFIG1_REG

#define F81534_DEF_CONF_ADDRESS_START
#define F81534_DEF_CONF_SIZE

#define F81534_CUSTOM_ADDRESS_START
#define F81534_CUSTOM_DATA_SIZE
#define F81534_CUSTOM_NO_CUSTOM_DATA
#define F81534_CUSTOM_VALID_TOKEN
#define F81534_CONF_OFFSET
#define F81534_CONF_INIT_GPIO_OFFSET
#define F81534_CONF_WORK_GPIO_OFFSET
#define F81534_CONF_GPIO_SHUTDOWN
#define F81534_CONF_GPIO_RS232

#define F81534_MAX_DATA_BLOCK
#define F81534_MAX_BUS_RETRY

/* Default URB timeout for USB operations */
#define F81534_USB_MAX_RETRY
#define F81534_USB_TIMEOUT
#define F81534_SET_GET_REGISTER

#define F81534_NUM_PORT
#define F81534_UNUSED_PORT
#define F81534_WRITE_BUFFER_SIZE

#define DRIVER_DESC
#define FINTEK_VENDOR_ID_1
#define FINTEK_VENDOR_ID_2
#define FINTEK_DEVICE_ID
#define F81534_MAX_TX_SIZE
#define F81534_MAX_RX_SIZE
#define F81534_RECEIVE_BLOCK_SIZE
#define F81534_MAX_RECEIVE_BLOCK_SIZE

#define F81534_TOKEN_RECEIVE
#define F81534_TOKEN_WRITE
#define F81534_TOKEN_TX_EMPTY
#define F81534_TOKEN_MSR_CHANGE

/*
 * We used interal SPI bus to access FLASH section. We must wait the SPI bus to
 * idle if we performed any command.
 *
 * SPI Bus status register: F81534_BUS_REG_STATUS
 *	Bit 0/1	: BUSY
 *	Bit 2	: IDLE
 */
#define F81534_BUS_BUSY
#define F81534_BUS_IDLE
#define F81534_BUS_READ_DATA
#define F81534_BUS_REG_STATUS
#define F81534_BUS_REG_START
#define F81534_BUS_REG_END

#define F81534_CMD_READ

#define F81534_DEFAULT_BAUD_RATE

#define F81534_PORT_CONF_RS232
#define F81534_PORT_CONF_RS485
#define F81534_PORT_CONF_RS485_INVERT
#define F81534_PORT_CONF_MODE_MASK
#define F81534_PORT_CONF_DISABLE_PORT
#define F81534_PORT_CONF_NOT_EXIST_PORT
#define F81534_PORT_UNAVAILABLE


#define F81534_1X_RXTRIGGER
#define F81534_8X_RXTRIGGER

/*
 * F81532/534 Clock registers (offset +08h)
 *
 * Bit0:	UART Enable (always on)
 * Bit2-1:	Clock source selector
 *			00: 1.846MHz.
 *			01: 18.46MHz.
 *			10: 24MHz.
 *			11: 14.77MHz.
 * Bit4:	Auto direction(RTS) control (RTS pin Low when TX)
 * Bit5:	Invert direction(RTS) when Bit4 enabled (RTS pin high when TX)
 */

#define F81534_UART_EN
#define F81534_CLK_1_846_MHZ
#define F81534_CLK_18_46_MHZ
#define F81534_CLK_24_MHZ
#define F81534_CLK_14_77_MHZ
#define F81534_CLK_MASK
#define F81534_CLK_TX_DELAY_1BIT
#define F81534_CLK_RS485_MODE
#define F81534_CLK_RS485_INVERT

static const struct usb_device_id f81534_id_table[] =;

#define F81534_TX_EMPTY_BIT

struct f81534_serial_private {};

struct f81534_port_private {};

struct f81534_pin_data {};

struct f81534_port_out_pin {};

/* Pin output value for M2/M1/M0(SD) */
static const struct f81534_port_out_pin f81534_port_out_pins[] =;

static u32 const baudrate_table[] =;
static u8 const clock_table[] =;

static int f81534_logic_to_phy_port(struct usb_serial *serial,
					struct usb_serial_port *port)
{}

static int f81534_set_register(struct usb_serial *serial, u16 reg, u8 data)
{}

static int f81534_get_register(struct usb_serial *serial, u16 reg, u8 *data)
{}

static int f81534_set_mask_register(struct usb_serial *serial, u16 reg,
					u8 mask, u8 data)
{}

static int f81534_set_phy_port_register(struct usb_serial *serial, int phy,
					u16 reg, u8 data)
{}

static int f81534_get_phy_port_register(struct usb_serial *serial, int phy,
					u16 reg, u8 *data)
{}

static int f81534_set_port_register(struct usb_serial_port *port, u16 reg,
					u8 data)
{}

static int f81534_get_port_register(struct usb_serial_port *port, u16 reg,
					u8 *data)
{}

/*
 * If we try to access the internal flash via SPI bus, we should check the bus
 * status for every command. e.g., F81534_BUS_REG_START/F81534_BUS_REG_END
 */
static int f81534_wait_for_spi_idle(struct usb_serial *serial)
{}

static int f81534_get_spi_register(struct usb_serial *serial, u16 reg,
					u8 *data)
{}

static int f81534_set_spi_register(struct usb_serial *serial, u16 reg, u8 data)
{}

static int f81534_read_flash(struct usb_serial *serial, u32 address,
				size_t size, u8 *buf)
{}

static void f81534_prepare_write_buffer(struct usb_serial_port *port, u8 *buf)
{}

static int f81534_submit_writer(struct usb_serial_port *port, gfp_t mem_flags)
{}

static u32 f81534_calc_baud_divisor(u32 baudrate, u32 clockrate)
{}

static int f81534_find_clk(u32 baudrate)
{}

static int f81534_set_port_config(struct usb_serial_port *port,
		struct tty_struct *tty, u32 baudrate, u32 old_baudrate, u8 lcr)
{}

static int f81534_break_ctl(struct tty_struct *tty, int break_state)
{}

static int f81534_update_mctrl(struct usb_serial_port *port, unsigned int set,
				unsigned int clear)
{}

/*
 * This function will search the data area with token F81534_CUSTOM_VALID_TOKEN
 * for latest configuration index. If nothing found
 * (*index = F81534_CUSTOM_NO_CUSTOM_DATA), We'll load default configure in
 * F81534_DEF_CONF_ADDRESS_START section.
 *
 * Due to we only use block0 to save data, so *index should be 0 or
 * F81534_CUSTOM_NO_CUSTOM_DATA.
 */
static int f81534_find_config_idx(struct usb_serial *serial, u8 *index)
{}

/*
 * The F81532/534 will not report serial port to USB serial subsystem when
 * H/W DCD/DSR/CTS/RI/RX pin connected to ground.
 *
 * To detect RX pin status, we'll enable MCR interal loopback, disable it and
 * delayed for 60ms. It connected to ground If LSR register report UART_LSR_BI.
 */
static bool f81534_check_port_hw_disabled(struct usb_serial *serial, int phy)
{}

/*
 * We had 2 generation of F81532/534 IC. All has an internal storage.
 *
 * 1st is pure USB-to-TTL RS232 IC and designed for 4 ports only, no any
 * internal data will used. All mode and gpio control should manually set
 * by AP or Driver and all storage space value are 0xff. The
 * f81534_calc_num_ports() will run to final we marked as "oldest version"
 * for this IC.
 *
 * 2rd is designed to more generic to use any transceiver and this is our
 * mass production type. We'll save data in F81534_CUSTOM_ADDRESS_START
 * (0x2f00) with 9bytes. The 1st byte is a indicater. If the token is
 * F81534_CUSTOM_VALID_TOKEN(0xf0), the IC is 2nd gen type, the following
 * 4bytes save port mode (0:RS232/1:RS485 Invert/2:RS485), and the last
 * 4bytes save GPIO state(value from 0~7 to represent 3 GPIO output pin).
 * The f81534_calc_num_ports() will run to "new style" with checking
 * F81534_PORT_UNAVAILABLE section.
 */
static int f81534_calc_num_ports(struct usb_serial *serial,
					struct usb_serial_endpoints *epds)
{}

static void f81534_set_termios(struct tty_struct *tty,
			       struct usb_serial_port *port,
			       const struct ktermios *old_termios)
{}

static int f81534_submit_read_urb(struct usb_serial *serial, gfp_t flags)
{}

static void f81534_msr_changed(struct usb_serial_port *port, u8 msr)
{}

static int f81534_read_msr(struct usb_serial_port *port)
{}

static int f81534_open(struct tty_struct *tty, struct usb_serial_port *port)
{}

static void f81534_close(struct usb_serial_port *port)
{}

static void f81534_get_serial_info(struct tty_struct *tty, struct serial_struct *ss)
{}

static void f81534_process_per_serial_block(struct usb_serial_port *port,
		u8 *data)
{}

static void f81534_process_read_urb(struct urb *urb)
{}

static void f81534_write_usb_callback(struct urb *urb)
{}

static void f81534_lsr_worker(struct work_struct *work)
{}

static int f81534_set_port_output_pin(struct usb_serial_port *port)
{}

static int f81534_port_probe(struct usb_serial_port *port)
{}

static void f81534_port_remove(struct usb_serial_port *port)
{}

static int f81534_tiocmget(struct tty_struct *tty)
{}

static int f81534_tiocmset(struct tty_struct *tty, unsigned int set,
				unsigned int clear)
{}

static void f81534_dtr_rts(struct usb_serial_port *port, int on)
{}

static int f81534_write(struct tty_struct *tty, struct usb_serial_port *port,
			const u8 *buf, int count)
{}

static bool f81534_tx_empty(struct usb_serial_port *port)
{}

static int f81534_resume(struct usb_serial *serial)
{}

static struct usb_serial_driver f81534_device =;

static struct usb_serial_driver *const serial_drivers[] =;

module_usb_serial_driver();

MODULE_DEVICE_TABLE(usb, f81534_id_table);
MODULE_DESCRIPTION();
MODULE_AUTHOR();
MODULE_AUTHOR();
MODULE_LICENSE();