1 /*$_FOR_ROCKCHIP_RBOX_$*/
2 /*$_rbox_$_modify_$_huangzhibao for spdif output*/
5 * smdk_spdif.c -- S/PDIF audio for SMDK
7 * Copyright 2010 Samsung Electronics Co. Ltd.
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of the
12 * License, or (at your option) any later version.
16 #include <linux/module.h>
17 #include <linux/device.h>
19 #include <linux/of_gpio.h>
20 #include <linux/clk.h>
21 #include <sound/core.h>
22 #include <sound/pcm.h>
23 #include <sound/soc.h>
24 #include <sound/soc-dapm.h>
26 #include "card_info.h"
31 #define RK_SPDIF_DBG(x...) printk(KERN_INFO "rk_hdmi_spdif:"x)
33 #define RK_SPDIF_DBG(x...) do { } while (0)
37 static int set_audio_clock_rate(unsigned long pll_rate,
38 unsigned long audio_rate)
40 struct clk *sclk_spdif;
41 #if defined (CONFIG_ARCH_RK30) || defined (CONFIG_ARCH_RK3188)
42 struct clk *hclk_spdif;
45 #if defined (CONFIG_ARCH_RK30) || defined (CONFIG_ARCH_RK3188)
46 hclk_spdif = clk_get(NULL, "hclk_spdif");
47 if (IS_ERR(hclk_spdif)) {
48 printk(KERN_ERR "spdif:failed to get hclk_spdif\n");
52 clk_set_rate(hclk_spdif, pll_rate);
56 sclk_spdif = clk_get(NULL, "spdif");
57 if (IS_ERR(sclk_spdif)) {
58 printk(KERN_ERR "spdif:failed to get sclk_spdif\n");
62 clk_set_rate(sclk_spdif, audio_rate);
68 static int rk_hw_params(struct snd_pcm_substream *substream,
69 struct snd_pcm_hw_params *params)
71 struct snd_soc_pcm_runtime *rtd = substream->private_data;
72 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
73 struct snd_soc_dai *codec_dai = rtd->codec_dai;
74 unsigned long pll_out, rclk_rate, dai_fmt = rtd->dai_link->dai_fmt;
77 RK_SPDIF_DBG("spdif:Entered %s\n", __func__);
81 /* set codec DAI configuration */
82 ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt);
84 printk("%s():failed to set the format for codec side\n", __func__);
88 /* set cpu DAI configuration */
89 ret = snd_soc_dai_set_fmt(cpu_dai, dai_fmt);
91 printk("%s():failed to set the format for cpu side\n", __func__);
95 switch (params_rate(params)) {
109 printk("rk_spdif: params not support\n");
114 rclk_rate = params_rate(params) * ratio;
116 /* Set audio source clock rates */
117 ret = set_audio_clock_rate(pll_out, rclk_rate);
121 /* Set S/PDIF uses internal source clock */
122 //ret = snd_soc_dai_set_sysclk(cpu_dai, SND_SOC_SPDIF_INT_MCLK,
123 //rclk_rate, SND_SOC_CLOCK_IN);
130 static struct snd_soc_ops rk_spdif_ops = {
131 .hw_params = rk_hw_params,
134 static struct snd_soc_dai_link rk_dai = {
136 .stream_name = "SPDIF PCM Playback",
137 .codec_dai_name = "rk-hdmi-spdif-hifi",
138 .ops = &rk_spdif_ops,
141 static struct snd_soc_card rockchip_hdmi_spdif_snd_card = {
142 .name = "RK-HDMI-SPDIF",
147 static int rockchip_hdmi_spdif_audio_probe(struct platform_device *pdev)
150 struct snd_soc_card *card = &rockchip_hdmi_spdif_snd_card;
152 card->dev = &pdev->dev;
154 ret = rockchip_of_get_sound_card_info_(card, false);
156 printk("%s() get sound card info failed:%d\n", __FUNCTION__, ret);
160 ret = snd_soc_register_card(card);
163 printk("%s() register card failed:%d\n", __FUNCTION__, ret);
168 static int rockchip_hdmi_spdif_audio_remove(struct platform_device *pdev)
170 struct snd_soc_card *card = platform_get_drvdata(pdev);
172 snd_soc_unregister_card(card);
178 static const struct of_device_id rockchip_hdmi_spdif_of_match[] = {
179 { .compatible = "rockchip-hdmi-spdif"},
182 MODULE_DEVICE_TABLE(of, rockchip_hdmi_spdif_of_match);
183 #endif /* CONFIG_OF */
185 static struct platform_driver rockchip_hdmi_spdif_audio_driver = {
187 .name = "rockchip-hdmi-spdif",
188 .owner = THIS_MODULE,
189 .pm = &snd_soc_pm_ops,
190 .of_match_table = of_match_ptr(rockchip_hdmi_spdif_of_match),
192 .probe = rockchip_hdmi_spdif_audio_probe,
193 .remove = rockchip_hdmi_spdif_audio_remove,
196 module_platform_driver(rockchip_hdmi_spdif_audio_driver);
198 MODULE_AUTHOR("hzb, <hzb@rock-chips.com>");
199 MODULE_DESCRIPTION("ALSA SoC RK+S/PDIF");
200 MODULE_LICENSE("GPL");