2 * NetChip 2280 high/full speed USB device controller.
3 * Unlike many such controllers, this one talks PCI.
7 * Copyright (C) 2002 NetChip Technology, Inc. (http://www.netchip.com)
8 * Copyright (C) 2003 David Brownell
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
16 #include <linux/usb/net2280.h>
18 /*-------------------------------------------------------------------------*/
22 /* indexed registers [11.10] are accessed indirectly
23 * caller must own the device lock.
27 get_idx_reg (struct net2280_regs __iomem *regs, u32 index)
29 writel (index, ®s->idxaddr);
30 /* NOTE: synchs device/cpu memory views */
31 return readl (®s->idxdata);
35 set_idx_reg (struct net2280_regs __iomem *regs, u32 index, u32 value)
37 writel (index, ®s->idxaddr);
38 writel (value, ®s->idxdata);
39 /* posted, may not be visible yet */
42 #endif /* __KERNEL__ */
46 #define RETRY_COUNTER 16
47 #define FORCE_PCI_SERR 11
48 #define FORCE_PCI_INTERRUPT 10
49 #define FORCE_USB_INTERRUPT 9
50 #define FORCE_CPU_INTERRUPT 8
51 #define ILLEGAL_BYTE_ENABLES 5
53 #define FORCE_RECEIVE_ERROR 2
54 #define FORCE_TRANSMIT_CRC_ERROR 0
55 #define REG_FRAME 0x02 /* from last sof */
56 #define REG_CHIPREV 0x03 /* in bcd */
57 #define REG_HS_NAK_RATE 0x0a /* NAK per N uframes */
59 #define CHIPREV_1 0x0100
60 #define CHIPREV_1A 0x0110
64 /* ep a-f highspeed and fullspeed maxpacket, addresses
65 * computed from ep->num
67 #define REG_EP_MAXPKT(dev,num) (((num) + 1) * 0x10 + \
68 (((dev)->gadget.speed == USB_SPEED_HIGH) ? 0 : 1))
70 /*-------------------------------------------------------------------------*/
72 /* [8.3] for scatter/gather i/o
73 * use struct net2280_dma_regs bitfields
77 __le32 dmaaddr; /* the buffer */
78 __le32 dmadesc; /* next dma descriptor */
80 } __attribute__ ((aligned (16)));
82 /*-------------------------------------------------------------------------*/
84 /* DRIVER DATA STRUCTURES and UTILITIES */
88 struct net2280_ep_regs __iomem *regs;
89 struct net2280_dma_regs __iomem *dma;
90 struct net2280_dma *dummy;
91 dma_addr_t td_dma; /* of dummy */
95 /* analogous to a host-side qh */
96 struct list_head queue;
97 const struct usb_endpoint_descriptor *desc;
100 in_fifo_validate : 1,
109 static inline void allow_status (struct net2280_ep *ep)
112 writel ( (1 << CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE)
113 | (1 << CLEAR_NAK_OUT_PACKETS)
114 | (1 << CLEAR_NAK_OUT_PACKETS_MODE)
115 , &ep->regs->ep_rsp);
119 /* count (<= 4) bytes in the next fifo write will be valid */
120 static inline void set_fifo_bytecount (struct net2280_ep *ep, unsigned count)
122 writeb (count, 2 + (u8 __iomem *) &ep->regs->ep_cfg);
125 struct net2280_request {
126 struct usb_request req;
127 struct net2280_dma *td;
129 struct list_head queue;
135 /* each pci device provides one gadget, several endpoints */
136 struct usb_gadget gadget;
138 struct net2280_ep ep [7];
139 struct usb_gadget_driver *driver;
140 unsigned enabled : 1,
147 /* pci state used to access those endpoints */
148 struct pci_dev *pdev;
149 struct net2280_regs __iomem *regs;
150 struct net2280_usb_regs __iomem *usb;
151 struct net2280_pci_regs __iomem *pci;
152 struct net2280_dma_regs __iomem *dma;
153 struct net2280_dep_regs __iomem *dep;
154 struct net2280_ep_regs __iomem *epregs;
156 struct pci_pool *requests;
160 static inline void set_halt (struct net2280_ep *ep)
162 /* ep0 and bulk/intr endpoints */
163 writel ( (1 << CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE)
164 /* set NAK_OUT for erratum 0114 */
165 | ((ep->dev->chiprev == CHIPREV_1) << SET_NAK_OUT_PACKETS)
166 | (1 << SET_ENDPOINT_HALT)
167 , &ep->regs->ep_rsp);
170 static inline void clear_halt (struct net2280_ep *ep)
172 /* ep0 and bulk/intr endpoints */
173 writel ( (1 << CLEAR_ENDPOINT_HALT)
174 | (1 << CLEAR_ENDPOINT_TOGGLE)
175 /* unless the gadget driver left a short packet in the
176 * fifo, this reverses the erratum 0114 workaround.
178 | ((ep->dev->chiprev == CHIPREV_1) << CLEAR_NAK_OUT_PACKETS)
179 , &ep->regs->ep_rsp);
184 static inline void net2280_led_init (struct net2280 *dev)
186 /* LED3 (green) is on during USB activity. note erratum 0113. */
187 writel ((1 << GPIO3_LED_SELECT)
188 | (1 << GPIO3_OUTPUT_ENABLE)
189 | (1 << GPIO2_OUTPUT_ENABLE)
190 | (1 << GPIO1_OUTPUT_ENABLE)
191 | (1 << GPIO0_OUTPUT_ENABLE)
192 , &dev->regs->gpioctl);
195 /* indicate speed with bi-color LED 0/1 */
197 void net2280_led_speed (struct net2280 *dev, enum usb_device_speed speed)
199 u32 val = readl (&dev->regs->gpioctl);
201 case USB_SPEED_HIGH: /* green */
202 val &= ~(1 << GPIO0_DATA);
203 val |= (1 << GPIO1_DATA);
205 case USB_SPEED_FULL: /* red */
206 val &= ~(1 << GPIO1_DATA);
207 val |= (1 << GPIO0_DATA);
209 default: /* (off/black) */
210 val &= ~((1 << GPIO1_DATA) | (1 << GPIO0_DATA));
213 writel (val, &dev->regs->gpioctl);
216 /* indicate power with LED 2 */
217 static inline void net2280_led_active (struct net2280 *dev, int is_active)
219 u32 val = readl (&dev->regs->gpioctl);
221 // FIXME this LED never seems to turn on.
226 writel (val, &dev->regs->gpioctl);
228 static inline void net2280_led_shutdown (struct net2280 *dev)
230 /* turn off all four GPIO*_DATA bits */
231 writel (readl (&dev->regs->gpioctl) & ~0x0f,
232 &dev->regs->gpioctl);
237 #define net2280_led_init(dev) do { } while (0)
238 #define net2280_led_speed(dev, speed) do { } while (0)
239 #define net2280_led_shutdown(dev) do { } while (0)
243 /*-------------------------------------------------------------------------*/
245 #define xprintk(dev,level,fmt,args...) \
246 printk(level "%s %s: " fmt , driver_name , \
247 pci_name(dev->pdev) , ## args)
251 #define DEBUG(dev,fmt,args...) \
252 xprintk(dev , KERN_DEBUG , fmt , ## args)
254 #define DEBUG(dev,fmt,args...) \
261 #define VDEBUG(dev,fmt,args...) \
265 #define ERROR(dev,fmt,args...) \
266 xprintk(dev , KERN_ERR , fmt , ## args)
267 #define WARNING(dev,fmt,args...) \
268 xprintk(dev , KERN_WARNING , fmt , ## args)
269 #define INFO(dev,fmt,args...) \
270 xprintk(dev , KERN_INFO , fmt , ## args)
272 /*-------------------------------------------------------------------------*/
274 static inline void start_out_naking (struct net2280_ep *ep)
276 /* NOTE: hardware races lurk here, and PING protocol issues */
277 writel ((1 << SET_NAK_OUT_PACKETS), &ep->regs->ep_rsp);
278 /* synch with device */
279 readl (&ep->regs->ep_rsp);
283 static inline void assert_out_naking (struct net2280_ep *ep, const char *where)
285 u32 tmp = readl (&ep->regs->ep_stat);
287 if ((tmp & (1 << NAK_OUT_PACKETS)) == 0) {
288 DEBUG (ep->dev, "%s %s %08x !NAK\n",
289 ep->ep.name, where, tmp);
290 writel ((1 << SET_NAK_OUT_PACKETS),
294 #define ASSERT_OUT_NAKING(ep) assert_out_naking(ep,__func__)
296 #define ASSERT_OUT_NAKING(ep) do {} while (0)
299 static inline void stop_out_naking (struct net2280_ep *ep)
303 tmp = readl (&ep->regs->ep_stat);
304 if ((tmp & (1 << NAK_OUT_PACKETS)) != 0)
305 writel ((1 << CLEAR_NAK_OUT_PACKETS), &ep->regs->ep_rsp);
308 #endif /* __KERNEL__ */