From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Rayhan Faizel <rayhan.faizel@gmail.com>, qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, pbonzini@redhat.com, qemu-arm@nongnu.org
Subject: Re: [PATCH v3 1/3] hw/i2c: Implement Broadcom Serial Controller (BSC)
Date: Fri, 23 Feb 2024 07:12:02 +0100 [thread overview]
Message-ID: <a8c904b1-ec5a-419e-99bf-159ae1413948@linaro.org> (raw)
In-Reply-To: <20240220134120.2961059-2-rayhan.faizel@gmail.com>
Hi Rayhan,
On 20/2/24 14:41, Rayhan Faizel wrote:
> A few deficiencies in the current device model need to be noted.
>
> 1. FIFOs are not used. All sends and receives are done directly.
> 2. Repeated starts are not emulated. Repeated starts can be triggered in real
> hardware by sending a new read transfer request in the window time between
> transfer active set of write transfer request and done bit set of the same.
>
> Signed-off-by: Rayhan Faizel <rayhan.faizel@gmail.com>
> ---
> docs/system/arm/raspi.rst | 1 +
> hw/i2c/Kconfig | 4 +
> hw/i2c/bcm2835_i2c.c | 278 +++++++++++++++++++++++++++++++++++
> hw/i2c/meson.build | 1 +
> include/hw/i2c/bcm2835_i2c.h | 80 ++++++++++
> 5 files changed, 364 insertions(+)
> create mode 100644 hw/i2c/bcm2835_i2c.c
> create mode 100644 include/hw/i2c/bcm2835_i2c.h
> new file mode 100644
> index 0000000000..d6b9bf887a
> --- /dev/null
> +++ b/hw/i2c/bcm2835_i2c.c
> @@ -0,0 +1,278 @@
> +/*
> + * Broadcom Serial Controller (BSC)
> + *
> + * Copyright (c) 2024 Rayhan Faizel <rayhan.faizel@gmail.com>
> + *
> + * SPDX-License-Identifier: MIT
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a copy
> + * of this software and associated documentation files (the "Software"), to deal
> + * in the Software without restriction, including without limitation the rights
> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> + * copies of the Software, and to permit persons to whom the Software is
> + * furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> + * THE SOFTWARE.
> + */
> +
> +#include "qemu/osdep.h"
> +#include "qemu/log.h"
> +#include "hw/i2c/bcm2835_i2c.h"
> +#include "hw/irq.h"
> +#include "migration/vmstate.h"
> +
> +static void bcm2835_i2c_update_interrupt(BCM2835I2CState *s)
> +{
> + int do_interrupt = 0;
> + /* Interrupt on RXR (Needs reading) */
> + if (s->c & BCM2835_I2C_C_INTR && s->s & BCM2835_I2C_S_RXR) {
> + do_interrupt = 1;
> + }
> +
> + /* Interrupt on TXW (Needs writing) */
> + if (s->c & BCM2835_I2C_C_INTT && s->s & BCM2835_I2C_S_TXW) {
> + do_interrupt = 1;
> + }
> +
> + /* Interrupt on DONE (Transfer complete) */
> + if (s->c & BCM2835_I2C_C_INTD && s->s & BCM2835_I2C_S_DONE) {
> + do_interrupt = 1;
> + }
> + qemu_set_irq(s->irq, do_interrupt);
> +}
> +
> +static void bcm2835_i2c_begin_transfer(BCM2835I2CState *s)
> +{
> + int direction = s->c & BCM2835_I2C_C_READ;
> + if (i2c_start_transfer(s->bus, s->a, direction)) {
> + s->s |= BCM2835_I2C_S_ERR;
> + }
> + s->s |= BCM2835_I2C_S_TA;
> +
> + if (direction) {
> + s->s |= BCM2835_I2C_S_RXR | BCM2835_I2C_S_RXD;
> + } else {
> + s->s |= BCM2835_I2C_S_TXW;
> + }
> +}
> +
> +static void bcm2835_i2c_finish_transfer(BCM2835I2CState *s)
> +{
> + /*
> + * STOP is sent when DLEN counts down to zero.
> + *
> + * https://github.com/torvalds/linux/blob/master/drivers/i2c/busses/i2c-bcm2835.c#L223-L261
Sorry for not reviewing your patches earlier.
Since this documentation will stay for long and the Linux master branch
will change, better use a tag:
https://github.com/torvalds/linux/blob//v6.7/drivers/i2c/busses/i2c-bcm2835.c#L223-L261
Do you mind posting a patch to correct this?
Thanks,
Phil.
next prev parent reply other threads:[~2024-02-23 6:12 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-20 13:41 [PATCH v3 0/3] Add support for I2C in BCM2835 boards Rayhan Faizel
2024-02-20 13:41 ` [PATCH v3 1/3] hw/i2c: Implement Broadcom Serial Controller (BSC) Rayhan Faizel
2024-02-23 6:12 ` Philippe Mathieu-Daudé [this message]
2024-02-23 6:15 ` Philippe Mathieu-Daudé
2024-02-23 10:05 ` Peter Maydell
2024-02-20 13:41 ` [PATCH v3 2/3] hw/arm: Connect BSC to BCM2835 board as I2C0, I2C1 and I2C2 Rayhan Faizel
2024-02-23 6:20 ` Philippe Mathieu-Daudé
2024-02-20 13:41 ` [PATCH v3 3/3] tests/qtest: Add testcase for BCM2835 BSC Rayhan Faizel
2024-02-23 10:06 ` Peter Maydell
2024-02-22 17:54 ` [PATCH v3 0/3] Add support for I2C in BCM2835 boards Peter Maydell
2024-02-23 6:23 ` Philippe Mathieu-Daudé
2024-02-23 10:04 ` Peter Maydell
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=a8c904b1-ec5a-419e-99bf-159ae1413948@linaro.org \
--to=philmd@linaro.org \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=rayhan.faizel@gmail.com \
/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).