Yellow Rabbit

Frozen

Here is an active version

The Mechanism for Adjusting the Brightness of the Screen

Laptop Screen Brightness - Acer C720 Laptop, BSD

The backlight adjustment keys on the Acer C720 keyboard are disguised F6 and F7 keys. Accordingly, when you change ChromeOS to DragoFly BSD, the backlight adjustment does not work. Also one can’t use xbacklight - it does not find video outputs with the ability to adjust the backlight. Xrandr can help, but it’s a software solution, something like dim the output pixels. It’s clear that it not will prolong the life of the battery in any way.

The first way

Let’s change the i915 driver so that it creates two sysctl’s:

Pros:

Cons:

The i915 driver provides a backlight control mechanism, it is enough to know the pointer to the current drm device: struct drm_device *dev.

For two sysctl we write two functions for reading/writing:


/*
 * Read max backlight level
 */
static int
sysctl_backlight_max(SYSCTL_HANDLER_ARGS)
{
	int err, val;

	val =intel_panel_get_max_backlight((struct drm_device *)arg1);
	err = sysctl_handle_int(oidp, &val, 0, req);
	return(err);
}

/*
 * Read/write backlight level 
 */
static int
sysctl_backlight_handler(SYSCTL_HANDLER_ARGS)
{
	struct drm_i915_private *dev_priv;
	int err, val;

	dev_priv = ((struct drm_device *)arg1)->dev_private;
	val = dev_priv->backlight_level;

	err = sysctl_handle_int(oidp, &val, 0, req);
	if (err != 0 || req->newptr == NULL) {
		return(err);
	}

	if (val != dev_priv->backlight_level && val >= 0
		&& val <= intel_panel_get_max_backlight((struct drm_device *)arg1)) {
		intel_panel_set_backlight(arg1, val);
	}

	return(err);
}

dev can be discovered only at run time, so we use dynamic control of sysctl with theSYSCTL_ADD_PROC macro.


SYSCTL_ADD_PROC(&connector->dev->sysctl->ctx, &sysctl__hw_children,
			OID_AUTO, "backlight_max", 
			CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_ANYBODY,
			connector->dev, sizeof(int),
			sysctl_backlight_max,
			"I", "Max backlight level");
SYSCTL_ADD_PROC(&connector->dev->sysctl->ctx, &sysctl__hw_children,
			OID_AUTO, "backlight_level", 
			CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_ANYBODY,
			connector->dev, sizeof(int),
			sysctl_backlight_handler,
			"I", "Backlight level");

As a result, it becomes possible to use commands like sysctl hw.backlight_level=370 to set the acceptable backlight level. Actually, now this command is written in my .xinitrc, I’m not puzzled with the binding of some script to the F6 and F7 keys. It’s not difficult, just ahead is another way that is just to come up :smile:

Full patch text applied to DragonFly BSD from 12/19/2014.