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