Re: mfokclock(4) -> mfokrtc(4): loongson's hugging arm

2020-09-29 Thread Theo de Raadt
Patrick Wildt  wrote:

> On Tue, Sep 29, 2020 at 11:23:03AM -0600, Theo de Raadt wrote:
> > +   if (strcmp(ia->ia_name, "st,m41t83") == 0)
> > 
> > fine with me.  But in that case, why not call the driver i2c/m41t83.c
> 
> Because it's a series of chips, like m41t80, m41t81, m41t82.  Machines
> and their device trees encode the specific chip, because some versions
> might have a different feature set as others.  We do the same x-place-
> holder-notation for other drivers as well.
> 
> For now I only match on st,m41t83 since that is the version of the chip
> the driver was originally written for.  For every additional supported
> variant of that series, the code needs to be checked for correctness.
> 
> But the file is still supposed to cover more than this one specific
> variant of the series.

If it supports many chips, why are you only matching for one variation?
To save code bytes, I guess.  But later on, will there be any variation
handling in the driver?  Not having checked the vendor docs, I suspect
they are highly compatible.  In chips like this, the variation tends
to be electronics, or power connectivity or such, rather than register
or behaviour layout.

The other way this works, is the new chip has a very similar number
but totally different behaviour.

Which is it?



Re: mfokclock(4) -> mfokrtc(4): loongson's hugging arm

2020-09-29 Thread Patrick Wildt
On Tue, Sep 29, 2020 at 11:23:03AM -0600, Theo de Raadt wrote:
> +   if (strcmp(ia->ia_name, "st,m41t83") == 0)
> 
> fine with me.  But in that case, why not call the driver i2c/m41t83.c

Because it's a series of chips, like m41t80, m41t81, m41t82.  Machines
and their device trees encode the specific chip, because some versions
might have a different feature set as others.  We do the same x-place-
holder-notation for other drivers as well.

For now I only match on st,m41t83 since that is the version of the chip
the driver was originally written for.  For every additional supported
variant of that series, the code needs to be checked for correctness.

But the file is still supposed to cover more than this one specific
variant of the series.



Re: mfokclock(4) -> mfokrtc(4): loongson's hugging arm

2020-09-29 Thread Theo de Raadt
+   if (strcmp(ia->ia_name, "st,m41t83") == 0)

fine with me.  But in that case, why not call the driver i2c/m41t83.c



mfokclock(4) -> mfokrtc(4): loongson's hugging arm

2020-09-29 Thread Patrick Wildt
Hi,

some arm64 that I'd like to use as replacement server for the one that's
crashing all the time (probably HW-related) has a Microcrystal RV4162
RTC.  As it turns out, this is about the same as the ST M41T8x series.

For that one we already have mfokclock(4), but only for loongson.  After
talking to kettenis@, we think that first of all sys/arch/loongson/dev/
m41t8xclock.c should be moved to sys/dev/i2c/m41t8x.c so that the file
can be re-used by multiple architectures.  And usually we don't have the
type of device in the filename, so I removed that as well.

Usually we reserve clock for clock control subsystems, while we call
RTCs as they are.  That's why I renamed mfokclock(4) to mfokrtc(4),
and also renamed the code accordingly.

Instead of matching on the driver's name, let's match on st,m41t83, as
when the driver was imported that specific chip was the reason for the
driver.  This also means changing the iic controller to pass a different
string.

Can someone make sure this still works on their loongson devices?  Are
there any objections to this?

Thank you,
Patrick

diff --git a/share/man/man4/Makefile b/share/man/man4/Makefile
index 4a3df6b33b1..8ba306f41ed 100644
--- a/share/man/man4/Makefile
+++ b/share/man/man4/Makefile
@@ -47,8 +47,8 @@ MAN=  aac.4 abcrtc.4 abl.4 ac97.4 acphy.4 acrtc.4 \
kate.4 kcov.4 km.4 ksmn.4 ksyms.4 kubsan.4 kue.4 lc.4 lge.4 lii.4 \
lisa.4 lm.4 lmenv.4 lmn.4 lmtemp.4 lo.4 lpt.4 lxtphy.4 luphy.4 \
maestro.4 mainbus.4 malo.4 maxds.4 maxrtc.4 maxtmp.4 mbg.4 \
-   mcprtc.4 mcx.4 midi.4 mii.4 mfi.4 \
-   mfii.4 mlphy.4 moscom.4 mos.4 mpe.4 mpath.4 mpi.4 mpii.4 \
+   mcprtc.4 mcx.4 midi.4 mii.4 mfi.4 mfii.4 mfokrtc.4 \
+   mlphy.4 moscom.4 mos.4 mpe.4 mpath.4 mpi.4 mpii.4 \
mpip.4 mpu.4 msk.4 mpw.4 msts.4 mtd.4 mtdphy.4 mtio.4 mue.4 \
multicast.4 mvclock.4 mvdog.4 mvgicp.4 mvgpio.4 mvicu.4 mviic.4 \
mvneta.4 mvpinctrl.4 mvpp.4 mvrng.4 mvrtc.4 mvspi.4 mvtemp.4 mvuart.4 \
diff --git a/share/man/man4/man4.loongson/Makefile 
b/share/man/man4/man4.loongson/Makefile
index 6e133c04f62..b3d5b061c84 100644
--- a/share/man/man4/man4.loongson/Makefile
+++ b/share/man/man4/man4.loongson/Makefile
@@ -1,7 +1,7 @@
 #  $OpenBSD: Makefile,v 1.10 2016/11/17 15:06:16 visa Exp $
 
 MAN=   apm.4 autoconf.4 bonito.4 gdiumiic.4 glxclk.4 glxpcib.4 htb.4 intro.4 \
-   leioc.4 mem.4 mfokclock.4 sisfb.4 smfb.4 stsec.4 voyager.4 ykbec.4
+   leioc.4 mem.4 sisfb.4 smfb.4 stsec.4 voyager.4 ykbec.4
 MANSUBDIR=loongson
 
 .include 
diff --git a/share/man/man4/man4.loongson/mfokclock.4 
b/share/man/man4/man4.loongson/mfokclock.4
deleted file mode 100644
index 69d122dfdf2..000
--- a/share/man/man4/man4.loongson/mfokclock.4
+++ /dev/null
@@ -1,31 +0,0 @@
-.\"$OpenBSD: mfokclock.4,v 1.2 2018/06/18 06:06:52 jmc Exp $
-.\"
-.\" Copyright (c) 2010 Miodrag Vallat.
-.\"
-.\" 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: June 18 2018 $
-.Dt MFOKCLOCK 4 loongson
-.Os
-.Sh NAME
-.Nm mfokclock
-.Nd M41T8x real-time clock
-.Sh SYNOPSIS
-.Cd "mfokclock* at iic? addr 0x68"
-.Sh DESCRIPTION
-The
-.Nm
-driver supports two-wire real-time clock chips of the M41T8x family.
-.Sh SEE ALSO
-.Xr iic 4 ,
-.Xr intro 4
diff --git a/share/man/man4/mfokrtc.4 b/share/man/man4/mfokrtc.4
new file mode 100644
index 000..487591817ec
--- /dev/null
+++ b/share/man/man4/mfokrtc.4
@@ -0,0 +1,31 @@
+.\"$OpenBSD: mfokclock.4,v 1.2 2018/06/18 06:06:52 jmc Exp $
+.\"
+.\" Copyright (c) 2010 Miodrag Vallat.
+.\"
+.\" 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.