|
1 | 1 | /* |
2 | 2 | * Copyright (c) 2016, Freescale Semiconductor, Inc. |
3 | | - * Copyright 2017, 2019, 2025, NXP |
| 3 | + * Copyright 2017, 2019, 2025 NXP |
4 | 4 | * |
5 | 5 | * SPDX-License-Identifier: Apache-2.0 |
6 | 6 | */ |
@@ -29,7 +29,13 @@ LOG_MODULE_REGISTER(spi_mcux_flexcomm, CONFIG_SPI_LOG_LEVEL); |
29 | 29 |
|
30 | 30 | #include "spi_context.h" |
31 | 31 |
|
32 | | -#define SPI_CHIP_SELECT_COUNT 4 |
| 32 | +#ifdef CONFIG_SOC_SERIES_RW6XX |
| 33 | +/* The RW61x SOC only allows use of HW chip select 0 */ |
| 34 | +#define SPI_CHIP_SELECT_COUNT 1 |
| 35 | +#else |
| 36 | +#define SPI_CHIP_SELECT_COUNT FSL_FEATURE_SPI_SSEL_COUNT |
| 37 | +#endif |
| 38 | + |
33 | 39 | #define SPI_MAX_DATA_WIDTH 16 |
34 | 40 | #define SPI_MIN_DATA_WIDTH 4 |
35 | 41 |
|
@@ -225,9 +231,19 @@ static int spi_mcux_configure(const struct device *dev, |
225 | 231 | return -EINVAL; |
226 | 232 | } |
227 | 233 |
|
228 | | - if (spi_cfg->slave > SPI_CHIP_SELECT_COUNT) { |
229 | | - LOG_ERR("Slave %d is greater than %d", |
230 | | - spi_cfg->slave, SPI_CHIP_SELECT_COUNT); |
| 234 | + uint8_t max_slave = SPI_CHIP_SELECT_COUNT; |
| 235 | + |
| 236 | +#ifndef DT_SPI_CTX_HAS_NO_CS_GPIOS |
| 237 | + struct spi_context *ctx = &data->ctx; |
| 238 | + |
| 239 | + max_slave = MAX(max_slave, ctx->num_cs_gpios); |
| 240 | +#endif |
| 241 | + |
| 242 | + max_slave -= 1; |
| 243 | + |
| 244 | + if (spi_cfg->slave > max_slave) { |
| 245 | + LOG_ERR("Slave %d is greater than max %d", |
| 246 | + spi_cfg->slave, max_slave); |
231 | 247 | return -EINVAL; |
232 | 248 | } |
233 | 249 |
|
|
0 commit comments