coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
spi.c File Reference
#include <stdint.h>
#include <device/mmio.h>
#include <console/console.h>
#include <spi_flash.h>
#include <spi-generic.h>
#include <device/device.h>
#include <device/pci.h>
#include <device/pci_ops.h>
#include <stddef.h>
#include <Proc/Fch/FchPlatform.h>
Include dependency graph for spi.c:

Go to the source code of this file.

Macros

#define SPI_REG_OPCODE   0x0
 
#define SPI_REG_CNTRL01   0x1
 
#define SPI_REG_CNTRL02   0x2
 
#define CNTRL02_FIFO_RESET   (1 << 4)
 
#define CNTRL02_EXEC_OPCODE   (1 << 0)
 
#define SPI_REG_CNTRL03   0x3
 
#define CNTRL03_SPIBUSY   (1 << 7)
 
#define SPI_REG_FIFO   0xc
 
#define SPI_REG_CNTRL11   0xd
 
#define CNTRL11_FIFOPTR_MASK   0x07
 
#define AMD_SB_SPI_TX_LEN   8
 

Functions

static uint8_t spi_read (uint8_t reg)
 
static void spi_write (uint8_t reg, uint8_t val)
 
static void reset_internal_fifo_pointer (void)
 
static void execute_command (void)
 
void spi_init (void)
 Init all SPI controllers with default values and enable all SPI controller. More...
 
static int spi_ctrlr_xfer (const struct spi_slave *slave, const void *dout, size_t bytesout, void *din, size_t bytesin)
 
int chipset_volatile_group_begin (const struct spi_flash *flash)
 
int chipset_volatile_group_end (const struct spi_flash *flash)
 
static int xfer_vectors (const struct spi_slave *slave, struct spi_op vectors[], size_t count)
 

Variables

static uintptr_t spibar
 
static const struct spi_ctrlr spi_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

◆ AMD_SB_SPI_TX_LEN

#define AMD_SB_SPI_TX_LEN   8

Definition at line 29 of file spi.c.

◆ CNTRL02_EXEC_OPCODE

#define CNTRL02_EXEC_OPCODE   (1 << 0)

Definition at line 19 of file spi.c.

◆ CNTRL02_FIFO_RESET

#define CNTRL02_FIFO_RESET   (1 << 4)

Definition at line 18 of file spi.c.

◆ CNTRL03_SPIBUSY

#define CNTRL03_SPIBUSY   (1 << 7)

Definition at line 21 of file spi.c.

◆ CNTRL11_FIFOPTR_MASK

#define CNTRL11_FIFOPTR_MASK   0x07

Definition at line 24 of file spi.c.

◆ SPI_REG_CNTRL01

#define SPI_REG_CNTRL01   0x1

Definition at line 16 of file spi.c.

◆ SPI_REG_CNTRL02

#define SPI_REG_CNTRL02   0x2

Definition at line 17 of file spi.c.

◆ SPI_REG_CNTRL03

#define SPI_REG_CNTRL03   0x3

Definition at line 20 of file spi.c.

◆ SPI_REG_CNTRL11

#define SPI_REG_CNTRL11   0xd

Definition at line 23 of file spi.c.

◆ SPI_REG_FIFO

#define SPI_REG_FIFO   0xc

Definition at line 22 of file spi.c.

◆ SPI_REG_OPCODE

#define SPI_REG_OPCODE   0x0

Definition at line 15 of file spi.c.

Function Documentation

◆ chipset_volatile_group_begin()

int chipset_volatile_group_begin ( const struct spi_flash flash)

Definition at line 132 of file spi.c.

◆ chipset_volatile_group_end()

int chipset_volatile_group_end ( const struct spi_flash flash)

Definition at line 141 of file spi.c.

◆ execute_command()

static void execute_command ( void  )
static

Definition at line 55 of file spi.c.

References CNTRL02_EXEC_OPCODE, CNTRL03_SPIBUSY, spi_read(), SPI_REG_CNTRL02, SPI_REG_CNTRL03, and spi_write().

Referenced by spi_ctrlr_xfer().

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

◆ reset_internal_fifo_pointer()

static void reset_internal_fifo_pointer ( void  )
static

Definition at line 44 of file spi.c.

References CNTRL02_FIFO_RESET, CNTRL11_FIFOPTR_MASK, spi_read(), SPI_REG_CNTRL02, SPI_REG_CNTRL11, and spi_write().

Referenced by spi_ctrlr_xfer().

Here is the call graph for this function:
Here is the caller 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 75 of file spi.c.

References AMD_SB_SPI_TX_LEN, BIOS_DEBUG, CONFIG, count, execute_command(), printk, reset_internal_fifo_pointer(), spi_read(), SPI_REG_CNTRL01, SPI_REG_FIFO, SPI_REG_OPCODE, and spi_write().

Here is the call graph for this function:

◆ spi_init()

void spi_init ( void  )

Init all SPI controllers with default values and enable all SPI controller.

Definition at line 67 of file spi.c.

References pci_read_config32(), pcidev_on_root(), and spibar.

Here is the call graph for this function:

◆ spi_read()

static uint8_t spi_read ( uint8_t  reg)
inlinestatic

Definition at line 34 of file spi.c.

References read8(), and spibar.

Referenced by execute_command(), reset_internal_fifo_pointer(), and spi_ctrlr_xfer().

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

◆ spi_write()

static void spi_write ( uint8_t  reg,
uint8_t  val 
)
inlinestatic

Definition at line 39 of file spi.c.

References spibar, val, and write8().

Referenced by execute_command(), reset_internal_fifo_pointer(), 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 150 of file spi.c.

Variable Documentation

◆ spi_ctrlr

const struct spi_ctrlr spi_ctrlr
static
Initial value:
= {
.xfer_vector = xfer_vectors,
.max_xfer_size = AMD_SB_SPI_TX_LEN,
}
static int xfer_vectors(const struct spi_slave *slave, struct spi_op vectors[], size_t count)
Definition: spi.c:150
#define AMD_SB_SPI_TX_LEN
Definition: spi.c:29
@ SPI_CNTRLR_DEDUCT_CMD_LEN
Definition: spi-generic.h:116

Definition at line 150 of file spi.c.

◆ spi_ctrlr_bus_map

const struct spi_ctrlr_buses spi_ctrlr_bus_map[]
Initial value:
= {
{
.ctrlr = &spi_ctrlr,
.bus_start = 0,
.bus_end = 0,
},
}
const struct spi_ctrlr spi_ctrlr
Definition: spi.c:261

Definition at line 150 of file spi.c.

◆ spi_ctrlr_bus_map_count

const size_t spi_ctrlr_bus_map_count = ARRAY_SIZE(spi_ctrlr_bus_map)

Definition at line 170 of file spi.c.

◆ spibar