Source-Changes-HG archive

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

[src/thorpej-i2c-spi-conf]: src/sys/arch/macppc Adapt the smu driver to the n...



details:   https://anonhg.NetBSD.org/src/rev/949f4b5cd4b3
branches:  thorpej-i2c-spi-conf
changeset: 983216:949f4b5cd4b3
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sun May 09 21:37:04 2021 +0000

description:
Adapt the smu driver to the new i2c device enumeration method.  While
here, collapse the "smuiic" driver into the base "smu" driver; it was
superfluous given how the rest of the "smu" driver is structured.

diffstat:

 sys/arch/macppc/conf/POWERMAC_G5      |    3 +-
 sys/arch/macppc/conf/POWERMAC_G5_11_2 |    3 +-
 sys/arch/macppc/conf/files.macppc     |    9 +-
 sys/arch/macppc/dev/smu.c             |  121 +++++++++++++++++++++---------
 sys/arch/macppc/dev/smuiic.c          |  135 ----------------------------------
 sys/arch/macppc/dev/smuiicvar.h       |   38 ---------
 6 files changed, 88 insertions(+), 221 deletions(-)

diffs (truncated from 430 to 300 lines):

diff -r 6d984d0141f1 -r 949f4b5cd4b3 sys/arch/macppc/conf/POWERMAC_G5
--- a/sys/arch/macppc/conf/POWERMAC_G5  Sat May 08 22:39:41 2021 +0000
+++ b/sys/arch/macppc/conf/POWERMAC_G5  Sun May 09 21:37:04 2021 +0000
@@ -131,8 +131,7 @@
 uninorth*      at mainbus?
 smu*           at mainbus?
 #options       SMU_DEBUG
-smuiic*        at smu?
-iic*           at smuiic?
+iic*           at smu?
 
 
 pci*   at ibmcpc? bus ?
diff -r 6d984d0141f1 -r 949f4b5cd4b3 sys/arch/macppc/conf/POWERMAC_G5_11_2
--- a/sys/arch/macppc/conf/POWERMAC_G5_11_2     Sat May 08 22:39:41 2021 +0000
+++ b/sys/arch/macppc/conf/POWERMAC_G5_11_2     Sun May 09 21:37:04 2021 +0000
@@ -117,8 +117,7 @@
 
 smu*           at mainbus?
 #options       SMU_DEBUG
-smuiic*        at smu?
-iic*           at smuiic?
+iic*           at smu?
 
 pci*   at ibmcpc? bus ?
 pci*   at uninorth? bus ?
diff -r 6d984d0141f1 -r 949f4b5cd4b3 sys/arch/macppc/conf/files.macppc
--- a/sys/arch/macppc/conf/files.macppc Sat May 08 22:39:41 2021 +0000
+++ b/sys/arch/macppc/conf/files.macppc Sun May 09 21:37:04 2021 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.macppc,v 1.116 2021/04/24 23:36:41 thorpej Exp $
+#      $NetBSD: files.macppc,v 1.116.2.1 2021/05/09 21:37:04 thorpej Exp $
 #
 # macppc-specific configuration info
 
@@ -175,16 +175,11 @@
 attach zstty at zsc
 file dev/ic/z8530tty.c                         zstty needs-flag
 
-define smu {}
-device smu: smu, obio
+device smu: i2cbus
 attach smu at mainbus
 file arch/macppc/dev/smu.c                     smu needs-flag
 defflag        opt_smu.h       SMU_DEBUG
 
-device smuiic: i2cbus
-attach smuiic at smu
-file arch/macppc/dev/smuiic.c                  smuiic
-
 device smusat
 attach smusat at iic
 file arch/macppc/dev/smusat.c                  smusat
diff -r 6d984d0141f1 -r 949f4b5cd4b3 sys/arch/macppc/dev/smu.c
--- a/sys/arch/macppc/dev/smu.c Sat May 08 22:39:41 2021 +0000
+++ b/sys/arch/macppc/dev/smu.c Sun May 09 21:37:04 2021 +0000
@@ -1,3 +1,5 @@
+/*     $NetBSD: smu.c,v 1.13.2.1 2021/05/09 21:37:04 thorpej Exp $     */
+
 /*-
  * Copyright (c) 2013 Phileas Fogg
  * All rights reserved.
@@ -30,6 +32,7 @@
 #include <sys/malloc.h>
 #include <sys/device.h>
 #include <sys/proc.h>
+#include <sys/kmem.h>
 #include <sys/mutex.h>
 #include <sys/time.h>
 #include <sys/reboot.h>
@@ -72,14 +75,15 @@
 };
 
 struct smu_iicbus {
-       struct smu_softc* sc;
+       struct smu_softc *sc;
 
        int reg;
        struct i2c_controller i2c;
+
+       LIST_ENTRY(smu_iicbus) buslist;
 };
 
 #define SMU_MAX_FANS           8
-#define SMU_MAX_IICBUS         3
 #define SMU_MAX_SME_SENSORS    (SMU_MAX_FANS + 8)
 
 struct smu_zone {
@@ -113,8 +117,12 @@
        int sc_num_fans;
        struct smu_fan sc_fans[SMU_MAX_FANS];
 
-       int sc_num_iicbus;
-       struct smu_iicbus sc_iicbus[SMU_MAX_IICBUS];
+       /*
+        * We provide our own i2c device enumeration method, so we
+        * need to provide our own devhandle_impl.
+        */
+       struct devhandle_impl sc_devhandle_impl;
+       LIST_HEAD(, smu_iicbus) sc_iic_busses;
 
        struct todr_chip_handle sc_todr;
 
@@ -158,7 +166,6 @@
 static void smu_setup_fans(struct smu_softc *);
 static void smu_setup_iicbus(struct smu_softc *);
 static void smu_setup_sme(struct smu_softc *);
-static int smu_iicbus_print(void *, const char *);
 static void smu_sme_refresh(struct sysmon_envsys *, envsys_data_t *);
 static int smu_do_cmd(struct smu_softc *, struct smu_cmd *, int);
 static int smu_dbell_gpio_intr(void *);
@@ -441,47 +448,98 @@
        }
 }
 
+static bool
+smu_i2c_get_address(int node, uint32_t *addrp)
+{
+       uint32_t reg;
+
+       if (of_getprop_uint32(node, "reg", &reg) == -1) {
+               return false;
+       }
+
+       *addrp = (reg & 0xff) >> 1;
+       return true;
+}
+
+static int
+smu_i2c_enumerate_devices(device_t dev, devhandle_t call_handle, void *v)
+{
+       /*
+        * This follows the OpenFirmware I2C binding for the most
+        * part, but has the address shifted left for the READ bit.
+        */
+       return of_i2c_enumerate_devices_ext(dev, call_handle, v,
+           smu_i2c_get_address);
+}
+
+static device_call_t
+smu_devhandle_lookup_device_call(devhandle_t handle, const char *name,
+    devhandle_t *call_handlep)
+{
+       if (strcmp(name, "i2c-enumerate-devices") == 0) {
+               return smu_i2c_enumerate_devices;
+       }
+
+       /* Defer everything else to the "super". */
+       return NULL;
+}
+
 static void
 smu_setup_iicbus(struct smu_softc *sc)
 {
        struct smu_iicbus *iicbus;
-       struct i2c_controller *i2c;
-       struct smu_iicbus_confargs ca;
+       struct i2cbus_attach_args iba;
+       devhandle_t devhandle;
        int node;
        char name[32];
 
        node = of_getnode_byname(sc->sc_node, "smu-i2c-control");
-       if (node == 0) node = sc->sc_node;
-       for (node = OF_child(node);
-           (node != 0) && (sc->sc_num_iicbus < SMU_MAX_IICBUS);
-           node = OF_peer(node)) {
+       if (node == 0)
+               node = sc->sc_node;
+
+       /*
+        * Set up our devhandle impl; we provide our own i2c device
+        * enumeration method.
+        */
+       devhandle = devhandle_from_of(node);
+       devhandle_impl_inherit(&sc->sc_devhandle_impl,
+           devhandle.impl);
+       sc->sc_devhandle_impl.lookup_device_call =
+           smu_devhandle_lookup_device_call;
+
+       for (node = OF_child(node); node != 0; node = OF_peer(node)) {
+
                memset(name, 0, sizeof(name));
                OF_getprop(node, "name", name, sizeof(name));
-               if ((strcmp(name, "i2c-bus") != 0) &&
-                   (strcmp(name, "i2c") != 0))
+               if (strcmp(name, "i2c-bus") != 0 && strcmp(name, "i2c") != 0)
                        continue;
 
-               iicbus = &sc->sc_iicbus[sc->sc_num_iicbus];
+               iicbus = kmem_zalloc(sizeof(*iicbus), KM_SLEEP);
                iicbus->sc = sc;
-               i2c = &iicbus->i2c;
 
-               if (OF_getprop(node, "reg", &iicbus->reg, sizeof(iicbus->reg)) <= 0)
+               if (OF_getprop(node, "reg", &iicbus->reg,
+                              sizeof(iicbus->reg)) <= 0) {
+                       kmem_free(iicbus, sizeof(*iicbus));
                        continue;
+               }
+               LIST_INSERT_HEAD(&sc->sc_iic_busses, iicbus, buslist);
 
                DPRINTF("iicbus: reg %x\n", iicbus->reg);
 
-               iic_tag_init(i2c);
-               i2c->ic_cookie = iicbus;
-               i2c->ic_exec = smu_iicbus_exec;
+               iic_tag_init(&iicbus->i2c);
+               iicbus->i2c.ic_cookie = iicbus;
+               iicbus->i2c.ic_exec = smu_iicbus_exec;
+
+               devhandle = devhandle_from_of(node);
+               devhandle.impl = &sc->sc_devhandle_impl;
 
-               ca.ca_name = name;
-               ca.ca_node = node;
-               ca.ca_tag = i2c;
-               config_found(sc->sc_dev, &ca, smu_iicbus_print,
-                   CFARG_DEVHANDLE, devhandle_from_of(node),
+               memset(&iba, 0, sizeof(iba));
+               iba.iba_tag = &iicbus->i2c;
+               iba.iba_bus = iicbus->reg;
+
+               config_found(sc->sc_dev, &iba, iicbus_print_multi,
+                   CFARG_DEVHANDLE, devhandle,
                    CFARG_EOL);
-
-               sc->sc_num_iicbus++;
        }
 }
 
@@ -540,17 +598,6 @@
        }
 }
 
-static int
-smu_iicbus_print(void *aux, const char *smu)
-{
-       struct smu_iicbus_confargs *ca = aux;
-
-       if (smu)
-               aprint_normal("%s at %s", ca->ca_name, smu);
-
-       return UNCONF;
-}
-
 static void
 smu_sme_refresh(struct sysmon_envsys *sme, envsys_data_t *edata)
 {
diff -r 6d984d0141f1 -r 949f4b5cd4b3 sys/arch/macppc/dev/smuiic.c
--- a/sys/arch/macppc/dev/smuiic.c      Sat May 08 22:39:41 2021 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,135 +0,0 @@
-/*     $NetBSD: smuiic.c,v 1.7 2021/04/24 23:36:41 thorpej Exp $ */
-
-/*-
- * Copyright (c) 2013 Phileas Fogg
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/kernel.h>
-#include <sys/malloc.h>
-#include <sys/device.h>
-#include <sys/proc.h>
-#include <sys/mutex.h>
-#include <sys/sysctl.h>
-
-#include <machine/autoconf.h>
-
-#include <dev/ofw/openfirm.h>
-#include <dev/i2c/i2cvar.h>
-
-#include <macppc/dev/smuvar.h>
-#include <macppc/dev/smuiicvar.h>
-
-struct smuiic_softc {
-       device_t sc_dev;



Home | Main Index | Thread Index | Old Index