xref: /openbsd/sys/arch/macppc/dev/maci2c.c (revision 09467b48)
1 /*	$OpenBSD: maci2c.c,v 1.11 2016/05/23 15:23:20 mglocker Exp $	*/
2 
3 /*
4  * Copyright (c) 2005 Mark Kettenis
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #include <sys/param.h>
20 #include <sys/systm.h>
21 #include <sys/device.h>
22 
23 #define _I2C_PRIVATE
24 #include <dev/i2c/i2cvar.h>
25 #include <dev/ofw/openfirm.h>
26 
27 #include <arch/macppc/dev/maci2cvar.h>
28 
29 void
30 maciic_scan(struct device *self, struct i2cbus_attach_args *iba, void *aux)
31 {
32 	int iba_node = *(int *)aux;
33 	struct i2c_attach_args ia;
34 	char name[32];
35 	u_int32_t reg;
36 	int node;
37 
38 	for (node = OF_child(iba_node); node; node = OF_peer(node)) {
39 		if (OF_getprop(node, "reg", &reg, sizeof reg) != sizeof reg &&
40 		    OF_getprop(node, "i2c-address", &reg, sizeof reg) != sizeof reg)
41 			continue;
42 		bzero(&ia, sizeof ia);
43 		ia.ia_tag = iba->iba_tag;
44 		ia.ia_addr = (reg >> 1);
45 		ia.ia_cookie = &node;
46 		bzero(name, sizeof name);
47 		if (OF_getprop(node, "compatible", &name,
48 		    sizeof name) && name[0])
49 			ia.ia_name = name;
50 		if (ia.ia_name == NULL &&
51 		    OF_getprop(node, "name", &name,
52 		    sizeof name) && name[0]) {
53 			if (strcmp(name, "cereal") == 0)
54 				continue;
55 			ia.ia_name = name;
56 		}
57 		/* XXX We should write a real driver for these instead
58 		   of reaching over from the sound driver that sits on
59 		   the i2s port.  For now hide them.  */
60 		if (strcmp(name, "deq") == 0 || strcmp(name, "tas3004") == 0)
61 			continue;
62 		if (ia.ia_name)
63 			config_found(self, &ia, iic_print);
64 	}
65 }
66