From: Alistair Francis <alistair.francis@xilinx.com>
To: "KONRAD Frédéric" <fred.konrad@greensocs.com>
Cc: Edgar Iglesias <edgar.iglesias@xilinx.com>,
Peter Maydell <peter.maydell@linaro.org>,
hyunk@xilinx.com, Peter Crosthwaite <crosthwaite.peter@gmail.com>,
Mark Burton <mark.burton@greensocs.com>,
"qemu-devel@nongnu.org Developers" <qemu-devel@nongnu.org>,
Alistair Francis <alistair.francis@xilinx.com>,
Peter Crosthwaite <crosthwaitepeter@gmail.com>,
Guillaume Delbergue <guillaume.delbergue@greensocs.com>
Subject: Re: [Qemu-devel] [PATCH V7 3/9] i2c: Factor our send() and recv() common logic
Date: Mon, 8 Feb 2016 15:56:24 -0800 [thread overview]
Message-ID: <CAKmqyKPzj9pKN-nP53ht0goDtth=oeJJ+qPsTypkhkgvLYcAKA@mail.gmail.com> (raw)
In-Reply-To: <1454341418-24227-4-git-send-email-fred.konrad@greensocs.com>
On Mon, Feb 1, 2016 at 7:43 AM, <fred.konrad@greensocs.com> wrote:
> From: Peter Crosthwaite <crosthwaitepeter@gmail.com>
>
> Most of the control flow logic between send and recv (error checking
> etc) is the same. Factor this out into a common send_recv() API.
> This is then usable by clients, where the control logic for send
> and receive differs only by a boolean. E.g.
>
> if (send)
> i2c_send(...):
> else
> i2c_recv(...);
>
> becomes:
>
> i2c_send_recv(... , send);
>
> Signed-off-by: Peter Crosthwaite <crosthwaite.peter@gmail.com>
> Changes from FK:
> * Rebased on master.
> * Rebased on my i2c broadcast patch.
> Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
Reviewed-by: Alistair Francis <alistair.francis@xilinx.com>
Thanks,
Alistair
> ---
> hw/i2c/core.c | 48 ++++++++++++++++++++++++++++++++----------------
> include/hw/i2c/i2c.h | 1 +
> 2 files changed, 33 insertions(+), 16 deletions(-)
>
> diff --git a/hw/i2c/core.c b/hw/i2c/core.c
> index a3921d9..a49138f 100644
> --- a/hw/i2c/core.c
> +++ b/hw/i2c/core.c
> @@ -148,34 +148,50 @@ void i2c_end_transfer(I2CBus *bus)
> bus->broadcast = false;
> }
>
> -int i2c_send(I2CBus *bus, uint8_t data)
> +int i2c_send_recv(I2CBus *bus, uint8_t *data, bool send)
> {
> I2CSlaveClass *sc;
> I2CNode *node;
> int ret = -1;
>
> - QLIST_FOREACH(node, &bus->current_devs, next) {
> - sc = I2C_SLAVE_GET_CLASS(node->elt);
> - if (sc->send) {
> - ret |= sc->send(node->elt, data);
> + if (send) {
> + QLIST_FOREACH(node, &bus->current_devs, next) {
> + sc = I2C_SLAVE_GET_CLASS(node->elt);
> + if (sc->send) {
> + ret |= sc->send(node->elt, *data);
> + }
> + }
> + return ret;
> + } else {
> + if ((QLIST_EMPTY(&bus->current_devs)) || (bus->broadcast)) {
> + return -1;
> }
> +
> + sc = I2C_SLAVE_GET_CLASS(QLIST_FIRST(&bus->current_devs)->elt);
> + if (sc->recv) {
> + ret = sc->recv(QLIST_FIRST(&bus->current_devs)->elt);
> + if (ret < 0) {
> + return ret;
> + } else {
> + *data = ret;
> + return 0;
> + }
> + }
> + return -1;
> }
> - return ret;
> }
>
> -int i2c_recv(I2CBus *bus)
> +int i2c_send(I2CBus *bus, uint8_t data)
> {
> - I2CSlaveClass *sc;
> + return i2c_send_recv(bus, &data, true);
> +}
>
> - if ((QLIST_EMPTY(&bus->current_devs)) || (bus->broadcast)) {
> - return -1;
> - }
> +int i2c_recv(I2CBus *bus)
> +{
> + uint8_t data;
> + int ret = i2c_send_recv(bus, &data, false);
>
> - sc = I2C_SLAVE_GET_CLASS(QLIST_FIRST(&bus->current_devs)->elt);
> - if (sc->recv) {
> - return sc->recv(QLIST_FIRST(&bus->current_devs)->elt);
> - }
> - return -1;
> + return ret < 0 ? ret : data;
> }
>
> void i2c_nack(I2CBus *bus)
> diff --git a/include/hw/i2c/i2c.h b/include/hw/i2c/i2c.h
> index 4986ebc..c4085aa 100644
> --- a/include/hw/i2c/i2c.h
> +++ b/include/hw/i2c/i2c.h
> @@ -56,6 +56,7 @@ 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);
> int i2c_send(I2CBus *bus, uint8_t data);
> int i2c_recv(I2CBus *bus);
>
> --
> 1.9.0
>
>
next prev parent reply other threads:[~2016-02-08 23:56 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-01 15:43 [Qemu-devel] [PATCH V7 0/9] Xilinx DisplayPort fred.konrad
2016-02-01 15:43 ` [Qemu-devel] [PATCH V7 1/9] i2cbus: remove unused dev field fred.konrad
2016-02-01 15:43 ` [Qemu-devel] [PATCH V7 2/9] i2c: implement broadcast write fred.konrad
2016-02-01 15:43 ` [Qemu-devel] [PATCH V7 3/9] i2c: Factor our send() and recv() common logic fred.konrad
2016-02-08 23:56 ` Alistair Francis [this message]
2016-02-01 15:43 ` [Qemu-devel] [PATCH V7 4/9] introduce aux-bus fred.konrad
2016-02-09 0:23 ` Alistair Francis
2016-02-01 15:43 ` [Qemu-devel] [PATCH V7 5/9] introduce dpcd module fred.konrad
2016-02-01 15:43 ` [Qemu-devel] [PATCH V7 6/9] hw/i2c-ddc.c: Implement DDC I2C slave fred.konrad
2016-02-01 15:43 ` [Qemu-devel] [PATCH V7 7/9] introduce xlnx-dpdma fred.konrad
2016-02-01 15:43 ` [Qemu-devel] [PATCH V7 8/9] introduce xlnx-dp fred.konrad
2016-02-09 1:10 ` Alistair Francis
2016-02-01 15:43 ` [Qemu-devel] [PATCH V7 9/9] arm: xlnx-zynqmp: Add xlnx-dp and xlnx-dpdma fred.konrad
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAKmqyKPzj9pKN-nP53ht0goDtth=oeJJ+qPsTypkhkgvLYcAKA@mail.gmail.com' \
--to=alistair.francis@xilinx.com \
--cc=crosthwaite.peter@gmail.com \
--cc=crosthwaitepeter@gmail.com \
--cc=edgar.iglesias@xilinx.com \
--cc=fred.konrad@greensocs.com \
--cc=guillaume.delbergue@greensocs.com \
--cc=hyunk@xilinx.com \
--cc=mark.burton@greensocs.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).