OpenOCD
sh_qspi.c File Reference
Include dependency graph for sh_qspi.c:

Go to the source code of this file.

Data Structures

struct  sh_qspi_flash_bank
 
struct  sh_qspi_target
 

Macros

#define SH_QSPI_DUMMY0   0x0f
 
#define SH_QSPI_DUMMY1   0x19
 
#define SH_QSPI_SPBDCR   0x1a
 
#define SH_QSPI_SPBFCR   0x18
 
#define SH_QSPI_SPBMUL0   0x1c
 
#define SH_QSPI_SPBMUL1   0x20
 
#define SH_QSPI_SPBMUL2   0x24
 
#define SH_QSPI_SPBMUL3   0x28
 
#define SH_QSPI_SPBR   0x0a
 
#define SH_QSPI_SPCKD   0x0c
 
#define SH_QSPI_SPCMD0   0x10
 
#define SH_QSPI_SPCMD1   0x12
 
#define SH_QSPI_SPCMD2   0x14
 
#define SH_QSPI_SPCMD3   0x16
 
#define SH_QSPI_SPCR   0x00
 
#define SH_QSPI_SPDCR   0x0b
 
#define SH_QSPI_SPDR   0x04
 
#define SH_QSPI_SPND   0x0e
 
#define SH_QSPI_SPPCR   0x02
 
#define SH_QSPI_SPSCR   0x08
 
#define SH_QSPI_SPSR   0x03
 
#define SH_QSPI_SPSSR   0x09
 
#define SH_QSPI_SSLND   0x0d
 
#define SH_QSPI_SSLP   0x01
 
#define SPBDCR_RXBC0   BIT(0)
 
#define SPBFCR_RXRST   BIT(6)
 
#define SPBFCR_RXTRG   0x07
 
#define SPBFCR_TXRST   BIT(7)
 
#define SPBFCR_TXTRG   0x30
 
#define SPCMD_BRDV0   BIT(2)
 
#define SPCMD_INIT1
 
#define SPCMD_INIT2
 
#define SPCMD_SCKDEN   BIT(15)
 
#define SPCMD_SLNDEN   BIT(14)
 
#define SPCMD_SPNDEN   BIT(13)
 
#define SPCMD_SSLKP   BIT(7)
 
#define SPCR_MSTR   0x08
 
#define SPCR_SPE   0x40
 
#define SPPCR_IO1FV   0x01
 
#define SPPCR_IO2FV   0x02
 
#define SPPCR_IO3FV   0x04
 
#define SPSR_SPRFF   0x80
 
#define SPSR_SPTEF   0x20
 

Functions

 FLASH_BANK_COMMAND_HANDLER (sh_qspi_flash_bank_command)
 
static int read_flash_id (struct flash_bank *bank, uint32_t *id)
 
static int read_status_reg (struct flash_bank *bank, uint32_t *status)
 
static int sh_qspi_auto_probe (struct flash_bank *bank)
 
static int sh_qspi_cs_activate (struct flash_bank *bank)
 
static int sh_qspi_cs_deactivate (struct flash_bank *bank)
 
static int sh_qspi_erase (struct flash_bank *bank, unsigned int first, unsigned int last)
 
static int sh_qspi_erase_sector (struct flash_bank *bank, int sector)
 
static int sh_qspi_flash_blank_check (struct flash_bank *bank)
 
static int sh_qspi_get_info (struct flash_bank *bank, struct command_invocation *cmd)
 
static int sh_qspi_init (struct flash_bank *bank)
 
static int sh_qspi_probe (struct flash_bank *bank)
 
static int sh_qspi_protect (struct flash_bank *bank, int set, unsigned int first, unsigned int last)
 
static int sh_qspi_protect_check (struct flash_bank *bank)
 
static int sh_qspi_read (struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count)
 
static int sh_qspi_upload_helper (struct flash_bank *bank)
 
static int sh_qspi_wait_for_bit (struct flash_bank *bank, uint8_t reg, uint32_t mask, bool set, unsigned long timeout)
 
static int sh_qspi_write (struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
 
static int sh_qspi_write_enable (struct flash_bank *bank)
 
static int sh_qspi_xfer_common (struct flash_bank *bank, const uint8_t *dout, unsigned int outlen, uint8_t *din, unsigned int inlen, bool xfer_start, bool xfer_end)
 
static int wait_till_ready (struct flash_bank *bank, int timeout)
 

Variables

const struct flash_driver sh_qspi_flash
 
static const struct sh_qspi_target target_devices []
 

Macro Definition Documentation

◆ SH_QSPI_DUMMY0

#define SH_QSPI_DUMMY0   0x0f

Definition at line 65 of file sh_qspi.c.

◆ SH_QSPI_DUMMY1

#define SH_QSPI_DUMMY1   0x19

Definition at line 71 of file sh_qspi.c.

◆ SH_QSPI_SPBDCR

#define SH_QSPI_SPBDCR   0x1a

Definition at line 72 of file sh_qspi.c.

◆ SH_QSPI_SPBFCR

#define SH_QSPI_SPBFCR   0x18

Definition at line 70 of file sh_qspi.c.

◆ SH_QSPI_SPBMUL0

#define SH_QSPI_SPBMUL0   0x1c

Definition at line 73 of file sh_qspi.c.

◆ SH_QSPI_SPBMUL1

#define SH_QSPI_SPBMUL1   0x20

Definition at line 74 of file sh_qspi.c.

◆ SH_QSPI_SPBMUL2

#define SH_QSPI_SPBMUL2   0x24

Definition at line 75 of file sh_qspi.c.

◆ SH_QSPI_SPBMUL3

#define SH_QSPI_SPBMUL3   0x28

Definition at line 76 of file sh_qspi.c.

◆ SH_QSPI_SPBR

#define SH_QSPI_SPBR   0x0a

Definition at line 60 of file sh_qspi.c.

◆ SH_QSPI_SPCKD

#define SH_QSPI_SPCKD   0x0c

Definition at line 62 of file sh_qspi.c.

◆ SH_QSPI_SPCMD0

#define SH_QSPI_SPCMD0   0x10

Definition at line 66 of file sh_qspi.c.

◆ SH_QSPI_SPCMD1

#define SH_QSPI_SPCMD1   0x12

Definition at line 67 of file sh_qspi.c.

◆ SH_QSPI_SPCMD2

#define SH_QSPI_SPCMD2   0x14

Definition at line 68 of file sh_qspi.c.

◆ SH_QSPI_SPCMD3

#define SH_QSPI_SPCMD3   0x16

Definition at line 69 of file sh_qspi.c.

◆ SH_QSPI_SPCR

#define SH_QSPI_SPCR   0x00

Definition at line 53 of file sh_qspi.c.

◆ SH_QSPI_SPDCR

#define SH_QSPI_SPDCR   0x0b

Definition at line 61 of file sh_qspi.c.

◆ SH_QSPI_SPDR

#define SH_QSPI_SPDR   0x04

Definition at line 57 of file sh_qspi.c.

◆ SH_QSPI_SPND

#define SH_QSPI_SPND   0x0e

Definition at line 64 of file sh_qspi.c.

◆ SH_QSPI_SPPCR

#define SH_QSPI_SPPCR   0x02

Definition at line 55 of file sh_qspi.c.

◆ SH_QSPI_SPSCR

#define SH_QSPI_SPSCR   0x08

Definition at line 58 of file sh_qspi.c.

◆ SH_QSPI_SPSR

#define SH_QSPI_SPSR   0x03

Definition at line 56 of file sh_qspi.c.

◆ SH_QSPI_SPSSR

#define SH_QSPI_SPSSR   0x09

Definition at line 59 of file sh_qspi.c.

◆ SH_QSPI_SSLND

#define SH_QSPI_SSLND   0x0d

Definition at line 63 of file sh_qspi.c.

◆ SH_QSPI_SSLP

#define SH_QSPI_SSLP   0x01

Definition at line 54 of file sh_qspi.c.

◆ SPBDCR_RXBC0

#define SPBDCR_RXBC0   BIT(0)

Definition at line 36 of file sh_qspi.c.

◆ SPBFCR_RXRST

#define SPBFCR_RXRST   BIT(6)

Definition at line 48 of file sh_qspi.c.

◆ SPBFCR_RXTRG

#define SPBFCR_RXTRG   0x07

Definition at line 50 of file sh_qspi.c.

◆ SPBFCR_TXRST

#define SPBFCR_TXRST   BIT(7)

Definition at line 47 of file sh_qspi.c.

◆ SPBFCR_TXTRG

#define SPBFCR_TXTRG   0x30

Definition at line 49 of file sh_qspi.c.

◆ SPCMD_BRDV0

#define SPCMD_BRDV0   BIT(2)

Definition at line 41 of file sh_qspi.c.

◆ SPCMD_INIT1

#define SPCMD_INIT1
Value:
SPCMD_SPNDEN | SPCMD_SSLKP | \
SPCMD_BRDV0)
#define SPCMD_SLNDEN
Definition: sh_qspi.c:38
#define SPCMD_SSLKP
Definition: sh_qspi.c:40
#define SPCMD_SCKDEN
Definition: sh_qspi.c:37

Definition at line 42 of file sh_qspi.c.

◆ SPCMD_INIT2

#define SPCMD_INIT2
Value:
SPCMD_BRDV0)
#define SPCMD_SPNDEN
Definition: sh_qspi.c:39

Definition at line 45 of file sh_qspi.c.

◆ SPCMD_SCKDEN

#define SPCMD_SCKDEN   BIT(15)

Definition at line 37 of file sh_qspi.c.

◆ SPCMD_SLNDEN

#define SPCMD_SLNDEN   BIT(14)

Definition at line 38 of file sh_qspi.c.

◆ SPCMD_SPNDEN

#define SPCMD_SPNDEN   BIT(13)

Definition at line 39 of file sh_qspi.c.

◆ SPCMD_SSLKP

#define SPCMD_SSLKP   BIT(7)

Definition at line 40 of file sh_qspi.c.

◆ SPCR_MSTR

#define SPCR_MSTR   0x08

Definition at line 29 of file sh_qspi.c.

◆ SPCR_SPE

#define SPCR_SPE   0x40

Definition at line 30 of file sh_qspi.c.

◆ SPPCR_IO1FV

#define SPPCR_IO1FV   0x01

Definition at line 35 of file sh_qspi.c.

◆ SPPCR_IO2FV

#define SPPCR_IO2FV   0x02

Definition at line 34 of file sh_qspi.c.

◆ SPPCR_IO3FV

#define SPPCR_IO3FV   0x04

Definition at line 33 of file sh_qspi.c.

◆ SPSR_SPRFF

#define SPSR_SPRFF   0x80

Definition at line 31 of file sh_qspi.c.

◆ SPSR_SPTEF

#define SPSR_SPTEF   0x20

Definition at line 32 of file sh_qspi.c.

Function Documentation

◆ FLASH_BANK_COMMAND_HANDLER()

FLASH_BANK_COMMAND_HANDLER ( sh_qspi_flash_bank_command  )

◆ read_flash_id()

static int read_flash_id ( struct flash_bank bank,
uint32_t *  id 
)
static

◆ read_status_reg()

static int read_status_reg ( struct flash_bank bank,
uint32_t *  status 
)
static

Definition at line 374 of file sh_qspi.c.

References bank, ERROR_OK, sh_qspi_xfer_common(), SPIFLASH_READ_STATUS, and status.

Referenced by wait_till_ready().

◆ sh_qspi_auto_probe()

static int sh_qspi_auto_probe ( struct flash_bank bank)
static

Definition at line 836 of file sh_qspi.c.

References bank, ERROR_OK, info, and sh_qspi_probe().

◆ sh_qspi_cs_activate()

static int sh_qspi_cs_activate ( struct flash_bank bank)
static

◆ sh_qspi_cs_deactivate()

static int sh_qspi_cs_deactivate ( struct flash_bank bank)
static

Definition at line 246 of file sh_qspi.c.

References bank, ERROR_OK, info, SH_QSPI_SPCR, SPCR_SPE, target_read_u8(), and target_write_u8().

Referenced by sh_qspi_xfer_common().

◆ sh_qspi_erase()

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

◆ sh_qspi_erase_sector()

static int sh_qspi_erase_sector ( struct flash_bank bank,
int  sector 
)
static

Definition at line 413 of file sh_qspi.c.

References bank, ERROR_OK, info, NULL, sh_qspi_write_enable(), sh_qspi_xfer_common(), and wait_till_ready().

Referenced by sh_qspi_erase().

◆ sh_qspi_flash_blank_check()

static int sh_qspi_flash_blank_check ( struct flash_bank bank)
static

Definition at line 846 of file sh_qspi.c.

References ERROR_OK.

◆ sh_qspi_get_info()

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

Definition at line 858 of file sh_qspi.c.

References bank, cmd, command_print_sameline(), ERROR_OK, and info.

◆ sh_qspi_init()

◆ sh_qspi_probe()

◆ sh_qspi_protect()

static int sh_qspi_protect ( struct flash_bank bank,
int  set,
unsigned int  first,
unsigned int  last 
)
static

Definition at line 687 of file sh_qspi.c.

References bank, and ERROR_OK.

◆ sh_qspi_protect_check()

static int sh_qspi_protect_check ( struct flash_bank bank)
static

Definition at line 852 of file sh_qspi.c.

References ERROR_OK.

◆ sh_qspi_read()

◆ sh_qspi_upload_helper()

static int sh_qspi_upload_helper ( struct flash_bank bank)
static

◆ sh_qspi_wait_for_bit()

static int sh_qspi_wait_for_bit ( struct flash_bank bank,
uint8_t  reg,
uint32_t  mask,
bool  set,
unsigned long  timeout 
)
static

◆ sh_qspi_write()

◆ sh_qspi_write_enable()

static int sh_qspi_write_enable ( struct flash_bank bank)
static

Definition at line 366 of file sh_qspi.c.

References bank, NULL, sh_qspi_xfer_common(), and SPIFLASH_WRITE_ENABLE.

Referenced by sh_qspi_erase_sector().

◆ sh_qspi_xfer_common()

static int sh_qspi_xfer_common ( struct flash_bank bank,
const uint8_t *  dout,
unsigned int  outlen,
uint8_t *  din,
unsigned int  inlen,
bool  xfer_start,
bool  xfer_end 
)
static

◆ wait_till_ready()

static int wait_till_ready ( struct flash_bank bank,
int  timeout 
)
static

Variable Documentation

◆ sh_qspi_flash

const struct flash_driver sh_qspi_flash
Initial value:
= {
.name = "sh_qspi",
.flash_bank_command = sh_qspi_flash_bank_command,
.erase = sh_qspi_erase,
.protect = sh_qspi_protect,
.write = sh_qspi_write,
.read = sh_qspi_read,
.probe = sh_qspi_probe,
.auto_probe = sh_qspi_auto_probe,
.erase_check = sh_qspi_flash_blank_check,
.protect_check = sh_qspi_protect_check,
.free_driver_priv = default_flash_free_driver_priv,
}
void default_flash_free_driver_priv(struct flash_bank *bank)
Deallocates bank->driver_priv.
static int sh_qspi_protect_check(struct flash_bank *bank)
Definition: sh_qspi.c:852
static int sh_qspi_get_info(struct flash_bank *bank, struct command_invocation *cmd)
Definition: sh_qspi.c:858
static int sh_qspi_probe(struct flash_bank *bank)
Definition: sh_qspi.c:749
static int sh_qspi_protect(struct flash_bank *bank, int set, unsigned int first, unsigned int last)
Definition: sh_qspi.c:687
static int sh_qspi_auto_probe(struct flash_bank *bank)
Definition: sh_qspi.c:836
static int sh_qspi_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
Definition: sh_qspi.c:485
static int sh_qspi_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
Definition: sh_qspi.c:441
static int sh_qspi_read(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count)
Definition: sh_qspi.c:589
static int sh_qspi_flash_blank_check(struct flash_bank *bank)
Definition: sh_qspi.c:846

Definition at line 874 of file sh_qspi.c.

◆ target_devices

const struct sh_qspi_target target_devices[]
static
Initial value:
= {
{ "SH QSPI", 0x4ba00477, 0xe6b10000 },
{ NULL, 0, 0 }
}
#define NULL
Definition: usb.h:16

Definition at line 1 of file sh_qspi.c.

Referenced by sh_qspi_probe().