Module Name:    src
Committed By:   thorpej
Date:           Wed May 19 02:58:26 UTC 2021

Modified Files:
        src/sys/arch/arm/imx [thorpej-i2c-spi-conf]: imxspi.c
        src/sys/arch/arm/rockchip [thorpej-i2c-spi-conf]: rk_spi.c
        src/sys/arch/arm/sunxi [thorpej-i2c-spi-conf]: sun4i_spi.c
        src/sys/dev/fdt [thorpej-i2c-spi-conf]: fdt_spi.c fdtvar.h

Log Message:
- 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.


To generate a diff of this commit:
cvs rdiff -u -r1.8.2.1 -r1.8.2.2 src/sys/arch/arm/imx/imxspi.c
cvs rdiff -u -r1.6 -r1.6.4.1 src/sys/arch/arm/rockchip/rk_spi.c
cvs rdiff -u -r1.7 -r1.7.4.1 src/sys/arch/arm/sunxi/sun4i_spi.c
cvs rdiff -u -r1.2.2.1 -r1.2.2.2 src/sys/dev/fdt/fdt_spi.c
cvs rdiff -u -r1.70 -r1.70.2.1 src/sys/dev/fdt/fdtvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/arm/imx/imxspi.c
diff -u src/sys/arch/arm/imx/imxspi.c:1.8.2.1 src/sys/arch/arm/imx/imxspi.c:1.8.2.2
--- src/sys/arch/arm/imx/imxspi.c:1.8.2.1	Tue May 18 23:30:55 2021
+++ src/sys/arch/arm/imx/imxspi.c	Wed May 19 02:58:26 2021
@@ -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;
 }

Index: src/sys/arch/arm/rockchip/rk_spi.c
diff -u src/sys/arch/arm/rockchip/rk_spi.c:1.6 src/sys/arch/arm/rockchip/rk_spi.c:1.6.4.1
--- src/sys/arch/arm/rockchip/rk_spi.c:1.6	Wed Jan 27 03:10:19 2021
+++ src/sys/arch/arm/rockchip/rk_spi.c	Wed May 19 02:58:26 2021
@@ -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

Index: src/sys/arch/arm/sunxi/sun4i_spi.c
diff -u src/sys/arch/arm/sunxi/sun4i_spi.c:1.7 src/sys/arch/arm/sunxi/sun4i_spi.c:1.7.4.1
--- src/sys/arch/arm/sunxi/sun4i_spi.c:1.7	Wed Jan 27 03:10:20 2021
+++ src/sys/arch/arm/sunxi/sun4i_spi.c	Wed May 19 02:58:26 2021
@@ -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

Index: src/sys/dev/fdt/fdt_spi.c
diff -u src/sys/dev/fdt/fdt_spi.c:1.2.2.1 src/sys/dev/fdt/fdt_spi.c:1.2.2.2
--- src/sys/dev/fdt/fdt_spi.c:1.2.2.1	Tue May 18 23:48:16 2021
+++ src/sys/dev/fdt/fdt_spi.c	Wed May 19 02:58:26 2021
@@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: fdt_spi.c,v 
 #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

Index: src/sys/dev/fdt/fdtvar.h
diff -u src/sys/dev/fdt/fdtvar.h:1.70 src/sys/dev/fdt/fdtvar.h:1.70.2.1
--- src/sys/dev/fdt/fdtvar.h:1.70	Sat Apr 24 23:36:53 2021
+++ src/sys/dev/fdt/fdtvar.h	Wed May 19 02:58:26 2021
@@ -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 <[email protected]>
@@ -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 *);
 int		fdtbus_register_i2c_controller(i2c_tag_t, int);
-int		fdtbus_register_spi_controller(device_t, int,
-		    const struct fdtbus_spi_controller_func *);
+int		fdtbus_register_spi_controller(struct spi_controller *, int);
 int		fdtbus_register_gpio_controller(device_t, int,
 		    const struct fdtbus_gpio_controller_func *);
 int		fdtbus_register_pinctrl_config(device_t, int,
@@ -404,7 +400,6 @@ void		fdtbus_power_reset(void);
 void		fdtbus_power_poweroff(void);
 
 device_t	fdtbus_attach_i2cbus(device_t, int, i2c_tag_t, cfprint_t);
-device_t	fdtbus_attach_spibus(device_t, int, cfprint_t);
 
 bool		fdtbus_init(const void *);
 const void *	fdtbus_get_data(void);

Reply via email to