Skip to content

Commit 9f6c531

Browse files
michalsieronmbolivar-nordic
authored andcommitted
drivers: spi: spi_litespi: Update driver registers
Make driver take register info from device tree so it can work with both 8-bit and 32-bit CSRs. Signed-off-by: Michal Sieron <[email protected]>
1 parent f45acb7 commit 9f6c531

File tree

3 files changed

+27
-19
lines changed

3 files changed

+27
-19
lines changed

drivers/spi/spi_litespi.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ static int spi_config(const struct spi_config *config, uint16_t *control)
6868

6969
/* Set Loopback */
7070
if (config->operation & SPI_MODE_LOOP) {
71-
litex_write8(SPI_ENABLE, SPI_LOOPBACK_REG);
71+
litex_write8(SPI_ENABLE, SPI_LOOPBACK_ADDR);
7272
}
7373
/* Set word size */
7474
*control = (uint16_t) (SPI_WORD_SIZE_GET(config->operation)
7575
<< POSITION_WORD_SIZE);
7676
/* Write configurations */
77-
litex_write8(cs, SPI_CS_REG);
78-
litex_write16(*control, SPI_CONTROL_REG);
77+
litex_write8(cs, SPI_CS_ADDR);
78+
litex_write16(*control, SPI_CONTROL_ADDR);
7979

8080
return 0;
8181
}
@@ -84,18 +84,18 @@ static void spi_litespi_send(const struct device *dev, uint8_t frame,
8484
uint16_t control)
8585
{
8686
/* Write frame to register */
87-
litex_write8(frame, SPI_MOSI_DATA_REG);
87+
litex_write8(frame, SPI_MOSI_DATA_ADDR);
8888
/* Start the transfer */
89-
litex_write16(control | SPI_ENABLE, SPI_CONTROL_REG);
89+
litex_write16(control | SPI_ENABLE, SPI_CONTROL_ADDR);
9090
/* Wait until the transfer ends */
91-
while (!(litex_read8(SPI_STATUS_REG)))
91+
while (!(litex_read8(SPI_STATUS_ADDR)))
9292
;
9393
}
9494

9595
static uint8_t spi_litespi_recv(void)
9696
{
9797
/* Return data inside MISO register */
98-
return litex_read8(SPI_MISO_DATA_REG);
98+
return litex_read8(SPI_MISO_DATA_ADDR);
9999
}
100100

101101
static void spi_litespi_xfer(const struct device *dev,
@@ -158,7 +158,7 @@ static int spi_litespi_transceive_async(const struct device *dev,
158158
static int spi_litespi_release(const struct device *dev,
159159
const struct spi_config *config)
160160
{
161-
if (!(litex_read8(SPI_STATUS_REG))) {
161+
if (!(litex_read8(SPI_STATUS_ADDR))) {
162162
return -EBUSY;
163163
}
164164
return 0;

drivers/spi/spi_litespi.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
#include <zephyr/device.h>
1414
#include <zephyr/drivers/spi.h>
1515

16-
#define SPI_BASE_ADDR DT_INST_REG_ADDR(0)
17-
#define SPI_CONTROL_REG SPI_BASE_ADDR
18-
#define SPI_STATUS_REG (SPI_BASE_ADDR + 0x08)
19-
#define SPI_MOSI_DATA_REG (SPI_BASE_ADDR + 0x0c)
20-
#define SPI_MISO_DATA_REG (SPI_BASE_ADDR + 0x10)
21-
#define SPI_CS_REG (SPI_BASE_ADDR + 0x14)
22-
#define SPI_LOOPBACK_REG (SPI_BASE_ADDR + 0x18)
16+
#define SPI_BASE_ADDR DT_INST_REG_ADDR(0)
17+
#define SPI_CONTROL_ADDR DT_INST_REG_ADDR_BY_NAME(0, control)
18+
#define SPI_STATUS_ADDR DT_INST_REG_ADDR_BY_NAME(0, status)
19+
#define SPI_MOSI_DATA_ADDR DT_INST_REG_ADDR_BY_NAME(0, mosi)
20+
#define SPI_MISO_DATA_ADDR DT_INST_REG_ADDR_BY_NAME(0, miso)
21+
#define SPI_CS_ADDR DT_INST_REG_ADDR_BY_NAME(0, cs)
22+
#define SPI_LOOPBACK_ADDR DT_INST_REG_ADDR_BY_NAME(0, loopback)
2323

2424
#define POSITION_WORD_SIZE 8
2525
#define SPI_MAX_CS_SIZE 0x100

dts/riscv/riscv32-litex-vexriscv.dtsi

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,18 @@
6767
};
6868
spi0: spi@e0002000 {
6969
compatible = "litex,spi";
70-
interrupt-parent = <&intc0>;
71-
interrupts = <5 0>;
72-
reg = <0xe0002000 0x34>;
73-
reg-names = "control";
70+
reg = <0xe0002000 0x4
71+
0xe0002004 0x4
72+
0xe0002008 0x4
73+
0xe000200c 0x4
74+
0xe0002010 0x4
75+
0xe0002014 0x4>;
76+
reg-names = "control",
77+
"status",
78+
"mosi",
79+
"miso",
80+
"cs",
81+
"loopback";
7482
label = "spi0";
7583
status = "disabled";
7684
#address-cells = <1>;

0 commit comments

Comments
 (0)