* [PATCH 0/5] i2c: i.MX driver some cleanup
@ 2019-02-27 8:19 Sascha Hauer
2019-02-27 8:19 ` [PATCH 1/5] i2c: i.MX: Do not call i2c_fsl_bus_busy twice Sascha Hauer
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Sascha Hauer @ 2019-02-27 8:19 UTC (permalink / raw)
To: Barebox List
Some small improvements for the i.MX I2C driver.
Sascha Hauer (5):
i2c: i.MX: Do not call i2c_fsl_bus_busy twice
i2c: i.MX: move disabling of controller out of i2c_fsl_stop
i2c: i.MX: Track stopped status in I2CR_MSTA bit
i2c: i.MX: consolidate code
i2c: i.MX: fix variable name
drivers/i2c/busses/i2c-imx.c | 121 +++++++++++++----------------------
1 file changed, 46 insertions(+), 75 deletions(-)
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/5] i2c: i.MX: Do not call i2c_fsl_bus_busy twice
2019-02-27 8:19 [PATCH 0/5] i2c: i.MX driver some cleanup Sascha Hauer
@ 2019-02-27 8:19 ` Sascha Hauer
2019-02-27 8:19 ` [PATCH 2/5] i2c: i.MX: move disabling of controller out of i2c_fsl_stop Sascha Hauer
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2019-02-27 8:19 UTC (permalink / raw)
To: Barebox List
In i2c_fsl_stop() we call i2c_fsl_bus_busy() a second time when it
fails. If it fails once it won't succeed the second time, so drop
the second call.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/i2c/busses/i2c-imx.c | 4 ----
1 file changed, 4 deletions(-)
diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index 67937da73a..72d9fe5845 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -342,10 +342,6 @@ static void i2c_fsl_stop(struct i2c_adapter *adapter)
fsl_i2c_write_reg(temp, i2c_fsl, FSL_I2C_I2CR);
/* wait for the stop condition to be send, otherwise the i2c
* controller is disabled before the STOP is sent completely */
- i2c_fsl->stopped = i2c_fsl_bus_busy(adapter, 0) ? 0 : 1;
- }
-
- if (!i2c_fsl->stopped) {
i2c_fsl_bus_busy(adapter, 0);
i2c_fsl->stopped = 1;
}
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/5] i2c: i.MX: move disabling of controller out of i2c_fsl_stop
2019-02-27 8:19 [PATCH 0/5] i2c: i.MX driver some cleanup Sascha Hauer
2019-02-27 8:19 ` [PATCH 1/5] i2c: i.MX: Do not call i2c_fsl_bus_busy twice Sascha Hauer
@ 2019-02-27 8:19 ` Sascha Hauer
2019-02-27 8:19 ` [PATCH 3/5] i2c: i.MX: Track stopped status in I2CR_MSTA bit Sascha Hauer
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2019-02-27 8:19 UTC (permalink / raw)
To: Barebox List
Move disabling of the controller out of i2c_fsl_stop(). This makes the
function reusable in other places in the next patch.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/i2c/busses/i2c-imx.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index 72d9fe5845..74f080dfc9 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -345,10 +345,6 @@ static void i2c_fsl_stop(struct i2c_adapter *adapter)
i2c_fsl_bus_busy(adapter, 0);
i2c_fsl->stopped = 1;
}
-
- /* Disable I2C controller, and force our state to stopped */
- temp = i2c_fsl->hwdata->i2cr_ien_opcode ^ I2CR_IEN,
- fsl_i2c_write_reg(temp, i2c_fsl, FSL_I2C_I2CR);
}
#ifdef CONFIG_PPC
@@ -609,6 +605,10 @@ fail0:
/* Stop I2C transfer */
i2c_fsl_stop(adapter);
+ /* Disable I2C controller, and force our state to stopped */
+ temp = i2c_fsl->hwdata->i2cr_ien_opcode ^ I2CR_IEN,
+ fsl_i2c_write_reg(temp, i2c_fsl, FSL_I2C_I2CR);
+
return (result < 0) ? result : num;
}
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 3/5] i2c: i.MX: Track stopped status in I2CR_MSTA bit
2019-02-27 8:19 [PATCH 0/5] i2c: i.MX driver some cleanup Sascha Hauer
2019-02-27 8:19 ` [PATCH 1/5] i2c: i.MX: Do not call i2c_fsl_bus_busy twice Sascha Hauer
2019-02-27 8:19 ` [PATCH 2/5] i2c: i.MX: move disabling of controller out of i2c_fsl_stop Sascha Hauer
@ 2019-02-27 8:19 ` Sascha Hauer
2019-02-27 8:19 ` [PATCH 4/5] i2c: i.MX: consolidate code Sascha Hauer
2019-02-27 8:19 ` [PATCH 5/5] i2c: i.MX: fix variable name Sascha Hauer
4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2019-02-27 8:19 UTC (permalink / raw)
To: Barebox List
We can track the stopped status in the I2CR_MSTA bit, no need for an
extra variable. Also we can call i2c_fsl_stop() instead of open coding
it in i2c_fsl_read().
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/i2c/busses/i2c-imx.c | 43 +++++++++++++-----------------------
1 file changed, 15 insertions(+), 28 deletions(-)
diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index 74f080dfc9..739f5b5cfd 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -168,7 +168,6 @@ struct fsl_i2c_struct {
struct clk *clk;
struct i2c_adapter adapter;
unsigned int disable_delay;
- int stopped;
unsigned int ifdr; /* FSL_I2C_IFDR */
unsigned int dfsrr; /* FSL_I2C_DFSRR */
struct i2c_bus_recovery_info rinfo;
@@ -322,8 +321,6 @@ static int i2c_fsl_start(struct i2c_adapter *adapter)
return -EAGAIN;
}
- i2c_fsl->stopped = 0;
-
temp |= I2CR_MTX | I2CR_TXAK;
fsl_i2c_write_reg(temp, i2c_fsl, FSL_I2C_I2CR);
@@ -335,16 +332,20 @@ static void i2c_fsl_stop(struct i2c_adapter *adapter)
struct fsl_i2c_struct *i2c_fsl = to_fsl_i2c_struct(adapter);
unsigned int temp = 0;
- if (!i2c_fsl->stopped) {
- /* Stop I2C transaction */
- temp = fsl_i2c_read_reg(i2c_fsl, FSL_I2C_I2CR);
- temp &= ~(I2CR_MSTA | I2CR_MTX);
- fsl_i2c_write_reg(temp, i2c_fsl, FSL_I2C_I2CR);
- /* wait for the stop condition to be send, otherwise the i2c
- * controller is disabled before the STOP is sent completely */
- i2c_fsl_bus_busy(adapter, 0);
- i2c_fsl->stopped = 1;
- }
+ /* Stop I2C transaction */
+ temp = fsl_i2c_read_reg(i2c_fsl, FSL_I2C_I2CR);
+ if (!(temp & I2CR_MSTA))
+ return;
+
+ temp &= ~(I2CR_MSTA | I2CR_MTX);
+ fsl_i2c_write_reg(temp, i2c_fsl, FSL_I2C_I2CR);
+ /* wait for the stop condition to be send, otherwise the i2c
+ * controller is disabled before the STOP is sent completely */
+
+ /* adding this delay helps on low bitrates */
+ udelay(i2c_fsl->disable_delay);
+
+ i2c_fsl_bus_busy(adapter, 0);
}
#ifdef CONFIG_PPC
@@ -534,21 +535,7 @@ static int i2c_fsl_read(struct i2c_adapter *adapter, struct i2c_msg *msgs)
return result;
if (i == (msgs->len - 1)) {
- /*
- * It must generate STOP before read I2DR to prevent
- * controller from generating another clock cycle
- */
- temp = fsl_i2c_read_reg(i2c_fsl, FSL_I2C_I2CR);
- temp &= ~(I2CR_MSTA | I2CR_MTX);
- fsl_i2c_write_reg(temp, i2c_fsl, FSL_I2C_I2CR);
-
- /*
- * adding this delay helps on low bitrates
- */
- udelay(i2c_fsl->disable_delay);
-
- i2c_fsl_bus_busy(adapter, 0);
- i2c_fsl->stopped = 1;
+ i2c_fsl_stop(adapter);
} else if (i == (msgs->len - 2)) {
temp = fsl_i2c_read_reg(i2c_fsl, FSL_I2C_I2CR);
temp |= I2CR_TXAK;
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 4/5] i2c: i.MX: consolidate code
2019-02-27 8:19 [PATCH 0/5] i2c: i.MX driver some cleanup Sascha Hauer
` (2 preceding siblings ...)
2019-02-27 8:19 ` [PATCH 3/5] i2c: i.MX: Track stopped status in I2CR_MSTA bit Sascha Hauer
@ 2019-02-27 8:19 ` Sascha Hauer
2019-02-27 8:19 ` [PATCH 5/5] i2c: i.MX: fix variable name Sascha Hauer
4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2019-02-27 8:19 UTC (permalink / raw)
To: Barebox List
We have to write to FSL_I2C_I2DR and wait for completion/ack three
times in the code. Instead of open coding it each time create a
helper function for it.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/i2c/busses/i2c-imx.c | 54 ++++++++++++++----------------------
1 file changed, 21 insertions(+), 33 deletions(-)
diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index 739f5b5cfd..7d7cb88dee 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -455,41 +455,39 @@ static void i2c_fsl_set_clk(struct fsl_i2c_struct *i2c_fsl,
}
#endif
-static int i2c_fsl_write(struct i2c_adapter *adapter, struct i2c_msg *msgs)
+static int i2c_fsl_send(struct i2c_adapter *adapter, uint8_t data)
{
struct fsl_i2c_struct *i2c_fsl = to_fsl_i2c_struct(adapter);
- int i, result;
+ int result;
- if ( !(msgs->flags & I2C_M_DATA_ONLY) ) {
- dev_dbg(&adapter->dev,
- "<%s> write slave address: addr=0x%02x\n",
- __func__, msgs->addr << 1);
+ dev_dbg(&adapter->dev, "<%s> send 0x%02x\n", __func__, data);
- /* write slave address */
- fsl_i2c_write_reg(msgs->addr << 1, i2c_fsl, FSL_I2C_I2DR);
+ fsl_i2c_write_reg(data, i2c_fsl, FSL_I2C_I2DR);
- result = i2c_fsl_trx_complete(adapter);
- if (result)
- return result;
- result = i2c_fsl_acked(adapter);
+ result = i2c_fsl_trx_complete(adapter);
+ if (result)
+ return result;
+
+ return i2c_fsl_acked(adapter);
+}
+
+static int i2c_fsl_write(struct i2c_adapter *adapter, struct i2c_msg *msgs)
+{
+ int i, result;
+
+ if (!(msgs->flags & I2C_M_DATA_ONLY)) {
+ result = i2c_fsl_send(adapter, msgs->addr << 1);
if (result)
return result;
}
/* write data */
for (i = 0; i < msgs->len; i++) {
- dev_dbg(&adapter->dev,
- "<%s> write byte: B%d=0x%02X\n",
- __func__, i, msgs->buf[i]);
- fsl_i2c_write_reg(msgs->buf[i], i2c_fsl, FSL_I2C_I2DR);
-
- result = i2c_fsl_trx_complete(adapter);
- if (result)
- return result;
- result = i2c_fsl_acked(adapter);
+ result = i2c_fsl_send(adapter, msgs->buf[i]);
if (result)
return result;
}
+
return 0;
}
@@ -503,18 +501,8 @@ static int i2c_fsl_read(struct i2c_adapter *adapter, struct i2c_msg *msgs)
fsl_i2c_write_reg(i2c_fsl->hwdata->i2sr_clr_opcode,
i2c_fsl, FSL_I2C_I2SR);
- if ( !(msgs->flags & I2C_M_DATA_ONLY) ) {
- dev_dbg(&adapter->dev,
- "<%s> write slave address: addr=0x%02x\n",
- __func__, (msgs->addr << 1) | 0x01);
-
- /* write slave address */
- fsl_i2c_write_reg((msgs->addr << 1) | 0x01, i2c_fsl, FSL_I2C_I2DR);
-
- result = i2c_fsl_trx_complete(adapter);
- if (result)
- return result;
- result = i2c_fsl_acked(adapter);
+ if (!(msgs->flags & I2C_M_DATA_ONLY)) {
+ result = i2c_fsl_send(adapter, (msgs->addr << 1) | 1);
if (result)
return result;
}
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 5/5] i2c: i.MX: fix variable name
2019-02-27 8:19 [PATCH 0/5] i2c: i.MX driver some cleanup Sascha Hauer
` (3 preceding siblings ...)
2019-02-27 8:19 ` [PATCH 4/5] i2c: i.MX: consolidate code Sascha Hauer
@ 2019-02-27 8:19 ` Sascha Hauer
4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2019-02-27 8:19 UTC (permalink / raw)
To: Barebox List
i2c_fsl_write() and i2c_fsl_read() take exactly one i2c message, not
multiple ones, hence rename the variable from "msgs" to "msg".
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/i2c/busses/i2c-imx.c | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index 7d7cb88dee..f5fc65b06e 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -471,19 +471,19 @@ static int i2c_fsl_send(struct i2c_adapter *adapter, uint8_t data)
return i2c_fsl_acked(adapter);
}
-static int i2c_fsl_write(struct i2c_adapter *adapter, struct i2c_msg *msgs)
+static int i2c_fsl_write(struct i2c_adapter *adapter, struct i2c_msg *msg)
{
int i, result;
- if (!(msgs->flags & I2C_M_DATA_ONLY)) {
- result = i2c_fsl_send(adapter, msgs->addr << 1);
+ if (!(msg->flags & I2C_M_DATA_ONLY)) {
+ result = i2c_fsl_send(adapter, msg->addr << 1);
if (result)
return result;
}
/* write data */
- for (i = 0; i < msgs->len; i++) {
- result = i2c_fsl_send(adapter, msgs->buf[i]);
+ for (i = 0; i < msg->len; i++) {
+ result = i2c_fsl_send(adapter, msg->buf[i]);
if (result)
return result;
}
@@ -491,7 +491,7 @@ static int i2c_fsl_write(struct i2c_adapter *adapter, struct i2c_msg *msgs)
return 0;
}
-static int i2c_fsl_read(struct i2c_adapter *adapter, struct i2c_msg *msgs)
+static int i2c_fsl_read(struct i2c_adapter *adapter, struct i2c_msg *msg)
{
struct fsl_i2c_struct *i2c_fsl = to_fsl_i2c_struct(adapter);
int i, result;
@@ -501,8 +501,8 @@ static int i2c_fsl_read(struct i2c_adapter *adapter, struct i2c_msg *msgs)
fsl_i2c_write_reg(i2c_fsl->hwdata->i2sr_clr_opcode,
i2c_fsl, FSL_I2C_I2SR);
- if (!(msgs->flags & I2C_M_DATA_ONLY)) {
- result = i2c_fsl_send(adapter, (msgs->addr << 1) | 1);
+ if (!(msg->flags & I2C_M_DATA_ONLY)) {
+ result = i2c_fsl_send(adapter, (msg->addr << 1) | 1);
if (result)
return result;
}
@@ -510,29 +510,29 @@ static int i2c_fsl_read(struct i2c_adapter *adapter, struct i2c_msg *msgs)
/* setup bus to read data */
temp = fsl_i2c_read_reg(i2c_fsl, FSL_I2C_I2CR);
temp &= ~I2CR_MTX;
- if (msgs->len - 1)
+ if (msg->len - 1)
temp &= ~I2CR_TXAK;
fsl_i2c_write_reg(temp, i2c_fsl, FSL_I2C_I2CR);
fsl_i2c_read_reg(i2c_fsl, FSL_I2C_I2DR); /* dummy read */
/* read data */
- for (i = 0; i < msgs->len; i++) {
+ for (i = 0; i < msg->len; i++) {
result = i2c_fsl_trx_complete(adapter);
if (result)
return result;
- if (i == (msgs->len - 1)) {
+ if (i == (msg->len - 1)) {
i2c_fsl_stop(adapter);
- } else if (i == (msgs->len - 2)) {
+ } else if (i == (msg->len - 2)) {
temp = fsl_i2c_read_reg(i2c_fsl, FSL_I2C_I2CR);
temp |= I2CR_TXAK;
fsl_i2c_write_reg(temp, i2c_fsl, FSL_I2C_I2CR);
}
- msgs->buf[i] = fsl_i2c_read_reg(i2c_fsl, FSL_I2C_I2DR);
+ msg->buf[i] = fsl_i2c_read_reg(i2c_fsl, FSL_I2C_I2DR);
dev_dbg(&adapter->dev, "<%s> read byte: B%d=0x%02X\n",
- __func__, i, msgs->buf[i]);
+ __func__, i, msg->buf[i]);
}
return 0;
}
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-02-27 8:20 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-27 8:19 [PATCH 0/5] i2c: i.MX driver some cleanup Sascha Hauer
2019-02-27 8:19 ` [PATCH 1/5] i2c: i.MX: Do not call i2c_fsl_bus_busy twice Sascha Hauer
2019-02-27 8:19 ` [PATCH 2/5] i2c: i.MX: move disabling of controller out of i2c_fsl_stop Sascha Hauer
2019-02-27 8:19 ` [PATCH 3/5] i2c: i.MX: Track stopped status in I2CR_MSTA bit Sascha Hauer
2019-02-27 8:19 ` [PATCH 4/5] i2c: i.MX: consolidate code Sascha Hauer
2019-02-27 8:19 ` [PATCH 5/5] i2c: i.MX: fix variable name Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox