GPIO

Benjamin Close Benjamin.Close at clearchain.com
Tue Nov 27 00:50:04 PST 2007


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


More information about the freebsd-drivers mailing list