saf1761_otg.h revision 266644
1265908Shselasky/* $FreeBSD: head/sys/dev/usb/controller/saf1761_otg.h 266644 2014-05-25 06:42:43Z hselasky $ */
2265908Shselasky/*-
3266051Shselasky * Copyright (c) 2014 Hans Petter Selasky <hselasky@FreeBSD.org>
4265908Shselasky * All rights reserved.
5265908Shselasky *
6265908Shselasky * This software was developed by SRI International and the University of
7265908Shselasky * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)
8265908Shselasky * ("CTSRD"), as part of the DARPA CRASH research programme.
9265908Shselasky *
10265908Shselasky * Redistribution and use in source and binary forms, with or without
11265908Shselasky * modification, are permitted provided that the following conditions
12265908Shselasky * are met:
13265908Shselasky * 1. Redistributions of source code must retain the above copyright
14265908Shselasky *    notice, this list of conditions and the following disclaimer.
15265908Shselasky * 2. Redistributions in binary form must reproduce the above copyright
16265908Shselasky *    notice, this list of conditions and the following disclaimer in the
17265908Shselasky *    documentation and/or other materials provided with the distribution.
18265908Shselasky *
19265908Shselasky * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20265908Shselasky * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21265908Shselasky * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22265908Shselasky * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23265908Shselasky * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24265908Shselasky * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25265908Shselasky * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26265908Shselasky * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27265908Shselasky * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28265908Shselasky * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29265908Shselasky * SUCH DAMAGE.
30265908Shselasky */
31265908Shselasky
32266244Shselasky#ifndef _SAF1761_OTG_H_
33266244Shselasky#define	_SAF1761_OTG_H_
34265908Shselasky
35266051Shselasky#define	SOTG_MAX_DEVICES (USB_MIN_DEVICES + 1)
36266051Shselasky#define	SOTG_FS_MAX_PACKET_SIZE 64
37266051Shselasky#define	SOTG_HS_MAX_PACKET_SIZE 512
38266241Shselasky#define	SOTG_NUM_PORTS 2	/* one Device and one Host port */
39266241Shselasky#define	SOTG_HOST_PORT_NUM 1
40266241Shselasky#define	SOTG_DEVICE_PORT_NUM 2
41266241Shselasky#define	SOTG_HOST_CHANNEL_MAX (3 * 32)
42265908Shselasky
43266644Shselasky/* Macros used for reading and writing registers */
44266051Shselasky
45266644Shselasky#define	SAF1761_READ_1(sc, reg) \
46266644Shselasky  bus_space_read_1((sc)->sc_io_tag, (sc)->sc_io_hdl, (reg))
47266644Shselasky#define	SAF1761_READ_2(sc, reg)	({ uint16_t _temp; \
48266644Shselasky  _temp = bus_space_read_2((sc)->sc_io_tag, (sc)->sc_io_hdl, (reg)); \
49266644Shselasky  le16toh(_temp); })
50266644Shselasky#define	SAF1761_READ_4(sc, reg)	({ uint32_t _temp; \
51266644Shselasky  _temp = bus_space_read_4((sc)->sc_io_tag, (sc)->sc_io_hdl, (reg)); \
52266644Shselasky  le32toh(_temp); })
53266644Shselasky
54266051Shselasky#define	SAF1761_WRITE_1(sc, reg, data)	\
55266644Shselasky  bus_space_write_1((sc)->sc_io_tag, (sc)->sc_io_hdl, (reg), data)
56266644Shselasky#define	SAF1761_WRITE_2(sc, reg, data)	do { \
57266644Shselasky  uint16_t _temp = (data); \
58266644Shselasky  bus_space_write_2((sc)->sc_io_tag, (sc)->sc_io_hdl, (reg), htole16(_temp)); \
59266644Shselasky} while (0)
60266644Shselasky#define	SAF1761_WRITE_4(sc, reg, data)	do { \
61266644Shselasky  uint32_t _temp = (data); \
62266644Shselasky  bus_space_write_4((sc)->sc_io_tag, (sc)->sc_io_hdl, (reg), htole32(_temp)); \
63266644Shselasky} while (0)
64266051Shselasky
65266244Shselaskystruct saf1761_otg_softc;
66266244Shselaskystruct saf1761_otg_td;
67266051Shselasky
68266244Shselaskytypedef uint8_t (saf1761_otg_cmd_t)(struct saf1761_otg_softc *, struct saf1761_otg_td *td);
69266051Shselasky
70266244Shselaskystruct saf1761_otg_td {
71266244Shselasky	struct saf1761_otg_td *obj_next;
72266244Shselasky	saf1761_otg_cmd_t *func;
73266051Shselasky	struct usb_page_cache *pc;
74266051Shselasky	uint32_t offset;
75266051Shselasky	uint32_t remainder;
76266241Shselasky	uint32_t dw1_value;
77266051Shselasky	uint16_t max_packet_size;
78266051Shselasky	uint8_t	ep_index;
79266241Shselasky	uint8_t ep_type;
80266241Shselasky	uint8_t channel;
81266508Shselasky	uint8_t uframe;
82266508Shselasky	uint8_t interval;
83266241Shselasky	uint8_t	error_any:1;
84266241Shselasky	uint8_t	error_stall:1;
85266051Shselasky	uint8_t	alt_next:1;
86266051Shselasky	uint8_t	short_pkt:1;
87266051Shselasky	uint8_t	did_stall:1;
88266241Shselasky	uint8_t	toggle:1;
89266241Shselasky	uint8_t	set_toggle:1;
90266051Shselasky};
91266051Shselasky
92266244Shselaskystruct saf1761_otg_std_temp {
93266244Shselasky	saf1761_otg_cmd_t *func;
94266051Shselasky	struct usb_page_cache *pc;
95266244Shselasky	struct saf1761_otg_td *td;
96266244Shselasky	struct saf1761_otg_td *td_next;
97266051Shselasky	uint32_t len;
98266051Shselasky	uint32_t offset;
99266051Shselasky	uint16_t max_frame_size;
100266051Shselasky	uint8_t	short_pkt;
101266051Shselasky	/*
102266051Shselasky         * short_pkt = 0: transfer should be short terminated
103266051Shselasky         * short_pkt = 1: transfer should not be short terminated
104266051Shselasky         */
105266051Shselasky	uint8_t	setup_alt_next;
106266051Shselasky	uint8_t	did_stall;
107266051Shselasky};
108266051Shselasky
109266244Shselaskystruct saf1761_otg_config_desc {
110266051Shselasky	struct usb_config_descriptor confd;
111266051Shselasky	struct usb_interface_descriptor ifcd;
112266051Shselasky	struct usb_endpoint_descriptor endpd;
113266051Shselasky} __packed;
114266051Shselasky
115266244Shselaskyunion saf1761_otg_hub_temp {
116266051Shselasky	uWord	wValue;
117266051Shselasky	struct usb_port_status ps;
118266051Shselasky};
119266051Shselasky
120266244Shselaskystruct saf1761_otg_flags {
121266051Shselasky	uint8_t	change_connect:1;
122266051Shselasky	uint8_t	change_suspend:1;
123266051Shselasky	uint8_t	status_suspend:1;	/* set if suspended */
124266051Shselasky	uint8_t	status_vbus:1;		/* set if present */
125266051Shselasky	uint8_t	status_bus_reset:1;	/* set if reset complete */
126266051Shselasky	uint8_t	clocks_off:1;
127266051Shselasky	uint8_t	port_powered:1;
128266051Shselasky	uint8_t	port_enabled:1;
129266051Shselasky	uint8_t	d_pulled_up:1;
130266051Shselasky};
131266051Shselasky
132266244Shselaskystruct saf1761_otg_softc {
133266051Shselasky	struct usb_bus sc_bus;
134266244Shselasky	union saf1761_otg_hub_temp sc_hub_temp;
135266051Shselasky
136266051Shselasky	struct usb_device *sc_devices[SOTG_MAX_DEVICES];
137266051Shselasky	struct resource *sc_io_res;
138266051Shselasky	struct resource *sc_irq_res;
139266051Shselasky	void   *sc_intr_hdl;
140266051Shselasky	bus_size_t sc_io_size;
141266051Shselasky	bus_space_tag_t sc_io_tag;
142266051Shselasky	bus_space_handle_t sc_io_hdl;
143266051Shselasky
144266241Shselasky	uint32_t sc_host_async_map;
145266241Shselasky	uint32_t sc_host_intr_map;
146266241Shselasky	uint32_t sc_host_isoc_map;
147266051Shselasky	uint32_t sc_intr_enable;	/* enabled interrupts */
148266214Shselasky	uint32_t sc_hw_mode;		/* hardware mode */
149266051Shselasky
150266241Shselasky	uint8_t sc_bounce_buffer[1024] __aligned(4);
151266051Shselasky	uint8_t	sc_rt_addr;		/* root HUB address */
152266051Shselasky	uint8_t	sc_dv_addr;		/* device address */
153266051Shselasky	uint8_t	sc_conf;		/* root HUB config */
154266241Shselasky	uint8_t sc_isreset;		/* host mode */
155266051Shselasky
156266051Shselasky	uint8_t	sc_hub_idata[1];
157266051Shselasky
158266244Shselasky	struct saf1761_otg_flags sc_flags;
159266051Shselasky};
160266051Shselasky
161266051Shselasky/* prototypes */
162266051Shselasky
163266244Shselaskyusb_error_t saf1761_otg_init(struct saf1761_otg_softc *sc);
164266244Shselaskyvoid	saf1761_otg_uninit(struct saf1761_otg_softc *sc);
165266244Shselaskyvoid	saf1761_otg_interrupt(struct saf1761_otg_softc *sc);
166266051Shselasky
167266244Shselasky#endif					/* _SAF1761_OTG_H_ */
168