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