Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/i2c Normalize how motoi2c controllers are attached.



details:   https://anonhg.NetBSD.org/src/rev/6695f05563ba
branches:  trunk
changeset: 368635:6695f05563ba
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Fri Jul 22 23:43:23 2022 +0000

description:
Normalize how motoi2c controllers are attached.

diffstat:

 sys/arch/arm/imx/imx51_i2c.c            |  10 ++--
 sys/arch/arm/imx/imxi2c.c               |  79 ++++++++++++++++----------------
 sys/arch/arm/imx/imxi2cvar.h            |  16 ++----
 sys/arch/arm/nxp/imx_i2c.c              |  22 ++++-----
 sys/arch/powerpc/booke/dev/pq3diic.c    |  22 +++-----
 sys/arch/sandpoint/sandpoint/iic_eumb.c |  23 +++------
 sys/dev/acpi/nxpiic_acpi.c              |  30 +++++-------
 sys/dev/i2c/motoi2c.c                   |  40 ++++++++--------
 sys/dev/i2c/motoi2cvar.h                |   6 +-
 9 files changed, 111 insertions(+), 137 deletions(-)

diffs (truncated from 572 to 300 lines):

diff -r 84c6eee6de78 -r 6695f05563ba sys/arch/arm/imx/imx51_i2c.c
--- a/sys/arch/arm/imx/imx51_i2c.c      Fri Jul 22 21:59:11 2022 +0000
+++ b/sys/arch/arm/imx/imx51_i2c.c      Fri Jul 22 23:43:23 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: imx51_i2c.c,v 1.2 2015/03/27 05:31:23 hkenken Exp $    */
+/*     $NetBSD: imx51_i2c.c,v 1.3 2022/07/22 23:43:23 thorpej Exp $    */
 
 /*
  * Copyright (c) 2012, 2015 Genetec Corporation.  All rights reserved.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: imx51_i2c.c,v 1.2 2015/03/27 05:31:23 hkenken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: imx51_i2c.c,v 1.3 2022/07/22 23:43:23 thorpej Exp $");
 
 #include "opt_imx.h"
 
@@ -65,7 +65,7 @@
        if (aa->aa_size <= 0)
                aa->aa_size = I2C_SIZE;
 
-       imxi2c_set_freq(self, imx51_get_clock(IMX51CLK_PERCLK_ROOT), 400000);
-       imxi2c_attach_common(parent, self,
-           aa->aa_iot, aa->aa_addr, aa->aa_size, aa->aa_irq, 0);
+       imxi2c_attach_common(self,
+           aa->aa_iot, aa->aa_addr, aa->aa_size,
+           imx51_get_clock(IMX51CLK_PERCLK_ROOT), 400000);
 }
diff -r 84c6eee6de78 -r 6695f05563ba sys/arch/arm/imx/imxi2c.c
--- a/sys/arch/arm/imx/imxi2c.c Fri Jul 22 21:59:11 2022 +0000
+++ b/sys/arch/arm/imx/imxi2c.c Fri Jul 22 23:43:23 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: imxi2c.c,v 1.3 2019/07/30 06:52:57 hkenken Exp $       */
+/*     $NetBSD: imxi2c.c,v 1.4 2022/07/22 23:43:23 thorpej Exp $       */
 
 /*
  * Copyright (c) 2012, 2015 Genetec Corporation.  All rights reserved.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: imxi2c.c,v 1.3 2019/07/30 06:52:57 hkenken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: imxi2c.c,v 1.4 2022/07/22 23:43:23 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -78,40 +78,9 @@
                bus_space_write_2(sc->sc_iot, sc->sc_ioh, off, data);
 }
 
-int
-imxi2c_attach_common(device_t parent, device_t self,
-    bus_space_tag_t iot, paddr_t iobase, size_t size, int intr, int flags)
+static void
+imxi2c_set_freq(struct imxi2c_softc *imxsc, long freq, unsigned int speed)
 {
-       struct imxi2c_softc *sc = device_private(self);
-       struct motoi2c_softc *msc = &sc->sc_motoi2c;
-       int error;
-
-       aprint_naive("\n");
-       aprint_normal("\n");
-
-       sc->sc_dev = self;
-       msc->sc_iot = iot;
-       error = bus_space_map(msc->sc_iot, iobase, size, 0, &msc->sc_ioh);
-       if (error) {
-               aprint_error_dev(sc->sc_dev,
-                       "failed to map registers (errno=%d)\n", error);
-               return 1;
-       }
-
-       sc->sc_motoi2c_settings.i2c_adr = MOTOI2C_ADR_DEFAULT;
-       sc->sc_motoi2c_settings.i2c_dfsrr = MOTOI2C_DFSRR_DEFAULT;
-       msc->sc_iord = imxi2c_iord1;
-       msc->sc_iowr = imxi2c_iowr1;
-
-       motoi2c_attach_common(self, msc, &sc->sc_motoi2c_settings);
-
-       return 0;
-}
-
-int
-imxi2c_set_freq(device_t self, long freq, int speed)
-{
-       struct imxi2c_softc *sc = device_private(self);
        bool found = false;
        int index;
 
@@ -122,10 +91,40 @@
                }
        }
 
-       if (found == false)
-               sc->sc_motoi2c_settings.i2c_fdr = 0x1f;
-       else
-               sc->sc_motoi2c_settings.i2c_fdr = imxi2c_clk_div[index].ic_val;
+       if (found == false) {
+               imxsc->sc_motoi2c_settings.i2c_fdr = 0x1f;
+       } else {
+               imxsc->sc_motoi2c_settings.i2c_fdr =
+                   imxi2c_clk_div[index].ic_val;
+       }
+}
+
+void
+imxi2c_attach_common(device_t self, bus_space_tag_t iot, paddr_t iobase,
+    size_t size, long freq, unsigned int speed)
+{
+       struct imxi2c_softc *imxsc = device_private(self);
+       struct motoi2c_softc *sc = &imxsc->sc_motoi2c;
+       int error;
+
+       aprint_naive("\n");
+       aprint_normal("\n");
 
-       return 0;
+       sc->sc_dev = self;
+       sc->sc_iot = iot;
+       error = bus_space_map(sc->sc_iot, iobase, size, 0, &sc->sc_ioh);
+       if (error) {
+               aprint_error_dev(sc->sc_dev,
+                       "failed to map registers (errno=%d)\n", error);
+               return;
+       }
+
+       imxsc->sc_motoi2c_settings.i2c_adr = MOTOI2C_ADR_DEFAULT;
+       imxsc->sc_motoi2c_settings.i2c_dfsrr = MOTOI2C_DFSRR_DEFAULT;
+       imxi2c_set_freq(imxsc, freq, speed);
+
+       sc->sc_iord = imxi2c_iord1;
+       sc->sc_iowr = imxi2c_iowr1;
+
+       motoi2c_attach(sc, &imxsc->sc_motoi2c_settings);
 }
diff -r 84c6eee6de78 -r 6695f05563ba sys/arch/arm/imx/imxi2cvar.h
--- a/sys/arch/arm/imx/imxi2cvar.h      Fri Jul 22 21:59:11 2022 +0000
+++ b/sys/arch/arm/imx/imxi2cvar.h      Fri Jul 22 23:43:23 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: imxi2cvar.h,v 1.3 2019/06/20 08:16:19 hkenken Exp $    */
+/*     $NetBSD: imxi2cvar.h,v 1.4 2022/07/22 23:43:23 thorpej Exp $    */
 
 /*
 * Copyright (c) 2012, 2015 Genetec Corporation.  All rights reserved.
@@ -33,22 +33,16 @@
 #include <dev/i2c/motoi2cvar.h>
 
 struct imxi2c_softc {
-       device_t sc_dev;
        struct motoi2c_softc sc_motoi2c;
        struct motoi2c_settings sc_motoi2c_settings;
 
        struct clk *sc_clk;
 };
 
-int imxi2c_attach_common(device_t, device_t,
-    bus_space_tag_t, paddr_t, size_t, int, int);
-int imxi2c_set_freq(device_t, long, int);
+void   imxi2c_attach_common(device_t, bus_space_tag_t, paddr_t, size_t,
+           long, unsigned int);
 
-/*
-* defined in imx51_i2c.c and imx31_i2c.c
-*/
-int imxi2c_match(device_t, cfdata_t, void *);
-void imxi2c_attach(device_t, device_t, void *);
+int    imxi2c_match(device_t, cfdata_t, void *);
+void   imxi2c_attach(device_t, device_t, void *);
 
 #endif /* _IMXI2CVAR_H_ */
-
diff -r 84c6eee6de78 -r 6695f05563ba sys/arch/arm/nxp/imx_i2c.c
--- a/sys/arch/arm/nxp/imx_i2c.c        Fri Jul 22 21:59:11 2022 +0000
+++ b/sys/arch/arm/nxp/imx_i2c.c        Fri Jul 22 23:43:23 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: imx_i2c.c,v 1.2 2021/01/27 03:10:20 thorpej Exp $      */
+/*     $NetBSD: imx_i2c.c,v 1.3 2022/07/22 23:43:24 thorpej Exp $      */
 
 /*-
  * Copyright (c) 2019 Genetec Corporation.  All rights reserved.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: imx_i2c.c,v 1.2 2021/01/27 03:10:20 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: imx_i2c.c,v 1.3 2022/07/22 23:43:24 thorpej Exp $");
 
 #include <sys/bus.h>
 
@@ -51,7 +51,7 @@
 void
 imxi2c_attach(device_t parent __unused, device_t self, void *aux)
 {
-       struct imxi2c_softc *sc = device_private(self);
+       struct imxi2c_softc *imxsc = device_private(self);
        struct fdt_attach_args * const faa = aux;
        const int phandle = faa->faa_phandle;
        bus_space_tag_t bst = faa->faa_bst;
@@ -64,15 +64,15 @@
                return;
        }
 
-       sc->sc_clk = fdtbus_clock_get_index(phandle, 0);
-       if (sc->sc_clk == NULL) {
+       imxsc->sc_clk = fdtbus_clock_get_index(phandle, 0);
+       if (imxsc->sc_clk == NULL) {
                aprint_error(": couldn't get clock\n");
                return;
        }
 
-       error = clk_enable(sc->sc_clk);
+       error = clk_enable(imxsc->sc_clk);
        if (error) {
-               aprint_error_dev(sc->sc_dev, "couldn't enable: %d\n", error);
+               aprint_error_dev(self, "couldn't enable: %d\n", error);
                return;
        }
 
@@ -80,10 +80,8 @@
        error = of_getprop_uint32(phandle, "clock-frequency", &freq);
        if (error)
                freq = 100000;
-       imxi2c_set_freq(self, clk_get_rate(sc->sc_clk), freq);
 
-       sc->sc_motoi2c.sc_phandle = phandle;
-
-       imxi2c_attach_common(parent, self, bst, addr, size, -1, 0);
+       imxsc->sc_motoi2c.sc_phandle = phandle;
+       imxi2c_attach_common(self, bst, addr, size,
+           clk_get_rate(imxsc->sc_clk), freq);
 }
-
diff -r 84c6eee6de78 -r 6695f05563ba sys/arch/powerpc/booke/dev/pq3diic.c
--- a/sys/arch/powerpc/booke/dev/pq3diic.c      Fri Jul 22 21:59:11 2022 +0000
+++ b/sys/arch/powerpc/booke/dev/pq3diic.c      Fri Jul 22 23:43:23 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pq3diic.c,v 1.6 2022/07/22 20:09:47 thorpej Exp $      */
+/*     $NetBSD: pq3diic.c,v 1.7 2022/07/22 23:43:24 thorpej Exp $      */
 /*-
  * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pq3diic.c,v 1.6 2022/07/22 20:09:47 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pq3diic.c,v 1.7 2022/07/22 23:43:24 thorpej Exp $");
 
 #include "ioconf.h"
 
@@ -56,15 +56,10 @@
 #include <powerpc/booke/e500var.h>
 #include <powerpc/booke/e500reg.h>
 
-struct pq3diic_softc {
-       device_t sc_dev;
-       struct motoi2c_softc sc_motoi2c;
-};
-
 static int pq3diic_match(device_t, cfdata_t, void *);
 static void pq3diic_attach(device_t, device_t, void *);
 
-CFATTACH_DECL_NEW(pq3diic, sizeof(struct pq3diic_softc),
+CFATTACH_DECL_NEW(pq3diic, sizeof(struct motoi2c_softc),
     pq3diic_match, pq3diic_attach, NULL, NULL);
 
 static int
@@ -91,8 +86,7 @@
 pq3diic_attach(device_t parent, device_t self, void *aux)
 {
        struct cpunode_softc * const psc = device_private(parent);
-       struct pq3diic_softc * const sc = device_private(self);
-       struct motoi2c_softc * const msc = &sc->sc_motoi2c;
+       struct motoi2c_softc * const sc = device_private(self);
        struct cpunode_attach_args * const cna = aux;
        struct cpunode_locators * const cnl = &cna->cna_locs;
        int error;
@@ -102,16 +96,16 @@
 
        aprint_normal("\n");
 
-       msc->sc_iot = cna->cna_memt;
-       error = bus_space_map(msc->sc_iot, cnl->cnl_addr, I2C_SIZE,
-           0, &msc->sc_ioh);
+       sc->sc_iot = cna->cna_memt;
+       error = bus_space_map(sc->sc_iot, cnl->cnl_addr, I2C_SIZE,
+           0, &sc->sc_ioh);
        if (error) {
                aprint_error_dev(self,
                    "can't map registers (error = %d)\n", error);
                return;
        }
 
-       motoi2c_attach_common(self, msc, NULL);
+       motoi2c_attach(sc, NULL);
 
 #if 0
        /*
diff -r 84c6eee6de78 -r 6695f05563ba sys/arch/sandpoint/sandpoint/iic_eumb.c



Home | Main Index | Thread Index | Old Index