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