xfel/fel.h

109 lines
3.0 KiB
C
Raw Normal View History

2021-05-25 16:56:02 +08:00
#ifndef __FEL_H__
#define __FEL_H__
#ifdef __cplusplus
extern "C" {
#endif
2021-05-25 23:44:28 +08:00
#include <x.h>
#include <progress.h>
2021-05-25 16:56:02 +08:00
2021-05-25 23:44:28 +08:00
struct xfel_ctx_t;
struct chip_t;
2021-05-25 16:56:02 +08:00
struct xfel_ctx_t {
libusb_device_handle * hdl;
int epout;
int epin;
2021-05-25 23:44:28 +08:00
struct {
2021-05-26 17:22:48 +08:00
char magic[8];
2021-05-25 23:44:28 +08:00
uint32_t id;
2021-05-26 17:22:48 +08:00
uint32_t firmware;
2021-05-25 23:44:28 +08:00
uint16_t protocol;
2021-05-26 17:22:48 +08:00
uint8_t dflag;
uint8_t dlength;
2021-05-25 23:44:28 +08:00
uint32_t scratchpad;
2021-05-26 17:22:48 +08:00
uint8_t pad[8];
2021-05-25 23:44:28 +08:00
} version;
2021-05-25 16:56:02 +08:00
struct chip_t * chip;
};
2021-05-25 23:44:28 +08:00
struct chip_t {
char * name;
uint32_t id;
int (*reset)(struct xfel_ctx_t * ctx);
2021-05-26 10:42:14 +08:00
int (*sid)(struct xfel_ctx_t * ctx, uint32_t * sid);
2021-05-25 23:44:28 +08:00
int (*jtag)(struct xfel_ctx_t * ctx);
int (*ddr)(struct xfel_ctx_t * ctx, const char * type);
2021-06-12 14:09:43 +08:00
int (*spi_init)(struct xfel_ctx_t * ctx, uint32_t * swapbuf, uint32_t * swaplen);
int (*spi_run)(struct xfel_ctx_t * ctx, uint8_t * cbuf, uint32_t clen);
2021-06-12 14:09:43 +08:00
};
enum {
SPI_CMD_END = 0x00,
SPI_CMD_INIT = 0x01,
SPI_CMD_SELECT = 0x02,
SPI_CMD_DESELECT = 0x03,
2021-06-12 21:02:21 +08:00
SPI_CMD_FAST = 0x04,
SPI_CMD_TXBUF = 0x05,
SPI_CMD_RXBUF = 0x06,
SPI_CMD_SPINOR_WAIT = 0x07,
SPI_CMD_SPINAND_WAIT = 0x08,
2021-05-25 23:44:28 +08:00
};
/*
* This R32 and W32 macro can only be used for byte access address, Don't used for address
* that can only support word access. Because the fel protocol can only support
* byte operation, VERY IMPORTANT !!!
*/
2021-06-05 15:03:19 +08:00
#define R32(reg) fel_read32(ctx, reg)
2021-05-26 10:49:30 +08:00
#define W32(reg, val) fel_write32(ctx, reg, val)
2021-05-25 23:44:28 +08:00
2021-06-10 18:16:11 +08:00
static inline int fel_chip_reset(struct xfel_ctx_t * ctx)
{
return ctx->chip->reset(ctx);
}
static inline int fel_chip_sid(struct xfel_ctx_t * ctx, uint32_t * sid)
{
return ctx->chip->sid(ctx, sid);
}
static inline int fel_chip_jtag(struct xfel_ctx_t * ctx)
{
return ctx->chip->jtag(ctx);
}
static inline int fel_chip_ddr(struct xfel_ctx_t * ctx, const char * type)
{
return ctx->chip->ddr(ctx, type);
}
2021-06-12 14:09:43 +08:00
static inline int fel_chip_spi_init(struct xfel_ctx_t * ctx, uint32_t * swapbuf, uint32_t * swaplen)
2021-06-10 18:16:11 +08:00
{
2021-06-12 14:09:43 +08:00
return ctx->chip->spi_init(ctx, swapbuf, swaplen);
2021-06-10 18:16:11 +08:00
}
static inline int fel_chip_spi_run(struct xfel_ctx_t * ctx, uint8_t * cbuf, uint32_t clen)
2021-06-10 18:16:11 +08:00
{
return ctx->chip->spi_run(ctx, cbuf, clen);
2021-06-10 18:16:11 +08:00
}
2021-05-26 10:03:58 +08:00
int fel_init(struct xfel_ctx_t * ctx);
2021-05-25 23:44:28 +08:00
void fel_exec(struct xfel_ctx_t * ctx, uint32_t addr);
2021-06-05 15:03:19 +08:00
uint32_t fel_read32(struct xfel_ctx_t * ctx, uint32_t addr);
2021-05-25 23:44:28 +08:00
void fel_write32(struct xfel_ctx_t * ctx, uint32_t addr, uint32_t val);
2021-06-05 15:03:19 +08:00
void fel_read(struct xfel_ctx_t * ctx, uint32_t addr, void * buf, size_t len);
void fel_write(struct xfel_ctx_t * ctx, uint32_t addr, void * buf, size_t len);
void fel_read_progress(struct xfel_ctx_t * ctx, uint32_t addr, void * buf, size_t len);
void fel_write_progress(struct xfel_ctx_t * ctx, uint32_t addr, void * buf, size_t len);
2021-06-12 14:09:43 +08:00
int fel_spi_init(struct xfel_ctx_t * ctx, uint32_t * swapbuf, uint32_t * swaplen);
int fel_spi_xfer(struct xfel_ctx_t * ctx, uint32_t swapbuf, uint32_t swaplen, void * txbuf, uint32_t txlen, void * rxbuf, uint32_t rxlen);
2021-05-25 23:44:28 +08:00
2021-05-25 16:56:02 +08:00
#ifdef __cplusplus
}
#endif
#endif /* __FEL_H__ */