From owner-freebsd-drivers@FreeBSD.ORG Tue Nov 27 08:50:03 2007 Return-Path: Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D834B16A417 for ; Tue, 27 Nov 2007 08:50:03 +0000 (UTC) (envelope-from Benjamin.Close@clearchain.com) Received: from ipmail04.adl2.internode.on.net (ipmail04.adl2.internode.on.net [203.16.214.57]) by mx1.freebsd.org (Postfix) with ESMTP id 5D34113C503 for ; Tue, 27 Nov 2007 08:50:02 +0000 (UTC) (envelope-from Benjamin.Close@clearchain.com) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ah4FADxmS0d5LTGL/2dsb2JhbACBWw X-IronPort-AV: E=Sophos;i="4.23,218,1194183000"; d="scan'208";a="4538528" Received: from ppp121-45-49-139.lns11.adl2.internode.on.net (HELO mail.clearchain.com) ([121.45.49.139]) by ipmail04.adl2.internode.on.net with ESMTP; 27 Nov 2007 19:20:01 +1030 Received: from [192.168.155.249] (draco.internal.clearchain.com [192.168.155.249]) (authenticated bits=0) by mail.clearchain.com (8.13.8/8.13.8) with ESMTP id lAR8nwdv097183 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 27 Nov 2007 19:19:58 +1030 (CST) (envelope-from Benjamin.Close@clearchain.com) Message-ID: <474BDA2E.7060003@clearchain.com> Date: Tue, 27 Nov 2007 19:19:50 +1030 From: Benjamin Close User-Agent: Thunderbird 2.0.0.9 (Windows/20071031) MIME-Version: 1.0 To: Joshua Hyatt References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: ClamAV version 0.91.2, clamav-milter version 0.91.2 on pegasus.clearchain.com X-Virus-Status: Clean X-Greylist: Sender succeeded SMTP AUTH authentication, not delayed by milter-greylist-2.0.2 (mail.clearchain.com [192.168.154.1]); Tue, 27 Nov 2007 19:19:58 +1030 (CST) Cc: freebsd-drivers@freebsd.org Subject: Re: GPIO X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 Nov 2007 08:50:04 -0000 Joshua Hyatt wrote: > I have a Soekris Net4801 computer running FreeBSD 6.2, which is an x86-based system using the AMD Geode SC1100 processor. It has a number of GPIO connections directly connected to the processor that I am interested in using. > > However, I am unfamiliar with writing a driver for FreeBSD, and all of my attempts thus far have resulted in failure. There is a led driver that uses the SPIO of the SC1100 for FreeBSD that works, with the source code located at /usr/src/sys/dev/led/, but it is write-only. > > If someone could guide me in adding a function to read the status of the gpio connection to led.c, or has a better suggestion of how to do this, it would be greatly appreciated. > > Thanks, > Joshua Hyatt > Hi Joshua, I think the bit you might be missing is dev/led is merely an intermediate driver that other drivers use. Things like dev/auxio make use of dev/led via led_create(). Hence if you look in dev/auxio/auxio.c at the auxio_led_func you can see that the function is actually doing both a read and write of the bus via auxio_led_read & auxio_led_write. In general, to read from general io registers you need to to use one of the bus_space * methods (BUS_SPACE(9)) but before you can do that you need to setup a bus resource via bus_alloc_resource_any. And perhaps an interrupt if required. Have a look at tha auxio driver, it'll probably make things a lot clearer - dev/led would have left you wondering where the actual work was done :) Cheers, Benjamin