Re: [PATCH 2/4] drm: bridge: dw-hdmi: Report connector status using callback

From: Cheng-yi Chiang
Date: Fri Jul 05 2019 - 03:35:52 EST


On Fri, Jul 5, 2019 at 3:09 PM Tzung-Bi Shih <tzungbi@xxxxxxxxxx> wrote:
>
> On Fri, Jul 5, 2019 at 12:26 PM Cheng-Yi Chiang <cychiang@xxxxxxxxxxxx> wrote:
> > diff --git a/drivers/gpu/drm/bridge/synopsys/dw-hdmi-audio.h b/drivers/gpu/drm/bridge/synopsys/dw-hdmi-audio.h
> > index 63b5756f463b..f523c590984e 100644
> > --- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi-audio.h
> > +++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi-audio.h
> > @@ -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
> > diff --git a/drivers/gpu/drm/bridge/synopsys/dw-hdmi-i2s-audio.c b/drivers/gpu/drm/bridge/synopsys/dw-hdmi-i2s-audio.c
> > index 5cbb71a866d5..7b93cf05c985 100644
> > --- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi-i2s-audio.c
> > +++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi-i2s-audio.c
> > @@ -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);
> > +}
> > +
> The first parameter dev could be removed. Not used.
>
Hi Tzungbi, thanks for the review.

I am not sure about this one.
I think it depends on the DRM driver so I need to keep both..
E.g.
drivers/gpu/drm/rockchip/cdn-dp-core.c
it needs dev to access the required data.
You can check this patch:

"efc9194bcff8 ASoC: hdmi-codec: callback function will be called with
private data"

It explains that some cases use *dev, some cases use *data.

> > 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)
> > diff --git a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
> > index 045b1b13fd0e..c69a399fc7ca 100644
> > --- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
> > +++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
> > @@ -26,6 +26,8 @@
> > #include <drm/drm_probe_helper.h>
> > #include <drm/bridge/dw_hdmi.h>
> >
> > +#include <sound/hdmi-codec.h>
> > +
> > #include <uapi/linux/media-bus-format.h>
> > #include <uapi/linux/videodev2.h>
> >
> > @@ -185,6 +187,9 @@ struct dw_hdmi {
> > void (*disable_audio)(struct dw_hdmi *hdmi);
> >
> > struct cec_notifier *cec_notifier;
> > +
> > + hdmi_codec_plugged_cb plugged_cb;
> > + enum drm_connector_status last_connector_result;
> > };
> >
> > #define HDMI_IH_PHY_STAT0_RX_SENSE \
> > @@ -209,6 +214,17 @@ static inline u8 hdmi_readb(struct dw_hdmi *hdmi, int offset)
> > return val;
> > }
> >
> > +static int hdmi_set_plugged_cb(struct dw_hdmi *hdmi, hdmi_codec_plugged_cb fn)
> > +{
> > + mutex_lock(&hdmi->mutex);
> > + hdmi->plugged_cb = fn;
> > + if (hdmi->audio && !IS_ERR(hdmi->audio))
> I would expect if IS_ERR(hdmi->audio), then this should not be called
> (i.e. should exit somewhere earlier).
>
ACK. I should fix that.
Thanks!
> > + fn(hdmi->audio,
> > + hdmi->last_connector_result == connector_status_connected);
> > + mutex_unlock(&hdmi->mutex);
> > + return 0;
> > +}
> > +
> > 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);
> > @@ -2044,6 +2060,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;
> > @@ -2051,7 +2068,20 @@ 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);
> > + if (hdmi->plugged_cb && hdmi->audio && !IS_ERR(hdmi->audio)) {
> Share the same concern above.
ACK