Audio : Change coding style
[firefly-linux-kernel-4.4.55.git] / sound / soc / rockchip / rk_hdmi_spdif.c
1 /*$_FOR_ROCKCHIP_RBOX_$*/
2 /*$_rbox_$_modify_$_huangzhibao for spdif output*/
3
4 /*
5  * smdk_spdif.c  --  S/PDIF audio for SMDK
6  *
7  * Copyright 2010 Samsung Electronics Co. Ltd.
8  *
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.
13  *
14  */
15
16 #include <linux/module.h>
17 #include <linux/device.h>
18 #include <linux/of.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>
25
26 #include "card_info.h"
27 #include "rk_pcm.h"
28
29 #if 0
30 #define RK_SPDIF_DBG(x...) pr_info(KERN_INFO "rk_hdmi_spdif:"x)
31 #else
32 #define RK_SPDIF_DBG(x...) do { } while (0)
33 #endif
34
35 static int set_audio_clock_rate(unsigned long pll_rate,
36                                 unsigned long audio_rate)
37 {
38         struct clk *sclk_spdif;
39 #if defined(CONFIG_ARCH_RK30) || defined(CONFIG_ARCH_RK3188)
40         struct clk *hclk_spdif;
41 #endif
42
43 #if defined(CONFIG_ARCH_RK30) || defined(CONFIG_ARCH_RK3188)
44         hclk_spdif = clk_get(NULL, "hclk_spdif");
45         if (IS_ERR(hclk_spdif)) {
46                 pr_info(KERN_INFO "spdif:failed to get hclk_spdif\n");
47                 return -ENOENT;
48         }
49
50         clk_set_rate(hclk_spdif, pll_rate);
51         clk_put(hclk_spdif);
52 #endif
53
54         sclk_spdif = clk_get(NULL, "spdif");
55         if (IS_ERR(sclk_spdif)) {
56                 pr_info(KERN_INFO "spdif:failed to get sclk_spdif\n");
57                 return -ENOENT;
58         }
59
60         clk_set_rate(sclk_spdif, audio_rate);
61         clk_put(sclk_spdif);
62
63         return 0;
64 }
65
66 static int rk_hw_params(struct snd_pcm_substream *substream,
67                 struct snd_pcm_hw_params *params)
68 {
69         struct snd_soc_pcm_runtime *rtd = substream->private_data;
70         struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
71         struct snd_soc_dai *codec_dai = rtd->codec_dai;
72         unsigned long pll_out, rclk_rate, dai_fmt = rtd->dai_link->dai_fmt;
73         int ret, ratio;
74
75         RK_SPDIF_DBG("spdif:Entered %s\n", __func__);
76
77         return 0;
78
79         /* set codec DAI configuration */
80         ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt);
81         if (ret < 0) {
82                 pr_info(KERN_INFO "%s():failed to set the format for codec side\n",
83                         __func__);
84                 return ret;
85         }
86
87         /* set cpu DAI configuration */
88         ret = snd_soc_dai_set_fmt(cpu_dai, dai_fmt);
89         if (ret < 0) {
90                 pr_info(KERN_INFO "%s():failed to set the format for cpu side\n",
91                         __func__);
92                 return ret;
93         }
94
95         switch (params_rate(params)) {
96         case 44100:
97                 pll_out = 11289600;
98                 break;
99         case 32000:
100                 pll_out = 8192000;
101                 break;
102         case 48000:
103                 pll_out = 12288000;
104                 break;
105         case 96000:
106                 pll_out = 24576000;
107                 break;
108         default:
109                 pr_info(KERN_INFO "rk_spdif: params not support\n");
110                 return -EINVAL;
111         }
112
113         ratio = 256;
114         rclk_rate = params_rate(params) * ratio;
115
116         /* Set audio source clock rates */
117         ret = set_audio_clock_rate(pll_out, rclk_rate);
118         if (ret < 0)
119                 return ret;
120
121         return ret;
122 }
123
124 static struct snd_soc_ops rk_spdif_ops = {
125         .hw_params = rk_hw_params,
126 };
127
128 static struct snd_soc_dai_link rk_dai = {
129         .name = "SPDIF",
130         .stream_name = "SPDIF PCM Playback",
131         .codec_dai_name = "rk-hdmi-spdif-hifi",
132         .ops = &rk_spdif_ops,
133 };
134
135 static struct snd_soc_card rockchip_hdmi_spdif_snd_card = {
136         .name = "RK-HDMI-SPDIF",
137         .dai_link = &rk_dai,
138         .num_links = 1,
139 };
140
141 static int rockchip_hdmi_spdif_audio_probe(struct platform_device *pdev)
142 {
143         int ret;
144         struct snd_soc_card *card = &rockchip_hdmi_spdif_snd_card;
145
146         card->dev = &pdev->dev;
147
148         ret = rockchip_of_get_sound_card_info_(card, false);
149         if (ret) {
150                 pr_info(KERN_INFO "%s() get sound card info failed:%d\n",
151                         __func__, ret);
152                 return ret;
153         }
154
155         ret = snd_soc_register_card(card);
156
157         if (ret)
158                 pr_info(KERN_INFO "%s() register card failed:%d\n",
159                         __func__, ret);
160
161         return ret;
162 }
163
164 static int rockchip_hdmi_spdif_audio_remove(struct platform_device *pdev)
165 {
166         struct snd_soc_card *card = platform_get_drvdata(pdev);
167
168         snd_soc_unregister_card(card);
169
170         return 0;
171 }
172
173 #ifdef CONFIG_OF
174 static const struct of_device_id rockchip_hdmi_spdif_of_match[] = {
175         { .compatible = "rockchip-hdmi-spdif"},
176         {},
177 };
178 MODULE_DEVICE_TABLE(of, rockchip_hdmi_spdif_of_match);
179 #endif /* CONFIG_OF */
180
181 static struct platform_driver rockchip_hdmi_spdif_audio_driver = {
182         .driver         = {
183                 .name   = "rockchip-hdmi-spdif",
184                 .owner  = THIS_MODULE,
185                 .pm = &snd_soc_pm_ops,
186                 .of_match_table = of_match_ptr(rockchip_hdmi_spdif_of_match),
187         },
188         .probe          = rockchip_hdmi_spdif_audio_probe,
189         .remove         = rockchip_hdmi_spdif_audio_remove,
190 };
191
192 module_platform_driver(rockchip_hdmi_spdif_audio_driver);
193
194 MODULE_AUTHOR("hzb, <hzb@rock-chips.com>");
195 MODULE_DESCRIPTION("ALSA SoC RK+S/PDIF");
196 MODULE_LICENSE("GPL");