aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/codecs/max98095_mixer.c
blob: eb4a4ecb24dbd85145133319c759bc7b9614fbf3 (plain) (blame)
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
/*
 * max98095.c -- MAX98095 ALSA SoC Audio driver
 *
 * Copyright 2010 Maxim Integrated Products
 *
 * 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.
 */

#include <sound/soc.h>
#include <sound/soc-dapm.h>
#include <linux/delay.h>
#include <asm/io.h>
#include <asm/gpio.h>
#include <plat/gpio-cfg.h>
#include <plat/map-base.h>
#include <mach/regs-clock.h>

#include <sound/max98095.h>
#include "max98095.h"

//----------------------------------------------------------------------------------------
// audio gain parameter
//----------------------------------------------------------------------------------------
#define   TUNNING_DAI1_VOL    	0x00 // 0dB
#define   TUNNING_DAI1_RCV_VOL  0x00 // 0dB

#define   TUNNING_SPKMIX_VOL    0x00 // 0dB
#define   TUNNING_HPMIX_VOL     0x00 // 0dB

#define   TUNNING_RCV_VOL    	0x1F // +8dB
#define   TUNNING_SPK_VOL    	0x18 // +8dB
#define   TUNNING_HP_VOL     	0x11 // -5dB

#define 	MIC_PRE_AMP_GAIN	(3<<5) // +30dB
#define 	MIC_PGA_GAIN		(0x00) // +20dB
#define   	TUNNING_MIC_PGA_GAIN    MIC_PRE_AMP_GAIN

#define 	MIC_ADC_GAIN		(3<<4) // +18dB
#define 	MIC_ADC_VOLUME		(0x03) // 0dB
#define   	TUNNING_ADC_GAIN    MIC_ADC_VOLUME

//----------------------------------------------------------------------------------------
// playback function
//----------------------------------------------------------------------------------------
void max98095_set_playback_speaker(struct snd_soc_codec *codec)
{
	int reg;
	
	// 0x92 Power DAC L/R, SPLEN
	reg = snd_soc_read(codec, M98095_091_PWR_EN_OUT);
	reg &= ~(M98095_DAREN|M98095_DALEN|M98095_DAMEN|M98095_RECEN|M98095_SPREN|M98095_SPLEN|M98095_HPREN|M98095_HPLEN);
	reg |= (M98095_DAREN|M98095_DALEN|M98095_SPREN|M98095_SPLEN);
	snd_soc_write(codec, M98095_091_PWR_EN_OUT, reg);

	// DAI1 L/R to L/R DAC
	reg = (M98095_DAI1R_TO_DACR|M98095_DAI1L_TO_DACL);
	snd_soc_write(codec, M98095_048_MIX_DAC_LR, reg);

	// Mono DAC to SPK_L, SPK_R Mute
	reg = M98095_DACL_TO_SPKL;
	snd_soc_write(codec, M98095_050_MIX_SPK_LEFT, reg);
	reg = M98095_DACR_TO_SPKR;
	snd_soc_write(codec, M98095_051_MIX_SPK_RIGHT, reg);

	reg = TUNNING_DAI1_VOL;
	snd_soc_write(codec, M98095_058_LVL_DAI1_PLAY, reg);

	reg = TUNNING_SPK_VOL;
	snd_soc_write(codec, M98095_068_LVL_SPK_R, reg);
	snd_soc_write(codec, M98095_067_LVL_SPK_L, reg);

	reg = TUNNING_SPKMIX_VOL;
	snd_soc_write(codec, M98095_052_MIX_SPK_CFG, reg);

	printk("\t[MAX98095] %s(%d)\n",__FUNCTION__,__LINE__);
	return;
}

//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
void max98095_set_playback_headset(struct snd_soc_codec *codec)
{
	int reg;
	
	// 0x92 Power DAC L/R, SPLEN
	reg = snd_soc_read(codec, M98095_091_PWR_EN_OUT);
	reg &= ~(M98095_DAREN|M98095_DALEN|M98095_DAMEN|M98095_RECEN|M98095_SPREN|M98095_SPLEN|M98095_HPREN|M98095_HPLEN);
	reg |= (M98095_DAREN|M98095_DALEN|M98095_HPREN|M98095_HPLEN);
	snd_soc_write(codec, M98095_091_PWR_EN_OUT, reg);

	// DAI1 L/R to L/R DAC
	reg = (M98095_DAI1R_TO_DACR|M98095_DAI1L_TO_DACL);
	snd_soc_write(codec, M98095_048_MIX_DAC_LR, reg);

	// DAC L/R to HP L/R
	reg = M98095_DACL_TO_HPL;
	snd_soc_write(codec, M98095_04C_MIX_HP_LEFT, reg);
	reg = M98095_DACR_TO_HPR;
	snd_soc_write(codec, M98095_04D_MIX_HP_RIGHT, reg);

	reg = TUNNING_DAI1_VOL;
	snd_soc_write(codec, M98095_058_LVL_DAI1_PLAY, reg);

	// HPMIX L/R to HP_AMP L/R
	reg = M98095_HPNORMAL;
	reg |= TUNNING_HPMIX_VOL;
	snd_soc_write(codec, M98095_04E_CFG_HP, reg);

	reg = TUNNING_HP_VOL;
	snd_soc_write(codec, M98095_064_LVL_HP_L, reg);
	snd_soc_write(codec, M98095_065_LVL_HP_R, reg);

	printk("\t[MAX98095] %s(%d)\n",__FUNCTION__,__LINE__);
	return;
}

//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
void max98095_set_playback_earpiece(struct snd_soc_codec *codec)
{
	int reg;
	
	// 0x92 Power DAC L/R, SPLEN
	reg = snd_soc_read(codec, M98095_091_PWR_EN_OUT);
	reg &= ~(M98095_DAREN|M98095_DALEN|M98095_DAMEN|M98095_RECEN|M98095_SPREN|M98095_SPLEN|M98095_HPREN|M98095_HPLEN);
	reg |= (M98095_DAREN|M98095_DALEN|M98095_RECEN);
	snd_soc_write(codec, M98095_091_PWR_EN_OUT, reg);

	// DAI1 L/R to L/R DAC
	reg = (M98095_DAI1R_TO_DACR|M98095_DAI1L_TO_DACL);
	snd_soc_write(codec, M98095_048_MIX_DAC_LR, reg);

	// DAC L/R to RCV
	reg = (M98095_DACL_TO_RCV|M98095_DACR_TO_RCV);
	snd_soc_write(codec, M98095_04F_MIX_RCV, reg);

	reg = TUNNING_DAI1_VOL;
	snd_soc_write(codec, M98095_058_LVL_DAI1_PLAY, reg);

	reg = TUNNING_RCV_VOL;
	snd_soc_write(codec, M98095_066_LVL_RCV, reg);

	printk("\t[MAX98095] %s(%d)\n",__FUNCTION__,__LINE__);
	return;
}

//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
void max98095_set_playback_speaker_headset(struct snd_soc_codec *codec)
{
	int reg;
	
	// 0x92 Power DAC L/R, SPLEN
	reg = snd_soc_read(codec, M98095_091_PWR_EN_OUT);
	reg &= ~(M98095_DAREN|M98095_DALEN|M98095_DAMEN|M98095_RECEN|M98095_SPREN|M98095_SPLEN|M98095_HPREN|M98095_HPLEN);
	reg |= (M98095_DAREN|M98095_DALEN|M98095_HPREN|M98095_HPLEN|M98095_SPREN|M98095_SPLEN|M98095_RECEN);
	snd_soc_write(codec, M98095_091_PWR_EN_OUT, reg);

	// DAI1 L/R to L/R DAC
	reg = (M98095_DAI1R_TO_DACR|M98095_DAI1L_TO_DACL);
	snd_soc_write(codec, M98095_048_MIX_DAC_LR, reg);

	// Stereo DAC to SPK_L, SPK_R Mute
	reg = M98095_DACL_TO_SPKL;
	snd_soc_write(codec, M98095_050_MIX_SPK_LEFT, reg);
	reg = M98095_DACR_TO_SPKR;
	snd_soc_write(codec, M98095_051_MIX_SPK_RIGHT, reg);

	// DAC L/R to HP L/R
	reg = (M98095_DACL_TO_RCV|M98095_DACR_TO_RCV);
	snd_soc_write(codec, M98095_04F_MIX_RCV, reg);

	// DAC L/R to HP L/R
	reg = M98095_DACL_TO_HPL;
	snd_soc_write(codec, M98095_04C_MIX_HP_LEFT, reg);
	reg = M98095_DACR_TO_HPR;
	snd_soc_write(codec, M98095_04D_MIX_HP_RIGHT, reg);

	reg = TUNNING_SPK_VOL;
	snd_soc_write(codec, M98095_058_LVL_DAI1_PLAY, reg);

	reg = TUNNING_SPK_VOL;
	snd_soc_write(codec, M98095_068_LVL_SPK_R, reg);
	snd_soc_write(codec, M98095_067_LVL_SPK_L, reg);

	reg = TUNNING_RCV_VOL;
	snd_soc_write(codec, M98095_066_LVL_RCV, reg);

	reg = TUNNING_SPKMIX_VOL;
	snd_soc_write(codec, M98095_052_MIX_SPK_CFG, reg);

	// HPMIX L/R to HP_AMP L/R
	reg = M98095_HPNORMAL;
	reg |= TUNNING_HPMIX_VOL;
	snd_soc_write(codec, M98095_04E_CFG_HP, reg);

	reg = TUNNING_HP_VOL;
	snd_soc_write(codec, M98095_064_LVL_HP_L, reg);
	snd_soc_write(codec, M98095_065_LVL_HP_R, reg);

	printk("\t[MAX98095] %s(%d)\n",__FUNCTION__,__LINE__);
	return;
}

//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
void max98095_disable_playback_path(struct snd_soc_codec *codec, enum playback_path path)
{

	int reg;
	
	reg = snd_soc_read(codec, M98095_091_PWR_EN_OUT);

	switch(path) {
		case REV : 
		case HP : 
				reg &= ~(M98095_HPREN|M98095_HPLEN);
			break;
		case SPK : 
				reg &= ~(M98095_SPREN|M98095_SPLEN);
			break;
		case SPK_HP :
				reg &= ~(M98095_HPREN|M98095_HPLEN | M98095_SPREN|M98095_SPLEN);
			break;
		case TV_OUT :
				reg &= ~(M98095_HPREN|M98095_HPLEN | M98095_HPREN|M98095_HPLEN);
			break;
		default :
			break;
	}
	snd_soc_write(codec, M98095_091_PWR_EN_OUT, reg);
	return;
}

//----------------------------------------------------------------------------------------
// recording function
//----------------------------------------------------------------------------------------
void max98095_set_record_main_mic(struct snd_soc_codec *codec)
{
	int reg;

	// 0x4C Mic bias, ADC L enable
//	reg = snd_soc_read(codec, M98095_090_PWR_EN_IN);
//	reg &= ~(M98095_MB1EN | M98095_MB2EN | M98095_INEN | M98095_ADREN | M98095_ADLEN);
//	reg |= (M98095_ADREN|M98095_ADLEN);
//	snd_soc_write(codec, M98095_090_PWR_EN_IN, reg);

	reg = snd_soc_read(codec, M98095_045_CFG_DSP);
	reg |= (1<<6); // DMIC CLK enable, DMIC CLK = MCLK/8
	snd_soc_write(codec, M98095_045_CFG_DSP, reg);
	
	reg = 0x04; // DMICL enable, EXTMIC disable
	snd_soc_write(codec, M98095_087_CFG_MIC, reg);

//	reg = 0x21;
//	snd_soc_write(codec, M98095_056_LVL_SIDETONE_DAI12, reg);

//	reg = (1<<7); // MIC1 to ADC L/R Mixer
//	snd_soc_write(codec, M98095_04A_MIX_ADC_LEFT, reg);
//	snd_soc_write(codec, M98095_04B_MIX_ADC_RIGHT, reg);
//
//	reg = 0x00; // AGC disable
//	snd_soc_write(codec, M98095_069_MICAGC_CFG, reg);
//	reg = 0x00; // Noisegate disable
//	snd_soc_write(codec, M98095_06A_MICAGC_THRESH, reg);

//	reg = TUNNING_MIC_PGA_GAIN;
//	snd_soc_write(codec, M98095_05F_LVL_MIC1, reg);

//	reg = 0x11;
//	snd_soc_write(codec, M98095_02F_DAI1_LVL1, reg);
//
//	reg = TUNNING_ADC_GAIN;
//	snd_soc_write(codec, M98095_05D_LVL_ADC_L, reg);
//	snd_soc_write(codec, M98095_05E_LVL_ADC_R, reg);

	printk("\t[MAX98095] %s(%d)\n",__FUNCTION__,__LINE__);
	return;
}

//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
void max98095_set_record_headset_mic(struct snd_soc_codec *codec)
{
	printk("\t[MAX98095] %s(%d)\n",__FUNCTION__,__LINE__);
	return;
}

//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
void max98095_disable_record_path(struct snd_soc_codec *codec, enum record_path rec_path)
{
	printk("\t[MAX98095] %s(%d)\n",__FUNCTION__,__LINE__);
	return;	
}