From patchwork Mon Jun 13 10:52:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sylwester Nawrocki/Kernel \\(PLT\\) /SRPOL/Staff Engineer/Samsung Electronics" X-Patchwork-Id: 9172663 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 55B80604DB for ; Mon, 13 Jun 2016 10:54:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 45CFF20499 for ; Mon, 13 Jun 2016 10:54:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3A9D927C0C; Mon, 13 Jun 2016 10:54:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2C9C720499 for ; Mon, 13 Jun 2016 10:54:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965368AbcFMKyi (ORCPT ); Mon, 13 Jun 2016 06:54:38 -0400 Received: from mailout4.samsung.com ([203.254.224.34]:52676 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964910AbcFMKyh (ORCPT ); Mon, 13 Jun 2016 06:54:37 -0400 Received: from epcpsbgm1new.samsung.com (epcpsbgm1 [203.254.230.26]) by mailout4.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0O8P02QARIAU10B0@mailout4.samsung.com>; Mon, 13 Jun 2016 19:54:34 +0900 (KST) X-AuditID: cbfee61a-f79656d000001a01-5d-575e90ea81ed Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm1new.samsung.com (EPCPMTA) with SMTP id 1F.A5.06657.AE09E575; Mon, 13 Jun 2016 19:54:34 +0900 (KST) Received: from AMDC1344.digital.local ([106.116.147.32]) by mmp2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0O8P009PMI8GID90@mmp2.samsung.com>; Mon, 13 Jun 2016 19:54:34 +0900 (KST) From: Sylwester Nawrocki To: broonie@kernel.org, alsa-devel@alsa-project.org, devicetree@vger.kernel.org Cc: robh@kernel.org, linux-samsung-soc@vger.kernel.org, ideal.song@samsung.com, beomho.seo@samsung.com, inki.dae@samsung.com, k.kozlowski@samsung.com, b.zolnierkie@samsung.com, Sylwester Nawrocki Subject: [PATCH RFC 5/6] ASoC: samsung: Add machine driver for Exynos5433 based TM2 board Date: Mon, 13 Jun 2016 12:52:39 +0200 Message-id: <1465815160-28504-6-git-send-email-s.nawrocki@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1465815160-28504-1-git-send-email-s.nawrocki@samsung.com> References: <1465815160-28504-1-git-send-email-s.nawrocki@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrCLMWRmVeSWpSXmKPExsVy+t9jQd1XE+LCDeaeMrO4cvEQk8XGGetZ LU5/2sZuMfXhEzaL+UfOsVrs+nuf0WLS/QksFq9fGFrMOL+PyeL/nh3sFofftLM6cHts+NzE 5rFpVSebR9+WVYwenzfJBbBEcdmkpOZklqUW6dslcGX07L7AVvChi7Fi08ZDLA2Mjwq6GDk4 JARMJBa2WXYxcgKZYhIX7q1n62Lk4hASmMUocWjpUUYI5xejxN6/Z1lBqtgEDCV6j/Yxgtgi Av4SE/63s4AUMQs8YJQ49v84E8hUYYFoiZUXfUFqWARUJc6/u8wCYvMKuEns+9bIArFNTuLk scmsIOWcAu4SG184gYSFgEpa7u1incDIu4CRYRWjRGpBckFxUnquYV5quV5xYm5xaV66XnJ+ 7iZGcNg9k9rBeHCX+yFGAQ5GJR5ejVWx4UKsiWXFlbmHGCU4mJVEeFf3x4UL8aYkVlalFuXH F5XmpBYfYpTmYFES5338f12YkEB6YklqdmpqQWoRTJaJg1OqgVFXPqfgkcsnX5+KhcH7V69f 9d2hXVvy9dXX8nEfJxxl6nMOLyme4HfP40fh1Cib+8kvHr0p//QqRJzTxSVwJvO+C4ILRWdN rWPdEvqpfCF/5kJ3izpJkYd5qbtPSL/136qy/aid37nUA49+rC2dJrX4XYKdhGKCVFZfsmaV /o/UD63K+38qHldiKc5INNRiLipOBADd3/d5NwIAAA== Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Inha Song This patch adds the sound machine driver for TM2 board. The codec operates in master mode. So, reference to the codec master clock must be set. This machine driver supports SPK playback and Main Mic capture, BT and Voice call and external accessory. Signed-off-by: Inha Song [k.kozlowski: rebased on 4.1] Signed-off-by: Krzysztof Kozlowski [s.nawrocki: rebased to 4.7, adjustment to the ASoC core changes, removed unused ops and direct calls to the max98504 function, added parsing of "samsung,speaker-amplifier" property] Signed-off-by: Sylwester Nawrocki --- sound/soc/samsung/Kconfig | 13 + sound/soc/samsung/Makefile | 2 + sound/soc/samsung/tm2_wm5110.c | 553 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 568 insertions(+) create mode 100644 sound/soc/samsung/tm2_wm5110.c diff --git a/sound/soc/samsung/Kconfig b/sound/soc/samsung/Kconfig index 7b722b0..475b25c 100644 --- a/sound/soc/samsung/Kconfig +++ b/sound/soc/samsung/Kconfig @@ -31,6 +31,9 @@ config SND_SAMSUNG_SPDIF config SND_SAMSUNG_I2S tristate +config SND_SAMSUNG_AUDSS + tristate + config SND_SOC_SAMSUNG_NEO1973_WM8753 tristate "Audio support for Openmoko Neo1973 Smartphones (GTA02)" depends on SND_SOC_SAMSUNG && MACH_NEO1973_GTA02 @@ -229,3 +232,13 @@ config SND_SOC_ARNDALE_RT5631_ALC5631 depends on SND_SOC_SAMSUNG && I2C select SND_SAMSUNG_I2S select SND_SOC_RT5631 + +config SND_SOC_SAMSUNG_TM2_WM5110 + tristate "SoC I2S Audio support for WM5110 on TM2 board" + depends on SND_SOC_SAMSUNG + select SND_SOC_MAX98504A + select SND_SOC_WM5110 + select SND_SAMSUNG_I2S + select SND_SAMSUNG_AUDSS + help + Say Y if you want to add support for SoC audio on the TM2 board. diff --git a/sound/soc/samsung/Makefile b/sound/soc/samsung/Makefile index 2b919d5..9332991 100644 --- a/sound/soc/samsung/Makefile +++ b/sound/soc/samsung/Makefile @@ -46,6 +46,7 @@ snd-soc-lowland-objs := lowland.o snd-soc-littlemill-objs := littlemill.o snd-soc-bells-objs := bells.o snd-soc-arndale-rt5631-objs := arndale_rt5631.o +snd-soc-tm2-wm5110-objs := tm2_wm5110.o obj-$(CONFIG_SND_SOC_SAMSUNG_JIVE_WM8750) += snd-soc-jive-wm8750.o obj-$(CONFIG_SND_SOC_SAMSUNG_NEO1973_WM8753) += snd-soc-neo1973-wm8753.o @@ -71,3 +72,4 @@ obj-$(CONFIG_SND_SOC_LOWLAND) += snd-soc-lowland.o obj-$(CONFIG_SND_SOC_LITTLEMILL) += snd-soc-littlemill.o obj-$(CONFIG_SND_SOC_BELLS) += snd-soc-bells.o obj-$(CONFIG_SND_SOC_ARNDALE_RT5631_ALC5631) += snd-soc-arndale-rt5631.o +obj-$(CONFIG_SND_SOC_SAMSUNG_TM2_WM5110) += snd-soc-tm2-wm5110.o diff --git a/sound/soc/samsung/tm2_wm5110.c b/sound/soc/samsung/tm2_wm5110.c new file mode 100644 index 0000000..7150958 --- /dev/null +++ b/sound/soc/samsung/tm2_wm5110.c @@ -0,0 +1,553 @@ +/* + * Copyright (C) 2015 - 2016 Samsung Electronics Co., Ltd. + * + * Author: Inha Song + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "i2s.h" +#include "lpass.h" +#include "../codecs/wm5110.h" + +struct tm2_machine_priv { + struct snd_soc_codec *codec; + struct clk *codec_mclk1; + struct clk *codec_mclk2; + + unsigned int sysclk_rate; + + int mic_bias; +}; + +static int tm2_start_sysclk(struct snd_soc_card *card) +{ + struct tm2_machine_priv *priv = snd_soc_card_get_drvdata(card); + struct snd_soc_codec *codec = priv->codec; + unsigned long mclk_rate = clk_get_rate(priv->codec_mclk1); + int ret; + + ret = clk_prepare_enable(priv->codec_mclk1); + if (ret < 0) { + dev_err(card->dev, "Failed to enable mclk: %d\n", ret); + return ret; + } + + ret = snd_soc_codec_set_pll(codec, WM5110_FLL1, + ARIZONA_FLL_SRC_MCLK1, + mclk_rate, + priv->sysclk_rate); + if (ret < 0) { + dev_err(codec->dev, "Failed to start FLL: %d\n", ret); + return ret; + } + + ret = snd_soc_codec_set_pll(codec, WM5110_FLL1_REFCLK, + ARIZONA_FLL_SRC_MCLK1, + mclk_rate, + priv->sysclk_rate); + if (ret < 0) { + dev_err(codec->dev, "Failed to set FLL1 Source: %d\n", ret); + return ret; + } + + ret = snd_soc_codec_set_sysclk(codec, ARIZONA_CLK_SYSCLK, + ARIZONA_CLK_SRC_FLL1, + priv->sysclk_rate, + SND_SOC_CLOCK_IN); + if (ret < 0) { + dev_err(codec->dev, "Failed to set SYSCLK Source: %d\n", ret); + return ret; + } + + return 0; +} + +static int tm2_stop_sysclk(struct snd_soc_card *card) +{ + struct tm2_machine_priv *priv = snd_soc_card_get_drvdata(card); + struct snd_soc_codec *codec = priv->codec; + int ret; + + ret = snd_soc_codec_set_pll(codec, WM5110_FLL1, 0, 0, 0); + if (ret < 0) { + dev_err(codec->dev, "Failed to stop FLL: %d\n", ret); + return ret; + } + + ret = snd_soc_codec_set_sysclk(codec, ARIZONA_CLK_SYSCLK, + ARIZONA_CLK_SRC_FLL1, 0, 0); + if (ret < 0) { + dev_err(codec->dev, "Failed to stop SYSCLK: %d\n", ret); + return ret; + } + + clk_disable_unprepare(priv->codec_mclk1); + + return 0; +} + +static int tm2_aif1_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_codec *codec = rtd->codec; + struct tm2_machine_priv *priv = snd_soc_card_get_drvdata(rtd->card); + int ret; + + dev_dbg(codec->dev, "params_rate: %d\n", params_rate(params)); + + /* + * SYSCLK Frequency is dependent on the Sample Rate. According to + * the sample rate, valid SYSCLK frequency is defined in manual. + * The manual recommand to select the highest possible SYSCLK + * frequency. + */ + switch (params_rate(params)) { + case 4000: + case 8000: + case 12000: + case 16000: + case 24000: + case 32000: + case 48000: + case 96000: + case 192000: + /* highest possible SYSCLK frequency: 147.456MHz */ + priv->sysclk_rate = 147456000U; + break; + case 11025: + case 22050: + case 44100: + case 88200: + case 176400: + /* highest possible SYSCLK frequency: 135.4752 MHz */ + priv->sysclk_rate = 135475200U; + break; + default: + dev_err(codec->dev, "Not supported sample rate: %d\n", + params_rate(params)); + return -EINVAL; + } + + ret = snd_soc_dai_set_sysclk(codec_dai, ARIZONA_CLK_SYSCLK, 0, 0); + if (ret < 0) { + dev_err(codec_dai->dev, "Failed to set SYSCLK: %d\n", ret); + return ret; + } + + return tm2_start_sysclk(rtd->card); +} + +static struct snd_soc_ops tm2_aif1_ops = { + .hw_params = tm2_aif1_hw_params, +}; + +static int tm2_aif2_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_codec *codec = rtd->codec; + struct tm2_machine_priv *priv = snd_soc_card_get_drvdata(rtd->card); + unsigned long mclk_rate = clk_get_rate(priv->codec_mclk1); + unsigned int asyncclk_rate; + int ret; + + dev_dbg(codec->dev, "params_rate: %d\n", params_rate(params)); + + /* + * ASYNC Frequency is dependent on the Sample Rate. According to + * the sample rate, valid ASYNC frequency is defined in manual. + * The manual recommand to select the highest possible ASYNC + * frequency. + */ + switch (params_rate(params)) { + case 8000: + case 12000: + case 16000: + /* highest possible ASYNCCLK frequency: 49.152MHz */ + asyncclk_rate = 49152000U; + break; + case 11025: + /* highest possible ASYNCCLK frequency: 45.1584 MHz */ + asyncclk_rate = 45158400U; + break; + default: + dev_err(codec->dev, "Not supported sample rate: %d\n", + params_rate(params)); + return -EINVAL; + } + + ret = snd_soc_codec_set_pll(codec, WM5110_FLL2, + ARIZONA_FLL_SRC_MCLK1, + mclk_rate, + asyncclk_rate); + if (ret < 0) { + dev_err(codec->dev, "Failed to start FLL: %d\n", ret); + return ret; + } + + ret = snd_soc_codec_set_pll(codec, WM5110_FLL2_REFCLK, + ARIZONA_FLL_SRC_MCLK1, + mclk_rate, + asyncclk_rate); + if (ret < 0) { + dev_err(codec->dev, "Failed to set FLL1 Source: %d\n", ret); + return ret; + } + + ret = snd_soc_dai_set_sysclk(codec_dai, ARIZONA_CLK_ASYNCCLK, 0, 0); + + if (ret < 0) { + dev_err(codec_dai->dev, "Failed to set ASYNCCLK: %d\n", ret); + return ret; + } + + ret = snd_soc_codec_set_sysclk(codec, ARIZONA_CLK_ASYNCCLK, + ARIZONA_CLK_SRC_FLL2, + asyncclk_rate, + SND_SOC_CLOCK_IN); + if (ret < 0) { + dev_err(codec->dev, "Failed to set ASYNCCLK Source: %d\n", ret); + return ret; + } + + return 0; +} + +static struct snd_soc_ops tm2_aif2_ops = { + .hw_params = tm2_aif2_hw_params, +}; + +static int tm2_mic_bias(struct snd_soc_dapm_widget *w, + struct snd_kcontrol *kcontrol, int event) +{ + struct snd_soc_card *card = w->dapm->card; + struct tm2_machine_priv *priv = snd_soc_card_get_drvdata(card); + + switch (event) { + case SND_SOC_DAPM_PRE_PMU: + gpio_set_value(priv->mic_bias, 1); + break; + case SND_SOC_DAPM_POST_PMD: + gpio_set_value(priv->mic_bias, 0); + break; + } + + return 0; +} + +static int tm2_set_bias_level(struct snd_soc_card *card, + struct snd_soc_dapm_context *dapm, + enum snd_soc_bias_level level) +{ + struct snd_soc_pcm_runtime *rtd; + + rtd = snd_soc_get_pcm_runtime(card, card->dai_link[0].name); + + if (dapm->dev != rtd->codec_dai->dev) + return 0; + + switch (level) { + case SND_SOC_BIAS_STANDBY: + if (card->dapm.bias_level == SND_SOC_BIAS_OFF) + tm2_start_sysclk(card); + break; + case SND_SOC_BIAS_OFF: + tm2_stop_sysclk(card); + break; + case SND_SOC_BIAS_PREPARE: + break; + default: + break; + } + + card->dapm.bias_level = level; + + dev_dbg(card->dev, "%s: %d\n", __func__, level); + + return 0; +} + +static int tm2_late_probe(struct snd_soc_card *card) +{ + struct tm2_machine_priv *priv = snd_soc_card_get_drvdata(card); + struct snd_soc_pcm_runtime *rtd; + int ret; + + rtd = snd_soc_get_pcm_runtime(card, card->dai_link[0].name); + priv->codec = rtd->codec; + + ret = devm_gpio_request_one(card->dev, priv->mic_bias, + GPIOF_OUT_INIT_LOW, "MICBIAS_EN_AP"); + if (ret < 0) { + dev_err(card->dev, + "Failed to request mic_bias_gpio: %d\n", ret); + return ret; + } + + /* 32 kHz must be enabled for jack detection */ + if (!IS_ERR(priv->codec_mclk2)) + clk_prepare_enable(priv->codec_mclk2); + + gpio_direction_output(priv->mic_bias, 0); + + return 0; +} + +static int tm2_suspend_post(struct snd_soc_card *card) +{ + return tm2_stop_sysclk(card); +} + +static int tm2_resume_pre(struct snd_soc_card *card) +{ + return tm2_start_sysclk(card); +} + +static const struct snd_kcontrol_new card_controls[] = { + SOC_DAPM_PIN_SWITCH("HP"), + SOC_DAPM_PIN_SWITCH("SPK"), + SOC_DAPM_PIN_SWITCH("RCV"), + SOC_DAPM_PIN_SWITCH("VPS"), + SOC_DAPM_PIN_SWITCH("HDMI"), + + SOC_DAPM_PIN_SWITCH("Main Mic"), + SOC_DAPM_PIN_SWITCH("Sub Mic"), + SOC_DAPM_PIN_SWITCH("Third Mic"), + + SOC_DAPM_PIN_SWITCH("Headset Mic"), +}; + +const struct snd_soc_dapm_widget machine_dapm_widgets[] = { + SND_SOC_DAPM_HP("HP", NULL), + SND_SOC_DAPM_SPK("SPK", NULL), + SND_SOC_DAPM_SPK("RCV", NULL), + SND_SOC_DAPM_LINE("VPS", NULL), + SND_SOC_DAPM_LINE("HDMI", NULL), + + SND_SOC_DAPM_MIC("Main Mic", tm2_mic_bias), + SND_SOC_DAPM_MIC("Sub Mic", NULL), + SND_SOC_DAPM_MIC("Third Mic", NULL), + + SND_SOC_DAPM_MIC("Headset Mic", NULL), +}; + +static const struct snd_soc_component_driver tm2_component = { + .name = "tm2-audio", +}; + +static struct snd_soc_dai_driver tm2_ext_dai[] = { + { + .name = "Voice call", + .playback = { + .channels_min = 1, + .channels_max = 4, + .rate_min = 8000, + .rate_max = 48000, + .rates = (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 | + SNDRV_PCM_RATE_48000), + .formats = SNDRV_PCM_FMTBIT_S16_LE, + }, + .capture = { + .channels_min = 1, + .channels_max = 4, + .rate_min = 8000, + .rate_max = 48000, + .rates = (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 | + SNDRV_PCM_RATE_48000), + .formats = SNDRV_PCM_FMTBIT_S16_LE, + }, + }, + { + .name = "Bluetooth", + .playback = { + .channels_min = 1, + .channels_max = 4, + .rate_min = 8000, + .rate_max = 16000, + .rates = (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000), + .formats = SNDRV_PCM_FMTBIT_S16_LE, + }, + .capture = { + .channels_min = 1, + .channels_max = 2, + .rate_min = 8000, + .rate_max = 16000, + .rates = (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000), + .formats = SNDRV_PCM_FMTBIT_S16_LE, + }, + }, +}; + +static struct snd_soc_dai_link machine_dai[] = { + { + .name = "WM5110 AIF1", + .stream_name = "HiFi Primary", + .codec_dai_name = "wm5110-aif1", + .codec_name = "wm5110-codec", + .ops = &tm2_aif1_ops, + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | + SND_SOC_DAIFMT_CBM_CFM, + }, { + .name = "WM5110 Voice", + .stream_name = "Voice call", + .codec_dai_name = "wm5110-aif2", + .codec_name = "wm5110-codec", + .ops = &tm2_aif2_ops, + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | + SND_SOC_DAIFMT_CBM_CFM, + .ignore_suspend = 1, + }, { + .name = "WM5110 BT", + .stream_name = "Bluetooth", + .codec_dai_name = "wm5110-aif3", + .codec_name = "wm5110-codec", + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | + SND_SOC_DAIFMT_CBM_CFM, + .ignore_suspend = 1, + } +}; + +static struct snd_soc_aux_dev tm2_speaker_amp_dev; + +static struct snd_soc_card tm2_card = { + .owner = THIS_MODULE, + + .dai_link = machine_dai, + .num_links = ARRAY_SIZE(machine_dai), + .controls = card_controls, + .num_controls = ARRAY_SIZE(card_controls), + .dapm_widgets = machine_dapm_widgets, + .num_dapm_widgets = ARRAY_SIZE(machine_dapm_widgets), + + .aux_dev = &tm2_speaker_amp_dev, + .num_aux_devs = 1, + + .late_probe = tm2_late_probe, + + .set_bias_level = tm2_set_bias_level, + + .suspend_post = tm2_suspend_post, + .resume_pre = tm2_resume_pre, +}; + +static int tm2_wm5110_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct snd_soc_card *card = &tm2_card; + struct snd_soc_dai_link *dai_link = card->dai_link; + struct tm2_machine_priv *priv; + int ret, i; + + if (!dev->of_node) { + dev_err(dev, "DT node is missing\n"); + return -ENODEV; + } + + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + snd_soc_card_set_drvdata(card, priv); + card->dev = dev; + + ret = snd_soc_of_parse_card_name(card, "samsung,model"); + if (ret < 0) { + dev_err(dev, "Card name is not provided\n"); + return ret; + } + + ret = snd_soc_of_parse_audio_routing(card, "samsung,audio-routing"); + if (ret < 0) { + dev_err(dev, "Audio routing is not provided\n"); + return ret; + } + + tm2_speaker_amp_dev.codec_of_node = of_parse_phandle(dev->of_node, + "samsung,speaker-amplifier", 0); + if (!tm2_speaker_amp_dev.codec_of_node) { + dev_err(dev, "speaker-amplifier property parse error\n"); + return -EINVAL; + } + + for (i = 0; i < card->num_links; i++) { + dai_link[i].cpu_dai_name = NULL; + dai_link[i].cpu_name = NULL; + dai_link[i].cpu_of_node = of_parse_phandle(dev->of_node, + "samsung,i2s-controller", 0); + if (!dai_link[i].cpu_of_node) { + dev_err(dev, "i2s-controller property parse error\n"); + return -EINVAL; + } + + dai_link[i].platform_name = NULL; + dai_link[i].platform_of_node = dai_link[i].cpu_of_node; + } + + priv->codec_mclk1 = devm_clk_get(dev, "mclk1"); + if (IS_ERR(priv->codec_mclk1)) { + dev_err(dev, "Failed to get out clock\n"); + return PTR_ERR(priv->codec_mclk1); + } + + /* mclk2 is optional */ + priv->codec_mclk2 = devm_clk_get(dev, "mclk2"); + if (IS_ERR(priv->codec_mclk2)) + dev_err(dev, "Failed to get mclk2 clock\n"); + + priv->mic_bias = of_get_named_gpio(dev->of_node, "mic_bias_gpio", 0); + if (!gpio_is_valid(priv->mic_bias)) { + dev_err(dev, "Failed to get mic_bias_gpio\n"); + return -EINVAL; + } + + ret = devm_snd_soc_register_component(dev, &tm2_component, + tm2_ext_dai, ARRAY_SIZE(tm2_ext_dai)); + if (ret < 0) { + dev_err(dev, "Failed to register component: %d\n", ret); + return ret; + } + + ret = devm_snd_soc_register_card(dev, card); + if (ret < 0) { + dev_err(dev, "Failed to register card: %d\n", ret); + return ret; + } + + return 0; +} + +static const struct of_device_id tm2_wm5110_of_match[] = { + { .compatible = "samsung,tm2-audio" }, + { }, +}; +MODULE_DEVICE_TABLE(of, tm2_wm5110_of_match); + +static struct platform_driver tm2_wm5110_driver = { + .driver = { + .name = "tm2-audio", + .pm = &snd_soc_pm_ops, + .of_match_table = tm2_wm5110_of_match, + }, + .probe = tm2_wm5110_probe, +}; + +module_platform_driver(tm2_wm5110_driver); + +MODULE_AUTHOR("Inha Song "); +MODULE_DESCRIPTION("ALSA SoC TM2 Audio Support"); +MODULE_LICENSE("GPL v2");