Re: thinkpad adaptive keyboard patch

2014-03-24 Thread rivo nurges
On Mon, Mar 17, 2014 at 07:11:09PM +, rivo nurges wrote:

Hi!

 New 2nd generation Lenovo X1 Carbon has touchable lcd strip instead
 of the F1-12 keys and the multimedia keys. It has 5 modes with tons
 of useless buttons triggering acpi hotkey events and 6th inactive
 mode.
 
 This patch adds support for switching between the Home and the
 Function modes. The Function mode has the standard F1-12 buttons
 and the Home mode has Volume, Mute and Brightness buttons. Other
 functions of the the Home mode are ignored. On power up BIOS activates
 the Function mode for us, on suspend it goes to the inactive mode
 and we need to reenable it when coming from suspend.
 
 The patch has been tested on X1 Carbon, X220 and X61s

New version. Style fixes suggested by jcs@, no functional changes.

-- 
rix


Index: sys/dev/acpi/acpithinkpad.c
===
RCS file: /OpenBSD/src/sys/dev/acpi/acpithinkpad.c,v
retrieving revision 1.34
diff -u -p -r1.34 acpithinkpad.c
--- sys/dev/acpi/acpithinkpad.c 4 Nov 2013 11:57:26 -   1.34
+++ sys/dev/acpi/acpithinkpad.c 24 Mar 2014 20:14:50 -
@@ -30,7 +30,8 @@
 #include audio.h
 #include wskbd.h
 
-#defineTHINKPAD_HKEY_VERSION   0x0100
+#defineTHINKPAD_HKEY_VERSION1  0x0100
+#defineTHINKPAD_HKEY_VERSION2  0x0200
 
 #defineTHINKPAD_CMOS_VOLUME_DOWN   0x00
 #defineTHINKPAD_CMOS_VOLUME_UP 0x01
@@ -65,6 +66,15 @@
 #defineTHINKPAD_BUTTON_MICROPHONE_MUTE 0x101b
 #defineTHINKPAD_BUTTON_FN_F11  0x100b
 #defineTHINKPAD_BUTTON_HIBERNATE   0x100c
+#defineTHINKPAD_ADAPTIVE_NEXT  0x1101
+#defineTHINKPAD_ADAPTIVE_QUICK 0x1102
+#defineTHINKPAD_ADAPTIVE_SNIP  0x1105
+#defineTHINKPAD_ADAPTIVE_VOICE 0x1108
+#defineTHINKPAD_ADAPTIVE_GESTURES  0x110a
+#defineTHINKPAD_ADAPTIVE_SETTINGS  0x110e
+#defineTHINKPAD_ADAPTIVE_TAB   0x110f
+#defineTHINKPAD_ADAPTIVE_REFRESH   0x1110
+#defineTHINKPAD_ADAPTIVE_BACK  0x
 #define THINKPAD_PORT_REPL_DOCKED  0x4010
 #define THINKPAD_PORT_REPL_UNDOCKED0x4011
 #defineTHINKPAD_LID_OPEN   0x5001
@@ -85,6 +95,9 @@
 #define THINKPAD_ECOFFSET_FANLO0x84
 #define THINKPAD_ECOFFSET_FANHI0x85
 
+#defineTHINKPAD_ADAPTIVE_MODE_HOME 1
+#defineTHINKPAD_ADAPTIVE_MODE_FUNCTION 3
+
 struct acpithinkpad_softc {
struct devicesc_dev;
 
@@ -110,6 +123,8 @@ int thinkpad_volume_up(struct acpithinkp
 intthinkpad_volume_mute(struct acpithinkpad_softc *);
 intthinkpad_brightness_up(struct acpithinkpad_softc *);
 intthinkpad_brightness_down(struct acpithinkpad_softc *);
+intthinkpad_adaptive_change(struct acpithinkpad_softc *);
+intthinkpad_activate(struct device *, int);
 
 voidthinkpad_sensor_attach(struct acpithinkpad_softc *sc);
 voidthinkpad_sensor_refresh(void *);
@@ -119,7 +134,8 @@ extern int wskbd_set_mixervolume(long, l
 #endif
 
 struct cfattach acpithinkpad_ca = {
-   sizeof(struct acpithinkpad_softc), thinkpad_match, thinkpad_attach
+   sizeof(struct acpithinkpad_softc), thinkpad_match, thinkpad_attach,
+   NULL, thinkpad_activate
 };
 
 struct cfdriver acpithinkpad_cd = {
@@ -144,7 +160,7 @@ thinkpad_match(struct device *parent, vo
MHKV, 0, NULL, res))
return (0);
 
-   if (res != THINKPAD_HKEY_VERSION)
+   if (!(res == THINKPAD_HKEY_VERSION1 || res == THINKPAD_HKEY_VERSION2))
return (0);
 
return (1);
@@ -328,6 +344,18 @@ thinkpad_hotkey(struct aml_node *node, i
 #endif
handled = 1;
break;
+   case THINKPAD_ADAPTIVE_NEXT:
+   case THINKPAD_ADAPTIVE_QUICK:
+   thinkpad_adaptive_change(sc);
+   handled = 1;
+   break;
+   case THINKPAD_ADAPTIVE_BACK:
+   case THINKPAD_ADAPTIVE_GESTURES:
+   case THINKPAD_ADAPTIVE_REFRESH:
+   case THINKPAD_ADAPTIVE_SETTINGS:
+   case THINKPAD_ADAPTIVE_SNIP:
+   case THINKPAD_ADAPTIVE_TAB:
+   case THINKPAD_ADAPTIVE_VOICE:
case THINKPAD_BACKLIGHT_CHANGED:
case THINKPAD_BRIGHTNESS_CHANGED:
case THINKPAD_BUTTON_BATTERY_INFO:
@@ -453,4 +481,50 @@ int
 thinkpad_brightness_down(struct acpithinkpad_softc *sc)
 {
return (thinkpad_cmos(sc, THINKPAD_CMOS_BRIGHTNESS_DOWN));
+}
+
+int
+thinkpad_adaptive_change(struct acpithinkpad_softc *sc)
+{
+   struct aml_value arg;
+   int64_t mode;
+
+   if (aml_evalinteger(sc-sc_acpi, sc-sc_devnode, GTRW,
+   0, NULL, mode)) {
+   printf(%s: couldn't get adaptive keyboard mode\n, 
DEVNAME(sc));
+   return 

thinkpad adaptive keyboard patch

2014-03-17 Thread rivo nurges
Hi!

New 2nd generation Lenovo X1 Carbon has touchable lcd strip instead
of the F1-12 keys and the multimedia keys. It has 5 modes with tons
of useless buttons triggering acpi hotkey events and 6th inactive
mode.

This patch adds support for switching between the Home and the
Function modes. The Function mode has the standard F1-12 buttons
and the Home mode has Volume, Mute and Brightness buttons. Other
functions of the the Home mode are ignored. On power up BIOS activates
the Function mode for us, on suspend it goes to the inactive mode
and we need to reenable it when coming from suspend.

The patch has been tested on X1 Carbon, X220 and X61s

Dmesg:
OpenBSD 5.5-current (GENERIC.MP) #26: Mon Mar 17 18:14:05 UTC 2014
rix@x1:/usr/src/sys/arch/amd64/compile/GENERIC.MP
real mem = 8262828032 (7880MB)
avail mem = 8034148352 (7661MB)
mainbus0 at root
bios0 at mainbus0: SMBIOS rev. 2.7 @ 0xdcd3d000 (60 entries)
bios0: vendor LENOVO version GRET32WW (1.09 ) date 02/13/2014
bios0: LENOVO 20A7005KMS
acpi0 at bios0: rev 2
acpi0: sleep states S0 S3 S4 S5
acpi0: tables DSDT FACP SLIC ASF! DBGP ECDT HPET APIC MCFG SSDT SSDT SSDT SSDT 
SSDT SSDT TCPA UEFI MSDM BATB FPDT UEFI SSDT
acpi0: wakeup devices LID_(S4) SLPB(S3) IGBE(S4) EXP2(S4) XHCI(S3) EHC1(S3)
acpitimer0 at acpi0: 3579545 Hz, 24 bits
acpiec0 at acpi0
acpihpet0 at acpi0: 14318179 Hz
acpimadt0 at acpi0 addr 0xfee0: PC-AT compat
cpu0 at mainbus0: apid 0 (boot processor)
cpu0: Intel(R) Core(TM) i7-4550U CPU @ 1.50GHz, 1396.98 MHz
cpu0: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,EST,TM2,SSSE3,FMA3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,MOVBE,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,LONG,LAHF,ABM,PERF,ITSC,FSGSBASE,BMI1,AVX2,SMEP,BMI2,ERMS,INVPCID
cpu0: 256KB 64b/line 8-way L2 cache
cpu0: smt 0, core 0, package 0
mtrr: Pentium Pro MTRR support, 10 var ranges, 88 fixed ranges
cpu0: apic clock running at 99MHz
cpu0: mwait min=64, max=64, C-substates=0.2.1.2.4, IBE
cpu1 at mainbus0: apid 1 (application processor)
cpu1: Intel(R) Core(TM) i7-4550U CPU @ 1.50GHz, 1396.77 MHz
cpu1: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,EST,TM2,SSSE3,FMA3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,MOVBE,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,LONG,LAHF,ABM,PERF,ITSC,FSGSBASE,BMI1,AVX2,SMEP,BMI2,ERMS,INVPCID
cpu1: 256KB 64b/line 8-way L2 cache
cpu1: smt 1, core 0, package 0
cpu2 at mainbus0: apid 2 (application processor)
cpu2: Intel(R) Core(TM) i7-4550U CPU @ 1.50GHz, 1396.77 MHz
cpu2: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,EST,TM2,SSSE3,FMA3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,MOVBE,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,LONG,LAHF,ABM,PERF,ITSC,FSGSBASE,BMI1,AVX2,SMEP,BMI2,ERMS,INVPCID
cpu2: 256KB 64b/line 8-way L2 cache
cpu2: smt 0, core 1, package 0
cpu3 at mainbus0: apid 3 (application processor)
cpu3: Intel(R) Core(TM) i7-4550U CPU @ 1.50GHz, 1396.77 MHz
cpu3: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,EST,TM2,SSSE3,FMA3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,MOVBE,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,LONG,LAHF,ABM,PERF,ITSC,FSGSBASE,BMI1,AVX2,SMEP,BMI2,ERMS,INVPCID
cpu3: 256KB 64b/line 8-way L2 cache
cpu3: smt 1, core 1, package 0
ioapic0 at mainbus0: apid 2 pa 0xfec0, version 20, 40 pins
acpimcfg0 at acpi0 addr 0xf800, bus 0-63
acpiprt0 at acpi0: bus 0 (PCI0)
acpiprt1 at acpi0: bus -1 (PEG_)
acpiprt2 at acpi0: bus 2 (EXP1)
acpiprt3 at acpi0: bus 3 (EXP2)
acpiprt4 at acpi0: bus -1 (EXP3)
acpicpu0 at acpi0: C3, C1, PSS
acpicpu1 at acpi0: C3, C1, PSS
acpicpu2 at acpi0: C3, C1, PSS
acpicpu3 at acpi0: C3, C1, PSS
acpipwrres0 at acpi0: PUBS, resource for XHCI, EHC1
acpitz0 at acpi0: critical temperature is 200 degC
acpibtn0 at acpi0: LID_
acpibtn1 at acpi0: SLPB
acpibat0 at acpi0: BAT0 model 45N1701 serial 11637 type LiP oem SONY
acpibat1 at acpi0: BAT1 not present
acpiac0 at acpi0: AC unit online
acpithinkpad0 at acpi0
cpu0: Enhanced SpeedStep 1396 MHz: speeds: 2101, 2100, 2000, 1900, 1800, 1700, 
1600, 1500, 1400, 1300, 1200, 1100, 1000, 900, 800, 777 MHz
pci0 at mainbus0 bus 0
pchb0 at pci0 dev 0 function 0 Intel Core 4G Host rev 0x09
vga1 at pci0 dev 2 function 0 Intel HD Graphics 5000 rev 0x09
intagp0 at vga1
agp0 at intagp0: aperture at 0xe000, size 0x1000
inteldrm0 at vga1
drm0 at inteldrm0
error: [drm:pid0:i915_write32] *ERROR* Unknown unclaimed register before 
writing to 10
error: [drm:pid0:intel_dp_set_link_train] *ERROR* Timed out waiting for DP idle 
patterns
error: [drm:pid0:i915_write32] *ERROR* Unknown unclaimed register before 
writing to 64040
inteldrm0: