summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@cvs.openbsd.org>2005-11-11 16:22:51 +0000
committerMark Kettenis <kettenis@cvs.openbsd.org>2005-11-11 16:22:51 +0000
commit40f3eaf2ff9a19b7ea7c86c987834c759afb1e7e (patch)
tree95a6053aada1bed1cebefbfc79c6102cdf675a4c /sys
parent3b64408ee0613637240a5c91711675f7940a506e (diff)
Add maciic(4), an OpenFirware aware version of iic(4).
Diffstat (limited to 'sys')
-rw-r--r--sys/arch/macppc/conf/files.macppc13
-rw-r--r--sys/arch/macppc/dev/maci2c.c80
-rw-r--r--sys/arch/macppc/dev/maci2cvar.h32
3 files changed, 123 insertions, 2 deletions
diff --git a/sys/arch/macppc/conf/files.macppc b/sys/arch/macppc/conf/files.macppc
index 7c04d52f492..0b566bcf49a 100644
--- a/sys/arch/macppc/conf/files.macppc
+++ b/sys/arch/macppc/conf/files.macppc
@@ -1,4 +1,4 @@
-# $OpenBSD: files.macppc,v 1.32 2005/11/06 03:10:09 drahn Exp $
+# $OpenBSD: files.macppc,v 1.33 2005/11/11 16:22:50 kettenis Exp $
#
# macppc-specific configuration info
@@ -77,7 +77,7 @@ device ht {} : pcibus
attach ht at mainbus
file arch/macppc/pci/ht.c ht
-device smu
+device smu {}
attach smu at mainbus
file arch/macppc/dev/smu.c smu
file dev/clock_subr.c smu
@@ -261,6 +261,15 @@ include "dev/pcmcia/files.pcmcia"
#
include "dev/usb/files.usb"
+#
+# Machine-independent I2C drivers
+#
+include "dev/i2c/files.i2c"
+
+device maciic {}
+attach maciic at smu
+file arch/macppc/dev/maci2c.c maciic
+
# Sun HME Ethernet controllers
device hme: ether, ifnet, mii, ifmedia
file dev/ic/hme.c
diff --git a/sys/arch/macppc/dev/maci2c.c b/sys/arch/macppc/dev/maci2c.c
new file mode 100644
index 00000000000..caea3cf2ab9
--- /dev/null
+++ b/sys/arch/macppc/dev/maci2c.c
@@ -0,0 +1,80 @@
+/* $OpenBSD: maci2c.c,v 1.1 2005/11/11 16:22:50 kettenis Exp $ */
+
+/*
+ * Copyright (c) 2005 Mark Kettenis
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+
+#include <dev/i2c/i2cvar.h>
+#include <dev/ofw/openfirm.h>
+
+#include <arch/macppc/dev/maci2cvar.h>
+
+int maciic_match(struct device *, void *, void *);
+void maciic_attach(struct device *, struct device *, void *);
+int maciic_print(void *, const char *);
+
+struct cfattach maciic_ca = {
+ sizeof (struct device), maciic_match, maciic_attach
+};
+
+struct cfdriver maciic_cd = {
+ NULL, "maciic", DV_DULL
+};
+
+int
+maciic_match(struct device *parent, void *cf, void *aux)
+{
+ return (1);
+}
+
+void
+maciic_attach(struct device *parent, struct device *self, void *aux)
+{
+ struct maci2cbus_attach_args *iba = aux;
+ struct maci2c_attach_args ia;
+ u_int32_t reg;
+ int node;
+
+ printf("\n");
+
+ for (node = OF_child(iba->iba_node); node; node = OF_peer(node)) {
+ if (OF_getprop(node, "reg", &reg, sizeof reg) != sizeof reg)
+ continue;
+ ia.ia_tag = iba->iba_tag;
+ ia.ia_addr = (reg >> 1);
+ ia.ia_node = node;
+ config_found(self, &ia, maciic_print);
+ }
+}
+
+int
+maciic_print(void *aux, const char *pnp)
+{
+ struct maci2c_attach_args *ia = aux;
+ char name[32];
+
+ if (pnp != NULL) {
+ OF_getprop(ia->ia_node, "name", name, sizeof name);
+ name[sizeof(name) - 1] = 0;
+ printf("%s at %s", name, pnp);
+ }
+ printf(" addr 0x%x", ia->ia_addr);
+
+ return (UNCONF);
+}
diff --git a/sys/arch/macppc/dev/maci2cvar.h b/sys/arch/macppc/dev/maci2cvar.h
new file mode 100644
index 00000000000..066a6f0ed98
--- /dev/null
+++ b/sys/arch/macppc/dev/maci2cvar.h
@@ -0,0 +1,32 @@
+/* $OpenBSD: maci2cvar.h,v 1.1 2005/11/11 16:22:50 kettenis Exp $ */
+
+/*
+ * Copyright (c) 2005 Mark Kettenis
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <dev/i2c/i2cvar.h>
+
+struct maci2cbus_attach_args {
+ i2c_tag_t iba_tag;
+ int iba_node;
+};
+
+struct maci2c_attach_args {
+ struct i2c_attach_args ia_ia;
+ int ia_node;
+};
+
+#define ia_tag ia_ia.ia_tag
+#define ia_addr ia_ia.ia_addr