bsp/beagle: Partial re-write of I2C driver.

The old driver worked well for EEPROMS with the RTEMS EEPROM driver. But
it had problems with a lot of other situations. Although it's not a
direct port, the new driver is heavily modeled after the FreeBSD ti_i2c
driver.

Closes #3764.
This commit is contained in:
Christian Mauderer
2019-06-29 09:37:24 +02:00
committed by Christian Mauderer
parent 5803f3738f
commit b89d6cc5e4
3 changed files with 421 additions and 446 deletions
File diff suppressed because it is too large Load Diff
+2 -82
View File
@@ -24,76 +24,15 @@
#define LIBBSP_ARM_BEAGLE_I2C_H
#include <rtems.h>
#include <dev/i2c/i2c.h>
#include <bsp.h>
#include <dev/i2c/i2c.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* I2C Configuration Register (I2C_CON): */
#define BBB_I2C_CON_EN (1 << 15) /* I2C module enable */
#define BBB_I2C_CON_BE (1 << 14) /* Big endian mode */
#define BBB_I2C_CON_STB (1 << 11) /* Start byte mode (master mode only) */
#define BBB_I2C_CON_MST (1 << 10) /* Master/slave mode */
#define BBB_I2C_CON_TRX (1 << 9) /* Transmitter/receiver mode */
/* (master mode only) */
#define BBB_I2C_CON_XA (1 << 8) /* Expand address */
#define BBB_I2C_CON_STP (1 << 1) /* Stop condition (master mode only) */
#define BBB_I2C_CON_STT (1 << 0) /* Start condition (master mode only) */
#define BBB_I2C_CON_CLR 0x0 /* Clear configuration register */
/* I2C Status Register (I2C_STAT): */
#define BBB_I2C_STAT_SBD (1 << 15) /* Single byte data */
#define BBB_I2C_STAT_BB (1 << 12) /* Bus busy */
#define BBB_I2C_STAT_ROVR (1 << 11) /* Receive overrun */
#define BBB_I2C_STAT_XUDF (1 << 10) /* Transmit underflow */
#define BBB_I2C_STAT_AAS (1 << 9) /* Address as slave */
#define BBB_I2C_STAT_GC (1 << 5)
#define BBB_I2C_STAT_XRDY (1 << 4) /* Transmit data ready */
#define BBB_I2C_STAT_RRDY (1 << 3) /* Receive data ready */
#define BBB_I2C_STAT_ARDY (1 << 2) /* Register access ready */
#define BBB_I2C_STAT_NACK (1 << 1) /* No acknowledgment interrupt enable */
#define BBB_I2C_STAT_AL (1 << 0) /* Arbitration lost interrupt enable */
/* I2C Interrupt Enable Register (I2C_IE): */
#define BBB_I2C_IE_GC_IE (1 << 5)
#define BBB_I2C_IE_XRDY_IE (1 << 4) /* Transmit data ready interrupt enable */
#define BBB_I2C_IE_RRDY_IE (1 << 3) /* Receive data ready interrupt enable */
#define BBB_I2C_IE_ARDY_IE (1 << 2) /* Register access ready interrupt enable */
#define BBB_I2C_IE_NACK_IE (1 << 1) /* No acknowledgment interrupt enable */
#define BBB_I2C_IE_AL_IE (1 << 0) /* Arbitration lost interrupt enable */
/* I2C SYSC Register (I2C_SYSC): */
#define BBB_I2C_SYSC_SRST (1 << 1)
#define BBB_I2C_TIMEOUT 1000
#define BBB_I2C_SYSS_RDONE (1 << 0) /* Internel reset monitoring */
#define BBB_CONFIG_SYS_I2C_SPEED 100000
#define BBB_CONFIG_SYS_I2C_SLAVE 1
#define BBB_I2C_ALL_FLAGS 0x7FFF
#define BBB_I2C_ALL_IRQ_FLAGS 0xFFFF
#define BBB_I2C_SYSCLK 48000000
#define BBB_I2C_INTERNAL_CLK 12000000
#define BBB_I2C_SPEED_CLK 100000
#define BBB_I2C_IRQ_ERROR \
( AM335X_I2C_IRQSTATUS_NACK \
| AM335X_I2C_IRQSTATUS_ROVR \
| AM335X_I2C_IRQSTATUS_AL \
| AM335X_I2C_IRQSTATUS_ARDY \
| AM335X_I2C_IRQSTATUS_RRDY \
| AM335X_I2C_IRQSTATUS_XRDY \
| AM335X_I2C_IRQSTATUS_XUDF )
#define BBB_I2C_IRQ_USED \
( AM335X_I2C_IRQSTATUS_ARDY \
| AM335X_I2C_IRQSTATUS_XRDY )
#define BBB_I2C_0_BUS_PATH "/dev/i2c-0"
#define BBB_I2C_1_BUS_PATH "/dev/i2c-1"
@@ -103,9 +42,6 @@ extern "C" {
#define BBB_I2C1_IRQ 71
#define BBB_I2C2_IRQ 30
#define BBB_MODE2 2
#define BBB_MODE3 3
typedef enum {
I2C0,
I2C1,
@@ -151,26 +87,10 @@ typedef struct i2c_regs {
uint32_t BBB_I2C_SBLOCK;
} bbb_i2c_regs;
typedef struct bbb_i2c_bus {
i2c_bus base;
volatile bbb_i2c_regs *regs;
i2c_msg *msgs;
uint32_t msg_todo;
uint32_t current_msg_todo;
uint8_t *current_msg_byte;
uint32_t current_todo;
bool read;
bool hold;
rtems_id task_id;
rtems_vector_number irq;
uint32_t input_clock;
uint32_t already_transferred;
} bbb_i2c_bus;
int am335x_i2c_bus_register(
const char *bus_path,
uintptr_t register_base,
uint32_t input_clock,
uint32_t input_clock, /* FIXME: Unused. Left for compatibility. */
rtems_vector_number irq
);
+24 -11
View File
@@ -664,6 +664,9 @@
#define AM335X_I2C_CON_MST (0x00000400u)
#define AM335X_I2C_CON_STB (0x00000800u)
#define AM335X_I2C_SYSC_AUTOIDLE (0x00000001u)
#define AM335X_I2C_SYSC_SRST (0x00000002u)
#define AM335X_I2C_SYSC_ENAWAKEUP (0x00000004u)
#define AM335X_I2C_SYSS_RDONE (0x00000001u)
/*I2C0 module clock registers*/
#define AM335X_CM_WKUP_CONTROL_CLKCTRL (0x4)
@@ -686,29 +689,39 @@
#define AM335X_CM_PER_CONTROL_CLKCTRL_IDLEST (0x00030000u)
#define AM335X_I2C_BUF_TXTRSH_SHIFT (0)
#define AM335X_I2C_BUF_TXTRSH_MASK (0x0000003Fu)
#define AM335X_I2C_BUF_TXTRSH(X) (((X) << AM335X_I2C_BUF_TXTRSH_SHIFT) \
& AM335X_I2C_BUF_TXTRSH_MASK)
#define AM335X_I2C_BUF_TXFIFO_CLR (0x00000040u)
#define AM335X_I2C_BUF_RXTRSH_SHIFT (8)
#define AM335X_I2C_BUF_RXTRSH_MASK (0x00003F00u)
#define AM335X_I2C_BUF_RXTRSH(X) (((X) << AM335X_I2C_BUF_RXTRSH_SHIFT) \
& AM335X_I2C_BUF_RXTRSH_MASK)
#define AM335X_I2C_BUF_RXFIFO_CLR (0x00004000u)
/* I2C status Register */
#define AM335X_I2C_IRQSTATUS_AL (1 << 0)
#define AM335X_I2C_IRQSTATUS_NACK (1 << 1)
#define AM335X_I2C_IRQSTATUS_ROVR (1 << 11)
#define AM335X_I2C_IRQSTATUS_AL (1<<0)
#define AM335X_I2C_IRQSTATUS_ARDY (1 << 2)
#define AM335X_I2C_IRQSTATUS_RRDY (1 << 3)
#define AM335X_I2C_IRQSTATUS_XRDY (1 << 4)
#define AM335X_I2C_IRQSTATUS_XUDF (1 << 10)
#define AM335X_I2C_BUF_TXFIFO_CLR (0x00000040u)
#define AM335X_I2C_BUF_RXFIFO_CLR (0x00004000u)
#define AM335X_I2C_IRQSTATUS_AAS (1 << 9)
#define AM335X_I2C_IRQSTATUS_BF (1 << 8)
#define AM335X_I2C_IRQSTATUS_GC (1 << 5)
#define AM335X_I2C_IRQSTATUS_STC (1 << 6)
#define AM335X_I2C_IRQSTATUS_GC (1 << 5)
#define AM335X_I2C_IRQSTATUS_XDR (1 << 14)
#define AM335X_I2C_IRQSTATUS_RDR (1 << 13)
#define AM335X_I2C_IRQSTATUS_AERR (1 << 7)
#define AM335X_I2C_IRQSTATUS_BF (1 << 8)
#define AM335X_I2C_IRQSTATUS_AAS (1 << 9)
#define AM335X_I2C_IRQSTATUS_XUDF (1 << 10)
#define AM335X_I2C_IRQSTATUS_ROVR (1 << 11)
#define AM335X_I2C_IRQSTATUS_BB (1 << 12)
#define AM335X_I2C_IRQSTATUS_RDR (1 << 13)
#define AM335X_I2C_IRQSTATUS_XDR (1 << 14)
#define AM335X_I2C_INT_RECV_READY AM335X_I2C_IRQSTATUS_RRDY
#define AM335X_I2C_CON_STOP (0x00000002u)
#define AM335X_I2C_CON_START (0x00000001u)
#define AM335X_I2C_CFG_MST_RX AM335X_I2C_CON_MST
#define AM335X_I2C_CFG_MST_TX (AM335X_I2C_CON_TRX | AM335X_I2C_CON_MST)
#define AM335X_I2C_IRQSTATUS_RAW_BB (0x00001000u)
#define AM335X_CM_PER_OCPWP_L3_CLKSTCTRL_CLKACTIVITY_OCPWP_L4_GCLK (0x00000020u)
#define AM335X_I2C_INT_STOP_CONDITION AM335X_I2C_IRQSTATUS_BF