Module Name:    src
Committed By:   jmcneill
Date:           Sun Jul  1 18:16:40 UTC 2018

Modified Files:
        src/sys/dev/fdt: fdt_i2c.c fdtvar.h

Log Message:
Add fdtbus_attach_i2cbus, used to attach an i2cbus to an fdt device node.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/fdt/fdt_i2c.c
cvs rdiff -u -r1.37 -r1.38 src/sys/dev/fdt/fdtvar.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/dev/fdt/fdt_i2c.c
diff -u src/sys/dev/fdt/fdt_i2c.c:1.3 src/sys/dev/fdt/fdt_i2c.c:1.4
--- src/sys/dev/fdt/fdt_i2c.c:1.3	Sat Jun 30 20:34:43 2018
+++ src/sys/dev/fdt/fdt_i2c.c	Sun Jul  1 18:16:40 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_i2c.c,v 1.3 2018/06/30 20:34:43 jmcneill Exp $ */
+/* $NetBSD: fdt_i2c.c,v 1.4 2018/07/01 18:16:40 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill <jmcne...@invisible.ca>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fdt_i2c.c,v 1.3 2018/06/30 20:34:43 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_i2c.c,v 1.4 2018/07/01 18:16:40 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -88,3 +88,26 @@ fdtbus_get_i2c_tag(int phandle)
 
 	return i2c->i2c_funcs->get_tag(i2c->i2c_dev);
 }
+
+device_t
+fdtbus_attach_i2cbus(device_t dev, int phandle, i2c_tag_t tag, cfprint_t print)
+{
+	struct i2cbus_attach_args iba;
+	prop_dictionary_t devs;
+	u_int address_cells;
+
+	devs = prop_dictionary_create();
+	if (of_getprop_uint32(phandle, "#address-cells", &address_cells))
+		address_cells = 1;
+
+	of_enter_i2c_devs(devs, phandle, address_cells * 4, 0);
+
+	memset(&iba, 0, sizeof(iba));
+	iba.iba_tag = tag;
+	iba.iba_child_devices = prop_dictionary_get(devs, "i2c-child-devices");
+	if (iba.iba_child_devices)
+		prop_object_retain(iba.iba_child_devices);
+	prop_object_release(devs);
+
+	return config_found_ia(dev, "i2cbus", &iba, print);
+}

Index: src/sys/dev/fdt/fdtvar.h
diff -u src/sys/dev/fdt/fdtvar.h:1.37 src/sys/dev/fdt/fdtvar.h:1.38
--- src/sys/dev/fdt/fdtvar.h:1.37	Sat Jun 30 18:07:12 2018
+++ src/sys/dev/fdt/fdtvar.h	Sun Jul  1 18:16:40 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: fdtvar.h,v 1.37 2018/06/30 18:07:12 jmcneill Exp $ */
+/* $NetBSD: fdtvar.h,v 1.38 2018/07/01 18:16:40 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill <jmcne...@invisible.ca>
@@ -333,6 +333,8 @@ int		fdtbus_todr_attach(device_t, int, t
 void		fdtbus_power_reset(void);
 void		fdtbus_power_poweroff(void);
 
+device_t	fdtbus_attach_i2cbus(device_t, int, i2c_tag_t, cfprint_t);
+
 bool		fdtbus_set_data(const void *);
 const void *	fdtbus_get_data(void);
 int		fdtbus_phandle2offset(int);

Reply via email to