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 static int rk_hw_params(struct snd_pcm_substream *substream,
31 struct snd_pcm_hw_params *params)
33 struct snd_soc_pcm_runtime *rtd = substream->private_data;
34 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
38 /* bmc: 2*32*fs*2 = 128fs */
40 switch (params_rate(params)) {
46 sclk = params_rate(params) * ratio;
49 pr_err("rk_spdif: params not support\n");
53 ret = snd_soc_dai_set_sysclk(cpu_dai, 0,
54 sclk, SND_SOC_CLOCK_IN);
59 static struct snd_soc_ops rk_spdif_ops = {
60 .hw_params = rk_hw_params,
63 static struct snd_soc_dai_link rk_dai = {
65 .stream_name = "SPDIF PCM Playback",
66 .codec_dai_name = "rk-hdmi-spdif-hifi",
70 static struct snd_soc_card rockchip_hdmi_spdif_snd_card = {
71 .name = "RK-HDMI-SPDIF",
76 static int rockchip_hdmi_spdif_audio_probe(struct platform_device *pdev)
79 struct snd_soc_card *card = &rockchip_hdmi_spdif_snd_card;
81 card->dev = &pdev->dev;
83 ret = rockchip_of_get_sound_card_info_(card, false);
85 pr_err("%s() get sound card info failed:%d\n",
90 ret = snd_soc_register_card(card);
93 pr_err("%s() register card failed:%d\n",
99 static int rockchip_hdmi_spdif_audio_remove(struct platform_device *pdev)
101 struct snd_soc_card *card = platform_get_drvdata(pdev);
103 snd_soc_unregister_card(card);
109 static const struct of_device_id rockchip_hdmi_spdif_of_match[] = {
110 { .compatible = "rockchip-hdmi-spdif", },
113 MODULE_DEVICE_TABLE(of, rockchip_hdmi_spdif_of_match);
114 #endif /* CONFIG_OF */
116 static struct platform_driver rockchip_hdmi_spdif_audio_driver = {
118 .name = "rockchip-hdmi-spdif",
119 .pm = &snd_soc_pm_ops,
120 .of_match_table = of_match_ptr(rockchip_hdmi_spdif_of_match),
122 .probe = rockchip_hdmi_spdif_audio_probe,
123 .remove = rockchip_hdmi_spdif_audio_remove,
126 module_platform_driver(rockchip_hdmi_spdif_audio_driver);
128 MODULE_AUTHOR("hzb <hzb@rock-chips.com>");
129 MODULE_DESCRIPTION("Rockchip HDMI Spdif Card");
130 MODULE_LICENSE("GPL");