saf1761_otg.h revision 266214
1/* $FreeBSD: head/sys/dev/usb/controller/saf1761_dci.h 266214 2014-05-16 10:30:30Z hselasky $ */
2/*-
3 * Copyright (c) 2014 Hans Petter Selasky <hselasky@FreeBSD.org>
4 * All rights reserved.
5 *
6 * This software was developed by SRI International and the University of
7 * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)
8 * ("CTSRD"), as part of the DARPA CRASH research programme.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32#ifndef _SAF1761_DCI_H_
33#define	_SAF1761_DCI_H_
34
35#define	SOTG_MAX_DEVICES (USB_MIN_DEVICES + 1)
36#define	SOTG_FS_MAX_PACKET_SIZE 64
37#define	SOTG_HS_MAX_PACKET_SIZE 512
38
39#define	SAF1761_READ_1(sc, reg)	\
40  bus_space_read_1((sc)->sc_io_tag, (sc)->sc_io_hdl, reg)
41#define	SAF1761_READ_2(sc, reg)	\
42  bus_space_read_2((sc)->sc_io_tag, (sc)->sc_io_hdl, reg)
43#define	SAF1761_READ_4(sc, reg)	\
44  bus_space_read_4((sc)->sc_io_tag, (sc)->sc_io_hdl, reg)
45
46#define	SAF1761_WRITE_1(sc, reg, data)	\
47  bus_space_write_1((sc)->sc_io_tag, (sc)->sc_io_hdl, reg, data)
48#define	SAF1761_WRITE_2(sc, reg, data)	\
49  bus_space_write_2((sc)->sc_io_tag, (sc)->sc_io_hdl, reg, data)
50#define	SAF1761_WRITE_4(sc, reg, data)	\
51  bus_space_write_4((sc)->sc_io_tag, (sc)->sc_io_hdl, reg, data)
52
53struct saf1761_dci_softc;
54struct saf1761_dci_td;
55
56typedef uint8_t (saf1761_dci_cmd_t)(struct saf1761_dci_softc *, struct saf1761_dci_td *td);
57
58struct saf1761_dci_td {
59	struct saf1761_dci_td *obj_next;
60	saf1761_dci_cmd_t *func;
61	struct usb_page_cache *pc;
62	uint32_t offset;
63	uint32_t remainder;
64	uint16_t max_packet_size;
65	uint8_t	ep_index;
66	uint8_t	error:1;
67	uint8_t	alt_next:1;
68	uint8_t	short_pkt:1;
69	uint8_t	did_stall:1;
70};
71
72struct saf1761_dci_std_temp {
73	saf1761_dci_cmd_t *func;
74	struct usb_page_cache *pc;
75	struct saf1761_dci_td *td;
76	struct saf1761_dci_td *td_next;
77	uint32_t len;
78	uint32_t offset;
79	uint16_t max_frame_size;
80	uint8_t	short_pkt;
81	/*
82         * short_pkt = 0: transfer should be short terminated
83         * short_pkt = 1: transfer should not be short terminated
84         */
85	uint8_t	setup_alt_next;
86	uint8_t	did_stall;
87};
88
89struct saf1761_dci_config_desc {
90	struct usb_config_descriptor confd;
91	struct usb_interface_descriptor ifcd;
92	struct usb_endpoint_descriptor endpd;
93} __packed;
94
95union saf1761_dci_hub_temp {
96	uWord	wValue;
97	struct usb_port_status ps;
98};
99
100struct saf1761_dci_flags {
101	uint8_t	change_connect:1;
102	uint8_t	change_suspend:1;
103	uint8_t	status_suspend:1;	/* set if suspended */
104	uint8_t	status_vbus:1;		/* set if present */
105	uint8_t	status_bus_reset:1;	/* set if reset complete */
106	uint8_t	clocks_off:1;
107	uint8_t	port_powered:1;
108	uint8_t	port_enabled:1;
109	uint8_t	d_pulled_up:1;
110};
111
112struct saf1761_dci_softc {
113	struct usb_bus sc_bus;
114	union saf1761_dci_hub_temp sc_hub_temp;
115
116	struct usb_device *sc_devices[SOTG_MAX_DEVICES];
117	struct resource *sc_io_res;
118	struct resource *sc_irq_res;
119	void   *sc_intr_hdl;
120	bus_size_t sc_io_size;
121	bus_space_tag_t sc_io_tag;
122	bus_space_handle_t sc_io_hdl;
123
124	uint32_t sc_intr_enable;	/* enabled interrupts */
125	uint32_t sc_hw_mode;		/* hardware mode */
126
127	uint8_t	sc_rt_addr;		/* root HUB address */
128	uint8_t	sc_dv_addr;		/* device address */
129	uint8_t	sc_conf;		/* root HUB config */
130
131	uint8_t	sc_hub_idata[1];
132
133	struct saf1761_dci_flags sc_flags;
134};
135
136/* prototypes */
137
138usb_error_t saf1761_dci_init(struct saf1761_dci_softc *sc);
139void	saf1761_dci_uninit(struct saf1761_dci_softc *sc);
140void	saf1761_dci_interrupt(struct saf1761_dci_softc *sc);
141
142#endif					/* _SAF1761_DCI_H_ */
143