linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
Cc: Jani Nikula <jani.nikula@linux.intel.com>,
	Joonas Lahtinen <joonas.lahtinen@linux.intel.com>,
	Rodrigo Vivi <rodrigo.vivi@intel.com>,
	Lee Jones <lee.jones@linaro.org>,
	Linus Walleij <linus.walleij@linaro.org>,
	intel-gfx <intel-gfx@lists.freedesktop.org>,
	dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	linux-gpio@vger.kernel.org
Subject: Re: [PATCH 5/5] drm/i915/dsi: Control panel and backlight enable GPIOs on BYT
Date: Mon, 16 Dec 2019 15:28:09 +0100	[thread overview]
Message-ID: <910ef405-39df-8c58-48cb-d3ee407bd60d@redhat.com> (raw)
In-Reply-To: <20191216140427.GT1208@intel.com>

Hi,

On 16-12-2019 15:04, Ville Syrjälä wrote:
> On Sun, Dec 15, 2019 at 05:38:10PM +0100, Hans de Goede wrote:
>> On Bay Trail devices the MIPI power on/off sequences for DSI LCD panels
>> do not control the LCD panel- and backlight-enable GPIOs. So far, when
>> the VBT indicates we should use the SoC for backlight control, we have
>> been relying on these GPIOs being configured as output and driven high by
>> the Video BIOS (GOP) when it initializes the panel.
>>
>> This does not work when the device is booted with a HDMI monitor connected
>> as then the GOP will initialize the HDMI instead of the panel, leaving the
>> panel black, even though the i915 driver tries to output an image to it.
>>
>> Likewise on some device-models when the GOP does not initialize the DSI
>> panel it also leaves the mux of the PWM0 pin in generic GPIO mode instead
>> of muxing it to the PWM controller.
>>
>> This commit makes the DSI code control the SoC GPIOs for panel- and
>> backlight-enable on BYT, when the VBT indicates the SoC should be used
>>
>> for backlight control. It also ensures that the PWM0 pin is muxed to the
>> PWM controller in this case.
>>
>> This fixes the LCD panel not lighting up on various devices when booted
>> with a HDMI monitor connected. This has been tested to fix this on the
>> following devices:
>>
>> Peaq C1010
>> Point of View MOBII TAB-P800W
>> Point of View MOBII TAB-P1005W
>> Terra Pad 1061
>> Yours Y8W81
>>
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>> ---
>>   drivers/gpu/drm/i915/display/intel_dsi.h     |  3 +-
>>   drivers/gpu/drm/i915/display/intel_dsi_vbt.c | 63 ++++++++++++++++++++
>>   2 files changed, 65 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/i915/display/intel_dsi.h b/drivers/gpu/drm/i915/display/intel_dsi.h
>> index 675771ea91aa..7481a5aa3084 100644
>> --- a/drivers/gpu/drm/i915/display/intel_dsi.h
>> +++ b/drivers/gpu/drm/i915/display/intel_dsi.h
>> @@ -45,8 +45,9 @@ struct intel_dsi {
>>   	struct intel_dsi_host *dsi_hosts[I915_MAX_PORTS];
>>   	intel_wakeref_t io_wakeref[I915_MAX_PORTS];
>>   
>> -	/* GPIO Desc for CRC based Panel control */
>> +	/* GPIO Desc for panel and backlight control */
>>   	struct gpio_desc *gpio_panel;
>> +	struct gpio_desc *gpio_backlight;
>>   
>>   	struct intel_connector *attached_connector;
>>   
>> diff --git a/drivers/gpu/drm/i915/display/intel_dsi_vbt.c b/drivers/gpu/drm/i915/display/intel_dsi_vbt.c
>> index 847f04eec2a1..bd007d4f86e2 100644
>> --- a/drivers/gpu/drm/i915/display/intel_dsi_vbt.c
>> +++ b/drivers/gpu/drm/i915/display/intel_dsi_vbt.c
>> @@ -27,6 +27,8 @@
>>   #include <linux/gpio/consumer.h>
>>   #include <linux/gpio/machine.h>
>>   #include <linux/mfd/intel_soc_pmic.h>
>> +#include <linux/pinctrl/consumer.h>
>> +#include <linux/pinctrl/machine.h>
>>   #include <linux/slab.h>
>>   
>>   #include <asm/intel-mid.h>
>> @@ -525,11 +527,15 @@ void intel_dsi_vbt_exec_sequence(struct intel_dsi *intel_dsi,
>>   {
>>   	if (seq_id == MIPI_SEQ_POWER_ON && intel_dsi->gpio_panel)
>>   		gpiod_set_value_cansleep(intel_dsi->gpio_panel, 1);
>> +	if (seq_id == MIPI_SEQ_BACKLIGHT_ON && intel_dsi->gpio_backlight)
>> +		gpiod_set_value_cansleep(intel_dsi->gpio_backlight, 1);
>>   
>>   	intel_dsi_vbt_exec(intel_dsi, seq_id);
>>   
>>   	if (seq_id == MIPI_SEQ_POWER_OFF && intel_dsi->gpio_panel)
>>   		gpiod_set_value_cansleep(intel_dsi->gpio_panel, 0);
>> +	if (seq_id == MIPI_SEQ_BACKLIGHT_OFF && intel_dsi->gpio_backlight)
>> +		gpiod_set_value_cansleep(intel_dsi->gpio_backlight, 0);
>>   }
>>   
>>   void intel_dsi_msleep(struct intel_dsi *intel_dsi, int msec)
>> @@ -688,6 +694,8 @@ bool intel_dsi_vbt_init(struct intel_dsi *intel_dsi, u16 panel_id)
>>   /*
>>    * On some BYT/CHT devs some sequences are incomplete and we need to manually
>>    * control some GPIOs. We need to add a GPIO lookup table before we get these.
>> + * If the GOP did not initialize the panel (HDMI inserted) we may need to also
>> + * change the pinmux for the SoC's PWM0 pin from GPIO to PWM.
>>    */
>>   static struct gpiod_lookup_table pmic_panel_gpio_table = {
>>   	/* Intel GFX is consumer */
>> @@ -699,23 +707,68 @@ static struct gpiod_lookup_table pmic_panel_gpio_table = {
>>   	},
>>   };
>>   
>> +static struct gpiod_lookup_table soc_panel_gpio_table = {
>> +	.dev_id = "0000:00:02.0",
>> +	.table = {
>> +	  GPIO_LOOKUP("INT33FC:01", 10, "backlight", GPIO_ACTIVE_HIGH),
>> +	  GPIO_LOOKUP("INT33FC:01", 11, "panel", GPIO_ACTIVE_HIGH),
>> +	  { },
> 
> Some kind of indent fail here.

Yeah, this was intentional in the previous revision because of the
80 char limit, but this indent hack is no longer necessary, fixed for
the v2 of this set which I'm preparing.

>> +	},
>> +};
>> +
>> +static const struct pinctrl_map soc_pwm_pinctrl_map[] = {
>> +	PIN_MAP_MUX_GROUP("0000:00:02.0", "soc_pwm0", "INT33FC:00",
>> +			  "pwm0_grp", "pwm"),
>> +};
>> +
>>   void intel_dsi_vbt_gpio_init(struct intel_dsi *intel_dsi, bool panel_is_on)
>>   {
>>   	struct drm_device *dev = intel_dsi->base.base.dev;
>>   	struct drm_i915_private *dev_priv = to_i915(dev);
>>   	struct mipi_config *mipi_config = dev_priv->vbt.dsi.config;
>>   	enum gpiod_flags flags = panel_is_on ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW;
>> +	bool want_backlight_gpio = false;
>> +	bool want_panel_gpio = false;
>> +	struct pinctrl *pinctrl;
>> +	int ret;
>>   
>>   	if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
>>   	    (mipi_config->pwm_blc == PPS_BLC_PMIC)) {
>>   		gpiod_add_lookup_table(&pmic_panel_gpio_table);
>> +		want_panel_gpio = true;
>> +	}
>> +
>> +	if (IS_VALLEYVIEW(dev_priv) && mipi_config->pwm_blc == PPS_BLC_SOC) {
>> +		gpiod_add_lookup_table(&soc_panel_gpio_table);
>> +		want_panel_gpio = true;
>> +		want_backlight_gpio = true;
>>   
>> +		/* Ensure PWM0 pin is muxed as PWM instead of GPIO */
>> +		ret = pinctrl_register_mappings(soc_pwm_pinctrl_map, 1);
> 
> ARRAY_SIZE()?

Ack, will fix for v2.


> 
>> +		if (ret)
>> +			DRM_ERROR("Failed to register pwm0 pinmux mapping\n");
>> +
>> +		pinctrl = devm_pinctrl_get_select(dev->dev, "soc_pwm0");
>> +		if (IS_ERR(pinctrl))
>> +			DRM_ERROR("Failed to set pinmux to PWM\n");
>> +	}
>> +
>> +	if (want_panel_gpio) {
>>   		intel_dsi->gpio_panel = gpiod_get(dev->dev, "panel", flags);
>>   		if (IS_ERR(intel_dsi->gpio_panel)) {
>>   			DRM_ERROR("Failed to own gpio for panel control\n");
>>   			intel_dsi->gpio_panel = NULL;
>>   		}
>>   	}
>> +
>> +	if (want_backlight_gpio) {
>> +		intel_dsi->gpio_backlight =
>> +			gpiod_get(dev->dev, "backlight", flags);
>> +		if (IS_ERR(intel_dsi->gpio_backlight)) {
>> +			DRM_ERROR("Failed to own gpio for backlight control\n");
>> +			intel_dsi->gpio_backlight = NULL;
>> +		}
>> +	}
>>   }
>>   
>>   void intel_dsi_vbt_gpio_cleanup(struct intel_dsi *intel_dsi)
>> @@ -729,7 +782,17 @@ void intel_dsi_vbt_gpio_cleanup(struct intel_dsi *intel_dsi)
>>   		intel_dsi->gpio_panel = NULL;
>>   	}
>>   
>> +	if (intel_dsi->gpio_backlight) {
>> +		gpiod_put(intel_dsi->gpio_backlight);
>> +		intel_dsi->gpio_backlight = NULL;
>> +	}
>> +
>>   	if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
>>   	    (mipi_config->pwm_blc == PPS_BLC_PMIC))
>>   		gpiod_remove_lookup_table(&pmic_panel_gpio_table);
>> +
>> +	if (IS_VALLEYVIEW(dev_priv) && mipi_config->pwm_blc == PPS_BLC_SOC) {
> 
> Slightly annoying to have these checks duplicated. Might be cleaner to
> have a few helpers that return the correct tables and just use those in
> both init and cleanup. OTOH those want_*_gpio flags and the pwm stuff is
> would still be a sticking point I suppose. So maybe not cleaner in the
> end after all.

So I tried adding a helper for the if condition, since as you mention
just returning the right table is not really helpful:

static bool intel_dsi_vbt_use_pmic_backlight_ctl(struct intel_dsi *intel_dsi)
{
        struct drm_device *dev = intel_dsi->base.base.dev;
        struct drm_i915_private *dev_priv = to_i915(dev);
        struct mipi_config *mipi_config = dev_priv->vbt.dsi.config;

        if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
            (mipi_config->pwm_blc == PPS_BLC_PMIC)) {
        return (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
               mipi_config->pwm_blc == PPS_BLC_PMIC;
}

And copy and paste that for the PPS_BLC_SOC case. The result does not
look a lot better then the original, worse actually IMHO, so I'm going
to keep this as is for v2.

> Looks all right to me:
> Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>

Thanks.

Regards,

Hans




> 
> 
>> +		pinctrl_unregister_mappings(soc_pwm_pinctrl_map);
>> +		gpiod_remove_lookup_table(&soc_panel_gpio_table);
>> +	}
>>   }
>> -- 
>> 2.23.0
> 


  reply	other threads:[~2019-12-16 14:28 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-15 16:38 [PATCH 0/5] drm/i915/dsi: Control panel and backlight enable GPIOs from VBT Hans de Goede
2019-12-15 16:38 ` [PATCH 1/5] pinctrl: Export pinctrl_unregister_mappings Hans de Goede
2019-12-15 16:38 ` [PATCH 2/5] drm/i915/dsi: Move poking of panel-enable GPIO to intel_dsi_vbt.c Hans de Goede
2019-12-16 10:27   ` Linus Walleij
2019-12-16 13:51   ` Ville Syrjälä
2019-12-15 16:38 ` [PATCH 3/5] drm/i915/dsi: Init panel-enable GPIO to low when the LCD is initially off Hans de Goede
2019-12-16 10:28   ` Linus Walleij
2019-12-16 13:45   ` Ville Syrjälä
2019-12-16 13:51     ` Hans de Goede
2019-12-16 14:14       ` Ville Syrjälä
2019-12-16 14:59         ` Hans de Goede
2019-12-15 16:38 ` [PATCH 4/5] drm/i915/dsi: Move Crystal Cove PMIC panel GPIO lookup from mfd to the i915 driver Hans de Goede
2019-12-16 10:30   ` Linus Walleij
2019-12-16 12:16   ` Andy Shevchenko
2019-12-16 13:13     ` Hans de Goede
2019-12-16 13:56   ` Ville Syrjälä
2019-12-16 14:16     ` Hans de Goede
2019-12-15 16:38 ` [PATCH 5/5] drm/i915/dsi: Control panel and backlight enable GPIOs on BYT Hans de Goede
2019-12-16 10:29   ` Linus Walleij
2019-12-16 14:04   ` Ville Syrjälä
2019-12-16 14:28     ` Hans de Goede [this message]
2019-12-16 10:26 ` [PATCH 0/5] drm/i915/dsi: Control panel and backlight enable GPIOs from VBT Linus Walleij
2019-12-16 10:59   ` Hans de Goede
2019-12-16 11:11   ` Hans de Goede
2019-12-16 12:16     ` Linus Walleij
2019-12-16 13:25       ` Hans de Goede
2019-12-16 12:18 ` Andy Shevchenko
2019-12-16 16:10   ` Lee Jones

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=910ef405-39df-8c58-48cb-d3ee407bd60d@redhat.com \
    --to=hdegoede@redhat.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=joonas.lahtinen@linux.intel.com \
    --cc=lee.jones@linaro.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rodrigo.vivi@intel.com \
    --cc=ville.syrjala@linux.intel.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).