|
@@ -25,18 +25,15 @@
|
|
* ----------------------------------------------------------------------------
|
|
* ----------------------------------------------------------------------------
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
-#include <linux/kernel.h>
|
|
|
|
-#include <linux/module.h>
|
|
|
|
-#include <linux/delay.h>
|
|
|
|
-#include <linux/i2c.h>
|
|
|
|
#include <linux/clk.h>
|
|
#include <linux/clk.h>
|
|
#include <linux/errno.h>
|
|
#include <linux/errno.h>
|
|
-#include <linux/sched.h>
|
|
|
|
#include <linux/err.h>
|
|
#include <linux/err.h>
|
|
|
|
+#include <linux/i2c.h>
|
|
#include <linux/interrupt.h>
|
|
#include <linux/interrupt.h>
|
|
-#include <linux/platform_device.h>
|
|
|
|
#include <linux/io.h>
|
|
#include <linux/io.h>
|
|
-#include <linux/slab.h>
|
|
|
|
|
|
+#include <linux/pm_runtime.h>
|
|
|
|
+#include <linux/delay.h>
|
|
|
|
+#include "i2c-designware-core.h"
|
|
|
|
|
|
/*
|
|
/*
|
|
* Registers offset
|
|
* Registers offset
|
|
@@ -68,15 +65,10 @@
|
|
#define DW_IC_STATUS 0x70
|
|
#define DW_IC_STATUS 0x70
|
|
#define DW_IC_TXFLR 0x74
|
|
#define DW_IC_TXFLR 0x74
|
|
#define DW_IC_RXFLR 0x78
|
|
#define DW_IC_RXFLR 0x78
|
|
-#define DW_IC_COMP_PARAM_1 0xf4
|
|
|
|
#define DW_IC_TX_ABRT_SOURCE 0x80
|
|
#define DW_IC_TX_ABRT_SOURCE 0x80
|
|
-
|
|
|
|
-#define DW_IC_CON_MASTER 0x1
|
|
|
|
-#define DW_IC_CON_SPEED_STD 0x2
|
|
|
|
-#define DW_IC_CON_SPEED_FAST 0x4
|
|
|
|
-#define DW_IC_CON_10BITADDR_MASTER 0x10
|
|
|
|
-#define DW_IC_CON_RESTART_EN 0x20
|
|
|
|
-#define DW_IC_CON_SLAVE_DISABLE 0x40
|
|
|
|
|
|
+#define DW_IC_COMP_PARAM_1 0xf4
|
|
|
|
+#define DW_IC_COMP_TYPE 0xfc
|
|
|
|
+#define DW_IC_COMP_TYPE_VALUE 0x44570140
|
|
|
|
|
|
#define DW_IC_INTR_RX_UNDER 0x001
|
|
#define DW_IC_INTR_RX_UNDER 0x001
|
|
#define DW_IC_INTR_RX_OVER 0x002
|
|
#define DW_IC_INTR_RX_OVER 0x002
|
|
@@ -170,55 +162,23 @@ static char *abort_sources[] = {
|
|
"lost arbitration",
|
|
"lost arbitration",
|
|
};
|
|
};
|
|
|
|
|
|
-/**
|
|
|
|
- * struct dw_i2c_dev - private i2c-designware data
|
|
|
|
- * @dev: driver model device node
|
|
|
|
- * @base: IO registers pointer
|
|
|
|
- * @cmd_complete: tx completion indicator
|
|
|
|
- * @lock: protect this struct and IO registers
|
|
|
|
- * @clk: input reference clock
|
|
|
|
- * @cmd_err: run time hadware error code
|
|
|
|
- * @msgs: points to an array of messages currently being transferred
|
|
|
|
- * @msgs_num: the number of elements in msgs
|
|
|
|
- * @msg_write_idx: the element index of the current tx message in the msgs
|
|
|
|
- * array
|
|
|
|
- * @tx_buf_len: the length of the current tx buffer
|
|
|
|
- * @tx_buf: the current tx buffer
|
|
|
|
- * @msg_read_idx: the element index of the current rx message in the msgs
|
|
|
|
- * array
|
|
|
|
- * @rx_buf_len: the length of the current rx buffer
|
|
|
|
- * @rx_buf: the current rx buffer
|
|
|
|
- * @msg_err: error status of the current transfer
|
|
|
|
- * @status: i2c master status, one of STATUS_*
|
|
|
|
- * @abort_source: copy of the TX_ABRT_SOURCE register
|
|
|
|
- * @irq: interrupt number for the i2c master
|
|
|
|
- * @adapter: i2c subsystem adapter node
|
|
|
|
- * @tx_fifo_depth: depth of the hardware tx fifo
|
|
|
|
- * @rx_fifo_depth: depth of the hardware rx fifo
|
|
|
|
- */
|
|
|
|
-struct dw_i2c_dev {
|
|
|
|
- struct device *dev;
|
|
|
|
- void __iomem *base;
|
|
|
|
- struct completion cmd_complete;
|
|
|
|
- struct mutex lock;
|
|
|
|
- struct clk *clk;
|
|
|
|
- int cmd_err;
|
|
|
|
- struct i2c_msg *msgs;
|
|
|
|
- int msgs_num;
|
|
|
|
- int msg_write_idx;
|
|
|
|
- u32 tx_buf_len;
|
|
|
|
- u8 *tx_buf;
|
|
|
|
- int msg_read_idx;
|
|
|
|
- u32 rx_buf_len;
|
|
|
|
- u8 *rx_buf;
|
|
|
|
- int msg_err;
|
|
|
|
- unsigned int status;
|
|
|
|
- u32 abort_source;
|
|
|
|
- int irq;
|
|
|
|
- struct i2c_adapter adapter;
|
|
|
|
- unsigned int tx_fifo_depth;
|
|
|
|
- unsigned int rx_fifo_depth;
|
|
|
|
-};
|
|
|
|
|
|
+u32 dw_readl(struct dw_i2c_dev *dev, int offset)
|
|
|
|
+{
|
|
|
|
+ u32 value = readl(dev->base + offset);
|
|
|
|
+
|
|
|
|
+ if (dev->swab)
|
|
|
|
+ return swab32(value);
|
|
|
|
+ else
|
|
|
|
+ return value;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void dw_writel(struct dw_i2c_dev *dev, u32 b, int offset)
|
|
|
|
+{
|
|
|
|
+ if (dev->swab)
|
|
|
|
+ b = swab32(b);
|
|
|
|
+
|
|
|
|
+ writel(b, dev->base + offset);
|
|
|
|
+}
|
|
|
|
|
|
static u32
|
|
static u32
|
|
i2c_dw_scl_hcnt(u32 ic_clk, u32 tSYMBOL, u32 tf, int cond, int offset)
|
|
i2c_dw_scl_hcnt(u32 ic_clk, u32 tSYMBOL, u32 tf, int cond, int offset)
|
|
@@ -283,13 +243,29 @@ static u32 i2c_dw_scl_lcnt(u32 ic_clk, u32 tLOW, u32 tf, int offset)
|
|
* This function is called during I2C init function, and in case of timeout at
|
|
* This function is called during I2C init function, and in case of timeout at
|
|
* run time.
|
|
* run time.
|
|
*/
|
|
*/
|
|
-static void i2c_dw_init(struct dw_i2c_dev *dev)
|
|
|
|
|
|
+int i2c_dw_init(struct dw_i2c_dev *dev)
|
|
{
|
|
{
|
|
- u32 input_clock_khz = clk_get_rate(dev->clk) / 1000;
|
|
|
|
- u32 ic_con, hcnt, lcnt;
|
|
|
|
|
|
+ u32 input_clock_khz;
|
|
|
|
+ u32 hcnt, lcnt;
|
|
|
|
+ u32 reg;
|
|
|
|
+
|
|
|
|
+ input_clock_khz = dev->get_clk_rate_khz(dev);
|
|
|
|
+
|
|
|
|
+ /* Configure register endianess access */
|
|
|
|
+ reg = dw_readl(dev, DW_IC_COMP_TYPE);
|
|
|
|
+ if (reg == ___constant_swab32(DW_IC_COMP_TYPE_VALUE)) {
|
|
|
|
+ dev->swab = 1;
|
|
|
|
+ reg = DW_IC_COMP_TYPE_VALUE;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (reg != DW_IC_COMP_TYPE_VALUE) {
|
|
|
|
+ dev_err(dev->dev, "Unknown Synopsys component type: "
|
|
|
|
+ "0x%08x\n", reg);
|
|
|
|
+ return -ENODEV;
|
|
|
|
+ }
|
|
|
|
|
|
/* Disable the adapter */
|
|
/* Disable the adapter */
|
|
- writel(0, dev->base + DW_IC_ENABLE);
|
|
|
|
|
|
+ dw_writel(dev, 0, DW_IC_ENABLE);
|
|
|
|
|
|
/* set standard and fast speed deviders for high/low periods */
|
|
/* set standard and fast speed deviders for high/low periods */
|
|
|
|
|
|
@@ -303,8 +279,8 @@ static void i2c_dw_init(struct dw_i2c_dev *dev)
|
|
47, /* tLOW = 4.7 us */
|
|
47, /* tLOW = 4.7 us */
|
|
3, /* tf = 0.3 us */
|
|
3, /* tf = 0.3 us */
|
|
0); /* No offset */
|
|
0); /* No offset */
|
|
- writel(hcnt, dev->base + DW_IC_SS_SCL_HCNT);
|
|
|
|
- writel(lcnt, dev->base + DW_IC_SS_SCL_LCNT);
|
|
|
|
|
|
+ dw_writel(dev, hcnt, DW_IC_SS_SCL_HCNT);
|
|
|
|
+ dw_writel(dev, lcnt, DW_IC_SS_SCL_LCNT);
|
|
dev_dbg(dev->dev, "Standard-mode HCNT:LCNT = %d:%d\n", hcnt, lcnt);
|
|
dev_dbg(dev->dev, "Standard-mode HCNT:LCNT = %d:%d\n", hcnt, lcnt);
|
|
|
|
|
|
/* Fast-mode */
|
|
/* Fast-mode */
|
|
@@ -317,18 +293,17 @@ static void i2c_dw_init(struct dw_i2c_dev *dev)
|
|
13, /* tLOW = 1.3 us */
|
|
13, /* tLOW = 1.3 us */
|
|
3, /* tf = 0.3 us */
|
|
3, /* tf = 0.3 us */
|
|
0); /* No offset */
|
|
0); /* No offset */
|
|
- writel(hcnt, dev->base + DW_IC_FS_SCL_HCNT);
|
|
|
|
- writel(lcnt, dev->base + DW_IC_FS_SCL_LCNT);
|
|
|
|
|
|
+ dw_writel(dev, hcnt, DW_IC_FS_SCL_HCNT);
|
|
|
|
+ dw_writel(dev, lcnt, DW_IC_FS_SCL_LCNT);
|
|
dev_dbg(dev->dev, "Fast-mode HCNT:LCNT = %d:%d\n", hcnt, lcnt);
|
|
dev_dbg(dev->dev, "Fast-mode HCNT:LCNT = %d:%d\n", hcnt, lcnt);
|
|
|
|
|
|
/* Configure Tx/Rx FIFO threshold levels */
|
|
/* Configure Tx/Rx FIFO threshold levels */
|
|
- writel(dev->tx_fifo_depth - 1, dev->base + DW_IC_TX_TL);
|
|
|
|
- writel(0, dev->base + DW_IC_RX_TL);
|
|
|
|
|
|
+ dw_writel(dev, dev->tx_fifo_depth - 1, DW_IC_TX_TL);
|
|
|
|
+ dw_writel(dev, 0, DW_IC_RX_TL);
|
|
|
|
|
|
/* configure the i2c master */
|
|
/* configure the i2c master */
|
|
- ic_con = DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE |
|
|
|
|
- DW_IC_CON_RESTART_EN | DW_IC_CON_SPEED_FAST;
|
|
|
|
- writel(ic_con, dev->base + DW_IC_CON);
|
|
|
|
|
|
+ dw_writel(dev, dev->master_cfg , DW_IC_CON);
|
|
|
|
+ return 0;
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
/*
|
|
@@ -338,7 +313,7 @@ static int i2c_dw_wait_bus_not_busy(struct dw_i2c_dev *dev)
|
|
{
|
|
{
|
|
int timeout = TIMEOUT;
|
|
int timeout = TIMEOUT;
|
|
|
|
|
|
- while (readl(dev->base + DW_IC_STATUS) & DW_IC_STATUS_ACTIVITY) {
|
|
|
|
|
|
+ while (dw_readl(dev, DW_IC_STATUS) & DW_IC_STATUS_ACTIVITY) {
|
|
if (timeout <= 0) {
|
|
if (timeout <= 0) {
|
|
dev_warn(dev->dev, "timeout waiting for bus ready\n");
|
|
dev_warn(dev->dev, "timeout waiting for bus ready\n");
|
|
return -ETIMEDOUT;
|
|
return -ETIMEDOUT;
|
|
@@ -356,24 +331,24 @@ static void i2c_dw_xfer_init(struct dw_i2c_dev *dev)
|
|
u32 ic_con;
|
|
u32 ic_con;
|
|
|
|
|
|
/* Disable the adapter */
|
|
/* Disable the adapter */
|
|
- writel(0, dev->base + DW_IC_ENABLE);
|
|
|
|
|
|
+ dw_writel(dev, 0, DW_IC_ENABLE);
|
|
|
|
|
|
/* set the slave (target) address */
|
|
/* set the slave (target) address */
|
|
- writel(msgs[dev->msg_write_idx].addr, dev->base + DW_IC_TAR);
|
|
|
|
|
|
+ dw_writel(dev, msgs[dev->msg_write_idx].addr, DW_IC_TAR);
|
|
|
|
|
|
/* if the slave address is ten bit address, enable 10BITADDR */
|
|
/* if the slave address is ten bit address, enable 10BITADDR */
|
|
- ic_con = readl(dev->base + DW_IC_CON);
|
|
|
|
|
|
+ ic_con = dw_readl(dev, DW_IC_CON);
|
|
if (msgs[dev->msg_write_idx].flags & I2C_M_TEN)
|
|
if (msgs[dev->msg_write_idx].flags & I2C_M_TEN)
|
|
ic_con |= DW_IC_CON_10BITADDR_MASTER;
|
|
ic_con |= DW_IC_CON_10BITADDR_MASTER;
|
|
else
|
|
else
|
|
ic_con &= ~DW_IC_CON_10BITADDR_MASTER;
|
|
ic_con &= ~DW_IC_CON_10BITADDR_MASTER;
|
|
- writel(ic_con, dev->base + DW_IC_CON);
|
|
|
|
|
|
+ dw_writel(dev, ic_con, DW_IC_CON);
|
|
|
|
|
|
/* Enable the adapter */
|
|
/* Enable the adapter */
|
|
- writel(1, dev->base + DW_IC_ENABLE);
|
|
|
|
|
|
+ dw_writel(dev, 1, DW_IC_ENABLE);
|
|
|
|
|
|
/* Enable interrupts */
|
|
/* Enable interrupts */
|
|
- writel(DW_IC_INTR_DEFAULT_MASK, dev->base + DW_IC_INTR_MASK);
|
|
|
|
|
|
+ dw_writel(dev, DW_IC_INTR_DEFAULT_MASK, DW_IC_INTR_MASK);
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
/*
|
|
@@ -382,7 +357,7 @@ static void i2c_dw_xfer_init(struct dw_i2c_dev *dev)
|
|
* messages into the tx buffer. Even if the size of i2c_msg data is
|
|
* messages into the tx buffer. Even if the size of i2c_msg data is
|
|
* longer than the size of the tx buffer, it handles everything.
|
|
* longer than the size of the tx buffer, it handles everything.
|
|
*/
|
|
*/
|
|
-static void
|
|
|
|
|
|
+void
|
|
i2c_dw_xfer_msg(struct dw_i2c_dev *dev)
|
|
i2c_dw_xfer_msg(struct dw_i2c_dev *dev)
|
|
{
|
|
{
|
|
struct i2c_msg *msgs = dev->msgs;
|
|
struct i2c_msg *msgs = dev->msgs;
|
|
@@ -420,15 +395,15 @@ i2c_dw_xfer_msg(struct dw_i2c_dev *dev)
|
|
buf_len = msgs[dev->msg_write_idx].len;
|
|
buf_len = msgs[dev->msg_write_idx].len;
|
|
}
|
|
}
|
|
|
|
|
|
- tx_limit = dev->tx_fifo_depth - readl(dev->base + DW_IC_TXFLR);
|
|
|
|
- rx_limit = dev->rx_fifo_depth - readl(dev->base + DW_IC_RXFLR);
|
|
|
|
|
|
+ tx_limit = dev->tx_fifo_depth - dw_readl(dev, DW_IC_TXFLR);
|
|
|
|
+ rx_limit = dev->rx_fifo_depth - dw_readl(dev, DW_IC_RXFLR);
|
|
|
|
|
|
while (buf_len > 0 && tx_limit > 0 && rx_limit > 0) {
|
|
while (buf_len > 0 && tx_limit > 0 && rx_limit > 0) {
|
|
if (msgs[dev->msg_write_idx].flags & I2C_M_RD) {
|
|
if (msgs[dev->msg_write_idx].flags & I2C_M_RD) {
|
|
- writel(0x100, dev->base + DW_IC_DATA_CMD);
|
|
|
|
|
|
+ dw_writel(dev, 0x100, DW_IC_DATA_CMD);
|
|
rx_limit--;
|
|
rx_limit--;
|
|
} else
|
|
} else
|
|
- writel(*buf++, dev->base + DW_IC_DATA_CMD);
|
|
|
|
|
|
+ dw_writel(dev, *buf++, DW_IC_DATA_CMD);
|
|
tx_limit--; buf_len--;
|
|
tx_limit--; buf_len--;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -453,7 +428,7 @@ i2c_dw_xfer_msg(struct dw_i2c_dev *dev)
|
|
if (dev->msg_err)
|
|
if (dev->msg_err)
|
|
intr_mask = 0;
|
|
intr_mask = 0;
|
|
|
|
|
|
- writel(intr_mask, dev->base + DW_IC_INTR_MASK);
|
|
|
|
|
|
+ dw_writel(dev, intr_mask, DW_IC_INTR_MASK);
|
|
}
|
|
}
|
|
|
|
|
|
static void
|
|
static void
|
|
@@ -477,10 +452,10 @@ i2c_dw_read(struct dw_i2c_dev *dev)
|
|
buf = dev->rx_buf;
|
|
buf = dev->rx_buf;
|
|
}
|
|
}
|
|
|
|
|
|
- rx_valid = readl(dev->base + DW_IC_RXFLR);
|
|
|
|
|
|
+ rx_valid = dw_readl(dev, DW_IC_RXFLR);
|
|
|
|
|
|
for (; len > 0 && rx_valid > 0; len--, rx_valid--)
|
|
for (; len > 0 && rx_valid > 0; len--, rx_valid--)
|
|
- *buf++ = readl(dev->base + DW_IC_DATA_CMD);
|
|
|
|
|
|
+ *buf++ = dw_readl(dev, DW_IC_DATA_CMD);
|
|
|
|
|
|
if (len > 0) {
|
|
if (len > 0) {
|
|
dev->status |= STATUS_READ_IN_PROGRESS;
|
|
dev->status |= STATUS_READ_IN_PROGRESS;
|
|
@@ -518,7 +493,7 @@ static int i2c_dw_handle_tx_abort(struct dw_i2c_dev *dev)
|
|
/*
|
|
/*
|
|
* Prepare controller for a transaction and call i2c_dw_xfer_msg
|
|
* Prepare controller for a transaction and call i2c_dw_xfer_msg
|
|
*/
|
|
*/
|
|
-static int
|
|
|
|
|
|
+int
|
|
i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
|
|
i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
|
|
{
|
|
{
|
|
struct dw_i2c_dev *dev = i2c_get_adapdata(adap);
|
|
struct dw_i2c_dev *dev = i2c_get_adapdata(adap);
|
|
@@ -527,6 +502,7 @@ i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
|
|
dev_dbg(dev->dev, "%s: msgs: %d\n", __func__, num);
|
|
dev_dbg(dev->dev, "%s: msgs: %d\n", __func__, num);
|
|
|
|
|
|
mutex_lock(&dev->lock);
|
|
mutex_lock(&dev->lock);
|
|
|
|
+ pm_runtime_get_sync(dev->dev);
|
|
|
|
|
|
INIT_COMPLETION(dev->cmd_complete);
|
|
INIT_COMPLETION(dev->cmd_complete);
|
|
dev->msgs = msgs;
|
|
dev->msgs = msgs;
|
|
@@ -563,7 +539,7 @@ i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
|
|
/* no error */
|
|
/* no error */
|
|
if (likely(!dev->cmd_err)) {
|
|
if (likely(!dev->cmd_err)) {
|
|
/* Disable the adapter */
|
|
/* Disable the adapter */
|
|
- writel(0, dev->base + DW_IC_ENABLE);
|
|
|
|
|
|
+ dw_writel(dev, 0, DW_IC_ENABLE);
|
|
ret = num;
|
|
ret = num;
|
|
goto done;
|
|
goto done;
|
|
}
|
|
}
|
|
@@ -576,19 +552,16 @@ i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
|
|
ret = -EIO;
|
|
ret = -EIO;
|
|
|
|
|
|
done:
|
|
done:
|
|
|
|
+ pm_runtime_put(dev->dev);
|
|
mutex_unlock(&dev->lock);
|
|
mutex_unlock(&dev->lock);
|
|
|
|
|
|
return ret;
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
|
|
-static u32 i2c_dw_func(struct i2c_adapter *adap)
|
|
|
|
|
|
+u32 i2c_dw_func(struct i2c_adapter *adap)
|
|
{
|
|
{
|
|
- return I2C_FUNC_I2C |
|
|
|
|
- I2C_FUNC_10BIT_ADDR |
|
|
|
|
- I2C_FUNC_SMBUS_BYTE |
|
|
|
|
- I2C_FUNC_SMBUS_BYTE_DATA |
|
|
|
|
- I2C_FUNC_SMBUS_WORD_DATA |
|
|
|
|
- I2C_FUNC_SMBUS_I2C_BLOCK;
|
|
|
|
|
|
+ struct dw_i2c_dev *dev = i2c_get_adapdata(adap);
|
|
|
|
+ return dev->functionality;
|
|
}
|
|
}
|
|
|
|
|
|
static u32 i2c_dw_read_clear_intrbits(struct dw_i2c_dev *dev)
|
|
static u32 i2c_dw_read_clear_intrbits(struct dw_i2c_dev *dev)
|
|
@@ -601,47 +574,47 @@ static u32 i2c_dw_read_clear_intrbits(struct dw_i2c_dev *dev)
|
|
* in the IC_RAW_INTR_STAT register.
|
|
* in the IC_RAW_INTR_STAT register.
|
|
*
|
|
*
|
|
* That is,
|
|
* That is,
|
|
- * stat = readl(IC_INTR_STAT);
|
|
|
|
|
|
+ * stat = dw_readl(IC_INTR_STAT);
|
|
* equals to,
|
|
* equals to,
|
|
- * stat = readl(IC_RAW_INTR_STAT) & readl(IC_INTR_MASK);
|
|
|
|
|
|
+ * stat = dw_readl(IC_RAW_INTR_STAT) & dw_readl(IC_INTR_MASK);
|
|
*
|
|
*
|
|
* The raw version might be useful for debugging purposes.
|
|
* The raw version might be useful for debugging purposes.
|
|
*/
|
|
*/
|
|
- stat = readl(dev->base + DW_IC_INTR_STAT);
|
|
|
|
|
|
+ stat = dw_readl(dev, DW_IC_INTR_STAT);
|
|
|
|
|
|
/*
|
|
/*
|
|
* Do not use the IC_CLR_INTR register to clear interrupts, or
|
|
* Do not use the IC_CLR_INTR register to clear interrupts, or
|
|
* you'll miss some interrupts, triggered during the period from
|
|
* you'll miss some interrupts, triggered during the period from
|
|
- * readl(IC_INTR_STAT) to readl(IC_CLR_INTR).
|
|
|
|
|
|
+ * dw_readl(IC_INTR_STAT) to dw_readl(IC_CLR_INTR).
|
|
*
|
|
*
|
|
* Instead, use the separately-prepared IC_CLR_* registers.
|
|
* Instead, use the separately-prepared IC_CLR_* registers.
|
|
*/
|
|
*/
|
|
if (stat & DW_IC_INTR_RX_UNDER)
|
|
if (stat & DW_IC_INTR_RX_UNDER)
|
|
- readl(dev->base + DW_IC_CLR_RX_UNDER);
|
|
|
|
|
|
+ dw_readl(dev, DW_IC_CLR_RX_UNDER);
|
|
if (stat & DW_IC_INTR_RX_OVER)
|
|
if (stat & DW_IC_INTR_RX_OVER)
|
|
- readl(dev->base + DW_IC_CLR_RX_OVER);
|
|
|
|
|
|
+ dw_readl(dev, DW_IC_CLR_RX_OVER);
|
|
if (stat & DW_IC_INTR_TX_OVER)
|
|
if (stat & DW_IC_INTR_TX_OVER)
|
|
- readl(dev->base + DW_IC_CLR_TX_OVER);
|
|
|
|
|
|
+ dw_readl(dev, DW_IC_CLR_TX_OVER);
|
|
if (stat & DW_IC_INTR_RD_REQ)
|
|
if (stat & DW_IC_INTR_RD_REQ)
|
|
- readl(dev->base + DW_IC_CLR_RD_REQ);
|
|
|
|
|
|
+ dw_readl(dev, DW_IC_CLR_RD_REQ);
|
|
if (stat & DW_IC_INTR_TX_ABRT) {
|
|
if (stat & DW_IC_INTR_TX_ABRT) {
|
|
/*
|
|
/*
|
|
* The IC_TX_ABRT_SOURCE register is cleared whenever
|
|
* The IC_TX_ABRT_SOURCE register is cleared whenever
|
|
* the IC_CLR_TX_ABRT is read. Preserve it beforehand.
|
|
* the IC_CLR_TX_ABRT is read. Preserve it beforehand.
|
|
*/
|
|
*/
|
|
- dev->abort_source = readl(dev->base + DW_IC_TX_ABRT_SOURCE);
|
|
|
|
- readl(dev->base + DW_IC_CLR_TX_ABRT);
|
|
|
|
|
|
+ dev->abort_source = dw_readl(dev, DW_IC_TX_ABRT_SOURCE);
|
|
|
|
+ dw_readl(dev, DW_IC_CLR_TX_ABRT);
|
|
}
|
|
}
|
|
if (stat & DW_IC_INTR_RX_DONE)
|
|
if (stat & DW_IC_INTR_RX_DONE)
|
|
- readl(dev->base + DW_IC_CLR_RX_DONE);
|
|
|
|
|
|
+ dw_readl(dev, DW_IC_CLR_RX_DONE);
|
|
if (stat & DW_IC_INTR_ACTIVITY)
|
|
if (stat & DW_IC_INTR_ACTIVITY)
|
|
- readl(dev->base + DW_IC_CLR_ACTIVITY);
|
|
|
|
|
|
+ dw_readl(dev, DW_IC_CLR_ACTIVITY);
|
|
if (stat & DW_IC_INTR_STOP_DET)
|
|
if (stat & DW_IC_INTR_STOP_DET)
|
|
- readl(dev->base + DW_IC_CLR_STOP_DET);
|
|
|
|
|
|
+ dw_readl(dev, DW_IC_CLR_STOP_DET);
|
|
if (stat & DW_IC_INTR_START_DET)
|
|
if (stat & DW_IC_INTR_START_DET)
|
|
- readl(dev->base + DW_IC_CLR_START_DET);
|
|
|
|
|
|
+ dw_readl(dev, DW_IC_CLR_START_DET);
|
|
if (stat & DW_IC_INTR_GEN_CALL)
|
|
if (stat & DW_IC_INTR_GEN_CALL)
|
|
- readl(dev->base + DW_IC_CLR_GEN_CALL);
|
|
|
|
|
|
+ dw_readl(dev, DW_IC_CLR_GEN_CALL);
|
|
|
|
|
|
return stat;
|
|
return stat;
|
|
}
|
|
}
|
|
@@ -650,13 +623,19 @@ static u32 i2c_dw_read_clear_intrbits(struct dw_i2c_dev *dev)
|
|
* Interrupt service routine. This gets called whenever an I2C interrupt
|
|
* Interrupt service routine. This gets called whenever an I2C interrupt
|
|
* occurs.
|
|
* occurs.
|
|
*/
|
|
*/
|
|
-static irqreturn_t i2c_dw_isr(int this_irq, void *dev_id)
|
|
|
|
|
|
+irqreturn_t i2c_dw_isr(int this_irq, void *dev_id)
|
|
{
|
|
{
|
|
struct dw_i2c_dev *dev = dev_id;
|
|
struct dw_i2c_dev *dev = dev_id;
|
|
- u32 stat;
|
|
|
|
|
|
+ u32 stat, enabled;
|
|
|
|
+
|
|
|
|
+ enabled = dw_readl(dev, DW_IC_ENABLE);
|
|
|
|
+ stat = dw_readl(dev, DW_IC_RAW_INTR_STAT);
|
|
|
|
+ dev_dbg(dev->dev, "%s: %s enabled= 0x%x stat=0x%x\n", __func__,
|
|
|
|
+ dev->adapter.name, enabled, stat);
|
|
|
|
+ if (!enabled || !(stat & ~DW_IC_INTR_ACTIVITY))
|
|
|
|
+ return IRQ_NONE;
|
|
|
|
|
|
stat = i2c_dw_read_clear_intrbits(dev);
|
|
stat = i2c_dw_read_clear_intrbits(dev);
|
|
- dev_dbg(dev->dev, "%s: stat=0x%x\n", __func__, stat);
|
|
|
|
|
|
|
|
if (stat & DW_IC_INTR_TX_ABRT) {
|
|
if (stat & DW_IC_INTR_TX_ABRT) {
|
|
dev->cmd_err |= DW_IC_ERR_TX_ABRT;
|
|
dev->cmd_err |= DW_IC_ERR_TX_ABRT;
|
|
@@ -666,7 +645,7 @@ static irqreturn_t i2c_dw_isr(int this_irq, void *dev_id)
|
|
* Anytime TX_ABRT is set, the contents of the tx/rx
|
|
* Anytime TX_ABRT is set, the contents of the tx/rx
|
|
* buffers are flushed. Make sure to skip them.
|
|
* buffers are flushed. Make sure to skip them.
|
|
*/
|
|
*/
|
|
- writel(0, dev->base + DW_IC_INTR_MASK);
|
|
|
|
|
|
+ dw_writel(dev, 0, DW_IC_INTR_MASK);
|
|
goto tx_aborted;
|
|
goto tx_aborted;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -689,159 +668,38 @@ tx_aborted:
|
|
return IRQ_HANDLED;
|
|
return IRQ_HANDLED;
|
|
}
|
|
}
|
|
|
|
|
|
-static struct i2c_algorithm i2c_dw_algo = {
|
|
|
|
- .master_xfer = i2c_dw_xfer,
|
|
|
|
- .functionality = i2c_dw_func,
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
-static int __devinit dw_i2c_probe(struct platform_device *pdev)
|
|
|
|
|
|
+void i2c_dw_enable(struct dw_i2c_dev *dev)
|
|
{
|
|
{
|
|
- struct dw_i2c_dev *dev;
|
|
|
|
- struct i2c_adapter *adap;
|
|
|
|
- struct resource *mem, *ioarea;
|
|
|
|
- int irq, r;
|
|
|
|
-
|
|
|
|
- /* NOTE: driver uses the static register mapping */
|
|
|
|
- mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
- if (!mem) {
|
|
|
|
- dev_err(&pdev->dev, "no mem resource?\n");
|
|
|
|
- return -EINVAL;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- irq = platform_get_irq(pdev, 0);
|
|
|
|
- if (irq < 0) {
|
|
|
|
- dev_err(&pdev->dev, "no irq resource?\n");
|
|
|
|
- return irq; /* -ENXIO */
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- ioarea = request_mem_region(mem->start, resource_size(mem),
|
|
|
|
- pdev->name);
|
|
|
|
- if (!ioarea) {
|
|
|
|
- dev_err(&pdev->dev, "I2C region already claimed\n");
|
|
|
|
- return -EBUSY;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- dev = kzalloc(sizeof(struct dw_i2c_dev), GFP_KERNEL);
|
|
|
|
- if (!dev) {
|
|
|
|
- r = -ENOMEM;
|
|
|
|
- goto err_release_region;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- init_completion(&dev->cmd_complete);
|
|
|
|
- mutex_init(&dev->lock);
|
|
|
|
- dev->dev = get_device(&pdev->dev);
|
|
|
|
- dev->irq = irq;
|
|
|
|
- platform_set_drvdata(pdev, dev);
|
|
|
|
-
|
|
|
|
- dev->clk = clk_get(&pdev->dev, NULL);
|
|
|
|
- if (IS_ERR(dev->clk)) {
|
|
|
|
- r = -ENODEV;
|
|
|
|
- goto err_free_mem;
|
|
|
|
- }
|
|
|
|
- clk_enable(dev->clk);
|
|
|
|
-
|
|
|
|
- dev->base = ioremap(mem->start, resource_size(mem));
|
|
|
|
- if (dev->base == NULL) {
|
|
|
|
- dev_err(&pdev->dev, "failure mapping io resources\n");
|
|
|
|
- r = -EBUSY;
|
|
|
|
- goto err_unuse_clocks;
|
|
|
|
- }
|
|
|
|
- {
|
|
|
|
- u32 param1 = readl(dev->base + DW_IC_COMP_PARAM_1);
|
|
|
|
-
|
|
|
|
- dev->tx_fifo_depth = ((param1 >> 16) & 0xff) + 1;
|
|
|
|
- dev->rx_fifo_depth = ((param1 >> 8) & 0xff) + 1;
|
|
|
|
- }
|
|
|
|
- i2c_dw_init(dev);
|
|
|
|
-
|
|
|
|
- writel(0, dev->base + DW_IC_INTR_MASK); /* disable IRQ */
|
|
|
|
- r = request_irq(dev->irq, i2c_dw_isr, IRQF_DISABLED, pdev->name, dev);
|
|
|
|
- if (r) {
|
|
|
|
- dev_err(&pdev->dev, "failure requesting irq %i\n", dev->irq);
|
|
|
|
- goto err_iounmap;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- adap = &dev->adapter;
|
|
|
|
- i2c_set_adapdata(adap, dev);
|
|
|
|
- adap->owner = THIS_MODULE;
|
|
|
|
- adap->class = I2C_CLASS_HWMON;
|
|
|
|
- strlcpy(adap->name, "Synopsys DesignWare I2C adapter",
|
|
|
|
- sizeof(adap->name));
|
|
|
|
- adap->algo = &i2c_dw_algo;
|
|
|
|
- adap->dev.parent = &pdev->dev;
|
|
|
|
-
|
|
|
|
- adap->nr = pdev->id;
|
|
|
|
- r = i2c_add_numbered_adapter(adap);
|
|
|
|
- if (r) {
|
|
|
|
- dev_err(&pdev->dev, "failure adding adapter\n");
|
|
|
|
- goto err_free_irq;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return 0;
|
|
|
|
-
|
|
|
|
-err_free_irq:
|
|
|
|
- free_irq(dev->irq, dev);
|
|
|
|
-err_iounmap:
|
|
|
|
- iounmap(dev->base);
|
|
|
|
-err_unuse_clocks:
|
|
|
|
- clk_disable(dev->clk);
|
|
|
|
- clk_put(dev->clk);
|
|
|
|
- dev->clk = NULL;
|
|
|
|
-err_free_mem:
|
|
|
|
- platform_set_drvdata(pdev, NULL);
|
|
|
|
- put_device(&pdev->dev);
|
|
|
|
- kfree(dev);
|
|
|
|
-err_release_region:
|
|
|
|
- release_mem_region(mem->start, resource_size(mem));
|
|
|
|
-
|
|
|
|
- return r;
|
|
|
|
|
|
+ /* Enable the adapter */
|
|
|
|
+ dw_writel(dev, 1, DW_IC_ENABLE);
|
|
}
|
|
}
|
|
|
|
|
|
-static int __devexit dw_i2c_remove(struct platform_device *pdev)
|
|
|
|
|
|
+u32 i2c_dw_is_enabled(struct dw_i2c_dev *dev)
|
|
{
|
|
{
|
|
- struct dw_i2c_dev *dev = platform_get_drvdata(pdev);
|
|
|
|
- struct resource *mem;
|
|
|
|
-
|
|
|
|
- platform_set_drvdata(pdev, NULL);
|
|
|
|
- i2c_del_adapter(&dev->adapter);
|
|
|
|
- put_device(&pdev->dev);
|
|
|
|
-
|
|
|
|
- clk_disable(dev->clk);
|
|
|
|
- clk_put(dev->clk);
|
|
|
|
- dev->clk = NULL;
|
|
|
|
-
|
|
|
|
- writel(0, dev->base + DW_IC_ENABLE);
|
|
|
|
- free_irq(dev->irq, dev);
|
|
|
|
- kfree(dev);
|
|
|
|
-
|
|
|
|
- mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
- release_mem_region(mem->start, resource_size(mem));
|
|
|
|
- return 0;
|
|
|
|
|
|
+ return dw_readl(dev, DW_IC_ENABLE);
|
|
}
|
|
}
|
|
|
|
|
|
-/* work with hotplug and coldplug */
|
|
|
|
-MODULE_ALIAS("platform:i2c_designware");
|
|
|
|
|
|
+void i2c_dw_disable(struct dw_i2c_dev *dev)
|
|
|
|
+{
|
|
|
|
+ /* Disable controller */
|
|
|
|
+ dw_writel(dev, 0, DW_IC_ENABLE);
|
|
|
|
|
|
-static struct platform_driver dw_i2c_driver = {
|
|
|
|
- .remove = __devexit_p(dw_i2c_remove),
|
|
|
|
- .driver = {
|
|
|
|
- .name = "i2c_designware",
|
|
|
|
- .owner = THIS_MODULE,
|
|
|
|
- },
|
|
|
|
-};
|
|
|
|
|
|
+ /* Disable all interupts */
|
|
|
|
+ dw_writel(dev, 0, DW_IC_INTR_MASK);
|
|
|
|
+ dw_readl(dev, DW_IC_CLR_INTR);
|
|
|
|
+}
|
|
|
|
|
|
-static int __init dw_i2c_init_driver(void)
|
|
|
|
|
|
+void i2c_dw_clear_int(struct dw_i2c_dev *dev)
|
|
{
|
|
{
|
|
- return platform_driver_probe(&dw_i2c_driver, dw_i2c_probe);
|
|
|
|
|
|
+ dw_readl(dev, DW_IC_CLR_INTR);
|
|
}
|
|
}
|
|
-module_init(dw_i2c_init_driver);
|
|
|
|
|
|
|
|
-static void __exit dw_i2c_exit_driver(void)
|
|
|
|
|
|
+void i2c_dw_disable_int(struct dw_i2c_dev *dev)
|
|
{
|
|
{
|
|
- platform_driver_unregister(&dw_i2c_driver);
|
|
|
|
|
|
+ dw_writel(dev, 0, DW_IC_INTR_MASK);
|
|
}
|
|
}
|
|
-module_exit(dw_i2c_exit_driver);
|
|
|
|
|
|
|
|
-MODULE_AUTHOR("Baruch Siach <baruch@tkos.co.il>");
|
|
|
|
-MODULE_DESCRIPTION("Synopsys DesignWare I2C bus adapter");
|
|
|
|
-MODULE_LICENSE("GPL");
|
|
|
|
|
|
+u32 i2c_dw_read_comp_param(struct dw_i2c_dev *dev)
|
|
|
|
+{
|
|
|
|
+ return dw_readl(dev, DW_IC_COMP_PARAM_1);
|
|
|
|
+}
|