Module Name: src Committed By: thorpej Date: Thu Feb 4 20:19:09 UTC 2021
Modified Files: src/sys/dev/ofw: files.ofw ofw_subr.c Added Files: src/sys/dev/ofw: ofw_i2c_subr.c ofw_spi_subr.c Log Message: Split the i2c and spi stuff out into their own files. To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 src/sys/dev/ofw/files.ofw cvs rdiff -u -r0 -r1.1 src/sys/dev/ofw/ofw_i2c_subr.c \ src/sys/dev/ofw/ofw_spi_subr.c cvs rdiff -u -r1.55 -r1.56 src/sys/dev/ofw/ofw_subr.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/ofw/files.ofw diff -u src/sys/dev/ofw/files.ofw:1.15 src/sys/dev/ofw/files.ofw:1.16 --- src/sys/dev/ofw/files.ofw:1.15 Fri Apr 3 06:02:51 2020 +++ src/sys/dev/ofw/files.ofw Thu Feb 4 20:19:09 2021 @@ -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 | o 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 Index: src/sys/dev/ofw/ofw_subr.c diff -u src/sys/dev/ofw/ofw_subr.c:1.55 src/sys/dev/ofw/ofw_subr.c:1.56 --- src/sys/dev/ofw/ofw_subr.c:1.55 Wed Jan 27 04:55:42 2021 +++ src/sys/dev/ofw/ofw_subr.c Thu Feb 4 20:19:09 2021 @@ -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", ®64, 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", ®32, 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", ®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_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 Added files: Index: src/sys/dev/ofw/ofw_i2c_subr.c diff -u /dev/null src/sys/dev/ofw/ofw_i2c_subr.c:1.1 --- /dev/null Thu Feb 4 20:19:09 2021 +++ src/sys/dev/ofw/ofw_i2c_subr.c Thu Feb 4 20:19:09 2021 @@ -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", ®64, 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", ®32, 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); + } +} Index: src/sys/dev/ofw/ofw_spi_subr.c diff -u /dev/null src/sys/dev/ofw/ofw_spi_subr.c:1.1 --- /dev/null Thu Feb 4 20:19:09 2021 +++ src/sys/dev/ofw/ofw_spi_subr.c Thu Feb 4 20:19:09 2021 @@ -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", ®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_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); + } +}