18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0+ */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * c67x00-hcd.h: Cypress C67X00 USB HCD
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2006-2008 Barco N.V.
68c2ecf20Sopenharmony_ci *    Derived from the Cypress cy7c67200/300 ezusb linux driver and
78c2ecf20Sopenharmony_ci *    based on multiple host controller drivers inside the linux kernel.
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#ifndef _USB_C67X00_HCD_H
118c2ecf20Sopenharmony_ci#define _USB_C67X00_HCD_H
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#include <linux/kernel.h>
148c2ecf20Sopenharmony_ci#include <linux/spinlock.h>
158c2ecf20Sopenharmony_ci#include <linux/list.h>
168c2ecf20Sopenharmony_ci#include <linux/usb.h>
178c2ecf20Sopenharmony_ci#include <linux/usb/hcd.h>
188c2ecf20Sopenharmony_ci#include "c67x00.h"
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci/*
218c2ecf20Sopenharmony_ci * The following parameters depend on the CPU speed, bus speed, ...
228c2ecf20Sopenharmony_ci * These can be tuned for specific use cases, e.g. if isochronous transfers
238c2ecf20Sopenharmony_ci * are very important, bandwidth can be sacrificed to guarantee that the
248c2ecf20Sopenharmony_ci * 1ms deadline will be met.
258c2ecf20Sopenharmony_ci * If bulk transfers are important, the MAX_FRAME_BW can be increased,
268c2ecf20Sopenharmony_ci * but some (or many) isochronous deadlines might not be met.
278c2ecf20Sopenharmony_ci *
288c2ecf20Sopenharmony_ci * The values are specified in bittime.
298c2ecf20Sopenharmony_ci */
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci/*
328c2ecf20Sopenharmony_ci * The current implementation switches between _STD (default) and _ISO (when
338c2ecf20Sopenharmony_ci * isochronous transfers are scheduled), in order to optimize the throughput
348c2ecf20Sopenharmony_ci * in normal circumstances, but also provide good isochronous behaviour.
358c2ecf20Sopenharmony_ci *
368c2ecf20Sopenharmony_ci * Bandwidth is described in bit time so with a 12MHz USB clock and 1ms
378c2ecf20Sopenharmony_ci * frames; there are 12000 bit times per frame.
388c2ecf20Sopenharmony_ci */
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci#define TOTAL_FRAME_BW		12000
418c2ecf20Sopenharmony_ci#define DEFAULT_EOT		2250
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci#define MAX_FRAME_BW_STD	(TOTAL_FRAME_BW - DEFAULT_EOT)
448c2ecf20Sopenharmony_ci#define MAX_FRAME_BW_ISO	2400
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci/*
478c2ecf20Sopenharmony_ci * Periodic transfers may only use 90% of the full frame, but as
488c2ecf20Sopenharmony_ci * we currently don't even use 90% of the full frame, we may
498c2ecf20Sopenharmony_ci * use the full usable time for periodic transfers.
508c2ecf20Sopenharmony_ci */
518c2ecf20Sopenharmony_ci#define MAX_PERIODIC_BW(full_bw)	full_bw
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci/* -------------------------------------------------------------------------- */
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_cistruct c67x00_hcd {
568c2ecf20Sopenharmony_ci	spinlock_t lock;
578c2ecf20Sopenharmony_ci	struct c67x00_sie *sie;
588c2ecf20Sopenharmony_ci	unsigned int low_speed_ports;	/* bitmask of low speed ports */
598c2ecf20Sopenharmony_ci	unsigned int urb_count;
608c2ecf20Sopenharmony_ci	unsigned int urb_iso_count;
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci	struct list_head list[4];	/* iso, int, ctrl, bulk */
638c2ecf20Sopenharmony_ci#if PIPE_BULK != 3
648c2ecf20Sopenharmony_ci#error "Sanity check failed, this code presumes PIPE_... to range from 0 to 3"
658c2ecf20Sopenharmony_ci#endif
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci	/* USB bandwidth allocated to td_list */
688c2ecf20Sopenharmony_ci	int bandwidth_allocated;
698c2ecf20Sopenharmony_ci	/* USB bandwidth allocated for isoc/int transfer */
708c2ecf20Sopenharmony_ci	int periodic_bw_allocated;
718c2ecf20Sopenharmony_ci	struct list_head td_list;
728c2ecf20Sopenharmony_ci	int max_frame_bw;
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci	u16 td_base_addr;
758c2ecf20Sopenharmony_ci	u16 buf_base_addr;
768c2ecf20Sopenharmony_ci	u16 next_td_addr;
778c2ecf20Sopenharmony_ci	u16 next_buf_addr;
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci	struct tasklet_struct tasklet;
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci	struct completion endpoint_disable;
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci	u16 current_frame;
848c2ecf20Sopenharmony_ci	u16 last_frame;
858c2ecf20Sopenharmony_ci};
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_cistatic inline struct c67x00_hcd *hcd_to_c67x00_hcd(struct usb_hcd *hcd)
888c2ecf20Sopenharmony_ci{
898c2ecf20Sopenharmony_ci	return (struct c67x00_hcd *)(hcd->hcd_priv);
908c2ecf20Sopenharmony_ci}
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_cistatic inline struct usb_hcd *c67x00_hcd_to_hcd(struct c67x00_hcd *c67x00)
938c2ecf20Sopenharmony_ci{
948c2ecf20Sopenharmony_ci	return container_of((void *)c67x00, struct usb_hcd, hcd_priv);
958c2ecf20Sopenharmony_ci}
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci/* ---------------------------------------------------------------------
988c2ecf20Sopenharmony_ci * Functions used by c67x00-drv
998c2ecf20Sopenharmony_ci */
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ciint c67x00_hcd_probe(struct c67x00_sie *sie);
1028c2ecf20Sopenharmony_civoid c67x00_hcd_remove(struct c67x00_sie *sie);
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci/* ---------------------------------------------------------------------
1058c2ecf20Sopenharmony_ci * Transfer Descriptor scheduling functions
1068c2ecf20Sopenharmony_ci */
1078c2ecf20Sopenharmony_ciint c67x00_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags);
1088c2ecf20Sopenharmony_ciint c67x00_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status);
1098c2ecf20Sopenharmony_civoid c67x00_endpoint_disable(struct usb_hcd *hcd,
1108c2ecf20Sopenharmony_ci			     struct usb_host_endpoint *ep);
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_civoid c67x00_hcd_msg_received(struct c67x00_sie *sie, u16 msg);
1138c2ecf20Sopenharmony_civoid c67x00_sched_kick(struct c67x00_hcd *c67x00);
1148c2ecf20Sopenharmony_ciint c67x00_sched_start_scheduler(struct c67x00_hcd *c67x00);
1158c2ecf20Sopenharmony_civoid c67x00_sched_stop_scheduler(struct c67x00_hcd *c67x00);
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci#define c67x00_hcd_dev(x)	(c67x00_hcd_to_hcd(x)->self.controller)
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci#endif				/* _USB_C67X00_HCD_H */
120