2019-05-20 05:39:32 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2019 Vestas Wind Systems A/S
|
|
|
|
*
|
|
|
|
* Based on clock_control_mcux_sim.c, which is:
|
|
|
|
* Copyright (c) 2017, NXP
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2020-03-25 03:11:52 +08:00
|
|
|
#define DT_DRV_COMPAT nxp_kinetis_mcg
|
|
|
|
|
2019-05-20 05:39:32 +08:00
|
|
|
#include <drivers/clock_control.h>
|
|
|
|
#include <dt-bindings/clock/kinetis_mcg.h>
|
|
|
|
#include <soc.h>
|
|
|
|
#include <fsl_clock.h>
|
|
|
|
|
|
|
|
#define LOG_LEVEL CONFIG_CLOCK_CONTROL_LOG_LEVEL
|
|
|
|
#include <logging/log.h>
|
|
|
|
LOG_MODULE_REGISTER(clock_control_mcg);
|
|
|
|
|
2020-05-01 02:33:38 +08:00
|
|
|
static int mcux_mcg_on(const struct device *dev,
|
|
|
|
clock_control_subsys_t sub_system)
|
2019-05-20 05:39:32 +08:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-01 02:33:38 +08:00
|
|
|
static int mcux_mcg_off(const struct device *dev,
|
|
|
|
clock_control_subsys_t sub_system)
|
2019-05-20 05:39:32 +08:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-01 02:33:38 +08:00
|
|
|
static int mcux_mcg_get_rate(const struct device *dev,
|
2019-05-20 05:39:32 +08:00
|
|
|
clock_control_subsys_t sub_system,
|
2020-05-28 00:26:57 +08:00
|
|
|
uint32_t *rate)
|
2019-05-20 05:39:32 +08:00
|
|
|
{
|
|
|
|
clock_name_t clock_name;
|
|
|
|
|
2020-05-28 00:26:57 +08:00
|
|
|
switch ((uint32_t) sub_system) {
|
2019-05-20 05:39:32 +08:00
|
|
|
case KINETIS_MCG_FIXED_FREQ_CLK:
|
|
|
|
clock_name = kCLOCK_McgFixedFreqClk;
|
|
|
|
break;
|
2021-03-04 17:36:57 +08:00
|
|
|
case KINETIS_MCG_OUT_CLK:
|
|
|
|
*rate = CLOCK_GetOutClkFreq();
|
|
|
|
return 0;
|
2019-05-20 05:39:32 +08:00
|
|
|
default:
|
|
|
|
LOG_ERR("Unsupported clock name");
|
|
|
|
return -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
*rate = CLOCK_GetFreq(clock_name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-01 02:33:38 +08:00
|
|
|
static int mcux_mcg_init(const struct device *dev)
|
2019-05-20 05:39:32 +08:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct clock_control_driver_api mcux_mcg_driver_api = {
|
|
|
|
.on = mcux_mcg_on,
|
|
|
|
.off = mcux_mcg_off,
|
|
|
|
.get_rate = mcux_mcg_get_rate,
|
|
|
|
};
|
|
|
|
|
2020-12-16 02:20:28 +08:00
|
|
|
DEVICE_DT_INST_DEFINE(0,
|
2019-05-20 05:39:32 +08:00
|
|
|
&mcux_mcg_init,
|
2020-12-16 02:20:28 +08:00
|
|
|
device_pm_control_nop,
|
2019-05-20 05:39:32 +08:00
|
|
|
NULL, NULL,
|
|
|
|
PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEVICE,
|
|
|
|
&mcux_mcg_driver_api);
|