summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-12-09 14:48:24 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-12-09 14:48:24 -0600
commit1f4edb08cfd32ec2c070a51aeffa40b6e67feac8 (patch)
tree03071274ba30c2a09c6416d7ad02a9387c5ce568
parent4f0446907970fea07a7593e4de6921580819b4eb (diff)
downloadnuttx-1f4edb08cfd32ec2c070a51aeffa40b6e67feac8.tar.gz
nuttx-1f4edb08cfd32ec2c070a51aeffa40b6e67feac8.tar.bz2
nuttx-1f4edb08cfd32ec2c070a51aeffa40b6e67feac8.zip
Add a little bit more Tiva I2C initialization logic
-rw-r--r--nuttx/arch/arm/src/tiva/chip/cc3200_pinmap.h6
-rw-r--r--nuttx/arch/arm/src/tiva/chip/lm4f_pinmap.h16
-rw-r--r--nuttx/arch/arm/src/tiva/chip/tm4c_pinmap.h42
-rw-r--r--nuttx/arch/arm/src/tiva/tiva_i2c.c49
4 files changed, 62 insertions, 51 deletions
diff --git a/nuttx/arch/arm/src/tiva/chip/cc3200_pinmap.h b/nuttx/arch/arm/src/tiva/chip/cc3200_pinmap.h
index 569aa1460..c674fdb45 100644
--- a/nuttx/arch/arm/src/tiva/chip/cc3200_pinmap.h
+++ b/nuttx/arch/arm/src/tiva/chip/cc3200_pinmap.h
@@ -66,9 +66,9 @@
# define GPIO_ADC_IN10 (GPIO_FUNC_ANINPUT | GPIO_PORTB | GPIO_PIN_4)
# define GPIO_ADC_IN11 (GPIO_FUNC_ANINPUT | GPIO_PORTB | GPIO_PIN_5)
-# define GPIO_CORE_TRCLK (GPIO_FUNC_PFOUTPUT | GPIO_ALT_14 | GPIO_PORTF | GPIO_PIN_3)
-# define GPIO_CORE_TRD0 (GPIO_FUNC_PFOUTPUT | GPIO_ALT_14 | GPIO_PORTF | GPIO_PIN_2)
-# define GPIO_CORE_TRD1 (GPIO_FUNC_PFOUTPUT | GPIO_ALT_14 | GPIO_PORTF | GPIO_PIN_1)
+# define GPIO_CORE_TRCLK (GPIO_FUNC_PFOUTPUT | GPIO_ALT_14 | GPIO_PADTYPE_ODWPU | GPIO_PORTF | GPIO_PIN_3)
+# define GPIO_CORE_TRD0 (GPIO_FUNC_PFOUTPUT | GPIO_ALT_14 | GPIO_PADTYPE_ODWPU | GPIO_PORTF | GPIO_PIN_2)
+# define GPIO_CORE_TRD1 (GPIO_FUNC_PFOUTPUT | GPIO_ALT_14 | GPIO_PADTYPE_ODWPU | GPIO_PORTF | GPIO_PIN_1)
# define GPIO_I2C0_SCL (GPIO_FUNC_PFODIO | GPIO_ALT_3 | GPIO_PORTB | GPIO_PIN_2)
# define GPIO_I2C0_SDA (GPIO_FUNC_PFODIO | GPIO_ALT_3 | GPIO_PORTB | GPIO_PIN_3)
diff --git a/nuttx/arch/arm/src/tiva/chip/lm4f_pinmap.h b/nuttx/arch/arm/src/tiva/chip/lm4f_pinmap.h
index 91c58bd2d..8a8eae839 100644
--- a/nuttx/arch/arm/src/tiva/chip/lm4f_pinmap.h
+++ b/nuttx/arch/arm/src/tiva/chip/lm4f_pinmap.h
@@ -98,14 +98,14 @@
# define GPIO_CORE_TRD0 (GPIO_FUNC_PFOUTPUT | GPIO_ALT_14 | GPIO_PORTF | GPIO_PIN_2)
# define GPIO_CORE_TRD1 (GPIO_FUNC_PFOUTPUT | GPIO_ALT_14 | GPIO_PORTF | GPIO_PIN_1)
-# define GPIO_I2C0_SCL (GPIO_FUNC_PFODIO | GPIO_ALT_3 | GPIO_PORTB | GPIO_PIN_2)
-# define GPIO_I2C0_SDA (GPIO_FUNC_PFODIO | GPIO_ALT_3 | GPIO_PORTB | GPIO_PIN_3)
-# define GPIO_I2C1_SCL (GPIO_FUNC_PFODIO | GPIO_ALT_3 | GPIO_PORTA | GPIO_PIN_6)
-# define GPIO_I2C1_SDA (GPIO_FUNC_PFODIO | GPIO_ALT_3 | GPIO_PORTA | GPIO_PIN_7)
-# define GPIO_I2C2_SCL (GPIO_FUNC_PFODIO | GPIO_ALT_3 | GPIO_PORTE | GPIO_PIN_4)
-# define GPIO_I2C2_SDA (GPIO_FUNC_PFODIO | GPIO_ALT_3 | GPIO_PORTE | GPIO_PIN_5)
-# define GPIO_I2C3_SCL (GPIO_FUNC_PFODIO | GPIO_ALT_3 | GPIO_PORTD | GPIO_PIN_0)
-# define GPIO_I2C3_SDA (GPIO_FUNC_PFODIO | GPIO_ALT_3 | GPIO_PORTD | GPIO_PIN_1)
+# define GPIO_I2C0_SCL (GPIO_FUNC_PFODIO | GPIO_ALT_3 | GPIO_PADTYPE_ODWPU | GPIO_PORTB | GPIO_PIN_2)
+# define GPIO_I2C0_SDA (GPIO_FUNC_PFODIO | GPIO_ALT_3 | GPIO_PADTYPE_ODWPU | GPIO_PORTB | GPIO_PIN_3)
+# define GPIO_I2C1_SCL (GPIO_FUNC_PFODIO | GPIO_ALT_3 | GPIO_PADTYPE_ODWPU | GPIO_PORTA | GPIO_PIN_6)
+# define GPIO_I2C1_SDA (GPIO_FUNC_PFODIO | GPIO_ALT_3 | GPIO_PADTYPE_ODWPU | GPIO_PORTA | GPIO_PIN_7)
+# define GPIO_I2C2_SCL (GPIO_FUNC_PFODIO | GPIO_ALT_3 | GPIO_PADTYPE_ODWPU | GPIO_PORTE | GPIO_PIN_4)
+# define GPIO_I2C2_SDA (GPIO_FUNC_PFODIO | GPIO_ALT_3 | GPIO_PADTYPE_ODWPU | GPIO_PORTE | GPIO_PIN_5)
+# define GPIO_I2C3_SCL (GPIO_FUNC_PFODIO | GPIO_ALT_3 | GPIO_PADTYPE_ODWPU | GPIO_PORTD | GPIO_PIN_0)
+# define GPIO_I2C3_SDA (GPIO_FUNC_PFODIO | GPIO_ALT_3 | GPIO_PADTYPE_ODWPU | GPIO_PORTD | GPIO_PIN_1)
# define GPIO_JTAG_SWCLK (GPIO_FUNC_PFINPUT | GPIO_ALT_1 | GPIO_PORTC | GPIO_PIN_0)
# define GPIO_JTAG_SWDIO (GPIO_FUNC_PFIO | GPIO_ALT_1 | GPIO_PORTC | GPIO_PIN_1)
diff --git a/nuttx/arch/arm/src/tiva/chip/tm4c_pinmap.h b/nuttx/arch/arm/src/tiva/chip/tm4c_pinmap.h
index cecac78ea..2f646c0b0 100644
--- a/nuttx/arch/arm/src/tiva/chip/tm4c_pinmap.h
+++ b/nuttx/arch/arm/src/tiva/chip/tm4c_pinmap.h
@@ -120,27 +120,27 @@
# define GPIO_HIB_RTCCLK (GPIO_FUNC_PFIO | GPIO_ALT_7 | GPIO_PORTK | GPIO_PIN_4)
-# define GPIO_I2C0_SCL (GPIO_FUNC_PFIO | GPIO_ALT_3 | GPIO_PORTB | GPIO_PIN_2)
-# define GPIO_I2C0_SDA (GPIO_FUNC_PFIO | GPIO_ALT_3 | GPIO_PORTB | GPIO_PIN_3)
-# define GPIO_I2C1_SCL_1 (GPIO_FUNC_PFIO | GPIO_ALT_3 | GPIO_PORTA | GPIO_PIN_6)
-# define GPIO_I2C1_SCL_2 (GPIO_FUNC_PFIO | GPIO_ALT_3 | GPIO_PORTG | GPIO_PIN_4)
-# define GPIO_I2C1_SDA_1 (GPIO_FUNC_PFIO | GPIO_ALT_3 | GPIO_PORTA | GPIO_PIN_7)
-# define GPIO_I2C1_SDA_2 (GPIO_FUNC_PFIO | GPIO_ALT_3 | GPIO_PORTG | GPIO_PIN_5)
-# define GPIO_I2C2_SCL_1 (GPIO_FUNC_PFIO | GPIO_ALT_3 | GPIO_PORTE | GPIO_PIN_4)
-# define GPIO_I2C2_SCL_2 (GPIO_FUNC_PFIO | GPIO_ALT_3 | GPIO_PORTF | GPIO_PIN_6)
-# define GPIO_I2C2_SDA_1 (GPIO_FUNC_PFIO | GPIO_ALT_3 | GPIO_PORTE | GPIO_PIN_5)
-# define GPIO_I2C2_SDA_2 (GPIO_FUNC_PFIO | GPIO_ALT_3 | GPIO_PORTF | GPIO_PIN_7)
-# define GPIO_I2C3_SCL_1 (GPIO_FUNC_PFIO | GPIO_ALT_3 | GPIO_PORTD | GPIO_PIN_0)
-# define GPIO_I2C3_SCL_2 (GPIO_FUNC_PFIO | GPIO_ALT_3 | GPIO_PORTG | GPIO_PIN_0)
-# define GPIO_I2C3_SDA_1 (GPIO_FUNC_PFIO | GPIO_ALT_3 | GPIO_PORTD | GPIO_PIN_1)
-# define GPIO_I2C3_SDA_2 (GPIO_FUNC_PFIO | GPIO_ALT_3 | GPIO_PORTG | GPIO_PIN_1)
-# define GPIO_I2C4_SCL (GPIO_FUNC_PFIO | GPIO_ALT_3 | GPIO_PORTG | GPIO_PIN_2)
-# define GPIO_I2C4_SDA_1 (GPIO_FUNC_PFIO | GPIO_ALT_3 | GPIO_PORTG | GPIO_PIN_3)
-# define GPIO_I2C4_SDA_2 (GPIO_FUNC_PFIO | GPIO_ALT_3 | GPIO_PORTG | GPIO_PIN_3)
-# define GPIO_I2C5_SCL_1 (GPIO_FUNC_PFIO | GPIO_ALT_3 | GPIO_PORTB | GPIO_PIN_6)
-# define GPIO_I2C5_SCL_2 (GPIO_FUNC_PFIO | GPIO_ALT_3 | GPIO_PORTG | GPIO_PIN_6)
-# define GPIO_I2C5_SDA_1 (GPIO_FUNC_PFIO | GPIO_ALT_3 | GPIO_PORTB | GPIO_PIN_7)
-# define GPIO_I2C5_SDA_2 (GPIO_FUNC_PFIO | GPIO_ALT_3 | GPIO_PORTG | GPIO_PIN_7)
+# define GPIO_I2C0_SCL (GPIO_FUNC_PFODIO | GPIO_ALT_3 | GPIO_PADTYPE_ODWPU | GPIO_PORTB | GPIO_PIN_2)
+# define GPIO_I2C0_SDA (GPIO_FUNC_PFODIO | GPIO_ALT_3 | GPIO_PADTYPE_ODWPU | GPIO_PORTB | GPIO_PIN_3)
+# define GPIO_I2C1_SCL_1 (GPIO_FUNC_PFODIO | GPIO_ALT_3 | GPIO_PADTYPE_ODWPU | GPIO_PORTA | GPIO_PIN_6)
+# define GPIO_I2C1_SCL_2 (GPIO_FUNC_PFODIO | GPIO_ALT_3 | GPIO_PADTYPE_ODWPU | GPIO_PORTG | GPIO_PIN_4)
+# define GPIO_I2C1_SDA_1 (GPIO_FUNC_PFODIO | GPIO_ALT_3 | GPIO_PADTYPE_ODWPU | GPIO_PORTA | GPIO_PIN_7)
+# define GPIO_I2C1_SDA_2 (GPIO_FUNC_PFODIO | GPIO_ALT_3 | GPIO_PADTYPE_ODWPU | GPIO_PORTG | GPIO_PIN_5)
+# define GPIO_I2C2_SCL_1 (GPIO_FUNC_PFODIO | GPIO_ALT_3 | GPIO_PADTYPE_ODWPU | GPIO_PORTE | GPIO_PIN_4)
+# define GPIO_I2C2_SCL_2 (GPIO_FUNC_PFODIO | GPIO_ALT_3 | GPIO_PADTYPE_ODWPU | GPIO_PORTF | GPIO_PIN_6)
+# define GPIO_I2C2_SDA_1 (GPIO_FUNC_PFODIO | GPIO_ALT_3 | GPIO_PADTYPE_ODWPU | GPIO_PORTE | GPIO_PIN_5)
+# define GPIO_I2C2_SDA_2 (GPIO_FUNC_PFODIO | GPIO_ALT_3 | GPIO_PADTYPE_ODWPU | GPIO_PORTF | GPIO_PIN_7)
+# define GPIO_I2C3_SCL_1 (GPIO_FUNC_PFODIO | GPIO_ALT_3 | GPIO_PADTYPE_ODWPU | GPIO_PORTD | GPIO_PIN_0)
+# define GPIO_I2C3_SCL_2 (GPIO_FUNC_PFODIO | GPIO_ALT_3 | GPIO_PADTYPE_ODWPU | GPIO_PORTG | GPIO_PIN_0)
+# define GPIO_I2C3_SDA_1 (GPIO_FUNC_PFODIO | GPIO_ALT_3 | GPIO_PADTYPE_ODWPU | GPIO_PORTD | GPIO_PIN_1)
+# define GPIO_I2C3_SDA_2 (GPIO_FUNC_PFODIO | GPIO_ALT_3 | GPIO_PADTYPE_ODWPU | GPIO_PORTG | GPIO_PIN_1)
+# define GPIO_I2C4_SCL (GPIO_FUNC_PFODIO | GPIO_ALT_3 | GPIO_PADTYPE_ODWPU | GPIO_PORTG | GPIO_PIN_2)
+# define GPIO_I2C4_SDA_1 (GPIO_FUNC_PFODIO | GPIO_ALT_3 | GPIO_PADTYPE_ODWPU | GPIO_PORTG | GPIO_PIN_3)
+# define GPIO_I2C4_SDA_2 (GPIO_FUNC_PFODIO | GPIO_ALT_3 | GPIO_PADTYPE_ODWPU | GPIO_PORTG | GPIO_PIN_3)
+# define GPIO_I2C5_SCL_1 (GPIO_FUNC_PFODIO | GPIO_ALT_3 | GPIO_PADTYPE_ODWPU | GPIO_PORTB | GPIO_PIN_6)
+# define GPIO_I2C5_SCL_2 (GPIO_FUNC_PFODIO | GPIO_ALT_3 | GPIO_PADTYPE_ODWPU | GPIO_PORTG | GPIO_PIN_6)
+# define GPIO_I2C5_SDA_1 (GPIO_FUNC_PFODIO | GPIO_ALT_3 | GPIO_PADTYPE_ODWPU | GPIO_PORTB | GPIO_PIN_7)
+# define GPIO_I2C5_SDA_2 (GPIO_FUNC_PFODIO | GPIO_ALT_3 | GPIO_PADTYPE_ODWPU | GPIO_PORTG | GPIO_PIN_7)
# define GPIO_M0_PWM0_1 (GPIO_FUNC_PFOUTPUT | GPIO_ALT_1 | GPIO_PORTP | GPIO_PIN_0)
# define GPIO_M0_PWM0_2 (GPIO_FUNC_PFOUTPUT | GPIO_ALT_4 | GPIO_PORTB | GPIO_PIN_6)
diff --git a/nuttx/arch/arm/src/tiva/tiva_i2c.c b/nuttx/arch/arm/src/tiva/tiva_i2c.c
index e06077a98..2fd60610c 100644
--- a/nuttx/arch/arm/src/tiva/tiva_i2c.c
+++ b/nuttx/arch/arm/src/tiva/tiva_i2c.c
@@ -58,6 +58,7 @@
#include "up_arch.h"
+#include "chip/tiva_syscontrol.h"
#include "tiva_i2c.h"
/* At least one I2C peripheral must be enabled */
@@ -174,7 +175,8 @@ struct tiva_trace_s
struct tiva_i2c_config_s
{
- uint32_t base; /* I2C base address */
+ uintptr_t base; /* I2C base address */
+ uint32_t rcgbit; /* Bits in RCG1 register to enable clocking */
uint32_t scl_pin; /* GPIO configuration for SCL as SCL */
uint32_t sda_pin; /* GPIO configuration for SDA as SDA */
#ifndef CONFIG_I2C_POLLED
@@ -318,6 +320,7 @@ static int tiva_i2c_transfer(FAR struct i2c_dev_s *dev, FAR struct i2c_msg_s *ms
static const struct tiva_i2c_config_s tiva_i2c0_config =
{
.base = TIVA_I2C0_BASE,
+ .rcgbit = SYSCON_RCGC1_I2C0,
.scl_pin = GPIO_I2C0_SCL,
.sda_pin = GPIO_I2C0_SDA,
#ifndef CONFIG_I2C_POLLED
@@ -344,6 +347,7 @@ static struct tiva_i2c_priv_s tiva_i2c0_priv =
static const struct tiva_i2c_config_s tiva_i2c1_config =
{
.base = TIVA_I2C1_BASE,
+ .rcgbit = SYSCON_RCGC1_I2C1,
.scl_pin = GPIO_I2C1_SCL,
.sda_pin = GPIO_I2C1_SDA,
#ifndef CONFIG_I2C_POLLED
@@ -370,6 +374,7 @@ static struct tiva_i2c_priv_s tiva_i2c1_priv =
static const struct tiva_i2c_config_s tiva_i2c2_config =
{
.base = TIVA_I2C2_BASE,
+ .rcgbit = SYSCON_RCGC1_I2C2,
.scl_pin = GPIO_I2C2_SCL,
.sda_pin = GPIO_I2C2_SDA,
#ifndef CONFIG_I2C_POLLED
@@ -396,6 +401,7 @@ static struct tiva_i2c_priv_s tiva_i2c2_priv =
static const struct tiva_i2c_config_s tiva_i2c3_config =
{
.base = TIVA_I2C3_BASE,
+ .rcgbit = SYSCON_RCGC1_I2C3,
.scl_pin = GPIO_I2C3_SCL,
.sda_pin = GPIO_I2C3_SDA,
#ifndef CONFIG_I2C_POLLED
@@ -422,6 +428,7 @@ static struct tiva_i2c_priv_s tiva_i2c3_priv =
static const struct tiva_i2c_config_s tiva_i2c4_config =
{
.base = TIVA_I2C4_BASE,
+ .rcgbit = SYSCON_RCGC1_I2C4,
.scl_pin = GPIO_I2C4_SCL,
.sda_pin = GPIO_I2C4_SDA,
#ifndef CONFIG_I2C_POLLED
@@ -448,6 +455,7 @@ static struct tiva_i2c_priv_s tiva_i2c4_priv =
static const struct tiva_i2c_config_s tiva_i2c5_config =
{
.base = TIVA_I2C5_BASE,
+ .rcgbit = SYSCON_RCGC1_I2C5,
.scl_pin = GPIO_I2C5_SCL,
.sda_pin = GPIO_I2C5_SDA,
#ifndef CONFIG_I2C_POLLED
@@ -503,9 +511,9 @@ static const struct i2c_ops_s tiva_i2c_ops =
************************************************************************************/
static inline uint16_t tiva_i2c_getreg(FAR struct tiva_i2c_priv_s *priv,
- uint8_t offset)
+ unsigned int offset)
{
- return getreg16(priv->config->base + offset);
+ return getreg32(priv->config->base + offset);
}
/************************************************************************************
@@ -516,10 +524,10 @@ static inline uint16_t tiva_i2c_getreg(FAR struct tiva_i2c_priv_s *priv,
*
************************************************************************************/
-static inline void tiva_i2c_putreg(FAR struct tiva_i2c_priv_s *priv, uint8_t offset,
- uint16_t value)
+static inline void tiva_i2c_putreg(FAR struct tiva_i2c_priv_s *priv,
+ unsigned int offset, uint32_t regval)
{
- putreg16(value, priv->config->base + offset);
+ putreg32(regval, priv->config->base + offset);
}
/************************************************************************************
@@ -1357,10 +1365,11 @@ static int tiva_i2c5_isr(int irq, void *context)
static int tiva_i2c_init(FAR struct tiva_i2c_priv_s *priv)
{
- /* Power-up and configure GPIOs */
+ uint32_t regval;
- /* Enable power and reset the peripheral */
-#warning Missing logic
+ /* Enable clocking to the I2C peripheral */
+
+ up_modifyreg32(TIVA_SYSCON_RCGC1, 0, priv->rcgbit);
/* Configure pins */
@@ -1375,23 +1384,25 @@ static int tiva_i2c_init(FAR struct tiva_i2c_priv_s *priv)
return ERROR;
}
- /* Attach ISRs */
+ /* Enable the I2C master block */
-#ifndef CONFIG_I2C_POLLED
- irq_attach(priv->config->irq, priv->config->isr);
- up_enable_irq(priv->config->irq);
-#endif
+ regval = tiva_i2c_getreg(priv, TIVA_I2CM_CR_OFFSET);
+ regval |= I2CM_CR_MFE;
+ tiva_i2c_putreg(priv, TIVA_I2CM_CR_OFFSET, regval);
- /* Set peripheral frequency, where it must be at least 2 MHz for 100 kHz
- * or 4 MHz for 400 kHz. This also disables all I2C interrupts.
- */
+ /* Configure the the initial I2C clock frequency. */
#warning Missing logic
tiva_i2c_setclock(priv, 100000);
- /* Enable I2C */
-#warning Missing logic
+ /* Attach interrupt handlers and enable interrupts at the NVIC (still
+ * disabled at the source)
+ */
+#ifndef CONFIG_I2C_POLLED
+ irq_attach(priv->config->irq, priv->config->isr);
+ up_enable_irq(priv->config->irq);
+#endif
return OK;
}