From patchwork Sun Aug 31 10:45:39 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: 4815291 Return-Path: X-Original-To: patchwork-dri-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 C0A2D9F3B4 for ; Sun, 31 Aug 2014 13:33:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 96EEA20107 for ; Sun, 31 Aug 2014 13:33:22 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 6C9B72010B for ; Sun, 31 Aug 2014 13:33:21 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BD1236E391; Sun, 31 Aug 2014 06:33:20 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from smtp2-g21.free.fr (smtp2-g21.free.fr [212.27.42.2]) by gabe.freedesktop.org (Postfix) with ESMTP id DF2046E391 for ; Sun, 31 Aug 2014 06:33:19 -0700 (PDT) Received: from localhost (unknown [IPv6:2a01:e35:2f5c:9de0:212:bfff:fe1e:9ce4]) by smtp2-g21.free.fr (Postfix) with ESMTP id D88D94B0097; Sun, 31 Aug 2014 15:33:12 +0200 (CEST) X-Mailbox-Line: From 080616c48997c53a14910f05a0fcf3f995412315 Mon Sep 17 00:00:00 2001 Message-Id: <080616c48997c53a14910f05a0fcf3f995412315.1409490122.git.moinejf@free.fr> In-Reply-To: References: From: Jean-Francois Moine Date: Sun, 31 Aug 2014 12:45:39 +0200 Subject: [PATCH v4 1/2] ASoC:codecs: Add a generic HDMI audio CODEC 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 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-5.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds a generic audio CODEC function to HDMI transmitters. The CODEC is implemented as a library in a kernel module. It handles both I2S and S/PDIF input, maintaining the audio format and rates constraints according to the HDMI device parameters (EDID). Audio source input switch is offered to the HDMI driver on start/stop of audio streaming. Signed-off-by: Jean-Francois Moine --- Documentation/devicetree/bindings/sound/hdmi2.txt | 32 ++++ include/sound/hdmi2.h | 24 +++ sound/soc/codecs/Kconfig | 3 + sound/soc/codecs/Makefile | 2 + sound/soc/codecs/hdmi2.c | 204 ++++++++++++++++++++++ 5 files changed, 265 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/hdmi2.txt create mode 100644 include/sound/hdmi2.h create mode 100644 sound/soc/codecs/hdmi2.c diff --git a/Documentation/devicetree/bindings/sound/hdmi2.txt b/Documentation/devicetree/bindings/sound/hdmi2.txt new file mode 100644 index 0000000..5776370 --- /dev/null +++ b/Documentation/devicetree/bindings/sound/hdmi2.txt @@ -0,0 +1,32 @@ +Device-Tree bindings for the generic HDMI2 CODEC + +The HDMI2 CODEC describes how the audio controller is connected to the +HDMI transmitter. +These definitions are included in the HDMI transmiter description. + +Required properties: + + - audio-ports: must contain one or two HDMI transmitter dependant + values identifying the audio sources. + The source type is given by the corresponding entry in + the audio-port-names property. + + - audio-port-names: must contain entries matching the entries in + the audio-ports property. + Each value may be "i2s" or "spdif", giving the type of + the associated audio port. + + - #sound-dai-cells: must be set to <1> for use with the simple-card. + The DAI 0 is the I2S input and the DAI 1 is the S/PDIF input. + +Example: + + hdmi: hdmi-encoder { + compatible = "nxp,tda998x"; + reg = <0x70>; + ... + + audio-ports = <0x03>, <0x04>; + audio-port-names = "i2s", "spdif"; + #sound-dai-cells = <1>; + }; diff --git a/include/sound/hdmi2.h b/include/sound/hdmi2.h new file mode 100644 index 0000000..59e4148 --- /dev/null +++ b/include/sound/hdmi2.h @@ -0,0 +1,24 @@ +#ifndef SND_HDMI2_H +#define SND_HDMI2_H +/* hdmi2 codec data */ +struct hdmi2_codec { + u8 ports[2]; + u16 source; /* audio DAI = index to ports[] */ +#define HDMI2_I2S 0 +#define HDMI2_SPDIF 1 + + unsigned sample_rate; /* current streaming values */ + int sample_format; + + u64 formats; /* HDMI (EDID) values */ + unsigned max_channels; + struct snd_pcm_hw_constraint_list rate_constraints; + + void (*start)(struct hdmi2_codec *audio, int full); + void (*stop)(struct hdmi2_codec *audio); +}; + +/* hdmi device -> hdmi2 codec */ +int hdmi2_codec_register(struct device *dev); +void hdmi2_codec_unregister(struct device *dev); +#endif diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig index 8ab1547..1b8d81e 100644 --- a/sound/soc/codecs/Kconfig +++ b/sound/soc/codecs/Kconfig @@ -424,6 +424,9 @@ config SND_SOC_ES8328_SPI tristate select SND_SOC_ES8328 +config SND_SOC_HDMI2 + tristate + config SND_SOC_ISABELLE tristate diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile index afba944..f59b1e6 100644 --- a/sound/soc/codecs/Makefile +++ b/sound/soc/codecs/Makefile @@ -53,6 +53,7 @@ snd-soc-dmic-objs := dmic.o snd-soc-es8328-objs := es8328.o snd-soc-es8328-i2c-objs := es8328-i2c.o snd-soc-es8328-spi-objs := es8328-spi.o +snd-soc-hdmi2-objs := hdmi2.o snd-soc-isabelle-objs := isabelle.o snd-soc-jz4740-codec-objs := jz4740.o snd-soc-l3-objs := l3.o @@ -228,6 +229,7 @@ obj-$(CONFIG_SND_SOC_DMIC) += snd-soc-dmic.o obj-$(CONFIG_SND_SOC_ES8328) += snd-soc-es8328.o obj-$(CONFIG_SND_SOC_ES8328_I2C)+= snd-soc-es8328-i2c.o obj-$(CONFIG_SND_SOC_ES8328_SPI)+= snd-soc-es8328-spi.o +obj-$(CONFIG_SND_SOC_HDMI2) += snd-soc-hdmi2.o obj-$(CONFIG_SND_SOC_ISABELLE) += snd-soc-isabelle.o obj-$(CONFIG_SND_SOC_JZ4740_CODEC) += snd-soc-jz4740-codec.o obj-$(CONFIG_SND_SOC_L3) += snd-soc-l3.o diff --git a/sound/soc/codecs/hdmi2.c b/sound/soc/codecs/hdmi2.c new file mode 100644 index 0000000..8ba8ba6 --- /dev/null +++ b/sound/soc/codecs/hdmi2.c @@ -0,0 +1,204 @@ +/* + * ALSA SoC generic HDMI CODEC + * + * Copyright (C) 2014 Jean-Francois Moine + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include +#include +#include +#include +#include +#include +#include + +#define HDMI2_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | \ + SNDRV_PCM_FMTBIT_S20_3LE | \ + SNDRV_PCM_FMTBIT_S24_LE | \ + SNDRV_PCM_FMTBIT_S32_LE) + +static int hdmi2_startup(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + struct hdmi2_codec *audio = snd_soc_codec_get_drvdata(dai->codec); + struct snd_pcm_runtime *runtime = substream->runtime; + + /* set the constraints */ + snd_pcm_hw_constraint_list(runtime, 0, + SNDRV_PCM_HW_PARAM_RATE, + &audio->rate_constraints); + snd_pcm_hw_constraint_mask64(runtime, + SNDRV_PCM_HW_PARAM_FORMAT, + audio->formats); + + snd_pcm_hw_constraint_minmax(runtime, + SNDRV_PCM_HW_PARAM_CHANNELS, + 1, audio->max_channels); + return 0; +} + +static int hdmi2_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params, + struct snd_soc_dai *dai) +{ + struct hdmi2_codec *audio = snd_soc_codec_get_drvdata(dai->codec); + + /* if same input and same parameters, do not do a full switch */ + if (dai->id == audio->source && + params_format(params) == audio->sample_format && + params_rate(params) == audio->sample_rate) { + audio->start(audio, 0); + return 0; + } + + audio->source = dai->id; + audio->sample_format = params_format(params); + audio->sample_rate = params_rate(params); + audio->start(audio, 1); + return 0; +} + +static void hdmi2_shutdown(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + struct hdmi2_codec *audio = snd_soc_codec_get_drvdata(dai->codec); + + audio->stop(audio); +} + +static const struct snd_soc_dai_ops hdmi2_ops = { + .startup = hdmi2_startup, + .hw_params = hdmi2_hw_params, + .shutdown = hdmi2_shutdown, +}; + +static struct snd_soc_dai_driver hdmi2_dai[] = { + { + .name = "i2s-hifi", + .id = HDMI2_I2S, + .playback = { + .stream_name = "HDMI I2S Playback", + .channels_min = 1, + .channels_max = 8, + .rates = SNDRV_PCM_RATE_CONTINUOUS, + .rate_min = 5512, + .rate_max = 192000, + .formats = HDMI2_FORMATS, + }, + .ops = &hdmi2_ops, + }, + { + .name = "spdif-hifi", + .id = HDMI2_SPDIF, + .playback = { + .stream_name = "HDMI SPDIF Playback", + .channels_min = 1, + .channels_max = 2, + .rates = SNDRV_PCM_RATE_CONTINUOUS, + .rate_min = 22050, + .rate_max = 192000, + .formats = HDMI2_FORMATS, + }, + .ops = &hdmi2_ops, + }, +}; + +static const struct snd_soc_dapm_widget hdmi2_widgets[] = { + SND_SOC_DAPM_OUTPUT("hdmi-out"), +}; +static const struct snd_soc_dapm_route hdmi2_routes[] = { + { "hdmi-out", NULL, "HDMI I2S Playback" }, + { "hdmi-out", NULL, "HDMI SPDIF Playback" }, +}; + +/* + * The HDMI driver must set the i2c client data to the hdmi2_codec + */ +static int hdmi2_probe(struct snd_soc_codec *codec) +{ + struct i2c_client *i2c_client = to_i2c_client(codec->dev); + struct hdmi2_codec *audio = i2c_get_clientdata(i2c_client); + struct device_node *np = codec->dev->of_node; + int i, j, ret; + const char *p; + + if (!audio) + return -ENODEV; + snd_soc_codec_set_drvdata(codec, audio); + + if (!np) + return 0; + + /* get the audio input ports*/ + for (i = 0; i < 2; i++) { + u32 port; + + ret = of_property_read_u32_index(np, "audio-ports", i, &port); + if (ret) { + if (i == 0) + dev_err(codec->dev, + "bad or missing audio-ports\n"); + break; + } + ret = of_property_read_string_index(np, "audio-port-names", + i, &p); + if (ret) { + dev_err(codec->dev, + "missing audio-port-names[%d]\n", i); + break; + } + if (strcmp(p, "i2s") == 0) { + j = 0; + } else if (strcmp(p, "spdif") == 0) { + j = 1; + } else { + dev_err(codec->dev, + "bad audio-port-names '%s'\n", p); + break; + } + audio->ports[j] = port; + } + return 0; +} + +static const struct snd_soc_codec_driver soc_codec_hdmi2 = { + .probe = hdmi2_probe, + .dapm_widgets = hdmi2_widgets, + .num_dapm_widgets = ARRAY_SIZE(hdmi2_widgets), + .dapm_routes = hdmi2_routes, + .num_dapm_routes = ARRAY_SIZE(hdmi2_routes), +}; + +int hdmi2_codec_register(struct device *dev) +{ + return snd_soc_register_codec(dev, + &soc_codec_hdmi2, + hdmi2_dai, ARRAY_SIZE(hdmi2_dai)); +} +EXPORT_SYMBOL(hdmi2_codec_register); + +void hdmi2_codec_unregister(struct device *dev) +{ + snd_soc_unregister_codec(dev); +} +EXPORT_SYMBOL(hdmi2_codec_unregister); + +/* -- module insert / remove -- */ +MODULE_AUTHOR("Jean-Francois Moine "); +MODULE_DESCRIPTION("HDMI2 CODEC"); +MODULE_LICENSE("GPL"); + +static int __init hdmi2_codec_init(void) +{ + return 0; +} +static void __exit hdmi2_codec_exit(void) +{ +} + +module_init(hdmi2_codec_init); +module_exit(hdmi2_codec_exit);