1#ifndef __LINUX_FUSBH200_H
2#define __LINUX_FUSBH200_H
3
4
5
6
7
8
9
10
11
12
13
14#define __hc32 __le32
15#define __hc16 __le16
16
17
18struct fusbh200_stats {
19
20 unsigned long normal;
21 unsigned long error;
22 unsigned long iaa;
23 unsigned long lost_iaa;
24
25
26 unsigned long complete;
27 unsigned long unlink;
28};
29
30
31
32
33
34
35
36
37
38
39
40#define FUSBH200_MAX_ROOT_PORTS 1
41
42
43
44
45
46enum fusbh200_rh_state {
47 FUSBH200_RH_HALTED,
48 FUSBH200_RH_SUSPENDED,
49 FUSBH200_RH_RUNNING,
50 FUSBH200_RH_STOPPING
51};
52
53
54
55
56
57
58enum fusbh200_hrtimer_event {
59 FUSBH200_HRTIMER_POLL_ASS,
60 FUSBH200_HRTIMER_POLL_PSS,
61 FUSBH200_HRTIMER_POLL_DEAD,
62 FUSBH200_HRTIMER_UNLINK_INTR,
63 FUSBH200_HRTIMER_FREE_ITDS,
64 FUSBH200_HRTIMER_ASYNC_UNLINKS,
65 FUSBH200_HRTIMER_IAA_WATCHDOG,
66 FUSBH200_HRTIMER_DISABLE_PERIODIC,
67 FUSBH200_HRTIMER_DISABLE_ASYNC,
68 FUSBH200_HRTIMER_IO_WATCHDOG,
69 FUSBH200_HRTIMER_NUM_EVENTS
70};
71#define FUSBH200_HRTIMER_NO_EVENT 99
72
73struct fusbh200_hcd {
74
75 enum fusbh200_hrtimer_event next_hrtimer_event;
76 unsigned enabled_hrtimer_events;
77 ktime_t hr_timeouts[FUSBH200_HRTIMER_NUM_EVENTS];
78 struct hrtimer hrtimer;
79
80 int PSS_poll_count;
81 int ASS_poll_count;
82 int died_poll_count;
83
84
85 struct fusbh200_caps __iomem *caps;
86 struct fusbh200_regs __iomem *regs;
87 struct fusbh200_dbg_port __iomem *debug;
88
89 __u32 hcs_params;
90 spinlock_t lock;
91 enum fusbh200_rh_state rh_state;
92
93
94 bool scanning:1;
95 bool need_rescan:1;
96 bool intr_unlinking:1;
97 bool async_unlinking:1;
98 bool shutdown:1;
99 struct fusbh200_qh *qh_scan_next;
100
101
102 struct fusbh200_qh *async;
103 struct fusbh200_qh *dummy;
104 struct fusbh200_qh *async_unlink;
105 struct fusbh200_qh *async_unlink_last;
106 struct fusbh200_qh *async_iaa;
107 unsigned async_unlink_cycle;
108 unsigned async_count;
109
110
111#define DEFAULT_I_TDPS 1024
112 unsigned periodic_size;
113 __hc32 *periodic;
114 dma_addr_t periodic_dma;
115 struct list_head intr_qh_list;
116 unsigned i_thresh;
117
118 union fusbh200_shadow *pshadow;
119 struct fusbh200_qh *intr_unlink;
120 struct fusbh200_qh *intr_unlink_last;
121 unsigned intr_unlink_cycle;
122 unsigned now_frame;
123 unsigned next_frame;
124 unsigned intr_count;
125 unsigned isoc_count;
126 unsigned periodic_count;
127 unsigned uframe_periodic_max;
128
129
130
131 struct list_head cached_itd_list;
132 struct fusbh200_itd *last_itd_to_free;
133
134
135 unsigned long reset_done [FUSBH200_MAX_ROOT_PORTS];
136
137
138 unsigned long bus_suspended;
139
140 unsigned long companion_ports;
141
142 unsigned long owned_ports;
143
144 unsigned long port_c_suspend;
145
146 unsigned long suspended_ports;
147
148 unsigned long resuming_ports;
149
150
151
152 struct dma_pool *qh_pool;
153 struct dma_pool *qtd_pool;
154 struct dma_pool *itd_pool;
155
156 unsigned random_frame;
157 unsigned long next_statechange;
158 ktime_t last_periodic_enable;
159 u32 command;
160
161
162 unsigned need_io_watchdog:1;
163 unsigned fs_i_thresh:1;
164
165 u8 sbrn;
166
167
168 struct fusbh200_stats stats;
169# define COUNT(x) do { (x)++; } while (0)
170
171
172 struct dentry *debug_dir;
173};
174
175
176static inline struct fusbh200_hcd *hcd_to_fusbh200 (struct usb_hcd *hcd)
177{
178 return (struct fusbh200_hcd *) (hcd->hcd_priv);
179}
180static inline struct usb_hcd *fusbh200_to_hcd (struct fusbh200_hcd *fusbh200)
181{
182 return container_of ((void *) fusbh200, struct usb_hcd, hcd_priv);
183}
184
185
186
187
188
189
190struct fusbh200_caps {
191
192
193
194
195
196
197 u32 hc_capbase;
198#define HC_LENGTH(fusbh200, p) (0x00ff&((p) >> \
199 (fusbh200_big_endian_capbase(fusbh200) ? 24 : 0)))
200#define HC_VERSION(fusbh200, p) (0xffff&((p) >> \
201 (fusbh200_big_endian_capbase(fusbh200) ? 0 : 16)))
202 u32 hcs_params;
203#define HCS_N_PORTS(p) (((p)>>0)&0xf)
204
205 u32 hcc_params;
206#define HCC_CANPARK(p) ((p)&(1 << 2))
207#define HCC_PGM_FRAMELISTLEN(p) ((p)&(1 << 1))
208 u8 portroute[8];
209};
210
211
212
213struct fusbh200_regs {
214
215
216 u32 command;
217
218
219
220#define CMD_PARK (1<<11)
221#define CMD_PARK_CNT(c) (((c)>>8)&3)
222#define CMD_IAAD (1<<6)
223#define CMD_ASE (1<<5)
224#define CMD_PSE (1<<4)
225
226#define CMD_RESET (1<<1)
227#define CMD_RUN (1<<0)
228
229
230 u32 status;
231#define STS_ASS (1<<15)
232#define STS_PSS (1<<14)
233#define STS_RECL (1<<13)
234#define STS_HALT (1<<12)
235
236
237#define STS_IAA (1<<5)
238#define STS_FATAL (1<<4)
239#define STS_FLR (1<<3)
240#define STS_PCD (1<<2)
241#define STS_ERR (1<<1)
242#define STS_INT (1<<0)
243
244
245 u32 intr_enable;
246
247
248 u32 frame_index;
249
250 u32 segment;
251
252 u32 frame_list;
253
254 u32 async_next;
255
256 u32 reserved1;
257
258 u32 port_status;
259
260#define PORT_USB11(x) (((x)&(3<<10)) == (1<<10))
261#define PORT_RESET (1<<8)
262#define PORT_SUSPEND (1<<7)
263#define PORT_RESUME (1<<6)
264#define PORT_PEC (1<<3)
265#define PORT_PE (1<<2)
266#define PORT_CSC (1<<1)
267#define PORT_CONNECT (1<<0)
268#define PORT_RWC_BITS (PORT_CSC | PORT_PEC)
269
270 u32 reserved2[3];
271
272
273 u32 bmcsr;
274#define BMCSR_HOST_SPD_TYP (3<<9)
275#define BMCSR_VBUS_OFF (1<<4)
276#define BMCSR_INT_POLARITY (1<<3)
277
278
279 u32 bmisr;
280#define BMISR_OVC (1<<1)
281
282
283 u32 bmier;
284#define BMIER_OVC_EN (1<<1)
285#define BMIER_VBUS_ERR_EN (1<<0)
286};
287
288
289
290
291struct fusbh200_dbg_port {
292 u32 control;
293#define DBGP_OWNER (1<<30)
294#define DBGP_ENABLED (1<<28)
295#define DBGP_DONE (1<<16)
296#define DBGP_INUSE (1<<10)
297#define DBGP_ERRCODE(x) (((x)>>7)&0x07)
298# define DBGP_ERR_BAD 1
299# define DBGP_ERR_SIGNAL 2
300#define DBGP_ERROR (1<<6)
301#define DBGP_GO (1<<5)
302#define DBGP_OUT (1<<4)
303#define DBGP_LEN(x) (((x)>>0)&0x0f)
304 u32 pids;
305#define DBGP_PID_GET(x) (((x)>>16)&0xff)
306#define DBGP_PID_SET(data, tok) (((data)<<8)|(tok))
307 u32 data03;
308 u32 data47;
309 u32 address;
310#define DBGP_EPADDR(dev, ep) (((dev)<<8)|(ep))
311};
312
313#ifdef CONFIG_EARLY_PRINTK_DBGP
314#include <linux/init.h>
315extern int __init early_dbgp_init(char *s);
316extern struct console early_dbgp_console;
317#endif
318
319struct usb_hcd;
320
321static inline int xen_dbgp_reset_prep(struct usb_hcd *hcd)
322{
323 return 1;
324}
325
326static inline int xen_dbgp_external_startup(struct usb_hcd *hcd)
327{
328 return -1;
329}
330
331#ifdef CONFIG_EARLY_PRINTK_DBGP
332
333extern int dbgp_external_startup(struct usb_hcd *);
334extern int dbgp_reset_prep(struct usb_hcd *hcd);
335#else
336static inline int dbgp_reset_prep(struct usb_hcd *hcd)
337{
338 return xen_dbgp_reset_prep(hcd);
339}
340static inline int dbgp_external_startup(struct usb_hcd *hcd)
341{
342 return xen_dbgp_external_startup(hcd);
343}
344#endif
345
346
347
348#define QTD_NEXT(fusbh200, dma) cpu_to_hc32(fusbh200, (u32)dma)
349
350
351
352
353
354
355
356
357
358struct fusbh200_qtd {
359
360 __hc32 hw_next;
361 __hc32 hw_alt_next;
362 __hc32 hw_token;
363#define QTD_TOGGLE (1 << 31)
364#define QTD_LENGTH(tok) (((tok)>>16) & 0x7fff)
365#define QTD_IOC (1 << 15)
366#define QTD_CERR(tok) (((tok)>>10) & 0x3)
367#define QTD_PID(tok) (((tok)>>8) & 0x3)
368#define QTD_STS_ACTIVE (1 << 7)
369#define QTD_STS_HALT (1 << 6)
370#define QTD_STS_DBE (1 << 5)
371#define QTD_STS_BABBLE (1 << 4)
372#define QTD_STS_XACT (1 << 3)
373#define QTD_STS_MMF (1 << 2)
374#define QTD_STS_STS (1 << 1)
375#define QTD_STS_PING (1 << 0)
376
377#define ACTIVE_BIT(fusbh200) cpu_to_hc32(fusbh200, QTD_STS_ACTIVE)
378#define HALT_BIT(fusbh200) cpu_to_hc32(fusbh200, QTD_STS_HALT)
379#define STATUS_BIT(fusbh200) cpu_to_hc32(fusbh200, QTD_STS_STS)
380
381 __hc32 hw_buf [5];
382 __hc32 hw_buf_hi [5];
383
384
385 dma_addr_t qtd_dma;
386 struct list_head qtd_list;
387 struct urb *urb;
388 size_t length;
389} __attribute__ ((aligned (32)));
390
391
392#define QTD_MASK(fusbh200) cpu_to_hc32 (fusbh200, ~0x1f)
393
394#define IS_SHORT_READ(token) (QTD_LENGTH (token) != 0 && QTD_PID (token) == 1)
395
396
397
398
399#define Q_NEXT_TYPE(fusbh200,dma) ((dma) & cpu_to_hc32(fusbh200, 3 << 1))
400
401
402
403
404
405
406
407
408
409#define Q_TYPE_ITD (0 << 1)
410#define Q_TYPE_QH (1 << 1)
411#define Q_TYPE_SITD (2 << 1)
412#define Q_TYPE_FSTN (3 << 1)
413
414
415#define QH_NEXT(fusbh200,dma) (cpu_to_hc32(fusbh200, (((u32)dma)&~0x01f)|Q_TYPE_QH))
416
417
418#define FUSBH200_LIST_END(fusbh200) cpu_to_hc32(fusbh200, 1)
419
420
421
422
423
424
425
426
427
428union fusbh200_shadow {
429 struct fusbh200_qh *qh;
430 struct fusbh200_itd *itd;
431 struct fusbh200_fstn *fstn;
432 __hc32 *hw_next;
433 void *ptr;
434};
435
436
437
438
439
440
441
442
443
444
445
446
447struct fusbh200_qh_hw {
448 __hc32 hw_next;
449 __hc32 hw_info1;
450#define QH_CONTROL_EP (1 << 27)
451#define QH_HEAD (1 << 15)
452#define QH_TOGGLE_CTL (1 << 14)
453#define QH_HIGH_SPEED (2 << 12)
454#define QH_LOW_SPEED (1 << 12)
455#define QH_FULL_SPEED (0 << 12)
456#define QH_INACTIVATE (1 << 7)
457 __hc32 hw_info2;
458#define QH_SMASK 0x000000ff
459#define QH_CMASK 0x0000ff00
460#define QH_HUBADDR 0x007f0000
461#define QH_HUBPORT 0x3f800000
462#define QH_MULT 0xc0000000
463 __hc32 hw_current;
464
465
466 __hc32 hw_qtd_next;
467 __hc32 hw_alt_next;
468 __hc32 hw_token;
469 __hc32 hw_buf [5];
470 __hc32 hw_buf_hi [5];
471} __attribute__ ((aligned(32)));
472
473struct fusbh200_qh {
474 struct fusbh200_qh_hw *hw;
475
476 dma_addr_t qh_dma;
477 union fusbh200_shadow qh_next;
478 struct list_head qtd_list;
479 struct list_head intr_node;
480 struct fusbh200_qtd *dummy;
481 struct fusbh200_qh *unlink_next;
482
483 unsigned unlink_cycle;
484
485 u8 needs_rescan;
486 u8 qh_state;
487#define QH_STATE_LINKED 1
488#define QH_STATE_UNLINK 2
489#define QH_STATE_IDLE 3
490#define QH_STATE_UNLINK_WAIT 4
491#define QH_STATE_COMPLETING 5
492
493 u8 xacterrs;
494#define QH_XACTERR_MAX 32
495
496
497 u8 usecs;
498 u8 gap_uf;
499 u8 c_usecs;
500 u16 tt_usecs;
501 unsigned short period;
502 unsigned short start;
503#define NO_FRAME ((unsigned short)~0)
504
505 struct usb_device *dev;
506 unsigned is_out:1;
507 unsigned clearing_tt:1;
508};
509
510
511
512
513struct fusbh200_iso_packet {
514
515 u64 bufp;
516 __hc32 transaction;
517 u8 cross;
518
519 u32 buf1;
520};
521
522
523
524
525
526struct fusbh200_iso_sched {
527 struct list_head td_list;
528 unsigned span;
529 struct fusbh200_iso_packet packet [0];
530};
531
532
533
534
535
536struct fusbh200_iso_stream {
537
538 struct fusbh200_qh_hw *hw;
539
540 u8 bEndpointAddress;
541 u8 highspeed;
542 struct list_head td_list;
543 struct list_head free_list;
544 struct usb_device *udev;
545 struct usb_host_endpoint *ep;
546
547
548 int next_uframe;
549 __hc32 splits;
550
551
552
553
554
555 u8 usecs, c_usecs;
556 u16 interval;
557 u16 tt_usecs;
558 u16 maxp;
559 u16 raw_mask;
560 unsigned bandwidth;
561
562
563 __hc32 buf0;
564 __hc32 buf1;
565 __hc32 buf2;
566
567
568 __hc32 address;
569};
570
571
572
573
574
575
576
577
578
579struct fusbh200_itd {
580
581 __hc32 hw_next;
582 __hc32 hw_transaction [8];
583#define FUSBH200_ISOC_ACTIVE (1<<31)
584#define FUSBH200_ISOC_BUF_ERR (1<<30)
585#define FUSBH200_ISOC_BABBLE (1<<29)
586#define FUSBH200_ISOC_XACTERR (1<<28)
587#define FUSBH200_ITD_LENGTH(tok) (((tok)>>16) & 0x0fff)
588#define FUSBH200_ITD_IOC (1 << 15)
589
590#define ITD_ACTIVE(fusbh200) cpu_to_hc32(fusbh200, FUSBH200_ISOC_ACTIVE)
591
592 __hc32 hw_bufp [7];
593 __hc32 hw_bufp_hi [7];
594
595
596 dma_addr_t itd_dma;
597 union fusbh200_shadow itd_next;
598
599 struct urb *urb;
600 struct fusbh200_iso_stream *stream;
601 struct list_head itd_list;
602
603
604 unsigned frame;
605 unsigned pg;
606 unsigned index[8];
607} __attribute__ ((aligned (32)));
608
609
610
611
612
613
614
615
616
617
618
619
620struct fusbh200_fstn {
621 __hc32 hw_next;
622 __hc32 hw_prev;
623
624
625 dma_addr_t fstn_dma;
626 union fusbh200_shadow fstn_next;
627} __attribute__ ((aligned (32)));
628
629
630
631
632
633#define fusbh200_prepare_ports_for_controller_suspend(fusbh200, do_wakeup) \
634 fusbh200_adjust_port_wakeup_flags(fusbh200, true, do_wakeup);
635
636#define fusbh200_prepare_ports_for_controller_resume(fusbh200) \
637 fusbh200_adjust_port_wakeup_flags(fusbh200, false, false);
638
639
640
641
642
643
644
645
646
647
648static inline unsigned int
649fusbh200_get_speed(struct fusbh200_hcd *fusbh200, unsigned int portsc)
650{
651 return (readl(&fusbh200->regs->bmcsr)
652 & BMCSR_HOST_SPD_TYP) >> 9;
653}
654
655
656static inline unsigned int
657fusbh200_port_speed(struct fusbh200_hcd *fusbh200, unsigned int portsc)
658{
659 switch (fusbh200_get_speed(fusbh200, portsc)) {
660 case 0:
661 return 0;
662 case 1:
663 return USB_PORT_STAT_LOW_SPEED;
664 case 2:
665 default:
666 return USB_PORT_STAT_HIGH_SPEED;
667 }
668}
669
670
671
672#define fusbh200_has_fsl_portno_bug(e) (0)
673
674
675
676
677
678
679
680
681
682
683
684
685#define fusbh200_big_endian_mmio(e) 0
686#define fusbh200_big_endian_capbase(e) 0
687
688static inline unsigned int fusbh200_readl(const struct fusbh200_hcd *fusbh200,
689 __u32 __iomem * regs)
690{
691 return readl(regs);
692}
693
694static inline void fusbh200_writel(const struct fusbh200_hcd *fusbh200,
695 const unsigned int val, __u32 __iomem *regs)
696{
697 writel(val, regs);
698}
699
700
701static inline __hc32 cpu_to_hc32 (const struct fusbh200_hcd *fusbh200, const u32 x)
702{
703 return cpu_to_le32(x);
704}
705
706
707static inline u32 hc32_to_cpu (const struct fusbh200_hcd *fusbh200, const __hc32 x)
708{
709 return le32_to_cpu(x);
710}
711
712static inline u32 hc32_to_cpup (const struct fusbh200_hcd *fusbh200, const __hc32 *x)
713{
714 return le32_to_cpup(x);
715}
716
717
718
719static inline unsigned fusbh200_read_frame_index(struct fusbh200_hcd *fusbh200)
720{
721 return fusbh200_readl(fusbh200, &fusbh200->regs->frame_index);
722}
723
724#define fusbh200_itdlen(urb, desc, t) ({ \
725 usb_pipein((urb)->pipe) ? \
726 (desc)->length - FUSBH200_ITD_LENGTH(t) : \
727 FUSBH200_ITD_LENGTH(t); \
728})
729
730
731#endif
732