Skip to contentSkip to conversation

drm/rockchip: rk3066_hdmi: add sound support

PATCH Superseded Johan Jonker 2 participants 3 messages Jun 28, 2024 – Jun 29, 2024

Subsystems (5)

v7 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

PATCH v7 1/1 drm/rockchip: rk3066_hdmi: add sound support

Add sound support to the RK3066 HDMI driver.
The HDMI TX audio source is connected to I2S_8CH.

---

Changed V7:
rebase

---
 drivers/gpu/drm/rockchip/Kconfig       |   2 +
 drivers/gpu/drm/rockchip/rk3066_hdmi.c | 274 ++++++++++++++++++++++++-
 2 files changed, 275 insertions(+), 1 deletion(-)
drivers/gpu/drm/rockchip/Kconfig +2 -0
index 1bf3e2829cd0..a32ee558408c 100644
@@ -102,6 +102,8 @@ config ROCKCHIP_RGB
 config ROCKCHIP_RK3066_HDMI
 	bool "Rockchip specific extensions for RK3066 HDMI"
 	depends on DRM_ROCKCHIP
+	select SND_SOC_HDMI_CODEC if SND_SOC
+	select SND_SOC_ROCKCHIP_I2S if SND_SOC
 	help
 	  This selects support for Rockchip SoC specific extensions
 	  for the RK3066 HDMI driver. If you want to enable
drivers/gpu/drm/rockchip/rk3066_hdmi.c +273 -1

339 lines not on this page · raw message

--
2.39.2

maintainer
#1 lore raw

Hi Johan,

Quoted 58 lines · Johan Jonker

Add sound support to the RK3066 HDMI driver.
The HDMI TX audio source is connected to I2S_8CH.

---

Changed V7:
rebase
---
drivers/gpu/drm/rockchip/Kconfig | 2 +
drivers/gpu/drm/rockchip/rk3066_hdmi.c | 274 ++++++++++++++++++++++++-

2 files changed, 275 insertions(+), 1 deletion(-)
drivers/gpu/drm/rockchip/Kconfig +0 -0
index 1bf3e2829cd0..a32ee558408c 100644
@@ -102,6 +102,8 @@ config ROCKCHIP_RGB

config ROCKCHIP_RK3066_HDMI
bool "Rockchip specific extensions for RK3066 HDMI" depends on DRM_ROCKCHIP

drivers/gpu/drm/rockchip/Kconfig +2 -0
+	select SND_SOC_HDMI_CODEC if SND_SOC
+	select SND_SOC_ROCKCHIP_I2S if SND_SOC

help
This selects support for Rockchip SoC specific extensions for the RK3066 HDMI driver. If you want to enable

drivers/gpu/drm/rockchip/rk3066_hdmi.c +10 -0
index 784de990da1b..d3128b787629 100644
@@ -15,12 +15,20 @@
 #include <linux/platform_device.h>
 #include <linux/regmap.h>
 
+#include <sound/hdmi-codec.h>
+
 #include "rk3066_hdmi.h"
 
 #include "rockchip_drm_drv.h"
 
 #define DEFAULT_PLLA_RATE 30000000
 
+struct audio_info {
+	int channels;
+	int sample_rate;
+	int sample_width;
+};
+
 struct hdmi_data_info {
 	int vic; /* The CEA Video ID (VIC) of the current drm display mode. */
 	unsigned int enc_out_format;
@@ -54,9 +62,16 @@ struct rk3066_hdmi {
 
 	unsigned int tmdsclk;
 
+	struct platform_device *audio_pdev;
+	stru

......

Quoted 39 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c +35 -0
+
+	return ret;
+}
+
+static const struct hdmi_codec_ops audio_codec_ops = {
+	.hw_params = rk3066_hdmi_audio_hw_params,
+	.audio_shutdown = rk3066_hdmi_audio_shutdown,
+	.mute_stream = rk3066_hdmi_audio_mute_stream,
+	.get_eld = rk3066_hdmi_audio_get_eld,
+	.no_capture_mute = 1,
+};
+
+static int rk3066_hdmi_audio_codec_init(struct rk3066_hdmi *hdmi,
+					struct device *dev)
+{
+	struct hdmi_codec_pdata codec_data = {
+		.i2s = 1,
+		.ops = &audio_codec_ops,
+		.max_i2s_channels = 8,
+	};
+
+	hdmi->audio.channels = 2;
+	hdmi->audio.sample_rate = 48000;
+	hdmi->audio.sample_width = 16;
+	hdmi->audio_enable = false;
+	hdmi->audio_pdev =
+		platform_device_register_data(dev,
+					      HDMI_CODEC_DRV_NAME,
+					      PLATFORM_DEVID_NONE,
+					      &codec_data,
+					      sizeof(codec_data));
+
+	return PTR_ERR_OR_ZERO(hdmi->audio_pdev);
+}
+

static int
rk3066_hdmi_register(struct drm_device *drm, struct rk3066_hdmi *hdmi) {

drivers/gpu/drm/rockchip/rk3066_hdmi.c rk3066_hdmi_register(struct drm_device *drm, struct rk3066_hdmi *hdmi) · line 837

Quoted 4 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c +1 -0
@@ -566,6 +834,8 @@ rk3066_hdmi_register(struct drm_device *drm, struct rk3066_hdmi *hdmi)
 
 	drm_connector_attach_encoder(&hdmi->connector, encoder);
 
+	rk3066_hdmi_audio_codec_init(hdmi, dev);

According to Documentation/driver-api/driver-model/driver.rst,

It is best not to register at the bind callback:

.. warning::
-EPROBE_DEFER must not be returned if probe() has already created child devices, even if those child devices are removed again in a cleanup path. If -EPROBE_DEFER is returned after a child device has been registered, it may result in an infinite loop of .probe() calls to the same driver.

For example:
vop_probe --》component_add--》rk3066_hdmi_bind--》rk3066_hdmi_audio_codec_init--》hdmi_codec_probe--》rockchip_rgb_init(DEFER when panel not ready)

This may result in an infinite loop of probe

Quoted 23 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c +1 -0
+
 	return 0;
 }
 
@@ -813,6 +1083,7 @@ static int rk3066_hdmi_bind(struct device *dev, struct device *master,
 	return 0;
 

err_cleanup_hdmi:

drivers/gpu/drm/rockchip/rk3066_hdmi.c +1 -0
+	platform_device_unregister(hdmi->audio_pdev);
	hdmi->connector.funcs->destroy(&hdmi->connector);
	hdmi->encoder.encoder.funcs->destroy(&hdmi->encoder.encoder);

err_disable_i2c:

drivers/gpu/drm/rockchip/rk3066_hdmi.c +1 -1
@@ -828,6 +1099,7 @@ static void rk3066_hdmi_unbind(struct device *dev, struct device *master,
 {
 	struct rk3066_hdmi *hdmi = dev_get_drvdata(dev);
 
+	platform_device_unregister(hdmi->audio_pdev);
 	hdmi->connector.funcs->destroy(&hdmi->connector);
 	hdmi->encoder.encoder.funcs->destroy(&hdmi->encoder.encoder);
 
--

2.39.2

#2 lore raw

Hi Andy, thanks.

Quoted 107 lines · Andy Yan

Hi Johan,

Quoted 58 lines · Johan Jonker

Add sound support to the RK3066 HDMI driver.
The HDMI TX audio source is connected to I2S_8CH.

---

Changed V7:
rebase
---
drivers/gpu/drm/rockchip/Kconfig | 2 +
drivers/gpu/drm/rockchip/rk3066_hdmi.c | 274 ++++++++++++++++++++++++-

2 files changed, 275 insertions(+), 1 deletion(-)
drivers/gpu/drm/rockchip/Kconfig +0 -0
index 1bf3e2829cd0..a32ee558408c 100644
@@ -102,6 +102,8 @@ config ROCKCHIP_RGB

config ROCKCHIP_RK3066_HDMI
bool "Rockchip specific extensions for RK3066 HDMI" depends on DRM_ROCKCHIP

drivers/gpu/drm/rockchip/Kconfig +2 -0
+	select SND_SOC_HDMI_CODEC if SND_SOC
+	select SND_SOC_ROCKCHIP_I2S if SND_SOC

help
This selects support for Rockchip SoC specific extensions for the RK3066 HDMI driver. If you want to enable

drivers/gpu/drm/rockchip/rk3066_hdmi.c +10 -0
index 784de990da1b..d3128b787629 100644
@@ -15,12 +15,20 @@
 #include <linux/platform_device.h>
 #include <linux/regmap.h>
 
+#include <sound/hdmi-codec.h>
+
 #include "rk3066_hdmi.h"
 
 #include "rockchip_drm_drv.h"
 
 #define DEFAULT_PLLA_RATE 30000000
 
+struct audio_info {
+	int channels;
+	int sample_rate;
+	int sample_width;
+};
+
 struct hdmi_data_info {
 	int vic; /* The CEA Video ID (VIC) of the current drm display mode. */
 	unsigned int enc_out_format;
@@ -54,9 +62,16 @@ struct rk3066_hdmi {
 
 	unsigned int tmdsclk;
 
+	struct platform_device *audio_pdev;
+	stru

......

Quoted 42 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c +35 -0
+
+	return ret;
+}
+
+static const struct hdmi_codec_ops audio_codec_ops = {
+	.hw_params = rk3066_hdmi_audio_hw_params,
+	.audio_shutdown = rk3066_hdmi_audio_shutdown,
+	.mute_stream = rk3066_hdmi_audio_mute_stream,
+	.get_eld = rk3066_hdmi_audio_get_eld,
+	.no_capture_mute = 1,
+};
+
+static int rk3066_hdmi_audio_codec_init(struct rk3066_hdmi *hdmi,
+					struct device *dev)
+{
+	struct hdmi_codec_pdata codec_data = {
+		.i2s = 1,
+		.ops = &audio_codec_ops,
+		.max_i2s_channels = 8,
+	};
+
+	hdmi->audio.channels = 2;
+	hdmi->audio.sample_rate = 48000;
+	hdmi->audio.sample_width = 16;
+	hdmi->audio_enable = false;
+	hdmi->audio_pdev =
+		platform_device_register_data(dev,
+					      HDMI_CODEC_DRV_NAME,
+					      PLATFORM_DEVID_NONE,
+					      &codec_data,
+					      sizeof(codec_data));
+
+	return PTR_ERR_OR_ZERO(hdmi->audio_pdev);
+}
+

static int
rk3066_hdmi_register(struct drm_device *drm, struct rk3066_hdmi *hdmi) {

drivers/gpu/drm/rockchip/rk3066_hdmi.c +0 -0
@@ -566,6 +834,8 @@ rk3066_hdmi_register(struct drm_device *drm, struct rk3066_hdmi *hdmi)
 
 	drm_connector_attach_encoder(&hdmi->connector, encoder);
 
Quoted 7 lines

drivers/gpu/drm/rockchip/rk3066_hdmi.c rk3066_hdmi_register(struct drm_device *drm, struct rk3066_hdmi *hdmi) · line 837

Quoted 1 line
drivers/gpu/drm/rockchip/rk3066_hdmi.c +1 -0
+	rk3066_hdmi_audio_codec_init(hdmi, dev);

According to Documentation/driver-api/driver-model/driver.rst,

It is best not to register at the bind callback:

Question for the DRM experts:
What would be the correct location/level for the rk3066_hdmi_audio_codec_init() function? Is that at the rk3066_hdmi_encoder_enable() function?
Are there other functions/examples for sound in the DRM toolbox?

Johan

Quoted 37 lines

.. warning::
-EPROBE_DEFER must not be returned if probe() has already created child devices, even if those child devices are removed again in a cleanup path. If -EPROBE_DEFER is returned after a child device has been registered, it may result in an infinite loop of .probe() calls to the same driver.

For example:
vop_probe --》component_add--》rk3066_hdmi_bind--》rk3066_hdmi_audio_codec_init--》hdmi_codec_probe--》rockchip_rgb_init(DEFER when panel not ready)

This may result in an infinite loop of probe

Quoted 23 lines
drivers/gpu/drm/rockchip/rk3066_hdmi.c +1 -0
+
 	return 0;
 }
 
@@ -813,6 +1083,7 @@ static int rk3066_hdmi_bind(struct device *dev, struct device *master,
 	return 0;
 

err_cleanup_hdmi:

drivers/gpu/drm/rockchip/rk3066_hdmi.c +1 -0
+	platform_device_unregister(hdmi->audio_pdev);
	hdmi->connector.funcs->destroy(&hdmi->connector);
	hdmi->encoder.encoder.funcs->destroy(&hdmi->encoder.encoder);

err_disable_i2c:

drivers/gpu/drm/rockchip/rk3066_hdmi.c +1 -1
@@ -828,6 +1099,7 @@ static void rk3066_hdmi_unbind(struct device *dev, struct device *master,
 {
 	struct rk3066_hdmi *hdmi = dev_get_drvdata(dev);
 
+	platform_device_unregister(hdmi->audio_pdev);
 	hdmi->connector.funcs->destroy(&hdmi->connector);
 	hdmi->encoder.encoder.funcs->destroy(&hdmi->encoder.encoder);
 
--

2.39.2