[alsa-devel] [RFC PATCH 0/6] Those patches is used for dw_hdmi audio.
rk3288 use Designware HDMI IP, Designware HDMI supports four interfaces to config hdmi audio(I2S, S/PDIF, Generic Parallel Audio, AHB Audio DMA), but rk3288 only support two ways to config hdmi audio(I2S, S/PDIF), So we take I2S as hdmi audio operation interfaces, and then treat hdmi audio as an standard ALSA devices(only got platback function).
Four things we have done: 1. modify the audio part of dw_hdmi drivers for rk3288 platform specific. 2. add codec driver for hdmi audio, and creat codec device dynamically in hdmi driver probe function, using platform_register_device_full way, so that hdmi codec driver can connected with hdmi driver. 3. add sound driver for hdmi audio, creat hdmi audio sound card. 4. add dt-bings file and add hdmi_audio node to corresponding dt file.
[Explanation]: those patch is depend on patch by Andy Yan drm: bridge/dw_hdmi: add rockchip rk3288 support see https://patchwork.kernel.org/patch/5442361/
Yakir Yang (6): drm: bridge/dw_hdmi: add hdmi audio config interfaces drm: bridge/bridge: add support for rk3288 hdmi-audio ASoC: dw-hdmi-audio: add codec driver for dw hdmi audio ASoC: rockchip-hdmi-audio: add sound driver for hdmi audio dt-bindings: Add documentation for Rockchip hdmi-audio ARM: dts: rockchip: add hdmi audio nodes
.../sound/rockchip,rockchip-hdmi-audio.txt | 16 + arch/arm/boot/dts/rk3288-evb.dtsi | 11 + arch/arm/boot/dts/rk3288.dtsi | 8 + drivers/gpu/drm/bridge/dw_hdmi.c | 32 +- include/drm/bridge/dw_hdmi.h | 12 + sound/soc/codecs/Kconfig | 4 + sound/soc/codecs/Makefile | 2 + sound/soc/codecs/dw-hdmi-audio.c | 371 +++++++++++++++++++++ sound/soc/codecs/dw-hdmi-audio.h | 82 +++++ sound/soc/rockchip/Kconfig | 9 + sound/soc/rockchip/Makefile | 2 + sound/soc/rockchip/rockchip_hdmi_audio.c | 208 ++++++++++++ 12 files changed, 756 insertions(+), 1 deletion(-) create mode 100644 Documentation/devicetree/bindings/sound/rockchip,rockchip-hdmi-audio.txt create mode 100644 sound/soc/codecs/dw-hdmi-audio.c create mode 100644 sound/soc/codecs/dw-hdmi-audio.h create mode 100644 sound/soc/rockchip/rockchip_hdmi_audio.c
codec driver get some interfaces from dw_hdmi driver, than using those to set hdmi audio formats, corresponding to alsa formats.
Signed-off-by: Yakir Yang ykk@rock-chips.com ---
sound/soc/codecs/Kconfig | 4 + sound/soc/codecs/Makefile | 2 + sound/soc/codecs/dw-hdmi-audio.c | 371 +++++++++++++++++++++++++++++++++++++++ sound/soc/codecs/dw-hdmi-audio.h | 82 +++++++++ 4 files changed, 459 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 883c577..e0b8be6 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..a76d85d --- /dev/null +++ b/sound/soc/codecs/dw-hdmi-audio.c @@ -0,0 +1,371 @@ +/* + * dw-hdmi-codec.c + * + * DesignerWare ALSA SoC DAI driver for DW HDMI audio. + * Copyright (c) 2014, CORPORATION. All rights reserved. + * Authors: Yakir Yang ykk@rock-chips.com + * + * 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 http://www.gnu.org/licenses/.* + * + */ +#include <linux/init.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/device.h> +#include <linux/moduleparam.h> + +#include <sound/pcm.h> +#include <sound/soc.h> +#include <sound/core.h> +#include <sound/jack.h> +#include <sound/initval.h> +#include <sound/pcm_params.h> + +#include <drm/bridge/dw_hdmi.h> +#include "dw-hdmi-audio.h" + +struct snd_dw_hdmi { + struct device *dev; + struct dw_hdmi_audio_data data; + + struct snd_soc_jack *jack; + struct delayed_work jack_work; + enum hdmi_jack_status jack_status; + enum hdmi_jack_status connect_status; +}; + +/** + * dw_hdmi_jack_detect - Enable hdmi detection via the HDMI IRQ + * + * @codec: HDMI codec + * @jack: jack to report detection events on + * + * Enable HDMI detection via IRQ on the HDMI. + * + * If no jack is supplied detection will be disabled. + */ +int dw_hdmi_jack_detect(struct snd_soc_codec *codec_dai, + struct snd_soc_jack *jack) +{ + struct snd_dw_hdmi *hdmi = snd_soc_codec_get_drvdata(codec_dai); + + hdmi->jack = jack; + hdmi->jack_status = JACK_NO_LINEOUT; + + snd_soc_jack_report(hdmi->jack, 0, SND_JACK_LINEOUT); + + queue_delayed_work(system_power_efficient_wq, &hdmi->jack_work, + msecs_to_jiffies(50)); + + return 0; +} +EXPORT_SYMBOL_GPL(dw_hdmi_jack_detect); + +static void dw_hdmi_jack_work(struct work_struct *work) +{ + struct snd_dw_hdmi *hdmi = container_of(work, struct snd_dw_hdmi, + jack_work.work); + u8 status; + + status = hdmi->data.read(hdmi->data.dw, HDMI_PHY_STAT0) & HDMI_PHY_HPD; + if (status != hdmi->connect_status) { + hdmi->jack_status = status ? SND_JACK_LINEOUT : 0; + snd_soc_jack_report(hdmi->jack, hdmi->jack_status, + SND_JACK_LINEOUT); + dev_info(hdmi->dev, "jack report [%d]\n", hdmi->jack_status); + } + hdmi->connect_status = status; +} + +static irqreturn_t snd_dw_hdmi_irq(int irq, void *dev_id) +{ + struct snd_dw_hdmi *hdmi = dev_id; + + queue_delayed_work(system_power_efficient_wq, &hdmi->jack_work, + msecs_to_jiffies(50)); + + return IRQ_HANDLED; +} + +void enable_dw_hdmi_audio(struct snd_dw_hdmi *hdmi) +{ + hdmi->data.mod(hdmi->data.dw, 0, HDMI_MC_CLKDIS_AUDCLK_DISABLE, + HDMI_MC_CLKDIS); +} + +void disable_dw_hdmi_audio(struct snd_dw_hdmi *hdmi) +{ + hdmi->data.mod(hdmi->data.dw, 1, + HDMI_MC_CLKDIS_AUDCLK_DISABLE, HDMI_MC_CLKDIS); +} + +void set_dw_hdmi_audio_fmt(struct snd_dw_hdmi *hdmi, struct hdmi_audio_fmt fmt) +{ + hdmi->data.mod(hdmi->data.dw, fmt.input_type, 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 dw_hdmi_dai_startup(struct snd_pcm_substream *substream, + struct snd_soc_dai *codec_dai) +{ + struct snd_dw_hdmi *hdmi = snd_soc_dai_get_drvdata(codec_dai); + + dev_info(codec_dai->dev, "[codec_dai]: startup.\n"); + enable_dw_hdmi_audio(hdmi); + + return 0; +} + +static int 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_info(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_info(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_info(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_info(codec_dai->dev, "[codec_dai]: sample_rate = %d.\n", rate); + + hdmi_fmt.input_type = AUDIO_INPUTTYPE_IIS; + + set_dw_hdmi_audio_fmt(hdmi, hdmi_fmt); + + return 0; +} + +static int 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: + disable_dw_hdmi_audio(hdmi); + dev_info(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: + enable_dw_hdmi_audio(hdmi); + dev_info(codec_dai->dev, "[codec_dai]: trigger disable.\n"); + break; + default: + return -EINVAL; + } + + return 0; +} + +static void dw_hdmi_dai_shutdown(struct snd_pcm_substream *substream, + struct snd_soc_dai *codec_dai) +{ + struct snd_dw_hdmi *hdmi = snd_soc_dai_get_drvdata(codec_dai); + + dev_info(codec_dai->dev, "[codec_dai]: shutdown.\n"); + disable_dw_hdmi_audio(hdmi); +} + +static const struct snd_soc_dapm_widget dw_hdmi_widgets[] = { + SND_SOC_DAPM_OUTPUT("TX"), +}; + +static const struct snd_soc_dapm_route dw_hdmi_routes[] = { + { "TX", NULL, "Playback" }, +}; + +static const struct snd_soc_dai_ops dw_hdmi_dai_ops = { + .startup = dw_hdmi_dai_startup, + .hw_params = dw_hdmi_dai_hw_params, + .trigger = dw_hdmi_dai_trigger, + .shutdown = dw_hdmi_dai_shutdown, +}; + +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 struct snd_soc_codec_driver dw_hdmi_audio = { + .dapm_widgets = dw_hdmi_widgets, + .num_dapm_widgets = ARRAY_SIZE(dw_hdmi_widgets), + .dapm_routes = dw_hdmi_routes, + .num_dapm_routes = ARRAY_SIZE(dw_hdmi_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); + + INIT_DELAYED_WORK(&hdmi->jack_work, dw_hdmi_jack_work); + + ret = devm_request_irq(&pdev->dev, hdmi->data.irq, 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, + ARRAY_SIZE(dw_hdmi_audio_dai)); + 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 ykk@rock-chips.com"); +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..38e2e81 --- /dev/null +++ b/sound/soc/codecs/dw-hdmi-audio.h @@ -0,0 +1,82 @@ +/* + * 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; +}; + +int dw_hdmi_jack_detect(struct snd_soc_codec *codec_dai, + struct snd_soc_jack *jack); + +#endif
Adds a sound driver that combines rockchip-i2s cpu_dai and dw-hdmi-codec as codec_dai to provide hdmi audio output on rk3288 platforms.
Signed-off-by: Yakir Yang ykk@rock-chips.com ---
sound/soc/rockchip/Kconfig | 9 ++ sound/soc/rockchip/Makefile | 2 + sound/soc/rockchip/rockchip_hdmi_audio.c | 208 +++++++++++++++++++++++++++++++ 3 files changed, 219 insertions(+) create mode 100644 sound/soc/rockchip/rockchip_hdmi_audio.c
diff --git a/sound/soc/rockchip/Kconfig b/sound/soc/rockchip/Kconfig index e181826..ed2b7f0 100644 --- a/sound/soc/rockchip/Kconfig +++ b/sound/soc/rockchip/Kconfig @@ -14,3 +14,12 @@ config SND_SOC_ROCKCHIP_I2S Say Y or M if you want to add support for I2S driver for Rockchip I2S device. The device supports upto maximum of 8 channels each for play and record. + +config SND_SOC_ROCKCHIP_HDMI_AUDIO + tristate "ASoC support for Rockchip HDMI audio" + depends on SND_SOC_ROCKCHIP + select SND_SOC_ROCKCHIP_I2S + select SND_SOC_DW_HDMI_AUDIO + help + Say Y or M here if you want to add support for SoC audio on Rockchip + HDMI, such as rk3288 hdmi. diff --git a/sound/soc/rockchip/Makefile b/sound/soc/rockchip/Makefile index b921909..b9185b3 100644 --- a/sound/soc/rockchip/Makefile +++ b/sound/soc/rockchip/Makefile @@ -1,4 +1,6 @@ # ROCKCHIP Platform Support snd-soc-i2s-objs := rockchip_i2s.o +snd-soc-rockchip-hdmi-audio-objs := rockchip_hdmi_audio.o
obj-$(CONFIG_SND_SOC_ROCKCHIP_I2S) += snd-soc-i2s.o +obj-$(CONFIG_SND_SOC_ROCKCHIP_HDMI_AUDIO) += snd-soc-rockchip-hdmi-audio.o diff --git a/sound/soc/rockchip/rockchip_hdmi_audio.c b/sound/soc/rockchip/rockchip_hdmi_audio.c new file mode 100644 index 0000000..a1a9c75 --- /dev/null +++ b/sound/soc/rockchip/rockchip_hdmi_audio.c @@ -0,0 +1,208 @@ +/* + * rockchip-hdmi-card.c + * + * ROCKCHIP ALSA SoC DAI driver for HDMI audio on rockchip processors. + * Copyright (c) 2014, ROCKCHIP CORPORATION. All rights reserved. + * Authors: Yakir Yang ykk@rock-chips.com + * + * 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 http://www.gnu.org/licenses/.* + * + */ +#include <linux/module.h> +#include <linux/platform_device.h> + +#include <sound/soc.h> +#include <sound/pcm.h> +#include <sound/jack.h> +#include <sound/core.h> +#include <sound/pcm_params.h> + +#include "rockchip_i2s.h" +#include "../codecs/dw-hdmi-audio.h" + +#define DRV_NAME "rockchip-hdmi-audio" + +struct hdmi_audio_private { + struct snd_soc_jack hdmi_jack; +}; + +static int rockchip_hdmi_audio_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 *cpu_dai = rtd->cpu_dai; + unsigned int dai_fmt = rtd->dai_link->dai_fmt; + int mclk, ret; + + switch (params_rate(params)) { + case 8000: + case 16000: + case 24000: + case 32000: + case 48000: + case 64000: + case 96000: + mclk = 12288000; + break; + case 11025: + case 22050: + case 44100: + case 88200: + mclk = 11289600; + break; + default: + return -EINVAL; + } + + ret = snd_soc_dai_set_fmt(cpu_dai, dai_fmt); + if (ret < 0) { + dev_err(cpu_dai->dev, "failed to set cpu_dai fmt.\n"); + return ret; + } + + ret = snd_soc_dai_set_sysclk(cpu_dai, 0, mclk, SND_SOC_CLOCK_OUT); + if (ret < 0) { + dev_err(cpu_dai->dev, "failed to set cpu_dai sysclk.\n"); + return ret; + } + + return 0; +} + +static int hdmi_audio_dai_init(struct snd_soc_pcm_runtime *runtime) +{ + struct snd_soc_codec *codec = runtime->codec; + struct snd_soc_card *card = runtime->card; + struct hdmi_audio_private *drv = snd_soc_card_get_drvdata(card); + + /* Enable headphone jack detection */ + snd_soc_jack_new(codec, "HDMI Jack", SND_JACK_LINEOUT, + &drv->hdmi_jack); + + return dw_hdmi_jack_detect(codec, &drv->hdmi_jack); +} + +static struct snd_soc_ops hdmi_audio_dai_ops = { + .hw_params = rockchip_hdmi_audio_hw_params, +}; + +static struct snd_soc_dai_link hdmi_audio_dai = { + .name = "RockchipHDMI", + .stream_name = "RockchipHDMI", + .init = hdmi_audio_dai_init, + .ops = &hdmi_audio_dai_ops, + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | + SND_SOC_DAIFMT_CBS_CFS, +}; + +static struct snd_soc_card rockchip_hdmi_audio_card = { + .name = "RockchipHDMI", + .owner = THIS_MODULE, + .dai_link = &hdmi_audio_dai, + .num_links = 1, +}; + +static int rockchip_hdmi_audio_probe(struct platform_device *pdev) +{ + struct snd_soc_card *card = &rockchip_hdmi_audio_card; + struct device_node *np = pdev->dev.of_node; + struct hdmi_audio_private *drv; + int ret; + + drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL); + if (!drv) + return -ENOMEM; + + card->dev = &pdev->dev; + platform_set_drvdata(pdev, &card); + snd_soc_card_set_drvdata(card, drv); + + of_property_read_string(np, "codec-name", &hdmi_audio_dai.codec_name); + if (!hdmi_audio_dai.codec_name) { + dev_err(&pdev->dev, "Property 'codec-name' missing !\n"); + goto free_priv_data; + } + + of_property_read_string(np, "codec-dai-name", + &hdmi_audio_dai.codec_dai_name); + if (!hdmi_audio_dai.codec_dai_name) { + dev_err(&pdev->dev, "Property 'codec-dai-name' missing !\n"); + goto free_codec_name; + } + + hdmi_audio_dai.cpu_of_node = of_parse_phandle(np, "cpu-of-node", 0); + if (!hdmi_audio_dai.cpu_of_node) { + dev_err(&pdev->dev, "Property 'cpu-of-node' missing !\n"); + goto free_codec_dai_name; + } + + hdmi_audio_dai.platform_of_node = hdmi_audio_dai.cpu_of_node; + + ret = snd_soc_register_card(card); + if (ret) { + dev_err(&pdev->dev, "register card failed (%d)\n", ret); + card->dev = NULL; + goto free_cpu_of_node; + } + + dev_info(&pdev->dev, "hdmi audio init success.\n"); + + return 0; + +free_cpu_of_node: + hdmi_audio_dai.cpu_of_node = NULL; + hdmi_audio_dai.platform_of_node = NULL; +free_codec_dai_name: + hdmi_audio_dai.codec_dai_name = NULL; +free_codec_name: + hdmi_audio_dai.codec_name = NULL; +free_priv_data: + platform_set_drvdata(pdev, NULL); + devm_kfree(&pdev->dev, drv); + card->dev = NULL; + + return ret; +} + +static int rockchip_hdmi_audio_remove(struct platform_device *pdev) +{ + struct snd_soc_card *card = platform_get_drvdata(pdev); + + snd_soc_unregister_card(card); + platform_set_drvdata(pdev, NULL); + card->dev = NULL; + + return 0; +} + +static const struct of_device_id rockchip_hdmi_audio_of_match[] = { + { .compatible = "rockchip,rk3288-hdmi-audio", }, + {}, +}; + +static struct platform_driver rockchip_hdmi_audio_driver = { + .driver = { + .name = DRV_NAME, + .owner = THIS_MODULE, + .of_match_table = rockchip_hdmi_audio_of_match, + }, + .probe = rockchip_hdmi_audio_probe, + .remove = rockchip_hdmi_audio_remove, +}; +module_platform_driver(rockchip_hdmi_audio_driver); + +MODULE_AUTHOR("Yakir Yang ykk@rock-chips.com"); +MODULE_DESCRIPTION("Rockchip HDMI Audio ASoC Interface"); +MODULE_LICENSE("GPL"); +MODULE_ALIAS("platform:" DRV_NAME); +MODULE_DEVICE_TABLE(of, rockchip_hdmi_audio_of_match);
Required properties: - compatible: platform specific - cpu-of-node: the device node of cpu_dai - codec-name: the dw-hdmi codec's device name - codec-dai-name: the dw-hdmi codec's dai name
Signed-off-by: Yakir Yang ykk@rock-chips.com ---
.../bindings/sound/rockchip,rockchip-hdmi-audio.txt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/rockchip,rockchip-hdmi-audio.txt
diff --git a/Documentation/devicetree/bindings/sound/rockchip,rockchip-hdmi-audio.txt b/Documentation/devicetree/bindings/sound/rockchip,rockchip-hdmi-audio.txt new file mode 100644 index 0000000..674cff0 --- /dev/null +++ b/Documentation/devicetree/bindings/sound/rockchip,rockchip-hdmi-audio.txt @@ -0,0 +1,16 @@ +Rockchip hdmi audio bindings + +Required properties: +- compatible: platform specific +- cpu-of-node: the device node of cpu_dai +- codec-name: the dw-hdmi codec's device name +- codec-dai-name: the dw-hdmi codec's dai name + +Example: + +sound { + compatible = "rockchip,rk3288-hdmi-audio"; + cpu-of-node = <&i2s>; + codec-name = "dw-hdmi-audio"; + codec-dai-name = "dw-hdmi-hifi"; +};
On 12/15/2014 03:55 AM, Yakir Yang wrote: [...]
+- codec-name: the dw-hdmi codec's device name +- codec-dai-name: the dw-hdmi codec's dai name
Please you phandles for this, the names are Linux driver and framework specific details. That should not leak into the DT bindings.
[..]
Hi lars:
thks for your review, I will move it to hdmi audio driver, give the codec_name & codec_dai_name an const string.
Best Regards.
Yang KuanKuan | Software Engineer | 15060416783 | ykk@rock-chips.com
From: Lars-Peter Clausen Date: 2014-12-15 17:02 To: Yakir Yang CC: Heiko Stuebner; Rob Herring; Pawel Moll; Mark Rutland; Ian Campbell; Kumar Gala; Russell King; Philipp Zabel; Zubair.Kakakhel; Fabio Estevam; Shawn Guo; dri-devel; Daniel Kurtz; Sonny Rao; Dylan Reid; Xu Jianqun; St��phane Marchesin; Brian Austin; Bard Liao; Max Filippov; Oder Chiou; devicetree; linux-kernel; linux-arm-kernel; linux-rockchip; alsa-devel; Arnd Bergmann; David Airlie; Sean Cross; Grant Likely; Greg Kroah-Hartman; Ben Zhang; Liam Girdwood; Jaroslav Kysela; Mark Brown; Takashi Iwai; Jyri Sarha Subject: Re: [PATCH 5/6] dt-bindings: Add documentation for Rockchip hdmi-audio On 12/15/2014 03:55 AM, Yakir Yang wrote: [...]
+- codec-name: the dw-hdmi codec's device name +- codec-dai-name: the dw-hdmi codec's dai name
Please you phandles for this, the names are Linux driver and framework specific details. That should not leak into the DT bindings.
[..]
Hi lars:
thks for your review, I will move it to hdmi audio driver, give the codec_name & codec_dai_name an const string.
Best Regards.
在 2014年12月15日 17:02, Lars-Peter Clausen 写道:
On 12/15/2014 03:55 AM, Yakir Yang wrote: [...]
+- codec-name: the dw-hdmi codec's device name +- codec-dai-name: the dw-hdmi codec's dai name
Please you phandles for this, the names are Linux driver and framework specific details. That should not leak into the DT bindings.
[..]
On Mon, Dec 15, 2014 at 10:55:14AM +0800, Yakir Yang wrote:
Required properties:
- compatible: platform specific
- cpu-of-node: the device node of cpu_dai
- codec-name: the dw-hdmi codec's device name
- codec-dai-name: the dw-hdmi codec's dai name
This is not actually a separate physical device from the main dw-hdmi device. What you are doing is merely describing the Linux kernel internals in DT, which is not what DT is supposed to be about. DT is supposed to describe the hardware in an operating system independent manner.
Including details like this (because ASoC needs a separate DT node) is the wrong approach.
On Mon, Dec 15, 2014 at 10:40:29AM +0000, Russell King - ARM Linux wrote:
Including details like this (because ASoC needs a separate DT node) is the wrong approach.
And indeed there should be no Linux-internal reason for that - we should be able to use whatever DT node makes sense, if there's some reason that's not possible we should fix that (we do have several drivers doing this sort of thing already though).
Hi Mark & Russell:
thanks for your replay, what your say is right, those dt is merely describing the Linux kernel internals. Instead of transmit cpu-of-node & codec-name & codec-dai-name through dt, i can give those an const name to rockchip-hdmi-audio.c .
In that way, dt will only need compatible for creating sound device. is it ok ? sound { compatible = "rockchip,rk3288-hdmi-audio"; status = "okay"; } could you give me some advises.
Best Regards.
在 2014年12月15日 20:02, Mark Brown 写道:
On Mon, Dec 15, 2014 at 10:40:29AM +0000, Russell King - ARM Linux wrote:
Including details like this (because ASoC needs a separate DT node) is the wrong approach.
And indeed there should be no Linux-internal reason for that - we should be able to use whatever DT node makes sense, if there's some reason that's not possible we should fix that (we do have several drivers doing this sort of thing already though).
On Mon, Dec 15, 2014 at 09:10:26PM +0800, Kuankuan.Yang wrote:
Hi Mark & Russell:
Please don't top post, that way people have some context for what you're saying - look at how people normally format their mails on thelist.
In that way, dt will only need compatible for creating sound device. is it ok ? sound { compatible = "rockchip,rk3288-hdmi-audio"; status = "okay"; } could you give me some advises.
That'd be good, though the other question is if this can be made to use simple-card so we can avoid having a custom driver for this.
Hi Mark :
Got it, it will be good to use simple-card. i will try it in next version.
Best Regards.
在 2014年12月16日 00:18, Mark Brown 写道:
On Mon, Dec 15, 2014 at 09:10:26PM +0800, Kuankuan.Yang wrote:
Hi Mark & Russell:
Please don't top post, that way people have some context for what you're saying - look at how people normally format their mails on thelist.
In that way, dt will only need compatible for creating sound device. is it ok ? sound { compatible = "rockchip,rk3288-hdmi-audio"; status = "okay"; } could you give me some advises.
That'd be good, though the other question is if this can be made to use simple-card so we can avoid having a custom driver for this.
在 2014年12月16日 00:18, Mark Brown 写道:
On Mon, Dec 15, 2014 at 09:10:26PM +0800, Kuankuan.Yang wrote:
Hi Mark & Russell:
Please don't top post, that way people have some context for what you're saying - look at how people normally format their mails on thelist.
got it, thanks for your remind.
In that way, dt will only need compatible for creating sound device. is it ok ? sound { compatible = "rockchip,rk3288-hdmi-audio"; status = "okay"; } could you give me some advises.
That'd be good, though the other question is if this can be made to use simple-card so we can avoid having a custom driver for this.
在 2014年12月16日 00:18, Mark Brown 写道:
On Mon, Dec 15, 2014 at 09:10:26PM +0800, Kuankuan.Yang wrote:
Hi Mark & Russell:
Please don't top post, that way people have some context for what you're saying - look at how people normally format their mails on thelist.
In that way, dt will only need compatible for creating sound device. is it ok ? sound { compatible = "rockchip,rk3288-hdmi-audio"; status = "okay"; } could you give me some advises.
That'd be good, though the other question is if this can be made to use simple-card so we can avoid having a custom driver for this.
Hi Russell & Mark:
hdmi-audio driver share irq with dw_hdmi driver, for continuing AHBAUDDMA or for detecting hdmi insert. So maybe it's hard to switch to simple-card way, Russell what's your opinion ?
Best Regards.
On Tue, Dec 16, 2014 at 02:17:51PM +0800, Kuankuan.Yang wrote:
hdmi-audio driver share irq with dw_hdmi driver, for continuing AHBAUDDMA or for detecting hdmi insert. So maybe it's hard to switch to simple-card way, Russell what's your opinion ?
My "opinion" is that I need to spend some time looking in depth at both your code and my code before I can form an idea of how to proceed.
However, since I seem to be spending a lot of time chasing regressions which have appeared in v3.18, I don't have a lot of time to look at this right now.
在 2014年12月16日 17:34, Russell King - ARM Linux 写道:
On Tue, Dec 16, 2014 at 02:17:51PM +0800, Kuankuan.Yang wrote:
hdmi-audio driver share irq with dw_hdmi driver, for continuing AHBAUDDMA or for detecting hdmi insert. So maybe it's hard to switch to simple-card way, Russell what's your opinion ?
My "opinion" is that I need to spend some time looking in depth at both your code and my code before I can form an idea of how to proceed.
However, since I seem to be spending a lot of time chasing regressions which have appeared in v3.18, I don't have a lot of time to look at this right now.
okay, if u got any ideas, wish u can let me know, thks.
Add hdmi_audio to rk3288.dtsi, enable hdmi_audio in rk3288-evb.dts
Signed-off-by: Yakir Yang ykk@rock-chips.com
series-cc: Dominik Behr dbehr@chromium.org
---
arch/arm/boot/dts/rk3288-evb.dtsi | 11 +++++++++++ arch/arm/boot/dts/rk3288.dtsi | 8 ++++++++ 2 files changed, 19 insertions(+)
diff --git a/arch/arm/boot/dts/rk3288-evb.dtsi b/arch/arm/boot/dts/rk3288-evb.dtsi index 3e067dd..53115d4 100644 --- a/arch/arm/boot/dts/rk3288-evb.dtsi +++ b/arch/arm/boot/dts/rk3288-evb.dtsi @@ -120,6 +120,17 @@ status = "okay"; };
+&i2s { + status = "okay"; + clock-names = "i2s_hclk", "i2s_clk", "i2s_clk_out"; + clocks = <&cru HCLK_I2S0>, <&cru SCLK_I2S0>, + <&cru SCLK_I2S0_OUT>; +}; + +&hdmi_audio { + status = "okay"; +}; + &wdt { status = "okay"; }; diff --git a/arch/arm/boot/dts/rk3288.dtsi b/arch/arm/boot/dts/rk3288.dtsi index fd19f00..3eeba16 100644 --- a/arch/arm/boot/dts/rk3288.dtsi +++ b/arch/arm/boot/dts/rk3288.dtsi @@ -588,6 +588,14 @@ interrupts = <GIC_PPI 9 0xf04>; };
+ hdmi_audio: hdmi_audio { + compatible = "rockchip,rk3288-hdmi-audio"; + cpu-of-node = <&i2s>; + codec-name = "dw-hdmi-audio"; + codec-dai-name = "dw-hdmi-hifi"; + status = "disable"; + }; + pinctrl: pinctrl { compatible = "rockchip,rk3288-pinctrl"; rockchip,grf = <&grf>;
On Mon, Dec 15, 2014 at 10:11:28AM +0800, Yakir Yang wrote:
rk3288 use Designware HDMI IP, Designware HDMI supports four interfaces to config hdmi audio(I2S, S/PDIF, Generic Parallel Audio, AHB Audio DMA), but rk3288 only support two ways to config hdmi audio(I2S, S/PDIF), So we take I2S as hdmi audio operation interfaces, and then treat hdmi audio as an standard ALSA devices(only got platback function).
There is no need for dw-hdmi audio to be implemented as an ASoC device - as I've already sent patches to Andy with my ALSA driver which has been around for the last two years, and works well, and doesn't require any additional DT description.
Hi Russell:
thks for your replay, actually you also have send me those dw-hdmi-audio.c patches, and I also agree it's an beautiful way to make hdmi-audio works. Beside, I try to reuse it into our platform, and actually the system have created the DW_HDMI sound card successfully, but i cannot play any sound with this sound card. After dump the registers, I found the part of "Audio DMA Registers" cannot write and always read with 0x00. So I searching the document "Designware Core HDMI Transmitter Controller Databook", and found that "Audio DMA Registers" only present when the hardware configuration parameter AUDIO_IF is set to AHBAUDDMA. Than I communicate with our IC colleagues, they told me that our cpu rk3288 only support two way to transmit audio data( I2S & SPDIF ), in that way we do not support AHB_DMA, it's very sad, and this it why i give up this way, also it's my bad that i should replay to u first in the before mail.
Best Regards.
在 2014年12月15日 18:38, Russell King - ARM Linux 写道:
On Mon, Dec 15, 2014 at 10:11:28AM +0800, Yakir Yang wrote:
rk3288 use Designware HDMI IP, Designware HDMI supports four interfaces to config hdmi audio(I2S, S/PDIF, Generic Parallel Audio, AHB Audio DMA), but rk3288 only support two ways to config hdmi audio(I2S, S/PDIF), So we take I2S as hdmi audio operation interfaces, and then treat hdmi audio as an standard ALSA devices(only got platback function).
There is no need for dw-hdmi audio to be implemented as an ASoC device - as I've already sent patches to Andy with my ALSA driver which has been around for the last two years, and works well, and doesn't require any additional DT description.
participants (6)
-
Kuankuan.Yang
-
Lars-Peter Clausen
-
Mark Brown
-
Russell King - ARM Linux
-
Yakir Yang
-
ykk@rock-chips.com