summaryrefslogtreecommitdiff
path: root/sound/soc/tegra/tegra_transport.h
blob: 7863efbee64d720487a693652266347f14b8de92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
/*
 * sound/soc/tegra/tegra_transport.h
 *
 * ALSA SOC driver for NVIDIA Tegra SoCs
 *
 * Copyright (C) 2010 NVIDIA Corporation
 *
 * 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 of the License, 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.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#ifndef _TEGRA_TRANSPORT_H_
#define _TEGRA_TRANSPORT_H_

#include <linux/module.h>
#include <linux/init.h>
#include <linux/io.h>
#include <linux/platform_device.h>
#include <linux/slab.h>
#include <linux/dma-mapping.h>
#include <linux/kthread.h>
#include <sound/core.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <sound/soc.h>
#include <linux/mutex.h>

#include <mach/nvrm_linux.h>
#include "nvrm_memmgr.h"
#include "nvassert.h"
#include "nvrm_transport.h"
#include "tegra_sndfx.h"


#define I2S1	0
#define I2S2	1

#define INIT_TIMEOUT 5000
#define PLAY_TIMEOUT 5000
#define REC_TIMEOUT 5000
#define WHISTLER_CODEC_ADDRESS 0x1a
#define WHISTLER_CODEC_BUS 0
#define NVALSA_BUFFER_COUNT 1
#define TEGRA_DEFAULT_BUFFER_SIZE 4096
#define NVALSA_INVALID_STATE -1
#define TEGRA_SAMPLE_RATES (SNDRV_PCM_RATE_8000_48000)
#define TEGRA_SAMPLE_FORMATS (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U8 |\
		     SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE |\
		     SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S16_BE)

#define TEGRA_TRANSPORT_SEND_TIMEOUT           5000
#define TEGRA_TRANSPORT_CONNECT_TIMEOUT        60000
#define FXTRANSPORT_MSG_BUFFER_SIZE           256
#define FXTRANSPORT_MSG_BUFFER_PROPERTY_SIZE  FXTRANSPORT_MSG_BUFFER_SIZE - 32
#define FXTRANSPORT_MSG_RESULT_DATA_SIZE      FXTRANSPORT_MSG_BUFFER_SIZE - 32

typedef enum {
	NVFXTRANSPORT_MESSAGE_MIXER_OPEN = 0,
	NVFXTRANSPORT_MESSAGE_MIXER_CLOSE,
	NVFXTRANSPORT_MESSAGE_CREATE_OBJECT,
	NVFXTRANSPORT_MESSAGE_DESTROY_OBJECT,
	NVFXTRANSPORT_MESSAGE_MAP_BUFFER,
	NVFXTRANSPORT_MESSAGE_UNMAP_BUFFER,
	NVFXTRANSPORT_MESSAGE_GET_PROPERTY,
	NVFXTRANSPORT_MESSAGE_SET_PROPERTY,
	NVFXTRANSPORT_MESSAGE_STREAM_ADD_BUFFER,

	NVFXTRANSPORT_MESSAGE_Force32 = 0x7FFFFFFF

} NVFXTRANSPORT_MESSAGE;


typedef struct NvFxTransportMessageRec {
#define NVFXTRANSPORT_MESSAGE_VARS          \
	NVFXTRANSPORT_MESSAGE Message;      \
	NvOsSemaphoreHandle Semaphore;      \
	void* pPrivateData;                 \
	NvU32 SendAck

	NVFXTRANSPORT_MESSAGE_VARS;

} NvFxTransportMessage;

typedef struct NvFxTransportMessageResultRec {
#define NVFXTRANSPORT_MESSAGE_RESULT_VARS       \
	NVFXTRANSPORT_MESSAGE Message;          \
	NvOsSemaphoreHandle Semaphore;          \
	void* pPrivateData

	NVFXTRANSPORT_MESSAGE_RESULT_VARS;

}  NvFxTransportMessageResult;


typedef struct NvFxTransportMessageMixerOpenRec {
	NVFXTRANSPORT_MESSAGE_VARS;
	NvAudioFxMixerHandle* phMixer;

} NvFxTransportMessageMixerOpen;

typedef struct NvFxTransportMessageResultMixerOpenRec {
	NVFXTRANSPORT_MESSAGE_RESULT_VARS;
	NvAudioFxMixerHandle hMixer;
	NvAudioFxMixerHandle* phMixer;

} NvFxTransportMessageResultMixerOpen;


typedef struct NvFxTransportMessageMixerCloseRec {
	NVFXTRANSPORT_MESSAGE_VARS;
	NvAudioFxMixerHandle hMixer;

} NvFxTransportMessageMixerClose;

typedef NvFxTransportMessageResult NvFxTransportMessageResultMixerClose;


typedef struct NvFxTransportMessageCreateObjectRec {
	NVFXTRANSPORT_MESSAGE_VARS;
	NvAudioFxMixerHandle hMixer;
	NvObjectId Id;

	NvAudioFxObjectHandle* phObject;

} NvFxTransportMessageCreateObject;

typedef struct NvFxTransportMessageResultCreateObjectRec {
	NVFXTRANSPORT_MESSAGE_RESULT_VARS;
	NvAudioFxObjectHandle hObject;
	NvAudioFxObjectHandle* phObject;

}  NvFxTransportMessageResultCreateObject;


typedef struct NvFxTransportMessageDestroyObjectRec {
	NVFXTRANSPORT_MESSAGE_VARS;
	NvAudioFxObjectHandle hObject;

} NvFxTransportMessageDestroyObject;

typedef NvFxTransportMessageResult NvFxTransportMessageResultDestroyObject;


typedef struct NvFxTransportMessageMapBufferRec {
	NVFXTRANSPORT_MESSAGE_VARS;
	NvAudioFxMixerHandle hMixer;
	NvU32 NvRmMemHandleId;
	NvU32 Offset;
	NvU32 Size;

	NvAudioFxMixBufferHandle* phMixBuffer;

} NvFxTransportMessageMapBuffer;

typedef struct NvFxTransportMessageResultMapBufferRec {
	NVFXTRANSPORT_MESSAGE_RESULT_VARS;
	NvAudioFxMixBufferHandle hMixBuffer;
	NvAudioFxMixBufferHandle* phMixBuffer;

}  NvFxTransportMessageResultMapBuffer;


typedef struct NvFxTransportMessageUnmapBufferRec {
	NVFXTRANSPORT_MESSAGE_VARS;
	NvAudioFxMixBufferHandle hMixBuffer;

} NvFxTransportMessageUnmapBuffer;

typedef NvFxTransportMessageResult NvFxTransportMessageResultUnmapBuffer;


typedef struct NvFxTransportMessageGetPropertyRec {
	NVFXTRANSPORT_MESSAGE_VARS;
	NvAudioFxObjectHandle hObject;
	NvAudioFxProperty Property;
	NvU32 Size;

	void* pProperty;
	NvError* pReturnError;

} NvFxTransportMessageGetProperty;

typedef struct NvFxTransportMessageResultGetPropertyRec {
	NVFXTRANSPORT_MESSAGE_RESULT_VARS;
	NvU32 Size;
	NvError ReturnError;
	void* pProperty;
	NvError* pReturnError;
	NvU8 PropertyData[FXTRANSPORT_MSG_BUFFER_PROPERTY_SIZE];

}  NvFxTransportMessageResultGetProperty;


typedef struct NvFxTransportMessageSetPropertyRec {
	NVFXTRANSPORT_MESSAGE_VARS;
	NvAudioFxObjectHandle hObject;
	NvAudioFxProperty Property;
	NvU32 Size;
	NvError* pReturnError;
	NvU8 PropertyData[FXTRANSPORT_MSG_BUFFER_PROPERTY_SIZE];
} NvFxTransportMessageSetProperty;

typedef struct NvFxTransportMessageResultSetPropertyRec {
	NVFXTRANSPORT_MESSAGE_RESULT_VARS;
	NvError ReturnError;
	NvError* pReturnError;

}  NvFxTransportMessageResultSetProperty;


typedef struct NvFxTransportMessageStreamAddBufferRec {
	NVFXTRANSPORT_MESSAGE_VARS;
	NvAudioFxStreamHandle hStream;
	NvAudioFxBufferDescriptor Descriptor;

	NvError* pReturnError;

} NvFxTransportMessageStreamAddBuffer;

typedef struct NvFxTransportMessageResultStreamAddBufferRec {
	NVFXTRANSPORT_MESSAGE_RESULT_VARS;
	NvError ReturnError;
	NvError* pReturnError;

}  NvFxTransportMessageResultStreamAddBuffer;

typedef union NvFxTranspportMessageBuffer {
	NvFxTransportMessage Message;
	NvFxTransportMessageMixerOpen MixerOpen;
	NvFxTransportMessageMixerClose MixerClose;
	NvFxTransportMessageCreateObject CreateObject;
	NvFxTransportMessageDestroyObject DestroyObject;
	NvFxTransportMessageMapBuffer MapBuffer;
	NvFxTransportMessageUnmapBuffer UnmapBuffer;
	NvFxTransportMessageGetProperty GetProperty;
	NvFxTransportMessageSetProperty SetProperty;
	NvFxTransportMessageStreamAddBuffer StreamAddBuffer;

} NvFxTransportMessageBuffer;

typedef union NvFxTranspportMessageResultBuffer {
	NvFxTransportMessageResult Message;
	NvFxTransportMessageResultMixerOpen MixerOpen;
	NvFxTransportMessageResultMixerClose MixerClose;
	NvFxTransportMessageResultCreateObject CreateObject;
	NvFxTransportMessageResultDestroyObject DestroyObject;
	NvFxTransportMessageResultMapBuffer MapBuffer;
	NvFxTransportMessageResultUnmapBuffer UnmapBuffer;
	NvFxTransportMessageResultGetProperty GetProperty;
	NvFxTransportMessageResultSetProperty SetProperty;
	NvFxTransportMessageResultStreamAddBuffer StreamAddBuffer;

} NvFxTransportMessageResultBuffer;

typedef struct AlsaTransportRec {
	NvddkAudioFxFxnTable*   hFxnTable;
	NvOsThreadHandle        hServiceThread;
	NvOsSemaphoreHandle     hServiceSema;

	NvRmDeviceHandle        hRmDevice;
	NvRmTransportHandle     hRmTransport;

	volatile NvU32          TransportConnected;
	NvU32                   RefCount;
	NvU32                   ShutDown;
	spinlock_t              lock;

} AlsaTransport;


enum {
	/* Default Playback Path*/
	GlobalFx_DefaultPlaybackMix = 0,
	GlobalFx_DefaultPlaybackSplit,

	/* I2S Playback Path*/
	GlobalFx_I2sPlaybackMix,
	GlobalFx_I2sPlaybackVolume,
	GlobalFx_I2s,

	/* I2S2 Playback Path*/
	GlobalFx_I2s2PlaybackMix,
	GlobalFx_I2s2PlaybackVolume,
	GlobalFx_I2s2,

	/* SPDIF Playback Path*/
	GlobalFx_SpdifPlaybackMix,
	GlobalFx_SpdifPlaybackVolume,
	GlobalFx_Spdif,


	/* Default Record Path*/
	GlobalFx_DefaultRecordMix,
	GlobalFx_DefaultRecordSplit,

	/* I2S Record Path*/
	GlobalFx_I2sRecordVolume,
	GlobalFx_I2sRecordSplit,

	/* I2S2 Record Path*/
	GlobalFx_I2s2RecordVolume,
	GlobalFx_I2s2RecordSplit,

	/* SPDIF Record Path*/
	GlobalFx_SpdifRecordVolume,
	GlobalFx_SpdifRecordSplit,


	/* Loopbacks*/
	GlobalFx_I2sLoopbackSplit,
	GlobalFx_I2s2LoopbackSplit,
	GlobalFx_SpdifLoopbackSplit,


	/* Music Path*/
	GlobalFx_MusicMix,
	GlobalFx_MusicEq,
	GlobalFx_MusicDrc,
	GlobalFx_MusicSpreader,
	GlobalFx_MusicPeq,
	GlobalFx_MusicVolume,
	GlobalFx_MusicSplit,


	/* Phone Path*/
	GlobalFx_PhoneMix,
	GlobalFx_PhoneSplit,

	GlobalFx_Num

};

typedef struct GlobalFxListRec {
	/* Default Playback Path*/
	NvAudioFxObjectHandle hFx[GlobalFx_Num];
} GlobalFxList;


typedef struct FxNotifierRec {
	NvAudioFxNotifierHandle hNotifier;
	NvRmTransportHandle hTransport;
	NvOsSemaphoreHandle hTransportSemaphore;
	NvOsThreadHandle hTransportThread;

	NvU32 Exit;
	NvU32 Connected;
	NvU8 RcvMessageBuffer[256];

	NvAudioFxEvent Event;

} FxNotifier;

typedef enum {
	NvAudioInputSelect_Record = 0,
	NvAudioInputSelect_Loopback

} InputSelection;

typedef struct StandardPathRec {
	NvAudioFxObjectHandle Stream;
	NvAudioFxObjectHandle Src;
	NvAudioFxObjectHandle Convert;
	NvAudioFxObjectHandle Volume;
	NvAudioFxObjectHandle Resize;

	/*NvAudioFxVolumeDescriptor VolumeDesc;*/
	/*NvU32 VolumeRamping;*/
	/*StandardPosition StandardPosition;*/

} StandardPath;

typedef struct NvAudioBufferRec {
	NvRmMemHandle hRmMem;
	NvAudioFxMixBufferHandle hMixBuffer;
	void* pVirtAddr;
	NvU32 Size;
} NvAudioBuffer;

struct pcm_runtime_data {
	spinlock_t lock;
	struct task_struct *play_thread,*rec_thread;
	int timeout;
	int state;
	int stream;
	unsigned int audiofx_frames;
	struct completion thread_comp;
	wait_queue_head_t buf_wait;
	struct semaphore buf_done_sem;
	struct semaphore stop_done_sem;
	StandardPath* stdoutpath;
	StandardPath* stdinpath;
	u64 cur_pos;
	u64 last_pos;
	NvAudioFxMixBufferHandle mixer_buffer;
};

struct tegra_audio_data {
	NvddkAudioFxFxnTable xrt_fxn;
	NvAudioFxMixerHandle mixer_handle;
	FxNotifier m_FxNotifier;
	NvRmDeviceHandle m_hRm;
	unsigned int mapped_buf_size;
	NvAudioFxMixBufferHandle mixer_buffer[2];
	NvRmMemHandle mem_handle[2];
	NvAudioFxObjectHandle mvolume;
	NvAudioFxObjectHandle mi2s1;
	NvAudioFxObjectHandle i2s1_play_mix;
	NvAudioFxObjectHandle i2s2_play_mix;
	NvAudioFxObjectHandle i2s1_rec_split;
	NvAudioFxObjectHandle i2s2_rec_split;
	NvAudioFxObjectHandle mroute;
	NvAudioFxIoDevice mi2s1_device_available;
	NvAudioFxIoDevice mspdif_device_available;
	int spdif_plugin;
	int i2s1volume;
	int device_id;
	struct mutex lock;
};

int tegra_audiofx_init(struct tegra_audio_data* tegra_snd_cx);
NvError tegra_audiofx_createfx(struct tegra_audio_data *audio_context);
void tegra_audiofx_destroyfx(struct tegra_audio_data *audio_context);
NvError tegra_audiofx_create_output(NvRmDeviceHandle,
				    NvAudioFxMixerHandle,
				    StandardPath*,
				    NvAudioFxObjectHandle hSource);
NvError tegra_audiofx_destroy_output(StandardPath* pPath);
NvError tegra_audiofx_create_input(NvRmDeviceHandle hRmDevice,
				NvAudioFxMixerHandle hMixer,
				StandardPath* pPath,
				InputSelection InputSelect,
				NvAudioFxObjectHandle hSource);
NvError tegra_audiofx_destroy_input(StandardPath* pPath);
NvError tegra_audiofx_route(struct tegra_audio_data* tegra_snd_cx);
NvError tegra_transport_init(NvddkAudioFxFxnTable* FxTransportFxFxnTable);
void tegra_transport_deinit(void);

#endif