Add HDMI jack support on RK3288
Subsystems (6)
v2 cover Add HDMI jack support on RK3288
This patch series supports HDMI jack reporting on RK3288, which uses DRM dw-hdmi driver and hdmi-codec codec driver.
The previous discussion about reporting jack status using hdmi-notifier and drm_audio_component is at
https://lore.kernel.org/patchwork/patch/1083027/
The new approach is to use a callback mechanism that is specific to hdmi-codec.
Changes from v1 to v2:
- hdmi-codec.c: cleanup the sequence of hdmi_codec_jack_report and hdmi_codec_set_jack_detect.
- dw-hdmi.c: change argument of hdmi_codec_plugged_cb so it takes a generic device which has hdmi_codec_priv in its drvdata.
- dw-hdmi.c: add a helper function handle_plugged_change to check audio platform device and codec platform device before calling callback.
- dw-hdmi-c: avoid setting callback function if audio platform device or codec platform device is missing.
- rockchip_max98090: fix the checking of return code when setting sysclk on cpu_dai and codec_dai. cpu_dai error should be reported. For HDMI codec_dai, there is no need to set sysclk.
Cheng-Yi Chiang (4):
ASoC: hdmi-codec: Add an op to set callback function for plug event
drm: bridge: dw-hdmi: Report connector status using callback
ASoC: rockchip_max98090: Add dai_link for HDMI
ASoC: rockchip_max98090: Add HDMI jack support
.../gpu/drm/bridge/synopsys/dw-hdmi-audio.h | 3 + .../drm/bridge/synopsys/dw-hdmi-i2s-audio.c | 10 ++ drivers/gpu/drm/bridge/synopsys/dw-hdmi.c | 55 ++++++++- include/sound/hdmi-codec.h | 16 +++ sound/soc/codecs/hdmi-codec.c | 45 +++++++ sound/soc/rockchip/rockchip_max98090.c | 116 ++++++++++++++---- 6 files changed, 221 insertions(+), 24 deletions(-)
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v2 1/4 ASoC: hdmi-codec: Add an op to set callback function for plug event
Add an op in hdmi_codec_ops so codec driver can register callback function to handle plug event.
Driver in DRM can use this callback function to report connector status.
--- include/sound/hdmi-codec.h | 16 +++++++++++++ sound/soc/codecs/hdmi-codec.c | 45 +++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+)
include/sound/hdmi-codec.h +16 -0
@@ -47,6 +47,9 @@ struct hdmi_codec_params {int channels; }; +typedef void (*hdmi_codec_plugged_cb )(struct device *dev, +bool plugged); +struct hdmi_codec_pdata ;struct hdmi_codec_ops {/*
@@ -88,6 +91,13 @@ struct hdmi_codec_ops {*/ int (*get_dai_id)(struct snd_soc_component *comment,struct device_node *endpoint); + +/* +* Hook callback function to handle connector plug event. +* Optional +*/ +int (*hook_plugged_cb)(struct device *dev,void *data, +hdmi_codec_plugged_cb fn); };/* HDMI codec initalization data */
@@ -99,6 +109,12 @@ struct hdmi_codec_pdata { void *data; }; +struct snd_soc_component ; +struct snd_soc_jack ; + +int hdmi_codec_set_jack_detect (struct snd_soc_component *component, +struct snd_soc_jack *jack); +#define HDMI_CODEC_DRV_NAME "hdmi-audio-codec"#endif /* __HDMI_CODEC_H__ */
sound/soc/codecs/hdmi-codec.c +45 -0
63 lines not on this page · raw message
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v2 2/4 drm: bridge: dw-hdmi: Report connector status using callback
In reply to Cheng-Yi ChiangAllow codec driver register callback function for plug event.
The callback registration flow:
dw-hdmi <--- hw-hdmi-i2s-audio <--- hdmi-codec
dw-hdmi-i2s-audio implements hook_plugged_cb op
so codec driver can register the callback.
dw-hdmi implements set_plugged_cb op so platform device can register the callback.
When connector plug/unplug event happens, report this event using the callback.
Make sure that audio and drm are using the single source of truth for connector status.
--- .../gpu/drm/bridge/synopsys/dw-hdmi-audio.h | 3 + .../drm/bridge/synopsys/dw-hdmi-i2s-audio.c | 10 ++++ drivers/gpu/drm/bridge/synopsys/dw-hdmi.c | 55 ++++++++++++++++++- 3 files changed, 67 insertions(+), 1 deletion(-)
drivers/gpu/drm/bridge/synopsys/dw-hdmi-audio.h +3 -0
@@ -2,6 +2,8 @@#ifndef DW_HDMI_AUDIO_H #define DW_HDMI_AUDIO_H +#include <sound/hdmi-codec.h> +struct dw_hdmi ; struct dw_hdmi_audio_data {
@@ -17,6 +19,7 @@ struct dw_hdmi_i2s_audio_data {void (*write)(struct dw_hdmi *hdmi,u8 val,int offset);u8 (*read)(struct dw_hdmi *hdmi,int offset); + int (*set_plugged_cb)(struct dw_hdmi *hdmi, hdmi_codec_plugged_cb fn); };#endif
drivers/gpu/drm/bridge/synopsys/dw-hdmi-i2s-audio.c +10 -0
@@ -104,10 +104,20 @@ static int dw_hdmi_i2s_get_dai_id(struct snd_soc_component *component,return -EINVAL ; } +static int dw_hdmi_i2s_hook_plugged_cb (struct device *dev,void *data, +hdmi_codec_plugged_cb fn) +{ +struct dw_hdmi_i2s_audio_data *audio = data; +struct dw_hdmi *hdmi = audio->hdmi; + +return audio->set_plugged_cb (hdmi, fn); +} +static struct hdmi_codec_ops dw_hdmi_i2s_ops = { .hw_params = dw_hdmi_i2s_hw_params, .audio_shutdown = dw_hdmi_i2s_audio_shutdown, .get_dai_id = dw_hdmi_i2s_get_dai_id, + .hook_plugged_cb = dw_hdmi_i2s_hook_plugged_cb, };static int snd_dw_hdmi_probe (struct platform_device *pdev)
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +54 -1
97 lines not on this page · raw message
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v2 3/4 ASoC: rockchip_max98090: Add dai_link for HDMI
In reply to Cheng-Yi ChiangUse two dai_links. One for HDMI and one for max98090. With this setup, audio can play to speaker and HDMI selectively.
--- sound/soc/rockchip/rockchip_max98090.c | 95 +++++++++++++++++++------- 1 file changed, 72 insertions(+), 23 deletions(-)
sound/soc/rockchip/rockchip_max98090.c +72 -23
@@ -41,6 +41,7 @@ static const struct snd_soc_dapm_widget rk_dapm_widgets[] = {SND_SOC_DAPM_MIC ("Headset Mic" ,NULL ),SND_SOC_DAPM_MIC ("Int Mic" ,NULL ),SND_SOC_DAPM_SPK ("Speaker" ,NULL ), + SND_SOC_DAPM_LINE("HDMI", NULL), }; static const struct snd_soc_dapm_route rk_audio_map[] = {
@@ -52,6 +53,7 @@ static const struct snd_soc_dapm_route rk_audio_map[] = { {"Headphone", NULL, "HPR"}, {"Speaker", NULL, "SPKL"}, {"Speaker", NULL, "SPKR"}, + {"HDMI", NULL, "TX"}, }; static const struct snd_kcontrol_new rk_mc_controls[] = {
@@ -59,6 +61,7 @@ static const struct snd_kcontrol_new rk_mc_controls[] = {SOC_DAPM_PIN_SWITCH ("Headset Mic" ),SOC_DAPM_PIN_SWITCH ("Int Mic" ),SOC_DAPM_PIN_SWITCH ("Speaker" ), + SOC_DAPM_PIN_SWITCH("HDMI"), }; static int rk_aif1_hw_params(struct snd_pcm_substream *substream,
@@ -92,38 +95,63 @@ static int rk_aif1_hw_params(struct snd_pcm_substream *substream, ret =snd_soc_dai_set_sysclk (cpu_dai,0 , mclk,SND_SOC_CLOCK_OUT ); -if (ret <0 ) { -dev_err (codec_dai->dev,"Can't set codec clock %d\n" , ret); +if (ret) { +dev_err (cpu_dai->dev,"Can't set cpu dai clock %d\n" , ret);return ret; } +/* HDMI codec dai does not need to set sysclk. */ +if (!strcmp (rtd->dai_link->name,"HDMI" )) +return 0 ; + ret =snd_soc_dai_set_sysclk (codec_dai,0 , mclk,SND_SOC_CLOCK_IN ); -if (ret <0 ) { -dev_err (codec_dai->dev,"Can't set codec clock %d\n" , ret); +if (ret) { +dev_err (codec_dai->dev,"Can't set codec dai clock %d\n" , ret);return ret; } -return ret; +return 0 ; }static const struct snd_soc_ops rk_aif1_ops = { .hw_params = rk_aif1_hw_params, }; -SND_SOC_DAILINK_DEFS (hifi, +SND_SOC_DAILINK_DEFS (analog,DAILINK_COMP_ARRAY (COMP_EMPTY ()),DAILINK_COMP_ARRAY (COMP_CODEC (NULL ,"HiFi" )),DAILINK_COMP_ARRAY (COMP_EMPTY ())); -static struct snd_soc_dai_link rk_dailink = { - .name ="max98090" , - .stream_name ="Audio" , - .ops = &rk_aif1_ops, -/* set max98090 as slave */ - .dai_fmt =SND_SOC_DAIFMT_I2S |SND_SOC_DAIFMT_NB_NF | -SND_SOC_DAIFMT_CBS_CFS , -SND_SOC_DAILINK_REG (hifi), +SND_SOC_DAILINK_DEFS (hdmi, +DAILINK_COMP_ARRAY (COMP_EMPTY ()), +DAILINK_COMP_ARRAY (COMP_CODEC ("hdmi-audio-codec.3.auto" ,"i2s-hifi" )), +DAILINK_COMP_ARRAY (COMP_EMPTY ())); + +enum { +DAILINK_MAX98090 , +DAILINK_HDMI , +}; + +/* max98090 and HDMI codec dai_link */ +static struct snd_soc_dai_link rk_dailinks[] = { + [DAILINK_MAX98090 ] = { + .name ="max98090" , + .stream_name ="Analog" , + .ops = &rk_aif1_ops, +/* set max98090 as slave */ + .dai_fmt =SND_SOC_DAIFMT_I2S |SND_SOC_DAIFMT_NB_NF | +SND_SOC_DAIFMT_CBS_CFS , +SND_SOC_DAILINK_REG (analog), + }, + [DAILINK_HDMI ] = { + .name ="HDMI" , + .stream_name ="HDMI" , + .ops = &rk_aif1_ops, + .dai_fmt =SND_SOC_DAIFMT_I2S |SND_SOC_DAIFMT_NB_NF | +SND_SOC_DAIFMT_CBS_CFS , +SND_SOC_DAILINK_REG (hdmi), + } };static int rk_98090_headset_init (struct snd_soc_component *component);
@@ -136,8 +164,8 @@ static struct snd_soc_aux_dev rk_98090_headset_dev = {static struct snd_soc_card snd_soc_card_rk = { .name ="ROCKCHIP-I2S" , .owner =THIS_MODULE , - .dai_link = &rk_dailink, - .num_links =1 , + .dai_link = rk_dailinks, + .num_links =ARRAY_SIZE (rk_dailinks), .aux_dev = &rk_98090_headset_dev, .num_aux_devs =1 , .dapm_widgets = rk_dapm_widgets,
@@ -173,27 +201,48 @@ static int snd_rk_mc_probe(struct platform_device *pdev)int ret =0 ;struct snd_soc_card *card = &snd_soc_card_rk;struct device_node *np = pdev->dev.of_node; +struct device_node *np_analog; +struct device_node *np_cpu; +struct of_phandle_args args;/* register the soc card */ card->dev = &pdev->dev; - rk_dailink.codecs->of_node =of_parse_phandle (np, -"rockchip,audio-codec" ,0 ); -if (!rk_dailink.codecs->of_node) { + np_analog =of_parse_phandle (np,"rockchip,audio-codec" ,0 ); +if (!np_analog) {dev_err (&pdev->dev,"Property 'rockchip,audio-codec' missing or invalid\n" );return -EINVAL ; } + rk_dailinks[DAILINK_MAX98090 ].codecs->of_node = np_analog; + + ret =of_parse_phandle_with_fixed_args (np,"rockchip,audio-codec" , +0 ,0 , &args); +if (ret) { +dev_err (&pdev->dev, +"Unable to parse property 'rockchip,audio-codec'\n" ); +return ret; + } + + ret =snd_soc_get_dai_name ( + &args, &rk_dailinks[DAILINK_MAX98090 ].codecs->dai_name); +if (ret) { +dev_err (&pdev->dev,"Unable to get codec dai_name\n" ); +return ret; + } + + np_cpu =of_parse_phandle (np,"rockchip,i2s-controller" ,0 ); - rk_dailink.cpus->of_node =of_parse_phandle (np, -"rockchip,i2s-controller" ,0 ); -if (!rk_dailink.cpus->of_node) { +if (!np_cpu) {dev_err (&pdev->dev,"Property 'rockchip,i2s-controller' missing or invalid\n" );return -EINVAL ; } - rk_dailink.platforms->of_node = rk_dailink.cpus->of_node; + rk_dailinks[DAILINK_MAX98090 ].cpus->of_node = np_cpu; + rk_dailinks[DAILINK_MAX98090 ].platforms->of_node = np_cpu; + rk_dailinks[DAILINK_HDMI ].cpus->of_node = np_cpu; + rk_dailinks[DAILINK_HDMI ].platforms->of_node = np_cpu; rk_98090_headset_dev.codec_of_node =of_parse_phandle (np,"rockchip,headset-codec" ,0 );
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v2 4/4 ASoC: rockchip_max98090: Add HDMI jack support
In reply to Cheng-Yi ChiangIn machine driver, create a jack and let hdmi-codec report jack status.
--- sound/soc/rockchip/rockchip_max98090.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
sound/soc/rockchip/rockchip_max98090.c +21 -0
@@ -15,6 +15,7 @@#include <sound/pcm.h> #include <sound/pcm_params.h> #include <sound/soc.h> +#include <sound/hdmi-codec.h> #include "rockchip_i2s.h" #include "../codecs/ts3a227e.h"
@@ -133,6 +134,25 @@ enum { DAILINK_HDMI, }; +static struct snd_soc_jack rk_hdmi_jack; + +static int rk_hdmi_init (struct snd_soc_pcm_runtime *runtime) +{ +struct snd_soc_card *card = runtime->card; +struct snd_soc_component *component = runtime->codec_dai->component; +int ret; + +/* enable jack detection */ + ret =snd_soc_card_jack_new (card,"HDMI Jack" ,SND_JACK_LINEOUT , + &rk_hdmi_jack,NULL ,0 ); +if (ret) { +dev_err (card->dev,"Can't new HDMI Jack %d\n" , ret); +return ret; + } + +return hdmi_codec_set_jack_detect (component, &rk_hdmi_jack); +} +/* max98090 and HDMI codec dai_link */ static struct snd_soc_dai_link rk_dailinks[] = { [DAILINK_MAX98090 ] = {
@@ -150,6 +170,7 @@ static struct snd_soc_dai_link rk_dailinks[] = { .ops = &rk_aif1_ops, .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS, + .init = rk_hdmi_init, SND_SOC_DAILINK_REG(hdmi), } };
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog