Skip to content

Commit 8b03ca7

Browse files
myguitarcujomalainey
authored andcommitted
drivers: spi: dw: support rx sample delay
The RX_SAMPLE_DELAY register controls the number of ssi_clk cycles that are delayed from the default sample time before the actual sample of the rxd input occurs. A 'rx-sample-delay' devicetree property is added to support the delay control. Signed-off-by: Younghyun Park <younghyunpark@google.com>
1 parent 17a4315 commit 8b03ca7

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

drivers/spi/spi_dw.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,15 @@ static int transceive(const struct device *dev,
423423
/* Rx Threshold */
424424
write_rxftlr(dev, reg_data);
425425

426+
/* Rx sample delay */
427+
if (info->rx_sample_delay) {
428+
reg_data = read_rx_sample_dly(dev);
429+
reg_data &= ~DW_SPI_RX_SAMPLE_DELAY_MASK;
430+
reg_data |= FIELD_PREP(DW_SPI_RX_SAMPLE_DELAY_MASK,
431+
info->rx_sample_delay);
432+
write_rx_sample_dly(dev, reg_data);
433+
}
434+
426435
/* Enable interrupts */
427436
reg_data = !rx_bufs ?
428437
DW_SPI_IMR_UNMASK & DW_SPI_IMR_MASK_RX :
@@ -647,6 +656,7 @@ COND_CODE_1(IS_EQ(DT_NUM_IRQS(DT_DRV_INST(inst)), 1), \
647656
.serial_target = DT_INST_PROP(inst, serial_target), \
648657
.fifo_depth = DT_INST_PROP(inst, fifo_depth), \
649658
.max_xfer_size = DT_INST_PROP(inst, max_xfer_size), \
659+
.rx_sample_delay = DT_INST_PROP(inst, rx_sample_delay), \
650660
IF_ENABLED(CONFIG_PINCTRL, (.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst),)) \
651661
COND_CODE_1(DT_INST_PROP(inst, aux_reg), \
652662
(.read_func = aux_reg_read, \

drivers/spi/spi_dw.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ struct spi_dw_config {
3535
bool serial_target;
3636
uint8_t fifo_depth;
3737
uint8_t max_xfer_size;
38+
uint8_t rx_sample_delay;
3839
#ifdef CONFIG_PINCTRL
3940
const struct pinctrl_dev_config *pcfg;
4041
#endif
@@ -273,6 +274,9 @@ static int reg_test_bit(uint8_t bit, mm_reg_t addr, uint32_t off)
273274
DW_SPI_IMR_RXOIM | \
274275
DW_SPI_IMR_RXFIM))
275276

277+
/* RX Sample Delay */
278+
#define DW_SPI_RX_SAMPLE_DELAY_MASK GENMASK(7, 0)
279+
276280
/*
277281
* Including the right register definition file
278282
* SoC SPECIFIC!

drivers/spi/spi_dw_regs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ DEFINE_MM_REG_READ(txftlr, DW_SPI_REG_TXFTLR, 32)
5151
DEFINE_MM_REG_WRITE(dr, DW_SPI_REG_DR, 32)
5252
DEFINE_MM_REG_READ(dr, DW_SPI_REG_DR, 32)
5353
DEFINE_MM_REG_READ(ssi_comp_version, DW_SPI_REG_SSI_COMP_VERSION, 32)
54+
DEFINE_MM_REG_WRITE(rx_sample_dly, DW_SPI_REG_RX_SAMPLE_DLY, 32)
55+
DEFINE_MM_REG_READ(rx_sample_dly, DW_SPI_REG_RX_SAMPLE_DLY, 32)
5456

5557
#ifdef CONFIG_SPI_DW_ACCESS_WORD_ONLY
5658
DEFINE_MM_REG_WRITE(ctrlr1, DW_SPI_REG_CTRLR1, 32)

dts/bindings/spi/snps,designware-spi.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,12 @@ properties:
4444
enum:
4545
- 16
4646
- 32
47+
48+
rx-sample-delay:
49+
type: int
50+
default: 0
51+
description: |
52+
Receive Data(rxd) Sample Delay. This is used to delay
53+
the sample of the rxd input port. Each value represents
54+
a single ssi_clk delay on the sample of rxd. Default is
55+
0 and delay ranges from 0-255.

0 commit comments

Comments
 (0)