This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] TAS2505:已加载 Linux 驱动程序、但引脚上无信号

Guru**** 1744610 points
Other Parts Discussed in Thread: TAS2505
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/audio-group/audio/f/audio-forum/1137086/tas2505-linux-driver-loaded-but-no-signals-on-pins

器件型号:TAS2505
大家好、我正在为 BeagleBone Black 和 Linux 开发应用、我需要将 BBB 连接到 TAS2505。 
那么、这就是我到目前为止拥有的内容:

> Linux 4.19.129使用 Yocto 构建
> Tas2505驱动程序从这里删除: TI-tas2505-driver
>修复了上述驱动程序中的错误:
>tas2505.c 第37行:#if kernel_version (5、9、0)<= linux_version_code

>在内核 kconfig 和 Makefile 中修补了驱动程序(请参见随附的)
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index efb095d..0da26ea 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -158,6 +158,7 @@ config SND_SOC_ALL_CODECS
 	select SND_SOC_STAC9766 if SND_SOC_AC97_BUS
 	select SND_SOC_STI_SAS
 	select SND_SOC_TAS2552 if I2C
+        select SND_SOC_TAS2505 if I2C
 	select SND_SOC_TAS5086 if I2C
 	select SND_SOC_TAS571X if I2C
 	select SND_SOC_TAS5720 if I2C
@@ -958,6 +959,10 @@ config SND_SOC_TAS2552
 	tristate "Texas Instruments TAS2552 Mono Audio amplifier"
 	depends on I2C
 
+config SND_SOC_TAS2505
+        tristate "Texas Instruments TAS2505 Mono Audio Amplifier for Automac"
+        depends on I2C
+
 config SND_SOC_TAS5086
 	tristate "Texas Instruments TAS5086 speaker amplifier"
 	depends on I2C
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index 7ae7c85..e8d0d34 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -256,6 +256,7 @@ snd-soc-max98504-objs := max98504.o
 snd-soc-simple-amplifier-objs := simple-amplifier.o
 snd-soc-tpa6130a2-objs := tpa6130a2.o
 snd-soc-tas2552-objs := tas2552.o
+snd-soc-tas2505-objs := tas2505.o
 
 obj-$(CONFIG_SND_SOC_88PM860X)	+= snd-soc-88pm860x.o
 obj-$(CONFIG_SND_SOC_AB8500_CODEC)	+= snd-soc-ab8500-codec.o
@@ -428,6 +429,7 @@ obj-$(CONFIG_SND_SOC_STA529)   += snd-soc-sta529.o
 obj-$(CONFIG_SND_SOC_STAC9766)	+= snd-soc-stac9766.o
 obj-$(CONFIG_SND_SOC_STI_SAS)	+= snd-soc-sti-sas.o
 obj-$(CONFIG_SND_SOC_TAS2552)	+= snd-soc-tas2552.o
+obj-$(CONFIG_SND_SOC_TAS2505)   += snd-soc-tas2505.o
 obj-$(CONFIG_SND_SOC_TAS5086)	+= snd-soc-tas5086.o
 obj-$(CONFIG_SND_SOC_TAS571X)	+= snd-soc-tas571x.o
 obj-$(CONFIG_SND_SOC_TAS5720)	+= snd-soc-tas5720.o
diff --git a/sound/soc/codecs/tas2505.c b/sound/soc/codecs/tas2505.c
new file mode 100644
index 0000000..20437b6
--- /dev/null
+++ b/sound/soc/codecs/tas2505.c
@@ -0,0 +1,857 @@
+/*
+ * ALSA SoC TAS2505 codec driver
+ *
+ * Author: Hieu Tran Dang <dangtranhieu2012@gmail.com>
+ *
+ * This package is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * THIS PACKAGE IS PROVIDED AS IS AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+/*
+ * Modificado por Fede 22/9/2022
+*/
+#include <linux/version.h>
+#include <linux/module.h>
+#include <linux/i2c.h>
+#include <linux/clk.h>
+#include <linux/of.h>
+#include <linux/of_gpio.h>
+#include <sound/soc.h>
+#include <sound/tlv.h>
+#include <sound/pcm_params.h>
+#include "tas2505.h"
+
+static int tas2505_spkdrv_getvol(struct snd_kcontrol *kcontrol,
+	struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_soc_component *component =
+		snd_soc_kcontrol_component(kcontrol);
+	struct soc_mixer_control *mc =
+		(struct soc_mixer_control *)kcontrol->private_value;
+	unsigned int val;
+#if KERNEL_VERSION(5, 9, 0) <= LINUX_VERSION_CODE
+	val = snd_soc_component_read(component, TAS2505_SPKVOL1);
+#else
+	snd_soc_component_read(component, TAS2505_SPKVOL1, &val);
+#endif
+	val = (val > mc->max) ? mc->max : val;
+	val = mc->invert ? mc->max - val : val;
+	ucontrol->value.integer.value[0] = val;
+
+	return 0;
+}
+
+static int tas2505_spkdrv_putvol(struct snd_kcontrol *kcontrol,
+	struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_soc_component *component =
+		snd_soc_kcontrol_component(kcontrol);
+	struct soc_mixer_control *mc =
+		(struct soc_mixer_control *)kcontrol->private_value;
+	u8 val;
+
+	val = (ucontrol->value.integer.value[0] & 0x7f);
+	val = mc->invert ? mc->max - val : val;
+	val = (val < 0) ? 0 : val;
+	snd_soc_component_write(component, TAS2505_SPKVOL1, val);
+
+	return 0;
+}
+
+static const DECLARE_TLV_DB_SCALE(dac_vol_tlv, -6350, 50, 0);
+static const DECLARE_TLV_DB_LINEAR(spk_drv_vol_tlv, TLV_DB_GAIN_MUTE, 0);
+static const DECLARE_TLV_DB_SCALE(spk_amp_vol_tlv, 0, 600, 1);
+
+static const struct snd_kcontrol_new tas2505_snd_controls[] = {
+	SOC_SINGLE_S8_TLV("DAC Playback Volume", TAS2505_DACVOL,
+		-127, 48, dac_vol_tlv),
+	SOC_SINGLE_RANGE_EXT_TLV("Speaker Driver Volume", TAS2505_SPKVOL1,
+		0, 0, 117, 1,
+		tas2505_spkdrv_getvol, tas2505_spkdrv_putvol, spk_drv_vol_tlv),
+	SOC_SINGLE_TLV("Speaker Amplifer Volume", TAS2505_SPKVOL2,
+		4, 5, 0, spk_amp_vol_tlv),
+};
+
+static const struct snd_soc_dapm_widget tas2505_dapm_widgets[] = {
+	SND_SOC_DAPM_DAC("DAC Channel", "Playback",
+		TAS2505_DACSETUP1, 7, 0),
+	SND_SOC_DAPM_OUT_DRV("Speaker Driver", TAS2505_SPKAMPCTRL1,
+		1, 0, NULL, 0),
+	SND_SOC_DAPM_OUTPUT("Speaker"),
+};
+
+static const struct snd_soc_dapm_route tas2505_audio_map[] = {
+	{ "Speaker Driver", NULL, "DAC Channel" },
+	{ "Speaker", NULL, "Speaker Driver" },
+};
+
+static const struct reg_default tas2505_reg_defaults[] = {
+	{ TAS2505_CLKMUX, 0x00 },
+	{ TAS2505_PLLPR, 0x11 },
+	{ TAS2505_PLLJ, 0x04 },
+	{ TAS2505_PLLDMSB, 0x00 },
+	{ TAS2505_PLLDLSB, 0x00 },
+	{ TAS2505_NDAC, 0x01 },
+	{ TAS2505_MDAC, 0x01 },
+	{ TAS2505_DOSRMSB, 0x00 },
+	{ TAS2505_DOSRLSB, 0x80 },
+	{ TAS2505_IFACE1, 0x00 },
+	{ TAS2505_IFACE3, 0x00 },
+	{ TAS2505_DACSETUP1, 0x14 },
+	{ TAS2505_DACSETUP2, 0x0c },
+	{ TAS2505_DACVOL, 0x00 },
+	{ TAS2505_REF_POR_LDO_BGAP_CTRL, 0x00 },
+	{ TAS2505_LDO_CTRL, 0x0c },
+	{ TAS2505_SPKAMPCTRL1, 0x00 },
+	{ TAS2505_SPKVOL1, 0x00 },
+	{ TAS2505_SPKVOL2, 0x00 },
+	{ TAS2505_DACFLAG1, 0x00 },
+	{ TAS2505_DACFLAG2, 0x00 },
+	{ TAS2505_STICKYFLAG1, 0x00 },
+	{ TAS2505_STICKYFLAG2, 0x00 },
+	{ TAS2505_INTFLAG1, 0x00 },
+	{ TAS2505_INTFLAG2, 0x00 },
+	{ TAS2505_DACANLGAINFLAG, 0x00 },
+};
+
+static bool tas2505_volatile(struct device *dev, unsigned int reg)
+{
+	switch (reg) {
+		case TAS2505_PAGECTL:
+		case TAS2505_RESET:
+		case TAS2505_DACFLAG1:
+		case TAS2505_DACFLAG2:
+		case TAS2505_STICKYFLAG1:
+		case TAS2505_STICKYFLAG2:
+		case TAS2505_INTFLAG1:
+		case TAS2505_INTFLAG2:
+		case TAS2505_DACANLGAINFLAG:
+			return true;
+	}
+	return false;
+}
+
+static bool tas2505_writeable(struct device *dev, unsigned int reg)
+{
+	switch (reg) {
+		case TAS2505_DACFLAG1:
+		case TAS2505_DACFLAG2:
+		case TAS2505_STICKYFLAG1:
+		case TAS2505_STICKYFLAG2:
+		case TAS2505_INTFLAG1:
+		case TAS2505_INTFLAG2:
+		case TAS2505_DACANLGAINFLAG:
+			return false;
+	}
+	return true;
+}
+
+static const struct regmap_range_cfg tas2505_ranges[] = {
+	{
+		.range_min = 0,
+		.range_max = 69 * 128,
+		.selector_reg = TAS2505_PAGECTL,
+		.selector_mask = 0xff,
+		.selector_shift = 0,
+		.window_start = 0,
+		.window_len = 128,
+	},
+};
+
+static const struct regmap_config tas2505_i2c_regmap = {
+	.reg_bits = 8,
+	.val_bits = 8,
+	.writeable_reg = tas2505_writeable,
+	.volatile_reg = tas2505_volatile,
+	.reg_defaults = tas2505_reg_defaults,
+	.num_reg_defaults = ARRAY_SIZE(tas2505_reg_defaults),
+	.cache_type = REGCACHE_RBTREE,
+	.ranges = tas2505_ranges,
+	.num_ranges = ARRAY_SIZE(tas2505_ranges),
+	.max_register = 69 * 128,
+};
+
+struct tas2505_rate_divs {
+	u32 mclk_p;
+	u32 rate;
+	u8 pll_r;
+	u8 pll_j;
+	u16 pll_d;
+	u8 mdac;
+	u8 ndac;
+	u16 dosr;
+};
+
+static const struct tas2505_rate_divs tas2505_divs[] = {
+	{ 12288000, 44100, 1, 7, 35, 4, 4, 128 },
+	{ 12288000, 48000, 1, 7, 0, 7, 2, 128 },
+};
+
+struct tas2505_priv {
+	void *codec;
+	struct device *dev;
+	struct regmap *regmap;
+	u32 sysclk;
+	u8 p_div;
+	int rate_div_line;
+};
+
+#if KERNEL_VERSION(4, 19, 0) <= LINUX_VERSION_CODE
+static int tas2505_setup_pll(struct snd_soc_component *codec,
+	struct snd_pcm_hw_params *params)
+{
+	struct tas2505_priv *tas2505 = snd_soc_component_get_drvdata(codec);
+	int mclk_p = tas2505->sysclk / tas2505->p_div;
+	int match = -1;
+	u8 p_div;
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(tas2505_divs); i++) {
+		if (
+			tas2505_divs[i].rate == params_rate(params) &&
+			tas2505_divs[i].mclk_p == mclk_p
+		) {
+			match = i;
+			break;
+		}
+	}
+
+	if (match == -1) {
+		dev_err(codec->dev,
+			"Sample rate (%u), sysclk (%u), div (%u) and format not supported\n",
+			params_rate(params), tas2505->sysclk, tas2505->p_div);
+		return -EINVAL;
+	}
+
+	tas2505->rate_div_line = match;
+
+	p_div = (tas2505->p_div == 8) ? 0 : tas2505->p_div;
+	p_div <<= TAS2505_PLLPR_P_SHIFT;
+
+	snd_soc_component_update_bits(codec, TAS2505_PLLPR, TAS2505_PLLPR_P_MASK,
+		p_div);
+	snd_soc_component_update_bits(codec, TAS2505_PLLPR, TAS2505_PLLPR_R_MASK,
+		tas2505_divs[match].pll_r);
+	snd_soc_component_write(codec, TAS2505_PLLJ, tas2505_divs[match].pll_j);
+	snd_soc_component_write(codec, TAS2505_PLLDMSB, tas2505_divs[match].pll_d >> 8);
+	snd_soc_component_write(codec, TAS2505_PLLDLSB, tas2505_divs[match].pll_d & 0xff);
+	snd_soc_component_update_bits(codec, TAS2505_NDAC, TAS2505_PLL_DAC_MASK,
+		tas2505_divs[match].ndac);
+	snd_soc_component_update_bits(codec, TAS2505_MDAC, TAS2505_PLL_DAC_MASK,
+		tas2505_divs[match].mdac);
+	snd_soc_component_write(codec, TAS2505_DOSRMSB, tas2505_divs[match].dosr >> 8);
+	snd_soc_component_write(codec, TAS2505_DOSRLSB, tas2505_divs[match].dosr & 0xff);
+	snd_soc_component_update_bits(codec, TAS2505_BCLKNDIV, TAS2505_BCLKNDIV_MASK,
+		(tas2505_divs[match].dosr * tas2505_divs[match].mdac) / snd_soc_params_to_frame_size(params));
+
+	return 0;
+}
+
+static int tas2505_hw_params(struct snd_pcm_substream *substream,
+	struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
+{
+	struct snd_soc_component *codec = dai->component;
+	u8 data = 0;
+
+	switch (params_width(params)) {
+		case 16:
+			break;
+
+		case 20:
+			data = TAS2505_WORD_LEN_20BITS;
+			break;
+
+		case 24:
+			data = TAS2505_WORD_LEN_24BITS;
+			break;
+
+		case 32:
+			data = TAS2505_WORD_LEN_32BITS;
+			break;
+
+		default:
+			dev_err(codec->dev, "Unsupported width %d\n",
+				params_width(params));
+			return -EINVAL;
+	}
+
+	data <<= TAS2505_IFACE1_DATALEN_SHIFT;
+
+	snd_soc_component_update_bits(codec, TAS2505_IFACE1,
+		TAS2505_IFACE1_DATALEN_MASK, data);
+
+	return tas2505_setup_pll(codec, params);
+}
+
+static int tas2505_dac_mute(struct snd_soc_dai *dai, int mute, int stream)
+{
+	struct snd_soc_component *codec = dai->component;
+
+	if (mute) {
+		snd_soc_component_update_bits(codec, TAS2505_DACSETUP2,
+			TAS2505_DACSETUP2_MUTE_MASK,
+			TAS2505_DACSETUP2_MUTE_MASK);
+	} else {
+		snd_soc_component_update_bits(codec, TAS2505_DACSETUP2,
+			TAS2505_DACSETUP2_MUTE_MASK, 0x0);
+	}
+
+	return 0;
+}
+
+static int tas2505_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
+{
+	struct snd_soc_component *codec = codec_dai->component;
+	u8 iface_reg1 = 0;
+	u8 iface_reg3 = 0;
+
+	switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
+		case SND_SOC_DAIFMT_CBS_CFS:
+			break;
+
+		case SND_SOC_DAIFMT_CBM_CFM:
+			iface_reg1 |= TAS2505_IFACE1_BCLKDIR_MASK;
+			iface_reg1 |= TAS2505_IFACE1_WCLKDIR_MASK;
+			break;
+
+		default:
+			return -EINVAL;
+	}
+
+	switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
+		case SND_SOC_DAIFMT_NB_NF:
+			break;
+
+		case SND_SOC_DAIFMT_IB_NF:
+			iface_reg3 |= TAS2505_IFACE3_BCLKINV_MASK;
+			break;
+
+		default:
+			return -EINVAL;
+	}
+
+	switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
+		case SND_SOC_DAIFMT_I2S:
+			break;
+
+		case SND_SOC_DAIFMT_DSP_A:
+		case SND_SOC_DAIFMT_DSP_B:
+			iface_reg1 |= (TAS2505_DSP_MODE <<
+				TAS2505_IFACE1_INTERFACE_SHIFT);
+			break;
+
+		case SND_SOC_DAIFMT_RIGHT_J:
+			iface_reg1 |= (TAS2505_RJF_MODE <<
+				TAS2505_IFACE1_INTERFACE_SHIFT);
+			break;
+
+		case SND_SOC_DAIFMT_LEFT_J:
+			iface_reg1 |= (TAS2505_LJF_MODE <<
+				TAS2505_IFACE1_INTERFACE_SHIFT);
+			break;
+
+		default:
+			dev_err(codec->dev, "Invalid DAI interface format\n");
+			return -EINVAL;
+	}
+
+	snd_soc_component_write(codec, TAS2505_IFACE1, iface_reg1);
+	snd_soc_component_update_bits(codec, TAS2505_IFACE3,
+		TAS2505_IFACE3_BCLKINV_MASK | TAS2505_IFACE3_BDIVCLKIN_MASK,
+		iface_reg3);
+
+	return 0;
+}
+
+static int tas2505_set_dai_sysclk(struct snd_soc_dai *codec_dai, int clk_id,
+	unsigned int freq, int dir)
+{
+	struct snd_soc_component *codec = codec_dai->component;
+	struct tas2505_priv *tas2505 = snd_soc_component_get_drvdata(codec);
+	int i, x;
+
+	dev_dbg(tas2505->dev, "clk_id: %d, freq: %d\n", clk_id, freq);
+
+	for (i = 0; i < ARRAY_SIZE(tas2505_divs); i++) {
+		for (x = 1; x < 9; x++) {
+			if ((freq / x) == tas2505_divs[i].mclk_p) {
+				tas2505->p_div = x;
+				goto found_p_div;
+			}
+		}
+	}
+
+	dev_err(tas2505->dev, "Can't produce required PLL_CLKIN frequency\n");
+	return -EINVAL;
+
+found_p_div:
+	snd_soc_component_write(codec, TAS2505_CLKMUX,
+		(clk_id << TAS2505_PLL_CLKIN_SHIFT) | TAS2505_CODEC_CLKIN_PLL);
+
+	tas2505->sysclk = freq;
+
+	return 0;
+}
+
+static void tas2505_clk_on(struct snd_soc_component *codec)
+{
+	u8 mask = TAS2505_PM_MASK;
+	u8 on = TAS2505_PM_MASK;
+
+	snd_soc_component_update_bits(codec, TAS2505_PLLPR, mask, on);
+	mdelay(15);
+	snd_soc_component_update_bits(codec, TAS2505_NDAC, mask, on);
+	snd_soc_component_update_bits(codec, TAS2505_MDAC, mask, on);
+	snd_soc_component_update_bits(codec, TAS2505_BCLKNDIV, mask, on);
+}
+
+static void tas2505_clk_off(struct snd_soc_component *codec)
+{
+	u8 mask = TAS2505_PM_MASK;
+
+	snd_soc_component_update_bits(codec, TAS2505_BCLKNDIV, mask, 0);
+	snd_soc_component_update_bits(codec, TAS2505_MDAC, mask, 0);
+	snd_soc_component_update_bits(codec, TAS2505_NDAC, mask, 0);
+	snd_soc_component_update_bits(codec, TAS2505_PLLPR, mask, 0);
+}
+
+static void tas2505_power_on(struct snd_soc_component *codec)
+{
+	snd_soc_component_write(codec, TAS2505_RESET, 1);
+	usleep_range(500, 1000);
+	snd_soc_component_update_bits(codec, TAS2505_LDO_CTRL,
+		TAS2505_LDO_PLL_HP_LVL_MASK, 0);
+	snd_soc_component_update_bits(codec, TAS2505_REF_POR_LDO_BGAP_CTRL,
+		TAS2505_REF_POR_LDO_BGAP_MASTER_REF_MASK,
+		TAS2505_REF_POR_LDO_BGAP_MASTER_REF_MASK);
+}
+
+static void tas2505_power_off(struct snd_soc_component *codec)
+{
+	snd_soc_component_update_bits(codec, TAS2505_REF_POR_LDO_BGAP_CTRL,
+		TAS2505_REF_POR_LDO_BGAP_MASTER_REF_MASK, 0);
+	snd_soc_component_update_bits(codec, TAS2505_LDO_CTRL,
+		TAS2505_LDO_PLL_HP_LVL_MASK,
+		TAS2505_LDO_PLL_HP_LVL_MASK);
+}
+#else
+static int tas2505_setup_pll(struct snd_soc_codec *codec,
+	struct snd_pcm_hw_params *params)
+{
+	struct tas2505_priv *tas2505 = snd_soc_codec_get_drvdata(codec);
+	int mclk_p = tas2505->sysclk / tas2505->p_div;
+	int match = -1;
+	u8 p_div;
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(tas2505_divs); i++) {
+		if (
+			tas2505_divs[i].rate == params_rate(params) &&
+			tas2505_divs[i].mclk_p == mclk_p
+		) {
+			match = i;
+			break;
+		}
+	}
+
+	if (match == -1) {
+		dev_err(codec->dev,
+			"Sample rate (%u) and format not supported\n",
+			params_rate(params));
+		return -EINVAL;
+	}
+
+	tas2505->rate_div_line = match;
+
+	p_div = (tas2505->p_div == 8) ? 0 : tas2505->p_div;
+	p_div <<= TAS2505_PLLPR_P_SHIFT;
+
+	snd_soc_update_bits(codec, TAS2505_PLLPR, TAS2505_PLLPR_P_MASK,
+		p_div);
+	snd_soc_update_bits(codec, TAS2505_PLLPR, TAS2505_PLLPR_R_MASK,
+		tas2505_divs[match].pll_r);
+	snd_soc_write(codec, TAS2505_PLLJ, tas2505_divs[match].pll_j);
+	snd_soc_write(codec, TAS2505_PLLDMSB, tas2505_divs[match].pll_d >> 8);
+	snd_soc_write(codec, TAS2505_PLLDLSB, tas2505_divs[match].pll_d & 0xff);
+	snd_soc_update_bits(codec, TAS2505_NDAC, TAS2505_PLL_DAC_MASK,
+		tas2505_divs[match].ndac);
+	snd_soc_update_bits(codec, TAS2505_MDAC, TAS2505_PLL_DAC_MASK,
+		tas2505_divs[match].mdac);
+	snd_soc_write(codec, TAS2505_DOSRMSB, tas2505_divs[match].dosr >> 8);
+	snd_soc_write(codec, TAS2505_DOSRLSB, tas2505_divs[match].dosr & 0xff);
+	snd_soc_update_bits(codec, TAS2505_BCLKNDIV, TAS2505_BCLKNDIV_MASK,
+		(tas2505_divs[match].dosr * tas2505_divs[match].mdac) / snd_soc_params_to_frame_size(params));
+
+	return 0;
+}
+
+static int tas2505_hw_params(struct snd_pcm_substream *substream,
+	struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
+{
+	struct snd_soc_codec *codec = dai->codec;
+	u8 data = 0;
+
+	switch (params_width(params)) {
+		case 16:
+			break;
+
+		case 20:
+			data = TAS2505_WORD_LEN_20BITS;
+			break;
+
+		case 24:
+			data = TAS2505_WORD_LEN_24BITS;
+			break;
+
+		case 32:
+			data = TAS2505_WORD_LEN_32BITS;
+			break;
+
+		default:
+			dev_err(codec->dev, "Unsupported width %d\n",
+				params_width(params));
+			return -EINVAL;
+	}
+
+	data <<= TAS2505_IFACE1_DATALEN_SHIFT;
+
+	snd_soc_update_bits(codec, TAS2505_IFACE1,
+		TAS2505_IFACE1_DATALEN_MASK, data);
+
+	return tas2505_setup_pll(codec, params);
+}
+
+static int tas2505_dac_mute(struct snd_soc_dai *codec_dai, int mute, int stream)
+{
+	struct snd_soc_codec *codec = codec_dai->codec;
+
+	if (mute) {
+		snd_soc_update_bits(codec, TAS2505_DACSETUP2,
+			TAS2505_DACSETUP2_MUTE_MASK,
+			TAS2505_DACSETUP2_MUTE_MASK);
+	} else {
+		snd_soc_update_bits(codec, TAS2505_DACSETUP2,
+			TAS2505_DACSETUP2_MUTE_MASK, 0x0);
+	}
+
+	return 0;
+}
+
+static int tas2505_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
+{
+	struct snd_soc_codec *codec = codec_dai->codec;
+	u8 iface_reg1 = 0;
+	u8 iface_reg3 = 0;
+
+	switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
+		case SND_SOC_DAIFMT_CBS_CFS:
+			break;
+
+		case SND_SOC_DAIFMT_CBM_CFM:
+			iface_reg1 |= TAS2505_IFACE1_BCLKDIR_MASK;
+			iface_reg1 |= TAS2505_IFACE1_WCLKDIR_MASK;
+			break;
+
+		default:
+			return -EINVAL;
+	}
+
+	switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
+		case SND_SOC_DAIFMT_NB_NF:
+			break;
+
+		case SND_SOC_DAIFMT_IB_NF:
+			iface_reg3 |= TAS2505_IFACE3_BCLKINV_MASK;
+			break;
+
+		default:
+			return -EINVAL;
+	}
+
+	switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
+		case SND_SOC_DAIFMT_I2S:
+			break;
+
+		case SND_SOC_DAIFMT_DSP_A:
+		case SND_SOC_DAIFMT_DSP_B:
+			iface_reg1 |= (TAS2505_DSP_MODE <<
+				TAS2505_IFACE1_INTERFACE_SHIFT);
+			break;
+
+		case SND_SOC_DAIFMT_RIGHT_J:
+			iface_reg1 |= (TAS2505_RJF_MODE <<
+				TAS2505_IFACE1_INTERFACE_SHIFT);
+			break;
+
+		case SND_SOC_DAIFMT_LEFT_J:
+			iface_reg1 |= (TAS2505_LJF_MODE <<
+				TAS2505_IFACE1_INTERFACE_SHIFT);
+			break;
+
+		default:
+			dev_err(codec->dev, "Invalid DAI interface format\n");
+			return -EINVAL;
+	}
+
+	snd_soc_write(codec, TAS2505_IFACE1, iface_reg1);
+	snd_soc_update_bits(codec, TAS2505_IFACE3,
+		TAS2505_IFACE3_BCLKINV_MASK | TAS2505_IFACE3_BDIVCLKIN_MASK,
+		iface_reg3);
+
+	return 0;
+}
+
+static int tas2505_set_dai_sysclk(struct snd_soc_dai *codec_dai, int clk_id,
+	unsigned int freq, int dir)
+{
+	struct snd_soc_codec *codec = codec_dai->codec;
+	struct tas2505_priv *tas2505 = snd_soc_codec_get_drvdata(codec);
+	int i, x;
+
+	dev_dbg(tas2505->dev, "clk_id: %d, freq: %d\n", clk_id, freq);
+
+	for (i = 0; i < ARRAY_SIZE(tas2505_divs); i++) {
+		for (x = 1; x < 9; x++) {
+			if ((freq / x) == tas2505_divs[i].mclk_p) {
+				tas2505->p_div = x;
+				goto found_p_div;
+			}
+		}
+	}
+
+	dev_err(tas2505->dev, "Can't produce required PLL_CLKIN frequency\n");
+	return -EINVAL;
+
+found_p_div:
+	snd_soc_write(codec, TAS2505_CLKMUX,
+		(clk_id << TAS2505_PLL_CLKIN_SHIFT) | TAS2505_CODEC_CLKIN_PLL);
+
+	tas2505->sysclk = freq;
+
+	return 0;
+}
+
+static void tas2505_clk_on(struct snd_soc_codec *codec)
+{
+	u8 mask = TAS2505_PM_MASK;
+	u8 on = TAS2505_PM_MASK;
+
+	snd_soc_update_bits(codec, TAS2505_PLLPR, mask, on);
+	mdelay(15);
+	snd_soc_update_bits(codec, TAS2505_NDAC, mask, on);
+	snd_soc_update_bits(codec, TAS2505_MDAC, mask, on);
+	snd_soc_update_bits(codec, TAS2505_BCLKNDIV, mask, on);
+}
+
+static void tas2505_clk_off(struct snd_soc_codec *codec)
+{
+	u8 mask = TAS2505_PM_MASK;
+
+	snd_soc_update_bits(codec, TAS2505_BCLKNDIV, mask, 0);
+	snd_soc_update_bits(codec, TAS2505_MDAC, mask, 0);
+	snd_soc_update_bits(codec, TAS2505_NDAC, mask, 0);
+	snd_soc_update_bits(codec, TAS2505_PLLPR, mask, 0);
+}
+
+static void tas2505_power_on(struct snd_soc_codec *codec)
+{
+	snd_soc_write(codec, TAS2505_RESET, 1);
+	usleep_range(500, 1000);
+	snd_soc_update_bits(codec, TAS2505_LDO_CTRL,
+		TAS2505_LDO_PLL_HP_LVL_MASK, 0);
+	snd_soc_update_bits(codec, TAS2505_REF_POR_LDO_BGAP_CTRL,
+		TAS2505_REF_POR_LDO_BGAP_MASTER_REF_MASK,
+		TAS2505_REF_POR_LDO_BGAP_MASTER_REF_MASK);
+}
+
+static void tas2505_power_off(struct snd_soc_codec *codec)
+{
+	snd_soc_update_bits(codec, TAS2505_REF_POR_LDO_BGAP_CTRL,
+		TAS2505_REF_POR_LDO_BGAP_MASTER_REF_MASK, 0);
+	snd_soc_update_bits(codec, TAS2505_LDO_CTRL,
+		TAS2505_LDO_PLL_HP_LVL_MASK,
+		TAS2505_LDO_PLL_HP_LVL_MASK);
+}
+#endif
+
+#if KERNEL_VERSION(4, 19, 0) <= LINUX_VERSION_CODE
+static int tas2505_set_bias_level(struct snd_soc_component *codec,
+	enum snd_soc_bias_level level)
+{
+	int current_lvl = snd_soc_component_get_bias_level(codec);
+#else
+static int tas2505_set_bias_level(struct snd_soc_codec *codec,
+	enum snd_soc_bias_level level)
+{
+	int current_lvl = snd_soc_codec_get_bias_level(codec);
+#endif
+	switch (level) {
+		case SND_SOC_BIAS_ON:
+			break;
+		case SND_SOC_BIAS_PREPARE:
+			if (current_lvl == SND_SOC_BIAS_STANDBY)
+				tas2505_clk_on(codec);
+			break;
+		case SND_SOC_BIAS_STANDBY:
+			if (current_lvl == SND_SOC_BIAS_OFF)
+				tas2505_power_on(codec);
+			else if (current_lvl == SND_SOC_BIAS_PREPARE)
+				tas2505_clk_off(codec);
+			else
+				BUG();
+			break;
+		case SND_SOC_BIAS_OFF:
+			if (current_lvl == SND_SOC_BIAS_STANDBY)
+				tas2505_power_off(codec);
+			break;
+		default:
+			dev_err(codec->dev, "Invalid bias level\n");
+			return -EINVAL;
+	}
+
+	return 0;
+}
+#if KERNEL_VERSION(4, 19, 0) <= LINUX_VERSION_CODE
+static int tas2505_codec_probe(struct snd_soc_component *codec)
+{
+	struct tas2505_priv *tas2505 = snd_soc_component_get_drvdata(codec);
+#else
+static int tas2505_codec_probe(struct snd_soc_codec *codec)
+{
+	struct tas2505_priv *tas2505 = snd_soc_codec_get_drvdata(codec);
+#endif
+	tas2505->codec = codec;
+	return 0;
+}
+
+#if KERNEL_VERSION(4, 19, 0) <= LINUX_VERSION_CODE
+static struct snd_soc_component_driver soc_codec_driver_tas2505 = {
+	.probe			= tas2505_codec_probe,
+	.set_bias_level		= tas2505_set_bias_level,
+	.suspend_bias_off	= true,
+
+	.controls		= tas2505_snd_controls,
+	.num_controls		= ARRAY_SIZE(tas2505_snd_controls),
+	.dapm_widgets		= tas2505_dapm_widgets,
+	.num_dapm_widgets	= ARRAY_SIZE(tas2505_dapm_widgets),
+	.dapm_routes		= tas2505_audio_map,
+	.num_dapm_routes	= ARRAY_SIZE(tas2505_audio_map),
+};
+#else
+static struct snd_soc_codec_driver soc_codec_driver_tas2505 = {
+	.probe			= tas2505_codec_probe,
+	.set_bias_level		= tas2505_set_bias_level,
+	.suspend_bias_off	= true,
+
+	.component_driver = {
+		.controls		= tas2505_snd_controls,
+		.num_controls		= ARRAY_SIZE(tas2505_snd_controls),
+		.dapm_widgets		= tas2505_dapm_widgets,
+		.num_dapm_widgets	= ARRAY_SIZE(tas2505_dapm_widgets),
+		.dapm_routes		= tas2505_audio_map,
+		.num_dapm_routes	= ARRAY_SIZE(tas2505_audio_map),
+	},
+};
+#endif
+
+static const struct snd_soc_dai_ops tas2505_dai_ops = {
+	.hw_params	= tas2505_hw_params,
+	.set_sysclk	= tas2505_set_dai_sysclk,
+	.set_fmt	= tas2505_set_dai_fmt,
+	.mute_stream	= tas2505_dac_mute,
+};
+
+static struct snd_soc_dai_driver tas2505_dai_driver[] = {
+	{
+		.name = "tas2505-hifi",
+		.playback = {
+			.stream_name	= "Playback",
+			.channels_min	= 1,
+			.channels_max	= 2,
+			.rates		= TAS2505_RATES,
+			.formats	= TAS2505_FORMATS,
+		},
+		.ops = &tas2505_dai_ops,
+		.symmetric_rates = 1,
+	},
+};
+
+static int tas2505_i2c_probe(struct i2c_client *i2c,
+	const struct i2c_device_id *id)
+{
+	struct tas2505_priv *tas2505;
+	struct device_node *np = i2c->dev.of_node;
+	const struct regmap_config *regmap_config = &tas2505_i2c_regmap;
+	int ret;
+
+	tas2505 = devm_kzalloc(&i2c->dev, sizeof(*tas2505), GFP_KERNEL);
+	if (tas2505 == NULL)
+		return -ENOMEM;
+
+	tas2505->regmap = devm_regmap_init_i2c(i2c, regmap_config);
+	if (IS_ERR(tas2505->regmap)) {
+		ret = PTR_ERR(tas2505->regmap);
+		dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
+			ret);
+		return ret;
+	}
+
+	ret = of_get_named_gpio(np, "gpio-reset", 0);
+	if ((ret > 0) && gpio_is_valid(ret)) {
+		devm_gpio_request_one(&i2c->dev, ret, GPIOF_OUT_INIT_HIGH, "reset");
+	}
+
+	tas2505->dev = &i2c->dev;
+
+	dev_set_drvdata(tas2505->dev, tas2505);
+#if KERNEL_VERSION(4, 19, 0) <= LINUX_VERSION_CODE
+	return snd_soc_register_component( &i2c->dev, &soc_codec_driver_tas2505,
+		tas2505_dai_driver, ARRAY_SIZE(tas2505_dai_driver));
+#else
+	return snd_soc_register_codec( &i2c->dev, &soc_codec_driver_tas2505,
+		tas2505_dai_driver, ARRAY_SIZE(tas2505_dai_driver));
+#endif
+}
+
+static int tas2505_i2c_remove(struct i2c_client *i2c)
+{
+#if KERNEL_VERSION(4, 19, 0) <= LINUX_VERSION_CODE
+	snd_soc_unregister_component(&i2c->dev);
+#else
+	snd_soc_unregister_codec(&i2c->dev);
+#endif
+	return 0;
+}
+
+static const struct of_device_id tas2505_of_match[] = {
+	{ .compatible = "ti,tas2505" },
+	{},
+};
+MODULE_DEVICE_TABLE(of, tas2505_of_match);
+
+static const struct i2c_device_id tas2505_i2c_id[] = {
+	{ "tas2505", 0 },
+	{}
+};
+MODULE_DEVICE_TABLE(i2ic, tas2505_i2c_id);
+
+static struct i2c_driver tas2505_i2c_driver = {
+	.driver = {
+		.name		= "tas2505-codec",
+		.of_match_table	= of_match_ptr(tas2505_of_match),
+	},
+	.probe		= tas2505_i2c_probe,
+	.remove		= tas2505_i2c_remove,
+	.id_table	= tas2505_i2c_id,
+};
+
+module_i2c_driver(tas2505_i2c_driver);
+
+MODULE_DESCRIPTION("ASoC TAS2505 codec driver");
+MODULE_AUTHOR("Hieu Tran Dang <dangtranhieu2012@gmail.com>");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/tas2505.h b/sound/soc/codecs/tas2505.h
new file mode 100644
index 0000000..496574d
--- /dev/null
+++ b/sound/soc/codecs/tas2505.h
@@ -0,0 +1,90 @@
+/*
+ * ALSA SoC TAS2505 codec driver
+ *
+ * Author: Hieu Tran Dang <dangtranhieu2012@gmail.com>
+ *
+ * This package is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * THIS PACKAGE IS PROVIDED AS IS AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#ifndef _TAS2505_H
+#define _TAS2505_H
+
+#define TAS2505_RATES	SNDRV_PCM_RATE_8000_96000
+#define TAS2505_FORMATS SNDRV_PCM_FMTBIT_S24_LE
+
+#define TAS2505_REG(page, reg)	((page * 128) + reg)
+
+#define TAS2505_PAGECTL			TAS2505_REG(0, 0)
+#define TAS2505_RESET			TAS2505_REG(0, 1)
+#define TAS2505_CLKMUX			TAS2505_REG(0, 4)
+#define TAS2505_PLLPR			TAS2505_REG(0, 5)
+#define TAS2505_PLLJ			TAS2505_REG(0, 6)
+#define TAS2505_PLLDMSB			TAS2505_REG(0, 7)
+#define TAS2505_PLLDLSB			TAS2505_REG(0, 8)
+#define TAS2505_NDAC			TAS2505_REG(0, 11)
+#define TAS2505_MDAC			TAS2505_REG(0, 12)
+#define TAS2505_DOSRMSB			TAS2505_REG(0, 13)
+#define TAS2505_DOSRLSB			TAS2505_REG(0, 14)
+#define TAS2505_IFACE1			TAS2505_REG(0, 27)
+#define TAS2505_IFACE3			TAS2505_REG(0, 29)
+#define TAS2505_BCLKNDIV		TAS2505_REG(0, 30)
+#define TAS2505_DACFLAG1		TAS2505_REG(0, 37)
+#define TAS2505_DACFLAG2		TAS2505_REG(0, 38)
+#define TAS2505_STICKYFLAG1		TAS2505_REG(0, 42)
+#define TAS2505_INTFLAG1		TAS2505_REG(0, 43)
+#define TAS2505_STICKYFLAG2		TAS2505_REG(0, 44)
+#define TAS2505_INTFLAG2		TAS2505_REG(0, 46)
+#define TAS2505_DACINSTRSET		TAS2505_REG(0, 60)
+#define TAS2505_DACSETUP1		TAS2505_REG(0, 63)
+#define TAS2505_DACSETUP2		TAS2505_REG(0, 64)
+#define TAS2505_DACVOL			TAS2505_REG(0, 65)
+#define TAS2505_REF_POR_LDO_BGAP_CTRL	TAS2505_REG(1, 1)
+#define TAS2505_LDO_CTRL		TAS2505_REG(1, 2)
+#define TAS2505_PLAYBACKCONF1		TAS2505_REG(1, 3)
+#define TAS2505_SPKAMPCTRL1		TAS2505_REG(1, 45)
+#define TAS2505_SPKVOL1			TAS2505_REG(1, 46)
+#define TAS2505_SPKVOL2			TAS2505_REG(1, 48)
+#define TAS2505_DACANLGAINFLAG		TAS2505_REG(1, 63)
+
+#define TAS2505_PLLPR_P_MASK				0x70
+#define TAS2505_PLLPR_R_MASK				0xf
+#define TAS2505_PLL_DAC_MASK				0x7f
+#define TAS2505_BCLKNDIV_MASK				0x7f
+#define TAS2505_IFACE1_DATALEN_MASK			0x30
+#define TAS2505_IFACE1_WCLKDIR_MASK			0x4
+#define TAS2505_IFACE1_BCLKDIR_MASK			0x8
+#define TAS2505_IFACE1_INTERFACE_MASK			0xc0
+#define TAS2505_IFACE3_BDIVCLKIN_MASK			0x1
+#define TAS2505_IFACE3_BCLKINV_MASK			0x8
+#define TAS2505_DACSETUP2_MUTE_MASK			0x8
+#define TAS2505_PM_MASK					0x80
+#define TAS2505_LDO_PLL_HP_LVL_MASK			0x8
+#define TAS2505_REF_POR_LDO_BGAP_MASTER_REF_MASK	0x10
+
+#define TAS2505_PLLPR_P_SHIFT		4
+#define TAS2505_PLL_CLKIN_SHIFT		2
+#define TAS2505_IFACE1_DATALEN_SHIFT	4
+#define TAS2505_IFACE1_INTERFACE_SHIFT	6
+#define TAS2505_IFACE3_BCLKINV_SHIFT	4
+
+#define TAS2505_WORD_LEN_20BITS		1
+#define TAS2505_WORD_LEN_24BITS		2
+#define TAS2505_WORD_LEN_32BITS		3
+
+#define TAS2505_DSP_MODE		1
+#define TAS2505_RJF_MODE		2
+#define TAS2505_LJF_MODE		3
+
+#define TAS2505_PLL_CLKIN_MCLK		0
+#define TAS2505_PLL_CLKIN_BCLK		1
+#define TAS2505_PLL_CLKIN_GPIO		2
+#define TAS2505_PLL_CLKIN_DIN		3
+#define TAS2505_CODEC_CLKIN_PLL		3
+
+#endif

>我在内核 menuconfig 中启用了驱动程序

>已修补设备树以添加驱动程序(请参见附件)
/*
 * 23/9/2022
 * Ing. Federico Arias
 * Device tree para botonera y preasignador con pantalla HDMI
 * version 5

 * configura señales de HDMI y audio por i2s
 */

/dts-v1/;

#include "am33xx.dtsi"
#include "am335x-bone-common.dtsi"
#include <dt-bindings/display/tda998x.h>


/ {
	model = "TI AM335x BeagleBone Black";
	compatible = "ti,am335x-bone-black", "ti,am335x-bone", "ti,am33xx";
};

&cpu0_opp_table {
	oppnitro-1000000000 {
		opp-supported-hw = <0x06 0x0100>;
	};
};

&ldo3_reg {
	regulator-min-microvolt = <1800000>;
	regulator-max-microvolt = <1800000>;
	regulator-always-on;
};

&mmc1 {
	vmmc-supply = <&vmmcsd_fixed>;
};

&mmc2 {
	vmmc-supply = <&vmmcsd_fixed>;
	pinctrl-names = "default";
	pinctrl-0 = <&emmc_pins>;
	bus-width = <8>;
	status = "okay";
};

&am33xx_pinmux {
	nxp_hdmi_bonelt_pins: nxp_hdmi_bonelt_pins {
		pinctrl-single,pins = <
			AM33XX_IOPAD(0x9b0, PIN_OUTPUT_PULLDOWN | MUX_MODE3)	/* xdma_event_intr0 */
			AM33XX_IOPAD(0x8a0, PIN_OUTPUT | MUX_MODE0)		/* lcd_data0.lcd_data0 */
			AM33XX_IOPAD(0x8a4, PIN_OUTPUT | MUX_MODE0)		/* lcd_data1.lcd_data1 */
			AM33XX_IOPAD(0x8a8, PIN_OUTPUT | MUX_MODE0)		/* lcd_data2.lcd_data2 */
			AM33XX_IOPAD(0x8ac, PIN_OUTPUT | MUX_MODE0)		/* lcd_data3.lcd_data3 */
			AM33XX_IOPAD(0x8b0, PIN_OUTPUT | MUX_MODE0)		/* lcd_data4.lcd_data4 */
			AM33XX_IOPAD(0x8b4, PIN_OUTPUT | MUX_MODE0)		/* lcd_data5.lcd_data5 */
			AM33XX_IOPAD(0x8b8, PIN_OUTPUT | MUX_MODE0)		/* lcd_data6.lcd_data6 */
			AM33XX_IOPAD(0x8bc, PIN_OUTPUT | MUX_MODE0)		/* lcd_data7.lcd_data7 */
			AM33XX_IOPAD(0x8c0, PIN_OUTPUT | MUX_MODE0)		/* lcd_data8.lcd_data8 */
			AM33XX_IOPAD(0x8c4, PIN_OUTPUT | MUX_MODE0)		/* lcd_data9.lcd_data9 */
			AM33XX_IOPAD(0x8c8, PIN_OUTPUT | MUX_MODE0)		/* lcd_data10.lcd_data10 */
			AM33XX_IOPAD(0x8cc, PIN_OUTPUT | MUX_MODE0)		/* lcd_data11.lcd_data11 */
			AM33XX_IOPAD(0x8d0, PIN_OUTPUT | MUX_MODE0)		/* lcd_data12.lcd_data12 */
			AM33XX_IOPAD(0x8d4, PIN_OUTPUT | MUX_MODE0)		/* lcd_data13.lcd_data13 */
			AM33XX_IOPAD(0x8d8, PIN_OUTPUT | MUX_MODE0)		/* lcd_data14.lcd_data14 */
			AM33XX_IOPAD(0x8dc, PIN_OUTPUT | MUX_MODE0)		/* lcd_data15.lcd_data15 */
			AM33XX_IOPAD(0x8e0, PIN_OUTPUT_PULLDOWN | MUX_MODE0)	/* lcd_vsync.lcd_vsync */
			AM33XX_IOPAD(0x8e4, PIN_OUTPUT_PULLDOWN | MUX_MODE0)	/* lcd_hsync.lcd_hsync */
			AM33XX_IOPAD(0x8e8, PIN_OUTPUT_PULLDOWN | MUX_MODE0)	/* lcd_pclk.lcd_pclk */
			AM33XX_IOPAD(0x8ec, PIN_OUTPUT_PULLDOWN | MUX_MODE0)	/* lcd_ac_bias_en.lcd_ac_bias_en */
		>;
	};
	nxp_hdmi_bonelt_off_pins: nxp_hdmi_bonelt_off_pins {
		pinctrl-single,pins = <
			AM33XX_IOPAD(0x9b0, PIN_OUTPUT_PULLDOWN | MUX_MODE3)	/* xdma_event_intr0 */
		>;
	};

	mcasp0_pins: mcasp0_pins {
		pinctrl-single,pins = <
			AM33XX_IOPAD(0x9ac, PIN_INPUT_PULLUP | MUX_MODE0) /* mcasp0_ahcklx.mcasp0_ahclkx */
			AM33XX_IOPAD(0x99c, PIN_OUTPUT_PULLDOWN | MUX_MODE2) /* mcasp0_ahclkr.mcasp0_axr2*/
			AM33XX_IOPAD(0x994, PIN_OUTPUT_PULLUP | MUX_MODE0) /* mcasp0_fsx.mcasp0_fsx */
			AM33XX_IOPAD(0x990, PIN_OUTPUT_PULLDOWN | MUX_MODE0) /* mcasp0_aclkx.mcasp0_aclkx */
			AM33XX_IOPAD(0x86c, PIN_OUTPUT_PULLDOWN | MUX_MODE7) /* gpmc_a11.GPIO1_27 */
		>;
	};
	tas_pins: tas_pins {
		pinctrl-single,pins = <
			AM33XX_IOPAD(0x84c, PIN_OUTPUT_PULLDOWN | MUX_MODE7) /* tas2505 reset pin gpio1.19 */
		>;
	};
};

&lcdc {
	status = "okay";

	/* para 24 bits cambiar por crossed*/

	blue-and-red-wiring = "straight";

	port {
		lcdc_0: endpoint@0 {
			remote-endpoint = <&hdmi_0>;
		};
	};
};

&i2c0 {
	tda19988: tda19988 {
		compatible = "nxp,tda998x";
		reg = <0x70>;

		pinctrl-names = "default", "off";
		pinctrl-0 = <&nxp_hdmi_bonelt_pins>;
		pinctrl-1 = <&nxp_hdmi_bonelt_off_pins>;

		/* para 24 bits descomentar siguiente linea*/
		/* video-ports = <0x234501>; */

		#sound-dai-cells = <0>;
		audio-ports = <	TDA998x_I2S	0x03>;

		ports {
			port@0 {
				hdmi_0: endpoint@0 {
					remote-endpoint = <&lcdc_0>;
				};
			};
		};
	};
};

&i2c2 {
	tas2505: tas2505@18 {
		#sound-dai-cells = <0>;
		compatible = "ti,tas2505";		
		reg = <0x18>;
		gpio-reset = <&gpio1 19 GPIO_ACTIVE_LOW>;
		status = "ok";
	};
};

&rtc {
	system-power-controller;
};

&mcasp0	{
	#sound-dai-cells = <0>;
	pinctrl-names = "default";
	pinctrl-0 = <&mcasp0_pins>;
	status = "okay";
	op-mode = <0>;	/* MCASP_IIS_MODE */
	tdm-slots = <8>;
	serial-dir = <	/* 0: INACTIVE, 1: TX, 2: RX */
			2 2 1 0
		>;
	tx-num-evt = <32>;
	rx-num-evt = <32>;
};

/ {
	memory@80000000 {
		device_type = "memory";
		reg = <0x80000000 0x20000000>; /* 512 MB */
	};

	clk_mcasp0_fixed: clk_mcasp0_fixed {
		#clock-cells = <0>;
		compatible = "fixed-clock";
		clock-frequency = <24576000>;
	};

	clk_mcasp0: clk_mcasp0 {
		#clock-cells = <0>;
		compatible = "gpio-gate-clock";
		clocks = <&clk_mcasp0_fixed>;
		enable-gpios = <&gpio1 27 0>; /* BeagleBone Black Clk enable on GPIO1_27 */
	};

	sound {
		compatible = "simple-audio-card";
		simple-audio-card,name = "TAS2505";
		simple-audio-card,dai-link@0 {
			format = "i2s";
			bitclock-master = <&sound0_master>;
			frame-master = <&sound0_master>;
			sound0_master: cpu {
				sound-dai = <&mcasp0>;
				clocks = <&clk_mcasp0>;
			};

			codec {
				sound-dai = <&tas2505>;
			};
		};
	};
};

>已成功编译、刷写并在 BBB 上引导映像。

已加载驱动程序(使用 aplay -l 进行检查)、但扬声器测试抛出以下错误:
速率48000Hz 不可用于回放:参数无效
hwparams 设置失败:参数无效
aplay 显示此错误:
Main:828:Audio open error:device or resource busy (主:828:音频打开错误:设备或资源繁忙

>可能是驱动程序/寄存器配置有误

dsmeg 显示了以下内容:

tas2505-codec 2-0018:不支持采样率(32000)和格式
tas2505-codec 2-0018:asoc:无法设置 tas2505-codec.2-0018 HW 参数:-22
在内核中除以0。

>i2cdetect -r 2在寄存器0x18上显示 UU

>在硬件侧、我已连接 I2C2 (SCA 和 SCL)、RESET、I2S (DIN、WCLK、BCLK)线路。
>我没有使用 MCLK 或 SCLK 线路。
>指示 ALSA 命令时、示波器不会在上述行中显示任何内容、I2C 除外

我 使用 Linux 进入嵌入式软件的时间很短、所以我对此不了解太多、而且我的想法已经过时了。
请帮助我继续进行此操作吗?
非常感谢你能抽出时间

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好 Federico、

    我们将检查您的问题、并在接下来的几天内提供更多意见。

    此致、
    -Ivan Salazar
    应用工程师

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好 Federico、

    很高兴回答您的问题、您能否共享测试位流或测试 wav 文件? 您的测试文件的采样率似乎是32kHz、我们需要您的分析测试文件。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Kevin:

    感谢您的帮助。 这是我与 aplay 一起使用的测试文件:

    e2e.ti.com/.../Emerg.wav

    我还尝试过其他 wav 文件和扬声器测试实用程序(噪声、wav 和正弦模式)、但始终得到相同的错误。

    我想澄清一点、如果我使用 BBB HDMI 声卡(TDA19988)或 USB 卡、声音效果良好、因此这不是内部内核问题。

    我还想提一下、如果相关的话、我已经将驱动程序配置并编译为内置驱动程序、而不是内核模块。 因为我无法让它在引导时加载驱动程序模块。

    此致

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好 Federico、

    将驱动程序配置并编译为内置驱动程序是正确的。

    原始驱动程序仅支持 MCLK、我们 对当前代码进行了一些修改、并在当前版本中添加了 BCLK 支持、请 比较这两个驱动程序的差异、并在您的平台中使用新代码。

    此外、您应该在 DTS 中的节点 tas2505@18下添加"clock-source =<1>;// 0:MCLK、1:BCLK */"。 以便代码能够识别使用的时钟源。 完成这些操作后、如果有任何疑问或问题、请共享打印日志。

    tas2505.c

    /*
     * ALSA SoC TAS2505 codec driver
     *
     * Author: Hieu Tran Dang <dangtranhieu2012@gmail.com>
     *
     * This package is free software; you can redistribute it and/or modify
     * it under the terms of the GNU General Public License version 2 as
     * published by the Free Software Foundation.
     *
     * THIS PACKAGE IS PROVIDED AS IS AND WITHOUT ANY EXPRESS OR
     * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
     * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
     */
    #include <linux/version.h>
    #include <linux/module.h>
    #include <linux/i2c.h>
    #include <linux/clk.h>
    #include <linux/of.h>
    #include <linux/of_gpio.h>
    #include <sound/soc.h>
    #include <sound/tlv.h>
    #include <sound/pcm_params.h>
    #include "tas2505.h"
    
    enum {
    	MCLK = 0,
    	BCLK = 1,
    };
    
    static int tas2505_spkdrv_getvol(struct snd_kcontrol *kcontrol,
    	struct snd_ctl_elem_value *ucontrol)
    {
    	struct snd_soc_component *component =
    		snd_soc_kcontrol_component(kcontrol);
    	struct soc_mixer_control *mc =
    		(struct soc_mixer_control *)kcontrol->private_value;
    	unsigned int val;
    
    	val = snd_soc_component_read(component, TAS2505_SPKVOL1);
    
    	val = (val > mc->max) ? mc->max : val;
    	val = mc->invert ? mc->max - val : val;
    	ucontrol->value.integer.value[0] = val;
    
    	return 0;
    }
    
    static int tas2505_spkdrv_putvol(struct snd_kcontrol *kcontrol,
    	struct snd_ctl_elem_value *ucontrol)
    {
    	struct snd_soc_component *component =
    		snd_soc_kcontrol_component(kcontrol);
    	struct soc_mixer_control *mc =
    		(struct soc_mixer_control *)kcontrol->private_value;
    	u8 val;
    
    	val = (ucontrol->value.integer.value[0] & 0x7f);
    	val = mc->invert ? mc->max - val : val;
    	val = (val < 0) ? 0 : val;
    	snd_soc_component_write(component, TAS2505_SPKVOL1, val);
    
    	return 0;
    }
    
    static const DECLARE_TLV_DB_SCALE(dac_vol_tlv, -6350, 50, 0);
    static const DECLARE_TLV_DB_LINEAR(spk_drv_vol_tlv, TLV_DB_GAIN_MUTE, 0);
    static const DECLARE_TLV_DB_SCALE(spk_amp_vol_tlv, 0, 600, 1);
    
    static const struct snd_kcontrol_new tas2505_snd_controls[] = {
    	SOC_SINGLE_S8_TLV("DAC Playback Volume", TAS2505_DACVOL,
    		-127, 48, dac_vol_tlv),
    	SOC_SINGLE_RANGE_EXT_TLV("Speaker Driver Volume", TAS2505_SPKVOL1,
    		0, 0, 117, 1,
    		tas2505_spkdrv_getvol, tas2505_spkdrv_putvol, spk_drv_vol_tlv),
    	SOC_SINGLE_TLV("Speaker Amplifer Volume", TAS2505_SPKVOL2,
    		4, 5, 0, spk_amp_vol_tlv),
    };
    
    static const struct snd_soc_dapm_widget tas2505_dapm_widgets[] = {
    	SND_SOC_DAPM_DAC("DAC Channel", "Playback",
    		TAS2505_DACSETUP1, 7, 0),
    	SND_SOC_DAPM_OUT_DRV("Speaker Driver", TAS2505_SPKAMPCTRL1,
    		1, 0, NULL, 0),
    	SND_SOC_DAPM_OUTPUT("Speaker"),
    };
    
    static const struct snd_soc_dapm_route tas2505_audio_map[] = {
    	{ "Speaker Driver", NULL, "DAC Channel" },
    	{ "Speaker", NULL, "Speaker Driver" },
    };
    
    static const struct reg_default tas2505_reg_defaults[] = {
    	{ TAS2505_CLKMUX, 0x00 },
    	{ TAS2505_PLLPR, 0x11 },
    	{ TAS2505_PLLJ, 0x04 },
    	{ TAS2505_PLLDMSB, 0x00 },
    	{ TAS2505_PLLDLSB, 0x00 },
    	{ TAS2505_NDAC, 0x01 },
    	{ TAS2505_MDAC, 0x01 },
    	{ TAS2505_DOSRMSB, 0x00 },
    	{ TAS2505_DOSRLSB, 0x80 },
    	{ TAS2505_IFACE1, 0x00 },
    	{ TAS2505_IFACE3, 0x00 },
    	{ TAS2505_DACSETUP1, 0x14 },
    	{ TAS2505_DACSETUP2, 0x0c },
    	{ TAS2505_DACVOL, 0x00 },
    	{ TAS2505_REF_POR_LDO_BGAP_CTRL, 0x00 },
    	{ TAS2505_LDO_CTRL, 0x0c },
    	{ TAS2505_SPKAMPCTRL1, 0x00 },
    	{ TAS2505_SPKVOL1, 0x00 },
    	{ TAS2505_SPKVOL2, 0x00 },
    	{ TAS2505_DACFLAG1, 0x00 },
    	{ TAS2505_DACFLAG2, 0x00 },
    	{ TAS2505_STICKYFLAG1, 0x00 },
    	{ TAS2505_STICKYFLAG2, 0x00 },
    	{ TAS2505_INTFLAG1, 0x00 },
    	{ TAS2505_INTFLAG2, 0x00 },
    	{ TAS2505_DACANLGAINFLAG, 0x00 },
    };
    
    static bool tas2505_volatile(struct device *dev, unsigned int reg)
    {
    	switch (reg) {
    		case TAS2505_PAGECTL:
    		case TAS2505_RESET:
    		case TAS2505_DACFLAG1:
    		case TAS2505_DACFLAG2:
    		case TAS2505_STICKYFLAG1:
    		case TAS2505_STICKYFLAG2:
    		case TAS2505_INTFLAG1:
    		case TAS2505_INTFLAG2:
    		case TAS2505_DACANLGAINFLAG:
    			return true;
    	}
    	return false;
    }
    
    static bool tas2505_writeable(struct device *dev, unsigned int reg)
    {
    	switch (reg) {
    		case TAS2505_DACFLAG1:
    		case TAS2505_DACFLAG2:
    		case TAS2505_STICKYFLAG1:
    		case TAS2505_STICKYFLAG2:
    		case TAS2505_INTFLAG1:
    		case TAS2505_INTFLAG2:
    		case TAS2505_DACANLGAINFLAG:
    			return false;
    	}
    	return true;
    }
    
    static const struct regmap_range_cfg tas2505_ranges[] = {
    	{
    		.range_min = 0,
    		.range_max = 69 * 128,
    		.selector_reg = TAS2505_PAGECTL,
    		.selector_mask = 0xff,
    		.selector_shift = 0,
    		.window_start = 0,
    		.window_len = 128,
    	},
    };
    
    static const struct regmap_config tas2505_i2c_regmap = {
    	.reg_bits = 8,
    	.val_bits = 8,
    	.writeable_reg = tas2505_writeable,
    	.volatile_reg = tas2505_volatile,
    	.reg_defaults = tas2505_reg_defaults,
    	.num_reg_defaults = ARRAY_SIZE(tas2505_reg_defaults),
    	.cache_type = REGCACHE_RBTREE,
    	.ranges = tas2505_ranges,
    	.num_ranges = ARRAY_SIZE(tas2505_ranges),
    	.max_register = 69 * 128,
    };
    
    struct tas2505_rate_divs {
    	u32 mclk_p;
    	u32 rate;
    	u8 pll_r;
    	u8 pll_j;
    	u16 pll_d;
    	u8 mdac;
    	u8 ndac;
    	u16 dosr;
    };
    
    static const struct tas2505_rate_divs tas2505_divs[] = {
    	{ 12288000, 44100, 1, 7, 35, 4, 4, 128 },
    	{ 12288000, 48000, 1, 7, 0, 7, 2, 128 },
    };
    
    static const struct tas2505_rate_divs tas2505_divs_bclksrc[] = {
    	{ 1536000, 48000, 1, 56, 0, 2, 7, 128 },
    	{ 1411200, 44100, 1, 60, 0, 5, 3, 128 },
    	{ 3072000, 48000, 1, 28, 0, 2, 7, 128 },
    	{ 2822400, 44100, 1, 30, 0, 5, 3, 128 },
    	{ 1024000, 32000, 2, 40, 0, 5, 4, 128 },
    	{ 2048000, 32000, 1, 40, 0, 5, 4, 128 },
    
    };
    
    struct tas2505_priv {
    	void *codec;
    	struct device *dev;
    	struct regmap *regmap;
    	u32 sysclk;
    	u32 clk_src;
    	u32 rate;
    	int rate_div_line;
    	int pll_clkin;
    	int frame_size;
    	u8 p_div;
    };
    
    static int tas2505_setup_pll(struct snd_soc_component *codec)
    {
    	struct tas2505_priv *tas2505 = snd_soc_component_get_drvdata(codec);
    	int mclk_p = tas2505->sysclk / tas2505->p_div;
    	struct tas2505_rate_divs *rate_divs;
    	int match = -1;
    	u8 p_div;
    	int i;
    
    	if (tas2505->clk_src == MCLK) {
    		for (i = 0; i < ARRAY_SIZE(tas2505_divs); i++) {
    			if (
    				tas2505_divs[i].rate == tas2505->rate &&
    				tas2505_divs[i].mclk_p == mclk_p
    			) {
    				match = i;
    				break;
    			}
    		}
    
    		if (match == -1) {
    			dev_err(codec->dev,
    				"Sample rate (%u) and format not supported\n",
    				tas2505->rate);
    			return -EINVAL;
    		}
    
    		tas2505->rate_div_line = match;
    		rate_divs = (struct tas2505_rate_divs *)tas2505_divs;
    	}else {
    		for (i = 0; i < ARRAY_SIZE(tas2505_divs_bclksrc); i++) {
    			if (tas2505_divs_bclksrc[i].rate ==
    				tas2505->rate) {
    				match = i;
    				break;
    			}
    		}
    
    		if (match == -1) {
    			dev_err(codec->dev,
    				"Sample rate (%u) and format not supported\n",
    				tas2505->rate);
    			return -EINVAL;
    		}
    		rate_divs = (struct tas2505_rate_divs *)tas2505_divs_bclksrc;
    	}
    
    	p_div = (tas2505->p_div == 8) ? 0 : tas2505->p_div;
    	p_div <<= TAS2505_PLLPR_P_SHIFT;
    
    	snd_soc_component_update_bits(codec,
    		TAS2505_PLLPR, TAS2505_PLLPR_P_MASK,
    		p_div);
    	snd_soc_component_update_bits(codec, TAS2505_PLLPR,
    		TAS2505_PLLPR_R_MASK,
    		rate_divs[match].pll_r);
    	snd_soc_component_write(codec, TAS2505_PLLJ,
    		rate_divs[match].pll_j);
    	snd_soc_component_write(codec, TAS2505_PLLDMSB,
    		rate_divs[match].pll_d >> 8);
    	snd_soc_component_write(codec, TAS2505_PLLDLSB,
    		rate_divs[match].pll_d & 0xff);
    	snd_soc_component_update_bits(codec, TAS2505_NDAC,
    		TAS2505_PLL_DAC_MASK,
    		rate_divs[match].ndac);
    	snd_soc_component_update_bits(codec, TAS2505_MDAC,
    		TAS2505_PLL_DAC_MASK,
    		rate_divs[match].mdac);
    	snd_soc_component_write(codec, TAS2505_DOSRMSB,
    		rate_divs[match].dosr >> 8);
    	snd_soc_component_write(codec, TAS2505_DOSRLSB,
    		rate_divs[match].dosr & 0xff);
    	snd_soc_component_update_bits(codec, TAS2505_BCLKNDIV,
    		TAS2505_BCLKNDIV_MASK,
    		(rate_divs[match].dosr * rate_divs[match].mdac) /
    		tas2505->frame_size);
    
    	return 0;
    }
    
    static int tas2505_hw_params(struct snd_pcm_substream *substream,
    	struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
    {
    	struct snd_soc_component *codec = dai->component;
    	struct tas2505_priv *tas2505 = snd_soc_component_get_drvdata(codec);
    	u8 data = 0;
    
    	switch (params_width(params)) {
    		case 16:
    			break;
    
    		case 20:
    			data = TAS2505_WORD_LEN_20BITS;
    			break;
    
    		case 24:
    			data = TAS2505_WORD_LEN_24BITS;
    			break;
    
    		case 32:
    			data = TAS2505_WORD_LEN_32BITS;
    			break;
    
    		default:
    			dev_err(codec->dev, "Unsupported width %d\n",
    				params_width(params));
    			return -EINVAL;
    	}
    	dev_info(codec->dev, "%s: bit width = %d\n",
    				__func__, params_width(params));
    	data <<= TAS2505_IFACE1_DATALEN_SHIFT;
    
    	snd_soc_component_update_bits(codec, TAS2505_IFACE1,
    		TAS2505_IFACE1_DATALEN_MASK, data);
    	tas2505->rate = params_rate(params);
    	tas2505->frame_size = snd_soc_params_to_frame_size(params);
    
    	return 0;
    }
    
    static int tas2505_dac_mute(struct snd_soc_dai *dai, int mute,
    	int stream)
    {
    	struct snd_soc_component *codec = dai->component;
    
    	dev_info(codec->dev, "%s: mute = %d\n", __func__, mute);
    	if (mute) {
    		snd_soc_component_update_bits(codec, TAS2505_SPKVOL2,
    			TAS2505_SPKVOL2_MSK,
    			TAS2505_SPKVOL2_MUTE << TAS2505_SPKVOL2_6DB_SHIFT);
    		snd_soc_component_update_bits(codec, TAS2505_DACSETUP2,
    			TAS2505_DACSETUP2_MUTE_MASK,
    			TAS2505_DACSETUP2_MUTE_MASK);
    	} else {
    		/*snd_soc_component_update_bits(codec, TAS2505_CLKMUX,
    			TAS2505_CODEC_CLKIN_MSK | TAS2505_PLL_INPUT_CLK_MSK,
    			(tas2505->pll_clkin << TAS2505_PLL_CLKIN_SHIFT) |
    			TAS2505_CODEC_CLKIN_PLL);*/
    		snd_soc_component_update_bits(codec, TAS2505_DACSETUP2,
    			TAS2505_DACSETUP2_MUTE_MASK, 0x0);
    		snd_soc_component_update_bits(codec, TAS2505_SPKVOL2,
    			TAS2505_SPKVOL2_MSK,
    			TAS2505_SPKVOL2_6DB << TAS2505_SPKVOL2_6DB_SHIFT);
    	}
    
    	return 0;
    }
    
    static int tas2505_set_dai_fmt(struct snd_soc_dai *codec_dai,
    	unsigned int fmt)
    {
    	struct snd_soc_component *codec = codec_dai->component;
    	u8 iface_reg1 = 0;
    	u8 iface_reg3 = 0;
    
    	switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
    		case SND_SOC_DAIFMT_CBS_CFS:
    			break;
    
    		case SND_SOC_DAIFMT_CBM_CFM:
    			iface_reg1 |= TAS2505_IFACE1_BCLKDIR_MASK;
    			iface_reg1 |= TAS2505_IFACE1_WCLKDIR_MASK;
    			break;
    
    		default:
    			return -EINVAL;
    	}
    
    	switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
    		case SND_SOC_DAIFMT_NB_NF:
    			break;
    
    		case SND_SOC_DAIFMT_IB_NF:
    			iface_reg3 |= TAS2505_IFACE3_BCLKINV_MASK;
    			break;
    
    		default:
    			return -EINVAL;
    	}
    
    	switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
    		case SND_SOC_DAIFMT_I2S:
    			break;
    
    		case SND_SOC_DAIFMT_DSP_A:
    		case SND_SOC_DAIFMT_DSP_B:
    			iface_reg1 |= (TAS2505_DSP_MODE <<
    				TAS2505_IFACE1_INTERFACE_SHIFT);
    			break;
    
    		case SND_SOC_DAIFMT_RIGHT_J:
    			iface_reg1 |= (TAS2505_RJF_MODE <<
    				TAS2505_IFACE1_INTERFACE_SHIFT);
    			break;
    
    		case SND_SOC_DAIFMT_LEFT_J:
    			iface_reg1 |= (TAS2505_LJF_MODE <<
    				TAS2505_IFACE1_INTERFACE_SHIFT);
    			break;
    
    		default:
    			dev_err(codec->dev, "Invalid DAI interface format\n");
    			return -EINVAL;
    	}
    
    	snd_soc_component_write(codec, TAS2505_IFACE1, iface_reg1);
    	snd_soc_component_update_bits(codec, TAS2505_IFACE3,
    		TAS2505_IFACE3_BCLKINV_MASK | TAS2505_IFACE3_BDIVCLKIN_MASK,
    		iface_reg3);
    
    	return 0;
    }
    
    static int tas2505_set_dai_sysclk(struct snd_soc_dai *codec_dai,
    	int clk_id, unsigned int freq, int dir)
    {
    	struct snd_soc_component *codec = codec_dai->component;
    	struct tas2505_priv *tas2505 = snd_soc_component_get_drvdata(codec);
    	int i, x;
    	int ret = 0;
    
    	dev_info(tas2505->dev, "%s: clk_id: %d, freq: %d\n",
    		__func__, clk_id, freq);
    
    	if (tas2505->clk_src == MCLK) {
    		for (i = 0; i < ARRAY_SIZE(tas2505_divs); i++) {
    			for (x = 1; x < 9; x++) {
    				if ((freq / x) == tas2505_divs[i].mclk_p) {
    					tas2505->p_div = x;
    					break;
    				}
    			}
    		}
    
    		if(i != ARRAY_SIZE(tas2505_divs)) {
    		} else {
    			dev_err(tas2505->dev,
    				"Can't produce required "
    				"PLL_CLKIN frequency\n");
    			ret = -EINVAL;
    		}
    		tas2505->pll_clkin = clk_id;
    	} else {
    		tas2505->pll_clkin = 1;
    		tas2505->p_div = 1;
    	}
    
    	if(!ret) {
    		snd_soc_component_write(codec, TAS2505_CLKMUX,
    			(tas2505->pll_clkin << TAS2505_PLL_CLKIN_SHIFT) |
    			TAS2505_CODEC_CLKIN_PLL);
    
    		tas2505->sysclk = freq;
    	}
    	return ret;
    
    }
    
    static void tas2505_clk_on(struct snd_soc_component *codec)
    {
    	u8 mask = TAS2505_PM_MASK;
    	u8 on = TAS2505_PM_MASK;
    
    	snd_soc_component_update_bits(codec, TAS2505_DACSETUP1,
    			TAS2505_DACSETUP1_PATH_CTRL_MSK,
    			TAS2505_DACSETUP1_PATH_CTRL_LRDIV2
    			<<TAS2505_DACSETUP1_PATH_CTRL_SHIFT);
    	tas2505_setup_pll(codec);
    	snd_soc_component_update_bits(codec, TAS2505_PLLPR, mask, on);
    	mdelay(15);
    	snd_soc_component_update_bits(codec, TAS2505_NDAC, mask, on);
    	snd_soc_component_update_bits(codec, TAS2505_MDAC, mask, on);
    	snd_soc_component_update_bits(codec, TAS2505_BCLKNDIV, mask, on);
    	/*snd_soc_component_update_bits(codec, TAS2505_SPKVOL2,
    		TAS2505_SPKVOL2_MSK,
    		TAS2505_SPKVOL2_6DB << TAS2505_SPKVOL2_6DB_SHIFT);*/
    }
    
    static void tas2505_clk_off(struct snd_soc_component *codec)
    {
    	u8 mask = TAS2505_PM_MASK;
    
    	snd_soc_component_update_bits(codec, TAS2505_BCLKNDIV, mask, 0);
    	snd_soc_component_update_bits(codec, TAS2505_MDAC, mask, 0);
    	snd_soc_component_update_bits(codec, TAS2505_NDAC, mask, 0);
    	snd_soc_component_update_bits(codec, TAS2505_PLLPR, mask, 0);
    }
    
    static void tas2505_power_on(struct snd_soc_component *codec)
    {
    	/*snd_soc_component_write(codec, TAS2505_RESET, 1);
    	usleep_range(500, 1000);*/
    	snd_soc_component_update_bits(codec, TAS2505_LDO_CTRL,
    		TAS2505_LDO_PLL_HP_LVL_MASK, 0);
    	snd_soc_component_update_bits(codec, TAS2505_REF_POR_LDO_BGAP_CTRL,
    		TAS2505_REF_POR_LDO_BGAP_MASTER_REF_MASK,
    		TAS2505_REF_POR_LDO_BGAP_MASTER_REF_MASK);
    }
    
    static void tas2505_power_off(struct snd_soc_component *codec)
    {
    	snd_soc_component_update_bits(codec, TAS2505_REF_POR_LDO_BGAP_CTRL,
    		TAS2505_REF_POR_LDO_BGAP_MASTER_REF_MASK, 0);
    	snd_soc_component_update_bits(codec, TAS2505_LDO_CTRL,
    		TAS2505_LDO_PLL_HP_LVL_MASK,
    		TAS2505_LDO_PLL_HP_LVL_MASK);
    }
    
    static int tas2505_set_bias_level(struct snd_soc_component *codec,
    	enum snd_soc_bias_level level)
    {
    	int current_lvl = snd_soc_component_get_bias_level(codec);
    
    	int rc = 0;
    	switch (level) {
    		case SND_SOC_BIAS_ON:
    			break;
    		case SND_SOC_BIAS_PREPARE:
    			if (current_lvl == SND_SOC_BIAS_STANDBY) {
    				tas2505_clk_on(codec);
    				dev_info(codec->dev, "%s:clk on\n",
    					__func__);
    			} else
    				dev_info(codec->dev,
    					"%s:SND_SOC_BIAS_PREPARE\n", __func__);
    			break;
    		case SND_SOC_BIAS_STANDBY:
    			if (current_lvl == SND_SOC_BIAS_OFF) {
    				tas2505_power_on(codec);
    				dev_info(codec->dev,
    					"%s:power on\n", __func__);
    			}
    			else if (current_lvl == SND_SOC_BIAS_PREPARE) {
    				tas2505_clk_off(codec);
    				dev_info(codec->dev,
    					"%s:clk off\n", __func__);
    			} else
    				dev_info(codec->dev,
    					"%s:SND_SOC_BIAS_STANDBY\n",
    					__func__);
    			break;
    		case SND_SOC_BIAS_OFF:
    			if (current_lvl == SND_SOC_BIAS_STANDBY) {
    				tas2505_power_off(codec);
    				dev_info(codec->dev,
    					"%s:power off\n",
    					__func__);
    			} else
    				dev_info(codec->dev,
    					"%s:SND_SOC_BIAS_OFF\n",
    					__func__);
    			break;
    		default:
    			dev_err(codec->dev, "Invalid bias level\n");
    			rc = -EINVAL;
    	}
    
    	return rc;
    }
    
    static int tas2505_codec_probe(struct snd_soc_component *codec)
    {
    	struct tas2505_priv *tas2505 = snd_soc_component_get_drvdata(codec);
    
    	tas2505->codec = codec;
    	snd_soc_component_write(codec, TAS2505_RESET, 1);
    	return 0;
    }
    
    static struct snd_soc_component_driver soc_codec_driver_tas2505 = {
    	.probe			= tas2505_codec_probe,
    	.set_bias_level		= tas2505_set_bias_level,
    	.suspend_bias_off	= true,
    
    	.controls		= tas2505_snd_controls,
    	.num_controls		= ARRAY_SIZE(tas2505_snd_controls),
    	.dapm_widgets		= tas2505_dapm_widgets,
    	.num_dapm_widgets	= ARRAY_SIZE(tas2505_dapm_widgets),
    	.dapm_routes		= tas2505_audio_map,
    	.num_dapm_routes	= ARRAY_SIZE(tas2505_audio_map),
    };
    
    static const struct snd_soc_dai_ops tas2505_dai_ops = {
    	.hw_params	= tas2505_hw_params,
    	.set_sysclk	= tas2505_set_dai_sysclk,
    	.set_fmt	= tas2505_set_dai_fmt,
    	.mute_stream	= tas2505_dac_mute,
    };
    
    static struct snd_soc_dai_driver tas2505_dai_driver[] = {
    	{
    		.name = "tas2505-hifi",
    		.playback = {
    			.stream_name	= "Playback",
    			.channels_min	= 1,
    			.channels_max	= 2,
    			.rates		= TAS2505_RATES,
    			.formats	= TAS2505_FORMATS,
    		},
    		.ops = &tas2505_dai_ops,
    		.symmetric_rates = 1,
    	},
    };
    
    static int tas2505_i2c_probe(struct i2c_client *i2c,
    	const struct i2c_device_id *id)
    {
    	struct tas2505_priv *tas2505;
    	struct device_node *np = i2c->dev.of_node;
    	const struct regmap_config *regmap_config = &tas2505_i2c_regmap;
    	int ret;
    
    	tas2505 = devm_kzalloc(&i2c->dev, sizeof(*tas2505), GFP_KERNEL);
    	if (tas2505 == NULL)
    		return -ENOMEM;
    
    	tas2505->regmap = devm_regmap_init_i2c(i2c, regmap_config);
    	if (IS_ERR(tas2505->regmap)) {
    		ret = PTR_ERR(tas2505->regmap);
    		dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
    			ret);
    		return ret;
    	}
    
    	ret = of_get_named_gpio(np, "gpio-reset", 0);
    	if ((ret > 0) && gpio_is_valid(ret)) {
    		devm_gpio_request_one(&i2c->dev, ret, GPIOF_OUT_INIT_HIGH,
    			"reset");
    	}
    
    	ret = of_property_read_u32(np, "clock-source",
    			&tas2505->clk_src);
    
    	dev_info(&i2c->dev, "%s: clock-source = %s\n", __func__,
    		tas2505->clk_src?"BCLK":"MCLK");
    
    	tas2505->dev = &i2c->dev;
    
    	dev_set_drvdata(tas2505->dev, tas2505);
    
    	return snd_soc_register_component( &i2c->dev,
    		&soc_codec_driver_tas2505, tas2505_dai_driver,
    		ARRAY_SIZE(tas2505_dai_driver));
    }
    
    static int tas2505_i2c_remove(struct i2c_client *i2c)
    {
    
    	snd_soc_unregister_component(&i2c->dev);
    
    	return 0;
    }
    
    static const struct of_device_id tas2505_of_match[] = {
    	{ .compatible = "ti,tas2505" },
    	{},
    };
    MODULE_DEVICE_TABLE(of, tas2505_of_match);
    
    static const struct i2c_device_id tas2505_i2c_id[] = {
    	{ "tas2505", 0 },
    	{}
    };
    MODULE_DEVICE_TABLE(i2ic, tas2505_i2c_id);
    
    static struct i2c_driver tas2505_i2c_driver = {
    	.driver = {
    		.name		= "tas2505-codec",
    		.of_match_table	= of_match_ptr(tas2505_of_match),
    	},
    	.probe		= tas2505_i2c_probe,
    	.remove		= tas2505_i2c_remove,
    	.id_table	= tas2505_i2c_id,
    };
    
    module_i2c_driver(tas2505_i2c_driver);
    
    MODULE_DESCRIPTION("ASoC TAS2505 codec driver");
    MODULE_AUTHOR("Hieu Tran Dang <dangtranhieu2012@gmail.com>");
    MODULE_LICENSE("GPL");
    

    tas2505.h

    /*
     * ALSA SoC TAS2505 codec driver
     *
     * Author: Hieu Tran Dang <dangtranhieu2012@gmail.com>
     *
     * This package is free software; you can redistribute it and/or modify
     * it under the terms of the GNU General Public License version 2 as
     * published by the Free Software Foundation.
     *
     * THIS PACKAGE IS PROVIDED AS IS AND WITHOUT ANY EXPRESS OR
     * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
     * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
     */
    
    #ifndef _TAS2505_H
    #define _TAS2505_H
    
    #define TAS2505_RATES	(SNDRV_PCM_RATE_8000_96000)
    #define TAS2505_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | \
    	SNDRV_PCM_FMTBIT_S24_LE | \
    	SNDRV_PCM_FMTBIT_S32_LE)
    
    #define TAS2505_REG(page, reg)	((page * 128) + reg)
    
    #define TAS2505_PAGECTL			TAS2505_REG(0, 0)
    #define TAS2505_RESET			TAS2505_REG(0, 1)
    #define TAS2505_CLKMUX			TAS2505_REG(0, 4)
    #define TAS2505_PLLPR			TAS2505_REG(0, 5)
    #define TAS2505_PLLJ			TAS2505_REG(0, 6)
    #define TAS2505_PLLDMSB			TAS2505_REG(0, 7)
    #define TAS2505_PLLDLSB			TAS2505_REG(0, 8)
    #define TAS2505_NDAC			TAS2505_REG(0, 11)
    #define TAS2505_MDAC			TAS2505_REG(0, 12)
    #define TAS2505_DOSRMSB			TAS2505_REG(0, 13)
    #define TAS2505_DOSRLSB			TAS2505_REG(0, 14)
    #define TAS2505_IFACE1			TAS2505_REG(0, 27)
    #define TAS2505_IFACE3			TAS2505_REG(0, 29)
    #define TAS2505_BCLKNDIV		TAS2505_REG(0, 30)
    #define TAS2505_DACFLAG1		TAS2505_REG(0, 37)
    #define TAS2505_DACFLAG2		TAS2505_REG(0, 38)
    #define TAS2505_STICKYFLAG1		TAS2505_REG(0, 42)
    #define TAS2505_INTFLAG1		TAS2505_REG(0, 43)
    #define TAS2505_STICKYFLAG2		TAS2505_REG(0, 44)
    #define TAS2505_INTFLAG2		TAS2505_REG(0, 46)
    #define TAS2505_DACINSTRSET		TAS2505_REG(0, 60)
    #define TAS2505_DACSETUP1		TAS2505_REG(0, 63)
    #define TAS2505_DACSETUP2		TAS2505_REG(0, 64)
    #define TAS2505_DACVOL			TAS2505_REG(0, 65)
    #define TAS2505_REF_POR_LDO_BGAP_CTRL	TAS2505_REG(1, 1)
    #define TAS2505_LDO_CTRL		TAS2505_REG(1, 2)
    #define TAS2505_PLAYBACKCONF1		TAS2505_REG(1, 3)
    #define TAS2505_SPKAMPCTRL1		TAS2505_REG(1, 45)
    #define TAS2505_SPKVOL1			TAS2505_REG(1, 46)
    #define TAS2505_SPKVOL2			TAS2505_REG(1, 48)
    #define TAS2505_DACANLGAINFLAG		TAS2505_REG(1, 63)
    
    #define TAS2505_PLLPR_P_MASK				(0x70)
    #define TAS2505_PLLPR_R_MASK				(0xf)
    #define TAS2505_PLL_DAC_MASK				(0x7f)
    #define TAS2505_BCLKNDIV_MASK				(0x7f)
    #define TAS2505_IFACE1_DATALEN_MASK			(0x30)
    #define TAS2505_IFACE1_WCLKDIR_MASK			(0x4)
    #define TAS2505_IFACE1_BCLKDIR_MASK			(0x8)
    #define TAS2505_IFACE1_INTERFACE_MASK			(0xc0)
    #define TAS2505_IFACE3_BDIVCLKIN_MASK			(0x1)
    #define TAS2505_IFACE3_BCLKINV_MASK			(0x8)
    #define TAS2505_DACSETUP1_PATH_CTRL_MSK			(0x30)
    #define TAS2505_DACSETUP2_MUTE_MASK			(0x8)
    #define TAS2505_PM_MASK					(0x80)
    #define TAS2505_LDO_PLL_HP_LVL_MASK			(0x8)
    #define TAS2505_REF_POR_LDO_BGAP_MASTER_REF_MASK	(0x10)
    #define TAS2505_SPKVOL2_MSK				(0x70)
    #define TAS2505_CODEC_CLKIN_MSK				(0x3)
    #define TAS2505_PLL_INPUT_CLK_MSK			(0xC)
    
    #define TAS2505_PLLPR_P_SHIFT			(4)
    #define TAS2505_PLL_CLKIN_SHIFT			(2)
    #define TAS2505_IFACE1_DATALEN_SHIFT		(4)
    #define TAS2505_IFACE1_INTERFACE_SHIFT		(6)
    #define TAS2505_IFACE3_BCLKINV_SHIFT		(4)
    #define TAS2505_SPKVOL2_6DB_SHIFT		(4)
    #define TAS2505_DACSETUP1_PATH_CTRL_SHIFT	(4)
    
    #define TAS2505_WORD_LEN_20BITS			(1)
    #define TAS2505_WORD_LEN_24BITS			(2)
    #define TAS2505_WORD_LEN_32BITS			(3)
    
    #define TAS2505_DSP_MODE			(1)
    #define TAS2505_RJF_MODE			(2)
    #define TAS2505_LJF_MODE			(3)
    
    #define TAS2505_PLL_CLKIN_MCLK			(0)
    #define TAS2505_PLL_CLKIN_BCLK			(1)
    #define TAS2505_PLL_CLKIN_GPIO			(2)
    #define TAS2505_PLL_CLKIN_DIN			(3)
    #define TAS2505_CODEC_CLKIN_PLL			(3)
    #define TAS2505_SPKVOL2_MUTE			(0)
    #define TAS2505_SPKVOL2_6DB			(1)
    #define TAS2505_DACSETUP1_PATH_CTRL_LRDIV2	(3)
    
    #endif
    

    此致

    Kevin

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Kevin:  

    非常感谢!!! 您的新驱动程序解决了我们的问题。 现在工作正常。  

    正如侧注:

    我修复了 tas2505.c 行39中的错误:

    将其更改为:snd_soc_component_read (component、TAS2505_SPKVOL1、&val);

    因为它在编译时抛出错误。 函数 snd_soc_component_read()接受两个参数,而不是三个,返回参数只是错误标志。
    此函数与 Linux v5.9不同

    此致。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好 Federico、

    感谢您的反馈、很高兴我们的团队能为您提供帮助。

    此致、
    -Ivan Salazar
    应用工程师