Module Name: src Committed By: martin Date: Sun Feb 28 13:59:05 UTC 2010
Modified Files: src/sys/arch/sparc64/sparc64: autoconf.c src/sys/dev/ofw: ofw_subr.c openfirm.h Log Message: Interpret the "reg" property of i2c nodes more liberal, and depending on the cell size in use. I have been unable to find any documents about the i2c bindings for OF, so this is all pretty much voodoo. To generate a diff of this commit: cvs rdiff -u -r1.169 -r1.170 src/sys/arch/sparc64/sparc64/autoconf.c cvs rdiff -u -r1.17 -r1.18 src/sys/dev/ofw/ofw_subr.c cvs rdiff -u -r1.28 -r1.29 src/sys/dev/ofw/openfirm.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/sparc64/sparc64/autoconf.c diff -u src/sys/arch/sparc64/sparc64/autoconf.c:1.169 src/sys/arch/sparc64/sparc64/autoconf.c:1.170 --- src/sys/arch/sparc64/sparc64/autoconf.c:1.169 Sun Feb 28 11:43:40 2010 +++ src/sys/arch/sparc64/sparc64/autoconf.c Sun Feb 28 13:59:05 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: autoconf.c,v 1.169 2010/02/28 11:43:40 martin Exp $ */ +/* $NetBSD: autoconf.c,v 1.170 2010/02/28 13:59:05 martin Exp $ */ /* * Copyright (c) 1996 @@ -48,7 +48,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.169 2010/02/28 11:43:40 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.170 2010/02/28 13:59:05 martin Exp $"); #include "opt_ddb.h" #include "opt_kgdb.h" @@ -873,7 +873,7 @@ struct ebus_attach_args *ea = aux; ofnode = ea->ea_node; - } else if (device_is_a(dev, "iic")) { + } else if (device_is_a(busdev, "iic")) { struct i2c_attach_args *ia = aux; ofnode = (int)ia->ia_cookie; @@ -995,7 +995,8 @@ prop_object_t cfg = prop_dictionary_get(props, "i2c-child-devices"); if (!cfg) - of_enter_i2c_devs(props, busnode); + of_enter_i2c_devs(props, busnode, + sizeof(cell_t)); } } Index: src/sys/dev/ofw/ofw_subr.c diff -u src/sys/dev/ofw/ofw_subr.c:1.17 src/sys/dev/ofw/ofw_subr.c:1.18 --- src/sys/dev/ofw/ofw_subr.c:1.17 Sun Feb 28 11:35:40 2010 +++ src/sys/dev/ofw/ofw_subr.c Sun Feb 28 13:59:05 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: ofw_subr.c,v 1.17 2010/02/28 11:35:40 martin Exp $ */ +/* $NetBSD: ofw_subr.c,v 1.18 2010/02/28 13:59:05 martin Exp $ */ /* * Copyright 1998 @@ -34,7 +34,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: ofw_subr.c,v 1.17 2010/02/28 11:35:40 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ofw_subr.c,v 1.18 2010/02/28 13:59:05 martin Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -333,13 +333,13 @@ * This is used by the i2c bus attach code to do direct configuration. */ void -of_enter_i2c_devs(prop_dictionary_t props, int ofnode) +of_enter_i2c_devs(prop_dictionary_t props, int ofnode, size_t cell_size) { int node, len; char name[32]; - uint64_t r64; - uint64_t r32; - uint8_t smr[24]; + uint64_t reg64; + uint32_t reg32; + uint64_t addr; prop_array_t array; prop_dictionary_t dev; @@ -349,30 +349,26 @@ if (OF_getprop(node, "name", name, sizeof(name)) <= 0) continue; len = OF_getproplen(node, "reg"); - if (len == sizeof(r64)) { - if (OF_getprop(node, "reg", &r64, sizeof(r64)) - != sizeof(r64)) + addr = 0; + if (cell_size == 8 && len >= sizeof(reg64)) { + if (OF_getprop(node, "reg", ®64, sizeof(reg64)) + < sizeof(reg64)) continue; - r32 = r64; - } else if (len == sizeof(r32)) { - if (OF_getprop(node, "reg", &r32, sizeof(r32)) - != sizeof(r32)) + addr = reg64; + } else if (cell_size == 4 && len >= sizeof(reg32)) { + if (OF_getprop(node, "reg", ®32, sizeof(reg32)) + < sizeof(reg32)) continue; - } else if (len == 24) { - if (OF_getprop(node, "reg", smr, sizeof(smr)) - != sizeof(smr)) - continue; - /* smbus reg property */ - r32 = smr[7]; + addr = reg32; } else { - panic("unexpected \"reg\" size %d for \"%s\", " - "parent %x, node %x", - len, name, ofnode, node); + continue; } + addr >>= 1; + if (addr == 0) continue; dev = prop_dictionary_create(); prop_dictionary_set_cstring(dev, "name", name); - prop_dictionary_set_uint32(dev, "addr", r32 >> 1); + prop_dictionary_set_uint32(dev, "addr", addr); prop_dictionary_set_uint64(dev, "cookie", node); of_to_dataprop(dev, node, "compatible", "compatible"); prop_array_add(array, dev); Index: src/sys/dev/ofw/openfirm.h diff -u src/sys/dev/ofw/openfirm.h:1.28 src/sys/dev/ofw/openfirm.h:1.29 --- src/sys/dev/ofw/openfirm.h:1.28 Sun Feb 28 11:35:40 2010 +++ src/sys/dev/ofw/openfirm.h Sun Feb 28 13:59:05 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: openfirm.h,v 1.28 2010/02/28 11:35:40 martin Exp $ */ +/* $NetBSD: openfirm.h,v 1.29 2010/02/28 13:59:05 martin Exp $ */ /* * Copyright (C) 1995, 1996 Wolfgang Solfrank. @@ -115,6 +115,6 @@ int *of_network_decode_media(int, int *, int *); char *of_get_mode_string(char *, int); -void of_enter_i2c_devs(prop_dictionary_t, int); +void of_enter_i2c_devs(prop_dictionary_t, int, size_t); #endif /*_OPENFIRM_H_*/