Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/alpha Add tsciic, a driver for the DECchip 21272 Co...
details: https://anonhg.NetBSD.org/src/rev/f24634e1b3e7
branches: trunk
changeset: 326885:f24634e1b3e7
user: jdc <jdc%NetBSD.org@localhost>
date: Fri Feb 21 12:23:30 2014 +0000
description:
Add tsciic, a driver for the DECchip 21272 Core Logic chipset I2C controller.
Tested on DS20L.
diffstat:
sys/arch/alpha/conf/files.alpha | 6 +-
sys/arch/alpha/pci/tsc.c | 54 +++++++++++-
sys/arch/alpha/pci/tsciic.c | 177 ++++++++++++++++++++++++++++++++++++++++
sys/arch/alpha/pci/tsreg.h | 7 +-
sys/arch/alpha/pci/tsvar.h | 15 +++-
5 files changed, 254 insertions(+), 5 deletions(-)
diffs (truncated from 368 to 300 lines):
diff -r 50b8455ac3e3 -r f24634e1b3e7 sys/arch/alpha/conf/files.alpha
--- a/sys/arch/alpha/conf/files.alpha Fri Feb 21 10:52:50 2014 +0000
+++ b/sys/arch/alpha/conf/files.alpha Fri Feb 21 12:23:30 2014 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.alpha,v 1.185 2012/10/02 23:54:51 christos Exp $
+# $NetBSD: files.alpha,v 1.186 2014/02/21 12:23:30 jdc Exp $
#
# alpha-specific configuration info
@@ -275,6 +275,10 @@
file arch/alpha/pci/tsp_bus_io.c tsp
file arch/alpha/pci/tsp_bus_mem.c tsp
+device tsciic: i2cbus, i2c_bitbang
+attach tsciic at tsc
+file arch/alpha/pci/tsciic.c tsciic
+
device ttwoga { hose = -1 }
attach ttwoga at mainbus
# identical to pcibus
diff -r 50b8455ac3e3 -r f24634e1b3e7 sys/arch/alpha/pci/tsc.c
--- a/sys/arch/alpha/pci/tsc.c Fri Feb 21 10:52:50 2014 +0000
+++ b/sys/arch/alpha/pci/tsc.c Fri Feb 21 12:23:30 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tsc.c,v 1.22 2013/09/23 16:50:12 tsutsui Exp $ */
+/* $NetBSD: tsc.c,v 1.23 2014/02/21 12:23:30 jdc Exp $ */
/*-
* Copyright (c) 1999 by Ross Harvey. All rights reserved.
@@ -35,7 +35,7 @@
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tsc.c,v 1.22 2013/09/23 16:50:12 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tsc.c,v 1.23 2014/02/21 12:23:30 jdc Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -80,6 +80,16 @@
static int tsp_bus_get_window(int, int,
struct alpha_bus_space_translation *);
+static int tsciicprint(void *, const char *pnp);
+
+static int tsciicmatch(device_t, cfdata_t, void *);
+static void tsciicattach(device_t, device_t, void *);
+
+CFATTACH_DECL_NEW(tsciic, sizeof(struct tsciic_softc), tsciicmatch,
+ tsciicattach, NULL, NULL);
+
+extern struct cfdriver tsciic_cd;
+
/* There can be only one */
static int tscfound;
@@ -107,6 +117,7 @@
int nbus;
uint64_t csc, aar;
struct tsp_attach_args tsp;
+ struct tsciic_attach_args tsciic;
struct mainbus_attach_args *ma = aux;
int titan = cputype == ST_DEC_TITAN;
@@ -146,6 +157,11 @@
config_found(self, &tsp, tscprint);
}
}
+
+ memset(&tsciic, 0, sizeof tsciic);
+ tsciic.tsciic_name = "tsciic";
+
+ config_found(self, &tsciic, tsciicprint);
}
static int
@@ -158,6 +174,18 @@
return UNCONF;
}
+static int
+tsciicprint(void *aux, const char *p)
+{
+ struct tsciic_attach_args *tsciic = aux;
+
+ if (p)
+ aprint_normal("%s at %s\n", tsciic->tsciic_name, p);
+ else
+ aprint_normal("\n");
+ return UNCONF;
+}
+
#define tsp() { Generate ctags(1) key. }
static int
@@ -277,6 +305,28 @@
return 0;
}
+#define tsciic() { Generate ctags(1) key. }
+
+static int
+tsciicmatch(device_t parent, cfdata_t match, void *aux)
+{
+ struct tsciic_attach_args *t = aux;
+
+ switch (cputype) {
+ case ST_DEC_6600:
+ case ST_DEC_TITAN:
+ return strcmp(t->tsciic_name, tsciic_cd.cd_name) == 0;
+ default:
+ return 0;
+ }
+}
+
+static void
+tsciicattach(device_t parent, device_t self, void *aux)
+{
+ tsciic_init(self);
+}
+
void
tsc_print_dir(unsigned int indent, unsigned long dir)
{
diff -r 50b8455ac3e3 -r f24634e1b3e7 sys/arch/alpha/pci/tsciic.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/alpha/pci/tsciic.c Fri Feb 21 12:23:30 2014 +0000
@@ -0,0 +1,177 @@
+/* $NetBSD: tsciic.c,v 1.1 2014/02/21 12:23:30 jdc Exp $ */
+
+/*
+ * Copyright (c) 2013 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Julian Coleman.
+ *
+ * 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: tsciic.c,v 1.1 2014/02/21 12:23:30 jdc Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+
+#include <alpha/pci/tsreg.h>
+#include <alpha/pci/tsvar.h>
+
+#include <dev/i2c/i2cvar.h>
+#include <dev/i2c/i2c_bitbang.h>
+#include <dev/i2c/ddcvar.h>
+
+/* I2C glue */
+static int tsciic_acquire_bus(void *, int);
+static void tsciic_release_bus(void *, int);
+static int tsciic_send_start(void *, int);
+static int tsciic_send_stop(void *, int);
+static int tsciic_initiate_xfer(void *, i2c_addr_t, int);
+static int tsciic_read_byte(void *, uint8_t *, int);
+static int tsciic_write_byte(void *, uint8_t, int);
+
+/* I2C bitbang glue */
+static void tsciicbb_set_bits(void *, uint32_t);
+static void tsciicbb_set_dir(void *, uint32_t);
+static uint32_t tsciicbb_read(void *);
+
+#define MPD_BIT_SDA 0x01
+#define MPD_BIT_SCL 0x02
+static const struct i2c_bitbang_ops tsciicbb_ops = {
+ tsciicbb_set_bits,
+ tsciicbb_set_dir,
+ tsciicbb_read,
+ {
+ MPD_BIT_SDA,
+ MPD_BIT_SCL,
+ 0,
+ 0
+ }
+};
+
+void
+tsciic_init(device_t self) {
+ struct tsciic_softc *sc = device_private(self);
+ struct i2cbus_attach_args iba;
+
+ mutex_init(&sc->sc_buslock, MUTEX_DEFAULT, IPL_NONE);
+
+ sc->sc_i2c.ic_cookie = sc;
+ sc->sc_i2c.ic_acquire_bus = tsciic_acquire_bus;
+ sc->sc_i2c.ic_release_bus = tsciic_release_bus;
+ sc->sc_i2c.ic_send_start = tsciic_send_start;
+ sc->sc_i2c.ic_send_stop = tsciic_send_stop;
+ sc->sc_i2c.ic_initiate_xfer = tsciic_initiate_xfer;
+ sc->sc_i2c.ic_read_byte = tsciic_read_byte;
+ sc->sc_i2c.ic_write_byte = tsciic_write_byte;
+ sc->sc_i2c.ic_exec = NULL;
+
+ memset(&iba, 0, sizeof(iba));
+ iba.iba_tag = &sc->sc_i2c;
+
+ config_found_ia(self, "i2cbus", &iba, iicbus_print);
+
+}
+
+/* I2C bitbanging */
+static void
+tsciicbb_set_bits(void *cookie, uint32_t bits)
+{
+ uint64_t val;
+
+ val = (bits & MPD_BIT_SDA ? MPD_DS : 0) |
+ (bits & MPD_BIT_SCL ? MPD_CKS : 0);
+ alpha_mb();
+ STQP(TS_C_MPD) = val;
+ alpha_mb();
+}
+
+static void
+tsciicbb_set_dir(void *cookie, uint32_t dir)
+{
+ /* Nothing to do */
+}
+
+static uint32_t
+tsciicbb_read(void *cookie)
+{
+ uint64_t val;
+ uint32_t bits;
+
+ val = LDQP(TS_C_MPD);
+ bits = (val & MPD_DR ? MPD_BIT_SDA : 0) |
+ (val & MPD_CKR ? MPD_BIT_SCL : 0);
+ return bits;
+}
+
+/* higher level I2C stuff */
+static int
+tsciic_acquire_bus(void *cookie, int flags)
+{
+ struct tsciic_softc *sc = cookie;
+
+ mutex_enter(&sc->sc_buslock);
+ return 0;
+}
+
+static void
+tsciic_release_bus(void *cookie, int flags)
+{
+ struct tsciic_softc *sc = cookie;
+
+ mutex_exit(&sc->sc_buslock);
+}
+
+static int
+tsciic_send_start(void *cookie, int flags)
+{
+ return (i2c_bitbang_send_start(cookie, flags, &tsciicbb_ops));
+}
+
+static int
+tsciic_send_stop(void *cookie, int flags)
+{
+ return (i2c_bitbang_send_stop(cookie, flags, &tsciicbb_ops));
+}
+
+static int
+tsciic_initiate_xfer(void *cookie, i2c_addr_t addr, int flags)
+{
+ return (i2c_bitbang_initiate_xfer(cookie, addr, flags,
+ &tsciicbb_ops));
+}
+
+static int
+tsciic_read_byte(void *cookie, uint8_t *valp, int flags)
+{
+ return (i2c_bitbang_read_byte(cookie, valp, flags, &tsciicbb_ops));
+}
+
+static int
Home |
Main Index |
Thread Index |
Old Index