Merge branch android-common-3.10
[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("rk_hdmi_spdif:"x)
31 #else
32 #define RK_SPDIF_DBG(x...) do { } while (0)
33 #endif
34
35 static int rk_hw_params(struct snd_pcm_substream *substream,
36                         struct snd_pcm_hw_params *params)
37 {
38         struct snd_soc_pcm_runtime *rtd = substream->private_data;
39         struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
40         unsigned long pll_out, rclk_rate;
41         int ret, ratio;
42
43         RK_SPDIF_DBG("spdif:Entered %s\n", __func__);
44
45         switch (params_rate(params)) {
46         case 44100:
47                 pll_out = 11289600;
48                 break;
49         case 32000:
50                 pll_out = 8192000;
51                 break;
52         case 48000:
53                 pll_out = 12288000;
54                 break;
55         case 96000:
56                 pll_out = 24576000;
57                 break;
58         default:
59                 pr_err("rk_spdif: params not support\n");
60                 return -EINVAL;
61         }
62
63         ratio = 256;
64         rclk_rate = params_rate(params) * ratio;
65
66         /* Set audio source clock rates */
67         ret = snd_soc_dai_set_sysclk(cpu_dai, 0,
68                                      rclk_rate, SND_SOC_CLOCK_IN);
69         if (ret < 0)
70                 return ret;
71
72         return ret;
73 }
74
75 static struct snd_soc_ops rk_spdif_ops = {
76         .hw_params = rk_hw_params,
77 };
78
79 static struct snd_soc_dai_link rk_dai = {
80         .name = "SPDIF",
81         .stream_name = "SPDIF PCM Playback",
82         .codec_dai_name = "rk-hdmi-spdif-hifi",
83         .ops = &rk_spdif_ops,
84 };
85
86 static struct snd_soc_card rockchip_hdmi_spdif_snd_card = {
87         .name = "RK-HDMI-SPDIF",
88         .dai_link = &rk_dai,
89         .num_links = 1,
90 };
91
92 static int rockchip_hdmi_spdif_audio_probe(struct platform_device *pdev)
93 {
94         int ret;
95         struct snd_soc_card *card = &rockchip_hdmi_spdif_snd_card;
96
97         card->dev = &pdev->dev;
98
99         ret = rockchip_of_get_sound_card_info_(card, false);
100         if (ret) {
101                 pr_err("%s() get sound card info failed:%d\n",
102                        __func__, ret);
103                 return ret;
104         }
105
106         ret = snd_soc_register_card(card);
107
108         if (ret)
109                 pr_err("%s() register card failed:%d\n",
110                        __func__, ret);
111
112         return ret;
113 }
114
115 static int rockchip_hdmi_spdif_audio_remove(struct platform_device *pdev)
116 {
117         struct snd_soc_card *card = platform_get_drvdata(pdev);
118
119         snd_soc_unregister_card(card);
120
121         return 0;
122 }
123
124 #ifdef CONFIG_OF
125 static const struct of_device_id rockchip_hdmi_spdif_of_match[] = {
126         { .compatible = "rockchip-hdmi-spdif"},
127         {},
128 };
129 MODULE_DEVICE_TABLE(of, rockchip_hdmi_spdif_of_match);
130 #endif /* CONFIG_OF */
131
132 static struct platform_driver rockchip_hdmi_spdif_audio_driver = {
133         .driver         = {
134                 .name   = "rockchip-hdmi-spdif",
135                 .owner  = THIS_MODULE,
136                 .pm = &snd_soc_pm_ops,
137                 .of_match_table = of_match_ptr(rockchip_hdmi_spdif_of_match),
138         },
139         .probe          = rockchip_hdmi_spdif_audio_probe,
140         .remove         = rockchip_hdmi_spdif_audio_remove,
141 };
142
143 module_platform_driver(rockchip_hdmi_spdif_audio_driver);
144
145 MODULE_AUTHOR("hzb, <hzb@rock-chips.com>");
146 MODULE_DESCRIPTION("ALSA SoC RK+S/PDIF");
147 MODULE_LICENSE("GPL");