diff --git a/arch/arm/src/efm32/efm32_i2c.c b/arch/arm/src/efm32/efm32_i2c.c index 574c788bfb..ac0eada528 100644 --- a/arch/arm/src/efm32/efm32_i2c.c +++ b/arch/arm/src/efm32/efm32_i2c.c @@ -338,8 +338,6 @@ static const char *efm32_i2c_state_str(int i2c_state); * Private Data ****************************************************************************/ -/* Trace events strings */ - /* I2C device structures */ #ifdef CONFIG_EFM32_I2C0 diff --git a/arch/arm/src/lpc11xx/lpc11_i2c.c b/arch/arm/src/lpc11xx/lpc11_i2c.c index 81b6c63494..213ba5a84a 100644 --- a/arch/arm/src/lpc11xx/lpc11_i2c.c +++ b/arch/arm/src/lpc11xx/lpc11_i2c.c @@ -204,8 +204,6 @@ static void lpc11_i2c_setfrequency(struct lpc11_i2cdev_s *priv, static int lpc11_i2c_start(struct lpc11_i2cdev_s *priv) { - int ret = -1; - putreg32(I2C_CONCLR_STAC | I2C_CONCLR_SIC, priv->base + LPC11_I2C_CONCLR_OFFSET); putreg32(I2C_CONSET_STA, priv->base + LPC11_I2C_CONSET_OFFSET); diff --git a/arch/arm/src/lpc17xx/lpc17_i2c.c b/arch/arm/src/lpc17xx/lpc17_i2c.c index 2eb4187597..b5c9ebaf19 100644 --- a/arch/arm/src/lpc17xx/lpc17_i2c.c +++ b/arch/arm/src/lpc17xx/lpc17_i2c.c @@ -167,7 +167,7 @@ struct i2c_ops_s lpc17_i2c_ops = ****************************************************************************/ static void lpc17_i2c_setfrequency(struct lpc17_i2cdev_s *priv, - uint32_t frequency); + uint32_t frequency) { if (frequency != priv->frequency) { @@ -204,8 +204,6 @@ static void lpc17_i2c_setfrequency(struct lpc17_i2cdev_s *priv, static int lpc17_i2c_start(struct lpc17_i2cdev_s *priv) { - int ret = -1; - putreg32(I2C_CONCLR_STAC | I2C_CONCLR_SIC, priv->base + LPC17_I2C_CONCLR_OFFSET); putreg32(I2C_CONSET_STA, priv->base + LPC17_I2C_CONSET_OFFSET); diff --git a/arch/arm/src/lpc2378/lpc23xx_i2c.c b/arch/arm/src/lpc2378/lpc23xx_i2c.c index dca3dac2fa..b752d4bc35 100644 --- a/arch/arm/src/lpc2378/lpc23xx_i2c.c +++ b/arch/arm/src/lpc2378/lpc23xx_i2c.c @@ -209,8 +209,6 @@ static void lpc2378_i2c_setfrequency(struct lpc2378_i2cdev_s *priv, static int lpc2378_i2c_start(struct lpc2378_i2cdev_s *priv) { - int ret = -1; - putreg32(I2C_CONCLR_STAC | I2C_CONCLR_SIC, priv->base + I2C_CONCLR_OFFSET); putreg32(I2C_CONSET_STA, priv->base + I2C_CONSET_OFFSET); diff --git a/arch/arm/src/lpc31xx/lpc31_i2c.c b/arch/arm/src/lpc31xx/lpc31_i2c.c index 4e85610c35..b65c9d8f22 100644 --- a/arch/arm/src/lpc31xx/lpc31_i2c.c +++ b/arch/arm/src/lpc31xx/lpc31_i2c.c @@ -120,7 +120,7 @@ static int i2c_transfer(FAR struct i2c_master_s *dev, FAR struct i2c_msg_s *msgs, int count); /**************************************************************************** - * I2C device operations + * Private Data ****************************************************************************/ struct i2c_ops_s lpc31_i2c_ops = @@ -129,83 +129,11 @@ struct i2c_ops_s lpc31_i2c_ops = }; /**************************************************************************** - * Name: up_i2cinitialize - * - * Description: - * Initialise an I2C device - * + * Private Functions ****************************************************************************/ -struct i2c_master_s *up_i2cinitialize(int port) -{ - struct lpc31_i2cdev_s *priv = &i2cdevices[port]; - - priv->base = (port == 0) ? LPC31_I2C0_VBASE : LPC31_I2C1_VBASE; - priv->clkid = (port == 0) ? CLKID_I2C0PCLK : CLKID_I2C1PCLK; - priv->rstid = (port == 0) ? RESETID_I2C0RST : RESETID_I2C1RST; - priv->irqid = (port == 0) ? LPC31_IRQ_I2C0 : LPC31_IRQ_I2C1; - - sem_init(&priv->mutex, 0, 1); - sem_init(&priv->wait, 0, 0); - - /* Enable I2C system clocks */ - - lpc31_enableclock(priv->clkid); - - /* Reset I2C blocks */ - - lpc31_softreset(priv->rstid); - - /* Soft reset the device */ - - i2c_reset(priv); - - /* Allocate a watchdog timer */ - priv->timeout = wd_create(); - - DEBUGASSERT(priv->timeout != 0); - - /* Attach Interrupt Handler */ - irq_attach(priv->irqid, i2c_interrupt); - - /* Enable Interrupt Handler */ - up_enable_irq(priv->irqid); - - /* Install our operations */ - priv->dev.ops = &lpc31_i2c_ops; - - return &priv->dev; -} - /**************************************************************************** - * Name: up_i2cuninitalize - * - * Description: - * Uninitialise an I2C device - * - ****************************************************************************/ - -void up_i2cuninitalize(struct lpc31_i2cdev_s *priv) -{ - /* Disable All Interrupts, soft reset the device */ - - i2c_reset(priv); - - /* Detach Interrupt Handler */ - - irq_detach(priv->irqid); - - /* Reset I2C blocks */ - - lpc31_softreset(priv->rstid); - - /* Disable I2C system clocks */ - - lpc31_disableclock(priv->clkid); -} - -/**************************************************************************** - * Name: lpc31_i2c_setfrequency + * Name: i2c_setfrequency * * Description: * Set the frequency for the next transfer @@ -567,6 +495,7 @@ static void i2c_timeout(int argc, uint32_t arg, ...) * Perform a soft reset of the I2C controller * ****************************************************************************/ + static void i2c_reset(struct lpc31_i2cdev_s *priv) { putreg32(I2C_CTRL_RESET, priv->base + LPC31_I2C_CTRL_OFFSET); @@ -576,3 +505,83 @@ static void i2c_reset(struct lpc31_i2cdev_s *priv) while ((getreg32(priv->base + LPC31_I2C_CTRL_OFFSET) & I2C_CTRL_RESET) != 0) ; } + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: up_i2cinitialize + * + * Description: + * Initialise an I2C device + * + ****************************************************************************/ + +struct i2c_master_s *up_i2cinitialize(int port) +{ + struct lpc31_i2cdev_s *priv = &i2cdevices[port]; + + priv->base = (port == 0) ? LPC31_I2C0_VBASE : LPC31_I2C1_VBASE; + priv->clkid = (port == 0) ? CLKID_I2C0PCLK : CLKID_I2C1PCLK; + priv->rstid = (port == 0) ? RESETID_I2C0RST : RESETID_I2C1RST; + priv->irqid = (port == 0) ? LPC31_IRQ_I2C0 : LPC31_IRQ_I2C1; + + sem_init(&priv->mutex, 0, 1); + sem_init(&priv->wait, 0, 0); + + /* Enable I2C system clocks */ + + lpc31_enableclock(priv->clkid); + + /* Reset I2C blocks */ + + lpc31_softreset(priv->rstid); + + /* Soft reset the device */ + + i2c_reset(priv); + + /* Allocate a watchdog timer */ + priv->timeout = wd_create(); + + DEBUGASSERT(priv->timeout != 0); + + /* Attach Interrupt Handler */ + irq_attach(priv->irqid, i2c_interrupt); + + /* Enable Interrupt Handler */ + up_enable_irq(priv->irqid); + + /* Install our operations */ + priv->dev.ops = &lpc31_i2c_ops; + + return &priv->dev; +} + +/**************************************************************************** + * Name: up_i2cuninitalize + * + * Description: + * Uninitialise an I2C device + * + ****************************************************************************/ + +void up_i2cuninitalize(struct lpc31_i2cdev_s *priv) +{ + /* Disable All Interrupts, soft reset the device */ + + i2c_reset(priv); + + /* Detach Interrupt Handler */ + + irq_detach(priv->irqid); + + /* Reset I2C blocks */ + + lpc31_softreset(priv->rstid); + + /* Disable I2C system clocks */ + + lpc31_disableclock(priv->clkid); +} diff --git a/arch/arm/src/lpc43xx/lpc43_i2c.c b/arch/arm/src/lpc43xx/lpc43_i2c.c index e5cbf11f6a..a831ec80d9 100644 --- a/arch/arm/src/lpc43xx/lpc43_i2c.c +++ b/arch/arm/src/lpc43xx/lpc43_i2c.c @@ -191,8 +191,6 @@ static void lpc43_i2c_setfrequency(struct lpc43_i2cdev_s *priv, static int lpc43_i2c_start(struct lpc43_i2cdev_s *priv) { - int ret = -1; - putreg32(I2C_CONCLR_STAC | I2C_CONCLR_SIC, priv->base + LPC43_I2C_CONCLR_OFFSET); putreg32(I2C_CONSET_STA, priv->base + LPC43_I2C_CONSET_OFFSET); diff --git a/arch/arm/src/sama5/sam_twi.c b/arch/arm/src/sama5/sam_twi.c index b8f0e4987d..3f82c2011f 100644 --- a/arch/arm/src/sama5/sam_twi.c +++ b/arch/arm/src/sama5/sam_twi.c @@ -237,7 +237,7 @@ static int twi_transfer(FAR struct i2c_master_s *dev, /* Initialization */ -static uint32_t twi_setfrequency(struct twi_dev_s *priv, uint32_t frequency); +static void twi_setfrequency(struct twi_dev_s *priv, uint32_t frequency); static void twi_hw_initialize(struct twi_dev_s *priv, uint32_t frequency); /**************************************************************************** diff --git a/arch/arm/src/tiva/tiva_i2c.c b/arch/arm/src/tiva/tiva_i2c.c index 2a2626e169..facc12edd0 100644 --- a/arch/arm/src/tiva/tiva_i2c.c +++ b/arch/arm/src/tiva/tiva_i2c.c @@ -1915,7 +1915,7 @@ static int tiva_i2c_process(struct i2c_master_s *dev, struct i2c_msg_s *msgv, in * each message segment. */ - tiva_i2c_setclock(priv, msgs->frequency); + tiva_i2c_setclock(priv, msgv->frequency); /* Send the address, then the process moves into the ISR. I2C * interrupts will be enabled within tiva_i2c_waitdone(). @@ -2033,7 +2033,9 @@ static int tiva_i2c_transfer(struct i2c_master_s *dev, struct i2c_msg_s *msgv, tiva_i2c_sem_wait(dev); /* Ensure that address or flags don't change meanwhile */ ret = tiva_i2c_process(dev, msgv, msgc); + tiva_i2c_sem_post(dev); + return ret; } /************************************************************************************