0001
0002 #ifndef __LINUX_FOTG210_H
0003 #define __LINUX_FOTG210_H
0004
0005 #include <linux/usb/ehci-dbgp.h>
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #define __hc32 __le32
0018 #define __hc16 __le16
0019
0020
0021 struct fotg210_stats {
0022
0023 unsigned long normal;
0024 unsigned long error;
0025 unsigned long iaa;
0026 unsigned long lost_iaa;
0027
0028
0029 unsigned long complete;
0030 unsigned long unlink;
0031 };
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043 #define FOTG210_MAX_ROOT_PORTS 1
0044
0045
0046
0047
0048
0049 enum fotg210_rh_state {
0050 FOTG210_RH_HALTED,
0051 FOTG210_RH_SUSPENDED,
0052 FOTG210_RH_RUNNING,
0053 FOTG210_RH_STOPPING
0054 };
0055
0056
0057
0058
0059
0060
0061 enum fotg210_hrtimer_event {
0062 FOTG210_HRTIMER_POLL_ASS,
0063 FOTG210_HRTIMER_POLL_PSS,
0064 FOTG210_HRTIMER_POLL_DEAD,
0065 FOTG210_HRTIMER_UNLINK_INTR,
0066 FOTG210_HRTIMER_FREE_ITDS,
0067 FOTG210_HRTIMER_ASYNC_UNLINKS,
0068 FOTG210_HRTIMER_IAA_WATCHDOG,
0069 FOTG210_HRTIMER_DISABLE_PERIODIC,
0070 FOTG210_HRTIMER_DISABLE_ASYNC,
0071 FOTG210_HRTIMER_IO_WATCHDOG,
0072 FOTG210_HRTIMER_NUM_EVENTS
0073 };
0074 #define FOTG210_HRTIMER_NO_EVENT 99
0075
0076 struct fotg210_hcd {
0077
0078 enum fotg210_hrtimer_event next_hrtimer_event;
0079 unsigned enabled_hrtimer_events;
0080 ktime_t hr_timeouts[FOTG210_HRTIMER_NUM_EVENTS];
0081 struct hrtimer hrtimer;
0082
0083 int PSS_poll_count;
0084 int ASS_poll_count;
0085 int died_poll_count;
0086
0087
0088 struct fotg210_caps __iomem *caps;
0089 struct fotg210_regs __iomem *regs;
0090 struct ehci_dbg_port __iomem *debug;
0091
0092 __u32 hcs_params;
0093 spinlock_t lock;
0094 enum fotg210_rh_state rh_state;
0095
0096
0097 bool scanning:1;
0098 bool need_rescan:1;
0099 bool intr_unlinking:1;
0100 bool async_unlinking:1;
0101 bool shutdown:1;
0102 struct fotg210_qh *qh_scan_next;
0103
0104
0105 struct fotg210_qh *async;
0106 struct fotg210_qh *dummy;
0107 struct fotg210_qh *async_unlink;
0108 struct fotg210_qh *async_unlink_last;
0109 struct fotg210_qh *async_iaa;
0110 unsigned async_unlink_cycle;
0111 unsigned async_count;
0112
0113
0114 #define DEFAULT_I_TDPS 1024
0115 unsigned periodic_size;
0116 __hc32 *periodic;
0117 dma_addr_t periodic_dma;
0118 struct list_head intr_qh_list;
0119 unsigned i_thresh;
0120
0121 union fotg210_shadow *pshadow;
0122 struct fotg210_qh *intr_unlink;
0123 struct fotg210_qh *intr_unlink_last;
0124 unsigned intr_unlink_cycle;
0125 unsigned now_frame;
0126 unsigned next_frame;
0127 unsigned intr_count;
0128 unsigned isoc_count;
0129 unsigned periodic_count;
0130
0131 unsigned uframe_periodic_max;
0132
0133
0134
0135 struct list_head cached_itd_list;
0136 struct fotg210_itd *last_itd_to_free;
0137
0138
0139 unsigned long reset_done[FOTG210_MAX_ROOT_PORTS];
0140
0141
0142
0143
0144 unsigned long bus_suspended;
0145
0146
0147 unsigned long companion_ports;
0148
0149
0150 unsigned long owned_ports;
0151
0152
0153 unsigned long port_c_suspend;
0154
0155
0156 unsigned long suspended_ports;
0157
0158
0159 unsigned long resuming_ports;
0160
0161
0162 struct dma_pool *qh_pool;
0163 struct dma_pool *qtd_pool;
0164 struct dma_pool *itd_pool;
0165
0166 unsigned random_frame;
0167 unsigned long next_statechange;
0168 ktime_t last_periodic_enable;
0169 u32 command;
0170
0171
0172 unsigned need_io_watchdog:1;
0173 unsigned fs_i_thresh:1;
0174
0175 u8 sbrn;
0176
0177
0178 #ifdef FOTG210_STATS
0179 struct fotg210_stats stats;
0180 # define INCR(x) ((x)++)
0181 #else
0182 # define INCR(x) do {} while (0)
0183 #endif
0184
0185
0186 struct clk *pclk;
0187 };
0188
0189
0190 static inline struct fotg210_hcd *hcd_to_fotg210(struct usb_hcd *hcd)
0191 {
0192 return (struct fotg210_hcd *)(hcd->hcd_priv);
0193 }
0194 static inline struct usb_hcd *fotg210_to_hcd(struct fotg210_hcd *fotg210)
0195 {
0196 return container_of((void *) fotg210, struct usb_hcd, hcd_priv);
0197 }
0198
0199
0200
0201
0202
0203
0204 struct fotg210_caps {
0205
0206
0207
0208
0209
0210
0211 u32 hc_capbase;
0212 #define HC_LENGTH(fotg210, p) (0x00ff&((p) >> \
0213 (fotg210_big_endian_capbase(fotg210) ? 24 : 0)))
0214 #define HC_VERSION(fotg210, p) (0xffff&((p) >> \
0215 (fotg210_big_endian_capbase(fotg210) ? 0 : 16)))
0216 u32 hcs_params;
0217 #define HCS_N_PORTS(p) (((p)>>0)&0xf)
0218
0219 u32 hcc_params;
0220 #define HCC_CANPARK(p) ((p)&(1 << 2))
0221 #define HCC_PGM_FRAMELISTLEN(p) ((p)&(1 << 1))
0222 u8 portroute[8];
0223 };
0224
0225
0226
0227 struct fotg210_regs {
0228
0229
0230 u32 command;
0231
0232
0233
0234 #define CMD_PARK (1<<11)
0235 #define CMD_PARK_CNT(c) (((c)>>8)&3)
0236 #define CMD_IAAD (1<<6)
0237 #define CMD_ASE (1<<5)
0238 #define CMD_PSE (1<<4)
0239
0240 #define CMD_RESET (1<<1)
0241 #define CMD_RUN (1<<0)
0242
0243
0244 u32 status;
0245 #define STS_ASS (1<<15)
0246 #define STS_PSS (1<<14)
0247 #define STS_RECL (1<<13)
0248 #define STS_HALT (1<<12)
0249
0250
0251 #define STS_IAA (1<<5)
0252 #define STS_FATAL (1<<4)
0253 #define STS_FLR (1<<3)
0254 #define STS_PCD (1<<2)
0255 #define STS_ERR (1<<1)
0256 #define STS_INT (1<<0)
0257
0258
0259 u32 intr_enable;
0260
0261
0262 u32 frame_index;
0263
0264 u32 segment;
0265
0266 u32 frame_list;
0267
0268 u32 async_next;
0269
0270 u32 reserved1;
0271
0272 u32 port_status;
0273
0274 #define PORT_USB11(x) (((x)&(3<<10)) == (1<<10))
0275 #define PORT_RESET (1<<8)
0276 #define PORT_SUSPEND (1<<7)
0277 #define PORT_RESUME (1<<6)
0278 #define PORT_PEC (1<<3)
0279 #define PORT_PE (1<<2)
0280 #define PORT_CSC (1<<1)
0281 #define PORT_CONNECT (1<<0)
0282 #define PORT_RWC_BITS (PORT_CSC | PORT_PEC)
0283 u32 reserved2[19];
0284
0285
0286 u32 otgcsr;
0287 #define OTGCSR_HOST_SPD_TYP (3 << 22)
0288 #define OTGCSR_A_BUS_DROP (1 << 5)
0289 #define OTGCSR_A_BUS_REQ (1 << 4)
0290
0291
0292 u32 otgisr;
0293 #define OTGISR_OVC (1 << 10)
0294
0295 u32 reserved3[15];
0296
0297
0298 u32 gmir;
0299 #define GMIR_INT_POLARITY (1 << 3)
0300 #define GMIR_MHC_INT (1 << 2)
0301 #define GMIR_MOTG_INT (1 << 1)
0302 #define GMIR_MDEV_INT (1 << 0)
0303 };
0304
0305
0306
0307 #define QTD_NEXT(fotg210, dma) cpu_to_hc32(fotg210, (u32)dma)
0308
0309
0310
0311
0312
0313
0314
0315
0316
0317 struct fotg210_qtd {
0318
0319 __hc32 hw_next;
0320 __hc32 hw_alt_next;
0321 __hc32 hw_token;
0322 #define QTD_TOGGLE (1 << 31)
0323 #define QTD_LENGTH(tok) (((tok)>>16) & 0x7fff)
0324 #define QTD_IOC (1 << 15)
0325 #define QTD_CERR(tok) (((tok)>>10) & 0x3)
0326 #define QTD_PID(tok) (((tok)>>8) & 0x3)
0327 #define QTD_STS_ACTIVE (1 << 7)
0328 #define QTD_STS_HALT (1 << 6)
0329 #define QTD_STS_DBE (1 << 5)
0330 #define QTD_STS_BABBLE (1 << 4)
0331 #define QTD_STS_XACT (1 << 3)
0332 #define QTD_STS_MMF (1 << 2)
0333 #define QTD_STS_STS (1 << 1)
0334 #define QTD_STS_PING (1 << 0)
0335
0336 #define ACTIVE_BIT(fotg210) cpu_to_hc32(fotg210, QTD_STS_ACTIVE)
0337 #define HALT_BIT(fotg210) cpu_to_hc32(fotg210, QTD_STS_HALT)
0338 #define STATUS_BIT(fotg210) cpu_to_hc32(fotg210, QTD_STS_STS)
0339
0340 __hc32 hw_buf[5];
0341 __hc32 hw_buf_hi[5];
0342
0343
0344 dma_addr_t qtd_dma;
0345 struct list_head qtd_list;
0346 struct urb *urb;
0347 size_t length;
0348 } __aligned(32);
0349
0350
0351 #define QTD_MASK(fotg210) cpu_to_hc32(fotg210, ~0x1f)
0352
0353 #define IS_SHORT_READ(token) (QTD_LENGTH(token) != 0 && QTD_PID(token) == 1)
0354
0355
0356
0357
0358 #define Q_NEXT_TYPE(fotg210, dma) ((dma) & cpu_to_hc32(fotg210, 3 << 1))
0359
0360
0361
0362
0363
0364
0365
0366
0367
0368 #define Q_TYPE_ITD (0 << 1)
0369 #define Q_TYPE_QH (1 << 1)
0370 #define Q_TYPE_SITD (2 << 1)
0371 #define Q_TYPE_FSTN (3 << 1)
0372
0373
0374 #define QH_NEXT(fotg210, dma) \
0375 (cpu_to_hc32(fotg210, (((u32)dma)&~0x01f)|Q_TYPE_QH))
0376
0377
0378 #define FOTG210_LIST_END(fotg210) \
0379 cpu_to_hc32(fotg210, 1)
0380
0381
0382
0383
0384
0385
0386
0387
0388
0389 union fotg210_shadow {
0390 struct fotg210_qh *qh;
0391 struct fotg210_itd *itd;
0392 struct fotg210_fstn *fstn;
0393 __hc32 *hw_next;
0394 void *ptr;
0395 };
0396
0397
0398
0399
0400
0401
0402
0403
0404
0405
0406
0407
0408 struct fotg210_qh_hw {
0409 __hc32 hw_next;
0410 __hc32 hw_info1;
0411 #define QH_CONTROL_EP (1 << 27)
0412 #define QH_HEAD (1 << 15)
0413 #define QH_TOGGLE_CTL (1 << 14)
0414 #define QH_HIGH_SPEED (2 << 12)
0415 #define QH_LOW_SPEED (1 << 12)
0416 #define QH_FULL_SPEED (0 << 12)
0417 #define QH_INACTIVATE (1 << 7)
0418 __hc32 hw_info2;
0419 #define QH_SMASK 0x000000ff
0420 #define QH_CMASK 0x0000ff00
0421 #define QH_HUBADDR 0x007f0000
0422 #define QH_HUBPORT 0x3f800000
0423 #define QH_MULT 0xc0000000
0424 __hc32 hw_current;
0425
0426
0427 __hc32 hw_qtd_next;
0428 __hc32 hw_alt_next;
0429 __hc32 hw_token;
0430 __hc32 hw_buf[5];
0431 __hc32 hw_buf_hi[5];
0432 } __aligned(32);
0433
0434 struct fotg210_qh {
0435 struct fotg210_qh_hw *hw;
0436
0437 dma_addr_t qh_dma;
0438 union fotg210_shadow qh_next;
0439 struct list_head qtd_list;
0440 struct list_head intr_node;
0441 struct fotg210_qtd *dummy;
0442 struct fotg210_qh *unlink_next;
0443
0444 unsigned unlink_cycle;
0445
0446 u8 needs_rescan;
0447 u8 qh_state;
0448 #define QH_STATE_LINKED 1
0449 #define QH_STATE_UNLINK 2
0450 #define QH_STATE_IDLE 3
0451 #define QH_STATE_UNLINK_WAIT 4
0452 #define QH_STATE_COMPLETING 5
0453
0454 u8 xacterrs;
0455 #define QH_XACTERR_MAX 32
0456
0457
0458 u8 usecs;
0459 u8 gap_uf;
0460 u8 c_usecs;
0461 u16 tt_usecs;
0462 unsigned short period;
0463 unsigned short start;
0464 #define NO_FRAME ((unsigned short)~0)
0465
0466 struct usb_device *dev;
0467 unsigned is_out:1;
0468 unsigned clearing_tt:1;
0469 };
0470
0471
0472
0473
0474 struct fotg210_iso_packet {
0475
0476 u64 bufp;
0477 __hc32 transaction;
0478 u8 cross;
0479
0480 u32 buf1;
0481 };
0482
0483
0484
0485
0486
0487 struct fotg210_iso_sched {
0488 struct list_head td_list;
0489 unsigned span;
0490 struct fotg210_iso_packet packet[];
0491 };
0492
0493
0494
0495
0496
0497 struct fotg210_iso_stream {
0498
0499 struct fotg210_qh_hw *hw;
0500
0501 u8 bEndpointAddress;
0502 u8 highspeed;
0503 struct list_head td_list;
0504 struct list_head free_list;
0505 struct usb_device *udev;
0506 struct usb_host_endpoint *ep;
0507
0508
0509 int next_uframe;
0510 __hc32 splits;
0511
0512
0513
0514
0515
0516 u8 usecs, c_usecs;
0517 u16 interval;
0518 u16 tt_usecs;
0519 u16 maxp;
0520 u16 raw_mask;
0521 unsigned bandwidth;
0522
0523
0524 __hc32 buf0;
0525 __hc32 buf1;
0526 __hc32 buf2;
0527
0528
0529 __hc32 address;
0530 };
0531
0532
0533
0534
0535
0536
0537
0538
0539
0540 struct fotg210_itd {
0541
0542 __hc32 hw_next;
0543 __hc32 hw_transaction[8];
0544 #define FOTG210_ISOC_ACTIVE (1<<31)
0545 #define FOTG210_ISOC_BUF_ERR (1<<30)
0546 #define FOTG210_ISOC_BABBLE (1<<29)
0547 #define FOTG210_ISOC_XACTERR (1<<28)
0548 #define FOTG210_ITD_LENGTH(tok) (((tok)>>16) & 0x0fff)
0549 #define FOTG210_ITD_IOC (1 << 15)
0550
0551 #define ITD_ACTIVE(fotg210) cpu_to_hc32(fotg210, FOTG210_ISOC_ACTIVE)
0552
0553 __hc32 hw_bufp[7];
0554 __hc32 hw_bufp_hi[7];
0555
0556
0557 dma_addr_t itd_dma;
0558 union fotg210_shadow itd_next;
0559
0560 struct urb *urb;
0561 struct fotg210_iso_stream *stream;
0562 struct list_head itd_list;
0563
0564
0565 unsigned frame;
0566 unsigned pg;
0567 unsigned index[8];
0568 } __aligned(32);
0569
0570
0571
0572
0573
0574
0575
0576
0577
0578
0579
0580
0581 struct fotg210_fstn {
0582 __hc32 hw_next;
0583 __hc32 hw_prev;
0584
0585
0586 dma_addr_t fstn_dma;
0587 union fotg210_shadow fstn_next;
0588 } __aligned(32);
0589
0590
0591
0592
0593
0594 #define fotg210_prepare_ports_for_controller_suspend(fotg210, do_wakeup) \
0595 fotg210_adjust_port_wakeup_flags(fotg210, true, do_wakeup)
0596
0597 #define fotg210_prepare_ports_for_controller_resume(fotg210) \
0598 fotg210_adjust_port_wakeup_flags(fotg210, false, false)
0599
0600
0601
0602
0603
0604
0605
0606
0607
0608
0609 static inline unsigned int
0610 fotg210_get_speed(struct fotg210_hcd *fotg210, unsigned int portsc)
0611 {
0612 return (readl(&fotg210->regs->otgcsr)
0613 & OTGCSR_HOST_SPD_TYP) >> 22;
0614 }
0615
0616
0617 static inline unsigned int
0618 fotg210_port_speed(struct fotg210_hcd *fotg210, unsigned int portsc)
0619 {
0620 switch (fotg210_get_speed(fotg210, portsc)) {
0621 case 0:
0622 return 0;
0623 case 1:
0624 return USB_PORT_STAT_LOW_SPEED;
0625 case 2:
0626 default:
0627 return USB_PORT_STAT_HIGH_SPEED;
0628 }
0629 }
0630
0631
0632
0633 #define fotg210_has_fsl_portno_bug(e) (0)
0634
0635
0636
0637
0638
0639
0640
0641
0642
0643
0644
0645
0646 #define fotg210_big_endian_mmio(e) 0
0647 #define fotg210_big_endian_capbase(e) 0
0648
0649 static inline unsigned int fotg210_readl(const struct fotg210_hcd *fotg210,
0650 __u32 __iomem *regs)
0651 {
0652 return readl(regs);
0653 }
0654
0655 static inline void fotg210_writel(const struct fotg210_hcd *fotg210,
0656 const unsigned int val, __u32 __iomem *regs)
0657 {
0658 writel(val, regs);
0659 }
0660
0661
0662 static inline __hc32 cpu_to_hc32(const struct fotg210_hcd *fotg210, const u32 x)
0663 {
0664 return cpu_to_le32(x);
0665 }
0666
0667
0668 static inline u32 hc32_to_cpu(const struct fotg210_hcd *fotg210, const __hc32 x)
0669 {
0670 return le32_to_cpu(x);
0671 }
0672
0673 static inline u32 hc32_to_cpup(const struct fotg210_hcd *fotg210,
0674 const __hc32 *x)
0675 {
0676 return le32_to_cpup(x);
0677 }
0678
0679
0680
0681 static inline unsigned fotg210_read_frame_index(struct fotg210_hcd *fotg210)
0682 {
0683 return fotg210_readl(fotg210, &fotg210->regs->frame_index);
0684 }
0685
0686
0687
0688 #endif