From patchwork Thu Oct 23 07:09:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Francois Moine X-Patchwork-Id: 5138611 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 4B8049F349 for ; Thu, 23 Oct 2014 08:49:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4782720251 for ; Thu, 23 Oct 2014 08:49:06 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id BFDD72021A for ; Thu, 23 Oct 2014 08:49:04 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id B502A260457; Thu, 23 Oct 2014 10:49:03 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, NO_DNS_FOR_FROM,RCVD_IN_DNSWL_NONE,UNPARSEABLE_RELAY autolearn=no version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id AF689260420; Thu, 23 Oct 2014 10:48:23 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id CA13B260416; Thu, 23 Oct 2014 10:48:20 +0200 (CEST) Received: from smtp4-g21.free.fr (smtp4-g21.free.fr [212.27.42.4]) by alsa0.perex.cz (Postfix) with ESMTP id 2BFC6260416 for ; Thu, 23 Oct 2014 10:48:19 +0200 (CEST) Received: from localhost (unknown [IPv6:2a01:e35:2f5c:9de0:212:bfff:fe1e:9ce4]) by smtp4-g21.free.fr (Postfix) with ESMTP id 5D0A44C80DE; Thu, 23 Oct 2014 10:46:42 +0200 (CEST) X-Mailbox-Line: From d63bb11d345ab1f1b7723ce5f82d42f56b0f1715 Mon Sep 17 00:00:00 2001 Message-Id: In-Reply-To: References: From: Jean-Francois Moine Date: Thu, 23 Oct 2014 09:09:35 +0200 To: Mark Brown , Russell King - ARM Linux Cc: devicetree@vger.kernel.org, alsa-devel@alsa-project.org, Andrew Jackson , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Jyri Sarha , Dave Airlie Subject: [alsa-devel] [PATCH v8 1/2] ASoC: hdmi: Add a transmitter interface to the HDMI CODEC X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP Audio in HDMI asks for: - the audio constraints of the HDMI device to be known when choosing the audio routes in the audio subsystem, and - the HDMI transmitter to know which of its audio inputs has been chosen when audio streaming starts. This patch adds the interface between a HDMI transmitter and the HDMI CODEC. At startup time, the HDMI transmitter device creates the HDMI device as a child device giving a description of its DAIs and 2 callback functions, these functions realizing the HDMI audio requirements. Signed-off-by: Jean-Francois Moine --- include/sound/hdmi.h | 20 ++++++ sound/soc/codecs/hdmi.c | 176 ++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 190 insertions(+), 6 deletions(-) create mode 100644 include/sound/hdmi.h diff --git a/include/sound/hdmi.h b/include/sound/hdmi.h new file mode 100644 index 0000000..49062c7 --- /dev/null +++ b/include/sound/hdmi.h @@ -0,0 +1,20 @@ +#ifndef SND_HDMI_H +#define SND_HDMI_H + +#include + +/* platform_data */ +struct hdmi_data { + int (*get_audio)(struct device *dev, + int *max_channels, + int *rate_mask, + int *fmt); + void (*audio_switch)(struct device *dev, + int port_index, + unsigned sample_rate, + int sample_format); + int ndais; + struct snd_soc_dai_driver *dais; + struct snd_soc_codec_driver *driver; +}; +#endif diff --git a/sound/soc/codecs/hdmi.c b/sound/soc/codecs/hdmi.c index 1391ad5..f66f1f6 100644 --- a/sound/soc/codecs/hdmi.c +++ b/sound/soc/codecs/hdmi.c @@ -22,9 +22,148 @@ #include #include #include +#include +#include #define DRV_NAME "hdmi-audio-codec" +struct hdmi_priv { + struct hdmi_data hdmi_data; + struct snd_pcm_hw_constraint_list rate_constraints; +}; + +static int hdmi_dev_match(struct device *dev, void *data) +{ + return !strcmp(dev_name(dev), (char *) data); +} + +/* get the codec device */ +static struct device *hdmi_get_cdev(struct device *dev) +{ + struct device *cdev; + + cdev = device_find_child(dev, + DRV_NAME, + hdmi_dev_match); + if (!cdev) + dev_err(dev, "Cannot get codec device"); + else + put_device(cdev); + return cdev; +} + +static int hdmi_startup(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + struct snd_pcm_runtime *runtime = substream->runtime; + struct device *cdev; + struct hdmi_priv *priv; + struct snd_pcm_hw_constraint_list *rate_constraints; + int ret, max_channels, rate_mask, fmt; + u64 formats; + static const u32 hdmi_rates[] = { + 32000, 44100, 48000, 88200, 96000, 176400, 192000 + }; + + cdev = hdmi_get_cdev(dai->dev); + if (!cdev) + return -ENODEV; + priv = dev_get_drvdata(cdev); + + /* get the EDID values and the rate constraints buffer */ + ret = priv->hdmi_data.get_audio(dai->dev, + &max_channels, &rate_mask, &fmt); + if (ret < 0) + return ret; /* no screen */ + + /* convert the EDID values to audio constraints */ + rate_constraints = &priv->rate_constraints; + rate_constraints->list = hdmi_rates; + rate_constraints->count = ARRAY_SIZE(hdmi_rates); + rate_constraints->mask = rate_mask; + snd_pcm_hw_constraint_list(runtime, 0, + SNDRV_PCM_HW_PARAM_RATE, + rate_constraints); + + formats = 0; + if (fmt & 1) + formats |= SNDRV_PCM_FMTBIT_S16_LE; + if (fmt & 2) + formats |= SNDRV_PCM_FMTBIT_S20_3LE; + if (fmt & 4) + formats |= SNDRV_PCM_FMTBIT_S24_LE | + SNDRV_PCM_FMTBIT_S24_3LE | + SNDRV_PCM_FMTBIT_S32_LE; + snd_pcm_hw_constraint_mask64(runtime, + SNDRV_PCM_HW_PARAM_FORMAT, + formats); + + snd_pcm_hw_constraint_minmax(runtime, + SNDRV_PCM_HW_PARAM_CHANNELS, + 1, max_channels); + return 0; +} + +static int hdmi_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params, + struct snd_soc_dai *dai) +{ + struct device *cdev; + struct hdmi_priv *priv; + + cdev = hdmi_get_cdev(dai->dev); + if (!cdev) + return -ENODEV; + priv = dev_get_drvdata(cdev); + + priv->hdmi_data.audio_switch(dai->dev, dai->id, + params_rate(params), + params_format(params)); + return 0; +} + +static void hdmi_shutdown(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + struct device *cdev; + struct hdmi_priv *priv; + + cdev = hdmi_get_cdev(dai->dev); + if (!cdev) + return; + priv = dev_get_drvdata(cdev); + + priv->hdmi_data.audio_switch(dai->dev, -1, 0, 0); /* stop */ +} + +static const struct snd_soc_dai_ops hdmi_ops = { + .startup = hdmi_startup, + .hw_params = hdmi_hw_params, + .shutdown = hdmi_shutdown, +}; + +static int hdmi_codec_probe(struct snd_soc_codec *codec) +{ + struct hdmi_priv *priv; + struct device *dev = codec->dev; /* encoder device */ + struct device *cdev; /* codec device */ + + cdev = hdmi_get_cdev(dev); + if (!cdev) + return -ENODEV; + + /* allocate some memory to store + * the encoder callback functions and the rate constraints */ + priv = devm_kzalloc(cdev, sizeof *priv, GFP_KERNEL); + if (!priv) + return -ENOMEM; + dev_set_drvdata(cdev, priv); + + memcpy(&priv->hdmi_data, cdev->platform_data, + sizeof priv->hdmi_data); + return 0; +} + static const struct snd_soc_dapm_widget hdmi_widgets[] = { SND_SOC_DAPM_INPUT("RX"), SND_SOC_DAPM_OUTPUT("TX"), @@ -79,13 +218,38 @@ static struct snd_soc_codec_driver hdmi_codec = { .ignore_pmdown_time = true, }; -static int hdmi_codec_probe(struct platform_device *pdev) +static int hdmi_codec_dev_probe(struct platform_device *pdev) { - return snd_soc_register_codec(&pdev->dev, &hdmi_codec, - &hdmi_codec_dai, 1); + struct hdmi_data *pdata = pdev->dev.platform_data; + struct snd_soc_dai_driver *dais; + struct snd_soc_codec_driver *driver; + int i, ret; + + if (!pdata) + return snd_soc_register_codec(&pdev->dev, &hdmi_codec, + &hdmi_codec_dai, 1); + + /* creation from a video encoder as a child device */ + dais = devm_kmemdup(&pdev->dev, + pdata->dais, + sizeof *pdata->dais * pdata->ndais, + GFP_KERNEL); + for (i = 0; i < pdata->ndais; i++) + dais[i].ops = &hdmi_ops; + + driver = devm_kmemdup(&pdev->dev, + pdata->driver, + sizeof *pdata->driver, + GFP_KERNEL); + driver->probe = hdmi_codec_probe; + + /* register the codec on the video encoder */ + ret = snd_soc_register_codec(pdev->dev.parent, driver, + dais, pdata->ndais); + return ret; } -static int hdmi_codec_remove(struct platform_device *pdev) +static int hdmi_codec_dev_remove(struct platform_device *pdev) { snd_soc_unregister_codec(&pdev->dev); return 0; @@ -98,8 +262,8 @@ static struct platform_driver hdmi_codec_driver = { .of_match_table = of_match_ptr(hdmi_audio_codec_ids), }, - .probe = hdmi_codec_probe, - .remove = hdmi_codec_remove, + .probe = hdmi_codec_dev_probe, + .remove = hdmi_codec_dev_remove, }; module_platform_driver(hdmi_codec_driver);