Changeset View
Changeset View
Standalone View
Standalone View
head/sys/mips/mediatek/mtk_spi_v1.c
Show All 36 Lines | |||||
#include <sys/kernel.h> | #include <sys/kernel.h> | ||||
#include <sys/module.h> | #include <sys/module.h> | ||||
#include <sys/rman.h> | #include <sys/rman.h> | ||||
#include <sys/lock.h> | #include <sys/lock.h> | ||||
#include <sys/mutex.h> | #include <sys/mutex.h> | ||||
#include <machine/bus.h> | #include <machine/bus.h> | ||||
#include <machine/cpu.h> | #include <machine/cpu.h> | ||||
//#include <machine/pmap.h> | |||||
#include <dev/spibus/spi.h> | #include <dev/spibus/spi.h> | ||||
#include <dev/spibus/spibusvar.h> | #include <dev/spibus/spibusvar.h> | ||||
#include "spibus_if.h" | #include "spibus_if.h" | ||||
#include "opt_platform.h" | #include "opt_platform.h" | ||||
#include <dev/ofw/openfirm.h> | #include <dev/ofw/openfirm.h> | ||||
▲ Show 20 Lines • Show All 107 Lines • ▼ Show 20 Lines | if (sc->sc_mem_res) | ||||
bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->sc_mem_res); | bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->sc_mem_res); | ||||
return (0); | return (0); | ||||
} | } | ||||
static void | static void | ||||
mtk_spi_chip_activate(struct mtk_spi_softc *sc) | mtk_spi_chip_activate(struct mtk_spi_softc *sc) | ||||
{ | { | ||||
// printf("%s\n", __func__); | |||||
mtk_spi_wait(sc); | mtk_spi_wait(sc); | ||||
/* | /* | ||||
* Put all CSx to low | * Put all CSx to low | ||||
*/ | */ | ||||
SPI_CLEAR_BITS(sc, MTK_SPICTL, CS_HIGH | HIZSMOSI); | SPI_CLEAR_BITS(sc, MTK_SPICTL, CS_HIGH | HIZSMOSI); | ||||
} | } | ||||
static void | static void | ||||
mtk_spi_chip_deactivate(struct mtk_spi_softc *sc) | mtk_spi_chip_deactivate(struct mtk_spi_softc *sc) | ||||
{ | { | ||||
// printf("%s\n", __func__); | |||||
mtk_spi_wait(sc); | mtk_spi_wait(sc); | ||||
/* | /* | ||||
* Put all CSx to high | * Put all CSx to high | ||||
*/ | */ | ||||
SPI_SET_BITS(sc, MTK_SPICTL, CS_HIGH | HIZSMOSI); | SPI_SET_BITS(sc, MTK_SPICTL, CS_HIGH | HIZSMOSI); | ||||
} | } | ||||
static int | static int | ||||
Show All 18 Lines | |||||
{ | { | ||||
if (mtk_spi_wait(sc)) | if (mtk_spi_wait(sc)) | ||||
return (EBUSY); | return (EBUSY); | ||||
if (write == MTK_SPI_WRITE) { | if (write == MTK_SPI_WRITE) { | ||||
SPI_WRITE(sc, MTK_SPIDATA, *data); | SPI_WRITE(sc, MTK_SPIDATA, *data); | ||||
SPI_SET_BITS(sc, MTK_SPICTL, START_WRITE); | SPI_SET_BITS(sc, MTK_SPICTL, START_WRITE); | ||||
//printf("%s(W:%d)\n", __func__, *data); | |||||
} else {/* MTK_SPI_READ */ | } else {/* MTK_SPI_READ */ | ||||
SPI_SET_BITS(sc, MTK_SPICTL, START_READ); | SPI_SET_BITS(sc, MTK_SPICTL, START_READ); | ||||
if (mtk_spi_wait(sc)) | if (mtk_spi_wait(sc)) | ||||
return (EBUSY); | return (EBUSY); | ||||
*data = SPI_READ(sc, MTK_SPIDATA) & 0xff; | *data = SPI_READ(sc, MTK_SPIDATA) & 0xff; | ||||
//printf("%s(R:%d)\n", __func__, *data); | |||||
} | } | ||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
mtk_spi_transfer(device_t dev, device_t child, struct spi_command *cmd) | mtk_spi_transfer(device_t dev, device_t child, struct spi_command *cmd) | ||||
{ | { | ||||
struct mtk_spi_softc *sc; | struct mtk_spi_softc *sc; | ||||
▲ Show 20 Lines • Show All 121 Lines • Show Last 20 Lines |