Audio: add dts property(i2s format) and delete them from menuconfig, add sound card...
[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         int ret;
34
35         DBG("Enter::%s----%d\n",__FUNCTION__,__LINE__);
36
37         switch(params_rate(params)) {
38                 case 8000:
39                 case 16000:
40                 case 24000:
41                 case 32000:
42                 case 48000:
43                         pll_out = 12288000;
44                         break;
45                 case 11025:
46                 case 22050:
47                 case 44100:
48                         pll_out = 11289600;
49                         break;
50                 default:
51                         printk("Enter:%s, %d, Error rate=%d\n", __FUNCTION__, __LINE__, params_rate(params));
52                         return -EINVAL;
53                         break;
54         }
55
56         DBG("Enter:%s, %d, rate=%d\n", __FUNCTION__, __LINE__, params_rate(params));
57
58         snd_soc_dai_set_sysclk(cpu_dai, 0, pll_out, 0);
59         snd_soc_dai_set_clkdiv(cpu_dai, ROCKCHIP_DIV_BCLK, (pll_out/4)/params_rate(params)-1);
60         snd_soc_dai_set_clkdiv(cpu_dai, ROCKCHIP_DIV_MCLK, 3);
61
62         DBG("Enter:%s, %d, pll_out/4/params_rate(params) = %d \n", __FUNCTION__, __LINE__, (pll_out/4)/params_rate(params));
63
64         return 0;
65 }
66
67
68
69 static struct snd_soc_ops hdmi_i2s_hifi_ops = {
70         .hw_params = hdmi_i2s_hifi_hw_params,
71 };
72
73 static struct snd_soc_dai_link hdmi_i2s_dai = {
74         .name = "HDMI I2S",
75         .stream_name = "HDMI PCM",
76         .codec_dai_name = "rk-hdmi-i2s-hifi",
77         .ops = &hdmi_i2s_hifi_ops,
78 };
79
80 static struct snd_soc_card rockchip_hdmi_i2s_snd_card = {
81         .name = "RK-HDMI-I2S",
82         .dai_link = &hdmi_i2s_dai,
83         .num_links = 1,
84 };
85
86 static int rockchip_hdmi_i2s_audio_probe(struct platform_device *pdev)
87 {
88         int ret;
89         struct snd_soc_card *card = &rockchip_hdmi_i2s_snd_card;
90
91         card->dev = &pdev->dev;
92
93         ret = rockchip_of_get_sound_card_info(card);
94         if (ret) {
95                 printk("%s() get sound card info failed:%d\n", __FUNCTION__, ret);
96                 return ret;
97         }
98
99         ret = snd_soc_register_card(card);
100         if (ret)
101                 printk("%s() register card failed:%d\n", __FUNCTION__, ret);
102
103         return ret;
104 }
105
106 static int rockchip_hdmi_i2s_audio_remove(struct platform_device *pdev)
107 {
108         struct snd_soc_card *card = platform_get_drvdata(pdev);
109
110         snd_soc_unregister_card(card);
111
112         return 0;
113 }
114
115 #ifdef CONFIG_OF
116 static const struct of_device_id rockchip_hdmi_i2s_of_match[] = {
117         { .compatible = "rockchip-hdmi-i2s", },
118         {},
119 };
120 MODULE_DEVICE_TABLE(of, rockchip_hdmi_i2s_of_match);
121 #endif /* CONFIG_OF */
122
123 static struct platform_driver rockchip_hdmi_i2s_audio_driver = {
124         .driver         = {
125                 .name   = "rockchip-hdmi-i2s",
126                 .owner  = THIS_MODULE,
127                 .of_match_table = of_match_ptr(rockchip_hdmi_i2s_of_match),
128         },
129         .probe          = rockchip_hdmi_i2s_audio_probe,
130         .remove         = rockchip_hdmi_i2s_audio_remove,
131 };
132
133 module_platform_driver(rockchip_hdmi_i2s_audio_driver);
134
135 /* Module information */
136 MODULE_AUTHOR("rockchip");
137 MODULE_DESCRIPTION("ROCKCHIP hdmi i2s ASoC Interface");
138 MODULE_LICENSE("GPL");