summaryrefslogtreecommitdiff
path: root/sound/arm/u8500_alsa_ab8500.h
blob: dda802c215658fea847172d91ff631f5da6b89f0 (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
/*
 * Copyright (C) ST-Ericsson SA 2010
 *
 * Author: Deepak Karda
 *         for ST-Ericsson.
 *
 * License terms:
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as published
 * by the Free Software Foundation.
 */

#ifndef _U8500_ALSA_H_
#define _U8500_ALSA_H_

#ifdef CONFIG_U8500_AB8500_CUT10
#include <mach/ab8500_codec_v1_0.h>
//#include <mach/ab8500_codec_p_v1_0.h>
#else
//#include <mach/ab8500_codec_p.h>
#include <mach/ab8500_codec.h>
#endif
#include <mach/u8500_acodec_ab8500.h>

#define DEFAULT_SAMPLE_RATE      48000
#define NMDK_BUFFER_SIZE 	(64*1024)
#define U8500_ALSA_DRIVER	"u8500_alsa"

#define MAX_NUMBER_OF_DEVICES		3	/* ALSA_PCM, ALSA_BT, ALSA_HDMI */
#define MAX_NUMBER_OF_STREAMS		2	/* PLAYBACK, CAPTURE */

#define ALSA_PCM_DEV				0
#define ALSA_BT_DEV					2
#define ALSA_HDMI_DEV				1

/* Debugging stuff */
#ifndef CONFIG_DEBUG_USER
#define DEBUG_LEVEL 0
#else
#define DEBUG_LEVEL 10
#endif

#if DEBUG_LEVEL > 0
static int u8500_acodec_debug = DEBUG_LEVEL;
#define DEBUG(n, args...) do { if (u8500_acodec_debug>(n)) printk(args); } while (0)
#else
#define DEBUG(n, args...) do { } while (0)
#endif
enum alsa_state {
	ALSA_STATE_PAUSE,
	ALSA_STATE_UNPAUSE
};

/* audio stream definition */
typedef struct audio_stream_s {
	char id[64];		/* module identifier  string */
	int stream_id;		/* stream identifier  */
	int status;
	int active;		/* we are using this stream for transfer now */
	int period;		/* current transfer period */
	int periods;		/* current count of periods registerd in the DMA engine */
	enum alsa_state state;
	unsigned int old_offset;
	struct snd_pcm_substream *substream;
	unsigned int exchId;
	snd_pcm_uframes_t played_frame;
	struct semaphore alsa_sem;
	struct completion alsa_com;

} audio_stream_t;

typedef struct hdmi_params_s {
	int sampling_freq;
	int channel_count;
} hdmi_params_t;

/* chip structure definition */
typedef struct u8500_acodec_s {
	struct snd_card *card;
	struct snd_pcm *pcm;
	struct snd_pcm *pcm_hdmi;
	struct snd_pcm *pcm_bt;
	unsigned int freq;
	unsigned int channels;
	unsigned int input_lvolume;
	unsigned int input_rvolume;
	unsigned int output_lvolume;
	unsigned int output_rvolume;
	t_ab8500_codec_src input_device;
	t_ab8500_codec_dest output_device;
	t_u8500_bool_state analog_lpbk;
	t_u8500_bool_state digital_lpbk;
	t_u8500_bool_state playback_switch;
	t_u8500_bool_state capture_switch;
	t_u8500_bool_state tdm8_ch_mode;
	t_u8500_bool_state direct_rendering_mode;
	t_u8500_pmc_rendering_state burst_fifo_mode;
	t_u8500_pmc_rendering_state fm_playback_mode;
	t_u8500_pmc_rendering_state fm_tx_mode;
	audio_stream_t stream[MAX_NUMBER_OF_DEVICES][MAX_NUMBER_OF_STREAMS];
	hdmi_params_t hdmi_params;
} u8500_acodec_chip_t;

void u8500_alsa_dma_start(audio_stream_t * stream);

#if (defined(CONFIG_U8500_ACODEC_DMA) || defined(CONFIG_U8500_ACODEC_INTR))

#define stm_trigger_alsa(x) u8500_alsa_dma_start(x)
static void inline stm_pause_alsa(audio_stream_t * stream)
{
	if (stream->state == ALSA_STATE_UNPAUSE) {
		stream->state = ALSA_STATE_PAUSE;
	}

}
static void inline stm_unpause_alsa(audio_stream_t * stream)
{
	if (stream->state == ALSA_STATE_PAUSE) {
		stream->state = ALSA_STATE_UNPAUSE;
		stm_trigger_alsa(stream);
	}
}
static void inline stm_stop_alsa(audio_stream_t * stream)
{
	stream->active = 0;
	stream->period = 0;

}
static void inline stm_hw_free(struct snd_pcm_substream *substream)
{
	snd_pcm_lib_free_pages(substream);
}

#define stm_close_alsa(x, y,z)
#define stm_config_hw(w,x, y, z) 0

#else ////// CONFIG_U8500_ACODEC_POLL ////////////

int spawn_acodec_feeding_thread(audio_stream_t * stream);
//static int configure_dmadev_acodec(struct snd_pcm_substream *substream);

#define stm_trigger_alsa(x) spawn_acodec_feeding_thread(x)
#define stm_close_alsa(x, y,z)
#define stm_config_hw(w,x, y, z) 0
#define stm_hw_free(x)
static void inline stm_pause_alsa(audio_stream_t * stream)
{
	stream->state = ALSA_STATE_PAUSE;
}
static void inline stm_unpause_alsa(audio_stream_t * stream)
{
	stream->state = ALSA_STATE_UNPAUSE;
	complete(&stream->alsa_com);
}
static void inline stm_stop_alsa(audio_stream_t * stream)
{
	stream->active = 0;
	stream->period = 0;
	if (stream->state == ALSA_STATE_PAUSE)
		complete(&stream->alsa_com);
}

#endif
#endif /*END OF HEADER FILE */