ameba micropython sdk first commit

This commit is contained in:
xidameng 2020-07-31 22:16:12 +08:00
commit 8508ee6139
5619 changed files with 1874619 additions and 0 deletions

View file

@ -0,0 +1,402 @@
#ifndef __USB_AUDIO_H
#define __USB_AUDIO_H
#include <platform_opts.h>
#ifdef CONFIG_USBD_AUDIO
#include "usb.h"
#include "usb_composite.h"
#include "usb_audio_8763.h"
#include "ameba_otg.h"
#define USBD_AUDIO_DEBUG 0
#if USBD_AUDIO_DEBUG
#define USBD_AUDIO_INFO(fmt, args...) printf("\n\r[ADC]%s: " fmt, __FUNCTION__, ## args)
#define USBD_AUDIO_WARN(fmt, args...) printf("\n\r[ADC]%s: " fmt, __FUNCTION__, ## args)
#define USBD_AUDIO_ERROR(fmt, args...) printf("\n\r[ADC]%s: " fmt, __FUNCTION__, ## args)
#define USBD_AUDIO_ENTER printf("\n\r[ADC]%s: =>", __FUNCTION__)
#define USBD_AUDIO_EXIT printf("\n\r[ADC]%s: <=", __FUNCTION__)
#define USBD_AUDIO_EXIT_ERR printf("\n\r[ADC]%s: ERR <=", __FUNCTION__)
#else
#define USBD_AUDIO_INFO(fmt, args...)
#define USBD_AUDIO_WARN(fmt, args...)
#define USBD_AUDIO_ERROR(fmt, args...)
#define USBD_AUDIO_ENTER
#define USBD_AUDIO_EXIT
#define USBD_AUDIO_EXIT_ERR
#endif
#define USB_ISO_OUT_ENDPOINT_ADDRESS 0x02
#define USB_ISO_IN_ENDPOINT_ADDRESS 0x81
struct usb_audio_control {
dwc_list_link_t list;
const char *name;
uint8_t type;
int data[5];
int (*set)(struct usb_audio_control *con, uint8_t cmd, int value);
int (*get)(struct usb_audio_control *con, uint8_t cmd);
};
struct usb_audio_control_selector {
dwc_list_link_t list;
dwc_list_link_t control;
uint8_t id;
const char *name;
uint8_t type;
struct usb_descriptor_header *desc;
};
#define UAC_VERSION_1 0x00
#define UAC_VERSION_2 0x20
/* A.2 Audio Interface Subclass Codes */
#define USB_SUBCLASS_AUDIOCONTROL 0x01
#define USB_SUBCLASS_AUDIOSTREAMING 0x02
#define USB_SUBCLASS_MIDISTREAMING 0x03
#define F_AUDIO_NUM_INTERFACES 2
/* A.5 Audio Class-Specific AC Interface Descriptor Subtypes */
#define UAC_HEADER 0x01
#define UAC_INPUT_TERMINAL 0x02
#define UAC_OUTPUT_TERMINAL 0x03
#define UAC_MIXER_UNIT 0x04
#define UAC_SELECTOR_UNIT 0x05
#define UAC_FEATURE_UNIT 0x06
#define UAC1_PROCESSING_UNIT 0x07
#define UAC1_EXTENSION_UNIT 0x08
/* A.6 Audio Class-Specific AS Interface Descriptor Subtypes */
#define UAC_AS_GENERAL 0x01
#define UAC_FORMAT_TYPE 0x02
#define UAC_FORMAT_SPECIFIC 0x03
/* A.7 Processing Unit Process Types */
#define UAC_PROCESS_UNDEFINED 0x00
#define UAC_PROCESS_UP_DOWNMIX 0x01
#define UAC_PROCESS_DOLBY_PROLOGIC 0x02
#define UAC_PROCESS_STEREO_EXTENDER 0x03
#define UAC_PROCESS_REVERB 0x04
#define UAC_PROCESS_CHORUS 0x05
#define UAC_PROCESS_DYN_RANGE_COMP 0x06
/* A.8 Audio Class-Specific Endpoint Descriptor Subtypes */
#define UAC_EP_GENERAL 0x01
/* A.9 Audio Class-Specific Request Codes */
#define UAC_SET_ 0x00
#define UAC_GET_ 0x80
#define UAC__CUR 0x1
#define UAC__MIN 0x2
#define UAC__MAX 0x3
#define UAC__RES 0x4
#define UAC__MEM 0x5
#define UAC_SET_CUR (UAC_SET_ | UAC__CUR)
#define UAC_GET_CUR (UAC_GET_ | UAC__CUR)
#define UAC_SET_MIN (UAC_SET_ | UAC__MIN)
#define UAC_GET_MIN (UAC_GET_ | UAC__MIN)
#define UAC_SET_MAX (UAC_SET_ | UAC__MAX)
#define UAC_GET_MAX (UAC_GET_ | UAC__MAX)
#define UAC_SET_RES (UAC_SET_ | UAC__RES)
#define UAC_GET_RES (UAC_GET_ | UAC__RES)
#define UAC_SET_MEM (UAC_SET_ | UAC__MEM)
#define UAC_GET_MEM (UAC_GET_ | UAC__MEM)
#define UAC_GET_STAT 0xff
/* A.10 Control Selector Codes */
/* A.10.1 Terminal Control Selectors */
#define UAC_TERM_COPY_PROTECT 0x01
/* A.10.2 Feature Unit Control Selectors */
#define UAC_FU_MUTE 0x01
#define UAC_FU_VOLUME 0x02
#define UAC_FU_BASS 0x03
#define UAC_FU_MID 0x04
#define UAC_FU_TREBLE 0x05
#define UAC_FU_GRAPHIC_EQUALIZER 0x06
#define UAC_FU_AUTOMATIC_GAIN 0x07
#define UAC_FU_DELAY 0x08
#define UAC_FU_BASS_BOOST 0x09
#define UAC_FU_LOUDNESS 0x0a
#define UAC_CONTROL_BIT(CS) (1 << ((CS) - 1))
/* A.10.3.1 Up/Down-mix Processing Unit Controls Selectors */
#define UAC_UD_ENABLE 0x01
#define UAC_UD_MODE_SELECT 0x02
/* A.10.3.2 Dolby Prologic (tm) Processing Unit Controls Selectors */
#define UAC_DP_ENABLE 0x01
#define UAC_DP_MODE_SELECT 0x02
/* A.10.3.3 3D Stereo Extender Processing Unit Control Selectors */
#define UAC_3D_ENABLE 0x01
#define UAC_3D_SPACE 0x02
/* A.10.3.4 Reverberation Processing Unit Control Selectors */
#define UAC_REVERB_ENABLE 0x01
#define UAC_REVERB_LEVEL 0x02
#define UAC_REVERB_TIME 0x03
#define UAC_REVERB_FEEDBACK 0x04
/* A.10.3.5 Chorus Processing Unit Control Selectors */
#define UAC_CHORUS_ENABLE 0x01
#define UAC_CHORUS_LEVEL 0x02
#define UAC_CHORUS_RATE 0x03
#define UAC_CHORUS_DEPTH 0x04
/* A.10.3.6 Dynamic Range Compressor Unit Control Selectors */
#define UAC_DCR_ENABLE 0x01
#define UAC_DCR_RATE 0x02
#define UAC_DCR_MAXAMPL 0x03
#define UAC_DCR_THRESHOLD 0x04
#define UAC_DCR_ATTACK_TIME 0x05
#define UAC_DCR_RELEASE_TIME 0x06
/* A.10.4 Extension Unit Control Selectors */
#define UAC_XU_ENABLE 0x01
/* MIDI - A.1 MS Class-Specific Interface Descriptor Subtypes */
#define UAC_MS_HEADER 0x01
#define UAC_MIDI_IN_JACK 0x02
#define UAC_MIDI_OUT_JACK 0x03
/* MIDI - A.1 MS Class-Specific Endpoint Descriptor Subtypes */
#define UAC_MS_GENERAL 0x01
/* Terminals - 2.1 USB Terminal Types */
#define UAC_TERMINAL_UNDEFINED 0x100
#define UAC_TERMINAL_STREAMING 0x101
#define UAC_TERMINAL_VENDOR_SPEC 0x1FF
#pragma pack(push)
#pragma pack(1)
/* Terminal Control Selectors */
/* 4.3.2 Class-Specific AC Interface Descriptor */
struct uac1_ac_header_descriptor {
uint8_t bLength; /* 8 + n */
uint8_t bDescriptorType; /* USB_DT_CS_INTERFACE */
uint8_t bDescriptorSubtype; /* UAC_MS_HEADER */
uint16_t bcdADC; /* 0x0100 */
uint16_t wTotalLength; /* includes Unit and Terminal desc. */
uint8_t bInCollection; /* n */
uint8_t baInterfaceNr[F_AUDIO_NUM_INTERFACES]; /* [n] */
} __attribute__((packed));
//#define AC_HEADER_COUNT 2
#define UAC_DT_AC_HEADER_SIZE(n) (8 + (n))
/* 4.3.2.1 Input Terminal Descriptor */
struct uac_input_terminal_descriptor {
uint8_t bLength; /* in bytes: 12 */
uint8_t bDescriptorType; /* CS_INTERFACE descriptor type */
uint8_t bDescriptorSubtype; /* INPUT_TERMINAL descriptor subtype */
uint8_t bTerminalID; /* Constant uniquely terminal ID */
uint16_t wTerminalType; /* USB Audio Terminal Types */
uint8_t bAssocTerminal; /* ID of the Output Terminal associated */
uint8_t bNrChannels; /* Number of logical output channels */
uint16_t wChannelConfig;
uint8_t iChannelNames;
uint8_t iTerminal;
} __attribute__((packed));
#define UAC_DT_INPUT_TERMINAL_SIZE 12
/* Terminals - 2.2 Input Terminal Types */
#define UAC_INPUT_TERMINAL_UNDEFINED 0x200
#define UAC_INPUT_TERMINAL_MICROPHONE 0x201
#define UAC_INPUT_TERMINAL_DESKTOP_MICROPHONE 0x202
#define UAC_INPUT_TERMINAL_PERSONAL_MICROPHONE 0x203
#define UAC_INPUT_TERMINAL_OMNI_DIR_MICROPHONE 0x204
#define UAC_INPUT_TERMINAL_MICROPHONE_ARRAY 0x205
#define UAC_INPUT_TERMINAL_PROC_MICROPHONE_ARRAY 0x206
/* Terminals - control selectors */
#define UAC_TERMINAL_CS_COPY_PROTECT_CONTROL 0x01
/* 4.3.2.2 Output Terminal Descriptor */
struct uac1_output_terminal_descriptor {
uint8_t bLength; /* in bytes: 9 */
uint8_t bDescriptorType; /* CS_INTERFACE descriptor type */
uint8_t bDescriptorSubtype; /* OUTPUT_TERMINAL descriptor subtype */
uint8_t bTerminalID; /* Constant uniquely terminal ID */
uint16_t wTerminalType; /* USB Audio Terminal Types */
uint8_t bAssocTerminal; /* ID of the Input Terminal associated */
uint8_t bSourceID; /* ID of the connected Unit or Terminal*/
uint8_t iTerminal;
} __attribute__((packed));
#define UAC_DT_OUTPUT_TERMINAL_SIZE 9
/* Terminals - 2.3 Output Terminal Types */
#define UAC_OUTPUT_TERMINAL_UNDEFINED 0x300
#define UAC_OUTPUT_TERMINAL_SPEAKER 0x301
#define UAC_OUTPUT_TERMINAL_HEADPHONES 0x302
#define UAC_OUTPUT_TERMINAL_HEAD_MOUNTED_DISPLAY_AUDIO 0x303
#define UAC_OUTPUT_TERMINAL_DESKTOP_SPEAKER 0x304
#define UAC_OUTPUT_TERMINAL_ROOM_SPEAKER 0x305
#define UAC_OUTPUT_TERMINAL_COMMUNICATION_SPEAKER 0x306
#define UAC_OUTPUT_TERMINAL_LOW_FREQ_EFFECTS_SPEAKER 0x307
/* Set bControlSize = 2 as default setting */
#define UAC_DT_FEATURE_UNIT_SIZE(ch) (7 + ((ch) + 1) * 2)
/* As above, but more useful for defining your own descriptors: */
//#define DECLARE_UAC_FEATURE_UNIT_DESCRIPTOR(ch)
#define DECLARE_UAC_FEATURE_UNIT_DESCRIPTOR 2
#define DECLARE_FEATURE_UNIY_CONTROL_SIZE 1
#define CHANNEL_CNT 2
struct uac_feature_unit_descriptor_2 {
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bDescriptorSubtype;
uint8_t bUnitID;
uint8_t bSourceID;
uint8_t bControlSize;//DECLARE_FEATURE_UNIY_CONTROL_SIZE
//uint16_t bmaControls[DECLARE_UAC_FEATURE_UNIT_DESCRIPTOR + 1];
uint8_t bmaControls[((DECLARE_FEATURE_UNIY_CONTROL_SIZE) * (2)) + 1];
uint8_t iFeature;
} __attribute__((packed));
struct uac_feature_unit_descriptor_1 {
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bDescriptorSubtype;
uint8_t bUnitID;
uint8_t bSourceID;
uint8_t bControlSize;//DECLARE_FEATURE_UNIY_CONTROL_SIZE
//uint16_t bmaControls[DECLARE_UAC_FEATURE_UNIT_DESCRIPTOR + 1];
uint8_t bmaControls[((DECLARE_FEATURE_UNIY_CONTROL_SIZE) * (1)) + 1];
uint8_t iFeature;
} __attribute__((packed));
struct uac_feature_unit_descriptor_0 {
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bDescriptorSubtype;
uint8_t bUnitID;
uint8_t bSourceID;
uint8_t bControlSize;//DECLARE_FEATURE_UNIY_CONTROL_SIZE
//uint16_t bmaControls[DECLARE_UAC_FEATURE_UNIT_DESCRIPTOR + 1];
uint8_t bmaControls[((DECLARE_FEATURE_UNIY_CONTROL_SIZE) * (0)) + 1];
uint8_t iFeature;
} __attribute__((packed));
/* 4.3.2.3 Mixer Unit Descriptor */
// fongpin modify
#define MIXER_UNIT_CONNECTED 2 // BBRRO DEFINE
struct uac_mixer_unit_descriptor {
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bDescriptorSubtype;
uint8_t bUnitID;
uint8_t bNrInPins;
uint8_t baSourceID[MIXER_UNIT_CONNECTED];// modify
uint8_t bNrChannels;// add
uint16_t bmChannelConfig;//add
uint8_t iChannelNames;//add
uint8_t bmControls;// add
uint8_t iMixer;//add
} __attribute__((packed));
/* 4.3.2.4 Selector Unit Descriptor */
// fongpin modify
struct uac_selector_unit_descriptor {
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bDescriptorSubtype;
uint8_t bUintID;
uint8_t bNrInPins;
uint8_t baSourceID;
uint8_t iSelector;
} __attribute__((packed));
/* 4.5.2 Class-Specific AS Interface Descriptor */
struct uac1_as_header_descriptor {
uint8_t bLength; /* in bytes: 7 */
uint8_t bDescriptorType; /* USB_DT_CS_INTERFACE */
uint8_t bDescriptorSubtype; /* AS_GENERAL */
uint8_t bTerminalLink; /* Terminal ID of connected Terminal */
uint8_t bDelay; /* Delay introduced by the data path */
uint16_t wFormatTag; /* The Audio Data Format */
} __attribute__((packed));
#define UAC_DT_AS_HEADER_SIZE 7
/* Formats - A.1.1 Audio Data Format Type I Codes */
#define UAC_FORMAT_TYPE_I_UNDEFINED 0x0
#define UAC_FORMAT_TYPE_I_PCM 0x1
#define UAC_FORMAT_TYPE_I_PCM8 0x2
#define UAC_FORMAT_TYPE_I_IEEE_FLOAT 0x3
#define UAC_FORMAT_TYPE_I_ALAW 0x4
#define UAC_FORMAT_TYPE_I_MULAW 0x5
struct uac_format_type_i_discrete_descriptor {
uint8_t bLength; /* in bytes: 8 + (ns * 3) */
uint8_t bDescriptorType; /* USB_DT_CS_INTERFACE */
uint8_t bDescriptorSubtype; /* FORMAT_TYPE */
uint8_t bFormatType; /* FORMAT_TYPE_1 */
uint8_t bNrChannels; /* physical channels in the stream */
uint8_t bSubframeSize; /* */
uint8_t bBitResolution;
uint8_t bSamFreqType;
uint8_t tSamFreq[3][3];
} __attribute__((packed));
/* Formats - A.2 Format Type Codes */
#define UAC_FORMAT_TYPE_UNDEFINED 0x0
#define UAC_FORMAT_TYPE_I 0x1
#define UAC_FORMAT_TYPE_II 0x2
#define UAC_FORMAT_TYPE_III 0x3
#define UAC_EXT_FORMAT_TYPE_I 0x81
#define UAC_EXT_FORMAT_TYPE_II 0x82
#define UAC_EXT_FORMAT_TYPE_III 0x83
struct uac_iso_endpoint_descriptor {
uint8_t bLength; /* in bytes: 7 */
uint8_t bDescriptorType; /* USB_DT_CS_ENDPOINT */
uint8_t bDescriptorSubtype; /* EP_GENERAL */
uint8_t bmAttributes;
uint8_t bLockDelayUnits;
uint16_t wLockDelay;
} __attribute__((packed));
#define UAC_ISO_ENDPOINT_DESC_SIZE 7
#define UAC_EP_CS_ATTR_SAMPLE_RATE 0x01
#define UAC_EP_CS_ATTR_PITCH_CONTROL 0x02
#define UAC_EP_CS_ATTR_FILL_MAX 0x80
/* status word format (3.7.1.1) */
#define UAC1_STATUS_TYPE_ORIG_MASK 0x0f
#define UAC1_STATUS_TYPE_ORIG_AUDIO_CONTROL_IF 0x0
#define UAC1_STATUS_TYPE_ORIG_AUDIO_STREAM_IF 0x1
#define UAC1_STATUS_TYPE_ORIG_AUDIO_STREAM_EP 0x2
#define UAC1_STATUS_TYPE_IRQ_PENDING (1 << 7)
#define UAC1_STATUS_TYPE_MEM_CHANGED (1 << 6)
struct uac1_status_word {
uint8_t bStatusType;
uint8_t bOriginator;
} __attribute__((packed));
#pragma pack(pop)
#endif // CONFIG_USBD_AUDIO
#endif // __USB_AUDIO_H

View file

@ -0,0 +1,60 @@
#ifndef __USB_AUDIO_8763_H
#define __USB_AUDIO_8763_H
#include <platform_opts.h>
#ifdef CONFIG_USBD_AUDIO
#define INPUT_TERMINAL_2CH_ID 0x01
#define INPUT_TERMINAL_MIC_ID 0x02
#define OUTPUT_TERMINAL_SPEAKER_ID 0x06
#define OUTPUT_TERMINAL_USB_ID 0x07
#define SELECTOR_UNIT_ID 0x08
#define FEATURE_UNIT_0_ID 0x09
#define FEATURE_UNIT_1_ID 0x0A
#define FEATURE_UNIT_2_ID 0x0D
#define MIXER_UNIT_2_ID 0x0F
#define AUDIO_CONTROL_INTF_NUM 0
#define AUDIO_STREAM_OUT_INTF_NUM 1
#define AUDIO_STREAM_IN_INTF_NUM 2
// 8763 PCM setting
#define BIT_RES_16 16
#define BIT_RES_24 24
#define DEFAULT_BIT_RES BIT_RES_16
#define ICODEC_SR_8K 0
#define ICODEC_SR_16K 1
#define ICODEC_SR_32K 2
#define ICODEC_SR_44K 3
#define ICODEC_SR_48K 4
#define ICODEC_SR_88K 5
#define ICODEC_SR_96K 6
#define ICODEC_SR_192K 7
#define DEFAULT_SR ICODEC_SR_48K
#define CHANNEL_MODE_1CH 0x01
#define CHANNEL_MODE_2CH 0x02
#define DEFAULT_PLAY_CH CHANNEL_MODE_2CH
#define DEFAULT_RECORD_CH CHANNEL_MODE_2CH //CHANNEL_MODE_1CH
typedef struct USB_DSP_STATE_ {
uint8_t usb_ad_state;
uint8_t usb_da_state;
} USB_DSP_STATE;
enum { DSP_STOP, DSP_START};
typedef struct USB_ISOEP_STATE_ {
uint8_t usb_OUTEP_state;
uint8_t usb_INEP_state;
} USB_ISOEP_STATE;
enum {ISOEP_DISABLE, ISOEP_ENABLE};
enum {IDX_DA = 1, IDX_AD = 2};
enum {L_GAIN = 1, R_GAIN = 2};
#endif // CONFIG_USBD_AUDIO
#endif // __USB_AUDIO_8763_H

View file

@ -0,0 +1,27 @@
#ifndef __USB_AUDIO_IF_H
#define __USB_AUDIO_IF_H
#include <platform_opts.h>
#ifdef CONFIG_USBD_AUDIO
#include <stdint.h>
#include <stdbool.h>
typedef struct {
void (* plug)(uint8_t audio_path, uint8_t bit_res, uint8_t sf, uint8_t chann_mode);
void (* unplug)(uint8_t audio_path);
bool (* put_data)(uint8_t *p_data, uint16_t len);
void (* set_gain)(uint8_t lr_chann, uint8_t gain);
bool (* pull_data)(uint8_t *p_data, uint16_t len);
int (* init)(void);
void (* deinit)(void);
} usbd_audio_usr_cb_t;
int usbd_audio_init(usbd_audio_usr_cb_t *cb);
void usbd_audio_deinit(void);
void usbd_audio_stop(void);
#endif // CONFIG_USBD_AUDIO
#endif // __USB_AUDIO_IF_H

View file

@ -0,0 +1,85 @@
/*
* u_uac1.h -- interface to USB gadget "ALSA AUDIO" utilities
*
* Copyright (C) 2008 Bryan Wu <cooloney@kernel.org>
* Copyright (C) 2008 Analog Devices, Inc
*
* Enter bugs at http://blackfin.uclinux.org/
*
* Licensed under the GPL-2 or later.
*/
#ifndef __U_AUDIO_H
#define __U_AUDIO_H
#include <platform_opts.h>
#ifdef CONFIG_USBD_AUDIO
#include "usb_composite.h"
#include "usb_audio_if.h"
#include "usb_audio.h"
#include "ameba_otg.h"
#define UAC1_OUT_EP_MAX_PACKET_SIZE 512
#define UAC1_REQ_COUNT 1
#define UAC1_AUDIO_BUF_SIZE 1024
#define SUPPORT_ISO_MAX_PACKET_SIZE 512 // for 19k2 *2 channel*16 bit
#define UAC1_ISO_OUT_EP_MAX_PACKET_SIZE 576 // must be 576 for 96K + 24-bit, ??? what about P & R ???
#define UAC1_ISO_IN_EP_MAX_PACKET_SIZE 288 // 492, Max Packet, or Play and Record Fail in Win7
#define UAC1_ISO_OUT_EP_MAX_BUFFER_SIZE 576 // 24 -> 32 ( 576 -> 768 )
#define UAC1_ISO_IN_EP_MAX_BUFFER_SIZE 288 // 32 -> 24 ( 384 -> 288 )
/*
* This represents the USB side of an audio card device, managed by a USB
* function which provides control and stream interfaces.
*/
struct gaudio_snd_dev {
struct gaudio *card;
//struct file *filp;
//struct snd_pcm_substream *substream;
int access;
int format;// bbpro: 0: 16bit, 1 : 24bit
int channels;// bbpro:
int rate;// ex 44100
int sample_freq_idx;// bbpro, map to rate
};
struct gaudio {
//struct usb_function func;
struct usb_gadget *gadget;
/* ALSA sound device interfaces */
struct gaudio_snd_dev control;
struct gaudio_snd_dev playback;
struct gaudio_snd_dev capture;
};
struct f_audio {
struct gaudio card;
//bbpro
uint8_t ac_intf;
uint8_t ac_alt;
uint8_t as_out_intf;
uint8_t as_out_alt;
uint8_t as_in_intf;
uint8_t as_in_alt;
/* endpoints handle full and/or high speeds */
struct usb_ep *out_ep;
struct usb_ep *in_ep;
dwc_list_link_t cs;
uint8_t set_cmd;
struct usb_audio_control *set_con;
//bbpro
struct usb_gadget *gadget;
};
#endif // CONFIG_USBD_AUDIO
#endif // __U_AUDIO_H

View file

@ -0,0 +1,228 @@
#ifndef _USBD_CDC_ACM_H_
#define _USBD_CDC_ACM_H_
#include <platform_opts.h>
#ifdef CONFIG_USBD_CDC_ACM
#include <platform/platform_stdlib.h>
#include "usb.h"
#include "usb_gadget.h"
#include "usb_composite.h"
#include "osdep_service.h"
#include "usbd_cdc_acm_if.h"
// Use INT in endpoint
#define USBD_CDC_ACM_USE_INT_IN_ENDPOINT 1
// Use thread for bulk in transfer, turn it on when using usbd_cdc_acm_async_transmit_data API to transfer large data,
// which can not be transfered via single bulk in transfer, i.e. the transfer size is larger than bulk_in_buf_size.
#define USBD_CDC_ACM_USE_BULK_IN_THREAD 1
// Allocate async bulk in buffer, turn it on to release bulk in transfer buffer in user application ASAP.
#define USBD_CDC_ACM_ALLOC_ASYNC_BULK_IN_BUF 0
// Bulk in request number
#define USBD_CDC_ACM_BULK_IN_REQ_NUM 2
// Bulk out request number
#define USBD_CDC_ACM_BULK_OUT_REQ_NUM 1
// Bulk transfer configurations
#define USBD_CDC_ACM_HS_BULK_MAX_PACKET_SIZE 512
#define USBD_CDC_ACM_FS_BULK_MAX_PACKET_SIZE 64
#define USBD_CDC_ACM_HS_BULK_IN_PACKET_SIZE (USBD_CDC_ACM_HS_BULK_MAX_PACKET_SIZE)
#define USBD_CDC_ACM_HS_BULK_OUT_PACKET_SIZE (USBD_CDC_ACM_HS_BULK_MAX_PACKET_SIZE)
#define USBD_CDC_ACM_FS_BULK_IN_PACKET_SIZE (USBD_CDC_ACM_FS_BULK_MAX_PACKET_SIZE)
#define USBD_CDC_ACM_FS_BULK_OUT_PACKET_SIZE (USBD_CDC_ACM_FS_BULK_MAX_PACKET_SIZE)
#define USBD_CDC_ACM_MAX_BULK_IN_XFER_SIZE 65535
#define USBD_CDC_ACM_DEFAULT_BULK_IN_XFER_SIZE 1024 // Shall be <= USBD_CDC_ACM_MAX_BULK_IN_XFER_SIZE, restrict it to save memory
#define USBD_CDC_ACM_DEFAULT_BULK_OUT_XFER_SIZE 1024 // Shall be <= USBD_CDC_ACM_MAX_BULK_IN_XFER_SIZE, restrict it to save memory
// Bulk in task configurations
#define USBD_CDC_ACM_BULK_IN_TASK_PRIORITY (tskIDLE_PRIORITY + 2) // Should be lower than USBD_IRQ_THREAD_PRIORITY
#define USBD_CDC_ACM_BULK_IN_TASK_STACK_SIZE 512
// Endpoint address
#define USBD_CDC_ACM_BULK_IN_EP_ADDRESS 0x81
#define USBD_CDC_ACM_BULK_OUT_EP_ADDRESS 0x02
#define USBD_CDC_ACM_INT_IN_EP_ADDRESS 0x83
// CDC descriptor types
#define USBD_CDC_HEADER_TYPE 0x00
#define USBD_CDC_CALL_MANAGEMENT_TYPE 0x01
#define USBD_CDC_ACM_TYPE 0x02
#define USBD_CDC_UNION_TYPE 0x06
#define USBD_CDC_COUNTRY_TYPE 0x07
#define USBD_CDC_NETWORK_TERMINAL_TYPE 0x0A
#define USBD_CDC_ETHERNET_TYPE 0x0F
#define USBD_CDC_WHCM_TYPE 0x11
#define USBD_CDC_MDLM_TYPE 0x12
#define USBD_CDC_MDLM_DETAIL_TYPE 0x13
#define USBD_CDC_DMM_TYPE 0x14
#define USBD_CDC_OBEX_TYPE 0x15
// CDC subclass
#define USBD_CDC_SUBCLASS_ACM 0x02
#define USBD_CDC_SUBCLASS_ETHERNET 0x06
#define USBD_CDC_SUBCLASS_WHCM 0x08
#define USBD_CDC_SUBCLASS_DMM 0x09
#define USBD_CDC_SUBCLASS_MDLM 0x0A
#define USBD_CDC_SUBCLASS_OBEX 0x0B
// CDC ACM protocol
#define USBD_CDC_ACM_PROTO_NONE 0x00
#define USBD_CDC_ACM_PROTO_AT 0x01
#define USBD_CDC_ACM_PROTO_VENDOR 0xFF
// CDC ACM requests
#define USBD_CDC_SEND_ENCAPSULATED_COMMAND 0x00U
#define USBD_CDC_GET_ENCAPSULATED_RESPONSE 0x01U
#define USBD_CDC_SET_COMM_FEATURE 0x02U
#define USBD_CDC_GET_COMM_FEATURE 0x03U
#define USBD_CDC_CLEAR_COMM_FEATURE 0x04U
#define USBD_CDC_SET_LINE_CODING 0x20U
#define USBD_CDC_GET_LINE_CODING 0x21U
#define USBD_CDC_SET_CONTROL_LINE_STATE 0x22U
#define USBD_CDC_SEND_BREAK 0x23U
// CDC ACM debug options
#define USBD_CDC_ACM_DEBUG 0
#if USBD_CDC_ACM_DEBUG
#define USBD_CDC_INFO(fmt, args...) printf("\n\r[CDC]%s: " fmt, __FUNCTION__, ## args)
#define USBD_CDC_WARN(fmt, args...) printf("\n\r[CDC]%s: " fmt, __FUNCTION__, ## args)
#define USBD_CDC_ERROR(fmt, args...) printf("\n\r[CDC]%s: " fmt, __FUNCTION__, ## args)
#define USBD_CDC_ENTER printf("\n\r[CDC]%s: =>", __FUNCTION__)
#define USBD_CDC_EXIT printf("\n\r[CDC]%s: <=", __FUNCTION__)
#define USBD_CDC_EXIT_ERR printf("\n\r[CDC]%s: ERR <=", __FUNCTION__)
#else
#define USBD_CDC_INFO(fmt, args...)
#define USBD_CDC_WARN(fmt, args...)
#define USBD_CDC_ERROR(fmt, args...) printf("\n\r[CDC]%s: " fmt, __FUNCTION__, ## args)
#define USBD_CDC_ENTER
#define USBD_CDC_EXIT
#define USBD_CDC_EXIT_ERR
#endif
#pragma pack(push)
#pragma pack(1)
// Header Functional Descriptor
struct usb_cdc_header_desc {
u8 bLength;
u8 bDescriptorType;
u8 bDescriptorSubType;
u16 bcdCDC;
} __attribute__((packed));
#define USBD_CDC_DT_HEADER_SIZE 5
// Call Management Descriptor
struct usb_cdc_call_mgmt_descriptor {
u8 bLength;
u8 bDescriptorType;
u8 bDescriptorSubType;
u8 bmCapabilities;
#define USB_CDC_CALL_MGMT_CAP_CALL_MGMT 0x01
#define USB_CDC_CALL_MGMT_CAP_DATA_INTF 0x02
u8 bDataInterface;
} __attribute__((packed));
#define USBD_CDC_DT_CALL_MGMT_SIZE 5
// Abstract Control Management Descriptor
struct usb_cdc_acm_descriptor {
u8 bLength;
u8 bDescriptorType;
u8 bDescriptorSubType;
u8 bmCapabilities;
} __attribute__((packed));
#define USBD_CDC_DT_ACM_SIZE 4
// Union Functional Descriptor
struct usb_cdc_union_desc {
u8 bLength;
u8 bDescriptorType;
u8 bDescriptorSubType;
u8 bControlInterface;
u8 bSubordinateInterface0;
} __attribute__((packed));
#define USBD_CDC_DT_UNION_SIZE 5
typedef struct {
u32 dwDTERate;
u8 bCharFormat;
u8 bParityType;
u8 bDataBits;
} __attribute__((packed)) usbd_cdc_acm_line_coding_t;
#define USBD_CDC_ACM_LINE_CODING_SIZE 7
#define USBD_CDC_ACM_CHAR_FORMAT_STOP_1 0
#define USBD_CDC_ACM_CHAR_FORMAT_STOP_1_5 1
#define USBD_CDC_ACM_CHAR_FORMAT_STOP_2 2
#define USBD_CDC_ACM_PARITY_TYPE_NONE 0
#define USBD_CDC_ACM_PARITY_TYPE_ODD 1
#define USBD_CDC_ACM_PARITY_TYPE_EVEN 2
#define USBD_CDC_ACM_PARITY_TYPE_MARK 3
#define USBD_CDC_ACM_PARITY_TYPE_SPACE 4
#define USBD_CDC_ACM_DATA_BIT_5 5
#define USBD_CDC_ACM_DATA_BIT_6 6
#define USBD_CDC_ACM_DATA_BIT_7 7
#define USBD_CDC_ACM_DATA_BIT_8 8
#define USBD_CDC_ACM_DATA_BIT_16 16
typedef union {
u16 d16;
struct {
unsigned present:1;
unsigned activate:1;
unsigned reserved_2_15:14;
} b;
} __attribute__((packed)) usbd_cdc_acm_ctrl_line_state_t;
#pragma pack(pop)
struct usb_cdc_dev_t {
u8 interface_number;
struct usb_gadget *gadget;
struct usb_ep *bulk_out_ep;
_list bulk_out_req_list;
u16 bulk_out_req_num;
volatile u16 bulk_out_req_act_num;
u16 bulk_out_buf_size;
_mutex bulk_out_mutex;
struct usb_ep *bulk_in_ep;
_list bulk_in_req_list;
u16 bulk_in_req_num;
volatile u16 bulk_in_req_act_num;
u16 bulk_in_buf_size;
_mutex bulk_in_mutex;
volatile int bulk_in_busy;
#if USBD_CDC_ACM_USE_BULK_IN_THREAD
struct task_struct bulk_in_task;
#endif
usbd_cdc_acm_usr_cb_t *cb;
};
#endif // CONFIG_USBD_CDC_ACM
#endif // _USBD_CDC_ACM_H_

View file

@ -0,0 +1,24 @@
#ifndef _USBD_CDC_ACM_IF_H_
#define _USBD_CDC_ACM_IF_H_
#include <platform_opts.h>
#ifdef CONFIG_USBD_CDC_ACM
typedef struct {
int(* init)(void);
int(* deinit)(void);
int(* receive)(void *buf, u16 length);
void(*transmit_complete)(int status);
} usbd_cdc_acm_usr_cb_t;
int usbd_cdc_acm_sync_transmit_data(void *buf, u16 length);
int usbd_cdc_acm_async_transmit_data(void *buf, u32 length);
int usbd_cdc_acm_init(u16 bulk_in_buf_size, u16 bulk_out_buf_size, usbd_cdc_acm_usr_cb_t *cb);
void usbd_cdc_acm_deinit(void);
#endif // CONFIG_USBD_CDC_ACM
#endif // _USBD_CDC_ACM_IF_H_

View file

@ -0,0 +1,208 @@
#ifndef USBD_MSC_H
#define USBD_MSC_H
#include <platform_opts.h>
#ifdef CONFIG_USBD_MSC
#include <platform/platform_stdlib.h>
#include "usb.h"
#include "usb_composite.h"
#include "osdep_service.h"
#include "sd.h"
/* MSC configurations */
#define USBD_MSC_RAM_DISK 0 /* Use RAM as storage media, for test purpose only */
/* MSC Request Codes */
#define USBD_MSC_REQUEST_RESET 0xFF
#define USBD_MSC_REQUEST_GET_MAX_LUN 0xFE
#define USBD_MSC_MAX_LUN 1
#define USBD_MSC_MAX_SCSI_CMD_SIZE 16
#define USBD_MSC_BLK_BITS 9
#define USBD_MSC_BLK_SIZE (1 << USBD_MSC_BLK_BITS)
/* MSC Sub Classes */
#define USBD_MSC_SC_RBC 1 /* Typically, flash devices */
#define USBD_MSC_SC_8020 2 /* CD-ROM */
#define USBD_MSC_SC_QIC 3 /* QIC-157 Tapes */
#define USBD_MSC_SC_UFI 4 /* Floppy */
#define USBD_MSC_SC_8070 5 /* Removable media */
#define USBD_MSC_SC_SCSI 6 /* Transparent */
/* MSC Protocols */
#define USBD_MSC_PR_CB 1 /* Control/Bulk w/o interrupt */
#define USBD_MSC_PR_CBI 0 /* Control/Bulk/Interrupt */
#define USBD_MSC_PR_BULK 0x50 /* bulk only */
#define USBD_MSC_BULK_OUT_EP_ADDRESS 0x02
#define USBD_MSC_BULK_IN_EP_ADDRESS 0x81
/* MSC thread priority*/
#define USBD_MSC_BULK_CMD_THREAD_PRIORITY (tskIDLE_PRIORITY + 3) // Should be lower than USBD_IRQ_THREAD_PRIORITY
/* MSC device buffer configuration */
#define USBD_MSC_NBR_BUFHD 2 /* Number of buffer header for bulk in/out data */
#define USBD_MSC_BUFLEN (32*512) /* Default size of buffer length */
/* MSC tasks stack size */
#define USBD_MSC_BULK_CMD_TASK_STACK_SIZE 512
#define USBD_MSC_BULK_DATA_TASK_STACK_SIZE 512
#define USBD_MSC_HALT_ERROR_TOLERANCE 20
/* RAM disk configurations */
#if USBD_MSC_RAM_DISK
#define USBD_MSC_RAM_DISK_SIZE (USBD_MSC_BUFLEN * 2) // Should be >= 32KB
#define USBD_MSC_RAM_DISK_SECTORS (USBD_MSC_RAM_DISK_SIZE >> USBD_MSC_BLK_BITS)
#endif
/* Debug options */
#define USBD_MSC_DEBUG 0
#if USBD_MSC_DEBUG
#define USBD_MSC_INFO(fmt, args...) printf("\n\r[MSC]%s: " fmt, __FUNCTION__, ## args)
#define USBD_MSC_WARN(fmt, args...) printf("\n\r[MSC]%s: " fmt, __FUNCTION__, ## args)
#define USBD_MSC_ERROR(fmt, args...) printf("\n\r[MSC]%s: " fmt, __FUNCTION__, ## args)
#define USBD_MSC_ENTER printf("\n\r[MSC]%s: =>", __FUNCTION__)
#define USBD_MSC_EXIT printf("\n\r[MSC]%s: <=", __FUNCTION__)
#define USBD_MSC_EXIT_ERR printf("\n\r[MSC]%s: ERR <=", __FUNCTION__)
#else
#define USBD_MSC_INFO(fmt, args...)
#define USBD_MSC_WARN(fmt, args...)
#define USBD_MSC_ERROR(fmt, args...)
#define USBD_MSC_ENTER
#define USBD_MSC_EXIT
#define USBD_MSC_EXIT_ERR
#endif
enum data_direction {
DATA_DIR_UNKNOWN = 0,
DATA_DIR_FROM_HOST,
DATA_DIR_TO_HOST,
DATA_DIR_NONE
};
//structure predefine
struct usb_msc_dev_t;
struct usb_msc_bufhd_t;
struct usb_msc_opts_t {
SD_RESULT(*disk_init)(void);
SD_RESULT(*disk_deinit)(void);
SD_RESULT(*disk_getcapacity)(u32 *sectors);
SD_RESULT(*disk_read)(u32 sector, u8 *buffer, u32 count);
SD_RESULT(*disk_write)(u32 sector, const u8 *buffer, u32 count);
};
struct usb_msc_lun_t {
unsigned int initially_ro: 1;
unsigned int ro: 1;
unsigned int removable: 1;
unsigned int cdrom: 1;
unsigned int prevent_medium_removal: 1;
unsigned int registered: 1;
unsigned int info_valid: 1;
unsigned int nofua: 1;
u32 sense_data;
u32 sense_data_info;
u32 unit_attention_data;
unsigned int num_sectors;
unsigned int blkbits; /* bits of logical block size of bound block device */
unsigned int blksize; /* logical block size of bound block device */
const char *name;
unsigned int lba; /* current read and write logical block address */
u8 is_open;
_mutex lun_mutex;
struct usb_msc_opts_t *lun_opts;
};
struct usb_msc_common_t {
struct usb_msc_dev_t *mscdev;
struct usb_msc_lun_t **luns;
struct usb_msc_lun_t *curlun;
struct usb_gadget *gadget;
/* scsi cbw relevant */
enum data_direction data_dir;
u32 data_size;
u32 data_size_from_cmnd;
u32 tag;
u32 residue;
u8 scsi_cmnd[USBD_MSC_MAX_SCSI_CMD_SIZE];
u8 cmnd_size;
u8 lun; /* current lun*/
u8 nluns;
u8 nbufhd; /* number of buffer header */
u8 nbufhd_a;
_list bufhd_pool;
_mutex bufhd_mutex;
/* bulk out cmd*/
_list boc_list;
_mutex boc_mutex;
/* bolk out data*/
_mutex bod_mutex;
_list bod_list;
struct usb_msc_bufhd_t *curbh; // current buffer header
struct usb_msc_bufhd_t *cbw_bh; // buffer header for CBW
struct usb_msc_bufhd_t *csw_bh; // buffer header for CSW
unsigned int can_stall: 1;
unsigned int phase_error: 1;
unsigned int short_packet_received: 1;
unsigned int bad_lun_okay: 1;
unsigned int running: 1;
};
typedef enum _bufhd_type {
BUFHD_CBW = 0,
BUFHD_CSW,
BUFHD_DATA,
} usb_msc_bufhd_type;
struct usb_msc_bufhd_t {
u8 *prebuf;
u8 *buf;
int buf_size;
usb_msc_bufhd_type type;
_list list;
struct usb_request *reqin; /* for bulkin responses */
struct usb_request *reqout;
};
struct usb_msc_dev_t {
struct usb_msc_common_t *common;
u16 interface_number;
struct usb_ep *in_ep;
struct usb_ep *out_ep;
unsigned int bulk_in_enabled: 1;
unsigned int bulk_out_enabled: 1;
struct task_struct bulk_out_cmd_task;
};
int usbd_msc_lun_read(struct usb_msc_lun_t *curlun, u32 sector, u8 *buffer, u32 count);
int usbd_msc_lun_write(struct usb_msc_lun_t *curlun, u32 sector, const u8 *buffer, u32 count);
int usbd_msc_halt_bulk_in_endpoint(struct usb_msc_dev_t *mscdev);
void usbd_msc_put_bufhd(struct usb_msc_common_t *common, struct usb_msc_bufhd_t *bufhd);
struct usb_msc_bufhd_t *usbd_msc_get_bufhd(struct usb_msc_common_t *common);
int usbd_msc_bulk_in_transfer(struct usb_msc_dev_t *mscdev, struct usb_request *req);
int usbd_msc_bulk_out_transfer(struct usb_msc_dev_t *mscdev, struct usb_request *req);
#endif // CONFIG_USBD_MSC
#endif // USBD_MSC_H

View file

@ -0,0 +1,16 @@
#ifndef USBD_MSC_IF_H
#define USBD_MSC_IF_H
#include <platform_opts.h>
#ifdef CONFIG_USBD_MSC
#include <stdint.h>
//int usbd_msc_register(void);
int usbd_msc_init(void);
void usbd_msc_deinit(void);
#endif // CONFIG_USBD_MSC
#endif // USBD_MSC_H

View file

@ -0,0 +1,110 @@
#ifndef USBD_SCSI_H
#define USBD_SCSI_H
#include <platform_opts.h>
#ifdef CONFIG_USBD_MSC
#include "basic_types.h"
#include "usbd_msc.h"
/* SCSI Commands */
#define SCSI_FORMAT_UNIT 0x04
#define SCSI_INQUIRY 0x12
#define SCSI_MODE_SELECT6 0x15
#define SCSI_MODE_SELECT10 0x55
#define SCSI_MODE_SENSE6 0x1A
#define SCSI_MODE_SENSE10 0x5A
#define SCSI_ALLOW_MEDIUM_REMOVAL 0x1E
#define SCSI_READ6 0x08
#define SCSI_READ10 0x28
#define SCSI_READ12 0xA8
#define SCSI_READ16 0x88
#define SCSI_READ_CAPACITY10 0x25
#define SCSI_READ_CAPACITY16 0x9E
#define SCSI_SYNCHRONIZE_CACHE 0x35
#define SCSI_REQUEST_SENSE 0x03
#define SCSI_START_STOP_UNIT 0x1B
#define SCSI_TEST_UNIT_READY 0x00
#define SCSI_WRITE6 0x0A
#define SCSI_WRITE10 0x2A
#define SCSI_WRITE12 0xAA
#define SCSI_WRITE16 0x8A
#define SCSI_VERIFY10 0x2F
#define SCSI_VERIFY12 0xAF
#define SCSI_VERIFY16 0x8F
#define SCSI_SEND_DIAGNOSTIC 0x1D
#define SCSI_READ_FORMAT_CAPACITIES 0x23
#define READ_FORMAT_CAPACITY_DATA_LEN 0x0C
#define READ_CAPACITY10_DATA_LEN 0x08
#define MODE_SENSE10_DATA_LEN 0x08
#define MODE_SENSE6_DATA_LEN 0x04
#define REQUEST_SENSE_DATA_LEN 0x12
#define STANDARD_INQUIRY_DATA_LEN 0x24
/* SCSI Sense Key/Additional Sense Code/ASC Qualifier values */
#define SS_NO_SENSE 0
#define SS_COMMUNICATION_FAILURE 0x040800
#define SS_INVALID_COMMAND 0x052000
#define SS_INVALID_FIELD_IN_CDB 0x052400
#define SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE 0x052100
#define SS_LOGICAL_UNIT_NOT_SUPPORTED 0x052500
#define SS_MEDIUM_NOT_PRESENT 0x023a00
#define SS_MEDIUM_REMOVAL_PREVENTED 0x055302
#define SS_NOT_READY_TO_READY_TRANSITION 0x062800
#define SS_RESET_OCCURRED 0x062900
#define SS_SAVING_PARAMETERS_NOT_SUPPORTED 0x053900
#define SS_UNRECOVERED_READ_ERROR 0x031100
#define SS_WRITE_ERROR 0x030c02
#define SS_WRITE_PROTECTED 0x072700
#define SK(x) ((u8) ((x) >> 16)) /* Sense Key byte, etc. */
#define ASC(x) ((u8) ((x) >> 8))
#define ASCQ(x) ((u8) (x))
/*
* Bulk only data structures
*/
/* command block wrapper */
struct bulk_cb_wrap {
unsigned int Signature; /* contains 'USBC', denote bulk_cb_wrap */
unsigned int Tag; /* unique per command id */
unsigned int DataTransferLength; /* size of data for transfer */
unsigned char Flags; /* data transfer direction */
unsigned char Lun; /* LUN normally 0, (which command block is sent) */
unsigned char Length; /* length of the CDB */
unsigned char CDB[USBD_MSC_MAX_SCSI_CMD_SIZE]; /* max command */
};
#define US_BULK_CB_WRAP_LEN 31
#define US_BULK_CB_SIGN 0x43425355 /*spells out USBC */
#define US_BULK_FLAG_IN (1 << 7)
#define US_BULK_FLAG_OUT 0
/* command status wrapper */
struct bulk_cs_wrap {
unsigned int Signature; /* should = 'USBS' */
unsigned int Tag; /* same as original command, echoed by the device as received */
unsigned int Residue; /* amount not transferred */
unsigned char Status; /* execute command status */
};
#define US_BULK_CS_WRAP_LEN 13
#define US_BULK_CS_SIGN 0x53425355 /* spells out 'USBS' */
// execute command status
#define US_BULK_STAT_OK 0
#define US_BULK_STAT_FAIL 1
#define US_BULK_STAT_PHASE 2
int usbd_msc_receive_cbw(struct usb_msc_dev_t *mscdev, struct usb_request *req);
#endif // CONFIG_USBD_MSC
#endif // USBD_SCSI_H

View file

@ -0,0 +1,91 @@
#ifndef USBD_VENDOR_H
#define USBD_VENDOR_H
#include <platform_opts.h>
#ifdef CONFIG_USBD_VENDOR
#include "usb.h"
#include "usb_composite.h"
// Test options
#define CONFIG_USBD_VENDOR_ISO_IN_TEST 1
#define CONFIG_USBD_VENDOR_ISO_OUT_TEST 1
#define CONFIG_USBD_VENDOR_ISO_INOUT_TEST 0
#define CONFIG_USBD_VENDOR_BULK_INOUT_TEST 0
#define CONFIG_USBD_VENDOR_ISO_IN_REQ_ASAP 1
#define CONFIG_USBD_VENDOR_ISO_OUT_REQ_ASAP 0
#define CONFIG_USBD_VENDOR_ISO_DBG_TIMER 1
#define CONFIG_USBD_VENDOR_ISO_DBG_GPIO 0
#define USBD_VENDOR_ISO_REQ_NUM 2
#define USBD_VENDOR_ISO_OUT_XFER_CNT 100
#define USBD_VENDOR_ISO_IN_CNT 512
/* Debug options */
#define USBD_VENDOR_DEBUG 0
#define USBD_VENDOR_STR "VS"
#if USBD_VENDOR_DEBUG
#define USBD_VENDOR_INFO(fmt, args...) printf("\n\r[%s]%s: " fmt, USBD_VENDOR_STR, __FUNCTION__, ## args)
#define USBD_VENDOR_WARN(fmt, args...) printf("\n\r[%s]%s: " fmt, USBD_VENDOR_STR, __FUNCTION__, ## args)
#define USBD_VENDOR_ERROR(fmt, args...) printf("\n\r[%s]%s: " fmt, USBD_VENDOR_STR, __FUNCTION__, ## args)
#define USBD_VENDOR_ENTER printf("\n\r[%s]%s: =>", USBD_VENDOR_STR, __FUNCTION__)
#define USBD_VENDOR_EXIT printf("\n\r[%s]%s: <=", USBD_VENDOR_STR, __FUNCTION__)
#define USBD_VENDOR_EXIT_ERR printf("\n\r[%s]%s: ERR <=", USBD_VENDOR_STR, __FUNCTION__)
#else
#define USBD_VENDOR_INFO(fmt, args...)
#define USBD_VENDOR_WARN(fmt, args...)
#define USBD_VENDOR_ERROR(fmt, args...) printf("\n\r[%s]%s: " fmt, USBD_VENDOR_STR, __FUNCTION__, ## args)
#define USBD_VENDOR_ENTER
#define USBD_VENDOR_EXIT
#define USBD_VENDOR_EXIT_ERR
#endif
struct usb_vendor_common_t;
struct usb_vendor_device_t;
struct usb_vendor_common_t {
struct usb_vendor_device_t *vendev;
struct usb_gadget *gadget;
struct usb_ep *ep0;
struct usb_request *req0;
};
struct usb_vendor_device_t {
struct usb_vendor_common_t *common;
struct usb_function func;
struct usb_ep *bulk_in_ep;
struct usb_ep *bulk_out_ep;
struct usb_ep *iso_in_ep;
struct usb_ep *iso_out_ep;
struct usb_iso_request *iso_out_req;
u8 *iso_out_req_buf[USBD_VENDOR_ISO_REQ_NUM];
struct usb_iso_request *iso_in_req;
u8 *iso_in_req_buf[USBD_VENDOR_ISO_REQ_NUM];
};
typedef struct {
u8 pos;
u8 data;
} usb_vendor_iso_out_record_t;
extern struct usb_gadget_strings *vendor_gadget_strings[];
extern struct usb_device_descriptor vendor_device_desc;
extern struct usb_config_descriptor vendor_config_desc;
extern struct usb_interface_descriptor vendor_intf0_desc;
extern struct usb_interface_descriptor vendor_intf1_desc;
extern struct usb_endpoint_descriptor vendor_bulk_source_desc_FS;
extern struct usb_endpoint_descriptor vendor_bulk_sink_desc_FS;
extern struct usb_endpoint_descriptor vendor_bulk_source_desc_HS;
extern struct usb_endpoint_descriptor vendor_bulk_sink_desc_HS;
extern struct usb_endpoint_descriptor vendor_iso_source_desc_FS;
extern struct usb_endpoint_descriptor vendor_iso_sink_desc_FS;
extern struct usb_endpoint_descriptor vendor_iso_source_desc_HS;
extern struct usb_endpoint_descriptor vendor_iso_sink_desc_HS;
extern struct usb_descriptor_header *vendor_descriptors_FS[];
extern struct usb_descriptor_header *vendor_descriptors_HS[];
#endif // CONFIG_USBD_VENDOR
#endif // USBD_VENDOR_H

View file

@ -0,0 +1,14 @@
#ifndef USBD_VENDOR_IF_H
#define USBD_VENDOR_IF_H
#include <platform_opts.h>
#ifdef CONFIG_USBD_VENDOR
#include "usb.h"
int usbd_vendor_init(void);
void usbd_vendor_deinit(void);
#endif // CONFIG_USBD_VENDOR
#endif // USBD_VENDOR_IF_H

View file

@ -0,0 +1,40 @@
/*
* This file holds the definitions of quirks found in USB devices.
* Only quirks that affect the whole device, not an interface,
* belong here.
*/
#ifndef __QUIRKS_H
#define __QUIRKS_H
#include <platform_opts.h>
#ifdef CONFIG_USBH_MSC
/* string descriptors must not be fetched using a 255-byte read */
#define USB_QUIRK_STRING_FETCH_255 0x00000001
/* device can't resume correctly so reset it instead */
#define USB_QUIRK_RESET_RESUME 0x00000002
/* device can't handle Set-Interface requests */
#define USB_QUIRK_NO_SET_INTF 0x00000004
/* device can't handle its Configuration or Interface strings */
#define USB_QUIRK_CONFIG_INTF_STRINGS 0x00000008
/* device can't be reset(e.g morph devices), don't use reset */
#define USB_QUIRK_RESET 0x00000010
/* device has more interface descriptions than the bNumInterfaces count,
and can't handle talking to these interfaces */
#define USB_QUIRK_HONOR_BNUMINTERFACES 0x00000020
/* device needs a pause during initialization, after we read the device
descriptor */
#define USB_QUIRK_DELAY_INIT 0x00000040
#endif // CONFIG_USBH_MSC
#endif // __QUIRKS_H

View file

@ -0,0 +1,28 @@
#ifndef _SCATTERLIST_H
#define _SCATTERLIST_H
#include <platform_opts.h>
#ifdef CONFIG_USBH_MSC
struct scatterlist {
unsigned long sg_magic;
unsigned long page_link;
unsigned int offset;
unsigned int length;
dma_addr_t dma_address;
__u32 dma_length;
};
struct sg_table {
struct scatterlist *sgl; /* the list */
unsigned int nents; /* number of mapped entries */
unsigned int orig_nents; /* original size of list */
};
#endif // CONFIG_USBH_MSC
#endif // _SCATTERLIST_H

View file

@ -0,0 +1,18 @@
#ifndef _DMA_DIRECTION_H
#define _DMA_DIRECTION_H
#include <platform_opts.h>
#ifdef CONFIG_USBH_MSC
enum dma_data_direction {
DMA_BIDIRECTIONAL = 0,
DMA_TO_DEVICE = 1,
DMA_FROM_DEVICE = 2,
DMA_NONE = 3,
};
#endif // CONFIG_USBH_MSC
#endif // _DMA_DIRECTION_H

View file

@ -0,0 +1,578 @@
/*
* This header file contains public constants and structures used by
* the scsi code for linux.
*
* For documentation on the OPCODES, MESSAGES, and SENSE values,
* please consult the SCSI standard.
*/
#ifndef _SCSI_SCSI_H
#define _SCSI_SCSI_H
#include <platform_opts.h>
#ifdef CONFIG_USBH_MSC
#include "us_os_wrap_via_osdep_api.h"
#define SCSI_HZ 1024
struct scsi_cmnd;
enum scsi_timeouts {
SCSI_DEFAULT_EH_TIMEOUT = 10 * SCSI_HZ,
};
/*
* The maximum number of SG segments that we will put inside a
* scatterlist (unless chaining is used). Should ideally fit inside a
* single page, to avoid a higher order allocation. We could define this
* to SG_MAX_SINGLE_ALLOC to pack correctly at the highest order. The
* minimum value is 32
*/
#define SCSI_MAX_SG_SEGMENTS 128
/*
* Like SCSI_MAX_SG_SEGMENTS, but for archs that have sg chaining. This limit
* is totally arbitrary, a setting of 2048 will get you at least 8mb ios.
*/
#ifdef ARCH_HAS_SG_CHAIN
#define SCSI_MAX_SG_CHAIN_SEGMENTS 2048
#else
#define SCSI_MAX_SG_CHAIN_SEGMENTS SCSI_MAX_SG_SEGMENTS
#endif
/*
* DIX-capable adapters effectively support infinite chaining for the
* protection information scatterlist
*/
#define SCSI_MAX_PROT_SG_SEGMENTS 0xFFFF
/*
* Special value for scanning to specify scanning or rescanning of all
* possible channels, (target) ids, or luns on a given shost.
*/
#define SCAN_WILD_CARD ~0
/*
* SCSI opcodes
*/
#define TEST_UNIT_READY 0x00
#define REZERO_UNIT 0x01
#define REQUEST_SENSE 0x03
#define FORMAT_UNIT 0x04
#define READ_BLOCK_LIMITS 0x05
#define REASSIGN_BLOCKS 0x07
#define INITIALIZE_ELEMENT_STATUS 0x07
#define READ_6 0x08
#define WRITE_6 0x0a
#define SEEK_6 0x0b
#define READ_REVERSE 0x0f
#define WRITE_FILEMARKS 0x10
#define SPACE 0x11
#define INQUIRY 0x12
#define RECOVER_BUFFERED_DATA 0x14
#define MODE_SELECT 0x15
#define RESERVE 0x16
#define RELEASE 0x17
#define COPY 0x18
#define ERASE 0x19
#define MODE_SENSE 0x1a
#define START_STOP 0x1b
#define RECEIVE_DIAGNOSTIC 0x1c
#define SEND_DIAGNOSTIC 0x1d
#define ALLOW_MEDIUM_REMOVAL 0x1e
#define READ_FORMAT_CAPACITIES 0x23
#define SET_WINDOW 0x24
#define READ_CAPACITY 0x25
#define READ_10 0x28
#define WRITE_10 0x2a
#define SEEK_10 0x2b
#define POSITION_TO_ELEMENT 0x2b
#define WRITE_VERIFY 0x2e
#define VERIFY 0x2f
#define SEARCH_HIGH 0x30
#define SEARCH_EQUAL 0x31
#define SEARCH_LOW 0x32
#define SET_LIMITS 0x33
#define PRE_FETCH 0x34
#define READ_POSITION 0x34
#define SYNCHRONIZE_CACHE 0x35
#define LOCK_UNLOCK_CACHE 0x36
#define READ_DEFECT_DATA 0x37
#define MEDIUM_SCAN 0x38
#define COMPARE 0x39
#define COPY_VERIFY 0x3a
#define WRITE_BUFFER 0x3b
#define READ_BUFFER 0x3c
#define UPDATE_BLOCK 0x3d
#define READ_LONG 0x3e
#define WRITE_LONG 0x3f
#define CHANGE_DEFINITION 0x40
#define WRITE_SAME 0x41
#define UNMAP 0x42
#define READ_TOC 0x43
#define READ_HEADER 0x44
#define GET_EVENT_STATUS_NOTIFICATION 0x4a
#define LOG_SELECT 0x4c
#define LOG_SENSE 0x4d
#define XDWRITEREAD_10 0x53
#define MODE_SELECT_10 0x55
#define RESERVE_10 0x56
#define RELEASE_10 0x57
#define MODE_SENSE_10 0x5a
#define PERSISTENT_RESERVE_IN 0x5e
#define PERSISTENT_RESERVE_OUT 0x5f
#define VARIABLE_LENGTH_CMD 0x7f
#define REPORT_LUNS 0xa0
#define SECURITY_PROTOCOL_IN 0xa2
#define MAINTENANCE_IN 0xa3
#define MAINTENANCE_OUT 0xa4
#define MOVE_MEDIUM 0xa5
#define EXCHANGE_MEDIUM 0xa6
#define READ_12 0xa8
#define WRITE_12 0xaa
#define READ_MEDIA_SERIAL_NUMBER 0xab
#define WRITE_VERIFY_12 0xae
#define VERIFY_12 0xaf
#define SEARCH_HIGH_12 0xb0
#define SEARCH_EQUAL_12 0xb1
#define SEARCH_LOW_12 0xb2
#define SECURITY_PROTOCOL_OUT 0xb5
#define READ_ELEMENT_STATUS 0xb8
#define SEND_VOLUME_TAG 0xb6
#define WRITE_LONG_2 0xea
#define EXTENDED_COPY 0x83
#define RECEIVE_COPY_RESULTS 0x84
#define ACCESS_CONTROL_IN 0x86
#define ACCESS_CONTROL_OUT 0x87
#define READ_16 0x88
#define COMPARE_AND_WRITE 0x89
#define WRITE_16 0x8a
#define READ_ATTRIBUTE 0x8c
#define WRITE_ATTRIBUTE 0x8d
#define VERIFY_16 0x8f
#define SYNCHRONIZE_CACHE_16 0x91
#define WRITE_SAME_16 0x93
#define SERVICE_ACTION_IN 0x9e
/* values for service action in */
#define SAI_READ_CAPACITY_16 0x10
#define SAI_GET_LBA_STATUS 0x12
#define SAI_REPORT_REFERRALS 0x13
/* values for VARIABLE_LENGTH_CMD service action codes
* see spc4r17 Section D.3.5, table D.7 and D.8 */
#define VLC_SA_RECEIVE_CREDENTIAL 0x1800
/* values for maintenance in */
#define MI_REPORT_IDENTIFYING_INFORMATION 0x05
#define MI_REPORT_TARGET_PGS 0x0a
#define MI_REPORT_ALIASES 0x0b
#define MI_REPORT_SUPPORTED_OPERATION_CODES 0x0c
#define MI_REPORT_SUPPORTED_TASK_MANAGEMENT_FUNCTIONS 0x0d
#define MI_REPORT_PRIORITY 0x0e
#define MI_REPORT_TIMESTAMP 0x0f
#define MI_MANAGEMENT_PROTOCOL_IN 0x10
/* value for MI_REPORT_TARGET_PGS ext header */
#define MI_EXT_HDR_PARAM_FMT 0x20
/* values for maintenance out */
#define MO_SET_IDENTIFYING_INFORMATION 0x06
#define MO_SET_TARGET_PGS 0x0a
#define MO_CHANGE_ALIASES 0x0b
#define MO_SET_PRIORITY 0x0e
#define MO_SET_TIMESTAMP 0x0f
#define MO_MANAGEMENT_PROTOCOL_OUT 0x10
/* values for variable length command */
#define XDREAD_32 0x03
#define XDWRITE_32 0x04
#define XPWRITE_32 0x06
#define XDWRITEREAD_32 0x07
#define READ_32 0x09
#define VERIFY_32 0x0a
#define WRITE_32 0x0b
#define WRITE_SAME_32 0x0d
/* Values for T10/04-262r7 */
#define ATA_16 0x85 /* 16-byte pass-thru */
#define ATA_12 0xa1 /* 12-byte pass-thru */
/*
* SCSI command lengths
*/
#define SCSI_MAX_VARLEN_CDB_SIZE 260
/* defined in T10 SCSI Primary Commands-2 (SPC2) */
struct scsi_varlen_cdb_hdr {
__u8 opcode; /* opcode always == VARIABLE_LENGTH_CMD */
__u8 control;
__u8 misc[5];
__u8 additional_cdb_length; /* total cdb length - 8 */
__be16 service_action;
/* service specific data follows */
};
static inline unsigned
scsi_varlen_cdb_length(const void *hdr)
{
return ((struct scsi_varlen_cdb_hdr *)hdr)->additional_cdb_length + 8;
}
extern const unsigned char scsi_command_size_tbl[8];
#define COMMAND_SIZE(opcode) scsi_command_size_tbl[((opcode) >> 5) & 7]
static inline unsigned
scsi_command_size(const unsigned char *cmnd)
{
return (cmnd[0] == VARIABLE_LENGTH_CMD) ?
scsi_varlen_cdb_length(cmnd) : COMMAND_SIZE(cmnd[0]);
}
#ifdef CONFIG_ACPI
struct acpi_bus_type;
extern int
scsi_register_acpi_bus_type(struct acpi_bus_type *bus);
extern void
scsi_unregister_acpi_bus_type(struct acpi_bus_type *bus);
#endif
/*
* SCSI Architecture Model (SAM) Status codes. Taken from SAM-3 draft
* T10/1561-D Revision 4 Draft dated 7th November 2002.
*/
#define SAM_STAT_GOOD 0x00
#define SAM_STAT_CHECK_CONDITION 0x02
#define SAM_STAT_CONDITION_MET 0x04
#define SAM_STAT_BUSY 0x08
#define SAM_STAT_INTERMEDIATE 0x10
#define SAM_STAT_INTERMEDIATE_CONDITION_MET 0x14
#define SAM_STAT_RESERVATION_CONFLICT 0x18
#define SAM_STAT_COMMAND_TERMINATED 0x22 /* obsolete in SAM-3 */
#define SAM_STAT_TASK_SET_FULL 0x28
#define SAM_STAT_ACA_ACTIVE 0x30
#define SAM_STAT_TASK_ABORTED 0x40
/** scsi_status_is_good - check the status return.
*
* @status: the status passed up from the driver (including host and
* driver components)
*
* This returns true for known good conditions that may be treated as
* command completed normally
*/
static inline int scsi_status_is_good(int status)
{
/*
* FIXME: bit0 is listed as reserved in SCSI-2, but is
* significant in SCSI-3. For now, we follow the SCSI-2
* behaviour and ignore reserved bits.
*/
status &= 0xfe;
return ((status == SAM_STAT_GOOD) ||
(status == SAM_STAT_INTERMEDIATE) ||
(status == SAM_STAT_INTERMEDIATE_CONDITION_MET) ||
/* FIXME: this is obsolete in SAM-3 */
(status == SAM_STAT_COMMAND_TERMINATED));
}
/*
* Status codes. These are deprecated as they are shifted 1 bit right
* from those found in the SCSI standards. This causes confusion for
* applications that are ported to several OSes. Prefer SAM Status codes
* above.
*/
#define GOOD 0x00
#define CHECK_CONDITION 0x01
#define CONDITION_GOOD 0x02
#define BUSY 0x04
#define INTERMEDIATE_GOOD 0x08
#define INTERMEDIATE_C_GOOD 0x0a
#define RESERVATION_CONFLICT 0x0c
#define COMMAND_TERMINATED 0x11
#define QUEUE_FULL 0x14
#define ACA_ACTIVE 0x18
#define TASK_ABORTED 0x20
#define STATUS_MASK 0xfe
/*
* SENSE KEYS
*/
#define NO_SENSE 0x00
#define RECOVERED_ERROR 0x01
#define NOT_READY 0x02
#define MEDIUM_ERROR 0x03
#define HARDWARE_ERROR 0x04
#define ILLEGAL_REQUEST 0x05
#define UNIT_ATTENTION 0x06
#define DATA_PROTECT 0x07
#define BLANK_CHECK 0x08
#define COPY_ABORTED 0x0a
#define ABORTED_COMMAND 0x0b
#define VOLUME_OVERFLOW 0x0d
#define MISCOMPARE 0x0e
/*
* DEVICE TYPES
* Please keep them in 0x%02x format for $MODALIAS to work
*/
#define TYPE_DISK 0x00
#define TYPE_TAPE 0x01
#define TYPE_PRINTER 0x02
#define TYPE_PROCESSOR 0x03 /* HP scanners use this */
#define TYPE_WORM 0x04 /* Treated as ROM by our system */
#define TYPE_ROM 0x05
#define TYPE_SCANNER 0x06
#define TYPE_MOD 0x07 /* Magneto-optical disk -
* - treated as TYPE_DISK */
#define TYPE_MEDIUM_CHANGER 0x08
#define TYPE_COMM 0x09 /* Communications device */
#define TYPE_RAID 0x0c
#define TYPE_ENCLOSURE 0x0d /* Enclosure Services Device */
#define TYPE_RBC 0x0e
#define TYPE_OSD 0x11
#define TYPE_NO_LUN 0x7f
/* SCSI protocols; these are taken from SPC-3 section 7.5 */
enum scsi_protocol {
SCSI_PROTOCOL_FCP = 0, /* Fibre Channel */
SCSI_PROTOCOL_SPI = 1, /* parallel SCSI */
SCSI_PROTOCOL_SSA = 2, /* Serial Storage Architecture - Obsolete */
SCSI_PROTOCOL_SBP = 3, /* firewire */
SCSI_PROTOCOL_SRP = 4, /* Infiniband RDMA */
SCSI_PROTOCOL_ISCSI = 5,
SCSI_PROTOCOL_SAS = 6,
SCSI_PROTOCOL_ADT = 7, /* Media Changers */
SCSI_PROTOCOL_ATA = 8,
SCSI_PROTOCOL_UNSPEC = 0xf, /* No specific protocol */
};
/* Returns a human-readable name for the device */
extern const char * scsi_device_type(unsigned type);
/*
* standard mode-select header prepended to all mode-select commands
*/
struct ccs_modesel_head {
__u8 _r1; /* reserved */
__u8 medium; /* device-specific medium type */
__u8 _r2; /* reserved */
__u8 block_desc_length; /* block descriptor length */
__u8 density; /* device-specific density code */
__u8 number_blocks_hi; /* number of blocks in this block desc */
__u8 number_blocks_med;
__u8 number_blocks_lo;
__u8 _r3;
__u8 block_length_hi; /* block length for blocks in this desc */
__u8 block_length_med;
__u8 block_length_lo;
};
/*
* ScsiLun: 8 byte LUN.
*/
struct scsi_lun {
__u8 scsi_lun[8];
};
/*
* The Well Known LUNS (SAM-3) in our int representation of a LUN
*/
#define SCSI_W_LUN_BASE 0xc100
#define SCSI_W_LUN_REPORT_LUNS (SCSI_W_LUN_BASE + 1)
#define SCSI_W_LUN_ACCESS_CONTROL (SCSI_W_LUN_BASE + 2)
#define SCSI_W_LUN_TARGET_LOG_PAGE (SCSI_W_LUN_BASE + 3)
static inline int scsi_is_wlun(unsigned int lun)
{
return (lun & 0xff00) == SCSI_W_LUN_BASE;
}
/*
* MESSAGE CODES
*/
#define COMMAND_COMPLETE 0x00
#define EXTENDED_MESSAGE 0x01
#define EXTENDED_MODIFY_DATA_POINTER 0x00
#define EXTENDED_SDTR 0x01
#define EXTENDED_EXTENDED_IDENTIFY 0x02 /* SCSI-I only */
#define EXTENDED_WDTR 0x03
#define EXTENDED_PPR 0x04
#define EXTENDED_MODIFY_BIDI_DATA_PTR 0x05
#define SAVE_POINTERS 0x02
#define RESTORE_POINTERS 0x03
#define DISCONNECT 0x04
#define INITIATOR_ERROR 0x05
#define ABORT_TASK_SET 0x06
#define MESSAGE_REJECT 0x07
#define NOP 0x08
#define MSG_PARITY_ERROR 0x09
#define LINKED_CMD_COMPLETE 0x0a
#define LINKED_FLG_CMD_COMPLETE 0x0b
#define TARGET_RESET 0x0c
#define ABORT_TASK 0x0d
#define CLEAR_TASK_SET 0x0e
#define INITIATE_RECOVERY 0x0f /* SCSI-II only */
#define RELEASE_RECOVERY 0x10 /* SCSI-II only */
#define CLEAR_ACA 0x16
#define LOGICAL_UNIT_RESET 0x17
#define SIMPLE_QUEUE_TAG 0x20
#define HEAD_OF_QUEUE_TAG 0x21
#define ORDERED_QUEUE_TAG 0x22
#define IGNORE_WIDE_RESIDUE 0x23
#define ACA 0x24
#define QAS_REQUEST 0x55
/* Old SCSI2 names, don't use in new code */
#define BUS_DEVICE_RESET TARGET_RESET
#define ABORT ABORT_TASK_SET
/*
* Host byte codes
*/
#define DID_OK 0x00 /* NO error */
#define DID_NO_CONNECT 0x01 /* Couldn't connect before timeout period */
#define DID_BUS_BUSY 0x02 /* BUS stayed busy through time out period */
#define DID_TIME_OUT 0x03 /* TIMED OUT for other reason */
#define DID_BAD_TARGET 0x04 /* BAD target. */
#define DID_ABORT 0x05 /* Told to abort for some other reason */
#define DID_PARITY 0x06 /* Parity error */
#define DID_ERROR 0x07 /* Internal error */
#define DID_RESET 0x08 /* Reset by somebody. */
#define DID_BAD_INTR 0x09 /* Got an interrupt we weren't expecting. */
#define DID_PASSTHROUGH 0x0a /* Force command past mid-layer */
#define DID_SOFT_ERROR 0x0b /* The low level driver just wish a retry */
#define DID_IMM_RETRY 0x0c /* Retry without decrementing retry count */
#define DID_REQUEUE 0x0d /* Requeue command (no immediate retry) also
* without decrementing the retry count */
#define DID_TRANSPORT_DISRUPTED 0x0e /* Transport error disrupted execution
* and the driver blocked the port to
* recover the link. Transport class will
* retry or fail IO */
#define DID_TRANSPORT_FAILFAST 0x0f /* Transport class fastfailed the io */
#define DID_TARGET_FAILURE 0x10 /* Permanent target failure, do not retry on
* other paths */
#define DID_NEXUS_FAILURE 0x11 /* Permanent nexus failure, retry on other
* paths might yield different results */
#define DID_ALLOC_FAILURE 0x12 /* Space allocation on the device failed */
#define DID_MEDIUM_ERROR 0x13 /* Medium error */
#define DRIVER_OK 0x00 /* Driver status */
/*
* These indicate the error that occurred, and what is available.
*/
#define DRIVER_BUSY 0x01
#define DRIVER_SOFT 0x02
#define DRIVER_MEDIA 0x03
#define DRIVER_ERROR 0x04
#define DRIVER_INVALID 0x05
#define DRIVER_TIMEOUT 0x06
#define DRIVER_HARD 0x07
#define DRIVER_SENSE 0x08
/*
* Midlevel queue return values.
*/
#define SCSI_MLQUEUE_HOST_BUSY 0x1055
#define SCSI_MLQUEUE_DEVICE_BUSY 0x1056
#define SCSI_MLQUEUE_EH_RETRY 0x1057
#define SCSI_MLQUEUE_TARGET_BUSY 0x1058
/*
* Use these to separate status msg and our bytes
*
* These are set by:
*
* status byte = set from target device
* msg_byte = return status from host adapter itself.
* host_byte = set by low-level driver to indicate status.
* driver_byte = set by mid-level.
*/
#define status_byte(result) (((result) >> 1) & 0x7f)
#define msg_byte(result) (((result) >> 8) & 0xff)
#define host_byte(result) (((result) >> 16) & 0xff)
#define driver_byte(result) (((result) >> 24) & 0xff)
#define sense_class(sense) (((sense) >> 4) & 0x7)
#define sense_error(sense) ((sense) & 0xf)
#define sense_valid(sense) ((sense) & 0x80)
/*
* default timeouts
*/
#define FORMAT_UNIT_TIMEOUT (2 * 60 * 60 * SCSI_HZ)
#define START_STOP_TIMEOUT (60 * SCSI_HZ)
#define MOVE_MEDIUM_TIMEOUT (5 * 60 * SCSI_HZ)
#define READ_ELEMENT_STATUS_TIMEOUT (5 * 60 * SCSI_HZ)
#define READ_DEFECT_DATA_TIMEOUT (60 * SCSI_HZ )
#define IDENTIFY_BASE 0x80
#define IDENTIFY(can_disconnect, lun) (IDENTIFY_BASE |\
((can_disconnect) ? 0x40 : 0) |\
((lun) & 0x07))
/*
* struct scsi_device::scsi_level values. For SCSI devices other than those
* prior to SCSI-2 (i.e. over 12 years old) this value is (resp[2] + 1)
* where "resp" is a byte array of the response to an INQUIRY. The scsi_level
* variable is visible to the user via sysfs.
*/
#define SCSI_UNKNOWN 0
#define SCSI_1 1
#define SCSI_1_CCS 2
#define SCSI_2 3
#define SCSI_3 4 /* SPC */
#define SCSI_SPC_2 5
#define SCSI_SPC_3 6
/*
* INQ PERIPHERAL QUALIFIERS
*/
#define SCSI_INQ_PQ_CON 0x00
#define SCSI_INQ_PQ_NOT_CON 0x01
#define SCSI_INQ_PQ_NOT_CAP 0x03
/*
* Here are some scsi specific ioctl commands which are sometimes useful.
*
* Note that include/linux/cdrom.h also defines IOCTL 0x5300 - 0x5395
*/
/* Used to obtain PUN and LUN info. Conflicts with CDROMAUDIOBUFSIZ */
#define SCSI_IOCTL_GET_IDLUN 0x5382
/* 0x5383 and 0x5384 were used for SCSI_IOCTL_TAGGED_{ENABLE,DISABLE} */
/* Used to obtain the host number of a device. */
#define SCSI_IOCTL_PROBE_HOST 0x5385
/* Used to obtain the bus number for a device */
#define SCSI_IOCTL_GET_BUS_NUMBER 0x5386
/* Used to obtain the PCI location of a device */
#define SCSI_IOCTL_GET_PCI 0x5387
/* Pull a u32 out of a SCSI message (using BE SCSI conventions) */
static inline __u32 scsi_to_u32(__u8 *ptr)
{
return (ptr[0]<<24) + (ptr[1]<<16) + (ptr[2]<<8) + ptr[3];
}
#endif // CONFIG_USBH_MSC
#endif // _SCSI_SCSI_H

View file

@ -0,0 +1,90 @@
#ifndef __SCSI_CMND_H_
#define __SCSI_CMND_H_
#include <platform_opts.h>
#ifdef CONFIG_USBH_MSC
#include "us_usb.h"
#include "us_os_wrap_via_osdep_api.h"
#include <scsi/scsi.h>
#include <scsi/dma_direction.h>
#include <scatterlist/scatterlist.h>
/**
* define flash block size
*/
#define BLOCK_SIZE 512
struct scsi_data_buffer {
struct sg_table table;
unsigned char *data_buffer; /* Data buffer to store read data */
unsigned length;
int resid;
};
struct scsi_cmnd{
int result; /* Status code from lower level driver */
unsigned int channel,id,lun;
enum dma_data_direction sc_data_direction;
unsigned short cmd_len;
unsigned length;
_sema cmnd_done;
int eh_eflags; /* Used by error handlr */
struct scsi_data_buffer sdb;
unsigned long sector;/* Sector address in LBA */
unsigned int count;/* Number of sectors to read */
void *request_buffer;
/* These elements define the operation we are about to perform */
#define MAX_COMMAND_SIZE 16
unsigned char cmnd[MAX_COMMAND_SIZE];
#define SCSI_SENSE_BUFFERSIZE 96
unsigned char *sense_buffer; /* obtained by REQUEST SENSE
* when CHECK CONDITION is
* received on original command
* (auto-sense) */
/* Low-level done function - can be used by low-level driver to point
* to completion function. Not used by mid/upper level code. */
void (*scsi_done) (struct scsi_cmnd *);
unsigned underflow; /* Return error if less than
this amount is transferred */
};
static inline unsigned scsi_sg_count(struct scsi_cmnd *cmd)
{
return cmd->sdb.table.nents;
}
static inline struct scatterlist *scsi_sglist(struct scsi_cmnd *cmd)
{
return cmd->sdb.table.sgl;
}
static inline void scsi_set_resid(struct scsi_cmnd *cmd, int resid)
{
cmd->sdb.resid = resid;
}
//
static inline int scsi_get_resid(struct scsi_cmnd *cmd)
{
return cmd->sdb.resid;
}
static inline unsigned scsi_bufflen(struct scsi_cmnd *cmd)
{
return cmd->sdb.length;
}
extern int scsi_cmnd_execute(char cmnd, unsigned char * _buff,
unsigned long _sector, unsigned int _count);
#endif // CONFIG_USBH_MSC
#endif // __SCSI_CMND_H_

View file

@ -0,0 +1,64 @@
#ifndef _SCSI_EH_H_
#define _SCSI_EH_H_
#include <platform_opts.h>
#ifdef CONFIG_USBH_MSC
#include "scsi/scsi_cmnd.h"
#include "dma_direction.h"
#define BLK_MAX_CDB 16
/*
* This is a slightly modified SCSI sense "descriptor" format header.
* The addition is to allow the 0x70 and 0x71 response codes. The idea
* is to place the salient data from either "fixed" or "descriptor" sense
* format into one structure to ease application processing.
*
* The original sense buffer should be kept around for those cases
* in which more information is required (e.g. the LBA of a MEDIUM ERROR).
*/
struct scsi_sense_hdr { /* See SPC-3 section 4.5 */
u8 response_code; /* permit: 0x0, 0x70, 0x71, 0x72, 0x73 */
u8 sense_key;
u8 asc;
u8 ascq;
u8 byte4;
u8 byte5;
u8 byte6;
u8 additional_length; /* always 0 for fixed sense format */
};
static inline int scsi_sense_valid(struct scsi_sense_hdr *sshdr)
{
if (!sshdr)
return 0;
return (sshdr->response_code & 0x70) == 0x70;
}
struct scsi_eh_save {
/* saved state */
int result;
enum dma_data_direction data_direction;
unsigned underflow;
unsigned char cmd_len;
// unsigned char prot_op;
unsigned char cmnd[BLK_MAX_CDB];
struct scsi_data_buffer sdb;
// struct request *next_rq;
/* new command support */
unsigned char eh_cmnd[BLK_MAX_CDB];
// struct scatterlist sense_sgl;
};
const u8 * scsi_sense_desc_find(const u8 * sense_buffer, int sb_len,
int desc_type);
void scsi_eh_prep_cmnd(struct scsi_cmnd *scmd, struct scsi_eh_save *ses,
unsigned char *cmnd, int cmnd_size, unsigned sense_bytes);
void scsi_eh_restore_cmnd(struct scsi_cmnd* scmd, struct scsi_eh_save *ses);
int scsi_normalize_sense(const u8 *sense_buffer, int sb_len,
struct scsi_sense_hdr *sshdr);
#endif // CONFIG_USBH_MSC
#endif // _SCSI_EH_H_

View file

@ -0,0 +1,89 @@
#ifndef __STORAGE_H
#define __STORAGE_H
#include <platform_opts.h>
#ifdef CONFIG_USBH_MSC
#include "us_os_wrap_via_osdep_api.h"
/* Storage subclass codes */
#define USB_SC_RBC 0x01 /* Typically, flash devices */
#define USB_SC_8020 0x02 /* CD-ROM */
#define USB_SC_QIC 0x03 /* QIC-157 Tapes */
#define USB_SC_UFI 0x04 /* Floppy */
#define USB_SC_8070 0x05 /* Removable media */
#define USB_SC_SCSI 0x06 /* Transparent */
#define USB_SC_LOCKABLE 0x07 /* Password-protected */
#define USB_SC_ISD200 0xf0 /* ISD200 ATA */
#define USB_SC_CYP_ATACB 0xf1 /* Cypress ATACB */
#define USB_SC_DEVICE 0xff /* Use device's value */
/* Storage protocol codes */
#define USB_PR_CBI 0x00 /* Control/Bulk/Interrupt */
#define USB_PR_CB 0x01 /* Control/Bulk w/o interrupt */
#define USB_PR_BULK 0x50 /* bulk only */
#define USB_PR_UAS 0x62 /* USB Attached SCSI */
#define USB_PR_USBAT 0x80 /* SCM-ATAPI bridge */
#define USB_PR_EUSB_SDDR09 0x81 /* SCM-SCSI bridge for SDDR-09 */
#define USB_PR_SDDR55 0x82 /* SDDR-55 (made up) */
#define USB_PR_DPCM_USB 0xf0 /* Combination CB/SDDR09 */
#define USB_PR_FREECOM 0xf1 /* Freecom */
#define USB_PR_DATAFAB 0xf2 /* Datafab chipsets */
#define USB_PR_JUMPSHOT 0xf3 /* Lexar Jumpshot */
#define USB_PR_ALAUDA 0xf4 /* Alauda chipsets */
#define USB_PR_KARMA 0xf5 /* Rio Karma */
#define USB_PR_DEVICE 0xff /* Use device's value */
/*
* Bulk only data structures
*/
#pragma pack(push)
#pragma pack(1)
/* command block wrapper */
struct bulk_cb_wrap {
__le32 Signature; /* contains 'USBC', denote bulk_cb_wrap */
__u32 Tag; /* unique per command id */
__le32 DataTransferLength; /* size of data for transfer */
__u8 Flags; /* data transfer direction */
__u8 Lun; /* LUN normally 0, (which command block is sent) */
__u8 Length; /* length of the CDB */
__u8 CDB[16]; /* max command */
} __attribute__((packed));
#define US_BULK_CB_WRAP_LEN 31
#define US_BULK_CB_SIGN 0x43425355 /*spells out USBC */
#define US_BULK_FLAG_IN (1 << 7)
#define US_BULK_FLAG_OUT 0
/* command status wrapper */
struct bulk_cs_wrap {
__le32 Signature; /* should = 'USBS' */
__u32 Tag; /* same as original command, echoed by the device as received */
__le32 Residue; /* amount not transferred */
__u8 Status; /* execute command status */
} __attribute__((packed));
#pragma pack(pop)
#define US_BULK_CS_WRAP_LEN 13
#define US_BULK_CS_SIGN 0x53425355 /* spells out 'USBS' */
// execute command status
#define US_BULK_STAT_OK 0
#define US_BULK_STAT_FAIL 1
#define US_BULK_STAT_PHASE 2
/* bulk-only class specific requests */
#define US_BULK_RESET_REQUEST 0xff
#define US_BULK_GET_MAX_LUN 0xfe
#endif // CONFIG_USBH_MSC
#endif // __STORAGE_H

View file

@ -0,0 +1,109 @@
/* Driver for USB Mass Storage compliant devices
* Transport Functions Header File
*
* Current development and maintenance by:
* (c) 1999, 2000 Matthew Dharm (mdharm-usb@one-eyed-alien.net)
*
* This driver is based on the 'USB Mass Storage Class' document. This
* describes in detail the protocol used to communicate with such
* devices. Clearly, the designers had SCSI and ATAPI commands in
* mind when they created this document. The commands are all very
* similar to commands in the SCSI-II and ATAPI specifications.
*
* It is important to note that in a number of cases this class
* exhibits class-specific exemptions from the USB specification.
* Notably the usage of NAK, STALL and ACK differs from the norm, in
* that they are used to communicate wait, failed and OK on commands.
*
* Also, for certain devices, the interrupt endpoint is used to convey
* status of a command.
*
* Please see http://www.one-eyed-alien.net/~mdharm/linux-usb for more
* information about this driver.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef _US_TRANSPORT_H_
#define _US_TRANSPORT_H_
#include <platform_opts.h>
#ifdef CONFIG_USBH_MSC
/*
* usb_stor_bulk_transfer_xxx() return codes, in order of severity
*/
#define USB_STOR_XFER_GOOD 0 /* good transfer */
#define USB_STOR_XFER_SHORT 1 /* transferred less than expected */
#define USB_STOR_XFER_STALLED 2 /* endpoint stalled */
#define USB_STOR_XFER_LONG 3 /* device tried to send too much */
#define USB_STOR_XFER_ERROR 4 /* transfer died in the middle */
/*
* Transport return codes
*/
#define USB_STOR_TRANSPORT_GOOD 0 /* Transport good, command good */
#define USB_STOR_TRANSPORT_FAILED 1 /* Transport good, command failed */
#define USB_STOR_TRANSPORT_NO_SENSE 2 /* Command failed, no auto-sense */
#define USB_STOR_TRANSPORT_ERROR 3 /* Transport bad (i.e. device dead) */
/*
* We used to have USB_STOR_XFER_ABORTED and USB_STOR_TRANSPORT_ABORTED
* return codes. But now the transport and low-level transfer routines
* treat an abort as just another error (-ENOENT for a cancelled URB).
* It is up to the invoke_transport() function to test for aborts and
* distinguish them from genuine communication errors.
*/
/*
* CBI accept device specific command
*/
#define US_CBI_ADSC 0
//extern int usb_stor_CB_transport(struct scsi_cmnd *, struct us_data*);
//extern int usb_stor_CB_reset(struct us_data*);
//
//extern int usb_stor_Bulk_transport(struct scsi_cmnd *, struct us_data*);
//extern int usb_stor_Bulk_max_lun(struct us_data*);
//extern int usb_stor_Bulk_reset(struct us_data*);
//
//extern void usb_stor_invoke_transport(struct scsi_cmnd *, struct us_data*);
//extern void usb_stor_stop_transport(struct us_data*);
extern int usb_stor_control_msg(struct us_data *us, unsigned int pipe,
u8 request, u8 requesttype, u16 value, u16 index,
void *data, u16 size, int timeout);
//extern int usb_stor_clear_halt(struct us_data *us, unsigned int pipe);
//
//extern int usb_stor_ctrl_transfer(struct us_data *us, unsigned int pipe,
// u8 request, u8 requesttype, u16 value, u16 index,
// void *data, u16 size);
extern int usb_stor_bulk_transfer_buf(struct us_data *us, unsigned int pipe,
void *buf, unsigned int length, unsigned int *act_len);
//extern int usb_stor_bulk_transfer_sg(struct us_data *us, unsigned int pipe,
// void *buf, unsigned int length, int use_sg, int *residual);
//extern int usb_stor_bulk_srb(struct us_data* us, unsigned int pipe,
// struct scsi_cmnd* srb);
//
//extern int usb_stor_port_reset(struct us_data *us);
#endif // CONFIG_USBH_MSC
#endif // _US_TRANSPORT_H_

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,38 @@
#ifndef __UNUSUAL_USBAT_H
#define __UNUSUAL_USBAT_H
#include <platform_opts.h>
#ifdef CONFIG_USBH_MSC
#if defined(CONFIG_USB_STORAGE_USBAT) || \
defined(CONFIG_USB_STORAGE_USBAT_MODULE)
UNUSUAL_DEV( 0x03f0, 0x0207, 0x0001, 0x0001,
"HP",
"CD-Writer+ 8200e",
USB_SC_8070, USB_PR_USBAT, init_usbat_cd, 0),
UNUSUAL_DEV( 0x03f0, 0x0307, 0x0001, 0x0001,
"HP",
"CD-Writer+ CD-4e",
USB_SC_8070, USB_PR_USBAT, init_usbat_cd, 0),
UNUSUAL_DEV( 0x04e6, 0x1010, 0x0000, 0x9999,
"Shuttle/SCM",
"USBAT-02",
USB_SC_SCSI, USB_PR_USBAT, init_usbat_flash,
US_FL_SINGLE_LUN),
UNUSUAL_DEV( 0x0781, 0x0005, 0x0005, 0x0005,
"Sandisk",
"ImageMate SDDR-05b",
USB_SC_SCSI, USB_PR_USBAT, init_usbat_flash,
US_FL_SINGLE_LUN),
#endif /* defined(CONFIG_USB_STORAGE_USBAT) || ... */
#endif // CONFIG_USBH_MSC
#endif // __UNUSUAL_USBAT_H

View file

@ -0,0 +1,30 @@
#ifndef _US_DEBUG_H_
#define _US_DEBUG_H_
#include <platform_opts.h>
#ifdef CONFIG_USBH_MSC
#include "diag.h"
#include "scsi/scsi_cmnd.h"
#define US_DEBUG 0
#define US_DRIVER "MSC"
#if US_DEBUG
#define US_INFO(fmt, args...) printf("\n\r[%s]%s: " fmt, US_DRIVER, __FUNCTION__, ## args)
#define US_ERR(fmt, args...) printf("\n\r[%s]%s: " fmt, US_DRIVER,__FUNCTION__, ## args)
#define US_WARN(fmt, args...) printf("\n\r[%s]%s: " fmt, US_DRIVER,__FUNCTION__, ## args)
#define US_ENTER printf("\n\r[%s]%s ==>\n", US_DRIVER,__FUNCTION__)
#define US_EXIT printf("\n\r[%s]%s <==\n", US_DRIVER,__FUNCTION__)
#else
#define US_INFO(fmt, args...)
#define US_ERR(fmt, args...) printf("\n\r[%s]%s: " fmt, US_DRIVER,__FUNCTION__, ## args)
#define US_WARN(fmt, args...)
#define US_ENTER
#define US_EXIT
#endif
#endif // CONFIG_USBH_MSC
#endif // _US_DEBUG_H_

View file

@ -0,0 +1,25 @@
#ifndef US_INITIALIZERS_H
#define US_INITIALIZERS_H
#include <platform_opts.h>
#ifdef CONFIG_USBH_MSC
#include "usb.h"
#include "transport.h"
/* This places the Shuttle/SCM USB<->SCSI bridge devices in multi-target
* mode */
int usb_stor_euscsi_init(struct us_data *us);
/* This function is required to activate all four slots on the UCR-61S2B
* flash reader */
int usb_stor_ucr61s2b_init(struct us_data *us);
/* This places the HUAWEI E220 devices in multi-port mode */
int usb_stor_huawei_e220_init(struct us_data *us);
#endif // CONFIG_USBH_MSC
#endif // US_INITIALIZERS_H

View file

@ -0,0 +1,34 @@
#ifndef __US_INTF_H_
#define __US_INTF_H_
#include <platform_opts.h>
#ifdef CONFIG_USBH_MSC
#include "basic_types.h"
typedef enum {
MSC_OK = 0,
MSC_NOT_READY,
MSC_W_PROTECT,
MSC_ERROR,
} MSC_RESULT;
extern MSC_RESULT us_init(void);
extern MSC_RESULT us_deinit(void);
extern MSC_RESULT us_isready (void);
extern MSC_RESULT us_getStatus(void);
extern MSC_RESULT us_getmaxlun (u8* lun_num);
extern MSC_RESULT us_unitisready (u8 lun);
extern MSC_RESULT us_inquiry (u8 *pbuf);
extern MSC_RESULT us_getcap(u32 *last_blk_addr, u32 *block_size);
extern MSC_RESULT us_read_blocks( u8 *pbuf, u32 sector, u32 count);
extern MSC_RESULT us_write_blocks( const u8 *pbuf, u32 sector, u32 count);
// indicate usb storage driver status
extern bool USB_STORAGE_READY;
#endif // CONFIG_USBH_MSC
#endif // __US_INTF_H_

View file

@ -0,0 +1,326 @@
/*
* umsc_os_wrap_via_osdep_api.h
*
* Created on: Sep 5, 2014
* Author: jimmysqf
*/
#ifndef US_OS_WRAP_VIA_OSDEP_API_H_
#define US_OS_WRAP_VIA_OSDEP_API_H_
#include <platform_opts.h>
#ifdef CONFIG_USBH_MSC
#include "basic_types.h"
#include "osdep_service.h"
#if !defined (CONFIG_PLATFORM_8721D)
#include "osdep_api.h"
#endif
#define GFP_KERNEL 1
#define GFP_ATOMIC 1
#if defined (CONFIG_PLATFORM_8721D)
#define RestoreFlags() portEXIT_CRITICAL()
#define SaveAndCli() portENTER_CRITICAL()
#endif
typedef unsigned int gfp_t;
/* misc items */
#ifndef ssize_t
#define ssize_t SSIZE_T
#endif
#ifndef size_t
#define size_t SIZE_T
#endif
#ifndef __user
#define __user
#endif
#ifndef loff_t
#define loff_t long
#endif
#ifndef __u8
#define __u8 u8
#endif
#ifndef __u16
#define __u16 u16
#endif
#ifndef __u32
#define __u32 u32
#endif
#ifndef __u64
#define __u64 u64
#endif
#ifndef __s8
#define __s8 s8
#endif
#ifndef __s16
#define __s16 s16
#endif
#ifndef __s32
#define __s32 s32
#endif
#ifndef __s64
#define __s64 s64
#endif
typedef __u16 __le16;
typedef __u16 __be16;
typedef __u32 __le32;
typedef __u32 __be32;
typedef __u64 __le64;
typedef __u64 __be64;
typedef __u16 __sum16;
typedef __u32 __wsum;
#ifndef cpu_to_le32
#define cpu_to_le32(x) rtk_cpu_to_le32(x)
#endif
#ifndef le32_to_cpu
#define le32_to_cpu(x) rtk_le32_to_cpu(x)
#endif
#ifndef cpu_to_le16
#define cpu_to_le16(x) rtk_cpu_to_le16(x)
#endif
#ifndef le16_to_cpu
#define le16_to_cpu(x) rtk_le16_to_cpu(x)
#endif
#ifndef cpu_to_be32
#define cpu_to_be32(x) rtk_cpu_to_be32(x)
#endif
#ifndef be32_to_cpu
#define be32_to_cpu(x) rtk_be32_to_cpu(x)
#endif
#ifndef cpu_to_be16
#define cpu_to_be16(x) rtk_cpu_to_be16(x)
#endif
#ifndef be16_to_cpu
#define be16_to_cpu(x) rtk_be16_to_cpu(x)
#endif
#ifndef DIV_ROUND_UP
#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
#endif
#ifndef BITS_PER_LONG
#define BITS_PER_LONG (32)
#endif
#ifndef BITS_PER_LONG_LONG
#define BITS_PER_LONG_LONG (32)
#endif
#ifndef BIT
#define BIT(nr) (1UL << (nr))
#endif
#ifndef BIT_ULL
#define BIT_ULL(nr) (1ULL << (nr))
#endif
#ifndef BIT_MASK
#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
#endif
#ifndef BIT_WORD
#define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
#endif
#ifndef BIT_ULL_MASK
#define BIT_ULL_MASK(nr) (1ULL << ((nr) % BITS_PER_LONG_LONG))
#endif
#ifndef BIT_ULL_WORD
#define BIT_ULL_WORD(nr) ((nr) / BITS_PER_LONG_LONG)
#endif
#ifndef BITS_PER_BYTE
#define BITS_PER_BYTE (8)
#endif
#ifndef BITS_TO_LONGS
#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
#endif
#ifndef min
#define min(x, y) ((x) < (y) ? (x) : (y))
#endif
#ifndef max
#define max(x, y) ((x) > (y) ? (x) : (y))
#endif
#ifndef min_t
#define min_t(type, x, y) ({ \
type __min1 = (x); \
type __min2 = (y); \
__min1 < __min2 ? __min1 : __min2; })
#endif
#ifndef max_t
#define max_t(type, x, y) ({ \
type __max1 = (x); \
type __max2 = (y); \
__max1 > __max2 ? __max1 : __max2; })
#endif
/**
* container_of - cast a member of a structure out to the containing structure
* @p(ptr): the pointer to the member.
* @t(type): the type of the container struct this is embedded in.
* @m(member): the name of the member within the struct.
*
*/
#ifndef container_of
#define container_of(ptr, type, member) \
((type *)((char *)(ptr)-(SIZE_T)(&((type *)0)->member)))
#endif
/**
* test_bit - Determine whether a bit is set
* @nr: bit number to test
* @addr: Address to start counting from
*/
static inline int test_bit(int nr, const volatile unsigned long *addr)
{
return ((1UL << (nr & 31)) & (addr[nr >> 5])) != 0;
}
/**
* set_bit - Atomically set a bit in memory
* @nr: the bit to set
* @addr: the address to start counting from
*
* This function is atomic and may not be reordered. See __set_bit()
* if you do not require the atomic guarantees.
*
* Note: there are no guarantees that this function will not be reordered
* on non x86 architectures, so if you are writing portable code,
* make sure not to rely on its reordering guarantees.
*
* Note that @nr may be almost arbitrarily large; this function is not
* restricted to acting on a single-word quantity.
*/
static inline void set_bit(int nr, volatile unsigned long *addr)
{
unsigned long mask = BIT_MASK(nr);
unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
SaveAndCli();
*p |= mask;
RestoreFlags();
}
/**
* clear_bit - Clears a bit in memory
* @nr: Bit to clear
* @addr: Address to start counting from
*
* clear_bit() is atomic and may not be reordered. However, it does
* not contain a memory barrier, so if it is used for locking purposes,
* you should call smp_mb__before_clear_bit() and/or smp_mb__after_clear_bit()
* in order to ensure changes are visible on other processors.
*/
static inline void clear_bit(int nr, volatile unsigned long *addr)
{
unsigned long mask = BIT_MASK(nr);
unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
SaveAndCli();
*p &= ~mask;
RestoreFlags();
}
/**
* change_bit - Toggle a bit in memory
* @nr: Bit to change
* @addr: Address to start counting from
*
* change_bit() is atomic and may not be reordered. It may be
* reordered on other architectures than x86.
* Note that @nr may be almost arbitrarily large; this function is not
* restricted to acting on a single-word quantity.
*/
static inline void change_bit(int nr, volatile unsigned long *addr)
{
unsigned long mask = BIT_MASK(nr);
unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
SaveAndCli();
*p ^= mask;
RestoreFlags();
}
/**
* test_and_set_bit - Set a bit and return its old value
* @nr: Bit to set
* @addr: Address to count from
*
* This operation is atomic and cannot be reordered.
* It may be reordered on other architectures than x86.
* It also implies a memory barrier.
*/
static inline int test_and_set_bit(int nr, volatile unsigned long *addr)
{
unsigned long mask = BIT_MASK(nr);
unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
unsigned long old;
SaveAndCli();
old = *p;
*p = old | mask;
RestoreFlags();
return (old & mask) != 0;
}
/**
* test_and_clear_bit - Clear a bit and return its old value
* @nr: Bit to clear
* @addr: Address to count from
*
* This operation is atomic and cannot be reordered.
* It can be reorderdered on other architectures other than x86.
* It also implies a memory barrier.
*/
static inline int test_and_clear_bit(int nr, volatile unsigned long *addr)
{
unsigned long mask = BIT_MASK(nr);
unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
unsigned long old;
SaveAndCli();
old = *p;
*p = old & ~mask;
RestoreFlags();
return (old & mask) != 0;
}
/**
* test_and_change_bit - Change a bit and return its old value
* @nr: Bit to change
* @addr: Address to count from
*
* This operation is atomic and cannot be reordered.
* It also implies a memory barrier.
*/
static inline int test_and_change_bit(int nr, volatile unsigned long *addr)
{
unsigned long mask = BIT_MASK(nr);
unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
unsigned long old;
SaveAndCli();
old = *p;
*p = old ^ mask;
RestoreFlags();
return (old & mask) != 0;
}
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
#endif
#endif // CONFIG_USBH_MSC
#endif // US_OS_WRAP_VIA_OSDEP_API_H_

View file

@ -0,0 +1,26 @@
#ifndef _US_SCSI_H
#define _US_SCSI_H
#include <platform_opts.h>
#ifdef CONFIG_USBH_MSC
/**
* define transfer length
*/
#define TRANS_LEN_READ_10 512
#define TRANS_LEN_WRITE_10 512
#define TRANS_LEN_INQUIRY 36
#define TRANS_LEN_TEST_UNIT_READY 0
#define TRANS_LEN_READ_CAPACITY_10 8
#define TRANS_LEN_READ_CAPACITY_16 12
#define TRANS_LEN_REQUEST_SENSE 18
#define TRANS_LEN_MODE_SENSE 192
extern int scsi_cmnd_execute(char cmnd, unsigned char * _buff,
unsigned long _sector, unsigned int _count);
#endif // CONFIG_USBH_MSC
#endif // _US_SCSI_H

View file

@ -0,0 +1,37 @@
#ifndef _US_STRINGS_H
#define _US_STRINGS_H
#include <platform_opts.h>
#ifdef CONFIG_USBH_MSC
/* description of the sense key values */
static const char * const snstext[] = {
"No Sense", /* 0: There is no sense information */
"Recovered Error", /* 1: The last command completed successfully
but used error correction */
"Not Ready", /* 2: The addressed target is not ready */
"Medium Error", /* 3: Data error detected on the medium */
"Hardware Error", /* 4: Controller or device failure */
"Illegal Request", /* 5: Error in request */
"Unit Attention", /* 6: Removable medium was changed, or
the target has been reset, or ... */
"Data Protect", /* 7: Access to the data is blocked */
"Blank Check", /* 8: Reached unexpected written or unwritten
region of the medium */
"Vendor Specific(9)",
"Copy Aborted", /* A: COPY or COMPARE was aborted */
"Aborted Command", /* B: The target aborted the command */
"Equal", /* C: A SEARCH DATA command found data equal,
reserved in SPC-4 rev 36 */
"Volume Overflow", /* D: Medium full with still data to be written */
"Miscompare", /* E: Source data and data on the medium
do not agree */
"Completed", /* F: command completed sense data reported,
may occur for successful command */
};
#endif // CONFIG_USBH_MSC
#endif // _US_STRINGS_H

View file

@ -0,0 +1,76 @@
/* Driver for USB Mass Storage compliant devices
* Transport Functions Header File
*/
#ifndef _US_TRANSPORT_H_
#define _US_TRANSPORT_H_
#include <platform_opts.h>
#ifdef CONFIG_USBH_MSC
#include "us_usb.h"
/*
* usb_stor_bulk_transfer_xxx() return codes, in order of severity
*/
#define USB_STOR_XFER_GOOD 0 /* good transfer */
#define USB_STOR_XFER_SHORT 1 /* transferred less than expected */
#define USB_STOR_XFER_STALLED 2 /* endpoint stalled */
#define USB_STOR_XFER_LONG 3 /* device tried to send too much */
#define USB_STOR_XFER_ERROR 4 /* transfer died in the middle */
/*
* Transport return codes
*/
#define USB_STOR_TRANSPORT_GOOD 0 /* Transport good, command good */
#define USB_STOR_TRANSPORT_FAILED 1 /* Transport good, command failed */
#define USB_STOR_TRANSPORT_NO_SENSE 2 /* Command failed, no auto-sense */
#define USB_STOR_TRANSPORT_ERROR 3 /* Transport bad (i.e. device dead) */
/*
* We used to have USB_STOR_XFER_ABORTED and USB_STOR_TRANSPORT_ABORTED
* return codes. But now the transport and low-level transfer routines
* treat an abort as just another error (-ENOENT for a cancelled URB).
* It is up to the invoke_transport() function to test for aborts and
* distinguish them from genuine communication errors.
*/
/*
* CBI accept device specific command
*/
#define US_CBI_ADSC 0
//extern int usb_stor_CB_transport(struct scsi_cmnd *, struct us_data*);
//extern int usb_stor_CB_reset(struct us_data*);
//
//extern int usb_stor_Bulk_transport(struct scsi_cmnd *, struct us_data*);
//extern int usb_stor_Bulk_max_lun(struct us_data*);
//extern int usb_stor_Bulk_reset(struct us_data*);
//
//extern void usb_stor_invoke_transport(struct scsi_cmnd *, struct us_data*);
//extern void usb_stor_stop_transport(struct us_data*);
//extern int usb_stor_control_msg(struct us_data *us, unsigned int pipe,
// u8 request, u8 requesttype, u16 value, u16 index,
// void *data, u16 size, int timeout);
//extern int usb_stor_clear_halt(struct us_data *us, unsigned int pipe);
//
//extern int usb_stor_ctrl_transfer(struct us_data *us, unsigned int pipe,
// u8 request, u8 requesttype, u16 value, u16 index,
// void *data, u16 size);
//extern int usb_stor_bulk_transfer_buf(struct us_data *us, unsigned int pipe,
// void *buf, unsigned int length, unsigned int *act_len);
//extern int usb_stor_bulk_transfer_sg(struct us_data *us, unsigned int pipe,
// void *buf, unsigned int length, int use_sg, int *residual);
//extern int usb_stor_bulk_srb(struct us_data* us, unsigned int pipe,
// struct scsi_cmnd* srb);
//
extern int usb_stor_port_reset(struct us_data *us);
#endif // CONFIG_USBH_MSC
#endif // _US_TRANSPORT_H_

View file

@ -0,0 +1,202 @@
#ifndef _US_USB_H_
#define _US_USB_H_
#include <platform_opts.h>
#ifdef CONFIG_USBH_MSC
#include "usb.h"
#include "us_os_wrap_via_osdep_api.h"
#include "us_debug.h"
//#include "sg.h"
struct us_data;
struct scsi_cmnd;
#define CONFIG_SG 0
#define CONFIG_DMA 0
/*
* Unusual device list definitions
*/
struct us_unusual_dev {
const char* vendorName;
const char* productName;
__u8 useProtocol;
__u8 useTransport;
int (*initFunction)(struct us_data *);
};
/* Flag definitions: these entries are static */
#define US_FL_SINGLE_LUN 0x00000001 /* allow access to only LUN 0 */
//#define US_FL_MODE_XLATE 0 /* [no longer used] */
#define US_FL_NEED_OVERRIDE 0x00000004 /* unusual_devs entry is necessary */
//#define US_FL_IGNORE_SER 0 /* [no longer used] */
#define US_FL_SCM_MULT_TARG 0x00000020 /* supports multiple targets */
#define US_FL_FIX_INQUIRY 0x00000040 /* INQUIRY response needs faking */
#define US_FL_FIX_CAPACITY 0x00000080 /* READ CAPACITY response too big */
#define US_FL_IGNORE_RESIDUE 0x00000100 /* reported residue is wrong */
#define US_FL_BULK32 0x00000200 /* Uses 32-byte CBW length */
/* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
#define US_FLIDX_URB_ACTIVE 0 /* current_urb is in use */
#define US_FLIDX_SG_ACTIVE 1 /* current_sg is in use */
#define US_FLIDX_ABORTING 2 /* abort is in progress */
#define US_FLIDX_DISCONNECTING 3 /* disconnect in progress */
#define US_FLIDX_RESETTING 4 /* device reset in progress */
#define US_FLIDX_TIMED_OUT 5 /* SCSI midlayer timed out */
#define US_FLIDX_SCAN_PENDING 6 /* scanning not yet done */
#define US_FLIDX_REDO_READ10 7 /* redo READ(10) command */
#define US_FLIDX_READ10_WORKED 8 /* previous READ(10) succeeded */
#define USB_STOR_STRING_LEN 32
/*
* We provide a DMA-mapped I/O buffer for use with small USB transfers.
* It turns out that CB[I] needs a 12-byte buffer and Bulk-only needs a
* 31-byte buffer. But Freecom needs a 64-byte buffer, so that's the
* size we'll allocate.
*/
#define US_IOBUF_SIZE 64 /* Size of the DMA-mapped I/O buffer */
#define US_SENSE_SIZE 18 /* Size of the autosense data buffer */
typedef int (*trans_cmnd)(struct scsi_cmnd *, struct us_data*);
typedef int (*trans_reset)(struct us_data*);
typedef void (*proto_cmnd)(struct scsi_cmnd*, struct us_data*);
typedef void (*extra_data_destructor)(void *); /* extra data destructor */
typedef void (*pm_hook)(struct us_data *, int); /* power management hook */
#define US_SUSPEND 0
#define US_RESUME 1
/* we allocate one of these for every device that we remember */
struct us_data {
/* The device we're working with
* It's important to note:
* (o) you must hold dev_mutex to change pusb_dev
*/
_mutex dev_mutex;
struct usb_device *pusb_dev; /* this usb_device */
struct usb_interface *pusb_intf; /* this interface */
struct us_unusual_dev *unusual_dev; /* device-filter entry */
unsigned long fflags; /* fixed flags from filter */
unsigned long dflags; /* dynamic atomic bitflags */
unsigned int send_bulk_pipe; /* cached pipe values */
unsigned int recv_bulk_pipe;
unsigned int send_ctrl_pipe;
unsigned int recv_ctrl_pipe;
unsigned int recv_intr_pipe;
/* information about the device */
char *transport_name;
char *protocol_name;
__le32 bcs_signature;
u8 subclass;
u8 protocol;
u8 max_lun; // max number of logical unit (0,1,2,3...)
u8 ifnum; /* interface number */
u8 ep_bInterval; /* interrupt interval */
/* function pointers for this device */
trans_cmnd transport; /* transport function */
trans_reset transport_reset; /* transport device reset */
proto_cmnd proto_handler; /* protocol handler */
/* SCSI interfaces */
struct scsi_cmnd *srb; /* current srb */
unsigned int tag; /* current dCBWTag */
/* control and bulk communications data */
struct urb *current_urb; /* USB requests */
struct usb_ctrlrequest *cr; /* control requests */
// struct usb_sg_request current_sg; /* scatter-gather req. */
unsigned char *iobuf; /* I/O buffer */
dma_addr_t iobuf_dma; /* buffer DMA addresses */
xTaskHandle ctl_task; /*the control task handle*/
/* mutual exclusion and synchronization structures */
_sema cmnd_ready; /* to sleep thread on */
_mutex notify; /* thread begin/end */
unsigned no_sg_constraint:1; /* no sg constraint */
unsigned sg_tablesize; /* 0 or largest number of sg list entries */
/* subdriver information */
void *extra; /* Any extra data */
};
/* Convert between us_data and the corresponding Scsi_Host */
//static inline struct Scsi_Host *us_to_host(struct us_data *us) {
// return container_of((void *) us, struct Scsi_Host, hostdata);
//}
//static inline struct us_data *host_to_us(struct Scsi_Host *host) {
// return (struct us_data *) host->hostdata;
//}
/* Function to fill an inquiry response. See usb.c for details */
extern void fill_inquiry_response(struct us_data *us,
unsigned char *data, unsigned int data_len);
/* The scsi_lock() and scsi_unlock() macros protect the sm_state and the
* single queue element srb for write access */
//#define scsi_unlock(host) spin_unlock_irq(host->host_lock)
//#define scsi_lock(host) spin_lock_irq(host->host_lock)
#define scsi_unlock(host) spin_unlock(host->host_lock)
#define scsi_lock(host) spin_lock(host->host_lock)
/* General routines provided by the usb-storage standard core */
#ifdef CONFIG_USBH_MSC_PM
extern int usb_stor_suspend(struct usb_interface *iface, pm_message_t message);
extern int usb_stor_resume(struct usb_interface *iface);
extern int usb_stor_reset_resume(struct usb_interface *iface);
#else
#define usb_stor_suspend NULL
#define usb_stor_resume NULL
#define usb_stor_reset_resume NULL
#endif
extern int usb_stor_pre_reset(struct usb_interface *iface);
extern int usb_stor_post_reset(struct usb_interface *iface);
extern int usb_stor_probe1(struct us_data *us,
struct usb_interface *intf,
const struct usb_device_id *id,
struct us_unusual_dev *unusual_dev);
extern int usb_stor_probe2(struct us_data *us);
extern void usb_stor_disconnect(struct usb_interface *intf);
extern void usb_stor_adjust_quirks(struct usb_device *dev,
unsigned long *fflags);
/* USB port reset for device reinitialization */
extern int usb_reset_device(struct usb_device *dev);
extern void usb_queue_reset_device(struct usb_interface *dev);
extern void *usb_alloc_coherent(struct usb_device *dev, size_t size,
gfp_t mem_flags, dma_addr_t *dma);
extern void usb_free_coherent(struct usb_device *dev, size_t size,
void *addr, dma_addr_t dma);
// copy from transport.h
extern int usb_stor_Bulk_transport(struct scsi_cmnd *, struct us_data*);
extern int usb_stor_Bulk_max_lun(struct us_data*);
extern int usb_stor_Bulk_reset(struct us_data*);
extern void usb_stor_invoke_transport(struct scsi_cmnd *, struct us_data*);
extern void usb_stor_stop_transport(struct us_data*);
// copy form protocol.h
extern void usb_stor_transparent_scsi_command(struct scsi_cmnd* srb, struct us_data* );
extern unsigned char usb_stor_sense_invalidCDB[18];
#endif // CONFIG_USBH_MSC
#endif // _US_USB_H_

View file

@ -0,0 +1,43 @@
#ifndef __US_USUAL_H
#define __US_USUAL_H
#include <platform_opts.h>
#ifdef CONFIG_USBH_MSC
#include "usb.h"
#include "storage.h"
#define US_FL_SINGLE_LUN 0x00000001/* allow access to only LUN 0 */
//#define US_FL_NEED_OVERRIDE 0x00000002/* unusual_devs entry is necessary */
//#define US_FL_SCM_MULT_TARG 0x00000004/* supports multiple targets */
//#define US_FL_FIX_INQUIRY 0x00000008/* INQUIRY response needs faking */
//#define US_FL_FIX_CAPACITY 0x00000010/* READ CAPACITY response too big */
//#define US_FL_IGNORE_RESIDUE 0x00000020/* reported residue is wrong */
//#define US_FL_BULK32 0x00000040/* Uses 32-byte CBW length */
#define US_FL_NOT_LOCKABLE 0x00000080/* PREVENT/ALLOW not supported */
#define US_FL_GO_SLOW 0x00000100/* Need delay after Command phase */
#define US_FL_NO_WP_DETECT 0x00000200/* Don't check for write-protect */
#define US_FL_MAX_SECTORS_64 0x00000400/* Sets max_sectors to 64 */
#define US_FL_IGNORE_DEVICE 0x00000800/* Don't claim device */
#define US_FL_CAPACITY_HEURISTICS 0x00001000/* sometimes sizes is too big */
#define US_FL_MAX_SECTORS_MIN 0x00002000/* Sets max_sectors to arch min */
#define US_FL_BULK_IGNORE_TAG 0x00004000/* Ignore tag mismatch in bulk operations */
#define US_FL_SANE_SENSE 0x00008000/* Sane Sense (> 18 bytes) */
#define US_FL_CAPACITY_OK 0x00010000/* READ CAPACITY response is correct */
#define US_FL_BAD_SENSE 0x00020000/* Bad Sense (never more than 18 bytes) */
#define US_FL_NO_READ_DISC_INFO 0x00040000/* cannot handle READ_DISC_INFO */
#define US_FL_NO_READ_CAPACITY_16 0x00080000/* cannot handle READ_CAPACITY_16*/
#define US_FL_INITIAL_READ10 0x00100000/* Initial READ(10) (and others) must be retried */
#define US_FL_WRITE_CACHE 0x00200000/* Write Cache status is not available */
#define US_FL_NEEDS_CAP16 0x00400000/* cannot handle READ_CAPACITY_10 */
#define US_FL_IGNORE_UAS 0x00800000/* Device advertises UAS but it is broken */
#define US_FL_BROKEN_FUA 0x01000000/* Cannot handle FUA in WRITE or READ CDBs */
extern int usb_usual_ignore_device(struct usb_interface *intf);
extern struct usb_device_id usb_storage_usb_ids[];
#endif // CONFIG_USBH_MSC
#endif // __US_USUAL_H

View file

@ -0,0 +1,72 @@
#ifndef USBH_VENDOR_H
#define USBH_VENDOR_H
#include <platform_opts.h>
#ifdef CONFIG_USBH_VENDOR
#include "usb.h"
//#define CONFIG_USBH_VENDOR_CTRL_TEST
//#define CONFIG_USBH_VENDOR_BULK_TEST
#define CONFIG_USBH_VENDOR_ISO_IN_TEST
#define CONFIG_USBH_VENDOR_ISO_OUT_TEST
#define USBH_VENDOR_ISO_IN_BUF_SIZE 128
#define USBH_VENDOR_ISO_OUT_BUF_SIZE 128
#define USBH_VENDOR_ISO_IN_CNT 100
#define USBH_VENDOR_TASK_PRIORITY 2
/* Debug options */
#define USBH_VENDOR_DEBUG 0
#define USBH_VENDOR_STR "VS"
#if USBH_VENDOR_DEBUG
#define USBH_VENDOR_INFO(fmt, args...) printf("\n\r[%s]%s: " fmt, USBH_VENDOR_STR, __FUNCTION__, ## args)
#define USBH_VENDOR_WARN(fmt, args...) printf("\n\r[%s]%s: " fmt, USBH_VENDOR_STR, __FUNCTION__, ## args)
#define USBH_VENDOR_ERROR(fmt, args...) printf("\n\r[%s]%s: " fmt, USBH_VENDOR_STR, __FUNCTION__, ## args)
#define USBH_VENDOR_ENTER printf("\n\r[%s]%s: =>", USBH_VENDOR_STR, __FUNCTION__)
#define USBH_VENDOR_EXIT printf("\n\r[%s]%s: <=", USBH_VENDOR_STR, __FUNCTION__)
#define USBH_VENDOR_EXIT_ERR printf("\n\r[%s]%s: ERR <=", USBH_VENDOR_STR, __FUNCTION__)
#else
#define USBH_VENDOR_INFO(fmt, args...)
#define USBH_VENDOR_WARN(fmt, args...)
#define USBH_VENDOR_ERROR(fmt, args...) printf("\n\r[%s]%s: " fmt, USBH_VENDOR_STR, __FUNCTION__, ## args)
#define USBH_VENDOR_ENTER
#define USBH_VENDOR_EXIT
#define USBH_VENDOR_EXIT_ERR
#endif
struct usbtest_info {
const char *name;
u8 ep_in; /* bulk/intr source */
u8 ep_out; /* bulk/intr sink */
unsigned autoconf: 1;
unsigned ctrl_out: 1;
unsigned iso: 1; /* try iso in/out */
unsigned intr: 1; /* try interrupt in/out */
int alt;
};
struct usbtest_dev {
struct usb_interface *intf;
struct usbtest_info *info;
int in_pipe;
int out_pipe;
int in_pipe_addr;
int out_pipe_addr;
int in_iso_pipe;
int out_iso_pipe;
int in_iso_addr;
int out_iso_addr;
int in_int_pipe;
int out_int_pipe;
struct usb_endpoint_descriptor *iso_in, *iso_out;
struct usb_endpoint_descriptor *int_in, *int_out;
u8 *buf;
};
#endif // CONFIG_USBH_VENDOR
#endif // USBH_VENDOR_H

View file

@ -0,0 +1,14 @@
#ifndef USBH_VENDOR_IF_H
#define USBH_VENDOR_IF_H
#include <platform_opts.h>
#ifdef CONFIG_USBH_VENDOR
int usbh_vendor_init(void);
void usbh_vendor_deinit(void);
#endif // CONFIG_USBH_VENDOR
#endif // USBH_VENDOR_IF_H