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