Skip to content

Commit

Permalink
fixor sound original commit by Zarboz
Browse files Browse the repository at this point in the history
  • Loading branch information
boss authored and boss committed Sep 2, 2013
1 parent 0ec0fe3 commit 4beb8d9
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 421 deletions.
44 changes: 20 additions & 24 deletions arch/arm/mach-msm/board-monarudo-audio.c
Expand Up @@ -14,21 +14,19 @@
*/

#include <linux/platform_device.h>
#include <mach/htc_acoustic_8960.h>
#include <sound/pcm.h>
#include <sound/q6asm.h>
#include <mach/htc_acoustic_8960.h>
#include <linux/module.h>
#include <linux/gpio.h>
#include "board-monarudo.h"
#include <mach/tpa6185.h>
#include <mach/rt5501.h>
#include "../sound/soc/msm/msm-pcm-routing.h"
#include "../sound/soc/msm/msm-compr-q6.h"
#define RCV_PAMP_GPIO 67

#include <linux/gpio.h>
#include <mach/tpa6185.h>
#include <mach/rt5501.h>
static atomic_t q6_effect_mode = ATOMIC_INIT(-1);
#define HAC_PAMP_GPIO 6
extern unsigned int system_rev;
extern unsigned int engineerid;

static int monarudo_get_hw_component(void)
{
Expand All @@ -38,7 +36,7 @@ static int monarudo_get_hw_component(void)
hw_com |= HTC_AUDIO_TPA6185;

if(query_rt5501())
hw_com |= HTC_AUDIO_RT5501;
hw_com |= HTC_AUDIO_RT5501;

return hw_com;
}
Expand All @@ -64,15 +62,10 @@ int apq8064_get_q6_effect_mode(void)
return mode;
}

int apq8064_get_24b_audio(void)
{
return 1;
}

static struct acoustic_ops acoustic = {
.enable_digital_mic = monarudo_enable_digital_mic,
.get_hw_component = monarudo_get_hw_component,
.set_q6_effect = apq8064_set_q6_effect_mode
.set_q6_effect = apq8064_set_q6_effect_mode,
};

static struct q6asm_ops qops = {
Expand All @@ -83,23 +76,26 @@ static struct msm_pcm_routing_ops rops = {
.get_q6_effect = apq8064_get_q6_effect_mode,
};

static struct msm_compr_q6_ops cops = {
.get_24b_audio = apq8064_get_24b_audio,
};


static int __init monarudo_audio_init(void)
{
int ret = 0;


gpio_request(RCV_PAMP_GPIO, "AUDIO_RCV_AMP");
gpio_tlmm_config(GPIO_CFG(67, 0, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), GPIO_CFG_DISABLE);
static uint32_t audio_i2s_table[] = {
GPIO_CFG(35, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA),
GPIO_CFG(36, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA),
GPIO_CFG(37, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA),
};
pr_info("%s", __func__);
gpio_request(HAC_PAMP_GPIO, "AUDIO_HAC_AMP");
gpio_direction_output(HAC_PAMP_GPIO, 0);
gpio_free(HAC_PAMP_GPIO);
gpio_tlmm_config(audio_i2s_table[0], GPIO_CFG_DISABLE);
gpio_tlmm_config(audio_i2s_table[1], GPIO_CFG_DISABLE);
gpio_tlmm_config(audio_i2s_table[2], GPIO_CFG_DISABLE);

htc_register_q6asm_ops(&qops);
htc_register_pcm_routing_ops(&rops);
htc_register_compr_q6_ops(&cops);
acoustic_register_ops(&acoustic);
pr_info("%s", __func__);
return ret;

}
Expand Down
87 changes: 33 additions & 54 deletions drivers/i2c/chips/rt5501.c
Expand Up @@ -51,13 +51,13 @@
#define RETRY_CNT 5

#define DRIVER_NAME "RT5501"
#define HS_IMP_WAKE_LOCK_TIMEOUT (1*HZ)

struct headset_query {
struct mutex mlock;
struct mutex gpiolock;
struct delayed_work hs_imp_detec_work;
struct wake_lock hs_wake_lock;
struct wake_lock gpio_wake_lock;
enum HEADSET_QUERY_STATUS hs_qstatus;
enum RT5501_STATUS rt5501_status;
enum HEADSET_OM headsetom;
Expand All @@ -74,13 +74,12 @@ struct headset_query {
static struct i2c_client *this_client;
static struct rt5501_platform_data *pdata;
static int rt5501Connect = 0;
static int MFG_MODE = 0;

struct rt5501_config_data rt5501_config_data;
static struct mutex hp_amp_lock;
static int rt5501_opened;
static int last_spkamp_state;
struct rt5501_config RT5501_AMP_ON = {6,{{0x1,0x1c},{0x2,0x00},{0x7,0x7f},{0x9,0x1},{0xa,0x0},{0xb,0xc7},}};
struct rt5501_config RT5501_AMP_ON = {6,{{0x1,0x22},{0x2,0x00},{0x7,0x7f},{0x9,0x1},{0xa,0x0},{0xb,0xc7},}};
struct rt5501_config RT5501_AMP_INIT = {11,{{0,0xc0},{0x81,0x30},{0x87,0xf6},{0x93,0x8d},{0x95,0x7d},{0xa4,0x52},\
{0x96,0xae},{0x97,0x13},{0x99,0x35},{0x9b,0x68},{0x9d,0x68},}};

Expand Down Expand Up @@ -167,7 +166,6 @@ static int rt5501_headset_detect(int on)
if(high_imp) {
rt5501_write_reg(1,0x7);
rt5501_write_reg(0xb1,0x81);

} else {
rt5501_write_reg(1,0xc7);

Expand Down Expand Up @@ -431,15 +429,13 @@ static int init_rt5501(void)
static void hs_imp_gpio_off(struct work_struct *work)
{
u64 timeout = get_jiffies_64() + 5*HZ;
wake_lock(&rt5501_query.gpio_wake_lock);

while(1) {
if(time_after64(get_jiffies_64(),timeout))
break;
else if(rt5501_query.gpio_off_cancel) {
wake_unlock(&rt5501_query.gpio_wake_lock);
else if(rt5501_query.gpio_off_cancel)
return;
} else
else
msleep(10);
}

Expand All @@ -454,7 +450,7 @@ static void hs_imp_gpio_off(struct work_struct *work)
}

mutex_unlock(&rt5501_query.gpiolock);
wake_unlock(&rt5501_query.gpio_wake_lock);

}

static void hs_imp_detec_func(struct work_struct *work)
Expand All @@ -466,7 +462,7 @@ static void hs_imp_detec_func(struct work_struct *work)
pr_info("%s: read rt5501 hs imp \n",__func__);

hs = container_of(work, struct headset_query, hs_imp_detec_work.work);
wake_lock(&hs->hs_wake_lock);
wake_lock_timeout(&hs->hs_wake_lock, HS_IMP_WAKE_LOCK_TIMEOUT);

rt5501_query.gpio_off_cancel = 1;
cancel_delayed_work_sync(&rt5501_query.gpio_off_work);
Expand All @@ -476,7 +472,6 @@ static void hs_imp_detec_func(struct work_struct *work)
if(hs->hs_qstatus != RT5501_QUERY_HEADSET) {
mutex_unlock(&hs->mlock);
mutex_unlock(&hs->gpiolock);
wake_unlock(&hs->hs_wake_lock);
return;
}

Expand Down Expand Up @@ -528,7 +523,6 @@ static void hs_imp_detec_func(struct work_struct *work)

mutex_unlock(&hs->mlock);
mutex_unlock(&hs->gpiolock);
wake_unlock(&hs->hs_wake_lock);
return;
}

Expand Down Expand Up @@ -645,52 +639,41 @@ static void hs_imp_detec_func(struct work_struct *work)
if(rt5501_status == RT5501_SUSPEND)
set_rt5501_amp(1);

wake_unlock(&hs->hs_wake_lock);
}

static void volume_ramp_func(struct work_struct *work)
{
mutex_lock(&rt5501_query.actionlock);
if(rt5501_query.rt5501_status != RT5501_PLAYBACK) {
u8 val;
pr_info("%s: ramping-------------------------\n",__func__);
mdelay(1);

if(high_imp)
rt5501_write_reg(0xb1,0x80);
if(rt5501_query.rt5501_status != RT5501_PLAYBACK) {
int i;
u8 val;
pr_info("%s: ramping-------------------------\n",__func__);
mdelay(1);

if(high_imp)
rt5501_write_reg(0xb1,0x80);

rt5501_write_reg(0x2,0x0);
mdelay(1);
val = 0x7;

rt5501_write_reg(0x2,0x0);
mdelay(1);
val = 0x7;

if (MFG_MODE) {
pr_info("Skip volume ramp for MFG build");
val += 15;
rt5501_write_reg(1,val);
} else {
#if 1
int i;
for(i=0; i<15; i++) {
if(!rt5501_query.action_on) {
mutex_unlock(&rt5501_query.actionlock);
return;
}
msleep(1);
rt5501_write_reg(1,val);
val++;
}
for(i=0; i<15; i++) {
msleep(1);
rt5501_write_reg(1,val);
val++;
}
#else
for(i=0; i<8; i++) {
msleep(10);
rt5501_write_reg(1,val);
val += 2;
}
for(i=0; i<8; i++) {
msleep(10);
rt5501_write_reg(1,val);
val += 2;
}

#endif
}
}
}

set_amp(1, &RT5501_AMP_ON);
set_amp(1, &RT5501_AMP_ON);
mutex_unlock(&rt5501_query.actionlock);
}

Expand Down Expand Up @@ -739,12 +722,8 @@ int query_rt5501(void)

void set_rt5501_amp(int on)
{
pr_info("%s: %d\n", __func__, on);
rt5501_query.gpio_off_cancel = 1;
if(!on)
rt5501_query.action_on = 0;
cancel_delayed_work_sync(&rt5501_query.gpio_off_work);
cancel_delayed_work_sync(&rt5501_query.volume_ramp_work);
flush_work_sync(&rt5501_query.volume_ramp_work.work);
mutex_lock(&rt5501_query.gpiolock);

Expand All @@ -763,10 +742,11 @@ void set_rt5501_amp(int on)
rt5501_query.gpiostatus = AMP_GPIO_ON;
msleep(1);
}
rt5501_query.action_on = 1;

queue_delayed_work(ramp_wq, &rt5501_query.volume_ramp_work, msecs_to_jiffies(0));

} else {

set_amp(0, &RT5501_AMP_ON);
if((rt5501_query.gpiostatus == AMP_GPIO_ON) && pdata->gpio_rt5501_spk_en) {

Expand Down Expand Up @@ -957,7 +937,7 @@ int rt5501_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
int ret = 0;
int err = 0;
MFG_MODE = board_mfg_mode();

pdata = client->dev.platform_data;

if (pdata == NULL) {
Expand Down Expand Up @@ -1028,7 +1008,6 @@ int rt5501_probe(struct i2c_client *client, const struct i2c_device_id *id)
hs_wq = create_workqueue("rt5501_hsdetect");
INIT_DELAYED_WORK(&rt5501_query.hs_imp_detec_work,hs_imp_detec_func);
wake_lock_init(&rt5501_query.hs_wake_lock, WAKE_LOCK_SUSPEND, DRIVER_NAME);
wake_lock_init(&rt5501_query.gpio_wake_lock, WAKE_LOCK_SUSPEND, DRIVER_NAME);
ramp_wq = create_workqueue("rt5501_volume_ramp");
INIT_DELAYED_WORK(&rt5501_query.volume_ramp_work, volume_ramp_func);
gpio_wq = create_workqueue("rt5501_gpio_off");
Expand Down

0 comments on commit 4beb8d9

Please sign in to comment.