2 * rk_hdmi_i2s.c -- HDMI i2s audio for rockchip
4 * Copyright 2013 Rockship
5 * Author: chenjq <chenjq@rock-chips.com>
8 #include <linux/module.h>
9 #include <linux/device.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>
17 #include "card_info.h"
22 #define DBG(x...) printk(KERN_INFO "rk_hdmi_i2s:"x)
24 #define DBG(x...) do { } while (0)
27 static int hdmi_i2s_hifi_hw_params(struct snd_pcm_substream *substream,
28 struct snd_pcm_hw_params *params)
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;
35 DBG("Enter::%s----%d\n",__FUNCTION__,__LINE__);
37 switch(params_rate(params)) {
51 printk("Enter:%s, %d, Error rate=%d\n", __FUNCTION__, __LINE__, params_rate(params));
56 DBG("Enter:%s, %d, rate=%d\n", __FUNCTION__, __LINE__, params_rate(params));
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);
62 DBG("Enter:%s, %d, pll_out/4/params_rate(params) = %d \n", __FUNCTION__, __LINE__, (pll_out/4)/params_rate(params));
69 static struct snd_soc_ops hdmi_i2s_hifi_ops = {
70 .hw_params = hdmi_i2s_hifi_hw_params,
73 static struct snd_soc_dai_link hdmi_i2s_dai = {
75 .stream_name = "HDMI PCM",
76 .codec_dai_name = "rk-hdmi-i2s-hifi",
77 .ops = &hdmi_i2s_hifi_ops,
80 static struct snd_soc_card rockchip_hdmi_i2s_snd_card = {
81 .name = "RK-HDMI-I2S",
82 .dai_link = &hdmi_i2s_dai,
86 static int rockchip_hdmi_i2s_audio_probe(struct platform_device *pdev)
89 struct snd_soc_card *card = &rockchip_hdmi_i2s_snd_card;
91 card->dev = &pdev->dev;
93 ret = rockchip_of_get_sound_card_info(card);
95 printk("%s() get sound card info failed:%d\n", __FUNCTION__, ret);
99 ret = snd_soc_register_card(card);
101 printk("%s() register card failed:%d\n", __FUNCTION__, ret);
106 static int rockchip_hdmi_i2s_audio_remove(struct platform_device *pdev)
108 struct snd_soc_card *card = platform_get_drvdata(pdev);
110 snd_soc_unregister_card(card);
116 static const struct of_device_id rockchip_hdmi_i2s_of_match[] = {
117 { .compatible = "rockchip-hdmi-i2s", },
120 MODULE_DEVICE_TABLE(of, rockchip_hdmi_i2s_of_match);
121 #endif /* CONFIG_OF */
123 static struct platform_driver rockchip_hdmi_i2s_audio_driver = {
125 .name = "rockchip-hdmi-i2s",
126 .owner = THIS_MODULE,
127 .of_match_table = of_match_ptr(rockchip_hdmi_i2s_of_match),
129 .probe = rockchip_hdmi_i2s_audio_probe,
130 .remove = rockchip_hdmi_i2s_audio_remove,
133 module_platform_driver(rockchip_hdmi_i2s_audio_driver);
135 /* Module information */
136 MODULE_AUTHOR("rockchip");
137 MODULE_DESCRIPTION("ROCKCHIP hdmi i2s ASoC Interface");
138 MODULE_LICENSE("GPL");