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.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include <linux/usb/net2280.h>
27 /*-------------------------------------------------------------------------*/
31 /* indexed registers [11.10] are accessed indirectly
32 * caller must own the device lock.
36 get_idx_reg (struct net2280_regs __iomem *regs, u32 index)
38 writel (index, ®s->idxaddr);
39 /* NOTE: synchs device/cpu memory views */
40 return readl (®s->idxdata);
44 set_idx_reg (struct net2280_regs __iomem *regs, u32 index, u32 value)
46 writel (index, ®s->idxaddr);
47 writel (value, ®s->idxdata);
48 /* posted, may not be visible yet */
51 #endif /* __KERNEL__ */
55 #define RETRY_COUNTER 16
56 #define FORCE_PCI_SERR 11
57 #define FORCE_PCI_INTERRUPT 10
58 #define FORCE_USB_INTERRUPT 9
59 #define FORCE_CPU_INTERRUPT 8
60 #define ILLEGAL_BYTE_ENABLES 5
62 #define FORCE_RECEIVE_ERROR 2
63 #define FORCE_TRANSMIT_CRC_ERROR 0
64 #define REG_FRAME 0x02 /* from last sof */
65 #define REG_CHIPREV 0x03 /* in bcd */
66 #define REG_HS_NAK_RATE 0x0a /* NAK per N uframes */
68 #define CHIPREV_1 0x0100
69 #define CHIPREV_1A 0x0110
73 /* ep a-f highspeed and fullspeed maxpacket, addresses
74 * computed from ep->num
76 #define REG_EP_MAXPKT(dev,num) (((num) + 1) * 0x10 + \
77 (((dev)->gadget.speed == USB_SPEED_HIGH) ? 0 : 1))
79 /*-------------------------------------------------------------------------*/
81 /* [8.3] for scatter/gather i/o
82 * use struct net2280_dma_regs bitfields
86 __le32 dmaaddr; /* the buffer */
87 __le32 dmadesc; /* next dma descriptor */
89 } __attribute__ ((aligned (16)));
91 /*-------------------------------------------------------------------------*/
93 /* DRIVER DATA STRUCTURES and UTILITIES */
97 struct net2280_ep_regs __iomem *regs;
98 struct net2280_dma_regs __iomem *dma;
99 struct net2280_dma *dummy;
100 dma_addr_t td_dma; /* of dummy */
104 /* analogous to a host-side qh */
105 struct list_head queue;
106 const struct usb_endpoint_descriptor *desc;
109 in_fifo_validate : 1,
117 static inline void allow_status (struct net2280_ep *ep)
120 writel ( (1 << CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE)
121 | (1 << CLEAR_NAK_OUT_PACKETS)
122 | (1 << CLEAR_NAK_OUT_PACKETS_MODE)
123 , &ep->regs->ep_rsp);
127 /* count (<= 4) bytes in the next fifo write will be valid */
128 static inline void set_fifo_bytecount (struct net2280_ep *ep, unsigned count)
130 writeb (count, 2 + (u8 __iomem *) &ep->regs->ep_cfg);
133 struct net2280_request {
134 struct usb_request req;
135 struct net2280_dma *td;
137 struct list_head queue;
143 /* each pci device provides one gadget, several endpoints */
144 struct usb_gadget gadget;
146 struct net2280_ep ep [7];
147 struct usb_gadget_driver *driver;
148 unsigned enabled : 1,
155 /* pci state used to access those endpoints */
156 struct pci_dev *pdev;
157 struct net2280_regs __iomem *regs;
158 struct net2280_usb_regs __iomem *usb;
159 struct net2280_pci_regs __iomem *pci;
160 struct net2280_dma_regs __iomem *dma;
161 struct net2280_dep_regs __iomem *dep;
162 struct net2280_ep_regs __iomem *epregs;
164 struct pci_pool *requests;
168 static inline void set_halt (struct net2280_ep *ep)
170 /* ep0 and bulk/intr endpoints */
171 writel ( (1 << CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE)
172 /* set NAK_OUT for erratum 0114 */
173 | ((ep->dev->chiprev == CHIPREV_1) << SET_NAK_OUT_PACKETS)
174 | (1 << SET_ENDPOINT_HALT)
175 , &ep->regs->ep_rsp);
178 static inline void clear_halt (struct net2280_ep *ep)
180 /* ep0 and bulk/intr endpoints */
181 writel ( (1 << CLEAR_ENDPOINT_HALT)
182 | (1 << CLEAR_ENDPOINT_TOGGLE)
183 /* unless the gadget driver left a short packet in the
184 * fifo, this reverses the erratum 0114 workaround.
186 | ((ep->dev->chiprev == CHIPREV_1) << CLEAR_NAK_OUT_PACKETS)
187 , &ep->regs->ep_rsp);
192 static inline void net2280_led_init (struct net2280 *dev)
194 /* LED3 (green) is on during USB activity. note erratum 0113. */
195 writel ((1 << GPIO3_LED_SELECT)
196 | (1 << GPIO3_OUTPUT_ENABLE)
197 | (1 << GPIO2_OUTPUT_ENABLE)
198 | (1 << GPIO1_OUTPUT_ENABLE)
199 | (1 << GPIO0_OUTPUT_ENABLE)
200 , &dev->regs->gpioctl);
203 /* indicate speed with bi-color LED 0/1 */
205 void net2280_led_speed (struct net2280 *dev, enum usb_device_speed speed)
207 u32 val = readl (&dev->regs->gpioctl);
209 case USB_SPEED_HIGH: /* green */
210 val &= ~(1 << GPIO0_DATA);
211 val |= (1 << GPIO1_DATA);
213 case USB_SPEED_FULL: /* red */
214 val &= ~(1 << GPIO1_DATA);
215 val |= (1 << GPIO0_DATA);
217 default: /* (off/black) */
218 val &= ~((1 << GPIO1_DATA) | (1 << GPIO0_DATA));
221 writel (val, &dev->regs->gpioctl);
224 /* indicate power with LED 2 */
225 static inline void net2280_led_active (struct net2280 *dev, int is_active)
227 u32 val = readl (&dev->regs->gpioctl);
229 // FIXME this LED never seems to turn on.
234 writel (val, &dev->regs->gpioctl);
236 static inline void net2280_led_shutdown (struct net2280 *dev)
238 /* turn off all four GPIO*_DATA bits */
239 writel (readl (&dev->regs->gpioctl) & ~0x0f,
240 &dev->regs->gpioctl);
245 #define net2280_led_init(dev) do { } while (0)
246 #define net2280_led_speed(dev, speed) do { } while (0)
247 #define net2280_led_shutdown(dev) do { } while (0)
251 /*-------------------------------------------------------------------------*/
253 #define xprintk(dev,level,fmt,args...) \
254 printk(level "%s %s: " fmt , driver_name , \
255 pci_name(dev->pdev) , ## args)
259 #define DEBUG(dev,fmt,args...) \
260 xprintk(dev , KERN_DEBUG , fmt , ## args)
262 #define DEBUG(dev,fmt,args...) \
269 #define VDEBUG(dev,fmt,args...) \
273 #define ERROR(dev,fmt,args...) \
274 xprintk(dev , KERN_ERR , fmt , ## args)
275 #define WARN(dev,fmt,args...) \
276 xprintk(dev , KERN_WARNING , fmt , ## args)
277 #define INFO(dev,fmt,args...) \
278 xprintk(dev , KERN_INFO , fmt , ## args)
280 /*-------------------------------------------------------------------------*/
282 static inline void start_out_naking (struct net2280_ep *ep)
284 /* NOTE: hardware races lurk here, and PING protocol issues */
285 writel ((1 << SET_NAK_OUT_PACKETS), &ep->regs->ep_rsp);
286 /* synch with device */
287 readl (&ep->regs->ep_rsp);
291 static inline void assert_out_naking (struct net2280_ep *ep, const char *where)
293 u32 tmp = readl (&ep->regs->ep_stat);
295 if ((tmp & (1 << NAK_OUT_PACKETS)) == 0) {
296 DEBUG (ep->dev, "%s %s %08x !NAK\n",
297 ep->ep.name, where, tmp);
298 writel ((1 << SET_NAK_OUT_PACKETS),
302 #define ASSERT_OUT_NAKING(ep) assert_out_naking(ep,__FUNCTION__)
304 #define ASSERT_OUT_NAKING(ep) do {} while (0)
307 static inline void stop_out_naking (struct net2280_ep *ep)
311 tmp = readl (&ep->regs->ep_stat);
312 if ((tmp & (1 << NAK_OUT_PACKETS)) != 0)
313 writel ((1 << CLEAR_NAK_OUT_PACKETS), &ep->regs->ep_rsp);
316 #endif /* __KERNEL__ */