#include <linux/usb/net2280.h>
#include <linux/usb/usb338x.h>
#ifdef __KERNEL__
static inline u32 get_idx_reg(struct net2280_regs __iomem *regs, u32 index)
{
writel(index, ®s->idxaddr);
return readl(®s->idxdata);
}
static inline void
set_idx_reg(struct net2280_regs __iomem *regs, u32 index, u32 value)
{
writel(index, ®s->idxaddr);
writel(value, ®s->idxdata);
}
#endif /* __KERNEL__ */
#define PCI_VENDOR_ID_PLX_LEGACY 0x17cc
#define PLX_LEGACY BIT(0)
#define PLX_2280 BIT(1)
#define PLX_SUPERSPEED BIT(2)
#define PLX_PCIE BIT(3)
#define REG_DIAG 0x0
#define RETRY_COUNTER 16
#define FORCE_PCI_SERR 11
#define FORCE_PCI_INTERRUPT 10
#define FORCE_USB_INTERRUPT 9
#define FORCE_CPU_INTERRUPT 8
#define ILLEGAL_BYTE_ENABLES 5
#define FAST_TIMES 4
#define FORCE_RECEIVE_ERROR 2
#define FORCE_TRANSMIT_CRC_ERROR 0
#define REG_FRAME 0x02 /* from last sof */
#define REG_CHIPREV 0x03 /* in bcd */
#define REG_HS_NAK_RATE 0x0a /* NAK per N uframes */
#define CHIPREV_1 0x0100
#define CHIPREV_1A 0x0110
#define DEFECT_7374_NUMBEROF_MAX_WAIT_LOOPS 200
#define DEFECT_7374_PROCESSOR_WAIT_TIME 10
#define EP0_SS_MAX_PACKET_SIZE 0x200
#define EP0_HS_MAX_PACKET_SIZE 0x40
#ifdef __KERNEL__
struct net2280_dma {
__le32 dmacount;
__le32 dmaaddr;
__le32 dmadesc;
__le32 _reserved;
} __aligned(16);
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;
dma_addr_t td_dma;
struct net2280 *dev;
unsigned long irqs;
struct list_head queue;
const struct usb_endpoint_descriptor *desc;
unsigned num : 8,
fifo_size : 12,
in_fifo_validate : 1,
out_overflow : 1,
stopped : 1,
wedged : 1,
is_in : 1,
is_iso : 1,
responded : 1;
};
static inline void allow_status(struct net2280_ep *ep)
{
writel(BIT(CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE) |
BIT(CLEAR_NAK_OUT_PACKETS) |
BIT(CLEAR_NAK_OUT_PACKETS_MODE),
&ep->regs->ep_rsp);
ep->stopped = 1;
}
static inline void allow_status_338x(struct net2280_ep *ep)
{
writel(BIT(CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE), &ep->regs->ep_rsp);
ep->stopped = 1;
ep->responded = 0;
}
struct net2280_request {
struct usb_request req;
struct net2280_dma *td;
dma_addr_t td_dma;
struct list_head queue;
unsigned mapped : 1,
valid : 1;
};
struct net2280 {
struct usb_gadget gadget;
spinlock_t lock;
struct net2280_ep ep[9];
struct usb_gadget_driver *driver;
unsigned enabled : 1,
protocol_stall : 1,
softconnect : 1,
got_irq : 1,
region:1,
added:1,
u1_enable:1,
u2_enable:1,
ltm_enable:1,
wakeup_enable:1,
addressed_state:1,
async_callbacks:1,
bug7734_patched:1;
u16 chiprev;
int enhanced_mode;
int n_ep;
kernel_ulong_t quirks;
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_ll_regs __iomem *llregs;
struct usb338x_pl_regs __iomem *plregs;
struct dma_pool *requests;
};
static inline void set_halt(struct net2280_ep *ep)
{
writel(BIT(CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE) |
((ep->dev->chiprev == CHIPREV_1) << SET_NAK_OUT_PACKETS) |
BIT(SET_ENDPOINT_HALT),
&ep->regs->ep_rsp);
}
static inline void clear_halt(struct net2280_ep *ep)
{
writel(BIT(CLEAR_ENDPOINT_HALT) |
BIT(CLEAR_ENDPOINT_TOGGLE) |
((ep->dev->chiprev == CHIPREV_1) << CLEAR_NAK_OUT_PACKETS),
&ep->regs->ep_rsp);
}
#define DEFECT7374_FSM_FIELD 28
#define DEFECT7374_FSM_WAITING_FOR_CONTROL_READ BIT(DEFECT7374_FSM_FIELD)
#define DEFECT7374_FSM_NON_SS_CONTROL_READ (2 << DEFECT7374_FSM_FIELD)
#define DEFECT7374_FSM_SS_CONTROL_READ (3 << DEFECT7374_FSM_FIELD)
#ifdef USE_RDK_LEDS
static inline void net2280_led_init(struct net2280 *dev)
{
writel(BIT(GPIO3_LED_SELECT) |
BIT(GPIO3_OUTPUT_ENABLE) |
BIT(GPIO2_OUTPUT_ENABLE) |
BIT(GPIO1_OUTPUT_ENABLE) |
BIT(GPIO0_OUTPUT_ENABLE),
&dev->regs->gpioctl);
}
static inline
void net2280_led_speed(struct net2280 *dev, enum usb_device_speed speed)
{
u32 val = readl(&dev->regs->gpioctl);
switch (speed) {
case USB_SPEED_SUPER:
val |= BIT(GPIO0_DATA) | BIT(GPIO1_DATA);
break;
case USB_SPEED_HIGH:
val &= ~BIT(GPIO0_DATA);
val |= BIT(GPIO1_DATA);
break;
case USB_SPEED_FULL:
val &= ~BIT(GPIO1_DATA);
val |= BIT(GPIO0_DATA);
break;
default:
val &= ~(BIT(GPIO1_DATA) | BIT(GPIO0_DATA));
break;
}
writel(val, &dev->regs->gpioctl);
}
static inline void net2280_led_active(struct net2280 *dev, int is_active)
{
u32 val = readl(&dev->regs->gpioctl);
if (is_active)
val |= GPIO2_DATA;
else
val &= ~GPIO2_DATA;
writel(val, &dev->regs->gpioctl);
}
static inline void net2280_led_shutdown(struct net2280 *dev)
{
writel(readl(&dev->regs->gpioctl) & ~0x0f,
&dev->regs->gpioctl);
}
#else
#define net2280_led_init(dev) do { } while (0)
#define net2280_led_speed(dev, speed) do { } while (0)
#define net2280_led_shutdown(dev) do { } while (0)
#endif
#define ep_dbg(ndev, fmt, args...) \
dev_dbg((&((ndev)->pdev->dev)), fmt, ##args)
#define ep_vdbg(ndev, fmt, args...) \
dev_vdbg((&((ndev)->pdev->dev)), fmt, ##args)
#define ep_info(ndev, fmt, args...) \
dev_info((&((ndev)->pdev->dev)), fmt, ##args)
#define ep_warn(ndev, fmt, args...) \
dev_warn((&((ndev)->pdev->dev)), fmt, ##args)
#define ep_err(ndev, fmt, args...) \
dev_err((&((ndev)->pdev->dev)), fmt, ##args)
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)
{
writel(BIT(SET_NAK_OUT_PACKETS), &ep->regs->ep_rsp);
readl(&ep->regs->ep_rsp);
}
static inline void stop_out_naking(struct net2280_ep *ep)
{
u32 tmp;
tmp = readl(&ep->regs->ep_stat);
if ((tmp & BIT(NAK_OUT_PACKETS)) != 0)
writel(BIT(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];
switch (ep->dev->gadget.speed) {
case USB_SPEED_SUPER:
reg += 2;
break;
case USB_SPEED_FULL:
reg += 1;
break;
case USB_SPEED_HIGH:
default:
break;
}
} 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__ */