Re: new gpiocharger driver

2021-09-25 Thread Mark Kettenis
> Date: Sat, 25 Sep 2021 15:45:15 +
> From: Klemens Nanni 
> 
> On Sat, Sep 25, 2021 at 10:53:12AM +, Klemens Nanni wrote:
> > On Fri, Sep 24, 2021 at 10:35:56PM +, Klemens Nanni wrote:
> > > On Thu, Sep 16, 2021 at 11:07:20AM +0200, Mark Kettenis wrote:
> > > > > Date: Thu, 16 Sep 2021 06:14:39 +
> > > > > From: Klemens Nanni 
> > > > > 
> > > > > On 5 September 2021 01:22:53 GMT+05:00, Klemens Nanni 
> > > > >  wrote:
> > > > > >Read a single GPIO pin indicating whether AC is plugged in or not.
> > > > > >
> > > > > >This gives me a sensor on my Pinebook Pro.
> > > > > >cwfg(4) already provides battery information but not the charger 
> > > > > >bits.
> > > > > >
> > > > > >apm(4) integration can follow separately.
> > > > > >
> > > > > >Feedback? OK?
> > > > > 
> > > > > Ping.
> > > > > The diff applies after the "new gpioleds driver" one.
> > > 
> > > New diff.  OK for after unlock modulo the gpioleds bits after being
> > > committed separately (CVS diffs juggling is annoying)?
> > > 
> > > > > >+gpios_len = OF_getproplen(node,
> > > > > >+gpios_property = "charger-status-gpios");
> > > > 
> > > > No, please don't hide assignment statements as function arguments.
> > > 
> > > Fixed, thanks.
> > 
> > Clean diff after gpioleds(4) got in, this time with the same whitespace
> > fixes.
> > 
> > Sorry for the noise.
> 
> Sigh, an eagle-eyed reader noticed my copy-paste error:
> 
> > +   gpios_property = "charger-status-gpios");
> 
> Here's the correct diff that also compiles.

ok kettenis@

> Index: share/man/man4/gpiocharger.4
> ===
> RCS file: share/man/man4/gpiocharger.4
> diff -N share/man/man4/gpiocharger.4
> --- /dev/null 1 Jan 1970 00:00:00 -
> +++ share/man/man4/gpiocharger.4  24 Sep 2021 22:33:26 -
> @@ -0,0 +1,51 @@
> +.\"  $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 04 2021 $
> +.Dt GPIOCHARGER 4
> +.Os
> +.Sh NAME
> +.Nm gpiocharger
> +.Nd GPIO battery charger
> +.Sh SYNOPSIS
> +.Cd "gpiocharger* at fdt?"
> +.Sh DESCRIPTION
> +The
> +.Nm
> +driver provides support for battery chargers connected to GPIO pins.
> +Currently, only power supply status events are supported.
> +.Pp
> +The power supply status (connected or disconnected) 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 .
> Index: share/man/man4/Makefile
> ===
> RCS file: /cvs/src/share/man/man4/Makefile,v
> retrieving revision 1.807
> diff -u -p -r1.807 Makefile
> --- share/man/man4/Makefile   25 Sep 2021 10:43:23 -  1.807
> +++ share/man/man4/Makefile   25 Sep 2021 10:45:42 -
> @@ -35,7 +35,8 @@ MAN=aac.4 abcrtc.4 abl.4 ac97.4 acphy.4
>   eso.4 ess.4 et.4 etherip.4 etphy.4 ex.4 exphy.4 exrtc.4 \
>   fanpwr.4 fd.4 fdc.4 fec.4 fido.4 fins.4 fintek.4 fms.4 fusbtc.4 \
>   fuse.4 fxp.4 \
> - gdt.4 gentbi.4 gem.4 gfrtc.4 gif.4 glenv.4 glkgpio.4 gpio.4 gpiodcf.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 \
>   hds.4 hiclock.4 hidwusb.4 hifn.4 hil.4 hilid.4 hilkbd.4 hilms.4 \
>   hireset.4 hitemp.4 hme.4 hotplug.4 hsq.4 \
> Index: sys/dev/fdt/gpiocharger.c
> ===
> RCS file: sys/dev/fdt/gpiocharger.c
> diff -N sys/dev/fdt/gpiocharger.c
> --- /dev/null 1 Jan 1970 00:00:00 -
> +++ sys/dev/fdt/gpiocharger.c 25 Sep 2021 14:42:16 -
> @@ -0,0 +1,117 @@
> +/*   $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 

Re: new gpiocharger driver

2021-09-25 Thread Klemens Nanni
On Sat, Sep 25, 2021 at 10:53:12AM +, Klemens Nanni wrote:
> On Fri, Sep 24, 2021 at 10:35:56PM +, Klemens Nanni wrote:
> > On Thu, Sep 16, 2021 at 11:07:20AM +0200, Mark Kettenis wrote:
> > > > Date: Thu, 16 Sep 2021 06:14:39 +
> > > > From: Klemens Nanni 
> > > > 
> > > > On 5 September 2021 01:22:53 GMT+05:00, Klemens Nanni 
> > > >  wrote:
> > > > >Read a single GPIO pin indicating whether AC is plugged in or not.
> > > > >
> > > > >This gives me a sensor on my Pinebook Pro.
> > > > >cwfg(4) already provides battery information but not the charger bits.
> > > > >
> > > > >apm(4) integration can follow separately.
> > > > >
> > > > >Feedback? OK?
> > > > 
> > > > Ping.
> > > > The diff applies after the "new gpioleds driver" one.
> > 
> > New diff.  OK for after unlock modulo the gpioleds bits after being
> > committed separately (CVS diffs juggling is annoying)?
> > 
> > > > >+  gpios_len = OF_getproplen(node,
> > > > >+  gpios_property = "charger-status-gpios");
> > > 
> > > No, please don't hide assignment statements as function arguments.
> > 
> > Fixed, thanks.
> 
> Clean diff after gpioleds(4) got in, this time with the same whitespace
> fixes.
> 
> Sorry for the noise.

Sigh, an eagle-eyed reader noticed my copy-paste error:

> + gpios_property = "charger-status-gpios");

Here's the correct diff that also compiles.


Index: share/man/man4/gpiocharger.4
===
RCS file: share/man/man4/gpiocharger.4
diff -N share/man/man4/gpiocharger.4
--- /dev/null   1 Jan 1970 00:00:00 -
+++ share/man/man4/gpiocharger.424 Sep 2021 22:33:26 -
@@ -0,0 +1,51 @@
+.\"$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 04 2021 $
+.Dt GPIOCHARGER 4
+.Os
+.Sh NAME
+.Nm gpiocharger
+.Nd GPIO battery charger
+.Sh SYNOPSIS
+.Cd "gpiocharger* at fdt?"
+.Sh DESCRIPTION
+The
+.Nm
+driver provides support for battery chargers connected to GPIO pins.
+Currently, only power supply status events are supported.
+.Pp
+The power supply status (connected or disconnected) 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 .
Index: share/man/man4/Makefile
===
RCS file: /cvs/src/share/man/man4/Makefile,v
retrieving revision 1.807
diff -u -p -r1.807 Makefile
--- share/man/man4/Makefile 25 Sep 2021 10:43:23 -  1.807
+++ share/man/man4/Makefile 25 Sep 2021 10:45:42 -
@@ -35,7 +35,8 @@ MAN=  aac.4 abcrtc.4 abl.4 ac97.4 acphy.4
eso.4 ess.4 et.4 etherip.4 etphy.4 ex.4 exphy.4 exrtc.4 \
fanpwr.4 fd.4 fdc.4 fec.4 fido.4 fins.4 fintek.4 fms.4 fusbtc.4 \
fuse.4 fxp.4 \
-   gdt.4 gentbi.4 gem.4 gfrtc.4 gif.4 glenv.4 glkgpio.4 gpio.4 gpiodcf.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 \
hds.4 hiclock.4 hidwusb.4 hifn.4 hil.4 hilid.4 hilkbd.4 hilms.4 \
hireset.4 hitemp.4 hme.4 hotplug.4 hsq.4 \
Index: sys/dev/fdt/gpiocharger.c
===
RCS file: sys/dev/fdt/gpiocharger.c
diff -N sys/dev/fdt/gpiocharger.c
--- /dev/null   1 Jan 1970 00:00:00 -
+++ sys/dev/fdt/gpiocharger.c   25 Sep 2021 14:42:16 -
@@ -0,0 +1,117 @@
+/* $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 

Re: new gpiocharger driver

2021-09-25 Thread Klemens Nanni
On Fri, Sep 24, 2021 at 10:35:56PM +, Klemens Nanni wrote:
> On Thu, Sep 16, 2021 at 11:07:20AM +0200, Mark Kettenis wrote:
> > > Date: Thu, 16 Sep 2021 06:14:39 +
> > > From: Klemens Nanni 
> > > 
> > > On 5 September 2021 01:22:53 GMT+05:00, Klemens Nanni  
> > > wrote:
> > > >Read a single GPIO pin indicating whether AC is plugged in or not.
> > > >
> > > >This gives me a sensor on my Pinebook Pro.
> > > >cwfg(4) already provides battery information but not the charger bits.
> > > >
> > > >apm(4) integration can follow separately.
> > > >
> > > >Feedback? OK?
> > > 
> > > Ping.
> > > The diff applies after the "new gpioleds driver" one.
> 
> New diff.  OK for after unlock modulo the gpioleds bits after being
> committed separately (CVS diffs juggling is annoying)?
> 
> > > >+gpios_len = OF_getproplen(node,
> > > >+gpios_property = "charger-status-gpios");
> > 
> > No, please don't hide assignment statements as function arguments.
> 
> Fixed, thanks.

Clean diff after gpioleds(4) got in, this time with the same whitespace
fixes.

Sorry for the noise.


Index: share/man/man4/gpiocharger.4
===
RCS file: share/man/man4/gpiocharger.4
diff -N share/man/man4/gpiocharger.4
--- /dev/null   1 Jan 1970 00:00:00 -
+++ share/man/man4/gpiocharger.425 Sep 2021 10:51:18 -
@@ -0,0 +1,51 @@
+.\"$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 04 2021 $
+.Dt GPIOCHARGER 4
+.Os
+.Sh NAME
+.Nm gpiocharger
+.Nd GPIO battery charger
+.Sh SYNOPSIS
+.Cd "gpiocharger* at fdt?"
+.Sh DESCRIPTION
+The
+.Nm
+driver provides support for battery chargers connected to GPIO pins.
+Currently, only power supply status events are supported.
+.Pp
+The power supply status (connected or disconnected) 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 .
Index: share/man/man4/Makefile
===
RCS file: /cvs/src/share/man/man4/Makefile,v
retrieving revision 1.807
diff -u -p -r1.807 Makefile
--- share/man/man4/Makefile 25 Sep 2021 10:43:23 -  1.807
+++ share/man/man4/Makefile 25 Sep 2021 10:51:18 -
@@ -35,7 +35,8 @@ MAN=  aac.4 abcrtc.4 abl.4 ac97.4 acphy.4
eso.4 ess.4 et.4 etherip.4 etphy.4 ex.4 exphy.4 exrtc.4 \
fanpwr.4 fd.4 fdc.4 fec.4 fido.4 fins.4 fintek.4 fms.4 fusbtc.4 \
fuse.4 fxp.4 \
-   gdt.4 gentbi.4 gem.4 gfrtc.4 gif.4 glenv.4 glkgpio.4 gpio.4 gpiodcf.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 \
hds.4 hiclock.4 hidwusb.4 hifn.4 hil.4 hilid.4 hilkbd.4 hilms.4 \
hireset.4 hitemp.4 hme.4 hotplug.4 hsq.4 \
Index: sys/dev/fdt/gpiocharger.c
===
RCS file: sys/dev/fdt/gpiocharger.c
diff -N sys/dev/fdt/gpiocharger.c
--- /dev/null   1 Jan 1970 00:00:00 -
+++ sys/dev/fdt/gpiocharger.c   25 Sep 2021 10:51:18 -
@@ -0,0 +1,117 @@
+/* $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.
+ */
+
+#include 
+#include 

Re: new gpiocharger driver

2021-09-24 Thread Klemens Nanni
On Thu, Sep 16, 2021 at 11:07:20AM +0200, Mark Kettenis wrote:
> > Date: Thu, 16 Sep 2021 06:14:39 +
> > From: Klemens Nanni 
> > 
> > On 5 September 2021 01:22:53 GMT+05:00, Klemens Nanni  
> > wrote:
> > >Read a single GPIO pin indicating whether AC is plugged in or not.
> > >
> > >This gives me a sensor on my Pinebook Pro.
> > >cwfg(4) already provides battery information but not the charger bits.
> > >
> > >apm(4) integration can follow separately.
> > >
> > >Feedback? OK?
> > 
> > Ping.
> > The diff applies after the "new gpioleds driver" one.

New diff.  OK for after unlock modulo the gpioleds bits after being
committed separately (CVS diffs juggling is annoying)?

> > >+  gpios_len = OF_getproplen(node,
> > >+  gpios_property = "charger-status-gpios");
> 
> No, please don't hide assignment statements as function arguments.

Fixed, thanks.

Index: share/man/man4/gpiocharger.4
===
RCS file: share/man/man4/gpiocharger.4
diff -N share/man/man4/gpiocharger.4
--- /dev/null   1 Jan 1970 00:00:00 -
+++ share/man/man4/gpiocharger.424 Sep 2021 22:33:26 -
@@ -0,0 +1,51 @@
+.\"$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 04 2021 $
+.Dt GPIOCHARGER 4
+.Os
+.Sh NAME
+.Nm gpiocharger
+.Nd GPIO battery charger
+.Sh SYNOPSIS
+.Cd "gpiocharger* at fdt?"
+.Sh DESCRIPTION
+The
+.Nm
+driver provides support for battery chargers connected to GPIO pins.
+Currently, only power supply status events are supported.
+.Pp
+The power supply status (connected or disconnected) 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 .
Index: share/man/man4/Makefile
===
RCS file: /cvs/src/share/man/man4/Makefile,v
retrieving revision 1.806
diff -u -p -r1.806 Makefile
--- share/man/man4/Makefile 4 Sep 2021 12:11:45 -   1.806
+++ share/man/man4/Makefile 24 Sep 2021 22:27:59 -
@@ -35,8 +35,9 @@ MAN=  aac.4 abcrtc.4 abl.4 ac97.4 acphy.4
eso.4 ess.4 et.4 etherip.4 etphy.4 ex.4 exphy.4 exrtc.4 \
fanpwr.4 fd.4 fdc.4 fec.4 fido.4 fins.4 fintek.4 fms.4 fusbtc.4 \
fuse.4 fxp.4 \
-   gdt.4 gentbi.4 gem.4 gfrtc.4 gif.4 glenv.4 glkgpio.4 gpio.4 gpiodcf.4 \
-   gpioiic.4 gpioow.4 graphaudio.4 gre.4 gscsio.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 \
hds.4 hiclock.4 hidwusb.4 hifn.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 \
Index: sys/dev/fdt/gpiocharger.c
===
RCS file: sys/dev/fdt/gpiocharger.c
diff -N sys/dev/fdt/gpiocharger.c
--- /dev/null   1 Jan 1970 00:00:00 -
+++ sys/dev/fdt/gpiocharger.c   24 Sep 2021 22:30:44 -
@@ -0,0 +1,117 @@
+/* $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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+struct 

Re: new gpiocharger driver

2021-09-16 Thread Mark Kettenis
> Date: Thu, 16 Sep 2021 06:14:39 +
> From: Klemens Nanni 
> 
> On 5 September 2021 01:22:53 GMT+05:00, Klemens Nanni  
> wrote:
> >Read a single GPIO pin indicating whether AC is plugged in or not.
> >
> >This gives me a sensor on my Pinebook Pro.
> >cwfg(4) already provides battery information but not the charger bits.
> >
> >apm(4) integration can follow separately.
> >
> >Feedback? OK?
> 
> Ping.
> The diff applies after the "new gpioleds driver" one.
> 
> >diff 4e7699b4cf65fba4bf837b202fb68ee0f66e6d07 refs/heads/master
> >blob - b92b1f60934ba60f92341ce94570d0ae96e78c1d
> >blob + 549a8316b874e4e5a6e1ede1640eeefadd9af0d4
> >--- distrib/sets/lists/man/mi
> >+++ distrib/sets/lists/man/mi
> >@@ -1417,6 +1417,7 @@
> > ./usr/share/man/man4/glenv.4
> > ./usr/share/man/man4/glkgpio.4
> > ./usr/share/man/man4/gpio.4
> >+./usr/share/man/man4/gpiocharger.4
> > ./usr/share/man/man4/gpiodcf.4
> > ./usr/share/man/man4/gpioiic.4
> > ./usr/share/man/man4/gpioleds.4
> >blob - bb62c44d32f152ecf64aa77d60a1a5a3454d3968
> >blob + a40cf91ec22f638f9c030aa7128d10bf75748305
> >--- share/man/man4/Makefile
> >+++ share/man/man4/Makefile
> >@@ -35,7 +35,8 @@ MAN=   aac.4 abcrtc.4 abl.4 ac97.4 acphy.4 acrtc.4 \
> > eso.4 ess.4 et.4 etherip.4 etphy.4 ex.4 exphy.4 exrtc.4 \
> > fanpwr.4 fd.4 fdc.4 fec.4 fido.4 fins.4 fintek.4 fms.4 fusbtc.4 \
> > fuse.4 fxp.4 \
> >-gdt.4 gentbi.4 gem.4 gfrtc.4 gif.4 glenv.4 glkgpio.4 gpio.4 gpiodcf.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 \
> > hds.4 hiclock.4 hidwusb.4 hifn.4 hil.4 hilid.4 hilkbd.4 hilms.4 \
> > hireset.4 hitemp.4 hme.4 hotplug.4 hsq.4 \
> >blob - /dev/null
> >blob + 12aa353d9367f57f07a89ae30dc3966c373032f8 (mode 644)
> >--- /dev/null
> >+++ share/man/man4/gpiocharger.4
> >@@ -0,0 +1,51 @@
> >+.\" $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 04 2021 $
> >+.Dt GPIOCHARGER 4
> >+.Os
> >+.Sh NAME
> >+.Nm gpiocharger
> >+.Nd GPIO battery charger
> >+.Sh SYNOPSIS
> >+.Cd "gpiocharger* at fdt?"
> >+.Sh DESCRIPTION
> >+The
> >+.Nm
> >+driver provides support for battery chargers connected to GPIO pins.
> >+Currently, only power supply status events are supported.
> >+.Pp
> >+The power supply status (connected or disconnected) 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.0 .
> >+.Sh AUTHORS
> >+.An -nosplit
> >+The
> >+.Nm
> >+driver was written by
> >+.An Klemens Nanni Aq Mt k...@openbsd.org .
> >blob - d3c3afb621f20013dc2475b4d87bd959e4127c9d
> >blob + b0702181cd2e510ef5267460dc71b68a8abd508a
> >--- sys/arch/arm64/conf/GENERIC
> >+++ sys/arch/arm64/conf/GENERIC
> >@@ -132,6 +132,7 @@ drm* at amdgpu?
> > wsdisplay*  at amdgpu?
> > 
> > gpioleds*   at fdt?
> >+gpiocharger*at fdt?
> > 
> > # Apple
> > apldart*at fdt?
> >blob - f749803b07408179ddc090d484ed4f79bfcb52a7
> >blob + f91263405dc183dd60e8ddc1fe69c5fbaf38b651
> >--- sys/dev/fdt/files.fdt
> >+++ sys/dev/fdt/files.fdt
> >@@ -592,3 +592,7 @@ file dev/fdt/dapmic.cdapmic
> > device  gpioleds
> > attach  gpioleds at fdt
> > filedev/fdt/gpioleds.c  gpioleds
> >+
> >+device  gpiocharger
> >+attach  gpiocharger at fdt
> >+filedev/fdt/gpiocharger.c   gpiocharger
> >blob - /dev/null
> >blob + dbf6bf50a13029438b9b7e969306c34640c5747e (mode 644)
> >--- /dev/null
> >+++ sys/dev/fdt/gpiocharger.c
> >@@ -0,0 +1,116 @@
> >+/*  $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 

Re: new gpiocharger driver

2021-09-16 Thread Klemens Nanni
On 5 September 2021 01:22:53 GMT+05:00, Klemens Nanni  wrote:
>Read a single GPIO pin indicating whether AC is plugged in or not.
>
>This gives me a sensor on my Pinebook Pro.
>cwfg(4) already provides battery information but not the charger bits.
>
>apm(4) integration can follow separately.
>
>Feedback? OK?

Ping.
The diff applies after the "new gpioleds driver" one.

>diff 4e7699b4cf65fba4bf837b202fb68ee0f66e6d07 refs/heads/master
>blob - b92b1f60934ba60f92341ce94570d0ae96e78c1d
>blob + 549a8316b874e4e5a6e1ede1640eeefadd9af0d4
>--- distrib/sets/lists/man/mi
>+++ distrib/sets/lists/man/mi
>@@ -1417,6 +1417,7 @@
> ./usr/share/man/man4/glenv.4
> ./usr/share/man/man4/glkgpio.4
> ./usr/share/man/man4/gpio.4
>+./usr/share/man/man4/gpiocharger.4
> ./usr/share/man/man4/gpiodcf.4
> ./usr/share/man/man4/gpioiic.4
> ./usr/share/man/man4/gpioleds.4
>blob - bb62c44d32f152ecf64aa77d60a1a5a3454d3968
>blob + a40cf91ec22f638f9c030aa7128d10bf75748305
>--- share/man/man4/Makefile
>+++ share/man/man4/Makefile
>@@ -35,7 +35,8 @@ MAN= aac.4 abcrtc.4 abl.4 ac97.4 acphy.4 acrtc.4 \
>   eso.4 ess.4 et.4 etherip.4 etphy.4 ex.4 exphy.4 exrtc.4 \
>   fanpwr.4 fd.4 fdc.4 fec.4 fido.4 fins.4 fintek.4 fms.4 fusbtc.4 \
>   fuse.4 fxp.4 \
>-  gdt.4 gentbi.4 gem.4 gfrtc.4 gif.4 glenv.4 glkgpio.4 gpio.4 gpiodcf.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 \
>   hds.4 hiclock.4 hidwusb.4 hifn.4 hil.4 hilid.4 hilkbd.4 hilms.4 \
>   hireset.4 hitemp.4 hme.4 hotplug.4 hsq.4 \
>blob - /dev/null
>blob + 12aa353d9367f57f07a89ae30dc3966c373032f8 (mode 644)
>--- /dev/null
>+++ share/man/man4/gpiocharger.4
>@@ -0,0 +1,51 @@
>+.\"   $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 04 2021 $
>+.Dt GPIOCHARGER 4
>+.Os
>+.Sh NAME
>+.Nm gpiocharger
>+.Nd GPIO battery charger
>+.Sh SYNOPSIS
>+.Cd "gpiocharger* at fdt?"
>+.Sh DESCRIPTION
>+The
>+.Nm
>+driver provides support for battery chargers connected to GPIO pins.
>+Currently, only power supply status events are supported.
>+.Pp
>+The power supply status (connected or disconnected) 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.0 .
>+.Sh AUTHORS
>+.An -nosplit
>+The
>+.Nm
>+driver was written by
>+.An Klemens Nanni Aq Mt k...@openbsd.org .
>blob - d3c3afb621f20013dc2475b4d87bd959e4127c9d
>blob + b0702181cd2e510ef5267460dc71b68a8abd508a
>--- sys/arch/arm64/conf/GENERIC
>+++ sys/arch/arm64/conf/GENERIC
>@@ -132,6 +132,7 @@ drm*   at amdgpu?
> wsdisplay*at amdgpu?
> 
> gpioleds* at fdt?
>+gpiocharger*  at fdt?
> 
> # Apple
> apldart*  at fdt?
>blob - f749803b07408179ddc090d484ed4f79bfcb52a7
>blob + f91263405dc183dd60e8ddc1fe69c5fbaf38b651
>--- sys/dev/fdt/files.fdt
>+++ sys/dev/fdt/files.fdt
>@@ -592,3 +592,7 @@ file   dev/fdt/dapmic.cdapmic
> devicegpioleds
> attachgpioleds at fdt
> file  dev/fdt/gpioleds.c  gpioleds
>+
>+devicegpiocharger
>+attachgpiocharger at fdt
>+file  dev/fdt/gpiocharger.c   gpiocharger
>blob - /dev/null
>blob + dbf6bf50a13029438b9b7e969306c34640c5747e (mode 644)
>--- /dev/null
>+++ sys/dev/fdt/gpiocharger.c
>@@ -0,0 +1,116 @@
>+/*$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 

new gpiocharger driver

2021-09-04 Thread Klemens Nanni
Read a single GPIO pin indicating whether AC is plugged in or not.

This gives me a sensor on my Pinebook Pro.
cwfg(4) already provides battery information but not the charger bits.

apm(4) integration can follow separately.

Feedback? OK?


diff 4e7699b4cf65fba4bf837b202fb68ee0f66e6d07 refs/heads/master
blob - b92b1f60934ba60f92341ce94570d0ae96e78c1d
blob + 549a8316b874e4e5a6e1ede1640eeefadd9af0d4
--- distrib/sets/lists/man/mi
+++ distrib/sets/lists/man/mi
@@ -1417,6 +1417,7 @@
 ./usr/share/man/man4/glenv.4
 ./usr/share/man/man4/glkgpio.4
 ./usr/share/man/man4/gpio.4
+./usr/share/man/man4/gpiocharger.4
 ./usr/share/man/man4/gpiodcf.4
 ./usr/share/man/man4/gpioiic.4
 ./usr/share/man/man4/gpioleds.4
blob - bb62c44d32f152ecf64aa77d60a1a5a3454d3968
blob + a40cf91ec22f638f9c030aa7128d10bf75748305
--- share/man/man4/Makefile
+++ share/man/man4/Makefile
@@ -35,7 +35,8 @@ MAN=  aac.4 abcrtc.4 abl.4 ac97.4 acphy.4 acrtc.4 \
eso.4 ess.4 et.4 etherip.4 etphy.4 ex.4 exphy.4 exrtc.4 \
fanpwr.4 fd.4 fdc.4 fec.4 fido.4 fins.4 fintek.4 fms.4 fusbtc.4 \
fuse.4 fxp.4 \
-   gdt.4 gentbi.4 gem.4 gfrtc.4 gif.4 glenv.4 glkgpio.4 gpio.4 gpiodcf.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 \
hds.4 hiclock.4 hidwusb.4 hifn.4 hil.4 hilid.4 hilkbd.4 hilms.4 \
hireset.4 hitemp.4 hme.4 hotplug.4 hsq.4 \
blob - /dev/null
blob + 12aa353d9367f57f07a89ae30dc3966c373032f8 (mode 644)
--- /dev/null
+++ share/man/man4/gpiocharger.4
@@ -0,0 +1,51 @@
+.\"$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 04 2021 $
+.Dt GPIOCHARGER 4
+.Os
+.Sh NAME
+.Nm gpiocharger
+.Nd GPIO battery charger
+.Sh SYNOPSIS
+.Cd "gpiocharger* at fdt?"
+.Sh DESCRIPTION
+The
+.Nm
+driver provides support for battery chargers connected to GPIO pins.
+Currently, only power supply status events are supported.
+.Pp
+The power supply status (connected or disconnected) 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.0 .
+.Sh AUTHORS
+.An -nosplit
+The
+.Nm
+driver was written by
+.An Klemens Nanni Aq Mt k...@openbsd.org .
blob - d3c3afb621f20013dc2475b4d87bd959e4127c9d
blob + b0702181cd2e510ef5267460dc71b68a8abd508a
--- sys/arch/arm64/conf/GENERIC
+++ sys/arch/arm64/conf/GENERIC
@@ -132,6 +132,7 @@ drm*at amdgpu?
 wsdisplay* at amdgpu?
 
 gpioleds*  at fdt?
+gpiocharger*   at fdt?
 
 # Apple
 apldart*   at fdt?
blob - f749803b07408179ddc090d484ed4f79bfcb52a7
blob + f91263405dc183dd60e8ddc1fe69c5fbaf38b651
--- sys/dev/fdt/files.fdt
+++ sys/dev/fdt/files.fdt
@@ -592,3 +592,7 @@ filedev/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
blob - /dev/null
blob + dbf6bf50a13029438b9b7e969306c34640c5747e (mode 644)
--- /dev/null
+++ sys/dev/fdt/gpiocharger.c
@@ -0,0 +1,116 @@
+/* $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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+struct gpiocharger_softc {
+