diff mbox

drm/i915/bxt: BLC implementation

Message ID 1430817716-5552-1-git-send-email-vandana.kannan@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

vandana.kannan@intel.com May 5, 2015, 9:21 a.m. UTC
Enabling BLC on BXT.
Includes register definition, and new functions for BXT.

In BXT, there are 2 sets of registers for BLC. Until there is clarity
about which set would be effective, set 1 is being used.
This would have to be re-visited if there is any change or when 2 LFPs are
enabled on BXT.

This patch enables brightness change which would be effected by use of
hot-keys or sysfs entry.

TODO:- BLC implementation will have to re-visited when
1. there is clarity about which set of registers has to be used and when.
2. CDCLK frequency is changed

v2: Jani's review comments
	- Modified comment in i915_reg.h
	- Renamed register defintions
	- Removed definition of duty cycle max. Not required now and its not 64-bit.

v3:
  - Rebase on top of VLV/CHV backlight changes, in particuliar
    bxt_set_backlight() now has a different prototype (Damien)

Reviewed-by: Jani Nikula <jani.nikula@intel.com>
Signed-off-by: Vandana Kannan <vandana.kannan@intel.com>
Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
Cc: Jani Nikula <jani.nikula@linux.intel.com>
Cc: Shankar, Uma <uma.shankar@intel.com>
---
 drivers/gpu/drm/i915/i915_reg.h    | 12 ++++++
 drivers/gpu/drm/i915/intel_panel.c | 87 +++++++++++++++++++++++++++++++++++++-
 2 files changed, 98 insertions(+), 1 deletion(-)

Comments

Jani Nikula May 5, 2015, 11:33 a.m. UTC | #1
On Tue, 05 May 2015, Vandana Kannan <vandana.kannan@intel.com> wrote:
> Enabling BLC on BXT.
> Includes register definition, and new functions for BXT.
>
> In BXT, there are 2 sets of registers for BLC. Until there is clarity
> about which set would be effective, set 1 is being used.
> This would have to be re-visited if there is any change or when 2 LFPs are
> enabled on BXT.
>
> This patch enables brightness change which would be effected by use of
> hot-keys or sysfs entry.
>
> TODO:- BLC implementation will have to re-visited when
> 1. there is clarity about which set of registers has to be used and when.
> 2. CDCLK frequency is changed
>
> v2: Jani's review comments
> 	- Modified comment in i915_reg.h
> 	- Renamed register defintions
> 	- Removed definition of duty cycle max. Not required now and its not 64-bit.
>
> v3:
>   - Rebase on top of VLV/CHV backlight changes, in particuliar
>     bxt_set_backlight() now has a different prototype (Damien)
>
> Reviewed-by: Jani Nikula <jani.nikula@intel.com>

Yup.


> Signed-off-by: Vandana Kannan <vandana.kannan@intel.com>
> Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
> Cc: Jani Nikula <jani.nikula@linux.intel.com>
> Cc: Shankar, Uma <uma.shankar@intel.com>
> ---
>  drivers/gpu/drm/i915/i915_reg.h    | 12 ++++++
>  drivers/gpu/drm/i915/intel_panel.c | 87 +++++++++++++++++++++++++++++++++++++-
>  2 files changed, 98 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_reg.h b/drivers/gpu/drm/i915/i915_reg.h
> index 36805b6..9d79e17 100644
> --- a/drivers/gpu/drm/i915/i915_reg.h
> +++ b/drivers/gpu/drm/i915/i915_reg.h
> @@ -3480,6 +3480,18 @@ enum skl_disp_power_wells {
>  #define UTIL_PIN_CTL		0x48400
>  #define   UTIL_PIN_ENABLE	(1 << 31)
>  
> +/* BXT backlight register definition. */
> +#define BXT_BLC_PWM_CTL1			0xC8250
> +#define   BXT_BLC_PWM_ENABLE			(1 << 31)
> +#define   BXT_BLC_PWM_POLARITY			(1 << 29)
> +#define BXT_BLC_PWM_FREQ1			0xC8254
> +#define BXT_BLC_PWM_DUTY1			0xC8258
> +
> +#define BXT_BLC_PWM_CTL2			0xC8350
> +#define BXT_BLC_PWM_FREQ2			0xC8354
> +#define BXT_BLC_PWM_DUTY2			0xC8358
> +
> +
>  #define PCH_GTC_CTL		0xe7000
>  #define   PCH_GTC_ENABLE	(1 << 31)
>  
> diff --git a/drivers/gpu/drm/i915/intel_panel.c b/drivers/gpu/drm/i915/intel_panel.c
> index d8686ce..06d0953 100644
> --- a/drivers/gpu/drm/i915/intel_panel.c
> +++ b/drivers/gpu/drm/i915/intel_panel.c
> @@ -535,6 +535,14 @@ static u32 vlv_get_backlight(struct intel_connector *connector)
>  	return _vlv_get_backlight(dev, pipe);
>  }
>  
> +static u32 bxt_get_backlight(struct intel_connector *connector)
> +{
> +	struct drm_device *dev = connector->base.dev;
> +	struct drm_i915_private *dev_priv = dev->dev_private;
> +
> +	return I915_READ(BXT_BLC_PWM_DUTY1);
> +}
> +
>  static u32 intel_panel_get_backlight(struct intel_connector *connector)
>  {
>  	struct drm_device *dev = connector->base.dev;
> @@ -615,6 +623,14 @@ static void vlv_set_backlight(struct intel_connector *connector, u32 level)
>  	I915_WRITE(VLV_BLC_PWM_CTL(pipe), tmp | level);
>  }
>  
> +static void bxt_set_backlight(struct intel_connector *connector, u32 level)
> +{
> +	struct drm_device *dev = connector->base.dev;
> +	struct drm_i915_private *dev_priv = dev->dev_private;
> +
> +	I915_WRITE(BXT_BLC_PWM_DUTY1, level);
> +}
> +
>  static void
>  intel_panel_actually_set_backlight(struct intel_connector *connector, u32 level)
>  {
> @@ -740,6 +756,18 @@ static void vlv_disable_backlight(struct intel_connector *connector)
>  	I915_WRITE(VLV_BLC_PWM_CTL2(pipe), tmp & ~BLM_PWM_ENABLE);
>  }
>  
> +static void bxt_disable_backlight(struct intel_connector *connector)
> +{
> +	struct drm_device *dev = connector->base.dev;
> +	struct drm_i915_private *dev_priv = dev->dev_private;
> +	u32 tmp;
> +
> +	intel_panel_actually_set_backlight(connector, 0);
> +
> +	tmp = I915_READ(BXT_BLC_PWM_CTL1);
> +	I915_WRITE(BXT_BLC_PWM_CTL1, tmp & ~BXT_BLC_PWM_ENABLE);
> +}
> +
>  void intel_panel_disable_backlight(struct intel_connector *connector)
>  {
>  	struct drm_device *dev = connector->base.dev;
> @@ -946,6 +974,33 @@ static void vlv_enable_backlight(struct intel_connector *connector)
>  	I915_WRITE(VLV_BLC_PWM_CTL2(pipe), ctl2 | BLM_PWM_ENABLE);
>  }
>  
> +static void bxt_enable_backlight(struct intel_connector *connector)
> +{
> +	struct drm_device *dev = connector->base.dev;
> +	struct drm_i915_private *dev_priv = dev->dev_private;
> +	struct intel_panel *panel = &connector->panel;
> +	u32 pwm_ctl;
> +
> +	pwm_ctl = I915_READ(BXT_BLC_PWM_CTL1);
> +	if (pwm_ctl & BXT_BLC_PWM_ENABLE) {
> +		DRM_DEBUG_KMS("backlight already enabled\n");
> +		pwm_ctl &= ~BXT_BLC_PWM_ENABLE;
> +		I915_WRITE(BXT_BLC_PWM_CTL1, pwm_ctl);
> +	}
> +
> +	I915_WRITE(BXT_BLC_PWM_FREQ1, panel->backlight.max);
> +
> +	intel_panel_actually_set_backlight(connector, panel->backlight.level);
> +
> +	pwm_ctl = 0;
> +	if (panel->backlight.active_low_pwm)
> +		pwm_ctl |= BXT_BLC_PWM_POLARITY;
> +
> +	I915_WRITE(BXT_BLC_PWM_CTL1, pwm_ctl);
> +	POSTING_READ(BXT_BLC_PWM_CTL1);
> +	I915_WRITE(BXT_BLC_PWM_CTL1, pwm_ctl | BXT_BLC_PWM_ENABLE);
> +}
> +
>  void intel_panel_enable_backlight(struct intel_connector *connector)
>  {
>  	struct drm_device *dev = connector->base.dev;
> @@ -1298,6 +1353,30 @@ static int vlv_setup_backlight(struct intel_connector *connector, enum pipe pipe
>  	return 0;
>  }
>  
> +static int
> +bxt_setup_backlight(struct intel_connector *connector, enum pipe unused)
> +{
> +	struct drm_device *dev = connector->base.dev;
> +	struct drm_i915_private *dev_priv = dev->dev_private;
> +	struct intel_panel *panel = &connector->panel;
> +	u32 pwm_ctl, val;
> +
> +	pwm_ctl = I915_READ(BXT_BLC_PWM_CTL1);
> +	panel->backlight.active_low_pwm = pwm_ctl & BXT_BLC_PWM_POLARITY;
> +
> +	panel->backlight.max = I915_READ(BXT_BLC_PWM_FREQ1);
> +	if (!panel->backlight.max)
> +		return -ENODEV;
> +
> +	val = bxt_get_backlight(connector);
> +	panel->backlight.level = intel_panel_compute_brightness(connector, val);
> +
> +	panel->backlight.enabled = (pwm_ctl & BXT_BLC_PWM_ENABLE) &&
> +		panel->backlight.level != 0;
> +
> +	return 0;
> +}
> +
>  int intel_panel_setup_backlight(struct drm_connector *connector, enum pipe pipe)
>  {
>  	struct drm_device *dev = connector->dev;
> @@ -1349,7 +1428,13 @@ void intel_panel_init_backlight_funcs(struct drm_device *dev)
>  {
>  	struct drm_i915_private *dev_priv = dev->dev_private;
>  
> -	if (IS_BROADWELL(dev) || (INTEL_INFO(dev)->gen >= 9)) {
> +	if (IS_BROXTON(dev)) {
> +		dev_priv->display.setup_backlight = bxt_setup_backlight;
> +		dev_priv->display.enable_backlight = bxt_enable_backlight;
> +		dev_priv->display.disable_backlight = bxt_disable_backlight;
> +		dev_priv->display.set_backlight = bxt_set_backlight;
> +		dev_priv->display.get_backlight = bxt_get_backlight;
> +	} else if (IS_BROADWELL(dev) || IS_SKYLAKE(dev)) {
>  		dev_priv->display.setup_backlight = bdw_setup_backlight;
>  		dev_priv->display.enable_backlight = bdw_enable_backlight;
>  		dev_priv->display.disable_backlight = pch_disable_backlight;
> -- 
> 2.0.1
>
Shuang He May 5, 2015, 2:30 p.m. UTC | #2
Tested-By: Intel Graphics QA PRTS (Patch Regression Test System Contact: shuang.he@intel.com)
Task id: 6318
-------------------------------------Summary-------------------------------------
Platform          Delta          drm-intel-nightly          Series Applied
PNV                                  276/276              276/276
ILK                                  302/302              302/302
SNB                                  316/316              316/316
IVB                                  342/342              342/342
BYT                                  286/286              286/286
BDW                                  318/318              318/318
-------------------------------------Detailed-------------------------------------
Platform  Test                                drm-intel-nightly          Series Applied
Note: You need to pay more attention to line start with '*'
Daniel Vetter May 6, 2015, 11:17 a.m. UTC | #3
On Tue, May 05, 2015 at 02:33:39PM +0300, Jani Nikula wrote:
> On Tue, 05 May 2015, Vandana Kannan <vandana.kannan@intel.com> wrote:
> > Enabling BLC on BXT.
> > Includes register definition, and new functions for BXT.
> >
> > In BXT, there are 2 sets of registers for BLC. Until there is clarity
> > about which set would be effective, set 1 is being used.
> > This would have to be re-visited if there is any change or when 2 LFPs are
> > enabled on BXT.
> >
> > This patch enables brightness change which would be effected by use of
> > hot-keys or sysfs entry.
> >
> > TODO:- BLC implementation will have to re-visited when
> > 1. there is clarity about which set of registers has to be used and when.
> > 2. CDCLK frequency is changed
> >
> > v2: Jani's review comments
> > 	- Modified comment in i915_reg.h
> > 	- Renamed register defintions
> > 	- Removed definition of duty cycle max. Not required now and its not 64-bit.
> >
> > v3:
> >   - Rebase on top of VLV/CHV backlight changes, in particuliar
> >     bxt_set_backlight() now has a different prototype (Damien)
> >
> > Reviewed-by: Jani Nikula <jani.nikula@intel.com>
> 
> Yup.

Queued for -next, thanks for the patch.
-Daniel
diff mbox

Patch

diff --git a/drivers/gpu/drm/i915/i915_reg.h b/drivers/gpu/drm/i915/i915_reg.h
index 36805b6..9d79e17 100644
--- a/drivers/gpu/drm/i915/i915_reg.h
+++ b/drivers/gpu/drm/i915/i915_reg.h
@@ -3480,6 +3480,18 @@  enum skl_disp_power_wells {
 #define UTIL_PIN_CTL		0x48400
 #define   UTIL_PIN_ENABLE	(1 << 31)
 
+/* BXT backlight register definition. */
+#define BXT_BLC_PWM_CTL1			0xC8250
+#define   BXT_BLC_PWM_ENABLE			(1 << 31)
+#define   BXT_BLC_PWM_POLARITY			(1 << 29)
+#define BXT_BLC_PWM_FREQ1			0xC8254
+#define BXT_BLC_PWM_DUTY1			0xC8258
+
+#define BXT_BLC_PWM_CTL2			0xC8350
+#define BXT_BLC_PWM_FREQ2			0xC8354
+#define BXT_BLC_PWM_DUTY2			0xC8358
+
+
 #define PCH_GTC_CTL		0xe7000
 #define   PCH_GTC_ENABLE	(1 << 31)
 
diff --git a/drivers/gpu/drm/i915/intel_panel.c b/drivers/gpu/drm/i915/intel_panel.c
index d8686ce..06d0953 100644
--- a/drivers/gpu/drm/i915/intel_panel.c
+++ b/drivers/gpu/drm/i915/intel_panel.c
@@ -535,6 +535,14 @@  static u32 vlv_get_backlight(struct intel_connector *connector)
 	return _vlv_get_backlight(dev, pipe);
 }
 
+static u32 bxt_get_backlight(struct intel_connector *connector)
+{
+	struct drm_device *dev = connector->base.dev;
+	struct drm_i915_private *dev_priv = dev->dev_private;
+
+	return I915_READ(BXT_BLC_PWM_DUTY1);
+}
+
 static u32 intel_panel_get_backlight(struct intel_connector *connector)
 {
 	struct drm_device *dev = connector->base.dev;
@@ -615,6 +623,14 @@  static void vlv_set_backlight(struct intel_connector *connector, u32 level)
 	I915_WRITE(VLV_BLC_PWM_CTL(pipe), tmp | level);
 }
 
+static void bxt_set_backlight(struct intel_connector *connector, u32 level)
+{
+	struct drm_device *dev = connector->base.dev;
+	struct drm_i915_private *dev_priv = dev->dev_private;
+
+	I915_WRITE(BXT_BLC_PWM_DUTY1, level);
+}
+
 static void
 intel_panel_actually_set_backlight(struct intel_connector *connector, u32 level)
 {
@@ -740,6 +756,18 @@  static void vlv_disable_backlight(struct intel_connector *connector)
 	I915_WRITE(VLV_BLC_PWM_CTL2(pipe), tmp & ~BLM_PWM_ENABLE);
 }
 
+static void bxt_disable_backlight(struct intel_connector *connector)
+{
+	struct drm_device *dev = connector->base.dev;
+	struct drm_i915_private *dev_priv = dev->dev_private;
+	u32 tmp;
+
+	intel_panel_actually_set_backlight(connector, 0);
+
+	tmp = I915_READ(BXT_BLC_PWM_CTL1);
+	I915_WRITE(BXT_BLC_PWM_CTL1, tmp & ~BXT_BLC_PWM_ENABLE);
+}
+
 void intel_panel_disable_backlight(struct intel_connector *connector)
 {
 	struct drm_device *dev = connector->base.dev;
@@ -946,6 +974,33 @@  static void vlv_enable_backlight(struct intel_connector *connector)
 	I915_WRITE(VLV_BLC_PWM_CTL2(pipe), ctl2 | BLM_PWM_ENABLE);
 }
 
+static void bxt_enable_backlight(struct intel_connector *connector)
+{
+	struct drm_device *dev = connector->base.dev;
+	struct drm_i915_private *dev_priv = dev->dev_private;
+	struct intel_panel *panel = &connector->panel;
+	u32 pwm_ctl;
+
+	pwm_ctl = I915_READ(BXT_BLC_PWM_CTL1);
+	if (pwm_ctl & BXT_BLC_PWM_ENABLE) {
+		DRM_DEBUG_KMS("backlight already enabled\n");
+		pwm_ctl &= ~BXT_BLC_PWM_ENABLE;
+		I915_WRITE(BXT_BLC_PWM_CTL1, pwm_ctl);
+	}
+
+	I915_WRITE(BXT_BLC_PWM_FREQ1, panel->backlight.max);
+
+	intel_panel_actually_set_backlight(connector, panel->backlight.level);
+
+	pwm_ctl = 0;
+	if (panel->backlight.active_low_pwm)
+		pwm_ctl |= BXT_BLC_PWM_POLARITY;
+
+	I915_WRITE(BXT_BLC_PWM_CTL1, pwm_ctl);
+	POSTING_READ(BXT_BLC_PWM_CTL1);
+	I915_WRITE(BXT_BLC_PWM_CTL1, pwm_ctl | BXT_BLC_PWM_ENABLE);
+}
+
 void intel_panel_enable_backlight(struct intel_connector *connector)
 {
 	struct drm_device *dev = connector->base.dev;
@@ -1298,6 +1353,30 @@  static int vlv_setup_backlight(struct intel_connector *connector, enum pipe pipe
 	return 0;
 }
 
+static int
+bxt_setup_backlight(struct intel_connector *connector, enum pipe unused)
+{
+	struct drm_device *dev = connector->base.dev;
+	struct drm_i915_private *dev_priv = dev->dev_private;
+	struct intel_panel *panel = &connector->panel;
+	u32 pwm_ctl, val;
+
+	pwm_ctl = I915_READ(BXT_BLC_PWM_CTL1);
+	panel->backlight.active_low_pwm = pwm_ctl & BXT_BLC_PWM_POLARITY;
+
+	panel->backlight.max = I915_READ(BXT_BLC_PWM_FREQ1);
+	if (!panel->backlight.max)
+		return -ENODEV;
+
+	val = bxt_get_backlight(connector);
+	panel->backlight.level = intel_panel_compute_brightness(connector, val);
+
+	panel->backlight.enabled = (pwm_ctl & BXT_BLC_PWM_ENABLE) &&
+		panel->backlight.level != 0;
+
+	return 0;
+}
+
 int intel_panel_setup_backlight(struct drm_connector *connector, enum pipe pipe)
 {
 	struct drm_device *dev = connector->dev;
@@ -1349,7 +1428,13 @@  void intel_panel_init_backlight_funcs(struct drm_device *dev)
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;
 
-	if (IS_BROADWELL(dev) || (INTEL_INFO(dev)->gen >= 9)) {
+	if (IS_BROXTON(dev)) {
+		dev_priv->display.setup_backlight = bxt_setup_backlight;
+		dev_priv->display.enable_backlight = bxt_enable_backlight;
+		dev_priv->display.disable_backlight = bxt_disable_backlight;
+		dev_priv->display.set_backlight = bxt_set_backlight;
+		dev_priv->display.get_backlight = bxt_get_backlight;
+	} else if (IS_BROADWELL(dev) || IS_SKYLAKE(dev)) {
 		dev_priv->display.setup_backlight = bdw_setup_backlight;
 		dev_priv->display.enable_backlight = bdw_enable_backlight;
 		dev_priv->display.disable_backlight = pch_disable_backlight;