xref: /openbsd-src/sys/arch/macppc/dev/maci2c.c (revision bb262015dc92822251d01cea9cfce91263c688fc)
1*bb262015Smglocker /*	$OpenBSD: maci2c.c,v 1.11 2016/05/23 15:23:20 mglocker Exp $	*/
20b27d03aSkettenis 
30b27d03aSkettenis /*
40b27d03aSkettenis  * Copyright (c) 2005 Mark Kettenis
50b27d03aSkettenis  *
60b27d03aSkettenis  * Permission to use, copy, modify, and distribute this software for any
70b27d03aSkettenis  * purpose with or without fee is hereby granted, provided that the above
80b27d03aSkettenis  * copyright notice and this permission notice appear in all copies.
90b27d03aSkettenis  *
100b27d03aSkettenis  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
110b27d03aSkettenis  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
120b27d03aSkettenis  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
130b27d03aSkettenis  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
140b27d03aSkettenis  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
150b27d03aSkettenis  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
160b27d03aSkettenis  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
170b27d03aSkettenis  */
180b27d03aSkettenis 
190b27d03aSkettenis #include <sys/param.h>
200b27d03aSkettenis #include <sys/systm.h>
210b27d03aSkettenis #include <sys/device.h>
220b27d03aSkettenis 
23a69c6821Skettenis #define _I2C_PRIVATE
240b27d03aSkettenis #include <dev/i2c/i2cvar.h>
250b27d03aSkettenis #include <dev/ofw/openfirm.h>
260b27d03aSkettenis 
270b27d03aSkettenis #include <arch/macppc/dev/maci2cvar.h>
280b27d03aSkettenis 
290b27d03aSkettenis void
maciic_scan(struct device * self,struct i2cbus_attach_args * iba,void * aux)30a5a63700Sderaadt maciic_scan(struct device *self, struct i2cbus_attach_args *iba, void *aux)
310b27d03aSkettenis {
32a5a63700Sderaadt 	int iba_node = *(int *)aux;
332d6ad09bSderaadt 	struct i2c_attach_args ia;
349b06f7aeSderaadt 	char name[32];
350b27d03aSkettenis 	u_int32_t reg;
360b27d03aSkettenis 	int node;
370b27d03aSkettenis 
38a5a63700Sderaadt 	for (node = OF_child(iba_node); node; node = OF_peer(node)) {
391ea7ad3dSderaadt 		if (OF_getprop(node, "reg", &reg, sizeof reg) != sizeof reg &&
401ea7ad3dSderaadt 		    OF_getprop(node, "i2c-address", &reg, sizeof reg) != sizeof reg)
410b27d03aSkettenis 			continue;
42d7949865Sjasper 		bzero(&ia, sizeof ia);
430b27d03aSkettenis 		ia.ia_tag = iba->iba_tag;
440b27d03aSkettenis 		ia.ia_addr = (reg >> 1);
45*bb262015Smglocker 		ia.ia_cookie = &node;
46d7949865Sjasper 		bzero(name, sizeof name);
479b06f7aeSderaadt 		if (OF_getprop(node, "compatible", &name,
489b06f7aeSderaadt 		    sizeof name) && name[0])
492d6ad09bSderaadt 			ia.ia_name = name;
509b06f7aeSderaadt 		if (ia.ia_name == NULL &&
519b06f7aeSderaadt 		    OF_getprop(node, "name", &name,
52dcc5a27eSderaadt 		    sizeof name) && name[0]) {
53dcc5a27eSderaadt 			if (strcmp(name, "cereal") == 0)
54dcc5a27eSderaadt 				continue;
559b06f7aeSderaadt 			ia.ia_name = name;
56dcc5a27eSderaadt 		}
57a69c6821Skettenis 		/* XXX We should write a real driver for these instead
58a69c6821Skettenis 		   of reaching over from the sound driver that sits on
59a69c6821Skettenis 		   the i2s port.  For now hide them.  */
60a69c6821Skettenis 		if (strcmp(name, "deq") == 0 || strcmp(name, "tas3004") == 0)
61a69c6821Skettenis 			continue;
629b06f7aeSderaadt 		if (ia.ia_name)
63a5a63700Sderaadt 			config_found(self, &ia, iic_print);
640b27d03aSkettenis 	}
650b27d03aSkettenis }
66