Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/i2c Add support FDT.



details:   https://anonhg.NetBSD.org/src/rev/b6c261d3f780
branches:  trunk
changeset: 964500:b6c261d3f780
user:      hkenken <hkenken%NetBSD.org@localhost>
date:      Mon Aug 05 12:21:00 2019 +0000

description:
Add support FDT.

diffstat:

 sys/arch/arm/imx/fdt/imx6_i2c.c |   7 +++++--
 sys/dev/i2c/motoi2c.c           |  33 +++++++++++++++++++++++++++++++--
 sys/dev/i2c/motoi2cvar.h        |   3 ++-
 3 files changed, 38 insertions(+), 5 deletions(-)

diffs (114 lines):

diff -r 70c451c60a5f -r b6c261d3f780 sys/arch/arm/imx/fdt/imx6_i2c.c
--- a/sys/arch/arm/imx/fdt/imx6_i2c.c   Mon Aug 05 10:25:41 2019 +0000
+++ b/sys/arch/arm/imx/fdt/imx6_i2c.c   Mon Aug 05 12:21:00 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: imx6_i2c.c,v 1.1 2019/07/30 06:52:57 hkenken Exp $     */
+/*     $NetBSD: imx6_i2c.c,v 1.2 2019/08/05 12:21:00 hkenken Exp $     */
 /*-
  * Copyright (c) 2019 Genetec Corporation.  All rights reserved.
  * Written by Hashimoto Kenichi for Genetec Corporation.
@@ -25,7 +25,7 @@
  * SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: imx6_i2c.c,v 1.1 2019/07/30 06:52:57 hkenken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: imx6_i2c.c,v 1.2 2019/08/05 12:21:00 hkenken Exp $");
 
 #include <sys/bus.h>
 
@@ -75,6 +75,9 @@
        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);
 }
 
diff -r 70c451c60a5f -r b6c261d3f780 sys/dev/i2c/motoi2c.c
--- a/sys/dev/i2c/motoi2c.c     Mon Aug 05 10:25:41 2019 +0000
+++ b/sys/dev/i2c/motoi2c.c     Mon Aug 05 12:21:00 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: motoi2c.c,v 1.4 2011/04/17 15:14:59 phx Exp $ */
+/* $NetBSD: motoi2c.c,v 1.5 2019/08/05 12:21:00 hkenken Exp $ */
 
 /*-
  * Copyright (c) 2007, 2010 The NetBSD Foundation, Inc.
@@ -30,7 +30,11 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: motoi2c.c,v 1.4 2011/04/17 15:14:59 phx Exp $");
+__KERNEL_RCSID(0, "$NetBSD: motoi2c.c,v 1.5 2019/08/05 12:21:00 hkenken Exp $");
+
+#if defined(__arm__) || defined(__aarch64__)
+#include "opt_fdt.h"
+#endif
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -43,6 +47,10 @@
 #include <dev/i2c/motoi2creg.h>
 #include <dev/i2c/motoi2cvar.h>
 
+#ifdef FDT
+#include <dev/fdt/fdtvar.h>
+#endif
+
 #ifdef DEBUG
 int motoi2c_debug = 0;
 #define        DPRINTF(x)      if (motoi2c_debug) printf x
@@ -50,6 +58,20 @@
 #define        DPRINTF(x)
 #endif
 
+#ifdef FDT
+static i2c_tag_t
+motoi2c_get_tag(device_t dev)
+{
+       struct motoi2c_softc * const sc = device_private(dev);
+
+       return &sc->sc_i2c;
+}
+
+static const struct fdtbus_i2c_controller_func motoi2c_funcs = {
+       .get_tag = motoi2c_get_tag,
+};
+#endif
+
 static int  motoi2c_acquire_bus(void *, int);
 static void motoi2c_release_bus(void *, int);
 static int  motoi2c_exec(void *, i2c_op_t, i2c_addr_t, const void *, size_t,
@@ -111,7 +133,14 @@
        I2C_WRITE(I2CADR, i2c->i2c_adr);        /* our slave address is 0x7f */
        I2C_WRITE(I2CSR, 0);            /* clear status flags */
 
+#ifdef FDT
+       KASSERT(sc->sc_phandle != 0);
+       fdtbus_register_i2c_controller(self, sc->sc_phandle, &motoi2c_funcs);
+
+       fdtbus_attach_i2cbus(self, sc->sc_phandle, &sc->sc_i2c, iicbus_print);
+#else
        config_found_ia(self, "i2cbus", &iba, iicbus_print);
+#endif
 }
 
 static int
diff -r 70c451c60a5f -r b6c261d3f780 sys/dev/i2c/motoi2cvar.h
--- a/sys/dev/i2c/motoi2cvar.h  Mon Aug 05 10:25:41 2019 +0000
+++ b/sys/dev/i2c/motoi2cvar.h  Mon Aug 05 12:21:00 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: motoi2cvar.h,v 1.4 2011/04/17 15:14:59 phx Exp $ */
+/* $NetBSD: motoi2cvar.h,v 1.5 2019/08/05 12:21:00 hkenken Exp $ */
 
 /*-
  * Copyright (c) 2007, 2010 The NetBSD Foundation, Inc.
@@ -51,6 +51,7 @@
        kmutex_t                sc_buslock;
        motoi2c_iord_t          sc_iord;
        motoi2c_iowr_t          sc_iowr;
+       int                     sc_phandle;
 };
 
 #define        MOTOI2C_ADR_DEFAULT     (0x7e << 1)



Home | Main Index | Thread Index | Old Index