summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Wildt <patrick@cvs.openbsd.org>2019-09-07 13:27:24 +0000
committerPatrick Wildt <patrick@cvs.openbsd.org>2019-09-07 13:27:24 +0000
commit42badf5972b46a3a22ee593a0f35669910d0fe05 (patch)
tree26007fa286f2ee5042ddf4a5a89c3d22b0559a75
parent966eb1e7e2cb4dd0cc69a908a943acfbb56b0736 (diff)
Add an I2C framework, so that nodes that need to use I2C but
are not children of the I2C controller are able to use it. ok kettenis@
-rw-r--r--sys/dev/ofw/ofw_misc.c45
-rw-r--r--sys/dev/ofw/ofw_misc.h18
2 files changed, 61 insertions, 2 deletions
diff --git a/sys/dev/ofw/ofw_misc.c b/sys/dev/ofw/ofw_misc.c
index db1e54760af..b988d3b0789 100644
--- a/sys/dev/ofw/ofw_misc.c
+++ b/sys/dev/ofw/ofw_misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ofw_misc.c,v 1.7 2019/09/04 11:25:54 kettenis Exp $ */
+/* $OpenBSD: ofw_misc.c,v 1.8 2019/09/07 13:27:23 patrick Exp $ */
/*
* Copyright (c) 2017 Mark Kettenis
*
@@ -198,3 +198,46 @@ phy_enable(int node, const char *name)
return phy_enable_idx(node, idx);
}
+
+/*
+ * I2C support.
+ */
+
+LIST_HEAD(, i2c_bus) i2c_busses =
+ LIST_HEAD_INITIALIZER(i2c_bus);
+
+void
+i2c_register(struct i2c_bus *ib)
+{
+ ib->ib_phandle = OF_getpropint(ib->ib_node, "phandle", 0);
+ if (ib->ib_phandle == 0)
+ return;
+
+ LIST_INSERT_HEAD(&i2c_busses, ib, ib_list);
+}
+
+struct i2c_controller *
+i2c_bynode(int node)
+{
+ struct i2c_bus *ib;
+
+ LIST_FOREACH(ib, &i2c_busses, ib_list) {
+ if (ib->ib_node == node)
+ return ib->ib_ic;
+ }
+
+ return NULL;
+}
+
+struct i2c_controller *
+i2c_byphandle(uint32_t phandle)
+{
+ struct i2c_bus *ib;
+
+ LIST_FOREACH(ib, &i2c_busses, ib_list) {
+ if (ib->ib_phandle == phandle)
+ return ib->ib_ic;
+ }
+
+ return NULL;
+}
diff --git a/sys/dev/ofw/ofw_misc.h b/sys/dev/ofw/ofw_misc.h
index 6cff23281d0..c97e04f0b48 100644
--- a/sys/dev/ofw/ofw_misc.h
+++ b/sys/dev/ofw/ofw_misc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ofw_misc.h,v 1.4 2019/08/28 07:03:51 kettenis Exp $ */
+/* $OpenBSD: ofw_misc.h,v 1.5 2019/09/07 13:27:23 patrick Exp $ */
/*
* Copyright (c) 2017 Mark Kettenis
*
@@ -54,4 +54,20 @@ void phy_register(struct phy_device *);
int phy_enable_idx(int, int);
int phy_enable(int, const char *);
+/* I2C support */
+
+struct i2c_controller;
+struct i2c_bus {
+ int ib_node;
+ struct i2c_controller *ib_ic;
+
+ LIST_ENTRY(i2c_bus) ib_list;
+ uint32_t ib_phandle;
+};
+
+void i2c_register(struct i2c_bus *);
+
+struct i2c_controller *i2c_bynode(int);
+struct i2c_controller *i2c_byphandle(uint32_t);
+
#endif /* _DEV_OFW_MISC_H_ */