Re: [PATCH RFC/RFT 2/9] drm/display: add CEC helpers code

From: Dmitry Baryshkov
Date: Wed Jan 15 2025 - 05:52:42 EST


On Tue, Jan 14, 2025 at 04:45:09PM +0100, Maxime Ripard wrote:
> On Tue, Jan 07, 2025 at 06:18:07PM +0200, Dmitry Baryshkov wrote:
> > On Tue, 7 Jan 2025 at 16:32, Maxime Ripard <mripard@xxxxxxxxxx> wrote:
> > >
> > > On Wed, Dec 25, 2024 at 01:10:10AM +0200, Dmitry Baryshkov wrote:
> > > > Add generic CEC helpers to be used by HDMI drivers. Both notifier and
> > > > and adapter are supported for registration. Once registered, the driver
> > > > can call common set of functions to update physical address, to
> > > > invalidate it or to unregister CEC data.
> > > >
> > > > Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@xxxxxxxxxx>
> > > > ---
> > > > drivers/gpu/drm/display/Kconfig | 5 +
> > > > drivers/gpu/drm/display/Makefile | 2 +
> > > > drivers/gpu/drm/display/drm_hdmi_cec_helper.c | 145 ++++++++++++++++++++++++++
> > > > include/drm/display/drm_hdmi_cec_helper.h | 38 +++++++
> > > > 4 files changed, 190 insertions(+)
> > > >
> > > > diff --git a/drivers/gpu/drm/display/Kconfig b/drivers/gpu/drm/display/Kconfig
> > > > index 8d22b7627d41f7bc015decf24ae02a05bc00f055..49da9b768acf3e5f84f2cefae4bb042cfd57a50c 100644
> > > > --- a/drivers/gpu/drm/display/Kconfig
> > > > +++ b/drivers/gpu/drm/display/Kconfig
> > > > @@ -82,6 +82,11 @@ config DRM_DISPLAY_HDMI_AUDIO_HELPER
> > > > DRM display helpers for HDMI Audio functionality (generic HDMI Codec
> > > > implementation).
> > > >
> > > > +config DRM_DISPLAY_HDMI_CEC_HELPER
> > > > + bool
> > > > + help
> > > > + DRM display helpers for HDMI CEC implementation.
> > > > +
> > > > config DRM_DISPLAY_HDMI_HELPER
> > > > bool
> > > > help
> > > > diff --git a/drivers/gpu/drm/display/Makefile b/drivers/gpu/drm/display/Makefile
> > > > index b17879b957d5401721396e247fa346387cf6c48a..2cd078e2b81c1a9e6b336c4187b444bcb8a50e51 100644
> > > > --- a/drivers/gpu/drm/display/Makefile
> > > > +++ b/drivers/gpu/drm/display/Makefile
> > > > @@ -16,6 +16,8 @@ drm_display_helper-$(CONFIG_DRM_DISPLAY_DSC_HELPER) += \
> > > > drm_display_helper-$(CONFIG_DRM_DISPLAY_HDCP_HELPER) += drm_hdcp_helper.o
> > > > drm_display_helper-$(CONFIG_DRM_DISPLAY_HDMI_AUDIO_HELPER) += \
> > > > drm_hdmi_audio_helper.o
> > > > +drm_display_helper-$(CONFIG_DRM_DISPLAY_HDMI_CEC_HELPER) += \
> > > > + drm_hdmi_cec_helper.o
> > > > drm_display_helper-$(CONFIG_DRM_DISPLAY_HDMI_HELPER) += \
> > > > drm_hdmi_helper.o \
> > > > drm_scdc_helper.o
> > > > diff --git a/drivers/gpu/drm/display/drm_hdmi_cec_helper.c b/drivers/gpu/drm/display/drm_hdmi_cec_helper.c
> > > > new file mode 100644
> > > > index 0000000000000000000000000000000000000000..2a3832e68232fa3b839a3c7457b2013779cada86
> > > > --- /dev/null
> > > > +++ b/drivers/gpu/drm/display/drm_hdmi_cec_helper.c
> > > > @@ -0,0 +1,145 @@
> > > > +// SPDX-License-Identifier: MIT
> > > > +/*
> > > > + * Copyright (c) 2024 Linaro Ltd
> > > > + */
> > > > +
> > > > +#include <drm/drm_bridge.h>
> > > > +#include <drm/drm_connector.h>
> > > > +#include <drm/display/drm_hdmi_cec_helper.h>
> > > > +
> > > > +#include <linux/mutex.h>
> > > > +
> > > > +#include <media/cec.h>
> > > > +#include <media/cec-notifier.h>
> > > > +
> > > > +static void drm_connector_hdmi_cec_adapter_unregister(struct drm_connector *connector)
> > > > +{
> > > > + cec_unregister_adapter(connector->cec.adapter);
> > > > + connector->cec.adapter = NULL;
> > > > + connector->cec.unregister = NULL;
> > > > +}
> > > > +
> > > > +int drm_connector_hdmi_cec_adapter_register(struct drm_connector *connector,
> > > > + const struct cec_adap_ops *ops,
> > > > + const char *name,
> > > > + u8 available_las,
> > > > + int (*init_cec)(struct drm_connector *connector),
> > > > + void (*uninit_cec)(struct drm_connector *connector),
> > > > + struct device *dev)
> > >
> > > We're missing a documentation here. Why do we need drivers to pass both
> > > a set of cec_adap_ops and a bunch of extra functions? Shouldn't we make
> > > this a single structure like we did for audio?
> >
> > Also might be an option, I didn't want to add extra wrappers in the
> > first place, but I can add them.
> >
> > >
> > > Also, to remain consistent, we should call that function drm_connector_hdmi_cec_register
> >
> > I wanted to point out the _adapter_ part, because we also have
> > whatever_cec_notifier_register() and at some point we might also get
> > whatever_cec_pin_register() if we wrap sun4i implementation too.
>
> I think we can get away with drm_connector_hdmi_cec_register,
> drm_connector_hdmi_cec_pin_register (or bitbanged, or polled, or gpio,
> or whatever), and drm_connector_hdmi_cec_notifier_register

Ack

--
With best wishes
Dmitry