mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-07 19:30:30 +09:00
ASoC: rockchip: add rt5651_rk628 driver
add rockchip_rt5651_rk628 machine driver to support HDMIIn function Signed-off-by: Binyuan Lan <lby@rock-chips.com> Change-Id: I893afca69ba555a3a05751df32aa4461720d3ca4 Signed-off-by: Shunhua Lan <lsh@rock-chips.com>
This commit is contained in:
@@ -99,6 +99,15 @@ config SND_SOC_ROCKCHIP_RT5651
|
||||
Say Y or M here if you want to add support for SoC audio on Rockchip
|
||||
boards using the RT5651 codec.
|
||||
|
||||
config SND_SOC_ROCKCHIP_RT5651_RK628
|
||||
tristate "ASoC support for Rockchip boards RT5651 RK628 HDMIIN"
|
||||
depends on SND_SOC_ROCKCHIP && I2C && GPIOLIB && CLKDEV_LOOKUP
|
||||
select SND_SOC_ROCKCHIP_I2S
|
||||
select SND_SOC_RT5651
|
||||
help
|
||||
Say Y or M here if you want to add support for SoC audio on Rockchip
|
||||
boards for RT5651 RK628 HDMIIn
|
||||
|
||||
config SND_SOC_RK3288_HDMI_ANALOG
|
||||
tristate "ASoC support multiple codecs for Rockchip RK3288 boards"
|
||||
depends on SND_SOC_ROCKCHIP && I2C && GPIOLIB && CLKDEV_LOOKUP
|
||||
|
||||
@@ -25,6 +25,7 @@ snd-soc-rockchip-max98090-objs := rockchip_max98090.o
|
||||
snd-soc-rockchip-multicodecs-objs := rockchip_multicodecs.o
|
||||
snd-soc-rockchip-rt5645-objs := rockchip_rt5645.o
|
||||
snd-soc-rockchip-rt5651-objs := rockchip_rt5651.o
|
||||
snd-soc-rockchip-rt5651-rk628-objs := rockchip_rt5651_rk628.o
|
||||
snd-soc-rk3288-hdmi-analog-objs := rk3288_hdmi_analog.o
|
||||
snd-soc-rk3399-gru-sound-objs := rk3399_gru_sound.o
|
||||
|
||||
@@ -32,5 +33,6 @@ obj-$(CONFIG_SND_SOC_ROCKCHIP_MAX98090) += snd-soc-rockchip-max98090.o
|
||||
obj-$(CONFIG_SND_SOC_ROCKCHIP_MULTICODECS) += snd-soc-rockchip-multicodecs.o
|
||||
obj-$(CONFIG_SND_SOC_ROCKCHIP_RT5645) += snd-soc-rockchip-rt5645.o
|
||||
obj-$(CONFIG_SND_SOC_ROCKCHIP_RT5651) += snd-soc-rockchip-rt5651.o
|
||||
obj-$(CONFIG_SND_SOC_ROCKCHIP_RT5651_RK628) += snd-soc-rockchip-rt5651-rk628.o
|
||||
obj-$(CONFIG_SND_SOC_RK3288_HDMI_ANALOG) += snd-soc-rk3288-hdmi-analog.o
|
||||
obj-$(CONFIG_SND_SOC_RK3399_GRU_SOUND) += snd-soc-rk3399-gru-sound.o
|
||||
|
||||
242
sound/soc/rockchip/rockchip_rt5651_rk628.c
Normal file
242
sound/soc/rockchip/rockchip_rt5651_rk628.c
Normal file
@@ -0,0 +1,242 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
/*
|
||||
* rockchip_rt5651_rk628.c -- RK3399 machine driver with
|
||||
* RT5651/RK628 codecs
|
||||
*
|
||||
* Copyright (c) 2020 Rockchip Electronics Co. Ltd.
|
||||
* Author: binyuan <kevan.lan@rock-chips.com>
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <sound/soc.h>
|
||||
|
||||
#include "rockchip_i2s.h"
|
||||
#include "../codecs/rt5651.h"
|
||||
|
||||
#define DRV_NAME "rk3399-rt5651-rk628"
|
||||
|
||||
static const struct snd_soc_dapm_widget rockchip_dapm_widgets[] = {
|
||||
SND_SOC_DAPM_HP("Headphones", NULL),
|
||||
SND_SOC_DAPM_SPK("Lineout", NULL),
|
||||
SND_SOC_DAPM_MIC("Headset Mic", NULL),
|
||||
SND_SOC_DAPM_MIC("Int Mic", NULL),
|
||||
SND_SOC_DAPM_MIC("HDMIIN", NULL),
|
||||
};
|
||||
|
||||
static const struct snd_soc_dapm_route rockchip_dapm_routes[] = {
|
||||
{"Headphones", NULL, "HPOL"},
|
||||
{"Headphones", NULL, "HPOR"},
|
||||
{"Lineout", NULL, "LOUTL"},
|
||||
{"Lineout", NULL, "LOUTR"},
|
||||
{"AIF2 Playback", NULL, "HDMIIN"},
|
||||
};
|
||||
|
||||
static const struct snd_kcontrol_new rockchip_controls[] = {
|
||||
SOC_DAPM_PIN_SWITCH("Headphones"),
|
||||
SOC_DAPM_PIN_SWITCH("Lineout"),
|
||||
SOC_DAPM_PIN_SWITCH("Headset Mic"),
|
||||
SOC_DAPM_PIN_SWITCH("Int Mic"),
|
||||
};
|
||||
|
||||
static int rockchip_rt5651_hw_params(struct snd_pcm_substream *substream,
|
||||
struct snd_pcm_hw_params *params)
|
||||
{
|
||||
struct snd_soc_pcm_runtime *rtd = substream->private_data;
|
||||
struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
|
||||
struct snd_soc_dai *codec_dai = rtd->codec_dai;
|
||||
int mclk, ret;
|
||||
|
||||
/* in bypass mode, the mclk has to be one of the frequencies below */
|
||||
switch (params_rate(params)) {
|
||||
case 8000:
|
||||
case 16000:
|
||||
case 24000:
|
||||
case 32000:
|
||||
case 48000:
|
||||
case 64000:
|
||||
case 96000:
|
||||
mclk = 12288000;
|
||||
break;
|
||||
case 11025:
|
||||
case 22050:
|
||||
case 44100:
|
||||
case 88200:
|
||||
mclk = 11289600;
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = snd_soc_dai_set_sysclk(cpu_dai, 0, mclk, SND_SOC_CLOCK_OUT);
|
||||
if (ret < 0) {
|
||||
dev_err(codec_dai->dev, "Can't set cpu clock out %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
snd_soc_dai_set_pll(codec_dai, 0, RT5651_PLL1_S_MCLK, mclk, mclk * 2);
|
||||
|
||||
ret = snd_soc_dai_set_sysclk(codec_dai, RT5651_SCLK_S_PLL1, mclk * 2,
|
||||
SND_SOC_CLOCK_IN);
|
||||
if (ret < 0) {
|
||||
dev_err(codec_dai->dev, "Can't set codec clock in %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rockchip_rt5651_voice_hw_params(struct snd_pcm_substream *substream,
|
||||
struct snd_pcm_hw_params *params)
|
||||
{
|
||||
struct snd_soc_pcm_runtime *rtd = substream->private_data;
|
||||
struct snd_soc_dai *codec_dai = rtd->codec_dai;
|
||||
int mclk, ret;
|
||||
|
||||
/* in bypass mode, the mclk has to be one of the frequencies below */
|
||||
switch (params_rate(params)) {
|
||||
case 8000:
|
||||
case 16000:
|
||||
case 24000:
|
||||
case 32000:
|
||||
case 48000:
|
||||
case 64000:
|
||||
case 96000:
|
||||
mclk = 12288000;
|
||||
break;
|
||||
case 11025:
|
||||
case 22050:
|
||||
case 44100:
|
||||
case 88200:
|
||||
mclk = 11289600;
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/*Set the system clk for codec*/
|
||||
snd_soc_dai_set_pll(codec_dai, 0, RT5651_PLL1_S_MCLK, mclk, 24576000);
|
||||
|
||||
ret = snd_soc_dai_set_sysclk(codec_dai, RT5651_SCLK_S_PLL1, 24576000,
|
||||
SND_SOC_CLOCK_IN);
|
||||
if (ret < 0) {
|
||||
dev_err(codec_dai->dev, "Can't set codec clock in %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct snd_soc_ops rockchip_sound_rt5651_hifi_ops = {
|
||||
.hw_params = rockchip_rt5651_hw_params,
|
||||
};
|
||||
|
||||
static struct snd_soc_ops rockchip_sound_rt5651_voice_ops = {
|
||||
.hw_params = rockchip_rt5651_voice_hw_params,
|
||||
};
|
||||
|
||||
enum {
|
||||
DAILINK_RT5651_HIFI,
|
||||
DAILINK_RT5651_VOICE,
|
||||
DAILINK_RK628_HDMIIN,
|
||||
};
|
||||
|
||||
#define DAILINK_ENTITIES (DAILINK_RK628_HDMIIN + 1)
|
||||
|
||||
static struct snd_soc_dai_link rockchip_dailinks[] = {
|
||||
[DAILINK_RT5651_HIFI] = {
|
||||
.name = "RT5651 HIFI",
|
||||
.stream_name = "RT5651 PCM",
|
||||
.codec_dai_name = "rt5651-aif1",
|
||||
.ops = &rockchip_sound_rt5651_hifi_ops,
|
||||
/* set rt5651 as slave */
|
||||
.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
|
||||
SND_SOC_DAIFMT_CBS_CFS,
|
||||
},
|
||||
[DAILINK_RT5651_VOICE] = {
|
||||
.name = "RT5651 HDMIIN",
|
||||
.stream_name = "RT5651 PCM",
|
||||
.codec_dai_name = "rt5651-aif2",
|
||||
.ops = &rockchip_sound_rt5651_voice_ops,
|
||||
/* set rt5651 as slave */
|
||||
.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
|
||||
SND_SOC_DAIFMT_CBS_CFS,
|
||||
},
|
||||
[DAILINK_RK628_HDMIIN] = {
|
||||
.name = "RK628 HDMIIN",
|
||||
.stream_name = "RK628 PCM",
|
||||
.codec_dai_name = "rk628-audio",
|
||||
},
|
||||
};
|
||||
|
||||
static struct snd_soc_card rockchip_sound_card = {
|
||||
.name = "realtekrt5651codec_hdmiin",
|
||||
.owner = THIS_MODULE,
|
||||
.dai_link = rockchip_dailinks,
|
||||
.num_links = ARRAY_SIZE(rockchip_dailinks),
|
||||
.dapm_widgets = rockchip_dapm_widgets,
|
||||
.num_dapm_widgets = ARRAY_SIZE(rockchip_dapm_widgets),
|
||||
.dapm_routes = rockchip_dapm_routes,
|
||||
.num_dapm_routes = ARRAY_SIZE(rockchip_dapm_routes),
|
||||
.controls = rockchip_controls,
|
||||
.num_controls = ARRAY_SIZE(rockchip_controls),
|
||||
};
|
||||
|
||||
static int rockchip_sound_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct snd_soc_card *card = &rockchip_sound_card;
|
||||
struct device_node *cpu_node;
|
||||
int i, ret;
|
||||
|
||||
dev_info(&pdev->dev, "%s\n", __func__);
|
||||
|
||||
cpu_node = of_parse_phandle(pdev->dev.of_node, "rockchip,cpu", 0);
|
||||
if (!cpu_node) {
|
||||
dev_err(&pdev->dev,
|
||||
"Property 'rockchip,cpu' failed\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
for (i = 0; i < DAILINK_ENTITIES; i++) {
|
||||
rockchip_dailinks[i].platform_of_node = cpu_node;
|
||||
rockchip_dailinks[i].cpu_of_node = cpu_node;
|
||||
|
||||
rockchip_dailinks[i].codec_of_node =
|
||||
of_parse_phandle(pdev->dev.of_node,
|
||||
"rockchip,codec", i);
|
||||
if (!rockchip_dailinks[i].codec_of_node) {
|
||||
card->num_links = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
card->dev = &pdev->dev;
|
||||
platform_set_drvdata(pdev, card);
|
||||
ret = devm_snd_soc_register_card(&pdev->dev, card);
|
||||
if (ret)
|
||||
dev_err(&pdev->dev, "%s register card failed %d\n",
|
||||
__func__, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const struct of_device_id rockchip_sound_of_match[] = {
|
||||
{ .compatible = "rockchip,rockchip-rt5651-rk628-sound", },
|
||||
{},
|
||||
};
|
||||
|
||||
static struct platform_driver rockchip_sound_driver = {
|
||||
.probe = rockchip_sound_probe,
|
||||
.driver = {
|
||||
.name = DRV_NAME,
|
||||
.of_match_table = rockchip_sound_of_match,
|
||||
#ifdef CONFIG_PM
|
||||
.pm = &snd_soc_pm_ops,
|
||||
#endif
|
||||
},
|
||||
};
|
||||
|
||||
module_platform_driver(rockchip_sound_driver);
|
||||
|
||||
MODULE_AUTHOR("binyuan <kevan.lan@rock-chips.com>");
|
||||
MODULE_DESCRIPTION("Rockchip ASoC Machine Driver");
|
||||
MODULE_LICENSE("GPL v2");
|
||||
MODULE_ALIAS("platform:" DRV_NAME);
|
||||
MODULE_DEVICE_TABLE(of, rockchip_sound_of_match);
|
||||
Reference in New Issue
Block a user