From owner-svn-src-head@freebsd.org Sun Feb 19 19:56:14 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 39BD4CE5235; Sun, 19 Feb 2017 19:56:14 +0000 (UTC) (envelope-from jhibbits@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id E3A42868; Sun, 19 Feb 2017 19:56:13 +0000 (UTC) (envelope-from jhibbits@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v1JJuDdw063148; Sun, 19 Feb 2017 19:56:13 GMT (envelope-from jhibbits@FreeBSD.org) Received: (from jhibbits@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v1JJuCwv063147; Sun, 19 Feb 2017 19:56:12 GMT (envelope-from jhibbits@FreeBSD.org) Message-Id: <201702191956.v1JJuCwv063147@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jhibbits set sender to jhibbits@FreeBSD.org using -f From: Justin Hibbits Date: Sun, 19 Feb 2017 19:56:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r313964 - in head/sys: conf powerpc/mikrotik X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 19 Feb 2017 19:56:14 -0000 Author: jhibbits Date: Sun Feb 19 19:56:12 2017 New Revision: 313964 URL: https://svnweb.freebsd.org/changeset/base/313964 Log: Add a driver for the RouterBoard RB800 User LED This may work on other RouterBoard PPC platforms, but I don't have any to test with. Added: head/sys/powerpc/mikrotik/rb_led.c (contents, props changed) Modified: head/sys/conf/files.powerpc Modified: head/sys/conf/files.powerpc ============================================================================== --- head/sys/conf/files.powerpc Sun Feb 19 19:46:47 2017 (r313963) +++ head/sys/conf/files.powerpc Sun Feb 19 19:56:12 2017 (r313964) @@ -134,6 +134,7 @@ powerpc/mambo/mambo.c optional mambo powerpc/mambo/mambo_console.c optional mambo powerpc/mambo/mambo_disk.c optional mambo powerpc/mikrotik/platform_rb.c optional mikrotik +powerpc/mikrotik/rb_led.c optional mikrotik powerpc/mpc85xx/atpic.c optional mpc85xx isa powerpc/mpc85xx/ds1553_bus_fdt.c optional ds1553 fdt powerpc/mpc85xx/ds1553_core.c optional ds1553 Added: head/sys/powerpc/mikrotik/rb_led.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/powerpc/mikrotik/rb_led.c Sun Feb 19 19:56:12 2017 (r313964) @@ -0,0 +1,149 @@ +/*- + * Copyright (c) 2017 Justin Hibbits + * All rights reserved. + * + * 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 ``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 "gpio_if.h" + +struct rbled_softc { + struct cdev *sc_led; + device_t sc_gpio; + uint32_t sc_ledpin; +}; + +static int rbled_probe(device_t); +static int rbled_attach(device_t); +static int rbled_detach(device_t); +static void rbled_toggle(void *, int); + +static device_method_t rbled_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, rbled_probe), + DEVMETHOD(device_attach, rbled_attach), + DEVMETHOD(device_detach, rbled_detach), + + DEVMETHOD_END +}; + +static driver_t rbled_driver = { + "rbled", + rbled_methods, + sizeof(struct rbled_softc), +}; + +static devclass_t rbled_devclass; + +DRIVER_MODULE(rbled, simplebus, rbled_driver, rbled_devclass, 0, 0); + +static int +rbled_probe(device_t dev) +{ + phandle_t node; + const char *name; + cell_t gp[2]; + char model[6]; + + node = ofw_bus_get_node(dev); + + name = ofw_bus_get_name(dev); + if (name == NULL) + return (ENXIO); + if (strcmp(name, "led") != 0) + return (ENXIO); + + if (OF_getprop(node, "user_led", gp, sizeof(gp)) <= 0) + return (ENXIO); + + /* Check root model. */ + node = OF_peer(0); + if (OF_getprop(node, "model", model, sizeof(model)) <= 0) + return (ENXIO); + if (strcmp(model, "RB800") != 0) + return (ENXIO); + + device_set_desc(dev, "RouterBoard LED"); + return (0); +} + +static int +rbled_attach(device_t dev) +{ + struct rbled_softc *sc; + phandle_t node; + cell_t gp[2]; + + sc = device_get_softc(dev); + node = ofw_bus_get_node(dev); + + if (OF_getprop(node, "user_led", gp, sizeof(gp)) <= 0) + return (ENXIO); + + sc->sc_gpio = OF_device_from_xref(gp[0]); + if (sc->sc_gpio == NULL) { + device_printf(dev, "No GPIO resource found!\n"); + return (ENXIO); + } + sc->sc_ledpin = gp[1]; + + sc->sc_led = led_create(rbled_toggle, sc, "user_led"); + + if (sc->sc_led == NULL) + return (ENXIO); + + return (0); +} + +static int +rbled_detach(device_t dev) +{ + struct rbled_softc *sc; + + sc = device_get_softc(dev); + led_destroy(sc->sc_led); + + return (0); +} + +static void +rbled_toggle(void *priv, int onoff) +{ + struct rbled_softc *sc = priv; + + GPIO_PIN_SET(sc->sc_gpio, sc->sc_ledpin, onoff); +}