فهرست منبع

remove vendor host class because its version is too old

sakumisu 2 سال پیش
والد
کامیت
7b936db889

+ 0 - 5
SConscript

@@ -140,11 +140,6 @@ if GetDepend(['PKG_CHERRYUSB_HOST']):
     if GetDepend('RT_USING_DFS'):
         src += Glob('third_party/rt-thread-5.0/dfs_usbh_msc.c')
 
-    if GetDepend(['PKG_CHERRYUSB_HOST_CP210X']):
-        path += [cwd + '/class/vendor/cp201x']
-        src += Glob('class/vendor/cp201x/usbh_cp210x.c')
-        src += Glob('third_party/rt-thread-4.1.1/dfs/drv_usbh_cp210x_rtt.c')
-
 src += Glob('third_party/rt-thread-5.0/msh_cmd.c')
 
 group = DefineGroup('CherryUSB', src, depend = ['PKG_USING_CHERRYUSB'], CPPPATH = path, CPPDEFINES = CPPDEFINES)

+ 0 - 125
class/vendor/air72x/usbh_air724.c

@@ -1,125 +0,0 @@
-/*
- * Copyright (c) 2022, sakumisu
- *
- * SPDX-License-Identifier: Apache-2.0
- */
-#include "usbh_core.h"
-
-#define DEV_FORMAT "/dev/air724"
-
-struct usbh_cdc_custom_air724 {
-    struct usbh_hubport *hport;
-
-    usbh_pipe_t bulkin;          /* Bulk IN endpoint */
-    usbh_pipe_t bulkout;         /* Bulk OUT endpoint */
-    struct usbh_urb bulkin_urb;  /* Bulk IN urb */
-    struct usbh_urb bulkout_urb; /* Bulk OUT urb */
-};
-
-USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_air724_buf[32];
-
-static inline int usbh_air724_bulk_out_transfer(struct usbh_cdc_custom_air724 *cdc_custom_class, uint8_t *buffer, uint32_t buflen, uint32_t timeout)
-{
-    int ret;
-    struct usbh_urb *urb = &cdc_custom_class->bulkout_urb;
-    memset(urb, 0, sizeof(struct usbh_urb));
-
-    usbh_bulk_urb_fill(urb, cdc_custom_class->bulkout, buffer, buflen, timeout, NULL, NULL);
-    ret = usbh_submit_urb(urb);
-    if (ret == 0) {
-        ret = urb->actual_length;
-    }
-    return ret;
-}
-
-static inline int usbh_air724_bulk_in_transfer(struct usbh_cdc_custom_air724 *cdc_custom_class, uint8_t *buffer, uint32_t buflen, uint32_t timeout)
-{
-    int ret;
-    struct usbh_urb *urb = &cdc_custom_class->bulkin_urb;
-    memset(urb, 0, sizeof(struct usbh_urb));
-
-    usbh_bulk_urb_fill(urb, cdc_custom_class->bulkin, buffer, buflen, timeout, NULL, NULL);
-    ret = usbh_submit_urb(urb);
-    if (ret == 0) {
-        ret = urb->actual_length;
-    }
-    return ret;
-}
-
-int usbh_air724_connect(struct usbh_hubport *hport, uint8_t intf)
-{
-    struct usb_endpoint_descriptor *ep_desc;
-    int ret;
-
-    /* interface 3 is AT command */
-    if (intf != 3) {
-        USB_LOG_WRN("ignore intf:%d\r\n", intf);
-        return 0;
-    }
-    struct usbh_cdc_custom_air724 *cdc_custom_class = usb_malloc(sizeof(struct usbh_cdc_custom_air724));
-    if (cdc_custom_class == NULL) {
-        USB_LOG_ERR("Fail to alloc cdc_custom_class\r\n");
-        return -ENOMEM;
-    }
-
-    memset(cdc_custom_class, 0, sizeof(struct usbh_cdc_custom_air724));
-    cdc_custom_class->hport = hport;
-
-    strncpy(hport->config.intf[intf].devname, DEV_FORMAT, CONFIG_USBHOST_DEV_NAMELEN);
-
-    hport->config.intf[intf].priv = cdc_custom_class;
-
-    for (uint8_t i = 0; i < hport->config.intf[intf].altsetting[0].intf_desc.bNumEndpoints; i++) {
-        ep_desc = &hport->config.intf[intf].altsetting[0].ep[i].ep_desc;
-
-        if (ep_desc->bEndpointAddress & 0x80) {
-            usbh_hport_activate_epx(&cdc_custom_class->bulkin, hport, ep_desc);
-        } else {
-            usbh_hport_activate_epx(&cdc_custom_class->bulkout, hport, ep_desc);
-        }
-    }
-
-    USB_LOG_INFO("Register air724 Class:%s\r\n", hport->config.intf[intf].devname);
-
-    const uint8_t AT[4] = { 0x41, 0x54, 0x0d, 0x0a };
-
-    memcpy(g_air724_buf, AT, 4);
-    ret = usbh_air724_bulk_out_transfer(cdc_custom_class, g_air724_buf, 4, 3000);
-    if (ret < 0) {
-        USB_LOG_ERR("bulk out error,ret:%d\r\n", ret);
-    } else {
-        USB_LOG_RAW("send over:%d\r\n", ret);
-    }
-    ret = usbh_air724_bulk_in_transfer(cdc_custom_class, g_air724_buf, 10, 3000);
-    if (ret < 0) {
-        USB_LOG_ERR("bulk in error,ret:%d\r\n", ret);
-    } else {
-        USB_LOG_RAW("recv over:%d\r\n", ret);
-        for (size_t i = 0; i < ret; i++) {
-            USB_LOG_RAW("0x%02x ", g_air724_buf[i]);
-        }
-    }
-
-    return ret;
-}
-
-int usbh_air724_disconnect(struct usbh_hubport *hport, uint8_t intf)
-{
-    return 0;
-}
-
-const struct usbh_class_driver cdc_custom_class_driver = {
-    .driver_name = "cdc_acm",
-    .connect = usbh_air724_connect,
-    .disconnect = usbh_air724_disconnect
-};
-
-CLASS_INFO_DEFINE const struct usbh_class_info cdc_custom_class_info = {
-    .match_flags = USB_CLASS_MATCH_INTF_CLASS | USB_CLASS_MATCH_INTF_SUBCLASS | USB_CLASS_MATCH_INTF_PROTOCOL,
-    .class = 0xff,
-    .subclass = 0,
-    .protocol = 0,
-    .vid = 0x1782,
-    .pid = 0x4e00,
-    .class_driver = &cdc_custom_class_driver
-};

+ 0 - 596
class/vendor/asix/asix.h

@@ -1,596 +0,0 @@
-/*
- * Change Logs
- * Date           Author       Notes
- * 2022-04-17     aozima       the first version for CherryUSB.
- */
-
-#ifndef	__LINUX_USBNET_ASIX_H
-#define	__LINUX_USBNET_ASIX_H
-
-// #define __BIG_ENDIAN_BITFIELD
-#define __LITTLE_ENDIAN_BITFIELD
-typedef uint8_t u8;
-typedef uint16_t u16;
-typedef uint32_t u32;
-
-#define KERNEL_VERSION(...)	(0)
-#define LINUX_VERSION_CODE	(1)
-
-/*
- * Turn on this flag if the implementation of your USB host controller
- * cannot handle non-double word aligned buffer.
- * When turn on this flag, driver will fixup egress packet aligned on double
- * word boundary before deliver to USB host controller. And will Disable the
- * function "skb_reserve (skb, NET_IP_ALIGN)" to retain the buffer aligned on
- * double word alignment for ingress packets.
- */
-#define AX_FORCE_BUFF_ALIGN		0
-
-//#define RX_SKB_COPY
-
-#define AX_MONITOR_MODE			0x01
-#define AX_MONITOR_LINK			0x02
-#define AX_MONITOR_MAGIC		0x04
-#define AX_MONITOR_HSFS			0x10
-
-/* AX88172 Medium Status Register values */
-#define AX_MEDIUM_FULL_DUPLEX		0x02
-#define AX_MEDIUM_TX_ABORT_ALLOW	0x04
-#define AX_MEDIUM_FLOW_CONTROL_EN	0x10
-#define AX_MCAST_FILTER_SIZE		8
-#define AX_MAX_MCAST			64
-
-#define AX_EEPROM_LEN			0x40
-
-#define AX_SWRESET_CLEAR		0x00
-#define AX_SWRESET_RR			0x01
-#define AX_SWRESET_RT			0x02
-#define AX_SWRESET_PRTE			0x04
-#define AX_SWRESET_PRL			0x08
-#define AX_SWRESET_BZ			0x10
-#define AX_SWRESET_IPRL			0x20
-#define AX_SWRESET_IPPD			0x40
-#define AX_SWRESET_IPOSC		0x0080
-#define AX_SWRESET_IPPSL_0		0x0100
-#define AX_SWRESET_IPPSL_1		0x0200
-#define AX_SWRESET_IPCOPS		0x0400
-#define AX_SWRESET_IPCOPSC		0x0800
-#define AX_SWRESET_AUTODETACH		0x1000
-#define AX_SWRESET_WOLLP		0x8000
-
-#define AX88772_IPG0_DEFAULT		0x15
-#define AX88772_IPG1_DEFAULT		0x0c
-#define AX88772_IPG2_DEFAULT		0x0E
-
-#define AX88772A_IPG0_DEFAULT		0x15
-#define AX88772A_IPG1_DEFAULT		0x16
-#define AX88772A_IPG2_DEFAULT		0x1A
-
-#define AX88772_MEDIUM_FULL_DUPLEX	0x0002
-#define AX88772_MEDIUM_RESERVED		0x0004
-#define AX88772_MEDIUM_RX_FC_ENABLE	0x0010
-#define AX88772_MEDIUM_TX_FC_ENABLE	0x0020
-#define AX88772_MEDIUM_PAUSE_FORMAT	0x0080
-#define AX88772_MEDIUM_RX_ENABLE	0x0100
-#define AX88772_MEDIUM_100MB		0x0200
-#define AX88772_MEDIUM_DEFAULT	\
-	(AX88772_MEDIUM_FULL_DUPLEX | AX88772_MEDIUM_RX_FC_ENABLE | \
-	 AX88772_MEDIUM_TX_FC_ENABLE | AX88772_MEDIUM_100MB | \
-	 AX88772_MEDIUM_RESERVED | AX88772_MEDIUM_RX_ENABLE)
-
-#define AX_CMD_SET_SW_MII		0x06
-#define AX_CMD_READ_MII_REG		0x07
-#define AX_CMD_WRITE_MII_REG		0x08
-#define AX_CMD_READ_STATMNGSTS_REG	0x09
-	#define AX_HOST_EN		0x01
-
-#define AX_CMD_SET_HW_MII		0x0a
-#define AX_CMD_READ_EEPROM		0x0b
-#define AX_CMD_WRITE_EEPROM		0x0c
-#define AX_CMD_WRITE_EEPROM_EN		0x0d
-#define AX_CMD_WRITE_EEPROM_DIS		0x0e
-#define AX_CMD_WRITE_RX_CTL		0x10
-#define AX_CMD_READ_IPG012		0x11
-#define AX_CMD_WRITE_IPG0		0x12
-#define AX_CMD_WRITE_IPG1		0x13
-#define AX_CMD_WRITE_IPG2		0x14
-#define AX_CMD_WRITE_MULTI_FILTER	0x16
-#define AX_CMD_READ_NODE_ID		0x17
-#define AX_CMD_READ_PHY_ID		0x19
-#define AX_CMD_READ_MEDIUM_MODE		0x1a
-#define AX_CMD_WRITE_MEDIUM_MODE	0x1b
-#define AX_CMD_READ_MONITOR_MODE	0x1c
-#define AX_CMD_WRITE_MONITOR_MODE	0x1d
-#define AX_CMD_WRITE_GPIOS		0x1f
-#define AX_CMD_SW_RESET			0x20
-#define AX_CMD_SW_PHY_STATUS		0x21
-#define AX_CMD_SW_PHY_SELECT		0x22
-	#define AX_PHYSEL_PSEL		(1 << 0)
-	#define AX_PHYSEL_ASEL		(1 << 1)
-	#define AX_PHYSEL_SSMII		(0 << 2)
-	#define AX_PHYSEL_SSRMII	(1 << 2)
-	#define AX_PHYSEL_SSRRMII	(3 << 2)
-	#define AX_PHYSEL_SSEN		(1 << 4)
-#define AX88772_CMD_READ_NODE_ID	0x13
-#define AX88772_CMD_WRITE_NODE_ID	0x14
-#define AX_CMD_READ_WKFARY		0x23
-#define AX_CMD_WRITE_WKFARY		0x24
-#define AX_CMD_READ_RXCOE_CTL		0x2b
-#define AX_CMD_WRITE_RXCOE_CTL		0x2c
-#define AX_CMD_READ_TXCOE_CTL		0x2d
-#define AX_CMD_WRITE_TXCOE_CTL		0x2e
-
-#define REG_LENGTH			2
-#define PHY_ID_MASK			0x1f
-
-#define AX_RXCOE_IPCE			0x0001
-#define AX_RXCOE_IPVE			0x0002
-#define AX_RXCOE_V6VE			0x0004
-#define AX_RXCOE_TCPE			0x0008
-#define AX_RXCOE_UDPE			0x0010
-#define AX_RXCOE_ICMP			0x0020
-#define AX_RXCOE_IGMP			0x0040
-#define AX_RXCOE_ICV6			0x0080
-#define AX_RXCOE_TCPV6			0x0100
-#define AX_RXCOE_UDPV6			0x0200
-#define AX_RXCOE_ICMV6			0x0400
-#define AX_RXCOE_IGMV6			0x0800
-#define AX_RXCOE_ICV6V6			0x1000
-#define AX_RXCOE_FOPC			0x8000
-#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 22)
-#define AX_RXCOE_DEF_CSUM		(AX_RXCOE_IPCE | AX_RXCOE_IPVE | \
-					 AX_RXCOE_V6VE | AX_RXCOE_TCPE | \
-					 AX_RXCOE_UDPE |  AX_RXCOE_ICV6 | \
-					 AX_RXCOE_TCPV6 | AX_RXCOE_UDPV6)
-#else
-#define AX_RXCOE_DEF_CSUM		(AX_RXCOE_IPCE | AX_RXCOE_IPVE | \
-					 AX_RXCOE_TCPE | AX_RXCOE_UDPE)
-#endif
-
-#define AX_RXCOE_64TE			0x0100
-#define AX_RXCOE_PPPOE			0x0200
-#define AX_RXCOE_RPCE			0x8000
-
-#define AX_TXCOE_IP			0x0001
-#define AX_TXCOE_TCP			0x0002
-#define AX_TXCOE_UDP			0x0004
-#define AX_TXCOE_ICMP			0x0008
-#define AX_TXCOE_IGMP			0x0010
-#define AX_TXCOE_ICV6			0x0020
-
-#define AX_TXCOE_TCPV6			0x0100
-#define AX_TXCOE_UDPV6			0x0200
-#define AX_TXCOE_ICMV6			0x0400
-#define AX_TXCOE_IGMV6			0x0800
-#define AX_TXCOE_ICV6V6			0x1000
-#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 22)
-#define AX_TXCOE_DEF_CSUM		(AX_TXCOE_TCP | AX_TXCOE_UDP | \
-					 AX_TXCOE_TCPV6 | AX_TXCOE_UDPV6)
-#else
-#define AX_TXCOE_DEF_CSUM		(AX_TXCOE_TCP | AX_TXCOE_UDP)
-#endif
-
-#define AX_TXCOE_64TE			0x0001
-#define AX_TXCOE_PPPE			0x0002
-
-#define AX88772B_MAX_BULKIN_2K		0
-#define AX88772B_MAX_BULKIN_4K		1
-#define AX88772B_MAX_BULKIN_6K		2
-#define AX88772B_MAX_BULKIN_8K		3
-#define AX88772B_MAX_BULKIN_16K		4
-#define AX88772B_MAX_BULKIN_20K		5
-#define AX88772B_MAX_BULKIN_24K		6
-#define AX88772B_MAX_BULKIN_32K		7
-struct {unsigned short size, byte_cnt, threshold; } AX88772B_BULKIN_SIZE[] = {
-	/* 2k */
-	{2048, 0x8000, 0x8001},
-	/* 4k */
-	{4096, 0x8100, 0x8147},
-	/* 6k */
-	{6144, 0x8200, 0x81EB},
-	/* 8k */
-	{8192, 0x8300, 0x83D7},
-	/* 16 */
-	{16384, 0x8400, 0x851E},
-	/* 20k */
-	{20480, 0x8500, 0x8666},
-	/* 24k */
-	{24576, 0x8600, 0x87AE},
-	/* 32k */
-	{32768, 0x8700, 0x8A3D},
-};
-
-
-#define AX_RX_CTL_RH1M			0x0100		/* Enable RX-Header mode 0 */
-#define AX_RX_CTL_RH2M			0x0200		/* Enable IP header in receive buffer aligned on 32-bit aligment */
-#define AX_RX_CTL_RH3M			0x0400		/* checksum value in rx header 3 */
-#define AX_RX_HEADER_DEFAULT		(AX_RX_CTL_RH1M | AX_RX_CTL_RH2M)
-
-#define AX_RX_CTL_MFB			0x0300		/* Maximum Frame size 16384bytes */
-#define AX_RX_CTL_START			0x0080		/* Ethernet MAC start */
-#define AX_RX_CTL_AP			0x0020		/* Accept physcial address from Multicast array */
-#define AX_RX_CTL_AM			0x0010
-#define AX_RX_CTL_AB			0x0008		/* Accetp Brocadcast frames*/
-#define AX_RX_CTL_SEP			0x0004		/* Save error packets */
-#define AX_RX_CTL_AMALL			0x0002		/* Accetp all multicast frames */
-#define AX_RX_CTL_PRO			0x0001		/* Promiscuous Mode */
-#define AX_RX_CTL_STOP			0x0000		/* Stop MAC */
-
-#define AX_MONITOR_MODE			0x01
-#define AX_MONITOR_LINK			0x02
-#define AX_MONITOR_MAGIC		0x04
-#define AX_MONITOR_HSFS			0x10
-
-#define AX_MCAST_FILTER_SIZE		8
-#define AX_MAX_MCAST			64
-#define AX_INTERRUPT_BUFSIZE		8
-
-#define AX_EEPROM_LEN			0x40
-#define AX_EEPROM_MAGIC			0xdeadbeef
-#define EEPROMMASK			0x7f
-
-/* GPIO REGISTER */
-#define AXGPIOS_GPO0EN			0X01 /* 1 << 0 */
-#define AXGPIOS_GPO0			0X02 /* 1 << 1 */
-#define AXGPIOS_GPO1EN			0X04 /*	1 << 2 */
-#define AXGPIOS_GPO1			0X08 /* 1 << 3 */
-#define AXGPIOS_GPO2EN			0X10 /* 1 << 4 */
-#define AXGPIOS_GPO2			0X20 /* 1 << 5 */
-#define AXGPIOS_RSE			0X80 /* 1 << 7 */
-
-/* TX-header format */
-#define AX_TX_HDR_CPHI			0x4000
-#define AX_TX_HDR_DICF			0x8000
-
-/* GMII register definitions */
-#define GMII_PHY_CONTROL		0x00	/* control reg */
-#define GMII_PHY_STATUS			0x01	/* status reg */
-#define GMII_PHY_OUI			0x02	/* most of the OUI bits */
-#define GMII_PHY_MODEL			0x03	/* model/rev bits, and rest of OUI */
-#define GMII_PHY_ANAR			0x04	/* AN advertisement reg */
-#define GMII_PHY_ANLPAR			0x05	/* AN Link Partner */
-#define GMII_PHY_ANER			0x06	/* AN expansion reg */
-#define GMII_PHY_1000BT_CONTROL		0x09	/* control reg for 1000BT */
-#define GMII_PHY_1000BT_STATUS		0x0A	/* status reg for 1000BT */
-
-/* Bit definitions: GMII Control */
-#define GMII_CONTROL_RESET		0x8000	/* reset bit in control reg */
-#define GMII_CONTROL_LOOPBACK		0x4000	/* loopback bit in control reg */
-#define GMII_CONTROL_10MB		0x0000	/* 10 Mbit */
-#define GMII_CONTROL_100MB		0x2000	/* 100Mbit */
-#define GMII_CONTROL_1000MB		0x0040	/* 1000Mbit */
-#define GMII_CONTROL_SPEED_BITS		0x2040	/* speed bit mask */
-#define GMII_CONTROL_ENABLE_AUTO	0x1000	/* autonegotiate enable */
-#define GMII_CONTROL_POWER_DOWN		0x0800
-#define GMII_CONTROL_ISOLATE		0x0400	/* islolate bit */
-#define GMII_CONTROL_START_AUTO		0x0200	/* restart autonegotiate */
-#define GMII_CONTROL_FULL_DUPLEX	0x0100
-
-/* Bit definitions: GMII Status */
-#define GMII_STATUS_100MB_MASK		0xE000	/* any of these indicate 100 Mbit */
-#define GMII_STATUS_10MB_MASK		0x1800	/* either of these indicate 10 Mbit */
-#define GMII_STATUS_AUTO_DONE		0x0020	/* auto negotiation complete */
-#define GMII_STATUS_AUTO		0x0008	/* auto negotiation is available */
-#define GMII_STATUS_LINK_UP		0x0004	/* link status bit */
-#define GMII_STATUS_EXTENDED		0x0001	/* extended regs exist */
-#define GMII_STATUS_100T4		0x8000	/* capable of 100BT4 */
-#define GMII_STATUS_100TXFD		0x4000	/* capable of 100BTX full duplex */
-#define GMII_STATUS_100TX		0x2000	/* capable of 100BTX */
-#define GMII_STATUS_10TFD		0x1000	/* capable of 10BT full duplex */
-#define GMII_STATUS_10T			0x0800	/* capable of 10BT */
-
-/* Bit definitions: Auto-Negotiation Advertisement */
-#define GMII_ANAR_ASYM_PAUSE		0x0800	/* support asymetric pause */
-#define GMII_ANAR_PAUSE			0x0400	/* support pause packets */
-#define GMII_ANAR_100T4			0x0200	/* support 100BT4 */
-#define GMII_ANAR_100TXFD		0x0100	/* support 100BTX full duplex */
-#define GMII_ANAR_100TX			0x0080	/* support 100BTX half duplex */
-#define GMII_ANAR_10TFD			0x0040	/* support 10BT full duplex */
-#define GMII_ANAR_10T			0x0020	/* support 10BT half duplex */
-#define GMII_SELECTOR_FIELD		0x001F	/* selector field. */
-
-/* Bit definitions: Auto-Negotiation Link Partner Ability */
-#define GMII_ANLPAR_100T4		0x0200	/* support 100BT4 */
-#define GMII_ANLPAR_100TXFD		0x0100	/* support 100BTX full duplex */
-#define GMII_ANLPAR_100TX		0x0080	/* support 100BTX half duplex */
-#define GMII_ANLPAR_10TFD		0x0040	/* support 10BT full duplex */
-#define GMII_ANLPAR_10T			0x0020	/* support 10BT half duplex */
-#define GMII_ANLPAR_PAUSE		0x0400	/* support pause packets */
-#define GMII_ANLPAR_ASYM_PAUSE		0x0800	/* support asymetric pause */
-#define GMII_ANLPAR_ACK			0x4000	/* means LCB was successfully rx'd */
-#define GMII_SELECTOR_8023		0x0001;
-
-/* Bit definitions: 1000BaseT AUX Control */
-#define GMII_1000_AUX_CTRL_MASTER_SLAVE		0x1000
-#define GMII_1000_AUX_CTRL_FD_CAPABLE		0x0200	/* full duplex capable */
-#define GMII_1000_AUX_CTRL_HD_CAPABLE		0x0100	/* half duplex capable */
-
-/* Bit definitions: 1000BaseT AUX Status */
-#define GMII_1000_AUX_STATUS_FD_CAPABLE		0x0800	/* full duplex capable */
-#define GMII_1000_AUX_STATUS_HD_CAPABLE		0x0400	/* half duplex capable */
-
-/* Cicada MII Registers */
-#define GMII_AUX_CTRL_STATUS			0x1C
-#define GMII_AUX_ANEG_CPLT			0x8000
-#define GMII_AUX_FDX				0x0020
-#define GMII_AUX_SPEED_1000			0x0010
-#define GMII_AUX_SPEED_100			0x0008
-
-#ifndef ADVERTISE_PAUSE_CAP
-#define ADVERTISE_PAUSE_CAP			0x0400
-#endif
-
-#ifndef MII_STAT1000
-#define MII_STAT1000				0x000A
-#endif
-
-#ifndef LPA_1000FULL
-#define LPA_1000FULL				0x0800
-#endif
-
-/* medium mode register */
-#define MEDIUM_GIGA_MODE			0x0001
-#define MEDIUM_FULL_DUPLEX_MODE			0x0002
-#define MEDIUM_TX_ABORT_MODE			0x0004
-#define MEDIUM_ENABLE_125MHZ			0x0008
-#define MEDIUM_ENABLE_RX_FLOWCTRL		0x0010
-#define MEDIUM_ENABLE_TX_FLOWCTRL		0x0020
-#define MEDIUM_ENABLE_JUMBO_FRAME		0x0040
-#define MEDIUM_CHECK_PAUSE_FRAME_MODE		0x0080
-#define MEDIUM_ENABLE_RECEIVE			0x0100
-#define MEDIUM_MII_100M_MODE			0x0200
-#define MEDIUM_ENABLE_JAM_PATTERN		0x0400
-#define MEDIUM_ENABLE_STOP_BACKPRESSURE		0x0800
-#define MEDIUM_ENABLE_SUPPER_MAC_SUPPORT	0x1000
-
-/* PHY mode */
-#define PHY_MODE_MARVELL		0
-#define PHY_MODE_CICADA_FAMILY		1
-#define PHY_MODE_CICADA_V1		1
-#define PHY_MODE_AGERE_FAMILY		2
-#define PHY_MODE_AGERE_V0		2
-#define PHY_MODE_CICADA_V2		5
-#define PHY_MODE_AGERE_V0_GMII		6
-#define PHY_MODE_CICADA_V2_ASIX		9
-#define PHY_MODE_VSC8601		10
-#define PHY_MODE_RTL8211CL		12
-#define PHY_MODE_RTL8211BN		13
-#define PHY_MODE_RTL8251CL		14
-#define PHY_MODE_ATTANSIC_V0		0x40
-#define PHY_MODE_ATTANSIC_FAMILY	0x40
-#define PHY_MODE_MAC_TO_MAC_GMII	0x7C
-
-/*  */
-#define LED_MODE_MARVELL		0
-#define LED_MODE_CAMEO			1
-
-#define MARVELL_LED_CTRL		0x18
-#define MARVELL_MANUAL_LED		0x19
-
-#define PHY_IDENTIFIER			0x0002
-#define PHY_AGERE_IDENTIFIER		0x0282
-#define PHY_CICADA_IDENTIFIER		0x000f
-#define PHY_MARVELL_IDENTIFIER		0x0141
-
-#define PHY_MARVELL_STATUS		0x001b
-#define MARVELL_STATUS_HWCFG		0x0004		/* SGMII without clock */
-
-#define PHY_MARVELL_CTRL		0x0014
-#define MARVELL_CTRL_RXDELAY		0x0080
-#define MARVELL_CTRL_TXDELAY		0x0002
-
-#define PHY_CICADA_EXTPAGE		0x001f
-#define CICADA_EXTPAGE_EN		0x0001
-#define CICADA_EXTPAGE_DIS		0x0000
-
-/* External ethernet phy */
-#define EXTPHY_ID_MASK_OUI(phyid1, phyid2) ((phyid1 << 6) | ((phyid2 & 0xFC00) >> 10))
-#define EXTPHY_ID_MASK_MODEL(phyid2) ((phyid2 & 0x3F0) >> 4) 
-
-#define EXTPHY_BROADCOM_OUI		0x2B8094
-#define EXTPHY_BCM89811_MODEL		0x02
-
-struct {unsigned short value, offset; } CICADA_FAMILY_HWINIT[] = {
-	{0x0001, 0x001f}, {0x1c25, 0x0017}, {0x2a30, 0x001f}, {0x234c, 0x0010},
-	{0x2a30, 0x001f}, {0x0212, 0x0008}, {0x52b5, 0x001f}, {0xa7fa, 0x0000},
-	{0x0012, 0x0002}, {0x3002, 0x0001}, {0x87fa, 0x0000}, {0x52b5, 0x001f},
-	{0xafac, 0x0000}, {0x000d, 0x0002}, {0x001c, 0x0001}, {0x8fac, 0x0000},
-	{0x2a30, 0x001f}, {0x0012, 0x0008}, {0x2a30, 0x001f}, {0x0400, 0x0014},
-	{0x2a30, 0x001f}, {0x0212, 0x0008}, {0x52b5, 0x001f}, {0xa760, 0x0000},
-	{0x0000, 0x0002}, {0xfaff, 0x0001}, {0x8760, 0x0000}, {0x52b5, 0x001f},
-	{0xa760, 0x0000}, {0x0000, 0x0002}, {0xfaff, 0x0001}, {0x8760, 0x0000},
-	{0x52b5, 0x001f}, {0xafae, 0x0000}, {0x0004, 0x0002}, {0x0671, 0x0001},
-	{0x8fae, 0x0000}, {0x2a30, 0x001f}, {0x0012, 0x0008}, {0x0000, 0x001f},
-};
-
-struct {unsigned short value, offset; } CICADA_V2_HWINIT[] = {
-	{0x2a30, 0x001f}, {0x0212, 0x0008}, {0x52b5, 0x001f}, {0x000f, 0x0002},
-	{0x472a, 0x0001}, {0x8fa4, 0x0000}, {0x2a30, 0x001f}, {0x0212, 0x0008},
-	{0x0000, 0x001f},
-};
-
-struct {unsigned short value, offset; } CICADA_V2_ASIX_HWINIT[] = {
-	{0x2a30, 0x001f}, {0x0212, 0x0008}, {0x52b5, 0x001f}, {0x0012, 0x0002},
-	{0x3002, 0x0001}, {0x87fa, 0x0000}, {0x52b5, 0x001f}, {0x000f, 0x0002},
-	{0x472a, 0x0001}, {0x8fa4, 0x0000}, {0x2a30, 0x001f}, {0x0212, 0x0008},
-	{0x0000, 0x001f},
-};
-
-struct {unsigned short value, offset; } AGERE_FAMILY_HWINIT[] = {
-	{0x0800, 0x0000}, {0x0007, 0x0012}, {0x8805, 0x0010}, {0xb03e, 0x0011},
-	{0x8808, 0x0010}, {0xe110, 0x0011}, {0x8806, 0x0010}, {0xb03e, 0x0011},
-	{0x8807, 0x0010}, {0xff00, 0x0011}, {0x880e, 0x0010}, {0xb4d3, 0x0011},
-	{0x880f, 0x0010}, {0xb4d3, 0x0011}, {0x8810, 0x0010}, {0xb4d3, 0x0011},
-	{0x8817, 0x0010}, {0x1c00, 0x0011}, {0x300d, 0x0010}, {0x0001, 0x0011},
-	{0x0002, 0x0012},
-};
-
-struct ax88178_data {
-	u16	EepromData;
-	u16	MediaLink;
-	int	UseGpio0;
-	int	UseRgmii;
-	u8	PhyMode;
-	u8	LedMode;
-	u8	BuffaloOld;
-};
-
-enum watchdog_state {
-	AX_NOP = 0,
-	CHK_LINK,			/* Routine A */
-	CHK_CABLE_EXIST,		/* Called by A */
-	CHK_CABLE_EXIST_AGAIN,		/* Routine B */
-	PHY_POWER_UP,			/* Called by B */
-	PHY_POWER_UP_BH,
-	PHY_POWER_DOWN,
-	CHK_CABLE_STATUS,		/* Routine C */
-	WAIT_AUTONEG_COMPLETE,
-	AX_SET_RX_CFG,
-	AX_CHK_AUTODETACH,
-};
-
-#if 0
-struct ax88772b_data {
-	struct usbnet *dev;
-	struct workqueue_struct *ax_work;
-	struct work_struct check_link;
-	unsigned long time_to_chk;
-	u16 psc;
-	u8 pw_enabled;
-	u8 Event;
-	u8 checksum;
-	u8 PhySelect:1;
-	u8 OperationMode:1;
-	u16 presvd_phy_advertise;
-	u16 presvd_phy_bmcr;
-
-	u32 ext_phy_oui;
-	u8  ext_phy_model;
-};
-#endif
-
-/* define for MAC or PHY mode */
-#define OPERATION_MAC_MODE			0
-#define OPERATION_PHY_MODE			1
-
-#if 0
-struct ax88772a_data {
-	struct usbnet *dev;
-	struct workqueue_struct *ax_work;
-	struct work_struct check_link;
-	unsigned long autoneg_start;
-#define AX88772B_WATCHDOG	(6 * HZ)
-	u8 Event;
-	u8 TickToExpire;
-	u8 DlyIndex;
-	u8 DlySel;
-	u16 EepromData;
-	u16 presvd_phy_advertise;
-	u16 presvd_phy_bmcr;
-};
-
-struct ax88772_data {
-	struct usbnet *dev;
-	struct workqueue_struct *ax_work;
-	struct work_struct check_link;
-	unsigned long autoneg_start;
-	u8 Event;
-	u8 TickToExpire;
-	u16 presvd_phy_advertise;
-	u16 presvd_phy_bmcr;
-};
-#endif
-
-#define AX_RX_CHECKSUM		1
-#define AX_TX_CHECKSUM		2
-
-#if 0
-/* This structure cannot exceed sizeof(unsigned long [5]) AKA 20 bytes */
-struct ax8817x_data {
-	u8 multi_filter[AX_MCAST_FILTER_SIZE];
-	int (*resume) (struct usb_interface *intf);
-	int (*suspend) (struct usb_interface *intf,
-#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 10)
-					pm_message_t message);
-#else
-					u32 message);
-#endif
-};
-#endif
-
-struct ax88172_int_data {
-	u16 res1;
-#define AX_INT_PPLS_LINK		(1 << 0)
-#define AX_INT_SPLS_LINK		(1 << 1)
-#define AX_INT_CABOFF_UNPLUG		(1 << 7)
-	u8 link;
-	u16 res2;
-	u8 status;
-	u16 res3;
-} __attribute__ ((packed));
-
-#define AX_RXHDR_L4_ERR		(1 << 8)
-#define AX_RXHDR_L3_ERR		(1 << 9)
-
-#define AX_RXHDR_L4_TYPE_UDP		1
-#define AX_RXHDR_L4_TYPE_ICMP		2
-#define AX_RXHDR_L4_TYPE_IGMP		3
-#define AX_RXHDR_L4_TYPE_TCP		4
-#define AX_RXHDR_L4_TYPE_TCMPV6	5
-#define AX_RXHDR_L4_TYPE_MASK		7
-
-#define AX_RXHDR_L3_TYPE_IP		1
-#define AX_RXHDR_L3_TYPE_IPV6		2
-
-struct ax88772b_rx_header {
-#if defined(__LITTLE_ENDIAN_BITFIELD)
-	u16	len:11,
-		res1:1,
-		crc:1,
-		mii:1,
-		runt:1,
-		mc_bc:1;
-
-	u16	len_bar:11,
-		res2:5;
-
-	u8	vlan_ind:3,
-		vlan_tag_striped:1,
-		pri:3,
-		res3:1;
-
-	u8	l4_csum_err:1,
-		l3_csum_err:1,
-		l4_type:3,
-		l3_type:2,
-		ce:1;
-#elif defined(__BIG_ENDIAN_BITFIELD)
-	u16	mc_bc:1,
-		runt:1,
-		mii:1,
-		crc:1,
-		res1:1,
-		len:11;
-
-	u16	res2:5,
-		len_bar:11;
-
-	u8	res3:1,
-		pri:3,
-		vlan_tag_striped:1,
-		vlan_ind:3;
-
-	u8	ce:1,
-		l3_type:2,
-		l4_type:3,
-		l3_csum_err:1,
-		l4_csum_err:1;
-#else
-#error	"Please fix <asm/byteorder.h>"
-#endif
-
-} __attribute__ ((packed));
-
-
-#endif /* __LINUX_USBNET_ASIX_H */
-

+ 0 - 1208
class/vendor/asix/axusbnet.c

@@ -1,1208 +0,0 @@
-/*
- * Copyright (c) 2022, aozima
- *
- * SPDX-License-Identifier: Apache-2.0
- */
-/*
- * Change Logs
- * Date           Author       Notes
- * 2022-04-17     aozima       the first version for CherryUSB.
- */
-
-#include <string.h>
-
-#include "usbh_core.h"
-#include "axusbnet.h"
-
-static const char *DEV_FORMAT = "/dev/u%d";
-
-#define USE_RTTHREAD    (1)
-// #define RX_DUMP
-// #define TX_DUMP
-// #define DUMP_RAW
-
-#if USE_RTTHREAD
-#include <rtthread.h>
-
-#include <netif/ethernetif.h>
-#include <netdev.h>
-#endif /* USE_RTTHREAD */
-
-#define MAX_ADDR_LEN            6
-#define ETH_ALEN                MAX_ADDR_LEN
-#define mdelay                  rt_thread_delay
-#define msleep                  rt_thread_delay
-#define deverr(dev, fmt, ...)   USB_LOG_ERR(fmt, ##__VA_ARGS__)
-#define cpu_to_le16(a)          (a)
-#define le32_to_cpus(a)         (a)
-
-/* Generic MII registers. */
-#define MII_BMCR		0x00	/* Basic mode control register */
-#define MII_BMSR		0x01	/* Basic mode status register  */
-#define MII_PHYSID1		0x02	/* PHYS ID 1                   */
-#define MII_PHYSID2		0x03	/* PHYS ID 2                   */
-#define MII_ADVERTISE		0x04	/* Advertisement control reg   */
-#define MII_LPA			0x05	/* Link partner ability reg    */
-#define MII_EXPANSION		0x06	/* Expansion register          */
-#define MII_CTRL1000		0x09	/* 1000BASE-T control          */
-#define MII_STAT1000		0x0a	/* 1000BASE-T status           */
-#define	MII_MMD_CTRL		0x0d	/* MMD Access Control Register */
-#define	MII_MMD_DATA		0x0e	/* MMD Access Data Register */
-#define MII_ESTATUS		0x0f	/* Extended Status             */
-#define MII_DCOUNTER		0x12	/* Disconnect counter          */
-#define MII_FCSCOUNTER		0x13	/* False carrier counter       */
-#define MII_NWAYTEST		0x14	/* N-way auto-neg test reg     */
-#define MII_RERRCOUNTER		0x15	/* Receive error counter       */
-#define MII_SREVISION		0x16	/* Silicon revision            */
-#define MII_RESV1		0x17	/* Reserved...                 */
-#define MII_LBRERROR		0x18	/* Lpback, rx, bypass error    */
-#define MII_PHYADDR		0x19	/* PHY address                 */
-#define MII_RESV2		0x1a	/* Reserved...                 */
-#define MII_TPISTATUS		0x1b	/* TPI status for 10mbps       */
-#define MII_NCONFIG		0x1c	/* Network interface config    */
-
-/* Basic mode control register. */
-#define BMCR_RESV		0x003f	/* Unused...                   */
-#define BMCR_SPEED1000		0x0040	/* MSB of Speed (1000)         */
-#define BMCR_CTST		0x0080	/* Collision test              */
-#define BMCR_FULLDPLX		0x0100	/* Full duplex                 */
-#define BMCR_ANRESTART		0x0200	/* Auto negotiation restart    */
-#define BMCR_ISOLATE		0x0400	/* Isolate data paths from MII */
-#define BMCR_PDOWN		0x0800	/* Enable low power state      */
-#define BMCR_ANENABLE		0x1000	/* Enable auto negotiation     */
-#define BMCR_SPEED100		0x2000	/* Select 100Mbps              */
-#define BMCR_LOOPBACK		0x4000	/* TXD loopback bits           */
-#define BMCR_RESET		0x8000	/* Reset to default state      */
-#define BMCR_SPEED10		0x0000	/* Select 10Mbps               */
-
-/* Advertisement control register. */
-#define ADVERTISE_SLCT		0x001f	/* Selector bits               */
-#define ADVERTISE_CSMA		0x0001	/* Only selector supported     */
-#define ADVERTISE_10HALF	0x0020	/* Try for 10mbps half-duplex  */
-#define ADVERTISE_1000XFULL	0x0020	/* Try for 1000BASE-X full-duplex */
-#define ADVERTISE_10FULL	0x0040	/* Try for 10mbps full-duplex  */
-#define ADVERTISE_1000XHALF	0x0040	/* Try for 1000BASE-X half-duplex */
-#define ADVERTISE_100HALF	0x0080	/* Try for 100mbps half-duplex */
-#define ADVERTISE_1000XPAUSE	0x0080	/* Try for 1000BASE-X pause    */
-#define ADVERTISE_100FULL	0x0100	/* Try for 100mbps full-duplex */
-#define ADVERTISE_1000XPSE_ASYM	0x0100	/* Try for 1000BASE-X asym pause */
-#define ADVERTISE_100BASE4	0x0200	/* Try for 100mbps 4k packets  */
-#define ADVERTISE_PAUSE_CAP	0x0400	/* Try for pause               */
-#define ADVERTISE_PAUSE_ASYM	0x0800	/* Try for asymetric pause     */
-#define ADVERTISE_RESV		0x1000	/* Unused...                   */
-#define ADVERTISE_RFAULT	0x2000	/* Say we can detect faults    */
-#define ADVERTISE_LPACK		0x4000	/* Ack link partners response  */
-#define ADVERTISE_NPAGE		0x8000	/* Next page bit               */
-
-#define ADVERTISE_FULL		(ADVERTISE_100FULL | ADVERTISE_10FULL | \
-				  ADVERTISE_CSMA)
-#define ADVERTISE_ALL		(ADVERTISE_10HALF | ADVERTISE_10FULL | \
-				  ADVERTISE_100HALF | ADVERTISE_100FULL)
-
-struct mii_if_info {
-	int phy_id;
-};
-
-struct usbnet
-{
-#if USE_RTTHREAD
-    /* inherit from ethernet device */
-    struct eth_device parent;
-#endif /* USE_RTTHREAD */
-
-    struct usbh_axusbnet *class;
-
-    uint8_t   dev_addr[MAX_ADDR_LEN];
-
-    uint8_t internalphy:1;
-	uint8_t PhySelect:1;
-	uint8_t OperationMode:1;
-
-	struct mii_if_info	mii;
-};
-typedef struct usbnet * usbnet_t;
-static struct usbnet usbh_axusbnet_eth_device;
-
-#define __is_print(ch) ((unsigned int)((ch) - ' ') < 127u - ' ')
-static void dump_hex(const void *ptr, uint32_t buflen)
-{
-    unsigned char *buf = (unsigned char*)ptr;
-    int i, j;
-
-    for (i=0; i<buflen; i+=16)
-    {
-        printf("%08X:", i);
-
-        for (j=0; j<16; j++)
-            if (i+j < buflen)
-            {
-                if ((j % 8) == 0) {
-                    printf("  ");
-                }
-
-                printf("%02X ", buf[i+j]);
-            }
-            else
-                printf("   ");
-        printf(" ");
-
-        for (j=0; j<16; j++)
-            if (i+j < buflen)
-                printf("%c", __is_print(buf[i+j]) ? buf[i+j] : '.');
-        printf("\n");
-    }
-}
-
-#if defined(RX_DUMP) ||  defined(TX_DUMP)
-static void packet_dump(const char * msg, const struct pbuf* p)
-{
-    rt_uint8_t header[6 + 6 + 2];
-    rt_uint16_t type;
-
-    pbuf_copy_partial(p, header, sizeof(header), 0);
-    type = (header[12] << 8) | header[13];
-
-    rt_kprintf("%02X:%02X:%02X:%02X:%02X:%02X <== %02X:%02X:%02X:%02X:%02X:%02X ",
-               header[0], header[1], header[2], header[3], header[4], header[5],
-               header[6], header[7], header[8], header[9], header[10], header[11]);
-
-    switch (type)
-    {
-    case 0x0800:
-        rt_kprintf("IPv4. ");
-        break;
-
-    case 0x0806:
-        rt_kprintf("ARP.  ");
-        break;
-
-    case 0x86DD:
-        rt_kprintf("IPv6. ");
-        break;
-
-    default:
-        rt_kprintf("%04X. ", type);
-        break;
-    }
-
-    rt_kprintf("%s %d byte. \n", msg, p->tot_len);
-#ifdef DUMP_RAW
-    const struct pbuf* q;
-    rt_uint32_t i,j;
-    rt_uint8_t *ptr;
-
-    // rt_kprintf("%s %d byte\n", msg, p->tot_len);
-
-    i=0;
-    for(q=p; q != RT_NULL; q= q->next)
-    {
-        ptr = q->payload;
-
-        for(j=0; j<q->len; j++)
-        {
-            if( (i%8) == 0 )
-            {
-                rt_kprintf("  ");
-            }
-            if( (i%16) == 0 )
-            {
-                rt_kprintf("\r\n");
-            }
-            rt_kprintf("%02X ", *ptr);
-
-            i++;
-            ptr++;
-        }
-    }
-
-    rt_kprintf("\n\n");
-#endif /* DUMP_RAW */
-}
-#else
-#define packet_dump(...)
-#endif /* dump */
-
-static int ax8817x_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
-			    u16 size, void *data)
-{
-    int ret = 0;
-    struct usbh_hubport *hport = dev->class->hport;
-    struct usb_setup_packet *setup = hport->setup;
-    setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_VENDOR | USB_REQUEST_RECIPIENT_DEVICE;
-    setup->bRequest = cmd;
-    setup->wValue = value;
-    setup->wIndex = index;
-    setup->wLength = size;
-
-    ret = usbh_control_transfer(hport->ep0, setup, (uint8_t *)data);
-    if (ret != 0) {
-        USB_LOG_ERR("%s cmd=%d ret: %d\r\n", __FUNCTION__, cmd, ret);
-        return ret;
-    }
-
-_exit:
-
-    return ret;
-}
-
-static int ax8817x_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
-			     u16 size, void *data)
-{
-    int ret = 0;
-    struct usbh_hubport *hport = dev->class->hport;
-    struct usb_setup_packet *setup = hport->setup;
-    setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_VENDOR | USB_REQUEST_RECIPIENT_DEVICE;
-    setup->bRequest = cmd;
-    setup->wValue = value;
-    setup->wIndex = index;
-    setup->wLength = size;
-
-    ret = usbh_control_transfer(hport->ep0, setup, (uint8_t *)data);
-    if (ret != 0) {
-        USB_LOG_ERR("%s cmd=%d ret: %d\r\n", __FUNCTION__, cmd, ret);
-        return ret;
-    }
-
-_exit:
-
-    return ret;
-}
-
-static int ax8817x_mdio_read(struct usbnet *dev, int phy_id, int loc)
-{
-    // struct usbnet *dev = netdev_priv(netdev);
-    u16 res, ret;
-    u8 smsr;
-    int i = 0;
-
-    // res = kmalloc(2, GFP_ATOMIC);
-    // if (!res)
-    //     return 0;
-
-    do {
-        ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, NULL);
-
-        msleep(1);
-
-        // smsr = (u8 *)&ret;
-        ax8817x_read_cmd(dev, AX_CMD_READ_STATMNGSTS_REG, 0, 0, 1, &smsr);
-    } while (!(smsr & AX_HOST_EN) && (i++ < 30));
-
-    ax8817x_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id, (uint16_t)loc, 2, &res);
-    ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, NULL);
-
-    // ret = *res & 0xffff;
-    // kfree(res);
-
-    return res;
-}
-
-/* same as above, but converts resulting value to cpu byte order */
-static int ax8817x_mdio_read_le(struct usbnet *netdev, int phy_id, int loc)
-{
-	return (ax8817x_mdio_read(netdev, phy_id, loc));
-}
-
-static void
-ax8817x_mdio_write(struct usbnet *dev, int phy_id, int loc, int val)
-{
-	// struct usbnet *dev = netdev_priv(netdev);
-	u16 res;
-	u8 smsr;
-	int i = 0;
-
-	// res = kmalloc(2, GFP_ATOMIC);
-	// if (!res)
-	// 	return;
-	// smsr = (u8 *) res;
-
-	do {
-		ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, NULL);
-
-		msleep(1);
-
-		ax8817x_read_cmd(dev, AX_CMD_READ_STATMNGSTS_REG, 0, 0, 1, &smsr);
-	} while (!(smsr & AX_HOST_EN) && (i++ < 30));
-
-	// *res = val;
-    res = val;
-
-    ax8817x_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id, (uint16_t)loc, 2, &res);
-    ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, NULL);
-
-	// kfree(res);
-}
-
-static void
-ax88772b_mdio_write(struct usbnet *dev, int phy_id, int loc, int val)
-{
-	// struct usbnet *dev = netdev_priv(netdev);
-	u16 res = val;
-
-	// res = kmalloc(2, GFP_ATOMIC);
-	// if (!res)
-	// 	return;
-	// *res = val;
-
-	ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, NULL);
-    ax8817x_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id, (uint16_t)loc, 2, &res);
-
-    if (loc == MII_ADVERTISE) {
-		res = cpu_to_le16(BMCR_ANENABLE | BMCR_ANRESTART);
-		ax8817x_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id, (uint16_t)MII_BMCR, 2, &res);
-	}
-
-	ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, NULL);
-
-	// kfree(res);
-}
-
-/* same as above, but converts new value to le16 byte order before writing */
-static void
-ax8817x_mdio_write_le(struct usbnet *netdev, int phy_id, int loc, int val)
-{
-	ax8817x_mdio_write(netdev, phy_id, loc, cpu_to_le16(val));
-}
-
-static int access_eeprom_mac(struct usbnet *dev, u8 *buf, u8 offset, bool wflag)
-{
-    int ret = 0, i;
-    u16 *tmp = (u16 *)buf;
-
-    if (wflag) {
-        ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_EEPROM_EN,
-                                0, 0, 0, NULL);
-        if (ret < 0)
-            return ret;
-
-        mdelay(15);
-    }
-
-    for (i = 0; i < (ETH_ALEN >> 1); i++) {
-        if (wflag) {
-            // u16 wd = cpu_to_le16(*(tmp + i));
-            u16 wd = (*(tmp + i));
-            ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_EEPROM, offset + i,
-                                    wd, 0, NULL);
-            if (ret < 0)
-                break;
-
-            mdelay(15);
-        } else {
-            ret = ax8817x_read_cmd(dev, AX_CMD_READ_EEPROM,
-                                   offset + i, 0, 2, tmp + i);
-            if (ret < 0)
-                break;
-        }
-    }
-
-    if (!wflag) {
-        if (ret < 0) {
-// #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 34)
-//             netdev_dbg(dev->net, "Failed to read MAC address from EEPROM: %d\n", ret);
-// #else
-//             devdbg(dev, "Failed to read MAC address from EEPROM: %d\n", ret);
-// #endif
-            USB_LOG_ERR("Failed to read MAC address from EEPROM: %d\n", ret);
-            return ret;
-        }
-        // memcpy(dev->net->dev_addr, buf, ETH_ALEN);
-    } else {
-        ax8817x_write_cmd(dev, AX_CMD_WRITE_EEPROM_DIS,
-                          0, 0, 0, NULL);
-        if (ret < 0)
-            return ret;
-
-        /* reload eeprom data */
-        ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_GPIOS,
-                                AXGPIOS_RSE, 0, 0, NULL);
-        if (ret < 0)
-            return ret;
-    }
-
-    return 0;
-}
-
-static int ax88772a_phy_powerup(struct usbnet *dev)
-{
-	int ret;
-	/* set the embedded Ethernet PHY in power-down state */
-	ret = ax8817x_write_cmd(dev, AX_CMD_SW_RESET,
-				AX_SWRESET_IPPD | AX_SWRESET_IPRL, 0, 0, NULL);
-	if (ret < 0) {
-		deverr(dev, "Failed to power down PHY: %d", ret);
-		return ret;
-	}
-
-	msleep(10);
-
-	/* set the embedded Ethernet PHY in power-up state */
-	ret = ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_IPRL,
-				0, 0, NULL);
-	if (ret < 0) {
-		deverr(dev, "Failed to reset PHY: %d", ret);
-		return ret;
-	}
-
-	msleep(600);
-
-	/* set the embedded Ethernet PHY in reset state */
-	ret = ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_CLEAR,
-				0, 0, NULL);
-	if (ret < 0) {
-		deverr(dev, "Failed to power up PHY: %d", ret);
-		return ret;
-	}
-
-	/* set the embedded Ethernet PHY in power-up state */
-	ret = ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_IPRL,
-				0, 0, NULL);
-	if (ret < 0) {
-		deverr(dev, "Failed to reset PHY: %d", ret);
-		return ret;
-	}
-
-	return 0;
-}
-
-static int ax88772b_reset(struct usbnet *dev)
-{
-	int ret;
-
-	ret = ax88772a_phy_powerup(dev);
-	if (ret < 0)
-		return ret;
-
-	/* Set the MAC address */
-    ret = ax8817x_write_cmd(dev, AX88772_CMD_WRITE_NODE_ID,
-                            0, 0, ETH_ALEN, dev->dev_addr);
-    if (ret < 0) {
-        deverr(dev, "set MAC address failed: %d", ret);
-    }
-
-    /* stop MAC operation */
-	ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, AX_RX_CTL_STOP,
-				0, 0, NULL);
-	if (ret < 0){
-		deverr(dev, "Reset RX_CTL failed: %d", ret);
-    }
-
-	ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE,
-				AX88772_MEDIUM_DEFAULT, 0, 0,
-				NULL);
-	if (ret < 0){
-		deverr(dev, "Write medium mode register: %d", ret);
-    }
-
-	return ret;
-}
-
-static int ax8817x_get_mac(struct usbnet *dev, u8 *buf)
-{
-    int ret, i;
-
-    ret = access_eeprom_mac(dev, buf, 0x04, 0);
-    if (ret < 0)
-        goto out;
-
-    // if (ax8817x_check_ether_addr(dev)) {
-    //     ret = access_eeprom_mac(dev, dev->net->dev_addr, 0x04, 1);
-    //     if (ret < 0) {
-    //         deverr(dev, "Failed to write MAC to EEPROM: %d", ret);
-    //         goto out;
-    //     }
-
-    //     msleep(5);
-
-    //     ret = ax8817x_read_cmd(dev, AX88772_CMD_READ_NODE_ID,
-    //                            0, 0, ETH_ALEN, buf);
-    //     if (ret < 0) {
-    //         deverr(dev, "Failed to read MAC address: %d", ret);
-    //         goto out;
-    //     }
-
-    //     for (i = 0; i < ETH_ALEN; i++)
-    //         if (*(dev->net->dev_addr + i) != *((u8 *)buf + i)) {
-    //             devwarn(dev, "Found invalid EEPROM part or non-EEPROM");
-    //             break;
-    //         }
-    // }
-
-    // memcpy(dev->net->perm_addr, dev->net->dev_addr, ETH_ALEN);
-
-    // /* Set the MAC address */
-    // ax8817x_write_cmd(dev, AX88772_CMD_WRITE_NODE_ID, 0, 0,
-    //                   ETH_ALEN, dev->net->dev_addr);
-
-    // if (ret < 0) {
-    //     deverr(dev, "Failed to write MAC address: %d", ret);
-    //     goto out;
-    // }
-
-    return 0;
-out:
-    return ret;
-}
-
-#if USE_RTTHREAD
-static rt_err_t rt_rndis_eth_init(rt_device_t dev)
-{
-    return RT_EOK;
-}
-
-static rt_err_t rt_rndis_eth_open(rt_device_t dev, rt_uint16_t oflag)
-{
-    return RT_EOK;
-}
-
-static rt_err_t rt_rndis_eth_close(rt_device_t dev)
-{
-    return RT_EOK;
-}
-
-static rt_size_t rt_rndis_eth_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t size)
-{
-    rt_set_errno(-RT_ENOSYS);
-    return 0;
-}
-
-static rt_size_t rt_rndis_eth_write (rt_device_t dev, rt_off_t pos, const void* buffer, rt_size_t size)
-{
-    rt_set_errno(-RT_ENOSYS);
-    return 0;
-}
-static rt_err_t rt_rndis_eth_control(rt_device_t dev, int cmd, void *args)
-{
-    usbnet_t rndis_eth_dev = (usbnet_t)dev;
-
-    USB_LOG_INFO("%s L%d\r\n", __FUNCTION__, __LINE__);
-    switch(cmd)
-    {
-    case NIOCTL_GADDR:
-        /* get mac address */
-        if(args)
-        {
-            USB_LOG_INFO("%s L%d NIOCTL_GADDR\r\n", __FUNCTION__, __LINE__);
-            rt_memcpy(args, rndis_eth_dev->dev_addr, MAX_ADDR_LEN);
-        }
-        else
-        {
-            return -RT_ERROR;
-        }
-        break;
-    default :
-        break;
-    }
-
-    return RT_EOK;
-}
-
-/* reception packet. */
-static struct pbuf *rt_rndis_eth_rx(rt_device_t dev)
-{
-    struct pbuf* p = RT_NULL;
-
-    // USB_LOG_INFO("%s L%d\r\n", __FUNCTION__, __LINE__);
-
-    return p;
-}
-
-/* transmit packet. */
-static rt_err_t rt_rndis_eth_tx(rt_device_t dev, struct pbuf* p)
-{
-    int ret = 0;
-    rt_err_t result = RT_EOK;
-    uint8_t *tmp_buf = RT_NULL;
-    usbnet_t rndis_eth = (usbnet_t)dev;
-    struct usbh_axusbnet *class = rndis_eth->class;
-    rt_tick_t tick_start, tick_end;
-    uint8_t int_notify_buf[8];
-
-#ifdef TX_DUMP
-    packet_dump("TX", p);
-#endif /* TX_DUMP */
-
-    tmp_buf = (uint8_t *)rt_malloc(16 + p->tot_len );
-    if (!tmp_buf) {
-        USB_LOG_INFO("[%s L%d], no memory for pbuf, len=%d.", __FUNCTION__, __LINE__, p->tot_len);
-        goto _exit;
-    }
-
-    uint32_t slen = p->tot_len;
-
-    uint32_t head = slen;
-    head = ((head ^ 0x0000ffff) << 16) + (head);
-
-    tmp_buf[0] = head & 0xFF;
-    tmp_buf[1] = (head >> 8) & 0xFF;
-    tmp_buf[2] = (head >> 16) & 0xFF;
-    tmp_buf[3] = (head >> 24) & 0xFF;
-    slen += 4;
-
-    int padlen = ((p->tot_len + 4) % 512) ? 0 : 4;
-    if (padlen) {
-        tmp_buf[4 + slen + 0] = 0x00;
-        tmp_buf[4 + slen + 1] = 0x00;
-        tmp_buf[4 + slen + 2] = 0xFF;
-        tmp_buf[4 + slen + 3] = 0xFF;
-        slen += 4;
-    }
-
-    pbuf_copy_partial(p, tmp_buf + 4, p->tot_len, 0);
-
-    tick_start = rt_tick_get();
-    ret = usbh_ep_bulk_transfer(class->bulkout, tmp_buf, slen, 500);
-    if (ret < 0) {
-        result = -RT_EIO;
-        USB_LOG_ERR("%s L%d send over ret:%d\r\n", __FUNCTION__, __LINE__, ret);
-        goto _exit;
-    }
-    tick_end = rt_tick_get();
-
-_exit:
-    if(tmp_buf)
-    {
-        rt_free(tmp_buf);
-    }
-
-    return result;
-}
-
-#ifdef RT_USING_DEVICE_OPS
-const static struct rt_device_ops rndis_device_ops =
-{
-    rt_rndis_eth_init,
-    rt_rndis_eth_open,
-    rt_rndis_eth_close,
-    rt_rndis_eth_read,
-    rt_rndis_eth_write,
-    rt_rndis_eth_control
-}
-#endif /* RT_USING_DEVICE_OPS */
-#endif /* USE_RTTHREAD */
-
-static void rt_thread_axusbnet_entry(void *parameter)
-{
-    int ret;
-    struct usbh_hubport *hport;
-    uint8_t intf;
-    uint8_t buf[2+8];
-
-    USB_LOG_INFO("%s L%d\r\n", __FUNCTION__, __LINE__);
-    rt_thread_delay(200);
-    USB_LOG_INFO("%s L%d\r\n\r\n\r\n\r\n", __FUNCTION__, __LINE__);
-
-    const char *dname = "/dev/u0";
-    struct usbh_axusbnet *class = (struct usbh_axusbnet *)usbh_find_class_instance(dname);
-    if (class == NULL) {
-        USB_LOG_ERR("do not find %s\r\n", dname);
-        return;
-    }
-    USB_LOG_INFO("axusbnet=%p\r\n", dname);
-
-    usbh_axusbnet_eth_device.class = class;
-
-    struct usbnet *dev = &usbh_axusbnet_eth_device;
-
-	ret = ax8817x_read_cmd(dev, AX_CMD_SW_PHY_STATUS,
-			       0, 0, 1, buf);
-    if (ret < 0) {
-        USB_LOG_ERR("AX_CMD_SW_PHY_STATUS ret=%d\r\n", ret);
-        return;
-    }
-    u8 tempphyselect = buf[0];
-    if (tempphyselect == AX_PHYSEL_SSRMII) {
-        USB_LOG_ERR("%s L%d AX_PHYSEL_SSRMII\r\n", __FUNCTION__, __LINE__);
-        dev->internalphy = false;
-        return;
-        // dev->OperationMode = OPERATION_MAC_MODE;
-        // dev->PhySelect = 0x00;
-    } else if (tempphyselect == AX_PHYSEL_SSRRMII) {
-        USB_LOG_ERR("%s L%d AX_PHYSEL_SSRRMII\r\n", __FUNCTION__, __LINE__);
-        dev->internalphy = true;
-        return;
-        // dev->OperationMode = OPERATION_PHY_MODE;
-        // dev->PhySelect = 0x00;
-    } else if (tempphyselect == AX_PHYSEL_SSMII) {
-        USB_LOG_INFO("%s L%d internalphy AX_PHYSEL_SSMII & OPERATION_MAC_MODE\r\n", __FUNCTION__, __LINE__);
-        dev->internalphy = true;
-        dev->OperationMode = OPERATION_MAC_MODE;
-        dev->PhySelect = 0x01;
-    } else {
-        // deverr(dev, "Unknown MII type\n");
-        USB_LOG_INFO("%s L%d Unknown MII type\r\n", __FUNCTION__, __LINE__);
-        return;
-    }
-
-    /* reload eeprom data */
-	ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_GPIOS, AXGPIOS_RSE, 0, 0, NULL);
-    if (ret < 0) {
-        USB_LOG_ERR("reload eeprom data ret=%d\r\n", ret);
-        return;
-    }
-
-	/* Get the EEPROM data: power saving configuration*/
-	ret = ax8817x_read_cmd(dev, AX_CMD_READ_EEPROM, 0x18, 0, 2, buf);
-	if (ret < 0) {
-		USB_LOG_ERR("read SROM address 18h failed: %d\r\n", ret);
-		goto err_out;
-	}
-    USB_LOG_INFO("reading AX88772C psc: %02x %02x\r\n", buf[0], buf[1]);
-	// le16_to_cpus(tmp16);
-	// ax772b_data->psc = *tmp16 & 0xFF00;
-	/* End of get EEPROM data */
-
-	ret = ax8817x_get_mac(dev, buf);
-	if (ret < 0) {
-		USB_LOG_ERR("Get HW address failed: %d\r\n", ret);
-		return;
-	}
-    dump_hex(buf, ETH_ALEN);
-    memcpy(dev->dev_addr, buf, ETH_ALEN);
-
-    uint16_t chipcode = 0xFFFF;
-    {
-        uint16_t smsr;
-        // asix_read_cmd(dev, AX_CMD_STATMNGSTS_REG, 0, 0, 1, &chipcode, 0);
-        ax8817x_read_cmd(dev, AX_CMD_READ_STATMNGSTS_REG, 0, 0, 1, &chipcode);
-        USB_LOG_ERR("AX_CMD_READ_STATMNGSTS_REG ret: %d %04X\r\n", ret, chipcode);
-
-// #define AX_CHIPCODE_MASK		0x70
-// #define AX_AX88772_CHIPCODE		0x00
-// #define AX_AX88772A_CHIPCODE		0x10
-// #define AX_AX88772B_CHIPCODE		0x20
-// #define AX_HOST_EN			0x01
-
-        chipcode &= 0x70;//AX_CHIPCODE_MASK; AX_AX88772_CHIPCODE
-        if(chipcode == 0x00)
-        {
-            USB_LOG_ERR("AX_CMD_READ_STATMNGSTS_REG AX_AX88772_CHIPCODE\r\n");
-        }
-        else if(chipcode == 0x10)
-        {
-            USB_LOG_ERR("AX_CMD_READ_STATMNGSTS_REG AX_AX88772A_CHIPCODE\r\n");
-        }
-        else if(chipcode == 0x20)
-        {
-            USB_LOG_ERR("AX_CMD_READ_STATMNGSTS_REG AX_AX88772B_CHIPCODE\r\n");
-        }
-    }
-
-    /* Get the PHY id: E0 10 */
-    ret = ax8817x_read_cmd(dev, AX_CMD_READ_PHY_ID, 0, 0, 2, buf);
-    if (ret < 0) {
-        USB_LOG_ERR("Error reading PHY ID: %02x\r\n", ret);
-        return;
-    }
-    if (dev->internalphy) {
-        dev->mii.phy_id = *((u8 *)buf + 1);
-    } else {
-        dev->mii.phy_id = *((u8 *)buf);
-    }
-    USB_LOG_INFO("reading %s PHY ID: %02x\r\n", dev->internalphy?"internal":"external", dev->mii.phy_id);
-
-    ret = ax8817x_write_cmd(dev, AX_CMD_SW_PHY_SELECT, dev->PhySelect, 0, 0, NULL);
-    if (ret < 0) {
-        USB_LOG_ERR("Select PHY #1 failed: %d", ret);
-        return;
-    }
-
-	ret = ax88772a_phy_powerup(dev);
-	if (ret < 0) {
-        USB_LOG_ERR("ax88772a_phy_powerup failed: %d", ret);
-        return;
-    }
-
-	/* stop MAC operation */
-	ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL,
-				AX_RX_CTL_STOP, 0, 0, NULL);
-	if (ret < 0) {
-		USB_LOG_ERR("Reset RX_CTL failed: %d", ret);
-		goto err_out;
-	}
-
-	/* make sure the driver can enable sw mii operation */
-	ret = ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, NULL);
-	if (ret < 0) {
-		USB_LOG_ERR("Enabling software MII failed: %d\r\n", ret);
-		goto err_out;
-	}
-
-    if ((dev->OperationMode == OPERATION_MAC_MODE) &&
-        (dev->PhySelect == 0x00)) {
-        USB_LOG_ERR("not support the external phy\r\n");
-        goto err_out;
-    }
-
-    if (dev->OperationMode == OPERATION_PHY_MODE) {
-        ax8817x_mdio_write_le(dev, dev->mii.phy_id, MII_BMCR, 0x3900);
-    }
-
-    if (dev->mii.phy_id != 0x10)
-    {
-        USB_LOG_ERR("not support phy_id != 0x10\r\n");
-		// ax8817x_mdio_write_le(dev->net, 0x10, MII_BMCR, 0x3900);
-    }
-
-    if (dev->mii.phy_id == 0x10 && dev->OperationMode != OPERATION_PHY_MODE) {
-        u16 tmp16 = ax8817x_mdio_read_le(dev, dev->mii.phy_id, 0x12);
-        ax8817x_mdio_write_le(dev, dev->mii.phy_id, 0x12, ((tmp16 & 0xFF9F) | 0x0040));
-    }
-
-	ax8817x_mdio_write_le(dev, dev->mii.phy_id, MII_ADVERTISE,
-			ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
-
-    // mii_nway_restart(&dev->mii);
-    {
-        /* if autoneg is off, it's an error */
-        uint16_t bmcr = ax8817x_mdio_read_le(dev, dev->mii.phy_id, MII_BMCR);
-        if (bmcr & BMCR_ANENABLE) {
-            bmcr |= BMCR_ANRESTART;
-            USB_LOG_ERR("BMCR_ANENABLE ==> BMCR_ANRESTART\r\n");
-            ax8817x_mdio_write_le(dev, dev->mii.phy_id, MII_BMCR, bmcr);
-        } else
-        {
-            USB_LOG_ERR("not BMCR_ANENABLE BMCR=%04X\r\n", bmcr);
-        }
-    }
-
-    ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, 0, 0, 0, NULL);
-    if (ret < 0) {
-		USB_LOG_ERR("Failed to write medium mode: %d", ret);
-		goto err_out;
-	}
-
-	ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_IPG0,
-			AX88772A_IPG0_DEFAULT | AX88772A_IPG1_DEFAULT << 8,
-			AX88772A_IPG2_DEFAULT, 0, NULL);
-	if (ret < 0) {
-		USB_LOG_ERR("Failed to write interframe gap: %d", ret);
-		goto err_out;
-	}
-
-	memset(buf, 0, 4);
-	ret = ax8817x_read_cmd(dev, AX_CMD_READ_IPG012, 0, 0, 3, buf);
-	*((u8 *)buf + 3) = 0x00;
-	if (ret < 0) {
-		USB_LOG_ERR("Failed to read IPG,IPG1,IPG2 failed: %d", ret);
-		goto err_out;
-	} else {
-		uint32_t tmp32 = *((u32*)buf);
-		le32_to_cpus(&tmp32);
-		if (tmp32 != (AX88772A_IPG2_DEFAULT << 16 |
-			AX88772A_IPG1_DEFAULT << 8 | AX88772A_IPG0_DEFAULT)) {
-			USB_LOG_ERR("Non-authentic ASIX product\nASIX does not support it\n");
-			// ret = -ENODEV;
-			goto err_out;
-		}
-	}
-
-    // TODO: optimized  for high speed.
-    ret = ax8817x_write_cmd(dev, 0x2A, 0x8000, 0x8001, 0, NULL);
-    if (ret < 0) {
-        USB_LOG_ERR("Reset RX_CTL failed: %d", ret);
-        goto err_out;
-    }
-
-    ret = ax88772b_reset(dev);
-    if (ret < 0) {
-        USB_LOG_ERR("ax88772b_reset failed: %d", ret);
-        goto err_out;
-    }
-
-    // OUT 29  0   0 0   AX_CMD_WRITE_MONITOR_MODE
-    ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_MONITOR_MODE, 0, 0, 0, NULL);
-    if (ret < 0) {
-        deverr(dev, "AX_CMD_WRITE_MONITOR_MODE failed: %d", ret);
-    }
-
-	/* Set the MAC address */
-    ret = ax8817x_write_cmd(dev, AX88772_CMD_WRITE_NODE_ID,
-                            0, 0, ETH_ALEN, dev->dev_addr);
-    if (ret < 0) {
-        deverr(dev, "set MAC address failed: %d", ret);
-    }
-
-    // update Multicast AX_CMD_WRITE_MULTI_FILTER.
-    const uint8_t multi_filter[] = {0x00, 0x00, 0x20, 0x80, 0x00, 0x00, 0x00, 0x40};
-    ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_MULTI_FILTER, 0, 0, AX_MCAST_FILTER_SIZE, (void *)multi_filter);
-    if (ret < 0) {
-        USB_LOG_ERR("Reset RX_CTL failed: %d", ret);
-        goto err_out;
-    }
-
-    /* Configure RX header type */
-    // u16 rx_reg = (AX_RX_CTL_PRO | AX_RX_CTL_AMALL | AX_RX_CTL_START | AX_RX_CTL_AB | AX_RX_HEADER_DEFAULT);
-    u16 rx_reg = (AX_RX_CTL_AB | AX_RX_CTL_AM | AX_RX_CTL_START);
-    ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, rx_reg, 0, 0, NULL);
-    if (ret < 0) {
-        USB_LOG_ERR("Reset RX_CTL failed: %d", ret);
-        goto err_out;
-    }
-
-    /* set the embedded Ethernet PHY in power-up state */
-    // ax772b_data->psc = *tmp16 & 0xFF00;
-    // psc: 15 5a AX88772C psc: %02x %02x\r\n", buf[0], buf[1]);
-    ret = ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_IPRL | (0x5a00 & 0x7FFF),
-                            0, 0, NULL);
-    if (ret < 0) {
-        deverr(dev, "Failed to reset PHY: %d", ret);
-        // return ret;
-    }
-
-    rt_thread_delay(1000);
-    u16 mode = AX88772_MEDIUM_DEFAULT;
-    ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL);
-    if (ret < 0) {
-        USB_LOG_ERR("AX_CMD_WRITE_MEDIUM_MODE failed: %d", ret);
-        goto err_out;
-    }
-
-#if USE_RTTHREAD
-#ifdef RT_USING_DEVICE_OPS
-    usbh_axusbnet_eth_device.parent.parent.ops           = &rndis_device_ops;
-#else
-    usbh_axusbnet_eth_device.parent.parent.init          = rt_rndis_eth_init;
-    usbh_axusbnet_eth_device.parent.parent.open          = rt_rndis_eth_open;
-    usbh_axusbnet_eth_device.parent.parent.close         = rt_rndis_eth_close;
-    usbh_axusbnet_eth_device.parent.parent.read          = rt_rndis_eth_read;
-    usbh_axusbnet_eth_device.parent.parent.write         = rt_rndis_eth_write;
-    usbh_axusbnet_eth_device.parent.parent.control       = rt_rndis_eth_control;
-#endif
-    usbh_axusbnet_eth_device.parent.parent.user_data     = RT_NULL;
-
-    usbh_axusbnet_eth_device.parent.eth_rx               = rt_rndis_eth_rx;
-    usbh_axusbnet_eth_device.parent.eth_tx               = rt_rndis_eth_tx;
-
-    usbh_axusbnet_eth_device.class = class;
-
-    eth_device_init(&usbh_axusbnet_eth_device.parent, "u0");
-    eth_device_linkchange(&usbh_axusbnet_eth_device.parent, RT_FALSE);
-#endif /* USE_RTTHREAD */
-    // check link status.
-    {
-        u16 bmcr = ax8817x_mdio_read_le(dev, dev->mii.phy_id, MII_BMCR);
-        u16 mode = AX88772_MEDIUM_DEFAULT;
-
-        USB_LOG_ERR("%s L%d MII_BMCR=%04X\r\n", __FUNCTION__, __LINE__, bmcr);
-		if (!(bmcr & BMCR_FULLDPLX))
-        {
-			mode &= ~AX88772_MEDIUM_FULL_DUPLEX;
-            USB_LOG_ERR("%s L%d not AX88772_MEDIUM_FULL_DUPLEX\r\n", __FUNCTION__, __LINE__);
-        }
-		if (!(bmcr & BMCR_SPEED100))
-        {
-			mode &= ~AX88772_MEDIUM_100MB;
-            USB_LOG_ERR("%s L%d not AX88772_MEDIUM_100MB\r\n", __FUNCTION__, __LINE__);
-        }
-		ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL);
-    }
-
-    while (1)
-    {
-        // USB_LOG_INFO("%s L%d\r\n", __FUNCTION__, __LINE__);
-
-        ret = usbh_ep_bulk_transfer(class->bulkin, class->bulkin_buf, sizeof(class->bulkin_buf), 1000);
-        if (ret < 0) {
-            if (ret != -2) {
-                USB_LOG_ERR("%s L%d bulk in error ret=%d\r\n", __FUNCTION__, __LINE__, ret);
-            }
-            continue;
-        }
-
-        {
-            const uint8_t *data = class->bulkin_buf;
-            uint16_t len1, len2;
-
-            len1 = data[0] | ((uint16_t)(data[1])<<8);
-            len2 = data[2] | ((uint16_t)(data[3])<<8);
-
-            // USB_LOG_INFO("transfer bulkin len1:%04X, len2:%04X, len2':%04X.\r\n", len1, len2, ~len2);
-
-            len1 &= 0x07ff;
-
-            if (data[0] != ((uint8_t)(~data[2]))) {
-                USB_LOG_ERR("transfer bulkin len1:%04X, len2:%04X, len2':%04X.\r\n", len1, len2, ~len2);
-
-                dump_hex(data, 32);
-                continue;
-            }
-
-#if !USE_RTTHREAD
-            {
-                static uint32_t count = 0;
-                USB_LOG_INFO("recv: #%d, len=%d\r\n", count, ret);
-                dump_hex(data+4, 32);
-
-                if ((count % 10) == 0) {
-                    // 192.168.89.14 ==> 255.255.255.255:7 echo hello world!
-                    const uint8_t packet_bytes[] = {
-                        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00,
-                        0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
-                        0x00, 0x36, 0xb0, 0xfd, 0x00, 0x00, 0x80, 0x11,
-                        0x00, 0x00, 0xc0, 0xa8, 0x59, 0x0e, 0xff, 0xff,
-                        0xff, 0xff, 0x00, 0x07, 0x00, 0x07, 0x00, 0x22,
-                        0x53, 0x06, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20,
-                        0x77, 0x6f, 0x72, 0x6c, 0x64, 0x20, 0x66, 0x72,
-                        0x6f, 0x6d, 0x20, 0x41, 0x58, 0x38, 0x38, 0x37,
-                        0x37, 0x32, 0x43, 0x2e
-                    };
-
-                    uint8_t *send_buf = (uint8_t *)class->bulkin_buf;
-                    send_buf[0] = sizeof(packet_bytes);
-                    send_buf[1] = sizeof(packet_bytes) >> 8;
-                    send_buf[2] = ~send_buf[0];
-                    send_buf[3] = ~send_buf[1];
-                    memcpy(send_buf+4, packet_bytes, sizeof(packet_bytes));
-                    memcpy(send_buf+4+6, dev->dev_addr, 6);// update src mac.
-
-                    ret = usbh_ep_bulk_transfer(class->bulkout, send_buf, 4 + sizeof(packet_bytes), 500);
-                    USB_LOG_INFO("bulkout, ret=%d\r\n", ret);
-                    dump_hex(send_buf, 64);
-                }
-
-                count++;
-            }
-#endif /* RT-Thread */
-
-#if USE_RTTHREAD
-            {
-                static uint32_t count = 0;
-
-                if (count == 0) {
-                    eth_device_linkchange(&usbh_axusbnet_eth_device.parent, RT_TRUE);
-                }
-
-                count++;
-            }
-
-            /* allocate buffer */
-            struct pbuf *p = RT_NULL;
-            p = pbuf_alloc(PBUF_LINK, len1, PBUF_RAM);
-            if (p != NULL) {
-                pbuf_take(p, data + 4, len1);
-
-#ifdef RX_DUMP
-                packet_dump("RX", p);
-#endif /* RX_DUMP */
-                struct eth_device *eth_dev = &usbh_axusbnet_eth_device.parent;
-                if ((eth_dev->netif->input(p, eth_dev->netif)) != ERR_OK) {
-                    USB_LOG_INFO("F:%s L:%d IP input error\r\n", __FUNCTION__, __LINE__);
-                    pbuf_free(p);
-                    p = RT_NULL;
-                }
-                // USB_LOG_INFO("%s L%d input OK\r\n", __FUNCTION__, __LINE__);
-            } else {
-                USB_LOG_ERR("%s L%d pbuf_alloc NULL\r\n", __FUNCTION__, __LINE__);
-            }
-#endif /* RT-Thread */
-        }
-    } // while (1)
-
-err_out:
-out2:
-
-    return;
-}
-
-static int axusbnet_startup(void)
-{
-    const char *tname = "axusbnet";
-    usb_osal_thread_t usb_thread;
-
-    usb_thread = usb_osal_thread_create(tname, 1024 * 6, CONFIG_USBHOST_PSC_PRIO, rt_thread_axusbnet_entry, NULL);
-    if (usb_thread == NULL) {
-        return -1;
-    }
-
-    return 0;
-}
-
-static int usbh_axusbnet_connect(struct usbh_hubport *hport, uint8_t intf)
-{
-    int ret = 0;
-    struct usbh_endpoint_cfg ep_cfg = { 0 };
-    struct usb_endpoint_descriptor *ep_desc;
-
-    USB_LOG_INFO("%s %d\r\n", __FUNCTION__, __LINE__);
-
-    struct usbh_axusbnet *class = usb_malloc(sizeof(struct usbh_axusbnet));
-    if (class == NULL)
-    {
-        USB_LOG_ERR("Fail to alloc class\r\n");
-        return -ENOMEM;
-    }
-    memset(class, 0, sizeof(struct usbh_axusbnet));
-    class->hport = hport;
-
-    class->intf = intf;
-
-    snprintf(hport->config.intf[intf].devname, CONFIG_USBHOST_DEV_NAMELEN, DEV_FORMAT, intf);
-    USB_LOG_INFO("Register axusbnet Class:%s\r\n", hport->config.intf[intf].devname);
-    hport->config.intf[intf].priv = class;
-
-#if 1
-    USB_LOG_INFO("hport=%p, intf=%d, intf_desc.bNumEndpoints:%d\r\n", hport, intf, hport->config.intf[intf].intf_desc.bNumEndpoints);
-    for (uint8_t i = 0; i < hport->config.intf[intf].intf_desc.bNumEndpoints; i++)
-    {
-        ep_desc = &hport->config.intf[intf].ep[i].ep_desc;
-
-        USB_LOG_INFO("ep[%d] bLength=%d, type=%d\r\n", i, ep_desc->bLength, ep_desc->bDescriptorType);
-        USB_LOG_INFO("ep_addr=%02X, attr=%02X\r\n", ep_desc->bEndpointAddress, ep_desc->bmAttributes & USB_ENDPOINT_TYPE_MASK);
-        USB_LOG_INFO("wMaxPacketSize=%d, bInterval=%d\r\n\r\n", ep_desc->wMaxPacketSize, ep_desc->bInterval);
-    }
-#endif
-
-    for (uint8_t i = 0; i < hport->config.intf[intf].intf_desc.bNumEndpoints; i++)
-    {
-        ep_desc = &hport->config.intf[intf].ep[i].ep_desc;
-
-        ep_cfg.ep_addr = ep_desc->bEndpointAddress;
-        ep_cfg.ep_type = ep_desc->bmAttributes & USB_ENDPOINT_TYPE_MASK;
-        ep_cfg.ep_mps = ep_desc->wMaxPacketSize;
-        ep_cfg.ep_interval = ep_desc->bInterval;
-        ep_cfg.hport = hport;
-
-        if(ep_cfg.ep_type == USB_ENDPOINT_TYPE_BULK)
-        {
-            if (ep_desc->bEndpointAddress & 0x80) {
-                usbh_pipe_alloc(&class->bulkin, &ep_cfg);
-            } else {
-                usbh_pipe_alloc(&class->bulkout, &ep_cfg);
-            }
-        }
-        else
-        {
-            usbh_pipe_alloc(&class->int_notify, &ep_cfg);
-        }
-    }
-
-    axusbnet_startup();
-
-    return ret;
-}
-
-static int usbh_axusbnet_disconnect(struct usbh_hubport *hport, uint8_t intf)
-{
-    int ret = 0;
-
-    USB_LOG_ERR("TBD: %s %d\r\n", __FUNCTION__, __LINE__);
-    return ret;
-}
-
-// Class:0xff,Subclass:0xff,Protocl:0x00
-static const struct usbh_class_driver axusbnet_class_driver = {
-    .driver_name = "axusbnet",
-    .connect = usbh_axusbnet_connect,
-    .disconnect = usbh_axusbnet_disconnect
-};
-
-CLASS_INFO_DEFINE const struct usbh_class_info axusbnet_class_info = {
-    .match_flags = USB_CLASS_MATCH_VENDOR | USB_CLASS_MATCH_PRODUCT | USB_CLASS_MATCH_INTF_CLASS | USB_CLASS_MATCH_INTF_SUBCLASS | USB_CLASS_MATCH_INTF_PROTOCOL,
-    .class = USB_DEVICE_CLASS_VEND_SPECIFIC,
-    .subclass = 0xff,
-    .protocol = 0x00,
-    .vid = 0x0b95,
-    .pid = 0x772b,
-    .class_driver = &axusbnet_class_driver
-};

+ 0 - 30
class/vendor/asix/axusbnet.h

@@ -1,30 +0,0 @@
-/*
- * Copyright (c) 2022, aozima
- *
- * SPDX-License-Identifier: Apache-2.0
- */
-/*
- * Change Logs
- * Date           Author       Notes
- * 2022-04-17     aozima       the first version for CherryUSB.
- */
-
-#ifndef __USB_CLASHH_AXUSBNET_H__
-#define __USB_CLASHH_AXUSBNET_H__
-
-#include "usbh_core.h"
-#include "asix.h"
-
-struct usbh_axusbnet {
-    struct usbh_hubport *hport;
-
-    uint8_t intf; /* interface number */
-
-    usbh_pipe_t int_notify; /* Notify endpoint */
-    usbh_pipe_t bulkin;  /* Bulk IN endpoint */
-    usbh_pipe_t bulkout; /* Bulk OUT endpoint */
-
-    uint32_t bulkin_buf[2048/sizeof(uint32_t)];
-};
-
-#endif /* __USB_CLASHH_AXUSBNET_H__ */

+ 0 - 1763
class/vendor/cp201x/usbh_cp210x.c

@@ -1,1763 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/*
- * Silicon Laboratories CP210x USB to RS232 serial adaptor driver
- *
- * Copyright (C) 2005 Craig Shelley (craig@microtron.org.uk)
- *
- * Support to set flow control line levels using TIOCMGET and TIOCMSET
- * thanks to Karl Hiramoto karl@hiramoto.org. RTSCTS hardware flow
- * control thanks to Munir Nassar nassarmu@real-time.com
- *
- */
-
-#include <stdint.h>
-#include <stdlib.h>
-
-#include <string.h>
-#include <limits.h>
-
-#include "usbh_cp210x.h"
-
-#define u16 uint16_t
-#define u32 uint32_t
-#define u8  uint8_t
-
-#ifndef container_of
-#define container_of(p, t, m) \
-    ((t *)((char *)p - (char *)(&(((t *)0)->m))))
-#endif
-
-#define dev_dbg(...)  do {} while (0)
-#define dev_err  USB_LOG_ERR
-#define dev_warn USB_LOG_WRN
-
-#warning FIXME: le32_to_cpu
-#define le32_to_cpu(le32_val) (le32_val)
-#define le16_to_cpu(v) (v)
-#define cpu_to_le32(v) (v)
-	
-
-#define USB_CTRL_SET_TIMEOUT 1
-#define USB_CTRL_GET_TIMEOUT 1
-
-#define TIOCSTI    0x5412
-#define TIOCMGET   0x5415
-#define TIOCMBIS   0x5416
-#define TIOCMBIC   0x5417
-#define TIOCMSET   0x5418
-#define TIOCM_LE   0x001
-#define TIOCM_DTR  0x002
-#define TIOCM_RTS  0x004
-#define TIOCM_ST   0x008
-#define TIOCM_SR   0x010
-#define TIOCM_CTS  0x020
-#define TIOCM_CAR  0x040
-#define TIOCM_RNG  0x080
-#define TIOCM_DSR  0x100
-#define TIOCM_CD   TIOCM_CAR
-#define TIOCM_RI   TIOCM_RNG
-#define TIOCM_OUT1 0x2000
-#define TIOCM_OUT2 0x4000
-#define TIOCM_LOOP 0x8000
-
-/* c_cc characters */
-#define VEOF     0
-#define VEOL     1
-#define VEOL2    2
-#define VERASE   3
-#define VWERASE  4
-#define VKILL    5
-#define VREPRINT 6
-#define VSWTC    7
-#define VINTR    8
-#define VQUIT    9
-#define VSUSP    10
-#define VSTART   12
-#define VSTOP    13
-#define VLNEXT   14
-#define VDISCARD 15
-#define VMIN     16
-#define VTIME    17
-
-/* c_iflag bits */
-#define IGNBRK  0000001
-#define BRKINT  0000002
-#define IGNPAR  0000004
-#define PARMRK  0000010
-#define INPCK   0000020
-#define ISTRIP  0000040
-#define INLCR   0000100
-#define IGNCR   0000200
-#define ICRNL   0000400
-#define IXON    0001000
-#define IXOFF   0002000
-#define IXANY   0004000
-#define IUCLC   0010000
-#define IMAXBEL 0020000
-#define IUTF8   0040000
-
-/* c_oflag bits */
-#define OPOST 0000001
-#define ONLCR 0000002
-#define OLCUC 0000004
-
-#define OCRNL  0000010
-#define ONOCR  0000020
-#define ONLRET 0000040
-
-#define OFILL  00000100
-#define OFDEL  00000200
-#define NLDLY  00001400
-#define NL0    00000000
-#define NL1    00000400
-#define NL2    00001000
-#define NL3    00001400
-#define TABDLY 00006000
-#define TAB0   00000000
-#define TAB1   00002000
-#define TAB2   00004000
-#define TAB3   00006000
-#define CRDLY  00030000
-#define CR0    00000000
-#define CR1    00010000
-#define CR2    00020000
-#define CR3    00030000
-#define FFDLY  00040000
-#define FF0    00000000
-#define FF1    00040000
-#define BSDLY  00100000
-#define BS0    00000000
-#define BS1    00100000
-#define VTDLY  00200000
-#define VT0    00000000
-#define VT1    00200000
-/*
- * Should be equivalent to TAB3, see description of TAB3 in
- * POSIX.1-2008, Ch. 11.2.3 "Output Modes"
- */
-#define XTABS TAB3
-
-/* c_cflag bit meaning */
-#define CBAUD    0000037
-#define B0       0000000 /* hang up */
-#define B50      0000001
-#define B75      0000002
-#define B110     0000003
-#define B134     0000004
-#define B150     0000005
-#define B200     0000006
-#define B300     0000007
-#define B600     0000010
-#define B1200    0000011
-#define B1800    0000012
-#define B2400    0000013
-#define B4800    0000014
-#define B9600    0000015
-#define B19200   0000016
-#define B38400   0000017
-#define EXTA     B19200
-#define EXTB     B38400
-#define CBAUDEX  0000000
-#define B57600   00020
-#define B115200  00021
-#define B230400  00022
-#define B460800  00023
-#define B500000  00024
-#define B576000  00025
-#define B921600  00026
-#define B1000000 00027
-#define B1152000 00030
-#define B1500000 00031
-#define B2000000 00032
-#define B2500000 00033
-#define B3000000 00034
-#define B3500000 00035
-#define B4000000 00036
-#define BOTHER   00037
-
-#define CSIZE 00001400
-#define CS5   00000000
-#define CS6   00000400
-#define CS7   00001000
-#define CS8   00001400
-
-#define CSTOPB 00002000
-#define CREAD  00004000
-#define PARENB 00010000
-#define PARODD 00020000
-#define HUPCL  00040000
-
-#define CLOCAL  00100000
-#define CMSPAR  010000000000 /* mark or space (stick) parity */
-#define CRTSCTS 020000000000 /* flow control */
-
-#define CIBAUD  07600000
-#define IBSHIFT 16
-
-/* c_lflag bits */
-#define ISIG    0x00000080
-#define ICANON  0x00000100
-#define XCASE   0x00004000
-#define ECHO    0x00000008
-#define ECHOE   0x00000002
-#define ECHOK   0x00000004
-#define ECHONL  0x00000010
-#define NOFLSH  0x80000000
-#define TOSTOP  0x00400000
-#define ECHOCTL 0x00000040
-#define ECHOPRT 0x00000020
-#define ECHOKE  0x00000001
-#define FLUSHO  0x00800000
-#define PENDIN  0x20000000
-#define IEXTEN  0x00000400
-#define EXTPROC 0x10000000
-
-/* Values for the ACTION argument to `tcflow'.  */
-#define TCOOFF 0
-#define TCOON  1
-#define TCIOFF 2
-#define TCION  3
-
-/* Values for the QUEUE_SELECTOR argument to `tcflush'.  */
-#define TCIFLUSH  0
-#define TCOFLUSH  1
-#define TCIOFLUSH 2
-
-/* Values for the OPTIONAL_ACTIONS argument to `tcsetattr'.  */
-#define TCSANOW   0
-#define TCSADRAIN 1
-#define TCSAFLUSH 2
-
-/* c_cc characters */
-#define VEOF     0
-#define VEOL     1
-#define VEOL2    2
-#define VERASE   3
-#define VWERASE  4
-#define VKILL    5
-#define VREPRINT 6
-#define VSWTC    7
-#define VINTR    8
-#define VQUIT    9
-#define VSUSP    10
-#define VSTART   12
-#define VSTOP    13
-#define VLNEXT   14
-#define VDISCARD 15
-#define VMIN     16
-#define VTIME    17
-
-/* c_iflag bits */
-#define IGNBRK  0000001
-#define BRKINT  0000002
-#define IGNPAR  0000004
-#define PARMRK  0000010
-#define INPCK   0000020
-#define ISTRIP  0000040
-#define INLCR   0000100
-#define IGNCR   0000200
-#define ICRNL   0000400
-#define IXON    0001000
-#define IXOFF   0002000
-#define IXANY   0004000
-#define IUCLC   0010000
-#define IMAXBEL 0020000
-#define IUTF8   0040000
-
-/* c_oflag bits */
-#define OPOST 0000001
-#define ONLCR 0000002
-#define OLCUC 0000004
-
-#define OCRNL  0000010
-#define ONOCR  0000020
-#define ONLRET 0000040
-
-#define OFILL  00000100
-#define OFDEL  00000200
-#define NLDLY  00001400
-#define NL0    00000000
-#define NL1    00000400
-#define NL2    00001000
-#define NL3    00001400
-#define TABDLY 00006000
-#define TAB0   00000000
-#define TAB1   00002000
-#define TAB2   00004000
-#define TAB3   00006000
-#define CRDLY  00030000
-#define CR0    00000000
-#define CR1    00010000
-#define CR2    00020000
-#define CR3    00030000
-#define FFDLY  00040000
-#define FF0    00000000
-#define FF1    00040000
-#define BSDLY  00100000
-#define BS0    00000000
-#define BS1    00100000
-#define VTDLY  00200000
-#define VT0    00000000
-#define VT1    00200000
-/*
- * Should be equivalent to TAB3, see description of TAB3 in
- * POSIX.1-2008, Ch. 11.2.3 "Output Modes"
- */
-#define XTABS TAB3
-
-/* c_cflag bit meaning */
-#define CBAUD    0000037
-#define B0       0000000 /* hang up */
-#define B50      0000001
-#define B75      0000002
-#define B110     0000003
-#define B134     0000004
-#define B150     0000005
-#define B200     0000006
-#define B300     0000007
-#define B600     0000010
-#define B1200    0000011
-#define B1800    0000012
-#define B2400    0000013
-#define B4800    0000014
-#define B9600    0000015
-#define B19200   0000016
-#define B38400   0000017
-#define EXTA     B19200
-#define EXTB     B38400
-#define CBAUDEX  0000000
-#define B57600   00020
-#define B115200  00021
-#define B230400  00022
-#define B460800  00023
-#define B500000  00024
-#define B576000  00025
-#define B921600  00026
-#define B1000000 00027
-#define B1152000 00030
-#define B1500000 00031
-#define B2000000 00032
-#define B2500000 00033
-#define B3000000 00034
-#define B3500000 00035
-#define B4000000 00036
-#define BOTHER   00037
-
-#define CSIZE 00001400
-#define CS5   00000000
-#define CS6   00000400
-#define CS7   00001000
-#define CS8   00001400
-
-#define CSTOPB 00002000
-#define CREAD  00004000
-#define PARENB 00010000
-#define PARODD 00020000
-#define HUPCL  00040000
-
-#define CLOCAL  00100000
-#define CMSPAR  010000000000 /* mark or space (stick) parity */
-#define CRTSCTS 020000000000 /* flow control */
-
-#define CIBAUD  07600000
-#define IBSHIFT 16
-
-/* c_lflag bits */
-#define ISIG    0x00000080
-#define ICANON  0x00000100
-#define XCASE   0x00004000
-#define ECHO    0x00000008
-#define ECHOE   0x00000002
-#define ECHOK   0x00000004
-#define ECHONL  0x00000010
-#define NOFLSH  0x80000000
-#define TOSTOP  0x00400000
-#define ECHOCTL 0x00000040
-#define ECHOPRT 0x00000020
-#define ECHOKE  0x00000001
-#define FLUSHO  0x00800000
-#define PENDIN  0x20000000
-#define IEXTEN  0x00000400
-#define EXTPROC 0x10000000
-
-/* Values for the ACTION argument to `tcflow'.  */
-#define TCOOFF 0
-#define TCOON  1
-#define TCIOFF 2
-#define TCION  3
-
-/* Values for the QUEUE_SELECTOR argument to `tcflush'.  */
-#define TCIFLUSH  0
-#define TCOFLUSH  1
-#define TCIOFLUSH 2
-
-/* Values for the OPTIONAL_ACTIONS argument to `tcsetattr'.  */
-#define TCSANOW   0
-#define TCSADRAIN 1
-#define TCSAFLUSH 2
-
-/* c_cc characters */
-#define VEOF     0
-#define VEOL     1
-#define VEOL2    2
-#define VERASE   3
-#define VWERASE  4
-#define VKILL    5
-#define VREPRINT 6
-#define VSWTC    7
-#define VINTR    8
-#define VQUIT    9
-#define VSUSP    10
-#define VSTART   12
-#define VSTOP    13
-#define VLNEXT   14
-#define VDISCARD 15
-#define VMIN     16
-#define VTIME    17
-
-/* c_iflag bits */
-#define IGNBRK  0000001
-#define BRKINT  0000002
-#define IGNPAR  0000004
-#define PARMRK  0000010
-#define INPCK   0000020
-#define ISTRIP  0000040
-#define INLCR   0000100
-#define IGNCR   0000200
-#define ICRNL   0000400
-#define IXON    0001000
-#define IXOFF   0002000
-#define IXANY   0004000
-#define IUCLC   0010000
-#define IMAXBEL 0020000
-#define IUTF8   0040000
-
-/* c_oflag bits */
-#define OPOST 0000001
-#define ONLCR 0000002
-#define OLCUC 0000004
-
-#define OCRNL  0000010
-#define ONOCR  0000020
-#define ONLRET 0000040
-
-#define OFILL  00000100
-#define OFDEL  00000200
-#define NLDLY  00001400
-#define NL0    00000000
-#define NL1    00000400
-#define NL2    00001000
-#define NL3    00001400
-#define TABDLY 00006000
-#define TAB0   00000000
-#define TAB1   00002000
-#define TAB2   00004000
-#define TAB3   00006000
-#define CRDLY  00030000
-#define CR0    00000000
-#define CR1    00010000
-#define CR2    00020000
-#define CR3    00030000
-#define FFDLY  00040000
-#define FF0    00000000
-#define FF1    00040000
-#define BSDLY  00100000
-#define BS0    00000000
-#define BS1    00100000
-#define VTDLY  00200000
-#define VT0    00000000
-#define VT1    00200000
-/*
- * Should be equivalent to TAB3, see description of TAB3 in
- * POSIX.1-2008, Ch. 11.2.3 "Output Modes"
- */
-#define XTABS TAB3
-
-/* c_cflag bit meaning */
-#define CBAUD    0000037
-#define B0       0000000 /* hang up */
-#define B50      0000001
-#define B75      0000002
-#define B110     0000003
-#define B134     0000004
-#define B150     0000005
-#define B200     0000006
-#define B300     0000007
-#define B600     0000010
-#define B1200    0000011
-#define B1800    0000012
-#define B2400    0000013
-#define B4800    0000014
-#define B9600    0000015
-#define B19200   0000016
-#define B38400   0000017
-#define EXTA     B19200
-#define EXTB     B38400
-#define CBAUDEX  0000000
-#define B57600   00020
-#define B115200  00021
-#define B230400  00022
-#define B460800  00023
-#define B500000  00024
-#define B576000  00025
-#define B921600  00026
-#define B1000000 00027
-#define B1152000 00030
-#define B1500000 00031
-#define B2000000 00032
-#define B2500000 00033
-#define B3000000 00034
-#define B3500000 00035
-#define B4000000 00036
-#define BOTHER   00037
-
-#define CSIZE 00001400
-#define CS5   00000000
-#define CS6   00000400
-#define CS7   00001000
-#define CS8   00001400
-
-#define CSTOPB 00002000
-#define CREAD  00004000
-#define PARENB 00010000
-#define PARODD 00020000
-#define HUPCL  00040000
-
-#define CLOCAL  00100000
-#define CMSPAR  010000000000 /* mark or space (stick) parity */
-#define CRTSCTS 020000000000 /* flow control */
-
-#define CIBAUD  07600000
-#define IBSHIFT 16
-
-/* c_lflag bits */
-#define ISIG    0x00000080
-#define ICANON  0x00000100
-#define XCASE   0x00004000
-#define ECHO    0x00000008
-#define ECHOE   0x00000002
-#define ECHOK   0x00000004
-#define ECHONL  0x00000010
-#define NOFLSH  0x80000000
-#define TOSTOP  0x00400000
-#define ECHOCTL 0x00000040
-#define ECHOPRT 0x00000020
-#define ECHOKE  0x00000001
-#define FLUSHO  0x00800000
-#define PENDIN  0x20000000
-#define IEXTEN  0x00000400
-#define EXTPROC 0x10000000
-
-/* Values for the ACTION argument to `tcflow'.  */
-#define TCOOFF 0
-#define TCOON  1
-#define TCIOFF 2
-#define TCION  3
-
-/* Values for the QUEUE_SELECTOR argument to `tcflush'.  */
-#define TCIFLUSH  0
-#define TCOFLUSH  1
-#define TCIOFLUSH 2
-
-/* Values for the OPTIONAL_ACTIONS argument to `tcsetattr'.  */
-#define TCSANOW   0
-#define TCSADRAIN 1
-#define TCSAFLUSH 2
-
-#define __packed
-
-#undef ARRAY_SIZE
-#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
-
-#define min(a, b) ((a) < (b) ? (a) : (b))
-#define max(a, b) ((a) > (b) ? (a) : (b))
-
-#define clamp(val, lo, hi) min(max(val, lo), hi)
-
-#define BITS_PER_LONG 32
-
-#define GENMASK(h, l) \
-    (((~0UL) - (1UL << (l)) + 1) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
-
-#define DIV_ROUND_CLOSEST(x, d) (((x) + ((d) / 2)) / (d))
-
-#define true           1
-#define false          0
-
-static uint16_t swab16(uint16_t v)
-{
-    return ((v & 0xff) << 8) | ((v & 0xff00) >> 8);
-}
-
-int usb_rcvctrlpipe(struct usb_serial_port *port, int useless)
-{
-    return port->ctrlpipe_rx;
-}
-int usb_sndctrlpipe(struct usb_serial_port *port, int useless)
-{
-    return port->ctrlpipe_tx;
-}
-
-void cp210x_get_termios(struct tty_struct *tty);
-void cp210x_change_speed(struct tty_struct *tty);
-
-void cp210x_get_termios(struct tty_struct *tty);
-void cp210x_get_termios_port(struct usb_serial_port *port, tcflag_t *cflagp, unsigned int *baudp);
-
-int usb_control_msg(struct usb_serial_port *port, int pipe, int req, u8 type, u16 val, u8 interface_num, void *dmabuf, int bufsize, int flags);
-
-/* Config request types */
-#define REQTYPE_HOST_TO_INTERFACE 0x41
-#define REQTYPE_INTERFACE_TO_HOST 0xc1
-#define REQTYPE_HOST_TO_DEVICE    0x40
-#define REQTYPE_DEVICE_TO_HOST    0xc0
-
-/* Config request codes */
-#define CP210X_IFC_ENABLE      0x00
-#define CP210X_SET_BAUDDIV     0x01
-#define CP210X_GET_BAUDDIV     0x02
-#define CP210X_SET_LINE_CTL    0x03
-#define CP210X_GET_LINE_CTL    0x04
-#define CP210X_SET_BREAK       0x05
-#define CP210X_IMM_CHAR        0x06
-#define CP210X_SET_MHS         0x07
-#define CP210X_GET_MDMSTS      0x08
-#define CP210X_SET_XON         0x09
-#define CP210X_SET_XOFF        0x0A
-#define CP210X_SET_EVENTMASK   0x0B
-#define CP210X_GET_EVENTMASK   0x0C
-#define CP210X_SET_CHAR        0x0D
-#define CP210X_GET_CHARS       0x0E
-#define CP210X_GET_PROPS       0x0F
-#define CP210X_GET_COMM_STATUS 0x10
-#define CP210X_RESET           0x11
-#define CP210X_PURGE           0x12
-#define CP210X_SET_FLOW        0x13
-#define CP210X_GET_FLOW        0x14
-#define CP210X_EMBED_EVENTS    0x15
-#define CP210X_GET_EVENTSTATE  0x16
-#define CP210X_SET_CHARS       0x19
-#define CP210X_GET_BAUDRATE    0x1D
-#define CP210X_SET_BAUDRATE    0x1E
-#define CP210X_VENDOR_SPECIFIC 0xFF
-
-/* CP210X_IFC_ENABLE */
-#define UART_ENABLE  0x0001
-#define UART_DISABLE 0x0000
-
-/* CP210X_(SET|GET)_BAUDDIV */
-#define BAUD_RATE_GEN_FREQ 0x384000
-
-/* CP210X_(SET|GET)_LINE_CTL */
-#define BITS_DATA_MASK 0X0f00
-#define BITS_DATA_5    0X0500
-#define BITS_DATA_6    0X0600
-#define BITS_DATA_7    0X0700
-#define BITS_DATA_8    0X0800
-#define BITS_DATA_9    0X0900
-
-#define BITS_PARITY_MASK  0x00f0
-#define BITS_PARITY_NONE  0x0000
-#define BITS_PARITY_ODD   0x0010
-#define BITS_PARITY_EVEN  0x0020
-#define BITS_PARITY_MARK  0x0030
-#define BITS_PARITY_SPACE 0x0040
-
-#define BITS_STOP_MASK 0x000f
-#define BITS_STOP_1    0x0000
-#define BITS_STOP_1_5  0x0001
-#define BITS_STOP_2    0x0002
-
-/* CP210X_SET_BREAK */
-#define BREAK_ON  0x0001
-#define BREAK_OFF 0x0000
-
-/* CP210X_(SET_MHS|GET_MDMSTS) */
-#define CONTROL_DTR       0x0001
-#define CONTROL_RTS       0x0002
-#define CONTROL_CTS       0x0010
-#define CONTROL_DSR       0x0020
-#define CONTROL_RING      0x0040
-#define CONTROL_DCD       0x0080
-#define CONTROL_WRITE_DTR 0x0100
-#define CONTROL_WRITE_RTS 0x0200
-
-/* CP210X_VENDOR_SPECIFIC values */
-#define CP210X_READ_2NCONFIG  0x000E
-#define CP210X_READ_LATCH     0x00C2
-#define CP210X_GET_PARTNUM    0x370B
-#define CP210X_GET_PORTCONFIG 0x370C
-#define CP210X_GET_DEVICEMODE 0x3711
-#define CP210X_WRITE_LATCH    0x37E1
-
-/* Part number definitions */
-#define CP210X_PARTNUM_CP2101        0x01
-#define CP210X_PARTNUM_CP2102        0x02
-#define CP210X_PARTNUM_CP2103        0x03
-#define CP210X_PARTNUM_CP2104        0x04
-#define CP210X_PARTNUM_CP2105        0x05
-#define CP210X_PARTNUM_CP2108        0x08
-#define CP210X_PARTNUM_CP2102N_QFN28 0x20
-#define CP210X_PARTNUM_CP2102N_QFN24 0x21
-#define CP210X_PARTNUM_CP2102N_QFN20 0x22
-#define CP210X_PARTNUM_UNKNOWN       0xFF
-
-#define __le32 int32_t
-/* CP210X_GET_COMM_STATUS returns these 0x13 bytes */
-struct cp210x_comm_status {
-    __le32 ulErrors;
-    __le32 ulHoldReasons;
-    __le32 ulAmountInInQueue;
-    __le32 ulAmountInOutQueue;
-    u8 bEofReceived;
-    u8 bWaitForImmediate;
-    u8 bReserved;
-} __packed;
-
-/*
- * CP210X_PURGE - 16 bits passed in wValue of USB request.
- * SiLabs app note AN571 gives a strange description of the 4 bits:
- * bit 0 or bit 2 clears the transmit queue and 1 or 3 receive.
- * writing 1 to all, however, purges cp2108 well enough to avoid the hang.
- */
-#define PURGE_ALL 0x000f
-
-/* CP210X_GET_FLOW/CP210X_SET_FLOW read/write these 0x10 bytes */
-struct cp210x_flow_ctl {
-    __le32 ulControlHandshake;
-    __le32 ulFlowReplace;
-    __le32 ulXonLimit;
-    __le32 ulXoffLimit;
-} __packed;
-
-#undef BIT
-#undef BIT_ULL
-#undef BIT_MASK
-#undef BIT_WORD
-#undef BIT_ULL_MASK
-#undef BITS_PER_BYTE
-#define BIT(nr)          (1UL << (nr))
-#define BIT_ULL(nr)      (1ULL << (nr))
-#define BIT_MASK(nr)     (1UL << ((nr) % BITS_PER_LONG))
-#define BIT_WORD(nr)     ((nr) / BITS_PER_LONG)
-#define BIT_ULL_MASK(nr) (1ULL << ((nr) % BITS_PER_LONG_LONG))
-#define BIT_ULL_WORD(nr) ((nr) / BITS_PER_LONG_LONG)
-#define BITS_PER_BYTE    8
-
-/* cp210x_flow_ctl::ulControlHandshake */
-#define CP210X_SERIAL_DTR_MASK         GENMASK(1, 0)
-#define CP210X_SERIAL_DTR_SHIFT(_mode) (_mode)
-#define CP210X_SERIAL_CTS_HANDSHAKE    BIT(3)
-#define CP210X_SERIAL_DSR_HANDSHAKE    BIT(4)
-#define CP210X_SERIAL_DCD_HANDSHAKE    BIT(5)
-#define CP210X_SERIAL_DSR_SENSITIVITY  BIT(6)
-
-/* values for cp210x_flow_ctl::ulControlHandshake::CP210X_SERIAL_DTR_MASK */
-#define CP210X_SERIAL_DTR_INACTIVE 0
-#define CP210X_SERIAL_DTR_ACTIVE   1
-#define CP210X_SERIAL_DTR_FLOW_CTL 2
-
-/* cp210x_flow_ctl::ulFlowReplace */
-#define CP210X_SERIAL_AUTO_TRANSMIT    BIT(0)
-#define CP210X_SERIAL_AUTO_RECEIVE     BIT(1)
-#define CP210X_SERIAL_ERROR_CHAR       BIT(2)
-#define CP210X_SERIAL_NULL_STRIPPING   BIT(3)
-#define CP210X_SERIAL_BREAK_CHAR       BIT(4)
-#define CP210X_SERIAL_RTS_MASK         GENMASK(7, 6)
-#define CP210X_SERIAL_RTS_SHIFT(_mode) (_mode << 6)
-#define CP210X_SERIAL_XOFF_CONTINUE    BIT(31)
-
-/* values for cp210x_flow_ctl::ulFlowReplace::CP210X_SERIAL_RTS_MASK */
-#define CP210X_SERIAL_RTS_INACTIVE 0
-#define CP210X_SERIAL_RTS_ACTIVE   1
-#define CP210X_SERIAL_RTS_FLOW_CTL 2
-
-/* CP210X_VENDOR_SPECIFIC, CP210X_GET_DEVICEMODE call reads these 0x2 bytes. */
-struct cp210x_pin_mode {
-    u8 eci;
-    u8 sci;
-} __packed;
-
-#define CP210X_PIN_MODE_MODEM 0
-#define CP210X_PIN_MODE_GPIO  BIT(0)
-
-/*
- * CP210X_VENDOR_SPECIFIC, CP210X_GET_PORTCONFIG call reads these 0xf bytes.
- * Structure needs padding due to unused/unspecified bytes.
- */
-#define __le16 int16_t
-
-struct cp210x_config {
-    __le16 gpio_mode;
-    u8 __pad0[2];
-    __le16 reset_state;
-    u8 __pad1[4];
-    __le16 suspend_state;
-    u8 sci_cfg;
-    u8 eci_cfg;
-    u8 device_cfg;
-} __packed;
-
-/* GPIO modes */
-#define CP210X_SCI_GPIO_MODE_OFFSET 9
-#define CP210X_SCI_GPIO_MODE_MASK   GENMASK(11, 9)
-
-#define CP210X_ECI_GPIO_MODE_OFFSET 2
-#define CP210X_ECI_GPIO_MODE_MASK   GENMASK(3, 2)
-
-/* CP2105 port configuration values */
-#define CP2105_GPIO0_TXLED_MODE BIT(0)
-#define CP2105_GPIO1_RXLED_MODE BIT(1)
-#define CP2105_GPIO1_RS485_MODE BIT(2)
-
-/* CP2102N configuration array indices */
-#define CP210X_2NCONFIG_CONFIG_VERSION_IDX 2
-#define CP210X_2NCONFIG_GPIO_MODE_IDX      581
-#define CP210X_2NCONFIG_GPIO_RSTLATCH_IDX  587
-#define CP210X_2NCONFIG_GPIO_CONTROL_IDX   600
-
-/* CP210X_VENDOR_SPECIFIC, CP210X_WRITE_LATCH call writes these 0x2 bytes. */
-struct cp210x_gpio_write {
-    u8 mask;
-    u8 state;
-} __packed;
-
-/*
- * Helper to get interface number when we only have struct usb_serial.
- */
-static u8 cp210x_interface_num(struct usb_serial_port *port)
-{
-    return port->bInterfaceNumber;
-}
-
-/*
- * Reads a variable-sized block of CP210X_ registers, identified by req.
- * Returns data into buf in native USB byte order.
- */
-static int cp210x_read_reg_block(struct usb_serial_port *port, u8 req,
-                                 void *buf, int bufsize)
-{
-    int result;
-
-    result = usb_control_msg(port, usb_rcvctrlpipe(port, 0),
-                             req, REQTYPE_INTERFACE_TO_HOST, 0,
-                             port->bInterfaceNumber, buf, bufsize,
-                             USB_CTRL_SET_TIMEOUT);
-    if (result == bufsize) {
-        result = 0;
-    } else {
-        dev_err("failed get req 0x%x size %d status: %d\n",
-                (uint8_t)req, bufsize, result);
-        if (result >= 0)
-            result = -EIO;
-
-        /*
-		 * FIXME Some callers don't bother to check for error,
-		 * at least give them consistent junk until they are fixed
-		 */
-        memset(buf, 0, bufsize);
-    }
-
-    return result;
-}
-
-/*
- * Reads any 32-bit CP210X_ register identified by req.
- */
-static int cp210x_read_u32_reg(struct usb_serial_port *port, u8 req, u32 *val)
-{
-    __le32 le32_val;
-    int err;
-
-    err = cp210x_read_reg_block(port, req, &le32_val, sizeof(le32_val));
-    if (err) {
-        /*
-		 * FIXME Some callers don't bother to check for error,
-		 * at least give them consistent junk until they are fixed
-		 */
-        *val = 0;
-        return err;
-    }
-
-    *val = le32_to_cpu(le32_val);
-
-    return 0;
-}
-
-/*
- * Reads any 16-bit CP210X_ register identified by req.
- */
-static int cp210x_read_u16_reg(struct usb_serial_port *port, u8 req, u16 *val)
-{
-    __le16 le16_val;
-    int err;
-
-    err = cp210x_read_reg_block(port, req, &le16_val, sizeof(le16_val));
-    if (err)
-        return err;
-
-    *val = le16_to_cpu(le16_val);
-
-    return 0;
-}
-
-/*
- * Reads any 8-bit CP210X_ register identified by req.
- */
-static int cp210x_read_u8_reg(struct usb_serial_port *port, u8 req, u8 *val)
-{
-    return cp210x_read_reg_block(port, req, val, sizeof(*val));
-}
-
-/*
- * Reads a variable-sized vendor block of CP210X_ registers, identified by val.
- * Returns data into buf in native USB byte order.
- */
-static int cp210x_read_vendor_block(struct usb_serial_port *port, u8 type, u16 val,
-                                    void *buf, int bufsize)
-{
-    int result;
-
-    result = usb_control_msg(port, usb_rcvctrlpipe(port, 0),
-                             CP210X_VENDOR_SPECIFIC, type, val,
-                             cp210x_interface_num(port), buf, bufsize,
-                             USB_CTRL_GET_TIMEOUT);
-    if (result == bufsize) {
-        return 0;
-    } else {
-        if (result >= 0)
-            return -1;
-    }
-
-    return -2;
-}
-
-/*
- * Writes any 16-bit CP210X_ register (req) whose value is passed
- * entirely in the wValue field of the USB request.
- */
-static int cp210x_write_u16_reg(struct usb_serial_port *port, u8 req, u16 val)
-{
-    int result;
-
-    result = usb_control_msg(port, usb_sndctrlpipe(port, 0),
-                             req, REQTYPE_HOST_TO_INTERFACE, val,
-                             port->bInterfaceNumber, NULL, 0,
-                             USB_CTRL_SET_TIMEOUT);
-    if (result < 0) {
-        USB_LOG_ERR("failed set request 0x%x status: %d\n",
-                    req, result);
-    }
-
-    return result;
-}
-
-/*
- * Writes a variable-sized block of CP210X_ registers, identified by req.
- * Data in buf must be in native USB byte order.
- */
-static int cp210x_write_reg_block(struct usb_serial_port *port, u8 req,
-                                  void *buf, int bufsize)
-{
-    int result;
-
-    result = usb_control_msg(port, usb_sndctrlpipe(port, 0),
-                             req, REQTYPE_HOST_TO_INTERFACE, 0,
-                             port->bInterfaceNumber, buf, bufsize,
-                             USB_CTRL_SET_TIMEOUT);
-
-    if (result == bufsize) {
-        result = 0;
-    } else {
-        USB_LOG_ERR("failed set req 0x%x size %d status: %d\n",
-                    req, bufsize, result);
-        if (result >= 0)
-            result = -EIO;
-    }
-
-    return result;
-}
-
-/*
- * Writes any 32-bit CP210X_ register identified by req.
- */
-static int cp210x_write_u32_reg(struct usb_serial_port *port, u8 req, u32 val)
-{
-    __le32 le32_val;
-
-    le32_val = cpu_to_le32(val);
-
-    return cp210x_write_reg_block(port, req, &le32_val, sizeof(le32_val));
-}
-
-/*
- * Detect CP2108 GET_LINE_CTL bug and activate workaround.
- * Write a known good value 0x800, read it back.
- * If it comes back swapped the bug is detected.
- * Preserve the original register value.
- */
-static int cp210x_detect_swapped_line_ctl(struct usb_serial_port *port)
-{
-    u16 line_ctl_save;
-    u16 line_ctl_test;
-    int err;
-
-    err = cp210x_read_u16_reg(port, CP210X_GET_LINE_CTL, &line_ctl_save);
-    if (err) {
-        USB_LOG_ERR("Error, read reg GET_LINE_CTL\n");
-        return err;
-    }
-
-    err = cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, 0x800);
-    if (err) {
-        USB_LOG_ERR("Error, write reg SET_LINE_CTL\n");
-        return err;
-    }
-
-    err = cp210x_read_u16_reg(port, CP210X_GET_LINE_CTL, &line_ctl_test);
-    if (err) {
-        USB_LOG_ERR("Error, read reg GET_LINE_CTL\n");
-        return err;
-    }
-
-    if (line_ctl_test == 8) {
-        port->has_swapped_line_ctl = true;
-        line_ctl_save = swab16(line_ctl_save);
-    }
-
-    return cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, line_ctl_save);
-}
-
-/*
- * Must always be called instead of cp210x_read_u16_reg(CP210X_GET_LINE_CTL)
- * to workaround cp2108 bug and get correct value.
- */
-static int cp210x_get_line_ctl(struct usb_serial_port *port, u16 *ctl)
-{
-    int err;
-
-    err = cp210x_read_u16_reg(port, CP210X_GET_LINE_CTL, ctl);
-    if (err)
-        return err;
-
-    /* Workaround swapped bytes in 16-bit value from CP210X_GET_LINE_CTL */
-    if (port->has_swapped_line_ctl)
-        *ctl = swab16(*ctl);
-
-    return 0;
-}
-
-int cp210x_open(struct tty_struct *tty)
-{
-    int result;
-    struct usb_serial_port *port = &tty->driver_data;
-
-    result = cp210x_write_u16_reg(port, CP210X_IFC_ENABLE, UART_ENABLE);
-    if (result) {
-        USB_LOG_ERR("%s - Unable to enable UART\n", __func__);
-        return result;
-    }
-
-    /* Configure the termios structure */
-    cp210x_get_termios(tty);
-
-    /* The baud rate must be initialised on cp2104 */
-    if (tty)
-        cp210x_change_speed(tty);
-
-    return 0;
-}
-
-void cp210x_close(struct usb_serial_port *port)
-{
-    /* Clear both queues; cp2108 needs this to avoid an occasional hang */
-    cp210x_write_u16_reg(port, CP210X_PURGE, PURGE_ALL);
-
-    cp210x_write_u16_reg(port, CP210X_IFC_ENABLE, UART_DISABLE);
-}
-
-/*
- * Read how many bytes are waiting in the TX queue.
- */
-static int cp210x_get_tx_queue_byte_count(struct usb_serial_port *port,
-                                          u32 *count)
-{
-    struct cp210x_comm_status sts;
-    int result;
-
-    result = usb_control_msg(port, usb_rcvctrlpipe(port, 0),
-                             CP210X_GET_COMM_STATUS, REQTYPE_INTERFACE_TO_HOST,
-                             0, port->bInterfaceNumber, &sts, sizeof(sts),
-                             USB_CTRL_GET_TIMEOUT);
-    if (result == sizeof(sts)) {
-        *count = le32_to_cpu(sts.ulAmountInOutQueue);
-        result = 0;
-    } else {
-        dev_err("failed to get comm status: %d\n", result);
-        if (result >= 0)
-            result = -EIO;
-    }
-
-    return result;
-}
-
-bool cp210x_tx_empty(struct usb_serial_port *port)
-{
-    int err;
-    u32 count;
-
-    err = cp210x_get_tx_queue_byte_count(port, &count);
-    if (err)
-        return true;
-
-    return !count;
-}
-
-/*
- * cp210x_get_termios
- * Reads the baud rate, data bits, parity, stop bits and flow control mode
- * from the device, corrects any unsupported values, and configures the
- * termios structure to reflect the state of the device
- */
-void cp210x_get_termios(struct tty_struct *tty)
-{
-    unsigned int baud;
-    struct usb_serial_port *port = &tty->driver_data;
-
-    if (tty) {
-        cp210x_get_termios_port(&tty->driver_data,
-                                &tty->termios.c_cflag, &baud);
-    } else {
-        tcflag_t cflag;
-        cflag = 0;
-        cp210x_get_termios_port(port, &cflag, &baud);
-    }
-}
-
-/*
- * cp210x_get_termios_port
- * This is the heart of cp210x_get_termios which always uses a &usb_serial_port.
- */
-void cp210x_get_termios_port(struct usb_serial_port *port, tcflag_t *cflagp, unsigned int *baudp)
-{
-    tcflag_t cflag;
-    struct cp210x_flow_ctl flow_ctl;
-    u32 baud;
-    u16 bits;
-    u32 ctl_hs;
-
-    cp210x_read_u32_reg(port, CP210X_GET_BAUDRATE, &baud);
-
-    dev_dbg("%s - baud rate = %d\n", __func__, baud);
-    *baudp = baud;
-
-    cflag = *cflagp;
-
-    cp210x_get_line_ctl(port, &bits);
-    cflag &= ~CSIZE;
-    switch (bits & BITS_DATA_MASK) {
-        case BITS_DATA_5:
-            dev_dbg("%s - data bits = 5\n", __func__);
-            cflag |= CS5;
-            break;
-        case BITS_DATA_6:
-            dev_dbg("%s - data bits = 6\n", __func__);
-            cflag |= CS6;
-            break;
-        case BITS_DATA_7:
-            dev_dbg("%s - data bits = 7\n", __func__);
-            cflag |= CS7;
-            break;
-        case BITS_DATA_8:
-            dev_dbg("%s - data bits = 8\n", __func__);
-            cflag |= CS8;
-            break;
-        case BITS_DATA_9:
-            dev_dbg("%s - data bits = 9 (not supported, using 8 data bits)\n", __func__);
-            cflag |= CS8;
-            bits &= ~BITS_DATA_MASK;
-            bits |= BITS_DATA_8;
-            cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits);
-            break;
-        default:
-            dev_dbg("%s - Unknown number of data bits, using 8\n", __func__);
-            cflag |= CS8;
-            bits &= ~BITS_DATA_MASK;
-            bits |= BITS_DATA_8;
-            cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits);
-            break;
-    }
-
-    switch (bits & BITS_PARITY_MASK) {
-        case BITS_PARITY_NONE:
-            dev_dbg("%s - parity = NONE\n", __func__);
-            cflag &= ~PARENB;
-            break;
-        case BITS_PARITY_ODD:
-            dev_dbg("%s - parity = ODD\n", __func__);
-            cflag |= (PARENB | PARODD);
-            break;
-        case BITS_PARITY_EVEN:
-            dev_dbg("%s - parity = EVEN\n", __func__);
-            cflag &= ~PARODD;
-            cflag |= PARENB;
-            break;
-        case BITS_PARITY_MARK:
-            dev_dbg("%s - parity = MARK\n", __func__);
-            cflag |= (PARENB | PARODD | CMSPAR);
-            break;
-        case BITS_PARITY_SPACE:
-            dev_dbg("%s - parity = SPACE\n", __func__);
-            cflag &= ~PARODD;
-            cflag |= (PARENB | CMSPAR);
-            break;
-        default:
-            dev_dbg("%s - Unknown parity mode, disabling parity\n", __func__);
-            cflag &= ~PARENB;
-            bits &= ~BITS_PARITY_MASK;
-            cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits);
-            break;
-    }
-
-    cflag &= ~CSTOPB;
-    switch (bits & BITS_STOP_MASK) {
-        case BITS_STOP_1:
-            dev_dbg("%s - stop bits = 1\n", __func__);
-            break;
-        case BITS_STOP_1_5:
-            dev_dbg("%s - stop bits = 1.5 (not supported, using 1 stop bit)\n", __func__);
-            bits &= ~BITS_STOP_MASK;
-            cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits);
-            break;
-        case BITS_STOP_2:
-            dev_dbg("%s - stop bits = 2\n", __func__);
-            cflag |= CSTOPB;
-            break;
-        default:
-            dev_dbg("%s - Unknown number of stop bits, using 1 stop bit\n", __func__);
-            bits &= ~BITS_STOP_MASK;
-            cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits);
-            break;
-    }
-
-    cp210x_read_reg_block(port, CP210X_GET_FLOW, &flow_ctl,
-                          sizeof(flow_ctl));
-    ctl_hs = le32_to_cpu(flow_ctl.ulControlHandshake);
-    if (ctl_hs & CP210X_SERIAL_CTS_HANDSHAKE) {
-        dev_dbg("%s - flow control = CRTSCTS\n", __func__);
-        cflag |= CRTSCTS;
-    } else {
-        dev_dbg("%s - flow control = NONE\n", __func__);
-        cflag &= ~CRTSCTS;
-    }
-
-    *cflagp = cflag;
-}
-
-struct cp210x_rate {
-    speed_t rate;
-    speed_t high;
-};
-
-static const struct cp210x_rate cp210x_an205_table1[] = {
-    { 300, 300 },
-    { 600, 600 },
-    { 1200, 1200 },
-    { 1800, 1800 },
-    { 2400, 2400 },
-    { 4000, 4000 },
-    { 4800, 4803 },
-    { 7200, 7207 },
-    { 9600, 9612 },
-    { 14400, 14428 },
-    { 16000, 16062 },
-    { 19200, 19250 },
-    { 28800, 28912 },
-    { 38400, 38601 },
-    { 51200, 51558 },
-    { 56000, 56280 },
-    { 57600, 58053 },
-    { 64000, 64111 },
-    { 76800, 77608 },
-    { 115200, 117028 },
-    { 128000, 129347 },
-    { 153600, 156868 },
-    { 230400, 237832 },
-    { 250000, 254234 },
-    { 256000, 273066 },
-    { 460800, 491520 },
-    { 500000, 567138 },
-    { 576000, 670254 },
-    { 921600, UINT_MAX }
-};
-
-/*
- * Quantises the baud rate as per AN205 Table 1
- */
-static speed_t cp210x_get_an205_rate(speed_t baud)
-{
-    int i;
-
-    for (i = 0; i < ARRAY_SIZE(cp210x_an205_table1); ++i) {
-        if (baud <= cp210x_an205_table1[i].high)
-            break;
-    }
-
-    return cp210x_an205_table1[i].rate;
-}
-
-static speed_t cp210x_get_actual_rate(struct usb_serial_port *port, speed_t baud)
-{
-    unsigned int prescale = 1;
-    unsigned int div;
-
-    baud = clamp(baud, 300u, port->max_speed);
-
-    if (baud <= 365)
-        prescale = 4;
-
-    div = DIV_ROUND_CLOSEST(48000000, 2 * prescale * baud);
-    baud = 48000000 / (2 * prescale * div);
-
-    return baud;
-}
-
-/*
- * CP2101 supports the following baud rates:
- *
- *	300, 600, 1200, 1800, 2400, 4800, 7200, 9600, 14400, 19200, 28800,
- *	38400, 56000, 57600, 115200, 128000, 230400, 460800, 921600
- *
- * CP2102 and CP2103 support the following additional rates:
- *
- *	4000, 16000, 51200, 64000, 76800, 153600, 250000, 256000, 500000,
- *	576000
- *
- * The device will map a requested rate to a supported one, but the result
- * of requests for rates greater than 1053257 is undefined (see AN205).
- *
- * CP2104, CP2105 and CP2110 support most rates up to 2M, 921k and 1M baud,
- * respectively, with an error less than 1%. The actual rates are determined
- * by
- *
- *	div = round(freq / (2 x prescale x request))
- *	actual = freq / (2 x prescale x div)
- *
- * For CP2104 and CP2105 freq is 48Mhz and prescale is 4 for request <= 365bps
- * or 1 otherwise.
- * For CP2110 freq is 24Mhz and prescale is 4 for request <= 300bps or 1
- * otherwise.
- */
-void cp210x_change_speed(struct tty_struct *tty)
-{
-    struct usb_serial_port *port = &tty->driver_data;
-    u32 baud;
-
-    baud = tty->termios.c_ospeed;
-
-    /*
-	 * This maps the requested rate to the actual rate, a valid rate on
-	 * cp2102 or cp2103, or to an arbitrary rate in [1M, max_speed].
-	 *
-	 * NOTE: B0 is not implemented.
-	 */
-    if (port->use_actual_rate)
-        baud = cp210x_get_actual_rate(port, baud);
-    else if (baud < 1000000)
-        baud = cp210x_get_an205_rate(baud);
-    else if (baud > port->max_speed)
-        baud = port->max_speed;
-
-    dev_dbg("%s - setting baud rate to %u\n", __func__, baud);
-    if (cp210x_write_u32_reg(port, CP210X_SET_BAUDRATE, baud)) {
-        dev_warn("failed to set baud rate to %u\n", baud);
-        baud = 9600;
-    }
-}
-
-void cp210x_set_termios(struct tty_struct *tty)
-{
-    unsigned int cflag;
-    u16 bits;
-    struct usb_serial_port *port = &tty->driver_data;
-
-    cflag = tty->termios.c_cflag;
-
-    cp210x_change_speed(tty);
-
-    /* If the number of data bits is to be updated */
-    cp210x_get_line_ctl(port, &bits);
-    bits &= ~BITS_DATA_MASK;
-    switch (cflag & CSIZE) {
-        case CS5:
-            bits |= BITS_DATA_5;
-            dev_dbg("%s - data bits = 5\n", __func__);
-            break;
-        case CS6:
-            bits |= BITS_DATA_6;
-            dev_dbg("%s - data bits = 6\n", __func__);
-            break;
-        case CS7:
-            bits |= BITS_DATA_7;
-            dev_dbg("%s - data bits = 7\n", __func__);
-            break;
-        case CS8:
-        default:
-            bits |= BITS_DATA_8;
-            dev_dbg("%s - data bits = 8\n", __func__);
-            break;
-    }
-    if (cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits))
-        dev_dbg("Number of data bits requested not supported by device%s\n", "");
-
-    cp210x_get_line_ctl(port, &bits);
-    bits &= ~BITS_PARITY_MASK;
-    if (cflag & PARENB) {
-        if (cflag & CMSPAR) {
-            if (cflag & PARODD) {
-                bits |= BITS_PARITY_MARK;
-                dev_dbg("%s - parity = MARK\n", __func__);
-            } else {
-                bits |= BITS_PARITY_SPACE;
-                dev_dbg(, "%s - parity = SPACE\n", __func__);
-            }
-        } else {
-            if (cflag & PARODD) {
-                bits |= BITS_PARITY_ODD;
-                dev_dbg("%s - parity = ODD\n", __func__);
-            } else {
-                bits |= BITS_PARITY_EVEN;
-                dev_dbg("%s - parity = EVEN\n", __func__);
-            }
-        }
-    }
-    if (cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits))
-        dev_dbg("Parity mode not supported by device%s\n", "");
-
-    cp210x_get_line_ctl(port, &bits);
-    bits &= ~BITS_STOP_MASK;
-    if (cflag & CSTOPB) {
-        bits |= BITS_STOP_2;
-        dev_dbg("%s - stop bits = 2\n", __func__);
-    } else {
-        bits |= BITS_STOP_1;
-        dev_dbg("%s - stop bits = 1\n", __func__);
-    }
-    if (cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits))
-        dev_dbg("Number of stop bits requested not supported by device%s\n", "");
-
-    {
-        struct cp210x_flow_ctl flow_ctl;
-        u32 ctl_hs;
-        u32 flow_repl;
-
-        cp210x_read_reg_block(port, CP210X_GET_FLOW, &flow_ctl,
-                              sizeof(flow_ctl));
-        ctl_hs = le32_to_cpu(flow_ctl.ulControlHandshake);
-        flow_repl = le32_to_cpu(flow_ctl.ulFlowReplace);
-        dev_dbg("%s - read ulControlHandshake=0x%08x, ulFlowReplace=0x%08x\n",
-                __func__, ctl_hs, flow_repl);
-
-        ctl_hs &= ~CP210X_SERIAL_DSR_HANDSHAKE;
-        ctl_hs &= ~CP210X_SERIAL_DCD_HANDSHAKE;
-        ctl_hs &= ~CP210X_SERIAL_DSR_SENSITIVITY;
-        ctl_hs &= ~CP210X_SERIAL_DTR_MASK;
-        ctl_hs |= CP210X_SERIAL_DTR_SHIFT(CP210X_SERIAL_DTR_ACTIVE);
-        if (cflag & CRTSCTS) {
-            ctl_hs |= CP210X_SERIAL_CTS_HANDSHAKE;
-
-            flow_repl &= ~CP210X_SERIAL_RTS_MASK;
-            flow_repl |= CP210X_SERIAL_RTS_SHIFT(
-                CP210X_SERIAL_RTS_FLOW_CTL);
-            dev_dbg("%s - flow control = CRTSCTS\n", __func__);
-        } else {
-            ctl_hs &= ~CP210X_SERIAL_CTS_HANDSHAKE;
-
-            flow_repl &= ~CP210X_SERIAL_RTS_MASK;
-            flow_repl |= CP210X_SERIAL_RTS_SHIFT(
-                CP210X_SERIAL_RTS_ACTIVE);
-            dev_dbg("%s - flow control = NONE\n", __func__);
-        }
-
-        dev_dbg("%s - write ulControlHandshake=0x%08x, ulFlowReplace=0x%08x\n",
-                __func__, ctl_hs, flow_repl);
-        flow_ctl.ulControlHandshake = cpu_to_le32(ctl_hs);
-        flow_ctl.ulFlowReplace = cpu_to_le32(flow_repl);
-        cp210x_write_reg_block(port, CP210X_SET_FLOW, &flow_ctl,
-                               sizeof(flow_ctl));
-    }
-}
-
-int cp210x_tiocmset_port(struct usb_serial_port *port, unsigned int set, unsigned int clear);
-
-int cp210x_tiocmset(struct tty_struct *tty,
-                    unsigned int set, unsigned int clear)
-{
-    struct usb_serial_port *port = 0;
-    return cp210x_tiocmset_port(port, set, clear);
-}
-
-int cp210x_tiocmset_port(struct usb_serial_port *port, unsigned int set, unsigned int clear)
-{
-    u16 control = 0;
-
-    if (set & TIOCM_RTS) {
-        control |= CONTROL_RTS;
-        control |= CONTROL_WRITE_RTS;
-    }
-    if (set & TIOCM_DTR) {
-        control |= CONTROL_DTR;
-        control |= CONTROL_WRITE_DTR;
-    }
-    if (clear & TIOCM_RTS) {
-        control &= ~CONTROL_RTS;
-        control |= CONTROL_WRITE_RTS;
-    }
-    if (clear & TIOCM_DTR) {
-        control &= ~CONTROL_DTR;
-        control |= CONTROL_WRITE_DTR;
-    }
-
-    return cp210x_write_u16_reg(port, CP210X_SET_MHS, control);
-}
-
-void cp210x_dtr_rts(struct usb_serial_port *p, int on)
-{
-    if (on)
-        cp210x_tiocmset_port(p, TIOCM_DTR | TIOCM_RTS, 0);
-    else
-        cp210x_tiocmset_port(p, 0, TIOCM_DTR | TIOCM_RTS);
-}
-
-int cp210x_tiocmget(struct tty_struct *tty)
-{
-    struct usb_serial_port *port = &tty->driver_data;
-    u8 control;
-    int result;
-
-    result = cp210x_read_u8_reg(port, CP210X_GET_MDMSTS, &control);
-    if (result)
-        return result;
-
-    result = ((control & CONTROL_DTR) ? TIOCM_DTR : 0) | ((control & CONTROL_RTS) ? TIOCM_RTS : 0) | ((control & CONTROL_CTS) ? TIOCM_CTS : 0) | ((control & CONTROL_DSR) ? TIOCM_DSR : 0) | ((control & CONTROL_RING) ? TIOCM_RI : 0) | ((control & CONTROL_DCD) ? TIOCM_CD : 0);
-
-    dev_dbg("%s - control = 0x%.2x\n", __func__, control);
-
-    return result;
-}
-
-void cp210x_break_ctl(struct tty_struct *tty, int break_state)
-{
-    struct usb_serial_port *port = &tty->driver_data;
-    u16 state;
-
-    if (break_state == 0)
-        state = BREAK_OFF;
-    else
-        state = BREAK_ON;
-    dev_dbg("%s - turning break %s\n", __func__,
-            state == BREAK_OFF ? "off" : "on");
-    cp210x_write_u16_reg(port, CP210X_SET_BREAK, state);
-}
-
-int cp210x_port_probe(struct usb_serial_port *port)
-{
-    int ret;
-
-    ret = cp210x_detect_swapped_line_ctl(port);
-    if (ret) {
-        return ret;
-    }
-
-    return 0;
-}
-
-void cp210x_init_max_speed(struct usb_serial_port *port)
-{
-    bool use_actual_rate = false;
-    speed_t max;
-
-    switch (port->partnum) {
-        case CP210X_PARTNUM_CP2101:
-            max = 921600;
-            break;
-        case CP210X_PARTNUM_CP2102:
-        case CP210X_PARTNUM_CP2103:
-            //max = 1000000;
-            max = 9600;
-            break;
-        case CP210X_PARTNUM_CP2104:
-            use_actual_rate = true;
-            max = 2000000;
-            break;
-        case CP210X_PARTNUM_CP2108:
-            max = 2000000;
-            break;
-        case CP210X_PARTNUM_CP2105:
-            if (cp210x_interface_num(port) == 0) {
-                use_actual_rate = true;
-                max = 2000000; /* ECI */
-            } else {
-                max = 921600;  /* SCI */
-            }
-            break;
-        case CP210X_PARTNUM_CP2102N_QFN28:
-        case CP210X_PARTNUM_CP2102N_QFN24:
-        case CP210X_PARTNUM_CP2102N_QFN20:
-            use_actual_rate = true;
-            max = 3000000;
-            break;
-        default:
-            max = 2000000;
-            break;
-    }
-
-    max = 9600;
-
-    port->max_speed = max;
-    port->use_actual_rate = use_actual_rate;
-    dev_dbg("max_speed=%d\n", max);
-    dev_dbg("use_actual_rate=%d\n", use_actual_rate);
-}
-
-int cp210x_attach(struct usb_serial_port *port)
-{
-    int result;
-    port->partnum = CP210X_PARTNUM_UNKNOWN;
-
-    result = cp210x_read_vendor_block(port, REQTYPE_DEVICE_TO_HOST,
-                                      CP210X_GET_PARTNUM, &port->partnum,
-                                      sizeof(port->partnum));
-    if (result < 0) {
-        dev_warn(
-            "querying part number failed%s\n", "");
-        port->partnum = CP210X_PARTNUM_UNKNOWN;
-    }
-
-    switch (port->partnum) {
-        case CP210X_PARTNUM_CP2101:
-        case CP210X_PARTNUM_CP2102:
-        case CP210X_PARTNUM_CP2103:
-        case CP210X_PARTNUM_CP2104:
-        case CP210X_PARTNUM_CP2108:
-        case CP210X_PARTNUM_CP2105:
-        case CP210X_PARTNUM_CP2102N_QFN28:
-        case CP210X_PARTNUM_CP2102N_QFN24:
-        case CP210X_PARTNUM_CP2102N_QFN20:
-            cp210x_init_max_speed(port);
-            return 0;
-        default:
-            return -1;
-    }
-}
-
-int usb_control_msg(struct usb_serial_port *port, int pipe, int req, u8 type, u16 val, u8 interface_num, void *dmabuf, int bufsize, int flags)
-{
-    struct usbh_cp210x *p_device = container_of(port, struct usbh_cp210x, drv_data.driver_data);
-    struct usb_setup_packet *setup = p_device->hport->setup;
-
-    setup->bmRequestType = type;
-    setup->bRequest = req;
-    setup->wValue = val;
-    setup->wIndex = interface_num;
-    setup->wLength = bufsize;
-    int len = usbh_control_transfer(p_device->hport->ep0, setup, dmabuf);
-    if (len > 0) {
-        return len - 8;
-    }
-    return len;
-}
-
-static int __usbh_cp210x_connect(struct usbh_hubport *hport, uint8_t intf)
-{
-    struct usb_endpoint_descriptor *ep_desc;
-    struct usbh_cp210x *p_cp210x = usb_malloc(sizeof(struct usbh_cp210x));
-    if (0 == p_cp210x) {
-        return -ENOSYS;
-    }
-    memset(p_cp210x, 0x00, sizeof(*p_cp210x));
-    p_cp210x->hport = hport;
-    p_cp210x->intf = intf;
-    p_cp210x->index = hport->port - 1;
-    hport->config.intf[intf].priv = p_cp210x;
-
-    p_cp210x->drv_data.driver_data.bInterfaceNumber = 1;
-    p_cp210x->drv_data.driver_data.ctrlpipe_rx = 0x80;
-    p_cp210x->drv_data.driver_data.ctrlpipe_tx = 0x00;
-    p_cp210x->drv_data.driver_data.max_speed = 9600;
-    p_cp210x->drv_data.driver_data.use_actual_rate = 1;
-    p_cp210x->drv_data.driver_data.bInterfaceNumber = 1;
-    p_cp210x->drv_data.driver_data.has_swapped_line_ctl = 0;
-
-    USB_LOG_INFO("%s hub %d port %d\n", "---- attach ----", hport->parent->index, hport->port);
-    if (0 != cp210x_attach(&p_cp210x->drv_data.driver_data)) {
-        USB_LOG_INFO("%s\n", "Device NOT supported!");
-        return -EIO;
-    }
-    cp210x_port_probe(&p_cp210x->drv_data.driver_data);
-    cp210x_open(&p_cp210x->drv_data);
-    cp210x_break_ctl(&p_cp210x->drv_data, 0);
-
-    memset(&p_cp210x->drv_data.termios, 0, sizeof(p_cp210x->drv_data.termios));
-    p_cp210x->drv_data.termios.c_iflag = 0;
-    p_cp210x->drv_data.termios.c_oflag = 0;
-    p_cp210x->drv_data.termios.c_cflag = CS8;
-    p_cp210x->drv_data.termios.c_lflag = 0;
-    p_cp210x->drv_data.termios.c_cc[0] = 0;
-    p_cp210x->drv_data.termios.c_ospeed = 9600;
-    cp210x_set_termios(&p_cp210x->drv_data);
-
-    for (uint8_t i = 0; i < hport->config.intf[intf].altsetting[0].intf_desc.bNumEndpoints; i++) {
-        ep_desc = &hport->config.intf[intf].altsetting[0].ep[i].ep_desc;
-        if (ep_desc->bEndpointAddress & 0x80) {
-            usbh_hport_activate_epx(&p_cp210x->bulkin, hport, ep_desc);
-        } else {
-            usbh_hport_activate_epx(&p_cp210x->bulkout, hport, ep_desc);
-        }
-    }
-
-    drv_usbh_cp210x_run(p_cp210x);
-
-    return 0;
-}
-
-__WEAK void drv_usbh_cp210x_run(struct usbh_cp210x *p_device)
-{
-}
-
-__WEAK void drv_usbh_cp210x_stop(struct usbh_cp210x *p_device)
-{
-}
-
-static int __usbh_cp210x_disconnect(struct usbh_hubport *hport, uint8_t intf)
-{
-    struct usbh_cp210x *p_device = (struct usbh_cp210x *)hport->config.intf[intf].priv;
-    if (p_device) {
-        drv_usbh_cp210x_stop(p_device);
-        if (p_device->bulkin) {
-            usbh_pipe_free(p_device->bulkin);
-        }
-        if (p_device->bulkout) {
-            usbh_pipe_free(p_device->bulkout);
-        }
-        memset(p_device, 0, sizeof(*p_device));
-        usb_free(p_device);
-    }
-    return 0;
-}
-
-static const struct usbh_class_driver cp210x_class_driver = {
-    .driver_name = "cp210x",
-    .connect = __usbh_cp210x_connect,
-    .disconnect = __usbh_cp210x_disconnect
-};
-
-CLASS_INFO_DEFINE const struct usbh_class_info cp210x_class_info = {
-    .match_flags = USB_CLASS_MATCH_INTF_CLASS | USB_CLASS_MATCH_INTF_SUBCLASS | USB_CLASS_MATCH_INTF_PROTOCOL,
-    .class = 0xff,    // usbh_cp210x_static_device_CLASS_MASS_STORAGE,
-    .subclass = 0x00, //MSC_SUBCLASS_SCSI,
-    .protocol = 0x00, //MSC_PROTOCOL_BULK_ONLY,
-    .vid = 0x00,
-    .pid = 0x00,
-    .class_driver = &cp210x_class_driver
-};

+ 0 - 99
class/vendor/cp201x/usbh_cp210x.h

@@ -1,99 +0,0 @@
-
-#ifndef USBH_CP210X_H
-#define USBH_CP210X_H
-
-#include <stdint.h>
-
-#include "usbh_core.h"
-
-typedef int32_t speed_t;
-typedef int32_t tcflag_t;
-
-#define DRIVER_DESC "Silicon Labs CP210x RS232 serial adaptor driver"
-
-struct usb_serial_port{
-	uint8_t partnum;
-	uint8_t ctrlpipe_rx;
-	uint8_t ctrlpipe_tx;
-	int32_t max_speed;
-	speed_t use_actual_rate;
-	uint8_t bInterfaceNumber;
-	int     has_swapped_line_ctl;
-};
-
-
-typedef unsigned char cc_t;
-
-#define NCCS 19
-struct termios {
-	tcflag_t c_iflag;		/* input mode flags */
-	tcflag_t c_oflag;		/* output mode flags */
-	tcflag_t c_cflag;		/* control mode flags */
-	tcflag_t c_lflag;		/* local mode flags */
-	cc_t c_cc[NCCS];		/* control characters */
-	cc_t c_line;			/* line discipline (== c_cc[19]) */
-	speed_t c_ispeed;		/* input speed */
-	speed_t c_ospeed;		/* output speed */
-};
-
-/* Alpha has identical termios and termios2 */
-
-struct termios2 {
-	tcflag_t c_iflag;		/* input mode flags */
-	tcflag_t c_oflag;		/* output mode flags */
-	tcflag_t c_cflag;		/* control mode flags */
-	tcflag_t c_lflag;		/* local mode flags */
-	cc_t c_cc[NCCS];		/* control characters */
-	cc_t c_line;			/* line discipline (== c_cc[19]) */
-	speed_t c_ispeed;		/* input speed */
-	speed_t c_ospeed;		/* output speed */
-};
-
-/* Alpha has matching termios and ktermios */
-
-struct ktermios {
-	tcflag_t c_iflag;		/* input mode flags */
-	tcflag_t c_oflag;		/* output mode flags */
-	tcflag_t c_cflag;		/* control mode flags */
-	tcflag_t c_lflag;		/* local mode flags */
-	cc_t c_cc[NCCS];		/* control characters */
-	cc_t c_line;			/* line discipline (== c_cc[19]) */
-	speed_t c_ispeed;		/* input speed */
-	speed_t c_ospeed;		/* output speed */
-};
-
-
-struct tty_struct{
-    struct usb_serial_port driver_data;
-    struct termios termios;
-};
-
-int cp210x_attach(struct usb_serial_port *port);
-int cp210x_port_probe(struct usb_serial_port *port);
-void cp210x_break_ctl(struct tty_struct *tty, int break_state);
-int cp210x_open(struct tty_struct *tty);
-int cp210x_tiocmget(struct tty_struct *tty);
-void cp210x_set_termios(struct tty_struct *tty);
-void cp210x_change_speed(struct tty_struct *tty);
-void cp210x_dtr_rts(struct usb_serial_port *port, int on);
-
-struct usbh_cp210x
-{
-    struct usbh_hubport *hport;
-
-    uint8_t intf;
-    usbh_pipe_t bulkin;
-    usbh_pipe_t bulkout;
-    struct usbh_urb bulkin_urb;
-    struct usbh_urb bulkout_urb;
-
-    struct tty_struct drv_data;
-    int index;
-};
-
-
-/* weak defined function */
-void drv_usbh_cp210x_run(struct usbh_cp210x *p_device);
-void drv_usbh_cp210x_stop(struct usbh_cp210x *p_device);
-
-#endif