i2c: mec15xx: add pinctrl for mec15xx/mec1501 i2c

Remove pinmux calls and add pinctrl support for mec15xx
and mec1501 pwm. Update board dts, pinmux and driver files.

Signed-off-by: Jay Vasanth <jay.vasanth@microchip.com>
This commit is contained in:
Jay Vasanth 2022-09-16 17:01:18 -04:00 committed by Fabio Baltieri
parent e46c56e117
commit d684425d4d
6 changed files with 29 additions and 185 deletions

View file

@ -63,6 +63,8 @@
port_sel = <0>; port_sel = <0>;
sda-gpios = <&gpio_000_036 3 0>; sda-gpios = <&gpio_000_036 3 0>;
scl-gpios = <&gpio_000_036 4 0>; scl-gpios = <&gpio_000_036 4 0>;
pinctrl-0 = < &i2c00_scl_gpio004 &i2c00_sda_gpio003 >;
pinctrl-names = "default";
}; };
&i2c_smb_1 { &i2c_smb_1 {
@ -70,6 +72,8 @@
port_sel = <1>; port_sel = <1>;
sda-gpios = <&gpio_100_136 24 0>; sda-gpios = <&gpio_100_136 24 0>;
scl-gpios = <&gpio_100_136 25 0>; scl-gpios = <&gpio_100_136 25 0>;
pinctrl-0 = < &i2c01_scl_gpio131 &i2c01_sda_gpio130 >;
pinctrl-names = "default";
}; };
&espi0 { &espi0 {

View file

@ -32,74 +32,6 @@ struct pinmux_ports_t {
#endif #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) static void configure_debug_interface(void)
{ {
/* No debug support */ /* 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); pinmux_pin_set(portb, MCHP_GPIO_067, MCHP_GPIO_CTRL_MUX_F1);
#endif /* CONFIG_ADC_XEC */ #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 #ifdef CONFIG_SPI_XEC_QMSPI
#if DT_NODE_HAS_STATUS(DT_INST(0, microchip_xec_qmspi), okay) #if DT_NODE_HAS_STATUS(DT_INST(0, microchip_xec_qmspi), okay)
mchp_pcr_periph_slp_ctrl(PCR_QMSPI, MCHP_PCR_SLEEP_DIS); mchp_pcr_periph_slp_ctrl(PCR_QMSPI, MCHP_PCR_SLEEP_DIS);

View file

@ -91,6 +91,8 @@
port_sel = <0>; port_sel = <0>;
sda-gpios = <&gpio_000_036 3 0>; sda-gpios = <&gpio_000_036 3 0>;
scl-gpios = <&gpio_000_036 4 0>; scl-gpios = <&gpio_000_036 4 0>;
pinctrl-0 = < &i2c00_scl_gpio004 &i2c00_sda_gpio003 >;
pinctrl-names = "default";
}; };
&i2c_smb_1 { &i2c_smb_1 {
@ -98,6 +100,8 @@
port_sel = <1>; port_sel = <1>;
sda-gpios = <&gpio_100_136 24 0>; sda-gpios = <&gpio_100_136 24 0>;
scl-gpios = <&gpio_100_136 25 0>; scl-gpios = <&gpio_100_136 25 0>;
pinctrl-0 = < &i2c01_scl_gpio131 &i2c01_sda_gpio130 >;
pinctrl-names = "default";
pca9555@26 { pca9555@26 {
compatible = "nxp,pca95xx"; compatible = "nxp,pca95xx";
@ -121,6 +125,8 @@
port_sel = <7>; port_sel = <7>;
sda-gpios = <&gpio_000_036 10 0>; sda-gpios = <&gpio_000_036 10 0>;
scl-gpios = <&gpio_000_036 11 0>; scl-gpios = <&gpio_000_036 11 0>;
pinctrl-0 = < &i2c07_scl_gpio013 &i2c07_sda_gpio012 >;
pinctrl-names = "default";
}; };
&espi0 { &espi0 {

View file

@ -32,74 +32,6 @@ struct pinmux_ports_t {
#endif #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) static void configure_debug_interface(void)
{ {
/* No debug support */ /* 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); pinmux_pin_set(portb, MCHP_GPIO_067, MCHP_GPIO_CTRL_MUX_F1);
#endif /* CONFIG_ADC_XEC */ #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 #ifdef CONFIG_SPI_XEC_QMSPI
#if DT_NODE_HAS_STATUS(DT_INST(0, microchip_xec_qmspi), okay) #if DT_NODE_HAS_STATUS(DT_INST(0, microchip_xec_qmspi), okay)
mchp_pcr_periph_slp_ctrl(PCR_QMSPI, MCHP_PCR_SLEEP_DIS); mchp_pcr_periph_slp_ctrl(PCR_QMSPI, MCHP_PCR_SLEEP_DIS);

View file

@ -12,6 +12,7 @@
#include <errno.h> #include <errno.h>
#include <zephyr/drivers/gpio.h> #include <zephyr/drivers/gpio.h>
#include <zephyr/drivers/i2c.h> #include <zephyr/drivers/i2c.h>
#include <zephyr/drivers/pinctrl.h>
#include <zephyr/logging/log.h> #include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(i2c_mchp, CONFIG_I2C_LOG_LEVEL); LOG_MODULE_REGISTER(i2c_mchp, CONFIG_I2C_LOG_LEVEL);
@ -49,6 +50,7 @@ struct i2c_xec_config {
uint8_t girq_bit; uint8_t girq_bit;
struct gpio_dt_spec sda_gpio; struct gpio_dt_spec sda_gpio;
struct gpio_dt_spec scl_gpio; struct gpio_dt_spec scl_gpio;
const struct pinctrl_dev_config *pcfg;
void (*irq_config_func)(void); void (*irq_config_func)(void);
}; };
@ -849,6 +851,12 @@ static int i2c_xec_init(const struct device *dev)
data->pending_stop = 0; data->pending_stop = 0;
data->slave_attached = false; 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)) { if (!device_is_ready(cfg->sda_gpio.port)) {
LOG_ERR("%s GPIO device is not ready for SDA GPIO", dev->name); LOG_ERR("%s GPIO device is not ready for SDA GPIO", dev->name);
return -ENODEV; return -ENODEV;
@ -878,6 +886,9 @@ static int i2c_xec_init(const struct device *dev)
} }
#define I2C_XEC_DEVICE(n) \ #define I2C_XEC_DEVICE(n) \
\
PINCTRL_DT_INST_DEFINE(n); \
\
static void i2c_xec_irq_config_func_##n(void); \ static void i2c_xec_irq_config_func_##n(void); \
\ \
static struct i2c_xec_data i2c_xec_data_##n; \ 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), \ .sda_gpio = GPIO_DT_SPEC_INST_GET(n, sda_gpios), \
.scl_gpio = GPIO_DT_SPEC_INST_GET(n, scl_gpios), \ .scl_gpio = GPIO_DT_SPEC_INST_GET(n, scl_gpios), \
.irq_config_func = i2c_xec_irq_config_func_##n, \ .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_DEVICE_DT_INST_DEFINE(n, i2c_xec_init, NULL, \
&i2c_xec_data_##n, &i2c_xec_config_##n, \ &i2c_xec_data_##n, &i2c_xec_config_##n, \

View file

@ -5,7 +5,7 @@ description: Microchip I2C/SMB controller
compatible: "microchip,xec-i2c" compatible: "microchip,xec-i2c"
include: i2c-controller.yaml include: [i2c-controller.yaml, pinctrl-device.yaml]
properties: properties:
reg: reg:
@ -26,6 +26,12 @@ properties:
required: true required: true
description: Bit position in GIRQ for this device description: Bit position in GIRQ for this device
pinctrl-0:
required: true
pinctrl-names:
required: true
sda-gpios: sda-gpios:
type: phandle-array type: phandle-array
required: true required: true