Audio: add codec-of-node and cpu-of-node, delete CODEC_NAME_CMP, codec-name, cpu...
[firefly-linux-kernel-4.4.55.git] / sound / soc / rockchip / rk_hdmi_i2s.c
1 /*
2  * rk_hdmi_i2s.c  --  HDMI i2s audio for rockchip
3  *
4  * Copyright 2013 Rockship
5  * Author: chenjq <chenjq@rock-chips.com>
6  */
7
8 #include <linux/module.h>
9 #include <linux/device.h>
10 #include <linux/of.h>
11 #include <linux/of_gpio.h>
12 #include <sound/core.h>
13 #include <sound/pcm.h>
14 #include <sound/soc.h>
15 #include <sound/soc-dapm.h>
16
17 #include "card_info.h"
18 #include "rk_pcm.h"
19 #include "rk_i2s.h"
20
21 #if 0
22 #define DBG(x...) printk(KERN_INFO "rk_hdmi_i2s:"x)
23 #else
24 #define DBG(x...) do { } while (0)
25 #endif
26
27 static int hdmi_i2s_hifi_hw_params(struct snd_pcm_substream *substream,
28         struct snd_pcm_hw_params *params)
29 {
30         struct snd_soc_pcm_runtime *rtd = substream->private_data;
31         struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
32         unsigned int pll_out = 0;
33
34         DBG("Enter::%s----%d\n",__FUNCTION__,__LINE__);
35
36         switch(params_rate(params)) {
37                 case 8000:
38                 case 16000:
39                 case 24000:
40                 case 32000:
41                 case 48000:
42                         pll_out = 12288000;
43                         break;
44                 case 11025:
45                 case 22050:
46                 case 44100:
47                         pll_out = 11289600;
48                         break;
49                 default:
50                         printk("Enter:%s, %d, Error rate=%d\n", __FUNCTION__, __LINE__, params_rate(params));
51                         return -EINVAL;
52                         break;
53         }
54
55         DBG("Enter:%s, %d, rate=%d\n", __FUNCTION__, __LINE__, params_rate(params));
56
57         snd_soc_dai_set_sysclk(cpu_dai, 0, pll_out, 0);
58         snd_soc_dai_set_clkdiv(cpu_dai, ROCKCHIP_DIV_BCLK, (pll_out/4)/params_rate(params)-1);
59         snd_soc_dai_set_clkdiv(cpu_dai, ROCKCHIP_DIV_MCLK, 3);
60
61         DBG("Enter:%s, %d, pll_out/4/params_rate(params) = %d \n", __FUNCTION__, __LINE__, (pll_out/4)/params_rate(params));
62
63         return 0;
64 }
65
66
67
68 static struct snd_soc_ops hdmi_i2s_hifi_ops = {
69         .hw_params = hdmi_i2s_hifi_hw_params,
70 };
71
72 static struct snd_soc_dai_link hdmi_i2s_dai = {
73         .name = "HDMI I2S",
74         .stream_name = "HDMI PCM",
75         .codec_dai_name = "rk-hdmi-i2s-hifi",
76         .ops = &hdmi_i2s_hifi_ops,
77 };
78
79 static struct snd_soc_card rockchip_hdmi_i2s_snd_card = {
80         .name = "RK-HDMI-I2S",
81         .dai_link = &hdmi_i2s_dai,
82         .num_links = 1,
83 };
84
85 static int rockchip_hdmi_i2s_audio_probe(struct platform_device *pdev)
86 {
87         int ret;
88         struct snd_soc_card *card = &rockchip_hdmi_i2s_snd_card;
89
90         card->dev = &pdev->dev;
91
92         ret = rockchip_of_get_sound_card_info(card);
93         if (ret) {
94                 printk("%s() get sound card info failed:%d\n", __FUNCTION__, ret);
95                 return ret;
96         }
97
98         ret = snd_soc_register_card(card);
99         if (ret)
100                 printk("%s() register card failed:%d\n", __FUNCTION__, ret);
101
102         return ret;
103 }
104
105 static int rockchip_hdmi_i2s_audio_remove(struct platform_device *pdev)
106 {
107         struct snd_soc_card *card = platform_get_drvdata(pdev);
108
109         snd_soc_unregister_card(card);
110
111         return 0;
112 }
113
114 #ifdef CONFIG_OF
115 static const struct of_device_id rockchip_hdmi_i2s_of_match[] = {
116         { .compatible = "rockchip-hdmi-i2s", },
117         {},
118 };
119 MODULE_DEVICE_TABLE(of, rockchip_hdmi_i2s_of_match);
120 #endif /* CONFIG_OF */
121
122 static struct platform_driver rockchip_hdmi_i2s_audio_driver = {
123         .driver         = {
124                 .name   = "rockchip-hdmi-i2s",
125                 .owner  = THIS_MODULE,
126                 .of_match_table = of_match_ptr(rockchip_hdmi_i2s_of_match),
127         },
128         .probe          = rockchip_hdmi_i2s_audio_probe,
129         .remove         = rockchip_hdmi_i2s_audio_remove,
130 };
131
132 module_platform_driver(rockchip_hdmi_i2s_audio_driver);
133
134 /* Module information */
135 MODULE_AUTHOR("rockchip");
136 MODULE_DESCRIPTION("ROCKCHIP hdmi i2s ASoC Interface");
137 MODULE_LICENSE("GPL");