Skip to content

Commit 2f678bd

Browse files
decsnykartben
authored andcommitted
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 e11634e commit 2f678bd

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
@@ -9,6 +9,49 @@ LOG_MODULE_REGISTER(spi_mcux_lpspi_common, CONFIG_SPI_LOG_LEVEL);
99

1010
#include "spi_nxp_lpspi_priv.h"
1111

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

174+
static void lpspi_module_system_init(LPSPI_Type *base)
175+
{
176+
#ifdef LPSPI_CLOCKS
177+
CLOCK_EnableClock(lpspi_get_clock(base));
178+
#endif
179+
180+
#ifdef LPSPI_RSTS
181+
RESET_ReleasePeripheralReset(lpspi_get_reset(base));
182+
#endif
183+
}
184+
131185
int spi_nxp_init_common(const struct device *dev)
132186
{
133187
LPSPI_Type *base = (LPSPI_Type *)DEVICE_MMIO_NAMED_GET(dev, reg_base);
@@ -144,6 +198,8 @@ int spi_nxp_init_common(const struct device *dev)
144198
return -ENODEV;
145199
}
146200

201+
lpspi_module_system_init(base);
202+
147203
err = spi_context_cs_configure_all(&data->ctx);
148204
if (err < 0) {
149205
return err;

0 commit comments

Comments
 (0)