diff mbox

Legacy backlight control with KMS and BACKLIGHT property

Message ID 20090817075650.GA8024@zhen-devel.sh.intel.com (mailing list archive)
State Not Applicable
Headers show

Commit Message

Zhenyu Wang Aug. 17, 2009, 7:56 a.m. UTC
On 2009.08.14 19:54:05 +0200, Matthias Hopf wrote:
> What we're supposing is
> 
> - a kernel driver for the /sys/class/backlight/ api for the legacy method

yeah, I think /sys/class/backlight/ should be the only backlight interface for 
any user space apps or X RandR property creation. So we need to add backlight
device inside i915 KMS driver, when !acpi_video_backlight_support().

Current KMS driver like LVDS only do PWM operation, maybe combo will be better
if it's supposed to be, Jesse?

> - support in the driver to actually open this one (trivial)

yeah.

> - support for the BACKLIGHT property in KMS case, *only* using the
>   kernel api method for now (will need some abstraction)

Current x-v-i driver in KMS could setup any property for all connectors,
like attached testing patch which will hook the property up. But if we just go 
with opening /sys/class/backlight/ in xorg driver, we simply don't need it...

So for X BACKLIGHT property creation, we'll have a checklist for acpi_video,
platform_driver, and new backlight device maybe like 'intel_lvds'.

Comments

Zhao, Yakui Aug. 17, 2009, 9:05 a.m. UTC | #1
On Mon, 2009-08-17 at 15:56 +0800, Zhenyu Wang wrote:
> On 2009.08.14 19:54:05 +0200, Matthias Hopf wrote:
> > What we're supposing is
> > 
> > - a kernel driver for the /sys/class/backlight/ api for the legacy method
> 
> yeah, I think /sys/class/backlight/ should be the only backlight interface for 
> any user space apps or X RandR property creation. So we need to add backlight
> device inside i915 KMS driver, when !acpi_video_backlight_support().
the function of acpi_video_backlight_support only checks whether the
generic acpi video method is supported.(_BCL/_BCM acpi video extension
method).

And we should also check whether the platform driver will register the
backlight interface.

Only when there is neither generic acpi video nor platform backlight
interface, we will register the i915 backlight interface. 
In such case the dependency is too strict. And it is not easy to handle
the three interface.
> 
> Current KMS driver like LVDS only do PWM operation, maybe combo will be better
> if it's supposed to be, Jesse?
> 
> > - support in the driver to actually open this one (trivial)
> 
> yeah.
> 
> > - support for the BACKLIGHT property in KMS case, *only* using the
> >   kernel api method for now (will need some abstraction)
> 
> Current x-v-i driver in KMS could setup any property for all connectors,
> like attached testing patch which will hook the property up. But if we just go 
> with opening /sys/class/backlight/ in xorg driver, we simply don't need it...
If the backlight is controlled by using the /sys/class/backlight/*
interface, then we can hook up this interface in video driver so that
the xrandr can adjust the brightness.

Thanks.
> 
> So for X BACKLIGHT property creation, we'll have a checklist for acpi_video,
> platform_driver, and new backlight device maybe like 'intel_lvds'.
>
Jesse Barnes Aug. 17, 2009, 5:45 p.m. UTC | #2
On Mon, 17 Aug 2009 15:56:50 +0800
Zhenyu Wang <zhenyuw@linux.intel.com> wrote:

> On 2009.08.14 19:54:05 +0200, Matthias Hopf wrote:
> > What we're supposing is
> > 
> > - a kernel driver for the /sys/class/backlight/ api for the legacy
> > method
> 
> yeah, I think /sys/class/backlight/ should be the only backlight
> interface for any user space apps or X RandR property creation. So we
> need to add backlight device inside i915 KMS driver,
> when !acpi_video_backlight_support().
> 
> Current KMS driver like LVDS only do PWM operation, maybe combo will
> be better if it's supposed to be, Jesse?

We'll want PWM+LBB and plain LBB at a minimum; not sure if we need a
plain PWM variant.

> Current x-v-i driver in KMS could setup any property for all
> connectors, like attached testing patch which will hook the property
> up. But if we just go with opening /sys/class/backlight/ in xorg
> driver, we simply don't need it...

Right, we can just expose whatever /sys/class/backlight interface we
find through x-v-i for xrandr/xbacklight.  No need for the
BACKLIGHT_CONTROL property.

> So for X BACKLIGHT property creation, we'll have a checklist for
> acpi_video, platform_driver, and new backlight device maybe like
> 'intel_lvds'.

If we see more than one interface in /sys/class/backlight we should
also consider it a kernel bug (unless they control different displays
somehow; but the /sys/class/backlight API would need work for that).
diff mbox

Patch

diff --git a/drivers/gpu/drm/i915/intel_lvds.c b/drivers/gpu/drm/i915/intel_lvds.c
index 3f445a8..e1affea 100644
--- a/drivers/gpu/drm/i915/intel_lvds.c
+++ b/drivers/gpu/drm/i915/intel_lvds.c
@@ -53,6 +53,7 @@  struct intel_lvds_priv {
 	int fitting_mode;
 	u32 pfit_control;
 	u32 pfit_pgm_ratios;
+	struct drm_property *backlight;
 };
 
 /**
@@ -75,6 +76,20 @@  static void intel_lvds_set_backlight(struct drm_device *dev, int level)
 				 (level << BACKLIGHT_DUTY_CYCLE_SHIFT)));
 }
 
+static u32 intel_lvds_get_backlight(struct drm_device *dev)
+{
+	struct drm_i915_private *dev_priv = dev->dev_private;
+	u32 blc_pwm_ctl, reg;
+
+	if (IS_IGDNG(dev))
+		reg = BLC_PWM_CPU_CTL;
+	else
+		reg = BLC_PWM_CTL;
+
+	blc_pwm_ctl = I915_READ(reg) & BACKLIGHT_DUTY_CYCLE_MASK;
+	return  blc_pwm_ctl;
+}
+
 /**
  * Returns the maximum level of the backlight duty cycle field.
  */
@@ -667,6 +682,7 @@  static int intel_lvds_set_property(struct drm_connector *connector,
 	struct drm_device *dev = connector->dev;
 	struct intel_output *intel_output =
 			to_intel_output(connector);
+	struct intel_lvds_priv *lvds_priv = intel_output->dev_priv;
 
 	if (property == dev->mode_config.scaling_mode_property &&
 				connector->encoder) {
@@ -690,6 +706,8 @@  static int intel_lvds_set_property(struct drm_connector *connector,
 			drm_crtc_helper_set_mode(crtc, &crtc->mode,
 				crtc->x, crtc->y, crtc->fb);
 		}
+	} else if (property == lvds_priv->backlight) {
+	    intel_lvds_set_backlight(dev, value);
 	}
 
 	return 0;
@@ -1009,7 +1028,17 @@  void intel_lvds_init(struct drm_device *dev)
 	if (!dev_priv->panel_fixed_mode)
 		goto failed;
 
+
 out:
+	/* backlight property */
+	lvds_priv->backlight = drm_property_create(dev, DRM_MODE_PROP_RANGE,
+							"BACKLIGHT", 2);
+	lvds_priv->backlight->values[0] = 0;
+	lvds_priv->backlight->values[1] = intel_lvds_get_max_backlight(dev);
+	drm_connector_attach_property(&intel_output->base,
+				      lvds_priv->backlight,
+				      (uint64_t)intel_lvds_get_backlight(dev));
+
 	if (IS_IGDNG(dev)) {
 		u32 pwm;
 		/* make sure PWM is enabled */