blob: e3d493d4d61ae4a70e903e3cfba887e663aab344 [file] [log] [blame]
Peter Korsgaarde9b29ff2008-04-27 08:59:45 +02001/*
2 * c67x00-hcd.h: Cypress C67X00 USB HCD
3 *
4 * Copyright (C) 2006-2008 Barco N.V.
5 * Derived from the Cypress cy7c67200/300 ezusb linux driver and
6 * based on multiple host controller drivers inside the linux kernel.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 * MA 02110-1301 USA.
22 */
23
24#ifndef _USB_C67X00_HCD_H
25#define _USB_C67X00_HCD_H
26
27#include <linux/kernel.h>
28#include <linux/spinlock.h>
29#include <linux/list.h>
30#include <linux/usb.h>
Eric Lescouet27729aa2010-04-24 23:21:52 +020031#include <linux/usb/hcd.h>
Peter Korsgaarde9b29ff2008-04-27 08:59:45 +020032#include "c67x00.h"
33
34/*
35 * The following parameters depend on the CPU speed, bus speed, ...
36 * These can be tuned for specific use cases, e.g. if isochronous transfers
Lucas De Marchi25985ed2011-03-30 22:57:33 -030037 * are very important, bandwidth can be sacrificed to guarantee that the
Peter Korsgaarde9b29ff2008-04-27 08:59:45 +020038 * 1ms deadline will be met.
39 * If bulk transfers are important, the MAX_FRAME_BW can be increased,
40 * but some (or many) isochronous deadlines might not be met.
41 *
42 * The values are specified in bittime.
43 */
44
45/*
46 * The current implementation switches between _STD (default) and _ISO (when
47 * isochronous transfers are scheduled), in order to optimize the throughput
48 * in normal cicrumstances, but also provide good isochronous behaviour.
49 *
50 * Bandwidth is described in bit time so with a 12MHz USB clock and 1ms
51 * frames; there are 12000 bit times per frame.
52 */
53
54#define TOTAL_FRAME_BW 12000
55#define DEFAULT_EOT 2250
56
57#define MAX_FRAME_BW_STD (TOTAL_FRAME_BW - DEFAULT_EOT)
58#define MAX_FRAME_BW_ISO 2400
59
60/*
61 * Periodic transfers may only use 90% of the full frame, but as
62 * we currently don't even use 90% of the full frame, we may
63 * use the full usable time for periodic transfers.
64 */
65#define MAX_PERIODIC_BW(full_bw) full_bw
66
67/* -------------------------------------------------------------------------- */
68
69struct c67x00_hcd {
70 spinlock_t lock;
71 struct c67x00_sie *sie;
72 unsigned int low_speed_ports; /* bitmask of low speed ports */
73 unsigned int urb_count;
74 unsigned int urb_iso_count;
75
76 struct list_head list[4]; /* iso, int, ctrl, bulk */
77#if PIPE_BULK != 3
78#error "Sanity check failed, this code presumes PIPE_... to range from 0 to 3"
79#endif
80
81 /* USB bandwidth allocated to td_list */
82 int bandwidth_allocated;
83 /* USB bandwidth allocated for isoc/int transfer */
84 int periodic_bw_allocated;
85 struct list_head td_list;
86 int max_frame_bw;
87
88 u16 td_base_addr;
89 u16 buf_base_addr;
90 u16 next_td_addr;
91 u16 next_buf_addr;
92
93 struct tasklet_struct tasklet;
94
95 struct completion endpoint_disable;
96
97 u16 current_frame;
98 u16 last_frame;
99};
100
101static inline struct c67x00_hcd *hcd_to_c67x00_hcd(struct usb_hcd *hcd)
102{
103 return (struct c67x00_hcd *)(hcd->hcd_priv);
104}
105
106static inline struct usb_hcd *c67x00_hcd_to_hcd(struct c67x00_hcd *c67x00)
107{
108 return container_of((void *)c67x00, struct usb_hcd, hcd_priv);
109}
110
111/* ---------------------------------------------------------------------
112 * Functions used by c67x00-drv
113 */
114
115int c67x00_hcd_probe(struct c67x00_sie *sie);
116void c67x00_hcd_remove(struct c67x00_sie *sie);
117
118/* ---------------------------------------------------------------------
119 * Transfer Descriptor scheduling functions
120 */
121int c67x00_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags);
122int c67x00_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status);
123void c67x00_endpoint_disable(struct usb_hcd *hcd,
124 struct usb_host_endpoint *ep);
125
126void c67x00_hcd_msg_received(struct c67x00_sie *sie, u16 msg);
127void c67x00_sched_kick(struct c67x00_hcd *c67x00);
128int c67x00_sched_start_scheduler(struct c67x00_hcd *c67x00);
129void c67x00_sched_stop_scheduler(struct c67x00_hcd *c67x00);
130
131#define c67x00_hcd_dev(x) (c67x00_hcd_to_hcd(x)->self.controller)
132
133#endif /* _USB_C67X00_HCD_H */