1 /* $NetBSD: motgvar.h,v 1.4 2014/09/13 18:36:39 jmcneill Exp $ */ 2 3 /* 4 * Copyright (c) 1998 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Lennart Augustsson (lennart@augustsson.net) at 9 * Carlstedt Research & Technology. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 #ifndef _MOTGVAR_H_ 34 #define _MOTGVAR_H_ 35 36 struct motg_pipe { 37 struct usbd_pipe pipe; 38 int nexttoggle; 39 struct motg_hw_ep *hw_ep; /* pointer to the hardware EP used */ 40 SIMPLEQ_ENTRY(motg_pipe) ep_pipe_list; 41 }; 42 43 /* description of a hardware endpoint */ 44 typedef enum { 45 IDLE = 0, 46 SETUP, 47 DATA_IN, 48 DATA_OUT, 49 STATUS_IN, 50 STATUS_OUT, 51 } usb_phase_t; 52 53 SIMPLEQ_HEAD(ep_pipes_head, motg_pipe); 54 struct motg_hw_ep { 55 int ep_number; 56 int ep_fifo_size; 57 usbd_xfer_handle xfer; /* active xfer on this EP */ 58 char *data; /* pointer to data to be transmitted/received */ 59 int datalen; /* data len to be transmitted */ 60 usb_phase_t phase; /* current phase of the transfer, if any */ 61 int refcount; /* how many devices using this EP */ 62 struct ep_pipes_head ep_pipes; /* list of pipes using this EP */ 63 bool need_short_xfer; 64 }; 65 #define MOTG_MAX_HW_EP 16 66 67 struct motg_softc { 68 device_t sc_dev; 69 struct usbd_bus sc_bus; 70 bus_space_tag_t sc_iot; 71 bus_space_handle_t sc_ioh; 72 int sc_size; 73 int sc_mode; 74 #define MOTG_MODE_HOST 0 75 #define MOTG_MODE_DEVICE 1 76 void (*sc_intr_poll)(void *); 77 void *sc_intr_poll_arg; 78 int sc_ep_max; 79 u_int sc_ep_fifosize; 80 81 uint16_t sc_intr_tx_ep; 82 uint16_t sc_intr_rx_ep; 83 uint8_t sc_intr_ctrl; 84 85 struct motg_hw_ep sc_in_ep[MOTG_MAX_HW_EP]; 86 struct motg_hw_ep sc_out_ep[MOTG_MAX_HW_EP]; 87 88 struct usb_dma_reserve sc_dma_reserve; 89 90 kmutex_t sc_lock; 91 kmutex_t sc_intr_lock; 92 int sc_dying; 93 94 pool_cache_t sc_xferpool; 95 96 /* Info for the root hub interrupt "pipe". */ 97 usbd_xfer_handle sc_intr_xfer; /* root hub interrupt transfer */ 98 uint8_t sc_root_addr; /* address of the root hub */ 99 uint8_t sc_root_conf; /* configuration of the root hub */ 100 101 char sc_vendor[32]; /* vendor string for root hub */ 102 int sc_id_vendor; /* vendor ID for root hub */ 103 104 int sc_port_enabled : 1; 105 int sc_port_enabled_changed : 1; 106 int sc_port_suspended : 1; 107 int sc_port_suspended_change : 1; 108 int sc_high_speed : 1; 109 int sc_connected : 1; 110 int sc_connected_changed : 1; 111 int sc_isreset : 1; 112 113 device_t sc_child; /* /dev/usb# device */ 114 }; 115 116 struct motg_xfer { 117 struct usbd_xfer xfer; 118 struct motg_softc *sc; 119 }; 120 121 #define UXFER(xfer) ((struct motg_xfer *)(xfer)) 122 123 124 usbd_status motg_init(struct motg_softc *); 125 int motg_intr(struct motg_softc *, uint16_t, uint16_t, uint8_t); 126 int motg_intr_vbus(struct motg_softc *, int); 127 int motg_detach(struct motg_softc *, int); 128 void motg_childdet(device_t, device_t); 129 int motg_activate(device_t, enum devact); 130 bool motg_resume(device_t, const pmf_qual_t *); 131 bool motg_suspend(device_t, const pmf_qual_t *); 132 133 #endif /* _MOTGVAR_H_ */ 134