Skip to content

Commit 9c829a1

Browse files
danieldegrassefabiobaltieri
authored andcommitted
drivers: mspi: mspi_dw: add API to configure RX_DLY timing
The SSI DW peripheral supports an RX_SAMPLE_DLY register in some instances- this register controls the number of clock cycles from the default sample time before the RX input is actually sampled. This can be used to improve reliability when operating the SSI at a higher clock speed. Add an implementation of the mspi_timing_cfg api, and header to define the identifier so that users can configure this parameter Signed-off-by: Daniel DeGrasse <[email protected]>
1 parent 59d8fbc commit 9c829a1

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

drivers/mspi/mspi_dw.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <zephyr/pm/device_runtime.h>
1818
#include <zephyr/sys/byteorder.h>
1919
#include <zephyr/sys/util.h>
20+
#include <zephyr/drivers/mspi/mspi_dw.h>
2021

2122
#include "mspi_dw.h"
2223

@@ -48,6 +49,7 @@ struct mspi_dw_data {
4849
uint32_t ctrlr0;
4950
uint32_t spi_ctrlr0;
5051
uint32_t baudr;
52+
uint32_t rx_sample_dly;
5153

5254
#if defined(CONFIG_MSPI_XIP)
5355
uint32_t xip_freq;
@@ -113,6 +115,7 @@ DEFINE_MM_REG_WR(imr, 0x2c)
113115
DEFINE_MM_REG_RD(isr, 0x30)
114116
DEFINE_MM_REG_RD(risr, 0x34)
115117
DEFINE_MM_REG_RD_WR(dr, 0x60)
118+
DEFINE_MM_REG_WR(rx_sample_dly, 0xf0)
116119
DEFINE_MM_REG_WR(spi_ctrlr0, 0xf4)
117120

118121
#if defined(CONFIG_MSPI_XIP)
@@ -936,6 +939,7 @@ static int start_next_packet(const struct device *dev, k_timeout_t timeout)
936939
: 0);
937940
write_spi_ctrlr0(dev, dev_data->spi_ctrlr0);
938941
write_baudr(dev, dev_data->baudr);
942+
write_rx_sample_dly(dev, dev_data->rx_sample_dly);
939943
write_ser(dev, BIT(dev_data->dev_id->dev_idx));
940944

941945
if (xip_enabled) {
@@ -1262,6 +1266,20 @@ static int _api_xip_config(const struct device *dev,
12621266
return 0;
12631267
}
12641268

1269+
static int api_timing_config(const struct device *dev,
1270+
const struct mspi_dev_id *dev_id,
1271+
const uint32_t param_mask, void *cfg)
1272+
{
1273+
struct mspi_dw_data *dev_data = dev->data;
1274+
struct mspi_dw_timing_cfg *config = cfg;
1275+
1276+
if (param_mask & MSPI_DW_RX_TIMING_CFG) {
1277+
dev_data->rx_sample_dly = config->rx_sample_dly;
1278+
return 0;
1279+
}
1280+
return -ENOTSUP;
1281+
}
1282+
12651283
static int api_xip_config(const struct device *dev,
12661284
const struct mspi_dev_id *dev_id,
12671285
const struct mspi_xip_cfg *cfg)
@@ -1407,6 +1425,7 @@ static DEVICE_API(mspi, drv_api) = {
14071425
.dev_config = api_dev_config,
14081426
.get_channel_status = api_get_channel_status,
14091427
.transceive = api_transceive,
1428+
.timing_config = api_timing_config,
14101429
#if defined(CONFIG_MSPI_XIP)
14111430
.xip_config = api_xip_config,
14121431
#endif

include/zephyr/drivers/mspi/mspi_dw.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) 2025 Tenstorrent AI ULC
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_INCLUDE_DRIVERS_MSPI_DW_H_
8+
#define ZEPHYR_INCLUDE_DRIVERS_MSPI_DW_H_
9+
10+
#ifdef __cplusplus
11+
extern "C" {
12+
#endif
13+
14+
/**
15+
* Designware MSPI configuration structure- this should be passed to the
16+
* MSPI driver when calling mspi_timing_config
17+
*/
18+
struct mspi_dw_timing_cfg {
19+
uint32_t rx_sample_dly; /* RX sample delay, written to RX_SAMPLE_DLY register */
20+
};
21+
22+
/* Configure RX_SAMPLE_DLY register for MSPI DW SSI */
23+
#define MSPI_DW_RX_TIMING_CFG BIT(0)
24+
25+
#ifdef __cplusplus
26+
}
27+
#endif
28+
29+
#endif /* ZEPHYR_INCLUDE_DRIVERS_MSPI_DW_H_ */

0 commit comments

Comments
 (0)