Changeset View
Changeset View
Standalone View
Standalone View
head/sys/mips/mediatek/mtk_spi_v2.c
Show All 37 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 97 Lines • ▼ Show 20 Lines | mtk_spi_attach(device_t dev) | ||||
return (bus_generic_attach(dev)); | return (bus_generic_attach(dev)); | ||||
} | } | ||||
static int | static int | ||||
mtk_spi_detach(device_t dev) | mtk_spi_detach(device_t dev) | ||||
{ | { | ||||
struct mtk_spi_softc *sc = device_get_softc(dev); | struct mtk_spi_softc *sc = device_get_softc(dev); | ||||
//SPI_SET_BITS(sc, MTK_SPICTL, HIZSMOSI | CS_HIGH); | |||||
if (sc->sc_mem_res) | 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_SET_BITS(sc, MTK_SPIPOLAR, 1); | SPI_SET_BITS(sc, MTK_SPIPOLAR, 1); | ||||
} | } | ||||
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_CLEAR_BITS(sc, MTK_SPIPOLAR, 1); | SPI_CLEAR_BITS(sc, MTK_SPIPOLAR, 1); | ||||
} | } | ||||
static int | static int | ||||
mtk_spi_wait(struct mtk_spi_softc *sc) | mtk_spi_wait(struct mtk_spi_softc *sc) | ||||
{ | { | ||||
int i = 1000; | int i = 1000; | ||||
while (i--) { | while (i--) { | ||||
if (!(SPI_READ(sc, MTK_SPITRANS) & SPIBUSY)) | if (!(SPI_READ(sc, MTK_SPITRANS) & SPIBUSY)) | ||||
break; | break; | ||||
} | } | ||||
if (i == 0) { | if (i == 0) { | ||||
//printf("busy\n"); | |||||
return (1); | return (1); | ||||
} | } | ||||
return (0); | return (0); | ||||
} | } | ||||
static uint8_t | static uint8_t | ||||
mtk_spi_txrx(struct mtk_spi_softc *sc, uint8_t *data, int write) | mtk_spi_txrx(struct mtk_spi_softc *sc, uint8_t *data, int write) | ||||
▲ Show 20 Lines • Show All 149 Lines • Show Last 20 Lines |