#ifndef __QCOM_SPI_VAR_H__
#define __QCOM_SPI_VAR_H__
typedef enum {
QCOM_SPI_HW_QPI_V1_1 = 1,
QCOM_SPI_HW_QPI_V2_1 = 2,
QCOM_SPI_HW_QPI_V2_2 = 3,
} qcom_spi_hw_version_t;
#define CS_MAX 4
struct qcom_spi_softc {
device_t sc_dev;
device_t spibus;
uint32_t sc_debug;
struct resource *sc_mem_res;
struct resource *sc_irq_res;
void *sc_irq_h;
struct mtx sc_mtx;
bool sc_busy;
qcom_spi_hw_version_t hw_version;
clk_t clk_core;
clk_t clk_iface;
gpio_pin_t cs_pins[CS_MAX];
struct {
uint32_t input_block_size;
uint32_t output_block_size;
uint32_t input_fifo_size;
uint32_t output_fifo_size;
uint32_t cs_select;
uint32_t num_cs;
uint32_t max_frequency;
} config;
struct {
uint32_t transfer_mode;
uint32_t transfer_word_size;
uint32_t frequency;
bool cs_high;
} state;
struct {
bool tx_dma_done;
bool rx_dma_done;
bool done;
bool do_tx;
bool do_rx;
bool error;
} intr;
struct {
bool active;
uint32_t num_words;
const char *tx_buf;
int tx_len;
int tx_offset;
char *rx_buf;
int rx_len;
int rx_offset;
bool done;
} transfer;
};
#define QCOM_SPI_QUP_VERSION_V1(sc) \
((sc)->hw_version == QCOM_SPI_HW_QPI_V1_1)
#define QCOM_SPI_LOCK(sc) mtx_lock(&(sc)->sc_mtx)
#define QCOM_SPI_UNLOCK(sc) mtx_unlock(&(sc)->sc_mtx)
#define QCOM_SPI_ASSERT_LOCKED(sc) mtx_assert(&(sc)->sc_mtx, MA_OWNED)
#define QCOM_SPI_READ_4(sc, reg) bus_read_4((sc)->sc_mem_res, (reg))
#define QCOM_SPI_WRITE_4(sc, reg, val) bus_write_4((sc)->sc_mem_res, \
(reg), (val))
#define QCOM_SPI_BARRIER_WRITE(sc) bus_barrier((sc)->sc_mem_res, \
0, 0x600, BUS_SPACE_BARRIER_WRITE)
#define QCOM_SPI_BARRIER_READ(sc) bus_barrier((sc)->sc_mem_res, \
0, 0x600, BUS_SPACE_BARRIER_READ)
#define QCOM_SPI_BARRIER_RW(sc) bus_barrier((sc)->sc_mem_res, \
0, 0x600, BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE)
extern int qcom_spi_hw_read_controller_transfer_sizes(
struct qcom_spi_softc *sc);
extern int qcom_spi_hw_qup_set_state_locked(struct qcom_spi_softc *sc,
uint32_t state);
extern int qcom_spi_hw_qup_init_locked(struct qcom_spi_softc *sc);
extern int qcom_spi_hw_spi_init_locked(struct qcom_spi_softc *sc);
extern int qcom_spi_hw_spi_cs_force(struct qcom_spi_softc *sc, int cs,
bool enable);
extern int qcom_spi_hw_interrupt_handle(struct qcom_spi_softc *sc);
extern int qcom_spi_hw_setup_transfer_selection(struct qcom_spi_softc *sc,
uint32_t len);
extern int qcom_spi_hw_complete_transfer(struct qcom_spi_softc *sc);
extern int qcom_spi_hw_setup_current_transfer(struct qcom_spi_softc *sc);
extern int qcom_spi_hw_setup_pio_transfer_cnt(struct qcom_spi_softc *sc);
extern int qcom_spi_hw_setup_block_transfer_cnt(struct qcom_spi_softc *sc);
extern int qcom_spi_hw_setup_io_modes(struct qcom_spi_softc *sc);
extern int qcom_spi_hw_setup_spi_io_clock_polarity(
struct qcom_spi_softc *sc, bool cpol);
extern int qcom_spi_hw_setup_spi_config(struct qcom_spi_softc *sc,
uint32_t clock_val, bool cpha);
extern int qcom_spi_hw_setup_qup_config(struct qcom_spi_softc *sc,
bool is_tx, bool is_rx);
extern int qcom_spi_hw_setup_operational_mask(struct qcom_spi_softc *sc);
extern int qcom_spi_hw_ack_write_pio_fifo(struct qcom_spi_softc *sc);
extern int qcom_spi_hw_ack_opmode(struct qcom_spi_softc *sc);
extern int qcom_spi_hw_write_pio_fifo(struct qcom_spi_softc *sc);
extern int qcom_spi_hw_write_pio_block(struct qcom_spi_softc *sc);
extern int qcom_spi_hw_read_pio_fifo(struct qcom_spi_softc *sc);
extern int qcom_spi_hw_read_pio_block(struct qcom_spi_softc *sc);
extern int qcom_spi_hw_do_full_reset(struct qcom_spi_softc *sc);
#endif