From: Doug Anderson <dianders@chromium.org>
To: Rajeev Nandan <rajeevny@codeaurora.org>
Cc: dri-devel <dri-devel@lists.freedesktop.org>,
linux-arm-msm <linux-arm-msm@vger.kernel.org>,
freedreno <freedreno@lists.freedesktop.org>,
"open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS"
<devicetree@vger.kernel.org>, LKML <linux-kernel@vger.kernel.org>,
Thierry Reding <thierry.reding@gmail.com>,
Sam Ravnborg <sam@ravnborg.org>, Rob Clark <robdclark@gmail.com>,
Lyude Paul <lyude@redhat.com>,
Jani Nikula <jani.nikula@intel.com>,
Rob Herring <robh@kernel.org>,
Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Andrzej Hajda <a.hajda@samsung.com>,
Daniel Thompson <daniel.thompson@linaro.org>,
"Kristian H. Kristensen" <hoegsberg@chromium.org>,
Abhinav Kumar <abhinavk@codeaurora.org>,
Sean Paul <seanpaul@chromium.org>,
Kalyan Thota <kalyan_t@codeaurora.org>,
Krishna Manikandan <mkrishn@codeaurora.org>,
Lee Jones <lee.jones@linaro.org>,
Jingoo Han <jingoohan1@gmail.com>,
linux-fbdev@vger.kernel.org
Subject: Re: [v5 1/5] drm/panel: add basic DP AUX backlight support
Date: Wed, 2 Jun 2021 17:05:06 -0700 [thread overview]
Message-ID: <CAD=FV=XMVKP=nK+-eTpxNK-AQ66rqvfMj_Q0TZrsG-CEWtbw8Q@mail.gmail.com> (raw)
In-Reply-To: <1622390172-31368-2-git-send-email-rajeevny@codeaurora.org>
Hi,
On Sun, May 30, 2021 at 8:57 AM Rajeev Nandan <rajeevny@codeaurora.org> wrote:
>
> +static int dp_aux_backlight_update_status(struct backlight_device *bd)
> +{
> + struct dp_aux_backlight *bl = bl_get_data(bd);
> + u16 brightness = backlight_get_brightness(bd);
> + int ret = 0;
> +
> + if (brightness > 0) {
> + if (!bl->enabled) {
> + drm_edp_backlight_enable(bl->aux, &bl->info, brightness);
> + bl->enabled = true;
> + return 0;
> + }
> + ret = drm_edp_backlight_set_level(bl->aux, &bl->info, brightness);
> + } else {
> + if (bl->enabled) {
> + drm_edp_backlight_disable(bl->aux, &bl->info);
> + bl->enabled = false;
> + }
> + }
I was trying to figure out if there are any races / locking problems /
problems trying to tweak the backlight when the panel is off. I don't
_think_ there are. Specifically:
1. Before turning the panel off, drm_panel will call
backlight_disable(). That will set BL_CORE_FBBLANK which is not set by
any other calls. Then it will call your
dp_aux_backlight_update_status().
2. Once BL_CORE_FBBLANK is set then backlight_get_brightness() will
always return 0.
This means that a transition from 0 -> non-zero (and enable) will
always only happen when the panel is on, which is good. It also means
that we'll always transition to 0 (disable the backlight) when the
panel turns off.
In terms of other races, it looks like the AUX transfer code handles
grabbing a mutex around transfers so we should be safe there.
So I guess the above is just a long-winded way of saying that this
looks right to me. :-)
BTW: we should probably make sure that the full set of people
identified by `./scripts/get_maintainer.pl -f
./drivers/video/backlight` are CCed on your series. I see Daniel
already and I've added the rest.
> +/**
> + * drm_panel_dp_aux_backlight - create and use DP AUX backlight
> + * @panel: DRM panel
> + * @aux: The DP AUX channel to use
> + *
> + * Use this function to create and handle backlight if your panel
> + * supports backlight control over DP AUX channel using DPCD
> + * registers as per VESA's standard backlight control interface.
> + *
> + * When the panel is enabled backlight will be enabled after a
> + * successful call to &drm_panel_funcs.enable()
> + *
> + * When the panel is disabled backlight will be disabled before the
> + * call to &drm_panel_funcs.disable().
> + *
> + * A typical implementation for a panel driver supporting backlight
> + * control over DP AUX will call this function at probe time.
> + * Backlight will then be handled transparently without requiring
> + * any intervention from the driver.
> + *
> + * drm_panel_dp_aux_backlight() must be called after the call to drm_panel_init().
> + *
> + * Return: 0 on success or a negative error code on failure.
> + */
> +int drm_panel_dp_aux_backlight(struct drm_panel *panel, struct drm_dp_aux *aux)
> +{
> + struct dp_aux_backlight *bl;
> + struct backlight_properties props = { 0 };
> + u16 current_level;
> + u8 current_mode;
> + u8 edp_dpcd[EDP_DISPLAY_CTL_CAP_SIZE];
> + int ret;
> +
> + if (!panel || !panel->dev || !aux)
> + return -EINVAL;
> +
> + bl = devm_kzalloc(panel->dev, sizeof(*bl), GFP_KERNEL);
> + if (!bl)
> + return -ENOMEM;
> +
> + bl->aux = aux;
> +
> + ret = drm_dp_dpcd_read(aux, DP_EDP_DPCD_REV, edp_dpcd,
> + EDP_DISPLAY_CTL_CAP_SIZE);
> + if (ret < 0)
> + return ret;
> +
> + if (!drm_edp_backlight_supported(edp_dpcd)) {
> + DRM_DEV_INFO(panel->dev, "DP AUX backlight is not supported\n");
> + return 0;
> + }
nit: move this part up above the memory allocation. There's no reason
to allocate memory for "bl" if the backlight isn't supported.
> @@ -64,8 +65,8 @@ enum drm_panel_orientation;
> * the panel. This is the job of the .unprepare() function.
> *
> * Backlight can be handled automatically if configured using
> - * drm_panel_of_backlight(). Then the driver does not need to implement the
> - * functionality to enable/disable backlight.
> + * drm_panel_of_backlight() or drm_panel_dp_aux_backlight(). Then the driver
> + * does not need to implement the functionality to enable/disable backlight.
> */
> struct drm_panel_funcs {
> /**
> @@ -144,8 +145,8 @@ struct drm_panel {
> * Backlight device, used to turn on backlight after the call
> * to enable(), and to turn off backlight before the call to
> * disable().
> - * backlight is set by drm_panel_of_backlight() and drivers
> - * shall not assign it.
> + * backlight is set by drm_panel_of_backlight()/drm_panel_dp_aux_backlight()
> + * and drivers shall not assign it.
Slight nit that I would have wrapped the drm_panel_dp_aux_backlight()
to the next line just to avoid one really long line followed by a
short one.
Other than the two nits (ordering of memory allocation and word
wrapping in a comment), this looks good to me. Feel free to add my
Reviewed-by tag when you fix the nits.
NOTE: Even though I have commit access to drm-misc now, I wouldn't
feel comfortable merging this to drm-misc myself without review
feedback from someone more senior. Obviously we're still blocked on my
and Lyude's series landing first, but even assuming those just land
as-is we'll need some more adult supervision before this can land. ;-)
That being said, I personally think this looks pretty nice now.
-Doug
> */
> struct backlight_device *backlight;
>
> @@ -208,11 +209,17 @@ static inline int of_drm_get_panel_orientation(const struct device_node *np,
> #if IS_ENABLED(CONFIG_DRM_PANEL) && (IS_BUILTIN(CONFIG_BACKLIGHT_CLASS_DEVICE) || \
> (IS_MODULE(CONFIG_DRM) && IS_MODULE(CONFIG_BACKLIGHT_CLASS_DEVICE)))
> int drm_panel_of_backlight(struct drm_panel *panel);
> +int drm_panel_dp_aux_backlight(struct drm_panel *panel, struct drm_dp_aux *aux);
> #else
> static inline int drm_panel_of_backlight(struct drm_panel *panel)
> {
> return 0;
> }
> +static inline int drm_panel_dp_aux_backlight(struct drm_panel *panel,
> + struct drm_dp_aux *aux)
> +{
> + return 0;
> +}
> #endif
>
> #endif
> --
> 2.7.4
>
next parent reply other threads:[~2021-06-03 0:13 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1622390172-31368-1-git-send-email-rajeevny@codeaurora.org>
[not found] ` <1622390172-31368-2-git-send-email-rajeevny@codeaurora.org>
2021-06-03 0:05 ` Doug Anderson [this message]
2021-06-03 6:26 ` [v5 1/5] drm/panel: add basic DP AUX backlight support rajeevny
[not found] ` <1622390172-31368-3-git-send-email-rajeevny@codeaurora.org>
2021-06-03 0:05 ` [v5 2/5] drm/panel-simple: Support DP AUX backlight Doug Anderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAD=FV=XMVKP=nK+-eTpxNK-AQ66rqvfMj_Q0TZrsG-CEWtbw8Q@mail.gmail.com' \
--to=dianders@chromium.org \
--cc=a.hajda@samsung.com \
--cc=abhinavk@codeaurora.org \
--cc=daniel.thompson@linaro.org \
--cc=devicetree@vger.kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=freedreno@lists.freedesktop.org \
--cc=hoegsberg@chromium.org \
--cc=jani.nikula@intel.com \
--cc=jingoohan1@gmail.com \
--cc=kalyan_t@codeaurora.org \
--cc=laurent.pinchart@ideasonboard.com \
--cc=lee.jones@linaro.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-fbdev@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lyude@redhat.com \
--cc=mkrishn@codeaurora.org \
--cc=rajeevny@codeaurora.org \
--cc=robdclark@gmail.com \
--cc=robh@kernel.org \
--cc=sam@ravnborg.org \
--cc=seanpaul@chromium.org \
--cc=thierry.reding@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).