2 * rk_spdif_card.c -- spdif card for rockchip
4 * Copyright (C) 2014 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 */
41 switch (params_rate(params)) {
47 sclk = params_rate(params) * ratio;
50 pr_err("rk_spdif: params not support\n");
54 ret = snd_soc_dai_set_sysclk(cpu_dai, 0,
55 sclk, SND_SOC_CLOCK_IN);
60 static struct snd_soc_ops rk_spdif_ops = {
61 .hw_params = rk_hw_params,
64 static struct snd_soc_dai_link rk_dai = {
66 .stream_name = "SPDIF PCM Playback",
67 .codec_dai_name = "rk-hdmi-spdif-hifi",
71 static struct snd_soc_card rockchip_spdif_card = {
72 .name = "RK-SPDIF-CARD",
77 static int rockchip_spdif_card_probe(struct platform_device *pdev)
80 struct snd_soc_card *card = &rockchip_spdif_card;
82 card->dev = &pdev->dev;
84 ret = rockchip_of_get_sound_card_info_(card, false);
86 pr_err("%s() get sound card info failed:%d\n",
91 ret = snd_soc_register_card(card);
94 pr_err("%s() register card failed:%d\n",
100 static int rockchip_spdif_card_remove(struct platform_device *pdev)
102 struct snd_soc_card *card = platform_get_drvdata(pdev);
104 snd_soc_unregister_card(card);
110 static const struct of_device_id rockchip_spdif_card_of_match[] = {
111 { .compatible = "rockchip-spdif-card", },
114 MODULE_DEVICE_TABLE(of, rockchip_spdif_card_of_match);
115 #endif /* CONFIG_OF */
117 static struct platform_driver rockchip_spdif_card_driver = {
119 .name = "rockchip-spdif-card",
120 .owner = THIS_MODULE,
121 .pm = &snd_soc_pm_ops,
122 .of_match_table = of_match_ptr(rockchip_spdif_card_of_match),
124 .probe = rockchip_spdif_card_probe,
125 .remove = rockchip_spdif_card_remove,
128 /* module_platform_driver(rockchip_spdif_card_driver); */
130 static int __init rockchip_spdif_init(void)
132 return platform_driver_register(&rockchip_spdif_card_driver);
134 late_initcall(rockchip_spdif_init);
136 static void __exit rockchip_spdif_exit(void)
138 platform_driver_unregister(&rockchip_spdif_card_driver);
140 module_exit(rockchip_spdif_exit);
143 MODULE_AUTHOR("hzb <hzb@rock-chips.com>");
144 MODULE_DESCRIPTION("ALSA SoC RK S/PDIF");
145 MODULE_LICENSE("GPL");