Changeset View
Changeset View
Standalone View
Standalone View
sys/arm/broadcom/bcm2835/bcm2835_spi.c
Show First 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | |||||
#include <machine/intr.h> | #include <machine/intr.h> | ||||
#include <dev/ofw/ofw_bus.h> | #include <dev/ofw/ofw_bus.h> | ||||
#include <dev/ofw/ofw_bus_subr.h> | #include <dev/ofw/ofw_bus_subr.h> | ||||
#include <dev/spibus/spi.h> | #include <dev/spibus/spi.h> | ||||
#include <dev/spibus/spibusvar.h> | #include <dev/spibus/spibusvar.h> | ||||
#include <arm/broadcom/bcm2835/bcm2835_gpio.h> | |||||
#include <arm/broadcom/bcm2835/bcm2835_spireg.h> | #include <arm/broadcom/bcm2835/bcm2835_spireg.h> | ||||
#include <arm/broadcom/bcm2835/bcm2835_spivar.h> | #include <arm/broadcom/bcm2835/bcm2835_spivar.h> | ||||
#include "spibus_if.h" | #include "spibus_if.h" | ||||
static struct ofw_compat_data compat_data[] = { | static struct ofw_compat_data compat_data[] = { | ||||
{"broadcom,bcm2835-spi", 1}, | {"broadcom,bcm2835-spi", 1}, | ||||
{"brcm,bcm2835-spi", 1}, | {"brcm,bcm2835-spi", 1}, | ||||
▲ Show 20 Lines • Show All 182 Lines • ▼ Show 20 Lines | bcm_spi_probe(device_t dev) | ||||
return (BUS_PROBE_DEFAULT); | return (BUS_PROBE_DEFAULT); | ||||
} | } | ||||
static int | static int | ||||
bcm_spi_attach(device_t dev) | bcm_spi_attach(device_t dev) | ||||
{ | { | ||||
struct bcm_spi_softc *sc; | struct bcm_spi_softc *sc; | ||||
device_t gpio; | int rid; | ||||
int i, rid; | |||||
if (device_get_unit(dev) != 0) { | if (device_get_unit(dev) != 0) { | ||||
device_printf(dev, "only one SPI controller supported\n"); | device_printf(dev, "only one SPI controller supported\n"); | ||||
return (ENXIO); | return (ENXIO); | ||||
} | } | ||||
sc = device_get_softc(dev); | sc = device_get_softc(dev); | ||||
sc->sc_dev = dev; | sc->sc_dev = dev; | ||||
/* Configure the GPIO pins to ALT0 function to enable SPI the pins. */ | |||||
gpio = devclass_get_device(devclass_find("gpio"), 0); | |||||
if (!gpio) { | |||||
device_printf(dev, "cannot find gpio0\n"); | |||||
return (ENXIO); | |||||
} | |||||
for (i = 0; i < nitems(bcm_spi_pins); i++) | |||||
bcm_gpio_set_alternate(gpio, bcm_spi_pins[i], BCM_GPIO_ALT0); | |||||
rid = 0; | rid = 0; | ||||
sc->sc_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, | sc->sc_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, | ||||
RF_ACTIVE); | RF_ACTIVE); | ||||
if (!sc->sc_mem_res) { | if (!sc->sc_mem_res) { | ||||
device_printf(dev, "cannot allocate memory window\n"); | device_printf(dev, "cannot allocate memory window\n"); | ||||
return (ENXIO); | return (ENXIO); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 251 Lines • Show Last 20 Lines |