diff mbox

i915 native backlight never got merged

Message ID 1313143895.876.5.camel@fauix11.informatik.uni-erlangen.de (mailing list archive)
State New, archived
Headers show

Commit Message

Michel Alexandre Salim Aug. 12, 2011, 10:11 a.m. UTC
Hi Keith & all,
On Thu, 2011-08-11 at 15:28 -0700, Keith Packard wrote:
> On Thu, 11 Aug 2011 21:36:38 +0200, Michel Alexandre Salim <salimma@fedoraproject.org> wrote:
> 
> > Since there's no known regression introduced by Matthew's patch, could
> > it be merged? Feel free to add a
> 
> I've had to amend the patch a bit to get it to apply on top of
> drm-intel-fixes; anyone care to take a look and see if it still looks
> reasonable (and/or actually works?)
> 
Matthew's last patch from July 16th applies without modification on top
of Linux 3.0 and 3.1-rc1, and applies with some offsets on top of
drm-intel-fixes.

I've eyeballed the code and they look identical apart from some lines
struct changes being transposed a bit, and intel_panel_init_backlight is
no longer static; please find the patch attached below (with my
Tested-by: added)

From fa7419eee713b989e2c268c7b06ec9a544a2b647 Mon Sep 17 00:00:00 2001
From: Matthew Garrett <mjg@redhat.com>
Date: Sat, 16 Jul 2011 23:31:01 +1000
Subject: [PATCH] Not all systems expose a firmware or platform mechanism for
 changing the backlight intensity on i915, so add native
 driver support.

Signed-off-by: Matthew Garrett <mjg@redhat.com>
Cc: Richard Purdie <rpurdie@rpsys.net>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: David Airlie <airlied@linux.ie>
Cc: Alex Deucher <alexdeucher@gmail.com>
Cc: Ben Skeggs <bskeggs@redhat.com>
Cc: Zhang Rui <rui.zhang@intel.com>
Cc: Len Brown <lenb@kernel.org>
Cc: Jesse Barnes <jbarnes@virtuousgeek.org>
Tested-by: Sedat Dilek <sedat.dilek@googlemail.com>
Tested-by: Michel Alexandre Salim <salimma@fedoraproject.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
 drivers/gpu/drm/i915/i915_drv.h       |    4 ++
 drivers/gpu/drm/i915/intel_dp.c       |    7 +++
 drivers/gpu/drm/i915/intel_drv.h      |    3 +-
 drivers/gpu/drm/i915/intel_lvds.c     |    5 ++
 drivers/gpu/drm/i915/intel_opregion.c |    1 -
 drivers/gpu/drm/i915/intel_panel.c    |   72 ++++++++++++++++++++++++++++++++-
 6 files changed, 89 insertions(+), 3 deletions(-)

Comments

Keith Packard Aug. 12, 2011, 1:52 p.m. UTC | #1
On Fri, 12 Aug 2011 12:11:33 +0200, Michel Alexandre Salim <salimma@fedoraproject.org> wrote:

> Matthew's last patch from July 16th applies without modification on top
> of Linux 3.0 and 3.1-rc1, and applies with some offsets on top of
> drm-intel-fixes.

I must have skipped right over it somehow.

> I've eyeballed the code and they look identical apart from some lines
> struct changes being transposed a bit, and intel_panel_init_backlight is
> no longer static; please find the patch attached below (with my
> Tested-by: added)

I'll merge this version, with the change to make
intel_panel_init_backlight static (it's not declared in a header, and
isn't used outside of intel_panel.c).

Thanks for finding this version!
Kamal Mostafa Aug. 12, 2011, 4:34 p.m. UTC | #2
On Fri, 2011-08-12 at 06:52 -0700, Keith Packard wrote:
> On Fri, 12 Aug 2011 12:11:33 +0200, Michel Alexandre Salim <salimma@fedoraproject.org> wrote:
> 
> > Matthew's last patch from July 16th applies without modification on top
> > of Linux 3.0 and 3.1-rc1 [...]
>> From fa7419eee713b989e2c268c7b06ec9a544a2b647 Mon Sep 17 00:00:00 2001
> 
> I'll merge this version, with the change to make
> intel_panel_init_backlight static (it's not declared in a header, and
> isn't used outside of intel_panel.c).

That version works also works fine for me.

Tested-by: Kamal Mostafa <kamal@canonical.com>

 -Kamal
Michel Alexandre Salim Aug. 15, 2011, 5:38 p.m. UTC | #3
Keith,

On Fri, 2011-08-12 at 09:34 -0700, Kamal Mostafa wrote:
> On Fri, 2011-08-12 at 06:52 -0700, Keith Packard wrote:
> > On Fri, 12 Aug 2011 12:11:33 +0200, Michel Alexandre Salim <salimma@fedoraproject.org> wrote:
> > 
> > > Matthew's last patch from July 16th applies without modification on top
> > > of Linux 3.0 and 3.1-rc1 [...]
> >> From fa7419eee713b989e2c268c7b06ec9a544a2b647 Mon Sep 17 00:00:00 2001
> > 
> > I'll merge this version, with the change to make
> > intel_panel_init_backlight static (it's not declared in a header, and
> > isn't used outside of intel_panel.c).
> 
> That version works also works fine for me.
> 
any update on the merge? I've not seen it anywhere on

  git://git.kernel.org/pub/scm/linux/kernel/git/keithp/linux-2.6

Thanks,
Keith Packard Aug. 15, 2011, 6:03 p.m. UTC | #4
On Mon, 15 Aug 2011 19:38:34 +0200, Michel Alexandre Salim <salimma@fedoraproject.org> wrote:

> any update on the merge? I've not seen it anywhere on

It's merged locally; I'm struggling with an SSC bug that's sitting on
top of drm-intel-fixes and needs to either be fixed or reverted. In any
case, the backlight fix will head off to Linus shortly.
diff mbox

Patch

diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 6867e19..886bd29 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -36,6 +36,7 @@ 
 #include <linux/io-mapping.h>
 #include <linux/i2c.h>
 #include <drm/intel-gtt.h>
+#include <linux/backlight.h>
 
 /* General customization:
  */
@@ -689,6 +690,7 @@  typedef struct drm_i915_private {
 	int child_dev_num;
 	struct child_device_config *child_dev;
 	struct drm_connector *int_lvds_connector;
+	struct drm_connector *int_edp_connector;
 
 	bool mchbar_need_disable;
 
@@ -722,6 +724,8 @@  typedef struct drm_i915_private {
 	/* list of fbdev register on this device */
 	struct intel_fbdev *fbdev;
 
+	struct backlight_device *backlight;
+
 	struct drm_property *broadcast_rgb_property;
 	struct drm_property *force_audio_property;
 
diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
index f797fb5..2cde606 100644
--- a/drivers/gpu/drm/i915/intel_dp.c
+++ b/drivers/gpu/drm/i915/intel_dp.c
@@ -1811,6 +1811,11 @@  done:
 static void
 intel_dp_destroy (struct drm_connector *connector)
 {
+	struct drm_device *dev = connector->dev;
+
+	if (intel_dpd_is_edp(dev))
+		intel_panel_destroy_backlight(dev);
+
 	drm_sysfs_connector_remove(connector);
 	drm_connector_cleanup(connector);
 	kfree(connector);
@@ -2043,6 +2048,8 @@  intel_dp_init(struct drm_device *dev, int output_reg)
 					DRM_MODE_TYPE_PREFERRED;
 			}
 		}
+		dev_priv->int_edp_connector = connector;
+		intel_panel_setup_backlight(dev);
 	}
 
 	intel_dp_add_properties(intel_dp, connector);
diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
index 6e990f9..057e2bc 100644
--- a/drivers/gpu/drm/i915/intel_drv.h
+++ b/drivers/gpu/drm/i915/intel_drv.h
@@ -274,9 +274,10 @@  extern void intel_pch_panel_fitting(struct drm_device *dev,
 extern u32 intel_panel_get_max_backlight(struct drm_device *dev);
 extern u32 intel_panel_get_backlight(struct drm_device *dev);
 extern void intel_panel_set_backlight(struct drm_device *dev, u32 level);
-extern void intel_panel_setup_backlight(struct drm_device *dev);
+extern int intel_panel_setup_backlight(struct drm_device *dev);
 extern void intel_panel_enable_backlight(struct drm_device *dev);
 extern void intel_panel_disable_backlight(struct drm_device *dev);
+extern void intel_panel_destroy_backlight(struct drm_device *dev);
 extern enum drm_connector_status intel_panel_detect(struct drm_device *dev);
 
 extern void intel_crtc_load_lut(struct drm_crtc *crtc);
diff --git a/drivers/gpu/drm/i915/intel_lvds.c b/drivers/gpu/drm/i915/intel_lvds.c
index b28f7bd..9104496 100644
--- a/drivers/gpu/drm/i915/intel_lvds.c
+++ b/drivers/gpu/drm/i915/intel_lvds.c
@@ -582,6 +582,8 @@  static void intel_lvds_destroy(struct drm_connector *connector)
 	struct drm_device *dev = connector->dev;
 	struct drm_i915_private *dev_priv = dev->dev_private;
 
+	intel_panel_destroy_backlight(dev);
+
 	if (dev_priv->lid_notifier.notifier_call)
 		acpi_lid_notifier_unregister(&dev_priv->lid_notifier);
 	drm_sysfs_connector_remove(connector);
@@ -1041,6 +1043,9 @@  out:
 	/* keep the LVDS connector */
 	dev_priv->int_lvds_connector = connector;
 	drm_sysfs_connector_add(connector);
+
+	intel_panel_setup_backlight(dev);
+
 	return true;
 
 failed:
diff --git a/drivers/gpu/drm/i915/intel_opregion.c b/drivers/gpu/drm/i915/intel_opregion.c
index b7c5ddb..b8e8158b 100644
--- a/drivers/gpu/drm/i915/intel_opregion.c
+++ b/drivers/gpu/drm/i915/intel_opregion.c
@@ -227,7 +227,6 @@  void intel_opregion_asle_intr(struct drm_device *dev)
 	asle->aslc = asle_stat;
 }
 
-/* Only present on Ironlake+ */
 void intel_opregion_gse_intr(struct drm_device *dev)
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;
diff --git a/drivers/gpu/drm/i915/intel_panel.c b/drivers/gpu/drm/i915/intel_panel.c
index a06ff07..49528c6 100644
--- a/drivers/gpu/drm/i915/intel_panel.c
+++ b/drivers/gpu/drm/i915/intel_panel.c
@@ -273,7 +273,7 @@  void intel_panel_enable_backlight(struct drm_device *dev)
 	dev_priv->backlight_enabled = true;
 }
 
-void intel_panel_setup_backlight(struct drm_device *dev)
+void intel_panel_init_backlight(struct drm_device *dev)
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;
 
@@ -305,3 +305,73 @@  intel_panel_detect(struct drm_device *dev)
 
 	return connector_status_unknown;
 }
+
+#ifdef CONFIG_BACKLIGHT_CLASS_DEVICE
+static int intel_panel_update_status(struct backlight_device *bd)
+{
+	struct drm_device *dev = bl_get_data(bd);
+	intel_panel_set_backlight(dev, bd->props.brightness);
+	return 0;
+}
+
+static int intel_panel_get_brightness(struct backlight_device *bd)
+{
+	struct drm_device *dev = bl_get_data(bd);
+	return intel_panel_get_backlight(dev);
+}
+
+static const struct backlight_ops intel_panel_bl_ops = {
+	.update_status = intel_panel_update_status,
+	.get_brightness = intel_panel_get_brightness,
+};
+
+int intel_panel_setup_backlight(struct drm_device *dev)
+{
+	struct drm_i915_private *dev_priv = dev->dev_private;
+	struct backlight_properties props;
+	struct drm_connector *connector;
+
+	intel_panel_init_backlight(dev);
+
+	if (dev_priv->int_lvds_connector)
+		connector = dev_priv->int_lvds_connector;
+	else if (dev_priv->int_edp_connector)
+		connector = dev_priv->int_edp_connector;
+	else
+		return -ENODEV;
+
+	props.type = BACKLIGHT_RAW;
+	props.max_brightness = intel_panel_get_max_backlight(dev);
+	dev_priv->backlight =
+		backlight_device_register("intel_backlight",
+					  &connector->kdev, dev,
+					  &intel_panel_bl_ops, &props);
+
+	if (IS_ERR(dev_priv->backlight)) {
+		DRM_ERROR("Failed to register backlight: %ld\n",
+			  PTR_ERR(dev_priv->backlight));
+		dev_priv->backlight = NULL;
+		return -ENODEV;
+	}
+	dev_priv->backlight->props.brightness = intel_panel_get_backlight(dev);
+	return 0;
+}
+
+void intel_panel_destroy_backlight(struct drm_device *dev)
+{
+	struct drm_i915_private *dev_priv = dev->dev_private;
+	if (dev_priv->backlight)
+		backlight_device_unregister(dev_priv->backlight);
+}
+#else
+int intel_panel_setup_backlight(struct drm_device *dev)
+{
+	intel_panel_init_backlight(dev);
+	return 0;
+}
+
+void intel_panel_destroy_backlight(struct drm_device *dev)
+{
+	return;
+}
+#endif