All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nicholas Piggin <npiggin@gmail.com>
To: "Philippe Mathieu-Daudé" <philmd@linaro.org>
Cc: Joel Stanley <joel@jms.id.au>,
	 Alistair Francis <alistair.francis@wdc.com>,
	Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>,
	 Chao Liu <chao.liu.zevorn@gmail.com>,
	Chris Rauer <crauer@google.com>,
	 Michael Ellerman <mpe@kernel.org>,
	Joel Stanley <jms@oss.tenstorrent.com>,
	 Anirudh Srinivasan <asrinivasan@oss.tenstorrent.com>,
	Portia Stephens <portias@oss.tenstorrent.com>,
	 qemu-riscv@nongnu.org, qemu-devel@nongnu.org,
	Hao Wu <wuhaotsh@google.com>
Subject: Re: [PATCH v4 01/13] hw/i2c: Add designware i2c controller
Date: Wed, 6 May 2026 15:53:01 +1000	[thread overview]
Message-ID: <afrVHbIeet5tqCA-@lima-default> (raw)
In-Reply-To: <972d8ddd-8ef9-4cd3-a7e5-90f00ec625ad@linaro.org>

On Tue, May 05, 2026 at 09:57:20AM +0200, Philippe Mathieu-Daudé wrote:
> On 25/4/26 15:17, Joel Stanley wrote:
> > From: Chris Rauer <crauer@google.com>
> > 
> > In the past this model has been submitted for use with the arm virt
> > machine, however in this case it will be used by the upcoming
> > Tenstorrent Atlantis RISC-V machine.
> > 
> > This is a re-submission of the model with Chris' permission, with a
> > light touch of updates to make it build with qemu master.
> > 
> > Reviewed-by: Hao Wu <wuhaotsh@google.com>
> > Signed-off-by: Chris Rauer <crauer@google.com>
> > Link: https://lore.kernel.org/qemu-devel/20220110214755.810343-2-venture@google.com
> > [jms: rebase and minor build fixes for class_init and reset callback]
> > Signed-off-by: Joel Stanley <joel@jms.id.au>
> > ---
> > v4: Remove unused random header
> > v2: Add trace event for read and write, document Alano and myself as
> > reviewers.
> > ---
> >   MAINTAINERS                     |   8 +
> >   include/hw/i2c/designware_i2c.h | 101 ++++
> >   hw/i2c/designware_i2c.c         | 817 ++++++++++++++++++++++++++++++++
> >   hw/i2c/Kconfig                  |   4 +
> >   hw/i2c/meson.build              |   1 +
> >   hw/i2c/trace-events             |   4 +
> >   6 files changed, 935 insertions(+)
> >   create mode 100644 include/hw/i2c/designware_i2c.h
> >   create mode 100644 hw/i2c/designware_i2c.c
> > 
> > diff --git a/MAINTAINERS b/MAINTAINERS
> > index aa4267b15806..e1942a86eba5 100644
> > --- a/MAINTAINERS
> > +++ b/MAINTAINERS
> > @@ -2716,6 +2716,14 @@ S: Orphan
> >   F: hw/gpio/pcf8574.c
> >   F: include/gpio/pcf8574.h
> > +DesignWare I2C
> > +M: Chris Rauer <crauer@google.com>
> 
> This was 4 years ago. Is Chris still up to this?

Joel is away for a few weeks, but AFAIK he did ping Chris and got
ack to upstream his patch.

> > +    case DW_IC_SAR:
> > +        qemu_log_mask(LOG_UNIMP, "%s: unsupported write - ic_sar\n",
> > +                      DEVICE(s)->canonical_path);
> > +        s->ic_sar = value & DW_IC_SAR_MASK;
> 
> Unsupported but updated...

Yeah, not sure what the best course of action is, maybe device driver
was working better if the value got saved?

> > +    s->ic_comp_param_1 = DW_IC_COMP_PARAM_1_INIT_VAL;
> > +    s->ic_comp_version = DW_IC_COMP_VERSION_INIT_VAL;
> > +    s->ic_comp_type = DW_IC_COMP_TYPE_INIT_VAL;
> 
> Preferably initialize the IC_COMP registers once in the
> designware_i2c_realize() handler.

This I didn't change yet because I started register API converstion and
that all changes.

> > +static void designware_i2c_smbus_init(Object *obj)
> > +{
> > +    DesignWareI2CState *s = DESIGNWARE_I2C(obj);
> > +    SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
> > +
> > +    sysbus_init_irq(sbd, &s->irq);
> > +
> > +    memory_region_init_io(&s->iomem, obj, &designware_i2c_ops, s,
> > +                          "regs", 4 * KiB);
> 
> I note the current registers only describe a 1KiB region.

256 bytes even. It might have 4K alignment in data sheet.

> > +}
> Since I couldn't look at the datasheet values, for overall modelling:
> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>

Thanks!

I have an incremental patch here that incorporates review comments and
also a couple of possible issues I found - RX underflow bit was never
being set AFAIKS it should be set here, and one of the INTR bit clear
registers was not recalculating irqs.

I will fold this in before next repost if there are no objections.

Thanks,
Nick

---
diff --git a/hw/i2c/designware_i2c.c b/hw/i2c/designware_i2c.c
index 7d8b1c1353..1e5505f571 100644
--- a/hw/i2c/designware_i2c.c
+++ b/hw/i2c/designware_i2c.c
@@ -217,7 +217,7 @@ static uint32_t dw_i2c_read_ic_data_cmd(DesignWareI2CState *s)
                       "%s: Attempted to read from RX fifo when not in receive "
                       "state.\n", DEVICE(s)->canonical_path);
         if (s->status != DW_I2C_STATUS_IDLE) {
-            s->ic_raw_intr_stat &= ~DW_IC_INTR_RX_UNDER;
+            s->ic_raw_intr_stat |= DW_IC_INTR_RX_UNDER;
             dw_i2c_update_irq(s);
         }
         return 0;
@@ -228,7 +228,7 @@ static uint32_t dw_i2c_read_ic_data_cmd(DesignWareI2CState *s)
     if (s->ic_rxflr > 0) {
         s->ic_rxflr--;
     } else {
-        s->ic_raw_intr_stat &= ~DW_IC_INTR_RX_UNDER;
+        s->ic_raw_intr_stat |= DW_IC_INTR_RX_UNDER;
         dw_i2c_update_irq(s);
         return 0;
     }
@@ -395,6 +395,7 @@ static uint64_t dw_i2c_read(void *opaque, hwaddr offset, unsigned size)
         break;
     case DW_IC_CLR_RESTART_DET:
         s->ic_raw_intr_stat &= ~(DW_IC_INTR_RESTART_DET);
+        dw_i2c_update_irq(s);
         break;
     case DW_IC_COMP_PARAM_1:
         value = s->ic_comp_param_1;
@@ -698,6 +699,10 @@ static const MemoryRegionOps designware_i2c_ops = {
     .read = dw_i2c_read,
     .write = dw_i2c_write,
     .endianness = DEVICE_LITTLE_ENDIAN,
+    .impl = {
+        .min_access_size = 4,
+        .max_access_size = 4,
+    },
     .valid = {
         .min_access_size = 4,
         .max_access_size = 4,
@@ -748,7 +753,7 @@ static const VMStateDescription vmstate_designware_i2c = {
     .name = TYPE_DESIGNWARE_I2C,
     .version_id = 0,
     .minimum_version_id = 0,
-    .fields = (VMStateField[]) {
+    .fields = (const VMStateField[]) {
         VMSTATE_UINT32(ic_con, DesignWareI2CState),
         VMSTATE_UINT32(ic_tar, DesignWareI2CState),
         VMSTATE_UINT32(ic_sar, DesignWareI2CState),
@@ -803,6 +808,8 @@ static void designware_i2c_class_init(ObjectClass *klass, const void *data)
     dc->vmsd = &vmstate_designware_i2c;
     rc->phases.enter = designware_i2c_enter_reset;
     rc->phases.hold = designware_i2c_hold_reset;
+
+    set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
 }
 
 static const TypeInfo designware_i2c_types[] = {
diff --git a/include/hw/i2c/designware_i2c.h b/include/hw/i2c/designware_i2c.h
index 0d8f904f51..71d74c9141 100644
--- a/include/hw/i2c/designware_i2c.h
+++ b/include/hw/i2c/designware_i2c.h
@@ -57,7 +57,7 @@ typedef enum DesignWareI2CStatus {
  * @status: The current status of the SMBus.
  */
 typedef struct DesignWareI2CState {
-    SysBusDevice parent;
+    SysBusDevice parent_obj;
 
     MemoryRegion iomem;
 


  reply	other threads:[~2026-05-06  5:54 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-25 13:17 [PATCH v4 00/13] hw/riscv: Add the Tenstorrent Atlantis machine Joel Stanley
2026-04-25 13:17 ` [PATCH v4 01/13] hw/i2c: Add designware i2c controller Joel Stanley
2026-04-30  3:53   ` Alistair Francis
2026-05-05  6:20     ` Nicholas Piggin
2026-05-05  7:36       ` Philippe Mathieu-Daudé
2026-05-06  5:58         ` Nicholas Piggin
2026-05-06  8:59           ` Philippe Mathieu-Daudé
2026-05-05  7:57   ` Philippe Mathieu-Daudé
2026-05-06  5:53     ` Nicholas Piggin [this message]
2026-05-06  8:55       ` Philippe Mathieu-Daudé
2026-04-25 13:17 ` [PATCH v4 02/13] hw/riscv/boot: Describe discontiguous memory in boot_info Joel Stanley
2026-04-25 13:17 ` [PATCH v4 03/13] hw/riscv/boot: Account for discontiguous memory when loading firmware Joel Stanley
2026-04-29 23:34   ` Alistair Francis
2026-05-04 23:45     ` Nicholas Piggin
2026-04-25 13:17 ` [PATCH v4 04/13] hw/riscv/boot: Provide a simple halting payload Joel Stanley
2026-04-29 23:35   ` Alistair Francis
2026-05-04 23:52     ` Nicholas Piggin
2026-05-05  8:06       ` Philippe Mathieu-Daudé
2026-05-07  1:53         ` Nicholas Piggin
2026-04-25 13:17 ` [PATCH v4 05/13] hw/riscv/virt: Move AIA initialisation to helper file Joel Stanley
2026-04-25 13:17 ` [PATCH v4 06/13] hw/riscv/aia: Provide number of irq sources Joel Stanley
2026-04-25 13:17 ` [PATCH v4 07/13] target/riscv: tt-ascalon: Enable Zkr extension Joel Stanley
2026-04-29 23:36   ` Alistair Francis
2026-05-05  0:06     ` Nicholas Piggin
2026-04-25 13:17 ` [PATCH v4 08/13] target/riscv: tt-ascalon: Enable Svadu by removing Svade Joel Stanley
2026-04-29 23:41   ` Alistair Francis
2026-04-25 13:17 ` [PATCH v4 09/13] hw/riscv: Add Tenstorrent Atlantis machine Joel Stanley
2026-04-29 23:57   ` Alistair Francis
2026-05-05  1:04     ` Nicholas Piggin
2026-05-05  4:34       ` Alistair Francis
2026-05-05  6:00         ` Nicholas Piggin
2026-05-05  7:31           ` Philippe Mathieu-Daudé
2026-05-06  3:14           ` Alistair Francis
2026-05-07  1:50             ` Nicholas Piggin
2026-05-07  2:53               ` Alistair Francis
2026-05-05  2:00     ` Nicholas Piggin
2026-05-05  4:36       ` Alistair Francis
2026-05-05  6:01         ` Nicholas Piggin
2026-04-25 13:17 ` [PATCH v4 10/13] hw/riscv/atlantis: Add PCIe controller Joel Stanley
2026-04-30  0:04   ` Alistair Francis
2026-05-05  1:38     ` Nicholas Piggin
2026-04-25 13:17 ` [PATCH v4 11/13] tests/functional/riscv64: Add tt-atlantis tests Joel Stanley
2026-04-25 13:17 ` [PATCH v4 12/13] hw/riscv/atlantis: Integrate i2c buses Joel Stanley
2026-04-25 13:17 ` [PATCH v4 13/13] hw/riscv/atlantis: Add some i2c peripherals Joel Stanley

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=afrVHbIeet5tqCA-@lima-default \
    --to=npiggin@gmail.com \
    --cc=alistair.francis@wdc.com \
    --cc=asrinivasan@oss.tenstorrent.com \
    --cc=chao.liu.zevorn@gmail.com \
    --cc=crauer@google.com \
    --cc=daniel.barboza@oss.qualcomm.com \
    --cc=jms@oss.tenstorrent.com \
    --cc=joel@jms.id.au \
    --cc=mpe@kernel.org \
    --cc=philmd@linaro.org \
    --cc=portias@oss.tenstorrent.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-riscv@nongnu.org \
    --cc=wuhaotsh@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.