From owner-freebsd-hackers@FreeBSD.ORG Wed May 7 08:19:40 2014 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 1A5E8FA3 for ; Wed, 7 May 2014 08:19:40 +0000 (UTC) Received: from mail-ie0-x22e.google.com (mail-ie0-x22e.google.com [IPv6:2607:f8b0:4001:c03::22e]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id D67936D9 for ; Wed, 7 May 2014 08:19:39 +0000 (UTC) Received: by mail-ie0-f174.google.com with SMTP id ar20so662395iec.19 for ; Wed, 07 May 2014 01:19:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=8FnKE6lqlXkWqtqK6+EO+2s6+gwDTrK0Za2V1/WHOHs=; b=c79lbGTmS9bb9oUdE0Yxydz5nsis9i53dm0p6voS0nMpdczaQ8uybCyIQGqqbHBqhG 46SSo02FrksVOIdRe0knMLOIjKXnDmS5wvAVTk5bVWjK2cS1MFSNlCQIe5hZR5H2dJ05 /B6UQxZvHJbq09OGIDK4fn0lz5DzZje7p9thw8joD5S4BC38nJadtwFs/5QzLV0olI6L q/UazuDOb2jpLgzZiwzG2FeSs316Bj17Ku1htKMS6aZGKuJGYOWaM2ZVJi7IdgXd1VuD xtOyGa89jn4GNkMbdVZw5XMOmqcSLYI1BjmQrysN42F25hkTg4kYTVifTBFjxwAGIGR1 cNTQ== MIME-Version: 1.0 X-Received: by 10.51.15.161 with SMTP id fp1mr40631918igd.25.1399450779175; Wed, 07 May 2014 01:19:39 -0700 (PDT) Sender: ermal.luci@gmail.com Received: by 10.50.159.134 with HTTP; Wed, 7 May 2014 01:19:39 -0700 (PDT) In-Reply-To: <69BC3E8E-A5D1-4CAD-96A0-9139FFBD8AA3@netgate.com> References: <20140422020109.GA57760@gta.com> <69BC3E8E-A5D1-4CAD-96A0-9139FFBD8AA3@netgate.com> Date: Wed, 7 May 2014 10:19:39 +0200 X-Google-Sender-Auth: 0AD_7Zig1ZhBUaMYyq8E3rqVLjo Message-ID: Subject: Re: apu1c led driver From: =?UTF-8?Q?Ermal_Lu=C3=A7i?= To: Larry Baird Content-Type: text/plain; charset=UTF-8 X-Content-Filtered-By: Mailman/MimeDel 2.1.18 Cc: Freebsd hackers list , Jim Thompson X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 May 2014 08:19:40 -0000 Hello, find attached the driver as written today. It needs some reshaping to be integrate with led(4) and gpio(4). I will see to have the reshaping done and submit it for inclusion. The idea as it is today is that it expses an gpioapu device to which you can write a string with 3 digits "101" for each led. If you read from this device you just get the status of the switch on the APU. On Tue, Apr 22, 2014 at 6:34 AM, Jim Thompson wrote: > > Might want to get Ermal to post the driver he did for us (@ pfSense). > > Or just submit it to the process for -HEAD. > > Jim > > On Apr 21, 2014, at 9:01 PM, Larry Baird wrote: > > > There exists a nice simple linux driver for the leds on a pc engines > apu1c > > board at http://daduke.org/linux/apu/. Converting driver to use led(4) > > and run on FreeBSD seemed straight forward. Or that is until I realized > > I don't know how to alloc and write to a fixed set of I/O ports. I > believe > > the magic happens by using bus_alloc_resource(). Code below attempts to > allow > > control of the second of three leds on the apu1c board. Once I get that > > working, it should be easy to extend driver to support all three leds. > > What is the correct way to allocate and write to a a set of I/O ports at > > address 0xFED801BD? > > > > #include > > #include > > #include > > #include > > #include > > #include > > #include > > > > #define BASEADDR (0xFED801BD) > > #define LEDON (0x8) > > #define LEDOFF (0xC8) > > > > #define GPIO_187 187 // MODESW > > #define GPIO_189 189 // LED1# > > #define GPIO_190 190 // LED2# > > #define GPIO_191 191 // LED3# > > > > struct apuled_softc { > > device_t sc_dev; > > int sc_rid; > > int sc_type; > > int sc_offset; > > struct resource *sc_res; > > void *sc_led1; > > }; > > > > /* > > * Device methods. > > */ > > static int apuled_probe(device_t dev); > > static int apuled_attach(device_t dev); > > static int apuled_detach(device_t dev); > > > > static device_method_t apuled_methods[] = { > > /* Device interface */ > > DEVMETHOD(device_probe, apuled_probe), > > DEVMETHOD(device_attach, apuled_attach), > > DEVMETHOD(device_detach, apuled_detach), > > > > DEVMETHOD_END > > }; > > > > static driver_t apuled_driver = { > > "apuled", > > apuled_methods, > > sizeof(struct apuled_softc), > > }; > > > > static devclass_t apuled_devclass; > > DRIVER_MODULE(apuled, pci, apuled_driver, apuled_devclass, NULL, NULL); > > > > > > static int > > apuled_probe(device_t dev) > > { > > device_set_desc(dev, "APU led"); > > > > return (BUS_PROBE_GENERIC); > > } > > > > static void > > led_func(void *ptr, int onoff) > > { > > struct apuled_softc *sc = (struct apuled_softc *)ptr; > > u_int8_t value; > > > > if ( onoff ) { > > value = LEDON; > > } else { > > value = LEDOFF; > > } > > > > bus_write_1(sc->sc_res, 1, value); > > } > > > > static int > > apuled_attach(device_t dev) > > { > > struct apuled_softc *sc = device_get_softc(dev); > > > > sc->sc_dev = dev; > > sc->sc_rid = 1; > > sc->sc_type = SYS_RES_IOPORT; > > > > if ( (sc->sc_res = bus_alloc_resource( sc->sc_dev, > > sc->sc_type, > > &sc->sc_rid, > > BASEADDR, > > BASEADDR + 4, > > 4, > > RF_ACTIVE)) == NULL ) { > > device_printf( sc->sc_dev, "Unable to allocate bus > resource\n" ); > > return ENXIO; > > > > } else if ( (sc->sc_led1 = led_create(led_func, sc, "led1")) == > NULL ) { > > device_printf( sc->sc_dev, "Unable to create LED 1\n" ); > > return ENXIO; > > > > } else { > > device_printf( sc->sc_dev, "LED 1 created\n" ); > > } > > > > return (0); > > } > > > > int > > apuled_detach(device_t dev) > > { > > struct apuled_softc *sc = device_get_softc(dev); > > > > if ( sc->sc_led1 != NULL ) { > > led_destroy( sc->sc_led1 ); > > } > > > > if ( sc->sc_res != NULL ) { > > bus_release_resource( sc->sc_dev, sc->sc_type, sc->sc_rid, > sc->sc_res ); > > } > > > > return (0); > > } > > > > -- > > ------------------------------------------------------------------------ > > Larry Baird > > Global Technology Associates, Inc. 1992-2012 | http://www.gta.com > > Celebrating Twenty Years of Software Innovation | Orlando, FL > > Email: lab@gta.com | TEL 407-380-0220 > > _______________________________________________ > > freebsd-hackers@freebsd.org mailing list > > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers > > To unsubscribe, send any mail to " > freebsd-hackers-unsubscribe@freebsd.org" > > -- Ermal