Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/sandpoint/sandpoint Now more than a single I2C devi...



details:   https://anonhg.NetBSD.org/src/rev/432d58cbc6f6
branches:  trunk
changeset: 340778:432d58cbc6f6
user:      phx <phx%NetBSD.org@localhost>
date:      Wed Sep 30 14:18:54 2015 +0000

description:
Now more than a single I2C device per model may be configured directly.
An additional flags argument makes the configuration depend on the model-
flags in an optional BTINFO_MODEL bootinfo node.
Print the model name together with the vendor name, when known.

diffstat:

 sys/arch/sandpoint/sandpoint/autoconf.c |  69 +++++++++++++++++++++-----------
 sys/arch/sandpoint/sandpoint/machdep.c  |  20 +++++++--
 2 files changed, 60 insertions(+), 29 deletions(-)

diffs (165 lines):

diff -r 627daebd45a4 -r 432d58cbc6f6 sys/arch/sandpoint/sandpoint/autoconf.c
--- a/sys/arch/sandpoint/sandpoint/autoconf.c   Wed Sep 30 14:14:32 2015 +0000
+++ b/sys/arch/sandpoint/sandpoint/autoconf.c   Wed Sep 30 14:18:54 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: autoconf.c,v 1.27 2012/07/29 18:05:45 mlelstv Exp $    */
+/*     $NetBSD: autoconf.c,v 1.28 2015/09/30 14:18:54 phx Exp $        */
 
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.27 2012/07/29 18:05:45 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.28 2015/09/30 14:18:54 phx Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -55,21 +55,30 @@
 static struct btinfo_bootpath *bi_path;
 static struct btinfo_net *bi_net;
 static struct btinfo_prodfamily *bi_pfam;
+static struct btinfo_model *bi_model;
 
-struct i2cdev {
-       const char *family;
-       const char *name;
-       int addr;
+struct i2c_dev {
+       const char      *name;
+       unsigned        addr;
+       /* only attach when one of these bits in the model flags is set */
+       uint32_t        model_mask;
 };
 
-static struct i2cdev rtcmodel[] = {
-    { "dlink",    "strtc",      0x68 },
-    { "iomega",   "dsrtc",      0x68 },
-    { "kurobox",  "rs5c372rtc", 0x32 },
-    { "kurot4",   "rs5c372rtc", 0x32 },
-    { "nhnas",    "pcf8563rtc", 0x51 },
-    { "qnap",     "s390rtc",    0x30 },
-    { "synology", "rs5c372rtc", 0x32 },
+#define MAXI2CDEVS     4
+struct model_i2c {
+       const char      *family;
+       struct i2c_dev  i2c_devs[MAXI2CDEVS];
+};
+
+static struct model_i2c model_i2c_list[] = {
+       { "dlink",      {       { "strtc",      0x68, 0 } } },
+       { "iomega",     {       { "dsrtc",      0x68, 0 } } },
+       { "kurobox",    {       { "rs5c372rtc", 0x32, 0 } } },
+       { "kurot4",     {       { "rs5c372rtc", 0x32, 0 } } },
+       { "nhnas",      {       { "pcf8563rtc", 0x51, 0 } } },
+       { "qnap",       {       { "s390rtc",    0x30, 0 } } },
+       { "synology",   {       { "rs5c372rtc", 0x32, 0 },
+                               { "lmtemp",     0x48, BI_MODEL_THERMAL } } },
 };
 
 static void add_i2c_child_devices(device_t, const char *);
@@ -85,6 +94,7 @@
        bi_path = lookup_bootinfo(BTINFO_BOOTPATH);
        bi_net = lookup_bootinfo(BTINFO_NET);
        bi_pfam = lookup_bootinfo(BTINFO_PRODFAMILY);
+       bi_model = lookup_bootinfo(BTINFO_MODEL);
 
        if (config_rootfound("mainbus", NULL) == NULL)
                panic("configure: mainbus not configured");
@@ -167,27 +177,38 @@
 static void
 add_i2c_child_devices(device_t self, const char *family)
 {
-       struct i2cdev *rtc;
+       struct i2c_dev *model_i2c_devs;
        prop_dictionary_t pd;
        prop_array_t pa;
        int i;
 
-       rtc = NULL;
-       for (i = 0; i < (int)(sizeof(rtcmodel)/sizeof(rtcmodel[0])); i++) {
-               if (strcmp(family, rtcmodel[i].family) == 0) {
-                       rtc = &rtcmodel[i];
+       for (i = 0;
+           i < (int)(sizeof(model_i2c_list) / sizeof(model_i2c_list[0]));
+           i++) {
+               if (strcmp(family, model_i2c_list[i].family) == 0) {
+                       model_i2c_devs = model_i2c_list[i].i2c_devs;
                        goto found;
                }
        }
        return;
 
  found:
-       pd = prop_dictionary_create();
+       /* make an i2c-child-devices property list with for direct config. */
        pa = prop_array_create();
-       prop_dictionary_set_cstring_nocopy(pd, "name", rtc->name);
-       prop_dictionary_set_uint32(pd, "addr", rtc->addr);
-       prop_array_add(pa, pd);
+
+       for (i = 0; i < MAXI2CDEVS && model_i2c_devs[i].name != NULL; i++) {
+               if (model_i2c_devs[i].model_mask != 0 &&
+                   !(bi_model->flags & model_i2c_devs[i].model_mask))
+                       continue;
+               pd = prop_dictionary_create();
+               prop_dictionary_set_cstring_nocopy(pd, "name",
+                   model_i2c_devs[i].name);
+               prop_dictionary_set_uint32(pd, "addr",
+                   model_i2c_devs[i].addr);
+               prop_array_add(pa, pd);
+               prop_object_release(pd);
+       }
+
        prop_dictionary_set(device_properties(self), "i2c-child-devices", pa);
-       prop_object_release(pd);
        prop_object_release(pa);
 }
diff -r 627daebd45a4 -r 432d58cbc6f6 sys/arch/sandpoint/sandpoint/machdep.c
--- a/sys/arch/sandpoint/sandpoint/machdep.c    Wed Sep 30 14:14:32 2015 +0000
+++ b/sys/arch/sandpoint/sandpoint/machdep.c    Wed Sep 30 14:18:54 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: machdep.c,v 1.64 2015/09/07 23:00:08 phx Exp $ */
+/*     $NetBSD: machdep.c,v 1.65 2015/09/30 14:18:54 phx Exp $ */
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.64 2015/09/07 23:00:08 phx Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.65 2015/09/30 14:18:54 phx Exp $");
 
 #include "opt_compat_netbsd.h"
 #include "opt_ddb.h"
@@ -231,15 +231,25 @@
 void
 cpu_startup(void)
 {
-       struct btinfo_prodfamily *bi_prod;
+       struct btinfo_prodfamily *bi_fam;
+       struct btinfo_model *bi_model;
+       char prod_name[32];
+       char *model;
        void *baseaddr;
        int msr;
 
        /*
         * Do common startup.
         */
-       bi_prod = lookup_bootinfo(BTINFO_PRODFAMILY);
-       oea_startup(bi_prod != NULL ? bi_prod->name : NULL);
+       bi_fam = lookup_bootinfo(BTINFO_PRODFAMILY);
+       bi_model = lookup_bootinfo(BTINFO_MODEL);
+       if (bi_fam != NULL) {
+               snprintf(prod_name, sizeof(prod_name), "%s %s", bi_fam->name,
+                   bi_model != NULL ? bi_model->name : "");
+               model = prod_name;
+       } else
+               model = NULL;
+       oea_startup(model);
 
        /*
         * Prepare EPIC and install external interrupt handler.



Home | Main Index | Thread Index | Old Index