From patchwork Fri Oct 21 07:44:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jean-Francois Moine X-Patchwork-Id: 9390843 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 16E70600CB for ; Sat, 22 Oct 2016 18:36:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0C06028D06 for ; Sat, 22 Oct 2016 18:36:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F38B328DB4; Sat, 22 Oct 2016 18:36:56 +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=-0.6 required=2.0 tests=BAYES_00, DATE_IN_PAST_24_48, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE autolearn=no version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 354EB28D06 for ; Sat, 22 Oct 2016 18:36:55 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 3DCF0266A3F; Sat, 22 Oct 2016 20:36:54 +0200 (CEST) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 4D1AC266A1A; Sat, 22 Oct 2016 20:34:36 +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 11E12266967; Sat, 22 Oct 2016 19:16:37 +0200 (CEST) Received: from smtp3-g21.free.fr (smtp3-g21.free.fr [212.27.42.3]) by alsa0.perex.cz (Postfix) with ESMTP id E3E6D26690D for ; Sat, 22 Oct 2016 19:16:26 +0200 (CEST) Received: from localhost (unknown [37.162.5.40]) by smtp3-g21.free.fr (Postfix) with ESMTP id E00EB13F8D5; Sat, 22 Oct 2016 19:16:25 +0200 (CEST) X-Mailbox-Line: From 5cb540f20f64d28bd7dee82a0e14ee5209631979 Mon Sep 17 00:00:00 2001 Message-Id: <5cb540f20f64d28bd7dee82a0e14ee5209631979.1477142934.git.moinejf@free.fr> In-Reply-To: References: From: Jean-Francois Moine Date: Fri, 21 Oct 2016 09:44:55 +0200 To: Dave Airlie , Liam Girdwood , Mark Brown , Maxime Ripard , Rob Herring Cc: devicetree@vger.kernel.org, alsa-devel@alsa-project.org, linux-sunxi@googlegroups.com, linux-arm-kernel@lists.infradead.org, dri-devel@lists.freedesktop.org Subject: [alsa-devel] [PATCH v5 2/7] ASoC: sunxi: Add a simple 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 Allwinner's SoCs include support for both audio and video on HDMI. This patch defines a simple audio CODEC which may be used in sunxi HDMI video drivers. Signed-off-by: Jean-Francois Moine --- include/sound/sunxi_hdmi.h | 23 +++++++++ sound/soc/codecs/Kconfig | 9 ++++ sound/soc/codecs/Makefile | 2 + sound/soc/codecs/sunxi-hdmi.c | 106 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 140 insertions(+) create mode 100644 include/sound/sunxi_hdmi.h create mode 100644 sound/soc/codecs/sunxi-hdmi.c diff --git a/include/sound/sunxi_hdmi.h b/include/sound/sunxi_hdmi.h new file mode 100644 index 0000000..0986bb9 --- /dev/null +++ b/include/sound/sunxi_hdmi.h @@ -0,0 +1,23 @@ +#ifndef __SUNXI_HDMI_H__ +#define __SUNXI_HDMI_H__ +/* + * Copyright (C) 2016 Jean-François Moine + * + * 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. + */ + +struct sunxi_hdmi_codec { + u8 *eld; + int (*set_audio_input)(struct device *dev, + int enable, + unsigned sample_rate, + unsigned sample_bit); +}; + +int sunxi_hdmi_codec_register(struct device *dev); +void sunxi_hdmi_codec_unregister(struct device *dev); + +#endif /* __SUNXI_HDMI_H__ */ diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig index c67667b..53385b1 100644 --- a/sound/soc/codecs/Kconfig +++ b/sound/soc/codecs/Kconfig @@ -131,6 +131,7 @@ config SND_SOC_ALL_CODECS select SND_SOC_STA529 if I2C select SND_SOC_STAC9766 if SND_SOC_AC97_BUS select SND_SOC_STI_SAS + select SND_SOC_SUNXI_HDMI select SND_SOC_TAS2552 if I2C select SND_SOC_TAS5086 if I2C select SND_SOC_TAS571X if I2C @@ -793,6 +794,14 @@ config SND_SOC_STAC9766 config SND_SOC_STI_SAS tristate "codec Audio support for STI SAS codec" +config SND_SOC_SUNXI_HDMI + tristate "Allwinner sunxi HDMI Support" + default m if DRM_SUNXI_DE2_HDMI=m + default y if DRM_SUNXI_DE2_HDMI=y + select SND_PCM_ELD + help + Enable HDMI audio output + config SND_SOC_TAS2552 tristate "Texas Instruments TAS2552 Mono Audio amplifier" depends on I2C diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile index 958cd49..35804eb 100644 --- a/sound/soc/codecs/Makefile +++ b/sound/soc/codecs/Makefile @@ -139,6 +139,7 @@ snd-soc-sta350-objs := sta350.o snd-soc-sta529-objs := sta529.o snd-soc-stac9766-objs := stac9766.o snd-soc-sti-sas-objs := sti-sas.o +snd-soc-sunxi-hdmi-objs := sunxi-hdmi.o snd-soc-tas5086-objs := tas5086.o snd-soc-tas571x-objs := tas571x.o snd-soc-tas5720-objs := tas5720.o @@ -359,6 +360,7 @@ obj-$(CONFIG_SND_SOC_STA350) += snd-soc-sta350.o obj-$(CONFIG_SND_SOC_STA529) += snd-soc-sta529.o obj-$(CONFIG_SND_SOC_STAC9766) += snd-soc-stac9766.o obj-$(CONFIG_SND_SOC_STI_SAS) += snd-soc-sti-sas.o +obj-$(CONFIG_SND_SOC_SUNXI_HDMI) += snd-soc-sunxi-hdmi.o obj-$(CONFIG_SND_SOC_TAS2552) += snd-soc-tas2552.o obj-$(CONFIG_SND_SOC_TAS5086) += snd-soc-tas5086.o obj-$(CONFIG_SND_SOC_TAS571X) += snd-soc-tas571x.o diff --git a/sound/soc/codecs/sunxi-hdmi.c b/sound/soc/codecs/sunxi-hdmi.c new file mode 100644 index 0000000..0d08676 --- /dev/null +++ b/sound/soc/codecs/sunxi-hdmi.c @@ -0,0 +1,106 @@ +/* + * Allwinner HDMI codec + * + * Copyright (C) 2016 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 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 "sound/sunxi_hdmi.h" + +#define SUNXI_HDMI_FORMATS (SNDRV_PCM_FMTBIT_S8 | \ + SNDRV_PCM_FMTBIT_S16_LE | \ + SNDRV_PCM_FMTBIT_S20_3LE | \ + SNDRV_PCM_FMTBIT_S24_LE | \ + SNDRV_PCM_FMTBIT_S32_LE) + +static int sunxi_hdmi_codec_startup(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + struct snd_pcm_runtime *runtime = substream->runtime; + struct sunxi_hdmi_codec *priv = dev_get_drvdata(dai->dev); + u8 *eld; + + eld = priv->eld; + if (!eld) + return -ENODEV; + + return snd_pcm_hw_constraint_eld(runtime, eld); +} + +static int sunxi_hdmi_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params, + struct snd_soc_dai *dai) +{ + struct sunxi_hdmi_codec *priv = dev_get_drvdata(dai->dev); + unsigned sample_bit; + + if (params_format(params) == SNDRV_PCM_FORMAT_S16_LE) + sample_bit = 16; + else + sample_bit = 24; + + return priv->set_audio_input(dai->dev, true, + params_rate(params), + sample_bit); +} + +static void sunxi_hdmi_codec_shutdown(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + struct sunxi_hdmi_codec *priv = dev_get_drvdata(dai->dev); + + priv->set_audio_input(dai->dev, false, 0, 0); +} + +static const struct snd_soc_dai_ops sunxi_hdmi_codec_ops = { + .startup = sunxi_hdmi_codec_startup, + .hw_params = sunxi_hdmi_hw_params, + .shutdown = sunxi_hdmi_codec_shutdown, +}; + +static struct snd_soc_dai_driver sunxi_hdmi_codec = { + .name = "hdmi", /* must be the name of the node in the DT */ + .playback = { + .stream_name = "HDMI Playback", + .channels_min = 1, + .channels_max = 8, + .rates = SNDRV_PCM_RATE_CONTINUOUS, + .rate_min = 8000, + .rate_max = 192000, + .formats = SUNXI_HDMI_FORMATS, + }, + .ops = &sunxi_hdmi_codec_ops, +}; + +static const struct snd_soc_codec_driver sunxi_hdmi_codec_drv = { + .ignore_pmdown_time = true, +}; + +/* functions called from the HDMI video driver */ +int sunxi_hdmi_codec_register(struct device *dev) +{ + return snd_soc_register_codec(dev, &sunxi_hdmi_codec_drv, + &sunxi_hdmi_codec, 1); +} +EXPORT_SYMBOL_GPL(sunxi_hdmi_codec_register); + +void sunxi_hdmi_codec_unregister(struct device *dev) +{ + snd_soc_unregister_codec(dev); +} +EXPORT_SYMBOL_GPL(sunxi_hdmi_codec_unregister); + +MODULE_AUTHOR("Jean-Francois Moine "); +MODULE_DESCRIPTION("Allwinner HDMI CODEC"); +MODULE_LICENSE("GPL");