2 * rk_hdmi_spdif.c -- hdmi spdif for rockchip
4 * Copyright (C) 2015 Fuzhou Rockchip Electronics Co., Ltd
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
17 #include <linux/module.h>
18 #include <linux/device.h>
20 #include <linux/of_gpio.h>
21 #include <linux/clk.h>
22 #include <sound/core.h>
23 #include <sound/pcm.h>
24 #include <sound/soc.h>
25 #include <sound/soc-dapm.h>
27 #include "card_info.h"
30 #if defined(CONFIG_RK_HDMI) && defined(CONFIG_SND_SOC_HDMI_SPDIF)
31 extern int snd_config_hdmi_audio(struct snd_pcm_hw_params *params);
34 static int rk_hw_params(struct snd_pcm_substream *substream,
35 struct snd_pcm_hw_params *params)
37 struct snd_soc_pcm_runtime *rtd = substream->private_data;
38 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
42 /* bmc: 2*32*fs*2 = 128fs */
44 switch (params_rate(params)) {
50 sclk = params_rate(params) * ratio;
53 pr_err("rk_spdif: params not support\n");
57 ret = snd_soc_dai_set_sysclk(cpu_dai, 0,
58 sclk, SND_SOC_CLOCK_IN);
60 #if defined(CONFIG_RK_HDMI) && defined(CONFIG_SND_SOC_HDMI_SPDIF)
61 snd_config_hdmi_audio(params);
67 static struct snd_soc_ops rk_spdif_ops = {
68 .hw_params = rk_hw_params,
71 static struct snd_soc_dai_link rk_dai = {
73 .stream_name = "SPDIF PCM Playback",
74 .codec_dai_name = "rk-hdmi-spdif-hifi",
78 static struct snd_soc_card rockchip_hdmi_spdif_snd_card = {
79 .name = "RK-HDMI-SPDIF",
84 static int rockchip_hdmi_spdif_audio_probe(struct platform_device *pdev)
87 struct snd_soc_card *card = &rockchip_hdmi_spdif_snd_card;
89 card->dev = &pdev->dev;
91 ret = rockchip_of_get_sound_card_info_(card, false);
93 pr_err("%s() get sound card info failed:%d\n",
98 ret = snd_soc_register_card(card);
101 pr_err("%s() register card failed:%d\n",
107 static int rockchip_hdmi_spdif_audio_remove(struct platform_device *pdev)
109 struct snd_soc_card *card = platform_get_drvdata(pdev);
111 snd_soc_unregister_card(card);
117 static const struct of_device_id rockchip_hdmi_spdif_of_match[] = {
118 { .compatible = "rockchip-hdmi-spdif", },
121 MODULE_DEVICE_TABLE(of, rockchip_hdmi_spdif_of_match);
122 #endif /* CONFIG_OF */
124 static struct platform_driver rockchip_hdmi_spdif_audio_driver = {
126 .name = "rockchip-hdmi-spdif",
127 .pm = &snd_soc_pm_ops,
128 .of_match_table = of_match_ptr(rockchip_hdmi_spdif_of_match),
130 .probe = rockchip_hdmi_spdif_audio_probe,
131 .remove = rockchip_hdmi_spdif_audio_remove,
134 module_platform_driver(rockchip_hdmi_spdif_audio_driver);
136 MODULE_AUTHOR("hzb <hzb@rock-chips.com>");
137 MODULE_DESCRIPTION("Rockchip HDMI Spdif Card");
138 MODULE_LICENSE("GPL");