diff --git a/sys/conf/files b/sys/conf/files index f002598d1c3d..fb57567d3e87 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -1854,6 +1854,7 @@ dev/iicbus/mux/ltc430x.c optional ltc430x dev/iicbus/mux/pca954x.c optional pca954x dev/iicbus/nxprtc.c optional nxprtc | pcf8563 dev/iicbus/ofw_iicbus.c optional fdt iicbus +dev/iicbus/ofw_iicbus_if.m optional fdt iicbus dev/iicbus/pcf8574.c optional pcf8574 dev/iicbus/pcf8591.c optional pcf8591 dev/iicbus/rtc8583.c optional rtc8583 diff --git a/sys/dev/iicbus/ofw_iicbus.c b/sys/dev/iicbus/ofw_iicbus.c index 9be05d73abde..2ccc9698e5bd 100644 --- a/sys/dev/iicbus/ofw_iicbus.c +++ b/sys/dev/iicbus/ofw_iicbus.c @@ -42,6 +42,7 @@ __FBSDID("$FreeBSD$"); #include #include "iicbus_if.h" +#include "ofw_iicbus_if.h" /* Methods */ static device_probe_t ofw_iicbus_probe; @@ -50,6 +51,8 @@ static device_t ofw_iicbus_add_child(device_t dev, u_int order, const char *name, int unit); static const struct ofw_bus_devinfo *ofw_iicbus_get_devinfo(device_t bus, device_t dev); +static int ofw_iicbus_set_devinfo(device_t bus, device_t dev, + phandle_t ofw_node, char *ofw_name, char *ofw_compat, int i2c_addr); static device_method_t ofw_iicbus_methods[] = { /* Device interface */ @@ -68,6 +71,9 @@ static device_method_t ofw_iicbus_methods[] = { DEVMETHOD(ofw_bus_get_node, ofw_bus_gen_get_node), DEVMETHOD(ofw_bus_get_type, ofw_bus_gen_get_type), + /* ofw_iicbus interface */ + DEVMETHOD(ofw_iicbus_set_devinfo, ofw_iicbus_set_devinfo), + DEVMETHOD_END }; @@ -238,3 +244,26 @@ ofw_iicbus_get_devinfo(device_t bus, device_t dev) dinfo = device_get_ivars(dev); return (&dinfo->opd_obdinfo); } + +static int +ofw_iicbus_set_devinfo(device_t bus, device_t dev, phandle_t ofw_node, + char *ofw_name, char *ofw_compat, int i2c_addr) +{ + struct ofw_iicbus_devinfo *devi; + + /* + * Setup OFW-related parts of the ivars for manually + * created ofw_iicbus childern. + */ + devi = device_get_ivars(dev); + if (devi == NULL) + return (ENXIO); + + devi->opd_obdinfo.obd_node = ofw_node; + if (ofw_name != NULL) + devi->opd_obdinfo.obd_name = strdup(ofw_name, M_OFWPROP); + if (ofw_compat != NULL) + devi->opd_obdinfo.obd_compat = strdup(ofw_compat, M_OFWPROP); + devi->opd_dinfo.addr = i2c_addr; + return (0); +} diff --git a/sys/dev/iicbus/ofw_iicbus_if.m b/sys/dev/iicbus/ofw_iicbus_if.m new file mode 100644 index 000000000000..a2b0bd2761db --- /dev/null +++ b/sys/dev/iicbus/ofw_iicbus_if.m @@ -0,0 +1,43 @@ +#- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright 2020 Michal Meloun +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# + +#include +#include + +INTERFACE ofw_iicbus; + +# +# Interpret interrupt +# +METHOD int set_devinfo { + device_t bus; + device_t dev; + phandle_t ofw_node; + char *ofw_name; + char *ofw_compat; + int i2c_addr; +};