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, dai_fmt = rtd->dai_link->dai_fmt;
35 DBG("Enter::%s----%d\n", __FUNCTION__, __LINE__);
37 /* set cpu DAI configuration */
38 ret = snd_soc_dai_set_fmt(cpu_dai, dai_fmt);
40 printk("%s():failed to set the format for cpu side\n", __FUNCTION__);
44 switch(params_rate(params)) {
58 printk("Enter:%s, %d, Error rate=%d\n", __FUNCTION__, __LINE__, params_rate(params));
63 DBG("Enter:%s, %d, rate=%d\n", __FUNCTION__, __LINE__, params_rate(params));
65 snd_soc_dai_set_sysclk(cpu_dai, 0, pll_out, 0);
66 snd_soc_dai_set_clkdiv(cpu_dai, ROCKCHIP_DIV_BCLK, (pll_out/4)/params_rate(params)-1);
67 snd_soc_dai_set_clkdiv(cpu_dai, ROCKCHIP_DIV_MCLK, 3);
69 DBG("Enter:%s, %d, pll_out/4/params_rate(params) = %d \n", __FUNCTION__, __LINE__, (pll_out/4)/params_rate(params));
76 static struct snd_soc_ops hdmi_i2s_hifi_ops = {
77 .hw_params = hdmi_i2s_hifi_hw_params,
80 static struct snd_soc_dai_link hdmi_i2s_dai = {
82 .stream_name = "HDMI PCM",
83 .codec_dai_name = "rk-hdmi-i2s-hifi",
84 .ops = &hdmi_i2s_hifi_ops,
87 static struct snd_soc_card rockchip_hdmi_i2s_snd_card = {
88 .name = "RK-HDMI-I2S",
89 .dai_link = &hdmi_i2s_dai,
93 static int rockchip_hdmi_i2s_audio_probe(struct platform_device *pdev)
96 struct snd_soc_card *card = &rockchip_hdmi_i2s_snd_card;
98 card->dev = &pdev->dev;
100 ret = rockchip_of_get_sound_card_info(card);
102 printk("%s() get sound card info failed:%d\n", __FUNCTION__, ret);
106 ret = snd_soc_register_card(card);
108 printk("%s() register card failed:%d\n", __FUNCTION__, ret);
113 static int rockchip_hdmi_i2s_audio_remove(struct platform_device *pdev)
115 struct snd_soc_card *card = platform_get_drvdata(pdev);
117 snd_soc_unregister_card(card);
123 static const struct of_device_id rockchip_hdmi_i2s_of_match[] = {
124 { .compatible = "rockchip-hdmi-i2s", },
127 MODULE_DEVICE_TABLE(of, rockchip_hdmi_i2s_of_match);
128 #endif /* CONFIG_OF */
130 static struct platform_driver rockchip_hdmi_i2s_audio_driver = {
132 .name = "rockchip-hdmi-i2s",
133 .owner = THIS_MODULE,
134 .pm = &snd_soc_pm_ops,
135 .of_match_table = of_match_ptr(rockchip_hdmi_i2s_of_match),
137 .probe = rockchip_hdmi_i2s_audio_probe,
138 .remove = rockchip_hdmi_i2s_audio_remove,
141 module_platform_driver(rockchip_hdmi_i2s_audio_driver);
143 /* Module information */
144 MODULE_AUTHOR("rockchip");
145 MODULE_DESCRIPTION("ROCKCHIP hdmi i2s ASoC Interface");
146 MODULE_LICENSE("GPL");