Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch Add i2c glue.
details: https://anonhg.NetBSD.org/src/rev/6958457630fb
branches: trunk
changeset: 354781:6958457630fb
user: jmcneill <jmcneill%NetBSD.org@localhost>
date: Thu Jun 29 19:16:08 2017 +0000
description:
Add i2c glue.
diffstat:
sys/arch/arm/sunxi/files.sunxi | 7 +-
sys/arch/arm/sunxi/sunxi_twi.c | 151 +++++++++++++++++++++++++++++++++++++++++
sys/arch/evbarm/conf/SUNXI | 7 +-
3 files changed, 161 insertions(+), 4 deletions(-)
diffs (198 lines):
diff -r f4640c9a7f3f -r 6958457630fb sys/arch/arm/sunxi/files.sunxi
--- a/sys/arch/arm/sunxi/files.sunxi Thu Jun 29 18:52:23 2017 +0000
+++ b/sys/arch/arm/sunxi/files.sunxi Thu Jun 29 19:16:08 2017 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.sunxi,v 1.3 2017/06/29 17:08:52 jmcneill Exp $
+# $NetBSD: files.sunxi,v 1.4 2017/06/29 19:16:08 jmcneill Exp $
#
# Configuration info for Allwinner sunxi family SoCs
#
@@ -52,6 +52,11 @@
attach ohci at fdt with ohci_fdt
file dev/fdt/ohci_fdt.c ohci_fdt
+# TWI
+device sunxitwi: i2cbus, i2cexec, mvi2c
+attach sunxitwi at fdt with sunxi_twi
+file arch/arm/sunxi/sunxi_twi.c sunxi_twi
+
# SOC parameters
defflag opt_soc.h SOC_SUNXI
defflag opt_soc.h SOC_SUN8I: SOC_SUNXI
diff -r f4640c9a7f3f -r 6958457630fb sys/arch/arm/sunxi/sunxi_twi.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/sunxi/sunxi_twi.c Thu Jun 29 19:16:08 2017 +0000
@@ -0,0 +1,151 @@
+/* $NetBSD: sunxi_twi.c,v 1.1 2017/06/29 19:16:08 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2017 Jared McNeill <jmcneill%invisible.ca@localhost>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+
+__KERNEL_RCSID(0, "$NetBSD: sunxi_twi.c,v 1.1 2017/06/29 19:16:08 jmcneill Exp $");
+
+#include <sys/param.h>
+#include <sys/bus.h>
+#include <sys/device.h>
+#include <sys/intr.h>
+#include <sys/systm.h>
+#include <sys/time.h>
+
+#include <dev/i2c/i2cvar.h>
+#include <dev/i2c/gttwsivar.h>
+
+#include <dev/fdt/fdtvar.h>
+
+static int sunxi_twi_match(device_t, cfdata_t, void *);
+static void sunxi_twi_attach(device_t, device_t, void *);
+
+static const char * const compatible[] = {
+ "allwinner,sun6i-a31-i2c",
+ NULL
+};
+
+CFATTACH_DECL_NEW(sunxi_twi, sizeof(struct gttwsi_softc),
+ sunxi_twi_match, sunxi_twi_attach, NULL, NULL);
+
+static i2c_tag_t
+sunxi_twi_get_tag(device_t dev)
+{
+ struct gttwsi_softc * const sc = device_private(dev);
+
+ return &sc->sc_i2c;
+}
+
+const struct fdtbus_i2c_controller_func sunxi_twi_funcs = {
+ .get_tag = sunxi_twi_get_tag,
+};
+
+static int
+sunxi_twi_match(device_t parent, cfdata_t cf, void *aux)
+{
+ struct fdt_attach_args * const faa = aux;
+
+ return of_match_compatible(faa->faa_phandle, compatible);
+}
+
+static void
+sunxi_twi_attach(device_t parent, device_t self, void *aux)
+{
+ struct gttwsi_softc * const sc = device_private(self);
+ struct fdt_attach_args * const faa = aux;
+ struct i2cbus_attach_args iba;
+ const int phandle = faa->faa_phandle;
+ bus_space_tag_t bst = faa->faa_bst;
+ bus_space_handle_t bsh;
+ prop_dictionary_t devs;
+ uint32_t address_cells;
+ struct fdtbus_reset *rst;
+ struct clk *clk;
+ char intrstr[128];
+ bus_addr_t addr;
+ bus_size_t size;
+ void *ih;
+
+ if (fdtbus_get_reg(phandle, 0, &addr, &size) != 0) {
+ aprint_error(": couldn't get registers\n");
+ return;
+ }
+
+ if (bus_space_map(bst, addr, size, 0, &bsh) != 0) {
+ aprint_error(": couldn't map registers\n");
+ return;
+ }
+
+ if (!fdtbus_intr_str(phandle, 0, intrstr, sizeof(intrstr))) {
+ aprint_error(": failed to decode interrupt\n");
+ return;
+ }
+
+ if ((clk = fdtbus_clock_get_index(phandle, 0)) != NULL)
+ if (clk_enable(clk) != 0) {
+ aprint_error(": couldn't enable clock\n");
+ return;
+ }
+ if ((rst = fdtbus_reset_get_index(phandle, 0)) != NULL)
+ if (fdtbus_reset_deassert(rst) != 0) {
+ aprint_error(": couldn't de-assert reset\n");
+ return;
+ }
+
+ gttwsi_attach_subr(self, bst, bsh);
+
+ aprint_naive("\n");
+ aprint_normal(": TWI\n");
+
+ ih = fdtbus_intr_establish(phandle, 0, IPL_VM, 0, gttwsi_intr, sc);
+ if (ih == NULL) {
+ aprint_error_dev(self, "couldn't establish interrupt on %s\n",
+ intrstr);
+ return;
+ }
+ aprint_normal_dev(self, "interrupting on %s\n", intrstr);
+
+ fdtbus_register_i2c_controller(self, phandle, &sunxi_twi_funcs);
+
+ devs = prop_dictionary_create();
+ if (of_getprop_uint32(phandle, "#address-cells", &address_cells))
+ address_cells = 1;
+
+ of_enter_i2c_devs(devs, phandle, address_cells * 4, 0);
+
+ memset(&iba, 0, sizeof(iba));
+ iba.iba_tag = &sc->sc_i2c;
+ iba.iba_child_devices = prop_dictionary_get(devs, "i2c-child-devices");
+ if (iba.iba_child_devices)
+ prop_object_retain(iba.iba_child_devices);
+ else
+ iba.iba_child_devices = prop_array_create();
+ prop_object_release(devs);
+
+ config_found_ia(self, "i2cbus", &iba, iicbus_print);
+}
diff -r f4640c9a7f3f -r 6958457630fb sys/arch/evbarm/conf/SUNXI
--- a/sys/arch/evbarm/conf/SUNXI Thu Jun 29 18:52:23 2017 +0000
+++ b/sys/arch/evbarm/conf/SUNXI Thu Jun 29 19:16:08 2017 +0000
@@ -1,5 +1,5 @@
#
-# $NetBSD: SUNXI,v 1.4 2017/06/29 17:20:59 jmcneill Exp $
+# $NetBSD: SUNXI,v 1.5 2017/06/29 19:16:08 jmcneill Exp $
#
# Allwinner sunxi family
#
@@ -85,8 +85,9 @@
options COM_AWIN # XXX this should be a driver flag
# I2C
-#sunxiiic* at fdt? # I2C
-#iic* at sunxiiic?
+sunxitwi* at fdt? # TWI
+options GTTWSI_ALLWINNER # XXX this should be a driver flag
+iic* at sunxitwi?
# RTC
Home |
Main Index |
Thread Index |
Old Index