Skip to content

Commit 9c68492

Browse files
committed
Revert "Update SPI flash driver for new QSPI core"
This reverts commit 8d3da3b.
1 parent 8d3da3b commit 9c68492

File tree

3 files changed

+57
-51
lines changed

3 files changed

+57
-51
lines changed

chipflow_lib/software/drivers/spiflash.S

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,67 @@
1+
12
.global flashio_worker_begin
23
.global flashio_worker_end
34

45
.balign 4
56

67
flashio_worker_begin:
7-
# a0 ... flash base address
8+
# a0 ... address of SPI ctrl reg
89
# a1 ... data pointer
910
# a2 ... data length
1011
# a3 ... optional WREN cmd (0 = disable)
1112

12-
mv t3, ra
13-
14-
# address of SPI ctrl reg
15-
li a0, 0xb0000000
16-
# enter bypass mode
17-
lbu t1, 0(a0)
18-
ori t1, t1, 0x1
19-
sb t1, 0(a0)
20-
call flashio_wait_bypass_ready
21-
22-
beqz a3, flashio_xfer
23-
24-
sb a3, 8(a0) # send wren
25-
call flashio_wait_bypass_ready
26-
li t1, 2 # deselect
27-
sb t1, 4(a0)
28-
call flashio_wait_bypass_ready
29-
30-
flashio_xfer:
31-
beqz a2, flashio_done
32-
lbu t1, 0(a1)
33-
sb t1, 8(a0) # tx data
34-
call flashio_wait_bypass_ready
35-
lbu t1, 12(a0) # rx data
36-
sb t1, 0(a1)
13+
# Set CS high, IO0 is output
14+
li t1, 0x120
15+
sh t1, 0(a0)
16+
17+
# Enable Manual SPI Ctrl
18+
sb zero, 3(a0)
19+
20+
# Send optional WREN cmd
21+
beqz a3, flashio_worker_L1
22+
li t5, 8
23+
andi t2, a3, 0xff
24+
flashio_worker_L4:
25+
srli t4, t2, 7
26+
sb t4, 0(a0)
27+
ori t4, t4, 0x10
28+
sb t4, 0(a0)
29+
slli t2, t2, 1
30+
andi t2, t2, 0xff
31+
addi t5, t5, -1
32+
bnez t5, flashio_worker_L4
33+
sb t1, 0(a0)
34+
35+
# SPI transfer
36+
flashio_worker_L1:
37+
beqz a2, flashio_worker_L3
38+
li t5, 8
39+
lbu t2, 0(a1)
40+
flashio_worker_L2:
41+
srli t4, t2, 7
42+
sb t4, 0(a0)
43+
ori t4, t4, 0x10
44+
sb t4, 0(a0)
45+
lbu t4, 0(a0)
46+
andi t4, t4, 2
47+
srli t4, t4, 1
48+
slli t2, t2, 1
49+
or t2, t2, t4
50+
andi t2, t2, 0xff
51+
addi t5, t5, -1
52+
bnez t5, flashio_worker_L2
53+
sb t2, 0(a1)
3754
addi a1, a1, 1
3855
addi a2, a2, -1
39-
j flashio_xfer
56+
j flashio_worker_L1
57+
flashio_worker_L3:
4058

41-
flashio_done:
42-
# exit bypass mode
43-
lbu t1, 0(a0)
44-
andi t1, t1, 0xFE
45-
sb t1, 0(a0)
59+
# Back to MEMIO mode
60+
li t1, 0x80
61+
sb t1, 3(a0)
4662

4763
fence.i
48-
mv ra, t3
49-
ret
5064

51-
flashio_wait_bypass_ready:
52-
lbu t1, 4(a0)
53-
andi t1, t1, 0x1
54-
beqz t1, flashio_wait_bypass_ready
5565
ret
5666

5767
.balign 4

chipflow_lib/software/drivers/spiflash.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,17 @@ extern uint32_t flashio_worker_end;
77

88
void spiflash_io(volatile spiflash_regs_t *flash, uint8_t *data, int len, uint8_t wrencmd) {
99
// Flash can't be accessed during IO, so copy to RAM and run that
10-
volatile uint32_t func[&flashio_worker_end - &flashio_worker_begin];
10+
volatile uint32_t func[&flashio_worker_end - &flashio_worker_begin];
1111

12-
// Can't execute off flash while talking to it, so copy IO code to SRAM
13-
uint32_t *src_ptr = &flashio_worker_begin;
14-
volatile uint32_t *dst_ptr = func;
12+
uint32_t *src_ptr = &flashio_worker_begin;
13+
volatile uint32_t *dst_ptr = func;
1514

16-
while (src_ptr != &flashio_worker_end)
17-
*(dst_ptr++) = *(src_ptr++);
15+
while (src_ptr != &flashio_worker_end)
16+
*(dst_ptr++) = *(src_ptr++);
1817

19-
__asm__ volatile ("fence.i" : : : "memory");
18+
__asm__ volatile ("fence.i" : : : "memory");
2019

21-
((void(*)(uint8_t*, uint8_t*, uint32_t, uint32_t))func)((uint8_t*)flash, data, len, wrencmd);
20+
((void(*)(volatile spiflash_regs_t *, uint8_t*, uint32_t, uint32_t))func)(flash, data, len, wrencmd);
2221
}
2322

2423
uint32_t spiflash_read_id(volatile spiflash_regs_t *flash) {
@@ -70,5 +69,5 @@ void spiflash_set_qspi_flag(volatile spiflash_regs_t *flash) {
7069
}
7170

7271
void spiflash_set_quad_mode(volatile spiflash_regs_t *flash) {
73-
flash->config = (0x3U << 3U) | (0x03U << 1U); // 3 dummy byte, X4 mode
72+
flash->ctrl = (flash->ctrl & ~0x007f0000) | 0x00240000;
7473
}

chipflow_lib/software/drivers/spiflash.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88
#define ISSI_ID 0x60
99

1010
typedef struct __attribute__((packed, aligned(4))) {
11-
uint32_t config;
12-
uint32_t raw_control;
13-
uint32_t raw_tx_data;
14-
uint32_t raw_rx_data;
11+
uint32_t ctrl;
1512
} spiflash_regs_t;
1613

1714
void spiflash_io(volatile spiflash_regs_t *flash, uint8_t *data, int len, uint8_t wrencmd);

0 commit comments

Comments
 (0)