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

Go to the source code of this file.

Data Structures

struct  rockchip_spi_slave
 

Macros

#define SPI_TIMEOUT_US   1000
 
#define SPI_SRCCLK_HZ   (198*MHz)
 
#define SPI_FIFO_DEPTH   32
 

Functions

static struct rockchip_spi_slaveto_rockchip_spi (const struct spi_slave *slave)
 
static void spi_cs_activate (const struct spi_slave *slave)
 
static void spi_cs_deactivate (const struct spi_slave *slave)
 
static void rockchip_spi_enable_chip (struct rockchip_spi *regs, int enable)
 
static void rockchip_spi_set_clk (struct rockchip_spi *regs, unsigned int hz)
 
void rockchip_spi_init (unsigned int bus, unsigned int speed_hz)
 
void rockchip_spi_set_sample_delay (unsigned int bus, unsigned int delay_ns)
 
static int spi_ctrlr_claim_bus (const struct spi_slave *slave)
 
static void spi_ctrlr_release_bus (const struct spi_slave *slave)
 
static int rockchip_spi_wait_till_not_busy (struct rockchip_spi *regs)
 
static void set_tmod (struct rockchip_spi *regs, unsigned int tmod)
 
static void set_transfer_mode (struct rockchip_spi *regs, unsigned int sout, unsigned int sin)
 
static int do_xfer (struct rockchip_spi *regs, bool use_16bit, const void *dout, size_t *bytes_out, void *din, size_t *bytes_in)
 
static int spi_ctrlr_xfer (const struct spi_slave *slave, const void *dout, size_t bytes_out, void *din, size_t bytes_in)
 

Variables

static struct rockchip_spi_slave rockchip_spi_slaves []
 
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

◆ SPI_FIFO_DEPTH

#define SPI_FIFO_DEPTH   32

Definition at line 22 of file spi.c.

◆ SPI_SRCCLK_HZ

#define SPI_SRCCLK_HZ   (198*MHz)

Definition at line 21 of file spi.c.

◆ SPI_TIMEOUT_US

#define SPI_TIMEOUT_US   1000

Definition at line 20 of file spi.c.

Function Documentation

◆ do_xfer()

static int do_xfer ( struct rockchip_spi regs,
bool  use_16bit,
const void dout,
size_t bytes_out,
void din,
size_t bytes_in 
)
static

Definition at line 180 of file spi.c.

References BIOS_ERR, buffer_from_fifo32(), MIN, printk, read32(), rockchip_spi_wait_till_not_busy(), RXFLR_LEVEL_MASK, SR_RF_EMPT, SR_TF_FULL, and write32().

Here is the call graph for this function:

◆ rockchip_spi_enable_chip()

static void rockchip_spi_enable_chip ( struct rockchip_spi regs,
int  enable 
)
static

Definition at line 69 of file spi.c.

References write32().

Referenced by rockchip_spi_init().

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

◆ rockchip_spi_init()

void rockchip_spi_init ( unsigned int  bus,
unsigned int  speed_hz 
)

Definition at line 84 of file spi.c.

◆ rockchip_spi_set_clk()

static void rockchip_spi_set_clk ( struct rockchip_spi regs,
unsigned int  hz 
)
static

Definition at line 77 of file spi.c.

References assert, SPI_SRCCLK_HZ, and write32().

Referenced by rockchip_spi_init().

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

◆ rockchip_spi_set_sample_delay()

void rockchip_spi_set_sample_delay ( unsigned int  bus,
unsigned int  delay_ns 
)

Definition at line 122 of file spi.c.

◆ rockchip_spi_wait_till_not_busy()

static int rockchip_spi_wait_till_not_busy ( struct rockchip_spi regs)
static

Definition at line 146 of file spi.c.

References BIOS_DEBUG, printk, read32(), SPI_TIMEOUT_US, SR_BUSY, stopwatch_expired(), and stopwatch_init_usecs_expire().

Referenced by do_xfer().

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

◆ set_tmod()

static void set_tmod ( struct rockchip_spi regs,
unsigned int  tmod 
)
static

Definition at line 160 of file spi.c.

References clrsetbits32, SPI_TMOD_MASK, and SPI_TMOD_OFFSET.

Referenced by set_transfer_mode().

Here is the caller graph for this function:

◆ set_transfer_mode()

static void set_transfer_mode ( struct rockchip_spi regs,
unsigned int  sout,
unsigned int  sin 
)
static

Definition at line 166 of file spi.c.

References set_tmod(), SPI_TMOD_RO, SPI_TMOD_TO, and SPI_TMOD_TR.

Here is the call graph for this function:

◆ spi_cs_activate()

static void spi_cs_activate ( const struct spi_slave slave)
static

Definition at line 57 of file spi.c.

References rockchip_spi_slave::regs, setbits32, slave, and to_rockchip_spi().

Referenced by spi_ctrlr_claim_bus().

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

◆ spi_cs_deactivate()

static void spi_cs_deactivate ( const struct spi_slave slave)
static

Definition at line 63 of file spi.c.

References clrbits32, rockchip_spi_slave::regs, slave, and to_rockchip_spi().

Referenced by spi_ctrlr_release_bus().

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

◆ spi_ctrlr_claim_bus()

static int spi_ctrlr_claim_bus ( const struct spi_slave slave)
static

Definition at line 135 of file spi.c.

References slave, and spi_cs_activate().

Here is the call graph for this function:

◆ spi_ctrlr_release_bus()

static void spi_ctrlr_release_bus ( const struct spi_slave slave)
static

Definition at line 141 of file spi.c.

References slave, and spi_cs_deactivate().

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  bytes_out,
void din,
size_t  bytes_in 
)
static

Definition at line 229 of file spi.c.

◆ to_rockchip_spi()

static struct rockchip_spi_slave* to_rockchip_spi ( const struct spi_slave slave)
static

Definition at line 51 of file spi.c.

References ARRAY_SIZE, assert, spi_slave::bus, rockchip_spi_slaves, and slave.

Referenced by spi_cs_activate(), and spi_cs_deactivate().

Here is the caller graph for this function:

Variable Documentation

◆ rockchip_spi_slaves

struct rockchip_spi_slave rockchip_spi_slaves[]
static
Initial value:
= {
{
.regs = (void *)SPI0_BASE,
},
{
.regs = (void *)SPI1_BASE,
},
{
.regs = (void *)SPI2_BASE,
},
}
#define SPI1_BASE
Definition: addressmap.h:14
#define SPI2_BASE
Definition: addressmap.h:15
#define SPI0_BASE
Definition: addressmap.h:13

Definition at line 1 of file spi.c.

Referenced by rockchip_spi_init(), rockchip_spi_set_sample_delay(), and to_rockchip_spi().

◆ spi_ctrlr

const struct spi_ctrlr spi_ctrlr
static
Initial value:
= {
.claim_bus = spi_ctrlr_claim_bus,
.release_bus = spi_ctrlr_release_bus,
.xfer = spi_ctrlr_xfer,
.max_xfer_size = 65535,
}
static void spi_ctrlr_release_bus(const struct spi_slave *slave)
Definition: spi.c:141
static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout, size_t bytes_out, void *din, size_t bytes_in)
Definition: spi.c:229
static int spi_ctrlr_claim_bus(const struct spi_slave *slave)
Definition: spi.c:135

Definition at line 229 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,
},
}
#define ARRAY_SIZE(a)
Definition: helpers.h:12
const struct spi_ctrlr spi_ctrlr
Definition: spi.c:261
static struct rockchip_spi_slave rockchip_spi_slaves[]
Definition: spi.c:24

Definition at line 229 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 316 of file spi.c.