1 /* $OpenBSD: maci2c.c,v 1.10 2010/04/09 17:01:30 jasper 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", ®, sizeof reg) != sizeof reg && 40 OF_getprop(node, "i2c-address", ®, 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 bzero(name, sizeof name); 46 if (OF_getprop(node, "compatible", &name, 47 sizeof name) && name[0]) 48 ia.ia_name = name; 49 if (ia.ia_name == NULL && 50 OF_getprop(node, "name", &name, 51 sizeof name) && name[0]) { 52 if (strcmp(name, "cereal") == 0) 53 continue; 54 ia.ia_name = name; 55 } 56 /* XXX We should write a real driver for these instead 57 of reaching over from the sound driver that sits on 58 the i2s port. For now hide them. */ 59 if (strcmp(name, "deq") == 0 || strcmp(name, "tas3004") == 0) 60 continue; 61 if (ia.ia_name) 62 config_found(self, &ia, iic_print); 63 } 64 } 65