Загрузка данных
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/slab.h>
#include <linux/gpio/consumer.h>
#include <linux/of_device.h>
#include <sound/core.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <sound/soc.h>
#include <sound/initval.h>
#include <linux/version.h>
#define TFA9882_RATES SNDRV_PCM_RATE_8000_192000
#define TFA9882_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE |\
SNDRV_PCM_FMTBIT_S32_LE)
/* codec private data */
struct tfa9882_priv {
struct gpio_desc *mute;
int sysclk;
int sai_num;
};
static const struct snd_soc_dapm_widget tfa9882_dapm_widgets[] = {
SND_SOC_DAPM_DAC("DAC", "Playback", SND_SOC_NOPM, 0, 0),
SND_SOC_DAPM_OUTPUT("LINEVOUTL"),
SND_SOC_DAPM_OUTPUT("LINEVOUTR"),
};
static const struct snd_soc_dapm_route tfa9882_dapm_routes[] = {
{ "LINEVOUTL", NULL, "DAC" },
{ "LINEVOUTR", NULL, "DAC" },
};
static int tfa9882_startup(struct snd_pcm_substream *substream,
struct snd_soc_dai *dai)
{
struct snd_pcm_runtime *runtime = substream->runtime;
static struct snd_pcm_hw_constraint_list constraint_rates;
int ret;
static u32 support_rates[] = {8000, 32000, 44100, 48000, 88200, 96000, 176400, 192000};
constraint_rates.list = support_rates;
constraint_rates.count = ARRAY_SIZE(support_rates);
ret = snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &constraint_rates);
if (ret)
return ret;
return 0;
}
static void tfa9882_shutdown(struct snd_pcm_substream *substream,
struct snd_soc_dai *dai)
{
}
int sai_try_set_mclk_rate(int sai_num, unsigned int freq);
static int tfa9882_pcm_hw_params(struct snd_pcm_substream *sub_stream,
struct snd_pcm_hw_params *params, struct snd_soc_dai *codec_dai)
{
struct snd_soc_component *component = codec_dai->component;
struct tfa9882_priv *tfa9882 = snd_soc_component_get_drvdata(component);
return 0;
}
static int tfa9882_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
{
fmt &= (SND_SOC_DAIFMT_FORMAT_MASK | SND_SOC_DAIFMT_INV_MASK |
SND_SOC_DAIFMT_MASTER_MASK);
if (fmt != (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
SND_SOC_DAIFMT_CBS_CFS)) {
dev_err(codec_dai->dev, "Invalid DAI format\n");
return -EINVAL;
}
return 0;
}
static const struct snd_soc_dai_ops tfa9882_dai_ops = {
.startup = tfa9882_startup,
.shutdown = tfa9882_shutdown,
.hw_params = tfa9882_pcm_hw_params,
.set_fmt = tfa9882_set_fmt,
};
static struct snd_soc_dai_driver tfa9882_dai = {
.name = "tfa9882-hifi",
.playback = {
.stream_name = "Playback",
.channels_min = 2,
.channels_max = 2,
.rates = TFA9882_RATES,
.formats = TFA9882_FORMATS,
},
.ops = &tfa9882_dai_ops,
};
static int tfa9882_probe(struct snd_soc_component *component)
{
#ifdef MY_CODE
struct tfa9882_priv *tfa9882 = snd_soc_component_get_drvdata(component);
#endif
return 0;
}
static const struct snd_soc_component_driver soc_component_dev_tfa9882 = {
.probe = tfa9882_probe,
.dapm_widgets = tfa9882_dapm_widgets,
.num_dapm_widgets = ARRAY_SIZE(tfa9882_dapm_widgets),
.dapm_routes = tfa9882_dapm_routes,
.num_dapm_routes = ARRAY_SIZE(tfa9882_dapm_routes),
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 154)
.idle_bias_on = 1,
.use_pmdown_time = 1,
.endianness = 1,
.legacy_dai_naming = 1,
#endif
};
static const struct of_device_id tfa9882_of_match[] = {
{ .compatible = "fsl,tfa9882" },
{ /* sentinel*/ }
};
MODULE_DEVICE_TABLE(of, tfa9882_of_match);
static int tfa9882_codec_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct tfa9882_priv *tfa9882;
int ret;
tfa9882 = devm_kzalloc(&pdev->dev, sizeof(struct tfa9882_priv),
GFP_KERNEL);
if (tfa9882 == NULL)
return -ENOMEM;
platform_set_drvdata(pdev, tfa9882);
ret = devm_snd_soc_register_component(&pdev->dev,
&soc_component_dev_tfa9882, &tfa9882_dai, 1);
if (ret < 0)
dev_err(&pdev->dev, "Failed to register component: %d\n", ret);
return ret;
}
static struct platform_driver tfa9882_codec_driver = {
.probe = tfa9882_codec_probe,
.driver = {
.name = "tfa9882-codec",
.of_match_table = tfa9882_of_match,
},
};
module_platform_driver(tfa9882_codec_driver);
MODULE_DESCRIPTION("ASoC tfa9882 driver");
MODULE_AUTHOR("Vissa");
MODULE_ALIAS("platform:tfa9882-codec");
MODULE_LICENSE("GPL");
Может создать свой простой codec? и указать его в качестве кодека для simple-audio-card?
tfa9882hf: tfa9882hf {
#sound-dai-cells = <0>;
compatible = "fsl,tfa9882";
sai-num = <1>;
sys-clk = <24576000>;
};
sound-tfa9882-hf {
compatible = "simple-audio-card";
simple-audio-card,name = "tfa9882-audio-hf";
simple-audio-card,format = "i2s";
simple-audio-card,frame-master = <&cpudaihf>;
simple-audio-card,bitclock-master = <&cpudaihf>;
simple-audio-card,widgets =
"Line", "Left Line Out Jack",
"Line", "Right Line Out Jack";
simple-audio-card,routing =
"Left Line Out Jack", "LINEVOUTL",
"Right Line Out Jack", "LINEVOUTR";
cpudaihf: simple-audio-card,cpu {
sound-dai = <&sai1>;
dai-tdm-slot-num = <2>;
dai-tdm-slot-width = <32>;
};
simple-audio-card,codec {
sound-dai = <&tfa9882hf>;
};
};
у меня используется аудио плата NS4168