xref: /freebsd/sys/dev/usb/controller/uss820dci.c (revision 5d38a4d4f7a511cc431d45ea7d7692d44f9fae00)
102ac6454SAndrew Thompson /* $FreeBSD$ */
202ac6454SAndrew Thompson /*-
35d38a4d4SEd Schouten  * Copyright (c) 2008 Hans Petter Selasky <hselasky@FreeBSD.org>
402ac6454SAndrew Thompson  * All rights reserved.
502ac6454SAndrew Thompson  *
602ac6454SAndrew Thompson  * Redistribution and use in source and binary forms, with or without
702ac6454SAndrew Thompson  * modification, are permitted provided that the following conditions
802ac6454SAndrew Thompson  * are met:
902ac6454SAndrew Thompson  * 1. Redistributions of source code must retain the above copyright
1002ac6454SAndrew Thompson  *    notice, this list of conditions and the following disclaimer.
1102ac6454SAndrew Thompson  * 2. Redistributions in binary form must reproduce the above copyright
1202ac6454SAndrew Thompson  *    notice, this list of conditions and the following disclaimer in the
1302ac6454SAndrew Thompson  *    documentation and/or other materials provided with the distribution.
1402ac6454SAndrew Thompson  *
1502ac6454SAndrew Thompson  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1602ac6454SAndrew Thompson  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1702ac6454SAndrew Thompson  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1802ac6454SAndrew Thompson  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1902ac6454SAndrew Thompson  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2002ac6454SAndrew Thompson  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2102ac6454SAndrew Thompson  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2202ac6454SAndrew Thompson  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2302ac6454SAndrew Thompson  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2402ac6454SAndrew Thompson  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2502ac6454SAndrew Thompson  * SUCH DAMAGE.
2602ac6454SAndrew Thompson  */
2702ac6454SAndrew Thompson 
2802ac6454SAndrew Thompson /*
2902ac6454SAndrew Thompson  * This file contains the driver for the USS820 series USB Device
3002ac6454SAndrew Thompson  * Controller
3102ac6454SAndrew Thompson  *
3202ac6454SAndrew Thompson  * NOTE: The datasheet does not document everything!
3302ac6454SAndrew Thompson  */
3402ac6454SAndrew Thompson 
3502ac6454SAndrew Thompson #include <dev/usb/usb.h>
3602ac6454SAndrew Thompson #include <dev/usb/usb_mfunc.h>
3702ac6454SAndrew Thompson #include <dev/usb/usb_revision.h>
3802ac6454SAndrew Thompson #include <dev/usb/usb_error.h>
3902ac6454SAndrew Thompson #include <dev/usb/usb_defs.h>
4002ac6454SAndrew Thompson 
4102ac6454SAndrew Thompson #define	USB_DEBUG_VAR uss820dcidebug
4202ac6454SAndrew Thompson 
4302ac6454SAndrew Thompson #include <dev/usb/usb_core.h>
4402ac6454SAndrew Thompson #include <dev/usb/usb_debug.h>
4502ac6454SAndrew Thompson #include <dev/usb/usb_busdma.h>
4602ac6454SAndrew Thompson #include <dev/usb/usb_process.h>
4702ac6454SAndrew Thompson #include <dev/usb/usb_sw_transfer.h>
4802ac6454SAndrew Thompson #include <dev/usb/usb_transfer.h>
4902ac6454SAndrew Thompson #include <dev/usb/usb_device.h>
5002ac6454SAndrew Thompson #include <dev/usb/usb_hub.h>
5102ac6454SAndrew Thompson #include <dev/usb/usb_util.h>
5202ac6454SAndrew Thompson 
5302ac6454SAndrew Thompson #include <dev/usb/usb_controller.h>
5402ac6454SAndrew Thompson #include <dev/usb/usb_bus.h>
5502ac6454SAndrew Thompson #include <dev/usb/controller/uss820dci.h>
5602ac6454SAndrew Thompson 
5702ac6454SAndrew Thompson #define	USS820_DCI_BUS2SC(bus) \
5802ac6454SAndrew Thompson    ((struct uss820dci_softc *)(((uint8_t *)(bus)) - \
5902ac6454SAndrew Thompson    USB_P2U(&(((struct uss820dci_softc *)0)->sc_bus))))
6002ac6454SAndrew Thompson 
6102ac6454SAndrew Thompson #define	USS820_DCI_PC2SC(pc) \
6202ac6454SAndrew Thompson    USS820_DCI_BUS2SC((pc)->tag_parent->info->bus)
6302ac6454SAndrew Thompson 
6402ac6454SAndrew Thompson #if USB_DEBUG
6502ac6454SAndrew Thompson static int uss820dcidebug = 0;
6602ac6454SAndrew Thompson 
6702ac6454SAndrew Thompson SYSCTL_NODE(_hw_usb2, OID_AUTO, uss820dci, CTLFLAG_RW, 0, "USB uss820dci");
6802ac6454SAndrew Thompson SYSCTL_INT(_hw_usb2_uss820dci, OID_AUTO, debug, CTLFLAG_RW,
6902ac6454SAndrew Thompson     &uss820dcidebug, 0, "uss820dci debug level");
7002ac6454SAndrew Thompson #endif
7102ac6454SAndrew Thompson 
7202ac6454SAndrew Thompson #define	USS820_DCI_INTR_ENDPT 1
7302ac6454SAndrew Thompson 
7402ac6454SAndrew Thompson /* prototypes */
7502ac6454SAndrew Thompson 
7602ac6454SAndrew Thompson struct usb2_bus_methods uss820dci_bus_methods;
7702ac6454SAndrew Thompson struct usb2_pipe_methods uss820dci_device_bulk_methods;
7802ac6454SAndrew Thompson struct usb2_pipe_methods uss820dci_device_ctrl_methods;
7902ac6454SAndrew Thompson struct usb2_pipe_methods uss820dci_device_intr_methods;
8002ac6454SAndrew Thompson struct usb2_pipe_methods uss820dci_device_isoc_fs_methods;
8102ac6454SAndrew Thompson struct usb2_pipe_methods uss820dci_root_ctrl_methods;
8202ac6454SAndrew Thompson struct usb2_pipe_methods uss820dci_root_intr_methods;
8302ac6454SAndrew Thompson 
8402ac6454SAndrew Thompson static uss820dci_cmd_t uss820dci_setup_rx;
8502ac6454SAndrew Thompson static uss820dci_cmd_t uss820dci_data_rx;
8602ac6454SAndrew Thompson static uss820dci_cmd_t uss820dci_data_tx;
8702ac6454SAndrew Thompson static uss820dci_cmd_t uss820dci_data_tx_sync;
8802ac6454SAndrew Thompson static void	uss820dci_device_done(struct usb2_xfer *, usb2_error_t);
8902ac6454SAndrew Thompson static void	uss820dci_do_poll(struct usb2_bus *);
9002ac6454SAndrew Thompson static void	uss820dci_root_ctrl_poll(struct uss820dci_softc *);
9102ac6454SAndrew Thompson static void	uss820dci_standard_done(struct usb2_xfer *);
9202ac6454SAndrew Thompson static void	uss820dci_intr_set(struct usb2_xfer *, uint8_t);
9302ac6454SAndrew Thompson static void	uss820dci_update_shared_1(struct uss820dci_softc *, uint8_t,
9402ac6454SAndrew Thompson 		    uint8_t, uint8_t);
9502ac6454SAndrew Thompson 
9602ac6454SAndrew Thompson static usb2_sw_transfer_func_t uss820dci_root_intr_done;
9702ac6454SAndrew Thompson static usb2_sw_transfer_func_t uss820dci_root_ctrl_done;
9802ac6454SAndrew Thompson 
9902ac6454SAndrew Thompson /*
10002ac6454SAndrew Thompson  * Here is a list of what the USS820D chip can support. The main
10102ac6454SAndrew Thompson  * limitation is that the sum of the buffer sizes must be less than
10202ac6454SAndrew Thompson  * 1120 bytes.
10302ac6454SAndrew Thompson  */
10402ac6454SAndrew Thompson static const struct usb2_hw_ep_profile
10502ac6454SAndrew Thompson 	uss820dci_ep_profile[] = {
10602ac6454SAndrew Thompson 
10702ac6454SAndrew Thompson 	[0] = {
10802ac6454SAndrew Thompson 		.max_in_frame_size = 32,
10902ac6454SAndrew Thompson 		.max_out_frame_size = 32,
11002ac6454SAndrew Thompson 		.is_simplex = 0,
11102ac6454SAndrew Thompson 		.support_control = 1,
11202ac6454SAndrew Thompson 	},
11302ac6454SAndrew Thompson 	[1] = {
11402ac6454SAndrew Thompson 		.max_in_frame_size = 64,
11502ac6454SAndrew Thompson 		.max_out_frame_size = 64,
11602ac6454SAndrew Thompson 		.is_simplex = 0,
11702ac6454SAndrew Thompson 		.support_multi_buffer = 1,
11802ac6454SAndrew Thompson 		.support_bulk = 1,
11902ac6454SAndrew Thompson 		.support_interrupt = 1,
12002ac6454SAndrew Thompson 		.support_in = 1,
12102ac6454SAndrew Thompson 		.support_out = 1,
12202ac6454SAndrew Thompson 	},
12302ac6454SAndrew Thompson 	[2] = {
12402ac6454SAndrew Thompson 		.max_in_frame_size = 8,
12502ac6454SAndrew Thompson 		.max_out_frame_size = 8,
12602ac6454SAndrew Thompson 		.is_simplex = 0,
12702ac6454SAndrew Thompson 		.support_multi_buffer = 1,
12802ac6454SAndrew Thompson 		.support_bulk = 1,
12902ac6454SAndrew Thompson 		.support_interrupt = 1,
13002ac6454SAndrew Thompson 		.support_in = 1,
13102ac6454SAndrew Thompson 		.support_out = 1,
13202ac6454SAndrew Thompson 	},
13302ac6454SAndrew Thompson 	[3] = {
13402ac6454SAndrew Thompson 		.max_in_frame_size = 256,
13502ac6454SAndrew Thompson 		.max_out_frame_size = 256,
13602ac6454SAndrew Thompson 		.is_simplex = 0,
13702ac6454SAndrew Thompson 		.support_multi_buffer = 1,
13802ac6454SAndrew Thompson 		.support_isochronous = 1,
13902ac6454SAndrew Thompson 		.support_in = 1,
14002ac6454SAndrew Thompson 		.support_out = 1,
14102ac6454SAndrew Thompson 	},
14202ac6454SAndrew Thompson };
14302ac6454SAndrew Thompson 
14402ac6454SAndrew Thompson static void
14502ac6454SAndrew Thompson uss820dci_update_shared_1(struct uss820dci_softc *sc, uint8_t reg,
14602ac6454SAndrew Thompson     uint8_t keep_mask, uint8_t set_mask)
14702ac6454SAndrew Thompson {
14802ac6454SAndrew Thompson 	uint8_t temp;
14902ac6454SAndrew Thompson 
15002ac6454SAndrew Thompson 	USS820_WRITE_1(sc, USS820_PEND, 1);
15102ac6454SAndrew Thompson 	temp = USS820_READ_1(sc, reg);
15202ac6454SAndrew Thompson 	temp &= (keep_mask);
15302ac6454SAndrew Thompson 	temp |= (set_mask);
15402ac6454SAndrew Thompson 	USS820_WRITE_1(sc, reg, temp);
15502ac6454SAndrew Thompson 	USS820_WRITE_1(sc, USS820_PEND, 0);
15602ac6454SAndrew Thompson }
15702ac6454SAndrew Thompson 
15802ac6454SAndrew Thompson static void
15902ac6454SAndrew Thompson uss820dci_get_hw_ep_profile(struct usb2_device *udev,
16002ac6454SAndrew Thompson     const struct usb2_hw_ep_profile **ppf, uint8_t ep_addr)
16102ac6454SAndrew Thompson {
16202ac6454SAndrew Thompson 	if (ep_addr == 0) {
16302ac6454SAndrew Thompson 		*ppf = uss820dci_ep_profile + 0;
16402ac6454SAndrew Thompson 	} else if (ep_addr < 5) {
16502ac6454SAndrew Thompson 		*ppf = uss820dci_ep_profile + 1;
16602ac6454SAndrew Thompson 	} else if (ep_addr < 7) {
16702ac6454SAndrew Thompson 		*ppf = uss820dci_ep_profile + 2;
16802ac6454SAndrew Thompson 	} else if (ep_addr == 7) {
16902ac6454SAndrew Thompson 		*ppf = uss820dci_ep_profile + 3;
17002ac6454SAndrew Thompson 	} else {
17102ac6454SAndrew Thompson 		*ppf = NULL;
17202ac6454SAndrew Thompson 	}
17302ac6454SAndrew Thompson }
17402ac6454SAndrew Thompson 
17502ac6454SAndrew Thompson static void
17602ac6454SAndrew Thompson uss820dci_pull_up(struct uss820dci_softc *sc)
17702ac6454SAndrew Thompson {
17802ac6454SAndrew Thompson 	uint8_t temp;
17902ac6454SAndrew Thompson 
18002ac6454SAndrew Thompson 	/* pullup D+, if possible */
18102ac6454SAndrew Thompson 
18202ac6454SAndrew Thompson 	if (!sc->sc_flags.d_pulled_up &&
18302ac6454SAndrew Thompson 	    sc->sc_flags.port_powered) {
18402ac6454SAndrew Thompson 		sc->sc_flags.d_pulled_up = 1;
18502ac6454SAndrew Thompson 
18602ac6454SAndrew Thompson 		DPRINTF("\n");
18702ac6454SAndrew Thompson 
18802ac6454SAndrew Thompson 		temp = USS820_READ_1(sc, USS820_MCSR);
18902ac6454SAndrew Thompson 		temp |= USS820_MCSR_DPEN;
19002ac6454SAndrew Thompson 		USS820_WRITE_1(sc, USS820_MCSR, temp);
19102ac6454SAndrew Thompson 	}
19202ac6454SAndrew Thompson }
19302ac6454SAndrew Thompson 
19402ac6454SAndrew Thompson static void
19502ac6454SAndrew Thompson uss820dci_pull_down(struct uss820dci_softc *sc)
19602ac6454SAndrew Thompson {
19702ac6454SAndrew Thompson 	uint8_t temp;
19802ac6454SAndrew Thompson 
19902ac6454SAndrew Thompson 	/* pulldown D+, if possible */
20002ac6454SAndrew Thompson 
20102ac6454SAndrew Thompson 	if (sc->sc_flags.d_pulled_up) {
20202ac6454SAndrew Thompson 		sc->sc_flags.d_pulled_up = 0;
20302ac6454SAndrew Thompson 
20402ac6454SAndrew Thompson 		DPRINTF("\n");
20502ac6454SAndrew Thompson 
20602ac6454SAndrew Thompson 		temp = USS820_READ_1(sc, USS820_MCSR);
20702ac6454SAndrew Thompson 		temp &= ~USS820_MCSR_DPEN;
20802ac6454SAndrew Thompson 		USS820_WRITE_1(sc, USS820_MCSR, temp);
20902ac6454SAndrew Thompson 	}
21002ac6454SAndrew Thompson }
21102ac6454SAndrew Thompson 
21202ac6454SAndrew Thompson static void
21302ac6454SAndrew Thompson uss820dci_wakeup_peer(struct uss820dci_softc *sc)
21402ac6454SAndrew Thompson {
21502ac6454SAndrew Thompson 	if (!(sc->sc_flags.status_suspend)) {
21602ac6454SAndrew Thompson 		return;
21702ac6454SAndrew Thompson 	}
21802ac6454SAndrew Thompson 	DPRINTFN(0, "not supported\n");
21902ac6454SAndrew Thompson }
22002ac6454SAndrew Thompson 
22102ac6454SAndrew Thompson static void
22202ac6454SAndrew Thompson uss820dci_set_address(struct uss820dci_softc *sc, uint8_t addr)
22302ac6454SAndrew Thompson {
22402ac6454SAndrew Thompson 	DPRINTFN(5, "addr=%d\n", addr);
22502ac6454SAndrew Thompson 
22602ac6454SAndrew Thompson 	USS820_WRITE_1(sc, USS820_FADDR, addr);
22702ac6454SAndrew Thompson }
22802ac6454SAndrew Thompson 
22902ac6454SAndrew Thompson static uint8_t
23002ac6454SAndrew Thompson uss820dci_setup_rx(struct uss820dci_td *td)
23102ac6454SAndrew Thompson {
23202ac6454SAndrew Thompson 	struct uss820dci_softc *sc;
23302ac6454SAndrew Thompson 	struct usb2_device_request req;
23402ac6454SAndrew Thompson 	uint16_t count;
23502ac6454SAndrew Thompson 	uint8_t rx_stat;
23602ac6454SAndrew Thompson 	uint8_t temp;
23702ac6454SAndrew Thompson 
23802ac6454SAndrew Thompson 	/* select the correct endpoint */
23902ac6454SAndrew Thompson 	bus_space_write_1(td->io_tag, td->io_hdl,
24002ac6454SAndrew Thompson 	    td->ep_reg, td->ep_index);
24102ac6454SAndrew Thompson 
24202ac6454SAndrew Thompson 	/* read out FIFO status */
24302ac6454SAndrew Thompson 	rx_stat = bus_space_read_1(td->io_tag, td->io_hdl,
24402ac6454SAndrew Thompson 	    td->rx_stat_reg);
24502ac6454SAndrew Thompson 
24602ac6454SAndrew Thompson 	/* get pointer to softc */
24702ac6454SAndrew Thompson 	sc = USS820_DCI_PC2SC(td->pc);
24802ac6454SAndrew Thompson 
24902ac6454SAndrew Thompson 	DPRINTFN(5, "rx_stat=0x%02x rem=%u\n", rx_stat, td->remainder);
25002ac6454SAndrew Thompson 
25102ac6454SAndrew Thompson 	if (!(rx_stat & USS820_RXSTAT_RXSETUP)) {
25202ac6454SAndrew Thompson 		/* abort any ongoing transfer */
25302ac6454SAndrew Thompson 		if (!td->did_stall) {
25402ac6454SAndrew Thompson 			DPRINTFN(5, "stalling\n");
25502ac6454SAndrew Thompson 
25602ac6454SAndrew Thompson 			/* set stall */
25702ac6454SAndrew Thompson 
25802ac6454SAndrew Thompson 			uss820dci_update_shared_1(sc, USS820_EPCON, 0xFF,
25902ac6454SAndrew Thompson 			    (USS820_EPCON_TXSTL | USS820_EPCON_RXSTL));
26002ac6454SAndrew Thompson 
26102ac6454SAndrew Thompson 			td->did_stall = 1;
26202ac6454SAndrew Thompson 		}
26302ac6454SAndrew Thompson 		goto not_complete;
26402ac6454SAndrew Thompson 	}
26502ac6454SAndrew Thompson 	/* clear stall and all I/O */
26602ac6454SAndrew Thompson 	uss820dci_update_shared_1(sc, USS820_EPCON,
26702ac6454SAndrew Thompson 	    0xFF ^ (USS820_EPCON_TXSTL |
26802ac6454SAndrew Thompson 	    USS820_EPCON_RXSTL |
26902ac6454SAndrew Thompson 	    USS820_EPCON_RXIE |
27002ac6454SAndrew Thompson 	    USS820_EPCON_TXOE), 0);
27102ac6454SAndrew Thompson 
27202ac6454SAndrew Thompson 	/* clear end overwrite flag */
27302ac6454SAndrew Thompson 	uss820dci_update_shared_1(sc, USS820_RXSTAT,
27402ac6454SAndrew Thompson 	    0xFF ^ USS820_RXSTAT_EDOVW, 0);
27502ac6454SAndrew Thompson 
27602ac6454SAndrew Thompson 	/* get the packet byte count */
27702ac6454SAndrew Thompson 	count = bus_space_read_1(td->io_tag, td->io_hdl,
27802ac6454SAndrew Thompson 	    td->rx_count_low_reg);
27902ac6454SAndrew Thompson 	count |= (bus_space_read_1(td->io_tag, td->io_hdl,
28002ac6454SAndrew Thompson 	    td->rx_count_high_reg) << 8);
28102ac6454SAndrew Thompson 	count &= 0x3FF;
28202ac6454SAndrew Thompson 
28302ac6454SAndrew Thompson 	/* verify data length */
28402ac6454SAndrew Thompson 	if (count != td->remainder) {
28502ac6454SAndrew Thompson 		DPRINTFN(0, "Invalid SETUP packet "
28602ac6454SAndrew Thompson 		    "length, %d bytes\n", count);
28702ac6454SAndrew Thompson 		goto not_complete;
28802ac6454SAndrew Thompson 	}
28902ac6454SAndrew Thompson 	if (count != sizeof(req)) {
29002ac6454SAndrew Thompson 		DPRINTFN(0, "Unsupported SETUP packet "
29102ac6454SAndrew Thompson 		    "length, %d bytes\n", count);
29202ac6454SAndrew Thompson 		goto not_complete;
29302ac6454SAndrew Thompson 	}
29402ac6454SAndrew Thompson 	/* receive data */
29502ac6454SAndrew Thompson 	bus_space_read_multi_1(td->io_tag, td->io_hdl,
29602ac6454SAndrew Thompson 	    td->rx_fifo_reg, (void *)&req, sizeof(req));
29702ac6454SAndrew Thompson 
29802ac6454SAndrew Thompson 	/* read out FIFO status */
29902ac6454SAndrew Thompson 	rx_stat = bus_space_read_1(td->io_tag, td->io_hdl,
30002ac6454SAndrew Thompson 	    td->rx_stat_reg);
30102ac6454SAndrew Thompson 
30202ac6454SAndrew Thompson 	if (rx_stat & (USS820_RXSTAT_EDOVW |
30302ac6454SAndrew Thompson 	    USS820_RXSTAT_STOVW)) {
30402ac6454SAndrew Thompson 		DPRINTF("new SETUP packet received\n");
30502ac6454SAndrew Thompson 		return (1);		/* not complete */
30602ac6454SAndrew Thompson 	}
30702ac6454SAndrew Thompson 	/* clear receive setup bit */
30802ac6454SAndrew Thompson 	uss820dci_update_shared_1(sc, USS820_RXSTAT,
30902ac6454SAndrew Thompson 	    0xFF ^ (USS820_RXSTAT_RXSETUP |
31002ac6454SAndrew Thompson 	    USS820_RXSTAT_EDOVW |
31102ac6454SAndrew Thompson 	    USS820_RXSTAT_STOVW), 0);
31202ac6454SAndrew Thompson 
31302ac6454SAndrew Thompson 	/* set RXFFRC bit */
31402ac6454SAndrew Thompson 	temp = bus_space_read_1(td->io_tag, td->io_hdl,
31502ac6454SAndrew Thompson 	    td->rx_cntl_reg);
31602ac6454SAndrew Thompson 	temp |= USS820_RXCON_RXFFRC;
31702ac6454SAndrew Thompson 	bus_space_write_1(td->io_tag, td->io_hdl,
31802ac6454SAndrew Thompson 	    td->rx_cntl_reg, temp);
31902ac6454SAndrew Thompson 
32002ac6454SAndrew Thompson 	/* copy data into real buffer */
32102ac6454SAndrew Thompson 	usb2_copy_in(td->pc, 0, &req, sizeof(req));
32202ac6454SAndrew Thompson 
32302ac6454SAndrew Thompson 	td->offset = sizeof(req);
32402ac6454SAndrew Thompson 	td->remainder = 0;
32502ac6454SAndrew Thompson 
32602ac6454SAndrew Thompson 	/* sneak peek the set address */
32702ac6454SAndrew Thompson 	if ((req.bmRequestType == UT_WRITE_DEVICE) &&
32802ac6454SAndrew Thompson 	    (req.bRequest == UR_SET_ADDRESS)) {
32902ac6454SAndrew Thompson 		sc->sc_dv_addr = req.wValue[0] & 0x7F;
33002ac6454SAndrew Thompson 	} else {
33102ac6454SAndrew Thompson 		sc->sc_dv_addr = 0xFF;
33202ac6454SAndrew Thompson 	}
33302ac6454SAndrew Thompson 	return (0);			/* complete */
33402ac6454SAndrew Thompson 
33502ac6454SAndrew Thompson not_complete:
33602ac6454SAndrew Thompson 	/* clear end overwrite flag, if any */
33702ac6454SAndrew Thompson 	if (rx_stat & USS820_RXSTAT_RXSETUP) {
33802ac6454SAndrew Thompson 		uss820dci_update_shared_1(sc, USS820_RXSTAT,
33902ac6454SAndrew Thompson 		    0xFF ^ (USS820_RXSTAT_EDOVW |
34002ac6454SAndrew Thompson 		    USS820_RXSTAT_STOVW |
34102ac6454SAndrew Thompson 		    USS820_RXSTAT_RXSETUP), 0);
34202ac6454SAndrew Thompson 	}
34302ac6454SAndrew Thompson 	return (1);			/* not complete */
34402ac6454SAndrew Thompson 
34502ac6454SAndrew Thompson }
34602ac6454SAndrew Thompson 
34702ac6454SAndrew Thompson static uint8_t
34802ac6454SAndrew Thompson uss820dci_data_rx(struct uss820dci_td *td)
34902ac6454SAndrew Thompson {
35002ac6454SAndrew Thompson 	struct usb2_page_search buf_res;
35102ac6454SAndrew Thompson 	uint16_t count;
35202ac6454SAndrew Thompson 	uint8_t rx_flag;
35302ac6454SAndrew Thompson 	uint8_t rx_stat;
35402ac6454SAndrew Thompson 	uint8_t rx_cntl;
35502ac6454SAndrew Thompson 	uint8_t to;
35602ac6454SAndrew Thompson 	uint8_t got_short;
35702ac6454SAndrew Thompson 
35802ac6454SAndrew Thompson 	to = 2;				/* don't loop forever! */
35902ac6454SAndrew Thompson 	got_short = 0;
36002ac6454SAndrew Thompson 
36102ac6454SAndrew Thompson 	/* select the correct endpoint */
36202ac6454SAndrew Thompson 	bus_space_write_1(td->io_tag, td->io_hdl, td->ep_reg, td->ep_index);
36302ac6454SAndrew Thompson 
36402ac6454SAndrew Thompson 	/* check if any of the FIFO banks have data */
36502ac6454SAndrew Thompson repeat:
36602ac6454SAndrew Thompson 	/* read out FIFO flag */
36702ac6454SAndrew Thompson 	rx_flag = bus_space_read_1(td->io_tag, td->io_hdl,
36802ac6454SAndrew Thompson 	    td->rx_flag_reg);
36902ac6454SAndrew Thompson 	/* read out FIFO status */
37002ac6454SAndrew Thompson 	rx_stat = bus_space_read_1(td->io_tag, td->io_hdl,
37102ac6454SAndrew Thompson 	    td->rx_stat_reg);
37202ac6454SAndrew Thompson 
37302ac6454SAndrew Thompson 	DPRINTFN(5, "rx_stat=0x%02x rx_flag=0x%02x rem=%u\n",
37402ac6454SAndrew Thompson 	    rx_stat, rx_flag, td->remainder);
37502ac6454SAndrew Thompson 
37602ac6454SAndrew Thompson 	if (rx_stat & (USS820_RXSTAT_RXSETUP |
37702ac6454SAndrew Thompson 	    USS820_RXSTAT_RXSOVW |
37802ac6454SAndrew Thompson 	    USS820_RXSTAT_EDOVW)) {
37902ac6454SAndrew Thompson 		if (td->remainder == 0) {
38002ac6454SAndrew Thompson 			/*
38102ac6454SAndrew Thompson 			 * We are actually complete and have
38202ac6454SAndrew Thompson 			 * received the next SETUP
38302ac6454SAndrew Thompson 			 */
38402ac6454SAndrew Thompson 			DPRINTFN(5, "faking complete\n");
38502ac6454SAndrew Thompson 			return (0);	/* complete */
38602ac6454SAndrew Thompson 		}
38702ac6454SAndrew Thompson 		/*
38802ac6454SAndrew Thompson 	         * USB Host Aborted the transfer.
38902ac6454SAndrew Thompson 	         */
39002ac6454SAndrew Thompson 		td->error = 1;
39102ac6454SAndrew Thompson 		return (0);		/* complete */
39202ac6454SAndrew Thompson 	}
39302ac6454SAndrew Thompson 	/* check for errors */
39402ac6454SAndrew Thompson 	if (rx_flag & (USS820_RXFLG_RXOVF |
39502ac6454SAndrew Thompson 	    USS820_RXFLG_RXURF)) {
39602ac6454SAndrew Thompson 		DPRINTFN(5, "overflow or underflow\n");
39702ac6454SAndrew Thompson 		/* should not happen */
39802ac6454SAndrew Thompson 		td->error = 1;
39902ac6454SAndrew Thompson 		return (0);		/* complete */
40002ac6454SAndrew Thompson 	}
40102ac6454SAndrew Thompson 	/* check status */
40202ac6454SAndrew Thompson 	if (!(rx_flag & (USS820_RXFLG_RXFIF0 |
40302ac6454SAndrew Thompson 	    USS820_RXFLG_RXFIF1))) {
40402ac6454SAndrew Thompson 
40502ac6454SAndrew Thompson 		/* read out EPCON register */
40602ac6454SAndrew Thompson 		/* enable RX input */
40702ac6454SAndrew Thompson 		if (!td->did_stall) {
40802ac6454SAndrew Thompson 			uss820dci_update_shared_1(USS820_DCI_PC2SC(td->pc),
40902ac6454SAndrew Thompson 			    USS820_EPCON, 0xFF, USS820_EPCON_RXIE);
41002ac6454SAndrew Thompson 			td->did_stall = 1;
41102ac6454SAndrew Thompson 		}
41202ac6454SAndrew Thompson 		return (1);		/* not complete */
41302ac6454SAndrew Thompson 	}
41402ac6454SAndrew Thompson 	/* get the packet byte count */
41502ac6454SAndrew Thompson 	count = bus_space_read_1(td->io_tag, td->io_hdl,
41602ac6454SAndrew Thompson 	    td->rx_count_low_reg);
41702ac6454SAndrew Thompson 
41802ac6454SAndrew Thompson 	count |= (bus_space_read_1(td->io_tag, td->io_hdl,
41902ac6454SAndrew Thompson 	    td->rx_count_high_reg) << 8);
42002ac6454SAndrew Thompson 	count &= 0x3FF;
42102ac6454SAndrew Thompson 
42202ac6454SAndrew Thompson 	DPRINTFN(5, "count=0x%04x\n", count);
42302ac6454SAndrew Thompson 
42402ac6454SAndrew Thompson 	/* verify the packet byte count */
42502ac6454SAndrew Thompson 	if (count != td->max_packet_size) {
42602ac6454SAndrew Thompson 		if (count < td->max_packet_size) {
42702ac6454SAndrew Thompson 			/* we have a short packet */
42802ac6454SAndrew Thompson 			td->short_pkt = 1;
42902ac6454SAndrew Thompson 			got_short = 1;
43002ac6454SAndrew Thompson 		} else {
43102ac6454SAndrew Thompson 			/* invalid USB packet */
43202ac6454SAndrew Thompson 			td->error = 1;
43302ac6454SAndrew Thompson 			return (0);	/* we are complete */
43402ac6454SAndrew Thompson 		}
43502ac6454SAndrew Thompson 	}
43602ac6454SAndrew Thompson 	/* verify the packet byte count */
43702ac6454SAndrew Thompson 	if (count > td->remainder) {
43802ac6454SAndrew Thompson 		/* invalid USB packet */
43902ac6454SAndrew Thompson 		td->error = 1;
44002ac6454SAndrew Thompson 		return (0);		/* we are complete */
44102ac6454SAndrew Thompson 	}
44202ac6454SAndrew Thompson 	while (count > 0) {
44302ac6454SAndrew Thompson 		usb2_get_page(td->pc, td->offset, &buf_res);
44402ac6454SAndrew Thompson 
44502ac6454SAndrew Thompson 		/* get correct length */
44602ac6454SAndrew Thompson 		if (buf_res.length > count) {
44702ac6454SAndrew Thompson 			buf_res.length = count;
44802ac6454SAndrew Thompson 		}
44902ac6454SAndrew Thompson 		/* receive data */
45002ac6454SAndrew Thompson 		bus_space_read_multi_1(td->io_tag, td->io_hdl,
45102ac6454SAndrew Thompson 		    td->rx_fifo_reg, buf_res.buffer, buf_res.length);
45202ac6454SAndrew Thompson 
45302ac6454SAndrew Thompson 		/* update counters */
45402ac6454SAndrew Thompson 		count -= buf_res.length;
45502ac6454SAndrew Thompson 		td->offset += buf_res.length;
45602ac6454SAndrew Thompson 		td->remainder -= buf_res.length;
45702ac6454SAndrew Thompson 	}
45802ac6454SAndrew Thompson 
45902ac6454SAndrew Thompson 	/* set RXFFRC bit */
46002ac6454SAndrew Thompson 	rx_cntl = bus_space_read_1(td->io_tag, td->io_hdl,
46102ac6454SAndrew Thompson 	    td->rx_cntl_reg);
46202ac6454SAndrew Thompson 	rx_cntl |= USS820_RXCON_RXFFRC;
46302ac6454SAndrew Thompson 	bus_space_write_1(td->io_tag, td->io_hdl,
46402ac6454SAndrew Thompson 	    td->rx_cntl_reg, rx_cntl);
46502ac6454SAndrew Thompson 
46602ac6454SAndrew Thompson 	/* check if we are complete */
46702ac6454SAndrew Thompson 	if ((td->remainder == 0) || got_short) {
46802ac6454SAndrew Thompson 		if (td->short_pkt) {
46902ac6454SAndrew Thompson 			/* we are complete */
47002ac6454SAndrew Thompson 			return (0);
47102ac6454SAndrew Thompson 		}
47202ac6454SAndrew Thompson 		/* else need to receive a zero length packet */
47302ac6454SAndrew Thompson 	}
47402ac6454SAndrew Thompson 	if (--to) {
47502ac6454SAndrew Thompson 		goto repeat;
47602ac6454SAndrew Thompson 	}
47702ac6454SAndrew Thompson 	return (1);			/* not complete */
47802ac6454SAndrew Thompson }
47902ac6454SAndrew Thompson 
48002ac6454SAndrew Thompson static uint8_t
48102ac6454SAndrew Thompson uss820dci_data_tx(struct uss820dci_td *td)
48202ac6454SAndrew Thompson {
48302ac6454SAndrew Thompson 	struct usb2_page_search buf_res;
48402ac6454SAndrew Thompson 	uint16_t count;
48502ac6454SAndrew Thompson 	uint16_t count_copy;
48602ac6454SAndrew Thompson 	uint8_t rx_stat;
48702ac6454SAndrew Thompson 	uint8_t tx_flag;
48802ac6454SAndrew Thompson 	uint8_t to;
48902ac6454SAndrew Thompson 
49002ac6454SAndrew Thompson 	/* select the correct endpoint */
49102ac6454SAndrew Thompson 	bus_space_write_1(td->io_tag, td->io_hdl,
49202ac6454SAndrew Thompson 	    td->ep_reg, td->ep_index);
49302ac6454SAndrew Thompson 
49402ac6454SAndrew Thompson 	to = 2;				/* don't loop forever! */
49502ac6454SAndrew Thompson 
49602ac6454SAndrew Thompson repeat:
49702ac6454SAndrew Thompson 	/* read out TX FIFO flags */
49802ac6454SAndrew Thompson 	tx_flag = bus_space_read_1(td->io_tag, td->io_hdl,
49902ac6454SAndrew Thompson 	    td->tx_flag_reg);
50002ac6454SAndrew Thompson 
50102ac6454SAndrew Thompson 	/* read out RX FIFO status last */
50202ac6454SAndrew Thompson 	rx_stat = bus_space_read_1(td->io_tag, td->io_hdl,
50302ac6454SAndrew Thompson 	    td->rx_stat_reg);
50402ac6454SAndrew Thompson 
50502ac6454SAndrew Thompson 	DPRINTFN(5, "rx_stat=0x%02x tx_flag=0x%02x rem=%u\n",
50602ac6454SAndrew Thompson 	    rx_stat, tx_flag, td->remainder);
50702ac6454SAndrew Thompson 
50802ac6454SAndrew Thompson 	if (rx_stat & (USS820_RXSTAT_RXSETUP |
50902ac6454SAndrew Thompson 	    USS820_RXSTAT_RXSOVW |
51002ac6454SAndrew Thompson 	    USS820_RXSTAT_EDOVW)) {
51102ac6454SAndrew Thompson 		/*
51202ac6454SAndrew Thompson 	         * The current transfer was aborted
51302ac6454SAndrew Thompson 	         * by the USB Host
51402ac6454SAndrew Thompson 	         */
51502ac6454SAndrew Thompson 		td->error = 1;
51602ac6454SAndrew Thompson 		return (0);		/* complete */
51702ac6454SAndrew Thompson 	}
51802ac6454SAndrew Thompson 	if (tx_flag & (USS820_TXFLG_TXOVF |
51902ac6454SAndrew Thompson 	    USS820_TXFLG_TXURF)) {
52002ac6454SAndrew Thompson 		td->error = 1;
52102ac6454SAndrew Thompson 		return (0);		/* complete */
52202ac6454SAndrew Thompson 	}
52302ac6454SAndrew Thompson 	if (tx_flag & USS820_TXFLG_TXFIF0) {
52402ac6454SAndrew Thompson 		if (tx_flag & USS820_TXFLG_TXFIF1) {
52502ac6454SAndrew Thompson 			return (1);	/* not complete */
52602ac6454SAndrew Thompson 		}
52702ac6454SAndrew Thompson 	}
52802ac6454SAndrew Thompson 	if ((!td->support_multi_buffer) &&
52902ac6454SAndrew Thompson 	    (tx_flag & (USS820_TXFLG_TXFIF0 |
53002ac6454SAndrew Thompson 	    USS820_TXFLG_TXFIF1))) {
53102ac6454SAndrew Thompson 		return (1);		/* not complete */
53202ac6454SAndrew Thompson 	}
53302ac6454SAndrew Thompson 	count = td->max_packet_size;
53402ac6454SAndrew Thompson 	if (td->remainder < count) {
53502ac6454SAndrew Thompson 		/* we have a short packet */
53602ac6454SAndrew Thompson 		td->short_pkt = 1;
53702ac6454SAndrew Thompson 		count = td->remainder;
53802ac6454SAndrew Thompson 	}
53902ac6454SAndrew Thompson 	count_copy = count;
54002ac6454SAndrew Thompson 	while (count > 0) {
54102ac6454SAndrew Thompson 
54202ac6454SAndrew Thompson 		usb2_get_page(td->pc, td->offset, &buf_res);
54302ac6454SAndrew Thompson 
54402ac6454SAndrew Thompson 		/* get correct length */
54502ac6454SAndrew Thompson 		if (buf_res.length > count) {
54602ac6454SAndrew Thompson 			buf_res.length = count;
54702ac6454SAndrew Thompson 		}
54802ac6454SAndrew Thompson 		/* transmit data */
54902ac6454SAndrew Thompson 		bus_space_write_multi_1(td->io_tag, td->io_hdl,
55002ac6454SAndrew Thompson 		    td->tx_fifo_reg, buf_res.buffer, buf_res.length);
55102ac6454SAndrew Thompson 
55202ac6454SAndrew Thompson 		/* update counters */
55302ac6454SAndrew Thompson 		count -= buf_res.length;
55402ac6454SAndrew Thompson 		td->offset += buf_res.length;
55502ac6454SAndrew Thompson 		td->remainder -= buf_res.length;
55602ac6454SAndrew Thompson 	}
55702ac6454SAndrew Thompson 
55802ac6454SAndrew Thompson 	/* post-write high packet byte count first */
55902ac6454SAndrew Thompson 	bus_space_write_1(td->io_tag, td->io_hdl,
56002ac6454SAndrew Thompson 	    td->tx_count_high_reg, count_copy >> 8);
56102ac6454SAndrew Thompson 
56202ac6454SAndrew Thompson 	/* post-write low packet byte count last */
56302ac6454SAndrew Thompson 	bus_space_write_1(td->io_tag, td->io_hdl,
56402ac6454SAndrew Thompson 	    td->tx_count_low_reg, count_copy);
56502ac6454SAndrew Thompson 
56602ac6454SAndrew Thompson 	/*
56702ac6454SAndrew Thompson 	 * Enable TX output, which must happen after that we have written
56802ac6454SAndrew Thompson 	 * data into the FIFO. This is undocumented.
56902ac6454SAndrew Thompson 	 */
57002ac6454SAndrew Thompson 	if (!td->did_stall) {
57102ac6454SAndrew Thompson 		uss820dci_update_shared_1(USS820_DCI_PC2SC(td->pc),
57202ac6454SAndrew Thompson 		    USS820_EPCON, 0xFF, USS820_EPCON_TXOE);
57302ac6454SAndrew Thompson 		td->did_stall = 1;
57402ac6454SAndrew Thompson 	}
57502ac6454SAndrew Thompson 	/* check remainder */
57602ac6454SAndrew Thompson 	if (td->remainder == 0) {
57702ac6454SAndrew Thompson 		if (td->short_pkt) {
57802ac6454SAndrew Thompson 			return (0);	/* complete */
57902ac6454SAndrew Thompson 		}
58002ac6454SAndrew Thompson 		/* else we need to transmit a short packet */
58102ac6454SAndrew Thompson 	}
58202ac6454SAndrew Thompson 	if (--to) {
58302ac6454SAndrew Thompson 		goto repeat;
58402ac6454SAndrew Thompson 	}
58502ac6454SAndrew Thompson 	return (1);			/* not complete */
58602ac6454SAndrew Thompson }
58702ac6454SAndrew Thompson 
58802ac6454SAndrew Thompson static uint8_t
58902ac6454SAndrew Thompson uss820dci_data_tx_sync(struct uss820dci_td *td)
59002ac6454SAndrew Thompson {
59102ac6454SAndrew Thompson 	struct uss820dci_softc *sc;
59202ac6454SAndrew Thompson 	uint8_t rx_stat;
59302ac6454SAndrew Thompson 	uint8_t tx_flag;
59402ac6454SAndrew Thompson 
59502ac6454SAndrew Thompson 	/* select the correct endpoint */
59602ac6454SAndrew Thompson 	bus_space_write_1(td->io_tag, td->io_hdl,
59702ac6454SAndrew Thompson 	    td->ep_reg, td->ep_index);
59802ac6454SAndrew Thompson 
59902ac6454SAndrew Thompson 	/* read out TX FIFO flag */
60002ac6454SAndrew Thompson 	tx_flag = bus_space_read_1(td->io_tag, td->io_hdl,
60102ac6454SAndrew Thompson 	    td->tx_flag_reg);
60202ac6454SAndrew Thompson 
60302ac6454SAndrew Thompson 	/* read out RX FIFO status last */
60402ac6454SAndrew Thompson 	rx_stat = bus_space_read_1(td->io_tag, td->io_hdl,
60502ac6454SAndrew Thompson 	    td->rx_stat_reg);
60602ac6454SAndrew Thompson 
60702ac6454SAndrew Thompson 	DPRINTFN(5, "rx_stat=0x%02x rem=%u\n", rx_stat, td->remainder);
60802ac6454SAndrew Thompson 
60902ac6454SAndrew Thompson 	if (rx_stat & (USS820_RXSTAT_RXSETUP |
61002ac6454SAndrew Thompson 	    USS820_RXSTAT_RXSOVW |
61102ac6454SAndrew Thompson 	    USS820_RXSTAT_EDOVW)) {
61202ac6454SAndrew Thompson 		DPRINTFN(5, "faking complete\n");
61302ac6454SAndrew Thompson 		/* Race condition */
61402ac6454SAndrew Thompson 		return (0);		/* complete */
61502ac6454SAndrew Thompson 	}
61602ac6454SAndrew Thompson 	DPRINTFN(5, "tx_flag=0x%02x rem=%u\n",
61702ac6454SAndrew Thompson 	    tx_flag, td->remainder);
61802ac6454SAndrew Thompson 
61902ac6454SAndrew Thompson 	if (tx_flag & (USS820_TXFLG_TXOVF |
62002ac6454SAndrew Thompson 	    USS820_TXFLG_TXURF)) {
62102ac6454SAndrew Thompson 		td->error = 1;
62202ac6454SAndrew Thompson 		return (0);		/* complete */
62302ac6454SAndrew Thompson 	}
62402ac6454SAndrew Thompson 	if (tx_flag & (USS820_TXFLG_TXFIF0 |
62502ac6454SAndrew Thompson 	    USS820_TXFLG_TXFIF1)) {
62602ac6454SAndrew Thompson 		return (1);		/* not complete */
62702ac6454SAndrew Thompson 	}
62802ac6454SAndrew Thompson 	sc = USS820_DCI_PC2SC(td->pc);
62902ac6454SAndrew Thompson 	if (sc->sc_dv_addr != 0xFF) {
63002ac6454SAndrew Thompson 		/* write function address */
63102ac6454SAndrew Thompson 		uss820dci_set_address(sc, sc->sc_dv_addr);
63202ac6454SAndrew Thompson 	}
63302ac6454SAndrew Thompson 	return (0);			/* complete */
63402ac6454SAndrew Thompson }
63502ac6454SAndrew Thompson 
63602ac6454SAndrew Thompson static uint8_t
63702ac6454SAndrew Thompson uss820dci_xfer_do_fifo(struct usb2_xfer *xfer)
63802ac6454SAndrew Thompson {
63902ac6454SAndrew Thompson 	struct uss820dci_td *td;
64002ac6454SAndrew Thompson 
64102ac6454SAndrew Thompson 	DPRINTFN(9, "\n");
64202ac6454SAndrew Thompson 
64302ac6454SAndrew Thompson 	td = xfer->td_transfer_cache;
64402ac6454SAndrew Thompson 	while (1) {
64502ac6454SAndrew Thompson 		if ((td->func) (td)) {
64602ac6454SAndrew Thompson 			/* operation in progress */
64702ac6454SAndrew Thompson 			break;
64802ac6454SAndrew Thompson 		}
64902ac6454SAndrew Thompson 		if (((void *)td) == xfer->td_transfer_last) {
65002ac6454SAndrew Thompson 			goto done;
65102ac6454SAndrew Thompson 		}
65202ac6454SAndrew Thompson 		if (td->error) {
65302ac6454SAndrew Thompson 			goto done;
65402ac6454SAndrew Thompson 		} else if (td->remainder > 0) {
65502ac6454SAndrew Thompson 			/*
65602ac6454SAndrew Thompson 			 * We had a short transfer. If there is no alternate
65702ac6454SAndrew Thompson 			 * next, stop processing !
65802ac6454SAndrew Thompson 			 */
65902ac6454SAndrew Thompson 			if (!td->alt_next) {
66002ac6454SAndrew Thompson 				goto done;
66102ac6454SAndrew Thompson 			}
66202ac6454SAndrew Thompson 		}
66302ac6454SAndrew Thompson 		/*
66402ac6454SAndrew Thompson 		 * Fetch the next transfer descriptor.
66502ac6454SAndrew Thompson 		 */
66602ac6454SAndrew Thompson 		td = td->obj_next;
66702ac6454SAndrew Thompson 		xfer->td_transfer_cache = td;
66802ac6454SAndrew Thompson 	}
66902ac6454SAndrew Thompson 	return (1);			/* not complete */
67002ac6454SAndrew Thompson 
67102ac6454SAndrew Thompson done:
67202ac6454SAndrew Thompson 	/* compute all actual lengths */
67302ac6454SAndrew Thompson 
67402ac6454SAndrew Thompson 	uss820dci_standard_done(xfer);
67502ac6454SAndrew Thompson 
67602ac6454SAndrew Thompson 	return (0);			/* complete */
67702ac6454SAndrew Thompson }
67802ac6454SAndrew Thompson 
67902ac6454SAndrew Thompson static void
68002ac6454SAndrew Thompson uss820dci_interrupt_poll(struct uss820dci_softc *sc)
68102ac6454SAndrew Thompson {
68202ac6454SAndrew Thompson 	struct usb2_xfer *xfer;
68302ac6454SAndrew Thompson 
68402ac6454SAndrew Thompson repeat:
68502ac6454SAndrew Thompson 	TAILQ_FOREACH(xfer, &sc->sc_bus.intr_q.head, wait_entry) {
68602ac6454SAndrew Thompson 		if (!uss820dci_xfer_do_fifo(xfer)) {
68702ac6454SAndrew Thompson 			/* queue has been modified */
68802ac6454SAndrew Thompson 			goto repeat;
68902ac6454SAndrew Thompson 		}
69002ac6454SAndrew Thompson 	}
69102ac6454SAndrew Thompson }
69202ac6454SAndrew Thompson 
69302ac6454SAndrew Thompson static void
69402ac6454SAndrew Thompson uss820dci_wait_suspend(struct uss820dci_softc *sc, uint8_t on)
69502ac6454SAndrew Thompson {
69602ac6454SAndrew Thompson 	uint8_t scr;
69702ac6454SAndrew Thompson 	uint8_t scratch;
69802ac6454SAndrew Thompson 
69902ac6454SAndrew Thompson 	scr = USS820_READ_1(sc, USS820_SCR);
70002ac6454SAndrew Thompson 	scratch = USS820_READ_1(sc, USS820_SCRATCH);
70102ac6454SAndrew Thompson 
70202ac6454SAndrew Thompson 	if (on) {
70302ac6454SAndrew Thompson 		scr |= USS820_SCR_IE_SUSP;
70402ac6454SAndrew Thompson 		scratch &= ~USS820_SCRATCH_IE_RESUME;
70502ac6454SAndrew Thompson 	} else {
70602ac6454SAndrew Thompson 		scr &= ~USS820_SCR_IE_SUSP;
70702ac6454SAndrew Thompson 		scratch |= USS820_SCRATCH_IE_RESUME;
70802ac6454SAndrew Thompson 	}
70902ac6454SAndrew Thompson 
71002ac6454SAndrew Thompson 	USS820_WRITE_1(sc, USS820_SCR, scr);
71102ac6454SAndrew Thompson 	USS820_WRITE_1(sc, USS820_SCRATCH, scratch);
71202ac6454SAndrew Thompson }
71302ac6454SAndrew Thompson 
71402ac6454SAndrew Thompson void
71502ac6454SAndrew Thompson uss820dci_interrupt(struct uss820dci_softc *sc)
71602ac6454SAndrew Thompson {
71702ac6454SAndrew Thompson 	uint8_t ssr;
71802ac6454SAndrew Thompson 	uint8_t event;
71902ac6454SAndrew Thompson 
72002ac6454SAndrew Thompson 	USB_BUS_LOCK(&sc->sc_bus);
72102ac6454SAndrew Thompson 
72202ac6454SAndrew Thompson 	ssr = USS820_READ_1(sc, USS820_SSR);
72302ac6454SAndrew Thompson 
72402ac6454SAndrew Thompson 	ssr &= (USS820_SSR_SUSPEND |
72502ac6454SAndrew Thompson 	    USS820_SSR_RESUME |
72602ac6454SAndrew Thompson 	    USS820_SSR_RESET);
72702ac6454SAndrew Thompson 
72802ac6454SAndrew Thompson 	/* acknowledge all interrupts */
72902ac6454SAndrew Thompson 
73002ac6454SAndrew Thompson 	uss820dci_update_shared_1(sc, USS820_SSR, 0, 0);
73102ac6454SAndrew Thompson 
73202ac6454SAndrew Thompson 	/* check for any bus state change interrupts */
73302ac6454SAndrew Thompson 
73402ac6454SAndrew Thompson 	if (ssr) {
73502ac6454SAndrew Thompson 
73602ac6454SAndrew Thompson 		event = 0;
73702ac6454SAndrew Thompson 
73802ac6454SAndrew Thompson 		if (ssr & USS820_SSR_RESET) {
73902ac6454SAndrew Thompson 			sc->sc_flags.status_bus_reset = 1;
74002ac6454SAndrew Thompson 			sc->sc_flags.status_suspend = 0;
74102ac6454SAndrew Thompson 			sc->sc_flags.change_suspend = 0;
74202ac6454SAndrew Thompson 			sc->sc_flags.change_connect = 1;
74302ac6454SAndrew Thompson 
74402ac6454SAndrew Thompson 			/* disable resume interrupt */
74502ac6454SAndrew Thompson 			uss820dci_wait_suspend(sc, 1);
74602ac6454SAndrew Thompson 
74702ac6454SAndrew Thompson 			event = 1;
74802ac6454SAndrew Thompson 		}
74902ac6454SAndrew Thompson 		/*
75002ac6454SAndrew Thompson 	         * If "RESUME" and "SUSPEND" is set at the same time
75102ac6454SAndrew Thompson 	         * we interpret that like "RESUME". Resume is set when
75202ac6454SAndrew Thompson 	         * there is at least 3 milliseconds of inactivity on
75302ac6454SAndrew Thompson 	         * the USB BUS.
75402ac6454SAndrew Thompson 	         */
75502ac6454SAndrew Thompson 		if (ssr & USS820_SSR_RESUME) {
75602ac6454SAndrew Thompson 			if (sc->sc_flags.status_suspend) {
75702ac6454SAndrew Thompson 				sc->sc_flags.status_suspend = 0;
75802ac6454SAndrew Thompson 				sc->sc_flags.change_suspend = 1;
75902ac6454SAndrew Thompson 				/* disable resume interrupt */
76002ac6454SAndrew Thompson 				uss820dci_wait_suspend(sc, 1);
76102ac6454SAndrew Thompson 				event = 1;
76202ac6454SAndrew Thompson 			}
76302ac6454SAndrew Thompson 		} else if (ssr & USS820_SSR_SUSPEND) {
76402ac6454SAndrew Thompson 			if (!sc->sc_flags.status_suspend) {
76502ac6454SAndrew Thompson 				sc->sc_flags.status_suspend = 1;
76602ac6454SAndrew Thompson 				sc->sc_flags.change_suspend = 1;
76702ac6454SAndrew Thompson 				/* enable resume interrupt */
76802ac6454SAndrew Thompson 				uss820dci_wait_suspend(sc, 0);
76902ac6454SAndrew Thompson 				event = 1;
77002ac6454SAndrew Thompson 			}
77102ac6454SAndrew Thompson 		}
77202ac6454SAndrew Thompson 		if (event) {
77302ac6454SAndrew Thompson 
77402ac6454SAndrew Thompson 			DPRINTF("real bus interrupt 0x%02x\n", ssr);
77502ac6454SAndrew Thompson 
77602ac6454SAndrew Thompson 			/* complete root HUB interrupt endpoint */
77702ac6454SAndrew Thompson 
77802ac6454SAndrew Thompson 			usb2_sw_transfer(&sc->sc_root_intr,
77902ac6454SAndrew Thompson 			    &uss820dci_root_intr_done);
78002ac6454SAndrew Thompson 		}
78102ac6454SAndrew Thompson 	}
78202ac6454SAndrew Thompson 	/* acknowledge all SBI interrupts */
78302ac6454SAndrew Thompson 	uss820dci_update_shared_1(sc, USS820_SBI, 0, 0);
78402ac6454SAndrew Thompson 
78502ac6454SAndrew Thompson 	/* acknowledge all SBI1 interrupts */
78602ac6454SAndrew Thompson 	uss820dci_update_shared_1(sc, USS820_SBI1, 0, 0);
78702ac6454SAndrew Thompson 
78802ac6454SAndrew Thompson 	/* poll all active transfers */
78902ac6454SAndrew Thompson 	uss820dci_interrupt_poll(sc);
79002ac6454SAndrew Thompson 
79102ac6454SAndrew Thompson 	USB_BUS_UNLOCK(&sc->sc_bus);
79202ac6454SAndrew Thompson }
79302ac6454SAndrew Thompson 
79402ac6454SAndrew Thompson static void
79502ac6454SAndrew Thompson uss820dci_setup_standard_chain_sub(struct uss820_std_temp *temp)
79602ac6454SAndrew Thompson {
79702ac6454SAndrew Thompson 	struct uss820dci_td *td;
79802ac6454SAndrew Thompson 
79902ac6454SAndrew Thompson 	/* get current Transfer Descriptor */
80002ac6454SAndrew Thompson 	td = temp->td_next;
80102ac6454SAndrew Thompson 	temp->td = td;
80202ac6454SAndrew Thompson 
80302ac6454SAndrew Thompson 	/* prepare for next TD */
80402ac6454SAndrew Thompson 	temp->td_next = td->obj_next;
80502ac6454SAndrew Thompson 
80602ac6454SAndrew Thompson 	/* fill out the Transfer Descriptor */
80702ac6454SAndrew Thompson 	td->func = temp->func;
80802ac6454SAndrew Thompson 	td->pc = temp->pc;
80902ac6454SAndrew Thompson 	td->offset = temp->offset;
81002ac6454SAndrew Thompson 	td->remainder = temp->len;
81102ac6454SAndrew Thompson 	td->error = 0;
81202ac6454SAndrew Thompson 	td->did_stall = 0;
81302ac6454SAndrew Thompson 	td->short_pkt = temp->short_pkt;
81402ac6454SAndrew Thompson 	td->alt_next = temp->setup_alt_next;
81502ac6454SAndrew Thompson }
81602ac6454SAndrew Thompson 
81702ac6454SAndrew Thompson static void
81802ac6454SAndrew Thompson uss820dci_setup_standard_chain(struct usb2_xfer *xfer)
81902ac6454SAndrew Thompson {
82002ac6454SAndrew Thompson 	struct uss820_std_temp temp;
82102ac6454SAndrew Thompson 	struct uss820dci_softc *sc;
82202ac6454SAndrew Thompson 	struct uss820dci_td *td;
82302ac6454SAndrew Thompson 	uint32_t x;
82402ac6454SAndrew Thompson 	uint8_t ep_no;
82502ac6454SAndrew Thompson 
82602ac6454SAndrew Thompson 	DPRINTFN(9, "addr=%d endpt=%d sumlen=%d speed=%d\n",
82702ac6454SAndrew Thompson 	    xfer->address, UE_GET_ADDR(xfer->endpoint),
82802ac6454SAndrew Thompson 	    xfer->sumlen, usb2_get_speed(xfer->xroot->udev));
82902ac6454SAndrew Thompson 
83002ac6454SAndrew Thompson 	temp.max_frame_size = xfer->max_frame_size;
83102ac6454SAndrew Thompson 
83202ac6454SAndrew Thompson 	td = xfer->td_start[0];
83302ac6454SAndrew Thompson 	xfer->td_transfer_first = td;
83402ac6454SAndrew Thompson 	xfer->td_transfer_cache = td;
83502ac6454SAndrew Thompson 
83602ac6454SAndrew Thompson 	/* setup temp */
83702ac6454SAndrew Thompson 
83802ac6454SAndrew Thompson 	temp.td = NULL;
83902ac6454SAndrew Thompson 	temp.td_next = xfer->td_start[0];
84002ac6454SAndrew Thompson 	temp.setup_alt_next = xfer->flags_int.short_frames_ok;
84102ac6454SAndrew Thompson 	temp.offset = 0;
84202ac6454SAndrew Thompson 
84302ac6454SAndrew Thompson 	sc = USS820_DCI_BUS2SC(xfer->xroot->bus);
84402ac6454SAndrew Thompson 	ep_no = (xfer->endpoint & UE_ADDR);
84502ac6454SAndrew Thompson 
84602ac6454SAndrew Thompson 	/* check if we should prepend a setup message */
84702ac6454SAndrew Thompson 
84802ac6454SAndrew Thompson 	if (xfer->flags_int.control_xfr) {
84902ac6454SAndrew Thompson 		if (xfer->flags_int.control_hdr) {
85002ac6454SAndrew Thompson 
85102ac6454SAndrew Thompson 			temp.func = &uss820dci_setup_rx;
85202ac6454SAndrew Thompson 			temp.len = xfer->frlengths[0];
85302ac6454SAndrew Thompson 			temp.pc = xfer->frbuffers + 0;
85402ac6454SAndrew Thompson 			temp.short_pkt = temp.len ? 1 : 0;
85502ac6454SAndrew Thompson 
85602ac6454SAndrew Thompson 			uss820dci_setup_standard_chain_sub(&temp);
85702ac6454SAndrew Thompson 		}
85802ac6454SAndrew Thompson 		x = 1;
85902ac6454SAndrew Thompson 	} else {
86002ac6454SAndrew Thompson 		x = 0;
86102ac6454SAndrew Thompson 	}
86202ac6454SAndrew Thompson 
86302ac6454SAndrew Thompson 	if (x != xfer->nframes) {
86402ac6454SAndrew Thompson 		if (xfer->endpoint & UE_DIR_IN) {
86502ac6454SAndrew Thompson 			temp.func = &uss820dci_data_tx;
86602ac6454SAndrew Thompson 		} else {
86702ac6454SAndrew Thompson 			temp.func = &uss820dci_data_rx;
86802ac6454SAndrew Thompson 		}
86902ac6454SAndrew Thompson 
87002ac6454SAndrew Thompson 		/* setup "pc" pointer */
87102ac6454SAndrew Thompson 		temp.pc = xfer->frbuffers + x;
87202ac6454SAndrew Thompson 	}
87302ac6454SAndrew Thompson 	while (x != xfer->nframes) {
87402ac6454SAndrew Thompson 
87502ac6454SAndrew Thompson 		/* DATA0 / DATA1 message */
87602ac6454SAndrew Thompson 
87702ac6454SAndrew Thompson 		temp.len = xfer->frlengths[x];
87802ac6454SAndrew Thompson 
87902ac6454SAndrew Thompson 		x++;
88002ac6454SAndrew Thompson 
88102ac6454SAndrew Thompson 		if (x == xfer->nframes) {
88202ac6454SAndrew Thompson 			temp.setup_alt_next = 0;
88302ac6454SAndrew Thompson 		}
88402ac6454SAndrew Thompson 		if (temp.len == 0) {
88502ac6454SAndrew Thompson 
88602ac6454SAndrew Thompson 			/* make sure that we send an USB packet */
88702ac6454SAndrew Thompson 
88802ac6454SAndrew Thompson 			temp.short_pkt = 0;
88902ac6454SAndrew Thompson 
89002ac6454SAndrew Thompson 		} else {
89102ac6454SAndrew Thompson 
89202ac6454SAndrew Thompson 			/* regular data transfer */
89302ac6454SAndrew Thompson 
89402ac6454SAndrew Thompson 			temp.short_pkt = (xfer->flags.force_short_xfer) ? 0 : 1;
89502ac6454SAndrew Thompson 		}
89602ac6454SAndrew Thompson 
89702ac6454SAndrew Thompson 		uss820dci_setup_standard_chain_sub(&temp);
89802ac6454SAndrew Thompson 
89902ac6454SAndrew Thompson 		if (xfer->flags_int.isochronous_xfr) {
90002ac6454SAndrew Thompson 			temp.offset += temp.len;
90102ac6454SAndrew Thompson 		} else {
90202ac6454SAndrew Thompson 			/* get next Page Cache pointer */
90302ac6454SAndrew Thompson 			temp.pc = xfer->frbuffers + x;
90402ac6454SAndrew Thompson 		}
90502ac6454SAndrew Thompson 	}
90602ac6454SAndrew Thompson 
90702ac6454SAndrew Thompson 	/* always setup a valid "pc" pointer for status and sync */
90802ac6454SAndrew Thompson 	temp.pc = xfer->frbuffers + 0;
90902ac6454SAndrew Thompson 
91002ac6454SAndrew Thompson 	/* check if we should append a status stage */
91102ac6454SAndrew Thompson 
91202ac6454SAndrew Thompson 	if (xfer->flags_int.control_xfr &&
91302ac6454SAndrew Thompson 	    !xfer->flags_int.control_act) {
91402ac6454SAndrew Thompson 		uint8_t need_sync;
91502ac6454SAndrew Thompson 
91602ac6454SAndrew Thompson 		/*
91702ac6454SAndrew Thompson 		 * Send a DATA1 message and invert the current
91802ac6454SAndrew Thompson 		 * endpoint direction.
91902ac6454SAndrew Thompson 		 */
92002ac6454SAndrew Thompson 		if (xfer->endpoint & UE_DIR_IN) {
92102ac6454SAndrew Thompson 			temp.func = &uss820dci_data_rx;
92202ac6454SAndrew Thompson 			need_sync = 0;
92302ac6454SAndrew Thompson 		} else {
92402ac6454SAndrew Thompson 			temp.func = &uss820dci_data_tx;
92502ac6454SAndrew Thompson 			need_sync = 1;
92602ac6454SAndrew Thompson 		}
92702ac6454SAndrew Thompson 		temp.len = 0;
92802ac6454SAndrew Thompson 		temp.short_pkt = 0;
92902ac6454SAndrew Thompson 
93002ac6454SAndrew Thompson 		uss820dci_setup_standard_chain_sub(&temp);
93102ac6454SAndrew Thompson 		if (need_sync) {
93202ac6454SAndrew Thompson 			/* we need a SYNC point after TX */
93302ac6454SAndrew Thompson 			temp.func = &uss820dci_data_tx_sync;
93402ac6454SAndrew Thompson 			temp.len = 0;
93502ac6454SAndrew Thompson 			temp.short_pkt = 0;
93602ac6454SAndrew Thompson 
93702ac6454SAndrew Thompson 			uss820dci_setup_standard_chain_sub(&temp);
93802ac6454SAndrew Thompson 		}
93902ac6454SAndrew Thompson 	}
94002ac6454SAndrew Thompson 	/* must have at least one frame! */
94102ac6454SAndrew Thompson 	td = temp.td;
94202ac6454SAndrew Thompson 	xfer->td_transfer_last = td;
94302ac6454SAndrew Thompson }
94402ac6454SAndrew Thompson 
94502ac6454SAndrew Thompson static void
94602ac6454SAndrew Thompson uss820dci_timeout(void *arg)
94702ac6454SAndrew Thompson {
94802ac6454SAndrew Thompson 	struct usb2_xfer *xfer = arg;
94902ac6454SAndrew Thompson 
95002ac6454SAndrew Thompson 	DPRINTF("xfer=%p\n", xfer);
95102ac6454SAndrew Thompson 
95202ac6454SAndrew Thompson 	USB_BUS_LOCK_ASSERT(xfer->xroot->bus, MA_OWNED);
95302ac6454SAndrew Thompson 
95402ac6454SAndrew Thompson 	/* transfer is transferred */
95502ac6454SAndrew Thompson 	uss820dci_device_done(xfer, USB_ERR_TIMEOUT);
95602ac6454SAndrew Thompson }
95702ac6454SAndrew Thompson 
95802ac6454SAndrew Thompson static void
95902ac6454SAndrew Thompson uss820dci_intr_set(struct usb2_xfer *xfer, uint8_t set)
96002ac6454SAndrew Thompson {
96102ac6454SAndrew Thompson 	struct uss820dci_softc *sc = USS820_DCI_BUS2SC(xfer->xroot->bus);
96202ac6454SAndrew Thompson 	uint8_t ep_no = (xfer->endpoint & UE_ADDR);
96302ac6454SAndrew Thompson 	uint8_t ep_reg;
96402ac6454SAndrew Thompson 	uint8_t temp;
96502ac6454SAndrew Thompson 
96602ac6454SAndrew Thompson 	DPRINTFN(15, "endpoint 0x%02x\n", xfer->endpoint);
96702ac6454SAndrew Thompson 
96802ac6454SAndrew Thompson 	if (ep_no > 3) {
96902ac6454SAndrew Thompson 		ep_reg = USS820_SBIE1;
97002ac6454SAndrew Thompson 	} else {
97102ac6454SAndrew Thompson 		ep_reg = USS820_SBIE;
97202ac6454SAndrew Thompson 	}
97302ac6454SAndrew Thompson 
97402ac6454SAndrew Thompson 	ep_no &= 3;
97502ac6454SAndrew Thompson 	ep_no = 1 << (2 * ep_no);
97602ac6454SAndrew Thompson 
97702ac6454SAndrew Thompson 	if (xfer->flags_int.control_xfr) {
97802ac6454SAndrew Thompson 		if (xfer->flags_int.control_hdr) {
97902ac6454SAndrew Thompson 			ep_no <<= 1;	/* RX interrupt only */
98002ac6454SAndrew Thompson 		} else {
98102ac6454SAndrew Thompson 			ep_no |= (ep_no << 1);	/* RX and TX interrupt */
98202ac6454SAndrew Thompson 		}
98302ac6454SAndrew Thompson 	} else {
98402ac6454SAndrew Thompson 		if (!(xfer->endpoint & UE_DIR_IN)) {
98502ac6454SAndrew Thompson 			ep_no <<= 1;
98602ac6454SAndrew Thompson 		}
98702ac6454SAndrew Thompson 	}
98802ac6454SAndrew Thompson 	temp = USS820_READ_1(sc, ep_reg);
98902ac6454SAndrew Thompson 	if (set) {
99002ac6454SAndrew Thompson 		temp |= ep_no;
99102ac6454SAndrew Thompson 	} else {
99202ac6454SAndrew Thompson 		temp &= ~ep_no;
99302ac6454SAndrew Thompson 	}
99402ac6454SAndrew Thompson 	USS820_WRITE_1(sc, ep_reg, temp);
99502ac6454SAndrew Thompson }
99602ac6454SAndrew Thompson 
99702ac6454SAndrew Thompson static void
99802ac6454SAndrew Thompson uss820dci_start_standard_chain(struct usb2_xfer *xfer)
99902ac6454SAndrew Thompson {
100002ac6454SAndrew Thompson 	DPRINTFN(9, "\n");
100102ac6454SAndrew Thompson 
100202ac6454SAndrew Thompson 	/* poll one time */
100302ac6454SAndrew Thompson 	if (uss820dci_xfer_do_fifo(xfer)) {
100402ac6454SAndrew Thompson 
100502ac6454SAndrew Thompson 		/*
100602ac6454SAndrew Thompson 		 * Only enable the endpoint interrupt when we are
100702ac6454SAndrew Thompson 		 * actually waiting for data, hence we are dealing
100802ac6454SAndrew Thompson 		 * with level triggered interrupts !
100902ac6454SAndrew Thompson 		 */
101002ac6454SAndrew Thompson 		uss820dci_intr_set(xfer, 1);
101102ac6454SAndrew Thompson 
101202ac6454SAndrew Thompson 		/* put transfer on interrupt queue */
101302ac6454SAndrew Thompson 		usb2_transfer_enqueue(&xfer->xroot->bus->intr_q, xfer);
101402ac6454SAndrew Thompson 
101502ac6454SAndrew Thompson 		/* start timeout, if any */
101602ac6454SAndrew Thompson 		if (xfer->timeout != 0) {
101702ac6454SAndrew Thompson 			usb2_transfer_timeout_ms(xfer,
101802ac6454SAndrew Thompson 			    &uss820dci_timeout, xfer->timeout);
101902ac6454SAndrew Thompson 		}
102002ac6454SAndrew Thompson 	}
102102ac6454SAndrew Thompson }
102202ac6454SAndrew Thompson 
102302ac6454SAndrew Thompson static void
102402ac6454SAndrew Thompson uss820dci_root_intr_done(struct usb2_xfer *xfer,
102502ac6454SAndrew Thompson     struct usb2_sw_transfer *std)
102602ac6454SAndrew Thompson {
102702ac6454SAndrew Thompson 	struct uss820dci_softc *sc = USS820_DCI_BUS2SC(xfer->xroot->bus);
102802ac6454SAndrew Thompson 
102902ac6454SAndrew Thompson 	DPRINTFN(9, "\n");
103002ac6454SAndrew Thompson 
103102ac6454SAndrew Thompson 	USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
103202ac6454SAndrew Thompson 
103302ac6454SAndrew Thompson 	if (std->state != USB_SW_TR_PRE_DATA) {
103402ac6454SAndrew Thompson 		if (std->state == USB_SW_TR_PRE_CALLBACK) {
103502ac6454SAndrew Thompson 			/* transfer transferred */
103602ac6454SAndrew Thompson 			uss820dci_device_done(xfer, std->err);
103702ac6454SAndrew Thompson 		}
103802ac6454SAndrew Thompson 		goto done;
103902ac6454SAndrew Thompson 	}
104002ac6454SAndrew Thompson 	/* setup buffer */
104102ac6454SAndrew Thompson 	std->ptr = sc->sc_hub_idata;
104202ac6454SAndrew Thompson 	std->len = sizeof(sc->sc_hub_idata);
104302ac6454SAndrew Thompson 
104402ac6454SAndrew Thompson 	/* set port bit */
104502ac6454SAndrew Thompson 	sc->sc_hub_idata[0] = 0x02;	/* we only have one port */
104602ac6454SAndrew Thompson 
104702ac6454SAndrew Thompson done:
104802ac6454SAndrew Thompson 	return;
104902ac6454SAndrew Thompson }
105002ac6454SAndrew Thompson 
105102ac6454SAndrew Thompson static usb2_error_t
105202ac6454SAndrew Thompson uss820dci_standard_done_sub(struct usb2_xfer *xfer)
105302ac6454SAndrew Thompson {
105402ac6454SAndrew Thompson 	struct uss820dci_td *td;
105502ac6454SAndrew Thompson 	uint32_t len;
105602ac6454SAndrew Thompson 	uint8_t error;
105702ac6454SAndrew Thompson 
105802ac6454SAndrew Thompson 	DPRINTFN(9, "\n");
105902ac6454SAndrew Thompson 
106002ac6454SAndrew Thompson 	td = xfer->td_transfer_cache;
106102ac6454SAndrew Thompson 
106202ac6454SAndrew Thompson 	do {
106302ac6454SAndrew Thompson 		len = td->remainder;
106402ac6454SAndrew Thompson 
106502ac6454SAndrew Thompson 		if (xfer->aframes != xfer->nframes) {
106602ac6454SAndrew Thompson 			/*
106702ac6454SAndrew Thompson 		         * Verify the length and subtract
106802ac6454SAndrew Thompson 		         * the remainder from "frlengths[]":
106902ac6454SAndrew Thompson 		         */
107002ac6454SAndrew Thompson 			if (len > xfer->frlengths[xfer->aframes]) {
107102ac6454SAndrew Thompson 				td->error = 1;
107202ac6454SAndrew Thompson 			} else {
107302ac6454SAndrew Thompson 				xfer->frlengths[xfer->aframes] -= len;
107402ac6454SAndrew Thompson 			}
107502ac6454SAndrew Thompson 		}
107602ac6454SAndrew Thompson 		/* Check for transfer error */
107702ac6454SAndrew Thompson 		if (td->error) {
107802ac6454SAndrew Thompson 			/* the transfer is finished */
107902ac6454SAndrew Thompson 			error = 1;
108002ac6454SAndrew Thompson 			td = NULL;
108102ac6454SAndrew Thompson 			break;
108202ac6454SAndrew Thompson 		}
108302ac6454SAndrew Thompson 		/* Check for short transfer */
108402ac6454SAndrew Thompson 		if (len > 0) {
108502ac6454SAndrew Thompson 			if (xfer->flags_int.short_frames_ok) {
108602ac6454SAndrew Thompson 				/* follow alt next */
108702ac6454SAndrew Thompson 				if (td->alt_next) {
108802ac6454SAndrew Thompson 					td = td->obj_next;
108902ac6454SAndrew Thompson 				} else {
109002ac6454SAndrew Thompson 					td = NULL;
109102ac6454SAndrew Thompson 				}
109202ac6454SAndrew Thompson 			} else {
109302ac6454SAndrew Thompson 				/* the transfer is finished */
109402ac6454SAndrew Thompson 				td = NULL;
109502ac6454SAndrew Thompson 			}
109602ac6454SAndrew Thompson 			error = 0;
109702ac6454SAndrew Thompson 			break;
109802ac6454SAndrew Thompson 		}
109902ac6454SAndrew Thompson 		td = td->obj_next;
110002ac6454SAndrew Thompson 
110102ac6454SAndrew Thompson 		/* this USB frame is complete */
110202ac6454SAndrew Thompson 		error = 0;
110302ac6454SAndrew Thompson 		break;
110402ac6454SAndrew Thompson 
110502ac6454SAndrew Thompson 	} while (0);
110602ac6454SAndrew Thompson 
110702ac6454SAndrew Thompson 	/* update transfer cache */
110802ac6454SAndrew Thompson 
110902ac6454SAndrew Thompson 	xfer->td_transfer_cache = td;
111002ac6454SAndrew Thompson 
111102ac6454SAndrew Thompson 	return (error ?
111202ac6454SAndrew Thompson 	    USB_ERR_STALLED : USB_ERR_NORMAL_COMPLETION);
111302ac6454SAndrew Thompson }
111402ac6454SAndrew Thompson 
111502ac6454SAndrew Thompson static void
111602ac6454SAndrew Thompson uss820dci_standard_done(struct usb2_xfer *xfer)
111702ac6454SAndrew Thompson {
111802ac6454SAndrew Thompson 	usb2_error_t err = 0;
111902ac6454SAndrew Thompson 
112002ac6454SAndrew Thompson 	DPRINTFN(13, "xfer=%p pipe=%p transfer done\n",
112102ac6454SAndrew Thompson 	    xfer, xfer->pipe);
112202ac6454SAndrew Thompson 
112302ac6454SAndrew Thompson 	/* reset scanner */
112402ac6454SAndrew Thompson 
112502ac6454SAndrew Thompson 	xfer->td_transfer_cache = xfer->td_transfer_first;
112602ac6454SAndrew Thompson 
112702ac6454SAndrew Thompson 	if (xfer->flags_int.control_xfr) {
112802ac6454SAndrew Thompson 
112902ac6454SAndrew Thompson 		if (xfer->flags_int.control_hdr) {
113002ac6454SAndrew Thompson 
113102ac6454SAndrew Thompson 			err = uss820dci_standard_done_sub(xfer);
113202ac6454SAndrew Thompson 		}
113302ac6454SAndrew Thompson 		xfer->aframes = 1;
113402ac6454SAndrew Thompson 
113502ac6454SAndrew Thompson 		if (xfer->td_transfer_cache == NULL) {
113602ac6454SAndrew Thompson 			goto done;
113702ac6454SAndrew Thompson 		}
113802ac6454SAndrew Thompson 	}
113902ac6454SAndrew Thompson 	while (xfer->aframes != xfer->nframes) {
114002ac6454SAndrew Thompson 
114102ac6454SAndrew Thompson 		err = uss820dci_standard_done_sub(xfer);
114202ac6454SAndrew Thompson 		xfer->aframes++;
114302ac6454SAndrew Thompson 
114402ac6454SAndrew Thompson 		if (xfer->td_transfer_cache == NULL) {
114502ac6454SAndrew Thompson 			goto done;
114602ac6454SAndrew Thompson 		}
114702ac6454SAndrew Thompson 	}
114802ac6454SAndrew Thompson 
114902ac6454SAndrew Thompson 	if (xfer->flags_int.control_xfr &&
115002ac6454SAndrew Thompson 	    !xfer->flags_int.control_act) {
115102ac6454SAndrew Thompson 
115202ac6454SAndrew Thompson 		err = uss820dci_standard_done_sub(xfer);
115302ac6454SAndrew Thompson 	}
115402ac6454SAndrew Thompson done:
115502ac6454SAndrew Thompson 	uss820dci_device_done(xfer, err);
115602ac6454SAndrew Thompson }
115702ac6454SAndrew Thompson 
115802ac6454SAndrew Thompson /*------------------------------------------------------------------------*
115902ac6454SAndrew Thompson  *	uss820dci_device_done
116002ac6454SAndrew Thompson  *
116102ac6454SAndrew Thompson  * NOTE: this function can be called more than one time on the
116202ac6454SAndrew Thompson  * same USB transfer!
116302ac6454SAndrew Thompson  *------------------------------------------------------------------------*/
116402ac6454SAndrew Thompson static void
116502ac6454SAndrew Thompson uss820dci_device_done(struct usb2_xfer *xfer, usb2_error_t error)
116602ac6454SAndrew Thompson {
116702ac6454SAndrew Thompson 	USB_BUS_LOCK_ASSERT(xfer->xroot->bus, MA_OWNED);
116802ac6454SAndrew Thompson 
116902ac6454SAndrew Thompson 	DPRINTFN(2, "xfer=%p, pipe=%p, error=%d\n",
117002ac6454SAndrew Thompson 	    xfer, xfer->pipe, error);
117102ac6454SAndrew Thompson 
117202ac6454SAndrew Thompson 	if (xfer->flags_int.usb2_mode == USB_MODE_DEVICE) {
117302ac6454SAndrew Thompson 		uss820dci_intr_set(xfer, 0);
117402ac6454SAndrew Thompson 	}
117502ac6454SAndrew Thompson 	/* dequeue transfer and start next transfer */
117602ac6454SAndrew Thompson 	usb2_transfer_done(xfer, error);
117702ac6454SAndrew Thompson }
117802ac6454SAndrew Thompson 
117902ac6454SAndrew Thompson static void
118002ac6454SAndrew Thompson uss820dci_set_stall(struct usb2_device *udev, struct usb2_xfer *xfer,
118102ac6454SAndrew Thompson     struct usb2_pipe *pipe)
118202ac6454SAndrew Thompson {
118302ac6454SAndrew Thompson 	struct uss820dci_softc *sc;
118402ac6454SAndrew Thompson 	uint8_t ep_no;
118502ac6454SAndrew Thompson 	uint8_t ep_type;
118602ac6454SAndrew Thompson 	uint8_t ep_dir;
118702ac6454SAndrew Thompson 	uint8_t temp;
118802ac6454SAndrew Thompson 
118902ac6454SAndrew Thompson 	USB_BUS_LOCK_ASSERT(udev->bus, MA_OWNED);
119002ac6454SAndrew Thompson 
119102ac6454SAndrew Thompson 	DPRINTFN(5, "pipe=%p\n", pipe);
119202ac6454SAndrew Thompson 
119302ac6454SAndrew Thompson 	if (xfer) {
119402ac6454SAndrew Thompson 		/* cancel any ongoing transfers */
119502ac6454SAndrew Thompson 		uss820dci_device_done(xfer, USB_ERR_STALLED);
119602ac6454SAndrew Thompson 	}
119702ac6454SAndrew Thompson 	/* set FORCESTALL */
119802ac6454SAndrew Thompson 	sc = USS820_DCI_BUS2SC(udev->bus);
119902ac6454SAndrew Thompson 	ep_no = (pipe->edesc->bEndpointAddress & UE_ADDR);
120002ac6454SAndrew Thompson 	ep_dir = (pipe->edesc->bEndpointAddress & (UE_DIR_IN | UE_DIR_OUT));
120102ac6454SAndrew Thompson 	ep_type = (pipe->edesc->bmAttributes & UE_XFERTYPE);
120202ac6454SAndrew Thompson 
120302ac6454SAndrew Thompson 	if (ep_type == UE_CONTROL) {
120402ac6454SAndrew Thompson 		/* should not happen */
120502ac6454SAndrew Thompson 		return;
120602ac6454SAndrew Thompson 	}
120702ac6454SAndrew Thompson 	USS820_WRITE_1(sc, USS820_EPINDEX, ep_no);
120802ac6454SAndrew Thompson 
120902ac6454SAndrew Thompson 	if (ep_dir == UE_DIR_IN) {
121002ac6454SAndrew Thompson 		temp = USS820_EPCON_TXSTL;
121102ac6454SAndrew Thompson 	} else {
121202ac6454SAndrew Thompson 		temp = USS820_EPCON_RXSTL;
121302ac6454SAndrew Thompson 	}
121402ac6454SAndrew Thompson 	uss820dci_update_shared_1(sc, USS820_EPCON, 0xFF, temp);
121502ac6454SAndrew Thompson }
121602ac6454SAndrew Thompson 
121702ac6454SAndrew Thompson static void
121802ac6454SAndrew Thompson uss820dci_clear_stall_sub(struct uss820dci_softc *sc,
121902ac6454SAndrew Thompson     uint8_t ep_no, uint8_t ep_type, uint8_t ep_dir)
122002ac6454SAndrew Thompson {
122102ac6454SAndrew Thompson 	uint8_t temp;
122202ac6454SAndrew Thompson 
122302ac6454SAndrew Thompson 	if (ep_type == UE_CONTROL) {
122402ac6454SAndrew Thompson 		/* clearing stall is not needed */
122502ac6454SAndrew Thompson 		return;
122602ac6454SAndrew Thompson 	}
122702ac6454SAndrew Thompson 	/* select endpoint index */
122802ac6454SAndrew Thompson 	USS820_WRITE_1(sc, USS820_EPINDEX, ep_no);
122902ac6454SAndrew Thompson 
123002ac6454SAndrew Thompson 	/* clear stall and disable I/O transfers */
123102ac6454SAndrew Thompson 	if (ep_dir == UE_DIR_IN) {
123202ac6454SAndrew Thompson 		temp = 0xFF ^ (USS820_EPCON_TXOE |
123302ac6454SAndrew Thompson 		    USS820_EPCON_TXSTL);
123402ac6454SAndrew Thompson 	} else {
123502ac6454SAndrew Thompson 		temp = 0xFF ^ (USS820_EPCON_RXIE |
123602ac6454SAndrew Thompson 		    USS820_EPCON_RXSTL);
123702ac6454SAndrew Thompson 	}
123802ac6454SAndrew Thompson 	uss820dci_update_shared_1(sc, USS820_EPCON, temp, 0);
123902ac6454SAndrew Thompson 
124002ac6454SAndrew Thompson 	if (ep_dir == UE_DIR_IN) {
124102ac6454SAndrew Thompson 		/* reset data toggle */
124202ac6454SAndrew Thompson 		USS820_WRITE_1(sc, USS820_TXSTAT,
124302ac6454SAndrew Thompson 		    USS820_TXSTAT_TXSOVW);
124402ac6454SAndrew Thompson 
124502ac6454SAndrew Thompson 		/* reset FIFO */
124602ac6454SAndrew Thompson 		temp = USS820_READ_1(sc, USS820_TXCON);
124702ac6454SAndrew Thompson 		temp |= USS820_TXCON_TXCLR;
124802ac6454SAndrew Thompson 		USS820_WRITE_1(sc, USS820_TXCON, temp);
124902ac6454SAndrew Thompson 		temp &= ~USS820_TXCON_TXCLR;
125002ac6454SAndrew Thompson 		USS820_WRITE_1(sc, USS820_TXCON, temp);
125102ac6454SAndrew Thompson 	} else {
125202ac6454SAndrew Thompson 
125302ac6454SAndrew Thompson 		/* reset data toggle */
125402ac6454SAndrew Thompson 		uss820dci_update_shared_1(sc, USS820_RXSTAT,
125502ac6454SAndrew Thompson 		    0, USS820_RXSTAT_RXSOVW);
125602ac6454SAndrew Thompson 
125702ac6454SAndrew Thompson 		/* reset FIFO */
125802ac6454SAndrew Thompson 		temp = USS820_READ_1(sc, USS820_RXCON);
125902ac6454SAndrew Thompson 		temp |= USS820_RXCON_RXCLR;
126002ac6454SAndrew Thompson 		temp &= ~USS820_RXCON_RXFFRC;
126102ac6454SAndrew Thompson 		USS820_WRITE_1(sc, USS820_RXCON, temp);
126202ac6454SAndrew Thompson 		temp &= ~USS820_RXCON_RXCLR;
126302ac6454SAndrew Thompson 		USS820_WRITE_1(sc, USS820_RXCON, temp);
126402ac6454SAndrew Thompson 	}
126502ac6454SAndrew Thompson }
126602ac6454SAndrew Thompson 
126702ac6454SAndrew Thompson static void
126802ac6454SAndrew Thompson uss820dci_clear_stall(struct usb2_device *udev, struct usb2_pipe *pipe)
126902ac6454SAndrew Thompson {
127002ac6454SAndrew Thompson 	struct uss820dci_softc *sc;
127102ac6454SAndrew Thompson 	struct usb2_endpoint_descriptor *ed;
127202ac6454SAndrew Thompson 
127302ac6454SAndrew Thompson 	USB_BUS_LOCK_ASSERT(udev->bus, MA_OWNED);
127402ac6454SAndrew Thompson 
127502ac6454SAndrew Thompson 	DPRINTFN(5, "pipe=%p\n", pipe);
127602ac6454SAndrew Thompson 
127702ac6454SAndrew Thompson 	/* check mode */
127802ac6454SAndrew Thompson 	if (udev->flags.usb2_mode != USB_MODE_DEVICE) {
127902ac6454SAndrew Thompson 		/* not supported */
128002ac6454SAndrew Thompson 		return;
128102ac6454SAndrew Thompson 	}
128202ac6454SAndrew Thompson 	/* get softc */
128302ac6454SAndrew Thompson 	sc = USS820_DCI_BUS2SC(udev->bus);
128402ac6454SAndrew Thompson 
128502ac6454SAndrew Thompson 	/* get endpoint descriptor */
128602ac6454SAndrew Thompson 	ed = pipe->edesc;
128702ac6454SAndrew Thompson 
128802ac6454SAndrew Thompson 	/* reset endpoint */
128902ac6454SAndrew Thompson 	uss820dci_clear_stall_sub(sc,
129002ac6454SAndrew Thompson 	    (ed->bEndpointAddress & UE_ADDR),
129102ac6454SAndrew Thompson 	    (ed->bmAttributes & UE_XFERTYPE),
129202ac6454SAndrew Thompson 	    (ed->bEndpointAddress & (UE_DIR_IN | UE_DIR_OUT)));
129302ac6454SAndrew Thompson }
129402ac6454SAndrew Thompson 
129502ac6454SAndrew Thompson usb2_error_t
129602ac6454SAndrew Thompson uss820dci_init(struct uss820dci_softc *sc)
129702ac6454SAndrew Thompson {
129802ac6454SAndrew Thompson 	const struct usb2_hw_ep_profile *pf;
129902ac6454SAndrew Thompson 	uint8_t n;
130002ac6454SAndrew Thompson 	uint8_t temp;
130102ac6454SAndrew Thompson 
130202ac6454SAndrew Thompson 	DPRINTF("start\n");
130302ac6454SAndrew Thompson 
130402ac6454SAndrew Thompson 	/* set up the bus structure */
130502ac6454SAndrew Thompson 	sc->sc_bus.usbrev = USB_REV_1_1;
130602ac6454SAndrew Thompson 	sc->sc_bus.methods = &uss820dci_bus_methods;
130702ac6454SAndrew Thompson 
130802ac6454SAndrew Thompson 	USB_BUS_LOCK(&sc->sc_bus);
130902ac6454SAndrew Thompson 
131002ac6454SAndrew Thompson 	/* we always have VBUS */
131102ac6454SAndrew Thompson 	sc->sc_flags.status_vbus = 1;
131202ac6454SAndrew Thompson 
131302ac6454SAndrew Thompson 	/* reset the chip */
131402ac6454SAndrew Thompson 	USS820_WRITE_1(sc, USS820_SCR, USS820_SCR_SRESET);
131502ac6454SAndrew Thompson 	DELAY(100);
131602ac6454SAndrew Thompson 	USS820_WRITE_1(sc, USS820_SCR, 0);
131702ac6454SAndrew Thompson 
131802ac6454SAndrew Thompson 	/* wait for reset to complete */
131902ac6454SAndrew Thompson 	for (n = 0;; n++) {
132002ac6454SAndrew Thompson 
132102ac6454SAndrew Thompson 		temp = USS820_READ_1(sc, USS820_MCSR);
132202ac6454SAndrew Thompson 
132302ac6454SAndrew Thompson 		if (temp & USS820_MCSR_INIT) {
132402ac6454SAndrew Thompson 			break;
132502ac6454SAndrew Thompson 		}
132602ac6454SAndrew Thompson 		if (n == 100) {
132702ac6454SAndrew Thompson 			USB_BUS_UNLOCK(&sc->sc_bus);
132802ac6454SAndrew Thompson 			return (USB_ERR_INVAL);
132902ac6454SAndrew Thompson 		}
133002ac6454SAndrew Thompson 		/* wait a little for things to stabilise */
133102ac6454SAndrew Thompson 		DELAY(100);
133202ac6454SAndrew Thompson 	}
133302ac6454SAndrew Thompson 
133402ac6454SAndrew Thompson 	/* do a pulldown */
133502ac6454SAndrew Thompson 	uss820dci_pull_down(sc);
133602ac6454SAndrew Thompson 
133702ac6454SAndrew Thompson 	/* wait 10ms for pulldown to stabilise */
133802ac6454SAndrew Thompson 	usb2_pause_mtx(&sc->sc_bus.bus_mtx, hz / 100);
133902ac6454SAndrew Thompson 
134002ac6454SAndrew Thompson 	/* check hardware revision */
134102ac6454SAndrew Thompson 	temp = USS820_READ_1(sc, USS820_REV);
134202ac6454SAndrew Thompson 
134302ac6454SAndrew Thompson 	if (temp < 0x13) {
134402ac6454SAndrew Thompson 		USB_BUS_UNLOCK(&sc->sc_bus);
134502ac6454SAndrew Thompson 		return (USB_ERR_INVAL);
134602ac6454SAndrew Thompson 	}
134702ac6454SAndrew Thompson 	/* enable interrupts */
134802ac6454SAndrew Thompson 	USS820_WRITE_1(sc, USS820_SCR,
134902ac6454SAndrew Thompson 	    USS820_SCR_T_IRQ |
135002ac6454SAndrew Thompson 	    USS820_SCR_IE_RESET |
135102ac6454SAndrew Thompson 	/* USS820_SCR_RWUPE | */
135202ac6454SAndrew Thompson 	    USS820_SCR_IE_SUSP |
135302ac6454SAndrew Thompson 	    USS820_SCR_IRQPOL);
135402ac6454SAndrew Thompson 
135502ac6454SAndrew Thompson 	/* enable interrupts */
135602ac6454SAndrew Thompson 	USS820_WRITE_1(sc, USS820_SCRATCH,
135702ac6454SAndrew Thompson 	    USS820_SCRATCH_IE_RESUME);
135802ac6454SAndrew Thompson 
135902ac6454SAndrew Thompson 	/* enable features */
136002ac6454SAndrew Thompson 	USS820_WRITE_1(sc, USS820_MCSR,
136102ac6454SAndrew Thompson 	    USS820_MCSR_BDFEAT |
136202ac6454SAndrew Thompson 	    USS820_MCSR_FEAT);
136302ac6454SAndrew Thompson 
136402ac6454SAndrew Thompson 	sc->sc_flags.mcsr_feat = 1;
136502ac6454SAndrew Thompson 
136602ac6454SAndrew Thompson 	/* disable interrupts */
136702ac6454SAndrew Thompson 	USS820_WRITE_1(sc, USS820_SBIE, 0);
136802ac6454SAndrew Thompson 
136902ac6454SAndrew Thompson 	/* disable interrupts */
137002ac6454SAndrew Thompson 	USS820_WRITE_1(sc, USS820_SBIE1, 0);
137102ac6454SAndrew Thompson 
137202ac6454SAndrew Thompson 	/* disable all endpoints */
137302ac6454SAndrew Thompson 	for (n = 0; n != USS820_EP_MAX; n++) {
137402ac6454SAndrew Thompson 
137502ac6454SAndrew Thompson 		/* select endpoint */
137602ac6454SAndrew Thompson 		USS820_WRITE_1(sc, USS820_EPINDEX, n);
137702ac6454SAndrew Thompson 
137802ac6454SAndrew Thompson 		/* disable endpoint */
137902ac6454SAndrew Thompson 		uss820dci_update_shared_1(sc, USS820_EPCON, 0, 0);
138002ac6454SAndrew Thompson 	}
138102ac6454SAndrew Thompson 
138202ac6454SAndrew Thompson 	/*
138302ac6454SAndrew Thompson 	 * Initialise default values for some registers that cannot be
138402ac6454SAndrew Thompson 	 * changed during operation!
138502ac6454SAndrew Thompson 	 */
138602ac6454SAndrew Thompson 	for (n = 0; n != USS820_EP_MAX; n++) {
138702ac6454SAndrew Thompson 
138802ac6454SAndrew Thompson 		uss820dci_get_hw_ep_profile(NULL, &pf, n);
138902ac6454SAndrew Thompson 
139002ac6454SAndrew Thompson 		/* the maximum frame sizes should be the same */
139102ac6454SAndrew Thompson 		if (pf->max_in_frame_size != pf->max_out_frame_size) {
139202ac6454SAndrew Thompson 			DPRINTF("Max frame size mismatch %u != %u\n",
139302ac6454SAndrew Thompson 			    pf->max_in_frame_size, pf->max_out_frame_size);
139402ac6454SAndrew Thompson 		}
139502ac6454SAndrew Thompson 		if (pf->support_isochronous) {
139602ac6454SAndrew Thompson 			if (pf->max_in_frame_size <= 64) {
139702ac6454SAndrew Thompson 				temp = (USS820_TXCON_FFSZ_16_64 |
139802ac6454SAndrew Thompson 				    USS820_TXCON_TXISO |
139902ac6454SAndrew Thompson 				    USS820_TXCON_ATM);
140002ac6454SAndrew Thompson 			} else if (pf->max_in_frame_size <= 256) {
140102ac6454SAndrew Thompson 				temp = (USS820_TXCON_FFSZ_64_256 |
140202ac6454SAndrew Thompson 				    USS820_TXCON_TXISO |
140302ac6454SAndrew Thompson 				    USS820_TXCON_ATM);
140402ac6454SAndrew Thompson 			} else if (pf->max_in_frame_size <= 512) {
140502ac6454SAndrew Thompson 				temp = (USS820_TXCON_FFSZ_8_512 |
140602ac6454SAndrew Thompson 				    USS820_TXCON_TXISO |
140702ac6454SAndrew Thompson 				    USS820_TXCON_ATM);
140802ac6454SAndrew Thompson 			} else {	/* 1024 bytes */
140902ac6454SAndrew Thompson 				temp = (USS820_TXCON_FFSZ_32_1024 |
141002ac6454SAndrew Thompson 				    USS820_TXCON_TXISO |
141102ac6454SAndrew Thompson 				    USS820_TXCON_ATM);
141202ac6454SAndrew Thompson 			}
141302ac6454SAndrew Thompson 		} else {
141402ac6454SAndrew Thompson 			if ((pf->max_in_frame_size <= 8) &&
141502ac6454SAndrew Thompson 			    (sc->sc_flags.mcsr_feat)) {
141602ac6454SAndrew Thompson 				temp = (USS820_TXCON_FFSZ_8_512 |
141702ac6454SAndrew Thompson 				    USS820_TXCON_ATM);
141802ac6454SAndrew Thompson 			} else if (pf->max_in_frame_size <= 16) {
141902ac6454SAndrew Thompson 				temp = (USS820_TXCON_FFSZ_16_64 |
142002ac6454SAndrew Thompson 				    USS820_TXCON_ATM);
142102ac6454SAndrew Thompson 			} else if ((pf->max_in_frame_size <= 32) &&
142202ac6454SAndrew Thompson 			    (sc->sc_flags.mcsr_feat)) {
142302ac6454SAndrew Thompson 				temp = (USS820_TXCON_FFSZ_32_1024 |
142402ac6454SAndrew Thompson 				    USS820_TXCON_ATM);
142502ac6454SAndrew Thompson 			} else {	/* 64 bytes */
142602ac6454SAndrew Thompson 				temp = (USS820_TXCON_FFSZ_64_256 |
142702ac6454SAndrew Thompson 				    USS820_TXCON_ATM);
142802ac6454SAndrew Thompson 			}
142902ac6454SAndrew Thompson 		}
143002ac6454SAndrew Thompson 
143102ac6454SAndrew Thompson 		/* need to configure the chip early */
143202ac6454SAndrew Thompson 
143302ac6454SAndrew Thompson 		USS820_WRITE_1(sc, USS820_EPINDEX, n);
143402ac6454SAndrew Thompson 		USS820_WRITE_1(sc, USS820_TXCON, temp);
143502ac6454SAndrew Thompson 		USS820_WRITE_1(sc, USS820_RXCON, temp);
143602ac6454SAndrew Thompson 
143702ac6454SAndrew Thompson 		if (pf->support_control) {
143802ac6454SAndrew Thompson 			temp = USS820_EPCON_CTLEP |
143902ac6454SAndrew Thompson 			    USS820_EPCON_RXSPM |
144002ac6454SAndrew Thompson 			    USS820_EPCON_RXIE |
144102ac6454SAndrew Thompson 			    USS820_EPCON_RXEPEN |
144202ac6454SAndrew Thompson 			    USS820_EPCON_TXOE |
144302ac6454SAndrew Thompson 			    USS820_EPCON_TXEPEN;
144402ac6454SAndrew Thompson 		} else {
144502ac6454SAndrew Thompson 			temp = USS820_EPCON_RXEPEN | USS820_EPCON_TXEPEN;
144602ac6454SAndrew Thompson 		}
144702ac6454SAndrew Thompson 
144802ac6454SAndrew Thompson 		uss820dci_update_shared_1(sc, USS820_EPCON, 0xFF, temp);
144902ac6454SAndrew Thompson 	}
145002ac6454SAndrew Thompson 
145102ac6454SAndrew Thompson 	USB_BUS_UNLOCK(&sc->sc_bus);
145202ac6454SAndrew Thompson 
145302ac6454SAndrew Thompson 	/* catch any lost interrupts */
145402ac6454SAndrew Thompson 
145502ac6454SAndrew Thompson 	uss820dci_do_poll(&sc->sc_bus);
145602ac6454SAndrew Thompson 
145702ac6454SAndrew Thompson 	return (0);			/* success */
145802ac6454SAndrew Thompson }
145902ac6454SAndrew Thompson 
146002ac6454SAndrew Thompson void
146102ac6454SAndrew Thompson uss820dci_uninit(struct uss820dci_softc *sc)
146202ac6454SAndrew Thompson {
146302ac6454SAndrew Thompson 	uint8_t temp;
146402ac6454SAndrew Thompson 
146502ac6454SAndrew Thompson 	USB_BUS_LOCK(&sc->sc_bus);
146602ac6454SAndrew Thompson 
146702ac6454SAndrew Thompson 	/* disable all interrupts */
146802ac6454SAndrew Thompson 	temp = USS820_READ_1(sc, USS820_SCR);
146902ac6454SAndrew Thompson 	temp &= ~USS820_SCR_T_IRQ;
147002ac6454SAndrew Thompson 	USS820_WRITE_1(sc, USS820_SCR, temp);
147102ac6454SAndrew Thompson 
147202ac6454SAndrew Thompson 	sc->sc_flags.port_powered = 0;
147302ac6454SAndrew Thompson 	sc->sc_flags.status_vbus = 0;
147402ac6454SAndrew Thompson 	sc->sc_flags.status_bus_reset = 0;
147502ac6454SAndrew Thompson 	sc->sc_flags.status_suspend = 0;
147602ac6454SAndrew Thompson 	sc->sc_flags.change_suspend = 0;
147702ac6454SAndrew Thompson 	sc->sc_flags.change_connect = 1;
147802ac6454SAndrew Thompson 
147902ac6454SAndrew Thompson 	uss820dci_pull_down(sc);
148002ac6454SAndrew Thompson 	USB_BUS_UNLOCK(&sc->sc_bus);
148102ac6454SAndrew Thompson }
148202ac6454SAndrew Thompson 
148302ac6454SAndrew Thompson void
148402ac6454SAndrew Thompson uss820dci_suspend(struct uss820dci_softc *sc)
148502ac6454SAndrew Thompson {
148602ac6454SAndrew Thompson 	return;
148702ac6454SAndrew Thompson }
148802ac6454SAndrew Thompson 
148902ac6454SAndrew Thompson void
149002ac6454SAndrew Thompson uss820dci_resume(struct uss820dci_softc *sc)
149102ac6454SAndrew Thompson {
149202ac6454SAndrew Thompson 	return;
149302ac6454SAndrew Thompson }
149402ac6454SAndrew Thompson 
149502ac6454SAndrew Thompson static void
149602ac6454SAndrew Thompson uss820dci_do_poll(struct usb2_bus *bus)
149702ac6454SAndrew Thompson {
149802ac6454SAndrew Thompson 	struct uss820dci_softc *sc = USS820_DCI_BUS2SC(bus);
149902ac6454SAndrew Thompson 
150002ac6454SAndrew Thompson 	USB_BUS_LOCK(&sc->sc_bus);
150102ac6454SAndrew Thompson 	uss820dci_interrupt_poll(sc);
150202ac6454SAndrew Thompson 	uss820dci_root_ctrl_poll(sc);
150302ac6454SAndrew Thompson 	USB_BUS_UNLOCK(&sc->sc_bus);
150402ac6454SAndrew Thompson }
150502ac6454SAndrew Thompson 
150602ac6454SAndrew Thompson /*------------------------------------------------------------------------*
150702ac6454SAndrew Thompson  * at91dci bulk support
150802ac6454SAndrew Thompson  *------------------------------------------------------------------------*/
150902ac6454SAndrew Thompson static void
151002ac6454SAndrew Thompson uss820dci_device_bulk_open(struct usb2_xfer *xfer)
151102ac6454SAndrew Thompson {
151202ac6454SAndrew Thompson 	return;
151302ac6454SAndrew Thompson }
151402ac6454SAndrew Thompson 
151502ac6454SAndrew Thompson static void
151602ac6454SAndrew Thompson uss820dci_device_bulk_close(struct usb2_xfer *xfer)
151702ac6454SAndrew Thompson {
151802ac6454SAndrew Thompson 	uss820dci_device_done(xfer, USB_ERR_CANCELLED);
151902ac6454SAndrew Thompson }
152002ac6454SAndrew Thompson 
152102ac6454SAndrew Thompson static void
152202ac6454SAndrew Thompson uss820dci_device_bulk_enter(struct usb2_xfer *xfer)
152302ac6454SAndrew Thompson {
152402ac6454SAndrew Thompson 	return;
152502ac6454SAndrew Thompson }
152602ac6454SAndrew Thompson 
152702ac6454SAndrew Thompson static void
152802ac6454SAndrew Thompson uss820dci_device_bulk_start(struct usb2_xfer *xfer)
152902ac6454SAndrew Thompson {
153002ac6454SAndrew Thompson 	/* setup TDs */
153102ac6454SAndrew Thompson 	uss820dci_setup_standard_chain(xfer);
153202ac6454SAndrew Thompson 	uss820dci_start_standard_chain(xfer);
153302ac6454SAndrew Thompson }
153402ac6454SAndrew Thompson 
153502ac6454SAndrew Thompson struct usb2_pipe_methods uss820dci_device_bulk_methods =
153602ac6454SAndrew Thompson {
153702ac6454SAndrew Thompson 	.open = uss820dci_device_bulk_open,
153802ac6454SAndrew Thompson 	.close = uss820dci_device_bulk_close,
153902ac6454SAndrew Thompson 	.enter = uss820dci_device_bulk_enter,
154002ac6454SAndrew Thompson 	.start = uss820dci_device_bulk_start,
154102ac6454SAndrew Thompson 	.enter_is_cancelable = 1,
154202ac6454SAndrew Thompson 	.start_is_cancelable = 1,
154302ac6454SAndrew Thompson };
154402ac6454SAndrew Thompson 
154502ac6454SAndrew Thompson /*------------------------------------------------------------------------*
154602ac6454SAndrew Thompson  * at91dci control support
154702ac6454SAndrew Thompson  *------------------------------------------------------------------------*/
154802ac6454SAndrew Thompson static void
154902ac6454SAndrew Thompson uss820dci_device_ctrl_open(struct usb2_xfer *xfer)
155002ac6454SAndrew Thompson {
155102ac6454SAndrew Thompson 	return;
155202ac6454SAndrew Thompson }
155302ac6454SAndrew Thompson 
155402ac6454SAndrew Thompson static void
155502ac6454SAndrew Thompson uss820dci_device_ctrl_close(struct usb2_xfer *xfer)
155602ac6454SAndrew Thompson {
155702ac6454SAndrew Thompson 	uss820dci_device_done(xfer, USB_ERR_CANCELLED);
155802ac6454SAndrew Thompson }
155902ac6454SAndrew Thompson 
156002ac6454SAndrew Thompson static void
156102ac6454SAndrew Thompson uss820dci_device_ctrl_enter(struct usb2_xfer *xfer)
156202ac6454SAndrew Thompson {
156302ac6454SAndrew Thompson 	return;
156402ac6454SAndrew Thompson }
156502ac6454SAndrew Thompson 
156602ac6454SAndrew Thompson static void
156702ac6454SAndrew Thompson uss820dci_device_ctrl_start(struct usb2_xfer *xfer)
156802ac6454SAndrew Thompson {
156902ac6454SAndrew Thompson 	/* setup TDs */
157002ac6454SAndrew Thompson 	uss820dci_setup_standard_chain(xfer);
157102ac6454SAndrew Thompson 	uss820dci_start_standard_chain(xfer);
157202ac6454SAndrew Thompson }
157302ac6454SAndrew Thompson 
157402ac6454SAndrew Thompson struct usb2_pipe_methods uss820dci_device_ctrl_methods =
157502ac6454SAndrew Thompson {
157602ac6454SAndrew Thompson 	.open = uss820dci_device_ctrl_open,
157702ac6454SAndrew Thompson 	.close = uss820dci_device_ctrl_close,
157802ac6454SAndrew Thompson 	.enter = uss820dci_device_ctrl_enter,
157902ac6454SAndrew Thompson 	.start = uss820dci_device_ctrl_start,
158002ac6454SAndrew Thompson 	.enter_is_cancelable = 1,
158102ac6454SAndrew Thompson 	.start_is_cancelable = 1,
158202ac6454SAndrew Thompson };
158302ac6454SAndrew Thompson 
158402ac6454SAndrew Thompson /*------------------------------------------------------------------------*
158502ac6454SAndrew Thompson  * at91dci interrupt support
158602ac6454SAndrew Thompson  *------------------------------------------------------------------------*/
158702ac6454SAndrew Thompson static void
158802ac6454SAndrew Thompson uss820dci_device_intr_open(struct usb2_xfer *xfer)
158902ac6454SAndrew Thompson {
159002ac6454SAndrew Thompson 	return;
159102ac6454SAndrew Thompson }
159202ac6454SAndrew Thompson 
159302ac6454SAndrew Thompson static void
159402ac6454SAndrew Thompson uss820dci_device_intr_close(struct usb2_xfer *xfer)
159502ac6454SAndrew Thompson {
159602ac6454SAndrew Thompson 	uss820dci_device_done(xfer, USB_ERR_CANCELLED);
159702ac6454SAndrew Thompson }
159802ac6454SAndrew Thompson 
159902ac6454SAndrew Thompson static void
160002ac6454SAndrew Thompson uss820dci_device_intr_enter(struct usb2_xfer *xfer)
160102ac6454SAndrew Thompson {
160202ac6454SAndrew Thompson 	return;
160302ac6454SAndrew Thompson }
160402ac6454SAndrew Thompson 
160502ac6454SAndrew Thompson static void
160602ac6454SAndrew Thompson uss820dci_device_intr_start(struct usb2_xfer *xfer)
160702ac6454SAndrew Thompson {
160802ac6454SAndrew Thompson 	/* setup TDs */
160902ac6454SAndrew Thompson 	uss820dci_setup_standard_chain(xfer);
161002ac6454SAndrew Thompson 	uss820dci_start_standard_chain(xfer);
161102ac6454SAndrew Thompson }
161202ac6454SAndrew Thompson 
161302ac6454SAndrew Thompson struct usb2_pipe_methods uss820dci_device_intr_methods =
161402ac6454SAndrew Thompson {
161502ac6454SAndrew Thompson 	.open = uss820dci_device_intr_open,
161602ac6454SAndrew Thompson 	.close = uss820dci_device_intr_close,
161702ac6454SAndrew Thompson 	.enter = uss820dci_device_intr_enter,
161802ac6454SAndrew Thompson 	.start = uss820dci_device_intr_start,
161902ac6454SAndrew Thompson 	.enter_is_cancelable = 1,
162002ac6454SAndrew Thompson 	.start_is_cancelable = 1,
162102ac6454SAndrew Thompson };
162202ac6454SAndrew Thompson 
162302ac6454SAndrew Thompson /*------------------------------------------------------------------------*
162402ac6454SAndrew Thompson  * at91dci full speed isochronous support
162502ac6454SAndrew Thompson  *------------------------------------------------------------------------*/
162602ac6454SAndrew Thompson static void
162702ac6454SAndrew Thompson uss820dci_device_isoc_fs_open(struct usb2_xfer *xfer)
162802ac6454SAndrew Thompson {
162902ac6454SAndrew Thompson 	return;
163002ac6454SAndrew Thompson }
163102ac6454SAndrew Thompson 
163202ac6454SAndrew Thompson static void
163302ac6454SAndrew Thompson uss820dci_device_isoc_fs_close(struct usb2_xfer *xfer)
163402ac6454SAndrew Thompson {
163502ac6454SAndrew Thompson 	uss820dci_device_done(xfer, USB_ERR_CANCELLED);
163602ac6454SAndrew Thompson }
163702ac6454SAndrew Thompson 
163802ac6454SAndrew Thompson static void
163902ac6454SAndrew Thompson uss820dci_device_isoc_fs_enter(struct usb2_xfer *xfer)
164002ac6454SAndrew Thompson {
164102ac6454SAndrew Thompson 	struct uss820dci_softc *sc = USS820_DCI_BUS2SC(xfer->xroot->bus);
164202ac6454SAndrew Thompson 	uint32_t temp;
164302ac6454SAndrew Thompson 	uint32_t nframes;
164402ac6454SAndrew Thompson 
164502ac6454SAndrew Thompson 	DPRINTFN(6, "xfer=%p next=%d nframes=%d\n",
164602ac6454SAndrew Thompson 	    xfer, xfer->pipe->isoc_next, xfer->nframes);
164702ac6454SAndrew Thompson 
164802ac6454SAndrew Thompson 	/* get the current frame index - we don't need the high bits */
164902ac6454SAndrew Thompson 
165002ac6454SAndrew Thompson 	nframes = USS820_READ_1(sc, USS820_SOFL);
165102ac6454SAndrew Thompson 
165202ac6454SAndrew Thompson 	/*
165302ac6454SAndrew Thompson 	 * check if the frame index is within the window where the
165402ac6454SAndrew Thompson 	 * frames will be inserted
165502ac6454SAndrew Thompson 	 */
165602ac6454SAndrew Thompson 	temp = (nframes - xfer->pipe->isoc_next) & USS820_SOFL_MASK;
165702ac6454SAndrew Thompson 
165802ac6454SAndrew Thompson 	if ((xfer->pipe->is_synced == 0) ||
165902ac6454SAndrew Thompson 	    (temp < xfer->nframes)) {
166002ac6454SAndrew Thompson 		/*
166102ac6454SAndrew Thompson 		 * If there is data underflow or the pipe queue is
166202ac6454SAndrew Thompson 		 * empty we schedule the transfer a few frames ahead
166302ac6454SAndrew Thompson 		 * of the current frame position. Else two isochronous
166402ac6454SAndrew Thompson 		 * transfers might overlap.
166502ac6454SAndrew Thompson 		 */
166602ac6454SAndrew Thompson 		xfer->pipe->isoc_next = (nframes + 3) & USS820_SOFL_MASK;
166702ac6454SAndrew Thompson 		xfer->pipe->is_synced = 1;
166802ac6454SAndrew Thompson 		DPRINTFN(3, "start next=%d\n", xfer->pipe->isoc_next);
166902ac6454SAndrew Thompson 	}
167002ac6454SAndrew Thompson 	/*
167102ac6454SAndrew Thompson 	 * compute how many milliseconds the insertion is ahead of the
167202ac6454SAndrew Thompson 	 * current frame position:
167302ac6454SAndrew Thompson 	 */
167402ac6454SAndrew Thompson 	temp = (xfer->pipe->isoc_next - nframes) & USS820_SOFL_MASK;
167502ac6454SAndrew Thompson 
167602ac6454SAndrew Thompson 	/*
167702ac6454SAndrew Thompson 	 * pre-compute when the isochronous transfer will be finished:
167802ac6454SAndrew Thompson 	 */
167902ac6454SAndrew Thompson 	xfer->isoc_time_complete =
168002ac6454SAndrew Thompson 	    usb2_isoc_time_expand(&sc->sc_bus, nframes) + temp +
168102ac6454SAndrew Thompson 	    xfer->nframes;
168202ac6454SAndrew Thompson 
168302ac6454SAndrew Thompson 	/* compute frame number for next insertion */
168402ac6454SAndrew Thompson 	xfer->pipe->isoc_next += xfer->nframes;
168502ac6454SAndrew Thompson 
168602ac6454SAndrew Thompson 	/* setup TDs */
168702ac6454SAndrew Thompson 	uss820dci_setup_standard_chain(xfer);
168802ac6454SAndrew Thompson }
168902ac6454SAndrew Thompson 
169002ac6454SAndrew Thompson static void
169102ac6454SAndrew Thompson uss820dci_device_isoc_fs_start(struct usb2_xfer *xfer)
169202ac6454SAndrew Thompson {
169302ac6454SAndrew Thompson 	/* start TD chain */
169402ac6454SAndrew Thompson 	uss820dci_start_standard_chain(xfer);
169502ac6454SAndrew Thompson }
169602ac6454SAndrew Thompson 
169702ac6454SAndrew Thompson struct usb2_pipe_methods uss820dci_device_isoc_fs_methods =
169802ac6454SAndrew Thompson {
169902ac6454SAndrew Thompson 	.open = uss820dci_device_isoc_fs_open,
170002ac6454SAndrew Thompson 	.close = uss820dci_device_isoc_fs_close,
170102ac6454SAndrew Thompson 	.enter = uss820dci_device_isoc_fs_enter,
170202ac6454SAndrew Thompson 	.start = uss820dci_device_isoc_fs_start,
170302ac6454SAndrew Thompson 	.enter_is_cancelable = 1,
170402ac6454SAndrew Thompson 	.start_is_cancelable = 1,
170502ac6454SAndrew Thompson };
170602ac6454SAndrew Thompson 
170702ac6454SAndrew Thompson /*------------------------------------------------------------------------*
170802ac6454SAndrew Thompson  * at91dci root control support
170902ac6454SAndrew Thompson  *------------------------------------------------------------------------*
171002ac6454SAndrew Thompson  * simulate a hardware HUB by handling
171102ac6454SAndrew Thompson  * all the necessary requests
171202ac6454SAndrew Thompson  *------------------------------------------------------------------------*/
171302ac6454SAndrew Thompson 
171402ac6454SAndrew Thompson static void
171502ac6454SAndrew Thompson uss820dci_root_ctrl_open(struct usb2_xfer *xfer)
171602ac6454SAndrew Thompson {
171702ac6454SAndrew Thompson 	return;
171802ac6454SAndrew Thompson }
171902ac6454SAndrew Thompson 
172002ac6454SAndrew Thompson static void
172102ac6454SAndrew Thompson uss820dci_root_ctrl_close(struct usb2_xfer *xfer)
172202ac6454SAndrew Thompson {
172302ac6454SAndrew Thompson 	struct uss820dci_softc *sc = USS820_DCI_BUS2SC(xfer->xroot->bus);
172402ac6454SAndrew Thompson 
172502ac6454SAndrew Thompson 	if (sc->sc_root_ctrl.xfer == xfer) {
172602ac6454SAndrew Thompson 		sc->sc_root_ctrl.xfer = NULL;
172702ac6454SAndrew Thompson 	}
172802ac6454SAndrew Thompson 	uss820dci_device_done(xfer, USB_ERR_CANCELLED);
172902ac6454SAndrew Thompson }
173002ac6454SAndrew Thompson 
173102ac6454SAndrew Thompson /*
173202ac6454SAndrew Thompson  * USB descriptors for the virtual Root HUB:
173302ac6454SAndrew Thompson  */
173402ac6454SAndrew Thompson 
173502ac6454SAndrew Thompson static const struct usb2_device_descriptor uss820dci_devd = {
173602ac6454SAndrew Thompson 	.bLength = sizeof(struct usb2_device_descriptor),
173702ac6454SAndrew Thompson 	.bDescriptorType = UDESC_DEVICE,
173802ac6454SAndrew Thompson 	.bcdUSB = {0x00, 0x02},
173902ac6454SAndrew Thompson 	.bDeviceClass = UDCLASS_HUB,
174002ac6454SAndrew Thompson 	.bDeviceSubClass = UDSUBCLASS_HUB,
174102ac6454SAndrew Thompson 	.bDeviceProtocol = UDPROTO_HSHUBSTT,
174202ac6454SAndrew Thompson 	.bMaxPacketSize = 64,
174302ac6454SAndrew Thompson 	.bcdDevice = {0x00, 0x01},
174402ac6454SAndrew Thompson 	.iManufacturer = 1,
174502ac6454SAndrew Thompson 	.iProduct = 2,
174602ac6454SAndrew Thompson 	.bNumConfigurations = 1,
174702ac6454SAndrew Thompson };
174802ac6454SAndrew Thompson 
174902ac6454SAndrew Thompson static const struct usb2_device_qualifier uss820dci_odevd = {
175002ac6454SAndrew Thompson 	.bLength = sizeof(struct usb2_device_qualifier),
175102ac6454SAndrew Thompson 	.bDescriptorType = UDESC_DEVICE_QUALIFIER,
175202ac6454SAndrew Thompson 	.bcdUSB = {0x00, 0x02},
175302ac6454SAndrew Thompson 	.bDeviceClass = UDCLASS_HUB,
175402ac6454SAndrew Thompson 	.bDeviceSubClass = UDSUBCLASS_HUB,
175502ac6454SAndrew Thompson 	.bDeviceProtocol = UDPROTO_FSHUB,
175602ac6454SAndrew Thompson 	.bMaxPacketSize0 = 0,
175702ac6454SAndrew Thompson 	.bNumConfigurations = 0,
175802ac6454SAndrew Thompson };
175902ac6454SAndrew Thompson 
176002ac6454SAndrew Thompson static const struct uss820dci_config_desc uss820dci_confd = {
176102ac6454SAndrew Thompson 	.confd = {
176202ac6454SAndrew Thompson 		.bLength = sizeof(struct usb2_config_descriptor),
176302ac6454SAndrew Thompson 		.bDescriptorType = UDESC_CONFIG,
176402ac6454SAndrew Thompson 		.wTotalLength[0] = sizeof(uss820dci_confd),
176502ac6454SAndrew Thompson 		.bNumInterface = 1,
176602ac6454SAndrew Thompson 		.bConfigurationValue = 1,
176702ac6454SAndrew Thompson 		.iConfiguration = 0,
176802ac6454SAndrew Thompson 		.bmAttributes = UC_SELF_POWERED,
176902ac6454SAndrew Thompson 		.bMaxPower = 0,
177002ac6454SAndrew Thompson 	},
177102ac6454SAndrew Thompson 	.ifcd = {
177202ac6454SAndrew Thompson 		.bLength = sizeof(struct usb2_interface_descriptor),
177302ac6454SAndrew Thompson 		.bDescriptorType = UDESC_INTERFACE,
177402ac6454SAndrew Thompson 		.bNumEndpoints = 1,
177502ac6454SAndrew Thompson 		.bInterfaceClass = UICLASS_HUB,
177602ac6454SAndrew Thompson 		.bInterfaceSubClass = UISUBCLASS_HUB,
177702ac6454SAndrew Thompson 		.bInterfaceProtocol = UIPROTO_HSHUBSTT,
177802ac6454SAndrew Thompson 	},
177902ac6454SAndrew Thompson 
178002ac6454SAndrew Thompson 	.endpd = {
178102ac6454SAndrew Thompson 		.bLength = sizeof(struct usb2_endpoint_descriptor),
178202ac6454SAndrew Thompson 		.bDescriptorType = UDESC_ENDPOINT,
178302ac6454SAndrew Thompson 		.bEndpointAddress = (UE_DIR_IN | USS820_DCI_INTR_ENDPT),
178402ac6454SAndrew Thompson 		.bmAttributes = UE_INTERRUPT,
178502ac6454SAndrew Thompson 		.wMaxPacketSize[0] = 8,
178602ac6454SAndrew Thompson 		.bInterval = 255,
178702ac6454SAndrew Thompson 	},
178802ac6454SAndrew Thompson };
178902ac6454SAndrew Thompson 
179002ac6454SAndrew Thompson static const struct usb2_hub_descriptor_min uss820dci_hubd = {
179102ac6454SAndrew Thompson 	.bDescLength = sizeof(uss820dci_hubd),
179202ac6454SAndrew Thompson 	.bDescriptorType = UDESC_HUB,
179302ac6454SAndrew Thompson 	.bNbrPorts = 1,
179402ac6454SAndrew Thompson 	.wHubCharacteristics[0] =
179502ac6454SAndrew Thompson 	(UHD_PWR_NO_SWITCH | UHD_OC_INDIVIDUAL) & 0xFF,
179602ac6454SAndrew Thompson 	.wHubCharacteristics[1] =
179702ac6454SAndrew Thompson 	(UHD_PWR_NO_SWITCH | UHD_OC_INDIVIDUAL) >> 8,
179802ac6454SAndrew Thompson 	.bPwrOn2PwrGood = 50,
179902ac6454SAndrew Thompson 	.bHubContrCurrent = 0,
180002ac6454SAndrew Thompson 	.DeviceRemovable = {0},		/* port is removable */
180102ac6454SAndrew Thompson };
180202ac6454SAndrew Thompson 
180302ac6454SAndrew Thompson #define	STRING_LANG \
180402ac6454SAndrew Thompson   0x09, 0x04,				/* American English */
180502ac6454SAndrew Thompson 
180602ac6454SAndrew Thompson #define	STRING_VENDOR \
180702ac6454SAndrew Thompson   'A', 0, 'G', 0, 'E', 0, 'R', 0, 'E', 0
180802ac6454SAndrew Thompson 
180902ac6454SAndrew Thompson #define	STRING_PRODUCT \
181002ac6454SAndrew Thompson   'D', 0, 'C', 0, 'I', 0, ' ', 0, 'R', 0, \
181102ac6454SAndrew Thompson   'o', 0, 'o', 0, 't', 0, ' ', 0, 'H', 0, \
181202ac6454SAndrew Thompson   'U', 0, 'B', 0,
181302ac6454SAndrew Thompson 
181402ac6454SAndrew Thompson USB_MAKE_STRING_DESC(STRING_LANG, uss820dci_langtab);
181502ac6454SAndrew Thompson USB_MAKE_STRING_DESC(STRING_VENDOR, uss820dci_vendor);
181602ac6454SAndrew Thompson USB_MAKE_STRING_DESC(STRING_PRODUCT, uss820dci_product);
181702ac6454SAndrew Thompson 
181802ac6454SAndrew Thompson static void
181902ac6454SAndrew Thompson uss820dci_root_ctrl_enter(struct usb2_xfer *xfer)
182002ac6454SAndrew Thompson {
182102ac6454SAndrew Thompson 	return;
182202ac6454SAndrew Thompson }
182302ac6454SAndrew Thompson 
182402ac6454SAndrew Thompson static void
182502ac6454SAndrew Thompson uss820dci_root_ctrl_start(struct usb2_xfer *xfer)
182602ac6454SAndrew Thompson {
182702ac6454SAndrew Thompson 	struct uss820dci_softc *sc = USS820_DCI_BUS2SC(xfer->xroot->bus);
182802ac6454SAndrew Thompson 
182902ac6454SAndrew Thompson 	sc->sc_root_ctrl.xfer = xfer;
183002ac6454SAndrew Thompson 
183102ac6454SAndrew Thompson 	usb2_bus_roothub_exec(xfer->xroot->bus);
183202ac6454SAndrew Thompson }
183302ac6454SAndrew Thompson 
183402ac6454SAndrew Thompson static void
183502ac6454SAndrew Thompson uss820dci_root_ctrl_task(struct usb2_bus *bus)
183602ac6454SAndrew Thompson {
183702ac6454SAndrew Thompson 	uss820dci_root_ctrl_poll(USS820_DCI_BUS2SC(bus));
183802ac6454SAndrew Thompson }
183902ac6454SAndrew Thompson 
184002ac6454SAndrew Thompson static void
184102ac6454SAndrew Thompson uss820dci_root_ctrl_done(struct usb2_xfer *xfer,
184202ac6454SAndrew Thompson     struct usb2_sw_transfer *std)
184302ac6454SAndrew Thompson {
184402ac6454SAndrew Thompson 	struct uss820dci_softc *sc = USS820_DCI_BUS2SC(xfer->xroot->bus);
184502ac6454SAndrew Thompson 	uint16_t value;
184602ac6454SAndrew Thompson 	uint16_t index;
184702ac6454SAndrew Thompson 
184802ac6454SAndrew Thompson 	USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
184902ac6454SAndrew Thompson 
185002ac6454SAndrew Thompson 	if (std->state != USB_SW_TR_SETUP) {
185102ac6454SAndrew Thompson 		if (std->state == USB_SW_TR_PRE_CALLBACK) {
185202ac6454SAndrew Thompson 			/* transfer transferred */
185302ac6454SAndrew Thompson 			uss820dci_device_done(xfer, std->err);
185402ac6454SAndrew Thompson 		}
185502ac6454SAndrew Thompson 		goto done;
185602ac6454SAndrew Thompson 	}
185702ac6454SAndrew Thompson 	/* buffer reset */
185802ac6454SAndrew Thompson 	std->ptr = USB_ADD_BYTES(&sc->sc_hub_temp, 0);
185902ac6454SAndrew Thompson 	std->len = 0;
186002ac6454SAndrew Thompson 
186102ac6454SAndrew Thompson 	value = UGETW(std->req.wValue);
186202ac6454SAndrew Thompson 	index = UGETW(std->req.wIndex);
186302ac6454SAndrew Thompson 
186402ac6454SAndrew Thompson 	/* demultiplex the control request */
186502ac6454SAndrew Thompson 
186602ac6454SAndrew Thompson 	switch (std->req.bmRequestType) {
186702ac6454SAndrew Thompson 	case UT_READ_DEVICE:
186802ac6454SAndrew Thompson 		switch (std->req.bRequest) {
186902ac6454SAndrew Thompson 		case UR_GET_DESCRIPTOR:
187002ac6454SAndrew Thompson 			goto tr_handle_get_descriptor;
187102ac6454SAndrew Thompson 		case UR_GET_CONFIG:
187202ac6454SAndrew Thompson 			goto tr_handle_get_config;
187302ac6454SAndrew Thompson 		case UR_GET_STATUS:
187402ac6454SAndrew Thompson 			goto tr_handle_get_status;
187502ac6454SAndrew Thompson 		default:
187602ac6454SAndrew Thompson 			goto tr_stalled;
187702ac6454SAndrew Thompson 		}
187802ac6454SAndrew Thompson 		break;
187902ac6454SAndrew Thompson 
188002ac6454SAndrew Thompson 	case UT_WRITE_DEVICE:
188102ac6454SAndrew Thompson 		switch (std->req.bRequest) {
188202ac6454SAndrew Thompson 		case UR_SET_ADDRESS:
188302ac6454SAndrew Thompson 			goto tr_handle_set_address;
188402ac6454SAndrew Thompson 		case UR_SET_CONFIG:
188502ac6454SAndrew Thompson 			goto tr_handle_set_config;
188602ac6454SAndrew Thompson 		case UR_CLEAR_FEATURE:
188702ac6454SAndrew Thompson 			goto tr_valid;	/* nop */
188802ac6454SAndrew Thompson 		case UR_SET_DESCRIPTOR:
188902ac6454SAndrew Thompson 			goto tr_valid;	/* nop */
189002ac6454SAndrew Thompson 		case UR_SET_FEATURE:
189102ac6454SAndrew Thompson 		default:
189202ac6454SAndrew Thompson 			goto tr_stalled;
189302ac6454SAndrew Thompson 		}
189402ac6454SAndrew Thompson 		break;
189502ac6454SAndrew Thompson 
189602ac6454SAndrew Thompson 	case UT_WRITE_ENDPOINT:
189702ac6454SAndrew Thompson 		switch (std->req.bRequest) {
189802ac6454SAndrew Thompson 		case UR_CLEAR_FEATURE:
189902ac6454SAndrew Thompson 			switch (UGETW(std->req.wValue)) {
190002ac6454SAndrew Thompson 			case UF_ENDPOINT_HALT:
190102ac6454SAndrew Thompson 				goto tr_handle_clear_halt;
190202ac6454SAndrew Thompson 			case UF_DEVICE_REMOTE_WAKEUP:
190302ac6454SAndrew Thompson 				goto tr_handle_clear_wakeup;
190402ac6454SAndrew Thompson 			default:
190502ac6454SAndrew Thompson 				goto tr_stalled;
190602ac6454SAndrew Thompson 			}
190702ac6454SAndrew Thompson 			break;
190802ac6454SAndrew Thompson 		case UR_SET_FEATURE:
190902ac6454SAndrew Thompson 			switch (UGETW(std->req.wValue)) {
191002ac6454SAndrew Thompson 			case UF_ENDPOINT_HALT:
191102ac6454SAndrew Thompson 				goto tr_handle_set_halt;
191202ac6454SAndrew Thompson 			case UF_DEVICE_REMOTE_WAKEUP:
191302ac6454SAndrew Thompson 				goto tr_handle_set_wakeup;
191402ac6454SAndrew Thompson 			default:
191502ac6454SAndrew Thompson 				goto tr_stalled;
191602ac6454SAndrew Thompson 			}
191702ac6454SAndrew Thompson 			break;
191802ac6454SAndrew Thompson 		case UR_SYNCH_FRAME:
191902ac6454SAndrew Thompson 			goto tr_valid;	/* nop */
192002ac6454SAndrew Thompson 		default:
192102ac6454SAndrew Thompson 			goto tr_stalled;
192202ac6454SAndrew Thompson 		}
192302ac6454SAndrew Thompson 		break;
192402ac6454SAndrew Thompson 
192502ac6454SAndrew Thompson 	case UT_READ_ENDPOINT:
192602ac6454SAndrew Thompson 		switch (std->req.bRequest) {
192702ac6454SAndrew Thompson 		case UR_GET_STATUS:
192802ac6454SAndrew Thompson 			goto tr_handle_get_ep_status;
192902ac6454SAndrew Thompson 		default:
193002ac6454SAndrew Thompson 			goto tr_stalled;
193102ac6454SAndrew Thompson 		}
193202ac6454SAndrew Thompson 		break;
193302ac6454SAndrew Thompson 
193402ac6454SAndrew Thompson 	case UT_WRITE_INTERFACE:
193502ac6454SAndrew Thompson 		switch (std->req.bRequest) {
193602ac6454SAndrew Thompson 		case UR_SET_INTERFACE:
193702ac6454SAndrew Thompson 			goto tr_handle_set_interface;
193802ac6454SAndrew Thompson 		case UR_CLEAR_FEATURE:
193902ac6454SAndrew Thompson 			goto tr_valid;	/* nop */
194002ac6454SAndrew Thompson 		case UR_SET_FEATURE:
194102ac6454SAndrew Thompson 		default:
194202ac6454SAndrew Thompson 			goto tr_stalled;
194302ac6454SAndrew Thompson 		}
194402ac6454SAndrew Thompson 		break;
194502ac6454SAndrew Thompson 
194602ac6454SAndrew Thompson 	case UT_READ_INTERFACE:
194702ac6454SAndrew Thompson 		switch (std->req.bRequest) {
194802ac6454SAndrew Thompson 		case UR_GET_INTERFACE:
194902ac6454SAndrew Thompson 			goto tr_handle_get_interface;
195002ac6454SAndrew Thompson 		case UR_GET_STATUS:
195102ac6454SAndrew Thompson 			goto tr_handle_get_iface_status;
195202ac6454SAndrew Thompson 		default:
195302ac6454SAndrew Thompson 			goto tr_stalled;
195402ac6454SAndrew Thompson 		}
195502ac6454SAndrew Thompson 		break;
195602ac6454SAndrew Thompson 
195702ac6454SAndrew Thompson 	case UT_WRITE_CLASS_INTERFACE:
195802ac6454SAndrew Thompson 	case UT_WRITE_VENDOR_INTERFACE:
195902ac6454SAndrew Thompson 		/* XXX forward */
196002ac6454SAndrew Thompson 		break;
196102ac6454SAndrew Thompson 
196202ac6454SAndrew Thompson 	case UT_READ_CLASS_INTERFACE:
196302ac6454SAndrew Thompson 	case UT_READ_VENDOR_INTERFACE:
196402ac6454SAndrew Thompson 		/* XXX forward */
196502ac6454SAndrew Thompson 		break;
196602ac6454SAndrew Thompson 
196702ac6454SAndrew Thompson 	case UT_WRITE_CLASS_DEVICE:
196802ac6454SAndrew Thompson 		switch (std->req.bRequest) {
196902ac6454SAndrew Thompson 		case UR_CLEAR_FEATURE:
197002ac6454SAndrew Thompson 			goto tr_valid;
197102ac6454SAndrew Thompson 		case UR_SET_DESCRIPTOR:
197202ac6454SAndrew Thompson 		case UR_SET_FEATURE:
197302ac6454SAndrew Thompson 			break;
197402ac6454SAndrew Thompson 		default:
197502ac6454SAndrew Thompson 			goto tr_stalled;
197602ac6454SAndrew Thompson 		}
197702ac6454SAndrew Thompson 		break;
197802ac6454SAndrew Thompson 
197902ac6454SAndrew Thompson 	case UT_WRITE_CLASS_OTHER:
198002ac6454SAndrew Thompson 		switch (std->req.bRequest) {
198102ac6454SAndrew Thompson 		case UR_CLEAR_FEATURE:
198202ac6454SAndrew Thompson 			goto tr_handle_clear_port_feature;
198302ac6454SAndrew Thompson 		case UR_SET_FEATURE:
198402ac6454SAndrew Thompson 			goto tr_handle_set_port_feature;
198502ac6454SAndrew Thompson 		case UR_CLEAR_TT_BUFFER:
198602ac6454SAndrew Thompson 		case UR_RESET_TT:
198702ac6454SAndrew Thompson 		case UR_STOP_TT:
198802ac6454SAndrew Thompson 			goto tr_valid;
198902ac6454SAndrew Thompson 
199002ac6454SAndrew Thompson 		default:
199102ac6454SAndrew Thompson 			goto tr_stalled;
199202ac6454SAndrew Thompson 		}
199302ac6454SAndrew Thompson 		break;
199402ac6454SAndrew Thompson 
199502ac6454SAndrew Thompson 	case UT_READ_CLASS_OTHER:
199602ac6454SAndrew Thompson 		switch (std->req.bRequest) {
199702ac6454SAndrew Thompson 		case UR_GET_TT_STATE:
199802ac6454SAndrew Thompson 			goto tr_handle_get_tt_state;
199902ac6454SAndrew Thompson 		case UR_GET_STATUS:
200002ac6454SAndrew Thompson 			goto tr_handle_get_port_status;
200102ac6454SAndrew Thompson 		default:
200202ac6454SAndrew Thompson 			goto tr_stalled;
200302ac6454SAndrew Thompson 		}
200402ac6454SAndrew Thompson 		break;
200502ac6454SAndrew Thompson 
200602ac6454SAndrew Thompson 	case UT_READ_CLASS_DEVICE:
200702ac6454SAndrew Thompson 		switch (std->req.bRequest) {
200802ac6454SAndrew Thompson 		case UR_GET_DESCRIPTOR:
200902ac6454SAndrew Thompson 			goto tr_handle_get_class_descriptor;
201002ac6454SAndrew Thompson 		case UR_GET_STATUS:
201102ac6454SAndrew Thompson 			goto tr_handle_get_class_status;
201202ac6454SAndrew Thompson 
201302ac6454SAndrew Thompson 		default:
201402ac6454SAndrew Thompson 			goto tr_stalled;
201502ac6454SAndrew Thompson 		}
201602ac6454SAndrew Thompson 		break;
201702ac6454SAndrew Thompson 	default:
201802ac6454SAndrew Thompson 		goto tr_stalled;
201902ac6454SAndrew Thompson 	}
202002ac6454SAndrew Thompson 	goto tr_valid;
202102ac6454SAndrew Thompson 
202202ac6454SAndrew Thompson tr_handle_get_descriptor:
202302ac6454SAndrew Thompson 	switch (value >> 8) {
202402ac6454SAndrew Thompson 	case UDESC_DEVICE:
202502ac6454SAndrew Thompson 		if (value & 0xff) {
202602ac6454SAndrew Thompson 			goto tr_stalled;
202702ac6454SAndrew Thompson 		}
202802ac6454SAndrew Thompson 		std->len = sizeof(uss820dci_devd);
202902ac6454SAndrew Thompson 		std->ptr = USB_ADD_BYTES(&uss820dci_devd, 0);
203002ac6454SAndrew Thompson 		goto tr_valid;
203102ac6454SAndrew Thompson 	case UDESC_CONFIG:
203202ac6454SAndrew Thompson 		if (value & 0xff) {
203302ac6454SAndrew Thompson 			goto tr_stalled;
203402ac6454SAndrew Thompson 		}
203502ac6454SAndrew Thompson 		std->len = sizeof(uss820dci_confd);
203602ac6454SAndrew Thompson 		std->ptr = USB_ADD_BYTES(&uss820dci_confd, 0);
203702ac6454SAndrew Thompson 		goto tr_valid;
203802ac6454SAndrew Thompson 	case UDESC_STRING:
203902ac6454SAndrew Thompson 		switch (value & 0xff) {
204002ac6454SAndrew Thompson 		case 0:		/* Language table */
204102ac6454SAndrew Thompson 			std->len = sizeof(uss820dci_langtab);
204202ac6454SAndrew Thompson 			std->ptr = USB_ADD_BYTES(&uss820dci_langtab, 0);
204302ac6454SAndrew Thompson 			goto tr_valid;
204402ac6454SAndrew Thompson 
204502ac6454SAndrew Thompson 		case 1:		/* Vendor */
204602ac6454SAndrew Thompson 			std->len = sizeof(uss820dci_vendor);
204702ac6454SAndrew Thompson 			std->ptr = USB_ADD_BYTES(&uss820dci_vendor, 0);
204802ac6454SAndrew Thompson 			goto tr_valid;
204902ac6454SAndrew Thompson 
205002ac6454SAndrew Thompson 		case 2:		/* Product */
205102ac6454SAndrew Thompson 			std->len = sizeof(uss820dci_product);
205202ac6454SAndrew Thompson 			std->ptr = USB_ADD_BYTES(&uss820dci_product, 0);
205302ac6454SAndrew Thompson 			goto tr_valid;
205402ac6454SAndrew Thompson 		default:
205502ac6454SAndrew Thompson 			break;
205602ac6454SAndrew Thompson 		}
205702ac6454SAndrew Thompson 		break;
205802ac6454SAndrew Thompson 	default:
205902ac6454SAndrew Thompson 		goto tr_stalled;
206002ac6454SAndrew Thompson 	}
206102ac6454SAndrew Thompson 	goto tr_stalled;
206202ac6454SAndrew Thompson 
206302ac6454SAndrew Thompson tr_handle_get_config:
206402ac6454SAndrew Thompson 	std->len = 1;
206502ac6454SAndrew Thompson 	sc->sc_hub_temp.wValue[0] = sc->sc_conf;
206602ac6454SAndrew Thompson 	goto tr_valid;
206702ac6454SAndrew Thompson 
206802ac6454SAndrew Thompson tr_handle_get_status:
206902ac6454SAndrew Thompson 	std->len = 2;
207002ac6454SAndrew Thompson 	USETW(sc->sc_hub_temp.wValue, UDS_SELF_POWERED);
207102ac6454SAndrew Thompson 	goto tr_valid;
207202ac6454SAndrew Thompson 
207302ac6454SAndrew Thompson tr_handle_set_address:
207402ac6454SAndrew Thompson 	if (value & 0xFF00) {
207502ac6454SAndrew Thompson 		goto tr_stalled;
207602ac6454SAndrew Thompson 	}
207702ac6454SAndrew Thompson 	sc->sc_rt_addr = value;
207802ac6454SAndrew Thompson 	goto tr_valid;
207902ac6454SAndrew Thompson 
208002ac6454SAndrew Thompson tr_handle_set_config:
208102ac6454SAndrew Thompson 	if (value >= 2) {
208202ac6454SAndrew Thompson 		goto tr_stalled;
208302ac6454SAndrew Thompson 	}
208402ac6454SAndrew Thompson 	sc->sc_conf = value;
208502ac6454SAndrew Thompson 	goto tr_valid;
208602ac6454SAndrew Thompson 
208702ac6454SAndrew Thompson tr_handle_get_interface:
208802ac6454SAndrew Thompson 	std->len = 1;
208902ac6454SAndrew Thompson 	sc->sc_hub_temp.wValue[0] = 0;
209002ac6454SAndrew Thompson 	goto tr_valid;
209102ac6454SAndrew Thompson 
209202ac6454SAndrew Thompson tr_handle_get_tt_state:
209302ac6454SAndrew Thompson tr_handle_get_class_status:
209402ac6454SAndrew Thompson tr_handle_get_iface_status:
209502ac6454SAndrew Thompson tr_handle_get_ep_status:
209602ac6454SAndrew Thompson 	std->len = 2;
209702ac6454SAndrew Thompson 	USETW(sc->sc_hub_temp.wValue, 0);
209802ac6454SAndrew Thompson 	goto tr_valid;
209902ac6454SAndrew Thompson 
210002ac6454SAndrew Thompson tr_handle_set_halt:
210102ac6454SAndrew Thompson tr_handle_set_interface:
210202ac6454SAndrew Thompson tr_handle_set_wakeup:
210302ac6454SAndrew Thompson tr_handle_clear_wakeup:
210402ac6454SAndrew Thompson tr_handle_clear_halt:
210502ac6454SAndrew Thompson 	goto tr_valid;
210602ac6454SAndrew Thompson 
210702ac6454SAndrew Thompson tr_handle_clear_port_feature:
210802ac6454SAndrew Thompson 	if (index != 1) {
210902ac6454SAndrew Thompson 		goto tr_stalled;
211002ac6454SAndrew Thompson 	}
211102ac6454SAndrew Thompson 	DPRINTFN(9, "UR_CLEAR_PORT_FEATURE on port %d\n", index);
211202ac6454SAndrew Thompson 
211302ac6454SAndrew Thompson 	switch (value) {
211402ac6454SAndrew Thompson 	case UHF_PORT_SUSPEND:
211502ac6454SAndrew Thompson 		uss820dci_wakeup_peer(sc);
211602ac6454SAndrew Thompson 		break;
211702ac6454SAndrew Thompson 
211802ac6454SAndrew Thompson 	case UHF_PORT_ENABLE:
211902ac6454SAndrew Thompson 		sc->sc_flags.port_enabled = 0;
212002ac6454SAndrew Thompson 		break;
212102ac6454SAndrew Thompson 
212202ac6454SAndrew Thompson 	case UHF_PORT_TEST:
212302ac6454SAndrew Thompson 	case UHF_PORT_INDICATOR:
212402ac6454SAndrew Thompson 	case UHF_C_PORT_ENABLE:
212502ac6454SAndrew Thompson 	case UHF_C_PORT_OVER_CURRENT:
212602ac6454SAndrew Thompson 	case UHF_C_PORT_RESET:
212702ac6454SAndrew Thompson 		/* nops */
212802ac6454SAndrew Thompson 		break;
212902ac6454SAndrew Thompson 	case UHF_PORT_POWER:
213002ac6454SAndrew Thompson 		sc->sc_flags.port_powered = 0;
213102ac6454SAndrew Thompson 		uss820dci_pull_down(sc);
213202ac6454SAndrew Thompson 		break;
213302ac6454SAndrew Thompson 	case UHF_C_PORT_CONNECTION:
213402ac6454SAndrew Thompson 		sc->sc_flags.change_connect = 0;
213502ac6454SAndrew Thompson 		break;
213602ac6454SAndrew Thompson 	case UHF_C_PORT_SUSPEND:
213702ac6454SAndrew Thompson 		sc->sc_flags.change_suspend = 0;
213802ac6454SAndrew Thompson 		break;
213902ac6454SAndrew Thompson 	default:
214002ac6454SAndrew Thompson 		std->err = USB_ERR_IOERROR;
214102ac6454SAndrew Thompson 		goto done;
214202ac6454SAndrew Thompson 	}
214302ac6454SAndrew Thompson 	goto tr_valid;
214402ac6454SAndrew Thompson 
214502ac6454SAndrew Thompson tr_handle_set_port_feature:
214602ac6454SAndrew Thompson 	if (index != 1) {
214702ac6454SAndrew Thompson 		goto tr_stalled;
214802ac6454SAndrew Thompson 	}
214902ac6454SAndrew Thompson 	DPRINTFN(9, "UR_SET_PORT_FEATURE\n");
215002ac6454SAndrew Thompson 
215102ac6454SAndrew Thompson 	switch (value) {
215202ac6454SAndrew Thompson 	case UHF_PORT_ENABLE:
215302ac6454SAndrew Thompson 		sc->sc_flags.port_enabled = 1;
215402ac6454SAndrew Thompson 		break;
215502ac6454SAndrew Thompson 	case UHF_PORT_SUSPEND:
215602ac6454SAndrew Thompson 	case UHF_PORT_RESET:
215702ac6454SAndrew Thompson 	case UHF_PORT_TEST:
215802ac6454SAndrew Thompson 	case UHF_PORT_INDICATOR:
215902ac6454SAndrew Thompson 		/* nops */
216002ac6454SAndrew Thompson 		break;
216102ac6454SAndrew Thompson 	case UHF_PORT_POWER:
216202ac6454SAndrew Thompson 		sc->sc_flags.port_powered = 1;
216302ac6454SAndrew Thompson 		break;
216402ac6454SAndrew Thompson 	default:
216502ac6454SAndrew Thompson 		std->err = USB_ERR_IOERROR;
216602ac6454SAndrew Thompson 		goto done;
216702ac6454SAndrew Thompson 	}
216802ac6454SAndrew Thompson 	goto tr_valid;
216902ac6454SAndrew Thompson 
217002ac6454SAndrew Thompson tr_handle_get_port_status:
217102ac6454SAndrew Thompson 
217202ac6454SAndrew Thompson 	DPRINTFN(9, "UR_GET_PORT_STATUS\n");
217302ac6454SAndrew Thompson 
217402ac6454SAndrew Thompson 	if (index != 1) {
217502ac6454SAndrew Thompson 		goto tr_stalled;
217602ac6454SAndrew Thompson 	}
217702ac6454SAndrew Thompson 	if (sc->sc_flags.status_vbus) {
217802ac6454SAndrew Thompson 		uss820dci_pull_up(sc);
217902ac6454SAndrew Thompson 	} else {
218002ac6454SAndrew Thompson 		uss820dci_pull_down(sc);
218102ac6454SAndrew Thompson 	}
218202ac6454SAndrew Thompson 
218302ac6454SAndrew Thompson 	/* Select FULL-speed and Device Side Mode */
218402ac6454SAndrew Thompson 
218502ac6454SAndrew Thompson 	value = UPS_PORT_MODE_DEVICE;
218602ac6454SAndrew Thompson 
218702ac6454SAndrew Thompson 	if (sc->sc_flags.port_powered) {
218802ac6454SAndrew Thompson 		value |= UPS_PORT_POWER;
218902ac6454SAndrew Thompson 	}
219002ac6454SAndrew Thompson 	if (sc->sc_flags.port_enabled) {
219102ac6454SAndrew Thompson 		value |= UPS_PORT_ENABLED;
219202ac6454SAndrew Thompson 	}
219302ac6454SAndrew Thompson 	if (sc->sc_flags.status_vbus &&
219402ac6454SAndrew Thompson 	    sc->sc_flags.status_bus_reset) {
219502ac6454SAndrew Thompson 		value |= UPS_CURRENT_CONNECT_STATUS;
219602ac6454SAndrew Thompson 	}
219702ac6454SAndrew Thompson 	if (sc->sc_flags.status_suspend) {
219802ac6454SAndrew Thompson 		value |= UPS_SUSPEND;
219902ac6454SAndrew Thompson 	}
220002ac6454SAndrew Thompson 	USETW(sc->sc_hub_temp.ps.wPortStatus, value);
220102ac6454SAndrew Thompson 
220202ac6454SAndrew Thompson 	value = 0;
220302ac6454SAndrew Thompson 
220402ac6454SAndrew Thompson 	if (sc->sc_flags.change_connect) {
220502ac6454SAndrew Thompson 		value |= UPS_C_CONNECT_STATUS;
220602ac6454SAndrew Thompson 	}
220702ac6454SAndrew Thompson 	if (sc->sc_flags.change_suspend) {
220802ac6454SAndrew Thompson 		value |= UPS_C_SUSPEND;
220902ac6454SAndrew Thompson 	}
221002ac6454SAndrew Thompson 	USETW(sc->sc_hub_temp.ps.wPortChange, value);
221102ac6454SAndrew Thompson 	std->len = sizeof(sc->sc_hub_temp.ps);
221202ac6454SAndrew Thompson 	goto tr_valid;
221302ac6454SAndrew Thompson 
221402ac6454SAndrew Thompson tr_handle_get_class_descriptor:
221502ac6454SAndrew Thompson 	if (value & 0xFF) {
221602ac6454SAndrew Thompson 		goto tr_stalled;
221702ac6454SAndrew Thompson 	}
221802ac6454SAndrew Thompson 	std->ptr = USB_ADD_BYTES(&uss820dci_hubd, 0);
221902ac6454SAndrew Thompson 	std->len = sizeof(uss820dci_hubd);
222002ac6454SAndrew Thompson 	goto tr_valid;
222102ac6454SAndrew Thompson 
222202ac6454SAndrew Thompson tr_stalled:
222302ac6454SAndrew Thompson 	std->err = USB_ERR_STALLED;
222402ac6454SAndrew Thompson tr_valid:
222502ac6454SAndrew Thompson done:
222602ac6454SAndrew Thompson 	return;
222702ac6454SAndrew Thompson }
222802ac6454SAndrew Thompson 
222902ac6454SAndrew Thompson static void
223002ac6454SAndrew Thompson uss820dci_root_ctrl_poll(struct uss820dci_softc *sc)
223102ac6454SAndrew Thompson {
223202ac6454SAndrew Thompson 	usb2_sw_transfer(&sc->sc_root_ctrl,
223302ac6454SAndrew Thompson 	    &uss820dci_root_ctrl_done);
223402ac6454SAndrew Thompson }
223502ac6454SAndrew Thompson 
223602ac6454SAndrew Thompson struct usb2_pipe_methods uss820dci_root_ctrl_methods =
223702ac6454SAndrew Thompson {
223802ac6454SAndrew Thompson 	.open = uss820dci_root_ctrl_open,
223902ac6454SAndrew Thompson 	.close = uss820dci_root_ctrl_close,
224002ac6454SAndrew Thompson 	.enter = uss820dci_root_ctrl_enter,
224102ac6454SAndrew Thompson 	.start = uss820dci_root_ctrl_start,
224202ac6454SAndrew Thompson 	.enter_is_cancelable = 1,
224302ac6454SAndrew Thompson 	.start_is_cancelable = 0,
224402ac6454SAndrew Thompson };
224502ac6454SAndrew Thompson 
224602ac6454SAndrew Thompson /*------------------------------------------------------------------------*
224702ac6454SAndrew Thompson  * at91dci root interrupt support
224802ac6454SAndrew Thompson  *------------------------------------------------------------------------*/
224902ac6454SAndrew Thompson static void
225002ac6454SAndrew Thompson uss820dci_root_intr_open(struct usb2_xfer *xfer)
225102ac6454SAndrew Thompson {
225202ac6454SAndrew Thompson 	return;
225302ac6454SAndrew Thompson }
225402ac6454SAndrew Thompson 
225502ac6454SAndrew Thompson static void
225602ac6454SAndrew Thompson uss820dci_root_intr_close(struct usb2_xfer *xfer)
225702ac6454SAndrew Thompson {
225802ac6454SAndrew Thompson 	struct uss820dci_softc *sc = USS820_DCI_BUS2SC(xfer->xroot->bus);
225902ac6454SAndrew Thompson 
226002ac6454SAndrew Thompson 	if (sc->sc_root_intr.xfer == xfer) {
226102ac6454SAndrew Thompson 		sc->sc_root_intr.xfer = NULL;
226202ac6454SAndrew Thompson 	}
226302ac6454SAndrew Thompson 	uss820dci_device_done(xfer, USB_ERR_CANCELLED);
226402ac6454SAndrew Thompson }
226502ac6454SAndrew Thompson 
226602ac6454SAndrew Thompson static void
226702ac6454SAndrew Thompson uss820dci_root_intr_enter(struct usb2_xfer *xfer)
226802ac6454SAndrew Thompson {
226902ac6454SAndrew Thompson 	return;
227002ac6454SAndrew Thompson }
227102ac6454SAndrew Thompson 
227202ac6454SAndrew Thompson static void
227302ac6454SAndrew Thompson uss820dci_root_intr_start(struct usb2_xfer *xfer)
227402ac6454SAndrew Thompson {
227502ac6454SAndrew Thompson 	struct uss820dci_softc *sc = USS820_DCI_BUS2SC(xfer->xroot->bus);
227602ac6454SAndrew Thompson 
227702ac6454SAndrew Thompson 	sc->sc_root_intr.xfer = xfer;
227802ac6454SAndrew Thompson }
227902ac6454SAndrew Thompson 
228002ac6454SAndrew Thompson struct usb2_pipe_methods uss820dci_root_intr_methods =
228102ac6454SAndrew Thompson {
228202ac6454SAndrew Thompson 	.open = uss820dci_root_intr_open,
228302ac6454SAndrew Thompson 	.close = uss820dci_root_intr_close,
228402ac6454SAndrew Thompson 	.enter = uss820dci_root_intr_enter,
228502ac6454SAndrew Thompson 	.start = uss820dci_root_intr_start,
228602ac6454SAndrew Thompson 	.enter_is_cancelable = 1,
228702ac6454SAndrew Thompson 	.start_is_cancelable = 1,
228802ac6454SAndrew Thompson };
228902ac6454SAndrew Thompson 
229002ac6454SAndrew Thompson static void
229102ac6454SAndrew Thompson uss820dci_xfer_setup(struct usb2_setup_params *parm)
229202ac6454SAndrew Thompson {
229302ac6454SAndrew Thompson 	const struct usb2_hw_ep_profile *pf;
229402ac6454SAndrew Thompson 	struct uss820dci_softc *sc;
229502ac6454SAndrew Thompson 	struct usb2_xfer *xfer;
229602ac6454SAndrew Thompson 	void *last_obj;
229702ac6454SAndrew Thompson 	uint32_t ntd;
229802ac6454SAndrew Thompson 	uint32_t n;
229902ac6454SAndrew Thompson 	uint8_t ep_no;
230002ac6454SAndrew Thompson 
230102ac6454SAndrew Thompson 	sc = USS820_DCI_BUS2SC(parm->udev->bus);
230202ac6454SAndrew Thompson 	xfer = parm->curr_xfer;
230302ac6454SAndrew Thompson 
230402ac6454SAndrew Thompson 	/*
230502ac6454SAndrew Thompson 	 * NOTE: This driver does not use any of the parameters that
230602ac6454SAndrew Thompson 	 * are computed from the following values. Just set some
230702ac6454SAndrew Thompson 	 * reasonable dummies:
230802ac6454SAndrew Thompson 	 */
230902ac6454SAndrew Thompson 	parm->hc_max_packet_size = 0x500;
231002ac6454SAndrew Thompson 	parm->hc_max_packet_count = 1;
231102ac6454SAndrew Thompson 	parm->hc_max_frame_size = 0x500;
231202ac6454SAndrew Thompson 
231302ac6454SAndrew Thompson 	usb2_transfer_setup_sub(parm);
231402ac6454SAndrew Thompson 
231502ac6454SAndrew Thompson 	/*
231602ac6454SAndrew Thompson 	 * compute maximum number of TDs
231702ac6454SAndrew Thompson 	 */
231802ac6454SAndrew Thompson 	if (parm->methods == &uss820dci_device_ctrl_methods) {
231902ac6454SAndrew Thompson 
232002ac6454SAndrew Thompson 		ntd = xfer->nframes + 1 /* STATUS */ + 1 /* SYNC */ ;
232102ac6454SAndrew Thompson 
232202ac6454SAndrew Thompson 	} else if (parm->methods == &uss820dci_device_bulk_methods) {
232302ac6454SAndrew Thompson 
232402ac6454SAndrew Thompson 		ntd = xfer->nframes + 1 /* SYNC */ ;
232502ac6454SAndrew Thompson 
232602ac6454SAndrew Thompson 	} else if (parm->methods == &uss820dci_device_intr_methods) {
232702ac6454SAndrew Thompson 
232802ac6454SAndrew Thompson 		ntd = xfer->nframes + 1 /* SYNC */ ;
232902ac6454SAndrew Thompson 
233002ac6454SAndrew Thompson 	} else if (parm->methods == &uss820dci_device_isoc_fs_methods) {
233102ac6454SAndrew Thompson 
233202ac6454SAndrew Thompson 		ntd = xfer->nframes + 1 /* SYNC */ ;
233302ac6454SAndrew Thompson 
233402ac6454SAndrew Thompson 	} else {
233502ac6454SAndrew Thompson 
233602ac6454SAndrew Thompson 		ntd = 0;
233702ac6454SAndrew Thompson 	}
233802ac6454SAndrew Thompson 
233902ac6454SAndrew Thompson 	/*
234002ac6454SAndrew Thompson 	 * check if "usb2_transfer_setup_sub" set an error
234102ac6454SAndrew Thompson 	 */
234202ac6454SAndrew Thompson 	if (parm->err) {
234302ac6454SAndrew Thompson 		return;
234402ac6454SAndrew Thompson 	}
234502ac6454SAndrew Thompson 	/*
234602ac6454SAndrew Thompson 	 * allocate transfer descriptors
234702ac6454SAndrew Thompson 	 */
234802ac6454SAndrew Thompson 	last_obj = NULL;
234902ac6454SAndrew Thompson 
235002ac6454SAndrew Thompson 	/*
235102ac6454SAndrew Thompson 	 * get profile stuff
235202ac6454SAndrew Thompson 	 */
235302ac6454SAndrew Thompson 	if (ntd) {
235402ac6454SAndrew Thompson 
235502ac6454SAndrew Thompson 		ep_no = xfer->endpoint & UE_ADDR;
235602ac6454SAndrew Thompson 		uss820dci_get_hw_ep_profile(parm->udev, &pf, ep_no);
235702ac6454SAndrew Thompson 
235802ac6454SAndrew Thompson 		if (pf == NULL) {
235902ac6454SAndrew Thompson 			/* should not happen */
236002ac6454SAndrew Thompson 			parm->err = USB_ERR_INVAL;
236102ac6454SAndrew Thompson 			return;
236202ac6454SAndrew Thompson 		}
236302ac6454SAndrew Thompson 	} else {
236402ac6454SAndrew Thompson 		ep_no = 0;
236502ac6454SAndrew Thompson 		pf = NULL;
236602ac6454SAndrew Thompson 	}
236702ac6454SAndrew Thompson 
236802ac6454SAndrew Thompson 	/* align data */
236902ac6454SAndrew Thompson 	parm->size[0] += ((-parm->size[0]) & (USB_HOST_ALIGN - 1));
237002ac6454SAndrew Thompson 
237102ac6454SAndrew Thompson 	for (n = 0; n != ntd; n++) {
237202ac6454SAndrew Thompson 
237302ac6454SAndrew Thompson 		struct uss820dci_td *td;
237402ac6454SAndrew Thompson 
237502ac6454SAndrew Thompson 		if (parm->buf) {
237602ac6454SAndrew Thompson 
237702ac6454SAndrew Thompson 			td = USB_ADD_BYTES(parm->buf, parm->size[0]);
237802ac6454SAndrew Thompson 
237902ac6454SAndrew Thompson 			/* init TD */
238002ac6454SAndrew Thompson 			td->io_tag = sc->sc_io_tag;
238102ac6454SAndrew Thompson 			td->io_hdl = sc->sc_io_hdl;
238202ac6454SAndrew Thompson 			td->max_packet_size = xfer->max_packet_size;
238302ac6454SAndrew Thompson 			td->rx_stat_reg = USS820_GET_REG(sc, USS820_RXSTAT);
238402ac6454SAndrew Thompson 			td->tx_stat_reg = USS820_GET_REG(sc, USS820_TXSTAT);
238502ac6454SAndrew Thompson 			td->rx_flag_reg = USS820_GET_REG(sc, USS820_RXFLG);
238602ac6454SAndrew Thompson 			td->tx_flag_reg = USS820_GET_REG(sc, USS820_TXFLG);
238702ac6454SAndrew Thompson 			td->rx_fifo_reg = USS820_GET_REG(sc, USS820_RXDAT);
238802ac6454SAndrew Thompson 			td->tx_fifo_reg = USS820_GET_REG(sc, USS820_TXDAT);
238902ac6454SAndrew Thompson 			td->rx_count_low_reg = USS820_GET_REG(sc, USS820_RXCNTL);
239002ac6454SAndrew Thompson 			td->rx_count_high_reg = USS820_GET_REG(sc, USS820_RXCNTH);
239102ac6454SAndrew Thompson 			td->tx_count_low_reg = USS820_GET_REG(sc, USS820_TXCNTL);
239202ac6454SAndrew Thompson 			td->tx_count_high_reg = USS820_GET_REG(sc, USS820_TXCNTH);
239302ac6454SAndrew Thompson 			td->rx_cntl_reg = USS820_GET_REG(sc, USS820_RXCON);
239402ac6454SAndrew Thompson 			td->tx_cntl_reg = USS820_GET_REG(sc, USS820_TXCON);
239502ac6454SAndrew Thompson 			td->pend_reg = USS820_GET_REG(sc, USS820_PEND);
239602ac6454SAndrew Thompson 			td->ep_reg = USS820_GET_REG(sc, USS820_EPINDEX);
239702ac6454SAndrew Thompson 			td->ep_index = ep_no;
239802ac6454SAndrew Thompson 			if (pf->support_multi_buffer &&
239902ac6454SAndrew Thompson 			    (parm->methods != &uss820dci_device_ctrl_methods)) {
240002ac6454SAndrew Thompson 				td->support_multi_buffer = 1;
240102ac6454SAndrew Thompson 			}
240202ac6454SAndrew Thompson 			td->obj_next = last_obj;
240302ac6454SAndrew Thompson 
240402ac6454SAndrew Thompson 			last_obj = td;
240502ac6454SAndrew Thompson 		}
240602ac6454SAndrew Thompson 		parm->size[0] += sizeof(*td);
240702ac6454SAndrew Thompson 	}
240802ac6454SAndrew Thompson 
240902ac6454SAndrew Thompson 	xfer->td_start[0] = last_obj;
241002ac6454SAndrew Thompson }
241102ac6454SAndrew Thompson 
241202ac6454SAndrew Thompson static void
241302ac6454SAndrew Thompson uss820dci_xfer_unsetup(struct usb2_xfer *xfer)
241402ac6454SAndrew Thompson {
241502ac6454SAndrew Thompson 	return;
241602ac6454SAndrew Thompson }
241702ac6454SAndrew Thompson 
241802ac6454SAndrew Thompson static void
241902ac6454SAndrew Thompson uss820dci_pipe_init(struct usb2_device *udev, struct usb2_endpoint_descriptor *edesc,
242002ac6454SAndrew Thompson     struct usb2_pipe *pipe)
242102ac6454SAndrew Thompson {
242202ac6454SAndrew Thompson 	struct uss820dci_softc *sc = USS820_DCI_BUS2SC(udev->bus);
242302ac6454SAndrew Thompson 
242402ac6454SAndrew Thompson 	DPRINTFN(2, "pipe=%p, addr=%d, endpt=%d, mode=%d (%d)\n",
242502ac6454SAndrew Thompson 	    pipe, udev->address,
242602ac6454SAndrew Thompson 	    edesc->bEndpointAddress, udev->flags.usb2_mode,
242702ac6454SAndrew Thompson 	    sc->sc_rt_addr);
242802ac6454SAndrew Thompson 
242902ac6454SAndrew Thompson 	if (udev->device_index == sc->sc_rt_addr) {
243002ac6454SAndrew Thompson 
243102ac6454SAndrew Thompson 		if (udev->flags.usb2_mode != USB_MODE_HOST) {
243202ac6454SAndrew Thompson 			/* not supported */
243302ac6454SAndrew Thompson 			return;
243402ac6454SAndrew Thompson 		}
243502ac6454SAndrew Thompson 		switch (edesc->bEndpointAddress) {
243602ac6454SAndrew Thompson 		case USB_CONTROL_ENDPOINT:
243702ac6454SAndrew Thompson 			pipe->methods = &uss820dci_root_ctrl_methods;
243802ac6454SAndrew Thompson 			break;
243902ac6454SAndrew Thompson 		case UE_DIR_IN | USS820_DCI_INTR_ENDPT:
244002ac6454SAndrew Thompson 			pipe->methods = &uss820dci_root_intr_methods;
244102ac6454SAndrew Thompson 			break;
244202ac6454SAndrew Thompson 		default:
244302ac6454SAndrew Thompson 			/* do nothing */
244402ac6454SAndrew Thompson 			break;
244502ac6454SAndrew Thompson 		}
244602ac6454SAndrew Thompson 	} else {
244702ac6454SAndrew Thompson 
244802ac6454SAndrew Thompson 		if (udev->flags.usb2_mode != USB_MODE_DEVICE) {
244902ac6454SAndrew Thompson 			/* not supported */
245002ac6454SAndrew Thompson 			return;
245102ac6454SAndrew Thompson 		}
245202ac6454SAndrew Thompson 		if (udev->speed != USB_SPEED_FULL) {
245302ac6454SAndrew Thompson 			/* not supported */
245402ac6454SAndrew Thompson 			return;
245502ac6454SAndrew Thompson 		}
245602ac6454SAndrew Thompson 		switch (edesc->bmAttributes & UE_XFERTYPE) {
245702ac6454SAndrew Thompson 		case UE_CONTROL:
245802ac6454SAndrew Thompson 			pipe->methods = &uss820dci_device_ctrl_methods;
245902ac6454SAndrew Thompson 			break;
246002ac6454SAndrew Thompson 		case UE_INTERRUPT:
246102ac6454SAndrew Thompson 			pipe->methods = &uss820dci_device_intr_methods;
246202ac6454SAndrew Thompson 			break;
246302ac6454SAndrew Thompson 		case UE_ISOCHRONOUS:
246402ac6454SAndrew Thompson 			pipe->methods = &uss820dci_device_isoc_fs_methods;
246502ac6454SAndrew Thompson 			break;
246602ac6454SAndrew Thompson 		case UE_BULK:
246702ac6454SAndrew Thompson 			pipe->methods = &uss820dci_device_bulk_methods;
246802ac6454SAndrew Thompson 			break;
246902ac6454SAndrew Thompson 		default:
247002ac6454SAndrew Thompson 			/* do nothing */
247102ac6454SAndrew Thompson 			break;
247202ac6454SAndrew Thompson 		}
247302ac6454SAndrew Thompson 	}
247402ac6454SAndrew Thompson }
247502ac6454SAndrew Thompson 
247602ac6454SAndrew Thompson struct usb2_bus_methods uss820dci_bus_methods =
247702ac6454SAndrew Thompson {
247802ac6454SAndrew Thompson 	.pipe_init = &uss820dci_pipe_init,
247902ac6454SAndrew Thompson 	.xfer_setup = &uss820dci_xfer_setup,
248002ac6454SAndrew Thompson 	.xfer_unsetup = &uss820dci_xfer_unsetup,
248102ac6454SAndrew Thompson 	.get_hw_ep_profile = &uss820dci_get_hw_ep_profile,
248202ac6454SAndrew Thompson 	.set_stall = &uss820dci_set_stall,
248302ac6454SAndrew Thompson 	.clear_stall = &uss820dci_clear_stall,
248402ac6454SAndrew Thompson 	.roothub_exec = &uss820dci_root_ctrl_task,
248502ac6454SAndrew Thompson };
2486