drm: bridge: dw-hdmi: Report connector status using callback
Allow 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 exports a function dw_hdmi_set_plugged_cb 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. Signed-off-by: Cheng-Yi Chiang <cychiang@chromium.org> Link: https://lore.kernel.org/r/20191028071930.145899-2-cychiang@chromium.org Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
parent
c3ad1092e1
commit
a9c82d63ca
|
@ -151,11 +151,22 @@ 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 device *codec_dev)
|
||||
{
|
||||
struct dw_hdmi_i2s_audio_data *audio = data;
|
||||
struct dw_hdmi *hdmi = audio->hdmi;
|
||||
|
||||
return dw_hdmi_set_plugged_cb(hdmi, fn, codec_dev);
|
||||
}
|
||||
|
||||
static struct hdmi_codec_ops dw_hdmi_i2s_ops = {
|
||||
.hw_params = dw_hdmi_i2s_hw_params,
|
||||
.audio_shutdown = dw_hdmi_i2s_audio_shutdown,
|
||||
.get_eld = dw_hdmi_i2s_get_eld,
|
||||
.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)
|
||||
|
|
|
@ -191,6 +191,10 @@ struct dw_hdmi {
|
|||
|
||||
struct mutex cec_notifier_mutex;
|
||||
struct cec_notifier *cec_notifier;
|
||||
|
||||
hdmi_codec_plugged_cb plugged_cb;
|
||||
struct device *codec_dev;
|
||||
enum drm_connector_status last_connector_result;
|
||||
};
|
||||
|
||||
#define HDMI_IH_PHY_STAT0_RX_SENSE \
|
||||
|
@ -215,6 +219,28 @@ static inline u8 hdmi_readb(struct dw_hdmi *hdmi, int offset)
|
|||
return val;
|
||||
}
|
||||
|
||||
static void handle_plugged_change(struct dw_hdmi *hdmi, bool plugged)
|
||||
{
|
||||
if (hdmi->plugged_cb && hdmi->codec_dev)
|
||||
hdmi->plugged_cb(hdmi->codec_dev, plugged);
|
||||
}
|
||||
|
||||
int dw_hdmi_set_plugged_cb(struct dw_hdmi *hdmi, hdmi_codec_plugged_cb fn,
|
||||
struct device *codec_dev)
|
||||
{
|
||||
bool plugged;
|
||||
|
||||
mutex_lock(&hdmi->mutex);
|
||||
hdmi->plugged_cb = fn;
|
||||
hdmi->codec_dev = codec_dev;
|
||||
plugged = hdmi->last_connector_result == connector_status_connected;
|
||||
handle_plugged_change(hdmi, plugged);
|
||||
mutex_unlock(&hdmi->mutex);
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(dw_hdmi_set_plugged_cb);
|
||||
|
||||
static void hdmi_modb(struct dw_hdmi *hdmi, u8 data, u8 mask, unsigned reg)
|
||||
{
|
||||
regmap_update_bits(hdmi->regm, reg << hdmi->reg_shift, mask, data);
|
||||
|
@ -2161,6 +2187,7 @@ dw_hdmi_connector_detect(struct drm_connector *connector, bool force)
|
|||
{
|
||||
struct dw_hdmi *hdmi = container_of(connector, struct dw_hdmi,
|
||||
connector);
|
||||
enum drm_connector_status result;
|
||||
|
||||
mutex_lock(&hdmi->mutex);
|
||||
hdmi->force = DRM_FORCE_UNSPECIFIED;
|
||||
|
@ -2168,7 +2195,18 @@ dw_hdmi_connector_detect(struct drm_connector *connector, bool force)
|
|||
dw_hdmi_update_phy_mask(hdmi);
|
||||
mutex_unlock(&hdmi->mutex);
|
||||
|
||||
return hdmi->phy.ops->read_hpd(hdmi, hdmi->phy.data);
|
||||
result = hdmi->phy.ops->read_hpd(hdmi, hdmi->phy.data);
|
||||
|
||||
mutex_lock(&hdmi->mutex);
|
||||
if (result != hdmi->last_connector_result) {
|
||||
dev_dbg(hdmi->dev, "read_hpd result: %d", result);
|
||||
handle_plugged_change(hdmi,
|
||||
result == connector_status_connected);
|
||||
hdmi->last_connector_result = result;
|
||||
}
|
||||
mutex_unlock(&hdmi->mutex);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static int dw_hdmi_connector_get_modes(struct drm_connector *connector)
|
||||
|
@ -2619,6 +2657,7 @@ __dw_hdmi_probe(struct platform_device *pdev,
|
|||
hdmi->rxsense = true;
|
||||
hdmi->phy_mask = (u8)~(HDMI_PHY_HPD | HDMI_PHY_RX_SENSE);
|
||||
hdmi->mc_clkdis = 0x7f;
|
||||
hdmi->last_connector_result = connector_status_disconnected;
|
||||
|
||||
mutex_init(&hdmi->mutex);
|
||||
mutex_init(&hdmi->audio_mutex);
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
#ifndef __DW_HDMI__
|
||||
#define __DW_HDMI__
|
||||
|
||||
#include <sound/hdmi-codec.h>
|
||||
|
||||
struct drm_connector;
|
||||
struct drm_display_mode;
|
||||
struct drm_encoder;
|
||||
|
@ -154,6 +156,8 @@ void dw_hdmi_resume(struct dw_hdmi *hdmi);
|
|||
|
||||
void dw_hdmi_setup_rx_sense(struct dw_hdmi *hdmi, bool hpd, bool rx_sense);
|
||||
|
||||
int dw_hdmi_set_plugged_cb(struct dw_hdmi *hdmi, hdmi_codec_plugged_cb fn,
|
||||
struct device *codec_dev);
|
||||
void dw_hdmi_set_sample_rate(struct dw_hdmi *hdmi, unsigned int rate);
|
||||
void dw_hdmi_set_channel_count(struct dw_hdmi *hdmi, unsigned int cnt);
|
||||
void dw_hdmi_set_channel_allocation(struct dw_hdmi *hdmi, unsigned int ca);
|
||||
|
|
Loading…
Reference in a new issue