Changeset View
Changeset View
Standalone View
Standalone View
sys/arm/ti/ti_spi.c
Show First 20 Lines • Show All 42 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/ti/ti_prcm.h> | #include <arm/ti/ti_sysc.h> | ||||
#include <arm/ti/ti_hwmods.h> | |||||
#include <arm/ti/ti_spireg.h> | #include <arm/ti/ti_spireg.h> | ||||
#include <arm/ti/ti_spivar.h> | #include <arm/ti/ti_spivar.h> | ||||
#include "spibus_if.h" | #include "spibus_if.h" | ||||
static void ti_spi_intr(void *); | static void ti_spi_intr(void *); | ||||
static int ti_spi_detach(device_t); | static int ti_spi_detach(device_t); | ||||
▲ Show 20 Lines • Show All 100 Lines • ▼ Show 20 Lines | ti_spi_probe(device_t dev) | ||||
device_set_desc(dev, "TI McSPI controller"); | device_set_desc(dev, "TI McSPI controller"); | ||||
return (BUS_PROBE_DEFAULT); | return (BUS_PROBE_DEFAULT); | ||||
} | } | ||||
static int | static int | ||||
ti_spi_attach(device_t dev) | ti_spi_attach(device_t dev) | ||||
{ | { | ||||
int clk_id, err, i, rid, timeout; | int err, i, rid, timeout; | ||||
struct ti_spi_softc *sc; | struct ti_spi_softc *sc; | ||||
uint32_t rev; | uint32_t rev; | ||||
sc = device_get_softc(dev); | sc = device_get_softc(dev); | ||||
sc->sc_dev = dev; | sc->sc_dev = dev; | ||||
/* | |||||
* Get the MMCHS device id from FDT. If it's not there use the newbus | |||||
* unit number (which will work as long as the devices are in order and | |||||
* none are skipped in the fdt). Note that this is a property we made | |||||
* up and added in freebsd, it doesn't exist in the published bindings. | |||||
*/ | |||||
clk_id = ti_hwmods_get_clock(dev); | |||||
if (clk_id == INVALID_CLK_IDENT) { | |||||
device_printf(dev, | |||||
"failed to get clock based on hwmods property\n"); | |||||
return (EINVAL); | |||||
} | |||||
/* Activate the McSPI module. */ | /* Activate the McSPI module. */ | ||||
err = ti_prcm_clk_enable(clk_id); | err = ti_sysc_clock_enable(device_get_parent(dev)); | ||||
if (err) { | if (err) { | ||||
device_printf(dev, "Error: failed to activate source clock\n"); | device_printf(dev, "Error: failed to activate source clock\n"); | ||||
return (err); | return (err); | ||||
} | } | ||||
/* Get the number of available channels. */ | /* Get the number of available channels. */ | ||||
if ((OF_getencprop(ofw_bus_get_node(dev), "ti,spi-num-cs", | if ((OF_getencprop(ofw_bus_get_node(dev), "ti,spi-num-cs", | ||||
&sc->sc_numcs, sizeof(sc->sc_numcs))) <= 0) { | &sc->sc_numcs, sizeof(sc->sc_numcs))) <= 0) { | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | if (--timeout == 0) { | ||||
"Error: Controller reset operation timed out\n"); | "Error: Controller reset operation timed out\n"); | ||||
ti_spi_detach(dev); | ti_spi_detach(dev); | ||||
return (ENXIO); | return (ENXIO); | ||||
} | } | ||||
DELAY(100); | DELAY(100); | ||||
} | } | ||||
/* Print the McSPI module revision. */ | /* Print the McSPI module revision. */ | ||||
rev = TI_SPI_READ(sc, MCSPI_REVISION); | rev = TI_SPI_READ(sc, | ||||
ti_sysc_get_rev_address_offset_host(device_get_parent(dev))); | |||||
device_printf(dev, | device_printf(dev, | ||||
"scheme: %#x func: %#x rtl: %d rev: %d.%d custom rev: %d\n", | "scheme: %#x func: %#x rtl: %d rev: %d.%d custom rev: %d\n", | ||||
(rev >> MCSPI_REVISION_SCHEME_SHIFT) & MCSPI_REVISION_SCHEME_MSK, | (rev >> MCSPI_REVISION_SCHEME_SHIFT) & MCSPI_REVISION_SCHEME_MSK, | ||||
(rev >> MCSPI_REVISION_FUNC_SHIFT) & MCSPI_REVISION_FUNC_MSK, | (rev >> MCSPI_REVISION_FUNC_SHIFT) & MCSPI_REVISION_FUNC_MSK, | ||||
(rev >> MCSPI_REVISION_RTL_SHIFT) & MCSPI_REVISION_RTL_MSK, | (rev >> MCSPI_REVISION_RTL_SHIFT) & MCSPI_REVISION_RTL_MSK, | ||||
(rev >> MCSPI_REVISION_MAJOR_SHIFT) & MCSPI_REVISION_MAJOR_MSK, | (rev >> MCSPI_REVISION_MAJOR_SHIFT) & MCSPI_REVISION_MAJOR_MSK, | ||||
(rev >> MCSPI_REVISION_MINOR_SHIFT) & MCSPI_REVISION_MINOR_MSK, | (rev >> MCSPI_REVISION_MINOR_SHIFT) & MCSPI_REVISION_MINOR_MSK, | ||||
(rev >> MCSPI_REVISION_CUSTOM_SHIFT) & MCSPI_REVISION_CUSTOM_MSK); | (rev >> MCSPI_REVISION_CUSTOM_SHIFT) & MCSPI_REVISION_CUSTOM_MSK); | ||||
▲ Show 20 Lines • Show All 330 Lines • ▼ Show 20 Lines | |||||
static driver_t ti_spi_driver = { | static driver_t ti_spi_driver = { | ||||
"spi", | "spi", | ||||
ti_spi_methods, | ti_spi_methods, | ||||
sizeof(struct ti_spi_softc), | sizeof(struct ti_spi_softc), | ||||
}; | }; | ||||
DRIVER_MODULE(ti_spi, simplebus, ti_spi_driver, ti_spi_devclass, 0, 0); | DRIVER_MODULE(ti_spi, simplebus, ti_spi_driver, ti_spi_devclass, 0, 0); | ||||
MODULE_DEPEND(ti_spi, ti_sysc, 1, 1, 1); |