ASoC: rockchip: coding style.
[firefly-linux-kernel-4.4.55.git] / sound / soc / rockchip / rk_spdif_card.c
1 /*
2  * rk_spdif_card.c  --  spdif card for rockchip
3  *
4  * Copyright (C) 2014 Fuzhou Rockchip Electronics Co., Ltd
5  *
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.
9  *
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.
14  *
15  */
16
17 #include <linux/module.h>
18 #include <linux/device.h>
19 #include <linux/of.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>
26
27 #include "card_info.h"
28 #include "rk_pcm.h"
29
30 static int rk_hw_params(struct snd_pcm_substream *substream,
31                         struct snd_pcm_hw_params *params)
32 {
33         struct snd_soc_pcm_runtime *rtd = substream->private_data;
34         struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
35         unsigned long sclk;
36         int ret, ratio;
37
38         /* bmc: 2*32*fs*2 = 128fs */
39         ratio = 128;
40
41         switch (params_rate(params)) {
42         case 44100:
43         case 32000:
44         case 48000:
45         case 96000:
46         case 192000:
47                 sclk = params_rate(params) * ratio;
48                 break;
49         default:
50                 pr_err("rk_spdif: params not support\n");
51                 return -EINVAL;
52         }
53
54         ret = snd_soc_dai_set_sysclk(cpu_dai, 0,
55                                      sclk, SND_SOC_CLOCK_IN);
56
57         return ret;
58 }
59
60 static struct snd_soc_ops rk_spdif_ops = {
61         .hw_params = rk_hw_params,
62 };
63
64 static struct snd_soc_dai_link rk_dai = {
65         .name = "SPDIF",
66         .stream_name = "SPDIF PCM Playback",
67         .codec_dai_name = "rk-hdmi-spdif-hifi",
68         .ops = &rk_spdif_ops,
69 };
70
71 static struct snd_soc_card rockchip_spdif_card = {
72         .name = "RK-SPDIF-CARD",
73         .dai_link = &rk_dai,
74         .num_links = 1,
75 };
76
77 static int rockchip_spdif_card_probe(struct platform_device *pdev)
78 {
79         int ret;
80         struct snd_soc_card *card = &rockchip_spdif_card;
81
82         card->dev = &pdev->dev;
83
84         ret = rockchip_of_get_sound_card_info_(card, false);
85         if (ret) {
86                 pr_err("%s() get sound card info failed:%d\n",
87                        __func__, ret);
88                 return ret;
89         }
90
91         ret = snd_soc_register_card(card);
92
93         if (ret)
94                 pr_err("%s() register card failed:%d\n",
95                        __func__, ret);
96
97         return ret;
98 }
99
100 static int rockchip_spdif_card_remove(struct platform_device *pdev)
101 {
102         struct snd_soc_card *card = platform_get_drvdata(pdev);
103
104         snd_soc_unregister_card(card);
105
106         return 0;
107 }
108
109 #ifdef CONFIG_OF
110 static const struct of_device_id rockchip_spdif_card_of_match[] = {
111         { .compatible = "rockchip-spdif-card", },
112         {},
113 };
114 MODULE_DEVICE_TABLE(of, rockchip_spdif_card_of_match);
115 #endif /* CONFIG_OF */
116
117 static struct platform_driver rockchip_spdif_card_driver = {
118         .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),
123         },
124         .probe = rockchip_spdif_card_probe,
125         .remove = rockchip_spdif_card_remove,
126 };
127
128 /* module_platform_driver(rockchip_spdif_card_driver); */
129
130 static int __init rockchip_spdif_init(void)
131 {
132         return platform_driver_register(&rockchip_spdif_card_driver);
133 };
134 late_initcall(rockchip_spdif_init);
135
136 static void __exit rockchip_spdif_exit(void)
137 {
138         platform_driver_unregister(&rockchip_spdif_card_driver);
139 }
140 module_exit(rockchip_spdif_exit);
141
142
143 MODULE_AUTHOR("hzb <hzb@rock-chips.com>");
144 MODULE_DESCRIPTION("ALSA SoC RK S/PDIF");
145 MODULE_LICENSE("GPL");