Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/ofw Split the i2c and spi stuff out into their own f...



details:   https://anonhg.NetBSD.org/src/rev/0f4a5ba419cf
branches:  trunk
changeset: 951507:0f4a5ba419cf
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Thu Feb 04 20:19:09 2021 +0000

description:
Split the i2c and spi stuff out into their own files.

diffstat:

 sys/dev/ofw/files.ofw      |    4 +-
 sys/dev/ofw/ofw_i2c_subr.c |  109 ++++++++++++++++++++++++++++++++++++++
 sys/dev/ofw/ofw_spi_subr.c |  100 +++++++++++++++++++++++++++++++++++
 sys/dev/ofw/ofw_subr.c     |  128 +--------------------------------------------
 4 files changed, 214 insertions(+), 127 deletions(-)

diffs (truncated from 391 to 300 lines):

diff -r e16eb565faa1 -r 0f4a5ba419cf sys/dev/ofw/files.ofw
--- a/sys/dev/ofw/files.ofw     Thu Feb 04 20:14:33 2021 +0000
+++ b/sys/dev/ofw/files.ofw     Thu Feb 04 20:19:09 2021 +0000
@@ -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_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 -r e16eb565faa1 -r 0f4a5ba419cf sys/dev/ofw/ofw_i2c_subr.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/ofw/ofw_i2c_subr.c        Thu Feb 04 20:19:09 2021 +0000
@@ -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 -r e16eb565faa1 -r 0f4a5ba419cf sys/dev/ofw/ofw_spi_subr.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/ofw/ofw_spi_subr.c        Thu Feb 04 20:19:09 2021 +0000
@@ -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 -r e16eb565faa1 -r 0f4a5ba419cf sys/dev/ofw/ofw_subr.c
--- a/sys/dev/ofw/ofw_subr.c    Thu Feb 04 20:14:33 2021 +0000
+++ b/sys/dev/ofw/ofw_subr.c    Thu Feb 04 20:19:09 2021 +0000
@@ -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 @@
 }
 
 /*
- * 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)) {



Home | Main Index | Thread Index | Old Index