Implement USB device side driver code for SAF1761 and compatible

chips, based on datasheet and existing USS820 DCI driver. This code is
not yet tested.

Sponsored by:	DARPA, AFRL
This commit is contained in:
Hans Petter Selasky 2014-05-14 17:04:02 +00:00
parent a19c94859b
commit b9f21c2ce8
4 changed files with 2106 additions and 8 deletions

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
/* $FreeBSD$ */
/*-
* Copyright (c) 2014 Hans Petter Selasky
* Copyright (c) 2014 Hans Petter Selasky <hselasky@FreeBSD.org>
* All rights reserved.
*
* This software was developed by SRI International and the University of
@ -32,5 +32,111 @@
#ifndef _SAF1761_DCI_H_
#define _SAF1761_DCI_H_
#define SOTG_MAX_DEVICES (USB_MIN_DEVICES + 1)
#define SOTG_FS_MAX_PACKET_SIZE 64
#define SOTG_HS_MAX_PACKET_SIZE 512
#define SAF1761_READ_1(sc, reg) \
bus_space_read_1((sc)->sc_io_tag, (sc)->sc_io_hdl, reg)
#define SAF1761_READ_2(sc, reg) \
bus_space_read_2((sc)->sc_io_tag, (sc)->sc_io_hdl, reg)
#define SAF1761_READ_4(sc, reg) \
bus_space_read_4((sc)->sc_io_tag, (sc)->sc_io_hdl, reg)
#define SAF1761_WRITE_1(sc, reg, data) \
bus_space_write_1((sc)->sc_io_tag, (sc)->sc_io_hdl, reg, data)
#define SAF1761_WRITE_2(sc, reg, data) \
bus_space_write_2((sc)->sc_io_tag, (sc)->sc_io_hdl, reg, data)
#define SAF1761_WRITE_4(sc, reg, data) \
bus_space_write_4((sc)->sc_io_tag, (sc)->sc_io_hdl, reg, data)
struct saf1761_dci_softc;
struct saf1761_dci_td;
typedef uint8_t (saf1761_dci_cmd_t)(struct saf1761_dci_softc *, struct saf1761_dci_td *td);
struct saf1761_dci_td {
struct saf1761_dci_td *obj_next;
saf1761_dci_cmd_t *func;
struct usb_page_cache *pc;
uint32_t offset;
uint32_t remainder;
uint16_t max_packet_size;
uint8_t ep_index;
uint8_t error:1;
uint8_t alt_next:1;
uint8_t short_pkt:1;
uint8_t did_stall:1;
};
struct saf1761_dci_std_temp {
saf1761_dci_cmd_t *func;
struct usb_page_cache *pc;
struct saf1761_dci_td *td;
struct saf1761_dci_td *td_next;
uint32_t len;
uint32_t offset;
uint16_t max_frame_size;
uint8_t short_pkt;
/*
* short_pkt = 0: transfer should be short terminated
* short_pkt = 1: transfer should not be short terminated
*/
uint8_t setup_alt_next;
uint8_t did_stall;
};
struct saf1761_dci_config_desc {
struct usb_config_descriptor confd;
struct usb_interface_descriptor ifcd;
struct usb_endpoint_descriptor endpd;
} __packed;
union saf1761_dci_hub_temp {
uWord wValue;
struct usb_port_status ps;
};
struct saf1761_dci_flags {
uint8_t change_connect:1;
uint8_t change_suspend:1;
uint8_t status_suspend:1; /* set if suspended */
uint8_t status_vbus:1; /* set if present */
uint8_t status_bus_reset:1; /* set if reset complete */
uint8_t clocks_off:1;
uint8_t port_powered:1;
uint8_t port_enabled:1;
uint8_t d_pulled_up:1;
uint8_t mcsr_feat:1;
};
struct saf1761_dci_softc {
struct usb_bus sc_bus;
union saf1761_dci_hub_temp sc_hub_temp;
struct usb_device *sc_devices[SOTG_MAX_DEVICES];
struct resource *sc_io_res;
struct resource *sc_irq_res;
void *sc_intr_hdl;
bus_size_t sc_io_size;
bus_space_tag_t sc_io_tag;
bus_space_handle_t sc_io_hdl;
uint32_t sc_intr_enable; /* enabled interrupts */
uint8_t sc_rt_addr; /* root HUB address */
uint8_t sc_dv_addr; /* device address */
uint8_t sc_conf; /* root HUB config */
uint8_t sc_hub_idata[1];
struct saf1761_dci_flags sc_flags;
};
/* prototypes */
usb_error_t saf1761_dci_init(struct saf1761_dci_softc *sc);
void saf1761_dci_uninit(struct saf1761_dci_softc *sc);
void saf1761_dci_interrupt(struct saf1761_dci_softc *sc);
#endif /* _SAF1761_DCI_H_ */

View file

@ -1,6 +1,6 @@
/* $FreeBSD$ */
/*-
* Copyright (c) 2014 Hans Petter Selasky
* Copyright (c) 2014 Hans Petter Selasky <hselasky@FreeBSD.org>
* All rights reserved.
*
* This software was developed by SRI International and the University of
@ -29,6 +29,42 @@
* SUCH DAMAGE.
*/
#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>
#include <dev/usb/usb_core.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 /* USB_GLOBAL_INCLUDE_FILE */
#include <dev/usb/controller/saf1761_dci.h>
#include <dev/usb/controller/saf1761_dci_reg.h>

View file

@ -1,6 +1,6 @@
/* $FreeBSD$ */
/*-
* Copyright (c) 2014 Hans Petter Selasky
* Copyright (c) 2014 Hans Petter Selasky <hselasky@FreeBSD.org>
* All rights reserved.
*
* This software was developed by SRI International and the University of
@ -105,8 +105,10 @@
#define SOTG_OTG_CTRL 0x374
#define SOTG_EP_INDEX 0x22c
#define SOTG_EP_INDEX_EP0SETUP (1 << 5)
#define SOTG_EP_INDEX_ENDP_INDEX (15 << 1)
#define SOTG_EP_INDEX_ENDP_INDEX_MASK (15 << 1)
#define SOTG_EP_INDEX_ENDP_INDEX_SHIFT 1
#define SOTG_EP_INDEX_DIR_IN (1 << 0)
#define SOTG_EP_INDEX_DIR_OUT 0
#define SOTG_CTRL_FUNC 0x228
#define SOTG_CTRL_FUNC_CLBUF (1 << 4)
#define SOTG_CTRL_FUNC_VENDP (1 << 3)
@ -116,6 +118,7 @@
#define SOTG_DATA_PORT 0x220
#define SOTG_BUF_LENGTH 0x21C
#define SOTG_DCBUFFERSTATUS 0x21E
#define SOTG_DCBUFFERSTATUS_FILLED_MASK (3 << 0)
#define SOTG_EP_MAXPACKET 0x204
#define SOTG_EP_TYPE 0x208
#define SOTG_EP_TYPE_NOEMPPKT (1 << 4)
@ -144,9 +147,9 @@
#define SOTG_DCINTERRUPT_IEBRST (1 << 0)
#define SOTG_DCCHIP_ID 0x270
#define SOTG_FRAME_NUM 0x274
#define SOTG_FRAME_NUM_MICROSOFR 0x3800
#define SOTG_FRAME_NUM_MICROSOFR_MASK 0x3800
#define SOTG_FRAME_NUM_MICROSOFR_SHIFT 11
#define SOTG_FRAME_NUM_SOFR 0x7FF
#define SOTG_FRAME_NUM_SOFR_MASK 0x7FF
#define SOTG_DCSCRATCH 0x278
#define SOTG_UNLOCK_DEVICE 0x27C
#define SOTG_UNLOCK_DEVICE_CODE 0xAA37