Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/sparc64 Move E250 and E450 i2c patches from dev/pcf...



details:   https://anonhg.NetBSD.org/src/rev/d62cdb4c6559
branches:  trunk
changeset: 956165:d62cdb4c6559
user:      jdc <jdc%NetBSD.org@localhost>
date:      Fri Oct 23 15:18:10 2020 +0000

description:
Move E250 and E450 i2c patches from dev/pcfiic_ebus.c to sparc64/ofw_patch.c.
They are now co-located with the other OFW patch routines.
New i2c devices are created for E250/E450 and v210/v240, so create new
functions to avoid duplicate code.

diffstat:

 sys/arch/sparc64/dev/pcfiic_ebus.c   |   76 ++--------------------
 sys/arch/sparc64/sparc64/autoconf.c  |   14 +++-
 sys/arch/sparc64/sparc64/ofw_patch.c |  117 ++++++++++++++++++++++++----------
 sys/arch/sparc64/sparc64/ofw_patch.h |    4 +-
 4 files changed, 106 insertions(+), 105 deletions(-)

diffs (truncated from 312 to 300 lines):

diff -r 806900a27ed8 -r d62cdb4c6559 sys/arch/sparc64/dev/pcfiic_ebus.c
--- a/sys/arch/sparc64/dev/pcfiic_ebus.c        Fri Oct 23 14:48:49 2020 +0000
+++ b/sys/arch/sparc64/dev/pcfiic_ebus.c        Fri Oct 23 15:18:10 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pcfiic_ebus.c,v 1.6 2020/06/12 03:41:57 thorpej Exp $  */
+/*     $NetBSD: pcfiic_ebus.c,v 1.7 2020/10/23 15:18:10 jdc Exp $      */
 /*     $OpenBSD: pcfiic_ebus.c,v 1.13 2008/06/08 03:07:40 deraadt Exp $ */
 
 /*
@@ -18,7 +18,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pcfiic_ebus.c,v 1.6 2020/06/12 03:41:57 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pcfiic_ebus.c,v 1.7 2020/10/23 15:18:10 jdc Exp $");
 
 /*
  * Device specific driver for the EBus i2c devices found on some sun4u
@@ -57,11 +57,6 @@
 CFATTACH_DECL_NEW(pcfiic, sizeof(struct pcfiic_ebus_softc),
        pcfiic_ebus_match, pcfiic_ebus_attach, NULL, NULL);
 
-static prop_array_t create_dict(device_t);
-static void add_prop(prop_array_t, const char *, const char *, u_int, int);
-static void envctrl_props(prop_array_t, int);
-static void envctrltwo_props(prop_array_t, int);
-
 int
 pcfiic_ebus_match(device_t parent, struct cfdata *match, void *aux)
 {
@@ -103,6 +98,11 @@
                return;
        }
 
+       /* E450 and E250 have a different clock */
+       if ((strcmp(ea->ea_name, "SUNW,envctrl") == 0) ||
+           (strcmp(ea->ea_name, "SUNW,envctrltwo") == 0))
+               clock = PCF8584_CLK_12 | PCF8584_SCL_45;
+
        sc->sc_dev = self;
        if (OF_getprop(ea->ea_node, "compatible", compat, sizeof(compat)) > 0 &&
            strcmp(compat, "SUNW,bbc-i2c") == 0) {
@@ -160,65 +160,5 @@
        if (esc->esc_ih == NULL)
                sc->sc_poll = 1;
 
-       if (strcmp(ea->ea_name, "SUNW,envctrl") == 0) {
-               envctrl_props(create_dict(self), ea->ea_node);
-               pcfiic_attach(sc, 0x55, PCF8584_CLK_12 | PCF8584_SCL_45, 0);
-       } else if (strcmp(ea->ea_name, "SUNW,envctrltwo") == 0) {
-               envctrltwo_props(create_dict(self), ea->ea_node);
-               pcfiic_attach(sc, 0x55, PCF8584_CLK_12 | PCF8584_SCL_45, 0);
-       } else
-               pcfiic_attach(sc, (i2c_addr_t)(addr >> 1), clock, swapregs);
-}
-
-static prop_array_t
-create_dict(device_t parent)
-{
-       prop_dictionary_t props = device_properties(parent);
-       prop_array_t cfg = prop_dictionary_get(props, "i2c-child-devices");
-       if (cfg) return cfg;
-       cfg = prop_array_create();
-       prop_dictionary_set(props, "i2c-child-devices", cfg);
-       prop_object_release(cfg);
-       return cfg;
+       pcfiic_attach(sc, (i2c_addr_t)(addr >> 1), clock, swapregs);
 }
-
-static void
-add_prop(prop_array_t c, const char *name, const char *compat, u_int addr,
-       int node)
-{
-       prop_dictionary_t dev;
-
-       dev = prop_dictionary_create();
-       prop_dictionary_set_string(dev, "name", name);
-       prop_dictionary_set_data(dev, "compatible", compat, strlen(compat)+1);
-       prop_dictionary_set_uint32(dev, "addr", addr);
-       prop_dictionary_set_uint64(dev, "cookie", node);
-       prop_array_add(c, dev);
-       prop_object_release(dev);
-}
-
-static void
-envctrl_props(prop_array_t c, int node)
-{
-       /* Power supply 1 temperature. */
-       add_prop(c, "PSU-1", "ecadc", 0x48, node);
-
-       /* Power supply 2 termperature. */
-       add_prop(c, "PSU-2", "ecadc", 0x49, node);
-
-       /* Power supply 3 tempterature. */
-       add_prop(c, "PSU-3", "ecadc", 0x4a, node);
-
-       /* Ambient tempterature. */
-       add_prop(c, "ambient", "i2c-lm75", 0x4d, node);
-
-       /* CPU temperatures. */
-       add_prop(c, "CPU", "ecadc", 0x4f, node);
-}
-
-static void
-envctrltwo_props(prop_array_t c, int node)
-{
-       add_prop(c, "PSU", "ecadc", 0x4a, node);
-       add_prop(c, "CPU", "ecadc", 0x4f, node);
-}
diff -r 806900a27ed8 -r d62cdb4c6559 sys/arch/sparc64/sparc64/autoconf.c
--- a/sys/arch/sparc64/sparc64/autoconf.c       Fri Oct 23 14:48:49 2020 +0000
+++ b/sys/arch/sparc64/sparc64/autoconf.c       Fri Oct 23 15:18:10 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: autoconf.c,v 1.225 2020/10/17 08:10:31 jdc Exp $ */
+/*     $NetBSD: autoconf.c,v 1.226 2020/10/23 15:18:10 jdc Exp $ */
 
 /*
  * Copyright (c) 1996
@@ -48,7 +48,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.225 2020/10/17 08:10:31 jdc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.226 2020/10/23 15:18:10 jdc Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -1281,6 +1281,16 @@
                    (!strcmp(machine_model, "SUNW,Sun-Fire-V240") ||
                    !strcmp(machine_model, "SUNW,Sun-Fire-V210")))
                        add_env_sensors_v210(busdev);
+
+               /* E450 SUNW,envctrl */
+               if (device_is_a(busdev, "pcfiic") &&
+                   (!strcmp(machine_model, "SUNW,Ultra-4")))
+                       add_i2c_props_e450(busdev, busnode);
+               /* E250 SUNW,envctrltwo */
+               if (device_is_a(busdev, "pcfiic") &&
+                   (!strcmp(machine_model, "SUNW,Ultra-250")))
+                       add_i2c_props_e250(busdev, busnode);
+
        }
 
        /* set properties for PCI framebuffers */
diff -r 806900a27ed8 -r d62cdb4c6559 sys/arch/sparc64/sparc64/ofw_patch.c
--- a/sys/arch/sparc64/sparc64/ofw_patch.c      Fri Oct 23 14:48:49 2020 +0000
+++ b/sys/arch/sparc64/sparc64/ofw_patch.c      Fri Oct 23 15:18:10 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ofw_patch.c,v 1.1 2020/10/16 07:35:16 jdc Exp $ */
+/*     $NetBSD: ofw_patch.c,v 1.2 2020/10/23 15:18:10 jdc Exp $ */
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ofw_patch.c,v 1.1 2020/10/16 07:35:16 jdc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_patch.c,v 1.2 2020/10/23 15:18:10 jdc Exp $");
 
 #include <sys/param.h>
 
@@ -54,7 +54,42 @@
        prop_array_add(pins, pin);
        prop_object_release(pin);
 }
-       
+
+static prop_array_t
+create_i2c_dict(device_t busdev)
+{
+       prop_dictionary_t props = device_properties(busdev);
+       prop_array_t cfg = NULL;
+
+       cfg = prop_dictionary_get(props, "i2c-child-devices");
+       if (!cfg) {
+               cfg = prop_array_create();
+               prop_dictionary_set(props, "i2c-child-devices", cfg);
+               prop_dictionary_set_bool(props, "i2c-indirect-config", false);
+       }
+       return cfg;
+}
+
+static void
+add_i2c_device(prop_array_t cfg, const char *name, const char *compat,
+uint32_t addr, uint64_t node)
+{
+       prop_dictionary_t dev;
+       prop_data_t data;
+
+       DPRINTF(ACDB_PROBE, ("\nAdding i2c device: %s (%s) @ 0x%x (%lx)\n",
+           name, compat, addr, node & 0xffffffff));
+       dev = prop_dictionary_create();
+       prop_dictionary_set_string(dev, "name", name);
+       data = prop_data_create_copy(compat, strlen(compat) + 1);
+       prop_dictionary_set(dev, "compatible", data);
+       prop_object_release(data);
+       prop_dictionary_set_uint32(dev, "addr", addr);
+       prop_dictionary_set_uint64(dev, "cookie", node);
+       prop_array_add(cfg, dev);
+       prop_object_release(dev);
+}
+
 void
 add_gpio_props_v210(device_t dev, void *aux)
 {
@@ -134,42 +169,56 @@
 void
 add_env_sensors_v210(device_t busdev)
 {
-       prop_dictionary_t props = device_properties(busdev);
-       prop_array_t cfg = NULL;
-       prop_dictionary_t sens;
-       prop_data_t data;
-       const char name_lm[] = "i2c-lm75";
-       const char name_adm[] = "i2c-adm1026";
+       prop_array_t cfg;
 
        DPRINTF(ACDB_PROBE, ("\nAdding sensors for %s ", machine_model));
-       cfg = prop_dictionary_get(props, "i2c-child-devices");
-       if (!cfg) {
-               cfg = prop_array_create();
-               prop_dictionary_set(props, "i2c-child-devices", cfg);
-               prop_dictionary_set_bool(props, "i2c-indirect-config", false);
-       }
+       cfg = create_i2c_dict(busdev);
 
        /* ADM1026 at 0x2e */
-       sens = prop_dictionary_create();
-       prop_dictionary_set_uint32(sens, "addr", 0x2e);
-       prop_dictionary_set_uint64(sens, "cookie", 0);
-       prop_dictionary_set_string(sens, "name", "hardware-monitor");
-       data = prop_data_create_copy(&name_adm[0], sizeof(name_adm));
-       prop_dictionary_set(sens, "compatible", data);
-       prop_object_release(data);
-       prop_array_add(cfg, sens);
-       prop_object_release(sens);
+       add_i2c_device(cfg, "hardware-monitor", "i2c-adm1026", 0x2e, 0);
+       /* LM75 at 0x4e */
+       add_i2c_device(cfg, "temperature-sensor", "i2c-lm75", 0x4e, 0);
+
+       prop_object_release(cfg);
+}
+
+/* Sensors and GPIO's for E450 and E250 */
+void
+add_i2c_props_e450(device_t busdev, uint64_t node)
+{
+       prop_array_t cfg;
+
+       DPRINTF(ACDB_PROBE, ("\nAdding sensors for %s ", machine_model));
+       cfg = create_i2c_dict(busdev);
+
+       /* Power supply 1 temperature. */
+       add_i2c_device(cfg, "PSU-1", "ecadc", 0x48, node);
+
+       /* Power supply 2 termperature. */
+       add_i2c_device(cfg, "PSU-2", "ecadc", 0x49, node);
 
-       /* LM75 at 0x4e */
-       sens = prop_dictionary_create();
-       prop_dictionary_set_uint32(sens, "addr", 0x4e);
-       prop_dictionary_set_uint64(sens, "cookie", 0);
-       prop_dictionary_set_string(sens, "name", "temperature-sensor");
-       data = prop_data_create_copy(&name_lm[0], sizeof(name_lm));
-       prop_dictionary_set(sens, "compatible", data);
-       prop_object_release(data);
-       prop_array_add(cfg, sens);
-       prop_object_release(sens);
+       /* Power supply 3 tempterature. */
+       add_i2c_device(cfg, "PSU-3", "ecadc", 0x4a, node);
+
+       /* Ambient tempterature. */
+       add_i2c_device(cfg, "ambient", "i2c-lm75", 0x4d, node);
+
+       /* CPU temperatures. */
+       add_i2c_device(cfg, "CPU", "ecadc", 0x4f, node);
+}
+
+void
+add_i2c_props_e250(device_t busdev, uint64_t node)
+{
+       prop_array_t cfg;
+
+       DPRINTF(ACDB_PROBE, ("\nAdding sensors for %s ", machine_model));
+       cfg = create_i2c_dict(busdev);
+
+       /* PSU temperature / CPU fan */
+       add_i2c_device(cfg, "PSU", "ecadc", 0x4a, node);
+       /* CPU & system board temperature */
+       add_i2c_device(cfg, "CPU", "ecadc", 0x4f, node);
 }
 
 /* Hardware specific device properties */
diff -r 806900a27ed8 -r d62cdb4c6559 sys/arch/sparc64/sparc64/ofw_patch.h
--- a/sys/arch/sparc64/sparc64/ofw_patch.h      Fri Oct 23 14:48:49 2020 +0000
+++ b/sys/arch/sparc64/sparc64/ofw_patch.h      Fri Oct 23 15:18:10 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ofw_patch.h,v 1.2 2020/10/17 08:10:31 jdc Exp $ */
+/*     $NetBSD: ofw_patch.h,v 1.3 2020/10/23 15:18:10 jdc Exp $ */



Home | Main Index | Thread Index | Old Index