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;
34 DBG("Enter::%s----%d\n",__FUNCTION__,__LINE__);
36 switch(params_rate(params)) {
50 printk("Enter:%s, %d, Error rate=%d\n", __FUNCTION__, __LINE__, params_rate(params));
55 DBG("Enter:%s, %d, rate=%d\n", __FUNCTION__, __LINE__, params_rate(params));
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);
61 DBG("Enter:%s, %d, pll_out/4/params_rate(params) = %d \n", __FUNCTION__, __LINE__, (pll_out/4)/params_rate(params));
68 static struct snd_soc_ops hdmi_i2s_hifi_ops = {
69 .hw_params = hdmi_i2s_hifi_hw_params,
72 static struct snd_soc_dai_link hdmi_i2s_dai = {
74 .stream_name = "HDMI PCM",
75 .codec_dai_name = "rk-hdmi-i2s-hifi",
76 .ops = &hdmi_i2s_hifi_ops,
79 static struct snd_soc_card rockchip_hdmi_i2s_snd_card = {
80 .name = "RK-HDMI-I2S",
81 .dai_link = &hdmi_i2s_dai,
85 static int rockchip_hdmi_i2s_audio_probe(struct platform_device *pdev)
88 struct snd_soc_card *card = &rockchip_hdmi_i2s_snd_card;
90 card->dev = &pdev->dev;
92 ret = rockchip_of_get_sound_card_info(card);
94 printk("%s() get sound card info failed:%d\n", __FUNCTION__, ret);
98 ret = snd_soc_register_card(card);
100 printk("%s() register card failed:%d\n", __FUNCTION__, ret);
105 static int rockchip_hdmi_i2s_audio_remove(struct platform_device *pdev)
107 struct snd_soc_card *card = platform_get_drvdata(pdev);
109 snd_soc_unregister_card(card);
115 static const struct of_device_id rockchip_hdmi_i2s_of_match[] = {
116 { .compatible = "rockchip-hdmi-i2s", },
119 MODULE_DEVICE_TABLE(of, rockchip_hdmi_i2s_of_match);
120 #endif /* CONFIG_OF */
122 static struct platform_driver rockchip_hdmi_i2s_audio_driver = {
124 .name = "rockchip-hdmi-i2s",
125 .owner = THIS_MODULE,
126 .of_match_table = of_match_ptr(rockchip_hdmi_i2s_of_match),
128 .probe = rockchip_hdmi_i2s_audio_probe,
129 .remove = rockchip_hdmi_i2s_audio_remove,
132 module_platform_driver(rockchip_hdmi_i2s_audio_driver);
134 /* Module information */
135 MODULE_AUTHOR("rockchip");
136 MODULE_DESCRIPTION("ROCKCHIP hdmi i2s ASoC Interface");
137 MODULE_LICENSE("GPL");