From brix@lothlorien.brixandersen.dk  Mon Apr 23 17:49:55 2007
Return-Path: <brix@lothlorien.brixandersen.dk>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id E579116A412;
	Mon, 23 Apr 2007 17:49:55 +0000 (UTC)
	(envelope-from brix@lothlorien.brixandersen.dk)
Received: from solow.pil.dk (relay.pil.dk [195.41.47.164])
	by mx1.freebsd.org (Postfix) with ESMTP id AF01713C45B;
	Mon, 23 Apr 2007 17:49:55 +0000 (UTC)
	(envelope-from brix@lothlorien.brixandersen.dk)
Received: from lothlorien.brixandersen.dk (osgiliath.brixandersen.dk [87.53.223.189])
	by solow.pil.dk (Postfix) with ESMTP id 1D3FD1CC0BE;
	Mon, 23 Apr 2007 19:49:54 +0200 (CEST)
Received: by lothlorien.brixandersen.dk (Postfix, from userid 1001)
	id 91DA911432; Mon, 23 Apr 2007 19:49:53 +0200 (CEST)
Message-Id: <20070423174953.91DA911432@lothlorien.brixandersen.dk>
Date: Mon, 23 Apr 2007 19:49:53 +0200 (CEST)
From: Henrik Brix Andersen <henrik@brixandersen.dk>
Reply-To: Henrik Brix Andersen <henrik@brixandersen.dk>
To: FreeBSD-gnats-submit@freebsd.org
Cc: Markus Brueffer <markus@FreeBSD.org>
Subject: [acpi_ibm] [patch] Preserve the ThinkLight state on driver attach
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         112044
>Category:       kern
>Synopsis:       [acpi_ibm] [patch] Preserve the ThinkLight state on driver attach
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    markus
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon Apr 23 17:50:03 GMT 2007
>Closed-Date:    Tue Apr 24 23:10:41 GMT 2007
>Last-Modified:  Tue Apr 24 23:10:41 GMT 2007
>Originator:     Henrik Brix Andersen
>Release:        FreeBSD 7.0-CURRENT i386
>Organization:
pil.dk
>Environment:
System: FreeBSD lothlorien.brixandersen.dk 7.0-CURRENT FreeBSD 7.0-CURRENT #17: Mon Apr 23 19:19:08 CEST 2007 root@lothlorien.brixandersen.dk:/usr/obj/usr/src/sys/LOTHLORIEN i386


	
>Description:
The current implementation of acpi_ibm(4) unconditionally turns off
the ThinkLight on driver attach through the call to led_create() in
led(4).

	
>How-To-Repeat:
You need an IBM/Lenovo ThinkPad with a ThinkLight.

Unload the acpi_ibm(4) kernel module if already loaded and turn on the
ThinkLight using the Fn-key combination.

Load acpi_ibm(4) and notice the ThinkLight turns off.
	
>Fix:
The patch below uses the newly added led_create_state() function in
led(4) with the current state of the ThinkLight as argument (if
reading the ThinkLight status is supported on that given model).

User who wish to have the old behavior where the ThinkLight is
automatically turned off at boot can set dev.acpi_ibm.0.thinklight=0
in /etc/sysctl.conf.

This was tested on my ThinkPad X60s.

	

--- acpi_ibm_thinklight.diff begins here ---
--- sys/dev/acpi_support/acpi_ibm.c.orig	Mon Apr 23 19:07:47 2007
+++ sys/dev/acpi_support/acpi_ibm.c	Mon Apr 23 19:09:24 2007
@@ -412,7 +412,7 @@ acpi_ibm_attach(device_t dev)
 
 	/* Hook up light to led(4) */
 	if (sc->light_set_supported)
-		sc->led_dev = led_create(ibm_led, sc, "thinklight");
+		sc->led_dev = led_create_state(ibm_led, sc, "thinklight", sc->light_val);
 
 	return (0);
 }
@@ -810,7 +810,7 @@ acpi_ibm_sysctl_init(struct acpi_ibm_sof
 
 	case ACPI_IBM_METHOD_THINKLIGHT:
 		sc->cmos_handle = NULL;
-		sc->light_get_supported = ACPI_SUCCESS(acpi_GetInteger(sc->ec_handle, IBM_NAME_KEYLIGHT, &dummy));
+		sc->light_get_supported = ACPI_SUCCESS(acpi_GetInteger(sc->ec_handle, IBM_NAME_KEYLIGHT, &sc->light_val));
 
 		if ((ACPI_SUCCESS(AcpiGetHandle(sc->handle, "\\UCMS", &sc->light_handle)) ||
 		     ACPI_SUCCESS(AcpiGetHandle(sc->handle, "\\CMOS", &sc->light_handle)) ||
@@ -831,7 +831,10 @@ acpi_ibm_sysctl_init(struct acpi_ibm_sof
 		sc->light_set_supported = (sc->light_handle &&
 		    ACPI_FAILURE(AcpiGetHandle(sc->ec_handle, "LEDB", &ledb_handle)));
 
-		if (sc->light_get_supported || sc->light_set_supported) {
+		if (sc->light_get_supported) {
+			return (TRUE);
+		}
+		else if (sc->light_set_supported) {
 			sc->light_val = 0;
 			return (TRUE);
 		}
--- acpi_ibm_thinklight.diff ends here ---


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->markus 
Responsible-Changed-By: markus 
Responsible-Changed-When: Mon Apr 23 21:24:07 UTC 2007 
Responsible-Changed-Why:  
I'll handle this one. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=112044 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/112044: commit references a PR
Date: Tue, 24 Apr 2007 23:09:45 +0000 (UTC)

 markus      2007-04-24 23:09:37 UTC
 
   FreeBSD src repository
 
   Modified files:
     sys/dev/acpi_support acpi_ibm.c 
   Log:
   Utilize led_create_state in order to preserve the status of the ThinkLight
   on driver attach.
   
   PR:             kern/112044
   Submitted by:   Henrik Brix Andersen <henrik@brixandersen.dk>
   Approved by:    emax (mentor) (earlier version)
   
   Revision  Changes    Path
   1.14      +9 -5      src/sys/dev/acpi_support/acpi_ibm.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->closed 
State-Changed-By: markus 
State-Changed-When: Tue Apr 24 23:10:09 UTC 2007 
State-Changed-Why:  
Committed, thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=112044 
>Unformatted:
