ASoC: rt1318: Add RT1318 audio amplifier driver
Subsystems (3)
PATCH 1/1 ASoC: rt1318: Add RT1318 audio amplifier driver
This is the initial amplifier driver for rt1318.
--- include/sound/rt1318.h | 16 + sound/soc/codecs/Kconfig | 5 + sound/soc/codecs/Makefile | 2 + sound/soc/codecs/rt1318.c | 1387 +++++++++++++++++++++++++++++++++++++ sound/soc/codecs/rt1318.h | 342 +++++++++ 5 files changed, 1752 insertions(+) create mode 100644 include/sound/rt1318.h create mode 100644 sound/soc/codecs/rt1318.c create mode 100644 sound/soc/codecs/rt1318.h
include/sound/rt1318.h new file +16 -0
@@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* linux/sound/rt1318.h -- Platform data for RT1318 +* +* Copyright 2024 Realtek Semiconductor Corp. +*/ + +#ifndef __LINUX_SND_RT1318_H +#define __LINUX_SND_RT1318_H + +struct rt1318_platform_data { +unsigned int init_r0_l; +unsigned int init_r0_r; +}; + +#endif
sound/soc/codecs/Kconfig +5 -0
@@ -221,6 +221,7 @@ config SND_SOC_ALL_CODECS imply SND_SOC_RT722_SDCA_SDW imply SND_SOC_RT1308_SDW imply SND_SOC_RT1316_SDW + imply SND_SOC_RT1318 imply SND_SOC_RT1318_SDW imply SND_SOC_RT9120 imply SND_SOC_RTQ9128
@@ -1570,6 +1571,10 @@ config SND_SOC_RT1316_SDW depends on SOUNDWIRE select REGMAP_SOUNDWIRE +config SND_SOC_RT1318 + tristate + depends on I2C + config SND_SOC_RT1318_SDW tristate "Realtek RT1318 Codec - SDW" depends on SOUNDWIRE
sound/soc/codecs/Makefile +2 -0
@@ -221,6 +221,7 @@ snd-soc-rt1305-y := rt1305.o snd-soc-rt1308-y := rt1308.o snd-soc-rt1308-sdw-y := rt1308-sdw.o snd-soc-rt1316-sdw-y := rt1316-sdw.o +snd-soc-rt1318-y := rt1318.o snd-soc-rt1318-sdw-y := rt1318-sdw.o snd-soc-rt274-y := rt274.o snd-soc-rt286-y := rt286.o
@@ -613,6 +614,7 @@ obj-$(CONFIG_SND_SOC_RT1305) += snd-soc-rt1305.o obj-$(CONFIG_SND_SOC_RT1308) += snd-soc-rt1308.o obj-$(CONFIG_SND_SOC_RT1308_SDW) += snd-soc-rt1308-sdw.o obj-$(CONFIG_SND_SOC_RT1316_SDW) += snd-soc-rt1316-sdw.o +obj-$(CONFIG_SND_SOC_RT1318) += snd-soc-rt1318.o obj-$(CONFIG_SND_SOC_RT1318_SDW) += snd-soc-rt1318-sdw.o obj-$(CONFIG_SND_SOC_RT274) += snd-soc-rt274.o obj-$(CONFIG_SND_SOC_RT286) += snd-soc-rt286.o
sound/soc/codecs/rt1318.c new file +1387 -0
1,387 lines not on this page · raw message
sound/soc/codecs/rt1318.h new file +342 -0
342 lines not on this page · raw message
Signature · 1 line
2.34.1
Mark Brown
maintainersound/soc/codecs/rt1318.c line 537
Quoted 13 lines · Jack Yu
sound/soc/codecs/rt1318.c new file +13
-0+static int rt1318_init_put (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{ +struct snd_soc_component *component =snd_soc_kcontrol_component (kcontrol); +struct rt1318_priv *rt1318 =snd_soc_component_get_drvdata (component); + + rt1318->rt1318_init = ucontrol->value.integer.value[0 ]; + +if (rt1318->rt1318_init) +rt1318_reg_init (component); + +return 0 ; +}
So this control resets the CODEC - what's the story here? Really it should be a boolean, and if you run mixer-test it'll tell you you're not returning 1 for value changes - please run mixer-test, there are a number of other errors that it will detect here.
sound/soc/codecs/rt1318.c line 562
Quoted 13 lines
sound/soc/codecs/rt1318.c new file +13
-0+static int rt1318_dvol_put (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{ +struct snd_soc_component *component =snd_soc_kcontrol_component (kcontrol); +struct rt1318_priv *rt1318 =snd_soc_component_get_drvdata (component); + + rt1318->rt1318_dvol = ucontrol->value.integer.value[0 ]; + +if (rt1318->rt1318_dvol <=RT1318_DVOL_STEP ) { +regmap_write (rt1318->regmap,RT1318_DA_VOL_L_8 , rt1318->rt1318_dvol >>8 ); +regmap_write (rt1318->regmap,RT1318_DA_VOL_L_1_7 , rt1318->rt1318_dvol &0xff ); +regmap_write (rt1318->regmap,RT1318_DA_VOL_R_8 , rt1318->rt1318_dvol >>8 ); +regmap_write (rt1318->regmap,RT1318_DA_VOL_R_1_7 , rt1318->rt1318_dvol &0xff );
This will happily accept negative values which you probably don't want.
sound/soc/codecs/rt1318.c line 565
Quoted 3 lines
sound/soc/codecs/rt1318.c new file +3
-0+ }else { + rt1318->rt1318_dvol =RT1318_DVOL_STEP ; +dev_err (component->dev,"Unsupported volume gain\n" );
The driver shouldn't allow userspace to spam the kernel log like this, it can be used to mask issues.
sound/soc/codecs/rt1318.c line 584
Quoted 3 lines
sound/soc/codecs/rt1318.c new file +3
-0+static const struct snd_kcontrol_new rt1318_snd_controls[] = { +SOC_SINGLE_EXT ("rt1318 digital volume" ,SND_SOC_NOPM ,0 ,383 ,0 , + rt1318_dvol_get, rt1318_dvol_put),
No need to include the part number in controls, users aren't going to care. The general style for ALSA controls is capitalised too.
Quoted 16 lines
-----Original Message-----
From: Mark Brown <[email protected]>
Sent: Tuesday, June 4, 2024 8:38 PM
To: Jack Yu <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Flove(HsinFu) <[email protected]>; Oder Chiou <[email protected]>; Shuming [范書銘] <[email protected]>; Derek [方德義] <[email protected]>
Subject: Re: [PATCH] ASoC: rt1318: Add RT1318 audio amplifier driverReview
Quoted 3 lines · Jack Yu
(quoted diff) +3
-0+static int rt1318_init_put(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) { + struct snd_soc_component *component =
snd_soc_kcontrol_component(kcontrol);
Quoted 16 lines
sound/soc/codecs/rt1318.c line 537
Quoted 10 lines
sound/soc/codecs/rt1318.c new file +10
-0+struct rt1318_priv *rt1318 = +snd_soc_component_get_drvdata (component); + + rt1318->rt1318_init = ucontrol->value.integer.value[0 ]; + +if (rt1318->rt1318_init) +rt1318_reg_init (component); + +return 0 ; +}So this control resets the CODEC - what's the story here? Really it should be a boolean, and if you run mixer-test it'll tell you you're not returning 1 for value changes - please run mixer-test, there are a number of other errors that it will detect here.
I will remove this control since it's only for internal testing purpose.
Quoted 12 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+static int rt1318_dvol_put(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) { + struct snd_soc_component *component =
snd_soc_kcontrol_component(kcontrol);sound/soc/codecs/rt1318.c
Quoted 7 lines
sound/soc/codecs/rt1318.c new file +7
-0+struct rt1318_priv *rt1318 = +snd_soc_component_get_drvdata (component); + + rt1318->rt1318_dvol = ucontrol->value.integer.value[0 ]; + +if (rt1318->rt1318_dvol <=RT1318_DVOL_STEP ) { + regmap_write(rt1318->regmap, RT1318_DA_VOL_L_8,
rt1318->rt1318_dvol>> 8);
Quoted 8 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ regmap_write(rt1318->regmap, RT1318_DA_VOL_L_1_7,
rt1318->rt1318_dvol&0xff);Review
Quoted 1 line
(quoted diff) +1
-0+ regmap_write(rt1318->regmap, RT1318_DA_VOL_R_8,
rt1318->rt1318_dvol>> 8);Review
Quoted 2 lines
(quoted diff) +2
-0+ regmap_write(rt1318->regmap, RT1318_DA_VOL_R_1_7, +rt1318->rt1318_dvol & 0xff);This will happily accept negative values which you probably don't want.
I'll do modification regarding to it.
Quoted 8 lines
sound/soc/codecs/rt1318.c line 565
Quoted 4 lines
sound/soc/codecs/rt1318.c new file +3
-0+ }else { + rt1318->rt1318_dvol =RT1318_DVOL_STEP ; +dev_err (component->dev,"Unsupported volume gain\n" );The driver shouldn't allow userspace to spam the kernel log like this, it can be used to mask issues.
I'll remove this "else" condition.
Quoted 6 lines
sound/soc/codecs/rt1318.c line 584
Quoted 3 lines
sound/soc/codecs/rt1318.c new file +3
-0+static const struct snd_kcontrol_new rt1318_snd_controls[] = { +SOC_SINGLE_EXT ("rt1318 digital volume" ,SND_SOC_NOPM ,0 ,383 ,0 , + rt1318_dvol_get, rt1318_dvol_put),No need to include the part number in controls, users aren't going to care. The general style for ALSA controls is capitalised too.
Will remove part number.
Quoted 1 line · Jack Yu
This is the initial amplifier driver for rt1318.
There is already a driver for the rt1318 in SoundWire mode, contributed back in November 2022, this seems to be an I2S-based version.
Are all parts independent and interface-specific, or would there be opportunities to share common parts, if any?
Quoted 15 lines
-----Original Message-----
From: Pierre-Louis Bossart <[email protected]>
Sent: Tuesday, June 4, 2024 11:29 PM
To: Jack Yu <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; [email protected]; Flove(HsinFu) <[email protected]>; Oder Chiou <[email protected]>; Shuming [范書 銘] <[email protected]>; Derek [方德義] <[email protected]>
Subject: Re: [PATCH] ASoC: rt1318: Add RT1318 audio amplifier driverExternal mail.
Quoted 8 lines
Quoted 1 line · Jack Yu
This is the initial amplifier driver for rt1318.
There is already a driver for the rt1318 in SoundWire mode, contributed back in November 2022, this seems to be an I2S-based version.
Are all parts independent and interface-specific, or would there be opportunities to share common parts, if any?
The settings for i2s-based driver are quite different, so we prefer to use separate files for better management.
sound/soc/codecs/rt1318.c line 37
Quoted 6 lines
sound/soc/codecs/rt1318.c new file +5
-0+struct rt1318_init_reg { +u32 reg; +u8 val; +u8 delay; +};
That looks like a 'struct reg_sequence' ?
Quoted 4 lines
sound/soc/codecs/rt1318.c new file +4
-0+static struct rt1318_init_reg init_list[] = { + {0x0000C000 ,0x01 ,0 }, + {0x0000F20D ,0x00 ,0 }, + {0x0000F212 ,0x3E ,0 },
...
Quoted 19 lines
sound/soc/codecs/rt1318.c new file +19
-0+ +static int rt1318_reg_init (struct snd_soc_component *component) +{ +struct rt1318_priv *rt1318 =snd_soc_component_get_drvdata (component); +int i; + +for (i =0 ; i < rt1318_INIT_REG_LEN; i++) { +regmap_write (rt1318->regmap, init_list[i].reg, init_list[i].val); +mdelay (init_list[i].delay); + } + +return 0 ; +} + +static const struct reg_default rt1318_reg[] = { + {0xc000 ,0x00 }, + {0xc001 ,0x43 }, + {0xc003 ,0x22 }, + {0xc004 ,0x44 },
...
sound/soc/codecs/rt1318.c line 407
Quoted 4 lines
sound/soc/codecs/rt1318.c new file +4
-0+ { 0xf20d, 0x00 }, + { 0xf212, 0x00 }, + { 0xf21a, 0x00 }, + { 0xf223, 0x40 },
And this looks to me as as a set of defaults patches by a reg_sequence - similar to what is done for rt1308 and rt1316.
Is there any opportunity to use regmap_register_patch() instead of open-coding the loop?
Quoted 43 lines
sound/soc/codecs/rt1318.c line 37
Quoted 5 lines
sound/soc/codecs/rt1318.c new file +5
-0+struct rt1318_init_reg { +u32 reg; +u8 val; +u8 delay; +};That looks like a 'struct
reg_sequence' ?Quoted 4 lines
sound/soc/codecs/rt1318.c new file +4
-0+static struct rt1318_init_reg init_list[] = { + {0x0000C000 ,0x01 ,0 }, + {0x0000F20D ,0x00 ,0 }, + {0x0000F212 ,0x3E ,0 },...
sound/soc/codecs/rt1318.c line 1318
Quoted 3 lines
sound/soc/codecs/rt1318.c new file +3
-0+ +static int rt1318_reg_init (struct snd_soc_component *component) { + struct rt1318_priv *rt1318 =
snd_soc_component_get_drvdata(component);sound/soc/codecs/rt1318.c
Quoted 4 lines
sound/soc/codecs/rt1318.c new file +4
-0+int i; + +for (i =0 ; i < rt1318_INIT_REG_LEN; i++) { + regmap_write(rt1318->regmap, init_list[i].reg,init_list[i].val);
Quoted 11 lines
sound/soc/codecs/rt1318.c new file +11
-0+mdelay (init_list[i].delay); + } + +return 0 ; +} + +static const struct reg_default rt1318_reg[] = { + {0xc000 ,0x00 }, + {0xc001 ,0x43 }, + {0xc003 ,0x22 }, + {0xc004 ,0x44 },...
sound/soc/codecs/rt1318.c line 407
Quoted 4 lines
sound/soc/codecs/rt1318.c new file +4
-0+ { 0xf20d, 0x00 }, + { 0xf212, 0x00 }, + { 0xf21a, 0x00 }, + { 0xf223, 0x40 },
Quoted 5 lines
And this looks to me as as a set of defaults patches by a
reg_sequence- similar to what is done for rt1308 and rt1316.Is there any opportunity to use
regmap_register_patch()instead of open-coding the loop?
OK, I'll include this modification in the v2 patch, thanks.