Re: arm64: new gpiokeys(4)

2021-11-10 Thread Jan Stary
On Nov 10 13:20:45, k...@openbsd.org wrote:
> On Wed, Nov 10, 2021 at 12:07:37AM +0100, Jan Stary wrote:
> > On Nov 09 15:43:04, k...@openbsd.org wrote:
> > > This populates `systat sensors' with the correct lid status on my
> > > Pinebook Pro:
> > > 
> > >   -gpio-key-lid at mainbus0 not configured
> > >   -gpio-key-power at mainbus0 not configured
> > >   +gpiokeys0 at mainbus0: "Lid"
> > >   +gpiokeys0 at mainbus0: "Power"
> > 
> > 
> > This is what the diff added on RPI4 (dmesg below).
> > 
> > -gpioleds0 at mainbus0: no LEDs
> > +gpioleds0 at mainbus0: "led0", "led1"
> 
> This is from another recent commit I made to gpioleds(4), specifically
> to recognise LEDs on this machine.

Ah, sorry for the confusion.
Thanks anyway :-)

Jan

> It has nothing to do with gpiokeys(4).
> 
> > (Nothing new in systat sens,
> > as leds are not sensors.)
> 
> Correct, that's because there are no GPIO keys on the Pi 4 (Model B),
> i.e. there's nothing in the device tree to match gpiokeys(4).
> 
> 



Re: arm64: new gpiokeys(4)

2021-11-10 Thread Klemens Nanni
On Wed, Nov 10, 2021 at 12:07:37AM +0100, Jan Stary wrote:
> On Nov 09 15:43:04, k...@openbsd.org wrote:
> > This populates `systat sensors' with the correct lid status on my
> > Pinebook Pro:
> > 
> > -gpio-key-lid at mainbus0 not configured
> > -gpio-key-power at mainbus0 not configured
> > +gpiokeys0 at mainbus0: "Lid"
> > +gpiokeys0 at mainbus0: "Power"
> 
> 
> This is what the diff added on RPI4 (dmesg below).
> 
> -gpioleds0 at mainbus0: no LEDs
> +gpioleds0 at mainbus0: "led0", "led1"

This is from another recent commit I made to gpioleds(4), specifically
to recognise LEDs on this machine.

It has nothing to do with gpiokeys(4).

> (Nothing new in systat sens,
> as leds are not sensors.)

Correct, that's because there are no GPIO keys on the Pi 4 (Model B),
i.e. there's nothing in the device tree to match gpiokeys(4).



Re: arm64: new gpiokeys(4)

2021-11-09 Thread Jan Stary
On Nov 09 15:43:04, k...@openbsd.org wrote:
> This populates `systat sensors' with the correct lid status on my
> Pinebook Pro:
> 
>   -gpio-key-lid at mainbus0 not configured
>   -gpio-key-power at mainbus0 not configured
>   +gpiokeys0 at mainbus0: "Lid"
>   +gpiokeys0 at mainbus0: "Power"


This is what the diff added on RPI4 (dmesg below).

-gpioleds0 at mainbus0: no LEDs
+gpioleds0 at mainbus0: "led0", "led1"

(Nothing new in systat sens,
as leds are not sensors.)

Jan


OpenBSD 7.0-current (GENERIC.MP) #0: Tue Nov  9 21:52:42 CET 2021
h...@pi.stare.cz:/usr/src/sys/arch/arm64/compile/GENERIC.MP
real mem  = 8419885056 (8029MB)
avail mem = 8128704512 (7752MB)
random: good seed from bootblocks
mainbus0 at root: Raspberry Pi 4 Model B Rev 1.4
cpu0 at mainbus0 mpidr 0: ARM Cortex-A72 r0p3
cpu0: 48KB 64b/line 3-way L1 PIPT I-cache, 32KB 64b/line 2-way L1 D-cache
cpu0: 1024KB 64b/line 16-way L2 cache
cpu0: CRC32,ASID16
cpu1 at mainbus0 mpidr 1: ARM Cortex-A72 r0p3
cpu1: 48KB 64b/line 3-way L1 PIPT I-cache, 32KB 64b/line 2-way L1 D-cache
cpu1: 1024KB 64b/line 16-way L2 cache
cpu1: CRC32,ASID16
cpu2 at mainbus0 mpidr 2: ARM Cortex-A72 r0p3
cpu2: 48KB 64b/line 3-way L1 PIPT I-cache, 32KB 64b/line 2-way L1 D-cache
cpu2: 1024KB 64b/line 16-way L2 cache
cpu2: CRC32,ASID16
cpu3 at mainbus0 mpidr 3: ARM Cortex-A72 r0p3
cpu3: 48KB 64b/line 3-way L1 PIPT I-cache, 32KB 64b/line 2-way L1 D-cache
cpu3: 1024KB 64b/line 16-way L2 cache
cpu3: CRC32,ASID16
efi0 at mainbus0: UEFI 2.8
efi0: Das U-Boot rev 0x20210100
apm0 at mainbus0
"system" at mainbus0 not configured
"axi" at mainbus0 not configured
simplebus0 at mainbus0: "soc"
bcmclock0 at simplebus0
bcmmbox0 at simplebus0
bcmgpio0 at simplebus0
bcmaux0 at simplebus0
ampintc0 at simplebus0 nirq 256, ncpu 4 ipi: 0, 1: "interrupt-controller"
bcmtmon0 at simplebus0
bcmdmac0 at simplebus0: DMA0 DMA2 DMA4 DMA5 DMA6 DMA7 DMA8 DMA9
"timer" at simplebus0 not configured
pluart0 at simplebus0: console
"local_intc" at simplebus0 not configured
bcmdog0 at simplebus0
bcmirng0 at simplebus0
"firmware" at simplebus0 not configured
"power" at simplebus0 not configured
"mailbox" at simplebus0 not configured
sdhc0 at simplebus0
sdhc0: SDHC 3.0, 250 MHz base clock
sdmmc0 at sdhc0: 4-bit, sd high-speed, mmc high-speed
"gpiomem" at simplebus0 not configured
"fb" at simplebus0 not configured
"vcsm" at simplebus0 not configured
"clocks" at mainbus0 not configured
"phy" at mainbus0 not configured
"clk-27M" at mainbus0 not configured
"clk-108M" at mainbus0 not configured
simplebus1 at mainbus0: "emmc2bus"
sdhc1 at simplebus1
sdhc1: SDHC 3.0, 100 MHz base clock
sdmmc1 at sdhc1: 8-bit, sd high-speed, mmc high-speed, ddr52, dma
"arm-pmu" at mainbus0 not configured
agtimer0 at mainbus0: 54000 kHz
simplebus2 at mainbus0: "scb"
bcmpcie0 at simplebus2
pci0 at bcmpcie0
ppb0 at pci0 dev 0 function 0 "Broadcom BCM2711" rev 0x10
pci1 at ppb0 bus 1
xhci0 at pci1 dev 0 function 0 "VIA VL805 xHCI" rev 0x01: intx, xHCI 1.0
usb0 at xhci0: USB revision 3.0
uhub0 at usb0 configuration 1 interface 0 "VIA xHCI root hub" rev 3.00/1.00 
addr 1
bse0 at simplebus2: address dc:a6:32:e0:50:d3
brgphy0 at bse0 phy 1: BCM54210E 10/100/1000baseT PHY, rev. 2
"dma" at simplebus2 not configured
"hevc-decoder" at simplebus2 not configured
"rpivid-local-intc" at simplebus2 not configured
"h264-decoder" at simplebus2 not configured
"vp9-decoder" at simplebus2 not configured
gpioleds0 at mainbus0: "led0", "led1"
"sd_io_1v8_reg" at mainbus0 not configured
"sd_vcc_reg" at mainbus0 not configured
"fixedregulator_3v3" at mainbus0 not configured
"fixedregulator_5v0" at mainbus0 not configured
simplebus3 at mainbus0: "v3dbus"
"bootloader" at mainbus0 not configured
dt: 445 probes
scsibus0 at sdmmc1: 2 targets, initiator 0
sd0 at scsibus0 targ 1 lun 0:  removable
sd0: 30436MB, 512 bytes/sector, 62333952 sectors
uhub1 at uhub0 port 1 configuration 1 interface 0 "VIA Labs USB2.0 Hub" rev 
2.10/4.21 addr 2
bwfm0 at sdmmc0 function 1
manufacturer 0x02d0, product 0xa9a6 at sdmmc0 function 2 not configured
manufacturer 0x02d0, product 0xa9a6 at sdmmc0 function 3 not configured
vscsi0 at root
scsibus1 at vscsi0: 256 targets
softraid0 at root
scsibus2 at softraid0: 256 targets
root on sd0a (d1a7e0233ab9545d.a) swap on sd0b dump on sd0b
WARNING: CHECK AND RESET THE DATE!
gpio0 at bcmgpio0: 58 pins
bwfm0: address dc:a6:32:e0:50:d4



Re: arm64: new gpiokeys(4)

2021-11-09 Thread Mark Kettenis
> Date: Tue,  9 Nov 2021 15:43:04 +
> From: Klemens Nanni 
> 
> This populates `systat sensors' with the correct lid status on my
> Pinebook Pro:
> 
>   -gpio-key-lid at mainbus0 not configured
>   -gpio-key-power at mainbus0 not configured
>   +gpiokeys0 at mainbus0: "Lid"
>   +gpiokeys0 at mainbus0: "Power"
> 
> 0/1 <-> closed/open is mapped exactly like acpibtn(4) already does on
> other machines, to maintain consistent user experience across devices.
> 
> Next steps are:
> - hook up lid status with `machdep.lidaction', see acpibtn(4)
> - handle power button -> hook up machdep.pwraction, see acpibtn(4)
> 
> 
> Sort gpio{led,charger,keys} while here.
> 
> Feedback? OK?

ok kettenis@

> diff 83b213946bcaccd148d4a46b6ebda89b120fc778 refs/heads/master
> blob - ab52b74cf7e9895cbcb29532b9898cdaf33e89f3
> blob + 0891a80caf135b983dea282f281d7f6089b52e30
> --- distrib/sets/lists/man/mi
> +++ distrib/sets/lists/man/mi
> @@ -1423,6 +1423,7 @@
>  ./usr/share/man/man4/gpiocharger.4
>  ./usr/share/man/man4/gpiodcf.4
>  ./usr/share/man/man4/gpioiic.4
> +./usr/share/man/man4/gpiokeys.4
>  ./usr/share/man/man4/gpioleds.4
>  ./usr/share/man/man4/gpioow.4
>  ./usr/share/man/man4/graphaudio.4
> blob - c32bc8962cd103da4ed17ad63a2162f63a16e639
> blob + 6057d2a559120ada9f43ae0f5e5e6eb63a514be8
> --- share/man/man4/Makefile
> +++ share/man/man4/Makefile
> @@ -37,7 +37,7 @@ MAN=aac.4 abcrtc.4 abl.4 ac97.4 acphy.4 acrtc.4 \
>   fuse.4 fxp.4 \
>   gdt.4 gentbi.4 gem.4 gfrtc.4 gif.4 glenv.4 glkgpio.4 gpio.4 \
>   gpiocharger.4 gpiodcf.4 \
> - gpioiic.4 gpioleds.4 gpioow.4 graphaudio.4 gre.4 gscsio.4 \
> + gpioiic.4 gpiokeys.4 gpioleds.4 gpioow.4 graphaudio.4 gre.4 gscsio.4 \
>   hds.4 hiclock.4 hidwusb.4 hil.4 hilid.4 hilkbd.4 hilms.4 \
>   hireset.4 hitemp.4 hme.4 hotplug.4 hsq.4 \
>   hvn.4 hvs.4 hyperv.4 \
> blob - /dev/null
> blob + 44c147f04672fa1b72820ebd7692d7efbe17ceae (mode 644)
> --- /dev/null
> +++ share/man/man4/gpiokeys.4
> @@ -0,0 +1,50 @@
> +.\"  $OpenBSD: $
> +.\"
> +.\" Copyright (c) 2021 Klemens Nanni 
> +.\"
> +.\" Permission to use, copy, modify, and distribute this software for any
> +.\" purpose with or without fee is hereby granted, provided that the above
> +.\" copyright notice and this permission notice appear in all copies.
> +.\"
> +.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
> +.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
> +.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
> +.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
> +.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
> +.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
> +.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
> +.\"
> +.Dd $Mdocdate: September 02 2021 $
> +.Dt GPIOKEYS 4
> +.Os
> +.Sh NAME
> +.Nm gpiokeys
> +.Nd GPIO keys
> +.Sh SYNOPSIS
> +.Cd "gpiokeys* at fdt?"
> +.Sh DESCRIPTION
> +The
> +.Nm
> +driver handles events triggered by GPIO keys.
> +Currently, only lid status events are supported.
> +.Pp
> +The lid status is set up as a sensor and can be monitored using
> +.Xr sysctl 8
> +or
> +.Xr sensorsd 8 .
> +.Sh SEE ALSO
> +.Xr gpio 4 ,
> +.Xr intro 4 ,
> +.Xr sensorsd 8 ,
> +.Xr sysctl 8
> +.Sh HISTORY
> +The
> +.Nm
> +driver first appeared in
> +.Ox 7.1 .
> +.Sh AUTHORS
> +.An -nosplit
> +The
> +.Nm
> +driver was written by
> +.An Klemens Nanni Aq Mt k...@openbsd.org .
> blob - 809ece860c07df596da208638f2f3facc829cb72
> blob + 0ceac9b6159e5cfe43fc4e601274100df1c40ffa
> --- sys/arch/arm64/conf/GENERIC
> +++ sys/arch/arm64/conf/GENERIC
> @@ -131,8 +131,9 @@ amdgpu*   at pci?
>  drm* at amdgpu?
>  wsdisplay*   at amdgpu?
>  
> -gpioleds*at fdt?
>  gpiocharger* at fdt?
> +gpiokeys*at fdt?
> +gpioleds*at fdt?
>  
>  # Apple
>  apldart* at fdt?
> blob - 301500e9b0c6501be4d55feb5135ca223d6337cc
> blob + 3d73e22edf7802172b29a26cb8b503eaeb8f3aa9
> --- sys/dev/fdt/files.fdt
> +++ sys/dev/fdt/files.fdt
> @@ -589,10 +589,14 @@ device  dapmic
>  attach   dapmic at i2c
>  file dev/fdt/dapmic.cdapmic
>  
> -device   gpioleds
> -attach   gpioleds at fdt
> -file dev/fdt/gpioleds.c  gpioleds
> -
>  device   gpiocharger
>  attach   gpiocharger at fdt
>  file dev/fdt/gpiocharger.c   gpiocharger
> +
> +device   gpioleds
> +attach   gpioleds at fdt
> +file dev/fdt/gpioleds.c  gpioleds
> +
> +device   gpiokeys
> +attach   gpiokeys at fdt
> +file dev/fdt/gpiokeys.c  gpiokeys
> blob - /dev/null
> blob + 4b4ca55a5c825ad8d66fbc8ec198bbcd13352b7c (mode 644)
> --- /dev/null
> +++ sys/dev/fdt/gpiokeys.c
> @@ -0,0 +1,179 @@
> +/*   $OpenBSD: $ */
> +/*
> + * Copyright (c) 2021 Klemens Nanni 
> + *
> + * Permission to use, copy, modify, and distribute this software for any
> + * purpose with or 

arm64: new gpiokeys(4)

2021-11-09 Thread Klemens Nanni
This populates `systat sensors' with the correct lid status on my
Pinebook Pro:

-gpio-key-lid at mainbus0 not configured
-gpio-key-power at mainbus0 not configured
+gpiokeys0 at mainbus0: "Lid"
+gpiokeys0 at mainbus0: "Power"

0/1 <-> closed/open is mapped exactly like acpibtn(4) already does on
other machines, to maintain consistent user experience across devices.

Next steps are:
- hook up lid status with `machdep.lidaction', see acpibtn(4)
- handle power button -> hook up machdep.pwraction, see acpibtn(4)


Sort gpio{led,charger,keys} while here.

Feedback? OK?


diff 83b213946bcaccd148d4a46b6ebda89b120fc778 refs/heads/master
blob - ab52b74cf7e9895cbcb29532b9898cdaf33e89f3
blob + 0891a80caf135b983dea282f281d7f6089b52e30
--- distrib/sets/lists/man/mi
+++ distrib/sets/lists/man/mi
@@ -1423,6 +1423,7 @@
 ./usr/share/man/man4/gpiocharger.4
 ./usr/share/man/man4/gpiodcf.4
 ./usr/share/man/man4/gpioiic.4
+./usr/share/man/man4/gpiokeys.4
 ./usr/share/man/man4/gpioleds.4
 ./usr/share/man/man4/gpioow.4
 ./usr/share/man/man4/graphaudio.4
blob - c32bc8962cd103da4ed17ad63a2162f63a16e639
blob + 6057d2a559120ada9f43ae0f5e5e6eb63a514be8
--- share/man/man4/Makefile
+++ share/man/man4/Makefile
@@ -37,7 +37,7 @@ MAN=  aac.4 abcrtc.4 abl.4 ac97.4 acphy.4 acrtc.4 \
fuse.4 fxp.4 \
gdt.4 gentbi.4 gem.4 gfrtc.4 gif.4 glenv.4 glkgpio.4 gpio.4 \
gpiocharger.4 gpiodcf.4 \
-   gpioiic.4 gpioleds.4 gpioow.4 graphaudio.4 gre.4 gscsio.4 \
+   gpioiic.4 gpiokeys.4 gpioleds.4 gpioow.4 graphaudio.4 gre.4 gscsio.4 \
hds.4 hiclock.4 hidwusb.4 hil.4 hilid.4 hilkbd.4 hilms.4 \
hireset.4 hitemp.4 hme.4 hotplug.4 hsq.4 \
hvn.4 hvs.4 hyperv.4 \
blob - /dev/null
blob + 44c147f04672fa1b72820ebd7692d7efbe17ceae (mode 644)
--- /dev/null
+++ share/man/man4/gpiokeys.4
@@ -0,0 +1,50 @@
+.\"$OpenBSD: $
+.\"
+.\" Copyright (c) 2021 Klemens Nanni 
+.\"
+.\" Permission to use, copy, modify, and distribute this software for any
+.\" purpose with or without fee is hereby granted, provided that the above
+.\" copyright notice and this permission notice appear in all copies.
+.\"
+.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+.\"
+.Dd $Mdocdate: September 02 2021 $
+.Dt GPIOKEYS 4
+.Os
+.Sh NAME
+.Nm gpiokeys
+.Nd GPIO keys
+.Sh SYNOPSIS
+.Cd "gpiokeys* at fdt?"
+.Sh DESCRIPTION
+The
+.Nm
+driver handles events triggered by GPIO keys.
+Currently, only lid status events are supported.
+.Pp
+The lid status is set up as a sensor and can be monitored using
+.Xr sysctl 8
+or
+.Xr sensorsd 8 .
+.Sh SEE ALSO
+.Xr gpio 4 ,
+.Xr intro 4 ,
+.Xr sensorsd 8 ,
+.Xr sysctl 8
+.Sh HISTORY
+The
+.Nm
+driver first appeared in
+.Ox 7.1 .
+.Sh AUTHORS
+.An -nosplit
+The
+.Nm
+driver was written by
+.An Klemens Nanni Aq Mt k...@openbsd.org .
blob - 809ece860c07df596da208638f2f3facc829cb72
blob + 0ceac9b6159e5cfe43fc4e601274100df1c40ffa
--- sys/arch/arm64/conf/GENERIC
+++ sys/arch/arm64/conf/GENERIC
@@ -131,8 +131,9 @@ amdgpu* at pci?
 drm*   at amdgpu?
 wsdisplay* at amdgpu?
 
-gpioleds*  at fdt?
 gpiocharger*   at fdt?
+gpiokeys*  at fdt?
+gpioleds*  at fdt?
 
 # Apple
 apldart*   at fdt?
blob - 301500e9b0c6501be4d55feb5135ca223d6337cc
blob + 3d73e22edf7802172b29a26cb8b503eaeb8f3aa9
--- sys/dev/fdt/files.fdt
+++ sys/dev/fdt/files.fdt
@@ -589,10 +589,14 @@ devicedapmic
 attach dapmic at i2c
 file   dev/fdt/dapmic.cdapmic
 
-device gpioleds
-attach gpioleds at fdt
-file   dev/fdt/gpioleds.c  gpioleds
-
 device gpiocharger
 attach gpiocharger at fdt
 file   dev/fdt/gpiocharger.c   gpiocharger
+
+device gpioleds
+attach gpioleds at fdt
+file   dev/fdt/gpioleds.c  gpioleds
+
+device gpiokeys
+attach gpiokeys at fdt
+file   dev/fdt/gpiokeys.c  gpiokeys
blob - /dev/null
blob + 4b4ca55a5c825ad8d66fbc8ec198bbcd13352b7c (mode 644)
--- /dev/null
+++ sys/dev/fdt/gpiokeys.c
@@ -0,0 +1,179 @@
+/* $OpenBSD: $ */
+/*
+ * Copyright (c) 2021 Klemens Nanni 
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT,