Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: mcux: flexio: Added generic MCUX FlexIO driver #53748

Merged
merged 5 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 0 additions & 17 deletions boards/nxp/twr_ke18f/dts/bindings/nxp,flexio.yaml

This file was deleted.

11 changes: 4 additions & 7 deletions boards/nxp/twr_ke18f/twr_ke18f.dts
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,6 @@
zephyr,code = <INPUT_KEY_1>;
};
};

flexio: flexio@4005a000 {
reg = <0x4005a000 0x1000>;
compatible = "nxp,flexio";
pinctrl-0 = <&flexio_clockout>;
pinctrl-names = "default";
};
};

&cpu0 {
Expand Down Expand Up @@ -331,6 +324,10 @@
status = "okay";
};

&flexio1 {
status = "okay";
};

&flash0 {

partitions {
Expand Down
45 changes: 45 additions & 0 deletions drivers/clock_control/clock_control_mcux_ccm.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,51 @@ static int mcux_ccm_get_subsys_rate(const struct device *dev,
case IMX_CCM_PIT_CLK:
*rate = CLOCK_GetFreq(kCLOCK_PerClk);
break;
#endif
#if DT_NODE_HAS_STATUS(DT_NODELABEL(flexio1), okay) && CONFIG_MCUX_FLEXIO
case IMX_CCM_FLEXIO1_CLK:
{
uint32_t flexio_mux = CLOCK_GetMux(kCLOCK_Flexio1Mux);
uint32_t source_clk_freq = 0;

if (flexio_mux == 0) {
source_clk_freq = CLOCK_GetPllFreq(kCLOCK_PllAudio);
} else if (flexio_mux == 1) {
source_clk_freq = CLOCK_GetUsb1PfdFreq(kCLOCK_Pfd2);
#ifdef PLL_VIDEO_OFFSET /* fsl_clock.h */
} else if (flexio_mux == 2) {
source_clk_freq = CLOCK_GetPllFreq(kCLOCK_PllVideo);
#endif
} else {
source_clk_freq = CLOCK_GetPllFreq(kCLOCK_PllUsb1);
}

*rate = source_clk_freq / (CLOCK_GetDiv(kCLOCK_Flexio1PreDiv) + 1)
/ (CLOCK_GetDiv(kCLOCK_Flexio1Div) + 1);
} break;
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the #endif here be after the case for IMX_CCM_FLEXIO2_3_CLK? Also, should we check if DT_NODE_HAS_STATUS(DT_NODELABEL(flexio1), okay) for the first case definition here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danieldegrasse, I agree that there should be a check for DT_NODE_HAS_STATUS(DT_NODELABEL(flexio1), okay), because flexio1 is not always enabled. But #endif, it seems to me better not to change it, as is done in lines 214 and 221 of the same file.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you are right- using &&CONFIG_MCUX_FLEXIO with each conditional is best here

#if (DT_NODE_HAS_STATUS(DT_NODELABEL(flexio2), okay) \
|| DT_NODE_HAS_STATUS(DT_NODELABEL(flexio3), okay)) && CONFIG_MCUX_FLEXIO
case IMX_CCM_FLEXIO2_3_CLK:
danieldegrasse marked this conversation as resolved.
Show resolved Hide resolved
{
uint32_t flexio_mux = CLOCK_GetMux(kCLOCK_Flexio2Mux);
uint32_t source_clk_freq = 0;

if (flexio_mux == 0) {
source_clk_freq = CLOCK_GetPllFreq(kCLOCK_PllAudio);
} else if (flexio_mux == 1) {
source_clk_freq = CLOCK_GetUsb1PfdFreq(kCLOCK_Pfd2);
#ifdef PLL_VIDEO_OFFSET /* fsl_clock.h */
} else if (flexio_mux == 2) {
source_clk_freq = CLOCK_GetPllFreq(kCLOCK_PllVideo);
#endif
} else {
source_clk_freq = CLOCK_GetPllFreq(kCLOCK_PllUsb1);
}

*rate = source_clk_freq / (CLOCK_GetDiv(kCLOCK_Flexio2PreDiv) + 1)
/ (CLOCK_GetDiv(kCLOCK_Flexio2Div) + 1);
} break;
#endif
}

Expand Down
1 change: 1 addition & 0 deletions drivers/misc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ add_subdirectory_ifdef(CONFIG_NXP_S32_EMIOS nxp_s32_emios)
add_subdirectory_ifdef(CONFIG_TIMEAWARE_GPIO timeaware_gpio)
add_subdirectory_ifdef(CONFIG_DEVMUX devmux)
add_subdirectory_ifdef(CONFIG_NORDIC_VPR_LAUNCHER nordic_vpr_launcher)
add_subdirectory_ifdef(CONFIG_MCUX_FLEXIO mcux_flexio)
1 change: 1 addition & 0 deletions drivers/misc/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ source "drivers/misc/nxp_s32_emios/Kconfig"
source "drivers/misc/timeaware_gpio/Kconfig"
source "drivers/misc/devmux/Kconfig"
source "drivers/misc/nordic_vpr_launcher/Kconfig"
source "drivers/misc/mcux_flexio/Kconfig"

endmenu
6 changes: 6 additions & 0 deletions drivers/misc/mcux_flexio/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright (c) 2024, STRIM, ALC
# SPDX-License-Identifier: Apache-2.0
aescolar marked this conversation as resolved.
Show resolved Hide resolved

zephyr_library()

zephyr_library_sources(mcux_flexio.c)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add zephyr_include_directories(.) to this file. That way when including the header file, we don't have to include the complete path.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that's the way to do this; the header should go in the include directory in the first place if it is intended to be a public header

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds like a better suggestion. We could move the .h file to the include folder.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will do it.

26 changes: 26 additions & 0 deletions drivers/misc/mcux_flexio/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright (c) 2024, STRIM, ALC
# SPDX-License-Identifier: Apache-2.0

config MCUX_FLEXIO
bool
depends on DT_HAS_NXP_FLEXIO_ENABLED
depends on CLOCK_CONTROL
help
Enable the FlexIO controller driver.
This driver is not user-selectable,
and should be enabled by other FlexIO drivers so
that they can use it to share the resources of the FlexIO device.

if MCUX_FLEXIO

config MCUX_FLEXIO_INIT_PRIORITY
int "FlexIO controller driver init priority"
default KERNEL_INIT_PRIORITY_DEVICE
help
MCUX FlexIO device driver initialization priority.

module = MCUX_FLEXIO
module-str = mcux_flexio
source "subsys/logging/Kconfig.template.log_config"

endif # MCUX_FLEXIO