Skip to content

Commit 8b99550

Browse files
xiaolusufabiobaltieri
authored andcommitted
drivers: spi_sedi: correct CPOL and CPHA mode handling in SPI config
The CPOL and CPHA mode handling logic in the SPI configuration was corrected to ensure proper evaluation of the SPI mode bits. Evaluate CPOL and CPHA bits using value of cpol_mode and cpha_mode: `(SPI_MODE_GET(config->operation) & SPI_MODE_CPOL) != 0` and `(SPI_MODE_GET(config->operation) & SPI_MODE_CPHA) != 0`. This fix ensures that the SPI configuration is robust and adheres to expected behavior when setting CPOL and CPHA modes. Signed-off-by: Xiaolu Sun <[email protected]>
1 parent 84112df commit 8b99550

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

drivers/spi/spi_sedi.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ static int spi_sedi_configure(const struct device *dev,
3939
{
4040
struct spi_sedi_data *data = dev->data;
4141
const struct spi_sedi_config *info = dev->config;
42-
uint32_t word_size, cpol, cpha, loopback;
42+
uint32_t word_size, loopback;
43+
bool cpol_mode, cpha_mode;
4344

4445
if (spi_context_configured(&data->ctx, config) == true) {
4546
return 0;
@@ -50,23 +51,23 @@ static int spi_sedi_configure(const struct device *dev,
5051
word_size);
5152

5253
/* CPOL and CPHA */
53-
cpol = SPI_MODE_GET(config->operation) & SPI_MODE_CPOL;
54-
cpha = SPI_MODE_GET(config->operation) & SPI_MODE_CPHA;
5554

56-
if ((cpol == 0) && (cpha == 0)) {
55+
cpol_mode = ((SPI_MODE_GET(config->operation) & SPI_MODE_CPOL) != 0);
56+
cpha_mode = ((SPI_MODE_GET(config->operation) & SPI_MODE_CPHA) != 0);
57+
58+
if (!cpol_mode && !cpha_mode) {
5759
sedi_spi_control(info->spi_device, SEDI_SPI_IOCTL_CPOL0_CPHA0,
5860
0);
59-
} else if ((cpol == 0) && (cpha == 1U)) {
61+
} else if (!cpol_mode && cpha_mode) {
6062
sedi_spi_control(info->spi_device, SEDI_SPI_IOCTL_CPOL0_CPHA1,
6163
0);
62-
} else if ((cpol == 1) && (cpha == 0U)) {
64+
} else if (cpol_mode && !cpha_mode) {
6365
sedi_spi_control(info->spi_device, SEDI_SPI_IOCTL_CPOL1_CPHA0,
6466
0);
6567
} else {
6668
sedi_spi_control(info->spi_device, SEDI_SPI_IOCTL_CPOL1_CPHA1,
6769
0);
6870
}
69-
7071
/* MSB and LSB */
7172
if (config->operation & SPI_TRANSFER_LSB) {
7273
sedi_spi_control(info->spi_device, SEDI_SPI_IOCTL_LSB, 0);

0 commit comments

Comments
 (0)