Message ID | 20220208044328.588860-2-bjorn.andersson@linaro.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [1/2] drm: Add HPD state to drm_connector_oob_hotplug_event() | expand |
On Mon, Feb 07, 2022 at 08:43:28PM -0800, Bjorn Andersson wrote: > The Qualcomm DisplayPort driver contains traces of the necessary > plumbing to hook up USB HPD, in the form of the dp_hpd module and the > dp_usbpd_cb struct. Use this as basis for implementing the > oob_hotplug_event() callback, by amending the dp_hpd module with the > missing logic. > > Overall the solution is similar to what's done downstream, but upstream > all the code to disect the HPD notification lives on the calling side of > drm_connector_oob_hotplug_event(). > > drm_connector_oob_hotplug_event() performs the lookup of the > drm_connector based on fwnode, hence the need to assign the fwnode in > dp_drm_connector_init(). > > Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org> > --- > drivers/gpu/drm/msm/dp/dp_display.c | 8 ++++++++ > drivers/gpu/drm/msm/dp/dp_display.h | 2 ++ > drivers/gpu/drm/msm/dp/dp_drm.c | 10 ++++++++++ > drivers/gpu/drm/msm/dp/dp_hpd.c | 19 +++++++++++++++++++ > drivers/gpu/drm/msm/dp/dp_hpd.h | 4 ++++ > 5 files changed, 43 insertions(+) > > diff --git a/drivers/gpu/drm/msm/dp/dp_display.c b/drivers/gpu/drm/msm/dp/dp_display.c > index 7cc4d21f2091..124a2f794382 100644 > --- a/drivers/gpu/drm/msm/dp/dp_display.c > +++ b/drivers/gpu/drm/msm/dp/dp_display.c > @@ -414,6 +414,13 @@ static int dp_display_usbpd_configure_cb(struct device *dev) > return dp_display_process_hpd_high(dp); > } > > +void dp_display_oob_hotplug_event(struct msm_dp *dp_display, bool hpd_state) > +{ > + struct dp_display_private *dp = container_of(dp_display, struct dp_display_private, dp_display); > + > + dp->usbpd->oob_event(dp->usbpd, hpd_state); > +} > + > static int dp_display_usbpd_disconnect_cb(struct device *dev) > { > struct dp_display_private *dp = dev_get_dp_display_private(dev); > @@ -1251,6 +1258,7 @@ static int dp_display_probe(struct platform_device *pdev) > dp->pdev = pdev; > dp->name = "drm_dp"; > dp->dp_display.connector_type = desc->connector_type; > + dp->dp_display.dev = &pdev->dev; You did not properly reference count this pointer you just saved. What is to keep that pointer from going away without you knowing about it? And you already have a pointer to pdev, why save another one here? > > rc = dp_init_sub_modules(dp); > if (rc) { > diff --git a/drivers/gpu/drm/msm/dp/dp_display.h b/drivers/gpu/drm/msm/dp/dp_display.h > index e3adcd578a90..1f856b3bca79 100644 > --- a/drivers/gpu/drm/msm/dp/dp_display.h > +++ b/drivers/gpu/drm/msm/dp/dp_display.h > @@ -11,6 +11,7 @@ > #include "disp/msm_disp_snapshot.h" > > struct msm_dp { > + struct device *dev; > struct drm_device *drm_dev; > struct device *codec_dev; So you now have pointers to 3 different devices here? What does 'dev' point to that the other ones do not? This needs to be documented really well here. thanks, greg k-h
On Mon 07 Feb 23:40 PST 2022, Greg Kroah-Hartman wrote: > On Mon, Feb 07, 2022 at 08:43:28PM -0800, Bjorn Andersson wrote: > > The Qualcomm DisplayPort driver contains traces of the necessary > > plumbing to hook up USB HPD, in the form of the dp_hpd module and the > > dp_usbpd_cb struct. Use this as basis for implementing the > > oob_hotplug_event() callback, by amending the dp_hpd module with the > > missing logic. > > > > Overall the solution is similar to what's done downstream, but upstream > > all the code to disect the HPD notification lives on the calling side of > > drm_connector_oob_hotplug_event(). > > > > drm_connector_oob_hotplug_event() performs the lookup of the > > drm_connector based on fwnode, hence the need to assign the fwnode in > > dp_drm_connector_init(). > > > > Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org> > > --- > > drivers/gpu/drm/msm/dp/dp_display.c | 8 ++++++++ > > drivers/gpu/drm/msm/dp/dp_display.h | 2 ++ > > drivers/gpu/drm/msm/dp/dp_drm.c | 10 ++++++++++ > > drivers/gpu/drm/msm/dp/dp_hpd.c | 19 +++++++++++++++++++ > > drivers/gpu/drm/msm/dp/dp_hpd.h | 4 ++++ > > 5 files changed, 43 insertions(+) > > > > diff --git a/drivers/gpu/drm/msm/dp/dp_display.c b/drivers/gpu/drm/msm/dp/dp_display.c > > index 7cc4d21f2091..124a2f794382 100644 > > --- a/drivers/gpu/drm/msm/dp/dp_display.c > > +++ b/drivers/gpu/drm/msm/dp/dp_display.c > > @@ -414,6 +414,13 @@ static int dp_display_usbpd_configure_cb(struct device *dev) > > return dp_display_process_hpd_high(dp); > > } > > > > +void dp_display_oob_hotplug_event(struct msm_dp *dp_display, bool hpd_state) > > +{ > > + struct dp_display_private *dp = container_of(dp_display, struct dp_display_private, dp_display); > > + > > + dp->usbpd->oob_event(dp->usbpd, hpd_state); > > +} > > + > > static int dp_display_usbpd_disconnect_cb(struct device *dev) > > { > > struct dp_display_private *dp = dev_get_dp_display_private(dev); > > @@ -1251,6 +1258,7 @@ static int dp_display_probe(struct platform_device *pdev) > > dp->pdev = pdev; > > dp->name = "drm_dp"; > > dp->dp_display.connector_type = desc->connector_type; > > + dp->dp_display.dev = &pdev->dev; > > You did not properly reference count this pointer you just saved. What > is to keep that pointer from going away without you knowing about it? > The "dp" object only lives while &pdev->dev is alive, both logically and as its devres allocated on &pdev-dev. So for this reference I don't see that we should refcount it. > And you already have a pointer to pdev, why save another one here? > The Qualcomm DisplayPort driver has per-c-file private context structs and "dp" is one such object. So I simply can't dereference it and get to pdev from the other c-file in the same driver... But I only need it in dp_drm.c to during initialization to get a reference to the associated fwnode, so it seems that I can rework this and pass the pointer as a parameter to dp_drm_connector_init(). That looks to be cleaner as well. Thanks, Bjorn
diff --git a/drivers/gpu/drm/msm/dp/dp_display.c b/drivers/gpu/drm/msm/dp/dp_display.c index 7cc4d21f2091..124a2f794382 100644 --- a/drivers/gpu/drm/msm/dp/dp_display.c +++ b/drivers/gpu/drm/msm/dp/dp_display.c @@ -414,6 +414,13 @@ static int dp_display_usbpd_configure_cb(struct device *dev) return dp_display_process_hpd_high(dp); } +void dp_display_oob_hotplug_event(struct msm_dp *dp_display, bool hpd_state) +{ + struct dp_display_private *dp = container_of(dp_display, struct dp_display_private, dp_display); + + dp->usbpd->oob_event(dp->usbpd, hpd_state); +} + static int dp_display_usbpd_disconnect_cb(struct device *dev) { struct dp_display_private *dp = dev_get_dp_display_private(dev); @@ -1251,6 +1258,7 @@ static int dp_display_probe(struct platform_device *pdev) dp->pdev = pdev; dp->name = "drm_dp"; dp->dp_display.connector_type = desc->connector_type; + dp->dp_display.dev = &pdev->dev; rc = dp_init_sub_modules(dp); if (rc) { diff --git a/drivers/gpu/drm/msm/dp/dp_display.h b/drivers/gpu/drm/msm/dp/dp_display.h index e3adcd578a90..1f856b3bca79 100644 --- a/drivers/gpu/drm/msm/dp/dp_display.h +++ b/drivers/gpu/drm/msm/dp/dp_display.h @@ -11,6 +11,7 @@ #include "disp/msm_disp_snapshot.h" struct msm_dp { + struct device *dev; struct drm_device *drm_dev; struct device *codec_dev; struct drm_bridge *bridge; @@ -40,5 +41,6 @@ bool dp_display_check_video_test(struct msm_dp *dp_display); int dp_display_get_test_bpp(struct msm_dp *dp_display); void dp_display_signal_audio_start(struct msm_dp *dp_display); void dp_display_signal_audio_complete(struct msm_dp *dp_display); +void dp_display_oob_hotplug_event(struct msm_dp *dp_display, bool hpd_state); #endif /* _DP_DISPLAY_H_ */ diff --git a/drivers/gpu/drm/msm/dp/dp_drm.c b/drivers/gpu/drm/msm/dp/dp_drm.c index d4d360d19eba..665568197c49 100644 --- a/drivers/gpu/drm/msm/dp/dp_drm.c +++ b/drivers/gpu/drm/msm/dp/dp_drm.c @@ -123,6 +123,13 @@ static enum drm_mode_status dp_connector_mode_valid( return dp_display_validate_mode(dp_disp, mode->clock); } +static void dp_oob_hotplug_event(struct drm_connector *connector, bool hpd_state) +{ + struct msm_dp *dp_disp = to_dp_connector(connector)->dp_display; + + dp_display_oob_hotplug_event(dp_disp, hpd_state); +} + static const struct drm_connector_funcs dp_connector_funcs = { .detect = dp_connector_detect, .fill_modes = drm_helper_probe_single_connector_modes, @@ -130,6 +137,7 @@ static const struct drm_connector_funcs dp_connector_funcs = { .reset = drm_atomic_helper_connector_reset, .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, + .oob_hotplug_event = dp_oob_hotplug_event, }; static const struct drm_connector_helper_funcs dp_connector_helper_funcs = { @@ -160,6 +168,8 @@ struct drm_connector *dp_drm_connector_init(struct msm_dp *dp_display) if (ret) return ERR_PTR(ret); + connector->fwnode = fwnode_handle_get(dev_fwnode(dp_display->dev)); + drm_connector_helper_add(connector, &dp_connector_helper_funcs); /* diff --git a/drivers/gpu/drm/msm/dp/dp_hpd.c b/drivers/gpu/drm/msm/dp/dp_hpd.c index db98a1d431eb..3e62852a18b4 100644 --- a/drivers/gpu/drm/msm/dp/dp_hpd.c +++ b/drivers/gpu/drm/msm/dp/dp_hpd.c @@ -7,6 +7,7 @@ #include <linux/slab.h> #include <linux/device.h> +#include <drm/drm_print.h> #include "dp_hpd.h" @@ -45,6 +46,23 @@ int dp_hpd_connect(struct dp_usbpd *dp_usbpd, bool hpd) return rc; } +static void dp_hpd_oob_event(struct dp_usbpd *dp_usbpd, bool hpd_state) +{ + struct dp_hpd_private *hpd_priv = container_of(dp_usbpd, struct dp_hpd_private, dp_usbpd); + + DRM_DEBUG_DP("hpd_state: %d connected: %d\n", hpd_state, dp_usbpd->connected); + + if (!dp_usbpd->connected && hpd_state) { + dp_usbpd->connected = true; + hpd_priv->dp_cb->configure(hpd_priv->dev); + } else if (!hpd_state) { + dp_usbpd->connected = false; + hpd_priv->dp_cb->disconnect(hpd_priv->dev); + } else { + hpd_priv->dp_cb->attention(hpd_priv->dev); + } +} + struct dp_usbpd *dp_hpd_get(struct device *dev, struct dp_usbpd_cb *cb) { struct dp_hpd_private *dp_hpd; @@ -62,6 +80,7 @@ struct dp_usbpd *dp_hpd_get(struct device *dev, struct dp_usbpd_cb *cb) dp_hpd->dp_cb = cb; dp_hpd->dp_usbpd.connect = dp_hpd_connect; + dp_hpd->dp_usbpd.oob_event = dp_hpd_oob_event; return &dp_hpd->dp_usbpd; } diff --git a/drivers/gpu/drm/msm/dp/dp_hpd.h b/drivers/gpu/drm/msm/dp/dp_hpd.h index 8feec5aa5027..310ecc2a8538 100644 --- a/drivers/gpu/drm/msm/dp/dp_hpd.h +++ b/drivers/gpu/drm/msm/dp/dp_hpd.h @@ -29,7 +29,9 @@ enum plug_orientation { * @hpd_irq: Change in the status since last message * @alt_mode_cfg_done: bool to specify alt mode status * @debug_en: bool to specify debug mode + * @connected: cable currently connected * @connect: simulate disconnect or connect for debug mode + * @oob_event: deliver oob event to the usbpd code */ struct dp_usbpd { enum plug_orientation orientation; @@ -41,8 +43,10 @@ struct dp_usbpd { bool hpd_irq; bool alt_mode_cfg_done; bool debug_en; + bool connected; int (*connect)(struct dp_usbpd *dp_usbpd, bool hpd); + void (*oob_event)(struct dp_usbpd *dp_usbpd, bool hpd_state); }; /**
The Qualcomm DisplayPort driver contains traces of the necessary plumbing to hook up USB HPD, in the form of the dp_hpd module and the dp_usbpd_cb struct. Use this as basis for implementing the oob_hotplug_event() callback, by amending the dp_hpd module with the missing logic. Overall the solution is similar to what's done downstream, but upstream all the code to disect the HPD notification lives on the calling side of drm_connector_oob_hotplug_event(). drm_connector_oob_hotplug_event() performs the lookup of the drm_connector based on fwnode, hence the need to assign the fwnode in dp_drm_connector_init(). Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org> --- drivers/gpu/drm/msm/dp/dp_display.c | 8 ++++++++ drivers/gpu/drm/msm/dp/dp_display.h | 2 ++ drivers/gpu/drm/msm/dp/dp_drm.c | 10 ++++++++++ drivers/gpu/drm/msm/dp/dp_hpd.c | 19 +++++++++++++++++++ drivers/gpu/drm/msm/dp/dp_hpd.h | 4 ++++ 5 files changed, 43 insertions(+)