1 /*---------------------------------------------------------------------------*
2   Project:     Cafe
3 
4   Copyright (C) Nintendo.  All rights reserved.
5 
6   These coded instructions, statements, and computer programs contain
7   proprietary information of Nintendo of America Inc. and/or Nintendo
8   Company Ltd., and are protected by Federal copyright law.  They may
9   not be disclosed to third parties or copied or duplicated in any form,
10   in whole or in part, without the prior written consent of Nintendo.
11 
12   *---------------------------------------------------------------------------*/
13 /*
14  * COS based UAC header
15  * Created by Gunter M. Zieber, August 1st, 2013
16  * Based on NEC-E's PPC shim and IOP class driver stack
17  */
18 //////////////////////////////////////////////////////////////////////////////
19 // Returned Error Codes
20 //////////////////////////////////////////////////////////////////////////////
21 
22 #define MAKE_UAC_ERROR(error)				(error)
23 
24 #define COS_UAC_ERROR_OK						(0)
25 
26 #define COS_UAC_ERROR_WAIT						(COS_UAC_ERROR_OK+1)
27 
28 #define COS_UAC_ERROR_CANCEL					MAKE_UAC_ERROR(-10)
29 
30 #define COS_UAC_ERROR_INVALID_ARG				MAKE_UAC_ERROR(-100)
31 #define COS_UAC_ERROR_NOTREADY					MAKE_UAC_ERROR(-101)
32 #define COS_UAC_ERROR_DEVICE_BUSY				MAKE_UAC_ERROR(-102)
33 #define COS_UAC_ERROR_DEVICE_NOTREADY			MAKE_UAC_ERROR(-103)
34 #define COS_UAC_ERROR_INVALID_DEVICE_HANDLE		MAKE_UAC_ERROR(-104)
35 #define COS_UAC_ERROR_BUFFER_SIZE				MAKE_UAC_ERROR(-105)
36 #define COS_UAC_ERROR_DATA_SIZE					MAKE_UAC_ERROR(-106)
37 #define COS_UAC_ERROR_UNSUPPORTED				MAKE_UAC_ERROR(-107)
38 #define COS_UAC_ERROR_FORMAT_TYPE				MAKE_UAC_ERROR(-108)
39 
40 #define COS_UAC_ERROR_NO_DATA					MAKE_UAC_ERROR(-110)
41 #define COS_UAC_ERROR_NO_REQUEST				MAKE_UAC_ERROR(-111)
42 #define COS_UAC_ERROR_INVALID_UNIT				MAKE_UAC_ERROR(-112)
43 #define COS_UAC_ERROR_CTRL_BUSY					MAKE_UAC_ERROR(-113)
44 #define COS_UAC_ERROR_IFSET_BUSY				MAKE_UAC_ERROR(-114)
45 #define COS_UAC_ERROR_IFSET						MAKE_UAC_ERROR(-115)
46 
47 #define COS_UAC_ERROR_INVALID_RM_CMD			MAKE_UAC_ERROR(-121)
48 #define COS_UAC_ERROR_INVALID_IOCTLV_CMD		MAKE_UAC_ERROR(-122)
49 #define COS_UAC_ERROR_CLIENT_PRIORITY			MAKE_UAC_ERROR(-123)
50 #define COS_UAC_ERROR_CLIENT_TXN_BUF_ERROR		MAKE_UAC_ERROR(-124)
51 #define COS_UAC_ERROR_MAX_QUEUE					MAKE_UAC_ERROR(-125)
52 
53 #define COS_UAC_ERROR_NO_MEMORY                 MAKE_UAC_ERROR(-130)
54 
55 #define COS_UAC_ERROR_UNDEFINED					MAKE_UAC_ERROR(-199)
56 
57 // usb_uac_request request value
58 #define COS_UAC_REQ_COPY_PROTECT					0x01	// Copy Protect Control
59 #define COS_UAC_REQ_MIXER							0x02	// Mixer Control Request
60 #define COS_UAC_REQ_SELECTOR						0x03	// Selector Control Request
61 #define COS_UAC_REQ_MUTE							0x04	// Mute Control Request
62 #define COS_UAC_REQ_VOLUME							0x05	// Volume Control Request
63 #define COS_UAC_REQ_BASS							0x06	// Bass Control Request
64 #define COS_UAC_REQ_MID								0x07	// Mid Control Request
65 #define COS_UAC_REQ_TREBLE							0x08	// Treble Control Request
66 #define COS_UAC_REQ_GRAPHIC_EQUALIZER				0x09	// Graphic Equalizer Control Request
67 #define COS_UAC_REQ_AUTOMATIC_GAIN					0x0a	// Automatic Gain Control Request
68 #define COS_UAC_REQ_DELAY							0x0b	// Delay Control Request
69 #define COS_UAC_REQ_BASS_BOOST						0x0c	// Bass Boost Control Request
70 #define COS_UAC_REQ_LOUDNESS						0x0d	// Loudness Control Request
71 #define COS_UAC_REQ_UP_DOWN_MIX_ENABLE				0x0e	// Up/Down-mix Enable Control Request
72 #define COS_UAC_REQ_UP_DOWN_MIX_MODE_SELECT			0x0f	// Up/Down-mix Mode Select Control Request
73 #define COS_UAC_REQ_DOLBY_PROLOGIC_ENABLE			0x10	// Dolby Prologic Enable Control Request
74 #define COS_UAC_REQ_DOLBY_PROLOGIC_MODE_SELECT		0x11	// Dolby Prologic Mode Select Control Request
75 #define COS_UAC_REQ_3D_STEREO_EXTENDER_ENABLE		0x12	// 3D Stereo Extender Enable Control Request
76 #define COS_UAC_REQ_3D_STEREO_EXTENDER_SPACIOUSNESS	0x13	// 3D Stereo Extender Spaciousness Control Request
77 #define COS_UAC_REQ_REVERBERATION_ENABLE			0x14	// Reverberation Enable Control Request
78 #define COS_UAC_REQ_REVERBERATION_LEVEL				0x15	// Reverberation Level Control Request
79 #define COS_UAC_REQ_REVERBERATION_TIME				0x16	// Reverberation Time Control Request
80 #define COS_UAC_REQ_REVERBERATION_FEEDBACK			0x17	// Reverberation Feedback Control Request
81 #define COS_UAC_REQ_CHORUS_ENABLE					0x18	// Chorus Enable Control Request
82 #define COS_UAC_REQ_CHORUS_LEVEL					0x19	// Chorus Level Control Request
83 #define COS_UAC_REQ_CHORUS_RATE						0x1a	// Chorus Rate Control Request
84 #define COS_UAC_REQ_CHORUS_DEPTH					0x1b	// Chorus Depth Control Request
85 #define COS_UAC_REQ_DRC_ENABLE						0x1c	// Dynamic Range Compressor Enable Control Request
86 #define COS_UAC_REQ_DRC_COMPRESSION_RATE			0x1d	// Dynamic Range Compressor Compression Rate Control Request
87 #define COS_UAC_REQ_DRC_MAXAMPL						0x1e	// Dynamic Range Compressor MaxAmpl Control Request
88 #define COS_UAC_REQ_DRC_THRESHOLD					0x1f	// Dynamic Range Compressor Threshold Control Request
89 #define COS_UAC_REQ_DRC_ATTACK_TIME					0x20	// Dynamic Range Compressor Attack Time Control Request
90 #define COS_UAC_REQ_DRC_RELEASE_TIME				0x21	// Dynamic Range Compressor Release Time Control Request
91 #define COS_UAC_REQ_EXTENSION_ENABLE				0x22	// Extension Enable Control Request
92 
93 #define COS_UAC_REQ_SAMPLING_FREQUENCY				0x30	// Sampling Frequency Control Request
94 #define COS_UAC_REQ_PITCH							0x31	// Pitch Control Request
95 
96 #define COS_UAC_REQ_ENTITY_MEMORY					0x40	// Entity Memory Request
97 #define COS_UAC_REQ_ENTITY_STATUS					0x41	// Entity Status Request
98 
99 #define COS_UAC_SET_FORMAT							0x80	// Set Format	UAC_FORMAT_PCM or UAC_FORMAT_ULAW
100 
101 // usb_uac_request Code Value
102 #define COS_UAC_SET_CUR							0x01
103 #define COS_UAC_SET_MIN							0x02
104 #define COS_UAC_SET_MAX							0x03
105 #define COS_UAC_SET_RES							0x04
106 #define COS_UAC_SET_MEM							0x05
107 #define COS_UAC_GET_CUR							0x81
108 #define COS_UAC_GET_MIN							0x82
109 #define COS_UAC_GET_MAX							0x83
110 #define COS_UAC_GET_RES							0x84
111 #define COS_UAC_GET_MEM							0x85
112 #define COS_UAC_GET_STAT						0xFF
113 
114 #define COS_UAC_GET_REQ_TYPE					0x80
115 
116 // usb_uac_request Channel
117 #define COS_UAC_ALL_CH							0xff
118 
119 /* device capability definitions */
120 /* sample formats */
121 #define FORMAT_PCM_8		(1 << 0)
122 #define FORMAT_PCM_16		(1 << 1)
123 #define FORMAT_U_LAW		(1 << 2)
124 #define FORMAT_A_LAW		(1 << 3)
125 /* channel designation */
126 #define CHANNELS_ONE		(1 << 0)
127 #define CHANNELS_TWO		(1 << 1)
128 /* sample rates */
129 #define RATE_8000			(1 << 0)
130 #define RATE_11025			(1 << 1)
131 #define RATE_16000			(1 << 2)
132 #define RATE_22050			(1 << 3)
133 #define RATE_24000			(1 << 4)
134 #define RATE_32000			(1 << 5)
135 #define RATE_44100			(1 << 6)
136 #define RATE_48000			(1 << 7)
137 
138 typedef short int       pcm_16_t;
139 typedef char            pcm_8_t;
140 
141 typedef struct {
142     unsigned long int   sample_formats;
143     unsigned long int   num_channels;
144     unsigned long int   sample_rates;
145     unsigned long int   buffer_size;
146     unsigned long int   dev_type;
147 } cos_uac_dev_cap_base_t;
148 
149 #define COS_UAC_TYPE_MIC    (0)
150 #define COS_UAC_TYPE_OUT    (1)
151 #define COS_UAC_NUM_TYPE    (2)
152 
153 typedef struct {
154     cos_uac_dev_cap_base_t  caps[COS_UAC_NUM_TYPE];
155 } cos_uac_dev_cap_t;
156 
157 #define MAX_HUB_HIERARCHY   (8)
158 
159 typedef struct {
160     unsigned long int   udd;
161     unsigned long int   i_host;
162     unsigned short int  vid;
163     unsigned short int  pid;
164     unsigned char       a_port[MAX_HUB_HIERARCHY];
165 } cos_uac_dev_info_t;
166 
167 typedef enum {
168     cos_uac_evt_attach,
169     cos_uac_evt_detach,
170     cos_uac_evt_init,
171     cos_uac_evt_uninit,
172     cos_uac_evt_error
173 } cos_uac_event_type_t;
174 
175 typedef unsigned long int   cos_uac_instance_t;
176 
177 typedef struct {
178     cos_uac_event_type_t    event;
179     cos_uac_instance_t      h_inst;
180     int                     error;
181 } cos_uac_event_data_t;
182 
183 typedef void (*cos_uac_event_t)(void*, cos_uac_event_data_t*, cos_uac_dev_info_t*, cos_uac_dev_cap_t*);
184 
185 typedef enum {
186     e_input,
187     e_output
188 } cos_uac_target_stream_t;
189 
190 typedef struct {
191     unsigned char       request;
192     unsigned char       code;
193     unsigned short int  value;
194     unsigned char*      ret_buf;
195     unsigned short int  size;
196     unsigned short int  channel;
197 } cos_uac_request_t;
198 
199 /* context, buffer, num iTD, per iTD, sequence #, mps, error */
200 typedef void (* cos_uac_xfer_complete_t)(void*, void*, unsigned int, long int*, unsigned long int, unsigned int, int);
201 
202 int cos_uac_submit_rc(cos_uac_instance_t, void*, unsigned int, unsigned int,long int*, void*, cos_uac_xfer_complete_t);
203 int cos_uac_submit_tx(cos_uac_instance_t, void*, unsigned int, unsigned int,long int*, void*, cos_uac_xfer_complete_t);
204 int cos_uac_request(cos_uac_instance_t, cos_uac_request_t*, cos_uac_target_stream_t);
205 int cos_uac_start(cos_uac_instance_t, cos_uac_target_stream_t, unsigned long int);
206 int cos_uac_stop(cos_uac_instance_t, cos_uac_target_stream_t);
207 int cos_uac_check_bus(void);
208 int cos_uac_class_query_init(unsigned int, unsigned int);
209 int cos_uac_class_init(void*, cos_uac_event_t, void*, unsigned long int, unsigned int, unsigned int);
210 int cos_uac_release_instance(cos_uac_instance_t);
211 int cos_uac_class_exit(void);
212