All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ASoC: tegra: Add platform driver for rt5677 audio codec
@ 2014-12-23 19:29 Anatol Pomozov
  2014-12-23 19:36 ` Anatol Pomozov
  2014-12-26 16:38 ` Mark Brown
  0 siblings, 2 replies; 16+ messages in thread
From: Anatol Pomozov @ 2014-12-23 19:29 UTC (permalink / raw)
  To: broonie, alsa-devel
  Cc: oder_chiou, swarren, Anatol Pomozov, bardliao, ldahan, dgreid

The driver supports NVIDIA Tegra Ryu board

Sponsored: Google ChromeOS
Signed-off-by: Anatol Pomozov <anatol.pomozov@gmail.com>
---
 .../bindings/sound/nvidia,tegra-audio-rt5677.txt   |  67 ++++
 sound/soc/tegra/Kconfig                            |  10 +
 sound/soc/tegra/Makefile                           |   2 +
 sound/soc/tegra/tegra_rt5677.c                     | 351 +++++++++++++++++++++
 4 files changed, 430 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/nvidia,tegra-audio-rt5677.txt
 create mode 100644 sound/soc/tegra/tegra_rt5677.c

diff --git a/Documentation/devicetree/bindings/sound/nvidia,tegra-audio-rt5677.txt b/Documentation/devicetree/bindings/sound/nvidia,tegra-audio-rt5677.txt
new file mode 100644
index 0000000..a4589cd
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/nvidia,tegra-audio-rt5677.txt
@@ -0,0 +1,67 @@
+NVIDIA Tegra audio complex, with RT5677 CODEC
+
+Required properties:
+- compatible : "nvidia,tegra-audio-rt5677"
+- clocks : Must contain an entry for each entry in clock-names.
+  See ../clocks/clock-bindings.txt for details.
+- clock-names : Must include the following entries:
+  - pll_a
+  - pll_a_out0
+  - mclk (The Tegra cdev1/extern1 clock, which feeds the CODEC's mclk)
+- nvidia,model : The user-visible name of this sound complex.
+- nvidia,audio-routing : A list of the connections between audio components.
+  Each entry is a pair of strings, the first being the connection's sink,
+  the second being the connection's source. Valid names for sources and
+  sinks are the RT5677's pins (as documented in its binding), and the jacks
+  on the board:
+
+  * Headphone
+  * Speaker
+  * Headset Mic
+  * Internal Mic 1
+  * Internal Mic 2
+
+- nvidia,i2s-controller : The phandle of the Tegra I2S controller that's
+  connected to the CODEC.
+- nvidia,audio-codec : The phandle of the RT5677 audio codec. This binding
+  assumes that AIF1 on the CODEC is connected to Tegra.
+
+Optional properties:
+- nvidia,hp-det-gpios : The GPIO that detects headphones are plugged in
+- nvidia,hp-en-gpios : The GPIO that enables headphone amplifier
+- nvidia,mic-present-gpios: The GPIO that mic jack is plugged in
+- nvidia,dmic-clk-en-gpios : The GPIO that gates DMIC clock signal
+
+Example:
+
+sound {
+	compatible = "nvidia,tegra-audio-rt5677-ryu",
+	        "nvidia,tegra-audio-rt5677";
+	nvidia,model = "NVIDIA Tegra Ryu";
+
+	nvidia,audio-routing =
+		"Headphone", "LOUT2",
+		"Headphone", "LOUT1",
+		"Headset Mic", "MICBIAS1",
+		"IN1P", "Headset Mic",
+		"IN1N", "Headset Mic",
+		"DMIC L1", "Internal Mic 1",
+		"DMIC R1", "Internal Mic 1",
+		"DMIC L2", "Internal Mic 2",
+		"DMIC R2", "Internal Mic 2",
+		"Speaker", "PDM1L",
+		"Speaker", "PDM1R";
+
+	nvidia,i2s-controller = <&tegra_i2s1>;
+	nvidia,audio-codec = <&rt5677>;
+
+	nvidia,hp-det-gpios = <&gpio TEGRA_GPIO(R, 7) GPIO_ACTIVE_HIGH>;
+	nvidia,mic-present-gpios = <&gpio TEGRA_GPIO(O, 5) GPIO_ACTIVE_LOW>;
+	nvidia,hp-en-gpios = <&rt5677 1 GPIO_ACTIVE_HIGH>;
+	nvidia,dmic-clk-en-gpios = <&rt5677 2 GPIO_ACTIVE_HIGH>;
+
+	clocks = <&tegra_car TEGRA124_CLK_PLL_A>,
+	         <&tegra_car TEGRA124_CLK_PLL_A_OUT0>,
+	         <&tegra_car TEGRA124_CLK_EXTERN1>;
+	clock-names = "pll_a", "pll_a_out0", "mclk";
+};
diff --git a/sound/soc/tegra/Kconfig b/sound/soc/tegra/Kconfig
index 31198cf7..a6768f8 100644
--- a/sound/soc/tegra/Kconfig
+++ b/sound/soc/tegra/Kconfig
@@ -128,3 +128,13 @@ config SND_SOC_TEGRA_MAX98090
 	help
 	  Say Y or M here if you want to add support for SoC audio on Tegra
 	  boards using the MAX98090 codec, such as Venice2.
+
+config SND_SOC_TEGRA_RT5677
+	tristate "SoC Audio support for Tegra boards using a RT5677 codec"
+	depends on SND_SOC_TEGRA && I2C && GPIOLIB
+	select SND_SOC_TEGRA20_I2S if ARCH_TEGRA_2x_SOC
+	select SND_SOC_TEGRA30_I2S if ARCH_TEGRA_3x_SOC
+	select SND_SOC_RT5677
+	help
+	  Say Y or M here if you want to add support for SoC audio on Tegra
+	  boards using the RT5677 codec, such as Ryu.
diff --git a/sound/soc/tegra/Makefile b/sound/soc/tegra/Makefile
index 5ae588c..9171655 100644
--- a/sound/soc/tegra/Makefile
+++ b/sound/soc/tegra/Makefile
@@ -19,6 +19,7 @@ obj-$(CONFIG_SND_SOC_TEGRA30_I2S) += snd-soc-tegra30-i2s.o
 
 # Tegra machine Support
 snd-soc-tegra-rt5640-objs := tegra_rt5640.o
+snd-soc-tegra-rt5677-objs := tegra_rt5677.o
 snd-soc-tegra-wm8753-objs := tegra_wm8753.o
 snd-soc-tegra-wm8903-objs := tegra_wm8903.o
 snd-soc-tegra-wm9712-objs := tegra_wm9712.o
@@ -27,6 +28,7 @@ snd-soc-tegra-alc5632-objs := tegra_alc5632.o
 snd-soc-tegra-max98090-objs := tegra_max98090.o
 
 obj-$(CONFIG_SND_SOC_TEGRA_RT5640) += snd-soc-tegra-rt5640.o
+obj-$(CONFIG_SND_SOC_TEGRA_RT5677) += snd-soc-tegra-rt5677.o
 obj-$(CONFIG_SND_SOC_TEGRA_WM8753) += snd-soc-tegra-wm8753.o
 obj-$(CONFIG_SND_SOC_TEGRA_WM8903) += snd-soc-tegra-wm8903.o
 obj-$(CONFIG_SND_SOC_TEGRA_WM9712) += snd-soc-tegra-wm9712.o
diff --git a/sound/soc/tegra/tegra_rt5677.c b/sound/soc/tegra/tegra_rt5677.c
new file mode 100644
index 0000000..6e98d10
--- /dev/null
+++ b/sound/soc/tegra/tegra_rt5677.c
@@ -0,0 +1,351 @@
+/*
+* tegra_rt5677.c - Tegra machine ASoC driver for boards using RT5677 codec.
+ *
+ * Copyright (c) 2014, The Chromium OS Authors.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Based on code copyright/by:
+ *
+ * Copyright (C) 2010-2012 - NVIDIA, Inc.
+ * Copyright (C) 2011 The AC100 Kernel Team <ac100@lists.lauchpad.net>
+ * (c) 2009, 2010 Nvidia Graphics Pvt. Ltd.
+ * Copyright 2007 Wolfson Microelectronics PLC.
+ */
+
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/gpio.h>
+#include <linux/of_gpio.h>
+
+#include <sound/core.h>
+#include <sound/jack.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/soc.h>
+
+#include "../codecs/rt5677.h"
+
+#include "tegra_asoc_utils.h"
+
+#define DRV_NAME "tegra-snd-rt5677"
+
+struct tegra_rt5677 {
+	struct tegra_asoc_utils_data util_data;
+	int gpio_hp_det;
+	int gpio_hp_en;
+	int gpio_mic_present;
+	int gpio_dmic_clk_en;
+};
+
+static int tegra_rt5677_asoc_hw_params(struct snd_pcm_substream *substream,
+					struct snd_pcm_hw_params *params)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct snd_soc_dai *codec_dai = rtd->codec_dai;
+	struct snd_soc_card *card = rtd->card;
+	struct tegra_rt5677 *machine = snd_soc_card_get_drvdata(card);
+	int srate, mclk, err;
+
+	srate = params_rate(params);
+	mclk = 256 * srate;
+
+	err = tegra_asoc_utils_set_rate(&machine->util_data, srate, mclk);
+	if (err < 0) {
+		dev_err(card->dev, "Can't configure clocks\n");
+		return err;
+	}
+
+	err = snd_soc_dai_set_sysclk(codec_dai, RT5677_SCLK_S_MCLK, mclk,
+					SND_SOC_CLOCK_IN);
+	if (err < 0) {
+		dev_err(card->dev, "codec_dai clock not set\n");
+		return err;
+	}
+
+	return 0;
+}
+
+static int tegra_rt5677_event_hp(struct snd_soc_dapm_widget *w,
+			struct snd_kcontrol *k, int event)
+{
+	struct snd_soc_dapm_context *dapm = w->dapm;
+	struct snd_soc_card *card = dapm->card;
+	struct tegra_rt5677 *machine = snd_soc_card_get_drvdata(card);
+
+	if (!gpio_is_valid(machine->gpio_hp_en))
+		return 0;
+
+	gpio_set_value_cansleep(machine->gpio_hp_en,
+		SND_SOC_DAPM_EVENT_ON(event));
+
+	return 0;
+}
+
+static struct snd_soc_ops tegra_rt5677_ops = {
+	.hw_params = tegra_rt5677_asoc_hw_params,
+};
+
+static struct snd_soc_jack tegra_rt5677_hp_jack;
+
+static struct snd_soc_jack_pin tegra_rt5677_hp_jack_pins = {
+	.pin = "Headphone",
+	.mask = SND_JACK_HEADPHONE,
+};
+static struct snd_soc_jack_gpio tegra_rt5677_hp_jack_gpio = {
+	.name = "Headphone detection",
+	.report = SND_JACK_HEADPHONE,
+	.debounce_time = 150,
+};
+
+static struct snd_soc_jack tegra_rt5677_mic_jack;
+
+static struct snd_soc_jack_pin tegra_rt5677_mic_jack_pins = {
+	.pin = "Headset Mic",
+	.mask = SND_JACK_MICROPHONE,
+};
+
+static struct snd_soc_jack_gpio tegra_rt5677_mic_jack_gpio = {
+	.name = "Headset Mic detection",
+	.report = SND_JACK_MICROPHONE,
+	.debounce_time = 150,
+	.invert = 1
+};
+
+static const struct snd_soc_dapm_widget tegra_rt5677_dapm_widgets[] = {
+	SND_SOC_DAPM_SPK("Speaker", NULL),
+	SND_SOC_DAPM_HP("Headphone", tegra_rt5677_event_hp),
+	SND_SOC_DAPM_MIC("Headset Mic", NULL),
+	SND_SOC_DAPM_MIC("Internal Mic 1", NULL),
+	SND_SOC_DAPM_MIC("Internal Mic 2", NULL),
+};
+
+static const struct snd_kcontrol_new tegra_rt5677_controls[] = {
+	SOC_DAPM_PIN_SWITCH("Speaker"),
+	SOC_DAPM_PIN_SWITCH("Headphone"),
+	SOC_DAPM_PIN_SWITCH("Headset Mic"),
+	SOC_DAPM_PIN_SWITCH("Internal Mic 1"),
+	SOC_DAPM_PIN_SWITCH("Internal Mic 2"),
+};
+
+static int tegra_rt5677_asoc_init(struct snd_soc_pcm_runtime *rtd)
+{
+	struct snd_soc_dai *codec_dai = rtd->codec_dai;
+	struct snd_soc_codec *codec = codec_dai->codec;
+	struct snd_soc_dapm_context *dapm = &codec->dapm;
+	struct tegra_rt5677 *machine = snd_soc_card_get_drvdata(rtd->card);
+
+	snd_soc_jack_new(codec, "Headphone Jack", SND_JACK_HEADPHONE,
+			&tegra_rt5677_hp_jack);
+	snd_soc_jack_add_pins(&tegra_rt5677_hp_jack, 1,
+			&tegra_rt5677_hp_jack_pins);
+
+	if (gpio_is_valid(machine->gpio_hp_det)) {
+		tegra_rt5677_hp_jack_gpio.gpio = machine->gpio_hp_det;
+		snd_soc_jack_add_gpios(&tegra_rt5677_hp_jack, 1,
+				&tegra_rt5677_hp_jack_gpio);
+	}
+
+
+	snd_soc_jack_new(codec, "Mic Jack", SND_JACK_MICROPHONE,
+			&tegra_rt5677_mic_jack);
+	snd_soc_jack_add_pins(&tegra_rt5677_mic_jack, 1,
+			&tegra_rt5677_mic_jack_pins);
+
+	if (gpio_is_valid(machine->gpio_mic_present)) {
+		tegra_rt5677_mic_jack_gpio.gpio = machine->gpio_mic_present;
+		snd_soc_jack_add_gpios(&tegra_rt5677_mic_jack, 1,
+				&tegra_rt5677_mic_jack_gpio);
+	}
+
+	snd_soc_dapm_force_enable_pin(dapm, "MICBIAS1");
+
+	return 0;
+}
+
+static int tegra_rt5677_card_remove(struct snd_soc_card *card)
+{
+	struct tegra_rt5677 *machine = snd_soc_card_get_drvdata(card);
+
+	if (gpio_is_valid(machine->gpio_hp_det)) {
+		snd_soc_jack_free_gpios(&tegra_rt5677_hp_jack, 1,
+				&tegra_rt5677_hp_jack_gpio);
+	}
+
+	if (gpio_is_valid(machine->gpio_mic_present)) {
+		snd_soc_jack_free_gpios(&tegra_rt5677_mic_jack, 1,
+				&tegra_rt5677_mic_jack_gpio);
+	}
+
+	return 0;
+}
+
+static struct snd_soc_dai_link tegra_rt5677_dai = {
+	.name = "RT5677",
+	.stream_name = "RT5677 PCM",
+	.codec_dai_name = "rt5677-aif1",
+	.init = tegra_rt5677_asoc_init,
+	.ops = &tegra_rt5677_ops,
+	.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
+			SND_SOC_DAIFMT_CBS_CFS,
+};
+
+static struct snd_soc_card snd_soc_tegra_rt5677 = {
+	.name = "tegra-rt5677",
+	.owner = THIS_MODULE,
+	.remove = tegra_rt5677_card_remove,
+	.dai_link = &tegra_rt5677_dai,
+	.num_links = 1,
+	.controls = tegra_rt5677_controls,
+	.num_controls = ARRAY_SIZE(tegra_rt5677_controls),
+	.dapm_widgets = tegra_rt5677_dapm_widgets,
+	.num_dapm_widgets = ARRAY_SIZE(tegra_rt5677_dapm_widgets),
+	.fully_routed = true,
+};
+
+static int tegra_rt5677_probe(struct platform_device *pdev)
+{
+	struct device_node *np = pdev->dev.of_node;
+	struct snd_soc_card *card = &snd_soc_tegra_rt5677;
+	struct tegra_rt5677 *machine;
+	int ret;
+
+#if defined(CONFIG_MODULES) && defined(MODULE)
+	request_module("snd_soc_tegra30_i2s");
+#endif
+
+	machine = devm_kzalloc(&pdev->dev,
+			sizeof(struct tegra_rt5677), GFP_KERNEL);
+	if (!machine)
+		return -ENOMEM;
+
+	card->dev = &pdev->dev;
+	platform_set_drvdata(pdev, card);
+	snd_soc_card_set_drvdata(card, machine);
+
+	machine->gpio_hp_det = of_get_named_gpio(np, "nvidia,hp-det-gpios", 0);
+	if (machine->gpio_hp_det == -EPROBE_DEFER)
+		return -EPROBE_DEFER;
+
+	machine->gpio_mic_present = of_get_named_gpio(np,
+			"nvidia,mic-present-gpios", 0);
+	if (machine->gpio_mic_present == -EPROBE_DEFER)
+		return -EPROBE_DEFER;
+
+	machine->gpio_hp_en = of_get_named_gpio(np, "nvidia,hp-en-gpios", 0);
+	if (machine->gpio_hp_en == -EPROBE_DEFER)
+		return -EPROBE_DEFER;
+	if (gpio_is_valid(machine->gpio_hp_en)) {
+		ret = devm_gpio_request_one(&pdev->dev, machine->gpio_hp_en,
+				GPIOF_OUT_INIT_LOW, "hp_en");
+		if (ret) {
+			dev_err(card->dev, "cannot get hp_en gpio\n");
+			return ret;
+		}
+	}
+
+	machine->gpio_dmic_clk_en = of_get_named_gpio(np,
+		"nvidia,dmic-clk-en-gpios", 0);
+	if (machine->gpio_dmic_clk_en == -EPROBE_DEFER)
+		return -EPROBE_DEFER;
+	if (gpio_is_valid(machine->gpio_dmic_clk_en)) {
+		ret = devm_gpio_request_one(&pdev->dev,
+				machine->gpio_dmic_clk_en,
+				GPIOF_OUT_INIT_HIGH, "dmic_clk_en");
+		if (ret) {
+			dev_err(card->dev, "cannot get dmic_clk_en gpio\n");
+			return ret;
+		}
+	}
+
+	ret = snd_soc_of_parse_card_name(card, "nvidia,model");
+	if (ret)
+		goto err;
+
+	ret = snd_soc_of_parse_audio_routing(card, "nvidia,audio-routing");
+	if (ret)
+		goto err;
+
+	tegra_rt5677_dai.codec_of_node = of_parse_phandle(np,
+			"nvidia,audio-codec", 0);
+	if (!tegra_rt5677_dai.codec_of_node) {
+		dev_err(&pdev->dev,
+			"Property 'nvidia,audio-codec' missing or invalid\n");
+		ret = -EINVAL;
+		goto err;
+	}
+
+	tegra_rt5677_dai.cpu_of_node = of_parse_phandle(np,
+			"nvidia,i2s-controller", 0);
+	if (!tegra_rt5677_dai.cpu_of_node) {
+		dev_err(&pdev->dev,
+			"Property 'nvidia,i2s-controller' missing or invalid\n");
+		ret = -EINVAL;
+		goto err;
+	}
+	tegra_rt5677_dai.platform_of_node = tegra_rt5677_dai.cpu_of_node;
+
+	ret = tegra_asoc_utils_init(&machine->util_data, &pdev->dev);
+	if (ret)
+		goto err;
+
+	ret = snd_soc_register_card(card);
+	if (ret) {
+		dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
+			ret);
+		goto err_fini_utils;
+	}
+
+	return 0;
+
+err_fini_utils:
+	tegra_asoc_utils_fini(&machine->util_data);
+err:
+	return ret;
+}
+
+static int tegra_rt5677_remove(struct platform_device *pdev)
+{
+	struct snd_soc_card *card = platform_get_drvdata(pdev);
+	struct tegra_rt5677 *machine = snd_soc_card_get_drvdata(card);
+
+	snd_soc_unregister_card(card);
+
+	tegra_asoc_utils_fini(&machine->util_data);
+
+	return 0;
+}
+
+static const struct of_device_id tegra_rt5677_of_match[] = {
+	{ .compatible = "nvidia,tegra-audio-rt5677", },
+	{},
+};
+
+static struct platform_driver tegra_rt5677_driver = {
+	.driver = {
+		.name = DRV_NAME,
+		.owner = THIS_MODULE,
+		.pm = &snd_soc_pm_ops,
+		.of_match_table = tegra_rt5677_of_match,
+	},
+	.probe = tegra_rt5677_probe,
+	.remove = tegra_rt5677_remove,
+};
+module_platform_driver(tegra_rt5677_driver);
+
+MODULE_AUTHOR("Anatol Pomozov <anatol@google.com>");
+MODULE_DESCRIPTION("Tegra+RT5677 machine ASoC driver");
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("platform:" DRV_NAME);
+MODULE_DEVICE_TABLE(of, tegra_rt5677_of_match);
-- 
2.2.0.rc0.207.ga3a616c

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH] ASoC: tegra: Add platform driver for rt5677 audio codec
  2014-12-23 19:29 [PATCH] ASoC: tegra: Add platform driver for rt5677 audio codec Anatol Pomozov
@ 2014-12-23 19:36 ` Anatol Pomozov
  2014-12-26 16:38 ` Mark Brown
  1 sibling, 0 replies; 16+ messages in thread
From: Anatol Pomozov @ 2014-12-23 19:36 UTC (permalink / raw)
  To: Mark Brown, alsa-devel
  Cc: Oder Chiou, Stephen Warren, Anatol Pomozov, Bard Liao,
	Laurent Dahan, Dylan Reid

Hi Mark

After thinking for a while we've decided to drop the speaker codec and
go with PDM speakers, thus we do not need speaker-codec property
anymore.

On Tue, Dec 23, 2014 at 11:29 AM, Anatol Pomozov
<anatol.pomozov@gmail.com> wrote:
> The driver supports NVIDIA Tegra Ryu board
>
> Sponsored: Google ChromeOS
> Signed-off-by: Anatol Pomozov <anatol.pomozov@gmail.com>
> ---
>  .../bindings/sound/nvidia,tegra-audio-rt5677.txt   |  67 ++++
>  sound/soc/tegra/Kconfig                            |  10 +
>  sound/soc/tegra/Makefile                           |   2 +
>  sound/soc/tegra/tegra_rt5677.c                     | 351 +++++++++++++++++++++
>  4 files changed, 430 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/sound/nvidia,tegra-audio-rt5677.txt
>  create mode 100644 sound/soc/tegra/tegra_rt5677.c
>
> diff --git a/Documentation/devicetree/bindings/sound/nvidia,tegra-audio-rt5677.txt b/Documentation/devicetree/bindings/sound/nvidia,tegra-audio-rt5677.txt
> new file mode 100644
> index 0000000..a4589cd
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/sound/nvidia,tegra-audio-rt5677.txt
> @@ -0,0 +1,67 @@
> +NVIDIA Tegra audio complex, with RT5677 CODEC
> +
> +Required properties:
> +- compatible : "nvidia,tegra-audio-rt5677"
> +- clocks : Must contain an entry for each entry in clock-names.
> +  See ../clocks/clock-bindings.txt for details.
> +- clock-names : Must include the following entries:
> +  - pll_a
> +  - pll_a_out0
> +  - mclk (The Tegra cdev1/extern1 clock, which feeds the CODEC's mclk)
> +- nvidia,model : The user-visible name of this sound complex.
> +- nvidia,audio-routing : A list of the connections between audio components.
> +  Each entry is a pair of strings, the first being the connection's sink,
> +  the second being the connection's source. Valid names for sources and
> +  sinks are the RT5677's pins (as documented in its binding), and the jacks
> +  on the board:
> +
> +  * Headphone
> +  * Speaker
> +  * Headset Mic
> +  * Internal Mic 1
> +  * Internal Mic 2
> +
> +- nvidia,i2s-controller : The phandle of the Tegra I2S controller that's
> +  connected to the CODEC.
> +- nvidia,audio-codec : The phandle of the RT5677 audio codec. This binding
> +  assumes that AIF1 on the CODEC is connected to Tegra.
> +
> +Optional properties:
> +- nvidia,hp-det-gpios : The GPIO that detects headphones are plugged in
> +- nvidia,hp-en-gpios : The GPIO that enables headphone amplifier
> +- nvidia,mic-present-gpios: The GPIO that mic jack is plugged in
> +- nvidia,dmic-clk-en-gpios : The GPIO that gates DMIC clock signal
> +
> +Example:
> +
> +sound {
> +       compatible = "nvidia,tegra-audio-rt5677-ryu",
> +               "nvidia,tegra-audio-rt5677";
> +       nvidia,model = "NVIDIA Tegra Ryu";
> +
> +       nvidia,audio-routing =
> +               "Headphone", "LOUT2",
> +               "Headphone", "LOUT1",
> +               "Headset Mic", "MICBIAS1",
> +               "IN1P", "Headset Mic",
> +               "IN1N", "Headset Mic",
> +               "DMIC L1", "Internal Mic 1",
> +               "DMIC R1", "Internal Mic 1",
> +               "DMIC L2", "Internal Mic 2",
> +               "DMIC R2", "Internal Mic 2",
> +               "Speaker", "PDM1L",
> +               "Speaker", "PDM1R";
> +
> +       nvidia,i2s-controller = <&tegra_i2s1>;
> +       nvidia,audio-codec = <&rt5677>;
> +
> +       nvidia,hp-det-gpios = <&gpio TEGRA_GPIO(R, 7) GPIO_ACTIVE_HIGH>;
> +       nvidia,mic-present-gpios = <&gpio TEGRA_GPIO(O, 5) GPIO_ACTIVE_LOW>;
> +       nvidia,hp-en-gpios = <&rt5677 1 GPIO_ACTIVE_HIGH>;
> +       nvidia,dmic-clk-en-gpios = <&rt5677 2 GPIO_ACTIVE_HIGH>;
> +
> +       clocks = <&tegra_car TEGRA124_CLK_PLL_A>,
> +                <&tegra_car TEGRA124_CLK_PLL_A_OUT0>,
> +                <&tegra_car TEGRA124_CLK_EXTERN1>;
> +       clock-names = "pll_a", "pll_a_out0", "mclk";
> +};
> diff --git a/sound/soc/tegra/Kconfig b/sound/soc/tegra/Kconfig
> index 31198cf7..a6768f8 100644
> --- a/sound/soc/tegra/Kconfig
> +++ b/sound/soc/tegra/Kconfig
> @@ -128,3 +128,13 @@ config SND_SOC_TEGRA_MAX98090
>         help
>           Say Y or M here if you want to add support for SoC audio on Tegra
>           boards using the MAX98090 codec, such as Venice2.
> +
> +config SND_SOC_TEGRA_RT5677
> +       tristate "SoC Audio support for Tegra boards using a RT5677 codec"
> +       depends on SND_SOC_TEGRA && I2C && GPIOLIB
> +       select SND_SOC_TEGRA20_I2S if ARCH_TEGRA_2x_SOC
> +       select SND_SOC_TEGRA30_I2S if ARCH_TEGRA_3x_SOC
> +       select SND_SOC_RT5677
> +       help
> +         Say Y or M here if you want to add support for SoC audio on Tegra
> +         boards using the RT5677 codec, such as Ryu.
> diff --git a/sound/soc/tegra/Makefile b/sound/soc/tegra/Makefile
> index 5ae588c..9171655 100644
> --- a/sound/soc/tegra/Makefile
> +++ b/sound/soc/tegra/Makefile
> @@ -19,6 +19,7 @@ obj-$(CONFIG_SND_SOC_TEGRA30_I2S) += snd-soc-tegra30-i2s.o
>
>  # Tegra machine Support
>  snd-soc-tegra-rt5640-objs := tegra_rt5640.o
> +snd-soc-tegra-rt5677-objs := tegra_rt5677.o
>  snd-soc-tegra-wm8753-objs := tegra_wm8753.o
>  snd-soc-tegra-wm8903-objs := tegra_wm8903.o
>  snd-soc-tegra-wm9712-objs := tegra_wm9712.o
> @@ -27,6 +28,7 @@ snd-soc-tegra-alc5632-objs := tegra_alc5632.o
>  snd-soc-tegra-max98090-objs := tegra_max98090.o
>
>  obj-$(CONFIG_SND_SOC_TEGRA_RT5640) += snd-soc-tegra-rt5640.o
> +obj-$(CONFIG_SND_SOC_TEGRA_RT5677) += snd-soc-tegra-rt5677.o
>  obj-$(CONFIG_SND_SOC_TEGRA_WM8753) += snd-soc-tegra-wm8753.o
>  obj-$(CONFIG_SND_SOC_TEGRA_WM8903) += snd-soc-tegra-wm8903.o
>  obj-$(CONFIG_SND_SOC_TEGRA_WM9712) += snd-soc-tegra-wm9712.o
> diff --git a/sound/soc/tegra/tegra_rt5677.c b/sound/soc/tegra/tegra_rt5677.c
> new file mode 100644
> index 0000000..6e98d10
> --- /dev/null
> +++ b/sound/soc/tegra/tegra_rt5677.c
> @@ -0,0 +1,351 @@
> +/*
> +* tegra_rt5677.c - Tegra machine ASoC driver for boards using RT5677 codec.
> + *
> + * Copyright (c) 2014, The Chromium OS Authors.  All rights reserved.
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms and conditions of the GNU General Public License,
> + * version 2, as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope it will be useful, but WITHOUT
> + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
> + * more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program.  If not, see <http://www.gnu.org/licenses/>.
> + *
> + * Based on code copyright/by:
> + *
> + * Copyright (C) 2010-2012 - NVIDIA, Inc.
> + * Copyright (C) 2011 The AC100 Kernel Team <ac100@lists.lauchpad.net>
> + * (c) 2009, 2010 Nvidia Graphics Pvt. Ltd.
> + * Copyright 2007 Wolfson Microelectronics PLC.
> + */
> +
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/slab.h>
> +#include <linux/gpio.h>
> +#include <linux/of_gpio.h>
> +
> +#include <sound/core.h>
> +#include <sound/jack.h>
> +#include <sound/pcm.h>
> +#include <sound/pcm_params.h>
> +#include <sound/soc.h>
> +
> +#include "../codecs/rt5677.h"
> +
> +#include "tegra_asoc_utils.h"
> +
> +#define DRV_NAME "tegra-snd-rt5677"
> +
> +struct tegra_rt5677 {
> +       struct tegra_asoc_utils_data util_data;
> +       int gpio_hp_det;
> +       int gpio_hp_en;
> +       int gpio_mic_present;
> +       int gpio_dmic_clk_en;
> +};
> +
> +static int tegra_rt5677_asoc_hw_params(struct snd_pcm_substream *substream,
> +                                       struct snd_pcm_hw_params *params)
> +{
> +       struct snd_soc_pcm_runtime *rtd = substream->private_data;
> +       struct snd_soc_dai *codec_dai = rtd->codec_dai;
> +       struct snd_soc_card *card = rtd->card;
> +       struct tegra_rt5677 *machine = snd_soc_card_get_drvdata(card);
> +       int srate, mclk, err;
> +
> +       srate = params_rate(params);
> +       mclk = 256 * srate;
> +
> +       err = tegra_asoc_utils_set_rate(&machine->util_data, srate, mclk);
> +       if (err < 0) {
> +               dev_err(card->dev, "Can't configure clocks\n");
> +               return err;
> +       }
> +
> +       err = snd_soc_dai_set_sysclk(codec_dai, RT5677_SCLK_S_MCLK, mclk,
> +                                       SND_SOC_CLOCK_IN);
> +       if (err < 0) {
> +               dev_err(card->dev, "codec_dai clock not set\n");
> +               return err;
> +       }
> +
> +       return 0;
> +}
> +
> +static int tegra_rt5677_event_hp(struct snd_soc_dapm_widget *w,
> +                       struct snd_kcontrol *k, int event)
> +{
> +       struct snd_soc_dapm_context *dapm = w->dapm;
> +       struct snd_soc_card *card = dapm->card;
> +       struct tegra_rt5677 *machine = snd_soc_card_get_drvdata(card);
> +
> +       if (!gpio_is_valid(machine->gpio_hp_en))
> +               return 0;
> +
> +       gpio_set_value_cansleep(machine->gpio_hp_en,
> +               SND_SOC_DAPM_EVENT_ON(event));
> +
> +       return 0;
> +}
> +
> +static struct snd_soc_ops tegra_rt5677_ops = {
> +       .hw_params = tegra_rt5677_asoc_hw_params,
> +};
> +
> +static struct snd_soc_jack tegra_rt5677_hp_jack;
> +
> +static struct snd_soc_jack_pin tegra_rt5677_hp_jack_pins = {
> +       .pin = "Headphone",
> +       .mask = SND_JACK_HEADPHONE,
> +};
> +static struct snd_soc_jack_gpio tegra_rt5677_hp_jack_gpio = {
> +       .name = "Headphone detection",
> +       .report = SND_JACK_HEADPHONE,
> +       .debounce_time = 150,
> +};
> +
> +static struct snd_soc_jack tegra_rt5677_mic_jack;
> +
> +static struct snd_soc_jack_pin tegra_rt5677_mic_jack_pins = {
> +       .pin = "Headset Mic",
> +       .mask = SND_JACK_MICROPHONE,
> +};
> +
> +static struct snd_soc_jack_gpio tegra_rt5677_mic_jack_gpio = {
> +       .name = "Headset Mic detection",
> +       .report = SND_JACK_MICROPHONE,
> +       .debounce_time = 150,
> +       .invert = 1
> +};
> +
> +static const struct snd_soc_dapm_widget tegra_rt5677_dapm_widgets[] = {
> +       SND_SOC_DAPM_SPK("Speaker", NULL),
> +       SND_SOC_DAPM_HP("Headphone", tegra_rt5677_event_hp),
> +       SND_SOC_DAPM_MIC("Headset Mic", NULL),
> +       SND_SOC_DAPM_MIC("Internal Mic 1", NULL),
> +       SND_SOC_DAPM_MIC("Internal Mic 2", NULL),
> +};
> +
> +static const struct snd_kcontrol_new tegra_rt5677_controls[] = {
> +       SOC_DAPM_PIN_SWITCH("Speaker"),
> +       SOC_DAPM_PIN_SWITCH("Headphone"),
> +       SOC_DAPM_PIN_SWITCH("Headset Mic"),
> +       SOC_DAPM_PIN_SWITCH("Internal Mic 1"),
> +       SOC_DAPM_PIN_SWITCH("Internal Mic 2"),
> +};
> +
> +static int tegra_rt5677_asoc_init(struct snd_soc_pcm_runtime *rtd)
> +{
> +       struct snd_soc_dai *codec_dai = rtd->codec_dai;
> +       struct snd_soc_codec *codec = codec_dai->codec;
> +       struct snd_soc_dapm_context *dapm = &codec->dapm;
> +       struct tegra_rt5677 *machine = snd_soc_card_get_drvdata(rtd->card);
> +
> +       snd_soc_jack_new(codec, "Headphone Jack", SND_JACK_HEADPHONE,
> +                       &tegra_rt5677_hp_jack);
> +       snd_soc_jack_add_pins(&tegra_rt5677_hp_jack, 1,
> +                       &tegra_rt5677_hp_jack_pins);
> +
> +       if (gpio_is_valid(machine->gpio_hp_det)) {
> +               tegra_rt5677_hp_jack_gpio.gpio = machine->gpio_hp_det;
> +               snd_soc_jack_add_gpios(&tegra_rt5677_hp_jack, 1,
> +                               &tegra_rt5677_hp_jack_gpio);
> +       }
> +
> +
> +       snd_soc_jack_new(codec, "Mic Jack", SND_JACK_MICROPHONE,
> +                       &tegra_rt5677_mic_jack);
> +       snd_soc_jack_add_pins(&tegra_rt5677_mic_jack, 1,
> +                       &tegra_rt5677_mic_jack_pins);
> +
> +       if (gpio_is_valid(machine->gpio_mic_present)) {
> +               tegra_rt5677_mic_jack_gpio.gpio = machine->gpio_mic_present;
> +               snd_soc_jack_add_gpios(&tegra_rt5677_mic_jack, 1,
> +                               &tegra_rt5677_mic_jack_gpio);
> +       }
> +
> +       snd_soc_dapm_force_enable_pin(dapm, "MICBIAS1");
> +
> +       return 0;
> +}
> +
> +static int tegra_rt5677_card_remove(struct snd_soc_card *card)
> +{
> +       struct tegra_rt5677 *machine = snd_soc_card_get_drvdata(card);
> +
> +       if (gpio_is_valid(machine->gpio_hp_det)) {
> +               snd_soc_jack_free_gpios(&tegra_rt5677_hp_jack, 1,
> +                               &tegra_rt5677_hp_jack_gpio);
> +       }
> +
> +       if (gpio_is_valid(machine->gpio_mic_present)) {
> +               snd_soc_jack_free_gpios(&tegra_rt5677_mic_jack, 1,
> +                               &tegra_rt5677_mic_jack_gpio);
> +       }
> +
> +       return 0;
> +}
> +
> +static struct snd_soc_dai_link tegra_rt5677_dai = {
> +       .name = "RT5677",
> +       .stream_name = "RT5677 PCM",
> +       .codec_dai_name = "rt5677-aif1",
> +       .init = tegra_rt5677_asoc_init,
> +       .ops = &tegra_rt5677_ops,
> +       .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
> +                       SND_SOC_DAIFMT_CBS_CFS,
> +};
> +
> +static struct snd_soc_card snd_soc_tegra_rt5677 = {
> +       .name = "tegra-rt5677",
> +       .owner = THIS_MODULE,
> +       .remove = tegra_rt5677_card_remove,
> +       .dai_link = &tegra_rt5677_dai,
> +       .num_links = 1,
> +       .controls = tegra_rt5677_controls,
> +       .num_controls = ARRAY_SIZE(tegra_rt5677_controls),
> +       .dapm_widgets = tegra_rt5677_dapm_widgets,
> +       .num_dapm_widgets = ARRAY_SIZE(tegra_rt5677_dapm_widgets),
> +       .fully_routed = true,
> +};
> +
> +static int tegra_rt5677_probe(struct platform_device *pdev)
> +{
> +       struct device_node *np = pdev->dev.of_node;
> +       struct snd_soc_card *card = &snd_soc_tegra_rt5677;
> +       struct tegra_rt5677 *machine;
> +       int ret;
> +
> +#if defined(CONFIG_MODULES) && defined(MODULE)
> +       request_module("snd_soc_tegra30_i2s");
> +#endif

What do you think about the code above?

Basically we need to tell kernel that tegra_rt5677 module should be
loaded only after tegra_i2s module. Otherwise kernel fails to load
tegra_rt5677 with error:

 [   32.664123] tegra-snd-rt5677 sound.8: ASoC: CPU DAI (null) not registered
 [   32.671110] tegra-snd-rt5677 sound.8: snd_soc_register_card failed (-517)
 [   32.678702] platform sound.8: Driver tegra-snd-rt5677 requests
probe deferral


Normally depmod scans module function usage and builds dependency
graph, but in this case we do not use any functions from i2s module
and thus kernel does not know about this dependency.


> +       machine = devm_kzalloc(&pdev->dev,
> +                       sizeof(struct tegra_rt5677), GFP_KERNEL);
> +       if (!machine)
> +               return -ENOMEM;
> +
> +       card->dev = &pdev->dev;
> +       platform_set_drvdata(pdev, card);
> +       snd_soc_card_set_drvdata(card, machine);
> +
> +       machine->gpio_hp_det = of_get_named_gpio(np, "nvidia,hp-det-gpios", 0);
> +       if (machine->gpio_hp_det == -EPROBE_DEFER)
> +               return -EPROBE_DEFER;
> +
> +       machine->gpio_mic_present = of_get_named_gpio(np,
> +                       "nvidia,mic-present-gpios", 0);
> +       if (machine->gpio_mic_present == -EPROBE_DEFER)
> +               return -EPROBE_DEFER;
> +
> +       machine->gpio_hp_en = of_get_named_gpio(np, "nvidia,hp-en-gpios", 0);
> +       if (machine->gpio_hp_en == -EPROBE_DEFER)
> +               return -EPROBE_DEFER;
> +       if (gpio_is_valid(machine->gpio_hp_en)) {
> +               ret = devm_gpio_request_one(&pdev->dev, machine->gpio_hp_en,
> +                               GPIOF_OUT_INIT_LOW, "hp_en");
> +               if (ret) {
> +                       dev_err(card->dev, "cannot get hp_en gpio\n");
> +                       return ret;
> +               }
> +       }
> +
> +       machine->gpio_dmic_clk_en = of_get_named_gpio(np,
> +               "nvidia,dmic-clk-en-gpios", 0);
> +       if (machine->gpio_dmic_clk_en == -EPROBE_DEFER)
> +               return -EPROBE_DEFER;
> +       if (gpio_is_valid(machine->gpio_dmic_clk_en)) {
> +               ret = devm_gpio_request_one(&pdev->dev,
> +                               machine->gpio_dmic_clk_en,
> +                               GPIOF_OUT_INIT_HIGH, "dmic_clk_en");
> +               if (ret) {
> +                       dev_err(card->dev, "cannot get dmic_clk_en gpio\n");
> +                       return ret;
> +               }
> +       }
> +
> +       ret = snd_soc_of_parse_card_name(card, "nvidia,model");
> +       if (ret)
> +               goto err;
> +
> +       ret = snd_soc_of_parse_audio_routing(card, "nvidia,audio-routing");
> +       if (ret)
> +               goto err;
> +
> +       tegra_rt5677_dai.codec_of_node = of_parse_phandle(np,
> +                       "nvidia,audio-codec", 0);
> +       if (!tegra_rt5677_dai.codec_of_node) {
> +               dev_err(&pdev->dev,
> +                       "Property 'nvidia,audio-codec' missing or invalid\n");
> +               ret = -EINVAL;
> +               goto err;
> +       }
> +
> +       tegra_rt5677_dai.cpu_of_node = of_parse_phandle(np,
> +                       "nvidia,i2s-controller", 0);
> +       if (!tegra_rt5677_dai.cpu_of_node) {
> +               dev_err(&pdev->dev,
> +                       "Property 'nvidia,i2s-controller' missing or invalid\n");
> +               ret = -EINVAL;
> +               goto err;
> +       }
> +       tegra_rt5677_dai.platform_of_node = tegra_rt5677_dai.cpu_of_node;
> +
> +       ret = tegra_asoc_utils_init(&machine->util_data, &pdev->dev);
> +       if (ret)
> +               goto err;
> +
> +       ret = snd_soc_register_card(card);
> +       if (ret) {
> +               dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
> +                       ret);
> +               goto err_fini_utils;
> +       }
> +
> +       return 0;
> +
> +err_fini_utils:
> +       tegra_asoc_utils_fini(&machine->util_data);
> +err:
> +       return ret;
> +}
> +
> +static int tegra_rt5677_remove(struct platform_device *pdev)
> +{
> +       struct snd_soc_card *card = platform_get_drvdata(pdev);
> +       struct tegra_rt5677 *machine = snd_soc_card_get_drvdata(card);
> +
> +       snd_soc_unregister_card(card);
> +
> +       tegra_asoc_utils_fini(&machine->util_data);
> +
> +       return 0;
> +}
> +
> +static const struct of_device_id tegra_rt5677_of_match[] = {
> +       { .compatible = "nvidia,tegra-audio-rt5677", },
> +       {},
> +};
> +
> +static struct platform_driver tegra_rt5677_driver = {
> +       .driver = {
> +               .name = DRV_NAME,
> +               .owner = THIS_MODULE,
> +               .pm = &snd_soc_pm_ops,
> +               .of_match_table = tegra_rt5677_of_match,
> +       },
> +       .probe = tegra_rt5677_probe,
> +       .remove = tegra_rt5677_remove,
> +};
> +module_platform_driver(tegra_rt5677_driver);
> +
> +MODULE_AUTHOR("Anatol Pomozov <anatol@google.com>");
> +MODULE_DESCRIPTION("Tegra+RT5677 machine ASoC driver");
> +MODULE_LICENSE("GPL v2");
> +MODULE_ALIAS("platform:" DRV_NAME);
> +MODULE_DEVICE_TABLE(of, tegra_rt5677_of_match);
> --
> 2.2.0.rc0.207.ga3a616c
>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] ASoC: tegra: Add platform driver for rt5677 audio codec
  2014-12-23 19:29 [PATCH] ASoC: tegra: Add platform driver for rt5677 audio codec Anatol Pomozov
  2014-12-23 19:36 ` Anatol Pomozov
@ 2014-12-26 16:38 ` Mark Brown
  2014-12-29 13:25   ` Anatol Pomozov
  1 sibling, 1 reply; 16+ messages in thread
From: Mark Brown @ 2014-12-26 16:38 UTC (permalink / raw)
  To: Anatol Pomozov; +Cc: oder_chiou, alsa-devel, swarren, bardliao, ldahan, dgreid


[-- Attachment #1.1: Type: text/plain, Size: 419 bytes --]

On Tue, Dec 23, 2014 at 11:29:01AM -0800, Anatol Pomozov wrote:

> +static int tegra_rt5677_probe(struct platform_device *pdev)
> +{
> +	struct device_node *np = pdev->dev.of_node;
> +	struct snd_soc_card *card = &snd_soc_tegra_rt5677;
> +	struct tegra_rt5677 *machine;
> +	int ret;
> +
> +#if defined(CONFIG_MODULES) && defined(MODULE)
> +	request_module("snd_soc_tegra30_i2s");
> +#endif

What's this all about then?

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] ASoC: tegra: Add platform driver for rt5677 audio codec
  2014-12-26 16:38 ` Mark Brown
@ 2014-12-29 13:25   ` Anatol Pomozov
  2014-12-29 15:55     ` Mark Brown
  0 siblings, 1 reply; 16+ messages in thread
From: Anatol Pomozov @ 2014-12-29 13:25 UTC (permalink / raw)
  To: Mark Brown
  Cc: Oder Chiou, alsa-devel, Stephen Warren, Bard Liao, Laurent Dahan,
	Dylan Reid

Hi

On Fri, Dec 26, 2014 at 8:38 AM, Mark Brown <broonie@kernel.org> wrote:
> On Tue, Dec 23, 2014 at 11:29:01AM -0800, Anatol Pomozov wrote:
>
>> +static int tegra_rt5677_probe(struct platform_device *pdev)
>> +{
>> +     struct device_node *np = pdev->dev.of_node;
>> +     struct snd_soc_card *card = &snd_soc_tegra_rt5677;
>> +     struct tegra_rt5677 *machine;
>> +     int ret;
>> +
>> +#if defined(CONFIG_MODULES) && defined(MODULE)
>> +     request_module("snd_soc_tegra30_i2s");
>> +#endif
>
> What's this all about then?

Sorry, my question was not clear. I meant is it ok to put this
request_module() to upstream code? If not then just remove it before
merging my patch.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] ASoC: tegra: Add platform driver for rt5677 audio codec
  2014-12-29 13:25   ` Anatol Pomozov
@ 2014-12-29 15:55     ` Mark Brown
  2015-01-06 18:46       ` Anatol Pomozov
  0 siblings, 1 reply; 16+ messages in thread
From: Mark Brown @ 2014-12-29 15:55 UTC (permalink / raw)
  To: Anatol Pomozov
  Cc: Oder Chiou, alsa-devel, Stephen Warren, Bard Liao, Laurent Dahan,
	Dylan Reid


[-- Attachment #1.1: Type: text/plain, Size: 706 bytes --]

On Mon, Dec 29, 2014 at 05:25:59AM -0800, Anatol Pomozov wrote:
> On Fri, Dec 26, 2014 at 8:38 AM, Mark Brown <broonie@kernel.org> wrote:

> >> +#if defined(CONFIG_MODULES) && defined(MODULE)
> >> +     request_module("snd_soc_tegra30_i2s");
> >> +#endif

> > What's this all about then?

> Sorry, my question was not clear. I meant is it ok to put this
> request_module() to upstream code? If not then just remove it before
> merging my patch.

What question, I'm not seeing a question in the patch (I'd expect it to
be after the --- if one was being asked)?  I've no idea what it's there
for so it's hard to tell, my first thought would be no and you need to
fix whatever you're working around directly.

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] ASoC: tegra: Add platform driver for rt5677 audio codec
  2014-12-29 15:55     ` Mark Brown
@ 2015-01-06 18:46       ` Anatol Pomozov
  0 siblings, 0 replies; 16+ messages in thread
From: Anatol Pomozov @ 2015-01-06 18:46 UTC (permalink / raw)
  To: Mark Brown
  Cc: Oder Chiou, alsa-devel, Stephen Warren, Bard Liao, Laurent Dahan,
	Dylan Reid

Hi

On Mon, Dec 29, 2014 at 7:55 AM, Mark Brown <broonie@kernel.org> wrote:
> On Mon, Dec 29, 2014 at 05:25:59AM -0800, Anatol Pomozov wrote:
>> On Fri, Dec 26, 2014 at 8:38 AM, Mark Brown <broonie@kernel.org> wrote:
>
>> >> +#if defined(CONFIG_MODULES) && defined(MODULE)
>> >> +     request_module("snd_soc_tegra30_i2s");
>> >> +#endif
>
>> > What's this all about then?
>
>> Sorry, my question was not clear. I meant is it ok to put this
>> request_module() to upstream code? If not then just remove it before
>> merging my patch.
>
> What question, I'm not seeing a question in the patch (I'd expect it to
> be after the --- if one was being asked)?  I've no idea what it's there
> for so it's hard to tell, my first thought would be no and you need to
> fix whatever you're working around directly.


My question was related to dependency between i2s and codec driver
modules. See it here (in the middle of the message)
http://permalink.gmane.org/gmane.linux.alsa.devel/132054

Anyway I think it is not worth spending too much time on it. I resent
this patch without request_module().

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] ASoC: tegra: Add platform driver for rt5677 audio codec
  2014-12-30 19:12 Anatol Pomozov
@ 2015-01-07 18:54 ` Mark Brown
  0 siblings, 0 replies; 16+ messages in thread
From: Mark Brown @ 2015-01-07 18:54 UTC (permalink / raw)
  To: Anatol Pomozov; +Cc: alsa-devel


[-- Attachment #1.1: Type: text/plain, Size: 127 bytes --]

On Tue, Dec 30, 2014 at 11:12:35AM -0800, Anatol Pomozov wrote:
> The driver supports NVIDIA Tegra Ryu board

Applied, thanks.

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH] ASoC: tegra: Add platform driver for rt5677 audio codec
@ 2014-12-30 19:12 Anatol Pomozov
  2015-01-07 18:54 ` Mark Brown
  0 siblings, 1 reply; 16+ messages in thread
From: Anatol Pomozov @ 2014-12-30 19:12 UTC (permalink / raw)
  To: broonie; +Cc: alsa-devel, Anatol Pomozov

The driver supports NVIDIA Tegra Ryu board

Sponsored: Google ChromeOS
Signed-off-by: Anatol Pomozov <anatol.pomozov@gmail.com>
---
 .../bindings/sound/nvidia,tegra-audio-rt5677.txt   |  67 ++++
 sound/soc/tegra/Kconfig                            |  10 +
 sound/soc/tegra/Makefile                           |   2 +
 sound/soc/tegra/tegra_rt5677.c                     | 347 +++++++++++++++++++++
 4 files changed, 426 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/nvidia,tegra-audio-rt5677.txt
 create mode 100644 sound/soc/tegra/tegra_rt5677.c

diff --git a/Documentation/devicetree/bindings/sound/nvidia,tegra-audio-rt5677.txt b/Documentation/devicetree/bindings/sound/nvidia,tegra-audio-rt5677.txt
new file mode 100644
index 0000000..a4589cd
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/nvidia,tegra-audio-rt5677.txt
@@ -0,0 +1,67 @@
+NVIDIA Tegra audio complex, with RT5677 CODEC
+
+Required properties:
+- compatible : "nvidia,tegra-audio-rt5677"
+- clocks : Must contain an entry for each entry in clock-names.
+  See ../clocks/clock-bindings.txt for details.
+- clock-names : Must include the following entries:
+  - pll_a
+  - pll_a_out0
+  - mclk (The Tegra cdev1/extern1 clock, which feeds the CODEC's mclk)
+- nvidia,model : The user-visible name of this sound complex.
+- nvidia,audio-routing : A list of the connections between audio components.
+  Each entry is a pair of strings, the first being the connection's sink,
+  the second being the connection's source. Valid names for sources and
+  sinks are the RT5677's pins (as documented in its binding), and the jacks
+  on the board:
+
+  * Headphone
+  * Speaker
+  * Headset Mic
+  * Internal Mic 1
+  * Internal Mic 2
+
+- nvidia,i2s-controller : The phandle of the Tegra I2S controller that's
+  connected to the CODEC.
+- nvidia,audio-codec : The phandle of the RT5677 audio codec. This binding
+  assumes that AIF1 on the CODEC is connected to Tegra.
+
+Optional properties:
+- nvidia,hp-det-gpios : The GPIO that detects headphones are plugged in
+- nvidia,hp-en-gpios : The GPIO that enables headphone amplifier
+- nvidia,mic-present-gpios: The GPIO that mic jack is plugged in
+- nvidia,dmic-clk-en-gpios : The GPIO that gates DMIC clock signal
+
+Example:
+
+sound {
+	compatible = "nvidia,tegra-audio-rt5677-ryu",
+	        "nvidia,tegra-audio-rt5677";
+	nvidia,model = "NVIDIA Tegra Ryu";
+
+	nvidia,audio-routing =
+		"Headphone", "LOUT2",
+		"Headphone", "LOUT1",
+		"Headset Mic", "MICBIAS1",
+		"IN1P", "Headset Mic",
+		"IN1N", "Headset Mic",
+		"DMIC L1", "Internal Mic 1",
+		"DMIC R1", "Internal Mic 1",
+		"DMIC L2", "Internal Mic 2",
+		"DMIC R2", "Internal Mic 2",
+		"Speaker", "PDM1L",
+		"Speaker", "PDM1R";
+
+	nvidia,i2s-controller = <&tegra_i2s1>;
+	nvidia,audio-codec = <&rt5677>;
+
+	nvidia,hp-det-gpios = <&gpio TEGRA_GPIO(R, 7) GPIO_ACTIVE_HIGH>;
+	nvidia,mic-present-gpios = <&gpio TEGRA_GPIO(O, 5) GPIO_ACTIVE_LOW>;
+	nvidia,hp-en-gpios = <&rt5677 1 GPIO_ACTIVE_HIGH>;
+	nvidia,dmic-clk-en-gpios = <&rt5677 2 GPIO_ACTIVE_HIGH>;
+
+	clocks = <&tegra_car TEGRA124_CLK_PLL_A>,
+	         <&tegra_car TEGRA124_CLK_PLL_A_OUT0>,
+	         <&tegra_car TEGRA124_CLK_EXTERN1>;
+	clock-names = "pll_a", "pll_a_out0", "mclk";
+};
diff --git a/sound/soc/tegra/Kconfig b/sound/soc/tegra/Kconfig
index 31198cf7..a6768f8 100644
--- a/sound/soc/tegra/Kconfig
+++ b/sound/soc/tegra/Kconfig
@@ -128,3 +128,13 @@ config SND_SOC_TEGRA_MAX98090
 	help
 	  Say Y or M here if you want to add support for SoC audio on Tegra
 	  boards using the MAX98090 codec, such as Venice2.
+
+config SND_SOC_TEGRA_RT5677
+	tristate "SoC Audio support for Tegra boards using a RT5677 codec"
+	depends on SND_SOC_TEGRA && I2C && GPIOLIB
+	select SND_SOC_TEGRA20_I2S if ARCH_TEGRA_2x_SOC
+	select SND_SOC_TEGRA30_I2S if ARCH_TEGRA_3x_SOC
+	select SND_SOC_RT5677
+	help
+	  Say Y or M here if you want to add support for SoC audio on Tegra
+	  boards using the RT5677 codec, such as Ryu.
diff --git a/sound/soc/tegra/Makefile b/sound/soc/tegra/Makefile
index 5ae588c..9171655 100644
--- a/sound/soc/tegra/Makefile
+++ b/sound/soc/tegra/Makefile
@@ -19,6 +19,7 @@ obj-$(CONFIG_SND_SOC_TEGRA30_I2S) += snd-soc-tegra30-i2s.o
 
 # Tegra machine Support
 snd-soc-tegra-rt5640-objs := tegra_rt5640.o
+snd-soc-tegra-rt5677-objs := tegra_rt5677.o
 snd-soc-tegra-wm8753-objs := tegra_wm8753.o
 snd-soc-tegra-wm8903-objs := tegra_wm8903.o
 snd-soc-tegra-wm9712-objs := tegra_wm9712.o
@@ -27,6 +28,7 @@ snd-soc-tegra-alc5632-objs := tegra_alc5632.o
 snd-soc-tegra-max98090-objs := tegra_max98090.o
 
 obj-$(CONFIG_SND_SOC_TEGRA_RT5640) += snd-soc-tegra-rt5640.o
+obj-$(CONFIG_SND_SOC_TEGRA_RT5677) += snd-soc-tegra-rt5677.o
 obj-$(CONFIG_SND_SOC_TEGRA_WM8753) += snd-soc-tegra-wm8753.o
 obj-$(CONFIG_SND_SOC_TEGRA_WM8903) += snd-soc-tegra-wm8903.o
 obj-$(CONFIG_SND_SOC_TEGRA_WM9712) += snd-soc-tegra-wm9712.o
diff --git a/sound/soc/tegra/tegra_rt5677.c b/sound/soc/tegra/tegra_rt5677.c
new file mode 100644
index 0000000..e4cf978
--- /dev/null
+++ b/sound/soc/tegra/tegra_rt5677.c
@@ -0,0 +1,347 @@
+/*
+* tegra_rt5677.c - Tegra machine ASoC driver for boards using RT5677 codec.
+ *
+ * Copyright (c) 2014, The Chromium OS Authors.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Based on code copyright/by:
+ *
+ * Copyright (C) 2010-2012 - NVIDIA, Inc.
+ * Copyright (C) 2011 The AC100 Kernel Team <ac100@lists.lauchpad.net>
+ * (c) 2009, 2010 Nvidia Graphics Pvt. Ltd.
+ * Copyright 2007 Wolfson Microelectronics PLC.
+ */
+
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/gpio.h>
+#include <linux/of_gpio.h>
+
+#include <sound/core.h>
+#include <sound/jack.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/soc.h>
+
+#include "../codecs/rt5677.h"
+
+#include "tegra_asoc_utils.h"
+
+#define DRV_NAME "tegra-snd-rt5677"
+
+struct tegra_rt5677 {
+	struct tegra_asoc_utils_data util_data;
+	int gpio_hp_det;
+	int gpio_hp_en;
+	int gpio_mic_present;
+	int gpio_dmic_clk_en;
+};
+
+static int tegra_rt5677_asoc_hw_params(struct snd_pcm_substream *substream,
+					struct snd_pcm_hw_params *params)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct snd_soc_dai *codec_dai = rtd->codec_dai;
+	struct snd_soc_card *card = rtd->card;
+	struct tegra_rt5677 *machine = snd_soc_card_get_drvdata(card);
+	int srate, mclk, err;
+
+	srate = params_rate(params);
+	mclk = 256 * srate;
+
+	err = tegra_asoc_utils_set_rate(&machine->util_data, srate, mclk);
+	if (err < 0) {
+		dev_err(card->dev, "Can't configure clocks\n");
+		return err;
+	}
+
+	err = snd_soc_dai_set_sysclk(codec_dai, RT5677_SCLK_S_MCLK, mclk,
+					SND_SOC_CLOCK_IN);
+	if (err < 0) {
+		dev_err(card->dev, "codec_dai clock not set\n");
+		return err;
+	}
+
+	return 0;
+}
+
+static int tegra_rt5677_event_hp(struct snd_soc_dapm_widget *w,
+			struct snd_kcontrol *k, int event)
+{
+	struct snd_soc_dapm_context *dapm = w->dapm;
+	struct snd_soc_card *card = dapm->card;
+	struct tegra_rt5677 *machine = snd_soc_card_get_drvdata(card);
+
+	if (!gpio_is_valid(machine->gpio_hp_en))
+		return 0;
+
+	gpio_set_value_cansleep(machine->gpio_hp_en,
+		SND_SOC_DAPM_EVENT_ON(event));
+
+	return 0;
+}
+
+static struct snd_soc_ops tegra_rt5677_ops = {
+	.hw_params = tegra_rt5677_asoc_hw_params,
+};
+
+static struct snd_soc_jack tegra_rt5677_hp_jack;
+
+static struct snd_soc_jack_pin tegra_rt5677_hp_jack_pins = {
+	.pin = "Headphone",
+	.mask = SND_JACK_HEADPHONE,
+};
+static struct snd_soc_jack_gpio tegra_rt5677_hp_jack_gpio = {
+	.name = "Headphone detection",
+	.report = SND_JACK_HEADPHONE,
+	.debounce_time = 150,
+};
+
+static struct snd_soc_jack tegra_rt5677_mic_jack;
+
+static struct snd_soc_jack_pin tegra_rt5677_mic_jack_pins = {
+	.pin = "Headset Mic",
+	.mask = SND_JACK_MICROPHONE,
+};
+
+static struct snd_soc_jack_gpio tegra_rt5677_mic_jack_gpio = {
+	.name = "Headset Mic detection",
+	.report = SND_JACK_MICROPHONE,
+	.debounce_time = 150,
+	.invert = 1
+};
+
+static const struct snd_soc_dapm_widget tegra_rt5677_dapm_widgets[] = {
+	SND_SOC_DAPM_SPK("Speaker", NULL),
+	SND_SOC_DAPM_HP("Headphone", tegra_rt5677_event_hp),
+	SND_SOC_DAPM_MIC("Headset Mic", NULL),
+	SND_SOC_DAPM_MIC("Internal Mic 1", NULL),
+	SND_SOC_DAPM_MIC("Internal Mic 2", NULL),
+};
+
+static const struct snd_kcontrol_new tegra_rt5677_controls[] = {
+	SOC_DAPM_PIN_SWITCH("Speaker"),
+	SOC_DAPM_PIN_SWITCH("Headphone"),
+	SOC_DAPM_PIN_SWITCH("Headset Mic"),
+	SOC_DAPM_PIN_SWITCH("Internal Mic 1"),
+	SOC_DAPM_PIN_SWITCH("Internal Mic 2"),
+};
+
+static int tegra_rt5677_asoc_init(struct snd_soc_pcm_runtime *rtd)
+{
+	struct snd_soc_dai *codec_dai = rtd->codec_dai;
+	struct snd_soc_codec *codec = codec_dai->codec;
+	struct snd_soc_dapm_context *dapm = &codec->dapm;
+	struct tegra_rt5677 *machine = snd_soc_card_get_drvdata(rtd->card);
+
+	snd_soc_jack_new(codec, "Headphone Jack", SND_JACK_HEADPHONE,
+			&tegra_rt5677_hp_jack);
+	snd_soc_jack_add_pins(&tegra_rt5677_hp_jack, 1,
+			&tegra_rt5677_hp_jack_pins);
+
+	if (gpio_is_valid(machine->gpio_hp_det)) {
+		tegra_rt5677_hp_jack_gpio.gpio = machine->gpio_hp_det;
+		snd_soc_jack_add_gpios(&tegra_rt5677_hp_jack, 1,
+				&tegra_rt5677_hp_jack_gpio);
+	}
+
+
+	snd_soc_jack_new(codec, "Mic Jack", SND_JACK_MICROPHONE,
+			&tegra_rt5677_mic_jack);
+	snd_soc_jack_add_pins(&tegra_rt5677_mic_jack, 1,
+			&tegra_rt5677_mic_jack_pins);
+
+	if (gpio_is_valid(machine->gpio_mic_present)) {
+		tegra_rt5677_mic_jack_gpio.gpio = machine->gpio_mic_present;
+		snd_soc_jack_add_gpios(&tegra_rt5677_mic_jack, 1,
+				&tegra_rt5677_mic_jack_gpio);
+	}
+
+	snd_soc_dapm_force_enable_pin(dapm, "MICBIAS1");
+
+	return 0;
+}
+
+static int tegra_rt5677_card_remove(struct snd_soc_card *card)
+{
+	struct tegra_rt5677 *machine = snd_soc_card_get_drvdata(card);
+
+	if (gpio_is_valid(machine->gpio_hp_det)) {
+		snd_soc_jack_free_gpios(&tegra_rt5677_hp_jack, 1,
+				&tegra_rt5677_hp_jack_gpio);
+	}
+
+	if (gpio_is_valid(machine->gpio_mic_present)) {
+		snd_soc_jack_free_gpios(&tegra_rt5677_mic_jack, 1,
+				&tegra_rt5677_mic_jack_gpio);
+	}
+
+	return 0;
+}
+
+static struct snd_soc_dai_link tegra_rt5677_dai = {
+	.name = "RT5677",
+	.stream_name = "RT5677 PCM",
+	.codec_dai_name = "rt5677-aif1",
+	.init = tegra_rt5677_asoc_init,
+	.ops = &tegra_rt5677_ops,
+	.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
+			SND_SOC_DAIFMT_CBS_CFS,
+};
+
+static struct snd_soc_card snd_soc_tegra_rt5677 = {
+	.name = "tegra-rt5677",
+	.owner = THIS_MODULE,
+	.remove = tegra_rt5677_card_remove,
+	.dai_link = &tegra_rt5677_dai,
+	.num_links = 1,
+	.controls = tegra_rt5677_controls,
+	.num_controls = ARRAY_SIZE(tegra_rt5677_controls),
+	.dapm_widgets = tegra_rt5677_dapm_widgets,
+	.num_dapm_widgets = ARRAY_SIZE(tegra_rt5677_dapm_widgets),
+	.fully_routed = true,
+};
+
+static int tegra_rt5677_probe(struct platform_device *pdev)
+{
+	struct device_node *np = pdev->dev.of_node;
+	struct snd_soc_card *card = &snd_soc_tegra_rt5677;
+	struct tegra_rt5677 *machine;
+	int ret;
+
+	machine = devm_kzalloc(&pdev->dev,
+			sizeof(struct tegra_rt5677), GFP_KERNEL);
+	if (!machine)
+		return -ENOMEM;
+
+	card->dev = &pdev->dev;
+	platform_set_drvdata(pdev, card);
+	snd_soc_card_set_drvdata(card, machine);
+
+	machine->gpio_hp_det = of_get_named_gpio(np, "nvidia,hp-det-gpios", 0);
+	if (machine->gpio_hp_det == -EPROBE_DEFER)
+		return -EPROBE_DEFER;
+
+	machine->gpio_mic_present = of_get_named_gpio(np,
+			"nvidia,mic-present-gpios", 0);
+	if (machine->gpio_mic_present == -EPROBE_DEFER)
+		return -EPROBE_DEFER;
+
+	machine->gpio_hp_en = of_get_named_gpio(np, "nvidia,hp-en-gpios", 0);
+	if (machine->gpio_hp_en == -EPROBE_DEFER)
+		return -EPROBE_DEFER;
+	if (gpio_is_valid(machine->gpio_hp_en)) {
+		ret = devm_gpio_request_one(&pdev->dev, machine->gpio_hp_en,
+				GPIOF_OUT_INIT_LOW, "hp_en");
+		if (ret) {
+			dev_err(card->dev, "cannot get hp_en gpio\n");
+			return ret;
+		}
+	}
+
+	machine->gpio_dmic_clk_en = of_get_named_gpio(np,
+		"nvidia,dmic-clk-en-gpios", 0);
+	if (machine->gpio_dmic_clk_en == -EPROBE_DEFER)
+		return -EPROBE_DEFER;
+	if (gpio_is_valid(machine->gpio_dmic_clk_en)) {
+		ret = devm_gpio_request_one(&pdev->dev,
+				machine->gpio_dmic_clk_en,
+				GPIOF_OUT_INIT_HIGH, "dmic_clk_en");
+		if (ret) {
+			dev_err(card->dev, "cannot get dmic_clk_en gpio\n");
+			return ret;
+		}
+	}
+
+	ret = snd_soc_of_parse_card_name(card, "nvidia,model");
+	if (ret)
+		goto err;
+
+	ret = snd_soc_of_parse_audio_routing(card, "nvidia,audio-routing");
+	if (ret)
+		goto err;
+
+	tegra_rt5677_dai.codec_of_node = of_parse_phandle(np,
+			"nvidia,audio-codec", 0);
+	if (!tegra_rt5677_dai.codec_of_node) {
+		dev_err(&pdev->dev,
+			"Property 'nvidia,audio-codec' missing or invalid\n");
+		ret = -EINVAL;
+		goto err;
+	}
+
+	tegra_rt5677_dai.cpu_of_node = of_parse_phandle(np,
+			"nvidia,i2s-controller", 0);
+	if (!tegra_rt5677_dai.cpu_of_node) {
+		dev_err(&pdev->dev,
+			"Property 'nvidia,i2s-controller' missing or invalid\n");
+		ret = -EINVAL;
+		goto err;
+	}
+	tegra_rt5677_dai.platform_of_node = tegra_rt5677_dai.cpu_of_node;
+
+	ret = tegra_asoc_utils_init(&machine->util_data, &pdev->dev);
+	if (ret)
+		goto err;
+
+	ret = snd_soc_register_card(card);
+	if (ret) {
+		dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
+			ret);
+		goto err_fini_utils;
+	}
+
+	return 0;
+
+err_fini_utils:
+	tegra_asoc_utils_fini(&machine->util_data);
+err:
+	return ret;
+}
+
+static int tegra_rt5677_remove(struct platform_device *pdev)
+{
+	struct snd_soc_card *card = platform_get_drvdata(pdev);
+	struct tegra_rt5677 *machine = snd_soc_card_get_drvdata(card);
+
+	snd_soc_unregister_card(card);
+
+	tegra_asoc_utils_fini(&machine->util_data);
+
+	return 0;
+}
+
+static const struct of_device_id tegra_rt5677_of_match[] = {
+	{ .compatible = "nvidia,tegra-audio-rt5677", },
+	{},
+};
+
+static struct platform_driver tegra_rt5677_driver = {
+	.driver = {
+		.name = DRV_NAME,
+		.owner = THIS_MODULE,
+		.pm = &snd_soc_pm_ops,
+		.of_match_table = tegra_rt5677_of_match,
+	},
+	.probe = tegra_rt5677_probe,
+	.remove = tegra_rt5677_remove,
+};
+module_platform_driver(tegra_rt5677_driver);
+
+MODULE_AUTHOR("Anatol Pomozov <anatol@google.com>");
+MODULE_DESCRIPTION("Tegra+RT5677 machine ASoC driver");
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("platform:" DRV_NAME);
+MODULE_DEVICE_TABLE(of, tegra_rt5677_of_match);
-- 
2.2.0.rc0.207.ga3a616c

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH] ASoC: tegra: Add platform driver for rt5677 audio codec
  2014-10-16  8:59   ` Anatol Pomazau
@ 2014-10-16  9:04     ` Mark Brown
  0 siblings, 0 replies; 16+ messages in thread
From: Mark Brown @ 2014-10-16  9:04 UTC (permalink / raw)
  To: Anatol Pomazau
  Cc: Oder Chiou, alsa-devel, lars, Stephen Warren, Anatol Pomozov,
	Bard Liao, Laurent Dahan, Dylan Reid


[-- Attachment #1.1: Type: text/plain, Size: 1250 bytes --]

On Thu, Oct 16, 2014 at 01:59:58AM -0700, Anatol Pomazau wrote:
> On Thu, Oct 16, 2014 at 12:38 AM, Mark Brown <broonie@kernel.org> wrote:
> > On Wed, Oct 15, 2014 at 02:15:42PM -0700, Anatol Pomozov wrote:

> >> +Required properties:
> >> +- nvidia,speaker-codec: The phandle of the board specific speaker amplifier.
> >> +  This binding assumes that AIF2 on the audio CODEC is connected to this
> >> +  amplifier.

> > To repeat my comment on the previous version:

> > | This isn't as generic as all that, it relies on the specific speaker
> > | driver.  I'd suggest either just saying it's board specific or making
> > | the speaker CODEC optional.

> > Please don't ignore review comments.

> In the description of the dts property I said that its board specific
> amp. If it not what you want then I do not know what "saying it's
> board specific" means. Could you please provide examples of "board
> specific" properties?

The *driver* is board specific.  Obviously all DT properties in a given
DT are specific to the particular board.  This driver claims to be a
generic driver for Tegra systems with this CODEC but it has a
non-optional requirement for an external speaker driver driver to be
specified and hooked up in that particular way.

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] ASoC: tegra: Add platform driver for rt5677 audio codec
  2014-10-16  7:38 ` Mark Brown
@ 2014-10-16  8:59   ` Anatol Pomazau
  2014-10-16  9:04     ` Mark Brown
  0 siblings, 1 reply; 16+ messages in thread
From: Anatol Pomazau @ 2014-10-16  8:59 UTC (permalink / raw)
  To: Mark Brown
  Cc: Oder Chiou, alsa-devel, lars, Stephen Warren, Anatol Pomozov,
	Bard Liao, Laurent Dahan, Dylan Reid

Hi

On Thu, Oct 16, 2014 at 12:38 AM, Mark Brown <broonie@kernel.org> wrote:
> On Wed, Oct 15, 2014 at 02:15:42PM -0700, Anatol Pomozov wrote:
>
>> +Required properties:
>> +- nvidia,speaker-codec: The phandle of the board specific speaker amplifier.
>> +  This binding assumes that AIF2 on the audio CODEC is connected to this
>> +  amplifier.
>
> To repeat my comment on the previous version:
>
> | This isn't as generic as all that, it relies on the specific speaker
> | driver.  I'd suggest either just saying it's board specific or making
> | the speaker CODEC optional.
>
> Please don't ignore review comments.

In the description of the dts property I said that its board specific
amp. If it not what you want then I do not know what "saying it's
board specific" means. Could you please provide examples of "board
specific" properties?

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] ASoC: tegra: Add platform driver for rt5677 audio codec
  2014-10-15 21:15 Anatol Pomozov
@ 2014-10-16  7:38 ` Mark Brown
  2014-10-16  8:59   ` Anatol Pomazau
  0 siblings, 1 reply; 16+ messages in thread
From: Mark Brown @ 2014-10-16  7:38 UTC (permalink / raw)
  To: Anatol Pomozov
  Cc: oder_chiou, alsa-devel, lars, swarren, Anatol Pomozov, bardliao,
	ldahan, dgreid


[-- Attachment #1.1: Type: text/plain, Size: 520 bytes --]

On Wed, Oct 15, 2014 at 02:15:42PM -0700, Anatol Pomozov wrote:

> +Required properties:
> +- nvidia,speaker-codec: The phandle of the board specific speaker amplifier.
> +  This binding assumes that AIF2 on the audio CODEC is connected to this
> +  amplifier.

To repeat my comment on the previous version:

| This isn't as generic as all that, it relies on the specific speaker
| driver.  I'd suggest either just saying it's board specific or making
| the speaker CODEC optional.

Please don't ignore review comments.

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH] ASoC: tegra: Add platform driver for rt5677 audio codec
@ 2014-10-15 21:15 Anatol Pomozov
  2014-10-16  7:38 ` Mark Brown
  0 siblings, 1 reply; 16+ messages in thread
From: Anatol Pomozov @ 2014-10-15 21:15 UTC (permalink / raw)
  To: broonie, swarren
  Cc: oder_chiou, alsa-devel, lars, Anatol Pomozov, Anatol Pomozov,
	bardliao, ldahan, dgreid

The driver supports NVIDIA Tegra Ryu board

Signed-off-by: Anatol Pomozov <anatol@google.com>
---
 .../bindings/sound/nvidia,tegra-audio-rt5677.txt   |  73 ++++
 sound/soc/tegra/Kconfig                            |  11 +
 sound/soc/tegra/Makefile                           |   2 +
 sound/soc/tegra/tegra_rt5677.c                     | 383 +++++++++++++++++++++
 4 files changed, 469 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/nvidia,tegra-audio-rt5677.txt
 create mode 100644 sound/soc/tegra/tegra_rt5677.c

diff --git a/Documentation/devicetree/bindings/sound/nvidia,tegra-audio-rt5677.txt b/Documentation/devicetree/bindings/sound/nvidia,tegra-audio-rt5677.txt
new file mode 100644
index 0000000..0e483c5
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/nvidia,tegra-audio-rt5677.txt
@@ -0,0 +1,73 @@
+NVIDIA Tegra audio complex, with RT5677 CODEC
+
+Required properties:
+- compatible : "nvidia,tegra-audio-rt5677"
+- clocks : Must contain an entry for each entry in clock-names.
+  See ../clocks/clock-bindings.txt for details.
+- clock-names : Must include the following entries:
+  - pll_a
+  - pll_a_out0
+  - mclk (The Tegra cdev1/extern1 clock, which feeds the CODEC's mclk)
+- nvidia,model : The user-visible name of this sound complex.
+- nvidia,audio-routing : A list of the connections between audio components.
+  Each entry is a pair of strings, the first being the connection's sink,
+  the second being the connection's source. Valid names for sources and
+  sinks are the RT5677's pins (as documented in its binding), and the jacks
+  on the board:
+
+  * Headphone
+  * Speaker
+  * Headset Mic
+  * Internal Mic 1
+  * Internal Mic 2
+
+- nvidia,i2s-controller : The phandle of the Tegra I2S controller that's
+  connected to the CODEC.
+- nvidia,audio-codec : The phandle of the RT5677 audio codec. This binding
+  assumes that AIF1 on the CODEC is connected to Tegra.
+- nvidia,speaker-codec: The phandle of the board specific speaker amplifier.
+  This binding assumes that AIF2 on the audio CODEC is connected to this
+  amplifier.
+
+Optional properties:
+- nvidia,hp-det-gpios : The GPIO that detects headphones are plugged in
+- nvidia,hp-en-gpios : The GPIO that enables headphone amplifier
+- nvidia,mic-present-gpios: The GPIO that mic jack is plugged in
+- nvidia,dmic-clk-en-gpios : The GPIO that gates DMIC clock signal
+
+Example:
+
+sound {
+	compatible = "nvidia,tegra-audio-rt5677-ryu",
+	        "nvidia,tegra-audio-rt5677";
+	nvidia,model = "NVIDIA Tegra Ryu";
+
+	nvidia,audio-routing =
+		/* rt5677 codec */
+		"Headphone", "LOUT2",
+		"Headphone", "LOUT1",
+		"Headset Mic", "MICBIAS1",
+		"IN1P", "Headset Mic",
+		"IN1N", "Headset Mic",
+		"DMIC L1", "Internal Mic 1",
+		"DMIC R1", "Internal Mic 1",
+		"DMIC L2", "Internal Mic 2",
+		"DMIC R2", "Internal Mic 2",
+		/* speaker amp */
+		"DAC", "AIF2TX",
+		"Speaker", "OUT";
+
+	nvidia,i2s-controller = <&tegra_i2s1>;
+	nvidia,audio-codec = <&rt5677>;
+	nvidia,speaker-codec = <&ssm4567>;
+
+	nvidia,hp-det-gpios = <&gpio TEGRA_GPIO(R, 7) GPIO_ACTIVE_HIGH>;
+	nvidia,mic-present-gpios = <&rt5677 5 GPIO_ACTIVE_LOW>;
+	nvidia,hp-en-gpios = <&rt5677 1 GPIO_ACTIVE_HIGH>;
+	nvidia,dmic-clk-en-gpios = <&rt5677 2 GPIO_ACTIVE_HIGH>;
+
+	clocks = <&tegra_car TEGRA124_CLK_PLL_A>,
+	         <&tegra_car TEGRA124_CLK_PLL_A_OUT0>,
+	         <&tegra_car TEGRA124_CLK_EXTERN1>;
+	clock-names = "pll_a", "pll_a_out0", "mclk";
+};
diff --git a/sound/soc/tegra/Kconfig b/sound/soc/tegra/Kconfig
index 31198cf7..c30611e 100644
--- a/sound/soc/tegra/Kconfig
+++ b/sound/soc/tegra/Kconfig
@@ -128,3 +128,14 @@ config SND_SOC_TEGRA_MAX98090
 	help
 	  Say Y or M here if you want to add support for SoC audio on Tegra
 	  boards using the MAX98090 codec, such as Venice2.
+
+config SND_SOC_TEGRA_RT5677
+	tristate "SoC Audio support for Tegra boards using a RT5677 codec"
+	depends on SND_SOC_TEGRA && I2C && GPIOLIB
+	select SND_SOC_TEGRA20_I2S if ARCH_TEGRA_2x_SOC
+	select SND_SOC_TEGRA30_I2S if ARCH_TEGRA_3x_SOC
+	select SND_SOC_RT5677
+	select SND_SOC_SSM4567
+	help
+	  Say Y or M here if you want to add support for SoC audio on Tegra
+	  boards using the RT5677 codec, such as Ryu.
diff --git a/sound/soc/tegra/Makefile b/sound/soc/tegra/Makefile
index 5ae588c..9171655 100644
--- a/sound/soc/tegra/Makefile
+++ b/sound/soc/tegra/Makefile
@@ -19,6 +19,7 @@ obj-$(CONFIG_SND_SOC_TEGRA30_I2S) += snd-soc-tegra30-i2s.o
 
 # Tegra machine Support
 snd-soc-tegra-rt5640-objs := tegra_rt5640.o
+snd-soc-tegra-rt5677-objs := tegra_rt5677.o
 snd-soc-tegra-wm8753-objs := tegra_wm8753.o
 snd-soc-tegra-wm8903-objs := tegra_wm8903.o
 snd-soc-tegra-wm9712-objs := tegra_wm9712.o
@@ -27,6 +28,7 @@ snd-soc-tegra-alc5632-objs := tegra_alc5632.o
 snd-soc-tegra-max98090-objs := tegra_max98090.o
 
 obj-$(CONFIG_SND_SOC_TEGRA_RT5640) += snd-soc-tegra-rt5640.o
+obj-$(CONFIG_SND_SOC_TEGRA_RT5677) += snd-soc-tegra-rt5677.o
 obj-$(CONFIG_SND_SOC_TEGRA_WM8753) += snd-soc-tegra-wm8753.o
 obj-$(CONFIG_SND_SOC_TEGRA_WM8903) += snd-soc-tegra-wm8903.o
 obj-$(CONFIG_SND_SOC_TEGRA_WM9712) += snd-soc-tegra-wm9712.o
diff --git a/sound/soc/tegra/tegra_rt5677.c b/sound/soc/tegra/tegra_rt5677.c
new file mode 100644
index 0000000..ce15876
--- /dev/null
+++ b/sound/soc/tegra/tegra_rt5677.c
@@ -0,0 +1,383 @@
+/*
+* tegra_rt5677.c - Tegra machine ASoC driver for boards using RT5677 codec.
+ *
+ * Copyright (c) 2014, The Chromium OS Authors.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Based on code copyright/by:
+ *
+ * Copyright (C) 2010-2012 - NVIDIA, Inc.
+ * Copyright (C) 2011 The AC100 Kernel Team <ac100@lists.lauchpad.net>
+ * (c) 2009, 2010 Nvidia Graphics Pvt. Ltd.
+ * Copyright 2007 Wolfson Microelectronics PLC.
+ */
+
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/gpio.h>
+#include <linux/of_gpio.h>
+
+#include <sound/core.h>
+#include <sound/jack.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/soc.h>
+
+#include "../codecs/rt5677.h"
+
+#include "tegra_asoc_utils.h"
+
+#define DRV_NAME "tegra-snd-rt5677"
+
+struct tegra_rt5677 {
+	struct tegra_asoc_utils_data util_data;
+	int gpio_hp_det;
+	int gpio_hp_en;
+	int gpio_mic_present;
+	int gpio_dmic_clk_en;
+};
+
+static struct snd_soc_pcm_stream tegra_rt5677_spk_params = {
+	.formats = SNDRV_PCM_FMTBIT_S16_LE,
+	.channels_min = 2,
+	.channels_max = 2,
+};
+
+static int tegra_rt5677_asoc_hw_params(struct snd_pcm_substream *substream,
+					struct snd_pcm_hw_params *params)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct snd_soc_dai *codec_dai = rtd->codec_dai;
+	struct snd_soc_card *card = rtd->card;
+	struct tegra_rt5677 *machine = snd_soc_card_get_drvdata(card);
+	int srate, mclk, err;
+
+	srate = params_rate(params);
+	mclk = 256 * srate;
+
+	err = tegra_asoc_utils_set_rate(&machine->util_data, srate, mclk);
+	if (err < 0) {
+		dev_err(card->dev, "Can't configure clocks\n");
+		return err;
+	}
+
+	err = snd_soc_dai_set_sysclk(codec_dai, RT5677_SCLK_S_MCLK, mclk,
+					SND_SOC_CLOCK_IN);
+	if (err < 0) {
+		dev_err(card->dev, "codec_dai clock not set\n");
+		return err;
+	}
+
+	/* both dai interfaces use the same bit clock,
+	 * set rate for both interfaces the same, otherwise driver might not
+	 * be able to configure clock divider.
+	 */
+	tegra_rt5677_spk_params.rate_min = srate;
+	tegra_rt5677_spk_params.rate_max = srate;
+
+	return 0;
+}
+
+static int tegra_rt5677_event_hp(struct snd_soc_dapm_widget *w,
+			struct snd_kcontrol *k, int event)
+{
+	struct snd_soc_dapm_context *dapm = w->dapm;
+	struct snd_soc_card *card = dapm->card;
+	struct tegra_rt5677 *machine = snd_soc_card_get_drvdata(card);
+
+	if (!gpio_is_valid(machine->gpio_hp_en))
+		return 0;
+
+	gpio_set_value_cansleep(machine->gpio_hp_en,
+		SND_SOC_DAPM_EVENT_ON(event));
+
+	return 0;
+}
+
+static struct snd_soc_ops tegra_rt5677_ops = {
+	.hw_params = tegra_rt5677_asoc_hw_params,
+};
+
+static struct snd_soc_jack tegra_rt5677_hp_jack;
+
+static struct snd_soc_jack_pin tegra_rt5677_hp_jack_pins = {
+	.pin = "Headphone",
+	.mask = SND_JACK_HEADPHONE,
+};
+static struct snd_soc_jack_gpio tegra_rt5677_hp_jack_gpio = {
+	.name = "Headphone detection",
+	.report = SND_JACK_HEADPHONE,
+	.debounce_time = 150,
+};
+
+static struct snd_soc_jack tegra_rt5677_mic_jack;
+
+static struct snd_soc_jack_pin tegra_rt5677_mic_jack_pins = {
+	.pin = "Headset Mic",
+	.mask = SND_JACK_MICROPHONE,
+};
+
+static struct snd_soc_jack_gpio tegra_rt5677_mic_jack_gpio = {
+	.name = "Headset Mic detection",
+	.report = SND_JACK_MICROPHONE,
+	.debounce_time = 150,
+	.invert = 1
+};
+
+static const struct snd_soc_dapm_widget tegra_rt5677_dapm_widgets[] = {
+	SND_SOC_DAPM_SPK("Speaker", NULL),
+	SND_SOC_DAPM_HP("Headphone", tegra_rt5677_event_hp),
+	SND_SOC_DAPM_MIC("Headset Mic", NULL),
+	SND_SOC_DAPM_MIC("Internal Mic 1", NULL),
+	SND_SOC_DAPM_MIC("Internal Mic 2", NULL),
+};
+
+static const struct snd_kcontrol_new tegra_rt5677_controls[] = {
+	SOC_DAPM_PIN_SWITCH("Speaker"),
+	SOC_DAPM_PIN_SWITCH("Headphone"),
+	SOC_DAPM_PIN_SWITCH("Headset Mic"),
+	SOC_DAPM_PIN_SWITCH("Internal Mic 1"),
+	SOC_DAPM_PIN_SWITCH("Internal Mic 2"),
+};
+
+static int tegra_rt5677_asoc_init(struct snd_soc_pcm_runtime *rtd)
+{
+	struct snd_soc_dai *codec_dai = rtd->codec_dai;
+	struct snd_soc_codec *codec = codec_dai->codec;
+	struct snd_soc_dapm_context *dapm = &codec->dapm;
+	struct tegra_rt5677 *machine = snd_soc_card_get_drvdata(rtd->card);
+
+	snd_soc_jack_new(codec, "Headphone Jack", SND_JACK_HEADPHONE,
+			&tegra_rt5677_hp_jack);
+	snd_soc_jack_add_pins(&tegra_rt5677_hp_jack, 1,
+			&tegra_rt5677_hp_jack_pins);
+
+	if (gpio_is_valid(machine->gpio_hp_det)) {
+		tegra_rt5677_hp_jack_gpio.gpio = machine->gpio_hp_det;
+		snd_soc_jack_add_gpios(&tegra_rt5677_hp_jack, 1,
+				&tegra_rt5677_hp_jack_gpio);
+	}
+
+
+	snd_soc_jack_new(codec, "Mic Jack", SND_JACK_MICROPHONE,
+			&tegra_rt5677_mic_jack);
+	snd_soc_jack_add_pins(&tegra_rt5677_mic_jack, 1,
+			&tegra_rt5677_mic_jack_pins);
+
+	if (gpio_is_valid(machine->gpio_mic_present)) {
+		tegra_rt5677_mic_jack_gpio.gpio = machine->gpio_mic_present;
+		snd_soc_jack_add_gpios(&tegra_rt5677_mic_jack, 1,
+				&tegra_rt5677_mic_jack_gpio);
+	}
+
+	snd_soc_dapm_force_enable_pin(dapm, "MICBIAS1");
+
+	return 0;
+}
+
+static int tegra_rt5677_card_remove(struct snd_soc_card *card)
+{
+	struct tegra_rt5677 *machine = snd_soc_card_get_drvdata(card);
+
+	if (gpio_is_valid(machine->gpio_hp_det)) {
+		snd_soc_jack_free_gpios(&tegra_rt5677_hp_jack, 1,
+				&tegra_rt5677_hp_jack_gpio);
+	}
+
+	if (gpio_is_valid(machine->gpio_mic_present)) {
+		snd_soc_jack_free_gpios(&tegra_rt5677_mic_jack, 1,
+				&tegra_rt5677_mic_jack_gpio);
+	}
+
+	return 0;
+}
+
+static struct snd_soc_dai_link tegra_rt5677_dai[] = {
+	{
+		.name = "RT5677",
+		.stream_name = "RT5677 PCM",
+		.codec_dai_name = "rt5677-aif1",
+		.init = tegra_rt5677_asoc_init,
+		.ops = &tegra_rt5677_ops,
+		.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
+				SND_SOC_DAIFMT_CBS_CFS,
+	}, {
+		.name = "SSM4567",
+		.stream_name = "Speaker",
+		.cpu_dai_name = "rt5677-aif2",
+		.codec_dai_name = "ssm4567-hifi",
+		.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
+				SND_SOC_DAIFMT_CBS_CFS,
+		.params = &tegra_rt5677_spk_params,
+		.playback_only = true,
+	}
+};
+
+static struct snd_soc_card snd_soc_tegra_rt5677 = {
+	.name = "tegra-rt5677",
+	.owner = THIS_MODULE,
+	.remove = tegra_rt5677_card_remove,
+	.dai_link = tegra_rt5677_dai,
+	.num_links = ARRAY_SIZE(tegra_rt5677_dai),
+	.controls = tegra_rt5677_controls,
+	.num_controls = ARRAY_SIZE(tegra_rt5677_controls),
+	.dapm_widgets = tegra_rt5677_dapm_widgets,
+	.num_dapm_widgets = ARRAY_SIZE(tegra_rt5677_dapm_widgets),
+	.fully_routed = true,
+};
+
+static int tegra_rt5677_probe(struct platform_device *pdev)
+{
+	struct device_node *np = pdev->dev.of_node;
+	struct snd_soc_card *card = &snd_soc_tegra_rt5677;
+	struct tegra_rt5677 *machine;
+	int ret;
+	struct snd_soc_dai_link *codec_dai = &tegra_rt5677_dai[0];
+	struct snd_soc_dai_link *speaker_dai = &tegra_rt5677_dai[1];
+
+	machine = devm_kzalloc(&pdev->dev,
+			sizeof(struct tegra_rt5677), GFP_KERNEL);
+	if (!machine)
+		return -ENOMEM;
+
+	card->dev = &pdev->dev;
+	platform_set_drvdata(pdev, card);
+	snd_soc_card_set_drvdata(card, machine);
+
+	machine->gpio_hp_det = of_get_named_gpio(np, "nvidia,hp-det-gpios", 0);
+	if (machine->gpio_hp_det == -EPROBE_DEFER)
+		return -EPROBE_DEFER;
+
+	machine->gpio_mic_present = of_get_named_gpio(np,
+			"nvidia,mic-present-gpios", 0);
+	if (machine->gpio_mic_present == -EPROBE_DEFER)
+		return -EPROBE_DEFER;
+
+	machine->gpio_hp_en = of_get_named_gpio(np, "nvidia,hp-en-gpios", 0);
+	if (machine->gpio_hp_en == -EPROBE_DEFER)
+		return -EPROBE_DEFER;
+	if (gpio_is_valid(machine->gpio_hp_en)) {
+		ret = devm_gpio_request_one(&pdev->dev, machine->gpio_hp_en,
+				GPIOF_OUT_INIT_LOW, "hp_en");
+		if (ret) {
+			dev_err(card->dev, "cannot get hp_en gpio\n");
+			return ret;
+		}
+	}
+
+	machine->gpio_dmic_clk_en = of_get_named_gpio(np,
+		"nvidia,dmic-clk-en-gpios", 0);
+	if (machine->gpio_dmic_clk_en == -EPROBE_DEFER)
+		return -EPROBE_DEFER;
+	if (gpio_is_valid(machine->gpio_dmic_clk_en)) {
+		ret = devm_gpio_request_one(&pdev->dev,
+				machine->gpio_dmic_clk_en,
+				GPIOF_OUT_INIT_HIGH, "dmic_clk_en");
+		if (ret) {
+			dev_err(card->dev, "cannot get dmic_clk_en gpio\n");
+			return ret;
+		}
+	}
+
+	ret = snd_soc_of_parse_card_name(card, "nvidia,model");
+	if (ret)
+		goto err;
+
+	ret = snd_soc_of_parse_audio_routing(card, "nvidia,audio-routing");
+	if (ret)
+		goto err;
+
+	codec_dai->codec_of_node = of_parse_phandle(np,
+			"nvidia,audio-codec", 0);
+	if (!codec_dai->codec_of_node) {
+		dev_err(&pdev->dev,
+			"Property 'nvidia,audio-codec' missing or invalid\n");
+		ret = -EINVAL;
+		goto err;
+	}
+
+	codec_dai->cpu_of_node = of_parse_phandle(np,
+			"nvidia,i2s-controller", 0);
+	if (!codec_dai->cpu_of_node) {
+		dev_err(&pdev->dev,
+			"Property 'nvidia,i2s-controller' missing or invalid\n");
+		ret = -EINVAL;
+		goto err;
+	}
+	codec_dai->platform_of_node = codec_dai->cpu_of_node;
+
+	speaker_dai->codec_of_node = of_parse_phandle(np,
+			"nvidia,speaker-codec", 0);
+	if (!speaker_dai->codec_of_node) {
+		dev_err(&pdev->dev,
+			"Property 'nvidia,speaker-codec' missing or invalid\n");
+		ret = -EINVAL;
+		goto err;
+	}
+	speaker_dai->cpu_of_node = codec_dai->codec_of_node;
+
+	ret = tegra_asoc_utils_init(&machine->util_data, &pdev->dev);
+	if (ret)
+		goto err;
+
+	ret = snd_soc_register_card(card);
+	if (ret) {
+		dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
+			ret);
+		goto err_fini_utils;
+	}
+
+	return 0;
+
+err_fini_utils:
+	tegra_asoc_utils_fini(&machine->util_data);
+err:
+	return ret;
+}
+
+static int tegra_rt5677_remove(struct platform_device *pdev)
+{
+	struct snd_soc_card *card = platform_get_drvdata(pdev);
+	struct tegra_rt5677 *machine = snd_soc_card_get_drvdata(card);
+
+	snd_soc_unregister_card(card);
+
+	tegra_asoc_utils_fini(&machine->util_data);
+
+	return 0;
+}
+
+static const struct of_device_id tegra_rt5677_of_match[] = {
+	{ .compatible = "nvidia,tegra-audio-rt5677", },
+	{},
+};
+
+static struct platform_driver tegra_rt5677_driver = {
+	.driver = {
+		.name = DRV_NAME,
+		.owner = THIS_MODULE,
+		.pm = &snd_soc_pm_ops,
+		.of_match_table = tegra_rt5677_of_match,
+	},
+	.probe = tegra_rt5677_probe,
+	.remove = tegra_rt5677_remove,
+};
+module_platform_driver(tegra_rt5677_driver);
+
+MODULE_AUTHOR("Anatol Pomozov <anatol@google.com>");
+MODULE_DESCRIPTION("Tegra+RT5677 machine ASoC driver");
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("platform:" DRV_NAME);
+MODULE_DEVICE_TABLE(of, tegra_rt5677_of_match);
-- 
2.1.0.rc2.206.gedb03e5

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH] ASoc: tegra: Add platform driver for rt5677 audio codec
  2014-10-07  3:44 ` Stephen Warren
@ 2014-10-07  5:29   ` Anatol Pomazau
  0 siblings, 0 replies; 16+ messages in thread
From: Anatol Pomazau @ 2014-10-07  5:29 UTC (permalink / raw)
  To: Stephen Warren
  Cc: Oder Chiou, alsa-devel, lars, Anatol Pomozov, broonie, Bard Liao,
	ldahan, Dylan Reid

Hi

On Mon, Oct 6, 2014 at 8:44 PM, Stephen Warren <swarren@nvidia.com> wrote:

> On 09/30/2014 02:52 PM, Anatol Pomozov wrote:
> > The driver will support Ryu board
>
> > diff --git
> a/Documentation/devicetree/bindings/sound/nvidia,tegra-audio-rt5677.txt
> b/Documentation/devicetree/bindings/sound/nvidia,tegra-audio-rt5677.txt
>
> > +- nvidia,i2s-controller : The phandle of the Tegra I2S controller that's
> > +  connected to the CODEC.
> > +- nvidia,audio-codec : The phandle of the RT5677 audio codec. This
> binding
> > +  assumes that AIF1 on the CODEC is connected to Tegra.
> > +- nvidia,speaker-codec: The phandle of the SSM4567 amplifier. This
> binding
> > +  assumes that AIF2 on the audio CODEC is connected to this speaker
> amplifier.
>
> Does the CODEC only output audio on an I2S link, or does it also have
> analog outputs?


Tegra Ryu board uses LOUT1/LOUT2 for headphones and I2S2 for speaker amp.


> As Mark mentioned, this binding deviates from the other
> generic audio bindings for Tegra in that the others all have CODEC
> analog outputs connected to speakers/headphones, whereas this binding
> requires an extra I2S based component, which doesn't seem very generic.
>

> > +sound {
> > +     compatible = "nvidia,tegra-audio-rt5677-ryu",
> > +                     "nvidia,tegra-audio-rt5677";
> > +     nvidia,model = "NVIDIA Tegra Ryu";
> > +
> > +     nvidia,audio-routing =
> > +             // rt5677 codec
>
> Let's use /* */
>
> > diff --git a/sound/soc/tegra/tegra_rt5677.c
> b/sound/soc/tegra/tegra_rt5677.c
>
> > +static struct snd_soc_pcm_stream tegra_rt5677_spk_params = {
> > +     .formats = SNDRV_PCM_FMTBIT_S16_LE,
> > +     .channels_min = 2,
> > +     .channels_max = 2,
> > +};
> ...
> > +static int tegra_rt5677_asoc_hw_params(struct snd_pcm_substream
> *substream,
> > +                                     struct snd_pcm_hw_params *params)
> ...
> > +     /* both dai interfaces use the same bit clock,
> > +      * set rate for both interfaces the same, otherwise driver might
> not
> > +      * be able to configure clock divider.
> > +      */
> > +     tegra_rt5677_spk_params.rate_min = srate;
> > +     tegra_rt5677_spk_params.rate_max = srate;
>
> This feels a bit odd. Shouldn't hw_params simply call some function on
> the appropriate DAI to configure it directly for the required sample rate?
>

That actually was my question above. Is there any better way to do the
same? I did not find any function that does it.


>
> > +static struct snd_soc_dai_link tegra_rt5677_dai[] = {
> > +{
>
> The array entries should be indented 1 level.
>
> > +static int tegra_rt5677_remove(struct platform_device *pdev)
> > +{
> > +     struct snd_soc_card *card = platform_get_drvdata(pdev);
> > +     struct tegra_rt5677 *machine = snd_soc_card_get_drvdata(card);
> > +
> > +     snd_soc_jack_free_gpios(&tegra_rt5677_hp_jack, 1,
> > +                             &tegra_rt5677_hp_jack_gpio);
>
> That needs to be part of the struct snd_soc_card's .remove function, not
> the struct platform_driver's .remove function. See the git history of
> other Tegra reasons for details of the crash this prevents.
>

Thanks for the pointer, the change you mentioned is fb6b8e71448aef. Fixed
it locally.

I will send updated change in a few days in addition to other cosmetic
changes.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] ASoc: tegra: Add platform driver for rt5677 audio codec
  2014-09-30 21:52 [PATCH] ASoc: " Anatol Pomozov
  2014-10-01 18:17 ` Mark Brown
@ 2014-10-07  3:44 ` Stephen Warren
  2014-10-07  5:29   ` Anatol Pomazau
  1 sibling, 1 reply; 16+ messages in thread
From: Stephen Warren @ 2014-10-07  3:44 UTC (permalink / raw)
  To: Anatol Pomozov, broonie, bardliao, oder_chiou, lars, ldahan, dgreid
  Cc: alsa-devel, Anatol Pomozov

On 09/30/2014 02:52 PM, Anatol Pomozov wrote:
> The driver will support Ryu board

> diff --git a/Documentation/devicetree/bindings/sound/nvidia,tegra-audio-rt5677.txt b/Documentation/devicetree/bindings/sound/nvidia,tegra-audio-rt5677.txt

> +- nvidia,i2s-controller : The phandle of the Tegra I2S controller that's
> +  connected to the CODEC.
> +- nvidia,audio-codec : The phandle of the RT5677 audio codec. This binding
> +  assumes that AIF1 on the CODEC is connected to Tegra.
> +- nvidia,speaker-codec: The phandle of the SSM4567 amplifier. This binding
> +  assumes that AIF2 on the audio CODEC is connected to this speaker amplifier.

Does the CODEC only output audio on an I2S link, or does it also have
analog outputs? As Mark mentioned, this binding deviates from the other
generic audio bindings for Tegra in that the others all have CODEC
analog outputs connected to speakers/headphones, whereas this binding
requires an extra I2S based component, which doesn't seem very generic.

> +sound {
> +	compatible = "nvidia,tegra-audio-rt5677-ryu",
> +			"nvidia,tegra-audio-rt5677";
> +	nvidia,model = "NVIDIA Tegra Ryu";
> +
> +	nvidia,audio-routing =
> +		// rt5677 codec

Let's use /* */

> diff --git a/sound/soc/tegra/tegra_rt5677.c b/sound/soc/tegra/tegra_rt5677.c

> +static struct snd_soc_pcm_stream tegra_rt5677_spk_params = {
> +	.formats = SNDRV_PCM_FMTBIT_S16_LE,
> +	.channels_min = 2,
> +	.channels_max = 2,
> +};
...
> +static int tegra_rt5677_asoc_hw_params(struct snd_pcm_substream *substream,
> +					struct snd_pcm_hw_params *params)
...
> +	/* both dai interfaces use the same bit clock,
> +	 * set rate for both interfaces the same, otherwise driver might not
> +	 * be able to configure clock divider.
> +	 */
> +	tegra_rt5677_spk_params.rate_min = srate;
> +	tegra_rt5677_spk_params.rate_max = srate;

This feels a bit odd. Shouldn't hw_params simply call some function on
the appropriate DAI to configure it directly for the required sample rate?

> +static struct snd_soc_dai_link tegra_rt5677_dai[] = {
> +{

The array entries should be indented 1 level.

> +static int tegra_rt5677_remove(struct platform_device *pdev)
> +{
> +	struct snd_soc_card *card = platform_get_drvdata(pdev);
> +	struct tegra_rt5677 *machine = snd_soc_card_get_drvdata(card);
> +
> +	snd_soc_jack_free_gpios(&tegra_rt5677_hp_jack, 1,
> +				&tegra_rt5677_hp_jack_gpio);

That needs to be part of the struct snd_soc_card's .remove function, not
the struct platform_driver's .remove function. See the git history of
other Tegra reasons for details of the crash this prevents.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] ASoc: tegra: Add platform driver for rt5677 audio codec
  2014-09-30 21:52 [PATCH] ASoc: " Anatol Pomozov
@ 2014-10-01 18:17 ` Mark Brown
  2014-10-07  3:44 ` Stephen Warren
  1 sibling, 0 replies; 16+ messages in thread
From: Mark Brown @ 2014-10-01 18:17 UTC (permalink / raw)
  To: Anatol Pomozov
  Cc: oder_chiou, alsa-devel, lars, swarren, Anatol Pomozov, bardliao,
	ldahan, dgreid


[-- Attachment #1.1: Type: text/plain, Size: 566 bytes --]

On Tue, Sep 30, 2014 at 02:52:19PM -0700, Anatol Pomozov wrote:
> The driver will support Ryu board

> +- nvidia,audio-codec : The phandle of the RT5677 audio codec. This binding
> +  assumes that AIF1 on the CODEC is connected to Tegra.
> +- nvidia,speaker-codec: The phandle of the SSM4567 amplifier. This binding
> +  assumes that AIF2 on the audio CODEC is connected to this speaker amplifier.

This isn't as generic as all that, it relies on the specific speaker
driver.  I'd suggest either just saying it's board specific or making
the speaker CODEC optional.

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH] ASoc: tegra: Add platform driver for rt5677 audio codec
@ 2014-09-30 21:52 Anatol Pomozov
  2014-10-01 18:17 ` Mark Brown
  2014-10-07  3:44 ` Stephen Warren
  0 siblings, 2 replies; 16+ messages in thread
From: Anatol Pomozov @ 2014-09-30 21:52 UTC (permalink / raw)
  To: broonie, bardliao, oder_chiou, swarren, lars, ldahan, dgreid
  Cc: alsa-devel, Anatol Pomozov, Anatol Pomozov

The driver will support Ryu board

Signed-off-by: Anatol Pomozov <anatol@google.com>
---
 .../bindings/sound/nvidia,tegra-audio-rt5677.txt   |  70 +++++
 sound/soc/tegra/Kconfig                            |  11 +
 sound/soc/tegra/Makefile                           |   2 +
 sound/soc/tegra/tegra_rt5677.c                     | 336 +++++++++++++++++++++
 4 files changed, 419 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/nvidia,tegra-audio-rt5677.txt
 create mode 100644 sound/soc/tegra/tegra_rt5677.c

diff --git a/Documentation/devicetree/bindings/sound/nvidia,tegra-audio-rt5677.txt b/Documentation/devicetree/bindings/sound/nvidia,tegra-audio-rt5677.txt
new file mode 100644
index 0000000..a42c96a
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/nvidia,tegra-audio-rt5677.txt
@@ -0,0 +1,70 @@
+NVIDIA Tegra audio complex, with RT5677 CODEC
+
+Required properties:
+- compatible : "nvidia,tegra-audio-rt5677"
+- clocks : Must contain an entry for each entry in clock-names.
+  See ../clocks/clock-bindings.txt for details.
+- clock-names : Must include the following entries:
+  - pll_a
+  - pll_a_out0
+  - mclk (The Tegra cdev1/extern1 clock, which feeds the CODEC's mclk)
+- nvidia,model : The user-visible name of this sound complex.
+- nvidia,audio-routing : A list of the connections between audio components.
+  Each entry is a pair of strings, the first being the connection's sink,
+  the second being the connection's source. Valid names for sources and
+  sinks are the RT5677's pins (as documented in its binding), and the jacks
+  on the board:
+
+  * Headphones
+  * Speakers
+  * Mic Jack
+  * Internal Mic 1
+  * Internal Mic 2
+
+- nvidia,i2s-controller : The phandle of the Tegra I2S controller that's
+  connected to the CODEC.
+- nvidia,audio-codec : The phandle of the RT5677 audio codec. This binding
+  assumes that AIF1 on the CODEC is connected to Tegra.
+- nvidia,speaker-codec: The phandle of the SSM4567 amplifier. This binding
+  assumes that AIF2 on the audio CODEC is connected to this speaker amplifier.
+
+Optional properties:
+- nvidia,hp-det-gpios : The GPIO that detects headphones are plugged in
+- nvidia,hp-en-gpios : The GPIO that enables headphone amplifier
+- nvidia,dmic-clk-en-gpios : The GPIO that gates DMIC clock
+
+Example:
+
+sound {
+	compatible = "nvidia,tegra-audio-rt5677-ryu",
+			"nvidia,tegra-audio-rt5677";
+	nvidia,model = "NVIDIA Tegra Ryu";
+
+	nvidia,audio-routing =
+		// rt5677 codec
+		"Headphones", "LOUT2",
+		"Headphones", "LOUT1",
+		"Mic Jack", "MICBIAS1",
+		"IN1P", "Mic Jack",
+		"IN1N", "Mic Jack",
+		"DMIC L1", "Internal Mic 1",
+		"DMIC R1", "Internal Mic 1",
+		"DMIC L2", "Internal Mic 2",
+		"DMIC R2", "Internal Mic 2",
+		// speaker amp
+		"DAC", "AIF2TX",
+		"Speakers", "OUT";
+
+	nvidia,i2s-controller = <&tegra_i2s1>;
+	nvidia,audio-codec = <&rt5677>;
+	nvidia,speaker-codec = <&ssm4567>;
+
+	nvidia,hp-det-gpios = <&gpio TEGRA_GPIO(R, 7) GPIO_ACTIVE_HIGH>;
+	nvidia,hp-en-gpios = <&rt5677 1 GPIO_ACTIVE_HIGH>;
+	nvidia,dmic-clk-en-gpios = <&rt5677 2 GPIO_ACTIVE_HIGH>;
+
+	clocks = <&tegra_car TEGRA124_CLK_PLL_A>,
+	         <&tegra_car TEGRA124_CLK_PLL_A_OUT0>,
+	         <&tegra_car TEGRA124_CLK_EXTERN1>;
+	clock-names = "pll_a", "pll_a_out0", "mclk";
+};
diff --git a/sound/soc/tegra/Kconfig b/sound/soc/tegra/Kconfig
index 31198cf7..c30611e 100644
--- a/sound/soc/tegra/Kconfig
+++ b/sound/soc/tegra/Kconfig
@@ -128,3 +128,14 @@ config SND_SOC_TEGRA_MAX98090
 	help
 	  Say Y or M here if you want to add support for SoC audio on Tegra
 	  boards using the MAX98090 codec, such as Venice2.
+
+config SND_SOC_TEGRA_RT5677
+	tristate "SoC Audio support for Tegra boards using a RT5677 codec"
+	depends on SND_SOC_TEGRA && I2C && GPIOLIB
+	select SND_SOC_TEGRA20_I2S if ARCH_TEGRA_2x_SOC
+	select SND_SOC_TEGRA30_I2S if ARCH_TEGRA_3x_SOC
+	select SND_SOC_RT5677
+	select SND_SOC_SSM4567
+	help
+	  Say Y or M here if you want to add support for SoC audio on Tegra
+	  boards using the RT5677 codec, such as Ryu.
diff --git a/sound/soc/tegra/Makefile b/sound/soc/tegra/Makefile
index 5ae588c..9171655 100644
--- a/sound/soc/tegra/Makefile
+++ b/sound/soc/tegra/Makefile
@@ -19,6 +19,7 @@ obj-$(CONFIG_SND_SOC_TEGRA30_I2S) += snd-soc-tegra30-i2s.o
 
 # Tegra machine Support
 snd-soc-tegra-rt5640-objs := tegra_rt5640.o
+snd-soc-tegra-rt5677-objs := tegra_rt5677.o
 snd-soc-tegra-wm8753-objs := tegra_wm8753.o
 snd-soc-tegra-wm8903-objs := tegra_wm8903.o
 snd-soc-tegra-wm9712-objs := tegra_wm9712.o
@@ -27,6 +28,7 @@ snd-soc-tegra-alc5632-objs := tegra_alc5632.o
 snd-soc-tegra-max98090-objs := tegra_max98090.o
 
 obj-$(CONFIG_SND_SOC_TEGRA_RT5640) += snd-soc-tegra-rt5640.o
+obj-$(CONFIG_SND_SOC_TEGRA_RT5677) += snd-soc-tegra-rt5677.o
 obj-$(CONFIG_SND_SOC_TEGRA_WM8753) += snd-soc-tegra-wm8753.o
 obj-$(CONFIG_SND_SOC_TEGRA_WM8903) += snd-soc-tegra-wm8903.o
 obj-$(CONFIG_SND_SOC_TEGRA_WM9712) += snd-soc-tegra-wm9712.o
diff --git a/sound/soc/tegra/tegra_rt5677.c b/sound/soc/tegra/tegra_rt5677.c
new file mode 100644
index 0000000..7503cd2
--- /dev/null
+++ b/sound/soc/tegra/tegra_rt5677.c
@@ -0,0 +1,336 @@
+/*
+* tegra_rt5677.c - Tegra machine ASoC driver for boards using RT5677 codec.
+ *
+ * Copyright (c) 2014, The Chromium OS Authors.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Based on code copyright/by:
+ *
+ * Copyright (C) 2010-2012 - NVIDIA, Inc.
+ * Copyright (C) 2011 The AC100 Kernel Team <ac100@lists.lauchpad.net>
+ * (c) 2009, 2010 Nvidia Graphics Pvt. Ltd.
+ * Copyright 2007 Wolfson Microelectronics PLC.
+ */
+
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/gpio.h>
+#include <linux/of_gpio.h>
+
+#include <sound/core.h>
+#include <sound/jack.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/soc.h>
+
+#include "../codecs/rt5677.h"
+
+#include "tegra_asoc_utils.h"
+
+#define DRV_NAME "tegra-snd-rt5677"
+
+struct tegra_rt5677 {
+	struct tegra_asoc_utils_data util_data;
+	int gpio_hp_det;
+	int gpio_hp_en;
+	int gpio_dmic_clk_en;
+};
+
+static struct snd_soc_pcm_stream tegra_rt5677_spk_params = {
+	.formats = SNDRV_PCM_FMTBIT_S16_LE,
+	.channels_min = 2,
+	.channels_max = 2,
+};
+
+static int tegra_rt5677_asoc_hw_params(struct snd_pcm_substream *substream,
+					struct snd_pcm_hw_params *params)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct snd_soc_dai *codec_dai = rtd->codec_dai;
+	struct snd_soc_card *card = rtd->card;
+	struct tegra_rt5677 *machine = snd_soc_card_get_drvdata(card);
+	int srate, mclk, err;
+
+	srate = params_rate(params);
+	mclk = 256 * srate;
+
+	err = tegra_asoc_utils_set_rate(&machine->util_data, srate, mclk);
+	if (err < 0) {
+		dev_err(card->dev, "Can't configure clocks\n");
+		return err;
+	}
+
+	err = snd_soc_dai_set_sysclk(codec_dai, RT5677_SCLK_S_MCLK, mclk,
+					SND_SOC_CLOCK_IN);
+	if (err < 0) {
+		dev_err(card->dev, "codec_dai clock not set\n");
+		return err;
+	}
+
+	/* both dai interfaces use the same bit clock,
+	 * set rate for both interfaces the same, otherwise driver might not
+	 * be able to configure clock divider.
+	 */
+	tegra_rt5677_spk_params.rate_min = srate;
+	tegra_rt5677_spk_params.rate_max = srate;
+
+	return 0;
+}
+
+static int tegra_rt5677_event_hp(struct snd_soc_dapm_widget *w,
+			struct snd_kcontrol *k, int event)
+{
+	struct snd_soc_dapm_context *dapm = w->dapm;
+	struct snd_soc_card *card = dapm->card;
+	struct tegra_rt5677 *machine = snd_soc_card_get_drvdata(card);
+
+	if (!gpio_is_valid(machine->gpio_hp_en))
+		return 0;
+
+	gpio_set_value_cansleep(machine->gpio_hp_en,
+		SND_SOC_DAPM_EVENT_ON(event));
+
+	return 0;
+}
+
+static struct snd_soc_ops tegra_rt5677_ops = {
+	.hw_params = tegra_rt5677_asoc_hw_params,
+};
+
+static struct snd_soc_jack tegra_rt5677_hp_jack;
+
+static struct snd_soc_jack_pin tegra_rt5677_hp_jack_pins = {
+	.pin = "Headphones",
+	.mask = SND_JACK_HEADPHONE,
+};
+
+static struct snd_soc_jack_gpio tegra_rt5677_hp_jack_gpio = {
+	.name = "Headphones detection",
+	.report = SND_JACK_HEADPHONE,
+	.debounce_time = 150,
+};
+
+static const struct snd_soc_dapm_widget tegra_rt5677_dapm_widgets[] = {
+	SND_SOC_DAPM_SPK("Speakers", NULL),
+	SND_SOC_DAPM_HP("Headphones", tegra_rt5677_event_hp),
+	SND_SOC_DAPM_MIC("Mic Jack", NULL),
+	SND_SOC_DAPM_MIC("Internal Mic 1", NULL),
+	SND_SOC_DAPM_MIC("Internal Mic 2", NULL),
+};
+
+static const struct snd_kcontrol_new tegra_rt5677_controls[] = {
+	SOC_DAPM_PIN_SWITCH("Speakers"),
+	SOC_DAPM_PIN_SWITCH("Internal Mic 1"),
+	SOC_DAPM_PIN_SWITCH("Internal Mic 2"),
+};
+
+static int tegra_rt5677_asoc_init(struct snd_soc_pcm_runtime *rtd)
+{
+	struct snd_soc_dai *codec_dai = rtd->codec_dai;
+	struct snd_soc_codec *codec = codec_dai->codec;
+	struct snd_soc_dapm_context *dapm = &codec->dapm;
+	struct tegra_rt5677 *machine = snd_soc_card_get_drvdata(rtd->card);
+
+	snd_soc_jack_new(codec, "Headphones", SND_JACK_HEADPHONE,
+			 &tegra_rt5677_hp_jack);
+	snd_soc_jack_add_pins(&tegra_rt5677_hp_jack, 1,
+			&tegra_rt5677_hp_jack_pins);
+
+	if (gpio_is_valid(machine->gpio_hp_det)) {
+		tegra_rt5677_hp_jack_gpio.gpio = machine->gpio_hp_det;
+		snd_soc_jack_add_gpios(&tegra_rt5677_hp_jack, 1,
+				&tegra_rt5677_hp_jack_gpio);
+	}
+
+	snd_soc_dapm_force_enable_pin(dapm, "MICBIAS1");
+
+	return 0;
+}
+
+static struct snd_soc_dai_link tegra_rt5677_dai[] = {
+{
+	.name = "RT5677",
+	.stream_name = "RT5677 PCM",
+	.codec_dai_name = "rt5677-aif1",
+	.init = tegra_rt5677_asoc_init,
+	.ops = &tegra_rt5677_ops,
+	.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
+			SND_SOC_DAIFMT_CBS_CFS,
+},
+{
+	.name = "SSM4567",
+	.stream_name = "Speaker",
+	.cpu_dai_name = "rt5677-aif2",
+	.codec_dai_name = "ssm4567-hifi",
+	.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
+			SND_SOC_DAIFMT_CBS_CFS,
+	.params = &tegra_rt5677_spk_params,
+	.playback_only = true,
+}
+};
+
+static struct snd_soc_card snd_soc_tegra_rt5677 = {
+	.name = "tegra-rt5677",
+	.owner = THIS_MODULE,
+	.dai_link = tegra_rt5677_dai,
+	.num_links = ARRAY_SIZE(tegra_rt5677_dai),
+	.controls = tegra_rt5677_controls,
+	.num_controls = ARRAY_SIZE(tegra_rt5677_controls),
+	.dapm_widgets = tegra_rt5677_dapm_widgets,
+	.num_dapm_widgets = ARRAY_SIZE(tegra_rt5677_dapm_widgets),
+	.fully_routed = true,
+};
+
+static int tegra_rt5677_probe(struct platform_device *pdev)
+{
+	struct device_node *np = pdev->dev.of_node;
+	struct snd_soc_card *card = &snd_soc_tegra_rt5677;
+	struct tegra_rt5677 *machine;
+	int ret;
+	struct snd_soc_dai_link *codec_dai = &tegra_rt5677_dai[0];
+	struct snd_soc_dai_link *speaker_dai = &tegra_rt5677_dai[1];
+
+	machine = devm_kzalloc(&pdev->dev,
+			sizeof(struct tegra_rt5677), GFP_KERNEL);
+	if (!machine)
+		return -ENOMEM;
+
+	card->dev = &pdev->dev;
+	platform_set_drvdata(pdev, card);
+	snd_soc_card_set_drvdata(card, machine);
+
+	machine->gpio_hp_det = of_get_named_gpio(np, "nvidia,hp-det-gpios", 0);
+	if (machine->gpio_hp_det == -EPROBE_DEFER)
+		return -EPROBE_DEFER;
+
+	machine->gpio_hp_en = of_get_named_gpio(np, "nvidia,hp-en-gpios", 0);
+	if (machine->gpio_hp_en == -EPROBE_DEFER)
+		return -EPROBE_DEFER;
+	if (gpio_is_valid(machine->gpio_hp_en)) {
+		ret = devm_gpio_request_one(&pdev->dev, machine->gpio_hp_en,
+				GPIOF_OUT_INIT_LOW, "hp_en");
+		if (ret) {
+			dev_err(card->dev, "cannot get hp_en gpio\n");
+			return ret;
+		}
+	}
+
+	machine->gpio_dmic_clk_en = of_get_named_gpio(np,
+		"nvidia,dmic-clk-en-gpios", 0);
+	if (machine->gpio_dmic_clk_en == -EPROBE_DEFER)
+		return -EPROBE_DEFER;
+	if (gpio_is_valid(machine->gpio_dmic_clk_en)) {
+		ret = devm_gpio_request_one(&pdev->dev,
+				machine->gpio_dmic_clk_en,
+				GPIOF_OUT_INIT_HIGH, "dmic_clk_en");
+		if (ret) {
+			dev_err(card->dev, "cannot get dmic_clk_en gpio\n");
+			return ret;
+		}
+	}
+
+	ret = snd_soc_of_parse_card_name(card, "nvidia,model");
+	if (ret)
+		goto err;
+
+	ret = snd_soc_of_parse_audio_routing(card, "nvidia,audio-routing");
+	if (ret)
+		goto err;
+
+	codec_dai->codec_of_node = of_parse_phandle(np,
+			"nvidia,audio-codec", 0);
+	if (!codec_dai->codec_of_node) {
+		dev_err(&pdev->dev,
+			"Property 'nvidia,audio-codec' missing or invalid\n");
+		ret = -EINVAL;
+		goto err;
+	}
+
+	codec_dai->cpu_of_node = of_parse_phandle(np,
+			"nvidia,i2s-controller", 0);
+	if (!codec_dai->cpu_of_node) {
+		dev_err(&pdev->dev,
+			"Property 'nvidia,i2s-controller' missing or invalid\n");
+		ret = -EINVAL;
+		goto err;
+	}
+	codec_dai->platform_of_node = codec_dai->cpu_of_node;
+
+	speaker_dai->codec_of_node = of_parse_phandle(np,
+			"nvidia,speaker-codec", 0);
+	if (!speaker_dai->codec_of_node) {
+		dev_err(&pdev->dev,
+			"Property 'nvidia,speaker-codec' missing or invalid\n");
+		ret = -EINVAL;
+		goto err;
+	}
+	speaker_dai->cpu_of_node = codec_dai->codec_of_node;
+
+	ret = tegra_asoc_utils_init(&machine->util_data, &pdev->dev);
+	if (ret)
+		goto err;
+
+	ret = snd_soc_register_card(card);
+	if (ret) {
+		dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
+			ret);
+		goto err_fini_utils;
+	}
+
+	return 0;
+
+err_fini_utils:
+	tegra_asoc_utils_fini(&machine->util_data);
+err:
+	return ret;
+}
+
+static int tegra_rt5677_remove(struct platform_device *pdev)
+{
+	struct snd_soc_card *card = platform_get_drvdata(pdev);
+	struct tegra_rt5677 *machine = snd_soc_card_get_drvdata(card);
+
+	snd_soc_jack_free_gpios(&tegra_rt5677_hp_jack, 1,
+				&tegra_rt5677_hp_jack_gpio);
+
+	snd_soc_unregister_card(card);
+
+	tegra_asoc_utils_fini(&machine->util_data);
+
+	return 0;
+}
+
+static const struct of_device_id tegra_rt5677_of_match[] = {
+	{ .compatible = "nvidia,tegra-audio-rt5677", },
+	{},
+};
+
+static struct platform_driver tegra_rt5677_driver = {
+	.driver = {
+		.name = DRV_NAME,
+		.owner = THIS_MODULE,
+		.pm = &snd_soc_pm_ops,
+		.of_match_table = tegra_rt5677_of_match,
+	},
+	.probe = tegra_rt5677_probe,
+	.remove = tegra_rt5677_remove,
+};
+module_platform_driver(tegra_rt5677_driver);
+
+MODULE_AUTHOR("Anatol Pomozov <anatol@google.com>");
+MODULE_DESCRIPTION("Tegra+RT5677 machine ASoC driver");
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("platform:" DRV_NAME);
+MODULE_DEVICE_TABLE(of, tegra_rt5677_of_match);
-- 
2.1.0.rc2.206.gedb03e5

^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2015-01-07 18:54 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-23 19:29 [PATCH] ASoC: tegra: Add platform driver for rt5677 audio codec Anatol Pomozov
2014-12-23 19:36 ` Anatol Pomozov
2014-12-26 16:38 ` Mark Brown
2014-12-29 13:25   ` Anatol Pomozov
2014-12-29 15:55     ` Mark Brown
2015-01-06 18:46       ` Anatol Pomozov
  -- strict thread matches above, loose matches on Subject: below --
2014-12-30 19:12 Anatol Pomozov
2015-01-07 18:54 ` Mark Brown
2014-10-15 21:15 Anatol Pomozov
2014-10-16  7:38 ` Mark Brown
2014-10-16  8:59   ` Anatol Pomazau
2014-10-16  9:04     ` Mark Brown
2014-09-30 21:52 [PATCH] ASoc: " Anatol Pomozov
2014-10-01 18:17 ` Mark Brown
2014-10-07  3:44 ` Stephen Warren
2014-10-07  5:29   ` Anatol Pomazau

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.