Module Name: src
Committed By: hkenken
Date: Mon Aug 5 12:21:00 UTC 2019
Modified Files:
src/sys/arch/arm/imx/fdt: imx6_i2c.c
src/sys/dev/i2c: motoi2c.c motoi2cvar.h
Log Message:
Add support FDT.
To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/arm/imx/fdt/imx6_i2c.c
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/i2c/motoi2c.c \
src/sys/dev/i2c/motoi2cvar.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/fdt/imx6_i2c.c
diff -u src/sys/arch/arm/imx/fdt/imx6_i2c.c:1.1 src/sys/arch/arm/imx/fdt/imx6_i2c.c:1.2
--- src/sys/arch/arm/imx/fdt/imx6_i2c.c:1.1 Tue Jul 30 06:52:57 2019
+++ src/sys/arch/arm/imx/fdt/imx6_i2c.c Mon Aug 5 12:21:00 2019
@@ -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 @@ imxi2c_attach(device_t parent __unused,
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);
}
Index: src/sys/dev/i2c/motoi2c.c
diff -u src/sys/dev/i2c/motoi2c.c:1.4 src/sys/dev/i2c/motoi2c.c:1.5
--- src/sys/dev/i2c/motoi2c.c:1.4 Sun Apr 17 15:14:59 2011
+++ src/sys/dev/i2c/motoi2c.c Mon Aug 5 12:21:00 2019
@@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: motoi2c.c,v
#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 @@ int motoi2c_debug = 0;
#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 @@ motoi2c_attach_common(device_t self, str
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
Index: src/sys/dev/i2c/motoi2cvar.h
diff -u src/sys/dev/i2c/motoi2cvar.h:1.4 src/sys/dev/i2c/motoi2cvar.h:1.5
--- src/sys/dev/i2c/motoi2cvar.h:1.4 Sun Apr 17 15:14:59 2011
+++ src/sys/dev/i2c/motoi2cvar.h Mon Aug 5 12:21:00 2019
@@ -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 @@ struct motoi2c_softc {
kmutex_t sc_buslock;
motoi2c_iord_t sc_iord;
motoi2c_iowr_t sc_iowr;
+ int sc_phandle;
};
#define MOTOI2C_ADR_DEFAULT (0x7e << 1)