source: rtems-libbsd/freebsd/sys/dev/usb/controller/saf1761_otg.h @ 1e77a45

5-freebsd-12
Last change on this file since 1e77a45 was 1e77a45, checked in by Sebastian Huber <sebastian.huber@…>, on Oct 4, 2018 at 10:06:44 AM

saf1761_otg: Use real interrupt handler

The USB_BUS_SPIN_LOCK() is only used internally to the bus driver.
Replace the mutex with an interrupt disable/enable section. Execute the
interrupt filter in a real interrupt context and forward the interrupt
handler to the interrupt server if necessary.

  • Property mode set to 100644
File size: 5.5 KB
Line 
1/* $FreeBSD$ */
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_OTG_H_
33#define _SAF1761_OTG_H_
34
35#ifdef __rtems__
36#include <rtems/irq-extension.h>
37#endif /* __rtems__ */
38#define SOTG_MAX_DEVICES MIN(USB_MAX_DEVICES, 32)
39#define SOTG_FS_MAX_PACKET_SIZE 64
40#define SOTG_HS_MAX_PACKET_SIZE 512
41#define SOTG_NUM_PORTS 2        /* one Device and one Host port */
42#define SOTG_HOST_PORT_NUM 1
43#define SOTG_DEVICE_PORT_NUM 2
44#define SOTG_HOST_CHANNEL_MAX (3 * 32)
45
46/* Macros used for reading and writing little endian registers */
47
48#define SAF1761_READ_LE_4(sc, reg) ({ uint32_t _temp; \
49  _temp = bus_space_read_4((sc)->sc_io_tag, (sc)->sc_io_hdl, (reg)); \
50  le32toh(_temp); })
51
52#define SAF1761_WRITE_LE_4(sc, reg, data) do { \
53  uint32_t _temp = (data); \
54  bus_space_write_4((sc)->sc_io_tag, (sc)->sc_io_hdl, (reg), htole32(_temp)); \
55} while (0)
56
57/* 90ns delay macro */
58
59#define SAF1761_90NS_DELAY(sc) do { \
60        (void) SAF1761_READ_LE_4(sc, SOTG_VEND_PROD_ID); \
61        (void) SAF1761_READ_LE_4(sc, SOTG_VEND_PROD_ID); \
62        (void) SAF1761_READ_LE_4(sc, SOTG_VEND_PROD_ID); \
63        (void) SAF1761_READ_LE_4(sc, SOTG_VEND_PROD_ID); \
64} while (0)
65
66struct saf1761_otg_softc;
67struct saf1761_otg_td;
68
69typedef uint8_t (saf1761_otg_cmd_t)(struct saf1761_otg_softc *, struct saf1761_otg_td *td);
70
71struct saf1761_otg_td {
72        struct saf1761_otg_td *obj_next;
73        saf1761_otg_cmd_t *func;
74        struct usb_page_cache *pc;
75        uint32_t offset;
76        uint32_t remainder;
77        uint32_t dw1_value;
78        uint16_t max_packet_size;
79        uint8_t ep_index;
80        uint8_t ep_type;
81        uint8_t channel;
82        uint8_t uframe;
83        uint8_t interval;
84        uint8_t error_any:1;
85        uint8_t error_stall:1;
86        uint8_t alt_next:1;
87        uint8_t short_pkt:1;
88        uint8_t did_stall:1;
89        uint8_t toggle:1;
90        uint8_t set_toggle:1;
91};
92
93struct saf1761_otg_std_temp {
94        saf1761_otg_cmd_t *func;
95        struct usb_page_cache *pc;
96        struct saf1761_otg_td *td;
97        struct saf1761_otg_td *td_next;
98        uint32_t len;
99        uint32_t offset;
100        uint16_t max_frame_size;
101        uint8_t short_pkt;
102        /*
103         * short_pkt = 0: transfer should be short terminated
104         * short_pkt = 1: transfer should not be short terminated
105         */
106        uint8_t setup_alt_next;
107        uint8_t did_stall;
108};
109
110struct saf1761_otg_config_desc {
111        struct usb_config_descriptor confd;
112        struct usb_interface_descriptor ifcd;
113        struct usb_endpoint_descriptor endpd;
114} __packed;
115
116union saf1761_otg_hub_temp {
117        uWord   wValue;
118        struct usb_port_status ps;
119};
120
121struct saf1761_otg_flags {
122        uint8_t change_connect:1;
123        uint8_t change_suspend:1;
124        uint8_t status_suspend:1;       /* set if suspended */
125        uint8_t status_vbus:1;          /* set if present */
126        uint8_t status_bus_reset:1;     /* set if reset complete */
127        uint8_t clocks_off:1;
128        uint8_t port_powered:1;
129        uint8_t port_enabled:1;
130        uint8_t d_pulled_up:1;
131};
132
133struct saf1761_otg_softc {
134        struct usb_bus sc_bus;
135        union saf1761_otg_hub_temp sc_hub_temp;
136
137        struct usb_device *sc_devices[SOTG_MAX_DEVICES];
138        struct resource *sc_io_res;
139        struct resource *sc_irq_res;
140        void   *sc_intr_hdl;
141        bus_size_t sc_io_size;
142        bus_space_tag_t sc_io_tag;
143        bus_space_handle_t sc_io_hdl;
144
145        uint32_t sc_host_async_busy_map[2];
146        uint32_t sc_host_async_map;
147        uint32_t sc_host_async_suspend_map;
148        uint32_t sc_host_intr_busy_map[2];
149        uint32_t sc_host_intr_map;
150        uint32_t sc_host_intr_suspend_map;
151        uint32_t sc_host_isoc_busy_map[2];
152        uint32_t sc_host_isoc_map;
153        uint32_t sc_host_isoc_suspend_map;
154        uint32_t sc_intr_enable;        /* enabled interrupts */
155        uint32_t sc_hw_mode;            /* hardware mode */
156        uint32_t sc_interrupt_cfg;      /* interrupt configuration */
157        uint32_t sc_xfer_complete;
158
159        uint32_t sc_bounce_buffer[1024 / 4];
160
161        uint8_t sc_rt_addr;             /* root HUB address */
162        uint8_t sc_dv_addr;             /* device address */
163        uint8_t sc_conf;                /* root HUB config */
164        uint8_t sc_isreset;             /* host mode */
165
166        uint8_t sc_hub_idata[1];
167
168        struct saf1761_otg_flags sc_flags;
169#ifdef __rtems__
170        rtems_interrupt_server_request sc_irq_srv_req;
171#endif /* __rtems__ */
172};
173
174/* prototypes */
175
176usb_error_t saf1761_otg_init(struct saf1761_otg_softc *sc);
177void    saf1761_otg_uninit(struct saf1761_otg_softc *sc);
178driver_filter_t saf1761_otg_filter_interrupt;
179driver_intr_t saf1761_otg_interrupt;
180
181#endif                                  /* _SAF1761_OTG_H_ */
Note: See TracBrowser for help on using the repository browser.