Skip to contentSkip to conversation

i2c-mpc: generate START condition after STOP caused by read i2c_msg

PATCH In review Esben Haabendal 12 participants 22 messages May 19, 2009 – Dec 4, 2009 12 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 i2c-mpc: generate START condition after STOP caused by read i2c_msg

This fixes MAL (arbitration lost) bug caused by illegal use of RSTA (repeated START) after STOP condition generated after last byte of reads. With this patch, it is possible to do an i2c_transfer() with additional i2c_msg's following the I2C_M_RD messages.

It still needs to be resolved if it is possible to fix this issue by removing the STOP condition after reads in a robust way.

---
 drivers/i2c/busses/i2c-mpc.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-mpc.c +7 -2
index 4af5c09..0199f9a 100644
@@ -456,17 +456,22 @@ static int mpc_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
 	}
 
 	for (i = 0; ret >= 0 && i < num; i++) {
+		int restart = i;
 		pmsg = &msgs[i];
 		dev_dbg(i2c->dev,
 			"Doing %s %d bytes to 0x%02x - %d of %d messages\n",
 			pmsg->flags & I2C_M_RD ? "read" : "write",
 			pmsg->len, pmsg->addr, i + 1, num);
+		if (i > 0 && ((pmsg - 1)->flags & I2C_M_RD))
+			restart = 0;
 		if (pmsg->flags & I2C_M_RD)
 			ret =
-			    mpc_read(i2c, pmsg->addr, pmsg->buf, pmsg->len, i);
+			    mpc_read(i2c, pmsg->addr, pmsg->buf, pmsg->len,
+				     restart);
 		else
 			ret =
-			    mpc_write(i2c, pmsg->addr, pmsg->buf, pmsg->len, i);
+			    mpc_write(i2c, pmsg->addr, pmsg->buf, pmsg->len,
+				      restart);
 	}
 	mpc_i2c_stop(i2c);
 	return (ret < 0) ? ret : num;
Signature · 1 line
1.6.3.1
#1 lore raw
Quoted 5 lines · Esben Haabendal

This fixes MAL (arbitration lost) bug caused by illegal use of RSTA (repeated START) after STOP condition generated after last byte of reads. With this patch, it is possible to do an i2c_transfer() with additional i2c_msg's following the I2C_M_RD messages.

Quoted 7 lines

It still needs to be resolved if it is possible to fix this issue by removing the STOP condition after reads in a robust way.

---
 drivers/i2c/busses/i2c-mpc.c |    9 +++++++--

 1 files changed, 7 insertions(+), 2 deletions(-)

Any blockers to get this accepted?

/Esben

A message that is not in the archive (sent off-list or not yet received): d2b9ea600905260430i72290901p9266de4cade049c1-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#3 lore raw
Quoted 9 lines · Esben Haabendal
Quoted 8 lines · Esben Haabendal

This fixes MAL (arbitration lost) bug caused by illegal use of RSTA (repeated START) after STOP condition generated after last byte of reads. With this patch, it is possible to do an i2c_transfer() with additional i2c_msg's following the I2C_M_RD messages.

It still needs to be resolved if it is possible to fix this issue by removing the STOP condition after reads in a robust way.

Quoted 6 lines
Quoted 4 lines

---
?drivers/i2c/busses/i2c-mpc.c | ? ?9 +++++++--
?1 files changed, 7 insertions(+), 2 deletions(-)

Any blockers to get this accepted?

It would be nice to get an ack from someone who can actually test the driver before getting this merged.

Quoted 5 lines

/Esben
--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 3 lines
Ben ([email protected], http://www.fluff.org/)

  'a smiley only costs 4 bytes'

A message that is not in the archive (sent off-list or not yet received): [email protected]

#5 lore raw
Quoted 4 lines
Quoted 1 line

Any blockers to get this accepted?

It would be nice to get an ack from someone who can actually test the driver before getting this merged.

I wanted to test it, but it does not apply due to line breaks (check @@-line). Also, I don't really have the time to dig into the topic, so I would only test it and give a tested-by-tag if it doesn't break anything here. I think Joakim would be a good candidate for an acked-by .

Signature · 2 lines
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

A message that is not in the archive (sent off-list or not yet received): [email protected]

#7 lore raw

Wolfram Sang <[email protected]> wrote on 28/05/2009 19:17:26:

Quoted 10 lines
Quoted 5 lines
Quoted 2 lines

Any blockers to get this accepted?

It would be nice to get an ack from someone who can actually test the driver before getting this merged.

I wanted to test it, but it does not apply due to line breaks (check @@-line). Also, I don't really have the time to dig into the topic, so I would only test it and give a tested-by-tag if it doesn't break anything here. I think Joakim would be a good candidate for an acked-by .

It sure looks OK, even at a closer look :)

#8 lore raw
In reply to Wolfram Sang
Quoted 9 lines · Wolfram Sang
Quoted 4 lines
Quoted 1 line

Any blockers to get this accepted?

It would be nice to get an ack from someone who can actually test the driver before getting this merged.

I wanted to test it, but it does not apply due to line breaks (check @@-line). Also, I don't really have the time to dig into the topic, so I would only test it and give a tested-by-tag if it doesn't break anything here. I think Joakim would be a good candidate for an acked-by .

I've checked both my copy in my "Sent" folder and the copy received from the list,
and I cannot see any "line break" breakage of the patch.

It must be your mail client that is messing with it, so I cannot really do it much better in that way.

If necessary, I can push a branch to a public repo you can pull from.

/Esben

A message that is not in the archive (sent off-list or not yet received): d2b9ea600905281310p16f47ed0i454e25bf256d3010-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#10 lore raw
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Esben" == Esben Haabendal <[email protected]> writes:

Hi,

Quoted 4 lines
Quoted 4 lines

I wanted to test it, but it does not apply due to line breaks (check @@-line). Also, I don't really have the time to dig into the topic, so I would only test it and give a tested-by-tag if it doesn't break anything here. I think Joakim would be a good candidate for an acked-by .

Esben> I've checked both my copy in my "Sent" folder and the copy Esben> received from the list, and I cannot see any "line break" Esben> breakage of the patch.

I guess Wolfram referred to the context line which was clearly word wrapped:

@@ -456,17 +456,22 @@ static int mpc_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)

The other lines look fine.

Signature · 1 line
Bye, Peter Korsgaard

A message that is not in the archive (sent off-list or not yet received): 87ws8155md.fsf-uXGAPMMVk8amE9MCos8gUmSdvHPH+/[email protected]

#12 lore raw
Quoted 10 lines

 Esben> I've checked both my copy in my "Sent" folder and the copy Esben> received from the list, and I cannot see any "line break" Esben> breakage of the patch.

I guess Wolfram referred to the context line which was clearly word wrapped:

(quoted diff) +0 -0
@@ -456,17 +456,22 @@ static int mpc_xfer(struct i2c_adapter *adap,
 struct i2c_msg *msgs, int num)
 

The other lines look fine.

It's strange, that line looks perfectly fine when I check the mail in my GMail inbox and the outbox from the account I sent it from.

/Esben

Signature · 4 lines
Esben Haabendal, Senior Software Consultant
DoréDevelopment ApS, Ved Stranden 1, 9560 Hadsund, DK-Denmark
Phone: +45 51 92 53 93, E-mail: eha-SIcX2qgNSybd/[email protected]
WWW: http://www.doredevelopment.dk

A message that is not in the archive (sent off-list or not yet received): d2b9ea600905281341s24efa4e3l6277a8aa5dec5bd-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#14 lore raw
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Esben" == Esben Haabendal <[email protected]> writes:

Hi,

Esben> It's strange, that line looks perfectly fine when I check the Esben> mail in my GMail inbox and the outbox from the account I sent Esben> it from.

Well, it is here and in the archive:
http://ozlabs.org/pipermail/linuxppc-dev/2009-May/072274.html

Please consider using git send-email for patches.

Signature · 1 line
Bye, Peter Korsgaard

A message that is not in the archive (sent off-list or not yet received): 87octd5415.fsf-uXGAPMMVk8amE9MCos8gUmSdvHPH+/[email protected]

#16 lore raw
Quoted 12 lines · Peter Korsgaard
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

"Esben" == Esben Haabendal <[email protected]> writes:

Hi,

Esben> It's strange, that line looks perfectly fine when I check the Esben> mail in my GMail inbox and the outbox from the account I sent Esben> it from.

Well, it is here and in the archive:
http://ozlabs.org/pipermail/linuxppc-dev/2009-May/072274.html

If you look at
http://www.mail-archive.com/[email protected]/msg01050.html
instead, the patch is not broken. I find it more likely that the ozlabs.org archive is breaking my lines, than mail-archive.com putting broken lines together again.

Quoted 2 lines

Please consider using git send-email for patches.

I used git imap-send and thunderbird to do it.

I will consider git send-email in the future, although I don't think my original e-mail were broken ;-)

But

#17 lore raw
In reply to a message not in the archive

Ben Dooks said the following:

Quoted 15 lines · Esben Haabendal
Quoted 14 lines · Esben Haabendal
Quoted 12 lines

This fixes MAL (arbitration lost) bug caused by illegal use of RSTA (repeated START) after STOP condition generated after last byte of reads. With this patch, it is possible to do an i2c_transfer() with additional i2c_msg's following the I2C_M_RD messages.

It still needs to be resolved if it is possible to fix this issue by removing the STOP condition after reads in a robust way.

---
?drivers/i2c/busses/i2c-mpc.c | ? ?9 +++++++--
?1 files changed, 7 insertions(+), 2 deletions(-)

Quoted 5 lines
Quoted 1 line

Any blockers to get this accepted?

It would be nice to get an ack from someone who can actually test the driver before getting this merged.

What is the state of this patch?
Shouldn't we attack the problem on a more general way by inventing a Flag I2C_M_RESTART (or better I2C_M_NO_RESTART for backward compatibility)? This way the client driver is able to decide what it needs. If we do the choice within adapter, chance is about 50% to be wrong.

Just my 2 Cents.

Signature · 1 line
Michael

A message that is not in the archive (sent off-list or not yet received): [email protected]

#19 lore raw
Quoted 18 lines · Michael Lawnick

Ben Dooks said the following:

Quoted 17 lines · Esben Haabendal
Quoted 15 lines · Esben Haabendal
Quoted 5 lines

This fixes MAL (arbitration lost) bug caused by illegal use of RSTA (repeated START) after STOP condition generated after last byte of reads. With this patch, it is possible to do an i2c_transfer() with additional i2c_msg's following the I2C_M_RD messages.

Quoted 7 lines

It still needs to be resolved if it is possible to fix this issue by removing the STOP condition after reads in a robust way.

---
?drivers/i2c/busses/i2c-mpc.c | ? ?9 +++++++--
?1 files changed, 7 insertions(+), 2 deletions(-)

Any blockers to get this accepted?

Quoted 8 lines
Quoted 3 lines

It would be nice to get an ack from someone who can actually test the driver before getting this merged.

What is the state of this patch?
Shouldn't we attack the problem on a more general way by inventing a Flag I2C_M_RESTART (or better I2C_M_NO_RESTART for backward compatibility)? This way the client driver is able to decide what it needs. If we do the choice within adapter, chance is about 50% to be wrong.

The documentation for 'struct i2c_msg' already says the STOP should only be generated for the last message of the transfer. If STOP is being generated for a message that isn't the last in the transfer than this is incorrect behaviour.

Unless otherwise indicated, I'll put the patch in the series that I'll send to Linus early next week.

Signature · 4 lines
Ben

Q:      What's a light-year?
A:      One-third less calories than a regular year.

A message that is not in the archive (sent off-list or not yet received): 20091203152916.GC23152-SMNkleLxa3Z6Wcw2j4pizdi2O/[email protected]

#21 lore raw
Quoted 29 lines · Michael Lawnick
Quoted 18 lines

Ben Dooks said the following:

Quoted 17 lines · Esben Haabendal
Quoted 15 lines · Esben Haabendal
Quoted 5 lines

This fixes MAL (arbitration lost) bug caused by illegal use of RSTA (repeated START) after STOP condition generated after last byte of reads. With this patch, it is possible to do an i2c_transfer() with additional i2c_msg's following the I2C_M_RD messages.

Quoted 7 lines

It still needs to be resolved if it is possible to fix this issue by removing the STOP condition after reads in a robust way.

---
?drivers/i2c/busses/i2c-mpc.c | ? ?9 +++++++--
?1 files changed, 7 insertions(+), 2 deletions(-)

Any blockers to get this accepted?

Quoted 8 lines
Quoted 3 lines

It would be nice to get an ack from someone who can actually test the driver before getting this merged.

What is the state of this patch?
Shouldn't we attack the problem on a more general way by inventing a Flag I2C_M_RESTART (or better I2C_M_NO_RESTART for backward compatibility)? This way the client driver is able to decide what it needs. If we do the choice within adapter, chance is about 50% to be wrong.

Quoted 7 lines

The documentation for 'struct i2c_msg' already says the STOP should only be generated for the last message of the transfer. If STOP is being generated for a message that isn't the last in the transfer than this is incorrect behaviour.

Unless otherwise indicated, I'll put the patch in the series that I'll send to Linus early next week.

Don't, already fixed properly and in Linus tree already.

#22 lore raw
In reply to a message not in the archive

Ben Dooks said the following:

Quoted 28 lines · Michael Lawnick
Quoted 18 lines

Ben Dooks said the following:

Quoted 17 lines · Esben Haabendal
Quoted 15 lines · Esben Haabendal
Quoted 5 lines

This fixes MAL (arbitration lost) bug caused by illegal use of RSTA (repeated START) after STOP condition generated after last byte of reads. With this patch, it is possible to do an i2c_transfer() with additional i2c_msg's following the I2C_M_RD messages.

Quoted 7 lines

It still needs to be resolved if it is possible to fix this issue by removing the STOP condition after reads in a robust way.

---
?drivers/i2c/busses/i2c-mpc.c | ? ?9 +++++++--
?1 files changed, 7 insertions(+), 2 deletions(-)

Any blockers to get this accepted?

Quoted 8 lines
Quoted 3 lines

It would be nice to get an ack from someone who can actually test the driver before getting this merged.

What is the state of this patch?
Shouldn't we attack the problem on a more general way by inventing a Flag I2C_M_RESTART (or better I2C_M_NO_RESTART for backward compatibility)? This way the client driver is able to decide what it needs. If we do the choice within adapter, chance is about 50% to be wrong.

Quoted 4 lines

The documentation for 'struct i2c_msg' already says the STOP should only be generated for the last message of the transfer. If STOP is being generated for a message that isn't the last in the transfer than this is incorrect behaviour.

Ah, now I see, this is a mpc-only problem of implementation (automatically generating stop in read function).
I couldn't find the above mentioned specification of STOP/RESTART (seems I need new glasses) and was worried about whether my own implementation for OCTEON is correct.

Thank you.

Signature · 1 line
Michael
#23 lore raw
In reply to Michael Lawnick
Quoted 19 lines

Ben Dooks said the following:

Quoted 17 lines · Esben Haabendal
Quoted 15 lines · Esben Haabendal
Quoted 5 lines

This fixes MAL (arbitration lost) bug caused by illegal use of RSTA (repeated START) after STOP condition generated after last byte of reads. With this patch, it is possible to do an i2c_transfer() with additional i2c_msg's following the I2C_M_RD messages.

Quoted 7 lines

It still needs to be resolved if it is possible to fix this issue by removing the STOP condition after reads in a robust way.

---
?drivers/i2c/busses/i2c-mpc.c | ? ?9 +++++++--
?1 files changed, 7 insertions(+), 2 deletions(-)

Any blockers to get this accepted?

Quoted 8 lines
Quoted 3 lines

It would be nice to get an ack from someone who can actually test the driver before getting this merged.

What is the state of this patch?
Shouldn't we attack the problem on a more general way by inventing a Flag I2C_M_RESTART (or better I2C_M_NO_RESTART for backward compatibility)? This way the client driver is able to decide what it needs. If we do the choice within adapter, chance is about 50% to be wrong.

I have sent another patch (which I think is in Linus tree already) that fixes the problem properly.

Can't remember if the driver handles M_RESTART or not. That is a separate issue though.

Jocke

#24 lore raw
In reply to a message not in the archive
Quoted 9 lines · Esben Haabendal
Quoted 8 lines · Esben Haabendal

This fixes MAL (arbitration lost) bug caused by illegal use of RSTA (repeated START) after STOP condition generated after last byte of reads. With this patch, it is possible to do an i2c_transfer() with additional i2c_msg's following the I2C_M_RD messages.

It still needs to be resolved if it is possible to fix this issue by removing the STOP condition after reads in a robust way.

Quoted 6 lines
Quoted 4 lines

---
 drivers/i2c/busses/i2c-mpc.c |    9 +++++++--

 1 files changed, 7 insertions(+), 2 deletions(-)

Any blockers to get this accepted?

It helps if you cc: developers/maintainers of the device. ie. Kumar for mpc8xxx, me for 52xx.

This is the first time I noticed your posting. It will take me a few days before I get a chance to review it.

g.

Signature · 2 lines
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.

A message that is not in the archive (sent off-list or not yet received): fa686aa40905281231o26c74a13v250bcedbd066e77b-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#26 lore raw
Quoted 15 lines · Grant Likely
Quoted 14 lines · Esben Haabendal
Quoted 12 lines · Esben Haabendal

This fixes MAL (arbitration lost) bug caused by illegal use of RSTA (repeated START) after STOP condition generated after last byte of reads. With this patch, it is possible to do an i2c_transfer() with additional i2c_msg's following the I2C_M_RD messages.

It still needs to be resolved if it is possible to fix this issue by removing the STOP condition after reads in a robust way.

---
 drivers/i2c/busses/i2c-mpc.c |    9 +++++++--

 1 files changed, 7 insertions(+), 2 deletions(-)
Quoted 7 lines
Quoted 1 line

Any blockers to get this accepted?

It helps if you cc: developers/maintainers of the device.  ie. Kumar for mpc8xxx, me for 52xx.

This is the first time I noticed your posting.  It will take me a few days before I get a chance to review it.

Kumar, will you take a look at this patch?

/Esben

#27 lore raw
Quoted 18 lines · Esben Haabendal
Quoted 17 lines · Grant Likely
Quoted 15 lines · Esben Haabendal
Quoted 5 lines · Esben Haabendal

This fixes MAL (arbitration lost) bug caused by illegal use of RSTA (repeated START) after STOP condition generated after last byte of reads. With this patch, it is possible to do an i2c_transfer() with additional i2c_msg's following the I2C_M_RD messages.

Quoted 7 lines

It still needs to be resolved if it is possible to fix this issue by removing the STOP condition after reads in a robust way.

---
?drivers/i2c/busses/i2c-mpc.c | ? ?9 +++++++--
?1 files changed, 7 insertions(+), 2 deletions(-)

Any blockers to get this accepted?

Quoted 7 lines
Quoted 5 lines

It helps if you cc: developers/maintainers of the device. ?ie. Kumar for mpc8xxx, me for 52xx.

This is the first time I noticed your posting. ?It will take me a few days before I get a chance to review it.

Kumar, will you take a look at this patch?

is anyone else likely to review it, or should I merge?

Signature · 3 lines
Ben ([email protected], http://www.fluff.org/)

  'a smiley only costs 4 bytes'
#28 lore raw
In reply to Esben Haabendal

Hi Esben and Ben,

Sorry for the lateness in reviewing this. FWIW, here are my comments.

g.

Quoted 35 lines · Esben Haabendal

This fixes MAL (arbitration lost) bug caused by illegal use of RSTA (repeated START) after STOP condition generated after last byte of reads. With this patch, it is possible to do an i2c_transfer() with additional i2c_msg's following the I2C_M_RD messages.

It still needs to be resolved if it is possible to fix this issue by removing the STOP condition after reads in a robust way.

---
 drivers/i2c/busses/i2c-mpc.c |    9 +++++++--

 1 files changed, 7 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-mpc.c +3 -0
index 4af5c09..0199f9a 100644
@@ -456,17 +456,22 @@ static int mpc_xfer(struct i2c_adapter *adap, struct
 i2c_msg *msgs, int num)
        }
 
        for (i = 0; ret >= 0 && i < num; i++) {
+               int restart = i;
                pmsg = &msgs[i];
                dev_dbg(i2c->dev,
                        "Doing %s %d bytes to 0x%02x - %d of %d messages\n",
                        pmsg->flags & I2C_M_RD ? "read" : "write",
                        pmsg->len, pmsg->addr, i + 1, num);
+               if (i > 0 && ((pmsg - 1)->flags & I2C_M_RD))
+                       restart = 0;
                if (pmsg->flags & I2C_M_RD)

                       ret =
-                           mpc_read(i2c, pmsg->addr, pmsg->buf, pmsg->len, i);
+                           mpc_read(i2c, pmsg->addr, pmsg->buf, pmsg->len,

Quoted 8 lines

+                                    restart);
               else
                       ret =
-                           mpc_write(i2c, pmsg->addr, pmsg->buf, pmsg->len, i);
+                           mpc_write(i2c, pmsg->addr, pmsg->buf, pmsg->len,
+                                     restart);
       }

Hmmm, seems to be a rather convoluted code path. Surely this could be handled in a clearer way. The whole (pmsg - 1) bit raises my eyebrows (I'd rather see msgs[i-1]). At the very least this deserves an comment describing what it is doing. The following might be better for the next person who has to read this code:

+      int restart = 0;
       for (i = 0; ret >= 0 && i < num; i++) {
               pmsg = &msgs[i];
               dev_dbg(i2c->dev,
                       "Doing %s %d bytes to 0x%02x - %d of %d messages\n",
                       pmsg->flags & I2C_M_RD ? "read" : "write",
                       pmsg->len, pmsg->addr, i + 1, num);
               if (pmsg->flags & I2C_M_RD)
                       ret =

- mpc_read(i2c, pmsg->addr, pmsg->buf, pmsg->len,
i);
+ mpc_read(i2c, pmsg->addr, pmsg->buf, pmsg->len,
+ restart);
else
ret =
- mpc_write(i2c, pmsg->addr, pmsg->buf, pmsg->len,
i);
+ mpc_write(i2c, pmsg->addr, pmsg->buf, pmsg->len,
+ restart);
+ /* Only set the restart flag if this was not an
I2C_M_RD transaction
+ * because it causes an illegal use of
+ * RSTA (repeated START) after STOP condition
generated after last byte
+ * of reads */

+               restart = (pmsg->flags & I2C_M_RD == 0);
       }

g.

Signature · 2 lines
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
#29 lore raw
Quoted 77 lines · Grant Likely

Hi Esben and Ben,

Sorry for the lateness in reviewing this.  FWIW, here are my comments.

g.

Quoted 35 lines · Esben Haabendal

This fixes MAL (arbitration lost) bug caused by illegal use of RSTA (repeated START) after STOP condition generated after last byte of reads. With this patch, it is possible to do an i2c_transfer() with additional i2c_msg's following the I2C_M_RD messages.

It still needs to be resolved if it is possible to fix this issue by removing the STOP condition after reads in a robust way.

---
 drivers/i2c/busses/i2c-mpc.c |    9 +++++++--

 1 files changed, 7 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-mpc.c +3 -0
index 4af5c09..0199f9a 100644
@@ -456,17 +456,22 @@ static int mpc_xfer(struct i2c_adapter *adap, struct
 i2c_msg *msgs, int num)
        }
 
        for (i = 0; ret >= 0 && i < num; i++) {
+               int restart = i;
                pmsg = &msgs[i];
                dev_dbg(i2c->dev,
                        "Doing %s %d bytes to 0x%02x - %d of %d messages\n",
                        pmsg->flags & I2C_M_RD ? "read" : "write",
                        pmsg->len, pmsg->addr, i + 1, num);
+               if (i > 0 && ((pmsg - 1)->flags & I2C_M_RD))
+                       restart = 0;
                if (pmsg->flags & I2C_M_RD)

                       ret =
-                           mpc_read(i2c, pmsg->addr, pmsg->buf, pmsg->len, i);
+                           mpc_read(i2c, pmsg->addr, pmsg->buf, pmsg->len,

Quoted 8 lines

+                                    restart);
               else
                       ret =
-                           mpc_write(i2c, pmsg->addr, pmsg->buf, pmsg->len, i);
+                           mpc_write(i2c, pmsg->addr, pmsg->buf, pmsg->len,
+                                     restart);
       }

Hmmm, seems to be a rather convoluted code path.  Surely this could be handled in a clearer way.  The whole (pmsg - 1) bit raises my eyebrows (I'd rather see msgs[i-1]).  At the very least this deserves an comment describing what it is doing.  The following might be better for the next person who has to read this code:

+      int restart = 0;
      for (i = 0; ret >= 0 && i < num; i++) {
              pmsg = &msgs[i];
              dev_dbg(i2c->dev,
                      "Doing %s %d bytes to 0x%02x - %d of %d messages\n", pmsg->flags & I2C_M_RD ? "read" : "write", pmsg->len, pmsg->addr, i + 1, num);
              if (pmsg->flags & I2C_M_RD)
                      ret =
-                           mpc_read(i2c, pmsg->addr, pmsg->buf, pmsg->len, i);
+                           mpc_read(i2c, pmsg->addr, pmsg->buf, pmsg->len,
+                                    restart);
              else
                      ret =
-                           mpc_write(i2c, pmsg->addr, pmsg->buf, pmsg->len, i);
+                           mpc_write(i2c, pmsg->addr, pmsg->buf, pmsg->len,
+                                     restart);

Quoted 8 lines

+               /* Only set the restart flag if this was not an I2C_M_RD transaction
+                * because it causes an illegal use of
+                * RSTA (repeated START) after STOP condition generated after last byte
+                * of reads  */
+               restart = (pmsg->flags & I2C_M_RD == 0); }

BTW, since you're touching these lines anyway, please clean up the whitespace usage. Since you have to break the line anyway, it no longer makes sense for the "ret = " to be on a separate line anymore.

g.

Signature · 2 lines
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.

A message that is not in the archive (sent off-list or not yet received): 4A124202.4010201-SIcX2qgNSybd/[email protected]

#31 lore raw

is there a new version of this patch available?

Signature · 3 lines
Ben ([email protected], http://www.fluff.org/)

  'a smiley only costs 4 bytes'

A message that is not in the archive (sent off-list or not yet received): [email protected]

#33 lore raw
Quoted 3 lines · Ben Dooks

is there a new version of this patch available?

I will catch up on it ASAP.

/Esben