From: Jani Nikula <jani.nikula@intel.com>
To: Shobhit Kumar <shobhit.kumar@intel.com>,
intel-gfx <intel-gfx@lists.freedesktop.org>,
linux-kernel <linux-kernel@vger.kernel.org>,
linux-gpio <linux-gpio@vger.kernel.org>,
linux-pwm <linux-pwm@vger.kernel.org>,
dri-devel <dri-devel@lists.freedesktop.org>
Cc: Linus Walleij <linus.walleij@linaro.org>,
Alexandre Courbot <gnurou@gmail.com>,
Daniel Vetter <daniel.vetter@intel.com>,
David Airlie <airlied@linux.ie>,
Samuel Ortiz <sameo@linux.intel.com>,
Thierry Reding <thierry.reding@gmail.com>,
Lee Jones <lee.jones@linaro.org>,
Povilas Staniulis <wdmonster@gmail.com>,
Chih-Wei Huang <cwhuang@android-x86.org>,
Shobhit Kumar <shobhit.kumar@intel.com>
Subject: Re: [PATCH 8/8] drm/i915: Backlight control using CRC PMIC based PWM driver
Date: Wed, 06 May 2015 16:39:40 +0300 [thread overview]
Message-ID: <87y4l1ddur.fsf@intel.com> (raw)
In-Reply-To: <1430316005-16480-9-git-send-email-shobhit.kumar@intel.com>
On Wed, 29 Apr 2015, Shobhit Kumar <shobhit.kumar@intel.com> wrote:
> Use the CRC PWM device in intel_panel.c and add new MIPI backlight
> specififc callbacks
>
> v2: Modify to use pwm_config callback
>
> CC: Samuel Ortiz <sameo@linux.intel.com>
> Cc: Linus Walleij <linus.walleij@linaro.org>
> Cc: Alexandre Courbot <gnurou@gmail.com>
> Cc: Thierry Reding <thierry.reding@gmail.com>
> Signed-off-by: Shobhit Kumar <shobhit.kumar@intel.com>
> ---
> drivers/gpu/drm/i915/intel_drv.h | 5 +++
> drivers/gpu/drm/i915/intel_dsi.c | 6 +++
> drivers/gpu/drm/i915/intel_panel.c | 92 +++++++++++++++++++++++++++++++++++---
> 3 files changed, 98 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
> index 897f17d..b4ebe3b 100644
> --- a/drivers/gpu/drm/i915/intel_drv.h
> +++ b/drivers/gpu/drm/i915/intel_drv.h
> @@ -182,7 +182,12 @@ struct intel_panel {
> bool enabled;
> bool combination_mode; /* gen 2/4 only */
> bool active_low_pwm;
> +
> + /* PWM chip */
> + struct pwm_device *pwm;
> +
> struct backlight_device *device;
> +
Superfluous whitespace.
> } backlight;
>
> void (*backlight_power)(struct intel_connector *, bool enable);
> diff --git a/drivers/gpu/drm/i915/intel_dsi.c b/drivers/gpu/drm/i915/intel_dsi.c
> index be55ffa..83c4540 100644
> --- a/drivers/gpu/drm/i915/intel_dsi.c
> +++ b/drivers/gpu/drm/i915/intel_dsi.c
> @@ -402,6 +402,8 @@ static void intel_dsi_enable(struct intel_encoder *encoder)
>
> intel_dsi_port_enable(encoder);
> }
> +
> + intel_panel_enable_backlight(intel_dsi->attached_connector);
> }
>
> static void intel_dsi_pre_enable(struct intel_encoder *encoder)
> @@ -466,6 +468,8 @@ static void intel_dsi_pre_disable(struct intel_encoder *encoder)
>
> DRM_DEBUG_KMS("\n");
>
> + intel_panel_disable_backlight(intel_dsi->attached_connector);
> +
> if (is_vid_mode(intel_dsi)) {
> /* Send Shutdown command to the panel in LP mode */
> for_each_dsi_port(port, intel_dsi->ports)
> @@ -1132,6 +1136,8 @@ void intel_dsi_init(struct drm_device *dev)
> }
>
> intel_panel_init(&intel_connector->panel, fixed_mode, NULL);
> + intel_panel_setup_backlight(connector,
> + (intel_encoder->crtc_mask = (1 << PIPE_A)) ? PIPE_A: PIPE_B);
>
> return;
>
> diff --git a/drivers/gpu/drm/i915/intel_panel.c b/drivers/gpu/drm/i915/intel_panel.c
> index 08532d4..5700f6f 100644
> --- a/drivers/gpu/drm/i915/intel_panel.c
> +++ b/drivers/gpu/drm/i915/intel_panel.c
> @@ -32,8 +32,12 @@
>
> #include <linux/kernel.h>
> #include <linux/moduleparam.h>
> +#include <linux/pwm.h>
> #include "intel_drv.h"
>
> +#define CRC_PMIC_PWM_PERIOD_NS 21333
> +#define CRC_PMIC_PWM_STEPS 255
> +
> void
> intel_fixed_panel_mode(const struct drm_display_mode *fixed_mode,
> struct drm_display_mode *adjusted_mode)
> @@ -536,6 +540,15 @@ static u32 vlv_get_backlight(struct intel_connector *connector)
> return _vlv_get_backlight(dev, pipe);
> }
>
> +static u32 vlv_get_mipi_backlight(struct intel_connector *connector)
I'd rather call this either pmic_get_backlight or even pwm_get_backlight
because there's nothing really vlv specific about the functions
themselves. Same for all of them.
> +{
> + struct intel_panel *panel = &connector->panel;
> + int duty_ns;
> +
> + duty_ns = pwm_get_duty_cycle(panel->backlight.pwm);
> + return DIV_ROUND_UP(duty_ns * 100, CRC_PMIC_PWM_PERIOD_NS);
Basically we have all the code in place to do the scaling from hw to
user. See the note in intel_backlight_device_register. We shouldn't need
to add additional scaling all around.
However this can be a future cleanup IMO.
> +}
> +
> static u32 intel_panel_get_backlight(struct intel_connector *connector)
> {
> struct drm_device *dev = connector->base.dev;
> @@ -616,6 +629,14 @@ static void vlv_set_backlight(struct intel_connector *connector, u32 level)
> I915_WRITE(VLV_BLC_PWM_CTL(pipe), tmp | level);
> }
>
> +static void vlv_set_mipi_backlight(struct intel_connector *connector, u32 level)
> +{
> + struct intel_panel *panel = &connector->panel;
> + int duty_ns = DIV_ROUND_UP(level * CRC_PMIC_PWM_PERIOD_NS, 100);
> +
> + pwm_config(panel->backlight.pwm, duty_ns, CRC_PMIC_PWM_PERIOD_NS);
> +}
> +
> static void
> intel_panel_actually_set_backlight(struct intel_connector *connector, u32 level)
> {
> @@ -741,6 +762,16 @@ static void vlv_disable_backlight(struct intel_connector *connector)
> I915_WRITE(VLV_BLC_PWM_CTL2(pipe), tmp & ~BLM_PWM_ENABLE);
> }
>
> +static void vlv_disable_mipi_backlight(struct intel_connector *connector)
> +{
> + struct intel_panel *panel = &connector->panel;
> +
> + /* Disable the backlight */
> + pwm_config(panel->backlight.pwm, 0, CRC_PMIC_PWM_PERIOD_NS);
> + usleep_range(2000, 3000);
> + pwm_disable(panel->backlight.pwm);
> +}
> +
> void intel_panel_disable_backlight(struct intel_connector *connector)
> {
> struct drm_device *dev = connector->base.dev;
> @@ -947,6 +978,16 @@ static void vlv_enable_backlight(struct intel_connector *connector)
> I915_WRITE(VLV_BLC_PWM_CTL2(pipe), ctl2 | BLM_PWM_ENABLE);
> }
>
> +static void vlv_enable_mipi_backlight(struct intel_connector *connector)
> +{
> + struct intel_panel *panel = &connector->panel;
> + int duty_ns = DIV_ROUND_UP(
> + panel->backlight.level * CRC_PMIC_PWM_PERIOD_NS, 100);
> +
> + pwm_enable(panel->backlight.pwm);
> + pwm_config(panel->backlight.pwm, duty_ns, CRC_PMIC_PWM_PERIOD_NS);
All other enable functions call
intel_panel_actually_set_backlight(connector, panel->backlight.level);
to do this. It'll give you logging too.
> +}
> +
> void intel_panel_enable_backlight(struct intel_connector *connector)
> {
> struct drm_device *dev = connector->base.dev;
> @@ -1299,6 +1340,34 @@ static int vlv_setup_backlight(struct intel_connector *connector, enum pipe pipe
> return 0;
> }
>
> +static int vlv_setup_mipi_backlight(struct intel_connector *connector, enum pipe pipe)
> +{
> + struct drm_device *dev = connector->base.dev;
> + struct intel_panel *panel = &connector->panel;
> +
> + /* Get the PWM chip for backlight control */
> + panel->backlight.pwm = pwm_get(dev->dev, "pwm_backlight");
> + if (IS_ERR(panel->backlight.pwm)) {
> + DRM_ERROR("Faild to own the pwm chip\n");
> + panel->backlight.pwm = NULL;
I think you want to return -ENODEV here. And then you can drop the
"else" below and make that a normal if.
> + } else if (pwm_config(panel->backlight.pwm, CRC_PMIC_PWM_PERIOD_NS,
> + CRC_PMIC_PWM_PERIOD_NS) < 0) {
> + DRM_ERROR("Failed to configure the pwm chip\n");
> + pwm_put(panel->backlight.pwm);
> + panel->backlight.pwm = NULL;
> + return -1;
Save whatever pwm_config returns and return that instead of -1.
> + }
> +
> + panel->backlight.min = 0; /* 0% */
> + panel->backlight.max = 100; /* 100% */
> + panel->backlight.level = DIV_ROUND_UP(
> + pwm_get_duty_cycle(panel->backlight.pwm) * 100,
> + CRC_PMIC_PWM_PERIOD_NS);
> + panel->backlight.enabled = panel->backlight.level ? true : false;
panel->backlight.level != 0
> +
> + return 0;
> +}
> +
> int intel_panel_setup_backlight(struct drm_connector *connector, enum pipe pipe)
> {
> struct drm_device *dev = connector->dev;
> @@ -1363,11 +1432,19 @@ void intel_panel_init_backlight_funcs(struct drm_device *dev)
> dev_priv->display.set_backlight = pch_set_backlight;
> dev_priv->display.get_backlight = pch_get_backlight;
> } else if (IS_VALLEYVIEW(dev)) {
> - dev_priv->display.setup_backlight = vlv_setup_backlight;
> - dev_priv->display.enable_backlight = vlv_enable_backlight;
> - dev_priv->display.disable_backlight = vlv_disable_backlight;
> - dev_priv->display.set_backlight = vlv_set_backlight;
> - dev_priv->display.get_backlight = vlv_get_backlight;
> + if (dev_priv->vbt.has_mipi) {
> + dev_priv->display.setup_backlight = vlv_setup_mipi_backlight;
> + dev_priv->display.enable_backlight = vlv_enable_mipi_backlight;
> + dev_priv->display.disable_backlight = vlv_disable_mipi_backlight;
> + dev_priv->display.set_backlight = vlv_set_mipi_backlight;
> + dev_priv->display.get_backlight = vlv_get_mipi_backlight;
> + } else {
> + dev_priv->display.setup_backlight = vlv_setup_backlight;
> + dev_priv->display.enable_backlight = vlv_enable_backlight;
> + dev_priv->display.disable_backlight = vlv_disable_backlight;
> + dev_priv->display.set_backlight = vlv_set_backlight;
> + dev_priv->display.get_backlight = vlv_get_backlight;
> + }
> } else if (IS_GEN4(dev)) {
> dev_priv->display.setup_backlight = i965_setup_backlight;
> dev_priv->display.enable_backlight = i965_enable_backlight;
> @@ -1404,6 +1481,11 @@ void intel_panel_fini(struct intel_panel *panel)
> if (panel->downclock_mode)
> drm_mode_destroy(intel_connector->base.dev,
> panel->downclock_mode);
> +
> + /* dispose of the pwm */
> + if (panel->backlight.pwm)
> + pwm_put(panel->backlight.pwm);
> +
The cleanup should be in intel_panel_destroy_backlight to match where
.pwm is initialized.
BR,
Jani.
> }
>
> void intel_backlight_register(struct drm_device *dev)
> --
> 2.1.0
>
--
Jani Nikula, Intel Open Source Technology Center
prev parent reply other threads:[~2015-05-06 13:41 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-29 13:59 [PATCH 0/8] Crystalcove (CRC) PMIC based panel and pwm control Shobhit Kumar
2015-04-29 13:59 ` [PATCH 1/8] drivers/gpio/gpiolib: Add support for removing registered consumer lookup table Shobhit Kumar
2015-05-05 9:32 ` [PATCH 1/8] gpiolib: " Shobhit Kumar
2015-05-05 10:45 ` Lee Jones
2015-05-05 15:44 ` [Intel-gfx] " Daniel Vetter
2015-05-07 7:25 ` Lee Jones
2015-05-06 14:49 ` [PATCH 1/8] drivers/gpio/gpiolib: " Linus Walleij
2015-05-06 15:09 ` [Intel-gfx] " Daniel Vetter
2015-05-12 8:52 ` Linus Walleij
2015-04-29 13:59 ` [PATCH 2/8] drivers/pwm/core: Add support to remove registered consumer lookup tables Shobhit Kumar
2015-05-05 9:34 ` [PATCH 2/8] pwm: core: " Shobhit Kumar
2015-05-06 12:21 ` Thierry Reding
2015-04-29 14:00 ` [PATCH 3/8] drivers/mfd: Add lookup table for Panel Control as GPIO signal Shobhit Kumar
2015-04-29 14:27 ` Lee Jones
2015-04-30 7:17 ` Shobhit Kumar
2015-04-29 14:29 ` Lee Jones
2015-05-05 9:36 ` [PATCH 3/8] mfd: intel_soc_pmic_core: " Shobhit Kumar
2015-05-12 9:14 ` Linus Walleij
2015-05-06 14:51 ` [PATCH 3/8] drivers/mfd: " Linus Walleij
2015-04-29 14:00 ` [PATCH 4/8] drivers/mfd: Add PWM cell device for Crystalcove PMIC Shobhit Kumar
2015-04-29 14:25 ` Lee Jones
2015-05-05 9:36 ` [PATCH 4/8] mfd: intel_soc_pmic_crc: " Shobhit Kumar
2015-04-29 14:00 ` [PATCH 5/8] drivers/mfd: ADD PWM lookup table for CRC PMIC based PWM Shobhit Kumar
2015-04-29 14:24 ` Lee Jones
2015-05-05 9:48 ` Shobhit Kumar
2015-05-05 10:42 ` Lee Jones
2015-05-05 9:38 ` [PATCH 5/8] mfd: intel_soc_pmic_core: " Shobhit Kumar
2015-04-29 14:00 ` [PATCH 6/8] drivers/pwm: Add Crystalcove (CRC) PWM driver Shobhit Kumar
2015-04-30 21:12 ` Paul Bolle
2015-06-18 17:54 ` [Intel-gfx] " Shobhit Kumar
2015-06-18 18:41 ` Paul Bolle
2015-06-19 6:46 ` Shobhit Kumar
2015-06-20 11:23 ` Paul Bolle
2015-06-20 18:04 ` Paul Gortmaker
2015-06-22 7:55 ` Shobhit Kumar
2015-05-05 9:38 ` [PATCH 6/8] pwm: crc: " Shobhit Kumar
2015-05-06 7:40 ` Paul Bolle
2015-05-07 7:13 ` [Intel-gfx] " Shobhit Kumar
2015-05-06 12:14 ` Thierry Reding
2015-05-07 7:19 ` [Intel-gfx] " Shobhit Kumar
2015-05-20 15:09 ` Shobhit Kumar
2015-06-17 2:43 ` Shobhit Kumar
2015-04-29 14:00 ` [PATCH 7/8] drm/i915: Use the CRC gpio for panel enable/disable Shobhit Kumar
2015-05-06 13:11 ` Jani Nikula
2015-05-06 14:08 ` [Intel-gfx] " Daniel Vetter
2015-05-12 11:10 ` Linus Walleij
2015-04-29 14:00 ` [PATCH 8/8] drm/i915: Backlight control using CRC PMIC based PWM driver Shobhit Kumar
2015-05-06 13:39 ` Jani Nikula [this message]
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=87y4l1ddur.fsf@intel.com \
--to=jani.nikula@intel.com \
--cc=airlied@linux.ie \
--cc=cwhuang@android-x86.org \
--cc=daniel.vetter@intel.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=gnurou@gmail.com \
--cc=intel-gfx@lists.freedesktop.org \
--cc=lee.jones@linaro.org \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=sameo@linux.intel.com \
--cc=shobhit.kumar@intel.com \
--cc=thierry.reding@gmail.com \
--cc=wdmonster@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 read-only IMAP folder(s) and NNTP newsgroup(s).