From patchwork Tue Feb 3 15:18:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yakir Yang X-Patchwork-Id: 5775061 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 49C26BF6C3 for ; Wed, 4 Feb 2015 07:31:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BC45E202F2 for ; Wed, 4 Feb 2015 07:31:56 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 03435202E5 for ; Wed, 4 Feb 2015 07:31:55 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 953416E6A0; Tue, 3 Feb 2015 23:31:31 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from regular1.263xmail.com (regular1.263xmail.com [211.150.99.140]) by gabe.freedesktop.org (Postfix) with ESMTP id 84FB66E515 for ; Tue, 3 Feb 2015 07:19:12 -0800 (PST) Received: from ykk?rock-chips.com (unknown [192.168.167.158]) by regular1.263xmail.com (Postfix) with SMTP id 42EF24A87; Tue, 3 Feb 2015 23:19:08 +0800 (CST) X-263anti-spam: KSV:0; X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-KSVirus-check: 0 X-ABS-CHECKED: 4 X-ADDR-CHECKED: 0 Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.263.net (Postfix) with ESMTP id 6BC8629CD0; Tue, 3 Feb 2015 23:18:38 +0800 (CST) X-RL-SENDER: ykk@rock-chips.com X-FST-TO: airlied@linux.ie X-SENDER-IP: 192.253.240.203 X-LOGIN-NAME: ykk@rock-chips.com X-UNIQUE-TAG: <681a32e32fe8fc55297b83662e4d2248> X-ATTACHMENT-NUM: 0 X-SENDER: ykk@rock-chips.com X-DNS-TYPE: 0 Received: from localhost.localdomain (unknown [192.253.240.203]) by smtp.263.net (Postfix) whith ESMTP id 32230RFQ1KH; Tue, 03 Feb 2015 23:19:04 +0800 (CST) From: Yakir Yang To: David Airlie , Russell King , Philipp Zabel Subject: [PATCH v3 13/15] ASoC: dw-hdmi-audio: add codec driver for dw hdmi audio Date: Tue, 3 Feb 2015 10:18:24 -0500 Message-Id: <1422976704-30494-1-git-send-email-ykk@rock-chips.com> X-Mailer: git-send-email 2.1.2 In-Reply-To: <1422975418-13302-1-git-send-email-ykk@rock-chips.com> References: <1422975418-13302-1-git-send-email-ykk@rock-chips.com> X-Mailman-Approved-At: Tue, 03 Feb 2015 23:31:28 -0800 Cc: Mark Rutland , alsa-devel@alsa-project.org, dianders@chromium.org, Yakir Yang , mmind00@googlemail.com, Pawel Moll , linux-rockchip@lists.infradead.org, devicetree@vger.kernel.org, Arnd Bergmann , Ian Campbell , Jyri Sarha , Ben Zhang , Rob Herring , dri-devel@lists.freedesktop.org, marcheu@chromium.org, linux-arm-kernel@lists.infradead.org, Mark Yao , Fabio Estevam , linux-kernel@vger.kernel.org, Kumar Gala X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 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=-2.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY, URIBL_BLACK autolearn=ham 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 codec driver creat an standard alsa device, than config audio and report jack status through some callback interfaces that dw_hdmi driver support. Signed-off-by: Yakir Yang --- Changes in v3: - Keep audio format config function in dw-hdmi-audio driver and remove audio_config & get_connect_status functions, move jack control to dw-hdmi-audio completely. Changes in v2: - Update dw_hdmi audio control interfaces, and adjust jack report process sound/soc/codecs/Kconfig | 4 + sound/soc/codecs/Makefile | 2 + sound/soc/codecs/dw-hdmi-audio.c | 333 +++++++++++++++++++++++++++++++++++++++ sound/soc/codecs/dw-hdmi-audio.h | 79 ++++++++++ 4 files changed, 418 insertions(+) create mode 100644 sound/soc/codecs/dw-hdmi-audio.c create mode 100644 sound/soc/codecs/dw-hdmi-audio.h diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig index 8349f98..b34dd12 100644 --- a/sound/soc/codecs/Kconfig +++ b/sound/soc/codecs/Kconfig @@ -75,6 +75,7 @@ config SND_SOC_ALL_CODECS select SND_SOC_MC13783 if MFD_MC13XXX select SND_SOC_ML26124 if I2C select SND_SOC_HDMI_CODEC + select SND_SOC_DW_HDMI_AUDIO select SND_SOC_PCM1681 if I2C select SND_SOC_PCM1792A if SPI_MASTER select SND_SOC_PCM3008 @@ -459,6 +460,9 @@ config SND_SOC_MAX98095 config SND_SOC_MAX9850 tristate +config SND_SOC_DW_HDMI_AUDIO + tristate + config SND_SOC_PCM1681 tristate "Texas Instruments PCM1681 CODEC" depends on I2C diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile index bbdfd1e..0ebb664 100644 --- a/sound/soc/codecs/Makefile +++ b/sound/soc/codecs/Makefile @@ -68,6 +68,7 @@ snd-soc-max9850-objs := max9850.o snd-soc-mc13783-objs := mc13783.o snd-soc-ml26124-objs := ml26124.o snd-soc-hdmi-codec-objs := hdmi.o +snd-soc-dw-hdmi-audio-objs := dw-hdmi-audio.o snd-soc-pcm1681-objs := pcm1681.o snd-soc-pcm1792a-codec-objs := pcm1792a.o snd-soc-pcm3008-objs := pcm3008.o @@ -249,6 +250,7 @@ obj-$(CONFIG_SND_SOC_MAX9850) += snd-soc-max9850.o obj-$(CONFIG_SND_SOC_MC13783) += snd-soc-mc13783.o obj-$(CONFIG_SND_SOC_ML26124) += snd-soc-ml26124.o obj-$(CONFIG_SND_SOC_HDMI_CODEC) += snd-soc-hdmi-codec.o +obj-$(CONFIG_SND_SOC_DW_HDMI_AUDIO) += snd-soc-dw-hdmi-audio.o obj-$(CONFIG_SND_SOC_PCM1681) += snd-soc-pcm1681.o obj-$(CONFIG_SND_SOC_PCM1792A) += snd-soc-pcm1792a-codec.o obj-$(CONFIG_SND_SOC_PCM3008) += snd-soc-pcm3008.o diff --git a/sound/soc/codecs/dw-hdmi-audio.c b/sound/soc/codecs/dw-hdmi-audio.c new file mode 100644 index 0000000..57d1ca1 --- /dev/null +++ b/sound/soc/codecs/dw-hdmi-audio.c @@ -0,0 +1,333 @@ +/* + * dw-hdmi-codec.c + * + * DesignerWare ALSA SoC DAI driver for DW HDMI audio. + * Copyright (c) 2014, CORPORATION. All rights reserved. + * Authors: Yakir Yang + * + * 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 .* + * + */ +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include "dw-hdmi-audio.h" + +struct snd_dw_hdmi { + struct device *dev; + struct dw_hdmi_audio_data data; + + u8 jack_status; + bool is_jack_ready; + struct snd_soc_jack jack; +}; + +int snd_dw_hdmi_jack_detect(struct snd_dw_hdmi *hdmi) +{ + u8 status, jack_status; + + if (!hdmi->is_jack_ready) + return -EINVAL; + + status = hdmi->data.read(hdmi->data.dw, HDMI_PHY_STAT0) & HDMI_PHY_HPD; + jack_status = status ? SND_JACK_LINEOUT : 0; + if (jack_status != hdmi->jack_status) { + snd_soc_jack_report(&hdmi->jack, jack_status, + SND_JACK_LINEOUT); + hdmi->jack_status = jack_status; + + dev_info(hdmi->dev, "jack report [%d]\n", hdmi->jack_status); + } + + return 0; +} + +static irqreturn_t snd_dw_hdmi_hardirq(int irq, void *dev_id) +{ + return IRQ_WAKE_THREAD; +} + +static irqreturn_t snd_dw_hdmi_irq(int irq, void *dev_id) +{ + struct snd_dw_hdmi *hdmi = dev_id; + + snd_dw_hdmi_jack_detect(hdmi); + + return IRQ_HANDLED; +} + +static void dw_hdmi_audio_set_fmt(struct snd_dw_hdmi *hdmi, + const struct hdmi_audio_fmt *fmt) +{ + hdmi->data.mod(hdmi->data.dw, AUDIO_INPUTTYPE_IIS, + AUDIO_CONF0_INTERFACE_MSK, HDMI_AUD_CONF0); + + hdmi->data.mod(hdmi->data.dw, fmt->chan_num, AUDIO_CONF0_I2SINEN_MSK, + HDMI_AUD_CONF0); + + hdmi->data.mod(hdmi->data.dw, fmt->word_length, AUDIO_CONF1_DATWIDTH_MSK, + HDMI_AUD_CONF1); + + hdmi->data.mod(hdmi->data.dw, fmt->dai_fmt, AUDIO_CONF1_DATAMODE_MSK, + HDMI_AUD_CONF1); + + hdmi->data.write(hdmi->data.dw, 0, HDMI_AUD_INPUTCLKFS); + + hdmi->data.set_sample_rate(hdmi->data.dw, fmt->sample_rate); +} + +static int snd_dw_hdmi_dai_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params, + struct snd_soc_dai *codec_dai) +{ + struct snd_dw_hdmi *hdmi = snd_soc_dai_get_drvdata(codec_dai); + struct snd_soc_pcm_runtime *rtd = substream->private_data; + struct hdmi_audio_fmt hdmi_fmt; + unsigned int fmt, rate, chan, width; + + fmt = rtd->dai_link->dai_fmt & SND_SOC_DAIFMT_FORMAT_MASK; + switch (fmt) { + case SND_SOC_DAIFMT_I2S: + hdmi_fmt.dai_fmt = AUDIO_DAIFMT_IIS; + break; + case SND_SOC_DAIFMT_LEFT_J: + hdmi_fmt.dai_fmt = AUDIO_DAIFMT_LEFT_J; + break; + case SND_SOC_DAIFMT_RIGHT_J: + hdmi_fmt.dai_fmt = AUDIO_DAIFMT_RIGHT_J; + break; + default: + dev_err(codec_dai->dev, "DAI format unsupported"); + return -EINVAL; + } + dev_dbg(codec_dai->dev, "[codec_dai]: dai_fmt = %d.\n", fmt); + + width = params_width(params); + switch (width) { + case 16: + case 24: + hdmi_fmt.word_length = width; + break; + default: + dev_err(codec_dai->dev, "width[%d] not support!\n", width); + return -EINVAL; + } + dev_dbg(codec_dai->dev, "[codec_dai]: word_length = %d.\n", width); + + chan = params_channels(params); + switch (chan) { + case 2: + hdmi_fmt.chan_num = AUDIO_CHANNELNUM_2; + break; + case 4: + hdmi_fmt.chan_num = AUDIO_CHANNELNUM_4; + break; + case 6: + hdmi_fmt.chan_num = AUDIO_CHANNELNUM_6; + break; + case 8: + hdmi_fmt.chan_num = AUDIO_CHANNELNUM_8; + break; + default: + dev_err(codec_dai->dev, "channel[%d] not support!\n", chan); + return -EINVAL; + } + dev_dbg(codec_dai->dev, "[codec_dai]: chan_num = %d.\n", chan); + + rate = params_rate(params); + switch (rate) { + case 32000: + case 44100: + case 48000: + case 88200: + case 96000: + case 176400: + case 192000: + hdmi_fmt.sample_rate = rate; + break; + default: + dev_err(codec_dai->dev, "rate[%d] not support!\n", rate); + return -EINVAL; + } + dev_dbg(codec_dai->dev, "[codec_dai]: sample_rate = %d.\n", rate); + + dw_hdmi_audio_set_fmt(hdmi, &hdmi_fmt); + + return 0; +} + +static int snd_dw_hdmi_dai_trigger(struct snd_pcm_substream *substream, + int cmd, struct snd_soc_dai *codec_dai) +{ + struct snd_dw_hdmi *hdmi = snd_soc_dai_get_drvdata(codec_dai); + + switch (cmd) { + case SNDRV_PCM_TRIGGER_START: + case SNDRV_PCM_TRIGGER_RESUME: + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: + hdmi->data.enable(hdmi->data.dw); + dev_dbg(codec_dai->dev, "[codec_dai]: trigger enable.\n"); + break; + + case SNDRV_PCM_TRIGGER_STOP: + case SNDRV_PCM_TRIGGER_SUSPEND: + case SNDRV_PCM_TRIGGER_PAUSE_PUSH: + hdmi->data.disable(hdmi->data.dw); + dev_dbg(codec_dai->dev, "[codec_dai]: trigger disable.\n"); + break; + default: + return -EINVAL; + } + + return 0; +} + +static int snd_dw_hdmi_audio_probe(struct snd_soc_codec *codec) +{ + struct snd_dw_hdmi *hdmi = snd_soc_codec_get_drvdata(codec); + int ret; + + ret = snd_soc_jack_new(codec, "HDMI Jack", SND_JACK_LINEOUT, + &hdmi->jack); + if (ret) { + dev_err(hdmi->dev, "jack new failed (%d)\n", ret); + hdmi->is_jack_ready = false; + return ret; + } + + hdmi->is_jack_ready = true; + + return snd_dw_hdmi_jack_detect(hdmi); +} + +static const struct snd_soc_dapm_widget snd_dw_hdmi_audio_widgets[] = { + SND_SOC_DAPM_OUTPUT("TX"), +}; + +static const struct snd_soc_dapm_route snd_dw_hdmi_audio_routes[] = { + { "TX", NULL, "Playback" }, +}; + +static const struct snd_soc_dai_ops dw_hdmi_dai_ops = { + .hw_params = snd_dw_hdmi_dai_hw_params, + .trigger = snd_dw_hdmi_dai_trigger, +}; + +static struct snd_soc_dai_driver dw_hdmi_audio_dai = { + .name = "dw-hdmi-hifi", + .playback = { + .stream_name = "Playback", + .channels_min = 2, + .channels_max = 8, + .rates = SNDRV_PCM_RATE_32000 | + SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 | + SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | + SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000, + .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE, + }, + .ops = &dw_hdmi_dai_ops, +}; + +static const struct snd_soc_codec_driver dw_hdmi_audio = { + .probe = snd_dw_hdmi_audio_probe, + .dapm_widgets = snd_dw_hdmi_audio_widgets, + .num_dapm_widgets = ARRAY_SIZE(snd_dw_hdmi_audio_widgets), + .dapm_routes = snd_dw_hdmi_audio_routes, + .num_dapm_routes = ARRAY_SIZE(snd_dw_hdmi_audio_routes), +}; + +static int dw_hdmi_audio_probe(struct platform_device *pdev) +{ + struct dw_hdmi_audio_data *data = pdev->dev.platform_data; + struct snd_dw_hdmi *hdmi; + int ret; + + hdmi = devm_kzalloc(&pdev->dev, sizeof(*hdmi), GFP_KERNEL); + if (!hdmi) + return -ENOMEM; + + hdmi->data = *data; + hdmi->dev = &pdev->dev; + platform_set_drvdata(pdev, hdmi); + + ret = devm_request_threaded_irq(&pdev->dev, hdmi->data.irq, + snd_dw_hdmi_hardirq, + snd_dw_hdmi_irq, IRQF_SHARED, + "dw-hdmi-audio", hdmi); + if (ret) { + dev_err(&pdev->dev, "request irq failed (%d)\n", ret); + goto free_hdmi_data; + } + + ret = snd_soc_register_codec(&pdev->dev, &dw_hdmi_audio, + &dw_hdmi_audio_dai, 1); + if (ret) { + dev_err(&pdev->dev, "register codec failed (%d)\n", ret); + goto free_irq; + } + + dev_info(&pdev->dev, "hdmi audio init success.\n"); + + return 0; + +free_irq: + devm_free_irq(&pdev->dev, hdmi->data.irq, hdmi); +free_hdmi_data: + devm_kfree(&pdev->dev, hdmi); + + return ret; +} + +static int dw_hdmi_audio_remove(struct platform_device *pdev) +{ + struct snd_dw_hdmi *hdmi = platform_get_drvdata(pdev); + + snd_soc_unregister_codec(&pdev->dev); + devm_free_irq(&pdev->dev, hdmi->data.irq, hdmi); + devm_kfree(&pdev->dev, hdmi); + + return 0; +} + +static const struct of_device_id dw_hdmi_audio_ids[] = { + { .compatible = "dw-hdmi-audio", }, + { } +}; + +static struct platform_driver dw_hdmi_audio_driver = { + .driver = { + .name = "dw-hdmi-audio", + .owner = THIS_MODULE, + .of_match_table = of_match_ptr(dw_hdmi_audio_ids), + }, + .probe = dw_hdmi_audio_probe, + .remove = dw_hdmi_audio_remove, +}; +module_platform_driver(dw_hdmi_audio_driver); + +MODULE_AUTHOR("Yakir Yang "); +MODULE_DESCRIPTION("DW HDMI Audio ASoC Interface"); +MODULE_LICENSE("GPL"); +MODULE_ALIAS("platform:" "dw-hdmi-audio"); +MODULE_DEVICE_TABLE(of, dw_hdmi_audio_ids); diff --git a/sound/soc/codecs/dw-hdmi-audio.h b/sound/soc/codecs/dw-hdmi-audio.h new file mode 100644 index 0000000..f41f519 --- /dev/null +++ b/sound/soc/codecs/dw-hdmi-audio.h @@ -0,0 +1,79 @@ +/* + * dw-hdmi-audio.h -- DW HDMI ALSA SoC Audio driver + * + * Copyright 2011-2012 DesignerWare Products + * + * 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. + */ + +#ifndef _DW_HDMI_AUDIO_H +#define _DW_HDMI_AUDIO_H + +enum hdmi_audio_reg { + HDMI_PHY_STAT0 = 0x3004, + HDMI_AUD_CONF0 = 0x3100, + HDMI_AUD_CONF1 = 0x3101, + HDMI_AUD_INPUTCLKFS = 0x3206, + HDMI_MC_CLKDIS = 0x4001, +}; + +enum { + HDMI_PHY_HPD = 0x2, + HDMI_MC_CLKDIS_AUDCLK_DISABLE = 0x8, +}; + +enum hdmi_audio_samplerate { + AUDIO_SAMPLERATE_32K = 32000, + AUDIO_SAMPLERATE_44K1 = 44100, + AUDIO_SAMPLERATE_48K = 48000, + AUDIO_SAMPLERATE_88K2 = 88200, + AUDIO_SAMPLERATE_96K = 96000, + AUDIO_SAMPLERATE_176K4 = 176400, + AUDIO_SAMPLERATE_192K = 192000, +}; + +#define AUDIO_CONF1_DATWIDTH_MSK 0x1F +enum hdmi_audio_wordlength { + AUDIO_WORDLENGTH_16BIT = 16, + AUDIO_WORDLENGTH_24BIT = 24, +}; + +#define AUDIO_CONF1_DATAMODE_MSK 0xE0 +enum hdmi_audio_daifmt { + AUDIO_DAIFMT_IIS = 0x00, + AUDIO_DAIFMT_RIGHT_J = 0x20, + AUDIO_DAIFMT_LEFT_J = 0x40, + AUDIO_DAIFMT_BURST_1 = 0x60, + AUDIO_DAIFMT_BURST_2 = 0x80, +}; + +#define AUDIO_CONF0_INTERFACE_MSK 0x20 +enum hdmi_audio_inputtype { + AUDIO_INPUTTYPE_IIS = 0x20, + AUDIO_INPUTTYPE_SPDIF = 0x00, +}; + +#define AUDIO_CONF0_I2SINEN_MSK 0x0F +enum hdmi_audio_channelnum { + AUDIO_CHANNELNUM_2 = 0x01, + AUDIO_CHANNELNUM_4 = 0x03, + AUDIO_CHANNELNUM_6 = 0x07, + AUDIO_CHANNELNUM_8 = 0x0F, +}; + +enum hdmi_jack_status { + JACK_LINEOUT, + JACK_NO_LINEOUT, +}; + +struct hdmi_audio_fmt { + enum hdmi_audio_inputtype input_type; + enum hdmi_audio_channelnum chan_num; + enum hdmi_audio_samplerate sample_rate; + enum hdmi_audio_wordlength word_length; + enum hdmi_audio_daifmt dai_fmt; +}; + +#endif