diff --git a/boards/arm/mec1501modular_assy6885/mec1501modular_assy6885.dts b/boards/arm/mec1501modular_assy6885/mec1501modular_assy6885.dts index 2dbe8b904e..1236cb7cd8 100644 --- a/boards/arm/mec1501modular_assy6885/mec1501modular_assy6885.dts +++ b/boards/arm/mec1501modular_assy6885/mec1501modular_assy6885.dts @@ -63,6 +63,8 @@ port_sel = <0>; sda-gpios = <&gpio_000_036 3 0>; scl-gpios = <&gpio_000_036 4 0>; + pinctrl-0 = < &i2c00_scl_gpio004 &i2c00_sda_gpio003 >; + pinctrl-names = "default"; }; &i2c_smb_1 { @@ -70,6 +72,8 @@ port_sel = <1>; sda-gpios = <&gpio_100_136 24 0>; scl-gpios = <&gpio_100_136 25 0>; + pinctrl-0 = < &i2c01_scl_gpio131 &i2c01_sda_gpio130 >; + pinctrl-names = "default"; }; &espi0 { diff --git a/boards/arm/mec1501modular_assy6885/pinmux.c b/boards/arm/mec1501modular_assy6885/pinmux.c index 27c0723346..2944037372 100644 --- a/boards/arm/mec1501modular_assy6885/pinmux.c +++ b/boards/arm/mec1501modular_assy6885/pinmux.c @@ -32,74 +32,6 @@ struct pinmux_ports_t { #endif }; -#ifdef CONFIG_I2C_XEC -static void i2c_pinmux(struct pinmux_ports_t *p, uint8_t port_sel) -{ - switch (port_sel) { -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pinmux_000_036), okay) - case 0: - pinmux_pin_set(p->porta, MCHP_GPIO_003, MCHP_GPIO_CTRL_MUX_F1); - pinmux_pin_set(p->porta, MCHP_GPIO_004, MCHP_GPIO_CTRL_MUX_F1); - break; -#endif - -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pinmux_100_136), okay) - case 1: - pinmux_pin_set(p->portc, MCHP_GPIO_130, MCHP_GPIO_CTRL_MUX_F1); - pinmux_pin_set(p->portc, MCHP_GPIO_131, MCHP_GPIO_CTRL_MUX_F1); - break; -#endif - -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pinmux_140_176), okay) - case 2: - pinmux_pin_set(p->portd, MCHP_GPIO_154, MCHP_GPIO_CTRL_MUX_F1); - pinmux_pin_set(p->portd, MCHP_GPIO_155, MCHP_GPIO_CTRL_MUX_F1); - break; -#endif - -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pinmux_000_036), okay) - case 3: - pinmux_pin_set(p->porta, MCHP_GPIO_007, MCHP_GPIO_CTRL_MUX_F1); - pinmux_pin_set(p->porta, MCHP_GPIO_010, MCHP_GPIO_CTRL_MUX_F1); - break; -#endif - -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pinmux_140_176), okay) - case 4: - pinmux_pin_set(p->portd, MCHP_GPIO_143, MCHP_GPIO_CTRL_MUX_F1); - pinmux_pin_set(p->portd, MCHP_GPIO_144, MCHP_GPIO_CTRL_MUX_F1); - break; -#endif - -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pinmux_140_176), okay) - case 5: - pinmux_pin_set(p->portd, MCHP_GPIO_141, MCHP_GPIO_CTRL_MUX_F1); - pinmux_pin_set(p->portd, MCHP_GPIO_142, MCHP_GPIO_CTRL_MUX_F1); - break; -#endif - -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pinmux_100_136), okay) -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pinmux_140_176), okay) - case 6: - pinmux_pin_set(p->portc, MCHP_GPIO_132, MCHP_GPIO_CTRL_MUX_F1); - pinmux_pin_set(p->portd, MCHP_GPIO_140, MCHP_GPIO_CTRL_MUX_F1); - break; -#endif -#endif - -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pinmux_000_036), okay) - case 7: - pinmux_pin_set(p->porta, MCHP_GPIO_012, MCHP_GPIO_CTRL_MUX_F1); - pinmux_pin_set(p->porta, MCHP_GPIO_013, MCHP_GPIO_CTRL_MUX_F1); - break; -#endif - - default: - break; - } -} -#endif - static void configure_debug_interface(void) { /* No debug support */ @@ -239,30 +171,6 @@ static int board_pinmux_init(const struct device *dev) pinmux_pin_set(portb, MCHP_GPIO_067, MCHP_GPIO_CTRL_MUX_F1); #endif /* CONFIG_ADC_XEC */ -#ifdef CONFIG_I2C_XEC - -#if DT_NODE_HAS_STATUS(DT_INST(0, microchip_xec_i2c), okay) - i2c_pinmux(&pinmux_ports, DT_PROP(DT_INST(0, microchip_xec_i2c), port_sel)); -#endif - -#if DT_NODE_HAS_STATUS(DT_INST(1, microchip_xec_i2c), okay) - i2c_pinmux(&pinmux_ports, DT_PROP(DT_INST(1, microchip_xec_i2c), port_sel)); -#endif - -#if DT_NODE_HAS_STATUS(DT_INST(2, microchip_xec_i2c), okay) - i2c_pinmux(&pinmux_ports, DT_PROP(DT_INST(2, microchip_xec_i2c), port_sel)); -#endif - -#if DT_NODE_HAS_STATUS(DT_INST(3, microchip_xec_i2c), okay) - i2c_pinmux(&pinmux_ports, DT_PROP(DT_INST(3, microchip_xec_i2c), port_sel)); -#endif - -#if DT_NODE_HAS_STATUS(DT_INST(4, microchip_xec_i2c), okay) - i2c_pinmux(&pinmux_ports, DT_PROP(DT_INST(4, microchip_xec_i2c), port_sel)); -#endif - -#endif /* CONFIG_I2C_XEC */ - #ifdef CONFIG_SPI_XEC_QMSPI #if DT_NODE_HAS_STATUS(DT_INST(0, microchip_xec_qmspi), okay) mchp_pcr_periph_slp_ctrl(PCR_QMSPI, MCHP_PCR_SLEEP_DIS); diff --git a/boards/arm/mec15xxevb_assy6853/mec15xxevb_assy6853.dts b/boards/arm/mec15xxevb_assy6853/mec15xxevb_assy6853.dts index 4e92973f60..80b1d7f4bb 100644 --- a/boards/arm/mec15xxevb_assy6853/mec15xxevb_assy6853.dts +++ b/boards/arm/mec15xxevb_assy6853/mec15xxevb_assy6853.dts @@ -91,6 +91,8 @@ port_sel = <0>; sda-gpios = <&gpio_000_036 3 0>; scl-gpios = <&gpio_000_036 4 0>; + pinctrl-0 = < &i2c00_scl_gpio004 &i2c00_sda_gpio003 >; + pinctrl-names = "default"; }; &i2c_smb_1 { @@ -98,6 +100,8 @@ port_sel = <1>; sda-gpios = <&gpio_100_136 24 0>; scl-gpios = <&gpio_100_136 25 0>; + pinctrl-0 = < &i2c01_scl_gpio131 &i2c01_sda_gpio130 >; + pinctrl-names = "default"; pca9555@26 { compatible = "nxp,pca95xx"; @@ -121,6 +125,8 @@ port_sel = <7>; sda-gpios = <&gpio_000_036 10 0>; scl-gpios = <&gpio_000_036 11 0>; + pinctrl-0 = < &i2c07_scl_gpio013 &i2c07_sda_gpio012 >; + pinctrl-names = "default"; }; &espi0 { diff --git a/boards/arm/mec15xxevb_assy6853/pinmux.c b/boards/arm/mec15xxevb_assy6853/pinmux.c index e233b2bb48..1d325a3152 100644 --- a/boards/arm/mec15xxevb_assy6853/pinmux.c +++ b/boards/arm/mec15xxevb_assy6853/pinmux.c @@ -32,74 +32,6 @@ struct pinmux_ports_t { #endif }; -#ifdef CONFIG_I2C_XEC -static void i2c_pinmux(struct pinmux_ports_t *p, uint8_t port_sel) -{ - switch (port_sel) { -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pinmux_000_036), okay) - case 0: - pinmux_pin_set(p->porta, MCHP_GPIO_003, MCHP_GPIO_CTRL_MUX_F1); - pinmux_pin_set(p->porta, MCHP_GPIO_004, MCHP_GPIO_CTRL_MUX_F1); - break; -#endif - -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pinmux_100_136), okay) - case 1: - pinmux_pin_set(p->portc, MCHP_GPIO_130, MCHP_GPIO_CTRL_MUX_F1); - pinmux_pin_set(p->portc, MCHP_GPIO_131, MCHP_GPIO_CTRL_MUX_F1); - break; -#endif - -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pinmux_140_176), okay) - case 2: - pinmux_pin_set(p->portd, MCHP_GPIO_154, MCHP_GPIO_CTRL_MUX_F1); - pinmux_pin_set(p->portd, MCHP_GPIO_155, MCHP_GPIO_CTRL_MUX_F1); - break; -#endif - -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pinmux_000_036), okay) - case 3: - pinmux_pin_set(p->porta, MCHP_GPIO_007, MCHP_GPIO_CTRL_MUX_F1); - pinmux_pin_set(p->porta, MCHP_GPIO_010, MCHP_GPIO_CTRL_MUX_F1); - break; -#endif - -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pinmux_140_176), okay) - case 4: - pinmux_pin_set(p->portd, MCHP_GPIO_143, MCHP_GPIO_CTRL_MUX_F1); - pinmux_pin_set(p->portd, MCHP_GPIO_144, MCHP_GPIO_CTRL_MUX_F1); - break; -#endif - -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pinmux_140_176), okay) - case 5: - pinmux_pin_set(p->portd, MCHP_GPIO_141, MCHP_GPIO_CTRL_MUX_F1); - pinmux_pin_set(p->portd, MCHP_GPIO_142, MCHP_GPIO_CTRL_MUX_F1); - break; -#endif - -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pinmux_100_136), okay) -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pinmux_140_176), okay) - case 6: - pinmux_pin_set(p->portc, MCHP_GPIO_132, MCHP_GPIO_CTRL_MUX_F1); - pinmux_pin_set(p->portd, MCHP_GPIO_140, MCHP_GPIO_CTRL_MUX_F1); - break; -#endif -#endif - -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pinmux_000_036), okay) - case 7: - pinmux_pin_set(p->porta, MCHP_GPIO_012, MCHP_GPIO_CTRL_MUX_F1); - pinmux_pin_set(p->porta, MCHP_GPIO_013, MCHP_GPIO_CTRL_MUX_F1); - break; -#endif - - default: - break; - } -} -#endif - static void configure_debug_interface(void) { /* No debug support */ @@ -229,30 +161,6 @@ static int board_pinmux_init(const struct device *dev) pinmux_pin_set(portb, MCHP_GPIO_067, MCHP_GPIO_CTRL_MUX_F1); #endif /* CONFIG_ADC_XEC */ -#ifdef CONFIG_I2C_XEC - -#if DT_NODE_HAS_STATUS(DT_INST(0, microchip_xec_i2c), okay) - i2c_pinmux(&pinmux_ports, DT_PROP(DT_INST(0, microchip_xec_i2c), port_sel)); -#endif - -#if DT_NODE_HAS_STATUS(DT_INST(1, microchip_xec_i2c), okay) - i2c_pinmux(&pinmux_ports, DT_PROP(DT_INST(1, microchip_xec_i2c), port_sel)); -#endif - -#if DT_NODE_HAS_STATUS(DT_INST(2, microchip_xec_i2c), okay) - i2c_pinmux(&pinmux_ports, DT_PROP(DT_INST(2, microchip_xec_i2c), port_sel)); -#endif - -#if DT_NODE_HAS_STATUS(DT_INST(3, microchip_xec_i2c), okay) - i2c_pinmux(&pinmux_ports, DT_PROP(DT_INST(3, microchip_xec_i2c), port_sel)); -#endif - -#if DT_NODE_HAS_STATUS(DT_INST(4, microchip_xec_i2c), okay) - i2c_pinmux(&pinmux_ports, DT_PROP(DT_INST(4, microchip_xec_i2c), port_sel)); -#endif - -#endif /* CONFIG_I2C_XEC */ - #ifdef CONFIG_SPI_XEC_QMSPI #if DT_NODE_HAS_STATUS(DT_INST(0, microchip_xec_qmspi), okay) mchp_pcr_periph_slp_ctrl(PCR_QMSPI, MCHP_PCR_SLEEP_DIS); diff --git a/drivers/i2c/i2c_mchp_xec.c b/drivers/i2c/i2c_mchp_xec.c index 523bc8beaf..35ab74ca33 100644 --- a/drivers/i2c/i2c_mchp_xec.c +++ b/drivers/i2c/i2c_mchp_xec.c @@ -12,6 +12,7 @@ #include #include #include +#include #include LOG_MODULE_REGISTER(i2c_mchp, CONFIG_I2C_LOG_LEVEL); @@ -49,6 +50,7 @@ struct i2c_xec_config { uint8_t girq_bit; struct gpio_dt_spec sda_gpio; struct gpio_dt_spec scl_gpio; + const struct pinctrl_dev_config *pcfg; void (*irq_config_func)(void); }; @@ -849,6 +851,12 @@ static int i2c_xec_init(const struct device *dev) data->pending_stop = 0; data->slave_attached = false; + ret = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT); + if (ret != 0) { + LOG_ERR("XEC I2C pinctrl setup failed (%d)", ret); + return ret; + } + if (!device_is_ready(cfg->sda_gpio.port)) { LOG_ERR("%s GPIO device is not ready for SDA GPIO", dev->name); return -ENODEV; @@ -878,6 +886,9 @@ static int i2c_xec_init(const struct device *dev) } #define I2C_XEC_DEVICE(n) \ + \ + PINCTRL_DT_INST_DEFINE(n); \ + \ static void i2c_xec_irq_config_func_##n(void); \ \ static struct i2c_xec_data i2c_xec_data_##n; \ @@ -890,6 +901,7 @@ static int i2c_xec_init(const struct device *dev) .sda_gpio = GPIO_DT_SPEC_INST_GET(n, sda_gpios), \ .scl_gpio = GPIO_DT_SPEC_INST_GET(n, scl_gpios), \ .irq_config_func = i2c_xec_irq_config_func_##n, \ + .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \ }; \ I2C_DEVICE_DT_INST_DEFINE(n, i2c_xec_init, NULL, \ &i2c_xec_data_##n, &i2c_xec_config_##n, \ diff --git a/dts/bindings/i2c/microchip,xec-i2c.yaml b/dts/bindings/i2c/microchip,xec-i2c.yaml index f9febd3f6f..50cdc53140 100644 --- a/dts/bindings/i2c/microchip,xec-i2c.yaml +++ b/dts/bindings/i2c/microchip,xec-i2c.yaml @@ -5,7 +5,7 @@ description: Microchip I2C/SMB controller compatible: "microchip,xec-i2c" -include: i2c-controller.yaml +include: [i2c-controller.yaml, pinctrl-device.yaml] properties: reg: @@ -26,6 +26,12 @@ properties: required: true description: Bit position in GIRQ for this device + pinctrl-0: + required: true + + pinctrl-names: + required: true + sda-gpios: type: phandle-array required: true