diff --git a/boards/arm/npcx7m6fb_evb/npcx7m6fb_evb-pinctrl.dtsi b/boards/arm/npcx7m6fb_evb/npcx7m6fb_evb-pinctrl.dtsi new file mode 100644 index 00000000000..94636234dd0 --- /dev/null +++ b/boards/arm/npcx7m6fb_evb/npcx7m6fb_evb-pinctrl.dtsi @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2022 Nuvoton Technology Corporation. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +&i2c0_0_sda_scl_gpb4_b5 { + bias-pull-up; /* Enable internal pull-up for i2c0_0 */ + pinmux-locked; /* Lock pinmuxing */ +}; diff --git a/boards/arm/npcx7m6fb_evb/npcx7m6fb_evb.dts b/boards/arm/npcx7m6fb_evb/npcx7m6fb_evb.dts index ca2eb8c3fa7..95782266391 100644 --- a/boards/arm/npcx7m6fb_evb/npcx7m6fb_evb.dts +++ b/boards/arm/npcx7m6fb_evb/npcx7m6fb_evb.dts @@ -7,7 +7,7 @@ /dts-v1/; #include -#include +#include "npcx7m6fb_evb-pinctrl.dtsi" / { model = "Nuvoton NPCX7M6FB evaluation board"; @@ -91,6 +91,8 @@ &i2c0_0 { status = "okay"; + pinctrl-0 = <&i2c0_0_sda_scl_gpb4_b5>; + pinctrl-names = "default"; clock-frequency = ; }; diff --git a/boards/arm/npcx9m6f_evb/npcx9m6f_evb-pinctrl.dtsi b/boards/arm/npcx9m6f_evb/npcx9m6f_evb-pinctrl.dtsi new file mode 100644 index 00000000000..33a315ef2a3 --- /dev/null +++ b/boards/arm/npcx9m6f_evb/npcx9m6f_evb-pinctrl.dtsi @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2022 Nuvoton Technology Corporation. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +&i2c0_0_sda_scl_gpb4_b5 { + bias-pull-up; /* Enable internal pull-up for i2c0_0 */ + pinmux-locked; /* Lock pinmuxing */ +}; diff --git a/boards/arm/npcx9m6f_evb/npcx9m6f_evb.dts b/boards/arm/npcx9m6f_evb/npcx9m6f_evb.dts index 871eee84fa9..97fd8fc5c42 100644 --- a/boards/arm/npcx9m6f_evb/npcx9m6f_evb.dts +++ b/boards/arm/npcx9m6f_evb/npcx9m6f_evb.dts @@ -7,7 +7,7 @@ /dts-v1/; #include -#include +#include "npcx9m6f_evb-pinctrl.dtsi" / { model = "Nuvoton NPCX9M6F evaluation board"; @@ -104,6 +104,8 @@ &i2c0_0 { status = "okay"; + pinctrl-0 = <&i2c0_0_sda_scl_gpb4_b5>; + pinctrl-names = "default"; clock-frequency = ; }; diff --git a/drivers/i2c/i2c_npcx_port.c b/drivers/i2c/i2c_npcx_port.c index 1164cea00c7..b458e36d081 100644 --- a/drivers/i2c/i2c_npcx_port.c +++ b/drivers/i2c/i2c_npcx_port.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -42,12 +43,11 @@ LOG_MODULE_REGISTER(i2c_npcx_port, LOG_LEVEL_ERR); /* Device config */ struct i2c_npcx_port_config { - /* pinmux configuration */ - const uint8_t alts_size; - const struct npcx_alt *alts_list; uint32_t bitrate; uint8_t port; const struct device *i2c_ctrl; + /* pinmux configuration */ + const struct pinctrl_dev_config *pcfg; }; /* I2C api functions */ @@ -131,7 +131,12 @@ static int i2c_npcx_port_init(const struct device *dev) int ret; /* Configure pin-mux for I2C device */ - npcx_pinctrl_mux_configure(config->alts_list, config->alts_size, 1); + ret = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT); + if (ret < 0) { + LOG_ERR("I2C pinctrl setup failed (%d)", ret); + return ret; + } + /* Setup initial i2c configuration */ i2c_config = (I2C_MODE_MASTER | i2c_map_dt_bitrate(config->bitrate)); @@ -151,15 +156,13 @@ static const struct i2c_driver_api i2c_port_npcx_driver_api = { /* I2C port init macro functions */ #define NPCX_I2C_PORT_INIT(inst) \ - static const struct npcx_alt i2c_port_alts##inst[] = \ - NPCX_DT_ALT_ITEMS_LIST(inst); \ + PINCTRL_DT_INST_DEFINE(inst); \ \ static const struct i2c_npcx_port_config i2c_npcx_port_cfg_##inst = { \ .port = DT_INST_PROP(inst, port), \ .bitrate = DT_INST_PROP(inst, clock_frequency), \ - .alts_size = ARRAY_SIZE(i2c_port_alts##inst), \ - .alts_list = i2c_port_alts##inst, \ .i2c_ctrl = DEVICE_DT_GET(DT_INST_PHANDLE(inst, controller)), \ + .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \ }; \ \ DEVICE_DT_INST_DEFINE(inst, \ diff --git a/dts/arm/nuvoton/npcx.dtsi b/dts/arm/nuvoton/npcx.dtsi index 19b2674e347..5051ac3dc6f 100644 --- a/dts/arm/nuvoton/npcx.dtsi +++ b/dts/arm/nuvoton/npcx.dtsi @@ -609,7 +609,6 @@ #size-cells = <0>; port = <0x00>; controller = <&i2c_ctrl0>; - pinctrl-0 = <&alt2_i2c0_0_sl>; /* PINB5.B4 */ label = "I2C_0_PORT_0"; status = "disabled"; }; @@ -620,7 +619,6 @@ #size-cells = <0>; port = <0x10>; controller = <&i2c_ctrl1>; - pinctrl-0 = <&alt2_i2c1_0_sl>; /* PIN90.87 */ label = "I2C_1_PORT_0"; status = "disabled"; }; @@ -631,7 +629,6 @@ #size-cells = <0>; port = <0x20>; controller = <&i2c_ctrl2>; - pinctrl-0 = <&alt2_i2c2_0_sl>; /* PIN92.91 */ label = "I2C_2_PORT_0"; status = "disabled"; }; @@ -642,7 +639,6 @@ #size-cells = <0>; port = <0x30>; controller = <&i2c_ctrl3>; - pinctrl-0 = <&alt2_i2c3_0_sl>; /* PIND1.D0 */ label = "I2C_3_PORT_0"; status = "disabled"; }; @@ -653,7 +649,6 @@ #size-cells = <0>; port = <0x41>; controller = <&i2c_ctrl4>; - pinctrl-0 = <&alt6_i2c4_1_sl>; /* PINF3.F2 */ label = "I2C_4_PORT_1"; status = "disabled"; }; @@ -664,7 +659,6 @@ #size-cells = <0>; port = <0x50>; controller = <&i2c_ctrl5>; - pinctrl-0 = <&alt2_i2c5_0_sl>; /* PIN33.36 */ label = "I2C_5_PORT_0"; status = "disabled"; }; @@ -675,7 +669,6 @@ #size-cells = <0>; port = <0x51>; controller = <&i2c_ctrl5>; - pinctrl-0 = <&alt6_i2c5_1_sl>; /* PINF5.F4 */ label = "I2C_5_PORT_1"; status = "disabled"; }; @@ -686,7 +679,6 @@ #size-cells = <0>; port = <0x60>; controller = <&i2c_ctrl6>; - pinctrl-0 = <&alt2_i2c6_0_sl>; /* PINC2.C1 */ label = "I2C_6_PORT_0"; status = "disabled"; }; @@ -697,7 +689,6 @@ #size-cells = <0>; port = <0x61>; controller = <&i2c_ctrl6>; - pinctrl-0 = <&alt6_i2c6_1_sl>; /* PINE4.E3 */ label = "I2C_6_PORT_1"; status = "disabled"; }; @@ -708,7 +699,6 @@ #size-cells = <0>; port = <0x70>; controller = <&i2c_ctrl7>; - pinctrl-0 = <&alt2_i2c7_0_sl>; /* PINB3.B2 */ label = "I2C_7_PORT_0"; status = "disabled"; }; diff --git a/dts/bindings/i2c/nuvoton,npcx-i2c-port.yaml b/dts/bindings/i2c/nuvoton,npcx-i2c-port.yaml index 1047f021df0..d94266000e6 100644 --- a/dts/bindings/i2c/nuvoton,npcx-i2c-port.yaml +++ b/dts/bindings/i2c/nuvoton,npcx-i2c-port.yaml @@ -5,7 +5,7 @@ description: Nuvoton, NPCX-I2C port pads node compatible: "nuvoton,npcx-i2c-port" -include: i2c-controller.yaml +include: [i2c-controller.yaml, pinctrl-device.yaml] properties: port: @@ -19,9 +19,10 @@ properties: description: i2c controller to handle signals from port pads pinctrl-0: - type: phandles required: true - description: configurations of pinmux controllers + + pinctrl-names: + required: true clock-frequency: required: true