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;
31 unsigned long pll_out, rclk_rate;
34 switch (params_rate(params)) {
48 pr_err("rk_spdif: params not support\n");
53 rclk_rate = params_rate(params) * ratio;
55 /* Set audio source clock rates */
56 ret = snd_soc_dai_set_sysclk(cpu_dai, 0,
57 rclk_rate, SND_SOC_CLOCK_IN);
64 static struct snd_soc_ops rk_spdif_ops = {
65 .hw_params = rk_hw_params,
68 static struct snd_soc_dai_link rk_dai = {
70 .stream_name = "SPDIF PCM Playback",
71 .codec_dai_name = "rk-hdmi-spdif-hifi",
75 static struct snd_soc_card rockchip_spdif_card = {
76 .name = "RK-SPDIF-CARD",
81 static int rockchip_spdif_card_probe(struct platform_device *pdev)
84 struct snd_soc_card *card = &rockchip_spdif_card;
86 card->dev = &pdev->dev;
88 ret = rockchip_of_get_sound_card_info_(card, false);
90 pr_err("%s() get sound card info failed:%d\n",
95 ret = snd_soc_register_card(card);
98 pr_err("%s() register card failed:%d\n",
104 static int rockchip_spdif_card_remove(struct platform_device *pdev)
106 struct snd_soc_card *card = platform_get_drvdata(pdev);
108 snd_soc_unregister_card(card);
114 static const struct of_device_id rockchip_spdif_card_of_match[] = {
115 { .compatible = "rockchip-spdif-card"},
118 MODULE_DEVICE_TABLE(of, rockchip_spdif_card_of_match);
119 #endif /* CONFIG_OF */
121 static struct platform_driver rockchip_spdif_card_driver = {
123 .name = "rockchip-spdif-card",
124 .owner = THIS_MODULE,
125 .pm = &snd_soc_pm_ops,
126 .of_match_table = of_match_ptr(rockchip_spdif_card_of_match),
128 .probe = rockchip_spdif_card_probe,
129 .remove = rockchip_spdif_card_remove,
132 module_platform_driver(rockchip_spdif_card_driver);
134 MODULE_AUTHOR("hzb, <hzb@rock-chips.com>");
135 MODULE_DESCRIPTION("ALSA SoC RK S/PDIF");
136 MODULE_LICENSE("GPL");