summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Wildt <patrick@cvs.openbsd.org>2020-06-25 12:35:22 +0000
committerPatrick Wildt <patrick@cvs.openbsd.org>2020-06-25 12:35:22 +0000
commit22abcef12ee6ae58579aa09601d44d9bc745ee05 (patch)
tree1eea5bc5132288385f9ebb11157a1c329d58d498
parente363152640091e8558176a07eb508de02236d909 (diff)
Add a "framework" for MII busses.
ok kettenis@
-rw-r--r--sys/dev/ofw/ofw_misc.c38
-rw-r--r--sys/dev/ofw/ofw_misc.h16
2 files changed, 52 insertions, 2 deletions
diff --git a/sys/dev/ofw/ofw_misc.c b/sys/dev/ofw/ofw_misc.c
index f4ca92260e5..3790f2a13d6 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.21 2020/06/10 23:43:06 patrick Exp $ */
+/* $OpenBSD: ofw_misc.c,v 1.22 2020/06/25 12:35:21 patrick Exp $ */
/*
* Copyright (c) 2017 Mark Kettenis
*
@@ -687,3 +687,39 @@ dai_byphandle(uint32_t phandle)
return NULL;
}
+
+/* MII support */
+
+LIST_HEAD(, mii_bus) mii_busses =
+ LIST_HEAD_INITIALIZER(mii_busses);
+
+void
+mii_register(struct mii_bus *md)
+{
+ LIST_INSERT_HEAD(&mii_busses, md, md_list);
+}
+
+struct mii_bus *
+mii_byphandle(uint32_t phandle)
+{
+ struct mii_bus *md;
+ int node;
+
+ if (phandle == 0)
+ return NULL;
+
+ node = OF_getnodebyphandle(phandle);
+ if (node == 0)
+ return NULL;
+
+ node = OF_parent(node);
+ if (node == 0)
+ return NULL;
+
+ LIST_FOREACH(md, &mii_busses, md_list) {
+ if (md->md_node == node)
+ return md;
+ }
+
+ return NULL;
+}
diff --git a/sys/dev/ofw/ofw_misc.h b/sys/dev/ofw/ofw_misc.h
index 8c7ff7e1d63..6d462b31cd4 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.13 2020/06/10 23:43:06 patrick Exp $ */
+/* $OpenBSD: ofw_misc.h,v 1.14 2020/06/25 12:35:21 patrick Exp $ */
/*
* Copyright (c) 2017 Mark Kettenis
*
@@ -213,4 +213,18 @@ struct dai_device *dai_byphandle(uint32_t);
#define DAI_CLOCK_CFS (0 << 1)
#define DAI_CLOCK_CFM (1 << 1)
+/* MII support */
+
+struct mii_bus {
+ int md_node;
+ void *md_cookie;
+ int (*md_readreg)(struct device *, int, int);
+ void (*md_writereg)(struct device *, int, int, int);
+
+ LIST_ENTRY(mii_bus) md_list;
+};
+
+void mii_register(struct mii_bus *);
+struct mii_bus *mii_byphandle(uint32_t);
+
#endif /* _DEV_OFW_MISC_H_ */