From 40f3eaf2ff9a19b7ea7c86c987834c759afb1e7e Mon Sep 17 00:00:00 2001 From: Mark Kettenis Date: Fri, 11 Nov 2005 16:22:51 +0000 Subject: Add maciic(4), an OpenFirware aware version of iic(4). --- sys/arch/macppc/conf/files.macppc | 13 ++++++- sys/arch/macppc/dev/maci2c.c | 80 +++++++++++++++++++++++++++++++++++++++ sys/arch/macppc/dev/maci2cvar.h | 32 ++++++++++++++++ 3 files changed, 123 insertions(+), 2 deletions(-) create mode 100644 sys/arch/macppc/dev/maci2c.c create mode 100644 sys/arch/macppc/dev/maci2cvar.h (limited to 'sys/arch') 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 +#include +#include + +#include +#include + +#include + +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", ®, 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 + +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 -- cgit v1.2.3