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/fdt - As with i2c, just register the ...



details:   https://anonhg.NetBSD.org/src/rev/41454b583e2e
branches:  thorpej-i2c-spi-conf
changeset: 378796:41454b583e2e
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Wed May 19 02:58:26 2021 +0000

description:
- As with i2c, just register the spi_controller directly.
- fdtbus_attach_spibus() is no longer anything other than a wrapper
  around config_found(); just get rid of it and make its callers
  look like all of the other SPI controller drivers.

diffstat:

 sys/arch/arm/imx/imxspi.c      |  26 +++++---------------------
 sys/arch/arm/rockchip/rk_spi.c |  27 ++++++++++-----------------
 sys/arch/arm/sunxi/sun4i_spi.c |  28 +++++++++++-----------------
 sys/dev/fdt/fdt_spi.c          |  37 +++++++++----------------------------
 sys/dev/fdt/fdtvar.h           |  11 +++--------
 5 files changed, 38 insertions(+), 91 deletions(-)

diffs (truncated from 315 to 300 lines):

diff -r 7b04d86f164d -r 41454b583e2e sys/arch/arm/imx/imxspi.c
--- a/sys/arch/arm/imx/imxspi.c Tue May 18 23:48:16 2021 +0000
+++ b/sys/arch/arm/imx/imxspi.c Wed May 19 02:58:26 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: imxspi.c,v 1.8.2.1 2021/05/18 23:30:55 thorpej Exp $   */
+/*     $NetBSD: imxspi.c,v 1.8.2.2 2021/05/19 02:58:26 thorpej Exp $   */
 
 /*-
  * Copyright (c) 2014  Genetec Corporation.  All rights reserved.
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: imxspi.c,v 1.8.2.1 2021/05/18 23:30:55 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: imxspi.c,v 1.8.2.2 2021/05/19 02:58:26 thorpej Exp $");
 
 #include "opt_imxspi.h"
 #include "opt_fdt.h"
@@ -86,20 +86,6 @@ int imxspi_debug = IMXSPI_DEBUG;
 #define        DPRINTFN(n,x)
 #endif
 
-#ifdef FDT
-static struct spi_controller *
-imxspi_get_controller(device_t dev)
-{
-       struct imxspi_softc * const sc = device_private(dev);
-
-       return &sc->sc_spi;
-}
-
-static const struct fdtbus_spi_controller_func imxspi_funcs = {
-       .get_controller = imxspi_get_controller
-};
-#endif
-
 int
 imxspi_attach_common(device_t self)
 {
@@ -140,16 +126,14 @@ imxspi_attach_common(device_t self)
 #ifdef FDT
        KASSERT(sc->sc_phandle != 0);
 
-       fdtbus_register_spi_controller(self, sc->sc_phandle, &imxspi_funcs);
-       fdtbus_attach_spibus(self, sc->sc_phandle, spibus_print);
-#else
+       fdtbus_register_spi_controller(&sc->sc_spi, sc->sc_phandle);
+#endif
        struct spibus_attach_args sba = {
                .sba_controller = &sc->sc_spi,
        };
-       config_found(sc->sc_dev, &sba, spibus_print,
+       config_found(self, &sba, spibus_print,
            CFARG_DEVHANDLE, device_handle(self),
            CFARG_EOL);
-#endif
 
        return 0;
 }
diff -r 7b04d86f164d -r 41454b583e2e sys/arch/arm/rockchip/rk_spi.c
--- a/sys/arch/arm/rockchip/rk_spi.c    Tue May 18 23:48:16 2021 +0000
+++ b/sys/arch/arm/rockchip/rk_spi.c    Wed May 19 02:58:26 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rk_spi.c,v 1.6 2021/01/27 03:10:19 thorpej Exp $       */
+/*     $NetBSD: rk_spi.c,v 1.6.4.1 2021/05/19 02:58:26 thorpej Exp $   */
 
 /*
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rk_spi.c,v 1.6 2021/01/27 03:10:19 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rk_spi.c,v 1.6.4.1 2021/05/19 02:58:26 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -170,7 +170,6 @@ struct rk_spi_softc {
 #define SPIREG_WRITE(sc, reg, val) \
     bus_space_write_4((sc)->sc_bst, (sc)->sc_bsh, (reg), (val))
 
-static struct spi_controller *rk_spi_get_controller(device_t);
 static int rk_spi_match(device_t, cfdata_t, void *);
 static void rk_spi_attach(device_t, device_t, void *);
 
@@ -187,18 +186,6 @@ static int rk_spi_intr(void *);
 CFATTACH_DECL_NEW(rk_spi, sizeof(struct rk_spi_softc),
     rk_spi_match, rk_spi_attach, NULL, NULL);
 
-static const struct fdtbus_spi_controller_func rk_spi_funcs = {
-       .get_controller = rk_spi_get_controller
-};
-
-static struct spi_controller *
-rk_spi_get_controller(device_t dev)
-{
-       struct rk_spi_softc * const sc = device_private(dev);
-
-       return &sc->sc_spi;
-}
-
 static int
 rk_spi_match(device_t parent, cfdata_t cf, void *aux)
 {
@@ -266,8 +253,14 @@ rk_spi_attach(device_t parent, device_t 
        sc->sc_spi.sct_transfer = rk_spi_transfer;
        sc->sc_spi.sct_nslaves = 2;
 
-       fdtbus_register_spi_controller(self, phandle, &rk_spi_funcs);
-       (void) fdtbus_attach_spibus(self, phandle, spibus_print);
+       fdtbus_register_spi_controller(&sc->sc_spi, phandle);
+
+       struct spibus_attach_args sba = {
+               .sba_controller = &sc->sc_spi,
+       };
+       config_found(self, &sba, spibus_print,
+           CFARG_DEVHANDLE, device_handle(self),
+           CFARG_EOL);
 }
 
 static int
diff -r 7b04d86f164d -r 41454b583e2e sys/arch/arm/sunxi/sun4i_spi.c
--- a/sys/arch/arm/sunxi/sun4i_spi.c    Tue May 18 23:48:16 2021 +0000
+++ b/sys/arch/arm/sunxi/sun4i_spi.c    Wed May 19 02:58:26 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sun4i_spi.c,v 1.7 2021/01/27 03:10:20 thorpej Exp $    */
+/*     $NetBSD: sun4i_spi.c,v 1.7.4.1 2021/05/19 02:58:26 thorpej Exp $        */
 
 /*
  * Copyright (c) 2019 Tobias Nygren
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sun4i_spi.c,v 1.7 2021/01/27 03:10:20 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sun4i_spi.c,v 1.7.4.1 2021/05/19 02:58:26 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -65,7 +65,6 @@ struct sun4ispi_softc {
 #define SPIREG_WRITE(sc, reg, val) \
     bus_space_write_4((sc)->sc_bst, (sc)->sc_bsh, (reg), (val))
 
-static struct spi_controller * sun4i_spi_get_controller(device_t);
 static int sun4ispi_match(device_t, cfdata_t, void *);
 static void sun4ispi_attach(device_t, device_t, void *);
 
@@ -82,18 +81,6 @@ static int sun4ispi_intr(void *);
 CFATTACH_DECL_NEW(sun4i_spi, sizeof(struct sun4ispi_softc),
     sun4ispi_match, sun4ispi_attach, NULL, NULL);
 
-static const struct fdtbus_spi_controller_func sun4i_spi_funcs = {
-       .get_controller = sun4i_spi_get_controller
-};
-
-static struct spi_controller *
-sun4i_spi_get_controller(device_t dev)
-{
-       struct sun4ispi_softc * const sc = device_private(dev);
-
-       return &sc->sc_spi;
-}
-
 static int
 sun4ispi_match(device_t parent, cfdata_t cf, void *aux)
 {
@@ -164,8 +151,15 @@ sun4ispi_attach(device_t parent, device_
        sc->sc_spi.sct_configure = sun4ispi_configure;
        sc->sc_spi.sct_transfer = sun4ispi_transfer;
        (void) of_getprop_uint32(phandle, "num-cs", &sc->sc_spi.sct_nslaves);
-       fdtbus_register_spi_controller(self, phandle, &sun4i_spi_funcs);
-       (void) fdtbus_attach_spibus(self, phandle, spibus_print);
+
+       fdtbus_register_spi_controller(&sc->sc_spi, phandle);
+
+       struct spibus_attach_args sba = {
+               .sba_controller = &sc->sc_spi,
+       };
+       config_found(self, &sba, spibus_print,
+           CFARG_DEVHANDLE, device_handle(self),
+           CFARG_EOL);
 }
 
 static int
diff -r 7b04d86f164d -r 41454b583e2e sys/dev/fdt/fdt_spi.c
--- a/sys/dev/fdt/fdt_spi.c     Tue May 18 23:48:16 2021 +0000
+++ b/sys/dev/fdt/fdt_spi.c     Wed May 19 02:58:26 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_spi.c,v 1.2.2.1 2021/05/18 23:48:16 thorpej Exp $ */
+/* $NetBSD: fdt_spi.c,v 1.2.2.2 2021/05/19 02:58:26 thorpej Exp $ */
 
 /*
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fdt_spi.c,v 1.2.2.1 2021/05/18 23:48:16 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_spi.c,v 1.2.2.2 2021/05/19 02:58:26 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -42,9 +42,9 @@
 #include <dev/fdt/fdtvar.h>
 
 struct fdtbus_spi_controller {
-       device_t spi_dev;
+       struct spi_controller *spi_ctlr;
        int spi_phandle;
-       const struct fdtbus_spi_controller_func *spi_funcs;
+
        LIST_ENTRY(fdtbus_spi_controller) spi_next;
 };
 
@@ -52,21 +52,20 @@ static LIST_HEAD(, fdtbus_spi_controller
     LIST_HEAD_INITIALIZER(fdtbus_spi_controllers);
 
 int
-fdtbus_register_spi_controller(device_t dev, int phandle,
-    const struct fdtbus_spi_controller_func *funcs)
+fdtbus_register_spi_controller(struct spi_controller *ctlr, int phandle)
 {
        struct fdtbus_spi_controller *spi;
 
        spi = kmem_alloc(sizeof(*spi), KM_SLEEP);
-       spi->spi_dev = dev;
+       spi->spi_ctlr = ctlr;
        spi->spi_phandle = phandle;
-       spi->spi_funcs = funcs;
 
        LIST_INSERT_HEAD(&fdtbus_spi_controllers, spi, spi_next);
 
        return 0;
 }
 
+#if 0
 static struct spi_controller *
 fdtbus_get_spi_controller(int phandle)
 {
@@ -74,27 +73,9 @@ fdtbus_get_spi_controller(int phandle)
 
        LIST_FOREACH(spi, &fdtbus_spi_controllers, spi_next) {
                if (spi->spi_phandle == phandle) {
-                       return spi->spi_funcs->get_controller(spi->spi_dev);
+                       return spi->spi_ctlr;
                }
        }
        return NULL;
 }
-
-device_t
-fdtbus_attach_spibus(device_t dev, int phandle, cfprint_t print)
-{
-       struct spi_controller *spi;
-
-       spi = fdtbus_get_spi_controller(phandle);
-       KASSERT(spi != NULL);
-
-       struct spibus_attach_args sba = {
-               .sba_controller = spi,
-       };
-       return config_found(dev, &sba, print,
-           CFARG_IATTR, "spibus",
-           CFARG_DEVHANDLE, device_handle(dev),
-           CFARG_EOL);
-}
-
-
+#endif
diff -r 7b04d86f164d -r 41454b583e2e sys/dev/fdt/fdtvar.h
--- a/sys/dev/fdt/fdtvar.h      Tue May 18 23:48:16 2021 +0000
+++ b/sys/dev/fdt/fdtvar.h      Wed May 19 02:58:26 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fdtvar.h,v 1.70 2021/04/24 23:36:53 thorpej Exp $ */
+/* $NetBSD: fdtvar.h,v 1.70.2.1 2021/05/19 02:58:26 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -35,6 +35,7 @@
 #include <sys/termios.h>
 
 #include <dev/i2c/i2cvar.h>
+#include <dev/spi/spivar.h>
 #include <dev/pwm/pwmvar.h>
 #include <dev/clk/clk.h>
 
@@ -79,10 +80,6 @@ struct fdtbus_interrupt_controller_func 
        void    (*unmask)(device_t, void *);
 };
 
-struct fdtbus_spi_controller_func {
-       struct spi_controller * (*get_controller)(device_t);
-};
-
 struct fdtbus_gpio_controller;
 
 struct fdtbus_gpio_pin {
@@ -274,8 +271,7 @@ struct fdt_dma_range {
 int            fdtbus_register_interrupt_controller(device_t, int,
                    const struct fdtbus_interrupt_controller_func *);



Home | Main Index | Thread Index | Old Index