Esempio n. 1
0
static int tegra_alc5623_init(struct snd_soc_pcm_runtime *rtd)
{
	struct snd_soc_codec *codec = rtd->codec;
	struct snd_soc_dapm_context *dapm = &codec->dapm;
	struct snd_soc_card *card = codec->card;
	struct tegra_alc5623 *machine = snd_soc_card_get_drvdata(card);
	struct tegra_alc5623_platform_data *pdata = machine->pdata;
	int ret, i;

	/* Add the controls used to route audio to bluetooth/voice */
	tegra_das_controls_init(codec);
	
	if (gpio_is_valid(pdata->gpio_spkr_en)) {
		ret = gpio_request(pdata->gpio_spkr_en, "spkr_en");
		if (ret) {
			dev_err(card->dev, "cannot get spkr_en gpio\n");
			return ret;
		}
		machine->gpio_requested |= GPIO_SPKR_EN;

		gpio_direction_output(pdata->gpio_spkr_en, 0);
	} else if(pdata->gpio_spkr_en == -2) {
          	snd_soc_update_bits(codec, ALC5623_GPIO_PIN_CONFIG,
                	ALC5623_GPIO_PIN_CONFIG_GPIO_CONF,
                        0);
	}

    if (gpio_is_valid(pdata->gpio_int_mic_en)) {
            ret = gpio_request(pdata->gpio_int_mic_en, "int_mic_en");
            if (ret) {
                    dev_err(card->dev, "cannot get int_mic_en gpio\n");
                    return ret;
            }
            machine->gpio_requested |= GPIO_INT_MIC_EN;

            /* Disable int mic; enable signal is active-high */
            gpio_direction_output(pdata->gpio_int_mic_en, 0);
    }

	ret = snd_soc_add_controls(codec, controls,
			ARRAY_SIZE(controls));

	if (ret < 0)
		return ret;

	snd_soc_dapm_new_controls(dapm, dapm_widgets,
			ARRAY_SIZE(dapm_widgets));

	snd_soc_dapm_add_routes(dapm, audio_map,
				ARRAY_SIZE(audio_map));


	if (gpio_is_valid(pdata->gpio_hp_det)) {
		tegra_alc5623_hp_jack_gpio.gpio = pdata->gpio_hp_det;
		snd_soc_jack_new(codec, "Headphone Jack", SND_JACK_HEADPHONE,
				&machine->tegra_jack);
#ifndef CONFIG_SWITCH
		snd_soc_jack_add_pins(&machine->tegra_jack,
					ARRAY_SIZE(tegra_alc5623_hp_jack_pins),
					tegra_alc5623_hp_jack_pins);
#else
		snd_soc_jack_notifier_register(&machine->tegra_jack,
					&tegra_alc5623_jack_detect_nb);
#endif
		snd_soc_jack_add_gpios(&machine->tegra_jack,
					1,
					&tegra_alc5623_hp_jack_gpio);
		machine->gpio_requested |= GPIO_HP_DET;
	}
	

	/* Set endpoints to not connected */
	for(i = 0; i < ARRAY_SIZE(nc_pins); i++) {
		snd_soc_dapm_nc_pin(dapm, nc_pins[i]);
	}

	/* Set endpoints to default off mode */
	snd_soc_dapm_enable_pin(dapm, "Channel Swap Detect");
	snd_soc_dapm_enable_pin(dapm, "Int Spk");
	snd_soc_dapm_enable_pin(dapm, "Int Mic");
	snd_soc_dapm_enable_pin(dapm, "FM Radio");
	snd_soc_dapm_disable_pin(dapm, "Headphone Jack");
	
	snd_soc_dapm_force_enable_pin(dapm, "Mic Bias1");
	
	ret = snd_soc_dapm_sync(dapm);
	if (ret) {
		dev_err(card->dev,"Failed to sync dapm\n");
		return ret;
	}

	return 0;
}
Esempio n. 2
0
static int tegra_codec_init(struct snd_soc_codec *codec)
{
	struct adam_audio_priv* ctx = codec->socdev->codec_data;
	int ret = 0;

	if (!ctx->init_done) {
		
		/* Get and enable the DAP clock */
		ctx->dap_mclk = tegra_das_get_dap_mclk();
		if (!ctx->dap_mclk) {
			pr_err("Failed to get dap mclk \n");
			return -ENODEV;
		}
		clk_enable(ctx->dap_mclk);

		/* Add the controls used to route audio to bluetooth/voice */
		tegra_das_controls_init(codec);
		
		/* Store the GPIO used to detect headphone */
		tegra_jack_gpios[0].gpio = ctx->gpio_hp_det;

		/* Add tegra specific widgets */
		snd_soc_dapm_new_controls(codec, tegra_dapm_widgets,
					ARRAY_SIZE(tegra_dapm_widgets));

#ifdef ADAM_MANUAL_CONTROL_OF_OUTPUTDEVICE
		/* Add specific adam controls */
		ret = snd_soc_add_controls(codec, tegra_controls,
					ARRAY_SIZE(tegra_controls));
		if (ret < 0) {
			pr_err("Failed to register controls\n");
			return ret;
		}
#endif
					
		/* Set up tegra specific audio path audio_map */
		snd_soc_dapm_add_routes(codec, audio_map,
					ARRAY_SIZE(audio_map));

		/* make sure to register the dapm widgets */
		snd_soc_dapm_new_widgets(codec);
					
		/* Set endpoints to not connected */
		snd_soc_dapm_nc_pin(codec, "LINEL");
		snd_soc_dapm_nc_pin(codec, "LINER");
		snd_soc_dapm_nc_pin(codec, "PHONEIN");
		snd_soc_dapm_nc_pin(codec, "MIC2");
		snd_soc_dapm_nc_pin(codec, "MONO");

		/* Set endpoints to default off mode */
		snd_soc_dapm_enable_pin(codec, "Internal Speaker");
		snd_soc_dapm_enable_pin(codec, "Internal Mic");
		snd_soc_dapm_disable_pin(codec, "Headphone Jack");
	
		ret = snd_soc_dapm_sync(codec);
		if (ret) {
			pr_err("Failed to sync\n");
			return ret;
		}

#ifndef ADAM_MANUAL_CONTROL_OF_OUTPUTDEVICE
		/* Headphone jack detection */		
		ret = snd_soc_jack_new(codec->socdev->card, "Headphone Jack", SND_JACK_HEADPHONE,
				 &ctx->tegra_jack);
		if (ret)
			return ret;
			 
		ret = snd_soc_jack_add_pins(&ctx->tegra_jack,
			      ARRAY_SIZE(tegra_jack_pins),
			      tegra_jack_pins);
		if (ret)
			return ret;
				  
		ret = snd_soc_jack_add_gpios(&ctx->tegra_jack,
			       ARRAY_SIZE(tegra_jack_gpios),
			       tegra_jack_gpios);
		if (ret)
			return ret;
#endif

		ctx->init_done = 1;
	}

	return ret;
}