[Intel-gfx] [PATCH 2/5] drm/i915: protect backlight enable and level with spinlock

Daniel Vetter daniel at ffwll.ch
Tue Apr 2 15:39:14 CEST 2013


On Tue, Apr 02, 2013 at 03:48:10PM +0300, Jani Nikula wrote:
> Backlight is fiddled both through backlight sysfs files and asle
> interrupts. Protect the relevant data.

It's also used by our modeset code in the lvds/edp enable/disable hooks.

> Signed-off-by: Jani Nikula <jani.nikula at intel.com>

Besides the panel code there's also the register save/restore code in
i915_suspend.c. I think that also needs to be protected with this new
spinlock.

That will get a bit ugly though, since that code is also used for ums  and
in that case we won't set up the backlight code and so not initialize the
spinlock. Either splatter really ugly if (DRIVER_MODESET) checks or make
two copies of that stuff ...

Cheers, Daniel

> ---
>  drivers/gpu/drm/i915/i915_drv.h    |    1 +
>  drivers/gpu/drm/i915/intel_panel.c |   16 ++++++++++++++++
>  2 files changed, 17 insertions(+)
> 
> diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
> index 5e38a2c..2e59610 100644
> --- a/drivers/gpu/drm/i915/i915_drv.h
> +++ b/drivers/gpu/drm/i915/i915_drv.h
> @@ -943,6 +943,7 @@ typedef struct drm_i915_private {
>  	struct {
>  		int level;
>  		bool enabled;
> +		spinlock_t lock;
>  		struct backlight_device *device;
>  	} backlight;
>  
> diff --git a/drivers/gpu/drm/i915/intel_panel.c b/drivers/gpu/drm/i915/intel_panel.c
> index 0e7e873..2a95297 100644
> --- a/drivers/gpu/drm/i915/intel_panel.c
> +++ b/drivers/gpu/drm/i915/intel_panel.c
> @@ -285,6 +285,9 @@ static void intel_panel_actually_set_backlight(struct drm_device *dev, u32 level
>  void intel_panel_set_backlight(struct drm_device *dev, u32 level)
>  {
>  	struct drm_i915_private *dev_priv = dev->dev_private;
> +	unsigned long flags;
> +
> +	spin_lock_irqsave(&dev_priv->backlight.lock, flags);
>  
>  	dev_priv->backlight.level = level;
>  	if (dev_priv->backlight.device)
> @@ -292,11 +295,16 @@ void intel_panel_set_backlight(struct drm_device *dev, u32 level)
>  
>  	if (dev_priv->backlight.enabled)
>  		intel_panel_actually_set_backlight(dev, level);
> +
> +	spin_unlock_irqrestore(&dev_priv->backlight.lock, flags);
>  }
>  
>  void intel_panel_disable_backlight(struct drm_device *dev)
>  {
>  	struct drm_i915_private *dev_priv = dev->dev_private;
> +	unsigned long flags;
> +
> +	spin_lock_irqsave(&dev_priv->backlight.lock, flags);
>  
>  	dev_priv->backlight.enabled = false;
>  	intel_panel_actually_set_backlight(dev, 0);
> @@ -314,12 +322,17 @@ void intel_panel_disable_backlight(struct drm_device *dev)
>  			I915_WRITE(BLC_PWM_PCH_CTL1, tmp);
>  		}
>  	}
> +
> +	spin_unlock_irqrestore(&dev_priv->backlight.lock, flags);
>  }
>  
>  void intel_panel_enable_backlight(struct drm_device *dev,
>  				  enum pipe pipe)
>  {
>  	struct drm_i915_private *dev_priv = dev->dev_private;
> +	unsigned long flags;
> +
> +	spin_lock_irqsave(&dev_priv->backlight.lock, flags);
>  
>  	if (dev_priv->backlight.level == 0) {
>  		dev_priv->backlight.level = intel_panel_get_max_backlight(dev);
> @@ -372,12 +385,15 @@ set_level:
>  	 */
>  	if (!intel_panel_get_backlight(dev))
>  		intel_panel_actually_set_backlight(dev, dev_priv->backlight.level);
> +
> +	spin_unlock_irqrestore(&dev_priv->backlight.lock, flags);
>  }
>  
>  static void intel_panel_init_backlight(struct drm_device *dev)
>  {
>  	struct drm_i915_private *dev_priv = dev->dev_private;
>  
> +	spin_lock_init(&dev_priv->backlight.lock);
>  	dev_priv->backlight.level = intel_panel_get_backlight(dev);
>  	dev_priv->backlight.enabled = dev_priv->backlight.level != 0;
>  }
> -- 
> 1.7.9.5
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx

-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch



More information about the Intel-gfx mailing list