38#ifdef USB_GLOBAL_INCLUDE_FILE
39#include USB_GLOBAL_INCLUDE_FILE
41#include <sys/stdint.h>
42#include <sys/stddef.h>
47#include <sys/kernel.h>
49#include <sys/module.h>
52#include <sys/condvar.h>
53#include <sys/sysctl.h>
55#include <sys/unistd.h>
56#include <sys/callout.h>
57#include <sys/malloc.h>
63#define USB_DEBUG_VAR avr32dci_debug
80#define AVR32_BUS2SC(bus) \
81 __containerof(bus, struct avr32dci_softc, sc_bus)
83#define AVR32_PC2SC(pc) \
84 AVR32_BUS2SC(USB_DMATAG_TO_XROOT((pc)->tag_parent)->bus)
87static int avr32dci_debug = 0;
90 CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
93 &avr32dci_debug, 0,
"AVR32 DCI debug level");
96#define AVR32_INTR_ENDPT 1
120 .max_out_frame_size = 64,
122 .support_control = 1,
126 .max_in_frame_size = 512,
127 .max_out_frame_size = 512,
130 .support_interrupt = 1,
131 .support_isochronous = 1,
137 .max_in_frame_size = 64,
138 .max_out_frame_size = 64,
141 .support_interrupt = 1,
147 .max_in_frame_size = 1024,
148 .max_out_frame_size = 1024,
151 .support_interrupt = 1,
152 .support_isochronous = 1,
164 else if (ep_addr < 3)
166 else if (ep_addr < 5)
168 else if (ep_addr < 7)
268 DPRINTFN(5,
"addr=%d\n",
addr);
287 DPRINTFN(5,
"EPTSTA(%u)=0x%08x\n", td->
ep_no, temp);
299 DPRINTFN(0,
"Invalid SETUP packet "
300 "length, %d bytes\n",
count);
304 DPRINTFN(0,
"Unsupported SETUP packet "
305 "length, %d bytes\n",
count);
340 DPRINTFN(5,
"stalling\n");
369 DPRINTFN(5,
"EPTSTA(%u)=0x%08x\n", td->
ep_no, temp);
377 DPRINTFN(5,
"faking complete\n");
396 if (count < td->max_packet_size) {
466 DPRINTFN(5,
"EPTSTA(%u)=0x%08x\n", td->
ep_no, temp);
533 DPRINTFN(5,
"EPTSTA(%u)=0x%08x\n", td->
ep_no, temp);
536 DPRINTFN(5,
"faking complete\n");
567 if ((td->
func) (td)) {
576 }
else if (td->remainder > 0) {
607 TAILQ_FOREACH(xfer, &sc->
sc_bus.
intr_q.head, wait_entry) {
618 DPRINTFN(5,
"vbus = %u\n", is_on);
656 DPRINTFN(14,
"INTSTA=0x%08x\n",
status);
660 DPRINTFN(5,
"end of reset\n");
681 DPRINTFN(5,
"resume interrupt\n");
696 DPRINTFN(5,
"suspend interrupt\n");
713 DPRINTFN(5,
"real endpoint interrupt\n");
753 DPRINTFN(9,
"addr=%d endpt=%d sumlen=%d speed=%d\n",
1008 DPRINTFN(13,
"xfer=%p pipe=%p transfer done\n",
1056 DPRINTFN(9,
"xfer=%p, pipe=%p, error=%d\n",
1065 DPRINTFN(15,
"disabled interrupts!\n");
1086 DPRINTFN(5,
"pipe=%p\n", pipe);
1097 uint8_t ep_type, uint8_t ep_dir)
1134 epsize =
pf->max_in_frame_size |
pf->max_out_frame_size;
1136 while ((epsize /= 2))
1153 device_printf(sc->
sc_bus.
bdev,
"Chip rejected configuration\n");
1166 DPRINTFN(5,
"pipe=%p\n", pipe);
1360 DPRINTFN(6,
"xfer=%p next=%d nframes=%d\n",
1399 .bcdUSB = {0x00, 0x02},
1403 .bMaxPacketSize = 64,
1404 .bcdDevice = {0x00, 0x01},
1407 .bNumConfigurations = 1,
1413 .bcdUSB = {0x00, 0x02},
1417 .bMaxPacketSize0 = 0,
1418 .bNumConfigurations = 0,
1438 .bInterfaceProtocol = 0,
1449#define HSETW(ptr, val) ptr = { (uint8_t)(val), (uint8_t)((val) >> 8) }
1461#define STRING_VENDOR \
1464#define STRING_PRODUCT \
1465 "D\0C\0I\0 \0R\0o\0o\0t\0 \0H\0U\0B"
1494 switch (
req->bmRequestType) {
1496 switch (
req->bRequest) {
1498 goto tr_handle_get_descriptor;
1500 goto tr_handle_get_config;
1502 goto tr_handle_get_status;
1509 switch (
req->bRequest) {
1511 goto tr_handle_set_address;
1513 goto tr_handle_set_config;
1525 switch (
req->bRequest) {
1529 goto tr_handle_clear_halt;
1531 goto tr_handle_clear_wakeup;
1539 goto tr_handle_set_halt;
1541 goto tr_handle_set_wakeup;
1554 switch (
req->bRequest) {
1556 goto tr_handle_get_ep_status;
1563 switch (
req->bRequest) {
1565 goto tr_handle_set_interface;
1575 switch (
req->bRequest) {
1577 goto tr_handle_get_interface;
1579 goto tr_handle_get_iface_status;
1596 switch (
req->bRequest) {
1608 switch (
req->bRequest) {
1610 goto tr_handle_clear_port_feature;
1612 goto tr_handle_set_port_feature;
1624 switch (
req->bRequest) {
1626 goto tr_handle_get_tt_state;
1628 goto tr_handle_get_port_status;
1635 switch (
req->bRequest) {
1637 goto tr_handle_get_class_descriptor;
1639 goto tr_handle_get_class_status;
1650tr_handle_get_descriptor:
1651 switch (
value >> 8) {
1673 switch (
value & 0xff) {
1680 len =
sizeof(avr32dci_vendor);
1681 ptr = (
const void *)&avr32dci_vendor;
1685 len =
sizeof(avr32dci_product);
1686 ptr = (
const void *)&avr32dci_product;
1697tr_handle_get_config:
1702tr_handle_get_status:
1707tr_handle_set_address:
1708 if (
value & 0xFF00) {
1714tr_handle_set_config:
1721tr_handle_get_interface:
1726tr_handle_get_tt_state:
1727tr_handle_get_class_status:
1728tr_handle_get_iface_status:
1729tr_handle_get_ep_status:
1735tr_handle_set_interface:
1736tr_handle_set_wakeup:
1737tr_handle_clear_wakeup:
1738tr_handle_clear_halt:
1741tr_handle_clear_port_feature:
1745 DPRINTFN(9,
"UR_CLEAR_PORT_FEATURE on port %d\n",
index);
1797 "Chip rejected configuration\n");
1812tr_handle_set_port_feature:
1816 DPRINTFN(9,
"UR_SET_PORT_FEATURE\n");
1837tr_handle_get_port_status:
1839 DPRINTFN(9,
"UR_GET_PORT_STATUS\n");
1887tr_handle_get_class_descriptor:
1964 for (
n = 0;
n != ntd;
n++) {
1975 temp =
pf->max_in_frame_size |
pf->max_out_frame_size;
1979 if (
pf->support_multi_buffer) {
1986 parm->
size[0] +=
sizeof(*td);
2004 DPRINTFN(2,
"pipe=%p, addr=%d, endpt=%d, mode=%d (%d,%d)\n",
static void avr32dci_device_isoc_fs_enter(struct usb_xfer *xfer)
static avr32dci_cmd_t avr32dci_data_tx_sync
static void avr32dci_wakeup_peer(struct avr32dci_softc *sc)
static void avr32dci_xfer_stall(struct usb_xfer *xfer)
static void avr32dci_ep_init(struct usb_device *udev, struct usb_endpoint_descriptor *edesc, struct usb_endpoint *pipe)
static void avr32dci_pull_down(struct avr32dci_softc *sc)
static void avr32dci_setup_standard_chain(struct usb_xfer *xfer)
static avr32dci_cmd_t avr32dci_data_rx
static void avr32dci_standard_done(struct usb_xfer *)
static void avr32dci_clocks_off(struct avr32dci_softc *sc)
static void avr32dci_device_isoc_fs_start(struct usb_xfer *xfer)
static void avr32dci_set_hw_power_sleep(struct usb_bus *bus, uint32_t state)
static const struct usb_hw_ep_profile avr32dci_ep_profile[4]
static void avr32dci_device_isoc_fs_open(struct usb_xfer *xfer)
static void avr32dci_device_non_isoc_enter(struct usb_xfer *xfer)
static void avr32dci_device_non_isoc_start(struct usb_xfer *xfer)
static void avr32dci_timeout(void *arg)
static void avr32dci_start_standard_chain(struct usb_xfer *xfer)
static void avr32dci_clear_stall_sub(struct avr32dci_softc *sc, uint8_t ep_no, uint8_t ep_type, uint8_t ep_dir)
void avr32dci_uninit(struct avr32dci_softc *sc)
static avr32dci_cmd_t avr32dci_setup_rx
static void avr32dci_clear_stall(struct usb_device *udev, struct usb_endpoint *pipe)
static void avr32dci_device_done(struct usb_xfer *, usb_error_t)
static void avr32dci_xfer_unsetup(struct usb_xfer *xfer)
static void avr32dci_clocks_on(struct avr32dci_softc *sc)
USB_MAKE_STRING_DESC(STRING_VENDOR, avr32dci_vendor)
static void avr32dci_set_address(struct avr32dci_softc *sc, uint8_t addr)
static const struct usb_pipe_methods avr32dci_device_non_isoc_methods
static void avr32dci_interrupt_poll(struct avr32dci_softc *sc)
static void avr32dci_do_poll(struct usb_bus *)
static const struct usb_bus_methods avr32dci_bus_methods
static const struct usb_device_descriptor avr32dci_devd
static void avr32dci_root_intr(struct avr32dci_softc *sc)
static const struct usb_device_qualifier avr32dci_odevd
static void avr32dci_device_non_isoc_close(struct usb_xfer *xfer)
static void avr32dci_device_isoc_fs_close(struct usb_xfer *xfer)
static void avr32dci_mod_ien(struct avr32dci_softc *sc, uint32_t set, uint32_t clear)
void avr32dci_vbus_interrupt(struct avr32dci_softc *sc, uint8_t is_on)
static void avr32dci_resume(struct avr32dci_softc *sc)
static void avr32dci_xfer_setup(struct usb_setup_params *parm)
static const struct usb_pipe_methods avr32dci_device_isoc_fs_methods
static usb_error_t avr32dci_standard_done_sub(struct usb_xfer *xfer)
static const struct avr32dci_config_desc avr32dci_confd
usb_error_t avr32dci_init(struct avr32dci_softc *sc)
static usb_error_t avr32dci_roothub_exec(struct usb_device *udev, struct usb_device_request *req, const void **pptr, uint16_t *plength)
static void avr32dci_device_non_isoc_open(struct usb_xfer *xfer)
void avr32dci_interrupt(struct avr32dci_softc *sc)
static void avr32dci_suspend(struct avr32dci_softc *sc)
static avr32dci_cmd_t avr32dci_data_tx
static void avr32dci_mod_ctrl(struct avr32dci_softc *sc, uint32_t set, uint32_t clear)
static const struct usb_hub_descriptor_min avr32dci_hubd
#define AVR32_BUS2SC(bus)
static void avr32dci_set_stall(struct usb_device *udev, struct usb_endpoint *pipe, uint8_t *did_stall)
static void avr32dci_pull_up(struct avr32dci_softc *sc)
static void avr32dci_setup_standard_chain_sub(struct avr32dci_std_temp *temp)
static void avr32dci_get_hw_ep_profile(struct usb_device *udev, const struct usb_hw_ep_profile **ppf, uint8_t ep_addr)
static uint8_t avr32dci_xfer_do_fifo(struct usb_xfer *xfer)
#define AVR32_INT_ENDRESET
uint8_t() avr32dci_cmd_t(struct avr32dci_td *td)
#define AVR32_EPTSTA_BUSY_BANK_STA(x)
#define AVR32_EPTCFG_TYPE_CTRL
#define AVR32_EPTSTA_RX_BK_RDY
#define AVR32_EPTCFG_TYPE_BULK
#define AVR32_INT_WAKE_UP
#define AVR32_EPTCTLENB(n)
#define AVR32_EPTSETSTA(n)
#define AVR32_EPTSTA_RX_SETUP
#define AVR32_CTRL_DEV_REWAKEUP
#define AVR32_EPTCFG_TYPE_INTR
#define AVR32_WRITE_4(sc, reg, data)
#define AVR32_EPTCFG_TYPE_ISOC
#define AVR32_EPTSTA_FRCESTALL
#define AVR32_INT_EPT_INT(n)
#define AVR32_CTRL_DEV_FADDR_EN
#define AVR32_EPTCTL_TX_PK_RDY
#define AVR32_EPTCFG_EPDIR_IN
#define AVR32_EPTSTA_BYTE_COUNT(x)
#define AVR32_CTRL_DEV_EN_USBA
#define AVR32_EPTSTA_CURRENT_BANK(x)
#define AVR32_EPTSTA_TOGGLESQ
#define AVR32_EPTCLRSTA(n)
#define AVR32_EPTCTL_EPT_ENABL
#define AVR32_EPTRST_MASK(n)
#define AVR32_INT_DET_SUSPD
#define AVR32_EPTSTA_TX_PK_RDY
#define AVR32_CTRL_DEV_ADDR
#define AVR32_EPTCFG_EPSIZE(n)
#define AVR32_READ_4(sc, reg)
#define AVR32_EPTCFG_EPT_MAPD
#define AVR32_EPTCFG_NBANK(n)
#define AVR32_EPTCTLDIS(n)
#define AVR32_EPTCFG_NB_TRANS(n)
#define AVR32_CTRL_DEV_DETACH
static SYSCTL_NODE(_hw_usb, OID_AUTO, dwc_otg, CTLFLAG_RW|CTLFLAG_MPSAFE, 0, "USB DWC OTG")
SYSCTL_INT(_hw_usb_dwc_otg, OID_AUTO, phy_type, CTLFLAG_RDTUN, &dwc_otg_phy_type, 0, "DWC OTG PHY TYPE - 0/1/2/3 - ULPI/HSIC/INTERNAL/UTMI+")
struct usb_config_descriptor confd
avr32dci_clocks_t * sc_clocks_on
struct avr32dci_flags sc_flags
avr32dci_clocks_t * sc_clocks_off
union avr32dci_hub_temp sc_hub_temp
struct avr32dci_td * td_next
struct usb_page_cache * pc
struct avr32dci_td * obj_next
struct usb_page_cache * pc
uint8_t support_multi_buffer
void(* endpoint_init)(struct usb_device *, struct usb_endpoint_descriptor *, struct usb_endpoint *)
const struct usb_bus_methods * methods
struct usb_xfer_queue intr_q
uByte bConfigurationValue
enum usb_hc_mode usb_mode
struct usb_device_flags flags
const struct usb_pipe_methods * methods
struct usb_endpoint_descriptor * edesc
uWord wHubCharacteristics
uint16_t max_in_frame_size
void(* open)(struct usb_xfer *)
uint32_t hc_max_frame_size
uint8_t hc_max_packet_count
struct usb_xfer * curr_xfer
uint16_t hc_max_packet_size
enum usb_hc_mode usb_mode
usb_frlength_t * frlengths
struct usb_page_cache * frbuffers
struct usb_endpoint * endpoint
struct usb_xfer_flags_int flags_int
struct usb_xfer_flags flags
struct usb_xfer_root * xroot
struct usb_port_status ps
#define UT_WRITE_INTERFACE
#define UR_SET_DESCRIPTOR
#define UT_WRITE_CLASS_OTHER
#define UT_WRITE_CLASS_DEVICE
#define UR_CLEAR_TT_BUFFER
#define UHF_C_PORT_SUSPEND
#define UT_READ_CLASS_INTERFACE
#define UDESC_DEVICE_QUALIFIER
#define UF_DEVICE_REMOTE_WAKEUP
#define UT_READ_VENDOR_INTERFACE
#define UHF_C_PORT_OVER_CURRENT
#define UPS_PORT_MODE_DEVICE
#define UHD_OC_INDIVIDUAL
#define UT_WRITE_ENDPOINT
#define UT_READ_CLASS_DEVICE
#define UT_WRITE_CLASS_INTERFACE
#define UT_READ_CLASS_OTHER
#define UHF_PORT_INDICATOR
#define UHD_PWR_NO_SWITCH
#define UPS_C_CONNECT_STATUS
#define UPS_CURRENT_CONNECT_STATUS
#define UHF_C_PORT_ENABLE
#define UT_WRITE_VENDOR_INTERFACE
#define UT_READ_INTERFACE
#define UR_GET_DESCRIPTOR
#define UHF_C_PORT_CONNECTION
void usbd_get_page(struct usb_page_cache *pc, usb_frlength_t offset, struct usb_page_search *res)
void usbd_copy_in(struct usb_page_cache *cache, usb_frlength_t offset, const void *ptr, usb_frlength_t len)
#define USB_HW_POWER_RESUME
#define USB_HW_POWER_SUSPEND
#define USB_HW_POWER_SHUTDOWN
const struct usb_string_lang usb_string_lang_en
#define USB_ADD_BYTES(ptr, size)
#define USB_BUS_UNLOCK(_b)
#define USB_BUS_LOCK_ASSERT(_b, _t)
enum usb_dev_speed usbd_get_speed(struct usb_device *udev)
void uhub_root_intr(struct usb_bus *bus, const uint8_t *ptr, uint8_t len)
void usbd_transfer_setup_sub(struct usb_setup_params *parm)
void usbd_transfer_done(struct usb_xfer *xfer, usb_error_t error)
void usbd_transfer_enqueue(struct usb_xfer_queue *pq, struct usb_xfer *xfer)
uint8_t usbd_xfer_get_isochronous_start_frame(struct usb_xfer *xfer, uint32_t frame_curr, uint32_t frame_min, uint32_t frame_ms, uint32_t frame_mask, uint32_t *p_frame_start)
void usbd_transfer_timeout_ms(struct usb_xfer *xfer, void(*cb)(void *arg), usb_timeout_t ms)
void usb_pause_mtx(struct mtx *mtx, int timo)
@ USB_ERR_NORMAL_COMPLETION