coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
flash_controller.c File Reference
#include <assert.h>
#include <console/console.h>
#include <device/mmio.h>
#include <soc/flash_controller_common.h>
#include <soc/symbols.h>
#include <spi_flash.h>
#include <spi-generic.h>
#include <string.h>
#include <symbols.h>
#include <timer.h>
#include <types.h>
Include dependency graph for flash_controller.c:

Go to the source code of this file.

Macros

#define GET_NTH_BYTE(d, n)   ((d >> (8 * n)) & 0xff)
 

Functions

static int polling_cmd (u32 val)
 
static int mtk_nor_execute_cmd (u8 cmdval)
 
static int sflashhw_read_flash_status (u8 *value)
 
static int wait_for_write_done (void)
 
static void set_sfpaddr (u32 addr)
 
static int sector_erase (int offset)
 
static int dma_read (u32 addr, uintptr_t dma_buf, u32 len)
 
static int nor_read (const struct spi_flash *flash, u32 addr, size_t len, void *buf)
 
static int nor_write (const struct spi_flash *flash, u32 addr, size_t len, const void *buf)
 
static int nor_erase (const struct spi_flash *flash, u32 offset, size_t len)
 
int mtk_spi_flash_probe (const struct spi_slave *spi, struct spi_flash *flash)
 

Variables

static struct mtk_nor_regs *const mtk_nor = (void *)SFLASH_REG_BASE
 
const struct spi_flash_ops spi_flash_ops
 

Macro Definition Documentation

◆ GET_NTH_BYTE

#define GET_NTH_BYTE (   d,
 
)    ((d >> (8 * n)) & 0xff)

Definition at line 17 of file flash_controller.c.

Function Documentation

◆ dma_read()

static int dma_read ( u32  addr,
uintptr_t  dma_buf,
u32  len 
)
static

◆ mtk_nor_execute_cmd()

static int mtk_nor_execute_cmd ( u8  cmdval)
static

Definition at line 33 of file flash_controller.c.

References mtk_nor_regs::cmd, mtk_nor, polling_cmd(), SFLASH_AUTOINC, val, and write8().

Referenced by nor_write(), sector_erase(), and sflashhw_read_flash_status().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mtk_spi_flash_probe()

int mtk_spi_flash_probe ( const struct spi_slave spi,
struct spi_flash flash 
)

◆ nor_erase()

static int nor_erase ( const struct spi_flash flash,
u32  offset,
size_t  len 
)
static

Definition at line 188 of file flash_controller.c.

References BIOS_WARNING, offset, printk, sector_erase(), and spi_flash::sector_size.

Here is the call graph for this function:

◆ nor_read()

static int nor_read ( const struct spi_flash flash,
u32  addr,
size_t  len,
void buf 
)
static

◆ nor_write()

static int nor_write ( const struct spi_flash flash,
u32  addr,
size_t  len,
const void buf 
)
static

Definition at line 169 of file flash_controller.c.

References addr, buf, buffer, mtk_nor, mtk_nor_execute_cmd(), set_sfpaddr(), SFLASH_AUTOINC, SFLASH_WR_TRIGGER, wait_for_write_done(), mtk_nor_regs::wdata, and write8().

Here is the call graph for this function:

◆ polling_cmd()

static int polling_cmd ( u32  val)
static

Definition at line 19 of file flash_controller.c.

References mtk_nor_regs::cmd, mtk_nor, read32(), SFLASH_POLLINGREG_US, stopwatch_expired(), stopwatch_init_usecs_expire(), and val.

Referenced by mtk_nor_execute_cmd().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sector_erase()

static int sector_erase ( int  offset)
static

Definition at line 75 of file flash_controller.c.

References mtk_nor_regs::cnt, GET_NTH_BYTE, mtk_nor, mtk_nor_execute_cmd(), offset, mtk_nor_regs::prgdata, SECTOR_ERASE_CMD, SFLASH_OP_WREN, SFLASH_PRG_CMD, wait_for_write_done(), and write8().

Referenced by nor_erase().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_sfpaddr()

static void set_sfpaddr ( u32  addr)
static

Definition at line 68 of file flash_controller.c.

References addr, GET_NTH_BYTE, mtk_nor, mtk_nor_regs::radr, and write8().

Referenced by nor_write().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sflashhw_read_flash_status()

static int sflashhw_read_flash_status ( u8 value)
static

Definition at line 41 of file flash_controller.c.

References mtk_nor, mtk_nor_execute_cmd(), mtk_nor_regs::rdsr, read8(), SFLASH_READSTATUS, and value.

Referenced by wait_for_write_done().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ wait_for_write_done()

static int wait_for_write_done ( void  )
static

Definition at line 50 of file flash_controller.c.

References SFLASH_POLLINGREG_US, SFLASH_WRITE_IN_PROGRESS, sflashhw_read_flash_status(), stopwatch_expired(), and stopwatch_init_usecs_expire().

Referenced by nor_write(), and sector_erase().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ mtk_nor

◆ spi_flash_ops

Initial value:
= {
.read = nor_read,
.write = nor_write,
.erase = nor_erase,
}
static int nor_write(const struct spi_flash *flash, u32 addr, size_t len, const void *buf)
static int nor_erase(const struct spi_flash *flash, u32 offset, size_t len)
static int nor_read(const struct spi_flash *flash, u32 addr, size_t len, void *buf)

Definition at line 188 of file flash_controller.c.

Referenced by mtk_spi_flash_probe().