i2c: Match parameters of i2c_start_transfer and i2c_send_recv
v2 cover i2c: Match parameters of i2c_start_transfer and i2c_send_recv
This is v2 of Zoltan's patch:
https://www.mail-archive.com/[email protected]/msg714711.html
- rebased
- added docstring
- include hw/misc/auxbus.c fix
Supersedes: <[email protected]>
BALATON Zoltan (2):
i2c: Match parameters of i2c_start_transfer and i2c_send_recv
i2c: Make i2c_start_transfer() direction argument a boolean
Philippe Mathieu-Daudé (1):
hw/misc/auxbus: Fix MOT/classic I2C mode
include/hw/i2c/i2c.h | 22 ++++++++++++++++++++-- hw/display/sm501.c | 4 ++-- hw/i2c/core.c | 36 ++++++++++++++++++------------------ hw/i2c/ppc4xx_i2c.c | 2 +- hw/misc/auxbus.c | 10 +++++----- 5 files changed, 46 insertions(+), 28 deletions(-)
Signature · 1 line
2.21.3
PATCH v2 1/3 i2c: Match parameters of i2c_start_transfer and i2c_send_recv
From: BALATON Zoltan <[email protected]>
These functions have a parameter that decides the direction of transfer but totally confusingly they don't match but inverted sense. To avoid frequent mistakes when using these functions change i2c_send_recv to match i2c_start_transfer.
Rename i2c_send_recv() as i2c_recv_send() and rename the 'send' argument as 'is_recv' (its boolean opposite). Invert the logic in i2c_recv_send() to not use inverted boolean value check.
Message-Id: <[email protected]>
--- include/hw/i2c/i2c.h | 11 ++++++++++- hw/display/sm501.c | 4 ++-- hw/i2c/core.c | 32 ++++++++++++++++---------------- hw/i2c/ppc4xx_i2c.c | 2 +- hw/misc/auxbus.c | 4 ++-- 5 files changed, 31 insertions(+), 22 deletions(-)
include/hw/i2c/i2c.h +10 -1
@@ -75,7 +75,16 @@ int i2c_bus_busy(I2CBus *bus);int i2c_start_transfer (I2CBus *bus,uint8_t address,int recv);void i2c_end_transfer (I2CBus *bus);void i2c_nack (I2CBus *bus); -int i2c_send_recv (I2CBus *bus,uint8_t *data,bool send); +/** +* i2c_recv_send: receive from or send to an I2C bus. +* +* @bus: #I2CBus to be used +* @data: buffer with the data transferred +* @is_recv: indicates the transfer direction +* +* Returns: 0 on success, -1 on error +*/ +int i2c_recv_send (I2CBus *bus,uint8_t *data,bool is_recv);int i2c_send (I2CBus *bus,uint8_t data);uint8_t i2c_recv (I2CBus *bus);
hw/display/sm501.c +2 -2
@@ -1040,8 +1040,8 @@ static void sm501_i2c_write(void *opaque, hwaddr addr, uint64_t value,SM501_DPRINTF ("sm501 i2c : transferring %d bytes to 0x%x\n" , s->i2c_byte_count +1 , s->i2c_addr >>1 );for (i =0 ; i <= s->i2c_byte_count; i++) { - res =i2c_send_recv (s->i2c_bus, &s->i2c_data[i], - !(s->i2c_addr &1 )); + res =i2c_recv_send (s->i2c_bus, &s->i2c_data[i], + s->i2c_addr &1 );if (res) {SM501_DPRINTF ("sm501 i2c : transfer failed" " i=%d, res=%d\n" , i, res);
hw/i2c/core.c +16 -16
@@ -175,26 +175,14 @@ void i2c_end_transfer(I2CBus *bus) bus->broadcast = false; } -int i2c_send_recv (I2CBus *bus,uint8_t *data,bool send) +int i2c_recv_send (I2CBus *bus,uint8_t *data,bool is_recv) {I2CSlaveClass *sc;I2CSlave *s;I2CNode *node;int ret =0 ; -if (send) { - QLIST_FOREACH(node, &bus->current_devs, next) { - s = node->elt; - sc =I2C_SLAVE_GET_CLASS (s); -if (sc->send) { -trace_i2c_send (s->address, *data); - ret = ret || sc->send (s, *data); - }else { - ret =-1 ; - } - } -return ret ?-1 :0 ; - }else { +if (is_recv) { ret =0xff ;if (!QLIST_EMPTY (&bus->current_devs) && !bus->broadcast) { sc =I2C_SLAVE_GET_CLASS (QLIST_FIRST (&bus->current_devs)->elt);
@@ -206,19 +194,31 @@ int i2c_send_recv(I2CBus *bus, uint8_t *data, bool send) } *data = ret;return 0 ; + }else { + QLIST_FOREACH(node, &bus->current_devs, next) { + s = node->elt; + sc =I2C_SLAVE_GET_CLASS (s); +if (sc->send) { +trace_i2c_send (s->address, *data); + ret = ret || sc->send (s, *data); + }else { + ret =-1 ; + } + } +return ret ?-1 :0 ; } }int i2c_send (I2CBus *bus,uint8_t data) { -return i2c_send_recv (bus, &data, true); +return i2c_recv_send (bus, &data, false); }uint8_t i2c_recv (I2CBus *bus) {uint8_t data =0xff ; -i2c_send_recv (bus, &data, false); +i2c_recv_send (bus, &data, true);return data; }
hw/i2c/ppc4xx_i2c.c +1 -1
@@ -239,7 +239,7 @@ static void ppc4xx_i2c_writeb(void *opaque, hwaddr addr, uint64_t value, } }if (!(i2c->sts &IIC_STS_ERR ) && -i2c_send_recv (i2c->bus, &i2c->mdata[i], !recv)) { +i2c_recv_send (i2c->bus, &i2c->mdata[i], recv)) { i2c->sts |=IIC_STS_ERR ; i2c->extsts |=IIC_EXTSTS_XFRA ;break ;
hw/misc/auxbus.c +2 -2
@@ -148,7 +148,7 @@ AUXReply aux_request(AUXBus *bus, AUXCommand cmd, uint32_t address, ret =AUX_I2C_ACK ;while (len >0 ) { -if (i2c_send_recv (i2c_bus, data++, is_write) <0 ) { +if (i2c_recv_send (i2c_bus, data++, is_write) <0 ) { ret =AUX_I2C_NACK ;break ; }
@@ -189,7 +189,7 @@ AUXReply aux_request(AUXBus *bus, AUXCommand cmd, uint32_t address, bus->last_transaction = cmd; bus->last_i2c_address = address;while (len >0 ) { -if (i2c_send_recv (i2c_bus, data++, is_write) <0 ) { +if (i2c_recv_send (i2c_bus, data++, is_write) <0 ) {i2c_end_transfer (i2c_bus);break ; }
Signature · 1 line
2.21.3
PATCH v2 2/3 i2c: Make i2c_start_transfer() direction argument a boolean
In reply to Philippe Mathieu-DaudéFrom: BALATON Zoltan <[email protected]>
Make the argument representing the direction of the transfer a boolean type.
Rename the boolean argument as 'is_recv' to match i2c_recv_send(). Document the function prototype.
Message-Id: <[email protected]>
--- include/hw/i2c/i2c.h | 11 ++++++++++- hw/i2c/core.c | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-)
include/hw/i2c/i2c.h +10 -1
@@ -72,7 +72,16 @@ struct I2CBus {I2CBus *i2c_init_bus (DeviceState *parent,const char *name);void i2c_set_slave_address (I2CSlave *dev,uint8_t address);int i2c_bus_busy (I2CBus *bus); -int i2c_start_transfer (I2CBus *bus,uint8_t address,int recv); +/** +* i2c_start_transfer: start a transfer on an I2C bus. +* +* @bus: #I2CBus to be used +* @address: address of the slave +* @is_recv: indicates the transfer direction +* +* Returns: 0 on success, -1 on error +*/ +int i2c_start_transfer (I2CBus *bus,uint8_t address,bool is_recv);void i2c_end_transfer (I2CBus *bus);void i2c_nack (I2CBus *bus);/**
hw/i2c/core.c +2 -2
@@ -91,7 +91,7 @@ int i2c_bus_busy(I2CBus *bus)* without releasing the bus. If that fails, the bus is still * in a transaction. */ -int i2c_start_transfer (I2CBus *bus,uint8_t address,int recv) +int i2c_start_transfer (I2CBus *bus,uint8_t address,bool is_recv) {BusChild *kid;I2CSlaveClass *sc;
@@ -144,7 +144,7 @@ int i2c_start_transfer(I2CBus *bus, uint8_t address, int recv)if (sc->event) {trace_i2c_event ("start" , s->address); - rv = sc->event (s, recv ?I2C_START_RECV :I2C_START_SEND ); + rv = sc->event (s, is_recv ?I2C_START_RECV :I2C_START_SEND );if (rv && !bus->broadcast) {if (bus_scanned) {/* First call, terminate the transfer. */
Signature · 1 line
2.21.3
RFC PATCH v2 3/3 hw/misc/auxbus: Fix MOT/classic I2C mode
In reply to Philippe Mathieu-DaudéSince its introduction in commit 6fc7f77fd2 i2c_start_transfer() uses incorrectly the direction of the transfer. Fix it now.
---
RFC because untested (probably never was anyway)
Cc: Frederic Konrad <[email protected]>
Cc: Alistair Francis <[email protected]>
Cc: Peter Maydell <[email protected]>
--- hw/misc/auxbus.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
hw/misc/auxbus.c +3 -3
@@ -141,7 +141,7 @@ AUXReply aux_request(AUXBus *bus, AUXCommand cmd, uint32_t address,i2c_end_transfer (i2c_bus); } -if (i2c_start_transfer (i2c_bus, address, is_write)) { +if (i2c_start_transfer (i2c_bus, address, !is_write)) { ret =AUX_I2C_NACK ;break ; }
@@ -172,7 +172,7 @@ AUXReply aux_request(AUXBus *bus, AUXCommand cmd, uint32_t address,/* * No transactions started.. */ -if (i2c_start_transfer (i2c_bus, address, is_write)) { +if (i2c_start_transfer (i2c_bus, address, !is_write)) {break ; } } else if ((address != bus->last_i2c_address) ||
@@ -181,7 +181,7 @@ AUXReply aux_request(AUXBus *bus, AUXCommand cmd, uint32_t address,* Transaction started but we need to restart.. */ i2c_end_transfer (i2c_bus); -if (i2c_start_transfer (i2c_bus, address, is_write)) { +if (i2c_start_transfer (i2c_bus, address, !is_write)) {break ; } }
Signature · 1 line
2.21.3
Re: [RFC PATCH v2 3/3] hw/misc/auxbus: Fix MOT/classic I2C mode
Quoted 6 lines · Philippe Mathieu-Daudé
Since its introduction in commit
6fc7f77fd2i2c_start_transfer()uses incorrectly the direction of the transfer. Fix it now.Fixes 6fc7f77fd2 ("introduce aux-bus")Reported-by BALATON Zoltan <[email protected]>Suggested-by BALATON Zoltan <[email protected]>
One of the above is probably enough, maybe Reported-by because I wasn't sure what's the solution. I'm also happy with your changes to the whole series, thanks for fixing it.
Regards,
BALATON Zoltan
Quoted 42 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
RFC because untested (probably never was anyway)
Cc: Frederic Konrad <[email protected]>
Cc: Alistair Francis <[email protected]>
Cc: Peter Maydell <[email protected]>
---hw/misc/auxbus.c| 6 +++---1 file changed, 3 insertions(+), 3 deletions(-)hw/misc/auxbus.c +3
-3@@ -141,7 +141,7 @@ AUXReply aux_request(AUXBus *bus, AUXCommand cmd, uint32_t address,i2c_end_transfer (i2c_bus); } -if (i2c_start_transfer (i2c_bus, address, is_write)) { +if (i2c_start_transfer (i2c_bus, address, !is_write)) { ret =AUX_I2C_NACK ;break ; }@@ -172,7 +172,7 @@ AUXReply aux_request(AUXBus *bus, AUXCommand cmd, uint32_t address,/* * No transactions started.. */ -if (i2c_start_transfer (i2c_bus, address, is_write)) { +if (i2c_start_transfer (i2c_bus, address, !is_write)) {break ; } } else if ((address != bus->last_i2c_address) ||@@ -181,7 +181,7 @@ AUXReply aux_request(AUXBus *bus, AUXCommand cmd, uint32_t address,* Transaction started but we need to restart.. */ i2c_end_transfer (i2c_bus); -if (i2c_start_transfer (i2c_bus, address, is_write)) { +if (i2c_start_transfer (i2c_bus, address, !is_write)) {break ; } }
Re: [RFC PATCH v2 3/3] hw/misc/auxbus: Fix MOT/classic I2C mode
Quoted 11 lines · BALATON Zoltan
Quoted 6 lines · Philippe Mathieu-Daudé
Since its introduction in commit
6fc7f77fd2i2c_start_transfer()uses incorrectly the direction of the transfer. Fix it now.Fixes 6fc7f77fd2 ("introduce aux-bus")Reported-by BALATON Zoltan <[email protected]>Suggested-by BALATON Zoltan <[email protected]>One of the above is probably enough, maybe Reported-by because I wasn't sure what's the solution. I'm also happy with your changes to the whole series, thanks for fixing it.
Hopefully the maintainer taking this series can simply remove the Suggested-by tag directly. Else I can respin if it is easier.
Quoted 49 lines
Regards,
BALATON ZoltanQuoted 45 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
RFC because untested (probably never was anyway)
Cc: Frederic Konrad <[email protected]>
Cc: Alistair Francis <[email protected]>
Cc: Peter Maydell <[email protected]>
---hw/misc/auxbus.c| 6 +++---1 file changed, 3 insertions(+), 3 deletions(-)hw/misc/auxbus.c +1
-1@@ -141,7 +141,7 @@ AUXReply aux_request(AUXBus *bus, AUXCommand cmd,uint32_t address, i2c_end_transfer(i2c_bus); } - if (i2c_start_transfer(i2c_bus, address, is_write)) { + if (i2c_start_transfer(i2c_bus, address, !is_write)) { ret = AUX_I2C_NACK; break;}
hw/misc/auxbus.c +1
-1@@ -172,7 +172,7 @@ AUXReply aux_request(AUXBus *bus, AUXCommand cmd, uint32_t address, /* * No transactions started.. */ - if (i2c_start_transfer(i2c_bus, address, is_write)) { + if (i2c_start_transfer(i2c_bus, address, !is_write)) { break; }} else if ((address !=
bus->last_i2c_address) ||hw/misc/auxbus.c +1
-1@@ -181,7 +181,7 @@ AUXReply aux_request(AUXBus *bus, AUXCommand cmd,uint32_t address, * Transaction started but we need to restart.. */ i2c_end_transfer(i2c_bus); - if (i2c_start_transfer(i2c_bus, address, is_write)) { + if (i2c_start_transfer(i2c_bus, address, !is_write)) { break; }}
ping?
Quoted 23 lines · Philippe Mathieu-Daudé
This is v2 of Zoltan's patch:
https://www.mail-archive.com/[email protected]/msg714711.html- rebased
- added docstring
- includehw/misc/auxbus.cfixSupersedes: <[email protected]>
BALATON Zoltan (2):
i2c: Match parameters ofi2c_start_transferandi2c_send_recv
i2c: Makei2c_start_transfer()direction argument a booleanPhilippe Mathieu-Daudé (1):
hw/misc/auxbus: Fix MOT/classic I2C modeinclude/hw/i2c/i2c.h | 22 ++++++++++++++++++++-- hw/display/sm501.c | 4 ++-- hw/i2c/core.c | 36 ++++++++++++++++++------------------ hw/i2c/ppc4xx_i2c.c | 2 +- hw/misc/auxbus.c | 10 +++++----- 5 files changed, 46 insertions(+), 28 deletions(-)
Hello,
Quoted 8 lines · Philippe Mathieu-Daudé
This is v2 of Zoltan's patch:
https://www.mail-archive.com/[email protected]/msg714711.html- rebased
- added docstring
- includehw/misc/auxbus.cfixSupersedes: <[email protected]>
What happened to this series? I did not find it in patchew, only my original patch:
https://patchew.org/QEMU/[email protected]/
I still have this in one of my branches so I think it was not merged at the end. Could this be resurrected or should I forget about it and live with the inconsistency in parameters instead?
Regards,
BALATON Zoltan
Quoted 15 lines
BALATON Zoltan (2):
i2c: Match parameters ofi2c_start_transferandi2c_send_recv
i2c: Makei2c_start_transfer()direction argument a booleanPhilippe Mathieu-Daudé (1):
hw/misc/auxbus: Fix MOT/classic I2C modeinclude/hw/i2c/i2c.h | 22 ++++++++++++++++++++-- hw/display/sm501.c | 4 ++-- hw/i2c/core.c | 36 ++++++++++++++++++------------------ hw/i2c/ppc4xx_i2c.c | 2 +- hw/misc/auxbus.c | 10 +++++----- 5 files changed, 46 insertions(+), 28 deletions(-)
Quoted 12 lines · BALATON Zoltan
Hello,
Quoted 8 lines · Philippe Mathieu-Daudé
This is v2 of Zoltan's patch:
https://www.mail-archive.com/[email protected]/msg714711.html- rebased
- added docstring
- includehw/misc/auxbus.cfixSupersedes: <[email protected]>
Quoted 8 lines
What happened to this series? I did not find it in patchew, only my original patch:
https://patchew.org/QEMU/[email protected]/
I still have this in one of my branches so I think it was not merged at the end. Could this be resurrected or should I forget about it and live with the inconsistency in parameters instead?
I suppose it was not queued because you asked to remove the "Reported-by" tag :/ I agree with you it would be nice to get this in the tree
for good. However 1 year passed, so it might need adjustment.
Quoted 18 lines · Philippe Mathieu-Daudé
Quoted 17 lines · BALATON Zoltan
Hello,
Quoted 8 lines · Philippe Mathieu-Daudé
This is v2 of Zoltan's patch:
https://www.mail-archive.com/[email protected]/msg714711.html- rebased
- added docstring
- includehw/misc/auxbus.cfixSupersedes: <[email protected]>
What happened to this series? I did not find it in patchew, only my original patch:
Quoted 7 lines
Quoted 3 lines
I still have this in one of my branches so I think it was not merged at the end. Could this be resurrected or should I forget about it and live with the inconsistency in parameters instead?
I suppose it was not queued because you asked to remove the "Reported-by" tag :/ I agree with you it would be nice to get this in the tree
I think I said only Reported-by is enough no need for Suggested-by as well but I don't see this as a reason to drop these patches. So maybe just nobody cared enough.
Quoted 1 line
for good. However 1 year passed, so it might need adjustment.
Should I try to rebase it or will you do it eventually?
Regards,
BALATON Zoltan
Quoted 23 lines · BALATON Zoltan
Quoted 22 lines · Philippe Mathieu-Daudé
Quoted 20 lines · BALATON Zoltan
Hello,
Quoted 8 lines · Philippe Mathieu-Daudé
This is v2 of Zoltan's patch:
https://www.mail-archive.com/[email protected]/msg714711.html- rebased
- added docstring
- includehw/misc/auxbus.cfixSupersedes: <[email protected]>
What happened to this series? I did not find it in patchew, only my original patch:
https://patchew.org/QEMU/[email protected]/
I still have this in one of my branches so I think it was not merged at the end. Could this be resurrected or should I forget about it and live with the inconsistency in parameters instead?
Quoted 7 lines
Quoted 3 lines
I suppose it was not queued because you asked to remove the "Reported-by" tag :/ I agree with you it would be nice to get this in the tree
I think I said only Reported-by is enough no need for Suggested-by as well but I don't see this as a reason to drop these patches. So maybe just nobody cared enough.
Ah OK now got it.
Quoted 3 lines
Quoted 1 line
for good. However 1 year passed, so it might need adjustment.
Should I try to rebase it or will you do it eventually?
Found the branch and clean rebase, so no change needed.
Corey, if you are busy, I could send a pull request if you provide and Acked-by tag.
Regards,
Phil.
Quoted 34 lines · Philippe Mathieu-Daudé
Quoted 23 lines · BALATON Zoltan
Quoted 22 lines · Philippe Mathieu-Daudé
Quoted 20 lines · BALATON Zoltan
Hello,
Quoted 8 lines · Philippe Mathieu-Daudé
This is v2 of Zoltan's patch:
https://www.mail-archive.com/[email protected]/msg714711.html- rebased
- added docstring
- includehw/misc/auxbus.cfixSupersedes: <[email protected]>
What happened to this series? I did not find it in patchew, only my original patch:
https://patchew.org/QEMU/[email protected]/
I still have this in one of my branches so I think it was not merged at the end. Could this be resurrected or should I forget about it and live with the inconsistency in parameters instead?
Quoted 7 lines
Quoted 3 lines
I suppose it was not queued because you asked to remove the "Reported-by" tag :/ I agree with you it would be nice to get this in the tree
I think I said only Reported-by is enough no need for Suggested-by as well but I don't see this as a reason to drop these patches. So maybe just nobody cared enough.
Ah OK now got it.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
for good. However 1 year passed, so it might need adjustment.
Should I try to rebase it or will you do it eventually?
Found the branch and clean rebase, so no change needed.
Corey, if you are busy, I could send a pull request if you provide and Acked-by tag.
I'm somewhat worried about the silent semantic change. I would much prefer the functions to be renamed, as you mentioned in an email a while ago. I think that you mentioned this in an email in the chain listed above, and I think I pulled it for that reason.
-corey
Quoted 5 lines
Regards,
Phil.
Quoted 41 lines · Corey Minyard
Quoted 40 lines · Philippe Mathieu-Daudé
Quoted 23 lines · BALATON Zoltan
Quoted 22 lines · Philippe Mathieu-Daudé
Quoted 20 lines · BALATON Zoltan
Hello,
Quoted 8 lines · Philippe Mathieu-Daudé
This is v2 of Zoltan's patch:
https://www.mail-archive.com/[email protected]/msg714711.html- rebased
- added docstring
- includehw/misc/auxbus.cfixSupersedes: <[email protected]>
What happened to this series? I did not find it in patchew, only my original patch:
https://patchew.org/QEMU/[email protected]/
I still have this in one of my branches so I think it was not merged at the end. Could this be resurrected or should I forget about it and live with the inconsistency in parameters instead?
Quoted 7 lines
Quoted 3 lines
I suppose it was not queued because you asked to remove the "Reported-by" tag :/ I agree with you it would be nice to get this in the tree
I think I said only Reported-by is enough no need for Suggested-by as well but I don't see this as a reason to drop these patches. So maybe just nobody cared enough.
Ah OK now got it.
Quoted 3 lines
Quoted 1 line
for good. However 1 year passed, so it might need adjustment.
Should I try to rebase it or will you do it eventually?
Found the branch and clean rebase, so no change needed.
Quoted 7 lines
Quoted 2 lines
Corey, if you are busy, I could send a pull request if you provide and Acked-by tag.
I'm somewhat worried about the silent semantic change. I would much prefer the functions to be renamed, as you mentioned in an email a while ago. I think that you mentioned this in an email in the chain listed above, and I think I pulled it for that reason.
OK, maybe the comment was sent after this series or I missed it.
Thanks for the reminder.
Phil.