Skip to content

Commit 5745a67

Browse files
cillian64popcornmix
authored andcommitted
vc4: Add jack detection to HDMI audio driver
Add ALSA jack detection to the vc4-hdmi audio driver so userspace knows when to add/remove HDMI audio devices. Signed-off-by: David Turner <[email protected]>
1 parent 8c5a1ee commit 5745a67

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

drivers/gpu/drm/vc4/vc4_hdmi.c

+25-2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include <linux/reset.h>
5454
#include <sound/dmaengine_pcm.h>
5555
#include <sound/hdmi-codec.h>
56+
#include <sound/jack.h>
5657
#include <sound/pcm_drm_eld.h>
5758
#include <sound/pcm_params.h>
5859
#include <sound/soc.h>
@@ -392,6 +393,12 @@ static void vc4_hdmi_handle_hotplug(struct vc4_hdmi *vc4_hdmi,
392393
struct drm_connector *connector = &vc4_hdmi->connector;
393394
int ret;
394395

396+
/*
397+
* Needs to be called for both connects and disconnects for HDMI
398+
* audio hotplug to work correctly.
399+
*/
400+
drm_atomic_helper_connector_hdmi_hotplug(connector, status);
401+
395402
/*
396403
* NOTE: This function should really be called with vc4_hdmi->mutex
397404
* held, but doing so results in reentrancy issues since
@@ -411,8 +418,6 @@ static void vc4_hdmi_handle_hotplug(struct vc4_hdmi *vc4_hdmi,
411418
return;
412419
}
413420

414-
drm_atomic_helper_connector_hdmi_hotplug(connector, status);
415-
416421
cec_s_phys_addr(vc4_hdmi->cec_adap,
417422
connector->display_info.source_physical_address, false);
418423

@@ -2234,6 +2239,22 @@ static const struct drm_connector_hdmi_audio_funcs vc4_hdmi_audio_funcs = {
22342239
.shutdown = vc4_hdmi_audio_shutdown,
22352240
};
22362241

2242+
static int vc4_hdmi_codec_init(struct snd_soc_pcm_runtime *rtd)
2243+
{
2244+
struct vc4_hdmi *vc4_hdmi = snd_soc_card_get_drvdata(rtd->card);
2245+
struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component;
2246+
int ret;
2247+
2248+
ret = snd_soc_card_jack_new(rtd->card, "HDMI Jack", SND_JACK_LINEOUT,
2249+
&vc4_hdmi->hdmi_jack);
2250+
if (ret) {
2251+
dev_err(rtd->dev, "HDMI Jack creation failed: %d\n", ret);
2252+
return ret;
2253+
}
2254+
2255+
return snd_soc_component_set_jack(component, &vc4_hdmi->hdmi_jack, NULL);
2256+
}
2257+
22372258
static int vc4_hdmi_audio_init(struct vc4_hdmi *vc4_hdmi)
22382259
{
22392260
const struct vc4_hdmi_register *mai_data =
@@ -2348,6 +2369,8 @@ static int vc4_hdmi_audio_init(struct vc4_hdmi *vc4_hdmi)
23482369
dai_link->codecs->name = dev_name(&vc4_hdmi->connector.hdmi_audio.codec_pdev->dev);
23492370
dai_link->platforms->name = dev_name(dev);
23502371

2372+
dai_link->init = vc4_hdmi_codec_init;
2373+
23512374
card->dai_link = dai_link;
23522375
card->num_links = 1;
23532376
card->name = vc4_hdmi->variant->card_name;

drivers/gpu/drm/vc4/vc4_hdmi.h

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <drm/drm_connector.h>
55
#include <media/cec.h>
66
#include <sound/dmaengine_pcm.h>
7+
#include <sound/hdmi-codec.h>
78
#include <sound/soc.h>
89

910
#include "vc4_drv.h"
@@ -215,6 +216,12 @@ struct vc4_hdmi {
215216
* KMS hooks. Protected by @mutex.
216217
*/
217218
enum hdmi_colorspace output_format;
219+
220+
/**
221+
* @hdmi_jack: Represents the connection state of the HDMI plug, for
222+
* ALSA jack detection.
223+
*/
224+
struct snd_soc_jack hdmi_jack;
218225
};
219226

220227
#define connector_to_vc4_hdmi(_connector) \

0 commit comments

Comments
 (0)