Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/i2c Eliminate all of the #ifdefs for the "strtc" dri...



details:   https://anonhg.NetBSD.org/src/rev/6be754c465d1
branches:  trunk
changeset: 968125:6be754c465d1
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Fri Jan 03 03:44:42 2020 +0000

description:
Eliminate all of the #ifdefs for the "strtc" driver.  Define model
properties (similar to what the "dsrtc" driver does), and provide
DT compat strings corresponding to those models.  Allow config flags
to specify the model for non-FDT platforms (also like "dsrtc").

diffstat:

 sys/arch/evbarm/conf/DNS323     |    4 +-
 sys/arch/evbarm/conf/IQ31244    |    4 +-
 sys/arch/evbmips/conf/GDIUM     |    7 +-
 sys/arch/evbmips/conf/LOONGSON  |    7 +-
 sys/arch/sandpoint/conf/GENERIC |    8 +-
 sys/arch/sandpoint/conf/KUROBOX |    4 +-
 sys/dev/i2c/files.i2c           |    4 +-
 sys/dev/i2c/m41st84.c           |  124 ++++++++++++++++++++++++++++++++-------
 8 files changed, 114 insertions(+), 48 deletions(-)

diffs (truncated from 400 to 300 lines):

diff -r cf77c314bf84 -r 6be754c465d1 sys/arch/evbarm/conf/DNS323
--- a/sys/arch/evbarm/conf/DNS323       Fri Jan 03 01:24:48 2020 +0000
+++ b/sys/arch/evbarm/conf/DNS323       Fri Jan 03 03:44:42 2020 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: DNS323,v 1.12 2018/07/12 10:46:43 maxv Exp $
+#      $NetBSD: DNS323,v 1.13 2020/01/03 03:44:42 thorpej Exp $
 #
 #  DNS323 -- D-Link. DNS-323 platform kernel
 #
@@ -32,5 +32,3 @@
 g760a* at iic? addr 0x3e               # G760a fan speed controller
 lmtemp*        at iic? addr 0x48               # LM75 temperature sensor
 strtc* at iic? addr 0x68               # ST M41T80 Real-Time Clock
-options        STRTC_NO_USERRAM
-options        STRTC_NO_WATCHDOG
diff -r cf77c314bf84 -r 6be754c465d1 sys/arch/evbarm/conf/IQ31244
--- a/sys/arch/evbarm/conf/IQ31244      Fri Jan 03 01:24:48 2020 +0000
+++ b/sys/arch/evbarm/conf/IQ31244      Fri Jan 03 03:44:42 2020 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: IQ31244,v 1.74 2018/07/12 10:46:43 maxv Exp $
+#      $NetBSD: IQ31244,v 1.75 2020/01/03 03:44:42 thorpej Exp $
 #
 #      IQ31244 -- Intel IQ31244 Evaluation Board Kernel
 #
@@ -151,7 +151,7 @@
 lmtemp1        at iic0 addr 0x49       # LM75 temperature sensor
 
 # RTC
-strtc0         at iic0 addr 0x68       # M41ST84 RTC & watchdog
+strtc0         at iic0 addr 0x68 flags 84 # M41ST84 RTC & watchdog
 
 # PCI-PCI bridges
 ppb*           at pci? dev ? function ?
diff -r cf77c314bf84 -r 6be754c465d1 sys/arch/evbmips/conf/GDIUM
--- a/sys/arch/evbmips/conf/GDIUM       Fri Jan 03 01:24:48 2020 +0000
+++ b/sys/arch/evbmips/conf/GDIUM       Fri Jan 03 03:44:42 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: GDIUM,v 1.36 2019/04/26 21:40:29 sevan Exp $
+# $NetBSD: GDIUM,v 1.37 2020/01/03 03:44:42 thorpej Exp $
 #
 # GDIUM machine description file
 # 
@@ -22,7 +22,7 @@
 
 options        INCLUDE_CONFIG_FILE     # embed config file in kernel binary
 
-#ident                 "GDIUM-$Revision: 1.36 $"
+#ident                 "GDIUM-$Revision: 1.37 $"
 
 maxusers       16
 
@@ -149,8 +149,7 @@
 voyager0       at pci0 dev ? function ?
 voyagerfb0     at voyager0
 iic*           at voyager0
-strtc* at iic? addr 0x68
-options        STRTC_NO_USERRAM
+strtc* at iic? addr 0x68                       # ST M41T80/81?
 lmtemp*        at iic? addr 0x48
 #stvii*        at iic? addr 0x40
 #genfb0                at pci0 dev ? function ?
diff -r cf77c314bf84 -r 6be754c465d1 sys/arch/evbmips/conf/LOONGSON
--- a/sys/arch/evbmips/conf/LOONGSON    Fri Jan 03 01:24:48 2020 +0000
+++ b/sys/arch/evbmips/conf/LOONGSON    Fri Jan 03 03:44:42 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: LOONGSON,v 1.42 2019/04/26 21:40:29 sevan Exp $
+# $NetBSD: LOONGSON,v 1.43 2020/01/03 03:44:42 thorpej Exp $
 #
 # LOONGSON machine description file
 # 
@@ -22,7 +22,7 @@
 
 options        INCLUDE_CONFIG_FILE     # embed config file in kernel binary
 
-#ident                 "LOONGSON-$Revision: 1.42 $"
+#ident                 "LOONGSON-$Revision: 1.43 $"
 
 maxusers       16
 
@@ -165,8 +165,7 @@
 voyagerfb0     at voyager0                     # framebuffer portion
 pwmclock0      at voyager0                     # clock and CPU freq scaling
 iic*           at voyager0
-strtc*         at iic? addr 0x68               # GDIUM's real time clock
-options        STRTC_NO_USERRAM
+strtc*         at iic? addr 0x68               # GDIUM's real time clock (M41T80/81 ?)
 lmtemp*                at iic? addr 0x48               # GDIUM's temperature sensor
 stvii*         at iic? addr 0x40               # GDIUM's onboard microcontroller
 lynxfb0                at pci0 dev ? function ?        # SM712 on Yeeloong Notebook
diff -r cf77c314bf84 -r 6be754c465d1 sys/arch/sandpoint/conf/GENERIC
--- a/sys/arch/sandpoint/conf/GENERIC   Fri Jan 03 01:24:48 2020 +0000
+++ b/sys/arch/sandpoint/conf/GENERIC   Fri Jan 03 03:44:42 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.102 2019/04/26 21:40:32 sevan Exp $
+# $NetBSD: GENERIC,v 1.103 2020/01/03 03:44:42 thorpej Exp $
 #
 # machine description file for GENERIC NAS
 # 
@@ -22,7 +22,7 @@
 
 options        INCLUDE_CONFIG_FILE     # embed config file in kernel binary
 
-#ident                 "GENERIC-$Revision: 1.102 $"
+#ident                 "GENERIC-$Revision: 1.103 $"
 
 maxusers       32
 
@@ -176,9 +176,7 @@
 s390rtc*       at iic? addr 0x30
 pcf8563rtc*    at iic? addr 0x51
 dsrtc*         at iic? addr 0x68
-strtc*         at iic? addr 0x68
-options        STRTC_NO_WATCHDOG
-options        STRTC_NO_USERRAM
+strtc*         at iic? addr 0x68               # ST M41T80 (or compat) RTC
 
 # PCI IDE controllers - see pciide(4) for supported hardware.
 acardide*      at pci? dev ? function ?        # Acard IDE controllers
diff -r cf77c314bf84 -r 6be754c465d1 sys/arch/sandpoint/conf/KUROBOX
--- a/sys/arch/sandpoint/conf/KUROBOX   Fri Jan 03 01:24:48 2020 +0000
+++ b/sys/arch/sandpoint/conf/KUROBOX   Fri Jan 03 03:44:42 2020 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: KUROBOX,v 1.7 2015/09/21 23:34:21 phx Exp $
+#      $NetBSD: KUROBOX,v 1.8 2020/01/03 03:44:42 thorpej Exp $
 #
 # KuroBox/LinkStation support
 #
@@ -18,8 +18,6 @@
 no pcf8563rtc*
 no dsrtc*
 no strtc*
-no options     STRTC_NO_WATCHDOG
-no options     STRTC_NO_USERRAM
 
 no acardide*
 no viaide* 
diff -r cf77c314bf84 -r 6be754c465d1 sys/dev/i2c/files.i2c
--- a/sys/dev/i2c/files.i2c     Fri Jan 03 01:24:48 2020 +0000
+++ b/sys/dev/i2c/files.i2c     Fri Jan 03 03:44:42 2020 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.i2c,v 1.105 2020/01/02 22:06:59 jmcneill Exp $
+#      $NetBSD: files.i2c,v 1.106 2020/01/03 03:44:42 thorpej Exp $
 
 obsolete defflag       opt_i2cbus.h            I2C_SCAN
 define i2cbus { }
@@ -70,8 +70,6 @@
 device strtc
 attach strtc at iic
 file   dev/i2c/m41st84.c                       strtc
-defflag        opt_strtc.h                             STRTC_NO_USERRAM
-                                               STRTC_NO_WATCHDOG
 
 # MAX6900 Real Time Clock
 device maxrtc
diff -r cf77c314bf84 -r 6be754c465d1 sys/dev/i2c/m41st84.c
--- a/sys/dev/i2c/m41st84.c     Fri Jan 03 01:24:48 2020 +0000
+++ b/sys/dev/i2c/m41st84.c     Fri Jan 03 03:44:42 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: m41st84.c,v 1.26 2020/01/02 19:24:48 thorpej Exp $     */
+/*     $NetBSD: m41st84.c,v 1.27 2020/01/03 03:44:42 thorpej Exp $     */
 
 /*
  * Copyright (c) 2003 Wasabi Systems, Inc.
@@ -36,9 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: m41st84.c,v 1.26 2020/01/02 19:24:48 thorpej Exp $");
-
-#include "opt_strtc.h"
+__KERNEL_RCSID(0, "$NetBSD: m41st84.c,v 1.27 2020/01/03 03:44:42 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -57,11 +55,44 @@
 
 #include "ioconf.h"
 
+struct strtc_model {
+       uint16_t        sm_model;
+       uint8_t         sm_nvram_start;
+       uint8_t         sm_nvram_size;
+       uint32_t        sm_flags;
+};
+
+#define        STRTC_F_HAS_WDOG        __BIT(0)
+
+static const struct strtc_model m41t80_model = {
+       .sm_model =             80,
+};
+
+static const struct strtc_model m41t81_model = {
+       .sm_model =             81,
+       .sm_flags =             STRTC_F_HAS_WDOG,
+};
+
+static const struct strtc_model m48t84_model = {
+       .sm_model =             84,
+       .sm_nvram_start =       M41ST84_USER_RAM,
+       .sm_nvram_size =        M41ST84_USER_RAM_SIZE,
+       .sm_flags =             STRTC_F_HAS_WDOG,
+};
+
+static const struct device_compatible_entry compat_data[] = {
+       { "st,m41t80",          (uintptr_t)&m41t80_model },
+       { "st,m41t81",          (uintptr_t)&m41t81_model },
+       { "st,m41t84",          (uintptr_t)&m48t84_model },
+       { NULL,                 0 },
+};
+
 struct strtc_softc {
        device_t sc_dev;
        i2c_tag_t sc_tag;
        int sc_address;
        int sc_open;
+       const struct strtc_model *sc_model;
        struct todr_chip_handle sc_todr;
 };
 
@@ -71,7 +102,6 @@
 CFATTACH_DECL_NEW(strtc, sizeof(struct strtc_softc),
     strtc_match, strtc_attach, NULL, NULL);
 
-#ifndef STRTC_NO_USERRAM
 dev_type_open(strtc_open);
 dev_type_close(strtc_close);
 dev_type_read(strtc_read);
@@ -91,7 +121,6 @@
        .d_discard = nodiscard,
        .d_flag = D_OTHER
 };
-#endif
 
 static int strtc_clock_read(struct strtc_softc *sc, struct clock_ymdhms *);
 static int strtc_gettime_ymdhms(struct todr_chip_handle *,
@@ -99,15 +128,48 @@
 static int strtc_settime_ymdhms(struct todr_chip_handle *,
                                struct clock_ymdhms *);
 
+static const struct strtc_model *
+strtc_model_by_number(u_int model)
+{
+       const struct device_compatible_entry *dce;
+       const struct strtc_model *sm;
+
+       /* no model given; assume it's a 41T80 */
+       if (model == 0)
+               return &m41t80_model;
+       
+       for (dce = compat_data; dce->compat != NULL; dce++) {
+               sm = (void *)dce->data;
+               if (sm->sm_model == model)
+                       return sm;
+       }
+       return NULL;
+}
+
+static const struct strtc_model *
+strtc_model_by_compat(const struct i2c_attach_args *ia)
+{
+       const struct device_compatible_entry *dce;
+       const struct strtc_model *sm = NULL;
+
+       if (iic_compatible_match(ia, compat_data, &dce))
+               sm = (void *)dce->data;
+       
+       return sm;
+}
+
 static int
 strtc_match(device_t parent, cfdata_t cf, void *arg)
 {
        struct i2c_attach_args *ia = arg;
        int match_result;
 
-       if (iic_use_direct_match(ia, cf, NULL, &match_result))
+       if (iic_use_direct_match(ia, cf, compat_data, &match_result))
                return match_result;
 
+       if (strtc_model_by_number(cf->cf_flags & 0xffff) == NULL)
+               return 0;
+
        /* indirect config - check typical address */
        if (ia->ia_addr == M41ST84_ADDR)
                return I2C_MATCH_ADDRESS_ONLY;
@@ -120,16 +182,24 @@
 {
        struct strtc_softc *sc = device_private(self);
        struct i2c_attach_args *ia = arg;
+       const struct strtc_model *sm;
 
-#ifndef STRTC_NO_USERRAM
-       aprint_naive(": Real-time Clock/NVRAM\n");
-       aprint_normal(": M41ST84 Real-time Clock/NVRAM\n");
-#else
-       aprint_naive(": Real-time Clock\n");
-       aprint_normal(": M41T8x Real-time Clock\n");
-#endif
+       if ((sm = strtc_model_by_compat(ia)) == NULL)
+               sm = strtc_model_by_number(device_cfdata(self)->cf_flags);



Home | Main Index | Thread Index | Old Index