1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0+ */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * c67x00-hcd.h: Cypress C67X00 USB HCD
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Copyright (C) 2006-2008 Barco N.V.
6*4882a593Smuzhiyun * Derived from the Cypress cy7c67200/300 ezusb linux driver and
7*4882a593Smuzhiyun * based on multiple host controller drivers inside the linux kernel.
8*4882a593Smuzhiyun */
9*4882a593Smuzhiyun
10*4882a593Smuzhiyun #ifndef _USB_C67X00_HCD_H
11*4882a593Smuzhiyun #define _USB_C67X00_HCD_H
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun #include <linux/kernel.h>
14*4882a593Smuzhiyun #include <linux/spinlock.h>
15*4882a593Smuzhiyun #include <linux/list.h>
16*4882a593Smuzhiyun #include <linux/usb.h>
17*4882a593Smuzhiyun #include <linux/usb/hcd.h>
18*4882a593Smuzhiyun #include "c67x00.h"
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun /*
21*4882a593Smuzhiyun * The following parameters depend on the CPU speed, bus speed, ...
22*4882a593Smuzhiyun * These can be tuned for specific use cases, e.g. if isochronous transfers
23*4882a593Smuzhiyun * are very important, bandwidth can be sacrificed to guarantee that the
24*4882a593Smuzhiyun * 1ms deadline will be met.
25*4882a593Smuzhiyun * If bulk transfers are important, the MAX_FRAME_BW can be increased,
26*4882a593Smuzhiyun * but some (or many) isochronous deadlines might not be met.
27*4882a593Smuzhiyun *
28*4882a593Smuzhiyun * The values are specified in bittime.
29*4882a593Smuzhiyun */
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun /*
32*4882a593Smuzhiyun * The current implementation switches between _STD (default) and _ISO (when
33*4882a593Smuzhiyun * isochronous transfers are scheduled), in order to optimize the throughput
34*4882a593Smuzhiyun * in normal circumstances, but also provide good isochronous behaviour.
35*4882a593Smuzhiyun *
36*4882a593Smuzhiyun * Bandwidth is described in bit time so with a 12MHz USB clock and 1ms
37*4882a593Smuzhiyun * frames; there are 12000 bit times per frame.
38*4882a593Smuzhiyun */
39*4882a593Smuzhiyun
40*4882a593Smuzhiyun #define TOTAL_FRAME_BW 12000
41*4882a593Smuzhiyun #define DEFAULT_EOT 2250
42*4882a593Smuzhiyun
43*4882a593Smuzhiyun #define MAX_FRAME_BW_STD (TOTAL_FRAME_BW - DEFAULT_EOT)
44*4882a593Smuzhiyun #define MAX_FRAME_BW_ISO 2400
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun /*
47*4882a593Smuzhiyun * Periodic transfers may only use 90% of the full frame, but as
48*4882a593Smuzhiyun * we currently don't even use 90% of the full frame, we may
49*4882a593Smuzhiyun * use the full usable time for periodic transfers.
50*4882a593Smuzhiyun */
51*4882a593Smuzhiyun #define MAX_PERIODIC_BW(full_bw) full_bw
52*4882a593Smuzhiyun
53*4882a593Smuzhiyun /* -------------------------------------------------------------------------- */
54*4882a593Smuzhiyun
55*4882a593Smuzhiyun struct c67x00_hcd {
56*4882a593Smuzhiyun spinlock_t lock;
57*4882a593Smuzhiyun struct c67x00_sie *sie;
58*4882a593Smuzhiyun unsigned int low_speed_ports; /* bitmask of low speed ports */
59*4882a593Smuzhiyun unsigned int urb_count;
60*4882a593Smuzhiyun unsigned int urb_iso_count;
61*4882a593Smuzhiyun
62*4882a593Smuzhiyun struct list_head list[4]; /* iso, int, ctrl, bulk */
63*4882a593Smuzhiyun #if PIPE_BULK != 3
64*4882a593Smuzhiyun #error "Sanity check failed, this code presumes PIPE_... to range from 0 to 3"
65*4882a593Smuzhiyun #endif
66*4882a593Smuzhiyun
67*4882a593Smuzhiyun /* USB bandwidth allocated to td_list */
68*4882a593Smuzhiyun int bandwidth_allocated;
69*4882a593Smuzhiyun /* USB bandwidth allocated for isoc/int transfer */
70*4882a593Smuzhiyun int periodic_bw_allocated;
71*4882a593Smuzhiyun struct list_head td_list;
72*4882a593Smuzhiyun int max_frame_bw;
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun u16 td_base_addr;
75*4882a593Smuzhiyun u16 buf_base_addr;
76*4882a593Smuzhiyun u16 next_td_addr;
77*4882a593Smuzhiyun u16 next_buf_addr;
78*4882a593Smuzhiyun
79*4882a593Smuzhiyun struct tasklet_struct tasklet;
80*4882a593Smuzhiyun
81*4882a593Smuzhiyun struct completion endpoint_disable;
82*4882a593Smuzhiyun
83*4882a593Smuzhiyun u16 current_frame;
84*4882a593Smuzhiyun u16 last_frame;
85*4882a593Smuzhiyun };
86*4882a593Smuzhiyun
hcd_to_c67x00_hcd(struct usb_hcd * hcd)87*4882a593Smuzhiyun static inline struct c67x00_hcd *hcd_to_c67x00_hcd(struct usb_hcd *hcd)
88*4882a593Smuzhiyun {
89*4882a593Smuzhiyun return (struct c67x00_hcd *)(hcd->hcd_priv);
90*4882a593Smuzhiyun }
91*4882a593Smuzhiyun
c67x00_hcd_to_hcd(struct c67x00_hcd * c67x00)92*4882a593Smuzhiyun static inline struct usb_hcd *c67x00_hcd_to_hcd(struct c67x00_hcd *c67x00)
93*4882a593Smuzhiyun {
94*4882a593Smuzhiyun return container_of((void *)c67x00, struct usb_hcd, hcd_priv);
95*4882a593Smuzhiyun }
96*4882a593Smuzhiyun
97*4882a593Smuzhiyun /* ---------------------------------------------------------------------
98*4882a593Smuzhiyun * Functions used by c67x00-drv
99*4882a593Smuzhiyun */
100*4882a593Smuzhiyun
101*4882a593Smuzhiyun int c67x00_hcd_probe(struct c67x00_sie *sie);
102*4882a593Smuzhiyun void c67x00_hcd_remove(struct c67x00_sie *sie);
103*4882a593Smuzhiyun
104*4882a593Smuzhiyun /* ---------------------------------------------------------------------
105*4882a593Smuzhiyun * Transfer Descriptor scheduling functions
106*4882a593Smuzhiyun */
107*4882a593Smuzhiyun int c67x00_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags);
108*4882a593Smuzhiyun int c67x00_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status);
109*4882a593Smuzhiyun void c67x00_endpoint_disable(struct usb_hcd *hcd,
110*4882a593Smuzhiyun struct usb_host_endpoint *ep);
111*4882a593Smuzhiyun
112*4882a593Smuzhiyun void c67x00_hcd_msg_received(struct c67x00_sie *sie, u16 msg);
113*4882a593Smuzhiyun void c67x00_sched_kick(struct c67x00_hcd *c67x00);
114*4882a593Smuzhiyun int c67x00_sched_start_scheduler(struct c67x00_hcd *c67x00);
115*4882a593Smuzhiyun void c67x00_sched_stop_scheduler(struct c67x00_hcd *c67x00);
116*4882a593Smuzhiyun
117*4882a593Smuzhiyun #define c67x00_hcd_dev(x) (c67x00_hcd_to_hcd(x)->self.controller)
118*4882a593Smuzhiyun
119*4882a593Smuzhiyun #endif /* _USB_C67X00_HCD_H */
120