diff --git a/drivers/clock_control/CMakeLists.txt b/drivers/clock_control/CMakeLists.txt index 5052cb642bb..b4230c932ac 100644 --- a/drivers/clock_control/CMakeLists.txt +++ b/drivers/clock_control/CMakeLists.txt @@ -1,4 +1,5 @@ zephyr_sources_ifdef(CONFIG_CLOCK_CONTROL_BEETLE beetle_clock_control.c) +zephyr_sources_ifdef(CONFIG_CLOCK_CONTROL_MCUX_CCM clock_control_mcux_ccm.c) zephyr_sources_ifdef(CONFIG_CLOCK_CONTROL_MCUX_SIM clock_control_mcux_sim.c) zephyr_sources_ifdef(CONFIG_CLOCK_CONTROL_NRF5 nrf5_power_clock.c) zephyr_sources_ifdef(CONFIG_CLOCK_CONTROL_QUARK_SE quark_se_clock_control.c) diff --git a/drivers/clock_control/Kconfig b/drivers/clock_control/Kconfig index ac191d7be94..3a1fb3fc286 100644 --- a/drivers/clock_control/Kconfig +++ b/drivers/clock_control/Kconfig @@ -49,6 +49,8 @@ source "drivers/clock_control/Kconfig.stm32" source "drivers/clock_control/Kconfig.beetle" +source "drivers/clock_control/Kconfig.mcux_ccm" + source "drivers/clock_control/Kconfig.mcux_sim" endif # CLOCK_CONTROL diff --git a/drivers/clock_control/Kconfig.mcux_ccm b/drivers/clock_control/Kconfig.mcux_ccm new file mode 100644 index 00000000000..98db052fe12 --- /dev/null +++ b/drivers/clock_control/Kconfig.mcux_ccm @@ -0,0 +1,14 @@ +# Kconfig - MCUXpresso SDK CCM +# +# Copyright (c) 2017, NXP +# +# SPDX-License-Identifier: Apache-2.0 +# + +menuconfig CLOCK_CONTROL_MCUX_CCM + bool + prompt "MCUX CCM driver" + depends on HAS_MCUX_CCM + default n + help + Enable support for mcux ccm driver. diff --git a/drivers/clock_control/clock_control_mcux_ccm.c b/drivers/clock_control/clock_control_mcux_ccm.c new file mode 100644 index 00000000000..fccb151b68b --- /dev/null +++ b/drivers/clock_control/clock_control_mcux_ccm.c @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2017, NXP + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include +#include +#include +#include +#include + +#define SYS_LOG_LEVEL CONFIG_SYS_LOG_CLOCK_CONTROL_LEVEL +#include + +static int mcux_ccm_on(struct device *dev, + clock_control_subsys_t sub_system) +{ + return 0; +} + +static int mcux_ccm_off(struct device *dev, + clock_control_subsys_t sub_system) +{ + return 0; +} + +static int mcux_ccm_get_subsys_rate(struct device *dev, + clock_control_subsys_t sub_system, + u32_t *rate) +{ + u32_t clock_name = (u32_t) sub_system; + + switch (clock_name) { + case IMX_CCM_LPUART_CLK: + if (CLOCK_GetMux(kCLOCK_UartMux) == 0) { + *rate = CLOCK_GetPllFreq(kCLOCK_PllUsb1) / 6 + / (CLOCK_GetDiv(kCLOCK_UartDiv) + 1); + } else { + *rate = CLOCK_GetOscFreq() + / (CLOCK_GetDiv(kCLOCK_UartDiv) + 1); + } + + break; + } + + return 0; +} + +static int mcux_ccm_init(struct device *dev) +{ + return 0; +} + +static const struct clock_control_driver_api mcux_ccm_driver_api = { + .on = mcux_ccm_on, + .off = mcux_ccm_off, + .get_rate = mcux_ccm_get_subsys_rate, +}; + +DEVICE_AND_API_INIT(mcux_ccm, CONFIG_MCUX_CCM_NAME, + &mcux_ccm_init, + NULL, NULL, + PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, + &mcux_ccm_driver_api); diff --git a/dts/bindings/clock/nxp,imx-ccm.yaml b/dts/bindings/clock/nxp,imx-ccm.yaml new file mode 100644 index 00000000000..c255f335956 --- /dev/null +++ b/dts/bindings/clock/nxp,imx-ccm.yaml @@ -0,0 +1,39 @@ +# +# Copyright (c) 2017, NXP +# +# SPDX-License-Identifier: Apache-2.0 +# +--- +title: i.MX Clock Controller Module (CCM) +id: nxp,imx-ccm +version: 0.1 + +description: > + This is a representation of the i.MX CCM IP node + +properties: + - compatible: + type: string + category: required + description: compatible strings + constraint: "nxp,imx-ccm" + + - reg: + type: int + description: mmio register space + generation: define + category: required + + - label: + type: string + category: required + description: Human readable string describing the device (used by Zephyr for API name) + generation: define + +cell_string: CCM_CLK + +"#cells": + - name + - offset + - bits +... diff --git a/ext/hal/nxp/mcux/Kconfig b/ext/hal/nxp/mcux/Kconfig index a7c0ba83698..aa56bd891fb 100644 --- a/ext/hal/nxp/mcux/Kconfig +++ b/ext/hal/nxp/mcux/Kconfig @@ -18,6 +18,12 @@ config HAS_MCUX_ADC16 help Set if the 16-bit ADC (ADC16) module is present in the SoC. +config HAS_MCUX_CCM + bool + default n + help + Set if the clock control module (CCM) module is present in the SoC. + config HAS_MCUX_FTM bool default n diff --git a/include/dt-bindings/clock/imx_ccm.h b/include/dt-bindings/clock/imx_ccm.h new file mode 100644 index 00000000000..82668ed3cf3 --- /dev/null +++ b/include/dt-bindings/clock/imx_ccm.h @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2017, NXP + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef __IMX_CCM_H +#define __IMX_CCM_H + +#define IMX_CCM_CORESYS_CLK 0 +#define IMX_CCM_PLATFORM_CLK 1 +#define IMX_CCM_BUS_CLK 2 +#define IMX_CCM_LPUART_CLK 3 +#define IMX_CCM_LPI2C_CLK 4 + +#endif /* __IMX_CCM_H */