From owner-freebsd-hackers@FreeBSD.ORG Tue Apr 22 04:34:54 2014 Return-Path: Delivered-To: freebsd-hackers@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 2B917641 for ; Tue, 22 Apr 2014 04:34:54 +0000 (UTC) Received: from mail-ob0-f171.google.com (mail-ob0-f171.google.com [209.85.214.171]) (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 E547810C6 for ; Tue, 22 Apr 2014 04:34:53 +0000 (UTC) Received: by mail-ob0-f171.google.com with SMTP id uy5so5227429obc.30 for ; Mon, 21 Apr 2014 21:34:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:content-type:mime-version:subject:from :in-reply-to:date:cc:content-transfer-encoding:message-id:references :to; bh=qaXqmquGSFUCLayloKXifAfmpAabyhfXIz3B7w1m5HQ=; b=QcLWxK6Jjimq14w016zigBdMJQKSK8UDIkwlWhWVnL0wMNZEn0hlHJtoB6AyY3tSb2 a+TYe06SWH2xqVqPECBK+pUmvpDntHhuC3BJcLSkydMP4gmDf+qrrKcNQ88UHX1aMxpN Mo/skC+Z26okBkP3d7taJQRjqSuIV+EEoIYD02W70ZvSqoFQuNWPYEpcEgzyo1NQ+6rB H8n9RT9YdAHev3nAEMDTiDzyeNxUP8XSdWxX0vfPvCC05GQzYO4ygqHvkHAj6g6oJK9T 6cmlzB0VjEOtPTu6/28Qe8YiuJURS/nYkAvmIehNerGnVGOzL0Z69sNM985Q5n76zuZ3 rEJA== X-Gm-Message-State: ALoCoQkVWqYrKibp6AniGqxDYhPUjxnO0zMtQxU9axQVD+fdIrkaHwJWpWWr9c/tItvUqgTjPJi0 X-Received: by 10.60.39.131 with SMTP id p3mr10347526oek.44.1398141287381; Mon, 21 Apr 2014 21:34:47 -0700 (PDT) Received: from [172.21.0.93] (65-111-100-227.static.grandenetworks.net. [65.111.100.227]) by mx.google.com with ESMTPSA id b6sm67803155oez.8.2014.04.21.21.34.41 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 21 Apr 2014 21:34:41 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 7.2 \(1874\)) Subject: Re: apu1c led driver From: Jim Thompson In-Reply-To: <20140422020109.GA57760@gta.com> Date: Mon, 21 Apr 2014 23:34:40 -0500 Content-Transfer-Encoding: quoted-printable Message-Id: <69BC3E8E-A5D1-4CAD-96A0-9139FFBD8AA3@netgate.com> References: <20140422020109.GA57760@gta.com> To: Larry Baird X-Mailer: Apple Mail (2.1874) Cc: =?iso-8859-1?Q?Ermal_Lu=E7i?= , Freebsd hackers list X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Apr 2014 04:34:54 -0000 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? >=20 > #include > #include > #include > #include > #include > #include > #include >=20 > #define BASEADDR (0xFED801BD) > #define LEDON (0x8) > #define LEDOFF (0xC8) >=20 > #define GPIO_187 187 // MODESW > #define GPIO_189 189 // LED1# > #define GPIO_190 190 // LED2# > #define GPIO_191 191 // LED3# >=20 > struct apuled_softc { > device_t sc_dev; > int sc_rid; > int sc_type; > int sc_offset; > struct resource *sc_res; > void *sc_led1; > }; >=20 > /* > * Device methods. > */ > static int apuled_probe(device_t dev); > static int apuled_attach(device_t dev); > static int apuled_detach(device_t dev); >=20 > static device_method_t apuled_methods[] =3D { > /* Device interface */ > DEVMETHOD(device_probe, apuled_probe), > DEVMETHOD(device_attach, apuled_attach), > DEVMETHOD(device_detach, apuled_detach), >=20 > DEVMETHOD_END > }; >=20 > static driver_t apuled_driver =3D { > "apuled", > apuled_methods, > sizeof(struct apuled_softc), > }; >=20 > static devclass_t apuled_devclass; > DRIVER_MODULE(apuled, pci, apuled_driver, apuled_devclass, NULL, = NULL); >=20 >=20 > static int > apuled_probe(device_t dev) > { > device_set_desc(dev, "APU led"); >=20 > return (BUS_PROBE_GENERIC); > } >=20 > static void > led_func(void *ptr, int onoff) > { > struct apuled_softc *sc =3D (struct apuled_softc *)ptr; > u_int8_t value; >=20 > if ( onoff ) { > value =3D LEDON; > } else { > value =3D LEDOFF; > } >=20 > bus_write_1(sc->sc_res, 1, value); > } >=20 > static int > apuled_attach(device_t dev) > { > struct apuled_softc *sc =3D device_get_softc(dev); >=20 > sc->sc_dev =3D dev; > sc->sc_rid =3D 1; > sc->sc_type =3D SYS_RES_IOPORT; >=20 > if ( (sc->sc_res =3D bus_alloc_resource( sc->sc_dev, > sc->sc_type, > &sc->sc_rid, > BASEADDR, > BASEADDR + 4, > 4, > RF_ACTIVE)) =3D=3D NULL ) { > device_printf( sc->sc_dev, "Unable to allocate bus = resource\n" ); > return ENXIO; >=20 > } else if ( (sc->sc_led1 =3D led_create(led_func, sc, "led1")) = =3D=3D NULL ) { > device_printf( sc->sc_dev, "Unable to create LED 1\n" ); > return ENXIO; >=20 > } else { > device_printf( sc->sc_dev, "LED 1 created\n" ); > } >=20 > return (0); > } >=20 > int > apuled_detach(device_t dev) > { > struct apuled_softc *sc =3D device_get_softc(dev); >=20 > if ( sc->sc_led1 !=3D NULL ) { > led_destroy( sc->sc_led1 ); > } >=20 > if ( sc->sc_res !=3D NULL ) { > bus_release_resource( sc->sc_dev, sc->sc_type, = sc->sc_rid, sc->sc_res ); > } >=20 > return (0); > } >=20 > --=20 > = ------------------------------------------------------------------------ > 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"