Module Name:    src
Committed By:   jdc
Date:           Fri Feb 21 12:23:30 UTC 2014

Modified Files:
        src/sys/arch/alpha/conf: files.alpha
        src/sys/arch/alpha/pci: tsc.c tsreg.h tsvar.h
Added Files:
        src/sys/arch/alpha/pci: tsciic.c

Log Message:
Add tsciic, a driver for the DECchip 21272 Core Logic chipset I2C controller.
Tested on DS20L.


To generate a diff of this commit:
cvs rdiff -u -r1.185 -r1.186 src/sys/arch/alpha/conf/files.alpha
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/alpha/pci/tsc.c
cvs rdiff -u -r0 -r1.1 src/sys/arch/alpha/pci/tsciic.c
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/alpha/pci/tsreg.h
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/alpha/pci/tsvar.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/alpha/conf/files.alpha
diff -u src/sys/arch/alpha/conf/files.alpha:1.185 src/sys/arch/alpha/conf/files.alpha:1.186
--- src/sys/arch/alpha/conf/files.alpha:1.185	Tue Oct  2 23:54:51 2012
+++ src/sys/arch/alpha/conf/files.alpha	Fri Feb 21 12:23:30 2014
@@ -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_pci.c	tsp
 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

Index: src/sys/arch/alpha/pci/tsc.c
diff -u src/sys/arch/alpha/pci/tsc.c:1.22 src/sys/arch/alpha/pci/tsc.c:1.23
--- src/sys/arch/alpha/pci/tsc.c:1.22	Mon Sep 23 16:50:12 2013
+++ src/sys/arch/alpha/pci/tsc.c	Fri Feb 21 12:23:30 2014
@@ -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 @@ extern struct cfdriver tsp_cd;
 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 @@ tscattach(device_t parent, device_t self
 	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 @@ tscattach(device_t parent, device_t self
 			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 @@ tscprint(void *aux, const char *p)
 	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 @@ tsp_bus_get_window(int type, int window,
 	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)
 {

Index: src/sys/arch/alpha/pci/tsreg.h
diff -u src/sys/arch/alpha/pci/tsreg.h:1.6 src/sys/arch/alpha/pci/tsreg.h:1.7
--- src/sys/arch/alpha/pci/tsreg.h:1.6	Mon Sep 23 16:41:57 2013
+++ src/sys/arch/alpha/pci/tsreg.h	Fri Feb 21 12:23:30 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: tsreg.h,v 1.6 2013/09/23 16:41:57 tsutsui Exp $ */
+/* $NetBSD: tsreg.h,v 1.7 2014/02/21 12:23:30 jdc Exp $ */
 
 /*-
  * Copyright (c) 1999 by Ross Harvey.  All rights reserved.
@@ -95,6 +95,11 @@
 
 #define TS_C_MPD	0x101##a000##00c0UL
 
+#	define	MPD_DR	0x08	/* RO: Data receive */
+#	define	MPD_CKR	0x04	/* RO: Clock receive */
+#	define	MPD_DS	0x02	/* WO: Data send - Must be a 1 to receive */
+#	define	MPD_CKS	0x01	/* WO: Clock send */
+
 #define TS_C_AAR0	0x101##a000##0100UL
 #define TS_C_AAR1	0x101##a000##0140UL
 #define TS_C_AAR2	0x101##a000##0180UL

Index: src/sys/arch/alpha/pci/tsvar.h
diff -u src/sys/arch/alpha/pci/tsvar.h:1.11 src/sys/arch/alpha/pci/tsvar.h:1.12
--- src/sys/arch/alpha/pci/tsvar.h:1.11	Mon Sep 23 16:41:57 2013
+++ src/sys/arch/alpha/pci/tsvar.h	Fri Feb 21 12:23:30 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: tsvar.h,v 1.11 2013/09/23 16:41:57 tsutsui Exp $ */
+/* $NetBSD: tsvar.h,v 1.12 2014/02/21 12:23:30 jdc Exp $ */
 
 /*-
  * Copyright (c) 1999 by Ross Harvey.  All rights reserved.
@@ -33,6 +33,7 @@
 
 #include <dev/isa/isavar.h>
 #include <dev/pci/pcivar.h>
+#include <dev/i2c/i2cvar.h>
 #include <alpha/pci/pci_sgmap_pte64.h>
 
 #define	_FSTORE	(EXTENT_FIXED_STORAGE_SIZE(8) / sizeof(long))
@@ -68,6 +69,16 @@ struct tsp_attach_args {
 	int	tsp_slot;
 };
 
+struct tsciic_softc {
+	device_t	sc_dev;
+	struct		i2c_controller sc_i2c;
+	kmutex_t	sc_buslock;
+};
+
+struct tsciic_attach_args {
+	const char *tsciic_name;
+};
+
 extern int tsp_console_hose;
 
 struct	tsp_config *tsp_init(int, int);
@@ -79,6 +90,8 @@ void	tsp_bus_mem_init(bus_space_tag_t, v
 
 void	tsp_bus_mem_init2(bus_space_tag_t, void *);
 
+void	tsciic_init(device_t);
+
 void	tsp_print_error(unsigned int, unsigned long);
 void	tsc_print_misc(unsigned int, unsigned long);
 void	tsc_print_dir(unsigned int, unsigned long);

Added files:

Index: src/sys/arch/alpha/pci/tsciic.c
diff -u /dev/null src/sys/arch/alpha/pci/tsciic.c:1.1
--- /dev/null	Fri Feb 21 12:23:30 2014
+++ src/sys/arch/alpha/pci/tsciic.c	Fri Feb 21 12:23:30 2014
@@ -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
+tsciic_write_byte(void *cookie, uint8_t val, int flags)
+{
+	return (i2c_bitbang_write_byte(cookie, val, flags, &tsciicbb_ops));
+}

Reply via email to