* [PATCH] i2c: mv64xxx: add timeout waiting for bus ready
@ 2017-08-16 10:16 Bastian Stender
2017-11-15 11:11 ` Bastian Stender
0 siblings, 1 reply; 5+ messages in thread
From: Bastian Stender @ 2017-08-16 10:16 UTC (permalink / raw)
To: barebox; +Cc: Bastian Stender
This prevents barebox hanging e.g. in case the i2c clock is accidentally
connected to GND.
Signed-off-by: Bastian Stender <bst@pengutronix.de>
---
drivers/i2c/busses/i2c-mv64xxx.c | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c
index fd1665bebb..f54d81608f 100644
--- a/drivers/i2c/busses/i2c-mv64xxx.c
+++ b/drivers/i2c/busses/i2c-mv64xxx.c
@@ -37,6 +37,8 @@
#define REG_CONTROL_TWSIEN 0x00000040
#define REG_CONTROL_INTEN 0x00000080
+#define MV46XXX_I2C_TIMEOUT (100 * MSECOND) /* transfer timeout */
+
/* Ctlr status values */
#define STATUS_MAST_START 0x08
#define STATUS_MAST_REPEAT_START 0x10
@@ -421,10 +423,11 @@ mv64xxx_i2c_do_action(struct mv64xxx_i2c_data *drv_data)
*
*****************************************************************************
*/
-static void
+static int
mv64xxx_i2c_wait_for_completion(struct mv64xxx_i2c_data *drv_data)
{
u32 status;
+ uint64_t start = get_time_ns();
do {
if (mv64xxx_read(drv_data, drv_data->reg_offsets.control) &
REG_CONTROL_IFLG) {
@@ -432,6 +435,11 @@ mv64xxx_i2c_wait_for_completion(struct mv64xxx_i2c_data *drv_data)
drv_data->reg_offsets.status);
mv64xxx_i2c_fsm(drv_data, status);
mv64xxx_i2c_do_action(drv_data);
+ } else {
+ if (is_timeout(start, MV46XXX_I2C_TIMEOUT)) {
+ dev_warn(&drv_data->adapter.dev, "timeout waiting for bus ready\n");
+ return -ETIMEDOUT;
+ }
}
if (drv_data->rc) {
drv_data->state = STATE_IDLE;
@@ -440,6 +448,8 @@ mv64xxx_i2c_wait_for_completion(struct mv64xxx_i2c_data *drv_data)
drv_data->block = false;
}
} while (drv_data->block);
+
+ return 0;
}
/*
@@ -453,7 +463,7 @@ static int
mv64xxx_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
{
struct mv64xxx_i2c_data *drv_data = container_of(adap, struct mv64xxx_i2c_data, adapter);
- int ret = num;
+ int ret;
BUG_ON(drv_data->msgs != NULL);
@@ -463,15 +473,15 @@ mv64xxx_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
drv_data->send_stop = (num == 1);
drv_data->block = true;
mv64xxx_i2c_send_start(drv_data);
- mv64xxx_i2c_wait_for_completion(drv_data);
+ ret = mv64xxx_i2c_wait_for_completion(drv_data);
- if (drv_data->rc < 0)
+ if (!ret && drv_data->rc < 0)
ret = drv_data->rc;
drv_data->num_msgs = 0;
drv_data->msgs = NULL;
- return ret;
+ return (ret < 0) ? ret : num;
}
/*
--
2.11.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] i2c: mv64xxx: add timeout waiting for bus ready
2017-08-16 10:16 [PATCH] i2c: mv64xxx: add timeout waiting for bus ready Bastian Stender
@ 2017-11-15 11:11 ` Bastian Stender
2017-11-17 8:48 ` Sascha Hauer
0 siblings, 1 reply; 5+ messages in thread
From: Bastian Stender @ 2017-11-15 11:11 UTC (permalink / raw)
To: barebox
On 08/16/2017 12:16 PM, Bastian Stender wrote:
> This prevents barebox hanging e.g. in case the i2c clock is accidentally
> connected to GND.
>
> Signed-off-by: Bastian Stender <bst@pengutronix.de>
> ---
Any thoughts on this one?
Regards,
Bastian
--
Pengutronix e.K.
Industrial Linux Solutions
http://www.pengutronix.de/
Peiner Str. 6-8, 31137 Hildesheim, Germany
Amtsgericht Hildesheim, HRA 2686
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] i2c: mv64xxx: add timeout waiting for bus ready
2017-11-15 11:11 ` Bastian Stender
@ 2017-11-17 8:48 ` Sascha Hauer
2017-11-17 9:23 ` Bastian Stender
0 siblings, 1 reply; 5+ messages in thread
From: Sascha Hauer @ 2017-11-17 8:48 UTC (permalink / raw)
To: Bastian Stender; +Cc: barebox
On Wed, Nov 15, 2017 at 12:11:03PM +0100, Bastian Stender wrote:
> On 08/16/2017 12:16 PM, Bastian Stender wrote:
> > This prevents barebox hanging e.g. in case the i2c clock is accidentally
> > connected to GND.
> >
> > Signed-off-by: Bastian Stender <bst@pengutronix.de>
> > ---
>
> Any thoughts on this one?
Patch looks fine. I must have overlooked it. Should I apply it as is?
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] i2c: mv64xxx: add timeout waiting for bus ready
2017-11-17 8:48 ` Sascha Hauer
@ 2017-11-17 9:23 ` Bastian Stender
2017-11-17 9:34 ` Sascha Hauer
0 siblings, 1 reply; 5+ messages in thread
From: Bastian Stender @ 2017-11-17 9:23 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
On 11/17/2017 09:48 AM, Sascha Hauer wrote:
> On Wed, Nov 15, 2017 at 12:11:03PM +0100, Bastian Stender wrote:
>> On 08/16/2017 12:16 PM, Bastian Stender wrote:
>>> This prevents barebox hanging e.g. in case the i2c clock is accidentally
>>> connected to GND.
>>>
>>> Signed-off-by: Bastian Stender <bst@pengutronix.de>
>>> ---
>>
>> Any thoughts on this one?
>
> Patch looks fine. I must have overlooked it. Should I apply it as
> is?
Yes, please. I did a quick test and the patch still works as expected :)
Bastian
--
Pengutronix e.K.
Industrial Linux Solutions
http://www.pengutronix.de/
Peiner Str. 6-8, 31137 Hildesheim, Germany
Amtsgericht Hildesheim, HRA 2686
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] i2c: mv64xxx: add timeout waiting for bus ready
2017-11-17 9:23 ` Bastian Stender
@ 2017-11-17 9:34 ` Sascha Hauer
0 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2017-11-17 9:34 UTC (permalink / raw)
To: Bastian Stender; +Cc: barebox
On Fri, Nov 17, 2017 at 10:23:51AM +0100, Bastian Stender wrote:
> On 11/17/2017 09:48 AM, Sascha Hauer wrote:
> > On Wed, Nov 15, 2017 at 12:11:03PM +0100, Bastian Stender wrote:
> > > On 08/16/2017 12:16 PM, Bastian Stender wrote:
> > > > This prevents barebox hanging e.g. in case the i2c clock is accidentally
> > > > connected to GND.
> > > >
> > > > Signed-off-by: Bastian Stender <bst@pengutronix.de>
> > > > ---
> > >
> > > Any thoughts on this one?
> >
> > Patch looks fine. I must have overlooked it. Should I apply it as
> > is?
>
> Yes, please. I did a quick test and the patch still works as expected :)
Ok, applied now.
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-11-17 9:34 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-16 10:16 [PATCH] i2c: mv64xxx: add timeout waiting for bus ready Bastian Stender
2017-11-15 11:11 ` Bastian Stender
2017-11-17 8:48 ` Sascha Hauer
2017-11-17 9:23 ` Bastian Stender
2017-11-17 9:34 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox