From owner-svn-src-all@FreeBSD.ORG Thu Jan 9 18:28:59 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id A5059F64; Thu, 9 Jan 2014 18:28:59 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 84F40109A; Thu, 9 Jan 2014 18:28:59 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id s09ISxB9062560; Thu, 9 Jan 2014 18:28:59 GMT (envelope-from loos@svn.freebsd.org) Received: (from loos@localhost) by svn.freebsd.org (8.14.7/8.14.7/Submit) id s09ISwhM062556; Thu, 9 Jan 2014 18:28:58 GMT (envelope-from loos@svn.freebsd.org) Message-Id: <201401091828.s09ISwhM062556@svn.freebsd.org> From: Luiz Otavio O Souza Date: Thu, 9 Jan 2014 18:28:58 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r260489 - in stable/10/sys: conf dev/spibus X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Jan 2014 18:28:59 -0000 Author: loos Date: Thu Jan 9 18:28:58 2014 New Revision: 260489 URL: http://svnweb.freebsd.org/changeset/base/260489 Log: MFC r257064: Add an OFW SPI compatible bus. Fix the spibus probe to return BUS_PROBE_GENERIC and not BUS_PROBE_SPECIFIC (0) so the OFW SPI bus can attach when enabled. Export the spibus devclass_t and driver_t declarations. Submitted by: ray Approved by: adrian (mentor) Added: stable/10/sys/dev/spibus/ofw_spibus.c - copied unchanged from r257064, head/sys/dev/spibus/ofw_spibus.c Modified: stable/10/sys/conf/files stable/10/sys/dev/spibus/spibus.c stable/10/sys/dev/spibus/spibusvar.h Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/conf/files ============================================================================== --- stable/10/sys/conf/files Thu Jan 9 18:13:25 2014 (r260488) +++ stable/10/sys/conf/files Thu Jan 9 18:28:58 2014 (r260489) @@ -2175,6 +2175,7 @@ dev/sound/midi/mpu_if.m optional sound dev/sound/midi/mpufoi_if.m optional sound dev/sound/midi/sequencer.c optional sound dev/sound/midi/synth_if.m optional sound +dev/spibus/ofw_spibus.c optional fdt spibus dev/spibus/spibus.c optional spibus \ dependency "spibus_if.h" dev/spibus/spibus_if.m optional spibus Copied: stable/10/sys/dev/spibus/ofw_spibus.c (from r257064, head/sys/dev/spibus/ofw_spibus.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/10/sys/dev/spibus/ofw_spibus.c Thu Jan 9 18:28:58 2014 (r260489, copy of r257064, head/sys/dev/spibus/ofw_spibus.c) @@ -0,0 +1,192 @@ +/*- + * Copyright (c) 2009, Nathan Whitehorn + * Copyright (c) 2013 The FreeBSD Foundation + * All rights reserved. + * + * Portions of this software were developed by Oleksandr Rybalko + * under sponsorship from the FreeBSD Foundation. + * + * 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 unmodified, 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 ``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 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 +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "spibus_if.h" + +struct ofw_spibus_devinfo { + struct spibus_ivar opd_dinfo; + struct ofw_bus_devinfo opd_obdinfo; +}; + +/* Methods */ +static device_probe_t ofw_spibus_probe; +static device_attach_t ofw_spibus_attach; +static device_t ofw_spibus_add_child(device_t dev, u_int order, + const char *name, int unit); +static const struct ofw_bus_devinfo *ofw_spibus_get_devinfo(device_t bus, + device_t dev); + +static int +ofw_spibus_probe(device_t dev) +{ + + if (ofw_bus_get_node(dev) == -1) + return (ENXIO); + device_set_desc(dev, "OFW SPI bus"); + + return (0); +} + +static int +ofw_spibus_attach(device_t dev) +{ + struct spibus_softc *sc = device_get_softc(dev); + struct ofw_spibus_devinfo *dinfo; + phandle_t child; + pcell_t paddr; + device_t childdev; + + sc->dev = dev; + + bus_generic_probe(dev); + bus_enumerate_hinted_children(dev); + + /* + * Attach those children represented in the device tree. + */ + for (child = OF_child(ofw_bus_get_node(dev)); child != 0; + child = OF_peer(child)) { + /* + * Try to get the CS number first from the spi-chipselect + * property, then try the reg property. + */ + if (OF_getencprop(child, "spi-chipselect", &paddr, + sizeof(paddr)) == -1) { + if (OF_getencprop(child, "reg", &paddr, + sizeof(paddr)) == -1) + continue; + } + + /* + * Now set up the SPI and OFW bus layer devinfo and add it + * to the bus. + */ + dinfo = malloc(sizeof(struct ofw_spibus_devinfo), M_DEVBUF, + M_NOWAIT | M_ZERO); + if (dinfo == NULL) + continue; + dinfo->opd_dinfo.cs = paddr; + if (ofw_bus_gen_setup_devinfo(&dinfo->opd_obdinfo, child) != + 0) { + free(dinfo, M_DEVBUF); + continue; + } + childdev = device_add_child(dev, NULL, -1); + device_set_ivars(childdev, dinfo); + } + + return (bus_generic_attach(dev)); +} + +static device_t +ofw_spibus_add_child(device_t dev, u_int order, const char *name, int unit) +{ + device_t child; + struct ofw_spibus_devinfo *devi; + + child = device_add_child_ordered(dev, order, name, unit); + if (child == NULL) + return (child); + devi = malloc(sizeof(struct ofw_spibus_devinfo), M_DEVBUF, + M_NOWAIT | M_ZERO); + if (devi == NULL) { + device_delete_child(dev, child); + return (0); + } + + /* + * NULL all the OFW-related parts of the ivars for non-OFW + * children. + */ + devi->opd_obdinfo.obd_node = -1; + devi->opd_obdinfo.obd_name = NULL; + devi->opd_obdinfo.obd_compat = NULL; + devi->opd_obdinfo.obd_type = NULL; + devi->opd_obdinfo.obd_model = NULL; + + device_set_ivars(child, devi); + + return (child); +} + +static const struct ofw_bus_devinfo * +ofw_spibus_get_devinfo(device_t bus, device_t dev) +{ + struct ofw_spibus_devinfo *dinfo; + + dinfo = device_get_ivars(dev); + return (&dinfo->opd_obdinfo); +} + +static device_method_t ofw_spibus_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, ofw_spibus_probe), + DEVMETHOD(device_attach, ofw_spibus_attach), + + /* Bus interface */ + DEVMETHOD(bus_child_pnpinfo_str, ofw_bus_gen_child_pnpinfo_str), + DEVMETHOD(bus_add_child, ofw_spibus_add_child), + + /* ofw_bus interface */ + DEVMETHOD(ofw_bus_get_devinfo, ofw_spibus_get_devinfo), + DEVMETHOD(ofw_bus_get_compat, ofw_bus_gen_get_compat), + DEVMETHOD(ofw_bus_get_model, ofw_bus_gen_get_model), + DEVMETHOD(ofw_bus_get_name, ofw_bus_gen_get_name), + DEVMETHOD(ofw_bus_get_node, ofw_bus_gen_get_node), + DEVMETHOD(ofw_bus_get_type, ofw_bus_gen_get_type), + + DEVMETHOD_END +}; + +static devclass_t ofwspibus_devclass; + +DEFINE_CLASS_1(spibus, ofw_spibus_driver, ofw_spibus_methods, + sizeof(struct spibus_softc), spibus_driver); +DRIVER_MODULE(ofw_spibus, spi, ofw_spibus_driver, ofwspibus_devclass, 0, 0); +MODULE_VERSION(ofw_spibus, 1); +MODULE_DEPEND(ofw_spibus, spibus, 1, 1, 1); Modified: stable/10/sys/dev/spibus/spibus.c ============================================================================== --- stable/10/sys/dev/spibus/spibus.c Thu Jan 9 18:13:25 2014 (r260488) +++ stable/10/sys/dev/spibus/spibus.c Thu Jan 9 18:28:58 2014 (r260489) @@ -23,7 +23,7 @@ static int spibus_probe(device_t dev) { device_set_desc(dev, "spibus bus"); - return (0); + return (BUS_PROBE_GENERIC); } static int @@ -185,7 +185,7 @@ static device_method_t spibus_methods[] DEVMETHOD_END }; -static driver_t spibus_driver = { +driver_t spibus_driver = { "spibus", spibus_methods, sizeof(struct spibus_softc) Modified: stable/10/sys/dev/spibus/spibusvar.h ============================================================================== --- stable/10/sys/dev/spibus/spibusvar.h Thu Jan 9 18:13:25 2014 (r260488) +++ stable/10/sys/dev/spibus/spibusvar.h Thu Jan 9 18:28:58 2014 (r260489) @@ -26,3 +26,6 @@ spibus_get_ ## A(device_t dev, T *t) } SPIBUS_ACCESSOR(cs, CS, uint32_t) + +extern driver_t spibus_driver; +extern devclass_t spibus_devclass;