2020-08-26 19:36:41 +08:00
|
|
|
/*
|
2022-01-08 01:36:17 +08:00
|
|
|
* Copyright (c) 2020-22, NXP
|
2020-08-26 19:36:41 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define DT_DRV_COMPAT nxp_lpc_syscon
|
|
|
|
#include <errno.h>
|
|
|
|
#include <soc.h>
|
2022-05-06 16:25:46 +08:00
|
|
|
#include <zephyr/drivers/clock_control.h>
|
|
|
|
#include <zephyr/dt-bindings/clock/mcux_lpc_syscon_clock.h>
|
2020-08-26 19:36:41 +08:00
|
|
|
#include <fsl_clock.h>
|
|
|
|
|
|
|
|
#define LOG_LEVEL CONFIG_CLOCK_CONTROL_LOG_LEVEL
|
2022-05-06 16:25:46 +08:00
|
|
|
#include <zephyr/logging/log.h>
|
2020-08-26 19:36:41 +08:00
|
|
|
LOG_MODULE_REGISTER(clock_control);
|
|
|
|
|
|
|
|
static int mcux_lpc_syscon_clock_control_on(const struct device *dev,
|
|
|
|
clock_control_subsys_t sub_system)
|
|
|
|
{
|
2021-06-01 04:13:49 +08:00
|
|
|
#if defined(CONFIG_CAN_MCUX_MCAN)
|
|
|
|
uint32_t clock_name = (uint32_t)sub_system;
|
|
|
|
|
|
|
|
if (clock_name == MCUX_MCAN_CLK) {
|
|
|
|
CLOCK_EnableClock(kCLOCK_Mcan);
|
|
|
|
}
|
|
|
|
#endif /* defined(CONFIG_CAN_MCUX_MCAN) */
|
|
|
|
|
2020-08-26 19:36:41 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mcux_lpc_syscon_clock_control_off(const struct device *dev,
|
|
|
|
clock_control_subsys_t sub_system)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mcux_lpc_syscon_clock_control_get_subsys_rate(
|
|
|
|
const struct device *dev,
|
|
|
|
clock_control_subsys_t sub_system,
|
|
|
|
uint32_t *rate)
|
|
|
|
{
|
|
|
|
uint32_t clock_name = (uint32_t) sub_system;
|
|
|
|
|
|
|
|
switch (clock_name) {
|
2022-01-08 01:36:17 +08:00
|
|
|
|
2021-06-01 04:13:49 +08:00
|
|
|
#if defined(CONFIG_I2C_MCUX_FLEXCOMM) || \
|
|
|
|
defined(CONFIG_SPI_MCUX_FLEXCOMM) || \
|
|
|
|
defined(CONFIG_UART_MCUX_FLEXCOMM)
|
2020-08-26 19:36:41 +08:00
|
|
|
case MCUX_FLEXCOMM0_CLK:
|
|
|
|
*rate = CLOCK_GetFlexCommClkFreq(0);
|
|
|
|
break;
|
|
|
|
case MCUX_FLEXCOMM1_CLK:
|
|
|
|
*rate = CLOCK_GetFlexCommClkFreq(1);
|
|
|
|
break;
|
|
|
|
case MCUX_FLEXCOMM2_CLK:
|
|
|
|
*rate = CLOCK_GetFlexCommClkFreq(2);
|
|
|
|
break;
|
|
|
|
case MCUX_FLEXCOMM3_CLK:
|
|
|
|
*rate = CLOCK_GetFlexCommClkFreq(3);
|
|
|
|
break;
|
|
|
|
case MCUX_FLEXCOMM4_CLK:
|
|
|
|
*rate = CLOCK_GetFlexCommClkFreq(4);
|
|
|
|
break;
|
|
|
|
case MCUX_FLEXCOMM5_CLK:
|
|
|
|
*rate = CLOCK_GetFlexCommClkFreq(5);
|
|
|
|
break;
|
|
|
|
case MCUX_FLEXCOMM6_CLK:
|
|
|
|
*rate = CLOCK_GetFlexCommClkFreq(6);
|
|
|
|
break;
|
|
|
|
case MCUX_FLEXCOMM7_CLK:
|
|
|
|
*rate = CLOCK_GetFlexCommClkFreq(7);
|
|
|
|
break;
|
2022-01-08 01:36:17 +08:00
|
|
|
case MCUX_FLEXCOMM8_CLK:
|
|
|
|
*rate = CLOCK_GetFlexCommClkFreq(8);
|
|
|
|
break;
|
|
|
|
case MCUX_FLEXCOMM9_CLK:
|
|
|
|
*rate = CLOCK_GetFlexCommClkFreq(9);
|
|
|
|
break;
|
|
|
|
case MCUX_FLEXCOMM10_CLK:
|
|
|
|
*rate = CLOCK_GetFlexCommClkFreq(10);
|
|
|
|
break;
|
|
|
|
case MCUX_FLEXCOMM11_CLK:
|
|
|
|
*rate = CLOCK_GetFlexCommClkFreq(11);
|
|
|
|
break;
|
|
|
|
case MCUX_FLEXCOMM12_CLK:
|
|
|
|
*rate = CLOCK_GetFlexCommClkFreq(12);
|
|
|
|
break;
|
|
|
|
case MCUX_FLEXCOMM13_CLK:
|
|
|
|
*rate = CLOCK_GetFlexCommClkFreq(13);
|
|
|
|
break;
|
2021-09-22 03:12:23 +08:00
|
|
|
case MCUX_PMIC_I2C_CLK:
|
|
|
|
*rate = CLOCK_GetFlexCommClkFreq(15);
|
|
|
|
break;
|
2020-08-26 19:36:41 +08:00
|
|
|
case MCUX_HS_SPI_CLK:
|
2022-01-08 01:36:17 +08:00
|
|
|
#if defined(SYSCON_HSLSPICLKSEL_SEL_MASK)
|
2020-08-26 19:36:41 +08:00
|
|
|
*rate = CLOCK_GetHsLspiClkFreq();
|
|
|
|
#else
|
2022-01-08 01:36:17 +08:00
|
|
|
*rate = CLOCK_GetFlexCommClkFreq(14);
|
2020-08-26 19:36:41 +08:00
|
|
|
#endif
|
2022-05-16 16:23:23 +08:00
|
|
|
case MCUX_HS_SPI1_CLK:
|
|
|
|
*rate = CLOCK_GetFlexCommClkFreq(16);
|
2020-08-26 19:36:41 +08:00
|
|
|
break;
|
2022-01-08 01:36:17 +08:00
|
|
|
#endif
|
|
|
|
|
2021-07-28 04:46:22 +08:00
|
|
|
#if (defined(FSL_FEATURE_SOC_USDHC_COUNT) && FSL_FEATURE_SOC_USDHC_COUNT)
|
|
|
|
case MCUX_USDHC1_CLK:
|
|
|
|
*rate = CLOCK_GetSdioClkFreq(0);
|
|
|
|
break;
|
|
|
|
case MCUX_USDHC2_CLK:
|
|
|
|
*rate = CLOCK_GetSdioClkFreq(1);
|
|
|
|
break;
|
2021-08-11 00:04:20 +08:00
|
|
|
#endif
|
2022-01-08 01:36:17 +08:00
|
|
|
|
2021-06-01 04:13:49 +08:00
|
|
|
#if defined(CONFIG_CAN_MCUX_MCAN)
|
|
|
|
case MCUX_MCAN_CLK:
|
|
|
|
*rate = CLOCK_GetMCanClkFreq();
|
|
|
|
break;
|
|
|
|
#endif /* defined(CONFIG_CAN_MCUX_MCAN) */
|
2022-01-08 01:36:17 +08:00
|
|
|
|
2021-08-11 00:04:20 +08:00
|
|
|
#if defined(CONFIG_COUNTER_MCUX_CTIMER)
|
|
|
|
case (MCUX_CTIMER0_CLK + MCUX_CTIMER_CLK_OFFSET):
|
|
|
|
*rate = CLOCK_GetCTimerClkFreq(0);
|
|
|
|
break;
|
|
|
|
case (MCUX_CTIMER1_CLK + MCUX_CTIMER_CLK_OFFSET):
|
|
|
|
*rate = CLOCK_GetCTimerClkFreq(1);
|
|
|
|
break;
|
|
|
|
case (MCUX_CTIMER2_CLK + MCUX_CTIMER_CLK_OFFSET):
|
|
|
|
*rate = CLOCK_GetCTimerClkFreq(2);
|
|
|
|
break;
|
|
|
|
case (MCUX_CTIMER3_CLK + MCUX_CTIMER_CLK_OFFSET):
|
|
|
|
*rate = CLOCK_GetCTimerClkFreq(3);
|
|
|
|
break;
|
|
|
|
case (MCUX_CTIMER4_CLK + MCUX_CTIMER_CLK_OFFSET):
|
|
|
|
*rate = CLOCK_GetCTimerClkFreq(4);
|
|
|
|
break;
|
2021-07-28 04:46:22 +08:00
|
|
|
#endif
|
2022-03-09 02:22:17 +08:00
|
|
|
|
|
|
|
case MCUX_BUS_CLK:
|
|
|
|
*rate = CLOCK_GetFreq(kCLOCK_BusClk);
|
|
|
|
break;
|
2020-08-26 19:36:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mcux_lpc_syscon_clock_control_init(const struct device *dev)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct clock_control_driver_api mcux_lpc_syscon_api = {
|
|
|
|
.on = mcux_lpc_syscon_clock_control_on,
|
|
|
|
.off = mcux_lpc_syscon_clock_control_off,
|
|
|
|
.get_rate = mcux_lpc_syscon_clock_control_get_subsys_rate,
|
|
|
|
};
|
|
|
|
|
|
|
|
#define LPC_CLOCK_INIT(n) \
|
|
|
|
\
|
2020-12-16 02:20:28 +08:00
|
|
|
DEVICE_DT_INST_DEFINE(n, \
|
2020-08-26 19:36:41 +08:00
|
|
|
&mcux_lpc_syscon_clock_control_init, \
|
2021-04-28 16:19:07 +08:00
|
|
|
NULL, \
|
2020-08-26 19:36:41 +08:00
|
|
|
NULL, NULL, \
|
2021-10-19 03:45:17 +08:00
|
|
|
PRE_KERNEL_1, CONFIG_CLOCK_CONTROL_INIT_PRIORITY, \
|
2020-08-26 19:36:41 +08:00
|
|
|
&mcux_lpc_syscon_api);
|
|
|
|
|
|
|
|
DT_INST_FOREACH_STATUS_OKAY(LPC_CLOCK_INIT)
|