Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Brightness buttons don't work in current



Hi There,

As nobody could help me, finally I successfully patched the kernel to handle the brightness buttons on my Dell laptop.
I used the pmf system to notify the driver about the key events.

Please find the patch attached.

Some drawbacks in which I need help to improve:

 * I had to add a new field into struct device in sys/device.h. The new field has a name dv_payload.
   I couldn't find a better solution to save the original drm_device structure for the new callbacks,
   however I think there should be one;
* In both callback functions in intel_panel.c I had to break the connector's loop after the 1st
   iteration. Otherwise the system simply crashes. I have to find out why is that.


So, plase read the patch, try it out.

I could try only on my Dell Latitude E6220, which uses the PCH line. With this patch it works as expected.
Other chips may not work.

Regards,

FeZ
Index: dev/acpi/wmi/wmi_dell.c
===================================================================
RCS file: /cvsroot/src/sys/dev/acpi/wmi/wmi_dell.c,v
retrieving revision 1.11
diff -u -r1.11 wmi_dell.c
--- dev/acpi/wmi/wmi_dell.c	3 Dec 2017 23:43:00 -0000	1.11
+++ dev/acpi/wmi/wmi_dell.c	14 Jan 2019 21:24:31 -0000
@@ -96,6 +96,8 @@
 	/* type 0x10 */
 	{WMI_DELLA_PMF, 0x0010, 0x0057, PMFE_DISPLAY_BRIGHTNESS_DOWN},
 	{WMI_DELLA_PMF, 0x0010, 0x0058, PMFE_DISPLAY_BRIGHTNESS_UP},
+	{WMI_DELLA_PMF, 0x0010, 0x0050, PMFE_DISPLAY_BRIGHTNESS_DOWN},
+	{WMI_DELLA_PMF, 0x0010, 0x0048, PMFE_DISPLAY_BRIGHTNESS_UP},
 	{WMI_DELLA_IGN, 0x0010, 0x0151, 0}, /* Fn-lock */
 	{WMI_DELLA_IGN, 0x0010, 0x0152, 0}, /* keyboard illumination */
 	{WMI_DELLA_PMF, 0x0010, 0x0153, PMFE_RADIO_TOGGLE},
Index: external/bsd/drm2/dist/drm/i915/intel_panel.c
===================================================================
RCS file: /cvsroot/src/sys/external/bsd/drm2/dist/drm/i915/intel_panel.c,v
retrieving revision 1.12
diff -u -r1.12 intel_panel.c
--- external/bsd/drm2/dist/drm/i915/intel_panel.c	6 Oct 2018 15:33:35 -0000	1.12
+++ external/bsd/drm2/dist/drm/i915/intel_panel.c	14 Jan 2019 21:24:40 -0000
@@ -1865,12 +1866,72 @@
 				panel->downclock_mode);
 }
 
-void intel_backlight_register(struct drm_device *dev)
+static void
+intel_panel_backlight_display_brightness_up(device_t dev)
 {
-	struct intel_connector *connector;
+  struct drm_device* parent = dev->dv_payload;
+  u32 level = 0;
+  u32 max_level = 0;
+  u32 step = 0;
+  struct intel_connector *connector;
+  struct intel_panel *panel;
+  list_for_each_entry(connector, &parent->mode_config.connector_list, base.head)
+    {
+      panel = &connector->panel;
+      max_level = panel->backlight.max;
+      step = max_level / 10;
+      level = pch_get_backlight(connector);
+      level += step;
+      if (level > max_level)
+	{
+	  level = max_level;
+	}
+      panel->backlight.set(connector, level);
+      break;
+    }
+  return;
+}
 
-	list_for_each_entry(connector, &dev->mode_config.connector_list, base.head)
-		intel_backlight_device_register(connector);
+static void
+intel_panel_backlight_display_brightness_down(device_t dev)
+{
+  struct drm_device* parent = dev->dv_payload;
+  u32 level = 0;
+  u32 max_level = 0;
+  u32 step = 0;
+  struct intel_connector *connector;
+  struct intel_panel *panel;
+  list_for_each_entry(connector, &parent->mode_config.connector_list, base.head)
+    {
+      panel = &connector->panel;
+      max_level = panel->backlight.max;
+      step = max_level / 10;
+      level = pch_get_backlight(connector);
+      level -= step;
+      if (level < step)
+	{
+	  level = step;
+	}
+      panel->backlight.set(connector, level);
+      break;
+    }
+  return;
+}
+
+
+void intel_backlight_register(struct drm_device *dev)
+{
+  struct intel_connector *connector;
+  list_for_each_entry(connector, &dev->mode_config.connector_list, base.head)
+    intel_backlight_device_register(connector);
+
+  struct device* child = dev->dev;
+  child->dv_payload = (void*)dev;
+  pmf_event_register(dev->dev, PMFE_DISPLAY_BRIGHTNESS_UP,
+  		     intel_panel_backlight_display_brightness_up, true);
+  pmf_event_register(dev->dev, PMFE_DISPLAY_BRIGHTNESS_DOWN,
+  		     intel_panel_backlight_display_brightness_down, true);
+  
 }
 
 void intel_backlight_unregister(struct drm_device *dev)
Index: sys/device.h
===================================================================
RCS file: /cvsroot/src/sys/sys/device.h,v
retrieving revision 1.157
diff -u -r1.157 device.h
--- sys/device.h	1 Dec 2018 01:51:38 -0000	1.157
+++ sys/device.h	14 Jan 2019 21:24:48 -0000
@@ -162,6 +162,7 @@
 	int		dv_depth;	/* number of parents until root */
 	int		dv_flags;	/* misc. flags; see below */
 	void		*dv_private;	/* this device's private storage */
+        void            *dv_payload;    /* an arbitrary payload */
 	int		*dv_locators;	/* our actual locators (optional) */
 	prop_dictionary_t dv_properties;/* properties dictionary */
 


Home | Main Index | Thread Index | Old Index