From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2E3ABC02192 for ; Mon, 3 Feb 2025 17:12:58 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4YmtMd5GQHz3gMb for ; Tue, 4 Feb 2025 04:11:57 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip=212.199.177.27 ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1738602710; cv=none; b=CMasAWkY8pBddJqTJKA5l2CyHbXU3Vk5fIWzGkLTRgnbB9rMDj/ZOAZUbCs18ztSqgD9GEiOqaMjFaLRppuhV8spGsQjI3BTUXZ1ih+5rTogOAgHjssOnw5Heh1rJz1eS+mcLOgfbipv/mFP+fZKjvu6obioEgoQ7IiO/YLIZtq6W/UjEPFJoQj4BcOrg5X7FH+5e9WiVGyFAgjTzZNzvbZl7rK0FkA0ftnGA9Pfr3jHIq+TYMcTGJzRmxeZO7RzadYr/fY3KPRjSbcH4UVK3E5KY2X8EyBJK6pFOl+i2UhX5gY90wRLJQlYQWM3StIdj166iXmk4sdN7bstgCRe3A== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1738602710; c=relaxed/relaxed; bh=JrjBVCo8np5pdmyneB6n1ZIlQMk2YnuiZVx4HyM/KcA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=eNG3a6fyaxKrwiJzgQjEJ6uoluMgJXKyEhtyr19NTJJNRv2lWiKrAmjZlFBCCPuRGx59t/i0oFjhEypP3mb+IQk6CcCEJxbMaen5gzyR3L/k7xQS40+b8IB3COi3skp35BqgnjxABvvrX/eA27A00jASMnKmoija7SAYjqlsk1BD3fNcU1z05hnQ+/Tjg8wK6hfXZS9ZJEyUMisncPVhYEETJCHJz90wq8MmUDRG9YaEV1gsyV2H32TLLczuJsuiC9fQjcXozT7O7fYttYoLF3QzmYorhj0P6fIia5QIsq52SNmu0XsIarG++IKodXUBahQu54qgWe7j6u5XQFmQIw== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com; spf=none (client-ip=212.199.177.27; helo=herzl.nuvoton.co.il; envelope-from=tmaimon@taln60.nuvoton.co.il; receiver=lists.ozlabs.org) smtp.mailfrom=taln60.nuvoton.co.il Authentication-Results: lists.ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=taln60.nuvoton.co.il (client-ip=212.199.177.27; helo=herzl.nuvoton.co.il; envelope-from=tmaimon@taln60.nuvoton.co.il; receiver=lists.ozlabs.org) Received: from herzl.nuvoton.co.il (unknown [212.199.177.27]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4YmtMS74nLz3bLS for ; Tue, 4 Feb 2025 04:11:48 +1100 (AEDT) Received: from NTILML01.nuvoton.com (212.199.177.18.static.012.net.il [212.199.177.18]) by herzl.nuvoton.co.il (8.13.8/8.13.8) with ESMTP id 513GEwU7006474 for ; Mon, 3 Feb 2025 18:14:59 +0200 Received: from NTHCML01B.nuvoton.com (10.1.8.178) by NTILML01.nuvoton.com (10.190.1.56) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.43; Mon, 3 Feb 2025 18:14:58 +0200 Received: from NTHCCAS01.nuvoton.com (10.1.8.28) by NTHCML01B.nuvoton.com (10.1.8.178) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 4 Feb 2025 00:14:56 +0800 Received: from taln58.nuvoton.co.il (10.191.1.178) by NTHCCAS01.nuvoton.com (10.1.8.28) with Microsoft SMTP Server id 15.1.2507.39 via Frontend Transport; Tue, 4 Feb 2025 00:14:56 +0800 Received: from taln60.nuvoton.co.il (taln60 [10.191.1.180]) by taln58.nuvoton.co.il (Postfix) with ESMTP id 5B4855F650; Mon, 3 Feb 2025 18:14:55 +0200 (IST) Received: by taln60.nuvoton.co.il (Postfix, from userid 10070) id 5A6EDDC3281; Mon, 3 Feb 2025 18:14:55 +0200 (IST) From: Tomer Maimon To: Subject: [PATCH linux dev-6.6 v1 4/8] i2c: npcm: use a software flag to indicate a BER condition Date: Mon, 3 Feb 2025 18:14:46 +0200 Message-ID: <20250203161450.265480-5-tmaimon77@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250203161450.265480-1-tmaimon77@gmail.com> References: <20250203161450.265480-1-tmaimon77@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-NotSetDelaration: True X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tyrone Ting , Andi Shyti , Joel Stanley , Tali Perry Errors-To: openbmc-bounces+openbmc=archiver.kernel.org@lists.ozlabs.org Sender: "openbmc" From: Tyrone Ting If not clearing the BB (bus busy) condition in the BER (bus error) interrupt, the driver causes a timeout and hence the i2c core doesn't do the i2c transfer retry but returns the driver's return value to the upper layer instead. Clear the BB condition in the BER interrupt and a software flag is used. The driver does an i2c recovery without causing the timeout if the flag is set. Signed-off-by: Tyrone Ting Reviewed-by: Tali Perry Signed-off-by: Andi Shyti --- drivers/i2c/busses/i2c-npcm7xx.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm7xx.c index 608dc14593e2..3a695ad24018 100644 --- a/drivers/i2c/busses/i2c-npcm7xx.c +++ b/drivers/i2c/busses/i2c-npcm7xx.c @@ -335,6 +335,7 @@ struct npcm_i2c { u64 nack_cnt; u64 timeout_cnt; u64 tx_complete_cnt; + bool ber_state; /* Indicate the bus error state */ }; static inline void npcm_i2c_select_bank(struct npcm_i2c *bus, @@ -1522,6 +1523,7 @@ static void npcm_i2c_irq_handle_ber(struct npcm_i2c *bus) if (npcm_i2c_is_master(bus)) { npcm_i2c_master_abort(bus); } else { + bus->ber_state = true; npcm_i2c_clear_master_status(bus); /* Clear BB (BUS BUSY) bit */ @@ -1700,6 +1702,7 @@ static int npcm_i2c_recovery_tgclk(struct i2c_adapter *_adap) dev_dbg(bus->dev, "bus%d-0x%x recovery skipped, bus not stuck", bus->num, bus->dest_addr); npcm_i2c_reset(bus); + bus->ber_state = false; return 0; } @@ -1764,6 +1767,7 @@ static int npcm_i2c_recovery_tgclk(struct i2c_adapter *_adap) if (bus->rec_succ_cnt < ULLONG_MAX) bus->rec_succ_cnt++; } + bus->ber_state = false; return status; } @@ -2159,7 +2163,16 @@ static int npcm_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, } while (time_is_after_jiffies(time_left) && bus_busy); - if (bus_busy) { + /* + * Check the BER (bus error) state, when ber_state is true, it means that the module + * detects the bus error which is caused by some factor like that the electricity + * noise occurs on the bus. Under this condition, the module is reset and the bus + * gets recovered. + * + * While ber_state is false, the module reset and bus recovery also get done as the + * bus is busy. + */ + if (bus_busy || bus->ber_state) { iowrite8(NPCM_I2CCST_BB, bus->reg + NPCM_I2CCST); npcm_i2c_reset(bus); i2c_recover_bus(adap); -- 2.34.1