usb: gadget: net2280: Add support for PLX USB338X

This patch adds support for the PLX USB3380 and USB3382.

This driver is based on the driver from the manufacturer.

Since USB338X is register compatible with NET2280, I thought that it
would be better to include this hardware into net2280 driver.

Manufacturer's driver only supported the USB33X, did not follow the
Kernel Style and contain some trivial errors. This patch has tried to
address this issues.

This patch has only been tested on USB338x hardware, but the merge has
been done trying to not affect the behaviour of NET2280.

Tested-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
This commit is contained in:
Ricardo Ribalda Delgado 2014-05-20 18:30:03 +02:00 committed by Felipe Balbi
parent dad833823f
commit adc82f77be
4 changed files with 1350 additions and 97 deletions

View File

@ -409,7 +409,7 @@ config USB_NET2272_DMA
If unsure, say "N" here. The driver works fine in PIO mode.
config USB_NET2280
tristate "NetChip 228x"
tristate "NetChip 228x / PLX USB338x"
depends on PCI
help
NetChip 2280 / 2282 is a PCI based USB peripheral controller which
@ -419,6 +419,14 @@ config USB_NET2280
(for control transfers) and several endpoints with dedicated
functions.
PLX 3380 / 3382 is a PCIe based USB peripheral controller which
supports full, high speed USB 2.0 and super speed USB 3.0
data transfers.
It has eight configurable endpoints, as well as endpoint zero
(for control transfers) and several endpoints with dedicated
functions.
Say "y" to link the driver statically, or "m" to build a
dynamically linked module called "net2280" and force all
gadget drivers to also be dynamically linked.

File diff suppressed because it is too large Load Diff

View File

@ -6,6 +6,7 @@
/*
* Copyright (C) 2002 NetChip Technology, Inc. (http://www.netchip.com)
* Copyright (C) 2003 David Brownell
* Copyright (C) 2014 Ricardo Ribalda - Qtechnology/AS
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -14,6 +15,7 @@
*/
#include <linux/usb/net2280.h>
#include <linux/usb/usb338x.h>
/*-------------------------------------------------------------------------*/
@ -59,13 +61,14 @@ set_idx_reg (struct net2280_regs __iomem *regs, u32 index, u32 value)
#define CHIPREV_1 0x0100
#define CHIPREV_1A 0x0110
#ifdef __KERNEL__
/* DEFECT 7374 */
#define DEFECT_7374_NUMBEROF_MAX_WAIT_LOOPS 200
#define DEFECT_7374_PROCESSOR_WAIT_TIME 10
/* ep a-f highspeed and fullspeed maxpacket, addresses
* computed from ep->num
*/
#define REG_EP_MAXPKT(dev,num) (((num) + 1) * 0x10 + \
(((dev)->gadget.speed == USB_SPEED_HIGH) ? 0 : 1))
/* ep0 max packet size */
#define EP0_SS_MAX_PACKET_SIZE 0x200
#define EP0_HS_MAX_PACKET_SIZE 0x40
#ifdef __KERNEL__
/*-------------------------------------------------------------------------*/
@ -85,12 +88,15 @@ struct net2280_dma {
struct net2280_ep {
struct usb_ep ep;
struct net2280_ep_regs __iomem *cfg;
struct net2280_ep_regs __iomem *regs;
struct net2280_dma_regs __iomem *dma;
struct net2280_dma *dummy;
struct usb338x_fifo_regs __iomem *fiforegs;
dma_addr_t td_dma; /* of dummy */
struct net2280 *dev;
unsigned long irqs;
unsigned is_halt:1, dma_started:1;
/* analogous to a host-side qh */
struct list_head queue;
@ -116,10 +122,19 @@ static inline void allow_status (struct net2280_ep *ep)
ep->stopped = 1;
}
/* count (<= 4) bytes in the next fifo write will be valid */
static inline void set_fifo_bytecount (struct net2280_ep *ep, unsigned count)
static void allow_status_338x(struct net2280_ep *ep)
{
writeb (count, 2 + (u8 __iomem *) &ep->regs->ep_cfg);
/*
* Control Status Phase Handshake was set by the chip when the setup
* packet arrived. While set, the chip automatically NAKs the host's
* Status Phase tokens.
*/
writel(1 << CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE, &ep->regs->ep_rsp);
ep->stopped = 1;
/* TD 9.9 Halt Endpoint test. TD 9.22 set feature test. */
ep->responded = 0;
}
struct net2280_request {
@ -135,23 +150,38 @@ struct net2280 {
/* each pci device provides one gadget, several endpoints */
struct usb_gadget gadget;
spinlock_t lock;
struct net2280_ep ep [7];
struct net2280_ep ep[9];
struct usb_gadget_driver *driver;
unsigned enabled : 1,
protocol_stall : 1,
softconnect : 1,
got_irq : 1,
region : 1;
region:1,
u1_enable:1,
u2_enable:1,
ltm_enable:1,
wakeup_enable:1,
selfpowered:1,
addressed_state:1;
u16 chiprev;
int enhanced_mode;
int n_ep;
/* pci state used to access those endpoints */
struct pci_dev *pdev;
struct net2280_regs __iomem *regs;
struct net2280_usb_regs __iomem *usb;
struct usb338x_usb_ext_regs __iomem *usb_ext;
struct net2280_pci_regs __iomem *pci;
struct net2280_dma_regs __iomem *dma;
struct net2280_dep_regs __iomem *dep;
struct net2280_ep_regs __iomem *epregs;
struct usb338x_fifo_regs __iomem *fiforegs;
struct usb338x_ll_regs __iomem *llregs;
struct usb338x_ll_lfps_regs __iomem *ll_lfps_regs;
struct usb338x_ll_tsn_regs __iomem *ll_tsn_regs;
struct usb338x_ll_chi_regs __iomem *ll_chicken_reg;
struct usb338x_pl_regs __iomem *plregs;
struct pci_pool *requests;
// statistics...
@ -179,6 +209,43 @@ static inline void clear_halt (struct net2280_ep *ep)
, &ep->regs->ep_rsp);
}
/*
* FSM value for Defect 7374 (U1U2 Test) is managed in
* chip's SCRATCH register:
*/
#define DEFECT7374_FSM_FIELD 28
/* Waiting for Control Read:
* - A transition to this state indicates a fresh USB connection,
* before the first Setup Packet. The connection speed is not
* known. Firmware is waiting for the first Control Read.
* - Starting state: This state can be thought of as the FSM's typical
* starting state.
* - Tip: Upon the first SS Control Read the FSM never
* returns to this state.
*/
#define DEFECT7374_FSM_WAITING_FOR_CONTROL_READ (1 << DEFECT7374_FSM_FIELD)
/* Non-SS Control Read:
* - A transition to this state indicates detection of the first HS
* or FS Control Read.
* - Tip: Upon the first SS Control Read the FSM never
* returns to this state.
*/
#define DEFECT7374_FSM_NON_SS_CONTROL_READ (2 << DEFECT7374_FSM_FIELD)
/* SS Control Read:
* - A transition to this state indicates detection of the
* first SS Control Read.
* - This state indicates workaround completion. Workarounds no longer
* need to be applied (as long as the chip remains powered up).
* - Tip: Once in this state the FSM state does not change (until
* the chip's power is lost and restored).
* - This can be thought of as the final state of the FSM;
* the FSM 'locks-up' in this state until the chip loses power.
*/
#define DEFECT7374_FSM_SS_CONTROL_READ (3 << DEFECT7374_FSM_FIELD)
#ifdef USE_RDK_LEDS
static inline void net2280_led_init (struct net2280 *dev)
@ -198,6 +265,9 @@ void net2280_led_speed (struct net2280 *dev, enum usb_device_speed speed)
{
u32 val = readl (&dev->regs->gpioctl);
switch (speed) {
case USB_SPEED_SUPER: /* green + red */
val |= (1 << GPIO0_DATA) | (1 << GPIO1_DATA);
break;
case USB_SPEED_HIGH: /* green */
val &= ~(1 << GPIO0_DATA);
val |= (1 << GPIO1_DATA);
@ -271,6 +341,17 @@ static inline void net2280_led_shutdown (struct net2280 *dev)
/*-------------------------------------------------------------------------*/
static inline void set_fifo_bytecount(struct net2280_ep *ep, unsigned count)
{
if (ep->dev->pdev->vendor == 0x17cc)
writeb(count, 2 + (u8 __iomem *) &ep->regs->ep_cfg);
else{
u32 tmp = readl(&ep->cfg->ep_cfg) &
(~(0x07 << EP_FIFO_BYTE_COUNT));
writel(tmp | (count << EP_FIFO_BYTE_COUNT), &ep->cfg->ep_cfg);
}
}
static inline void start_out_naking (struct net2280_ep *ep)
{
/* NOTE: hardware races lurk here, and PING protocol issues */
@ -305,4 +386,22 @@ static inline void stop_out_naking (struct net2280_ep *ep)
writel ((1 << CLEAR_NAK_OUT_PACKETS), &ep->regs->ep_rsp);
}
static inline void set_max_speed(struct net2280_ep *ep, u32 max)
{
u32 reg;
static const u32 ep_enhanced[9] = { 0x10, 0x60, 0x30, 0x80,
0x50, 0x20, 0x70, 0x40, 0x90 };
if (ep->dev->enhanced_mode)
reg = ep_enhanced[ep->num];
else{
reg = (ep->num + 1) * 0x10;
if (ep->dev->gadget.speed != USB_SPEED_HIGH)
reg += 1;
}
set_idx_reg(ep->dev->regs, reg, max);
}
#endif /* __KERNEL__ */

199
include/linux/usb/usb338x.h Normal file
View File

@ -0,0 +1,199 @@
/*
* USB 338x super/high/full speed USB device controller.
* Unlike many such controllers, this one talks PCI.
*
* Copyright (C) 2002 NetChip Technology, Inc. (http://www.netchip.com)
* Copyright (C) 2003 David Brownell
* Copyright (C) 2014 Ricardo Ribalda - Qtechnology/AS
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#ifndef __LINUX_USB_USB338X_H
#define __LINUX_USB_USB338X_H
#include <linux/usb/net2280.h>
/*
* Extra defined bits for net2280 registers
*/
#define SCRATCH 0x0b
#define DEFECT7374_FSM_FIELD 28
#define SUPER_SPEED 8
#define DMA_REQUEST_OUTSTANDING 5
#define DMA_PAUSE_DONE_INTERRUPT 26
#define SET_ISOCHRONOUS_DELAY 24
#define SET_SEL 22
#define SUPER_SPEED_MODE 8
/*ep_cfg*/
#define MAX_BURST_SIZE 24
#define EP_FIFO_BYTE_COUNT 16
#define IN_ENDPOINT_ENABLE 14
#define IN_ENDPOINT_TYPE 12
#define OUT_ENDPOINT_ENABLE 10
#define OUT_ENDPOINT_TYPE 8
struct usb338x_usb_ext_regs {
u32 usbclass;
#define DEVICE_PROTOCOL 16
#define DEVICE_SUB_CLASS 8
#define DEVICE_CLASS 0
u32 ss_sel;
#define U2_SYSTEM_EXIT_LATENCY 8
#define U1_SYSTEM_EXIT_LATENCY 0
u32 ss_del;
#define U2_DEVICE_EXIT_LATENCY 8
#define U1_DEVICE_EXIT_LATENCY 0
u32 usb2lpm;
#define USB_L1_LPM_HIRD 2
#define USB_L1_LPM_REMOTE_WAKE 1
#define USB_L1_LPM_SUPPORT 0
u32 usb3belt;
#define BELT_MULTIPLIER 10
#define BEST_EFFORT_LATENCY_TOLERANCE 0
u32 usbctl2;
#define LTM_ENABLE 7
#define U2_ENABLE 6
#define U1_ENABLE 5
#define FUNCTION_SUSPEND 4
#define USB3_CORE_ENABLE 3
#define USB2_CORE_ENABLE 2
#define SERIAL_NUMBER_STRING_ENABLE 0
u32 in_timeout;
#define GPEP3_TIMEOUT 19
#define GPEP2_TIMEOUT 18
#define GPEP1_TIMEOUT 17
#define GPEP0_TIMEOUT 16
#define GPEP3_TIMEOUT_VALUE 13
#define GPEP3_TIMEOUT_ENABLE 12
#define GPEP2_TIMEOUT_VALUE 9
#define GPEP2_TIMEOUT_ENABLE 8
#define GPEP1_TIMEOUT_VALUE 5
#define GPEP1_TIMEOUT_ENABLE 4
#define GPEP0_TIMEOUT_VALUE 1
#define GPEP0_TIMEOUT_ENABLE 0
u32 isodelay;
#define ISOCHRONOUS_DELAY 0
} __packed;
struct usb338x_fifo_regs {
/* offset 0x0500, 0x0520, 0x0540, 0x0560, 0x0580 */
u32 ep_fifo_size_base;
#define IN_FIFO_BASE_ADDRESS 22
#define IN_FIFO_SIZE 16
#define OUT_FIFO_BASE_ADDRESS 6
#define OUT_FIFO_SIZE 0
u32 ep_fifo_out_wrptr;
u32 ep_fifo_out_rdptr;
u32 ep_fifo_in_wrptr;
u32 ep_fifo_in_rdptr;
u32 unused[3];
} __packed;
/* Link layer */
struct usb338x_ll_regs {
/* offset 0x700 */
u32 ll_ltssm_ctrl1;
u32 ll_ltssm_ctrl2;
u32 ll_ltssm_ctrl3;
u32 unused[2];
u32 ll_general_ctrl0;
u32 ll_general_ctrl1;
#define PM_U3_AUTO_EXIT 29
#define PM_U2_AUTO_EXIT 28
#define PM_U1_AUTO_EXIT 27
#define PM_FORCE_U2_ENTRY 26
#define PM_FORCE_U1_ENTRY 25
#define PM_LGO_COLLISION_SEND_LAU 24
#define PM_DIR_LINK_REJECT 23
#define PM_FORCE_LINK_ACCEPT 22
#define PM_DIR_ENTRY_U3 20
#define PM_DIR_ENTRY_U2 19
#define PM_DIR_ENTRY_U1 18
#define PM_U2_ENABLE 17
#define PM_U1_ENABLE 16
#define SKP_THRESHOLD_ADJUST_FMW 8
#define RESEND_DPP_ON_LRTY_FMW 7
#define DL_BIT_VALUE_FMW 6
#define FORCE_DL_BIT 5
u32 ll_general_ctrl2;
#define SELECT_INVERT_LANE_POLARITY 7
#define FORCE_INVERT_LANE_POLARITY 6
u32 ll_general_ctrl3;
u32 ll_general_ctrl4;
u32 ll_error_gen;
} __packed;
struct usb338x_ll_lfps_regs {
/* offset 0x748 */
u32 ll_lfps_5;
#define TIMER_LFPS_6US 16
u32 ll_lfps_6;
#define TIMER_LFPS_80US 0
} __packed;
struct usb338x_ll_tsn_regs {
/* offset 0x77C */
u32 ll_tsn_counters_2;
#define HOT_TX_NORESET_TS2 24
u32 ll_tsn_counters_3;
#define HOT_RX_RESET_TS2 0
} __packed;
struct usb338x_ll_chi_regs {
/* offset 0x79C */
u32 ll_tsn_chicken_bit;
#define RECOVERY_IDLE_TO_RECOVER_FMW 3
} __packed;
/* protocol layer */
struct usb338x_pl_regs {
/* offset 0x800 */
u32 pl_reg_1;
u32 pl_reg_2;
u32 pl_reg_3;
u32 pl_reg_4;
u32 pl_ep_ctrl;
/* Protocol Layer Endpoint Control*/
#define PL_EP_CTRL 0x810
#define ENDPOINT_SELECT 0
/* [4:0] */
#define EP_INITIALIZED 16
#define SEQUENCE_NUMBER_RESET 17
#define CLEAR_ACK_ERROR_CODE 20
u32 pl_reg_6;
u32 pl_reg_7;
u32 pl_reg_8;
u32 pl_ep_status_1;
/* Protocol Layer Endpoint Status 1*/
#define PL_EP_STATUS_1 0x820
#define STATE 16
#define ACK_GOOD_NORMAL 0x11
#define ACK_GOOD_MORE_ACKS_TO_COME 0x16
u32 pl_ep_status_2;
u32 pl_ep_status_3;
/* Protocol Layer Endpoint Status 3*/
#define PL_EP_STATUS_3 0x828
#define SEQUENCE_NUMBER 0
u32 pl_ep_status_4;
/* Protocol Layer Endpoint Status 4*/
#define PL_EP_STATUS_4 0x82c
u32 pl_ep_cfg_4;
/* Protocol Layer Endpoint Configuration 4*/
#define PL_EP_CFG_4 0x830
#define NON_CTRL_IN_TOLERATE_BAD_DIR 6
} __packed;
#endif /* __LINUX_USB_USB338X_H */