155e76c21SAndrew Thompson /*- 2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 3718cf2ccSPedro F. Giffuni * 455e76c21SAndrew Thompson * Copyright (c) 2009 Hans Petter Selasky. All rights reserved. 555e76c21SAndrew Thompson * 655e76c21SAndrew Thompson * Redistribution and use in source and binary forms, with or without 755e76c21SAndrew Thompson * modification, are permitted provided that the following conditions 855e76c21SAndrew Thompson * are met: 955e76c21SAndrew Thompson * 1. Redistributions of source code must retain the above copyright 1055e76c21SAndrew Thompson * notice, this list of conditions and the following disclaimer. 1155e76c21SAndrew Thompson * 2. Redistributions in binary form must reproduce the above copyright 1255e76c21SAndrew Thompson * notice, this list of conditions and the following disclaimer in the 1355e76c21SAndrew Thompson * documentation and/or other materials provided with the distribution. 1455e76c21SAndrew Thompson * 1555e76c21SAndrew Thompson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1655e76c21SAndrew Thompson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1755e76c21SAndrew Thompson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1855e76c21SAndrew Thompson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1955e76c21SAndrew Thompson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2055e76c21SAndrew Thompson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2155e76c21SAndrew Thompson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2255e76c21SAndrew Thompson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2355e76c21SAndrew Thompson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2455e76c21SAndrew Thompson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2555e76c21SAndrew Thompson * SUCH DAMAGE. 2655e76c21SAndrew Thompson */ 2755e76c21SAndrew Thompson 2855e76c21SAndrew Thompson #ifndef _AVR32DCI_H_ 2955e76c21SAndrew Thompson #define _AVR32DCI_H_ 3055e76c21SAndrew Thompson 3155e76c21SAndrew Thompson #define AVR32_MAX_DEVICES (USB_MIN_DEVICES + 1) 3255e76c21SAndrew Thompson 3355e76c21SAndrew Thompson /* Register definitions */ 3455e76c21SAndrew Thompson 3555e76c21SAndrew Thompson #define AVR32_CTRL 0x00 /* Control */ 3655e76c21SAndrew Thompson #define AVR32_CTRL_DEV_ADDR 0x7F 3755e76c21SAndrew Thompson #define AVR32_CTRL_DEV_FADDR_EN 0x80 3855e76c21SAndrew Thompson #define AVR32_CTRL_DEV_EN_USBA 0x100 3955e76c21SAndrew Thompson #define AVR32_CTRL_DEV_DETACH 0x200 4055e76c21SAndrew Thompson #define AVR32_CTRL_DEV_REWAKEUP 0x400 4155e76c21SAndrew Thompson 4255e76c21SAndrew Thompson #define AVR32_FNUM 0x04 /* Frame Number */ 4355e76c21SAndrew Thompson #define AVR32_FNUM_MASK 0x3FFF 4455e76c21SAndrew Thompson #define AVR32_FRAME_MASK 0x7FF 4555e76c21SAndrew Thompson 4655e76c21SAndrew Thompson /* 0x08 - 0x0C Reserved */ 4755e76c21SAndrew Thompson #define AVR32_IEN 0x10 /* Interrupt Enable */ 4855e76c21SAndrew Thompson #define AVR32_INTSTA 0x14 /* Interrupt Status */ 4955e76c21SAndrew Thompson #define AVR32_CLRINT 0x18 /* Clear Interrupt */ 5055e76c21SAndrew Thompson 5155e76c21SAndrew Thompson #define AVR32_INT_SPEED 0x00000001 /* set if High Speed else Full Speed */ 5255e76c21SAndrew Thompson #define AVR32_INT_DET_SUSPD 0x00000002 5355e76c21SAndrew Thompson #define AVR32_INT_MICRO_SOF 0x00000004 5455e76c21SAndrew Thompson #define AVR32_INT_INT_SOF 0x00000008 5555e76c21SAndrew Thompson #define AVR32_INT_ENDRESET 0x00000010 5655e76c21SAndrew Thompson #define AVR32_INT_WAKE_UP 0x00000020 5755e76c21SAndrew Thompson #define AVR32_INT_ENDOFRSM 0x00000040 5855e76c21SAndrew Thompson #define AVR32_INT_UPSTR_RES 0x00000080 5955e76c21SAndrew Thompson #define AVR32_INT_EPT_INT(n) (0x00000100 << (n)) 6055e76c21SAndrew Thompson #define AVR32_INT_DMA_INT(n) (0x01000000 << (n)) 6155e76c21SAndrew Thompson 6255e76c21SAndrew Thompson #define AVR32_EPTRST 0x1C /* Endpoints Reset */ 6355e76c21SAndrew Thompson #define AVR32_EPTRST_MASK(n) (0x00000001 << (n)) 6455e76c21SAndrew Thompson 6555e76c21SAndrew Thompson /* 0x20 - 0xCC Reserved */ 6655e76c21SAndrew Thompson #define AVR32_TSTSOFCNT 0xD0 /* Test SOF Counter */ 6755e76c21SAndrew Thompson #define AVR32_TSTCNTA 0xD4 /* Test A Counter */ 6855e76c21SAndrew Thompson #define AVR32_TSTCNTB 0xD8 /* Test B Counter */ 6955e76c21SAndrew Thompson #define AVR32_TSTMODEREG 0xDC /* Test Mode */ 7055e76c21SAndrew Thompson #define AVR32_TST 0xE0 /* Test */ 7155e76c21SAndrew Thompson #define AVR32_TST_NORMAL 0x00000000 7255e76c21SAndrew Thompson #define AVR32_TST_HS_ONLY 0x00000002 7355e76c21SAndrew Thompson #define AVR32_TST_FS_ONLY 0x00000003 7455e76c21SAndrew Thompson 7555e76c21SAndrew Thompson /* 0xE4 - 0xE8 Reserved */ 7655e76c21SAndrew Thompson #define AVR32_IPPADDRSIZE 0xEC /* PADDRSIZE */ 7755e76c21SAndrew Thompson #define AVR32_IPNAME1 0xF0 /* Name1 */ 7855e76c21SAndrew Thompson #define AVR32_IPNAME2 0xF4 /* Name2 */ 7955e76c21SAndrew Thompson #define AVR32_IPFEATURES 0xF8 /* Features */ 8055e76c21SAndrew Thompson #define AVR32_IPFEATURES_NEP(x) (((x) & 0xF) ? ((x) & 0xF) : 0x10) 8155e76c21SAndrew Thompson 8255e76c21SAndrew Thompson #define AVR32_IPVERSION 0xFC /* IP Version */ 8355e76c21SAndrew Thompson 8455e76c21SAndrew Thompson #define _A(base,n) ((base) + (0x20*(n))) 8555e76c21SAndrew Thompson #define AVR32_EPTCFG(n) _A(0x100, n) /* Endpoint Configuration */ 8655e76c21SAndrew Thompson #define AVR32_EPTCFG_EPSIZE(n) ((n)-3) /* power of two */ 8755e76c21SAndrew Thompson #define AVR32_EPTCFG_EPDIR_OUT 0x00000000 8855e76c21SAndrew Thompson #define AVR32_EPTCFG_EPDIR_IN 0x00000008 8955e76c21SAndrew Thompson #define AVR32_EPTCFG_TYPE_CTRL 0x00000000 9055e76c21SAndrew Thompson #define AVR32_EPTCFG_TYPE_ISOC 0x00000100 9155e76c21SAndrew Thompson #define AVR32_EPTCFG_TYPE_BULK 0x00000200 9255e76c21SAndrew Thompson #define AVR32_EPTCFG_TYPE_INTR 0x00000300 9355e76c21SAndrew Thompson #define AVR32_EPTCFG_NBANK(n) (0x00000400*(n)) 9455e76c21SAndrew Thompson #define AVR32_EPTCFG_NB_TRANS(n) (0x00001000*(n)) 9555e76c21SAndrew Thompson #define AVR32_EPTCFG_EPT_MAPD 0x80000000 9655e76c21SAndrew Thompson 9755e76c21SAndrew Thompson #define AVR32_EPTCTLENB(n) _A(0x104, n) /* Endpoint Control Enable */ 9855e76c21SAndrew Thompson #define AVR32_EPTCTLDIS(n) _A(0x108, n) /* Endpoint Control Disable */ 9955e76c21SAndrew Thompson #define AVR32_EPTCTL(n) _A(0x10C, n) /* Endpoint Control */ 10055e76c21SAndrew Thompson #define AVR32_EPTCTL_EPT_ENABL 0x00000001 10155e76c21SAndrew Thompson #define AVR32_EPTCTL_AUTO_VALID 0x00000002 10255e76c21SAndrew Thompson #define AVR32_EPTCTL_INTDIS_DMA 0x00000008 10355e76c21SAndrew Thompson #define AVR32_EPTCTL_NYET_DIS 0x00000010 10455e76c21SAndrew Thompson #define AVR32_EPTCTL_DATAX_RX 0x00000040 10555e76c21SAndrew Thompson #define AVR32_EPTCTL_MDATA_RX 0x00000080 10655e76c21SAndrew Thompson #define AVR32_EPTCTL_ERR_OVFLW 0x00000100 10755e76c21SAndrew Thompson #define AVR32_EPTCTL_RX_BK_RDY 0x00000200 10855e76c21SAndrew Thompson #define AVR32_EPTCTL_TX_COMPLT 0x00000400 10955e76c21SAndrew Thompson #define AVR32_EPTCTL_TX_PK_RDY 0x00000800 11055e76c21SAndrew Thompson #define AVR32_EPTCTL_RX_SETUP 0x00001000 11155e76c21SAndrew Thompson #define AVR32_EPTCTL_STALL_SNT 0x00002000 11255e76c21SAndrew Thompson #define AVR32_EPTCTL_NAK_IN 0x00004000 11355e76c21SAndrew Thompson #define AVR32_EPTCTL_NAK_OUT 0x00008000 11455e76c21SAndrew Thompson #define AVR32_EPTCTL_BUSY_BANK 0x00040000 11555e76c21SAndrew Thompson #define AVR32_EPTCTL_SHORT_PCKT 0x80000000 11655e76c21SAndrew Thompson 11755e76c21SAndrew Thompson /* 0x110 Reserved */ 11855e76c21SAndrew Thompson #define AVR32_EPTSETSTA(n) _A(0x114, n) /* Endpoint Set Status */ 11955e76c21SAndrew Thompson #define AVR32_EPTCLRSTA(n) _A(0x118, n) /* Endpoint Clear Status */ 12055e76c21SAndrew Thompson #define AVR32_EPTSTA(n) _A(0x11C, n) /* Endpoint Status */ 12155e76c21SAndrew Thompson #define AVR32_EPTSTA_FRCESTALL 0x00000020 12255e76c21SAndrew Thompson #define AVR32_EPTSTA_TOGGLESQ_STA(x) (((x) & 0xC0) >> 6) 12355e76c21SAndrew Thompson #define AVR32_EPTSTA_TOGGLESQ 0x00000040 12455e76c21SAndrew Thompson #define AVR32_EPTSTA_ERR_OVFLW 0x00000100 12555e76c21SAndrew Thompson #define AVR32_EPTSTA_RX_BK_RDY 0x00000200 12655e76c21SAndrew Thompson #define AVR32_EPTSTA_TX_COMPLT 0x00000400 12755e76c21SAndrew Thompson #define AVR32_EPTSTA_TX_PK_RDY 0x00000800 12855e76c21SAndrew Thompson #define AVR32_EPTSTA_RX_SETUP 0x00001000 12955e76c21SAndrew Thompson #define AVR32_EPTSTA_STALL_SNT 0x00002000 13055e76c21SAndrew Thompson #define AVR32_EPTSTA_NAK_IN 0x00004000 13155e76c21SAndrew Thompson #define AVR32_EPTSTA_NAK_OUT 0x00008000 13255e76c21SAndrew Thompson #define AVR32_EPTSTA_CURRENT_BANK(x) (((x) & 0x00030000) >> 16) 13355e76c21SAndrew Thompson #define AVR32_EPTSTA_BUSY_BANK_STA(x) (((x) & 0x000C0000) >> 18) 13455e76c21SAndrew Thompson #define AVR32_EPTSTA_BYTE_COUNT(x) (((x) & 0x7FF00000) >> 20) 13555e76c21SAndrew Thompson #define AVR32_EPTSTA_SHRT_PCKT 0x80000000 13655e76c21SAndrew Thompson 13755e76c21SAndrew Thompson /* 0x300 - 0x30C Reserved */ 13855e76c21SAndrew Thompson #define AVR32_DMANXTDSC 0x310 /* DMA Next Descriptor Address */ 13955e76c21SAndrew Thompson #define AVR32_DMAADDRESS 0x314 /* DMA Channel Address */ 14055e76c21SAndrew Thompson 14155e76c21SAndrew Thompson #define AVR32_READ_4(sc, reg) \ 14255e76c21SAndrew Thompson bus_space_read_4((sc)->sc_io_tag, (sc)->sc_io_hdl, reg) 14355e76c21SAndrew Thompson 14455e76c21SAndrew Thompson #define AVR32_WRITE_4(sc, reg, data) \ 14555e76c21SAndrew Thompson bus_space_write_4((sc)->sc_io_tag, (sc)->sc_io_hdl, reg, data) 14655e76c21SAndrew Thompson 14755e76c21SAndrew Thompson #define AVR32_WRITE_MULTI_4(sc, reg, ptr, len) \ 14855e76c21SAndrew Thompson bus_space_write_multi_4((sc)->sc_io_tag, (sc)->sc_io_hdl, reg, ptr, len) 14955e76c21SAndrew Thompson 15055e76c21SAndrew Thompson #define AVR32_READ_MULTI_4(sc, reg, ptr, len) \ 15155e76c21SAndrew Thompson bus_space_read_multi_4((sc)->sc_io_tag, (sc)->sc_io_hdl, reg, ptr, len) 15255e76c21SAndrew Thompson 15355e76c21SAndrew Thompson /* 15455e76c21SAndrew Thompson * Maximum number of endpoints supported: 15555e76c21SAndrew Thompson */ 15655e76c21SAndrew Thompson #define AVR32_EP_MAX 7 15755e76c21SAndrew Thompson 15855e76c21SAndrew Thompson struct avr32dci_td; 15955e76c21SAndrew Thompson 16055e76c21SAndrew Thompson typedef uint8_t (avr32dci_cmd_t)(struct avr32dci_td *td); 161760bc48eSAndrew Thompson typedef void (avr32dci_clocks_t)(struct usb_bus *); 16255e76c21SAndrew Thompson 16355e76c21SAndrew Thompson struct avr32dci_td { 16455e76c21SAndrew Thompson struct avr32dci_td *obj_next; 16555e76c21SAndrew Thompson avr32dci_cmd_t *func; 166760bc48eSAndrew Thompson struct usb_page_cache *pc; 16755e76c21SAndrew Thompson uint32_t offset; 16855e76c21SAndrew Thompson uint32_t remainder; 16955e76c21SAndrew Thompson uint16_t max_packet_size; 1702e141748SHans Petter Selasky uint8_t bank_shift; 17155e76c21SAndrew Thompson uint8_t error:1; 17255e76c21SAndrew Thompson uint8_t alt_next:1; 17355e76c21SAndrew Thompson uint8_t short_pkt:1; 17455e76c21SAndrew Thompson uint8_t support_multi_buffer:1; 17555e76c21SAndrew Thompson uint8_t did_stall:1; 17655e76c21SAndrew Thompson uint8_t ep_no:3; 17755e76c21SAndrew Thompson }; 17855e76c21SAndrew Thompson 17955e76c21SAndrew Thompson struct avr32dci_std_temp { 18055e76c21SAndrew Thompson avr32dci_cmd_t *func; 181760bc48eSAndrew Thompson struct usb_page_cache *pc; 18255e76c21SAndrew Thompson struct avr32dci_td *td; 18355e76c21SAndrew Thompson struct avr32dci_td *td_next; 18455e76c21SAndrew Thompson uint32_t len; 18555e76c21SAndrew Thompson uint32_t offset; 18655e76c21SAndrew Thompson uint16_t max_frame_size; 18755e76c21SAndrew Thompson uint8_t bank_shift; 18855e76c21SAndrew Thompson uint8_t short_pkt; 18955e76c21SAndrew Thompson /* 19055e76c21SAndrew Thompson * short_pkt = 0: transfer should be short terminated 19155e76c21SAndrew Thompson * short_pkt = 1: transfer should not be short terminated 19255e76c21SAndrew Thompson */ 19355e76c21SAndrew Thompson uint8_t setup_alt_next; 19455e76c21SAndrew Thompson uint8_t did_stall; 19555e76c21SAndrew Thompson }; 19655e76c21SAndrew Thompson 19755e76c21SAndrew Thompson struct avr32dci_config_desc { 198760bc48eSAndrew Thompson struct usb_config_descriptor confd; 199760bc48eSAndrew Thompson struct usb_interface_descriptor ifcd; 200760bc48eSAndrew Thompson struct usb_endpoint_descriptor endpd; 20155e76c21SAndrew Thompson } __packed; 20255e76c21SAndrew Thompson 20355e76c21SAndrew Thompson union avr32dci_hub_temp { 20455e76c21SAndrew Thompson uWord wValue; 205760bc48eSAndrew Thompson struct usb_port_status ps; 20655e76c21SAndrew Thompson }; 20755e76c21SAndrew Thompson 20855e76c21SAndrew Thompson struct avr32dci_flags { 20955e76c21SAndrew Thompson uint8_t change_connect:1; 21055e76c21SAndrew Thompson uint8_t change_suspend:1; 21155e76c21SAndrew Thompson uint8_t status_suspend:1; /* set if suspended */ 21255e76c21SAndrew Thompson uint8_t status_vbus:1; /* set if present */ 21355e76c21SAndrew Thompson uint8_t status_bus_reset:1; /* set if reset complete */ 21455e76c21SAndrew Thompson uint8_t remote_wakeup:1; 21555e76c21SAndrew Thompson uint8_t self_powered:1; 21655e76c21SAndrew Thompson uint8_t clocks_off:1; 21755e76c21SAndrew Thompson uint8_t port_powered:1; 21855e76c21SAndrew Thompson uint8_t port_enabled:1; 21955e76c21SAndrew Thompson uint8_t d_pulled_up:1; 22055e76c21SAndrew Thompson }; 22155e76c21SAndrew Thompson 22255e76c21SAndrew Thompson struct avr32dci_softc { 223760bc48eSAndrew Thompson struct usb_bus sc_bus; 22455e76c21SAndrew Thompson union avr32dci_hub_temp sc_hub_temp; 22555e76c21SAndrew Thompson 22655e76c21SAndrew Thompson /* must be set by by the bus interface layer */ 22755e76c21SAndrew Thompson avr32dci_clocks_t *sc_clocks_on; 22855e76c21SAndrew Thompson avr32dci_clocks_t *sc_clocks_off; 22955e76c21SAndrew Thompson 230760bc48eSAndrew Thompson struct usb_device *sc_devices[AVR32_MAX_DEVICES]; 23155e76c21SAndrew Thompson struct resource *sc_irq_res; 23255e76c21SAndrew Thompson void *sc_intr_hdl; 23355e76c21SAndrew Thompson struct resource *sc_io_res; 23455e76c21SAndrew Thompson bus_space_tag_t sc_io_tag; 23555e76c21SAndrew Thompson bus_space_handle_t sc_io_hdl; 23655e76c21SAndrew Thompson uint8_t *physdata; 23755e76c21SAndrew Thompson 23855e76c21SAndrew Thompson uint8_t sc_rt_addr; /* root hub address */ 23955e76c21SAndrew Thompson uint8_t sc_dv_addr; /* device address */ 24055e76c21SAndrew Thompson uint8_t sc_conf; /* root hub config */ 24155e76c21SAndrew Thompson 24255e76c21SAndrew Thompson uint8_t sc_hub_idata[1]; 24355e76c21SAndrew Thompson 24455e76c21SAndrew Thompson struct avr32dci_flags sc_flags; 24555e76c21SAndrew Thompson }; 24655e76c21SAndrew Thompson 24755e76c21SAndrew Thompson /* prototypes */ 24855e76c21SAndrew Thompson 249e0a69b51SAndrew Thompson usb_error_t avr32dci_init(struct avr32dci_softc *sc); 25055e76c21SAndrew Thompson void avr32dci_uninit(struct avr32dci_softc *sc); 25155e76c21SAndrew Thompson void avr32dci_interrupt(struct avr32dci_softc *sc); 25255e76c21SAndrew Thompson void avr32dci_vbus_interrupt(struct avr32dci_softc *sc, uint8_t is_on); 25355e76c21SAndrew Thompson 25455e76c21SAndrew Thompson #endif /* _AVR32DCI_H_ */ 255