From a5a925f44f8b69d3f6a2eccb9f9c2698169b8581 Mon Sep 17 00:00:00 2001 From: Chris Zhong Date: Fri, 25 Nov 2016 13:18:07 +0800 Subject: [PATCH] ASoC: rockchip: Add machine driver for cdn DP Change-Id: Id5fe7eee2bf1e73103d71f61a2b98aeaf0ea48b1 Signed-off-by: Chris Zhong --- .../bindings/sound/rockchip-cdndp.txt | 15 ++ sound/soc/rockchip/Kconfig | 8 + sound/soc/rockchip/Makefile | 2 + sound/soc/rockchip/rockchip_cdndp.c | 161 ++++++++++++++++++ 4 files changed, 186 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/rockchip-cdndp.txt create mode 100644 sound/soc/rockchip/rockchip_cdndp.c diff --git a/Documentation/devicetree/bindings/sound/rockchip-cdndp.txt b/Documentation/devicetree/bindings/sound/rockchip-cdndp.txt new file mode 100644 index 000000000000..8e032d85839c --- /dev/null +++ b/Documentation/devicetree/bindings/sound/rockchip-cdndp.txt @@ -0,0 +1,15 @@ +ROCKCHIP with DP via I2S + +Required properties: +- compatible: "rockchip,cdndp-sound" +- rockchip,cpu: The phandle of the Rockchip I2S controller controller that's + connected to the codec +- rockchip,codec: The phandle of the the DP encoder node + +Example: + +sound { + compatible = "rockchip,cdndp-sound"; + rockchip,cpu = <&i2s2>; + rockchip,codec = <&cdn_dp>; +}; diff --git a/sound/soc/rockchip/Kconfig b/sound/soc/rockchip/Kconfig index 6f874e1a721b..8e68a5d859f2 100644 --- a/sound/soc/rockchip/Kconfig +++ b/sound/soc/rockchip/Kconfig @@ -50,3 +50,11 @@ config SND_SOC_ROCKCHIP_RT5645 help Say Y or M here if you want to add support for SoC audio on Rockchip boards using the RT5645/RT5650 codec, such as Veyron. + +config SND_SOC_ROCKCHIP_CDNDP + tristate "ASoC support for Rockchip CDN DP common codec" + depends on SND_SOC_ROCKCHIP && CLKDEV_LOOKUP + select SND_SOC_ROCKCHIP_I2S + help + Say Y or M here if you want to add support for SoC audio on Rockchip + boards using CDN DP, such as RK3399 boards. diff --git a/sound/soc/rockchip/Makefile b/sound/soc/rockchip/Makefile index 38a83ed4be5e..17d084b36fa4 100644 --- a/sound/soc/rockchip/Makefile +++ b/sound/soc/rockchip/Makefile @@ -8,7 +8,9 @@ obj-$(CONFIG_SND_SOC_ROCKCHIP_SPDIF) += snd-soc-rockchip-spdif.o snd-soc-rockchip-da7219-objs := rockchip_da7219.o snd-soc-rockchip-max98090-objs := rockchip_max98090.o snd-soc-rockchip-rt5645-objs := rockchip_rt5645.o +snd-soc-rockchip-cdndp-objs := rockchip_cdndp.o obj-$(CONFIG_SND_SOC_ROCKCHIP_DA7219) += snd-soc-rockchip-da7219.o obj-$(CONFIG_SND_SOC_ROCKCHIP_MAX98090) += snd-soc-rockchip-max98090.o obj-$(CONFIG_SND_SOC_ROCKCHIP_RT5645) += snd-soc-rockchip-rt5645.o +obj-$(CONFIG_SND_SOC_ROCKCHIP_CDNDP) += snd-soc-rockchip-cdndp.o diff --git a/sound/soc/rockchip/rockchip_cdndp.c b/sound/soc/rockchip/rockchip_cdndp.c new file mode 100644 index 000000000000..7c0222a9346c --- /dev/null +++ b/sound/soc/rockchip/rockchip_cdndp.c @@ -0,0 +1,161 @@ +/* + * Rockchip machine ASoC driver for boards using CDN DP + * + * Copyright (c) 2016, ROCKCHIP CORPORATION. All rights reserved. + * + * 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 + +#define DRV_NAME "rockchip-cdndp-sound" + +static int rockchip_sound_cdndp_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; + struct snd_soc_dai *codec_dai = rtd->codec_dai; + int mclk, ret; + + /* in bypass mode, the mclk has to be one of the frequencies below */ + 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_sysclk(cpu_dai, 0, mclk, + SND_SOC_CLOCK_OUT); + if (ret < 0) { + dev_err(codec_dai->dev, "Can't set cpu clock out %d\n", ret); + return ret; + } + + return 0; +} + +static struct snd_soc_jack cdn_dp_card_jack; + +static int rockchip_sound_cdndp_init(struct snd_soc_pcm_runtime *runtime) +{ + struct snd_soc_card *card = runtime->card; + struct snd_soc_codec *codec = runtime->codec; + int ret; + + /* enable jack detection */ + ret = snd_soc_card_jack_new(card, "DP Jack", SND_JACK_LINEOUT, + &cdn_dp_card_jack, NULL, 0); + if (ret) { + dev_err(card->dev, "Can't create DP Jack %d\n", ret); + return ret; + } + + return hdmi_codec_set_jack_detect(codec, &cdn_dp_card_jack); +} + +static struct snd_soc_ops rockchip_sound_cdndp_ops = { + .hw_params = rockchip_sound_cdndp_hw_params, +}; + +static struct snd_soc_dai_link cdndp_dailink = { + .name = "DP", + .stream_name = "DP PCM", + .codec_dai_name = "i2s-hifi", + .init = rockchip_sound_cdndp_init, + .ops = &rockchip_sound_cdndp_ops, + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | + SND_SOC_DAIFMT_CBS_CFS, +}; + +static struct snd_soc_card rockchip_sound_card = { + .name = "rockchip-cdndp-sound", + .owner = THIS_MODULE, + .dai_link = &cdndp_dailink, + .num_links = 1, +}; + +static int rockchip_sound_probe(struct platform_device *pdev) +{ + struct snd_soc_card *card = &rockchip_sound_card; + struct device_node *cpu_node; + int ret; + + cpu_node = of_parse_phandle(pdev->dev.of_node, "rockchip,cpu", 0); + if (!cpu_node) { + dev_err(&pdev->dev, "Property 'rockchip,cpu' missing or invalid\n"); + return -EINVAL; + } + + cdndp_dailink.platform_of_node = cpu_node; + cdndp_dailink.cpu_of_node = cpu_node; + + cdndp_dailink.codec_of_node = of_parse_phandle(pdev->dev.of_node, + "rockchip,codec", 0); + if (!cdndp_dailink.codec_of_node) { + dev_err(&pdev->dev, "Property 'rockchip,codec' invalid\n"); + return -EINVAL; + } + + card->dev = &pdev->dev; + platform_set_drvdata(pdev, card); + + ret = devm_snd_soc_register_card(&pdev->dev, card); + if (ret) + dev_err(&pdev->dev, "%s snd_soc_register_card fail %d\n", + __func__, ret); + + return ret; +} + +static const struct of_device_id rockchip_sound_of_match[] = { + { .compatible = "rockchip,cdndp-sound", }, + {}, +}; + +static struct platform_driver rockchip_sound_driver = { + .probe = rockchip_sound_probe, + .driver = { + .name = DRV_NAME, + .of_match_table = rockchip_sound_of_match, +#ifdef CONFIG_PM + .pm = &snd_soc_pm_ops, +#endif + }, +}; + +module_platform_driver(rockchip_sound_driver); + +MODULE_AUTHOR("Chris Zhong "); +MODULE_DESCRIPTION("Rockchip CDN DP Machine Driver"); +MODULE_LICENSE("GPL v2"); +MODULE_ALIAS("platform:" DRV_NAME); +MODULE_DEVICE_TABLE(of, rockchip_sound_of_match); -- 2.34.1