coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
fch_spi_ctrl.c File Reference
#include <console/console.h>
#include <spi_flash.h>
#include <soc/pci_devs.h>
#include <amdblocks/lpc.h>
#include <amdblocks/spi.h>
#include <device/pci_ops.h>
#include <lib.h>
#include <timer.h>
#include <types.h>
Include dependency graph for fch_spi_ctrl.c:

Go to the source code of this file.

Macros

#define GRANULARITY_TEST_4k   0x0000f000 /* bits 15-12 */
 
#define WORD_TO_DWORD_UPPER(x)   ((x << 16) & 0xffff0000)
 
#define SPI_RESTRICTED_CMD1   0x04
 
#define SPI_RESTRICTED_CMD2   0x08
 
#define SPI_CNTRL1   0x0c
 
#define SPI_CMD_CODE   0x45
 
#define SPI_CMD_TRIGGER   0x47
 
#define SPI_CMD_TRIGGER_EXECUTE   BIT(7)
 
#define SPI_TX_BYTE_COUNT   0x48
 
#define SPI_RX_BYTE_COUNT   0x4b
 
#define SPI_STATUS   0x4c
 
#define SPI_DONE_BYTE_COUNT_SHIFT   0
 
#define SPI_DONE_BYTE_COUNT_MASK   0xff
 
#define SPI_FIFO_WR_PTR_SHIFT   8
 
#define SPI_FIFO_WR_PTR_MASK   0x7f
 
#define SPI_FIFO_RD_PTR_SHIFT   16
 
#define SPI_FIFO_RD_PTR_MASK   0x7f
 

Enumerations

enum  spi_dump_state_phase { SPI_DUMP_STATE_BEFORE_CMD , SPI_DUMP_STATE_AFTER_CMD }
 

Functions

static void dump_state (enum spi_dump_state_phase phase)
 
static int wait_for_ready (void)
 
static int execute_command (void)
 
void spi_init (void)
 
static int spi_ctrlr_xfer (const struct spi_slave *slave, const void *dout, size_t bytesout, void *din, size_t bytesin)
 
static int xfer_vectors (const struct spi_slave *slave, struct spi_op vectors[], size_t count)
 
static int protect_a_range (u32 value)
 
static int fch_spi_flash_protect (const struct spi_flash *flash, const struct region *region, const enum ctrlr_prot_type type)
 

Variables

static const struct spi_ctrlr fch_spi_flash_ctrlr
 
const struct spi_ctrlr_buses spi_ctrlr_bus_map []
 
const size_t spi_ctrlr_bus_map_count = ARRAY_SIZE(spi_ctrlr_bus_map)
 

Macro Definition Documentation

◆ GRANULARITY_TEST_4k

#define GRANULARITY_TEST_4k   0x0000f000 /* bits 15-12 */

Definition at line 13 of file fch_spi_ctrl.c.

◆ SPI_CMD_CODE

#define SPI_CMD_CODE   0x45

Definition at line 20 of file fch_spi_ctrl.c.

◆ SPI_CMD_TRIGGER

#define SPI_CMD_TRIGGER   0x47

Definition at line 21 of file fch_spi_ctrl.c.

◆ SPI_CMD_TRIGGER_EXECUTE

#define SPI_CMD_TRIGGER_EXECUTE   BIT(7)

Definition at line 22 of file fch_spi_ctrl.c.

◆ SPI_CNTRL1

#define SPI_CNTRL1   0x0c

Definition at line 19 of file fch_spi_ctrl.c.

◆ SPI_DONE_BYTE_COUNT_MASK

#define SPI_DONE_BYTE_COUNT_MASK   0xff

Definition at line 27 of file fch_spi_ctrl.c.

◆ SPI_DONE_BYTE_COUNT_SHIFT

#define SPI_DONE_BYTE_COUNT_SHIFT   0

Definition at line 26 of file fch_spi_ctrl.c.

◆ SPI_FIFO_RD_PTR_MASK

#define SPI_FIFO_RD_PTR_MASK   0x7f

Definition at line 31 of file fch_spi_ctrl.c.

◆ SPI_FIFO_RD_PTR_SHIFT

#define SPI_FIFO_RD_PTR_SHIFT   16

Definition at line 30 of file fch_spi_ctrl.c.

◆ SPI_FIFO_WR_PTR_MASK

#define SPI_FIFO_WR_PTR_MASK   0x7f

Definition at line 29 of file fch_spi_ctrl.c.

◆ SPI_FIFO_WR_PTR_SHIFT

#define SPI_FIFO_WR_PTR_SHIFT   8

Definition at line 28 of file fch_spi_ctrl.c.

◆ SPI_RESTRICTED_CMD1

#define SPI_RESTRICTED_CMD1   0x04

Definition at line 17 of file fch_spi_ctrl.c.

◆ SPI_RESTRICTED_CMD2

#define SPI_RESTRICTED_CMD2   0x08

Definition at line 18 of file fch_spi_ctrl.c.

◆ SPI_RX_BYTE_COUNT

#define SPI_RX_BYTE_COUNT   0x4b

Definition at line 24 of file fch_spi_ctrl.c.

◆ SPI_STATUS

#define SPI_STATUS   0x4c

Definition at line 25 of file fch_spi_ctrl.c.

◆ SPI_TX_BYTE_COUNT

#define SPI_TX_BYTE_COUNT   0x48

Definition at line 23 of file fch_spi_ctrl.c.

◆ WORD_TO_DWORD_UPPER

#define WORD_TO_DWORD_UPPER (   x)    ((x << 16) & 0xffff0000)

Definition at line 14 of file fch_spi_ctrl.c.

Enumeration Type Documentation

◆ spi_dump_state_phase

Enumerator
SPI_DUMP_STATE_BEFORE_CMD 
SPI_DUMP_STATE_AFTER_CMD 

Definition at line 33 of file fch_spi_ctrl.c.

Function Documentation

◆ dump_state()

◆ execute_command()

static int execute_command ( void  )
static

Definition at line 104 of file fch_spi_ctrl.c.

References BIOS_ERR, dump_state(), printk, SPI_CMD_TRIGGER, SPI_CMD_TRIGGER_EXECUTE, SPI_DUMP_STATE_AFTER_CMD, SPI_DUMP_STATE_BEFORE_CMD, spi_write8(), and wait_for_ready().

Referenced by spi_ctrlr_xfer().

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

◆ fch_spi_flash_protect()

static int fch_spi_flash_protect ( const struct spi_flash flash,
const struct region region,
const enum ctrlr_prot_type  type 
)
static

Definition at line 216 of file fch_spi_ctrl.c.

◆ protect_a_range()

static int protect_a_range ( u32  value)
static

Definition at line 185 of file fch_spi_ctrl.c.

References MAX_ROM_PROTECT_RANGES, pci_read_config32(), pci_write_config32(), ROM_PROTECT_RANGE_REG, SOC_LPC_DEV, and value.

Here is the call graph for this function:

◆ spi_ctrlr_xfer()

static int spi_ctrlr_xfer ( const struct spi_slave slave,
const void dout,
size_t  bytesout,
void din,
size_t  bytesin 
)
static

Definition at line 125 of file fch_spi_ctrl.c.

References BIOS_DEBUG, BIOS_ERR, BIOS_WARNING, CONFIG, count, execute_command(), printk, SPI_CMD_CODE, SPI_FIFO, SPI_FIFO_DEPTH, spi_read8(), SPI_RX_BYTE_COUNT, SPI_TX_BYTE_COUNT, spi_write8(), and wait_for_ready().

Referenced by xfer_vectors().

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

◆ spi_init()

void spi_init ( void  )

Definition at line 120 of file fch_spi_ctrl.c.

References BIOS_DEBUG, printk, and spi_get_bar().

Here is the call graph for this function:

◆ wait_for_ready()

static int wait_for_ready ( void  )
static

Definition at line 89 of file fch_spi_ctrl.c.

References SPI_BUSY, spi_read32(), SPI_STATUS, stopwatch_expired(), and stopwatch_init_msecs_expire().

Referenced by execute_command(), and spi_ctrlr_xfer().

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

◆ xfer_vectors()

static int xfer_vectors ( const struct spi_slave slave,
struct spi_op  vectors[],
size_t  count 
)
static

Definition at line 173 of file fch_spi_ctrl.c.

References count, slave, spi_ctrlr_xfer(), spi_flash_vector_helper(), spi_hw_mutex, thread_mutex_lock(), and thread_mutex_unlock().

Here is the call graph for this function:

Variable Documentation

◆ fch_spi_flash_ctrlr

const struct spi_ctrlr fch_spi_flash_ctrlr
static
Initial value:
= {
.xfer_vector = xfer_vectors,
.max_xfer_size = SPI_FIFO_DEPTH,
.flash_protect = fch_spi_flash_protect,
}
static int xfer_vectors(const struct spi_slave *slave, struct spi_op vectors[], size_t count)
Definition: fch_spi_ctrl.c:173
static int fch_spi_flash_protect(const struct spi_flash *flash, const struct region *region, const enum ctrlr_prot_type type)
Definition: fch_spi_ctrl.c:216
#define SPI_FIFO_DEPTH
Definition: spi.h:75
@ SPI_CNTRLR_DEDUCT_CMD_LEN
Definition: spi-generic.h:116
@ SPI_CNTRLR_DEDUCT_OPCODE_LEN
Definition: spi-generic.h:121

Definition at line 216 of file fch_spi_ctrl.c.

◆ spi_ctrlr_bus_map

const struct spi_ctrlr_buses spi_ctrlr_bus_map[]
Initial value:
= {
{
.bus_start = 0,
.bus_end = 0,
},
}
static const struct spi_ctrlr fch_spi_flash_ctrlr
Definition: fch_spi_ctrl.c:293

Definition at line 216 of file fch_spi_ctrl.c.

◆ spi_ctrlr_bus_map_count

const size_t spi_ctrlr_bus_map_count = ARRAY_SIZE(spi_ctrlr_bus_map)

Definition at line 308 of file fch_spi_ctrl.c.