OpenOCD
dw-spi.c File Reference

Driver for SPI NOR flash chips connected via DesignWare SPI Core. More...

Include dependency graph for dw-spi.c:

Go to the source code of this file.

Data Structures

struct  dw_spi_driver
 Driver private state. More...
 
struct  dw_spi_regmap
 IP block placement map. More...
 

Macros

#define DW_SPI_ARG_REG   "r4"
 Register used to pass argument struct to helper functions. More...
 
#define DW_SPI_IF_OWNER_WIDTH   2
 IF owner register field width. More...
 
#define DW_SPI_REG_BAUDR   0x14
 Baud rate configuration register. More...
 
#define DW_SPI_REG_BAUDR_SCKDV(x)   ((x) & GENMASK(15, 0))
 Clock divisor. More...
 
#define DW_SPI_REG_CTRLR0   0x00
 General configuration register. More...
 
#define DW_SPI_REG_CTRLR0_DFS(x)   ((x) & GENMASK(3, 0))
 Data frame size. More...
 
#define DW_SPI_REG_CTRLR0_FRF(x)   (((x) << 4) & GENMASK(5, 4))
 SI protocol. More...
 
#define DW_SPI_REG_CTRLR0_SCPH(x)   ((!!(x)) << 6)
 Probe position. More...
 
#define DW_SPI_REG_CTRLR0_SCPOL(x)   ((!!(x)) << 7)
 Probe polarity. More...
 
#define DW_SPI_REG_CTRLR0_TMOD(x)   (((x) << 8) & GENMASK(9, 8))
 SI mode. More...
 
#define DW_SPI_REG_DR   0x60
 Data register. More...
 
#define DW_SPI_REG_IMR   0x2c
 Interrupt configuration register. More...
 
#define DW_SPI_REG_SER   0x10
 Slave select register. More...
 
#define DW_SPI_REG_SER_SER(x)   ((x) & GENMASK(15, 0))
 Slave select bitmask. More...
 
#define DW_SPI_REG_SIMCEN   0x08
 Master controller enable register. More...
 
#define DW_SPI_REG_SIMCEN_SIMCEN(x)   (!!(x))
 Controller enable. More...
 
#define DW_SPI_REG_SR   0x28
 Status register. More...
 
#define DW_SPI_TIMEOUT_DEFAULT   (600 * 1000)
 Default timeout value in ms for flash transaction jobs. More...
 
#define DW_SPI_TIMEOUT_TRANSACTION   1000
 Timeout value in ms for short flash transactions, e.g. More...
 

Enumerations

enum  dw_spi_si_mode { DW_SPI_SI_MODE_BOOT = 1 , DW_SPI_SI_MODE_MASTER = 2 }
 Owner of the SI interface. More...
 

Functions

static int dw_spi_assert_halted (const struct flash_bank *const bank)
 Assert target is halted. More...
 
static int dw_spi_auto_probe (struct flash_bank *bank)
 Autoprobe driver. More...
 
static int dw_spi_blank_check (struct flash_bank *bank, size_t sector_count, uint8_t pattern)
 Flash bank blank check. More...
 
static int dw_spi_ctrl_check_sectors_fill (const struct flash_bank *const bank, uint32_t address, size_t sector_size, size_t sector_count, uint8_t pattern, uint8_t read_cmd, uint8_t *buffer)
 Check that selected region is filled with pattern. More...
 
static int dw_spi_ctrl_configure_si (const struct flash_bank *const bank)
 Configure SI transfer mode. More...
 
static int dw_spi_ctrl_configure_speed (const struct flash_bank *const bank)
 Configure SI transfer speed. More...
 
static int dw_spi_ctrl_disable_interrupts (const struct flash_bank *const bank)
 Disable SI master controller interrupts. More...
 
static int dw_spi_ctrl_erase_sectors (const struct flash_bank *const bank, uint32_t address, uint32_t sector_size, size_t sector_count, uint8_t stat_cmd, uint8_t we_cmd, uint8_t erase_sector_cmd, uint8_t we_mask, uint8_t busy_mask)
 Erase sectors. More...
 
static int dw_spi_ctrl_mode (const struct flash_bank *const bank, enum dw_spi_si_mode mode)
 Select SI interface owner. More...
 
static int dw_spi_ctrl_mode_configure (const struct flash_bank *const bank, enum dw_spi_si_mode mode)
 Select master controller as SI interface owner. More...
 
static int dw_spi_ctrl_mode_restore (const struct flash_bank *const bank)
 Restore SI controller mode. More...
 
static int dw_spi_ctrl_program (const struct flash_bank *const bank, uint32_t address, const uint8_t *const buffer, size_t buffer_size, uint32_t page_size, uint8_t stat_cmd, uint8_t we_cmd, uint8_t program_cmd, uint8_t we_mask, uint8_t busy_mask)
 Write flash region. More...
 
static int dw_spi_ctrl_read (const struct flash_bank *const bank, uint32_t address, uint8_t *buffer, size_t buffer_size, uint8_t read_cmd)
 Read flash data. More...
 
static int dw_spi_ctrl_transaction (const struct flash_bank *const bank, uint8_t *const buffer, size_t size, bool read)
 Do data transaction. More...
 
static int dw_spi_erase (struct flash_bank *bank, unsigned int first, unsigned int last)
 Flash bank erase sectors. More...
 
static int dw_spi_erase_check (struct flash_bank *bank)
 Flash bank erase check. More...
 
static int dw_spi_erase_chip (const struct flash_bank *const bank)
 Erase Flash chip. More...
 
static int dw_spi_erase_sectors (const struct flash_bank *const bank, unsigned int first, unsigned int last)
 Flash device erase sectors. More...
 
static int dw_spi_info (struct flash_bank *bank, struct command_invocation *cmd)
 Flash bank info. More...
 
static int dw_spi_master_ctrl_configure (struct flash_bank *bank)
 Prepare master controller for transaction. More...
 
static int dw_spi_master_ctrl_enable (const struct flash_bank *const bank, bool value)
 Enable master controller. More...
 
static int dw_spi_master_ctrl_restore (struct flash_bank *bank)
 Restore SI controller selection. More...
 
static int dw_spi_probe (struct flash_bank *bank)
 Flash bank probe. More...
 
static int dw_spi_read (struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count)
 Flash bank read data using master controller. More...
 
static int dw_spi_read_id (const struct flash_bank *const bank)
 Read Flash device ID. More...
 
static int dw_spi_read_status (const struct flash_bank *const bank, uint8_t *const status)
 Read Flash device status. More...
 
static int dw_spi_spiflash_search (const struct flash_bank *const bank)
 Search for Flash chip info. More...
 
static int dw_spi_wait_finish (const struct flash_bank *const bank, unsigned int timeout)
 Wait for Flash command to finish. More...
 
static int dw_spi_write (struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
 Flash bank write data. More...
 
static int dw_spi_write_buffer (const struct flash_bank *const bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
 Write buffer to Flash. More...
 
static int dw_spi_write_enable (const struct flash_bank *const bank)
 Flash device write enable. More...
 
 FLASH_BANK_COMMAND_HANDLER (dw_spi_flash_bank_command)
 Handle flash bank command. More...
 

Variables

const struct flash_driver dw_spi_flash
 DW-SPI NOR flash functions. More...
 
static const struct dw_spi_regmap jaguar2_regmap
 Register map for Jaguar2 switch devices. More...
 
static const struct dw_spi_regmap ocelot_regmap
 Register map for Ocelot switch devices. More...
 

Detailed Description

Driver for SPI NOR flash chips connected via DesignWare SPI Core.

Controller's Linux driver is located at drivers/spi/spi-dw-mmio.c. DW-SPI is used in a number of processors, including Microsemi Jaguar2 and Ocelot switch chips.

Serial interface (SI) nCS0 pin, which is usually connected to the external flash, cannot be controlled via GPIO controller: it is asserted only when TX FIFO is not empty. Since JTAG is not fast enough to fill TX FIFO and collect data from RX FIFO at the same time even on the slowest SPI clock speeds, driver can only operate using functions, loaded in target's memory. Therefore, it requires the user to set up DRAM controller and provide work-area.

In Microsemi devices, serial interface pins may be governed either by Boot or Master controller. For these devices, additional configuration of spi_mst address is required to switch between the two.

Currently supported devices typically have much more RAM then NOR Flash (Jaguar2 reference design has 256MB RAM and 32MB NOR Flash), so supporting work-area sizes smaller then transfer buffer seems like the unnecessary complication.

This code was tested on Jaguar2 VSC7448 connected to Macronix MX25L25635F.

Definition in file dw-spi.c.

Macro Definition Documentation

◆ DW_SPI_ARG_REG

#define DW_SPI_ARG_REG   "r4"

Register used to pass argument struct to helper functions.

Definition at line 129 of file dw-spi.c.

◆ DW_SPI_IF_OWNER_WIDTH

#define DW_SPI_IF_OWNER_WIDTH   2

IF owner register field width.

Definition at line 81 of file dw-spi.c.

◆ DW_SPI_REG_BAUDR

#define DW_SPI_REG_BAUDR   0x14

Baud rate configuration register.

Definition at line 96 of file dw-spi.c.

◆ DW_SPI_REG_BAUDR_SCKDV

#define DW_SPI_REG_BAUDR_SCKDV (   x)    ((x) & GENMASK(15, 0))

Clock divisor.

Definition at line 108 of file dw-spi.c.

◆ DW_SPI_REG_CTRLR0

#define DW_SPI_REG_CTRLR0   0x00

General configuration register.

Definition at line 93 of file dw-spi.c.

◆ DW_SPI_REG_CTRLR0_DFS

#define DW_SPI_REG_CTRLR0_DFS (   x)    ((x) & GENMASK(3, 0))

Data frame size.

Definition at line 101 of file dw-spi.c.

◆ DW_SPI_REG_CTRLR0_FRF

#define DW_SPI_REG_CTRLR0_FRF (   x)    (((x) << 4) & GENMASK(5, 4))

SI protocol.

Definition at line 102 of file dw-spi.c.

◆ DW_SPI_REG_CTRLR0_SCPH

#define DW_SPI_REG_CTRLR0_SCPH (   x)    ((!!(x)) << 6)

Probe position.

Definition at line 103 of file dw-spi.c.

◆ DW_SPI_REG_CTRLR0_SCPOL

#define DW_SPI_REG_CTRLR0_SCPOL (   x)    ((!!(x)) << 7)

Probe polarity.

Definition at line 104 of file dw-spi.c.

◆ DW_SPI_REG_CTRLR0_TMOD

#define DW_SPI_REG_CTRLR0_TMOD (   x)    (((x) << 8) & GENMASK(9, 8))

SI mode.

Definition at line 105 of file dw-spi.c.

◆ DW_SPI_REG_DR

#define DW_SPI_REG_DR   0x60

Data register.

Definition at line 99 of file dw-spi.c.

◆ DW_SPI_REG_IMR

#define DW_SPI_REG_IMR   0x2c

Interrupt configuration register.

Definition at line 98 of file dw-spi.c.

◆ DW_SPI_REG_SER

#define DW_SPI_REG_SER   0x10

Slave select register.

Definition at line 95 of file dw-spi.c.

◆ DW_SPI_REG_SER_SER

#define DW_SPI_REG_SER_SER (   x)    ((x) & GENMASK(15, 0))

Slave select bitmask.

Definition at line 107 of file dw-spi.c.

◆ DW_SPI_REG_SIMCEN

#define DW_SPI_REG_SIMCEN   0x08

Master controller enable register.

Definition at line 94 of file dw-spi.c.

◆ DW_SPI_REG_SIMCEN_SIMCEN

#define DW_SPI_REG_SIMCEN_SIMCEN (   x)    (!!(x))

Controller enable.

Definition at line 106 of file dw-spi.c.

◆ DW_SPI_REG_SR

#define DW_SPI_REG_SR   0x28

Status register.

Definition at line 97 of file dw-spi.c.

◆ DW_SPI_TIMEOUT_DEFAULT

#define DW_SPI_TIMEOUT_DEFAULT   (600 * 1000)

Default timeout value in ms for flash transaction jobs.

Definition at line 134 of file dw-spi.c.

◆ DW_SPI_TIMEOUT_TRANSACTION

#define DW_SPI_TIMEOUT_TRANSACTION   1000

Timeout value in ms for short flash transactions, e.g.

reading flash ID and status register.

Definition at line 140 of file dw-spi.c.

Enumeration Type Documentation

◆ dw_spi_si_mode

Owner of the SI interface.

Enumerator
DW_SPI_SI_MODE_BOOT 

Boot controller maps contents of SPI Flash to memory in read-only mode.

DW_SPI_SI_MODE_MASTER 

SPI controller mode for reading/writing SPI Flash.

Definition at line 86 of file dw-spi.c.

Function Documentation

◆ dw_spi_assert_halted()

static int dw_spi_assert_halted ( const struct flash_bank *const  bank)
static

Assert target is halted.

Parameters
[in]bankFlash bank handle.
Returns
Command execution status.

Definition at line 1325 of file dw-spi.c.

References bank, ERROR_OK, ERROR_TARGET_NOT_HALTED, LOG_ERROR, and TARGET_HALTED.

Referenced by dw_spi_master_ctrl_configure().

◆ dw_spi_auto_probe()

static int dw_spi_auto_probe ( struct flash_bank bank)
static

Autoprobe driver.

Parameters
[in]bankFlash bank handle.
Returns
Command execution status.

Definition at line 1583 of file dw-spi.c.

References bank, dw_spi_probe(), ERROR_FAIL, ERROR_OK, and dw_spi_driver::probed.

◆ dw_spi_blank_check()

static int dw_spi_blank_check ( struct flash_bank bank,
size_t  sector_count,
uint8_t  pattern 
)
static

Flash bank blank check.

Definition at line 1130 of file dw-spi.c.

References bank, dw_spi_ctrl_check_sectors_fill(), ERROR_FAIL, LOG_ERROR, pattern, flash_device::read_cmd, sector_count, and dw_spi_driver::spi_flash.

Referenced by dw_spi_erase_check().

◆ dw_spi_ctrl_check_sectors_fill()

static int dw_spi_ctrl_check_sectors_fill ( const struct flash_bank *const  bank,
uint32_t  address,
size_t  sector_size,
size_t  sector_count,
uint8_t  pattern,
uint8_t  read_cmd,
uint8_t *  buffer 
)
static

◆ dw_spi_ctrl_configure_si()

static int dw_spi_ctrl_configure_si ( const struct flash_bank *const  bank)
static

◆ dw_spi_ctrl_configure_speed()

static int dw_spi_ctrl_configure_speed ( const struct flash_bank *const  bank)
static

Configure SI transfer speed.

Parameters
[in]bankFlash bank.
Returns
Command execution status.

Definition at line 298 of file dw-spi.c.

References bank, DW_SPI_REG_BAUDR, DW_SPI_REG_BAUDR_SCKDV, dw_spi_regmap::freq, LOG_DEBUG, LOG_ERROR, MIN, dw_spi_driver::regmap, dw_spi_regmap::simc, dw_spi_driver::speed, and target_write_u32().

Referenced by dw_spi_master_ctrl_configure().

◆ dw_spi_ctrl_disable_interrupts()

static int dw_spi_ctrl_disable_interrupts ( const struct flash_bank *const  bank)
static

Disable SI master controller interrupts.

Parameters
[in]bankFlash bank.
Returns
Command execution status.

Definition at line 327 of file dw-spi.c.

References bank, DW_SPI_REG_IMR, LOG_ERROR, dw_spi_driver::regmap, dw_spi_regmap::simc, and target_write_u32().

Referenced by dw_spi_master_ctrl_configure().

◆ dw_spi_ctrl_erase_sectors()

static int dw_spi_ctrl_erase_sectors ( const struct flash_bank *const  bank,
uint32_t  address,
uint32_t  sector_size,
size_t  sector_count,
uint8_t  stat_cmd,
uint8_t  we_cmd,
uint8_t  erase_sector_cmd,
uint8_t  we_mask,
uint8_t  busy_mask 
)
static

Erase sectors.

Parameters
[in]bankFlash bank.
[in]addressFlash address. Must be sector aligned.
[in]sector_sizeSize of flash sector.
[in]sector_countNumber of sectors to erase.
[in]stat_cmdFlash command to read chip status.
[in]we_cmdFlash command to set enable write.
[in]erase_sector_cmdFlash command to set erase sector.
[in]we_maskStatus byte write enable mask.
[in]busy_maskStatus byte write busy mask.
Returns
Command execution status.

Definition at line 733 of file dw-spi.c.

References address, dw_spi_erase::address, working_area::address, bank, buf_set_u32(), busy_mask, dw_spi_erase::busy_mask, mips32_algorithm::common_magic, dw_spi_erase::data_reg, destroy_mem_param(), destroy_reg_param(), DW_SPI_ARG_REG, DW_SPI_REG_DR, DW_SPI_REG_SR, erase_sector_cmd, dw_spi_erase::erase_sector_cmd, dw_spi_erase::four_byte_mode, dw_spi_driver::four_byte_mode, init_mem_param(), init_reg_param(), LOG_ERROR, MIPS32_COMMON_MAGIC, MIPS32_ISA_MIPS32, PARAM_OUT, dw_spi_erase::read_status_cmd, dw_spi_driver::regmap, sector_count, dw_spi_erase::sector_count, sector_size, dw_spi_erase::sector_size, dw_spi_regmap::simc, working_area::size, dw_spi_erase::status_reg, target_alloc_working_area(), target_buffer_set_u32(), target_free_working_area(), target_run_algorithm(), target_write_buffer(), dw_spi_driver::timeout, mem_param::value, reg_param::value, dw_spi_erase::write_enable_cmd, and dw_spi_erase::write_enable_mask.

Referenced by dw_spi_erase_sectors().

◆ dw_spi_ctrl_mode()

static int dw_spi_ctrl_mode ( const struct flash_bank *const  bank,
enum dw_spi_si_mode  mode 
)
static

Select SI interface owner.

Mode selection is skipped if Boot controller not available on target (i.e. spi_mst command argument is not configured).

Parameters
[in]bankFlash bank.
[in]modeNew controller mode.
Returns
Command execution status.

Definition at line 153 of file dw-spi.c.

References bank, ctrl, DW_SPI_IF_OWNER_WIDTH, ERROR_OK, GENMASK, LOG_ERROR, mode, dw_spi_driver::regmap, dw_spi_regmap::si_if_owner_offset, dw_spi_regmap::spi_mst, target_read_u32(), and target_write_u32().

Referenced by dw_spi_ctrl_mode_configure(), and dw_spi_ctrl_mode_restore().

◆ dw_spi_ctrl_mode_configure()

static int dw_spi_ctrl_mode_configure ( const struct flash_bank *const  bank,
enum dw_spi_si_mode  mode 
)
static

Select master controller as SI interface owner.

Previous interface owner is restored via dw_spi_ctrl_mode_restore() function. Mode selection is skipped if Boot controller not available on target (i.e. spi_mst command argument is not configured).

Parameters
[in]bankFlash bank.
[in]modeNew controller mode.
Returns
Command execution status.

Definition at line 191 of file dw-spi.c.

References bank, ctrl, dw_spi_ctrl_mode(), DW_SPI_IF_OWNER_WIDTH, ERROR_OK, GENMASK, LOG_ERROR, mode, dw_spi_driver::regmap, dw_spi_driver::saved_ctrl_mode, dw_spi_regmap::si_if_owner_offset, dw_spi_regmap::spi_mst, and target_read_u32().

Referenced by dw_spi_master_ctrl_configure().

◆ dw_spi_ctrl_mode_restore()

static int dw_spi_ctrl_mode_restore ( const struct flash_bank *const  bank)
static

Restore SI controller mode.

Restore initially configured SI controller mode. Undo configuration done by dw_spi_ctrl_mode_configure() function. Mode selection is skipped if Boot controller not available on target (i.e. spi_mst command argument is not configured).

Parameters
[in]bankFlash bank.
Returns
Command execution status.

Definition at line 226 of file dw-spi.c.

References bank, dw_spi_ctrl_mode(), and dw_spi_driver::saved_ctrl_mode.

Referenced by dw_spi_master_ctrl_restore().

◆ dw_spi_ctrl_program()

static int dw_spi_ctrl_program ( const struct flash_bank *const  bank,
uint32_t  address,
const uint8_t *const  buffer,
size_t  buffer_size,
uint32_t  page_size,
uint8_t  stat_cmd,
uint8_t  we_cmd,
uint8_t  program_cmd,
uint8_t  we_mask,
uint8_t  busy_mask 
)
static

Write flash region.

Parameters
[in]bankFlash bank.
[in]addressFirst page address. Page aligned when write is crossing the page boundary.
[in]bufferData buffer.
[in]buffer_sizebuffer size.
[in]page_sizeSize of flash page.
[in]stat_cmdFlash command to read chip status.
[in]we_cmdFlash command to enable write.
[in]program_cmdFlash command to program chip.
[in]we_maskStatus byte write enable mask.
[in]busy_maskStatus byte write busy mask.
Returns
Command execution status.

Definition at line 608 of file dw-spi.c.

References address, dw_spi_program::address, working_area::address, bank, buf_set_u32(), buffer, dw_spi_program::buffer, buffer_size, dw_spi_program::buffer_size, busy_mask, dw_spi_program::busy_mask, mips32_algorithm::common_magic, dw_spi_program::data_reg, destroy_mem_param(), destroy_reg_param(), DW_SPI_ARG_REG, DW_SPI_REG_DR, DW_SPI_REG_SR, dw_spi_program::four_byte_mode, dw_spi_driver::four_byte_mode, init_mem_param(), init_reg_param(), LOG_ERROR, MIPS32_COMMON_MAGIC, MIPS32_ISA_MIPS32, page_size, dw_spi_program::page_size, PARAM_OUT, program_cmd, dw_spi_program::program_cmd, dw_spi_program::read_status_cmd, dw_spi_driver::regmap, dw_spi_regmap::simc, working_area::size, dw_spi_program::status_reg, target_alloc_working_area(), target_buffer_set_u32(), target_free_working_area(), target_run_algorithm(), target_write_buffer(), dw_spi_driver::timeout, mem_param::value, reg_param::value, dw_spi_program::write_enable_cmd, and dw_spi_program::write_enable_mask.

Referenced by dw_spi_write_buffer().

◆ dw_spi_ctrl_read()

static int dw_spi_ctrl_read ( const struct flash_bank *const  bank,
uint32_t  address,
uint8_t *  buffer,
size_t  buffer_size,
uint8_t  read_cmd 
)
static

◆ dw_spi_ctrl_transaction()

static int dw_spi_ctrl_transaction ( const struct flash_bank *const  bank,
uint8_t *const  buffer,
size_t  size,
bool  read 
)
static

Do data transaction.

Buffer data are sent and replaced with received data. Total buffer size is a sum of TX and RX messages. RX portion of the buffer is initially filled with dummy values, which get replaced by the message.

Parameters
[in]bankFlash bank.
[in,out]bufferData buffer. If read flag is set, buffer is filled with received data.
[in]sizebuffer size.
[in]readThe read flag. If set to true, read values will override buffer.
Returns
Command execution status.

Definition at line 356 of file dw-spi.c.

References working_area::address, bank, buf_set_u32(), buffer, dw_spi_transaction::buffer, mips32_algorithm::common_magic, dw_spi_transaction::data_reg, destroy_mem_param(), destroy_reg_param(), DW_SPI_ARG_REG, DW_SPI_REG_DR, DW_SPI_REG_SR, DW_SPI_TIMEOUT_TRANSACTION, init_mem_param(), init_reg_param(), LOG_ERROR, MIPS32_COMMON_MAGIC, MIPS32_ISA_MIPS32, PARAM_OUT, dw_spi_transaction::read_flag, dw_spi_driver::regmap, dw_spi_regmap::simc, size, dw_spi_transaction::size, working_area::size, dw_spi_transaction::status_reg, target_alloc_working_area(), target_buffer_set_u32(), target_free_working_area(), target_read_buffer(), target_run_algorithm(), target_write_buffer(), mem_param::value, and reg_param::value.

Referenced by dw_spi_erase_chip(), dw_spi_read_id(), dw_spi_read_status(), and dw_spi_write_enable().

◆ dw_spi_erase()

static int dw_spi_erase ( struct flash_bank bank,
unsigned int  first,
unsigned int  last 
)
static

Flash bank erase sectors.

Parameters
[in]bankFlash bank handle.
[in]firstThe first sector to erase.
[in]lastThe last sector to erase.
Returns
Command execution status.

Definition at line 1482 of file dw-spi.c.

References bank, dw_spi_erase_sectors(), dw_spi_master_ctrl_configure(), and dw_spi_master_ctrl_restore().

◆ dw_spi_erase_check()

static int dw_spi_erase_check ( struct flash_bank bank)
static

Flash bank erase check.

Parameters
[in]bankFlash bank handle.
Returns
Command execution status.

Definition at line 1547 of file dw-spi.c.

References bank, dw_spi_blank_check(), dw_spi_master_ctrl_configure(), and dw_spi_master_ctrl_restore().

◆ dw_spi_erase_chip()

static int dw_spi_erase_chip ( const struct flash_bank *const  bank)
static

Erase Flash chip.

Parameters
[in]bankFlash bank handle.
Returns
Command execution status.

Definition at line 1060 of file dw-spi.c.

References bank, buffer, buffer_size, flash_device::chip_erase_cmd, dw_spi_ctrl_transaction(), dw_spi_wait_finish(), dw_spi_write_enable(), ERROR_OK, LOG_ERROR, dw_spi_driver::spi_flash, and dw_spi_driver::timeout.

Referenced by dw_spi_erase_sectors().

◆ dw_spi_erase_sectors()

static int dw_spi_erase_sectors ( const struct flash_bank *const  bank,
unsigned int  first,
unsigned int  last 
)
static

Flash device erase sectors.

Parameters
[in]bankFlash bank handle.
[in]firstThe first sector to erase.
[in]lastThe last sector to erase.
Returns
Command execution status.

Definition at line 1098 of file dw-spi.c.

References bank, dw_spi_ctrl_erase_sectors(), dw_spi_erase_chip(), flash_device::erase_cmd, ERROR_OK, LOG_ERROR, flash_device::sectorsize, dw_spi_driver::spi_flash, SPIFLASH_BSY_BIT, SPIFLASH_READ_STATUS, SPIFLASH_WE_BIT, and SPIFLASH_WRITE_ENABLE.

Referenced by dw_spi_erase().

◆ dw_spi_info()

static int dw_spi_info ( struct flash_bank bank,
struct command_invocation cmd 
)
static

Flash bank info.

Parameters
[in]bankFlash bank handle.
[in,out]cmdCommand invocation.
Returns
Command execution status.

Definition at line 1567 of file dw-spi.c.

References bank, cmd, command_print(), command_print_sameline(), ERROR_OK, dw_spi_driver::id, flash_device::name, and dw_spi_driver::spi_flash.

◆ dw_spi_master_ctrl_configure()

static int dw_spi_master_ctrl_configure ( struct flash_bank bank)
static

Prepare master controller for transaction.

Parameters
[in]bankFlash bank handle.
Returns
Command execution status.

Definition at line 1341 of file dw-spi.c.

References bank, dw_spi_assert_halted(), dw_spi_ctrl_configure_si(), dw_spi_ctrl_configure_speed(), dw_spi_ctrl_disable_interrupts(), dw_spi_ctrl_mode_configure(), dw_spi_master_ctrl_enable(), DW_SPI_SI_MODE_MASTER, ERROR_OK, and LOG_ERROR.

Referenced by dw_spi_erase(), dw_spi_erase_check(), dw_spi_probe(), dw_spi_read(), and dw_spi_write().

◆ dw_spi_master_ctrl_enable()

static int dw_spi_master_ctrl_enable ( const struct flash_bank *const  bank,
bool  value 
)
static

Enable master controller.

Configuration of the master controller must be done when it is disabled.

Parameters
[in]bankFlash bank.
[in]valueNew enable state.
Returns
Command execution status.

Definition at line 243 of file dw-spi.c.

References bank, DW_SPI_REG_SIMCEN, DW_SPI_REG_SIMCEN_SIMCEN, LOG_ERROR, dw_spi_driver::regmap, dw_spi_regmap::simc, and target_write_u32().

Referenced by dw_spi_master_ctrl_configure(), and dw_spi_master_ctrl_restore().

◆ dw_spi_master_ctrl_restore()

static int dw_spi_master_ctrl_restore ( struct flash_bank bank)
static

Restore SI controller selection.

Parameters
[in]bankFlash bank handle.
Returns
Command execution status.

Definition at line 1387 of file dw-spi.c.

References bank, dw_spi_ctrl_mode_restore(), dw_spi_master_ctrl_enable(), and LOG_ERROR.

Referenced by dw_spi_erase(), dw_spi_erase_check(), dw_spi_probe(), dw_spi_read(), and dw_spi_write().

◆ dw_spi_probe()

◆ dw_spi_read()

static int dw_spi_read ( struct flash_bank bank,
uint8_t *  buffer,
uint32_t  offset,
uint32_t  count 
)
static

Flash bank read data using master controller.

Parameters
[in]bankFlash bank handle.
[out]bufferData buffer.
[in]offsetFlash address offset.
[in]countbuffer size.
Returns
Command execution status.

Definition at line 1525 of file dw-spi.c.

References bank, buffer, count, dw_spi_ctrl_read(), dw_spi_master_ctrl_configure(), dw_spi_master_ctrl_restore(), offset, flash_device::read_cmd, and dw_spi_driver::spi_flash.

◆ dw_spi_read_id()

static int dw_spi_read_id ( const struct flash_bank *const  bank)
static

Read Flash device ID.

Parameters
[in]bankFlash bank handle.
Returns
Command execution status.

Definition at line 945 of file dw-spi.c.

References bank, buffer, buffer_size, dw_spi_ctrl_transaction(), ERROR_OK, dw_spi_driver::id, le_to_h_u32(), LOG_DEBUG, LOG_ERROR, and SPIFLASH_READ_ID.

Referenced by dw_spi_spiflash_search().

◆ dw_spi_read_status()

static int dw_spi_read_status ( const struct flash_bank *const  bank,
uint8_t *const  status 
)
static

Read Flash device status.

Parameters
[in]bankFlash bank handle.
[out]statusThe status byte.
Returns
Command execution status.

Definition at line 977 of file dw-spi.c.

References bank, buffer, buffer_size, dw_spi_ctrl_transaction(), ERROR_OK, LOG_ERROR, SPIFLASH_READ_STATUS, and status.

Referenced by dw_spi_wait_finish(), and dw_spi_write_enable().

◆ dw_spi_spiflash_search()

static int dw_spi_spiflash_search ( const struct flash_bank *const  bank)
static

Search for Flash chip info.

Parameters
[in]bankFlash bank handle.
Returns
Command execution status.

Definition at line 1225 of file dw-spi.c.

References bank, dw_spi_read_id(), ERROR_FAIL, ERROR_OK, flash_devices, dw_spi_driver::id, LOG_ERROR, name, and dw_spi_driver::spi_flash.

Referenced by dw_spi_probe().

◆ dw_spi_wait_finish()

static int dw_spi_wait_finish ( const struct flash_bank *const  bank,
unsigned int  timeout 
)
static

Wait for Flash command to finish.

Parameters
[in]bankFlash bank handle.
[in]timeoutThe timeout in ms.
Returns
Command execution status.

Definition at line 1004 of file dw-spi.c.

References alive_sleep(), bank, dw_spi_read_status(), ERROR_OK, ERROR_TIMEOUT_REACHED, LOG_ERROR, SPIFLASH_BSY_BIT, status, dw_spi_driver::timeout, and timeval_ms().

Referenced by dw_spi_erase_chip().

◆ dw_spi_write()

static int dw_spi_write ( struct flash_bank bank,
const uint8_t *  buffer,
uint32_t  offset,
uint32_t  count 
)
static

Flash bank write data.

Parameters
[in]bankFlash bank handle.
[in]bufferData buffer.
[in]offsetFlash address offset.
[in]countbuffer size.
Returns
Command execution status.

Definition at line 1503 of file dw-spi.c.

References bank, buffer, count, dw_spi_master_ctrl_configure(), dw_spi_master_ctrl_restore(), dw_spi_write_buffer(), and offset.

◆ dw_spi_write_buffer()

static int dw_spi_write_buffer ( const struct flash_bank *const  bank,
const uint8_t *  buffer,
uint32_t  offset,
uint32_t  count 
)
static

Write buffer to Flash.

Parameters
[in]bankFlash bank handle.
[in]bufferData buffer.
[in]offsetFlash address offset.
[in]countbuffer size.
Returns
Command execution status.

Definition at line 1173 of file dw-spi.c.

References address, ARRAY_SIZE, bank, buffer, count, dw_spi_ctrl_program(), ERROR_OK, LOG_ERROR, MIN, offset, page_size, flash_device::pagesize, flash_device::pprog_cmd, dw_spi_driver::spi_flash, SPIFLASH_BSY_BIT, SPIFLASH_READ_STATUS, SPIFLASH_WE_BIT, and SPIFLASH_WRITE_ENABLE.

Referenced by dw_spi_write().

◆ dw_spi_write_enable()

static int dw_spi_write_enable ( const struct flash_bank *const  bank)
static

Flash device write enable.

Parameters
[in]bankFlash bank handle.
Returns
Command execution status.

Definition at line 1031 of file dw-spi.c.

References bank, buffer, buffer_size, dw_spi_ctrl_transaction(), dw_spi_read_status(), ERROR_FAIL, ERROR_OK, LOG_ERROR, SPIFLASH_WE_BIT, SPIFLASH_WRITE_ENABLE, and status.

Referenced by dw_spi_erase_chip().

◆ FLASH_BANK_COMMAND_HANDLER()

FLASH_BANK_COMMAND_HANDLER ( dw_spi_flash_bank_command  )

Variable Documentation

◆ dw_spi_flash

const struct flash_driver dw_spi_flash
Initial value:
= {
.name = "dw-spi",
.flash_bank_command = dw_spi_flash_bank_command,
.erase = dw_spi_erase,
.write = dw_spi_write,
.read = dw_spi_read,
.probe = dw_spi_probe,
.auto_probe = dw_spi_auto_probe,
.erase_check = dw_spi_erase_check,
.info = dw_spi_info,
.free_driver_priv = default_flash_free_driver_priv,
}
static int dw_spi_read(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count)
Flash bank read data using master controller.
Definition: dw-spi.c:1525
static int dw_spi_auto_probe(struct flash_bank *bank)
Autoprobe driver.
Definition: dw-spi.c:1583
static int dw_spi_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
Flash bank write data.
Definition: dw-spi.c:1503
static int dw_spi_erase_check(struct flash_bank *bank)
Flash bank erase check.
Definition: dw-spi.c:1547
static int dw_spi_probe(struct flash_bank *bank)
Flash bank probe.
Definition: dw-spi.c:1410
static int dw_spi_info(struct flash_bank *bank, struct command_invocation *cmd)
Flash bank info.
Definition: dw-spi.c:1567
static int dw_spi_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
Flash bank erase sectors.
Definition: dw-spi.c:1482
int default_flash_verify(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
Provides default verify implementation for flash memory.
void default_flash_free_driver_priv(struct flash_bank *bank)
Deallocates bank->driver_priv.

DW-SPI NOR flash functions.

Definition at line 1583 of file dw-spi.c.

◆ jaguar2_regmap

const struct dw_spi_regmap jaguar2_regmap
static
Initial value:
= {
.freq = 250000000UL,
.simc = 0x70101000UL,
.spi_mst = 0x70000024UL,
.si_if_owner_offset = 6,
}

Register map for Jaguar2 switch devices.

Definition at line 1 of file dw-spi.c.

Referenced by FLASH_BANK_COMMAND_HANDLER().

◆ ocelot_regmap

const struct dw_spi_regmap ocelot_regmap
static
Initial value:
= {
.freq = 250000000UL,
.simc = 0x70101000UL,
.spi_mst = 0x70000024UL,
.si_if_owner_offset = 4,
}

Register map for Ocelot switch devices.

Definition at line 1 of file dw-spi.c.

Referenced by FLASH_BANK_COMMAND_HANDLER().