SAMA5: Add TWI3 support

This commit is contained in:
Gregory Nutt 2014-06-08 08:25:39 -06:00
parent da8dfdcb6f
commit 339f5f8e51
2 changed files with 55 additions and 4 deletions

View File

@ -1778,7 +1778,7 @@ config SAMA5_SPI_REGDEBUG
endmenu # SPI device driver options endmenu # SPI device driver options
endif # SAMA5_SPI0 || SAMA5_SPI1 endif # SAMA5_SPI0 || SAMA5_SPI1
if SAMA5_TWI0 || SAMA5_TWI1 || SAMA5_TWI2 if SAMA5_TWI0 || SAMA5_TWI1 || SAMA5_TWI2 || SAMA5_TWI3
menu "TWI device driver options" menu "TWI device driver options"
@ -1797,6 +1797,11 @@ config SAMA5_TWI2_FREQUENCY
default 100000 default 100000
depends on SAMA5_TWI2 depends on SAMA5_TWI2
config SAMA5_TWI3_FREQUENCY
int "TWI3 Frequency"
default 100000
depends on SAMA5_TWI3
config SAMA5_TWI_REGDEBUG config SAMA5_TWI_REGDEBUG
bool "TWI register level debug" bool "TWI register level debug"
depends on DEBUG depends on DEBUG
@ -1806,7 +1811,7 @@ config SAMA5_TWI_REGDEBUG
Very invasive! Requires also DEBUG. Very invasive! Requires also DEBUG.
endmenu # TWI device driver options endmenu # TWI device driver options
endif # SAMA5_TWI0 || SAMA5_TWI1 || SAMA5_TWI2 endif # SAMA5_TWI0 || SAMA5_TWI1 || SAMA5_TWI2 || SAMA5_TWI3
if SAMA5_SSC0 || SAMA5_SSC1 if SAMA5_SSC0 || SAMA5_SSC1
menu "SSC Configuration" menu "SSC Configuration"

View File

@ -70,7 +70,8 @@
#include "sam_pio.h" #include "sam_pio.h"
#include "sam_twi.h" #include "sam_twi.h"
#if defined(CONFIG_SAMA5_TWI0) || defined(CONFIG_SAMA5_TWI1) || defined(CONFIG_SAMA5_TWI2) #if defined(CONFIG_SAMA5_TWI0) || defined(CONFIG_SAMA5_TWI1) || \
defined(CONFIG_SAMA5_TWI2) || defined(CONFIG_SAMA5_TWI3)
/******************************************************************************* /*******************************************************************************
* Pre-processor Definitions * Pre-processor Definitions
@ -89,6 +90,10 @@
#define CONFIG_SAMA5_TWI2_FREQUENCY 100000 #define CONFIG_SAMA5_TWI2_FREQUENCY 100000
#endif #endif
#ifndef CONFIG_SAMA5_TWI3_FREQUENCY
#define CONFIG_SAMA5_TWI3_FREQUENCY 100000
#endif
/* Driver internal definitions *************************************************/ /* Driver internal definitions *************************************************/
#define TWI_TIMEOUT ((20 * CLK_TCK) / 1000) /* 20 mS */ #define TWI_TIMEOUT ((20 * CLK_TCK) / 1000) /* 20 mS */
@ -186,6 +191,9 @@ static int twi1_interrupt(int irq, FAR void *context);
#ifdef CONFIG_SAMA5_TWI2 #ifdef CONFIG_SAMA5_TWI2
static int twi2_interrupt(int irq, FAR void *context); static int twi2_interrupt(int irq, FAR void *context);
#endif #endif
#ifdef CONFIG_SAMA5_TWI3
static int twi3_interrupt(int irq, FAR void *context);
#endif
static void twi_timeout(int argc, uint32_t arg, ...); static void twi_timeout(int argc, uint32_t arg, ...);
static void twi_startread(struct twi_dev_s *priv, struct i2c_msg_s *msg); static void twi_startread(struct twi_dev_s *priv, struct i2c_msg_s *msg);
@ -237,6 +245,10 @@ static struct twi_dev_s g_twi1;
static struct twi_dev_s g_twi2; static struct twi_dev_s g_twi2;
#endif #endif
#ifdef CONFIG_SAMA5_TWI3
static struct twi_dev_s g_twi3;
#endif
struct i2c_ops_s g_twiops = struct i2c_ops_s g_twiops =
{ {
.setfrequency = twi_setfrequency, .setfrequency = twi_setfrequency,
@ -620,6 +632,13 @@ static int twi2_interrupt(int irq, FAR void *context)
} }
#endif #endif
#ifdef CONFIG_SAMA5_TWI3
static int twi3_interrupt(int irq, FAR void *context)
{
return twi_interrupt(&g_twi3);
}
#endif
/******************************************************************************* /*******************************************************************************
* Name: twi_timeout * Name: twi_timeout
* *
@ -1208,7 +1227,7 @@ struct i2c_dev_s *up_i2cinitialize(int bus)
#ifdef CONFIG_SAMA5_TWI0 #ifdef CONFIG_SAMA5_TWI0
if (bus == 0) if (bus == 0)
{ {
/* Set up TWI2 register base address and IRQ number */ /* Set up TWI0 register base address and IRQ number */
priv = &g_twi0; priv = &g_twi0;
priv->base = SAM_TWI0_VBASE; priv->base = SAM_TWI0_VBASE;
@ -1285,6 +1304,33 @@ struct i2c_dev_s *up_i2cinitialize(int bus)
pid = SAM_PID_TWI2; pid = SAM_PID_TWI2;
} }
else else
#endif
#ifdef CONFIG_SAMA5_TWI3
if (bus == 3)
{
/* Set up TWI3 register base address and IRQ number */
priv = &g_twi3;
priv->base = SAM_TWI3_VBASE;
priv->irq = SAM_IRQ_TWI3;
priv->twi = 3;
/* Configure PIO pins */
sam_configpio(PIO_TWI3_CK);
sam_configpio(PIO_TWI3_D);
/* Enable peripheral clocking */
sam_twi3_enableclk();
/* Select the interrupt handler, TWI frequency, and peripheral ID */
handler = twi3_interrupt;
frequency = CONFIG_SAMA5_TWI3_FREQUENCY;
pid = SAM_PID_TWI3;
}
else
#endif #endif
{ {
irqrestore(flags); irqrestore(flags);