Skip to content

Commit

Permalink
vc4: Add jack detection to HDMI audio driver
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
cillian64 authored and popcornmix committed Feb 5, 2025
1 parent 8c5a1ee commit 5745a67
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
27 changes: 25 additions & 2 deletions drivers/gpu/drm/vc4/vc4_hdmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include <linux/reset.h>
#include <sound/dmaengine_pcm.h>
#include <sound/hdmi-codec.h>
#include <sound/jack.h>
#include <sound/pcm_drm_eld.h>
#include <sound/pcm_params.h>
#include <sound/soc.h>
Expand Down Expand Up @@ -392,6 +393,12 @@ static void vc4_hdmi_handle_hotplug(struct vc4_hdmi *vc4_hdmi,
struct drm_connector *connector = &vc4_hdmi->connector;
int ret;

/*
* Needs to be called for both connects and disconnects for HDMI
* audio hotplug to work correctly.
*/
drm_atomic_helper_connector_hdmi_hotplug(connector, status);

/*
* NOTE: This function should really be called with vc4_hdmi->mutex
* held, but doing so results in reentrancy issues since
Expand All @@ -411,8 +418,6 @@ static void vc4_hdmi_handle_hotplug(struct vc4_hdmi *vc4_hdmi,
return;
}

drm_atomic_helper_connector_hdmi_hotplug(connector, status);

cec_s_phys_addr(vc4_hdmi->cec_adap,
connector->display_info.source_physical_address, false);

Expand Down Expand Up @@ -2234,6 +2239,22 @@ static const struct drm_connector_hdmi_audio_funcs vc4_hdmi_audio_funcs = {
.shutdown = vc4_hdmi_audio_shutdown,
};

static int vc4_hdmi_codec_init(struct snd_soc_pcm_runtime *rtd)
{
struct vc4_hdmi *vc4_hdmi = snd_soc_card_get_drvdata(rtd->card);
struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component;
int ret;

ret = snd_soc_card_jack_new(rtd->card, "HDMI Jack", SND_JACK_LINEOUT,
&vc4_hdmi->hdmi_jack);
if (ret) {
dev_err(rtd->dev, "HDMI Jack creation failed: %d\n", ret);
return ret;
}

return snd_soc_component_set_jack(component, &vc4_hdmi->hdmi_jack, NULL);
}

static int vc4_hdmi_audio_init(struct vc4_hdmi *vc4_hdmi)
{
const struct vc4_hdmi_register *mai_data =
Expand Down Expand Up @@ -2348,6 +2369,8 @@ static int vc4_hdmi_audio_init(struct vc4_hdmi *vc4_hdmi)
dai_link->codecs->name = dev_name(&vc4_hdmi->connector.hdmi_audio.codec_pdev->dev);
dai_link->platforms->name = dev_name(dev);

dai_link->init = vc4_hdmi_codec_init;

card->dai_link = dai_link;
card->num_links = 1;
card->name = vc4_hdmi->variant->card_name;
Expand Down
7 changes: 7 additions & 0 deletions drivers/gpu/drm/vc4/vc4_hdmi.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <drm/drm_connector.h>
#include <media/cec.h>
#include <sound/dmaengine_pcm.h>
#include <sound/hdmi-codec.h>
#include <sound/soc.h>

#include "vc4_drv.h"
Expand Down Expand Up @@ -215,6 +216,12 @@ struct vc4_hdmi {
* KMS hooks. Protected by @mutex.
*/
enum hdmi_colorspace output_format;

/**
* @hdmi_jack: Represents the connection state of the HDMI plug, for
* ALSA jack detection.
*/
struct snd_soc_jack hdmi_jack;
};

#define connector_to_vc4_hdmi(_connector) \
Expand Down

0 comments on commit 5745a67

Please sign in to comment.