Module Name:    src
Committed By:   nisimura
Date:           Thu Mar 31 02:32:36 UTC 2011

Modified Files:
        src/sys/arch/sandpoint/sandpoint: iic_eumb.c

Log Message:
Build and use "i2c-child-devices" property to choose the correct RTC
chip among various models.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/sandpoint/sandpoint/iic_eumb.c

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/sandpoint/sandpoint/iic_eumb.c
diff -u src/sys/arch/sandpoint/sandpoint/iic_eumb.c:1.10 src/sys/arch/sandpoint/sandpoint/iic_eumb.c:1.11
--- src/sys/arch/sandpoint/sandpoint/iic_eumb.c:1.10	Wed Jan 12 18:09:03 2011
+++ src/sys/arch/sandpoint/sandpoint/iic_eumb.c	Thu Mar 31 02:32:35 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: iic_eumb.c,v 1.10 2011/01/12 18:09:03 phx Exp $ */
+/* $NetBSD: iic_eumb.c,v 1.11 2011/03/31 02:32:35 nisimura Exp $ */
 
 /*-
  * Copyright (c) 2010,2011 Frank Wille.
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: iic_eumb.c,v 1.10 2011/01/12 18:09:03 phx Exp $");
+__KERNEL_RCSID(0, "$NetBSD: iic_eumb.c,v 1.11 2011/03/31 02:32:35 nisimura Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -37,6 +37,7 @@
 #include <machine/bus.h>
 #include <dev/i2c/motoi2cvar.h>
 #include <sandpoint/sandpoint/eumbvar.h>
+#include <machine/bootinfo.h>
 
 struct iic_eumb_softc {
 	device_t		sc_dev;
@@ -51,6 +52,19 @@
 
 static int found;
 
+struct i2cdev {
+	const char *family;
+	const char *name;
+	int addr;
+};
+
+static struct i2cdev rtcmodel[] = {
+   { "kurobox",  "rs5c372rtc", 0x32 },
+   { "synology", "rs5c372rtc", 0x32 },
+};
+
+void add_i2c_child_devices(device_t, const char *);
+
 static int
 iic_eumb_match(device_t parent, cfdata_t cf, void *aux)
 {
@@ -64,6 +78,7 @@
 	struct iic_eumb_softc *sc;
 	struct eumb_attach_args *eaa;
 	bus_space_handle_t ioh;
+	struct btinfo_prodfamily *pfam;
 
 	sc = device_private(self);
 	sc->sc_dev = self;
@@ -73,6 +88,9 @@
 	aprint_naive("\n");
 	aprint_normal("\n");
 
+	if ((pfam = lookup_bootinfo(BTINFO_PRODFAMILY)) != NULL)
+		add_i2c_child_devices(self, pfam->name);
+
 	/*
 	 * map EUMB registers and attach MI motoi2c with default settings
 	 */
@@ -81,3 +99,31 @@
 	sc->sc_motoi2c.sc_ioh = ioh;
 	motoi2c_attach_common(self, &sc->sc_motoi2c, NULL);
 }
+
+void
+add_i2c_child_devices(device_t self, const char *family)
+{
+	struct i2cdev *rtc;
+	prop_dictionary_t pd;
+	prop_array_t pa;
+	int i;
+
+	rtc = NULL;
+	for (i = 0; i < (int)(sizeof(rtcmodel)/sizeof(rtcmodel[0])); i++) {
+		if (strcmp(family, rtcmodel[i].family) == 0) {
+			rtc = &rtcmodel[i];
+			goto found;
+		}
+	}
+	return;
+
+ found:
+	pd = prop_dictionary_create();
+	pa = prop_array_create();
+	prop_dictionary_set_cstring_nocopy(pd, "name", rtc->name);
+	prop_dictionary_set_uint32(pd, "addr", rtc->addr);
+	prop_array_add(pa, pd);
+	prop_dictionary_set(device_properties(self), "i2c-child-devices", pa);
+	prop_object_release(pd);
+	prop_object_release(pa);
+}

Reply via email to