Skip to content

Commit 4818585

Browse files
krish2718kartben
authored andcommitted
modules: nrf_wifi: spi: Implement frequency switching
In order to support higher frequencies than 8MHz, we need to implement frequency switching while waking up the RPU, as it has to be done only at 8MHz, once RPU is awake, we can switch back to the configured (DTS) frequency. Signed-off-by: Chaitanya Tata <[email protected]>
1 parent 6f42911 commit 4818585

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

modules/nrf_wifi/bus/spi_if.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ static struct qspi_config *spim_config;
2626
static const struct spi_dt_spec spi_spec =
2727
SPI_DT_SPEC_GET(NRF7002_NODE, SPI_WORD_SET(8) | SPI_TRANSFER_MSB, 0);
2828

29+
static struct spi_dt_spec spi_spec_8mhz =
30+
SPI_DT_SPEC_GET(NRF7002_NODE, SPI_WORD_SET(8) | SPI_TRANSFER_MSB, 0);
31+
2932
static int spim_xfer_tx(unsigned int addr, void *data, unsigned int len)
3033
{
3134
int err;
@@ -116,15 +119,15 @@ int spim_read_reg(uint32_t reg_addr, uint8_t *reg_value)
116119
return err;
117120
}
118121

119-
int spim_write_reg(uint32_t reg_addr, const uint8_t reg_value)
122+
int spim_write_reg(const struct spi_dt_spec *spi_spec, uint32_t reg_addr, const uint8_t reg_value)
120123
{
121124
int err;
122125
uint8_t tx_buffer[] = { reg_addr, reg_value };
123126

124127
const struct spi_buf tx_buf = { .buf = tx_buffer, .len = sizeof(tx_buffer) };
125128
const struct spi_buf_set tx = { .buffers = &tx_buf, .count = 1 };
126129

127-
err = spi_transceive_dt(&spi_spec, &tx, NULL);
130+
err = spi_transceive_dt(spi_spec, &tx, NULL);
128131

129132
if (err) {
130133
LOG_ERR("SPI error: %d", err);
@@ -150,7 +153,7 @@ int spim_RDSR2(const struct device *dev, uint8_t *rdsr1)
150153

151154
int spim_WRSR2(const struct device *dev, const uint8_t wrsr2)
152155
{
153-
return spim_write_reg(0x3F, wrsr2);
156+
return spim_write_reg(&spi_spec, 0x3F, wrsr2);
154157
}
155158

156159
int _spim_wait_while_rpu_awake(void)
@@ -208,7 +211,13 @@ int spim_wait_while_rpu_wake_write(void)
208211

209212
int spim_cmd_rpu_wakeup(uint32_t data)
210213
{
211-
return spim_write_reg(0x3F, data);
214+
struct spi_dt_spec *spi_spec_tmp = (struct spi_dt_spec *)&spi_spec;
215+
216+
if (spi_spec.config.frequency > MHZ(8)) {
217+
spi_spec_tmp = &spi_spec_8mhz;
218+
}
219+
/* Waking RPU works reliably only with lowest frequency (8MHz) */
220+
return spim_write_reg(spi_spec_tmp, 0x3F, data);
212221
}
213222

214223
unsigned int spim_cmd_sleep_rpu(void)
@@ -243,6 +252,8 @@ int spim_init(struct qspi_config *config)
243252
spim_config->qspi_slave_latency = 1;
244253
}
245254

255+
spi_spec_8mhz.config.frequency = MHZ(8);
256+
246257
LOG_INF("SPIM %s: freq = %d MHz", spi_spec.bus->name,
247258
spi_spec.config.frequency / MHZ(1));
248259
LOG_INF("SPIM %s: latency = %d", spi_spec.bus->name, spim_config->qspi_slave_latency);

0 commit comments

Comments
 (0)