Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/ofw ofw: add of_enter_spi_devs helper method
details: https://anonhg.NetBSD.org/src/rev/0324710e0e38
branches: trunk
changeset: 964533:0324710e0e38
user: tnn <tnn%NetBSD.org@localhost>
date: Tue Aug 06 18:17:52 2019 +0000
description:
ofw: add of_enter_spi_devs helper method
For translating OFW child nodes of SPI controller into "spi-child-devices"
property. In similar spirit to the existing of_enter_i2c_devs method.
diffstat:
sys/dev/ofw/ofw_subr.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++-
sys/dev/ofw/openfirm.h | 3 +-
2 files changed, 62 insertions(+), 3 deletions(-)
diffs (100 lines):
diff -r 47d8807c3b7d -r 0324710e0e38 sys/dev/ofw/ofw_subr.c
--- a/sys/dev/ofw/ofw_subr.c Tue Aug 06 18:07:51 2019 +0000
+++ b/sys/dev/ofw/ofw_subr.c Tue Aug 06 18:17:52 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ofw_subr.c,v 1.33 2018/09/26 20:03:36 jakllsch Exp $ */
+/* $NetBSD: ofw_subr.c,v 1.34 2019/08/06 18:17:52 tnn Exp $ */
/*
* Copyright 1998
@@ -34,7 +34,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ofw_subr.c,v 1.33 2018/09/26 20:03:36 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_subr.c,v 1.34 2019/08/06 18:17:52 tnn Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -503,6 +503,64 @@
}
}
+void
+of_enter_spi_devs(prop_dictionary_t props, int ofnode, size_t cell_size)
+{
+ int node, len;
+ char name[32];
+ uint64_t reg64;
+ uint32_t reg32;
+ uint32_t slave;
+ u_int32_t maxfreq;
+ prop_array_t array = NULL;
+ prop_dictionary_t dev;
+ int mode;
+
+ for (node = OF_child(ofnode); node; node = OF_peer(node)) {
+ if (OF_getprop(node, "name", name, sizeof(name)) <= 0)
+ continue;
+ len = OF_getproplen(node, "reg");
+ slave = 0;
+ if (cell_size == 8 && len >= sizeof(reg64)) {
+ if (OF_getprop(node, "reg", ®64, sizeof(reg64))
+ < sizeof(reg64))
+ continue;
+ slave = be64toh(reg64);
+ } else if (cell_size == 4 && len >= sizeof(reg32)) {
+ if (OF_getprop(node, "reg", ®32, sizeof(reg32))
+ < sizeof(reg32))
+ continue;
+ slave = be32toh(reg32);
+ } else {
+ continue;
+ }
+ if (of_getprop_uint32(node, "spi-max-frequency", &maxfreq)) {
+ maxfreq = 0;
+ }
+ mode = ((int)of_hasprop(node, "cpol") << 1) | (int)of_hasprop(node, "cpha");
+
+ if (array == NULL)
+ array = prop_array_create();
+
+ dev = prop_dictionary_create();
+ prop_dictionary_set_cstring(dev, "name", name);
+ prop_dictionary_set_uint32(dev, "slave", slave);
+ prop_dictionary_set_uint32(dev, "mode", mode);
+ if (maxfreq > 0)
+ prop_dictionary_set_uint32(dev, "spi-max-frequency", maxfreq);
+ prop_dictionary_set_uint64(dev, "cookie", node);
+ of_to_dataprop(dev, node, "compatible", "compatible");
+ prop_array_add(array, dev);
+ prop_object_release(dev);
+ }
+
+ if (array != NULL) {
+ prop_dictionary_set(props, "spi-child-devices", array);
+ prop_object_release(array);
+ }
+}
+
+
/*
* Returns true if the specified property is present.
*/
diff -r 47d8807c3b7d -r 0324710e0e38 sys/dev/ofw/openfirm.h
--- a/sys/dev/ofw/openfirm.h Tue Aug 06 18:07:51 2019 +0000
+++ b/sys/dev/ofw/openfirm.h Tue Aug 06 18:17:52 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: openfirm.h,v 1.37 2018/08/23 13:24:44 jmcneill Exp $ */
+/* $NetBSD: openfirm.h,v 1.38 2019/08/06 18:17:52 tnn Exp $ */
/*
* Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -126,6 +126,7 @@
char *of_get_mode_string(char *, int);
void of_enter_i2c_devs(prop_dictionary_t, int, size_t, int);
+void of_enter_spi_devs(prop_dictionary_t, int, size_t);
bool of_hasprop(int, const char *);
#define of_getprop_bool of_hasprop
Home |
Main Index |
Thread Index |
Old Index