From nobody Tue Feb 10 12:13:49 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=163.com ARC-Seal: i=1; a=rsa-sha256; t=1677757397; cv=none; d=zohomail.com; s=zohoarc; b=Kzau7Bgy5SlTQyv3Xiz1+rg22tutg9NMB1fDMtf/M8e9FkhIE5Q9noG82KKR39EWS9TvcbcrOxeDdyjbNqg6ebVgA9+KIER2MssTLVnnWfYlVadutDEE7LvLkdHUiFPJd3a19c/Lh031WK/u+XuB85Fk3xaIuPJDNdM04Mh5BZ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677757397; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=W8oseXLLoGmg6ep9d/aMwd6HC+YABeP2tHYrtdkhkk4=; b=eT5giOPgy4Guz3XxDOFUk1RClT1Qyz39yFSDRPIvcGDhVlw9mgpyHBThe/xEuXLyNiMnrsakSOuzXiTj6rPDzsqH9rWmH0i2fggkJ5uETfruZU3ID4qLQ7VMk4Gx7HheC0+9fkM7kE6dyd4CziMyaWnD3yu3DHEhaCGFPOhbWIQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 167775739763181.30255838819414; Thu, 2 Mar 2023 03:43:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pXhJe-00044V-Ko; Thu, 02 Mar 2023 06:41:42 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pXhJb-00041X-P6; Thu, 02 Mar 2023 06:41:39 -0500 Received: from m12.mail.163.com ([123.126.96.233]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pXhJZ-00069R-2b; Thu, 02 Mar 2023 06:41:39 -0500 Received: from DESKTOP-B1R4FVG.localdomain (unknown [144.123.156.254]) by smtp20 (Coremail) with SMTP id H91pCgBni79OiwBknjVaGA--.63318S4; Thu, 02 Mar 2023 19:41:03 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=W8ose XLLoGmg6ep9d/aMwd6HC+YABeP2tHYrtdkhkk4=; b=KSRrRfZGpY3W7JVvTIkVf P9m8lRoD7EVKd+TXHaDnATOVf7/7iKB1iXyDc9ffzfuM9486oir9FSg3jFVzYBl9 IbeCkroxAYXLZr9hK8MxImXO0bUNlCRKBM8SyulnIKAz8lpS/GAi1hepY+phwQ/I erN0vxIFSMItJs1TpsGJvE= From: qianfanguijin@163.com To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Cc: Strahinja Jankovic , Peter Maydell , Beniamino Galvani , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Niek Linnenbank , qianfan Zhao Subject: [RFC PATCH v1 02/12] hw: allwinner-i2c: Fix TWI_CNTR_INT_FLAG on SUN6i SoCs Date: Thu, 2 Mar 2023 19:40:51 +0800 Message-Id: <20230302114102.32236-3-qianfanguijin@163.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230302114102.32236-1-qianfanguijin@163.com> References: <20230302114102.32236-1-qianfanguijin@163.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: H91pCgBni79OiwBknjVaGA--.63318S4 X-Coremail-Antispam: 1Uf129KBjvJXoWxGFyxCFW3KFyrAFWUWF43Awb_yoW5Kw4rpF Wqgr45KF4Yqa97WrnIqFn8GF18Jry8C3y8Krsa9FyIvFnrW3ZFqr1ktrWakrn8GrWrJw43 tFs8tFyxWFn0qaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pi2YLDUUUUU= X-Originating-IP: [144.123.156.254] X-CM-SenderInfo: htld0w5dqj3xxmlqqiywtou0bp/1tbiXRAm7VWBoxmNGAAAs9 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=123.126.96.233; envelope-from=qianfanguijin@163.com; helo=m12.mail.163.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @163.com) X-ZM-MESSAGEID: 1677757398051100003 Content-Type: text/plain; charset="utf-8" From: qianfan Zhao TWI_CNTR_INT_FLAG is W1C(write 1 to clear and write 0 has non-effect) register on SUN6i based SoCs, we should lower interrupt when the guest set this bit. The linux kernel will hang in irq handler(mv64xxx_i2c_intr) if no device connected on the i2c bus, next is the trace log: allwinner_i2c_write write CNTR(0x0c): 0xc4 A_ACK BUS_EN INT_EN allwinner_i2c_write write CNTR(0x0c): 0xcc A_ACK INT_FLAG BUS_EN INT_EN allwinner_i2c_read read CNTR(0x0c): 0xcc A_ACK INT_FLAG BUS_EN INT_EN allwinner_i2c_read read STAT(0x10): 0x20 STAT_M_ADDR_WR_NACK allwinner_i2c_write write CNTR(0x0c): 0x54 A_ACK M_STP BUS_EN allwinner_i2c_write write CNTR(0x0c): 0x4c A_ACK INT_FLAG BUS_EN allwinner_i2c_read read CNTR(0x0c): 0x4c A_ACK INT_FLAG BUS_EN allwinner_i2c_read read STAT(0x10): 0xf8 STAT_IDLE allwinner_i2c_write write CNTR(0x0c): 0x54 A_ACK M_STP BUS_EN allwinner_i2c_write write CNTR(0x0c): 0x4c A_ACK INT_FLAG BUS_EN allwinner_i2c_read read CNTR(0x0c): 0x4c A_ACK INT_FLAG BUS_EN allwinner_i2c_read read STAT(0x10): 0xf8 STAT_IDLE ... Fix it. Signed-off-by: qianfan Zhao --- hw/i2c/allwinner-i2c.c | 26 ++++++++++++++++++++++++-- include/hw/i2c/allwinner-i2c.h | 6 ++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/hw/i2c/allwinner-i2c.c b/hw/i2c/allwinner-i2c.c index fa650e7e02..819638d740 100644 --- a/hw/i2c/allwinner-i2c.c +++ b/hw/i2c/allwinner-i2c.c @@ -463,10 +463,16 @@ static void allwinner_i2c_write(void *opaque, hwaddr = offset, s->stat =3D STAT_FROM_STA(STAT_IDLE); s->cntr &=3D ~TWI_CNTR_M_STP; } - if ((s->cntr & TWI_CNTR_INT_FLAG) =3D=3D 0) { - /* Interrupt flag cleared */ + + if (!s->irq_clear_inverted && !(s->cntr & TWI_CNTR_INT_FLAG)) { + /* Write 0 to clear this flag */ + qemu_irq_lower(s->irq); + } else if (s->irq_clear_inverted && (s->cntr & TWI_CNTR_INT_FL= AG)) { + /* Write 1 to clear this flag */ + s->cntr &=3D ~TWI_CNTR_INT_FLAG; qemu_irq_lower(s->irq); } + if ((s->cntr & TWI_CNTR_A_ACK) =3D=3D 0) { if (STAT_TO_STA(s->stat) =3D=3D STAT_M_DATA_RX_ACK) { s->stat =3D STAT_FROM_STA(STAT_M_DATA_RX_NACK); @@ -557,9 +563,25 @@ static const TypeInfo allwinner_i2c_type_info =3D { .class_init =3D allwinner_i2c_class_init, }; =20 +static void allwinner_i2c_sun6i_init(Object *obj) +{ + AWI2CState *s =3D AW_I2C(obj); + + s->irq_clear_inverted =3D true; +} + +static const TypeInfo allwinner_i2c_sun6i_type_info =3D { + .name =3D TYPE_AW_I2C_SUN6I, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(AWI2CState), + .instance_init =3D allwinner_i2c_sun6i_init, + .class_init =3D allwinner_i2c_class_init, +}; + static void allwinner_i2c_register_types(void) { type_register_static(&allwinner_i2c_type_info); + type_register_static(&allwinner_i2c_sun6i_type_info); } =20 type_init(allwinner_i2c_register_types) diff --git a/include/hw/i2c/allwinner-i2c.h b/include/hw/i2c/allwinner-i2c.h index 4f378b86ba..0e325d265e 100644 --- a/include/hw/i2c/allwinner-i2c.h +++ b/include/hw/i2c/allwinner-i2c.h @@ -28,6 +28,10 @@ #include "qom/object.h" =20 #define TYPE_AW_I2C "allwinner.i2c" + +/** Allwinner I2C sun6i family and newer (A31, H2+, H3, etc) */ +#define TYPE_AW_I2C_SUN6I TYPE_AW_I2C "-sun6i" + OBJECT_DECLARE_SIMPLE_TYPE(AWI2CState, AW_I2C) =20 #define AW_I2C_MEM_SIZE 0x24 @@ -50,6 +54,8 @@ struct AWI2CState { uint8_t srst; uint8_t efr; uint8_t lcr; + + bool irq_clear_inverted; }; =20 #endif /* ALLWINNER_I2C_H */ --=20 2.25.1