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 <console/console.h>
#include <delay.h>
#include <gpio.h>
#include <soc/iomap.h>
#include <soc/spi.h>
#include <types.h>
Include dependency graph for spi.c:

Go to the source code of this file.

Macros

#define SUCCESS   0
 
#define DUMMY_DATA_VAL   0
 
#define TIMEOUT_CNT   100
 
#define CS_ASSERT   1
 
#define CS_DEASSERT   0
 
#define NUM_PORTS   3
 
#define NUM_GSBI_PINS   3
 
#define TLMM_ARGS   6
 
#define NUM_CS   4
 
#define GSBI_PIN_IDX   0
 
#define FUNC_SEL_IDX   1
 
#define GPIO_DIR_IDX   2
 
#define PULL_CONF_IDX   3
 
#define DRV_STR_IDX   4
 
#define GPIO_EN_IDX   5
 
#define ETIMEDOUT   -10
 
#define EINVAL   -11
 
#define EIO   -12
 
#define GSBI_IDX_TO_GSBI(idx)   (idx + 5)
 
#define MAX_PACKET_COUNT   ((64 * KiB) - 1)
 

Functions

static int check_bit_state (uint32_t reg_addr, int bit_num, int val, int us_delay)
 
static int check_qup_state_valid (struct ipq_spi_slave *ds)
 
static int config_spi_state (struct ipq_spi_slave *ds, unsigned int state)
 
static void spi_set_mode (struct ipq_spi_slave *ds, unsigned int mode)
 
static int check_hclk_state (unsigned int core_num, int enable)
 
static int check_qup_clk_state (unsigned int core_num, int enable)
 
static void CS_change (int port_num, int cs_num, int enable)
 
static void gsbi_pin_config (unsigned int port_num, int cs_num)
 
static int gsbi_clock_init (struct ipq_spi_slave *ds)
 
static void spi_reset (struct ipq_spi_slave *ds)
 
static struct ipq_spi_slaveto_ipq_spi (const struct spi_slave *slave)
 
static int spi_hw_init (struct ipq_spi_slave *ds)
 
static int spi_ctrlr_claim_bus (const struct spi_slave *slave)
 
static void spi_ctrlr_release_bus (const struct spi_slave *slave)
 
static int spi_xfer_tx_packet (struct ipq_spi_slave *ds, const uint8_t *dout, unsigned int out_bytes)
 
static int spi_xfer_rx_packet (struct ipq_spi_slave *ds, uint8_t *din, unsigned int in_bytes)
 
static int spi_ctrlr_xfer (const struct spi_slave *slave, const void *dout, size_t out_bytes, void *din, size_t in_bytes)
 
static int spi_ctrlr_setup (const struct spi_slave *slave)
 

Variables

static unsigned int gsbi_pin_conf [NUM_PORTS][NUM_GSBI_PINS][TLMM_ARGS]
 
static unsigned int cs_gpio_array [NUM_PORTS][NUM_CS]
 
static unsigned int hclk_state [NUM_PORTS]
 
static unsigned int qup_apps_clk_state [NUM_PORTS]
 
static const struct gsbi_spi spi_reg []
 
static struct ipq_spi_slave spi_slave_pool [2]
 
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

◆ CS_ASSERT

#define CS_ASSERT   1

Definition at line 15 of file spi.c.

◆ CS_DEASSERT

#define CS_DEASSERT   0

Definition at line 16 of file spi.c.

◆ DRV_STR_IDX

#define DRV_STR_IDX   4

Definition at line 25 of file spi.c.

◆ DUMMY_DATA_VAL

#define DUMMY_DATA_VAL   0

Definition at line 13 of file spi.c.

◆ EINVAL

#define EINVAL   -11

Definition at line 30 of file spi.c.

◆ EIO

#define EIO   -12

Definition at line 31 of file spi.c.

◆ ETIMEDOUT

#define ETIMEDOUT   -10

Definition at line 29 of file spi.c.

◆ FUNC_SEL_IDX

#define FUNC_SEL_IDX   1

Definition at line 22 of file spi.c.

◆ GPIO_DIR_IDX

#define GPIO_DIR_IDX   2

Definition at line 23 of file spi.c.

◆ GPIO_EN_IDX

#define GPIO_EN_IDX   5

Definition at line 26 of file spi.c.

◆ GSBI_IDX_TO_GSBI

#define GSBI_IDX_TO_GSBI (   idx)    (idx + 5)

Definition at line 33 of file spi.c.

◆ GSBI_PIN_IDX

#define GSBI_PIN_IDX   0

Definition at line 21 of file spi.c.

◆ MAX_PACKET_COUNT

#define MAX_PACKET_COUNT   ((64 * KiB) - 1)

Definition at line 37 of file spi.c.

◆ NUM_CS

#define NUM_CS   4

Definition at line 20 of file spi.c.

◆ NUM_GSBI_PINS

#define NUM_GSBI_PINS   3

Definition at line 18 of file spi.c.

◆ NUM_PORTS

#define NUM_PORTS   3

Definition at line 17 of file spi.c.

◆ PULL_CONF_IDX

#define PULL_CONF_IDX   3

Definition at line 24 of file spi.c.

◆ SUCCESS

#define SUCCESS   0

Definition at line 11 of file spi.c.

◆ TIMEOUT_CNT

#define TIMEOUT_CNT   100

Definition at line 14 of file spi.c.

◆ TLMM_ARGS

#define TLMM_ARGS   6

Definition at line 19 of file spi.c.

Function Documentation

◆ check_bit_state()

static int check_bit_state ( uint32_t  reg_addr,
int  bit_num,
int  val,
int  us_delay 
)
static

Definition at line 143 of file spi.c.

References count, ETIMEDOUT, readl_i, SUCCESS, TIMEOUT_CNT, udelay(), and val.

Referenced by check_hclk_state(), check_qup_clk_state(), and check_qup_state_valid().

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

◆ check_hclk_state()

static int check_hclk_state ( unsigned int  core_num,
int  enable 
)
static

Definition at line 257 of file spi.c.

References check_bit_state(), CLK_HALT_CFPB_STATEB_REG, and hclk_state.

Referenced by gsbi_clock_init().

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

◆ check_qup_clk_state()

static int check_qup_clk_state ( unsigned int  core_num,
int  enable 
)
static

Definition at line 266 of file spi.c.

References check_bit_state(), CLK_HALT_CFPB_STATEB_REG, and qup_apps_clk_state.

Referenced by gsbi_clock_init().

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

◆ check_qup_state_valid()

static int check_qup_state_valid ( struct ipq_spi_slave ds)
static

Definition at line 162 of file spi.c.

References check_bit_state(), blsp_spi::qup_state, QUP_STATE_VALID, QUP_STATE_VALID_BIT, and ipq_spi_slave::regs.

Referenced by config_spi_state().

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

◆ config_spi_state()

static int config_spi_state ( struct ipq_spi_slave ds,
unsigned int  state 
)
static

◆ CS_change()

static void CS_change ( int  port_num,
int  cs_num,
int  enable 
)
static

Definition at line 275 of file spi.c.

References addr, cs_gpio_array, GPIO_IN_OUT_ADDR, GPIO_OUTPUT, readl_i, val, and write32().

Referenced by gsbi_pin_config(), and spi_ctrlr_xfer().

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

◆ gsbi_clock_init()

◆ gsbi_pin_config()

static void gsbi_pin_config ( unsigned int  port_num,
int  cs_num 
)
static

◆ spi_ctrlr_claim_bus()

static int spi_ctrlr_claim_bus ( const struct spi_slave slave)
static

Definition at line 587 of file spi.c.

References spi_slave::bus, spi_slave::cs, EIO, gsbi_clock_init(), gsbi_pin_config(), ipq_spi_slave::initialized, slave, ipq_spi_slave::slave, spi_hw_init(), SUCCESS, and to_ipq_spi().

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 610 of file spi.c.

References ipq_spi_slave::initialized, slave, spi_reset(), and to_ipq_spi().

Here is the call graph for this function:

◆ spi_ctrlr_setup()

static int spi_ctrlr_setup ( const struct spi_slave slave)
static

Definition at line 744 of file spi.c.

◆ spi_ctrlr_xfer()

static int spi_ctrlr_xfer ( const struct spi_slave slave,
const void dout,
size_t  out_bytes,
void din,
size_t  in_bytes 
)
static

◆ spi_hw_init()

◆ spi_reset()

static void spi_reset ( struct ipq_spi_slave ds)
static

Definition at line 418 of file spi.c.

Referenced by spi_ctrlr_release_bus(), and spi_hw_init().

Here is the caller graph for this function:

◆ spi_set_mode()

static void spi_set_mode ( struct ipq_spi_slave ds,
unsigned int  mode 
)
static

◆ spi_xfer_rx_packet()

static int spi_xfer_rx_packet ( struct ipq_spi_slave ds,
uint8_t din,
unsigned int  in_bytes 
)
static

◆ spi_xfer_tx_packet()

static int spi_xfer_tx_packet ( struct ipq_spi_slave ds,
const uint8_t dout,
unsigned int  out_bytes 
)
static

Definition at line 619 of file spi.c.

References config_spi_state(), blsp_spi::qup_mx_output_count, blsp_spi::qup_operational, blsp_spi::qup_output_fifo, QUP_OUTPUT_FIFO_FULL, QUP_OUTPUT_FIFO_NOT_EMPTY, readl_i, ipq_spi_slave::regs, SPI_RESET_STATE, SPI_RUN_STATE, and writel_i.

Referenced by spi_ctrlr_xfer().

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

◆ to_ipq_spi()

static struct ipq_spi_slave* to_ipq_spi ( const struct spi_slave slave)
static

Definition at line 491 of file spi.c.

References ipq_spi_slave::allocated, ARRAY_SIZE, spi_slave::bus, spi_slave::cs, NULL, slave, ipq_spi_slave::slave, and spi_slave_pool.

Referenced by spi_ctrlr_claim_bus(), spi_ctrlr_release_bus(), and spi_ctrlr_xfer().

Here is the caller graph for this function:

Variable Documentation

◆ cs_gpio_array

unsigned int cs_gpio_array[NUM_PORTS][NUM_CS]
static
Initial value:
= {
{
},
{
GSBI6_SPI_CS_0, 0, 0, 0
},
{
GSBI7_SPI_CS_0, 0, 0, 0
}
}
#define GSBI5_SPI_CS_2
Definition: spi.h:219
#define GSBI7_SPI_CS_0
Definition: spi.h:226
#define GSBI6_SPI_CS_0
Definition: spi.h:222
#define GSBI5_SPI_CS_3
Definition: spi.h:220
#define GSBI5_SPI_CS_1
Definition: spi.h:218
#define GSBI5_SPI_CS_0
Definition: spi.h:217

Definition at line 107 of file spi.c.

Referenced by CS_change(), and gsbi_pin_config().

◆ gsbi_pin_conf

unsigned int gsbi_pin_conf[NUM_PORTS][NUM_GSBI_PINS][TLMM_ARGS]
static

Definition at line 47 of file spi.c.

Referenced by gsbi_pin_config().

◆ hclk_state

unsigned int hclk_state[NUM_PORTS]
static
Initial value:
= {
}
#define GSBI7_HCLK
Definition: spi.h:134
#define GSBI6_HCLK
Definition: spi.h:133
#define GSBI5_HCLK
Definition: spi.h:132

Definition at line 125 of file spi.c.

Referenced by check_hclk_state().

◆ qup_apps_clk_state

unsigned int qup_apps_clk_state[NUM_PORTS]
static
Initial value:
= {
}
#define GSBI6_QUP_APPS_CLK
Definition: spi.h:136
#define GSBI5_QUP_APPS_CLK
Definition: spi.h:135
#define GSBI7_QUP_APPS_CLK
Definition: spi.h:137

Definition at line 137 of file spi.c.

Referenced by check_qup_clk_state().

◆ spi_ctrlr

const struct spi_ctrlr spi_ctrlr
static
Initial value:
= {
.setup = spi_ctrlr_setup,
.claim_bus = spi_ctrlr_claim_bus,
.release_bus = spi_ctrlr_release_bus,
.xfer = spi_ctrlr_xfer,
.max_xfer_size = MAX_PACKET_COUNT,
}
#define MAX_PACKET_COUNT
Definition: spi.c:37
static void spi_ctrlr_release_bus(const struct spi_slave *slave)
Definition: spi.c:610
static int spi_ctrlr_claim_bus(const struct spi_slave *slave)
Definition: spi.c:587
static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout, size_t out_bytes, void *din, size_t in_bytes)
Definition: spi.c:675
static int spi_ctrlr_setup(const struct spi_slave *slave)
Definition: spi.c:744

Definition at line 744 of file spi.c.

◆ spi_ctrlr_bus_map

const struct spi_ctrlr_buses spi_ctrlr_bus_map[]
Initial value:
= {
{
.ctrlr = &spi_ctrlr,
.bus_start = GSBI5_SPI,
.bus_end = GSBI7_SPI,
},
}
const struct spi_ctrlr spi_ctrlr
Definition: spi.c:261
#define GSBI7_SPI
Definition: spi.h:243
#define GSBI5_SPI
Definition: spi.h:241

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

◆ spi_reg

const struct gsbi_spi spi_reg[]
static

Definition at line 418 of file spi.c.

◆ spi_slave_pool

struct ipq_spi_slave spi_slave_pool[2]
static

Definition at line 418 of file spi.c.

Referenced by to_ipq_spi().