imxrt:lpi2c imxrt_lpi2c_reset uses GPIO with SION

Reworked imxrt_lpi2c_reset to use GPIO because the IO
   can not be mapped from a peripheral to a GPIO with
   simple bit logic.
This commit is contained in:
David Sidrane 2019-12-12 16:23:38 -08:00
parent f297e41219
commit 9ebeaa1d53

View File

@ -130,16 +130,6 @@
#define LPI2C_MASTER 1
#define LPI2C_SLAVE 2
#define MKI2C_OUTPUT(p) (((p) & GPIO_PADMUX_MASK) | \
IOMUX_OPENDRAIN | IOMUX_DRIVE_33OHM | \
IOMUX_SLEW_SLOW | (5 << GPIO_ALT_SHIFT) | \
IOMUX_PULL_NONE | GPIO_OUTPUT_ONE)
#define MKI2C_INPUT(p) (((p) & GPIO_PADMUX_MASK) | \
IOMUX_DRIVE_HIZ | IOMUX_SLEW_SLOW | \
IOMUX_CMOS_INPUT | (5 << GPIO_ALT_SHIFT) | \
IOMUX_PULL_NONE)
/****************************************************************************
* Private Types
****************************************************************************/
@ -186,8 +176,12 @@ struct imxrt_lpi2c_config_s
uint16_t busy_idle; /* LPI2C Bus Idle Timeout */
uint8_t filtscl; /* Glitch Filter for SCL pin */
uint8_t filtsda; /* Glitch Filter for SDA pin */
uint32_t scl_pin; /* GPIO configuration for SCL as SCL */
uint32_t sda_pin; /* GPIO configuration for SDA as SDA */
uint32_t scl_pin; /* Peripheral configuration for SCL as SCL */
uint32_t sda_pin; /* Peripheral configuration for SDA as SDA */
#if defined(CONFIG_I2C_RESET)
uint32_t reset_scl_pin; /* GPIO configuration for SCL as SCL */
uint32_t reset_sda_pin; /* GPIO configuration for SDA as SDA */
#endif
uint8_t mode; /* Master or Slave mode */
#ifndef CONFIG_I2C_POLLED
uint32_t irq; /* Event IRQ */
@ -318,136 +312,152 @@ static const struct i2c_ops_s imxrt_lpi2c_ops =
#ifdef CONFIG_IMXRT_LPI2C1
static const struct imxrt_lpi2c_config_s imxrt_lpi2c1_config =
{
.base = IMXRT_LPI2C1_BASE,
.busy_idle = CONFIG_LPI2C1_BUSYIDLE,
.filtscl = CONFIG_LPI2C1_FILTSCL,
.filtsda = CONFIG_LPI2C1_FILTSDA,
.scl_pin = GPIO_LPI2C1_SCL,
.sda_pin = GPIO_LPI2C1_SDA,
.base = IMXRT_LPI2C1_BASE,
.busy_idle = CONFIG_LPI2C1_BUSYIDLE,
.filtscl = CONFIG_LPI2C1_FILTSCL,
.filtsda = CONFIG_LPI2C1_FILTSDA,
.scl_pin = GPIO_LPI2C1_SCL,
.sda_pin = GPIO_LPI2C1_SDA,
#if defined(CONFIG_I2C_RESET)
.reset_scl_pin = GPIO_LPI2C1_SCL_RESET,
.reset_sda_pin = GPIO_LPI2C1_SDA_RESET,
#endif
#ifndef CONFIG_I2C_SLAVE
.mode = LPI2C_MASTER,
.mode = LPI2C_MASTER,
#else
.mode = LPI2C_SLAVE,
.mode = LPI2C_SLAVE,
#endif
#ifndef CONFIG_I2C_POLLED
.irq = IMXRT_IRQ_LPI2C1,
.irq = IMXRT_IRQ_LPI2C1,
#endif
};
static struct imxrt_lpi2c_priv_s imxrt_lpi2c1_priv =
{
.ops = &imxrt_lpi2c_ops,
.config = &imxrt_lpi2c1_config,
.refs = 0,
.intstate = INTSTATE_IDLE,
.msgc = 0,
.msgv = NULL,
.ptr = NULL,
.dcnt = 0,
.flags = 0,
.status = 0
.ops = &imxrt_lpi2c_ops,
.config = &imxrt_lpi2c1_config,
.refs = 0,
.intstate = INTSTATE_IDLE,
.msgc = 0,
.msgv = NULL,
.ptr = NULL,
.dcnt = 0,
.flags = 0,
.status = 0
};
#endif
#ifdef CONFIG_IMXRT_LPI2C2
static const struct imxrt_lpi2c_config_s imxrt_lpi2c2_config =
{
.base = IMXRT_LPI2C2_BASE,
.busy_idle = CONFIG_LPI2C2_BUSYIDLE,
.filtscl = CONFIG_LPI2C2_FILTSCL,
.filtsda = CONFIG_LPI2C2_FILTSDA,
.scl_pin = GPIO_LPI2C2_SCL,
.sda_pin = GPIO_LPI2C2_SDA,
.base = IMXRT_LPI2C2_BASE,
.busy_idle = CONFIG_LPI2C2_BUSYIDLE,
.filtscl = CONFIG_LPI2C2_FILTSCL,
.filtsda = CONFIG_LPI2C2_FILTSDA,
.scl_pin = GPIO_LPI2C2_SCL,
.sda_pin = GPIO_LPI2C2_SDA,
#if defined(CONFIG_I2C_RESET)
.reset_scl_pin = GPIO_LPI2C2_SCL_RESET,
.reset_sda_pin = GPIO_LPI2C2_SDA_RESET,
#endif
#ifndef CONFIG_I2C_SLAVE
.mode = LPI2C_MASTER,
.mode = LPI2C_MASTER,
#else
.mode = LPI2C_SLAVE,
.mode = LPI2C_SLAVE,
#endif
#ifndef CONFIG_I2C_POLLED
.irq = IMXRT_IRQ_LPI2C2,
.irq = IMXRT_IRQ_LPI2C2,
#endif
};
static struct imxrt_lpi2c_priv_s imxrt_lpi2c2_priv =
{
.ops = &imxrt_lpi2c_ops,
.config = &imxrt_lpi2c2_config,
.refs = 0,
.intstate = INTSTATE_IDLE,
.msgc = 0,
.msgv = NULL,
.ptr = NULL,
.dcnt = 0,
.flags = 0,
.status = 0
.ops = &imxrt_lpi2c_ops,
.config = &imxrt_lpi2c2_config,
.refs = 0,
.intstate = INTSTATE_IDLE,
.msgc = 0,
.msgv = NULL,
.ptr = NULL,
.dcnt = 0,
.flags = 0,
.status = 0
};
#endif
#ifdef CONFIG_IMXRT_LPI2C3
static const struct imxrt_lpi2c_config_s imxrt_lpi2c3_config =
{
.base = IMXRT_LPI2C3_BASE,
.busy_idle = CONFIG_LPI2C3_BUSYIDLE,
.filtscl = CONFIG_LPI2C3_FILTSCL,
.filtsda = CONFIG_LPI2C3_FILTSDA,
.scl_pin = GPIO_LPI2C3_SCL,
.sda_pin = GPIO_LPI2C3_SDA,
.base = IMXRT_LPI2C3_BASE,
.busy_idle = CONFIG_LPI2C3_BUSYIDLE,
.filtscl = CONFIG_LPI2C3_FILTSCL,
.filtsda = CONFIG_LPI2C3_FILTSDA,
.scl_pin = GPIO_LPI2C3_SCL,
.sda_pin = GPIO_LPI2C3_SDA,
#if defined(CONFIG_I2C_RESET)
.reset_scl_pin = GPIO_LPI2C3_SCL_RESET,
.reset_sda_pin = GPIO_LPI2C3_SDA_RESET,
#endif
#ifndef CONFIG_I2C_SLAVE
.mode = LPI2C_MASTER,
.mode = LPI2C_MASTER,
#else
.mode = LPI2C_SLAVE,
.mode = LPI2C_SLAVE,
#endif
#ifndef CONFIG_I2C_POLLED
.irq = IMXRT_IRQ_LPI2C3,
.irq = IMXRT_IRQ_LPI2C3,
#endif
};
static struct imxrt_lpi2c_priv_s imxrt_lpi2c3_priv =
{
.ops = &imxrt_lpi2c_ops,
.config = &imxrt_lpi2c3_config,
.refs = 0,
.intstate = INTSTATE_IDLE,
.msgc = 0,
.msgv = NULL,
.ptr = NULL,
.dcnt = 0,
.flags = 0,
.status = 0
.ops = &imxrt_lpi2c_ops,
.config = &imxrt_lpi2c3_config,
.refs = 0,
.intstate = INTSTATE_IDLE,
.msgc = 0,
.msgv = NULL,
.ptr = NULL,
.dcnt = 0,
.flags = 0,
.status = 0
};
#endif
#ifdef CONFIG_IMXRT_LPI2C4
static const struct imxrt_lpi2c_config_s imxrt_lpi2c4_config =
{
.base = IMXRT_LPI2C4_BASE,
.busy_idle = CONFIG_LPI2C4_BUSYIDLE,
.filtscl = CONFIG_LPI2C4_FILTSCL,
.filtsda = CONFIG_LPI2C4_FILTSDA,
.scl_pin = GPIO_LPI2C4_SCL,
.sda_pin = GPIO_LPI2C4_SDA,
.base = IMXRT_LPI2C4_BASE,
.busy_idle = CONFIG_LPI2C4_BUSYIDLE,
.filtscl = CONFIG_LPI2C4_FILTSCL,
.filtsda = CONFIG_LPI2C4_FILTSDA,
.scl_pin = GPIO_LPI2C4_SCL,
.sda_pin = GPIO_LPI2C4_SDA,
#if defined(CONFIG_I2C_RESET)
.reset_scl_pin = GPIO_LPI2C4_SCL_RESET,
.reset_sda_pin = GPIO_LPI2C4_SDA_RESET,
#endif
#ifndef CONFIG_I2C_SLAVE
.mode = LPI2C_MASTER,
.mode = LPI2C_MASTER,
#else
.mode = LPI2C_SLAVE,
.mode = LPI2C_SLAVE,
#endif
#ifndef CONFIG_I2C_POLLED
.irq = IMXRT_IRQ_LPI2C4,
.irq = IMXRT_IRQ_LPI2C4,
#endif
};
static struct imxrt_lpi2c_priv_s imxrt_lpi2c4_priv =
{
.ops = &imxrt_lpi2c_ops,
.config = &imxrt_lpi2c4_config,
.refs = 0,
.intstate = INTSTATE_IDLE,
.msgc = 0,
.msgv = NULL,
.ptr = NULL,
.dcnt = 0,
.flags = 0,
.status = 0
.ops = &imxrt_lpi2c_ops,
.config = &imxrt_lpi2c4_config,
.refs = 0,
.intstate = INTSTATE_IDLE,
.msgc = 0,
.msgv = NULL,
.ptr = NULL,
.dcnt = 0,
.flags = 0,
.status = 0
};
#endif
@ -1298,8 +1308,8 @@ static int imxrt_lpi2c_isr_process(struct imxrt_lpi2c_priv_s *priv)
{
if (priv->msgc > 0 && priv->msgv != NULL)
{
priv->ptr = priv->msgv->buffer;
priv->dcnt = priv->msgv->length;
priv->ptr = priv->msgv->buffer;
priv->dcnt = priv->msgv->length;
priv->flags = priv->msgv->flags;
if ((priv->msgv->flags & I2C_M_NOSTART) == 0)
@ -1754,8 +1764,8 @@ static int imxrt_lpi2c_reset(FAR struct i2c_master_s *dev)
/* Use GPIO configuration to un-wedge the bus */
scl_gpio = MKI2C_OUTPUT(priv->config->scl_pin);
sda_gpio = MKI2C_OUTPUT(priv->config->sda_pin);
scl_gpio = priv->config->reset_scl_pin | GPIO_SION_ENABLE;
sda_gpio = priv->config->reset_sda_pin | GPIO_SION_ENABLE;
imxrt_config_gpio(scl_gpio);
imxrt_config_gpio(sda_gpio);
@ -1818,11 +1828,6 @@ static int imxrt_lpi2c_reset(FAR struct i2c_master_s *dev)
imxrt_gpio_write(sda_gpio, 1);
up_udelay(10);
/* Revert the GPIO configuration. */
sda_gpio = MKI2C_INPUT(sda_gpio);
scl_gpio = MKI2C_INPUT(scl_gpio);
imxrt_config_gpio(sda_gpio);
imxrt_config_gpio(scl_gpio);