On Sun, Oct 13, 2019 at 09:28:26PM -0500, joshua stein wrote:
> When responding to hardware keys to increment or decrement screen 
> brightness, don't just adjust by 1 BCL level as there may be 100 
> levels.  Find the next brightness level that is at least 5% up or 
> down, and use that.
        revision 1.14
        date: 2019/10/21 16:32:51;  author: jcs;  state: Exp;  lines: +20 -33;
        When incrementing or decrementing screen brightness, don't just
        adjust by 1 BCL level as there may be 100 levels.  Find the next
        brightness level that is at least 5% up or down and use that.

        ok kettenis

This diff broke backlight adjustment on my X230:  With 100% screen
brightness, pressing the function keys to *de*crease it won't do
anything.  Booting a kernel with ACPIVIDEO_DEBUG suggests that
acpivout_find_brightness() is unable to find the next level below 100%
that is at least 5% less than the full brightness, hence it returns
something above 95% such that acpivout_brightness_step() gets stuck and
will set brightness to 100% again.

`xbacklight -50' will properly decrease brightness to 50%, then the
function keys also work and I can decrease to 44% as the immediate lower
level, however increasing it again never works and is stuck at 44%.

In general, setting a lower brightness level with xbacklight(1) makes
the function keys work but only ever in the range of [0, n) -- I can
never reach a higher level than set with xbacklight.

`xbacklight +100' works and reverting avpivout.c revision 1.14 makes
everything work again for me.

tobhe has the exact same issues on his T420.

Below is diff to show my X230 brightness levels, dmesg as well.


Index: dev/acpi/acpivout.c
===================================================================
RCS file: /cvs/src/sys/dev/acpi/acpivout.c,v
retrieving revision 1.16
diff -u -p -r1.16 acpivout.c
--- dev/acpi/acpivout.c 14 Dec 2019 10:57:48 -0000      1.16
+++ dev/acpi/acpivout.c 13 Jan 2020 10:47:13 -0000
@@ -34,6 +34,7 @@ int   acpivout_match(struct device *, void
 void   acpivout_attach(struct device *, struct device *, void *);
 int    acpivout_notify(struct aml_node *, int, void *);
 
+#define ACPIVIDEO_DEBUG
 #ifdef ACPIVIDEO_DEBUG
 #define DPRINTF(x)     printf x
 #else
@@ -215,6 +216,9 @@ int
 acpivout_find_brightness(struct acpivout_softc *sc, int level)
 {
        int i, mid;
+
+       for (i = 0; i < sc->sc_bcl_len; i++)
+               printf("%s: sc->sc_bcl[%d]: %d\n", __func__, i, sc->sc_bcl[i]);
 
        for (i = 0; i < sc->sc_bcl_len - 1; i++) {
                mid = sc->sc_bcl[i] + (sc->sc_bcl[i + 1] - sc->sc_bcl[i]) / 2;


OpenBSD 6.6-current (GENERIC.MP) #3: Mon Jan 13 11:47:31 CET 2020
    [email protected]:/sys/arch/amd64/compile/GENERIC.MP
real mem = 17118126080 (16325MB)
avail mem = 16586883072 (15818MB)
mpath0 at root
scsibus0 at mpath0: 256 targets
mainbus0 at root
bios0 at mainbus0: SMBIOS rev. 2.8 @ 0xbff31020 (17 entries)
bios0: vendor coreboot version "CBET4000 x230-seabios" date 01/07/2020
bios0: LENOVO 2325A95
acpi0 at bios0: ACPI 4.0
acpi0: sleep states S0 S3 S4 S5
acpi0: tables DSDT FACP SSDT MCFG TCPA APIC DMAR HPET
acpi0: wakeup devices HDEF(S4) EHC1(S4) EHC2(S4) XHC_(S4) SLPB(S3) LID_(S3)
acpitimer0 at acpi0: 3579545 Hz, 24 bits
acpimcfg0 at acpi0
acpimcfg0: addr 0xf0000000, bus 0-63
acpimadt0 at acpi0 addr 0xfee00000: PC-AT compat
cpu0 at mainbus0: apid 0 (boot processor)
cpu0: Intel(R) Core(TM) i5-3320M CPU @ 2.60GHz, 2594.47 MHz, 06-3a-09
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,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,RDTSCP,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS,MD_CLEAR,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,MELTDOWN
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.1.2, IBE
cpu1 at mainbus0: apid 1 (application processor)
cpu1: Intel(R) Core(TM) i5-3320M CPU @ 2.60GHz, 2594.11 MHz, 06-3a-09
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,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,RDTSCP,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS,MD_CLEAR,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,MELTDOWN
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) i5-3320M CPU @ 2.60GHz, 2594.12 MHz, 06-3a-09
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,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,RDTSCP,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS,MD_CLEAR,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,MELTDOWN
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) i5-3320M CPU @ 2.60GHz, 2594.11 MHz, 06-3a-09
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,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,RDTSCP,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS,MD_CLEAR,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,MELTDOWN
cpu3: 256KB 64b/line 8-way L2 cache
cpu3: smt 1, core 1, package 0
ioapic0 at mainbus0: apid 2 pa 0xfec00000, version 20, 24 pins
acpihpet0 at acpi0: 14318179 Hz
acpiprt0 at acpi0: bus 0 (PCI0)
acpiprt1 at acpi0: bus 1 (RP01)
acpiprt2 at acpi0: bus 2 (RP02)
acpiprt3 at acpi0: bus 3 (RP03)
acpiprt4 at acpi0: bus -1 (RP04)
acpiprt5 at acpi0: bus -1 (RP05)
acpiprt6 at acpi0: bus -1 (RP06)
acpiprt7 at acpi0: bus -1 (RP07)
acpiprt8 at acpi0: bus -1 (RP08)
acpiec0 at acpi0
acpicpu0 at acpi0: C3(200@90 mwait.1@0x30), C2(500@63 mwait.1@0x10), C1(1000@1 
mwait.1), PSS
acpicpu1 at acpi0: C3(200@90 mwait.1@0x30), C2(500@63 mwait.1@0x10), C1(1000@1 
mwait.1), PSS
acpicpu2 at acpi0: C3(200@90 mwait.1@0x30), C2(500@63 mwait.1@0x10), C1(1000@1 
mwait.1), PSS
acpicpu3 at acpi0: C3(200@90 mwait.1@0x30), C2(500@63 mwait.1@0x10), C1(1000@1 
mwait.1), PSS
acpitz0 at acpi0: critical temperature is 100 degC
acpipwrres0 at acpi0: FPWR, resource for FAN_
acpitz1 at acpi0: critical temperature is 99 degC
acpipci0 at acpi0 PCI0: 0x00000000 0x00000011 0x00000001
acpiac0 at acpi0: AC unit online
acpibat0 at acpi0: BAT0 model "45N1175" serial 11496 type LION oem "SANYO"
acpibat1 at acpi0: BAT1 not present
acpibtn0 at acpi0: SLPB
acpibtn1 at acpi0: LID_
acpithinkpad0 at acpi0: version 1.0
acpicmos0 at acpi0
tpm0 at acpi0: TPM_ addr 0xfed40000/0x5000, device 0x0000104a rev 0x4e
"PNP0C0B" at acpi0 not configured
"BOOT0000" at acpi0 not configured
acpivideo0 at acpi0: GFX0
acpivout0 at acpivideo0: LCD0
Getting _BCL!cpu0: using VERW MDS workaround (except on vmm entry)
cpu0: Enhanced SpeedStep 2594 MHz: speeds: 2601, 2600, 2400, 2200, 2000, 1800, 
1600, 1400, 1200 MHz
pci0 at mainbus0 bus 0
pchb0 at pci0 dev 0 function 0 "Intel Core 3G Host" rev 0x09
inteldrm0 at pci0 dev 2 function 0 "Intel HD Graphics 4000" rev 0x09
drm0 at inteldrm0
inteldrm0: msi
"Intel Core 3G Thermal" rev 0x09 at pci0 dev 4 function 0 not configured
xhci0 at pci0 dev 20 function 0 "Intel 7 Series xHCI" rev 0x04: msi, xHCI 1.0
usb0 at xhci0: USB revision 3.0
uhub0 at usb0 configuration 1 interface 0 "Intel xHCI root hub" rev 3.00/1.00 
addr 1
"Intel 7 Series MEI" rev 0x04 at pci0 dev 22 function 0 not configured
em0 at pci0 dev 25 function 0 "Intel 82579LM" rev 0x04: msi, address 
3c:97:0e:6e:e9:1b
ehci0 at pci0 dev 26 function 0 "Intel 7 Series USB" rev 0x04: apic 2 int 19
usb1 at ehci0: USB revision 2.0
uhub1 at usb1 configuration 1 interface 0 "Intel EHCI root hub" rev 2.00/1.00 
addr 1
azalia0 at pci0 dev 27 function 0 "Intel 7 Series HD Audio" rev 0x04: msi
azalia0: codecs: Realtek ALC269, Intel/0x2806, using Realtek ALC269
audio0 at azalia0
ppb0 at pci0 dev 28 function 0 "Intel 7 Series PCIE" rev 0xc4
pci1 at ppb0 bus 1
sdhc0 at pci1 dev 0 function 0 "Ricoh 5U822 SD/MMC" rev 0x07: apic 2 int 16
sdhc0: SDHC 3.0, 50 MHz base clock
sdmmc0 at sdhc0: 4-bit, sd high-speed, mmc high-speed, dma
ppb1 at pci0 dev 28 function 1 "Intel 7 Series PCIE" rev 0xc4
pci2 at ppb1 bus 2
athn0 at pci2 dev 0 function 0 "Atheros AR9281" rev 0x01: apic 2 int 17
athn0: AR9280 rev 2 (2T2R), ROM rev 22, address 04:f0:21:30:37:de
ppb2 at pci0 dev 28 function 2 "Intel 7 Series PCIE" rev 0xc4: msi
pci3 at ppb2 bus 3
ehci1 at pci0 dev 29 function 0 "Intel 7 Series USB" rev 0x04: apic 2 int 18
usb2 at ehci1: USB revision 2.0
uhub2 at usb2 configuration 1 interface 0 "Intel EHCI root hub" rev 2.00/1.00 
addr 1
pcib0 at pci0 dev 31 function 0 "Intel QM77 LPC" rev 0x04
ahci0 at pci0 dev 31 function 2 "Intel 7 Series AHCI" rev 0x04: msi, AHCI 1.3
ahci0: port 0: 6.0Gb/s
scsibus1 at ahci0: 32 targets
sd0 at scsibus1 targ 0 lun 0: <ATA, Samsung SSD 850, EMT0> naa.5002538d410a7bce
sd0: 238475MB, 512 bytes/sector, 488397168 sectors, thin
ichiic0 at pci0 dev 31 function 3 "Intel 7 Series SMBus" rev 0x04: apic 2 int 16
iic0 at ichiic0
iic0: addr 0x24 03=04 09=45 0a=48 0b=10 0c=02 0d=13 0e=01 0f=20 words 00=00ff 
01=00ff 02=00ff 03=04ff 04=00ff 05=00ff 06=00ff 07=00ff
spdmem0 at iic0 addr 0x50: 8GB DDR3 SDRAM PC3-12800 SO-DIMM
spdmem1 at iic0 addr 0x51: 8GB DDR3 SDRAM PC3-12800 SO-DIMM
"Intel 7 Series Thermal" rev 0x04 at pci0 dev 31 function 6 not configured
isa0 at pcib0
isadma0 at isa0
pckbc0 at isa0 port 0x60/5 irq 1 irq 12
pckbd0 at pckbc0 (kbd slot)
wskbd0 at pckbd0: console keyboard
pms0 at pckbc0 (aux slot)
wsmouse0 at pms0 mux 0
wsmouse1 at pms0 mux 0
pms0: Synaptics clickpad, firmware 8.1, 0x1e2b1 0x940300
pcppi0 at isa0 port 0x61
spkr0 at pcppi0
vmm0 at mainbus0: VMX/EPT
efifb at mainbus0 not configured
sdmmc0: can't enable card
uhidev0 at uhub0 port 2 configuration 1 interface 0 "Kinesis Advantage2 
Keyboard" rev 2.00/1.00 addr 2
uhidev0: iclass 3/1
ums0 at uhidev0: 3 buttons, Z dir
wsmouse2 at ums0 mux 0
uhidev1 at uhub0 port 2 configuration 1 interface 1 "Kinesis Advantage2 
Keyboard" rev 2.00/1.00 addr 2
uhidev1: iclass 3/1
ukbd0 at uhidev1: 8 variable keys, 6 key codes
wskbd1 at ukbd0 mux 1
uhidev2 at uhub0 port 2 configuration 1 interface 2 "Kinesis Advantage2 
Keyboard" rev 2.00/1.00 addr 2
uhidev2: iclass 3/0, 2 report ids
uhid0 at uhidev2 reportid 1: input=1, output=0, feature=0
uhid1 at uhidev2 reportid 2: input=1, output=0, feature=0
uhub3 at uhub1 port 1 configuration 1 interface 0 "Intel Rate Matching Hub" rev 
2.00/0.00 addr 2
uhub4 at uhub2 port 1 configuration 1 interface 0 "Intel Rate Matching Hub" rev 
2.00/0.00 addr 2
vscsi0 at root
scsibus2 at vscsi0: 256 targets
softraid0 at root
scsibus3 at softraid0: 256 targets
sd1 at scsibus3 targ 1 lun 0: <OPENBSD, SR CRYPTO, 006>
sd1: 238472MB, 512 bytes/sector, 488391473 sectors
root on sd1a (b712848db54bdd1d.a) swap on sd1b dump on sd1b
inteldrm0: 1366x768, 32bpp
acpivout0: BQC = 100
wsdisplay0 at inteldrm0 mux 1: console (std, vt100 emulation), using wskbd0
wskbd1: connecting to wsdisplay0
wsdisplay0: screen 1-5 added (std, vt100 emulation)
acpivout0: BQC = 100
acpivout0: BQC = 100
acpivout0: BQC = 100
acpivout_find_brightness: sc->sc_bcl[0]: 2
acpivout_find_brightness: sc->sc_bcl[1]: 4
acpivout_find_brightness: sc->sc_bcl[2]: 5
acpivout_find_brightness: sc->sc_bcl[3]: 7
acpivout_find_brightness: sc->sc_bcl[4]: 9
acpivout_find_brightness: sc->sc_bcl[5]: 11
acpivout_find_brightness: sc->sc_bcl[6]: 13
acpivout_find_brightness: sc->sc_bcl[7]: 18
acpivout_find_brightness: sc->sc_bcl[8]: 20
acpivout_find_brightness: sc->sc_bcl[9]: 24
acpivout_find_brightness: sc->sc_bcl[10]: 29
acpivout_find_brightness: sc->sc_bcl[11]: 33
acpivout_find_brightness: sc->sc_bcl[12]: 40
acpivout_find_brightness: sc->sc_bcl[13]: 50
acpivout_find_brightness: sc->sc_bcl[14]: 67
acpivout_find_brightness: sc->sc_bcl[15]: 100
acpivout0: BCM = 100
wsmouse2 detached
ums0 detached
uhidev0 detached
wskbd1: disconnecting from wsdisplay0
wskbd1 detached
ukbd0 detached
uhidev1 detached
uhid0 detached
uhid1 detached
uhidev2 detached
uhidev0 at uhub0 port 2 configuration 1 interface 0 "Kinesis Advantage2 
Keyboard" rev 2.00/1.00 addr 2
uhidev0: iclass 3/1
ums0 at uhidev0: 3 buttons, Z dir
wsmouse2 at ums0 mux 0
uhidev1 at uhub0 port 2 configuration 1 interface 1 "Kinesis Advantage2 
Keyboard" rev 2.00/1.00 addr 2
uhidev1: iclass 3/1
ukbd0 at uhidev1: 8 variable keys, 6 key codes
wskbd1 at ukbd0 mux 1
wskbd1: connecting to wsdisplay0
uhidev2 at uhub0 port 2 configuration 1 interface 2 "Kinesis Advantage2 
Keyboard" rev 2.00/1.00 addr 2
uhidev2: no report descriptor
wsmouse2 detached
ums0 detached
uhidev0 detached
wskbd1: disconnecting from wsdisplay0
wskbd1 detached
ukbd0 detached
uhidev1 detached
uhidev2 detached
uhidev0 at uhub0 port 2 configuration 1 interface 0 "Kinesis Advantage2 
Keyboard" rev 2.00/1.00 addr 2
uhidev0: iclass 3/1
ums0 at uhidev0: 3 buttons, Z dir
wsmouse2 at ums0 mux 0
uhidev1 at uhub0 port 2 configuration 1 interface 1 "Kinesis Advantage2 
Keyboard" rev 2.00/1.00 addr 2
uhidev1: iclass 3/1
ukbd0 at uhidev1: 8 variable keys, 6 key codes
wskbd1 at ukbd0 mux 1
wskbd1: connecting to wsdisplay0
uhidev2 at uhub0 port 2 configuration 1 interface 2 "Kinesis Advantage2 
Keyboard" rev 2.00/1.00 addr 2
uhidev2: iclass 3/0, 2 report ids
uhid0 at uhidev2 reportid 1: input=1, output=0, feature=0
uhid1 at uhidev2 reportid 2: input=1, output=0, feature=0
acpivout0: BQC = 100

Reply via email to