| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
#ifndef SPI_H_ |
| 40 |
#define SPI_H_ |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
#define BIT(x) (1UL << (x)) |
| 48 |
|
| 49 |
#define SPI_ENGINE_VERSION_MAJOR(x) ((x >> 16) & 0xff) |
| 50 |
#define SPI_ENGINE_VERSION_MINOR(x) ((x >> 8) & 0xff) |
| 51 |
#define SPI_ENGINE_VERSION_PATCH(x) (x & 0xff) |
| 52 |
|
| 53 |
#define SPI_ENGINE_REG_VERSION 0x00 |
| 54 |
|
| 55 |
#define SPI_ENGINE_REG_DATA_WIDTH 0x0C |
| 56 |
|
| 57 |
#define SPI_ENGINE_REG_RESET 0x40 |
| 58 |
|
| 59 |
#define SPI_ENGINE_REG_INT_ENABLE 0x80 |
| 60 |
#define SPI_ENGINE_REG_INT_PENDING 0x84 |
| 61 |
#define SPI_ENGINE_REG_INT_SOURCE 0x88 |
| 62 |
|
| 63 |
#define SPI_ENGINE_REG_SYNC_ID 0xc0 |
| 64 |
|
| 65 |
#define SPI_ENGINE_REG_CMD_FIFO_ROOM 0xd0 |
| 66 |
#define SPI_ENGINE_REG_SDO_FIFO_ROOM 0xd4 |
| 67 |
#define SPI_ENGINE_REG_SDI_FIFO_LEVEL 0xd8 |
| 68 |
|
| 69 |
#define SPI_ENGINE_REG_CMD_FIFO 0xe0 |
| 70 |
#define SPI_ENGINE_REG_SDO_DATA_FIFO 0xe4 |
| 71 |
#define SPI_ENGINE_REG_SDI_DATA_FIFO 0xe8 |
| 72 |
#define SPI_ENGINE_REG_SDI_DATA_FIFO_PEEK 0xec |
| 73 |
|
| 74 |
#define SPI_ENGINE_REG_OFFLOAD_CTRL(x) (0x100 + (0x20 * x)) |
| 75 |
#define SPI_ENGINE_REG_OFFLOAD_STATUS(x) (0x104 + (0x20 * x)) |
| 76 |
#define SPI_ENGINE_REG_OFFLOAD_RESET(x) (0x108 + (0x20 * x)) |
| 77 |
#define SPI_ENGINE_REG_OFFLOAD_CMD_MEM(x) (0x110 + (0x20 * x)) |
| 78 |
#define SPI_ENGINE_REG_OFFLOAD_SDO_MEM(x) (0x114 + (0x20 * x)) |
| 79 |
|
| 80 |
#define SPI_ENGINE_INT_CMD_ALMOST_EMPTY BIT(0) |
| 81 |
#define SPI_ENGINE_INT_SDO_ALMOST_EMPTY BIT(1) |
| 82 |
#define SPI_ENGINE_INT_SDI_ALMOST_FULL BIT(2) |
| 83 |
#define SPI_ENGINE_INT_SYNC BIT(3) |
| 84 |
|
| 85 |
#define SPI_ENGINE_OFFLOAD_CTRL_ENABLE BIT(0) |
| 86 |
#define SPI_ENGINE_OFFLOAD_STATUS_ENABLED BIT(0) |
| 87 |
|
| 88 |
#define SPI_ENGINE_CONFIG_CPHA BIT(0) |
| 89 |
#define SPI_ENGINE_CONFIG_CPOL BIT(1) |
| 90 |
#define SPI_ENGINE_CONFIG_3WIRE BIT(2) |
| 91 |
|
| 92 |
#define SPI_ENGINE_INST_TRANSFER 0x0 |
| 93 |
#define SPI_ENGINE_INST_ASSERT 0x1 |
| 94 |
#define SPI_ENGINE_INST_WRITE 0x2 |
| 95 |
#define SPI_ENGINE_INST_MISC 0x3 |
| 96 |
|
| 97 |
#define SPI_ENGINE_CMD_REG_CLK_DIV 0x0 |
| 98 |
#define SPI_ENGINE_CMD_REG_CONFIG 0x1 |
| 99 |
|
| 100 |
#define SPI_ENGINE_MISC_SYNC 0x0 |
| 101 |
#define SPI_ENGINE_MISC_SLEEP 0x1 |
| 102 |
|
| 103 |
#define SPI_ENGINE_CMD(inst, arg1, arg2) \ |
| 104 |
(((inst) << 12) | ((arg1) << 8) | (arg2)) |
| 105 |
|
| 106 |
#define SPI_ENGINE_CMD_TRANSFER(write, read, n) \ |
| 107 |
SPI_ENGINE_CMD(SPI_ENGINE_INST_TRANSFER, ((read) << 1 | (write)), (n)) |
| 108 |
#define SPI_ENGINE_CMD_ASSERT(delay, cs) \ |
| 109 |
SPI_ENGINE_CMD(SPI_ENGINE_INST_ASSERT, (delay), (cs)) |
| 110 |
#define SPI_ENGINE_CMD_WRITE(reg, val) \ |
| 111 |
SPI_ENGINE_CMD(SPI_ENGINE_INST_WRITE, (reg), (val)) |
| 112 |
#define SPI_ENGINE_CMD_SLEEP(delay) \ |
| 113 |
SPI_ENGINE_CMD(SPI_ENGINE_INST_MISC, SPI_ENGINE_MISC_SLEEP, (delay)) |
| 114 |
#define SPI_ENGINE_CMD_SYNC(id) \ |
| 115 |
SPI_ENGINE_CMD(SPI_ENGINE_INST_MISC, SPI_ENGINE_MISC_SYNC, (id)) |
| 116 |
|
| 117 |
|
| 118 |
#define DMAC_REG_IRQ_MASK 0x80 |
| 119 |
#define DMAC_REG_IRQ_PENDING 0x84 |
| 120 |
#define DMAC_REG_IRQ_SOURCE 0x88 |
| 121 |
|
| 122 |
#define DMAC_REG_CTRL 0x400 |
| 123 |
#define DMAC_REG_TRANSFER_ID 0x404 |
| 124 |
#define DMAC_REG_START_TRANSFER 0x408 |
| 125 |
#define DMAC_REG_FLAGS 0x40c |
| 126 |
#define DMAC_REG_DEST_ADDRESS 0x410 |
| 127 |
#define DMAC_REG_SRC_ADDRESS 0x414 |
| 128 |
#define DMAC_REG_X_LENGTH 0x418 |
| 129 |
#define DMAC_REG_Y_LENGTH 0x41c |
| 130 |
#define DMAC_REG_DEST_STRIDE 0x420 |
| 131 |
#define DMAC_REG_SRC_STRIDE 0x424 |
| 132 |
#define DMAC_REG_TRANSFER_DONE 0x428 |
| 133 |
#define DMAC_REG_ACTIVE_TRANSFER_ID 0x42c |
| 134 |
#define DMAC_REG_STATUS 0x430 |
| 135 |
#define DMAC_REG_CURRENT_DEST_ADDR 0x434 |
| 136 |
#define DMAC_REG_CURRENT_SRC_ADDR 0x438 |
| 137 |
#define DMAC_REG_DBG0 0x43c |
| 138 |
#define DMAC_REG_DBG1 0x440 |
| 139 |
|
| 140 |
#define DMAC_CTRL_ENABLE (1 << 0) |
| 141 |
#define DMAC_CTRL_PAUSE (1 << 1) |
| 142 |
|
| 143 |
#define DMAC_IRQ_SOT (1 << 0) |
| 144 |
#define DMAC_IRQ_EOT (1 << 1) |
| 145 |
|
| 146 |
|
| 147 |
#define CS_DEASSERT 0 << 28 |
| 148 |
|
| 149 |
#define CS_ASSERT 1 << 28 |
| 150 |
|
| 151 |
#define SLEEP_CMD 2 << 28 |
| 152 |
#define SLEEP(x) (SLEEP_CMD | (x & ( ~(0xF << 28) ))) |
| 153 |
|
| 154 |
#define TRANSFER_R_CMD 3 << 28 |
| 155 |
#define TRANSFER_R(x) (TRANSFER_R_CMD | (x & 0xF)) |
| 156 |
|
| 157 |
#define TRANSFER_W_CMD 4 << 28 |
| 158 |
#define TRANSFER_W(x) (TRANSFER_W_CMD | (x & 0xF)) |
| 159 |
|
| 160 |
#define TRANSFER_R_W_CMD 5 << 28 |
| 161 |
#define TRANSFER_R_W(x) (TRANSFER_R_W_CMD | (x & 0xF)) |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
typedef struct { |
| 168 |
uint32_t spi_baseaddr; |
| 169 |
uint8_t chip_select; |
| 170 |
uint8_t spi_config; |
| 171 |
uint32_t spi_clk_hz; |
| 172 |
uint32_t ref_clk_hz; |
| 173 |
uint32_t clk_div; |
| 174 |
uint32_t rx_length; |
| 175 |
uint32_t tx_length; |
| 176 |
uint8_t spi_offload_rx_support_en; |
| 177 |
uint32_t spi_offload_rx_dma_baseaddr; |
| 178 |
uint32_t rx_dma_startaddr; |
| 179 |
uint8_t spi_offload_tx_support_en; |
| 180 |
uint32_t spi_offload_tx_dma_baseaddr; |
| 181 |
uint32_t tx_dma_startaddr; |
| 182 |
uint8_t offload_configured; |
| 183 |
uint8_t data_width; |
| 184 |
} spi_dev; |
| 185 |
|
| 186 |
typedef struct { |
| 187 |
uint32_t spi_baseaddr; |
| 188 |
uint8_t chip_select; |
| 189 |
uint8_t spi_config; |
| 190 |
uint32_t spi_clk_hz; |
| 191 |
uint32_t ref_clk_hz; |
| 192 |
uint8_t spi_offload_rx_support_en; |
| 193 |
uint32_t spi_offload_rx_dma_baseaddr; |
| 194 |
uint8_t spi_offload_tx_support_en; |
| 195 |
uint32_t spi_offload_tx_dma_baseaddr; |
| 196 |
} spi_init_param; |
| 197 |
|
| 198 |
typedef struct { |
| 199 |
uint32_t tx_buf_addr; |
| 200 |
uint32_t rx_buf_addr; |
| 201 |
uint32_t *spi_msg_cmds; |
| 202 |
uint8_t msg_cmd_len; |
| 203 |
} spi_msg; |
| 204 |
|
| 205 |
|
| 206 |
typedef struct { |
| 207 |
uint32_t cmd_fifo_len; |
| 208 |
uint16_t cmd_fifo[]; |
| 209 |
} spi_transfer_fifo; |
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
int32_t spi_eng_write(spi_dev *dev, |
| 216 |
uint32_t reg_addr, |
| 217 |
uint32_t ui32data); |
| 218 |
|
| 219 |
int32_t spi_eng_read(spi_dev *dev, |
| 220 |
uint32_t reg_addr, |
| 221 |
uint32_t *reg_data); |
| 222 |
|
| 223 |
int32_t spi_eng_dma_write(spi_dev *dev, |
| 224 |
uint32_t reg_addr, |
| 225 |
uint32_t reg_data); |
| 226 |
|
| 227 |
int32_t spi_eng_dma_read(spi_dev *dev, |
| 228 |
uint32_t reg_addr, |
| 229 |
uint32_t *reg_data); |
| 230 |
|
| 231 |
|
| 232 |
int32_t spi_eng_setup(spi_dev **device, |
| 233 |
spi_init_param init_param); |
| 234 |
|
| 235 |
int32_t spi_eng_offload_load_msg(spi_dev *dev, spi_msg *msg); |
| 236 |
|
| 237 |
int32_t spi_eng_transfer_message(spi_dev *dev, spi_msg *msg); |
| 238 |
|
| 239 |
int32_t spi_eng_transfer_multiple_msgs(spi_dev *dev, uint8_t no_of_messages); |
| 240 |
|
| 241 |
#endif |