File: [local] / sys / dev / spi.c (download)
Revision 1.1, Tue Mar 4 16:09:35 2008 UTC (16 years, 1 month ago) by nbrk
Branch point for: MAIN
Initial revision
|
/* $Id: spi.c,v 1.1 2008/03/04 16:09:35 nbrk Exp $ */
/*
* SPI bus.
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/proc.h>
#include <sys/queue.h>
#include <sys/rwlock.h>
#include <dev/spivar.h>
struct spi_softc {
struct device sc_dev;
struct spi_bus *sc_bus;
};
int spi_match(struct device *parent, void *cf, void *aux);
void spi_attach(struct device *parent, struct device *self, void *aux);
struct cfattach spibus_ca = {
sizeof(struct spi_softc),
spi_match,
spi_attach,
NULL,
NULL
};
struct cfdriver spibus_cd = {
NULL,
"spibus",
DV_DULL
};
int
spi_match(struct device *parent, void *cf, void *aux)
{
return(1);
}
void
spi_attach(struct device *parent, struct device *self, void *aux)
{
struct spi_softc *sc = (struct spi_softc *)self;
struct spibus_attach_args *sba = aux;
sc->sc_bus = sba->sba_bus;
sba->sba_spisc = sc;
printf("\n");
/* attach slave */
config_found(&sc->sc_dev, sba, spibus_print);
}
int
spibus_print(void *aux, const char *pnp)
{
return(QUIET);
}
int
spi_shift_1(void *arg, uint8_t data)
{
struct spi_softc *sc = arg;
struct spi_bus *sb = sc->sc_bus;
/*
* TODO: locking.
*/
return(sb->bus_shift_1(sb->bus_cookie, data));
}
int
spi_acquire(void *arg)
{
struct spi_softc *sc = arg;
struct spi_bus *sb = sc->sc_bus;
return(sb->bus_acquire(sb->bus_cookie));
}
void
spi_release(void *arg)
{
struct spi_softc *sc = arg;
struct spi_bus *sb = sc->sc_bus;
return(sb->bus_release(sb->bus_cookie));
}