Skip to content

Commit 82b882f

Browse files
decsnyjhedberg
authored andcommitted
drivers: spi: nxp_lpspi: Use spi_config timing params
Use the timing params from spi_config that are specific to the slave instead of using the same timing for the controller for all slaves. Remove these properties from the LPSPI DT binding. Signed-off-by: Declan Snyder <[email protected]>
1 parent 1154c96 commit 82b882f

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

drivers/spi/spi_nxp_lpspi/spi_nxp_lpspi_common.c

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,32 @@ static uint8_t lpspi_calc_delay_scaler(uint32_t desired_delay_ns,
158158
}
159159

160160
/* returns CCR mask of the bits 8-31 */
161-
static inline uint32_t lpspi_set_delays(const struct device *dev, uint32_t prescaled_clock)
161+
static inline uint32_t lpspi_set_delays(const struct device *dev,
162+
const struct spi_config *spi_cfg,
163+
uint32_t prescaled_clock)
162164
{
163165
const struct lpspi_config *config = dev->config;
166+
uint32_t val = 0;
167+
168+
if (!spi_cs_is_gpio(spi_cfg)) {
169+
uint32_t lead_time_ns = config->pcs_sck_delay > 0 ?
170+
config->pcs_sck_delay : spi_cfg->cs.setup_ns;
171+
uint32_t lag_time_ns = config->sck_pcs_delay > 0 ?
172+
config->sck_pcs_delay : spi_cfg->cs.hold_ns;
173+
174+
val |= LPSPI_CCR_PCSSCK(lpspi_calc_delay_scaler(lead_time_ns,
175+
prescaled_clock, 1)) |
176+
LPSPI_CCR_SCKPCS(lpspi_calc_delay_scaler(lag_time_ns,
177+
prescaled_clock, 1));
178+
}
179+
180+
uint16_t word_delay = config->transfer_delay > 0 ?
181+
(uint16_t)(config->transfer_delay & 0xFFFF) :
182+
spi_get_word_delay(spi_cfg);
183+
184+
val |= LPSPI_CCR_DBT(lpspi_calc_delay_scaler(word_delay, prescaled_clock, 2));
164185

165-
return LPSPI_CCR_PCSSCK(lpspi_calc_delay_scaler(config->pcs_sck_delay,
166-
prescaled_clock, 1)) |
167-
LPSPI_CCR_SCKPCS(lpspi_calc_delay_scaler(config->sck_pcs_delay,
168-
prescaled_clock, 1)) |
169-
LPSPI_CCR_DBT(lpspi_calc_delay_scaler(config->transfer_delay,
170-
prescaled_clock, 2));
186+
return val;
171187
}
172188

173189
/* This is the equation for the sck frequency given a div and prescaler. */
@@ -324,7 +340,7 @@ int lpspi_configure(const struct device *dev, const struct spi_config *spi_cfg)
324340

325341
/* sckdiv algorithm must run *before* delays are set in order to know prescaler */
326342
ccr |= lpspi_set_sckdiv(spi_cfg->frequency, clock_freq, &prescaler);
327-
ccr |= lpspi_set_delays(dev, clock_freq / TWO_EXP(prescaler));
343+
ccr |= lpspi_set_delays(dev, spi_cfg, clock_freq / TWO_EXP(prescaler));
328344

329345
/* note that not all bits of the register are readable on some platform,
330346
* that's why we update it on one write

0 commit comments

Comments
 (0)