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