Skip to content

Commit eae7312

Browse files
committed
spi_nxp_lpspi: Reset/clock peripheral
If there are HAL definitions available, do these two things: Ungate the clock for the device from the zephyr driver. Eventually it would be better to have a clocks property in the LPSPI DT node and get the resources from there rather than the HAL. Some platforms require the peripheral to be reset at system level, add code to do this. Eventually it would be more ideal to have Zephyr reset drivers for all of the NXP platforms and use DT to describe the reset resources, but for now we can just do this to get the LPSPI supported. Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
1 parent 77dc96c commit eae7312

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

drivers/spi/spi_nxp_lpspi/spi_nxp_lpspi_common.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,49 @@ LOG_MODULE_REGISTER(spi_mcux_lpspi_common, CONFIG_SPI_LOG_LEVEL);
1010
#include "spi_nxp_lpspi_priv.h"
1111
#include <fsl_lpspi.h>
1212

13+
#if defined(LPSPI_RSTS) || defined(LPSPI_CLOCKS)
14+
static LPSPI_Type *const lpspi_bases[] = LPSPI_BASE_PTRS;
15+
#endif
16+
17+
#ifdef LPSPI_RSTS
18+
static const reset_ip_name_t lpspi_resets[] = LPSPI_RSTS;
19+
20+
static inline reset_ip_name_t lpspi_get_reset(LPSPI_Type *const base)
21+
{
22+
reset_ip_name_t rst = -1; /* invalid initial value */
23+
24+
ARRAY_FOR_EACH(lpspi_bases, idx) {
25+
if (lpspi_bases[idx] == base) {
26+
rst = lpspi_resets[idx];
27+
break;
28+
}
29+
}
30+
31+
__ASSERT_NO_MSG(rst != -1);
32+
return rst;
33+
34+
}
35+
#endif
36+
37+
#ifdef LPSPI_CLOCKS
38+
static const clock_ip_name_t lpspi_clocks[] = LPSPI_CLOCKS;
39+
40+
static inline clock_ip_name_t lpspi_get_clock(LPSPI_Type *const base)
41+
{
42+
clock_ip_name_t clk = -1; /* invalid initial value */
43+
44+
ARRAY_FOR_EACH(lpspi_bases, idx) {
45+
if (lpspi_bases[idx] == base) {
46+
clk = lpspi_clocks[idx];
47+
break;
48+
}
49+
}
50+
51+
__ASSERT_NO_MSG(clk != -1);
52+
return clk;
53+
}
54+
#endif
55+
1356
void lpspi_wait_tx_fifo_empty(const struct device *dev)
1457
{
1558
LPSPI_Type *base = (LPSPI_Type *)DEVICE_MMIO_NAMED_GET(dev, reg_base);
@@ -141,6 +184,17 @@ int spi_mcux_configure(const struct device *dev, const struct spi_config *spi_cf
141184
return 0;
142185
}
143186

187+
static void lpspi_module_system_init(LPSPI_Type *base)
188+
{
189+
#ifdef LPSPI_CLOCKS
190+
CLOCK_EnableClock(lpspi_get_clock(base));
191+
#endif
192+
193+
#ifdef LPSPI_RSTS
194+
RESET_ReleasePeripheralReset(lpspi_get_reset(base));
195+
#endif
196+
}
197+
144198
int spi_nxp_init_common(const struct device *dev)
145199
{
146200
LPSPI_Type *base = (LPSPI_Type *)DEVICE_MMIO_NAMED_GET(dev, reg_base);
@@ -157,6 +211,8 @@ int spi_nxp_init_common(const struct device *dev)
157211
return -ENODEV;
158212
}
159213

214+
lpspi_module_system_init(base);
215+
160216
err = spi_context_cs_configure_all(&data->ctx);
161217
if (err < 0) {
162218
return err;

0 commit comments

Comments
 (0)