From 0e3872357166d91db8a4444979fd6a2698a5eb40 Mon Sep 17 00:00:00 2001 From: Neil Chen Date: Wed, 4 Dec 2024 16:35:25 +0800 Subject: [PATCH 1/4] drivers: syscon: update syscon driver to add lpi2c clock Add lpi2c clock support Signed-off-by: Neil Chen --- drivers/clock_control/clock_control_mcux_syscon.c | 15 +++++++++++++++ .../dt-bindings/clock/mcux_lpc_syscon_clock.h | 5 +++++ 2 files changed, 20 insertions(+) diff --git a/drivers/clock_control/clock_control_mcux_syscon.c b/drivers/clock_control/clock_control_mcux_syscon.c index 8f36225cb81d07..a09e22ee4e3a16 100644 --- a/drivers/clock_control/clock_control_mcux_syscon.c +++ b/drivers/clock_control/clock_control_mcux_syscon.c @@ -428,6 +428,21 @@ static int mcux_lpc_syscon_clock_control_get_subsys_rate(const struct device *de *rate = CLOCK_GetLpuartClkFreq(4); break; #endif /* defined(CONFIG_UART_MCUX_LPUART) */ + +#if (defined(CONFIG_I2C_MCUX_LPI2C) && CONFIG_SOC_SERIES_MCXA) + case MCUX_LPI2C0_CLK: + *rate = CLOCK_GetLpi2cClkFreq(0); + break; + case MCUX_LPI2C1_CLK: + *rate = CLOCK_GetLpi2cClkFreq(1); + break; + case MCUX_LPI2C2_CLK: + *rate = CLOCK_GetLpi2cClkFreq(2); + break; + case MCUX_LPI2C3_CLK: + *rate = CLOCK_GetLpi2cClkFreq(3); + break; +#endif /* defined(CONFIG_I2C_MCUX_LPI2C) */ } return 0; diff --git a/include/zephyr/dt-bindings/clock/mcux_lpc_syscon_clock.h b/include/zephyr/dt-bindings/clock/mcux_lpc_syscon_clock.h index c26735174880b9..77b5741b23d10b 100644 --- a/include/zephyr/dt-bindings/clock/mcux_lpc_syscon_clock.h +++ b/include/zephyr/dt-bindings/clock/mcux_lpc_syscon_clock.h @@ -98,4 +98,9 @@ #define MCUX_LPUART3_CLK MCUX_LPC_CLK_ID(0x13, 0x03) #define MCUX_LPUART4_CLK MCUX_LPC_CLK_ID(0x13, 0x04) +#define MCUX_LPI2C0_CLK MCUX_LPC_CLK_ID(0x14, 0x00) +#define MCUX_LPI2C1_CLK MCUX_LPC_CLK_ID(0x14, 0x01) +#define MCUX_LPI2C2_CLK MCUX_LPC_CLK_ID(0x14, 0x02) +#define MCUX_LPI2C3_CLK MCUX_LPC_CLK_ID(0x14, 0x03) + #endif /* ZEPHYR_INCLUDE_DT_BINDINGS_CLOCK_MCUX_LPC_SYSCON_H_ */ From 366db61972df6f67e2bb4cb8c7a7699b10507eff Mon Sep 17 00:00:00 2001 From: Neil Chen Date: Wed, 11 Dec 2024 16:29:16 +0800 Subject: [PATCH 2/4] dts: arm/nxp: Add lpi2c nodes to NXP MCXA156 dtsi file Add lpi2c nodes to NXP MCXA156 dtsi file Signed-off-by: Neil Chen --- dts/arm/nxp/nxp_mcxa156.dtsi | 45 ++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/dts/arm/nxp/nxp_mcxa156.dtsi b/dts/arm/nxp/nxp_mcxa156.dtsi index 0aa4ed2cb52add..29e6c55cf8d5e9 100644 --- a/dts/arm/nxp/nxp_mcxa156.dtsi +++ b/dts/arm/nxp/nxp_mcxa156.dtsi @@ -8,6 +8,7 @@ #include #include #include +#include / { cpus { @@ -286,6 +287,50 @@ #io-channel-cells = <2>; }; + lpi2c0: i2c@4009a000 { + compatible = "nxp,lpi2c"; + clock-frequency = ; + #address-cells = <1>; + #size-cells = <0>; + reg = <0x4009a000 0x1000>; + interrupts = <26 0>; + clocks = <&syscon MCUX_LPI2C0_CLK>; + status = "disabled"; + }; + + lpi2c1: i2c@4009b000 { + compatible = "nxp,lpi2c"; + clock-frequency = ; + #address-cells = <1>; + #size-cells = <0>; + reg = <0x4009b000 0x1000>; + interrupts = <27 0>; + clocks = <&syscon MCUX_LPI2C1_CLK>; + status = "disabled"; + }; + + lpi2c2: i2c@400d4000 { + compatible = "nxp,lpi2c"; + clock-frequency = ; + #address-cells = <1>; + #size-cells = <0>; + reg = <0x400d4000 0x1000>; + interrupts = <77 0>; + clocks = <&syscon MCUX_LPI2C2_CLK>; + status = "disabled"; + }; + + lpi2c3: i2c@400d5000 { + compatible = "nxp,lpi2c"; + clock-frequency = ; + #address-cells = <1>; + #size-cells = <0>; + reg = <0x400d5000 0x1000>; + interrupts = <78 0>; + clocks = <&syscon MCUX_LPI2C3_CLK>; + status = "disabled"; + }; + lptmr0: lptmr@400ab000 { compatible = "nxp,lptmr"; reg = <0x400ab000 0x1000>; From ed38264e967741d4e8f0f8cd34f57fc54a44323c Mon Sep 17 00:00:00 2001 From: Neil Chen Date: Wed, 11 Dec 2024 16:32:01 +0800 Subject: [PATCH 3/4] boards: nxp: frdm_mcxa156: Support lpi2c for NXP frdm_mcxa156 board Support lpi2c for NXP frdm_mcxa156 board. Signed-off-by: Neil Chen --- boards/nxp/frdm_mcxa156/board.c | 20 +++++++++++ boards/nxp/frdm_mcxa156/doc/index.rst | 2 ++ .../frdm_mcxa156/frdm_mcxa156-pinctrl.dtsi | 33 +++++++++++++++++++ boards/nxp/frdm_mcxa156/frdm_mcxa156.dts | 12 +++++++ boards/nxp/frdm_mcxa156/frdm_mcxa156.yaml | 1 + 5 files changed, 68 insertions(+) diff --git a/boards/nxp/frdm_mcxa156/board.c b/boards/nxp/frdm_mcxa156/board.c index 648d017592229f..9dd88d1f213549 100644 --- a/boards/nxp/frdm_mcxa156/board.c +++ b/boards/nxp/frdm_mcxa156/board.c @@ -137,6 +137,26 @@ static int frdm_mcxa156_init(void) SPC_EnableActiveModeAnalogModules(SPC0, (kSPC_controlCmp0 | kSPC_controlCmp0Dac)); #endif +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lpi2c0)) + CLOCK_SetClockDiv(kCLOCK_DivLPI2C0, 1u); + CLOCK_AttachClk(kFRO12M_to_LPI2C0); +#endif + +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lpi2c1)) + CLOCK_SetClockDiv(kCLOCK_DivLPI2C1, 1u); + CLOCK_AttachClk(kFRO12M_to_LPI2C1); +#endif + +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lpi2c2)) + CLOCK_SetClockDiv(kCLOCK_DivLPI2C2, 1u); + CLOCK_AttachClk(kFRO12M_to_LPI2C2); +#endif + +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lpi2c3)) + CLOCK_SetClockDiv(kCLOCK_DivLPI2C3, 1u); + CLOCK_AttachClk(kFRO12M_to_LPI2C3); +#endif + #if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lptmr0)) /* diff --git a/boards/nxp/frdm_mcxa156/doc/index.rst b/boards/nxp/frdm_mcxa156/doc/index.rst index 0ee1c41ef77a77..c61042e3a7f9b4 100644 --- a/boards/nxp/frdm_mcxa156/doc/index.rst +++ b/boards/nxp/frdm_mcxa156/doc/index.rst @@ -58,6 +58,8 @@ The FRDM-MCXA156 board configuration supports the following hardware features: +-----------+------------+-------------------------------------+ | DAC | on-chip | dac | +-----------+------------+-------------------------------------+ +| I2C | on-chip | i2c | ++-----------+------------+-------------------------------------+ | LPCMP | on-chip | sensor(comparator) | +-----------+------------+-------------------------------------+ | LPTMR | on-chip | counter | diff --git a/boards/nxp/frdm_mcxa156/frdm_mcxa156-pinctrl.dtsi b/boards/nxp/frdm_mcxa156/frdm_mcxa156-pinctrl.dtsi index b5ad9fc2856a63..e231ae7edafd92 100644 --- a/boards/nxp/frdm_mcxa156/frdm_mcxa156-pinctrl.dtsi +++ b/boards/nxp/frdm_mcxa156/frdm_mcxa156-pinctrl.dtsi @@ -47,4 +47,37 @@ bias-pull-up; }; }; + pinmux_lpi2c0: pinmux_lpi2c0 { + group0 { + pinmux = , + ; + slew-rate = "fast"; + drive-strength = "low"; + input-enable; + bias-pull-up; + drive-open-drain; + }; + }; + pinmux_lpi2c2: pinmux_lpi2c2 { + group0 { + pinmux = , + ; + slew-rate = "fast"; + drive-strength = "low"; + input-enable; + bias-pull-up; + drive-open-drain; + }; + }; + pinmux_lpi2c3: pinmux_lpi2c3 { + group0 { + pinmux = , + ; + slew-rate = "fast"; + drive-strength = "low"; + input-enable; + bias-pull-up; + drive-open-drain; + }; + }; }; diff --git a/boards/nxp/frdm_mcxa156/frdm_mcxa156.dts b/boards/nxp/frdm_mcxa156/frdm_mcxa156.dts index 2e6160c59fd82d..b8447ac9aeacc5 100644 --- a/boards/nxp/frdm_mcxa156/frdm_mcxa156.dts +++ b/boards/nxp/frdm_mcxa156/frdm_mcxa156.dts @@ -114,6 +114,18 @@ pinctrl-names = "default"; }; +&lpi2c0 { + status = "okay"; + pinctrl-0 = <&pinmux_lpi2c0>; + pinctrl-names = "default"; +}; + +&lpi2c3 { + status = "okay"; + pinctrl-0 = <&pinmux_lpi2c3>; + pinctrl-names = "default"; +}; + &lptmr0 { status = "okay"; }; diff --git a/boards/nxp/frdm_mcxa156/frdm_mcxa156.yaml b/boards/nxp/frdm_mcxa156/frdm_mcxa156.yaml index edbe6c4a32a4d2..2da4c738309d78 100644 --- a/boards/nxp/frdm_mcxa156/frdm_mcxa156.yaml +++ b/boards/nxp/frdm_mcxa156/frdm_mcxa156.yaml @@ -20,5 +20,6 @@ supported: - gpio - counter - dac + - i2c - pwm vendor: nxp From 494d85f3a23d7cf654e522f14472385ade258c9e Mon Sep 17 00:00:00 2001 From: Neil Chen Date: Wed, 4 Dec 2024 16:39:39 +0800 Subject: [PATCH 4/4] tests: drivers: i2c: add i2c test support for frdm_mcxa156 board add i2c test support for frdm_mcxa156 board Signed-off-by: Neil Chen --- .../boards/frdm_mcxa156.overlay | 26 +++++++++++++++++++ .../drivers/i2c/i2c_target_api/testcase.yaml | 1 + 2 files changed, 27 insertions(+) create mode 100644 tests/drivers/i2c/i2c_target_api/boards/frdm_mcxa156.overlay diff --git a/tests/drivers/i2c/i2c_target_api/boards/frdm_mcxa156.overlay b/tests/drivers/i2c/i2c_target_api/boards/frdm_mcxa156.overlay new file mode 100644 index 00000000000000..d82f84ab3de3e9 --- /dev/null +++ b/tests/drivers/i2c/i2c_target_api/boards/frdm_mcxa156.overlay @@ -0,0 +1,26 @@ +/* + * Copyright 2024 NXP + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/* To test this sample, connect + * LPI2C0 SCL(J2-20) --> LPI2C3 SCL(J5-5) + * LPI2C0 SDA(J2-18) --> LPI2C3 SDA(J5-6) + */ + +&lpi2c0 { + eeprom0: eeprom@54 { + compatible = "zephyr,i2c-target-eeprom"; + reg = <0x54>; + size = <256>; + }; +}; + +&lpi2c3 { + eeprom1: eeprom@56 { + compatible = "zephyr,i2c-target-eeprom"; + reg = <0x56>; + size = <256>; + }; +}; diff --git a/tests/drivers/i2c/i2c_target_api/testcase.yaml b/tests/drivers/i2c/i2c_target_api/testcase.yaml index bf931f8a08d1d2..d57b121582acbb 100644 --- a/tests/drivers/i2c/i2c_target_api/testcase.yaml +++ b/tests/drivers/i2c/i2c_target_api/testcase.yaml @@ -45,6 +45,7 @@ tests: - mimxrt1060_evk - frdm_ke17z512 - frdm_mcxn236 + - frdm_mcxa156 - max32655evkit/max32655/m4 - max32662evkit - max32666evkit/max32666/cpu0