summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorthorpej <thorpej@NetBSD.org>2021-02-04 20:19:09 +0000
committerthorpej <thorpej@NetBSD.org>2021-02-04 20:19:09 +0000
commita1b3946ce5c624bb6253bcaa14900efb0bb003c3 (patch)
tree34c2388bc17ae86a61121b5f453d65182dec2681 /sys/dev
parent281377a29498e7d94171d652219e9382183f3255 (diff)
Split the i2c and spi stuff out into their own files.
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/ofw/files.ofw4
-rw-r--r--sys/dev/ofw/ofw_i2c_subr.c109
-rw-r--r--sys/dev/ofw/ofw_spi_subr.c100
-rw-r--r--sys/dev/ofw/ofw_subr.c128
4 files changed, 214 insertions, 127 deletions
diff --git a/sys/dev/ofw/files.ofw b/sys/dev/ofw/files.ofw
index 0a57cfb1fba..80c0b63809c 100644
--- a/sys/dev/ofw/files.ofw
+++ b/sys/dev/ofw/files.ofw
@@ -1,4 +1,4 @@
-# $NetBSD: files.ofw,v 1.15 2020/04/03 06:02:51 macallan Exp $
+# $NetBSD: files.ofw,v 1.16 2021/02/04 20:19:09 thorpej Exp $
#
# First cut on Openfirmware interface
#
@@ -13,7 +13,9 @@ file dev/ofw/ofw_sysctl.c openfirm | ofw_subr
file dev/ofw/ofw_subr.c ofbus | openfirm | ofw_subr
+file dev/ofw/ofw_i2c_subr.c ofbus | openfirm | ofw_subr
file dev/ofw/ofw_network_subr.c of_network_dev
+file dev/ofw/ofw_spi_subr.c ofbus | openfirm | ofw_subr
# Generic disk support
device ofdisk: disk
diff --git a/sys/dev/ofw/ofw_i2c_subr.c b/sys/dev/ofw/ofw_i2c_subr.c
new file mode 100644
index 00000000000..abee69387d8
--- /dev/null
+++ b/sys/dev/ofw/ofw_i2c_subr.c
@@ -0,0 +1,109 @@
+/* $NetBSD: ofw_i2c_subr.c,v 1.1 2021/02/04 20:19:09 thorpej Exp $ */
+
+/*
+ * Copyright 1998
+ * Digital Equipment Corporation. All rights reserved.
+ *
+ * This software is furnished under license and may be used and
+ * copied only in accordance with the following terms and conditions.
+ * Subject to these conditions, you may download, copy, install,
+ * use, modify and distribute this software in source and/or binary
+ * form. No title or ownership is transferred hereby.
+ *
+ * 1) Any source code used, modified or distributed must reproduce
+ * and retain this copyright notice and list of conditions as
+ * they appear in the source file.
+ *
+ * 2) No right is granted to use any trade name, trademark, or logo of
+ * Digital Equipment Corporation. Neither the "Digital Equipment
+ * Corporation" name nor any trademark or logo of Digital Equipment
+ * Corporation may be used to endorse or promote products derived
+ * from this software without the prior written permission of
+ * Digital Equipment Corporation.
+ *
+ * 3) This software is provided "AS-IS" and any express or implied
+ * warranties, including but not limited to, any implied warranties
+ * of merchantability, fitness for a particular purpose, or
+ * non-infringement are disclaimed. In no event shall DIGITAL be
+ * liable for any damages whatsoever, and in particular, DIGITAL
+ * shall not be liable for special, indirect, consequential, or
+ * incidental damages or damages for lost profits, loss of
+ * revenue or loss of use, whether such damages arise in contract,
+ * negligence, tort, under statute, in equity, at law or otherwise,
+ * even if advised of the possibility of such damage.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: ofw_i2c_subr.c,v 1.1 2021/02/04 20:19:09 thorpej Exp $");
+
+#include <sys/param.h>
+#include <sys/device.h>
+#include <sys/kmem.h>
+#include <sys/systm.h>
+#include <dev/ofw/openfirm.h>
+#include <dev/i2c/i2cvar.h>
+
+/*
+ * Iterate over the subtree of a i2c controller node.
+ * Add all sub-devices into an array as part of the controller's
+ * device properties.
+ * This is used by the i2c bus attach code to do direct configuration.
+ */
+void
+of_enter_i2c_devs(prop_dictionary_t props, int ofnode, size_t cell_size,
+ int addr_shift)
+{
+ int node, len;
+ char name[32];
+ uint64_t reg64;
+ uint32_t reg32;
+ uint64_t addr;
+ prop_array_t array = NULL;
+ prop_dictionary_t dev;
+
+ 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");
+ addr = 0;
+ if (cell_size == 8 && len >= sizeof(reg64)) {
+ if (OF_getprop(node, "reg", &reg64, sizeof(reg64))
+ < sizeof(reg64))
+ continue;
+ addr = be64toh(reg64);
+ /*
+ * The i2c bus number (0 or 1) is encoded in bit 33
+ * of the register, but we encode it in bit 8 of
+ * i2c_addr_t.
+ */
+ if (addr & 0x100000000)
+ addr = (addr & 0xff) | 0x100;
+ } else if (cell_size == 4 && len >= sizeof(reg32)) {
+ if (OF_getprop(node, "reg", &reg32, sizeof(reg32))
+ < sizeof(reg32))
+ continue;
+ addr = be32toh(reg32);
+ } else {
+ continue;
+ }
+ addr >>= addr_shift;
+ if (addr == 0) continue;
+
+ if (array == NULL)
+ array = prop_array_create();
+
+ dev = prop_dictionary_create();
+ prop_dictionary_set_string(dev, "name", name);
+ prop_dictionary_set_uint32(dev, "addr", addr);
+ prop_dictionary_set_uint64(dev, "cookie", node);
+ prop_dictionary_set_uint32(dev, "cookietype", I2C_COOKIE_OF);
+ of_to_dataprop(dev, node, "compatible", "compatible");
+ prop_array_add(array, dev);
+ prop_object_release(dev);
+ }
+
+ if (array != NULL) {
+ prop_dictionary_set(props, "i2c-child-devices", array);
+ prop_object_release(array);
+ }
+}
diff --git a/sys/dev/ofw/ofw_spi_subr.c b/sys/dev/ofw/ofw_spi_subr.c
new file mode 100644
index 00000000000..788dc443ca9
--- /dev/null
+++ b/sys/dev/ofw/ofw_spi_subr.c
@@ -0,0 +1,100 @@
+/* $NetBSD: ofw_spi_subr.c,v 1.1 2021/02/04 20:19:09 thorpej Exp $ */
+
+/*
+ * Copyright 1998
+ * Digital Equipment Corporation. All rights reserved.
+ *
+ * This software is furnished under license and may be used and
+ * copied only in accordance with the following terms and conditions.
+ * Subject to these conditions, you may download, copy, install,
+ * use, modify and distribute this software in source and/or binary
+ * form. No title or ownership is transferred hereby.
+ *
+ * 1) Any source code used, modified or distributed must reproduce
+ * and retain this copyright notice and list of conditions as
+ * they appear in the source file.
+ *
+ * 2) No right is granted to use any trade name, trademark, or logo of
+ * Digital Equipment Corporation. Neither the "Digital Equipment
+ * Corporation" name nor any trademark or logo of Digital Equipment
+ * Corporation may be used to endorse or promote products derived
+ * from this software without the prior written permission of
+ * Digital Equipment Corporation.
+ *
+ * 3) This software is provided "AS-IS" and any express or implied
+ * warranties, including but not limited to, any implied warranties
+ * of merchantability, fitness for a particular purpose, or
+ * non-infringement are disclaimed. In no event shall DIGITAL be
+ * liable for any damages whatsoever, and in particular, DIGITAL
+ * shall not be liable for special, indirect, consequential, or
+ * incidental damages or damages for lost profits, loss of
+ * revenue or loss of use, whether such damages arise in contract,
+ * negligence, tort, under statute, in equity, at law or otherwise,
+ * even if advised of the possibility of such damage.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: ofw_spi_subr.c,v 1.1 2021/02/04 20:19:09 thorpej Exp $");
+
+#include <sys/param.h>
+#include <sys/device.h>
+#include <sys/kmem.h>
+#include <sys/systm.h>
+#include <dev/ofw/openfirm.h>
+
+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", &reg64, sizeof(reg64))
+ < sizeof(reg64))
+ continue;
+ slave = be64toh(reg64);
+ } else if (cell_size == 4 && len >= sizeof(reg32)) {
+ if (OF_getprop(node, "reg", &reg32, 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_string(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);
+ }
+}
diff --git a/sys/dev/ofw/ofw_subr.c b/sys/dev/ofw/ofw_subr.c
index 8b8b4de3a91..515cf9b24f6 100644
--- a/sys/dev/ofw/ofw_subr.c
+++ b/sys/dev/ofw/ofw_subr.c
@@ -1,4 +1,4 @@
-/* $NetBSD: ofw_subr.c,v 1.55 2021/01/27 04:55:42 thorpej Exp $ */
+/* $NetBSD: ofw_subr.c,v 1.56 2021/02/04 20:19:09 thorpej Exp $ */
/*
* Copyright 1998
@@ -34,14 +34,13 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ofw_subr.c,v 1.55 2021/01/27 04:55:42 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_subr.c,v 1.56 2021/02/04 20:19:09 thorpej Exp $");
#include <sys/param.h>
#include <sys/device.h>
#include <sys/kmem.h>
#include <sys/systm.h>
#include <dev/ofw/openfirm.h>
-#include <dev/i2c/i2cvar.h>
#define OFW_MAX_STACK_BUF_SIZE 256
#define OFW_PATH_BUF_SIZE 512
@@ -431,129 +430,6 @@ of_get_mode_string(char *buffer, int len)
}
/*
- * Iterate over the subtree of a i2c controller node.
- * Add all sub-devices into an array as part of the controller's
- * device properties.
- * This is used by the i2c bus attach code to do direct configuration.
- */
-void
-of_enter_i2c_devs(prop_dictionary_t props, int ofnode, size_t cell_size,
- int addr_shift)
-{
- int node, len;
- char name[32];
- uint64_t reg64;
- uint32_t reg32;
- uint64_t addr;
- prop_array_t array = NULL;
- prop_dictionary_t dev;
-
- 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");
- addr = 0;
- if (cell_size == 8 && len >= sizeof(reg64)) {
- if (OF_getprop(node, "reg", &reg64, sizeof(reg64))
- < sizeof(reg64))
- continue;
- addr = be64toh(reg64);
- /*
- * The i2c bus number (0 or 1) is encoded in bit 33
- * of the register, but we encode it in bit 8 of
- * i2c_addr_t.
- */
- if (addr & 0x100000000)
- addr = (addr & 0xff) | 0x100;
- } else if (cell_size == 4 && len >= sizeof(reg32)) {
- if (OF_getprop(node, "reg", &reg32, sizeof(reg32))
- < sizeof(reg32))
- continue;
- addr = be32toh(reg32);
- } else {
- continue;
- }
- addr >>= addr_shift;
- if (addr == 0) continue;
-
- if (array == NULL)
- array = prop_array_create();
-
- dev = prop_dictionary_create();
- prop_dictionary_set_string(dev, "name", name);
- prop_dictionary_set_uint32(dev, "addr", addr);
- prop_dictionary_set_uint64(dev, "cookie", node);
- prop_dictionary_set_uint32(dev, "cookietype", I2C_COOKIE_OF);
- of_to_dataprop(dev, node, "compatible", "compatible");
- prop_array_add(array, dev);
- prop_object_release(dev);
- }
-
- if (array != NULL) {
- prop_dictionary_set(props, "i2c-child-devices", array);
- prop_object_release(array);
- }
-}
-
-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", &reg64, sizeof(reg64))
- < sizeof(reg64))
- continue;
- slave = be64toh(reg64);
- } else if (cell_size == 4 && len >= sizeof(reg32)) {
- if (OF_getprop(node, "reg", &reg32, 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_string(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.
*/
bool