|
4 | 4 | * SPDX-License-Identifier: Apache-2.0
|
5 | 5 | */
|
6 | 6 |
|
| 7 | +/* |
| 8 | + * This is a collection of functions that would be useful for any driver for LPSPI. |
| 9 | + * This function/file has no knowledge of lpspi usage model by the driver |
| 10 | + * beyond basic configuration and should avoid making any assumptions about how |
| 11 | + * the driver is going to achieve the zephyr API. |
| 12 | + */ |
| 13 | + |
7 | 14 | #include <zephyr/logging/log.h>
|
8 | 15 | LOG_MODULE_REGISTER(spi_lpspi, CONFIG_SPI_LOG_LEVEL);
|
9 | 16 |
|
@@ -131,23 +138,20 @@ int spi_mcux_configure(const struct device *dev, const struct spi_config *spi_cf
|
131 | 138 | return ret;
|
132 | 139 | }
|
133 | 140 |
|
134 |
| - if (already_configured) { |
135 |
| - /* Setting the baud rate in LPSPI_MasterInit requires module to be disabled. Only |
136 |
| - * disable if already configured, otherwise the clock is not enabled and the |
137 |
| - * CR register cannot be written. |
138 |
| - */ |
139 |
| - LPSPI_Enable(base, false); |
140 |
| - while ((base->CR & LPSPI_CR_MEN_MASK) != 0U) { |
141 |
| - /* Wait until LPSPI is disabled. Datasheet: |
142 |
| - * After writing 0, MEN (Module Enable) remains set until the LPSPI has |
143 |
| - * completed the current transfer and is idle. |
144 |
| - */ |
145 |
| - } |
| 141 | + /* specific driver implementation should set up watermarks and interrupts. |
| 142 | + * we reset them here to avoid any unexpected events during configuring. |
| 143 | + */ |
| 144 | + base->FCR = 0; |
| 145 | + base->IER = 0; |
| 146 | + |
| 147 | + /* this is workaround for ERR050456 */ |
| 148 | + base->CR |= LPSPI_CR_RST_MASK; |
| 149 | + base->CR |= LPSPI_CR_RRF_MASK | LPSPI_CR_RTF_MASK; |
146 | 150 |
|
147 |
| - /* this is workaround for ERR050456 */ |
148 |
| - base->CR |= LPSPI_CR_RST_MASK; |
149 |
| - base->CR |= LPSPI_CR_RRF_MASK | LPSPI_CR_RTF_MASK; |
150 |
| - base->CR = 0x00U; |
| 151 | + /* Setting the baud rate requires module to be disabled. */ |
| 152 | + base->CR = 0; |
| 153 | + while ((base->CR & LPSPI_CR_MEN_MASK) != 0) { |
| 154 | + /* According to datasheet, should wait for this MEN bit to clear once idle */ |
151 | 155 | }
|
152 | 156 |
|
153 | 157 | data->ctx.config = spi_cfg;
|
|
0 commit comments