From nobody@FreeBSD.org  Sat Aug 17 18:19:32 2013
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1])
	(using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by hub.freebsd.org (Postfix) with ESMTP id CFAAF40A
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 17 Aug 2013 18:19:32 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from oldred.freebsd.org (oldred.freebsd.org [8.8.178.121])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by mx1.freebsd.org (Postfix) with ESMTPS id AC29924C2
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 17 Aug 2013 18:19:32 +0000 (UTC)
Received: from oldred.freebsd.org ([127.0.1.6])
	by oldred.freebsd.org (8.14.5/8.14.7) with ESMTP id r7HIJWbe094162
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 17 Aug 2013 18:19:32 GMT
	(envelope-from nobody@oldred.freebsd.org)
Received: (from nobody@localhost)
	by oldred.freebsd.org (8.14.5/8.14.5/Submit) id r7HIJWvW094158;
	Sat, 17 Aug 2013 18:19:32 GMT
	(envelope-from nobody)
Message-Id: <201308171819.r7HIJWvW094158@oldred.freebsd.org>
Date: Sat, 17 Aug 2013 18:19:32 GMT
From: Matthias Petermann <matthias@petermann-it.de>
To: freebsd-gnats-submit@FreeBSD.org
Subject: LCD Brightness Control not working on Lenovo X121e (ACPI issue?)
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         181357
>Category:       amd64
>Synopsis:       LCD Brightness Control not working on Lenovo X121e (ACPI issue?)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-amd64
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Aug 17 18:20:00 UTC 2013
>Closed-Date:    
>Last-Modified:  Wed May  7 00:00:00 UTC 2014
>Originator:     Matthias Petermann
>Release:        10.0-CURRENT
>Organization:
>Environment:
FreeBSD thinkpad.local 10.0-CURRENT FreeBSD 10.0-CURRENT #0 r252853: 
Sat Jul  6 02:01:48 CEST 2013
>Description:
The X121e is expected to increase/decrease LCD brightness by Fn+F9/Fn+F8. This is not working in FreeBSD 9.1 and FreeBSD 10.0. Direct ACPI calls (via sysutils/acpi_call port) provide a workaround. A comprehensive solution would be appreciated. I think a solution for this problem will help not just X121e users but any user of more recent thinkpads. I saw similiar postings in freebsd-current for X230 and X220 as well.

I have FreeBSD 10.0-CURRENT installed permanently to my X121e and am willing to test / investigate at any time. Please advise if there is anything I could provide right now.

The affected model is a Lenovo X121e (Model 3045-79G, i3, HD3000). Details:

http://www.petermann-it.de/files/freebsd-pr-x121e-acpi/dmesg.txt
http://www.petermann-it.de/files/freebsd-pr-x121e-acpi/devinfo.txt
http://www.petermann-it.de/files/freebsd-pr-x121e-acpi/mpeterma-lenovo_x121e_i3.asl
http://www.petermann-it.de/files/freebsd-pr-x121e-acpi/sysctl_hw_acpi.txt
>How-To-Repeat:
I tried:

# acpi_video / sysctl hw.acpi.video.lcd0.brightness

This is what is working on most of the other laptops I tried it.

   root@thinkpad:/usr/home/mpeterma # kldload acpi_video
   acpi_video0: <ACPI video extension> on vgapci0
   root@thinkpad:/usr/home/mpeterma # sysctl -a |grep bright
   hw.acpi.video.lcd0.brightness: 35
   root@thinkpad:/usr/home/mpeterma # sysctl 
hw.acpi.video.lcd0.brightness=100
   hw.acpi.video.lcd0.brightness: 35 -> 100

Result: LCD brightness doesn't change after sysctl call, Fn+F9/Fn+F8 not 
working.

# acpi_ibm / sysctl dev.acpi_ibm.0.lcd_brightness

This is what worked on some older Thinkpads.

   root@thinkpad:/usr/home/mpeterma # kldload acpi_ibm
   acpi_ibm0: <IBM ThinkPad ACPI Extras> on acpi0
   root@thinkpad:/usr/home/mpeterma # sysctl -a | grep bright
   hw.acpi.video.lcd0.brightness: 90
   dev.acpi_ibm.0.lcd_brightness: 7
   root@thinkpad:/usr/home/mpeterma #
   root@thinkpad:/usr/home/mpeterma # sysctl dev.acpi_ibm.0.lcd_brightness=1
   dev.acpi_ibm.0.lcd_brightness: 7 -> 1

Result: LCD brightness doesn't change after sysctl, Fn+F9/Fn+F8 still 
not working.

# Activate sysctl dev.acpi_ibm.0.events

   root@thinkpad:/usr/home/mpeterma # sysctl -a | grep 
dev.acpi_ibm.0.availmask
   dev.acpi_ibm.0.availmask: 67733756
   root@thinkpad:/usr/home/mpeterma # sysctl dev.acpi_ibm.0.events=1
   dev.acpi_ibm.0.events: 0 -> 1
   root@thinkpad:/usr/home/mpeterma # sysctl 
dev.acpi_ibm.0.handlerevents='0x03 0x04 0x10 0x11'

Result: Fn+F9/Fn+F8 still not working.

# Direct ACPI calls with acpi_call

    root@thinkpad:/usr/home/mpeterma # cd /usr/ports/sysutils/acpi_call/
    root@thinkpad:/usr/ports/sysutils/acpi_call # make install clean
    root@thinkpad:/usr/ports/sysutils/acpi_call # kldload acpi_call

    root@thinkpad:/usr/ports/sysutils/acpi_call # acpi_call -p '\VBRU'
    root@thinkpad:/usr/ports/sysutils/acpi_call # acpi_call -p '\VBRD'

Result: on each acpi_call, \VBRU increases and \VBRD decreases LCD 
brightness by one step.
Fn+F9/Fn+F8 still not working.
>Fix:


>Release-Note:
>Audit-Trail:

From: Matthias Petermann <matthias@petermann-it.de>
To: bug-followup@freebsd.org
Cc: matthias@petermann-it.de
Subject: amd64/181357: LCD Brightness Control not working on Lenovo X121e
 (ACPI issue?)
Date: Sun, 18 Aug 2013 22:16:41 +0200

 This message is in MIME format.
 
 --=_u7jrKzkqA8e5X0RGN1287A1
 Content-Type: text/plain; charset=UTF-8; format=flowed; DelSp=Yes
 Content-Disposition: inline
 Content-Transfer-Encoding: 8bit
 
 Hello, to narrow down the issue I added some temporar logging to  
 acpi_ibm.c. The attached patch is not intended to be committed, just  
 for demonstration where I put the statements. With this applied and  
 the following sequence:
 
 # kldload acpi_ibm
 # sysctl dev.acpi_ibm.0.events=1
 # sysctl dev.acpi_ibm.0.handlerevents='0x03 0x04 0x10 0x11'
 # tail -f /var/log/messages
 
 I see the following output, when I press Fn+F9/F8 multiple times:
 
 [Fn+F9]
 Aug 18 22:02:55 thinkpad kernel: acpi_ibm0: #### Tune brightness ####
 Aug 18 22:02:55 thinkpad kernel: acpi_ibm0: #### in cmos handle ####
 Aug 18 22:02:55 thinkpad kernel: acpi_ibm0: #### before acpi_ec_write ####: 1
 [Fn+F9]
 Aug 18 22:02:57 thinkpad kernel: acpi_ibm0: #### Tune brightness ####
 Aug 18 22:02:57 thinkpad kernel: acpi_ibm0: #### in cmos handle ####
 Aug 18 22:02:57 thinkpad kernel: acpi_ibm0: #### before acpi_ec_write ####: 2
 [Fn+F9]
 Aug 18 22:02:58 thinkpad kernel: acpi_ibm0: #### Tune brightness ####
 Aug 18 22:02:58 thinkpad kernel: acpi_ibm0: #### in cmos handle ####
 Aug 18 22:02:58 thinkpad kernel: acpi_ibm0: #### before acpi_ec_write ####: 3
 [Fn+F9]
 Aug 18 22:02:59 thinkpad kernel: acpi_ibm0: #### Tune brightness ####
 Aug 18 22:02:59 thinkpad kernel: acpi_ibm0: #### in cmos handle ####
 Aug 18 22:02:59 thinkpad kernel: acpi_ibm0: #### before acpi_ec_write ####: 4
 [Fn+F9]
 Aug 18 22:02:59 thinkpad kernel: acpi_ibm0: #### Tune brightness ####
 Aug 18 22:02:59 thinkpad kernel: acpi_ibm0: #### in cmos handle ####
 Aug 18 22:02:59 thinkpad kernel: acpi_ibm0: #### before acpi_ec_write ####: 5
 [Fn+F9]
 Aug 18 22:03:00 thinkpad kernel: acpi_ibm0: #### Tune brightness ####
 Aug 18 22:03:00 thinkpad kernel: acpi_ibm0: #### in cmos handle ####
 Aug 18 22:03:00 thinkpad kernel: acpi_ibm0: #### before acpi_ec_write ####: 6
 [Fn+F9]
 Aug 18 22:03:00 thinkpad kernel: acpi_ibm0: #### Tune brightness ####
 Aug 18 22:03:00 thinkpad kernel: acpi_ibm0: #### in cmos handle ####
 Aug 18 22:03:00 thinkpad kernel: acpi_ibm0: #### before acpi_ec_write ####: 7
 [Fn+F8]
 Aug 18 22:03:01 thinkpad kernel: acpi_ibm0: #### Tune brightness ####
 Aug 18 22:03:01 thinkpad kernel: acpi_ibm0: #### in cmos handle ####
 Aug 18 22:03:01 thinkpad kernel: acpi_ibm0: #### before acpi_ec_write ####: 6
 [Fn+F8]
 Aug 18 22:03:02 thinkpad kernel: acpi_ibm0: #### Tune brightness ####
 Aug 18 22:03:02 thinkpad kernel: acpi_ibm0: #### in cmos handle ####
 Aug 18 22:03:02 thinkpad kernel: acpi_ibm0: #### before acpi_ec_write ####: 5
 ...
 
 Looks like acpi_ec_write gets proper values. From this point, the keys  
 for brightness control seem to work, but acpi_ec_write doesn't have  
 any effect. So next stop would be ACPI_EC_WRITE(...). Are there any  
 known assumptions for potential causes where I should focus on?
 
 Thanks in advance & regards,
 Matthias
 
 -- 
 Matthias Petermann <matthias@petermann-it.de>
 Ihr Partner für anspruchsvolle IT-Lösungen
 www.petermann-it.de - lösungsorientiert, innovativ und erfolgreich
 
 --=_u7jrKzkqA8e5X0RGN1287A1
 Content-Type: text/x-diff; name=2013-08-18-patch_acpi_ibm.c_debug.txt;
  charset=us-ascii
 Content-Disposition: attachment; size=2013;
  filename=2013-08-18-patch_acpi_ibm.c_debug.txt
 
 --- acpi_ibm.c.orig	2013-08-18 02:01:11.000000000 +0200
 +++ acpi_ibm.c	2013-08-18 21:57:14.000000000 +0200
 @@ -367,7 +367,7 @@
  	devclass_t		ec_devclass;
  
  	ACPI_FUNCTION_TRACE((char *)(uintptr_t) __func__);
 -
 +	
  	sc = device_get_softc(dev);
  	sc->dev = dev;
  	sc->handle = acpi_get_handle(dev);
 @@ -983,6 +983,7 @@
  static int
  acpi_ibm_brightness_set(struct acpi_ibm_softc *sc, int arg)
  {
 +	
  	int			val, step;
  	UINT64			val_ec;
  	ACPI_OBJECT		Arg;
 @@ -992,15 +993,20 @@
  	ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
  	ACPI_SERIAL_ASSERT(ibm);
  
 -	if (arg < 0 || arg > 7)
 +	if (arg < 0 || arg > 7) {
 +		device_printf(sc->dev, "#### arg out of range ####\n");
  		return (EINVAL);
 -
 +	}
 +	
  	/* Read the current brightness */
  	status = ACPI_EC_READ(sc->ec_dev, IBM_EC_BRIGHTNESS, &val_ec, 1);
 -	if (ACPI_FAILURE(status))
 +	if (ACPI_FAILURE(status)) {
 +		device_printf(sc->dev, "#### failure read current brightness 2 ####\n");
  		return (status);
 -
 +	}
 +	
  	if (sc->cmos_handle) {
 +		device_printf(sc->dev, "#### in cmos handle ####\n");
  		val = val_ec & IBM_EC_MASK_BRI;
  
  		Args.Count = 1;
 @@ -1024,7 +1030,10 @@
  		}
  	}
  
 -	return ACPI_EC_WRITE(sc->ec_dev, IBM_EC_BRIGHTNESS, arg, 1);
 +	/* This is the original code from FreeBSD 10 current. I just added
 +	 * a log statement to see if it tries to set the proper values */ 
 +	device_printf(sc->dev, "#### before acpi_ec_write ####: %d\n",arg);
 +	return ACPI_EC_WRITE(sc->ec_dev, IBM_EC_BRIGHTNESS, arg, 1);  
  }
  
  static int
 @@ -1175,11 +1184,14 @@
  
  	case IBM_EVENT_BRIGHTNESS_UP:
  	case IBM_EVENT_BRIGHTNESS_DOWN:
 +		device_printf(sc->dev, "#### Tune brightness ####\n");
  		/* Read the current brightness */
  		status = ACPI_EC_READ(sc->ec_dev, IBM_EC_BRIGHTNESS,
  				      &val_ec, 1);
 -		if (ACPI_FAILURE(status))
 +		if (ACPI_FAILURE(status)) {
 +			device_printf(sc->dev, "#### Failure read current brightness 1 ####\n");
  			return;
 +		}
  
  		val = val_ec & IBM_EC_MASK_BRI;
  		val = (arg == IBM_EVENT_BRIGHTNESS_UP) ? val + 1 : val - 1;
 
 --=_u7jrKzkqA8e5X0RGN1287A1--
 

From: Matthias Petermann <matthias@petermann-it.de>
To: bug-followup@FreeBSD.org, matthias@petermann-it.de, 
 current@freebsd.org
Cc:  
Subject: Re: amd64/181357: LCD Brightness Control not working on Lenovo X121e
 (ACPI issue?)
Date: Sat, 24 Aug 2013 17:08:25 +0200

 Hello,
 
 regarding this PR I made some further observation. Even the 
 acpi_ec_write seems to not have any effect on the brightness, the values 
 set to the appropriate register (IBM_EC_BRIGHTNESS   0x31) survive a 
 reboot.
 
 Looks like the values are stored correctly, but EC doesn't care for them 
 when setting brightness?
 
 I'm not sure where to look next. Could this be a hardware issue with the 
 Device?
 
 Kind regards,
 Matthias

From: Dominic Fandrey <kamikaze@bsdforen.de>
To: Matthias Petermann <matthias@petermann-it.de>
Cc: bug-followup@FreeBSD.org, current@freebsd.org
Subject: Re: amd64/181357: LCD Brightness Control not working on Lenovo X121e
 (ACPI issue?)
Date: Sat, 24 Aug 2013 20:02:28 +0200

 On 24/08/2013 17:08, Matthias Petermann wrote:
 > regarding this PR I made some further observation. Even the acpi_ec_write seems to not have any effect on the brightness, the values set to the appropriate register (IBM_EC_BRIGHTNESS   0x31) survive a reboot.
 
 My LCD brightness control stopped working when I switched to NEW_XORG
 with Intel KMS (on stable/9).
 
 -- 
 A: Because it fouls the order in which people normally read text.
 Q: Why is top-posting such a bad thing?
 A: Top-posting.
 Q: What is the most annoying thing on usenet and in e-mail? 

From: Matthias Petermann <matthias@petermann-it.de>
To: Dominic Fandrey <kamikaze@bsdforen.de>
Cc: bug-followup@FreeBSD.org, current@freebsd.org
Subject: Re: amd64/181357: LCD Brightness Control not working on Lenovo X121e
 (ACPI issue?)
Date: Sat, 24 Aug 2013 20:37:44 +0200

 Am 24.08.2013 20:02, schrieb Dominic Fandrey:
 > My LCD brightness control stopped working when I switched to NEW_XORG 
 > with Intel KMS (on stable/9). 
 
 It's the same issue when I run in console only mode (without Xorg, 
 without KMS kernel module loaded).
 What Lenovo model are you using?

From: Miguel Clara <miguelmclara@gmail.com>
To: bug-followup@freebsd.org, matthias@petermann-it.de
Cc:  
Subject: Re: amd64/181357: LCD Brightness Control not working on Lenovo X121e
 (ACPI issue?)
Date: Wed, 7 May 2014 00:57:33 +0100

 --047d7bae487e1f0c3d04f8c4041c
 Content-Type: text/plain; charset=UTF-8
 
 I get the same issue with an acer laptop!
 
 xbacklight gives me:
 
 No outputs have backlight property
 
 I had no luck with acpi_call though (and I've tried loading several acpi_
 modules with no luck)
 
 only workaround I have is:
 
 xrandr --output LVDS1 --brightness 0.9
 
 --047d7bae487e1f0c3d04f8c4041c
 Content-Type: text/html; charset=UTF-8
 Content-Transfer-Encoding: quoted-printable
 
 <div dir=3D"ltr">I get the same issue with an acer laptop!<br><br><div>xbac=
 klight gives me:<br><br></div><div>No outputs have backlight property</div>=
 <div><br></div><div>I had no luck with acpi_call though (and I&#39;ve tried=
  loading several acpi_ modules with no luck)</div>
 
 <div><br></div><div>only workaround I have is:</div><div><br></div><div>xra=
 ndr --output LVDS1 --brightness 0.9<br></div><div><br></div>
 </div>
 
 --047d7bae487e1f0c3d04f8c4041c--
>Unformatted:
