xfel/fel.h

73 lines
2.2 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-04 15:35:21 +08:00
int (*spi_init)(struct xfel_ctx_t * ctx);
int (*spi_exit)(struct xfel_ctx_t * ctx);
int (*spi_select)(struct xfel_ctx_t * ctx);
int (*spi_deselect)(struct xfel_ctx_t * ctx);
2021-06-05 15:03:19 +08:00
int (*spi_xfer)(struct xfel_ctx_t * ctx, void * txbuf, uint32_t txlen, void * rxbuf, uint32_t rxlen);
2021-05-25 23:44:28 +08:00
};
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-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-05-25 23:44:28 +08:00
int fel_chip_reset(struct xfel_ctx_t * ctx);
2021-05-26 10:42:14 +08:00
int fel_chip_sid(struct xfel_ctx_t * ctx, uint32_t * sid);
2021-05-25 23:44:28 +08:00
int fel_chip_jtag(struct xfel_ctx_t * ctx);
int fel_chip_ddr(struct xfel_ctx_t * ctx, const char * type);
2021-06-04 15:35:21 +08:00
int fel_chip_spi_init(struct xfel_ctx_t * ctx);
int fel_chip_spi_exit(struct xfel_ctx_t * ctx);
int fel_chip_spi_select(struct xfel_ctx_t * ctx);
int fel_chip_spi_deselect(struct xfel_ctx_t * ctx);
2021-06-05 15:03:19 +08:00
int fel_chip_spi_xfer(struct xfel_ctx_t * ctx, void * txbuf, uint32_t txlen, void * rxbuf, uint32_t rxlen);
2021-06-04 15:35:21 +08:00
2021-05-25 16:56:02 +08:00
#ifdef __cplusplus
}
#endif
#endif /* __FEL_H__ */