Skip to contentSkip to conversation

ASoC: rt766: add RT766/RT767 SDCA driver

PATCH Superseded [email protected] 2 participants 4 messages Jul 31 – Aug 3

Subsystems (3)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 ASoC: rt766: add RT766/RT767 SDCA driver

From: Shuming Fan <[email protected]>

This patch adds the initial SDCA multi-function codec driver for the RT766 and RT767.

---
 sound/soc/codecs/Kconfig          |   10 +
 sound/soc/codecs/Makefile         |    2 +
 sound/soc/codecs/rt766-sdca-sdw.c |  339 +++++++
 sound/soc/codecs/rt766-sdca-sdw.h |   61 ++
 sound/soc/codecs/rt766-sdca.c     | 1361 +++++++++++++++++++++++++++++
 sound/soc/codecs/rt766-sdca.h     |  138 +++
 6 files changed, 1911 insertions(+)
 create mode 100644 sound/soc/codecs/rt766-sdca-sdw.c
 create mode 100644 sound/soc/codecs/rt766-sdca-sdw.h
 create mode 100644 sound/soc/codecs/rt766-sdca.c
 create mode 100644 sound/soc/codecs/rt766-sdca.h
sound/soc/codecs/Kconfig +10 -0
index bfd81ca89110..5a9c58bbc8d7 100644
@@ -238,6 +238,7 @@ config SND_SOC_ALL_CODECS
 	imply SND_SOC_RT715_SDCA_SDW
 	imply SND_SOC_RT721_SDCA_SDW
 	imply SND_SOC_RT722_SDCA_SDW
+	imply SND_SOC_RT766_SDCA_SDW
 	imply SND_SOC_RT1308_SDW
 	imply SND_SOC_RT1316_SDW
 	imply SND_SOC_RT1318
@@ -1983,6 +1984,15 @@ config SND_SOC_RT715_SDCA_SDW
 	select REGMAP_SOUNDWIRE
 	select REGMAP_SOUNDWIRE_MBQ
 
+config SND_SOC_RT766_SDCA_SDW
+	tristate "Realtek RT766 SDCA Codec - SDW"
+	depends on SOUNDWIRE
+	depends on SND_SOC_SDCA
+	select SND_SOC_SDCA_HID
+	select SND_SOC_SDCA_IRQ
+	select REGMAP_SOUNDWIRE
+	select REGMAP_SOUNDWIRE_MBQ
+
 config SND_SOC_RT9120
 	tristate "Richtek RT9120 Stereo Class-D Amplifier"
 	depends on I2C
sound/soc/codecs/Makefile +2 -0
index d2a689006d69..9c4b822b5197 100644
@@ -285,6 +285,7 @@ snd-soc-rt715-y := rt715.o rt715-sdw.o
 snd-soc-rt715-sdca-y := rt715-sdca.o rt715-sdca-sdw.o
 snd-soc-rt721-sdca-y := rt721-sdca.o rt721-sdca-sdw.o
 snd-soc-rt722-sdca-y := rt722-sdca.o rt722-sdca-sdw.o
+snd-soc-rt766-sdca-y := rt766-sdca.o rt766-sdca-sdw.o
 snd-soc-rt9120-y := rt9120.o
 snd-soc-rt9123-y := rt9123.o
 snd-soc-rt9123p-y := rt9123p.o
@@ -726,6 +727,7 @@ obj-$(CONFIG_SND_SOC_RT715)     += snd-soc-rt715.o
 obj-$(CONFIG_SND_SOC_RT715_SDCA_SDW)     += snd-soc-rt715-sdca.o
 obj-$(CONFIG_SND_SOC_RT721_SDCA_SDW)     += snd-soc-rt721-sdca.o
 obj-$(CONFIG_SND_SOC_RT722_SDCA_SDW)     += snd-soc-rt722-sdca.o
+obj-$(CONFIG_SND_SOC_RT766_SDCA_SDW)     += snd-soc-rt766-sdca.o
 obj-$(CONFIG_SND_SOC_RT9120)	+= snd-soc-rt9120.o
 obj-$(CONFIG_SND_SOC_RT9123)	+= snd-soc-rt9123.o
 obj-$(CONFIG_SND_SOC_RT9123P)	+= snd-soc-rt9123p.o
sound/soc/codecs/rt766-sdca-sdw.c new file +339 -0

339 lines not on this page · raw message

sound/soc/codecs/rt766-sdca-sdw.h new file +61 -0

61 lines not on this page · raw message

sound/soc/codecs/rt766-sdca.c new file +1361 -0

1,361 lines not on this page · raw message

sound/soc/codecs/rt766-sdca.h new file +138 -0

138 lines not on this page · raw message

Signature · 1 line
2.54.0
#1 lore raw
Quoted 41 lines · On Fri, Jul 31, 2026 at 05:10:37PM +0800, [email protected] wrote:
sound/soc/codecs/rt766-sdca.c new file +41 -0
+static int rt766_sdca_irq_ctl(struct rt766_sdca_priv *rt766,
+							  struct sdca_function_data *function,
+							  struct snd_soc_component *component,
+							  struct sdca_interrupt_info *info,
+							  bool enabled)
+{
+	struct device *dev = &rt766->slave->dev;
+	struct sdca_interrupt *interrupt;
+	struct sdca_control *control;
+	struct sdca_entity *entity;
+	irq_handler_t handler;
+	int i, j, irq, ret;
+
+	for (i = 0; i < function->num_entities; i++) {
+		entity = &function->entities[i];
+
+		for (j = 0; j < entity->num_controls; j++) {
+			control = &entity->controls[j];
+			irq = control->interrupt_position;
+
+			switch (SDCA_CTL_TYPE(entity->type, control->sel)) {
+			case SDCA_CTL_TYPE_S(GE, DETECTED_MODE):
+				handler = rt766_sdca_irq_jd_handler;
+				break;
+			case SDCA_CTL_TYPE_S(HIDE, HIDTX_CURRENTOWNER):
+				handler = rt766_sdca_irq_btn_handler;
+				break;
+			default:
+				continue;
+			}
+
+			interrupt = &info->irqs[irq];
+
+			if (enabled) {
+				ret = sdca_irq_data_populate(dev, rt766->regmap, component,
+								function, entity, control,
+								interrupt);
+				if (ret)
+					return ret;
+
+				interrupt->priv = rt766;

sound/soc/codecs/rt766-sdca.c line 244

Quoted 10 lines
sound/soc/codecs/rt766-sdca.c new file +10 -0
+				ret = sdca_irq_request(dev, info, irq, interrupt->name,
+								handler, interrupt);
+				if (ret) {
+					dev_err(dev, "failed to request irq %s: %d\n",
+						interrupt->name, ret);
+					return ret;
+				}
+				dev_dbg(dev, "Requesting IRQ %d InterruptName=%s\n", irq, interrupt->name);
+			} else {
+				sdca_irq_free(dev, info, irq, interrupt->name, interrupt);

You need to also free the IRQ name allocated by sdca_irq_data_populate() here or it will leak if the jack is re-enabled.

sound/soc/codecs/rt766-sdca.c line 887

Quoted 7 lines
sound/soc/codecs/rt766-sdca.c new file +7 -0
+static void rt766_sdca_remove(struct snd_soc_component *component)
+{
+	struct rt766_sdca_priv *rt766  = snd_soc_component_get_drvdata(component);
+
+	sdca_irq_cleanup(component->dev, rt766->uaj_func_data, rt766->irq_info);
+	sdca_irq_cleanup(component->dev, rt766->hid_func_data, rt766->irq_info);
+}

These should be sdca_irq_cleanup_late(), to ensure they free the names as well. Although, worth noting this only does anything if rt766_sdca_set_jack_detect() didn't already clean everything up, not sure if that is guaranteed or not.

Thanks,
Charles

#2 lore raw
Quoted 62 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+static int rt766_sdca_irq_ctl(struct rt766_sdca_priv *rt766,
+                                                       struct

sdca_function_data *function,

Quoted 1 line

+ struct

snd_soc_component *component,

Quoted 1 line

+ struct

sdca_interrupt_info *info,

Quoted 1 line

+ bool

enabled)

Quoted 6 lines
sound/soc/codecs/rt766-sdca.c new file +6 -0
+{
+     struct device *dev = &rt766->slave->dev;
+     struct sdca_interrupt *interrupt;
+     struct sdca_control *control;
+     struct sdca_entity *entity;
+     irq_handler_t handler;

sound/soc/codecs/rt766-sdca.c

Quoted 10 lines
sound/soc/codecs/rt766-sdca.c new file +10 -0
+     int i, j, irq, ret;
+
+     for (i = 0; i < function->num_entities; i++) {
+             entity = &function->entities[i];
+
+             for (j = 0; j < entity->num_controls; j++) {
+                     control = &entity->controls[j];
+                     irq = control->interrupt_position;
+
+                     switch (SDCA_CTL_TYPE(entity->type,

control->sel)) {

sound/soc/codecs/rt766-sdca.c

Quoted 4 lines
sound/soc/codecs/rt766-sdca.c new file +4 -0
+                     case SDCA_CTL_TYPE_S(GE, DETECTED_MODE):
+                             handler = rt766_sdca_irq_jd_handler;
+                             break;
+                     case SDCA_CTL_TYPE_S(HIDE,

HIDTX_CURRENTOWNER):

sound/soc/codecs/rt766-sdca.c

Quoted 10 lines
sound/soc/codecs/rt766-sdca.c new file +10 -0
+                             handler = rt766_sdca_irq_btn_handler;
+                             break;
+                     default:
+                             continue;
+                     }
+
+                     interrupt = &info->irqs[irq];
+
+                     if (enabled) {
+                             ret = sdca_irq_data_populate(dev,

rt766->regmap, component,

Quoted 1 line

+

function, entity, control,

Quoted 1 line

+

interrupt);

sound/soc/codecs/rt766-sdca.c

Quoted 5 lines
sound/soc/codecs/rt766-sdca.c new file +5 -0
+                             if (ret)
+                                     return ret;
+
+                             interrupt->priv = rt766;
+                             ret = sdca_irq_request(dev, info, irq,

interrupt->name,

Quoted 1 line

+

handler, interrupt);

Review

Quoted 2 lines
(quoted diff) +2 -0
+                             if (ret) {
+                                     dev_err(dev, "failed to

request irq %s: %d\n",

Quoted 1 line

+ interrupt->name,

ret);

sound/soc/codecs/rt766-sdca-sdw.c

Quoted 3 lines
sound/soc/codecs/rt766-sdca-sdw.c new file +3 -0
+                                     return ret;
+                             }
+                             dev_dbg(dev, "Requesting IRQ %d
Quoted 7 lines

InterruptName=%s\n", irq, interrupt->name);

Review

Quoted 3 lines
(quoted diff) +3 -0
+                     } else {
+                             sdca_irq_free(dev, info, irq,
+ interrupt->name, interrupt);

You need to also free the IRQ name allocated by sdca_irq_data_populate() here or it will leak if the jack is re-enabled.

Thanks for review.
I will call sdca_irq_cleanup() to free the IRQ.

Quoted 6 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+static void rt766_sdca_remove(struct snd_soc_component *component) {
+     struct rt766_sdca_priv *rt766  =
+snd_soc_component_get_drvdata(component);
+
+     sdca_irq_cleanup(component->dev, rt766->uaj_func_data,

rt766->irq_info);

Quoted 7 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+     sdca_irq_cleanup(component->dev, rt766->hid_func_data,
+rt766->irq_info); }

These should be sdca_irq_cleanup_late(), to ensure they free the names as well. Although, worth noting this only does anything if rt766_sdca_set_jack_detect() didn't already clean everything up, not sure if that is guaranteed or not.

Sure, will use sdca_irq_cleanup_late().

Quoted 2 lines

Thanks,
Charles

#3 lore raw
Quoted 9 lines · Shuming [范書銘]
Quoted 6 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+                     } else {
+                             sdca_irq_free(dev, info, irq,
+ interrupt->name, interrupt);

You need to also free the IRQ name allocated by sdca_irq_data_populate() here or it will leak if the jack is re-enabled.

Thanks for review.
I will call sdca_irq_cleanup() to free the IRQ.

Would need to be cleanup_late to free the name.

Thanks,
Charles