Example #1
0
static int aml_asoc_init(struct snd_soc_pcm_runtime *rtd)
{
	struct snd_soc_card *card = rtd->card;
    struct snd_soc_codec *codec = rtd->codec;
    //struct snd_soc_dai *codec_dai = rtd->codec_dai;
    struct snd_soc_dapm_context *dapm = &codec->dapm;
	struct aml_audio_private_data * p_aml_audio;
    int ret = 0;
	
    printk(KERN_DEBUG "enter %s \n", __func__);
	p_aml_audio = snd_soc_card_get_drvdata(card);

    /* Add specific widgets */
    snd_soc_dapm_new_controls(dapm, aml_asoc_dapm_widgets,
                  ARRAY_SIZE(aml_asoc_dapm_widgets));
    ret = snd_soc_jack_new(codec, "hp switch", SND_JACK_HEADPHONE, &p_aml_audio->jack);
    if (ret) {
        printk(KERN_WARNING "Failed to alloc resource for hp switch\n");
    } else {
        ret = snd_soc_jack_add_pins(&p_aml_audio->jack, ARRAY_SIZE(jack_pins), jack_pins);
        if (ret) {
            printk(KERN_WARNING "Failed to setup hp pins\n");
        }
    }
#if HP_IRQ	
	p_aml_audio->gpio_hp_det = of_get_named_gpio(card->dev->of_node,"rt5631_gpio",0);

	if (gpio_is_valid(p_aml_audio->gpio_hp_det)) {
		aml_audio_hp_jack_gpio.gpio = p_aml_audio->gpio_hp_det;
		snd_soc_jack_add_gpios(&p_aml_audio->jack,
						1, &aml_audio_hp_jack_gpio);
	}
#endif
#if HP_DET
    init_timer(&p_aml_audio->timer);
    p_aml_audio->timer.function = aml_asoc_timer_func;
    p_aml_audio->timer.data = (unsigned long)p_aml_audio;
    p_aml_audio->data= (void*)card;

    INIT_WORK(&p_aml_audio->work, aml_asoc_work_func);
    mutex_init(&p_aml_audio->lock);

    mutex_lock(&p_aml_audio->lock);
    if (!p_aml_audio->timer_en) {
        aml_audio_start_timer(p_aml_audio, msecs_to_jiffies(100));
    }
    mutex_unlock(&p_aml_audio->lock);

#endif

    return 0;
}
Example #2
0
static int aml_asoc_init(struct snd_soc_pcm_runtime *rtd)
{
    struct snd_soc_card *card = rtd->card;
    struct snd_soc_codec *codec = rtd->codec;
    struct snd_soc_dapm_context *dapm = &codec->dapm;
    struct aml_audio_private_data * p_aml_audio;
    int ret = 0;
    int hp_paraments[5];

    printk(KERN_DEBUG "enter %s \n", __func__);
    p_aml_audio = snd_soc_card_get_drvdata(card);

    ret = snd_soc_add_card_controls(codec->card, aml_m8_controls,
                ARRAY_SIZE(aml_m8_controls));
    if (ret)
       return ret;

    /* Add specific widgets */
    snd_soc_dapm_new_controls(dapm, aml_asoc_dapm_widgets,
                  ARRAY_SIZE(aml_asoc_dapm_widgets));
    if (ret)
        return ret;

#if HP_DET

    p_aml_audio->sdev.name = "h2w";//for report headphone to android
    ret = switch_dev_register(&p_aml_audio->sdev);
    if (ret < 0){
        printk(KERN_ERR "ASoC: register hp switch dev failed\n");
        return ret;
    }

    p_aml_audio->mic_sdev.name = "mic_dev";//for micphone detect
    ret = switch_dev_register(&p_aml_audio->mic_sdev);
    if (ret < 0){
        printk(KERN_ERR "ASoC: register mic switch dev failed\n");
        return ret;
    }

    ret = snd_soc_jack_new(codec, "hp switch", SND_JACK_HEADPHONE, &p_aml_audio->jack);
    if (ret < 0) {
        printk(KERN_WARNING "Failed to alloc resource for hp switch\n");
    } else {
        ret = snd_soc_jack_add_pins(&p_aml_audio->jack, ARRAY_SIZE(jack_pins), jack_pins);
        if (ret < 0) {
            printk(KERN_WARNING "Failed to setup hp pins\n");
        }
    }

    p_aml_audio->mic_det = of_property_read_bool(card->dev->of_node,"mic_det");

    printk("entern %s : mic_det=%d \n",__func__,p_aml_audio->mic_det);
    ret = of_property_read_u32_array(card->dev->of_node, "hp_paraments", &hp_paraments[0], 5);
    if(ret){
        printk("falied to get hp detect paraments from dts file\n");
    }else{
        p_aml_audio->hp_val_h  = hp_paraments[0];  // hp adc value higher base, hp unplugged
        p_aml_audio->hp_val_l  = hp_paraments[1];  // hp adc value low base, 3 section hp plugged.
        p_aml_audio->mic_val   = hp_paraments[2];  // hp adc value mic detect value.
        p_aml_audio->hp_detal  = hp_paraments[3];  // hp adc value test toerance
        p_aml_audio->hp_adc_ch = hp_paraments[4];  // get adc value from which adc port for hp detect

        printk("hp detect paraments: h=%d,l=%d,mic=%d,det=%d,ch=%d \n",p_aml_audio->hp_val_h,p_aml_audio->hp_val_l,
            p_aml_audio->mic_val,p_aml_audio->hp_detal,p_aml_audio->hp_adc_ch);
    }
    init_timer(&p_aml_audio->timer);
    p_aml_audio->timer.function = aml_asoc_timer_func;
    p_aml_audio->timer.data = (unsigned long)p_aml_audio;
    p_aml_audio->data= (void*)card;

    INIT_WORK(&p_aml_audio->work, aml_asoc_work_func);
    mutex_init(&p_aml_audio->lock);

    mutex_lock(&p_aml_audio->lock);
    if (!p_aml_audio->timer_en) {
        aml_audio_start_timer(p_aml_audio, msecs_to_jiffies(100));
    }
    mutex_unlock(&p_aml_audio->lock);

#endif

    return 0;
}
Example #3
0
static int aml_asoc_init(struct snd_soc_pcm_runtime *rtd)
{
    struct snd_soc_card *card = rtd->card;
    struct snd_soc_codec *codec = rtd->codec;
    //struct snd_soc_dai *codec_dai = rtd->codec_dai;
    struct snd_soc_dapm_context *dapm = &codec->dapm;
    struct aml_audio_private_data * p_aml_audio;
    int ret = 0;
    
    printk(KERN_DEBUG "enter %s \n", __func__);
    p_aml_audio = snd_soc_card_get_drvdata(card);

    /* Add specific widgets */
  //  snd_soc_dapm_new_controls(dapm, aml_asoc_dapm_widgets,
 //                ARRAY_SIZE(aml_asoc_dapm_widgets));
    /* set ADCLRC/GPIO1 Pin Function Select */
    snd_soc_update_bits(codec, WM8960_IFACE2, (1 << 6), (1 << 6));

    /* not connected */
    snd_soc_dapm_nc_pin(dapm, "LINPUT3");
    snd_soc_dapm_nc_pin(dapm, "RINPUT3");
    
    snd_soc_dapm_nc_pin(dapm, "OUT3");

    /* always connected */
    snd_soc_dapm_enable_pin(dapm, "Ext Spk");
    snd_soc_dapm_enable_pin(dapm, "Mic");

    /* disable connected */
    snd_soc_dapm_disable_pin(dapm, "HP");

    snd_soc_dapm_sync(dapm);
    ret = snd_soc_jack_new(codec, "hp switch", SND_JACK_HEADPHONE, &p_aml_audio->jack);
    if (ret) {
        printk(KERN_WARNING "Failed to alloc resource for hp switch\n");
    } else {
        ret = snd_soc_jack_add_pins(&p_aml_audio->jack, ARRAY_SIZE(jack_pins), jack_pins);
        if (ret) {
            printk(KERN_WARNING "Failed to setup hp pins\n");
        }
    }
#if HP_IRQ  
    p_aml_audio->gpio_hp_det = of_get_named_gpio(card->dev->of_node,"wm8960_gpio",0);

    if (gpio_is_valid(p_aml_audio->gpio_hp_det)) {
        aml_audio_hp_jack_gpio.gpio = p_aml_audio->gpio_hp_det;
        snd_soc_jack_add_gpios(&p_aml_audio->jack,
                        1, &aml_audio_hp_jack_gpio);
    }
#endif
#if HP_DET
    init_timer(&p_aml_audio->timer);
    p_aml_audio->timer.function = aml_asoc_timer_func;
    p_aml_audio->timer.data = (unsigned long)p_aml_audio;
    p_aml_audio->data= (void*)card;

    INIT_WORK(&p_aml_audio->work, aml_asoc_work_func);
    mutex_init(&p_aml_audio->lock);

    mutex_lock(&p_aml_audio->lock);
    if (!p_aml_audio->timer_en) {
        aml_audio_start_timer(p_aml_audio, msecs_to_jiffies(100));
    }
    mutex_unlock(&p_aml_audio->lock);

#endif

//p_aml_audio->dis_hp_det = of_property_read_bool(card->dev->of_node,"dis_hp_det");
     ret = of_property_read_u32(card->dev->of_node,"dis_hp_det",(u32 *)&p_aml_audio->dis_hp_det);
     printk("******p_aml_audio->dis_hp_det=%d***\n",p_aml_audio->dis_hp_det);
    if(ret){
        printk("don't find match dis_hp_det\n");
        goto out1;
    }
  
    if(!p_aml_audio->dis_hp_det){
        printk("****mm**p_aml_audio->dis_hp_det\n");
        //JD2 as headphone detect
        snd_soc_update_bits(codec,27, 0x008, 0x008);// OUT3 buffer Enabled and disabled with HPL and HPR jack detect              
        //INSERT_DELAY    [1] 
        mdelay(1);      
        ///GPIO1 output the "jack detect output"
        snd_soc_update_bits(codec,48, 0x03A, 0x03A);// JD2 used for Jack Detect Input, GPIO function = jack detect output 

        snd_soc_update_bits(codec,24, 0x040, 0x040);// HPDETECT LOW = Speaker 
    
        snd_soc_update_bits(codec, 23, 0x1D1, 0x1D1);
        mdelay(500);

    }
out1:    
   
    return 0;
}