Home | History | Annotate | Line # | Download | only in usb
      1 /*	$NetBSD: motgvar.h,v 1.6 2018/04/09 16:21:11 jakllsch 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 (at) 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 	struct usbd_xfer *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 	kmutex_t sc_lock;
     89 	kmutex_t sc_intr_lock;
     90 	int sc_dying;
     91 
     92 	pool_cache_t sc_xferpool;
     93 
     94 	/* Info for the root hub interrupt "pipe". */
     95 	struct usbd_xfer *sc_intr_xfer;	/* root hub interrupt transfer */
     96 
     97 	int	sc_port_enabled : 1;
     98 	int	sc_port_enabled_changed : 1;
     99 	int	sc_port_suspended : 1;
    100 	int	sc_port_suspended_change : 1;
    101 	int	sc_high_speed : 1;
    102 	int	sc_connected : 1;
    103 	int	sc_connected_changed : 1;
    104 	int	sc_isreset : 1;
    105 
    106 	device_t sc_child;		/* /dev/usb# device */
    107 };
    108 
    109 struct motg_xfer {
    110 	struct usbd_xfer xfer;
    111 };
    112 
    113 #define MOTG_BUS2SC(bus)	((bus)->ub_hcpriv)
    114 #define MOTG_PIPE2SC(pipe)	MOTG_BUS2SC((pipe)->up_dev->ud_bus)
    115 #define MOTG_XFER2SC(xfer)	MOTG_BUS2SC((xfer)->ux_bus)
    116 #define MOTG_MPIPE2SC(mpipe)	MOTG_BUS2SC((mpipe)->pipe.up_dev->ud_bus)
    117 
    118 #define MOTG_XFER2MXFER(xfer)	((struct motg_xfer *)(xfer))
    119 #define MOTG_PIPE2MPIPE(pipe)	((struct motg_pipe *)(pipe))
    120 
    121 int		motg_init(struct motg_softc *);
    122 int		motg_intr(struct motg_softc *, uint16_t, uint16_t, uint8_t);
    123 int		motg_intr_vbus(struct motg_softc *, int);
    124 int		motg_detach(struct motg_softc *, int);
    125 void		motg_childdet(device_t, device_t);
    126 int		motg_activate(device_t, enum devact);
    127 bool		motg_resume(device_t, const pmf_qual_t *);
    128 bool		motg_suspend(device_t, const pmf_qual_t *);
    129 
    130 #endif /* _MOTGVAR_H_ */
    131