2 * rk_spdif_card.c -- spdif card for rockchip
4 * Copyright 2014 rockchip Co. Ltd.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
13 #include <linux/module.h>
14 #include <linux/device.h>
16 #include <linux/of_gpio.h>
17 #include <linux/clk.h>
18 #include <sound/core.h>
19 #include <sound/pcm.h>
20 #include <sound/soc.h>
21 #include <sound/soc-dapm.h>
23 #include "card_info.h"
26 static int rk_hw_params(struct snd_pcm_substream *substream,
27 struct snd_pcm_hw_params *params)
29 struct snd_soc_pcm_runtime *rtd = substream->private_data;
30 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
34 /* bmc: 2*32*fs*2 = 128fs */
37 switch (params_rate(params)) {
43 sclk = params_rate(params) * ratio;
46 pr_err("rk_spdif: params not support\n");
50 ret = snd_soc_dai_set_sysclk(cpu_dai, 0,
51 sclk, SND_SOC_CLOCK_IN);
58 static struct snd_soc_ops rk_spdif_ops = {
59 .hw_params = rk_hw_params,
62 static struct snd_soc_dai_link rk_dai = {
64 .stream_name = "SPDIF PCM Playback",
65 .codec_dai_name = "rk-hdmi-spdif-hifi",
69 static struct snd_soc_card rockchip_spdif_card = {
70 .name = "RK-SPDIF-CARD",
75 static int rockchip_spdif_card_probe(struct platform_device *pdev)
78 struct snd_soc_card *card = &rockchip_spdif_card;
80 card->dev = &pdev->dev;
82 ret = rockchip_of_get_sound_card_info_(card, false);
84 pr_err("%s() get sound card info failed:%d\n",
89 ret = snd_soc_register_card(card);
92 pr_err("%s() register card failed:%d\n",
98 static int rockchip_spdif_card_remove(struct platform_device *pdev)
100 struct snd_soc_card *card = platform_get_drvdata(pdev);
102 snd_soc_unregister_card(card);
108 static const struct of_device_id rockchip_spdif_card_of_match[] = {
109 { .compatible = "rockchip-spdif-card"},
112 MODULE_DEVICE_TABLE(of, rockchip_spdif_card_of_match);
113 #endif /* CONFIG_OF */
115 static struct platform_driver rockchip_spdif_card_driver = {
117 .name = "rockchip-spdif-card",
118 .owner = THIS_MODULE,
119 .pm = &snd_soc_pm_ops,
120 .of_match_table = of_match_ptr(rockchip_spdif_card_of_match),
122 .probe = rockchip_spdif_card_probe,
123 .remove = rockchip_spdif_card_remove,
126 //module_platform_driver(rockchip_spdif_card_driver);
129 static int __init rockchip_spdif_init(void)
131 return platform_driver_register(&rockchip_spdif_card_driver);
133 late_initcall(rockchip_spdif_init);
135 static void __exit rockchip_spdif_exit(void)
137 platform_driver_unregister(&rockchip_spdif_card_driver);
139 module_exit(rockchip_spdif_exit);
142 MODULE_AUTHOR("hzb, <hzb@rock-chips.com>");
143 MODULE_DESCRIPTION("ALSA SoC RK S/PDIF");
144 MODULE_LICENSE("GPL");