Skip to content

File tree

1 file changed

+213
-0
lines changed

1 file changed

+213
-0
lines changed
Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
/*****************************************************************************
2+
* E X T E R N A L R E F E R E N C E S
3+
******************************************************************************
4+
*/
5+
#include <linux/delay.h>
6+
#include "yusu_android_speaker.h"
7+
8+
#if defined(MT6575)
9+
#include <mach/mt_gpio.h>
10+
#include <mach/mt_typedefs.h>
11+
#include <mach/mt_clock_manager.h>
12+
#include <mach/mt_pmic_feature_api.h>
13+
#include <linux/pmic6326_sw.h>
14+
15+
#elif defined(MT6577)
16+
#include <mach/mt_gpio.h>
17+
#include <mach/mt_typedefs.h>
18+
#include <mach/mt_clock_manager.h>
19+
#include <mach/mt_pmic_feature_api.h>
20+
#include <linux/pmic6326_sw.h>
21+
22+
#elif defined(MT6589)
23+
#include <mach/mt_gpio.h>
24+
#include <mach/mt_typedefs.h>
25+
#endif
26+
27+
/*****************************************************************************
28+
* C O M P I L E R F L A G S
29+
******************************************************************************
30+
*/
31+
//#define CONFIG_DEBUG_MSG
32+
#ifdef CONFIG_DEBUG_MSG
33+
#define PRINTK(format, args...) printk( KERN_DEBUG format,##args )
34+
#else
35+
#define PRINTK(format, args...)
36+
#endif
37+
38+
/*****************************************************************************
39+
* C O N S T A N T S
40+
******************************************************************************
41+
*/
42+
#define SPK_WARM_UP_TIME (40) //unit is ms
43+
// SN2415B takes SPK_SHUTDOWN_TIME ms to transfer from shutdown state to operation state
44+
#define SPK_SHUTDOWN_TIME (80) //unit is ms
45+
46+
/*****************************************************************************
47+
* D A T A T Y P E S
48+
******************************************************************************
49+
*/
50+
static bool gsk_on = false;
51+
static bool gsk_resume = false;
52+
static bool gsk_forceon = false;
53+
static bool g_receiver_on = false;
54+
static unsigned long long g_time_to_shutdown = 0;
55+
56+
/*****************************************************************************
57+
* F U N C T I O N D E F I N I T I O N
58+
******************************************************************************
59+
*/
60+
extern void Yusu_Sound_AMP_Switch(BOOL enable);
61+
62+
bool Speaker_Init(void)
63+
{
64+
PRINTK("+Speaker_Init Success\n");
65+
mt_set_gpio_mode(GPIO_SPEAKER_EN_PIN, GPIO_MODE_00);
66+
mt_set_gpio_pull_enable(GPIO_SPEAKER_EN_PIN, GPIO_PULL_ENABLE);
67+
mt_set_gpio_mode(GPIO_RECEIVER_EN_PIN, GPIO_MODE_00);
68+
mt_set_gpio_pull_enable(GPIO_RECEIVER_EN_PIN, GPIO_PULL_ENABLE);
69+
g_time_to_shutdown = 0;
70+
PRINTK("-Speaker_Init Success\n");
71+
return true;
72+
}
73+
74+
bool Speaker_Register(void)
75+
{
76+
return false;
77+
}
78+
79+
int ExternalAmp(void)
80+
{
81+
return 0;
82+
}
83+
84+
bool Speaker_DeInit(void)
85+
{
86+
return false;
87+
}
88+
89+
void Sound_SpeakerL_SetVolLevel(int level)
90+
{
91+
PRINTK("Sound_SpeakerL_SetVolLevel level=%d\n", level);
92+
}
93+
94+
void Sound_SpeakerR_SetVolLevel(int level)
95+
{
96+
PRINTK("Sound_SpeakerR_SetVolLevel level=%d\n", level);
97+
}
98+
99+
void Sound_Speaker_Turnon(int channel)
100+
{
101+
PRINTK("+Sound_Speaker_Turnon channel = %d\n", channel);
102+
if(!gsk_on) {
103+
// check if shutdown time expires
104+
unsigned long long time_to_operate = sched_clock();
105+
if (g_time_to_shutdown != 0 && time_to_operate > g_time_to_shutdown) {
106+
unsigned long long elapse_time = time_to_operate - g_time_to_shutdown;
107+
if (elapse_time < (SPK_SHUTDOWN_TIME * 1000000)) {
108+
unsigned long sleep_time = SPK_SHUTDOWN_TIME - ((unsigned long)elapse_time / 1000000);
109+
printk("Sound_Speaker_Turnon wait %lu ms for shutdown time expiration\n", sleep_time);
110+
msleep(sleep_time);
111+
}
112+
}
113+
mt_set_gpio_dir(GPIO_SPEAKER_EN_PIN, GPIO_DIR_OUT); // output
114+
mt_set_gpio_out(GPIO_SPEAKER_EN_PIN, GPIO_OUT_ONE); // high
115+
msleep(SPK_WARM_UP_TIME);
116+
gsk_on = true;
117+
}
118+
PRINTK("-Sound_Speaker_Turnon channel = %d\n", channel);
119+
}
120+
121+
void Sound_Speaker_Turnoff(int channel)
122+
{
123+
PRINTK("Sound_Speaker_Turnoff channel = %d\n", channel);
124+
if (gsk_on) {
125+
mt_set_gpio_dir(GPIO_SPEAKER_EN_PIN, GPIO_DIR_OUT); // output
126+
mt_set_gpio_out(GPIO_SPEAKER_EN_PIN, GPIO_OUT_ZERO); // low
127+
gsk_on = false;
128+
g_time_to_shutdown = sched_clock();
129+
}
130+
}
131+
132+
void Sound_Speaker_SetVolLevel(int level)
133+
{
134+
}
135+
136+
void Sound_Headset_Turnon(void)
137+
{
138+
}
139+
140+
void Sound_Headset_Turnoff(void)
141+
{
142+
}
143+
144+
void AudioAMPDevice_Suspend(void)
145+
{
146+
PRINTK("AudioDevice_Suspend\n");
147+
if(gsk_on) {
148+
Sound_Speaker_Turnoff(Channel_Stereo);
149+
gsk_resume = true;
150+
}
151+
}
152+
153+
void AudioAMPDevice_Resume(void)
154+
{
155+
PRINTK("AudioDevice_Resume\n");
156+
if(gsk_resume)
157+
Sound_Speaker_Turnon(Channel_Stereo);
158+
gsk_resume = false;
159+
}
160+
161+
void AudioAMPDevice_SpeakerLouderOpen(void)
162+
{
163+
PRINTK("AudioDevice_SpeakerLouderOpen\n");
164+
gsk_forceon = false;
165+
Sound_Speaker_Turnon(Channel_Stereo);
166+
gsk_forceon = true;
167+
}
168+
169+
void AudioAMPDevice_SpeakerLouderClose(void)
170+
{
171+
PRINTK("AudioDevice_SpeakerLouderClose\n");
172+
if(gsk_forceon)
173+
Sound_Speaker_Turnoff(Channel_Stereo);
174+
gsk_forceon = false;
175+
}
176+
177+
void AudioAMPDevice_mute(void)
178+
{
179+
PRINTK("AudioDevice_mute\n");
180+
if(gsk_on)
181+
Sound_Speaker_Turnoff(Channel_Stereo);
182+
}
183+
184+
int Audio_eamp_command(unsigned int type, unsigned long args, unsigned int count)
185+
{
186+
switch (type)
187+
{
188+
case EAMP_EARPIECE_OPEN:
189+
PRINTK("Audio_eamp_command EAMP_EARPIECE_OPEN\n");
190+
if (!g_receiver_on) {
191+
mt_set_gpio_dir(GPIO_RECEIVER_EN_PIN, GPIO_DIR_OUT);
192+
mt_set_gpio_out(GPIO_RECEIVER_EN_PIN, GPIO_OUT_ONE);
193+
g_receiver_on = true;
194+
}
195+
break;
196+
case EAMP_EARPIECE_CLOSE:
197+
PRINTK("Audio_eamp_command EAMP_EARPIECE_CLOSE\n");
198+
if (g_receiver_on) {
199+
mt_set_gpio_dir(GPIO_RECEIVER_EN_PIN, GPIO_DIR_OUT);
200+
mt_set_gpio_out(GPIO_RECEIVER_EN_PIN, GPIO_OUT_ZERO);
201+
g_receiver_on = false;
202+
}
203+
break;
204+
default:
205+
break;
206+
}
207+
return 0;
208+
}
209+
210+
kal_int32 Sound_ExtFunction(const char* name, void* param, int param_size)
211+
{
212+
return 1;
213+
}

0 commit comments

Comments
 (0)