Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Interpret the "reg" property of i2c nodes more liberal, ...



details:   https://anonhg.NetBSD.org/src/rev/071d528a5d0f
branches:  trunk
changeset: 752516:071d528a5d0f
user:      martin <martin%NetBSD.org@localhost>
date:      Sun Feb 28 13:59:05 2010 +0000

description:
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.

diffstat:

 sys/arch/sparc64/sparc64/autoconf.c |   9 ++++---
 sys/dev/ofw/ofw_subr.c              |  42 ++++++++++++++++--------------------
 sys/dev/ofw/openfirm.h              |   4 +-
 3 files changed, 26 insertions(+), 29 deletions(-)

diffs (134 lines):

diff -r 4b99b4aeba07 -r 071d528a5d0f sys/arch/sparc64/sparc64/autoconf.c
--- a/sys/arch/sparc64/sparc64/autoconf.c       Sun Feb 28 13:56:49 2010 +0000
+++ b/sys/arch/sparc64/sparc64/autoconf.c       Sun Feb 28 13:59:05 2010 +0000
@@ -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));
                }
        }
 
diff -r 4b99b4aeba07 -r 071d528a5d0f sys/dev/ofw/ofw_subr.c
--- a/sys/dev/ofw/ofw_subr.c    Sun Feb 28 13:56:49 2010 +0000
+++ b/sys/dev/ofw/ofw_subr.c    Sun Feb 28 13:59:05 2010 +0000
@@ -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))
-                               continue;
-                       r32 = r64;
-               } else if (len == sizeof(r32)) {
-                       if (OF_getprop(node, "reg", &r32, sizeof(r32))
-                           != sizeof(r32))
+               addr = 0;
+               if (cell_size == 8 && len >= sizeof(reg64)) {
+                       if (OF_getprop(node, "reg", &reg64, sizeof(reg64))
+                           < sizeof(reg64))
                                continue;
-               } else if (len == 24) {
-                       if (OF_getprop(node, "reg", smr, sizeof(smr))
-                           != sizeof(smr))
+                       addr = reg64;
+               } else if (cell_size == 4 && len >= sizeof(reg32)) {
+                       if (OF_getprop(node, "reg", &reg32, sizeof(reg32))
+                           < sizeof(reg32))
                                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);
diff -r 4b99b4aeba07 -r 071d528a5d0f sys/dev/ofw/openfirm.h
--- a/sys/dev/ofw/openfirm.h    Sun Feb 28 13:56:49 2010 +0000
+++ b/sys/dev/ofw/openfirm.h    Sun Feb 28 13:59:05 2010 +0000
@@ -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_*/



Home | Main Index | Thread Index | Old Index