/
yusu_android_speaker.c
262 lines (225 loc) · 6.75 KB
/
yusu_android_speaker.c
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
/*****************************************************************************
* E X T E R N A L R E F E R E N C E S
******************************************************************************
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/device.h>
#include <linux/slab.h>
#include <linux/fs.h>
#include <linux/mm.h>
#include <linux/interrupt.h>
#include <linux/vmalloc.h>
#include <linux/platform_device.h>
#include <linux/miscdevice.h>
#include <linux/wait.h>
#include <linux/spinlock.h>
#include <linux/semaphore.h>
#include <asm/uaccess.h>
#include <linux/delay.h>
#include "yusu_android_speaker.h"
#include <mach/mt_gpio.h>
#include <mach/mt_typedefs.h>
/*****************************************************************************
* C O M P I L E R F L A G S
******************************************************************************
*/
//#define CONFIG_DEBUG_MSG
#ifdef CONFIG_DEBUG_MSG
#define PRINTK(format, args...) printk( KERN_EMERG format,##args )
#else
#define PRINTK(format, args...)
#endif
/*****************************************************************************
* C O N S T A N T S
******************************************************************************
*/
#define SPK_WARM_UP_TIME (10) //unit is ms
/*****************************************************************************
* D A T A T Y P E S
******************************************************************************
*/
static int Speaker_Volume=0;
static bool gsk_on=false; // speaker is open?
static bool gsk_resume=false;
static bool gsk_forceon=false;
/*****************************************************************************
* F U N C T I O N D E F I N I T I O N
******************************************************************************
*/
extern void Yusu_Sound_AMP_Switch(BOOL enable);
bool Speaker_Init(void)
{
PRINTK("+Speaker_Init Success");
#ifndef LENOVO_NXP_SMARTPA_SUPPORT
mt_set_gpio_mode(GPIO_SPEAKER_EN_PIN,GPIO_MODE_00); // gpio mode
mt_set_gpio_pull_enable(GPIO_SPEAKER_EN_PIN,GPIO_PULL_ENABLE);
#endif
/* lenovo-sw zhouwl, 2014-01-08, use headphone pa for handset */
#if defined(LENOVO_USE_HP_CODEC) //sofina
mt_set_gpio_mode(GPIO_HPPA_EN_PIN,GPIO_MODE_00); // gpio mode
mt_set_gpio_pull_enable(GPIO_HPPA_EN_PIN,GPIO_PULL_ENABLE);
#endif
/* lenovo-sw zhouwl, 2014-01-08, use headphone pa for handset */
#if defined(DUAL_SPEAKER_SUPPORT)
mt_set_gpio_mode(GPIO_SPEAKER2_EN_PIN,GPIO_MODE_00); // gpio mode
mt_set_gpio_pull_enable(GPIO_SPEAKER2_EN_PIN,GPIO_PULL_ENABLE);
#endif
#if defined(LENOVO_USE_HPTPA6136_CODEC)
mt_set_gpio_mode(GPIO_HPTPA6136_HI_Z_PIN,GPIO_MODE_00); // gpio mode
mt_set_gpio_pull_enable(GPIO_HPTPA6136_HI_Z_PIN,GPIO_PULL_ENABLE);
mt_set_gpio_mode(GPIO_HPTPA6136_GAIN_PIN,GPIO_MODE_00); // gpio mode
mt_set_gpio_pull_enable(GPIO_HPTPA6136_GAIN_PIN,GPIO_PULL_ENABLE);
mt_set_gpio_mode(GPIO_HPTPA6136_SDB_PIN,GPIO_MODE_00); // gpio mode
mt_set_gpio_pull_enable(GPIO_HPTPA6136_SDB_PIN,GPIO_PULL_ENABLE);
#endif
PRINTK("-Speaker_Init Success");
return true;
}
bool Speaker_Register(void)
{
return false;
}
int ExternalAmp(void)
{
return 0;
}
bool Speaker_DeInit(void)
{
return false;
}
void Sound_SpeakerL_SetVolLevel(int level)
{
PRINTK(" Sound_SpeakerL_SetVolLevel level=%d\n",level);
}
void Sound_SpeakerR_SetVolLevel(int level)
{
PRINTK(" Sound_SpeakerR_SetVolLevel level=%d\n",level);
}
void Sound_Speaker_Turnon(int channel)
{
PRINTK("Sound_Speaker_Turnon channel = %d\n",channel);
if(gsk_on)
return;
#if (defined(DRC_2_0_SPK_EARPHONE_SUPPORT))/*scofield */ || (defined(DRC_2_0_HEADSET_SUPPORT) && defined(DRC_2_0_EARPHONE_SUPPORT)) /*scofield_row*/
mt_set_gpio_dir(GPIO_SPEAKER_EN_PIN,GPIO_DIR_OUT); // output
mt_set_gpio_out(GPIO_SPEAKER_EN_PIN,GPIO_OUT_ONE); // high
udelay(2);
mt_set_gpio_out(GPIO_SPEAKER_EN_PIN,GPIO_OUT_ZERO); //low
udelay(2);
mt_set_gpio_out(GPIO_SPEAKER_EN_PIN,GPIO_OUT_ONE); // high
#else
#ifndef LENOVO_NXP_SMARTPA_SUPPORT
mt_set_gpio_dir(GPIO_SPEAKER_EN_PIN,GPIO_DIR_OUT); // output
mt_set_gpio_out(GPIO_SPEAKER_EN_PIN,GPIO_OUT_ONE); // high
#endif
#endif
#if defined(DUAL_SPEAKER_SUPPORT)
mt_set_gpio_dir(GPIO_SPEAKER2_EN_PIN,GPIO_DIR_OUT); // output
mt_set_gpio_out(GPIO_SPEAKER2_EN_PIN,GPIO_OUT_ONE); // high
#endif
msleep(25);
gsk_on = true;
}
void Sound_Speaker_Turnoff(int channel)
{
PRINTK("Sound_Speaker_Turnoff channel = %d\n",channel);
if(!gsk_on)
return;
msleep(25);
#ifndef LENOVO_NXP_SMARTPA_SUPPORT
mt_set_gpio_dir(GPIO_SPEAKER_EN_PIN,GPIO_DIR_OUT); // output
mt_set_gpio_out(GPIO_SPEAKER_EN_PIN,GPIO_OUT_ZERO); // high
#endif
#if defined(DUAL_SPEAKER_SUPPORT)
mt_set_gpio_dir(GPIO_SPEAKER2_EN_PIN,GPIO_DIR_OUT); // output
mt_set_gpio_out(GPIO_SPEAKER2_EN_PIN,GPIO_OUT_ZERO); // low
#endif
msleep(25);
gsk_on = false;
}
void Sound_Speaker_SetVolLevel(int level)
{
Speaker_Volume =level;
}
void Sound_Headset_Turnon(void)
{
}
void Sound_Headset_Turnoff(void)
{
}
//kernal use
void AudioAMPDevice_Suspend(void)
{
PRINTK("AudioDevice_Suspend\n");
if(gsk_on)
{
Sound_Speaker_Turnoff(Channel_Stereo);
gsk_resume = true;
}
}
void AudioAMPDevice_Resume(void)
{
PRINTK("AudioDevice_Resume\n");
if(gsk_resume)
Sound_Speaker_Turnon(Channel_Stereo);
gsk_resume = false;
}
void AudioAMPDevice_SpeakerLouderOpen(void)
{
PRINTK("AudioDevice_SpeakerLouderOpen\n");
gsk_forceon = false;
if(gsk_on)
return;
Sound_Speaker_Turnon(Channel_Stereo);
gsk_forceon = true;
return ;
}
void AudioAMPDevice_SpeakerLouderClose(void)
{
PRINTK("AudioDevice_SpeakerLouderClose\n");
if(gsk_forceon)
Sound_Speaker_Turnoff(Channel_Stereo);
gsk_forceon = false;
}
void AudioAMPDevice_mute(void)
{
PRINTK("AudioDevice_mute\n");
if(gsk_on)
Sound_Speaker_Turnoff(Channel_Stereo);
}
int Audio_eamp_command(unsigned int type, unsigned long args, unsigned int count)
{
return 0;
}
static char *ExtFunArray[] =
{
"InfoMATVAudioStart",
"InfoMATVAudioStop",
"End",
};
kal_int32 Sound_ExtFunction(const char* name, void* param, int param_size)
{
int i = 0;
int funNum = -1;
//Search the supported function defined in ExtFunArray
while(strcmp("End",ExtFunArray[i]) != 0 ) { //while function not equal to "End"
if (strcmp(name,ExtFunArray[i]) == 0 ) { //When function name equal to table, break
funNum = i;
break;
}
i++;
}
switch (funNum) {
case 0: //InfoMATVAudioStart
printk("RunExtFunction InfoMATVAudioStart \n");
break;
case 1: //InfoMATVAudioStop
printk("RunExtFunction InfoMATVAudioStop \n");
break;
default:
break;
}
return 1;
}