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 0xfee00000: 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 0xfec00000, version 20, 40 pins
acpimcfg0 at acpi0 addr 0xf8000000, 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 0xe0000000, size 0x10000000
inteldrm0 at vga1
drm0 at inteldrm0
error: [drm:pid0:i915_write32] *ERROR* Unknown unclaimed register before 
writing to 100000
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: 2560x1440
wsdisplay0 at vga1 mux 1: console (std, vt100 emulation)
wsdisplay0: screen 1-5 added (std, vt100 emulation)
azalia0 at pci0 dev 3 function 0 "Intel Core 4G HD Audio" rev 0x09: msi
azalia0: No codecs found
"Intel 8 Series MEI" rev 0x04 at pci0 dev 22 function 0 not configured
em0 at pci0 dev 25 function 0 "Intel I218-V" rev 0x04: msi, address 
3c:97:0e:ee:65:b7
azalia1 at pci0 dev 27 function 0 "Intel 8 Series HD Audio" rev 0x04: msi
azalia1: codecs: Realtek ALC292
audio0 at azalia1
ppb0 at pci0 dev 28 function 0 "Intel 8 Series PCIE" rev 0xe4: msi
pci1 at ppb0 bus 2
ppb1 at pci0 dev 28 function 1 "Intel 8 Series PCIE" rev 0xe4: msi
pci2 at ppb1 bus 3
"Intel Dual Band Wireless AC 7260" rev 0x83 at pci2 dev 0 function 0 not 
configured
ehci0 at pci0 dev 29 function 0 "Intel 8 Series USB" rev 0x04: apic 2 int 23
usb0 at ehci0: USB revision 2.0
uhub0 at usb0 "Intel EHCI root hub" rev 2.00/1.00 addr 1
pcib0 at pci0 dev 31 function 0 "Intel 8 Series LPC" rev 0x04
ahci0 at pci0 dev 31 function 2 "Intel 8 Series AHCI" rev 0x04: msi, AHCI 1.3
scsibus0 at ahci0: 32 targets
sd0 at scsibus0 targ 0 lun 0: <ATA, SAMSUNG MZNTD256, DXT2> SCSI3 0/direct 
fixed naa.5002538500000000
sd0: 244198MB, 512 bytes/sector, 500118192 sectors, thin
ichiic0 at pci0 dev 31 function 3 "Intel 8 Series SMBus" rev 0x04: apic 2 int 18
iic0 at ichiic0
isa0 at pcib0
isadma0 at isa0
pckbc0 at isa0 port 0x60/5
pckbd0 at pckbc0 (kbd slot)
pckbc0: using irq 1 for kbd slot
wskbd0 at pckbd0: console keyboard, using wsdisplay0
pms0 at pckbc0 (aux slot)
pckbc0: using irq 12 for aux slot
wsmouse0 at pms0 mux 0
wsmouse1 at pms0 mux 0
pms0: Synaptics clickpad, firmware 8.1
pcppi0 at isa0 port 0x61
spkr0 at pcppi0
uhub1 at uhub0 port 1 "Intel Rate Matching Hub" rev 2.00/0.04 addr 2
urtwn0 at uhub1 port 2 "Realtek 802.11n WLAN Adapter" rev 2.00/2.00 addr 3
urtwn0: MAC/BB RTL8188CUS, RF 6052 1T1R, address 00:e0:4c:06:da:8e
umodem0 at uhub1 port 4 configuration 1 interface 2 "Sierra Wireless Inc. 
Sierra Wireless EM7345 4G LTE" rev 2.00/17.29 addr 4
umodem0: data interface 3, has no CM over data, has break
umodem0: status change notification available
ucom0 at umodem0
ugen0 at uhub1 port 4 configuration 1 "Sierra Wireless Inc. Sierra Wireless 
EM7345 4G LTE" rev 2.00/17.29 addr 4
ugen1 at uhub1 port 7 "Intel product 0x07dc" rev 2.00/0.01 addr 5
uvideo0 at uhub1 port 8 configuration 1 interface 0 "SC20A38485AA41936K 
Integrated Camera" rev 2.00/0.21 addr 6
video0 at uvideo0
vscsi0 at root
scsibus1 at vscsi0: 256 targets
softraid0 at root
scsibus2 at softraid0: 256 targets
root on sd0a (4e91201669a3abb4.a) swap on sd0b dump on sd0b

-- 
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 -0000       1.34
+++ sys/dev/acpi/acpithinkpad.c 17 Mar 2014 18:41:56 -0000
@@ -30,7 +30,8 @@
 #include "audio.h"
 #include "wskbd.h"
 
-#define        THINKPAD_HKEY_VERSION           0x0100
+#define        THINKPAD_HKEY_VERSION1          0x0100
+#define        THINKPAD_HKEY_VERSION2          0x0200
 
 #define        THINKPAD_CMOS_VOLUME_DOWN       0x00
 #define        THINKPAD_CMOS_VOLUME_UP         0x01
@@ -65,6 +66,15 @@
 #define        THINKPAD_BUTTON_MICROPHONE_MUTE 0x101b
 #define        THINKPAD_BUTTON_FN_F11          0x100b
 #define        THINKPAD_BUTTON_HIBERNATE       0x100c
+#define        THINKPAD_ADAPTIVE_NEXT          0x1101
+#define        THINKPAD_ADAPTIVE_QUICK         0x1102
+#define        THINKPAD_ADAPTIVE_SNIP          0x1105
+#define        THINKPAD_ADAPTIVE_VOICE         0x1108
+#define        THINKPAD_ADAPTIVE_GESTURES      0x110a
+#define        THINKPAD_ADAPTIVE_SETTINGS      0x110e
+#define        THINKPAD_ADAPTIVE_TAB           0x110f
+#define        THINKPAD_ADAPTIVE_REFRESH       0x1110
+#define        THINKPAD_ADAPTIVE_BACK          0x1111
 #define THINKPAD_PORT_REPL_DOCKED      0x4010
 #define THINKPAD_PORT_REPL_UNDOCKED    0x4011
 #define        THINKPAD_LID_OPEN               0x5001
@@ -85,6 +95,9 @@
 #define THINKPAD_ECOFFSET_FANLO                0x84
 #define THINKPAD_ECOFFSET_FANHI                0x85
 
+#define        THINKPAD_ADAPTIVE_MODE_HOME     1
+#define        THINKPAD_ADAPTIVE_MODE_FUNCTION 3
+
 struct acpithinkpad_softc {
        struct device            sc_dev;
 
@@ -110,6 +123,8 @@ int thinkpad_volume_up(struct acpithinkp
 int    thinkpad_volume_mute(struct acpithinkpad_softc *);
 int    thinkpad_brightness_up(struct acpithinkpad_softc *);
 int    thinkpad_brightness_down(struct acpithinkpad_softc *);
+int    thinkpad_adaptive_change(struct acpithinkpad_softc *);
+int    thinkpad_activate(struct device *, int);
 
 void    thinkpad_sensor_attach(struct acpithinkpad_softc *sc);
 void    thinkpad_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,11 @@ 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_BACKLIGHT_CHANGED:
                case THINKPAD_BRIGHTNESS_CHANGED:
                case THINKPAD_BUTTON_BATTERY_INFO:
@@ -352,6 +373,13 @@ thinkpad_hotkey(struct aml_node *node, i
                case THINKPAD_TABLET_SCREEN_NORMAL:
                case THINKPAD_TABLET_SCREEN_ROTATED:
                case THINKPAD_THERMAL_TABLE_CHANGED:
+               case THINKPAD_ADAPTIVE_SNIP:
+               case THINKPAD_ADAPTIVE_VOICE:
+               case THINKPAD_ADAPTIVE_GESTURES:
+               case THINKPAD_ADAPTIVE_SETTINGS:
+               case THINKPAD_ADAPTIVE_TAB:
+               case THINKPAD_ADAPTIVE_REFRESH:
+               case THINKPAD_ADAPTIVE_BACK:
                        handled = 1;
                        break;
                default:
@@ -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 (1);
+       }
+
+       bzero(&arg, sizeof(arg));
+       arg.type = AML_OBJTYPE_INTEGER;
+
+       if (mode == THINKPAD_ADAPTIVE_MODE_FUNCTION)
+               arg.v_integer = THINKPAD_ADAPTIVE_MODE_HOME;
+       else
+               arg.v_integer = THINKPAD_ADAPTIVE_MODE_FUNCTION;
+
+       if (aml_evalname(sc->sc_acpi, sc->sc_devnode, "STRW",
+           1, &arg, NULL)) {
+               printf("%s: couldn't set adaptive keyboard mode\n", 
DEVNAME(sc));
+               return (1);
+       }
+
+       return (0);
+}
+
+int
+thinkpad_activate(struct device *self, int act)
+{
+
+       struct acpithinkpad_softc *sc = (struct acpithinkpad_softc *)self;
+       int64_t res;
+
+       switch(act) {
+       case DVACT_WAKEUP:
+               if (aml_evalinteger(sc->sc_acpi, sc->sc_devnode, "GTRW",
+                   0, NULL, &res) == 0)
+                       thinkpad_adaptive_change(sc);
+               break;
+       }
+       return (0);
 }

Reply via email to