#ifdef USB_GLOBAL_INCLUDE_FILE
#include USB_GLOBAL_INCLUDE_FILE
#else
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#define USB_DEBUG_VAR avr32dci_debug
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_busdma.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/usb_transfer.h>
#include <dev/usb/usb_device.h>
#include <dev/usb/usb_hub.h>
#include <dev/usb/usb_util.h>
#include <dev/usb/usb_controller.h>
#include <dev/usb/usb_bus.h>
#endif
#include <dev/usb/controller/avr32dci.h>
#define AVR32_BUS2SC(bus) \
__containerof(bus, struct avr32dci_softc, sc_bus)
#define AVR32_PC2SC(pc) \
AVR32_BUS2SC(USB_DMATAG_TO_XROOT((pc)->tag_parent)->bus)
#ifdef USB_DEBUG
static int avr32dci_debug = 0;
static SYSCTL_NODE(_hw_usb, OID_AUTO, avr32dci,
CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
"USB AVR32 DCI");
SYSCTL_INT(_hw_usb_avr32dci, OID_AUTO, debug, CTLFLAG_RWTUN,
&avr32dci_debug, 0, "AVR32 DCI debug level");
#endif
#define AVR32_INTR_ENDPT 1
static const struct usb_bus_methods avr32dci_bus_methods;
static const struct usb_pipe_methods avr32dci_device_non_isoc_methods;
static const struct usb_pipe_methods avr32dci_device_isoc_fs_methods;
static avr32dci_cmd_t avr32dci_setup_rx;
static avr32dci_cmd_t avr32dci_data_rx;
static avr32dci_cmd_t avr32dci_data_tx;
static avr32dci_cmd_t avr32dci_data_tx_sync;
static void avr32dci_device_done(struct usb_xfer *, usb_error_t);
static void avr32dci_do_poll(struct usb_bus *);
static void avr32dci_standard_done(struct usb_xfer *);
static void avr32dci_root_intr(struct avr32dci_softc *sc);
static const struct usb_hw_ep_profile
avr32dci_ep_profile[4] = {
[0] = {
.max_in_frame_size = 64,
.max_out_frame_size = 64,
.is_simplex = 1,
.support_control = 1,
},
[1] = {
.max_in_frame_size = 512,
.max_out_frame_size = 512,
.is_simplex = 1,
.support_bulk = 1,
.support_interrupt = 1,
.support_isochronous = 1,
.support_in = 1,
.support_out = 1,
},
[2] = {
.max_in_frame_size = 64,
.max_out_frame_size = 64,
.is_simplex = 1,
.support_bulk = 1,
.support_interrupt = 1,
.support_in = 1,
.support_out = 1,
},
[3] = {
.max_in_frame_size = 1024,
.max_out_frame_size = 1024,
.is_simplex = 1,
.support_bulk = 1,
.support_interrupt = 1,
.support_isochronous = 1,
.support_in = 1,
.support_out = 1,
},
};
static void
avr32dci_get_hw_ep_profile(struct usb_device *udev,
const struct usb_hw_ep_profile **ppf, uint8_t ep_addr)
{
if (ep_addr == 0)
*ppf = avr32dci_ep_profile;
else if (ep_addr < 3)
*ppf = avr32dci_ep_profile + 1;
else if (ep_addr < 5)
*ppf = avr32dci_ep_profile + 2;
else if (ep_addr < 7)
*ppf = avr32dci_ep_profile + 3;
else
*ppf = NULL;
}
static void
avr32dci_mod_ctrl(struct avr32dci_softc *sc, uint32_t set, uint32_t clear)
{
uint32_t temp;
temp = AVR32_READ_4(sc, AVR32_CTRL);
temp |= set;
temp &= ~clear;
AVR32_WRITE_4(sc, AVR32_CTRL, temp);
}
static void
avr32dci_mod_ien(struct avr32dci_softc *sc, uint32_t set, uint32_t clear)
{
uint32_t temp;
temp = AVR32_READ_4(sc, AVR32_IEN);
temp |= set;
temp &= ~clear;
AVR32_WRITE_4(sc, AVR32_IEN, temp);
}
static void
avr32dci_clocks_on(struct avr32dci_softc *sc)
{
if (sc->sc_flags.clocks_off &&
sc->sc_flags.port_powered) {
DPRINTFN(5, "\n");
(sc->sc_clocks_on) (&sc->sc_bus);
avr32dci_mod_ctrl(sc, AVR32_CTRL_DEV_EN_USBA, 0);
sc->sc_flags.clocks_off = 0;
}
}
static void
avr32dci_clocks_off(struct avr32dci_softc *sc)
{
if (!sc->sc_flags.clocks_off) {
DPRINTFN(5, "\n");
avr32dci_mod_ctrl(sc, 0, AVR32_CTRL_DEV_EN_USBA);
(sc->sc_clocks_off) (&sc->sc_bus);
sc->sc_flags.clocks_off = 1;
}
}
static void
avr32dci_pull_up(struct avr32dci_softc *sc)
{
if (!sc->sc_flags.d_pulled_up &&
sc->sc_flags.port_powered) {
sc->sc_flags.d_pulled_up = 1;
avr32dci_mod_ctrl(sc, 0, AVR32_CTRL_DEV_DETACH);
}
}
static void
avr32dci_pull_down(struct avr32dci_softc *sc)
{
if (sc->sc_flags.d_pulled_up) {
sc->sc_flags.d_pulled_up = 0;
avr32dci_mod_ctrl(sc, AVR32_CTRL_DEV_DETACH, 0);
}
}
static void
avr32dci_wakeup_peer(struct avr32dci_softc *sc)
{
if (!sc->sc_flags.status_suspend) {
return;
}
avr32dci_mod_ctrl(sc, AVR32_CTRL_DEV_REWAKEUP, 0);
usb_pause_mtx(&sc->sc_bus.bus_mtx, hz / 125);
}
static void
avr32dci_set_address(struct avr32dci_softc *sc, uint8_t addr)
{
DPRINTFN(5, "addr=%d\n", addr);
avr32dci_mod_ctrl(sc, AVR32_CTRL_DEV_FADDR_EN | addr, 0);
}
static uint8_t
avr32dci_setup_rx(struct avr32dci_td *td)
{
struct avr32dci_softc *sc;
struct usb_device_request req;
uint16_t count;
uint32_t temp;
sc = AVR32_PC2SC(td->pc);
temp = AVR32_READ_4(sc, AVR32_EPTSTA(td->ep_no));
DPRINTFN(5, "EPTSTA(%u)=0x%08x\n", td->ep_no, temp);
if (!(temp & AVR32_EPTSTA_RX_SETUP)) {
goto not_complete;
}
td->did_stall = 0;
count = AVR32_EPTSTA_BYTE_COUNT(temp);
if (count != td->remainder) {
DPRINTFN(0, "Invalid SETUP packet "
"length, %d bytes\n", count);
goto not_complete;
}
if (count != sizeof(req)) {
DPRINTFN(0, "Unsupported SETUP packet "
"length, %d bytes\n", count);
goto not_complete;
}
memcpy(&req, sc->physdata, sizeof(req));
usbd_copy_in(td->pc, 0, &req, sizeof(req));
td->offset = sizeof(req);
td->remainder = 0;
if ((req.bmRequestType == UT_WRITE_DEVICE) &&
(req.bRequest == UR_SET_ADDRESS)) {
sc->sc_dv_addr = req.wValue[0] & 0x7F;
avr32dci_mod_ctrl(sc, 0, AVR32_CTRL_DEV_FADDR_EN |
AVR32_CTRL_DEV_ADDR);
avr32dci_mod_ctrl(sc, sc->sc_dv_addr, 0);
} else {
sc->sc_dv_addr = 0xFF;
}
AVR32_WRITE_4(sc, AVR32_EPTCLRSTA(td->ep_no), AVR32_EPTSTA_RX_SETUP);
return (0);
not_complete:
if (temp & AVR32_EPTSTA_RX_SETUP) {
AVR32_WRITE_4(sc, AVR32_EPTCLRSTA(td->ep_no), AVR32_EPTSTA_RX_SETUP);
}
if (!td->did_stall) {
DPRINTFN(5, "stalling\n");
AVR32_WRITE_4(sc, AVR32_EPTSETSTA(td->ep_no),
AVR32_EPTSTA_FRCESTALL);
td->did_stall = 1;
}
return (1);
}
static uint8_t
avr32dci_data_rx(struct avr32dci_td *td)
{
struct avr32dci_softc *sc;
struct usb_page_search buf_res;
uint16_t count;
uint32_t temp;
uint8_t to;
uint8_t got_short;
to = 4;
got_short = 0;
sc = AVR32_PC2SC(td->pc);
repeat:
temp = AVR32_READ_4(sc, AVR32_EPTSTA(td->ep_no));
DPRINTFN(5, "EPTSTA(%u)=0x%08x\n", td->ep_no, temp);
if (temp & AVR32_EPTSTA_RX_SETUP) {
if (td->remainder == 0) {
DPRINTFN(5, "faking complete\n");
return (0);
}
td->error = 1;
return (0);
}
if (!(temp & AVR32_EPTSTA_RX_BK_RDY)) {
goto not_complete;
}
count = AVR32_EPTSTA_BYTE_COUNT(temp);
if (count != td->max_packet_size) {
if (count < td->max_packet_size) {
td->short_pkt = 1;
got_short = 1;
} else {
td->error = 1;
return (0);
}
}
if (count > td->remainder) {
td->error = 1;
return (0);
}
while (count > 0) {
usbd_get_page(td->pc, td->offset, &buf_res);
if (buf_res.length > count) {
buf_res.length = count;
}
memcpy(buf_res.buffer, sc->physdata +
(AVR32_EPTSTA_CURRENT_BANK(temp) << td->bank_shift) +
(td->ep_no << 16) + (td->offset % td->max_packet_size), buf_res.length);
count -= buf_res.length;
td->offset += buf_res.length;
td->remainder -= buf_res.length;
}
AVR32_WRITE_4(sc, AVR32_EPTCLRSTA(td->ep_no), AVR32_EPTSTA_RX_BK_RDY);
if ((td->remainder == 0) || got_short) {
if (td->short_pkt) {
return (0);
}
}
if (--to) {
goto repeat;
}
not_complete:
return (1);
}
static uint8_t
avr32dci_data_tx(struct avr32dci_td *td)
{
struct avr32dci_softc *sc;
struct usb_page_search buf_res;
uint16_t count;
uint8_t to;
uint32_t temp;
to = 4;
sc = AVR32_PC2SC(td->pc);
repeat:
temp = AVR32_READ_4(sc, AVR32_EPTSTA(td->ep_no));
DPRINTFN(5, "EPTSTA(%u)=0x%08x\n", td->ep_no, temp);
if (temp & AVR32_EPTSTA_RX_SETUP) {
td->error = 1;
return (0);
}
if (temp & AVR32_EPTSTA_TX_PK_RDY) {
goto not_complete;
}
count = td->max_packet_size;
if (td->remainder < count) {
td->short_pkt = 1;
count = td->remainder;
}
while (count > 0) {
usbd_get_page(td->pc, td->offset, &buf_res);
if (buf_res.length > count) {
buf_res.length = count;
}
memcpy(sc->physdata +
(AVR32_EPTSTA_CURRENT_BANK(temp) << td->bank_shift) +
(td->ep_no << 16) + (td->offset % td->max_packet_size),
buf_res.buffer, buf_res.length);
count -= buf_res.length;
td->offset += buf_res.length;
td->remainder -= buf_res.length;
}
AVR32_WRITE_4(sc, AVR32_EPTCTL(td->ep_no), AVR32_EPTCTL_TX_PK_RDY);
if (td->remainder == 0) {
if (td->short_pkt) {
return (0);
}
}
if (--to) {
goto repeat;
}
not_complete:
return (1);
}
static uint8_t
avr32dci_data_tx_sync(struct avr32dci_td *td)
{
struct avr32dci_softc *sc;
uint32_t temp;
sc = AVR32_PC2SC(td->pc);
temp = AVR32_READ_4(sc, AVR32_EPTSTA(td->ep_no));
DPRINTFN(5, "EPTSTA(%u)=0x%08x\n", td->ep_no, temp);
if (temp & AVR32_EPTSTA_RX_SETUP) {
DPRINTFN(5, "faking complete\n");
return (0);
}
if (AVR32_EPTSTA_BUSY_BANK_STA(temp) != 0) {
goto not_complete;
}
if (sc->sc_dv_addr != 0xFF) {
avr32dci_set_address(sc, sc->sc_dv_addr);
}
return (0);
not_complete:
return (1);
}
static uint8_t
avr32dci_xfer_do_fifo(struct usb_xfer *xfer)
{
struct avr32dci_td *td;
DPRINTFN(9, "\n");
td = xfer->td_transfer_cache;
while (1) {
if ((td->func) (td)) {
break;
}
if (((void *)td) == xfer->td_transfer_last) {
goto done;
}
if (td->error) {
goto done;
} else if (td->remainder > 0) {
if (!td->alt_next) {
goto done;
}
}
td = td->obj_next;
xfer->td_transfer_cache = td;
}
return (1);
done:
avr32dci_standard_done(xfer);
return (0);
}
static void
avr32dci_interrupt_poll(struct avr32dci_softc *sc)
{
struct usb_xfer *xfer;
repeat:
TAILQ_FOREACH(xfer, &sc->sc_bus.intr_q.head, wait_entry) {
if (!avr32dci_xfer_do_fifo(xfer)) {
goto repeat;
}
}
}
void
avr32dci_vbus_interrupt(struct avr32dci_softc *sc, uint8_t is_on)
{
DPRINTFN(5, "vbus = %u\n", is_on);
if (is_on) {
if (!sc->sc_flags.status_vbus) {
sc->sc_flags.status_vbus = 1;
avr32dci_root_intr(sc);
}
} else {
if (sc->sc_flags.status_vbus) {
sc->sc_flags.status_vbus = 0;
sc->sc_flags.status_bus_reset = 0;
sc->sc_flags.status_suspend = 0;
sc->sc_flags.change_suspend = 0;
sc->sc_flags.change_connect = 1;
avr32dci_root_intr(sc);
}
}
}
void
avr32dci_interrupt(struct avr32dci_softc *sc)
{
uint32_t status;
USB_BUS_LOCK(&sc->sc_bus);
status = AVR32_READ_4(sc, AVR32_INTSTA);
AVR32_WRITE_4(sc, AVR32_CLRINT, status);
DPRINTFN(14, "INTSTA=0x%08x\n", status);
if (status & AVR32_INT_ENDRESET) {
DPRINTFN(5, "end of reset\n");
sc->sc_flags.status_bus_reset = 1;
sc->sc_flags.status_suspend = 0;
sc->sc_flags.change_suspend = 0;
sc->sc_flags.change_connect = 1;
avr32dci_mod_ien(sc, AVR32_INT_DET_SUSPD |
AVR32_INT_ENDRESET, AVR32_INT_WAKE_UP);
avr32dci_root_intr(sc);
}
if (status & AVR32_INT_WAKE_UP) {
DPRINTFN(5, "resume interrupt\n");
if (sc->sc_flags.status_suspend) {
sc->sc_flags.status_suspend = 0;
sc->sc_flags.change_suspend = 1;
avr32dci_mod_ien(sc, AVR32_INT_DET_SUSPD |
AVR32_INT_ENDRESET, AVR32_INT_WAKE_UP);
avr32dci_root_intr(sc);
}
} else if (status & AVR32_INT_DET_SUSPD) {
DPRINTFN(5, "suspend interrupt\n");
if (!sc->sc_flags.status_suspend) {
sc->sc_flags.status_suspend = 1;
sc->sc_flags.change_suspend = 1;
avr32dci_mod_ien(sc, AVR32_INT_WAKE_UP |
AVR32_INT_ENDRESET, AVR32_INT_DET_SUSPD);
avr32dci_root_intr(sc);
}
}
if (status & -AVR32_INT_EPT_INT(0)) {
DPRINTFN(5, "real endpoint interrupt\n");
avr32dci_interrupt_poll(sc);
}
USB_BUS_UNLOCK(&sc->sc_bus);
}
static void
avr32dci_setup_standard_chain_sub(struct avr32dci_std_temp *temp)
{
struct avr32dci_td *td;
td = temp->td_next;
temp->td = td;
temp->td_next = td->obj_next;
td->func = temp->func;
td->pc = temp->pc;
td->offset = temp->offset;
td->remainder = temp->len;
td->error = 0;
td->did_stall = temp->did_stall;
td->short_pkt = temp->short_pkt;
td->alt_next = temp->setup_alt_next;
}
static void
avr32dci_setup_standard_chain(struct usb_xfer *xfer)
{
struct avr32dci_std_temp temp;
struct avr32dci_softc *sc;
struct avr32dci_td *td;
uint32_t x;
uint8_t ep_no;
uint8_t need_sync;
DPRINTFN(9, "addr=%d endpt=%d sumlen=%d speed=%d\n",
xfer->address, UE_GET_ADDR(xfer->endpointno),
xfer->sumlen, usbd_get_speed(xfer->xroot->udev));
temp.max_frame_size = xfer->max_frame_size;
td = xfer->td_start[0];
xfer->td_transfer_first = td;
xfer->td_transfer_cache = td;
temp.pc = NULL;
temp.td = NULL;
temp.td_next = xfer->td_start[0];
temp.offset = 0;
temp.setup_alt_next = xfer->flags_int.short_frames_ok ||
xfer->flags_int.isochronous_xfr;
temp.did_stall = !xfer->flags_int.control_stall;
sc = AVR32_BUS2SC(xfer->xroot->bus);
ep_no = (xfer->endpointno & UE_ADDR);
if (xfer->flags_int.control_xfr) {
if (xfer->flags_int.control_hdr) {
temp.func = &avr32dci_setup_rx;
temp.len = xfer->frlengths[0];
temp.pc = xfer->frbuffers + 0;
temp.short_pkt = temp.len ? 1 : 0;
if (xfer->nframes == 1) {
if (xfer->flags_int.control_act)
temp.setup_alt_next = 0;
}
avr32dci_setup_standard_chain_sub(&temp);
}
x = 1;
} else {
x = 0;
}
if (x != xfer->nframes) {
if (xfer->endpointno & UE_DIR_IN) {
temp.func = &avr32dci_data_tx;
need_sync = 1;
} else {
temp.func = &avr32dci_data_rx;
need_sync = 0;
}
temp.pc = xfer->frbuffers + x;
} else {
need_sync = 0;
}
while (x != xfer->nframes) {
temp.len = xfer->frlengths[x];
x++;
if (x == xfer->nframes) {
if (xfer->flags_int.control_xfr) {
if (xfer->flags_int.control_act) {
temp.setup_alt_next = 0;
}
} else {
temp.setup_alt_next = 0;
}
}
if (temp.len == 0) {
temp.short_pkt = 0;
} else {
temp.short_pkt = (xfer->flags.force_short_xfer) ? 0 : 1;
}
avr32dci_setup_standard_chain_sub(&temp);
if (xfer->flags_int.isochronous_xfr) {
temp.offset += temp.len;
} else {
temp.pc = xfer->frbuffers + x;
}
}
if (xfer->flags_int.control_xfr) {
temp.pc = xfer->frbuffers + 0;
temp.len = 0;
temp.short_pkt = 0;
temp.setup_alt_next = 0;
if (need_sync) {
temp.func = &avr32dci_data_tx_sync;
avr32dci_setup_standard_chain_sub(&temp);
}
if (!xfer->flags_int.control_act) {
if (xfer->endpointno & UE_DIR_IN) {
temp.func = &avr32dci_data_rx;
need_sync = 0;
} else {
temp.func = &avr32dci_data_tx;
need_sync = 1;
}
avr32dci_setup_standard_chain_sub(&temp);
if (need_sync) {
temp.func = &avr32dci_data_tx_sync;
avr32dci_setup_standard_chain_sub(&temp);
}
}
}
td = temp.td;
xfer->td_transfer_last = td;
}
static void
avr32dci_timeout(void *arg)
{
struct usb_xfer *xfer = arg;
DPRINTF("xfer=%p\n", xfer);
USB_BUS_LOCK_ASSERT(xfer->xroot->bus, MA_OWNED);
avr32dci_device_done(xfer, USB_ERR_TIMEOUT);
}
static void
avr32dci_start_standard_chain(struct usb_xfer *xfer)
{
DPRINTFN(9, "\n");
if (avr32dci_xfer_do_fifo(xfer)) {
uint8_t ep_no = xfer->endpointno & UE_ADDR;
struct avr32dci_softc *sc = AVR32_BUS2SC(xfer->xroot->bus);
avr32dci_mod_ien(sc, AVR32_INT_EPT_INT(ep_no), 0);
usbd_transfer_enqueue(&xfer->xroot->bus->intr_q, xfer);
if (xfer->timeout != 0) {
usbd_transfer_timeout_ms(xfer,
&avr32dci_timeout, xfer->timeout);
}
}
}
static void
avr32dci_root_intr(struct avr32dci_softc *sc)
{
DPRINTFN(9, "\n");
USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
sc->sc_hub_idata[0] = 0x02;
uhub_root_intr(&sc->sc_bus, sc->sc_hub_idata,
sizeof(sc->sc_hub_idata));
}
static usb_error_t
avr32dci_standard_done_sub(struct usb_xfer *xfer)
{
struct avr32dci_td *td;
uint32_t len;
uint8_t error;
DPRINTFN(9, "\n");
td = xfer->td_transfer_cache;
do {
len = td->remainder;
if (xfer->aframes != xfer->nframes) {
if (len > xfer->frlengths[xfer->aframes]) {
td->error = 1;
} else {
xfer->frlengths[xfer->aframes] -= len;
}
}
if (td->error) {
error = 1;
td = NULL;
break;
}
if (len > 0) {
if (xfer->flags_int.short_frames_ok ||
xfer->flags_int.isochronous_xfr) {
if (td->alt_next) {
td = td->obj_next;
} else {
td = NULL;
}
} else {
td = NULL;
}
error = 0;
break;
}
td = td->obj_next;
error = 0;
break;
} while (0);
xfer->td_transfer_cache = td;
return (error ?
USB_ERR_STALLED : USB_ERR_NORMAL_COMPLETION);
}
static void
avr32dci_standard_done(struct usb_xfer *xfer)
{
usb_error_t err = 0;
DPRINTFN(13, "xfer=%p pipe=%p transfer done\n",
xfer, xfer->endpoint);
xfer->td_transfer_cache = xfer->td_transfer_first;
if (xfer->flags_int.control_xfr) {
if (xfer->flags_int.control_hdr) {
err = avr32dci_standard_done_sub(xfer);
}
xfer->aframes = 1;
if (xfer->td_transfer_cache == NULL) {
goto done;
}
}
while (xfer->aframes != xfer->nframes) {
err = avr32dci_standard_done_sub(xfer);
xfer->aframes++;
if (xfer->td_transfer_cache == NULL) {
goto done;
}
}
if (xfer->flags_int.control_xfr &&
!xfer->flags_int.control_act) {
err = avr32dci_standard_done_sub(xfer);
}
done:
avr32dci_device_done(xfer, err);
}
static void
avr32dci_device_done(struct usb_xfer *xfer, usb_error_t error)
{
struct avr32dci_softc *sc = AVR32_BUS2SC(xfer->xroot->bus);
uint8_t ep_no;
USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
DPRINTFN(9, "xfer=%p, pipe=%p, error=%d\n",
xfer, xfer->endpoint, error);
if (xfer->flags_int.usb_mode == USB_MODE_DEVICE) {
ep_no = (xfer->endpointno & UE_ADDR);
avr32dci_mod_ien(sc, 0, AVR32_INT_EPT_INT(ep_no));
DPRINTFN(15, "disabled interrupts!\n");
}
usbd_transfer_done(xfer, error);
}
static void
avr32dci_xfer_stall(struct usb_xfer *xfer)
{
avr32dci_device_done(xfer, USB_ERR_STALLED);
}
static void
avr32dci_set_stall(struct usb_device *udev,
struct usb_endpoint *pipe, uint8_t *did_stall)
{
struct avr32dci_softc *sc;
uint8_t ep_no;
USB_BUS_LOCK_ASSERT(udev->bus, MA_OWNED);
DPRINTFN(5, "pipe=%p\n", pipe);
sc = AVR32_BUS2SC(udev->bus);
ep_no = (pipe->edesc->bEndpointAddress & UE_ADDR);
AVR32_WRITE_4(sc, AVR32_EPTSETSTA(ep_no), AVR32_EPTSTA_FRCESTALL);
}
static void
avr32dci_clear_stall_sub(struct avr32dci_softc *sc, uint8_t ep_no,
uint8_t ep_type, uint8_t ep_dir)
{
const struct usb_hw_ep_profile *pf;
uint32_t temp;
uint32_t epsize;
uint8_t n;
if (ep_type == UE_CONTROL) {
return;
}
AVR32_WRITE_4(sc, AVR32_EPTRST, AVR32_EPTRST_MASK(ep_no));
AVR32_WRITE_4(sc, AVR32_EPTSETSTA(ep_no), AVR32_EPTSTA_FRCESTALL);
AVR32_WRITE_4(sc, AVR32_EPTCLRSTA(ep_no), AVR32_EPTSTA_TOGGLESQ);
AVR32_WRITE_4(sc, AVR32_EPTCLRSTA(ep_no), AVR32_EPTSTA_FRCESTALL);
if (ep_type == UE_BULK) {
temp = AVR32_EPTCFG_TYPE_BULK;
} else if (ep_type == UE_INTERRUPT) {
temp = AVR32_EPTCFG_TYPE_INTR;
} else {
temp = AVR32_EPTCFG_TYPE_ISOC |
AVR32_EPTCFG_NB_TRANS(1);
}
if (ep_dir & UE_DIR_IN) {
temp |= AVR32_EPTCFG_EPDIR_IN;
}
avr32dci_get_hw_ep_profile(NULL, &pf, ep_no);
epsize = pf->max_in_frame_size | pf->max_out_frame_size;
n = 0;
while ((epsize /= 2))
n++;
temp |= AVR32_EPTCFG_EPSIZE(n);
if (ep_no < 1)
temp |= AVR32_EPTCFG_NBANK(1);
else if (ep_no < 3)
temp |= AVR32_EPTCFG_NBANK(2);
else
temp |= AVR32_EPTCFG_NBANK(3);
AVR32_WRITE_4(sc, AVR32_EPTCFG(ep_no), temp);
temp = AVR32_READ_4(sc, AVR32_EPTCFG(ep_no));
if (!(temp & AVR32_EPTCFG_EPT_MAPD)) {
device_printf(sc->sc_bus.bdev, "Chip rejected configuration\n");
} else {
AVR32_WRITE_4(sc, AVR32_EPTCTLENB(ep_no),
AVR32_EPTCTL_EPT_ENABL);
}
}
static void
avr32dci_clear_stall(struct usb_device *udev, struct usb_endpoint *pipe)
{
struct avr32dci_softc *sc;
struct usb_endpoint_descriptor *ed;
DPRINTFN(5, "pipe=%p\n", pipe);
USB_BUS_LOCK_ASSERT(udev->bus, MA_OWNED);
if (udev->flags.usb_mode != USB_MODE_DEVICE) {
return;
}
sc = AVR32_BUS2SC(udev->bus);
ed = pipe->edesc;
avr32dci_clear_stall_sub(sc,
(ed->bEndpointAddress & UE_ADDR),
(ed->bmAttributes & UE_XFERTYPE),
(ed->bEndpointAddress & (UE_DIR_IN | UE_DIR_OUT)));
}
usb_error_t
avr32dci_init(struct avr32dci_softc *sc)
{
uint8_t n;
DPRINTF("start\n");
sc->sc_bus.usbrev = USB_REV_1_1;
sc->sc_bus.methods = &avr32dci_bus_methods;
USB_BUS_LOCK(&sc->sc_bus);
avr32dci_mod_ctrl(sc, AVR32_CTRL_DEV_EN_USBA, 0);
(sc->sc_clocks_on) (&sc->sc_bus);
avr32dci_mod_ctrl(sc, AVR32_CTRL_DEV_DETACH, 0);
usb_pause_mtx(&sc->sc_bus.bus_mtx, hz / 20);
avr32dci_mod_ien(sc, 0, 0xFFFFFFFF);
avr32dci_mod_ien(sc, AVR32_INT_DET_SUSPD |
AVR32_INT_ENDRESET, 0);
AVR32_WRITE_4(sc, AVR32_EPTRST, (1 << AVR32_EP_MAX) - 1);
for (n = 0; n != AVR32_EP_MAX; n++) {
AVR32_WRITE_4(sc, AVR32_EPTCTLDIS(n), AVR32_EPTCTL_EPT_ENABL);
}
avr32dci_clocks_off(sc);
USB_BUS_UNLOCK(&sc->sc_bus);
avr32dci_do_poll(&sc->sc_bus);
return (0);
}
void
avr32dci_uninit(struct avr32dci_softc *sc)
{
uint8_t n;
USB_BUS_LOCK(&sc->sc_bus);
(sc->sc_clocks_on) (&sc->sc_bus);
avr32dci_mod_ien(sc, 0, 0xFFFFFFFF);
AVR32_WRITE_4(sc, AVR32_EPTRST, (1 << AVR32_EP_MAX) - 1);
for (n = 0; n != AVR32_EP_MAX; n++) {
AVR32_WRITE_4(sc, AVR32_EPTCTLDIS(n), AVR32_EPTCTL_EPT_ENABL);
}
sc->sc_flags.port_powered = 0;
sc->sc_flags.status_vbus = 0;
sc->sc_flags.status_bus_reset = 0;
sc->sc_flags.status_suspend = 0;
sc->sc_flags.change_suspend = 0;
sc->sc_flags.change_connect = 1;
avr32dci_pull_down(sc);
avr32dci_clocks_off(sc);
USB_BUS_UNLOCK(&sc->sc_bus);
}
static void
avr32dci_suspend(struct avr32dci_softc *sc)
{
}
static void
avr32dci_resume(struct avr32dci_softc *sc)
{
}
static void
avr32dci_do_poll(struct usb_bus *bus)
{
struct avr32dci_softc *sc = AVR32_BUS2SC(bus);
USB_BUS_LOCK(&sc->sc_bus);
avr32dci_interrupt_poll(sc);
USB_BUS_UNLOCK(&sc->sc_bus);
}
static void
avr32dci_device_non_isoc_open(struct usb_xfer *xfer)
{
return;
}
static void
avr32dci_device_non_isoc_close(struct usb_xfer *xfer)
{
avr32dci_device_done(xfer, USB_ERR_CANCELLED);
}
static void
avr32dci_device_non_isoc_enter(struct usb_xfer *xfer)
{
return;
}
static void
avr32dci_device_non_isoc_start(struct usb_xfer *xfer)
{
avr32dci_setup_standard_chain(xfer);
avr32dci_start_standard_chain(xfer);
}
static const struct usb_pipe_methods avr32dci_device_non_isoc_methods =
{
.open = avr32dci_device_non_isoc_open,
.close = avr32dci_device_non_isoc_close,
.enter = avr32dci_device_non_isoc_enter,
.start = avr32dci_device_non_isoc_start,
};
static void
avr32dci_device_isoc_fs_open(struct usb_xfer *xfer)
{
return;
}
static void
avr32dci_device_isoc_fs_close(struct usb_xfer *xfer)
{
avr32dci_device_done(xfer, USB_ERR_CANCELLED);
}
static void
avr32dci_device_isoc_fs_enter(struct usb_xfer *xfer)
{
struct avr32dci_softc *sc = AVR32_BUS2SC(xfer->xroot->bus);
uint32_t nframes;
uint8_t ep_no;
DPRINTFN(6, "xfer=%p next=%d nframes=%d\n",
xfer, xfer->endpoint->isoc_next, xfer->nframes);
ep_no = xfer->endpointno & UE_ADDR;
nframes = (AVR32_READ_4(sc, AVR32_FNUM) / 8);
if (usbd_xfer_get_isochronous_start_frame(
xfer, nframes, 0, 1, AVR32_FRAME_MASK, NULL))
DPRINTFN(3, "start next=%d\n", xfer->endpoint->isoc_next);
avr32dci_setup_standard_chain(xfer);
}
static void
avr32dci_device_isoc_fs_start(struct usb_xfer *xfer)
{
avr32dci_start_standard_chain(xfer);
}
static const struct usb_pipe_methods avr32dci_device_isoc_fs_methods =
{
.open = avr32dci_device_isoc_fs_open,
.close = avr32dci_device_isoc_fs_close,
.enter = avr32dci_device_isoc_fs_enter,
.start = avr32dci_device_isoc_fs_start,
};
static const struct usb_device_descriptor avr32dci_devd = {
.bLength = sizeof(struct usb_device_descriptor),
.bDescriptorType = UDESC_DEVICE,
.bcdUSB = {0x00, 0x02},
.bDeviceClass = UDCLASS_HUB,
.bDeviceSubClass = UDSUBCLASS_HUB,
.bDeviceProtocol = UDPROTO_HSHUBSTT,
.bMaxPacketSize = 64,
.bcdDevice = {0x00, 0x01},
.iManufacturer = 1,
.iProduct = 2,
.bNumConfigurations = 1,
};
static const struct usb_device_qualifier avr32dci_odevd = {
.bLength = sizeof(struct usb_device_qualifier),
.bDescriptorType = UDESC_DEVICE_QUALIFIER,
.bcdUSB = {0x00, 0x02},
.bDeviceClass = UDCLASS_HUB,
.bDeviceSubClass = UDSUBCLASS_HUB,
.bDeviceProtocol = UDPROTO_FSHUB,
.bMaxPacketSize0 = 0,
.bNumConfigurations = 0,
};
static const struct avr32dci_config_desc avr32dci_confd = {
.confd = {
.bLength = sizeof(struct usb_config_descriptor),
.bDescriptorType = UDESC_CONFIG,
.wTotalLength[0] = sizeof(avr32dci_confd),
.bNumInterface = 1,
.bConfigurationValue = 1,
.iConfiguration = 0,
.bmAttributes = UC_SELF_POWERED,
.bMaxPower = 0,
},
.ifcd = {
.bLength = sizeof(struct usb_interface_descriptor),
.bDescriptorType = UDESC_INTERFACE,
.bNumEndpoints = 1,
.bInterfaceClass = UICLASS_HUB,
.bInterfaceSubClass = UISUBCLASS_HUB,
.bInterfaceProtocol = 0,
},
.endpd = {
.bLength = sizeof(struct usb_endpoint_descriptor),
.bDescriptorType = UDESC_ENDPOINT,
.bEndpointAddress = (UE_DIR_IN | AVR32_INTR_ENDPT),
.bmAttributes = UE_INTERRUPT,
.wMaxPacketSize[0] = 8,
.bInterval = 255,
},
};
#define HSETW(ptr, val) ptr = { (uint8_t)(val), (uint8_t)((val) >> 8) }
static const struct usb_hub_descriptor_min avr32dci_hubd = {
.bDescLength = sizeof(avr32dci_hubd),
.bDescriptorType = UDESC_HUB,
.bNbrPorts = 1,
HSETW(.wHubCharacteristics, (UHD_PWR_NO_SWITCH | UHD_OC_INDIVIDUAL)),
.bPwrOn2PwrGood = 50,
.bHubContrCurrent = 0,
.DeviceRemovable = {0},
};
#define STRING_VENDOR \
"A\0V\0R\0003\0002"
#define STRING_PRODUCT \
"D\0C\0I\0 \0R\0o\0o\0t\0 \0H\0U\0B"
USB_MAKE_STRING_DESC(STRING_VENDOR, avr32dci_vendor);
USB_MAKE_STRING_DESC(STRING_PRODUCT, avr32dci_product);
static usb_error_t
avr32dci_roothub_exec(struct usb_device *udev,
struct usb_device_request *req, const void **pptr, uint16_t *plength)
{
struct avr32dci_softc *sc = AVR32_BUS2SC(udev->bus);
const void *ptr;
uint16_t len;
uint16_t value;
uint16_t index;
uint32_t temp;
usb_error_t err;
USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
ptr = (const void *)&sc->sc_hub_temp;
len = 0;
err = 0;
value = UGETW(req->wValue);
index = UGETW(req->wIndex);
switch (req->bmRequestType) {
case UT_READ_DEVICE:
switch (req->bRequest) {
case UR_GET_DESCRIPTOR:
goto tr_handle_get_descriptor;
case UR_GET_CONFIG:
goto tr_handle_get_config;
case UR_GET_STATUS:
goto tr_handle_get_status;
default:
goto tr_stalled;
}
break;
case UT_WRITE_DEVICE:
switch (req->bRequest) {
case UR_SET_ADDRESS:
goto tr_handle_set_address;
case UR_SET_CONFIG:
goto tr_handle_set_config;
case UR_CLEAR_FEATURE:
goto tr_valid;
case UR_SET_DESCRIPTOR:
goto tr_valid;
case UR_SET_FEATURE:
default:
goto tr_stalled;
}
break;
case UT_WRITE_ENDPOINT:
switch (req->bRequest) {
case UR_CLEAR_FEATURE:
switch (UGETW(req->wValue)) {
case UF_ENDPOINT_HALT:
goto tr_handle_clear_halt;
case UF_DEVICE_REMOTE_WAKEUP:
goto tr_handle_clear_wakeup;
default:
goto tr_stalled;
}
break;
case UR_SET_FEATURE:
switch (UGETW(req->wValue)) {
case UF_ENDPOINT_HALT:
goto tr_handle_set_halt;
case UF_DEVICE_REMOTE_WAKEUP:
goto tr_handle_set_wakeup;
default:
goto tr_stalled;
}
break;
case UR_SYNCH_FRAME:
goto tr_valid;
default:
goto tr_stalled;
}
break;
case UT_READ_ENDPOINT:
switch (req->bRequest) {
case UR_GET_STATUS:
goto tr_handle_get_ep_status;
default:
goto tr_stalled;
}
break;
case UT_WRITE_INTERFACE:
switch (req->bRequest) {
case UR_SET_INTERFACE:
goto tr_handle_set_interface;
case UR_CLEAR_FEATURE:
goto tr_valid;
case UR_SET_FEATURE:
default:
goto tr_stalled;
}
break;
case UT_READ_INTERFACE:
switch (req->bRequest) {
case UR_GET_INTERFACE:
goto tr_handle_get_interface;
case UR_GET_STATUS:
goto tr_handle_get_iface_status;
default:
goto tr_stalled;
}
break;
case UT_WRITE_CLASS_INTERFACE:
case UT_WRITE_VENDOR_INTERFACE:
break;
case UT_READ_CLASS_INTERFACE:
case UT_READ_VENDOR_INTERFACE:
break;
case UT_WRITE_CLASS_DEVICE:
switch (req->bRequest) {
case UR_CLEAR_FEATURE:
goto tr_valid;
case UR_SET_DESCRIPTOR:
case UR_SET_FEATURE:
break;
default:
goto tr_stalled;
}
break;
case UT_WRITE_CLASS_OTHER:
switch (req->bRequest) {
case UR_CLEAR_FEATURE:
goto tr_handle_clear_port_feature;
case UR_SET_FEATURE:
goto tr_handle_set_port_feature;
case UR_CLEAR_TT_BUFFER:
case UR_RESET_TT:
case UR_STOP_TT:
goto tr_valid;
default:
goto tr_stalled;
}
break;
case UT_READ_CLASS_OTHER:
switch (req->bRequest) {
case UR_GET_TT_STATE:
goto tr_handle_get_tt_state;
case UR_GET_STATUS:
goto tr_handle_get_port_status;
default:
goto tr_stalled;
}
break;
case UT_READ_CLASS_DEVICE:
switch (req->bRequest) {
case UR_GET_DESCRIPTOR:
goto tr_handle_get_class_descriptor;
case UR_GET_STATUS:
goto tr_handle_get_class_status;
default:
goto tr_stalled;
}
break;
default:
goto tr_stalled;
}
goto tr_valid;
tr_handle_get_descriptor:
switch (value >> 8) {
case UDESC_DEVICE:
if (value & 0xff) {
goto tr_stalled;
}
len = sizeof(avr32dci_devd);
ptr = (const void *)&avr32dci_devd;
goto tr_valid;
case UDESC_DEVICE_QUALIFIER:
if (value & 0xff)
goto tr_stalled;
len = sizeof(avr32dci_odevd);
ptr = (const void *)&avr32dci_odevd;
goto tr_valid;
case UDESC_CONFIG:
if (value & 0xff) {
goto tr_stalled;
}
len = sizeof(avr32dci_confd);
ptr = (const void *)&avr32dci_confd;
goto tr_valid;
case UDESC_STRING:
switch (value & 0xff) {
case 0:
len = sizeof(usb_string_lang_en);
ptr = (const void *)&usb_string_lang_en;
goto tr_valid;
case 1:
len = sizeof(avr32dci_vendor);
ptr = (const void *)&avr32dci_vendor;
goto tr_valid;
case 2:
len = sizeof(avr32dci_product);
ptr = (const void *)&avr32dci_product;
goto tr_valid;
default:
break;
}
break;
default:
goto tr_stalled;
}
goto tr_stalled;
tr_handle_get_config:
len = 1;
sc->sc_hub_temp.wValue[0] = sc->sc_conf;
goto tr_valid;
tr_handle_get_status:
len = 2;
USETW(sc->sc_hub_temp.wValue, UDS_SELF_POWERED);
goto tr_valid;
tr_handle_set_address:
if (value & 0xFF00) {
goto tr_stalled;
}
sc->sc_rt_addr = value;
goto tr_valid;
tr_handle_set_config:
if (value >= 2) {
goto tr_stalled;
}
sc->sc_conf = value;
goto tr_valid;
tr_handle_get_interface:
len = 1;
sc->sc_hub_temp.wValue[0] = 0;
goto tr_valid;
tr_handle_get_tt_state:
tr_handle_get_class_status:
tr_handle_get_iface_status:
tr_handle_get_ep_status:
len = 2;
USETW(sc->sc_hub_temp.wValue, 0);
goto tr_valid;
tr_handle_set_halt:
tr_handle_set_interface:
tr_handle_set_wakeup:
tr_handle_clear_wakeup:
tr_handle_clear_halt:
goto tr_valid;
tr_handle_clear_port_feature:
if (index != 1) {
goto tr_stalled;
}
DPRINTFN(9, "UR_CLEAR_PORT_FEATURE on port %d\n", index);
switch (value) {
case UHF_PORT_SUSPEND:
avr32dci_wakeup_peer(sc);
break;
case UHF_PORT_ENABLE:
sc->sc_flags.port_enabled = 0;
break;
case UHF_PORT_TEST:
case UHF_PORT_INDICATOR:
case UHF_C_PORT_ENABLE:
case UHF_C_PORT_OVER_CURRENT:
case UHF_C_PORT_RESET:
break;
case UHF_PORT_POWER:
sc->sc_flags.port_powered = 0;
avr32dci_pull_down(sc);
avr32dci_clocks_off(sc);
break;
case UHF_C_PORT_CONNECTION:
sc->sc_flags.change_connect = 0;
if (!sc->sc_flags.status_bus_reset) {
break;
}
AVR32_WRITE_4(sc, AVR32_EPTRST, AVR32_EPTRST_MASK(0));
AVR32_WRITE_4(sc, AVR32_EPTSETSTA(0), AVR32_EPTSTA_FRCESTALL);
AVR32_WRITE_4(sc, AVR32_EPTCLRSTA(0), AVR32_EPTSTA_TOGGLESQ);
AVR32_WRITE_4(sc, AVR32_EPTCLRSTA(0), AVR32_EPTSTA_FRCESTALL);
AVR32_WRITE_4(sc, AVR32_EPTCFG(0), AVR32_EPTCFG_TYPE_CTRL |
AVR32_EPTCFG_NBANK(1) | AVR32_EPTCFG_EPSIZE(6));
temp = AVR32_READ_4(sc, AVR32_EPTCFG(0));
if (!(temp & AVR32_EPTCFG_EPT_MAPD)) {
device_printf(sc->sc_bus.bdev,
"Chip rejected configuration\n");
} else {
AVR32_WRITE_4(sc, AVR32_EPTCTLENB(0),
AVR32_EPTCTL_EPT_ENABL);
}
break;
case UHF_C_PORT_SUSPEND:
sc->sc_flags.change_suspend = 0;
break;
default:
err = USB_ERR_IOERROR;
goto done;
}
goto tr_valid;
tr_handle_set_port_feature:
if (index != 1) {
goto tr_stalled;
}
DPRINTFN(9, "UR_SET_PORT_FEATURE\n");
switch (value) {
case UHF_PORT_ENABLE:
sc->sc_flags.port_enabled = 1;
break;
case UHF_PORT_SUSPEND:
case UHF_PORT_RESET:
case UHF_PORT_TEST:
case UHF_PORT_INDICATOR:
break;
case UHF_PORT_POWER:
sc->sc_flags.port_powered = 1;
break;
default:
err = USB_ERR_IOERROR;
goto done;
}
goto tr_valid;
tr_handle_get_port_status:
DPRINTFN(9, "UR_GET_PORT_STATUS\n");
if (index != 1) {
goto tr_stalled;
}
if (sc->sc_flags.status_vbus) {
avr32dci_clocks_on(sc);
avr32dci_pull_up(sc);
} else {
avr32dci_pull_down(sc);
avr32dci_clocks_off(sc);
}
value = UPS_PORT_MODE_DEVICE;
if (AVR32_READ_4(sc, AVR32_INTSTA) & AVR32_INT_SPEED)
value |= UPS_HIGH_SPEED;
if (sc->sc_flags.port_powered) {
value |= UPS_PORT_POWER;
}
if (sc->sc_flags.port_enabled) {
value |= UPS_PORT_ENABLED;
}
if (sc->sc_flags.status_vbus &&
sc->sc_flags.status_bus_reset) {
value |= UPS_CURRENT_CONNECT_STATUS;
}
if (sc->sc_flags.status_suspend) {
value |= UPS_SUSPEND;
}
USETW(sc->sc_hub_temp.ps.wPortStatus, value);
value = 0;
if (sc->sc_flags.change_connect) {
value |= UPS_C_CONNECT_STATUS;
}
if (sc->sc_flags.change_suspend) {
value |= UPS_C_SUSPEND;
}
USETW(sc->sc_hub_temp.ps.wPortChange, value);
len = sizeof(sc->sc_hub_temp.ps);
goto tr_valid;
tr_handle_get_class_descriptor:
if (value & 0xFF) {
goto tr_stalled;
}
ptr = (const void *)&avr32dci_hubd;
len = sizeof(avr32dci_hubd);
goto tr_valid;
tr_stalled:
err = USB_ERR_STALLED;
tr_valid:
done:
*plength = len;
*pptr = ptr;
return (err);
}
static void
avr32dci_xfer_setup(struct usb_setup_params *parm)
{
const struct usb_hw_ep_profile *pf;
struct avr32dci_softc *sc;
struct usb_xfer *xfer;
void *last_obj;
uint32_t ntd;
uint32_t n;
uint8_t ep_no;
sc = AVR32_BUS2SC(parm->udev->bus);
xfer = parm->curr_xfer;
parm->hc_max_packet_size = 0x400;
parm->hc_max_packet_count = 1;
parm->hc_max_frame_size = 0x400;
usbd_transfer_setup_sub(parm);
if ((xfer->endpoint->edesc->bmAttributes & UE_XFERTYPE) == UE_CONTROL) {
ntd = xfer->nframes + 1 + 1
+ 1 ;
} else {
ntd = xfer->nframes + 1 ;
}
if (parm->err)
return;
last_obj = NULL;
ep_no = xfer->endpointno & UE_ADDR;
avr32dci_get_hw_ep_profile(parm->udev, &pf, ep_no);
if (pf == NULL) {
parm->err = USB_ERR_INVAL;
return;
}
parm->size[0] += ((-parm->size[0]) & (USB_HOST_ALIGN - 1));
for (n = 0; n != ntd; n++) {
struct avr32dci_td *td;
if (parm->buf) {
uint32_t temp;
td = USB_ADD_BYTES(parm->buf, parm->size[0]);
td->max_packet_size = xfer->max_packet_size;
td->ep_no = ep_no;
temp = pf->max_in_frame_size | pf->max_out_frame_size;
td->bank_shift = 0;
while ((temp /= 2))
td->bank_shift++;
if (pf->support_multi_buffer) {
td->support_multi_buffer = 1;
}
td->obj_next = last_obj;
last_obj = td;
}
parm->size[0] += sizeof(*td);
}
xfer->td_start[0] = last_obj;
}
static void
avr32dci_xfer_unsetup(struct usb_xfer *xfer)
{
return;
}
static void
avr32dci_ep_init(struct usb_device *udev, struct usb_endpoint_descriptor *edesc,
struct usb_endpoint *pipe)
{
struct avr32dci_softc *sc = AVR32_BUS2SC(udev->bus);
DPRINTFN(2, "pipe=%p, addr=%d, endpt=%d, mode=%d (%d,%d)\n",
pipe, udev->address,
edesc->bEndpointAddress, udev->flags.usb_mode,
sc->sc_rt_addr, udev->device_index);
if (udev->device_index != sc->sc_rt_addr) {
if ((udev->speed != USB_SPEED_FULL) &&
(udev->speed != USB_SPEED_HIGH)) {
return;
}
if ((edesc->bmAttributes & UE_XFERTYPE) == UE_ISOCHRONOUS)
pipe->methods = &avr32dci_device_isoc_fs_methods;
else
pipe->methods = &avr32dci_device_non_isoc_methods;
}
}
static void
avr32dci_set_hw_power_sleep(struct usb_bus *bus, uint32_t state)
{
struct avr32dci_softc *sc = AVR32_BUS2SC(bus);
switch (state) {
case USB_HW_POWER_SUSPEND:
avr32dci_suspend(sc);
break;
case USB_HW_POWER_SHUTDOWN:
avr32dci_uninit(sc);
break;
case USB_HW_POWER_RESUME:
avr32dci_resume(sc);
break;
default:
break;
}
}
static const struct usb_bus_methods avr32dci_bus_methods =
{
.endpoint_init = &avr32dci_ep_init,
.xfer_setup = &avr32dci_xfer_setup,
.xfer_unsetup = &avr32dci_xfer_unsetup,
.get_hw_ep_profile = &avr32dci_get_hw_ep_profile,
.xfer_stall = &avr32dci_xfer_stall,
.set_stall = &avr32dci_set_stall,
.clear_stall = &avr32dci_clear_stall,
.roothub_exec = &avr32dci_roothub_exec,
.xfer_poll = &avr32dci_do_poll,
.set_hw_power_sleep = &avr32dci_set_hw_power_sleep,
};