8 #include <soc/pci_devs.h>
14 #define BOILERPLATE_CREATE_CTX(ctx) \
15 struct fast_spi_flash_ctx real_ctx; \
16 struct fast_spi_flash_ctx *ctx = &real_ctx; \
17 _fast_spi_flash_get_ctx(ctx)
118 printk(
BIOS_ERR,
"SPI Transaction Error at Flash Offset %x HSFSTS = 0x%08x\n",
127 printk(
BIOS_ERR,
"SPI Transaction Timeout (Exceeded %d ms) at Flash Offset %x HSFSTS = 0x%08x\n",
154 printk(
BIOS_ERR,
"SPI Transaction Timeout (Exceeded %d ms) due to prior"
155 " operation at Flash Offset %x\n",
170 printk(
BIOS_ERR,
"SPI Transaction Timeout (Exceeded %d ms) due to prior"
187 xfer_len =
MIN(xfer_len, bytes_left);
208 erase_size = 64 *
KiB;
211 erase_size = 4 *
KiB;
322 flash->
size = (flash_bits >> 3) + 1;
343 printk(
BIOS_ERR,
"%s: Invalid CS for fast SPI bus=0x%x,cs=0x%x!\n",
344 __func__, dev->
bus, dev->
cs);
351 #define SPI_FPR_SHIFT 12
352 #define SPI_FPR_MASK 0x7fff
353 #define SPI_FPR_BASE_SHIFT 0
354 #define SPI_FPR_LIMIT_SHIFT 16
355 #define SPI_FPR_RPE (1 << 15)
356 #define SPI_FPR_WPE (1 << 31)
357 #define SPI_FPR(base, limit) \
358 (((((limit) >> SPI_FPR_SHIFT) & SPI_FPR_MASK) << SPI_FPR_LIMIT_SHIFT) |\
359 ((((base) >> SPI_FPR_SHIFT) & SPI_FPR_MASK) << SPI_FPR_BASE_SHIFT))
372 u32 protect_mask = 0;
381 reg =
read32((
void *)fpr_base);
408 reg =
SPI_FPR(start, end) | protect_mask;
411 write32((
void *)fpr_base, reg);
412 reg =
read32((
void *)fpr_base);
413 if (!(reg & protect_mask)) {
419 __func__, fpr, start, end);
static void write32(void *addr, uint32_t val)
static uint32_t read32(const void *addr)
void * memcpy(void *dest, const void *src, size_t n)
#define printk(level,...)
void * fast_spi_get_bar(void)
#define SPIBAR_HSFSTS_CYCLE_4K_ERASE
#define SPIBAR_PTINX_HORD_JEDEC
#define SPIBAR_HSFSTS_W1C_BITS
#define SPIBAR_FDATA_FIFO_SIZE
#define SPIBAR_PTINX_IDX_MASK
#define SPIBAR_HSFSTS_CYCLE_RD_STATUS
#define SPIBAR_HSFSTS_FDONE
#define SPIBAR_HSFSTS_CYCLE_64K_ERASE
#define SPIBAR_HSFSTS_FCYCLE_MASK
#define SPIBAR_HSFSTS_CTL
#define SPIBAR_HSFSTS_FCERR
#define SPIBAR_HWSEQ_XFER_TIMEOUT_MS
#define SPIBAR_HSFSTS_SCIP
#define SPIBAR_HSFSTS_FDBC(n)
#define SPIBAR_HSFSTS_CYCLE_WRITE
#define SPIBAR_HSFSTS_CYCLE_READ
#define SPIBAR_HSFSTS_FGO
static int wait_for_hwseq_spi_cycle_complete(struct fast_spi_flash_ctx *ctx)
static int fast_spi_flash_status(const struct spi_flash *flash, uint8_t *reg)
static int fast_spi_flash_ctrlr_setup(const struct spi_slave *dev)
static int fast_spi_flash_write(const struct spi_flash *flash, uint32_t addr, size_t len, const void *buf)
#define BOILERPLATE_CREATE_CTX(ctx)
static void drain_xfer_fifo(struct fast_spi_flash_ctx *ctx, void *dest, size_t len)
static size_t get_xfer_len(const struct spi_flash *flash, uint32_t addr, size_t len)
const struct spi_ctrlr fast_spi_flash_ctrlr
static void fast_spi_flash_ctrlr_reg_write(struct fast_spi_flash_ctx *ctx, uint16_t reg, uint32_t val)
static uint32_t fast_spi_flash_read_sfdp_param(struct fast_spi_flash_ctx *ctx, uint16_t sfdp_reg)
static int fast_spi_flash_probe(const struct spi_slave *dev, struct spi_flash *flash)
int fast_spi_cycle_in_progress(void)
static int fast_spi_flash_erase(const struct spi_flash *flash, uint32_t offset, size_t len)
static void _fast_spi_flash_get_ctx(struct fast_spi_flash_ctx *ctx)
static void start_hwseq_xfer(struct fast_spi_flash_ctx *ctx, uint32_t hsfsts_cycle, uint32_t flash_addr, size_t len)
static int exec_sync_hwseq_xfer(struct fast_spi_flash_ctx *ctx, uint32_t hsfsts_cycle, uint32_t flash_addr, size_t len)
#define SPI_FPR(base, limit)
static int fast_spi_flash_read(const struct spi_flash *flash, uint32_t addr, size_t len, void *buf)
static int fast_spi_flash_protect(const struct spi_flash *flash, const struct region *region, const enum ctrlr_prot_type type)
static uint32_t fast_spi_flash_ctrlr_reg_read(struct fast_spi_flash_ctx *ctx, uint16_t reg)
const struct spi_flash_ops fast_spi_flash_ops
static void fill_xfer_fifo(struct fast_spi_flash_ctx *ctx, const void *data, size_t len)
static int wait_for_hwseq_xfer(struct fast_spi_flash_ctx *ctx, uint32_t flash_addr)
static int stopwatch_expired(struct stopwatch *sw)
static void stopwatch_init_msecs_expire(struct stopwatch *sw, long ms)
#define BIOS_INFO
BIOS_INFO - Expected events.
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
#define BIOS_SPEW
BIOS_SPEW - Excessively verbose output.
static size_t region_sz(const struct region *r)
static size_t region_offset(const struct region *r)
#define SPI_CTRLR_DEFAULT_MAX_XFER_SIZE
int(* setup)(const struct spi_slave *slave)
int(* read)(const struct spi_flash *flash, u32 offset, size_t len, void *buf)
const struct spi_flash_ops * ops