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/dev Update the i2c mux code for the new e...



details:   https://anonhg.NetBSD.org/src/rev/0176ffe368d1
branches:  thorpej-i2c-spi-conf
changeset: 1020783:0176ffe368d1
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sat May 08 02:44:22 2021 +0000

description:
Update the i2c mux code for the new enumeration methods.

diffstat:

 sys/dev/fdt/i2cmux_fdt.c |   32 +++++---
 sys/dev/i2c/i2cmux.c     |  163 +++++++++++++++++++++++-----------------------
 sys/dev/i2c/i2cmuxvar.h  |   55 ++++++++++++++-
 sys/dev/i2c/pcai2cmux.c  |   46 +++++++------
 4 files changed, 175 insertions(+), 121 deletions(-)

diffs (truncated from 626 to 300 lines):

diff -r 9cf5dac0f660 -r 0176ffe368d1 sys/dev/fdt/i2cmux_fdt.c
--- a/sys/dev/fdt/i2cmux_fdt.c  Sun Apr 25 23:19:16 2021 +0000
+++ b/sys/dev/fdt/i2cmux_fdt.c  Sat May 08 02:44:22 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: i2cmux_fdt.c,v 1.10 2021/01/27 03:10:21 thorpej Exp $  */
+/*     $NetBSD: i2cmux_fdt.c,v 1.10.4.1 2021/05/08 02:44:22 thorpej Exp $      */
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: i2cmux_fdt.c,v 1.10 2021/01/27 03:10:21 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i2cmux_fdt.c,v 1.10.4.1 2021/05/08 02:44:22 thorpej Exp $");
 
 #include <sys/types.h>
 #include <sys/device.h>
@@ -59,11 +59,12 @@
 iicmux_gpio_get_mux_info(struct iicmux_softc * const sc)
 {
        struct mux_info_gpio *mux_data;
+       const int phandle = devhandle_to_of(device_handle(sc->sc_dev));
        int i;
 
        mux_data = kmem_zalloc(sizeof(*mux_data), KM_SLEEP);
 
-       mux_data->npins = fdtbus_gpio_count(sc->sc_handle, "mux-gpios");
+       mux_data->npins = fdtbus_gpio_count(phandle, "mux-gpios");
        if (mux_data->npins == 0) {
                aprint_error_dev(sc->sc_dev,
                    "unable to get mux-gpios property\n");
@@ -73,7 +74,7 @@
        mux_data->pins =
            kmem_zalloc(sizeof(*mux_data->pins) * mux_data->npins, KM_SLEEP);
        for (i = 0; i < mux_data->npins; i++) {
-               mux_data->pins[i] = fdtbus_gpio_acquire_index(sc->sc_handle,
+               mux_data->pins[i] = fdtbus_gpio_acquire_index(phandle,
                    "mux-gpios", i, GPIO_PIN_OUTPUT);
                if (mux_data->pins[i] == NULL) {
                        aprint_error_dev(sc->sc_dev,
@@ -83,7 +84,7 @@
        }
 
        mux_data->has_idle_value =
-           of_getprop_uint32(sc->sc_handle, "idle-state",
+           of_getprop_uint32(phandle, "idle-state",
                              &mux_data->idle_value) == 0;
 
        return mux_data;
@@ -102,12 +103,13 @@
 iicmux_gpio_get_bus_info(struct iicmux_bus * const bus)
 {
        struct iicmux_softc * const sc = bus->mux;
+       const int phandle = devhandle_to_of(bus->devhandle);
        struct bus_info_gpio *bus_info;
        int error;
 
        bus_info = kmem_zalloc(sizeof(*bus_info), KM_SLEEP);
 
-       error = fdtbus_get_reg(bus->handle, 0, &bus_info->value, NULL);
+       error = fdtbus_get_reg(phandle, 0, &bus_info->value, NULL);
        if (error) {
                aprint_error_dev(sc->sc_dev,
                    "unable to get reg property for bus %d\n", bus->busidx);
@@ -172,12 +174,13 @@
 static void *
 iicmux_pinctrl_get_mux_info(struct iicmux_softc * const sc)
 {
+       const int phandle = devhandle_to_of(device_handle(sc->sc_dev));
        struct mux_info_pinctrl *mux_info;
 
        mux_info = kmem_alloc(sizeof(*mux_info), KM_SLEEP);
 
        mux_info->has_idle_idx =
-           fdtbus_get_index(sc->sc_handle, "pinctrl-names", "idle",
+           fdtbus_get_index(phandle, "pinctrl-names", "idle",
                             &mux_info->idle_idx) == 0;
 
        return mux_info;
@@ -187,12 +190,13 @@
 iicmux_pinctrl_get_bus_info(struct iicmux_bus * const bus)
 {
        struct iicmux_softc * const sc = bus->mux;
+       const int phandle = devhandle_to_of(bus->devhandle);
        struct bus_info_pinctrl *bus_info;
        int error;
 
        bus_info = kmem_alloc(sizeof(*bus_info), KM_SLEEP);
 
-       error = fdtbus_get_reg(bus->handle, 0, &bus_info->idx, NULL);
+       error = fdtbus_get_reg(phandle, 0, &bus_info->idx, NULL);
        if (error) {
                aprint_error_dev(sc->sc_dev,
                    "unable to get reg property for bus %d\n", bus->busidx);
@@ -208,9 +212,10 @@
     int const flags __unused)
 {
        struct iicmux_softc * const sc = bus->mux;
+       const int phandle = devhandle_to_of(device_handle(sc->sc_dev));
        struct bus_info_pinctrl * const bus_info = bus->bus_data;
 
-       return fdtbus_pinctrl_set_config_index(sc->sc_handle, bus_info->idx);
+       return fdtbus_pinctrl_set_config_index(phandle, bus_info->idx);
 }
 
 static void
@@ -218,10 +223,11 @@
     int const flags __unused)
 {
        struct iicmux_softc * const sc = bus->mux;
+       const int phandle = devhandle_to_of(device_handle(sc->sc_dev));
        struct mux_info_pinctrl * const mux_info = sc->sc_mux_data;
 
        if (mux_info->has_idle_idx) {
-               (void) fdtbus_pinctrl_set_config_index(sc->sc_handle,
+               (void) fdtbus_pinctrl_set_config_index(phandle,
                    mux_info->idle_idx);
        }
 }
@@ -261,13 +267,13 @@
        struct fdt_attach_args * const faa = aux;
 
        sc->sc_dev = self;
-       sc->sc_handle = faa->faa_phandle;
-       sc->sc_config = of_compatible_lookup(sc->sc_handle, compat_data)->data;
+       sc->sc_config =
+           of_compatible_lookup(faa->faa_phandle, compat_data)->data;
 
        aprint_naive("\n");
        aprint_normal(": %s I2C mux\n", sc->sc_config->desc);
 
-       sc->sc_i2c_parent = fdtbus_i2c_acquire(sc->sc_handle, "i2c-parent");
+       sc->sc_i2c_parent = fdtbus_i2c_acquire(faa->faa_phandle, "i2c-parent");
        if (sc->sc_i2c_parent == NULL) {
                aprint_error_dev(sc->sc_dev, "unable to acquire i2c-parent\n");
                return;
diff -r 9cf5dac0f660 -r 0176ffe368d1 sys/dev/i2c/i2cmux.c
--- a/sys/dev/i2c/i2cmux.c      Sun Apr 25 23:19:16 2021 +0000
+++ b/sys/dev/i2c/i2cmux.c      Sat May 08 02:44:22 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: i2cmux.c,v 1.5 2021/04/24 23:36:54 thorpej Exp $       */
+/*     $NetBSD: i2cmux.c,v 1.5.2.1 2021/05/08 02:44:22 thorpej Exp $   */
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -29,27 +29,17 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#if defined(__i386__) || defined(__amd64__) || defined(__aarch64__)
-#include "acpica.h"
-#endif
-
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: i2cmux.c,v 1.5 2021/04/24 23:36:54 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i2cmux.c,v 1.5.2.1 2021/05/08 02:44:22 thorpej Exp $");
 
 #include <sys/types.h>
 #include <sys/device.h>
 #include <sys/kernel.h>
 #include <sys/kmem.h>
 
-#include <dev/fdt/fdtvar.h>
 #include <dev/i2c/i2cvar.h>
 #include <dev/i2c/i2cmuxvar.h>
 
-#if NACPICA > 0
-#include <dev/acpi/acpivar.h>
-#include <dev/acpi/acpi_i2c.h>
-#endif
-
 /*
  * i2c mux
  *
@@ -120,33 +110,6 @@
 
 /*****************************************************************************/
 
-static int
-iicmux_count_children(struct iicmux_softc * const sc)
-{
-       char name[32];
-       int child, count;
-
- restart:
-       for (child = OF_child(sc->sc_i2c_mux_phandle), count = 0; child;
-            child = OF_peer(child)) {
-               if (OF_getprop(child, "name", name, sizeof(name)) <= 0) {
-                       continue;
-               }
-               if (strcmp(name, "i2c-mux") == 0) {
-                       /*
-                        * The node we encountered is the acutal parent
-                        * of the i2c bus children.  Stash its phandle
-                        * and restart the enumeration.
-                        */
-                       sc->sc_i2c_mux_phandle = child;
-                       goto restart;
-               }
-               count++;
-       }
-
-       return count;
-}
-
 /* XXX iicbus_print() should be able to do this. */
 static int
 iicmux_print(void * const aux, const char * const pnp)
@@ -162,15 +125,14 @@
 }
 
 static void
-iicmux_attach_bus(struct iicmux_softc * const sc,
-    uintptr_t const handle, enum i2c_cookie_type handletype, int const busidx)
+iicmux_attach_bus(struct iicmux_softc * const sc, devhandle_t devhandle,
+    int const busidx)
 {
        struct iicmux_bus * const bus = &sc->sc_busses[busidx];
 
        bus->mux = sc;
        bus->busidx = busidx;
-       bus->handle = handle;
-       bus->handletype = handletype;
+       bus->devhandle = devhandle;
 
        bus->bus_data = sc->sc_config->get_bus_info(bus);
        if (bus->bus_data == NULL) {
@@ -185,63 +147,89 @@
        bus->controller.ic_release_bus = iicmux_release_bus;
        bus->controller.ic_exec = iicmux_exec;
 
-       switch (handletype) {
-       case I2C_COOKIE_OF:
+       switch (devhandle_type(devhandle)) {
+#if defined(I2CMUX_USE_FDT)
+       case DEVHANDLE_TYPE_OF:
                fdtbus_register_i2c_controller(&bus->controller,
-                   (int)bus->handle);
+                   devhandle_to_of(devhandle));
 
-               fdtbus_attach_i2cbus(sc->sc_dev, (int)bus->handle,
+               fdtbus_attach_i2cbus(sc->sc_dev, devhandle_to_of(devhandle),
                    &bus->controller, iicmux_print);
                break;
-#if NACPICA > 0
-       case I2C_COOKIE_ACPI: {
-               struct acpi_devnode *ad = acpi_match_node((ACPI_HANDLE)handle);
-               KASSERT(ad != NULL);
+#endif /* I2CMUX_USE_FDT */
+
+       case DEVHANDLE_TYPE_INVALID:
+               aprint_error_dev(sc->sc_dev, "invalid bus device handle\n");
+               return;
+
+       default: {
                struct i2cbus_attach_args iba = {
                        .iba_tag = &bus->controller,
-                       .iba_child_devices = acpi_enter_i2c_devs(NULL, ad)
                };
-               config_found(sc->sc_dev, &iba, iicbus_print, CFARG_EOL);
-       }       break;
-#endif
-       default:
-               aprint_error_dev(sc->sc_dev, "unknown handle type\n");
+               config_found(sc->sc_dev, &iba, iicmux_print,
+                   CFARG_DEVHANDLE, devhandle,
+                   CFARG_EOL);
                break;
+           }
        }
 }
 
+#if defined(I2CMUX_USE_FDT)
+static int
+iicmux_fdt_count_children(struct iicmux_softc * const sc)
+{
+       int phandle = devhandle_to_of(sc->sc_i2c_mux_devhandle);
+       char name[32];
+       int child, count;
+
+ restart:
+       for (child = OF_child(phandle), count = 0; child;
+            child = OF_peer(child)) {
+               if (OF_getprop(child, "name", name, sizeof(name)) <= 0) {
+                       continue;
+               }
+               if (strcmp(name, "i2c-mux") == 0) {
+                       phandle = child;
+                       goto restart;
+               }
+               count++;
+       }
+
+       /* phandle may have changed. */
+       sc->sc_i2c_mux_devhandle = devhandle_from_of(phandle);
+       return count;
+}
+
 static void



Home | Main Index | Thread Index | Old Index