From patchwork Wed Aug 7 10:02:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tyrone Ting X-Patchwork-Id: 1969956 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=hKaLrUTp; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wf5PX2W7pz1yfC for ; Wed, 7 Aug 2024 20:04:32 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=hKaLrUTp; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Wf5PX1SxMz3d90 for ; Wed, 7 Aug 2024 20:04:32 +1000 (AEST) X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=hKaLrUTp; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::62c; helo=mail-pl1-x62c.google.com; envelope-from=warp5tw@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Wf5NP5NZ0z3cXy for ; Wed, 7 Aug 2024 20:03:33 +1000 (AEST) Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1fc587361b6so14439805ad.2 for ; Wed, 07 Aug 2024 03:03:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723025011; x=1723629811; darn=lists.ozlabs.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=CC5pNBBwbHzuFRI5vRop3kEGSaPPEJAGbytrwhnEs/A=; b=hKaLrUTpWT72eMPod8aZ8lQ7sIjoLTmLHMSQ+N56/m8dLW6ZJgbQJPA5Y5jNMHR/Ja rFLP80ZvSoV8nVrK0EbLfy4X1he0Tx6GHwiZSxTnZ3EjQI6KU3kDuTgw9tftWR2MSOlK CaxFA/WrhiSsrTwJ/ltmz/uZysKyzqontQjthx47JsfaNL3W+sar7MKOwPw06891HNjd zshcMaoDkHY7ifyQmMJTSq2y4diIPT612OujD29f23Dg+zVPzjnhVsy1bSWtMYI/3NrN rpNHkG7b67YpPp7RxqAiDfyCFyic0y98HeYl1eHdd3RFoIIgUq1DVt6+VpoDKgulo/dR 9iCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723025011; x=1723629811; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=CC5pNBBwbHzuFRI5vRop3kEGSaPPEJAGbytrwhnEs/A=; b=osKgutosNdP5eD7bNLF7slMXiEj+S1zmFzJuA1UYsqkV5vjO/PtbYUyfmfrhUzgY+S nJVGuBD8VGBrJnHxWZa1ZGwzhGGlP5m/fLWTqc758s+viMdS+t41l63SX45a7+E38ZCU EtDrIXmH6Fkd/jRriN1MFh+JcuJJnme8XbxCsY26lsaBj0mc9mLcYoi4Wb2+srhUarY5 q+SC3OAYsJ2E31P6KlFrPbIPuzpGXLScu5bza+dIQL8f7ZGvN28/ywjkFcDnR57ttt6c fG4zuiDRun6mInsbHD8+A002h0QsA2/f922texMoqZGCO7VqAxJ8iNIYP2zUhTjy8apH 9CsQ== X-Forwarded-Encrypted: i=1; AJvYcCUbDnsVynQHGufzddBtUn1J7m0ILwucGNaL0dg8Mgmp5l1o4JAFplDjW+mSsJ5eiTwEuk9w+S2yf4jCAYd6Tc8nGImWYrsFkB8= X-Gm-Message-State: AOJu0YzXlPCkbKrhHop9N2TpsgG2InndHoTAygUYmW1hdMwTCa+ovocj VZEXofKsoGWywX17bbXuqSp7bNTkGT2aSVmWZ0djWuLLjgd0Zes= X-Google-Smtp-Source: AGHT+IGaljIfOINvp35rTl5T4iijxPSBPWtVHz2ZOvAehR7Vkfor0vpEheNeOShza8gm7JoO5jsENQ== X-Received: by 2002:a17:902:ce10:b0:1fb:3b89:b11d with SMTP id d9443c01a7336-1ff57257f43mr185632175ad.4.1723025010560; Wed, 07 Aug 2024 03:03:30 -0700 (PDT) Received: from localhost (2001-b400-e352-b705-880f-4661-e7a1-4abb.emome-ip6.hinet.net. [2001:b400:e352:b705:880f:4661:e7a1:4abb]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ff59059f6dsm102022675ad.132.2024.08.07.03.03.29 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 07 Aug 2024 03:03:29 -0700 (PDT) From: warp5tw@gmail.com X-Google-Original-From: kfting@nuvoton.com To: tali.perry@nuvoton.com, Avi.Fishman@nuvoton.com, tomer.maimon@nuvoton.com, avifishman70@gmail.com, tmaimon77@gmail.com, tali.perry1@gmail.com, venture@google.com, yuenn@google.com, benjaminfair@google.com, andi.shyti@kernel.org, wsa+renesas@sang-engineering.com, rand.sec96@gmail.com, kwliu@nuvoton.com, jjliu0@nuvoton.com, kfting@nuvoton.com, warp5tw@gmail.com Subject: [PATCH v1 1/7] i2c: npcm: correct the read/write operation procedure Date: Wed, 7 Aug 2024 18:02:38 +0800 Message-Id: <20240807100244.16872-2-kfting@nuvoton.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240807100244.16872-1-kfting@nuvoton.com> References: <20240807100244.16872-1-kfting@nuvoton.com> 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: openbmc@lists.ozlabs.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" From: Tyrone Ting Originally the driver uses the XMIT bit in SMBnST register to decide the upcoming i2c transaction. If XMIT bit is 1, then it will be an i2c write operation. If it's 0, then a read operation will be executed. After checking the datasheet, the XMIT bit is valid when the i2c module is acting in a slave role. Use the software status to control the i2c transaction flow instead when the i2c module is acting in a master role. Fixes: 48acf8292280 ("i2c: Remove redundant comparison in npcm_i2c_reg_slave") Signed-off-by: Tyrone Ting --- drivers/i2c/busses/i2c-npcm7xx.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm7xx.c index 2fe68615942e..c8503acdaff8 100644 --- a/drivers/i2c/busses/i2c-npcm7xx.c +++ b/drivers/i2c/busses/i2c-npcm7xx.c @@ -1626,13 +1626,10 @@ static void npcm_i2c_irq_handle_sda(struct npcm_i2c *bus, u8 i2cst) npcm_i2c_wr_byte(bus, bus->dest_addr | BIT(0)); /* SDA interrupt, after start\restart */ } else { - if (NPCM_I2CST_XMIT & i2cst) { - bus->operation = I2C_WRITE_OPER; + if (bus->operation == I2C_WRITE_OPER) npcm_i2c_irq_master_handler_write(bus); - } else { - bus->operation = I2C_READ_OPER; + else if (bus->operation == I2C_READ_OPER) npcm_i2c_irq_master_handler_read(bus); - } } } From patchwork Wed Aug 7 10:02:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tyrone Ting X-Patchwork-Id: 1969960 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=J8zroKdA; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wf5QT5CxMz1yXs for ; Wed, 7 Aug 2024 20:05:21 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=J8zroKdA; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Wf5QS3LpFz3dBV for ; Wed, 7 Aug 2024 20:05:20 +1000 (AEST) X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=J8zroKdA; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::631; helo=mail-pl1-x631.google.com; envelope-from=warp5tw@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Wf5NT39VBz3cyg for ; Wed, 7 Aug 2024 20:03:37 +1000 (AEST) Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1fc65329979so14668815ad.0 for ; Wed, 07 Aug 2024 03:03:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723025015; x=1723629815; darn=lists.ozlabs.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=BDqYPFDQ8C1Tp5b7bagIZayk3yRE5OYklUz/hGN2mSE=; b=J8zroKdA9kpXhIZ38OUMVDUDqPlhUJ+Ke6rysSTnAZ+jrwKsHhsPyI+R4jXv7WfNUs RXHhrIGP9FcVqFQsAj/Ws4XVDmJQqfndAYiabthWldZVJR337ai+4HJLLH6xru214L5p g2fRh4ONL6vczte03dJ4Izlk8ntjqr6x1aGMranKm+lSe/6d37WKOxXxsldwoiYVhFg0 I21l9J2++6wbtc0u1qsjRV56sHwAkX+4IwQOrddb9oVitaJH8IRtqXacbErz4/qNO3u6 pX1lli+E0/Bxl49gqj8HKcPpZxT6F/oK/WSR544oCutjtYv+p2hy/iJ0DslWdiWLhASV X+gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723025015; x=1723629815; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=BDqYPFDQ8C1Tp5b7bagIZayk3yRE5OYklUz/hGN2mSE=; b=TowBi20gMzRP3TEkHNOKQ8PlFwIjly6gUJ8cyLmiupEg0ki7zRBLqdrY/5IQoSZ4VO fWHAAye1xlnVjMUc9nlZm1QlTZ91/1UNnatTL5Ir5UtThaOeUmE4EO/RtxMi1eAPYISp BDKF/I/6ZoFbqWcB6dn2khwWkqp5ETRasK8WKToc0Q/9WCtfvKO00z3b/2I+7edI3L9i m9kRKDOtZm1nQ2x+DW2qqi7zyu5BiFj25cXQ4PBKzhDgXxihyRViv+FEslUVFZ0YVLal JYUtSBFSV9euxI/aTjEDLqXRTXCwD+AT2yUlXrIgDX6hD29CI/wVMY+b0dnqiXiA9xYl GhRg== X-Forwarded-Encrypted: i=1; AJvYcCV+R1HDlBxJrRbFn4POrJZBOK1XUcmcXFD0kP/O2m+Q/PbfDFnGMg9FFtcxvg/ovlxgbmTerG4zGL19a7OSRyY8tTZkUl1BfCg= X-Gm-Message-State: AOJu0Yz/vsleY7dJ8P9ZSmz/+hapluuuWXlA51reAA9oofCXbA+/XQhb 6xoVvOJti2PfJJfqC2b6+ek00CmIDw57LRtd2NnwPkpRbdlpAII= X-Google-Smtp-Source: AGHT+IF6/COrwRqAiRFSVZRZmy72Ongk1XUuk5O7KX5dNirXd8DXP6iFhlCT6mU3VemP2quJG039bA== X-Received: by 2002:a17:902:f691:b0:1fb:8e98:4468 with SMTP id d9443c01a7336-1ff573f4efbmr191271825ad.50.1723025014926; Wed, 07 Aug 2024 03:03:34 -0700 (PDT) Received: from localhost (2001-b400-e352-b705-880f-4661-e7a1-4abb.emome-ip6.hinet.net. [2001:b400:e352:b705:880f:4661:e7a1:4abb]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ff58f6d80csm102373675ad.119.2024.08.07.03.03.34 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 07 Aug 2024 03:03:34 -0700 (PDT) From: warp5tw@gmail.com X-Google-Original-From: kfting@nuvoton.com To: tali.perry@nuvoton.com, Avi.Fishman@nuvoton.com, tomer.maimon@nuvoton.com, avifishman70@gmail.com, tmaimon77@gmail.com, tali.perry1@gmail.com, venture@google.com, yuenn@google.com, benjaminfair@google.com, andi.shyti@kernel.org, wsa+renesas@sang-engineering.com, rand.sec96@gmail.com, kwliu@nuvoton.com, jjliu0@nuvoton.com, kfting@nuvoton.com, warp5tw@gmail.com Subject: [PATCH v1 2/7] i2c: npcm: use a software flag to indicate a BER condition Date: Wed, 7 Aug 2024 18:02:39 +0800 Message-Id: <20240807100244.16872-3-kfting@nuvoton.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240807100244.16872-1-kfting@nuvoton.com> References: <20240807100244.16872-1-kfting@nuvoton.com> 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: openbmc@lists.ozlabs.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.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. Fixes: 48acf8292280 ("i2c: Remove redundant comparison in npcm_i2c_reg_slave") Signed-off-by: Tyrone Ting --- drivers/i2c/busses/i2c-npcm7xx.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm7xx.c index c8503acdaff8..bd444ff83a8c 100644 --- a/drivers/i2c/busses/i2c-npcm7xx.c +++ b/drivers/i2c/busses/i2c-npcm7xx.c @@ -332,6 +332,7 @@ struct npcm_i2c { u64 nack_cnt; u64 timeout_cnt; u64 tx_complete_cnt; + bool ber_state; }; static inline void npcm_i2c_select_bank(struct npcm_i2c *bus, @@ -1519,6 +1520,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 */ @@ -1697,6 +1699,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; } @@ -1761,6 +1764,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; } @@ -2156,7 +2160,7 @@ 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) { + if (bus_busy || bus->ber_state) { iowrite8(NPCM_I2CCST_BB, bus->reg + NPCM_I2CCST); npcm_i2c_reset(bus); i2c_recover_bus(adap); From patchwork Wed Aug 7 10:02:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tyrone Ting X-Patchwork-Id: 1969963 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=GgEDUpF5; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wf5RP1V3qz1yXs for ; Wed, 7 Aug 2024 20:06:09 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=GgEDUpF5; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Wf5RP0QDJz2xcw for ; Wed, 7 Aug 2024 20:06:09 +1000 (AEST) X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=GgEDUpF5; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::62c; helo=mail-pl1-x62c.google.com; envelope-from=warp5tw@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Wf5NY4BCBz3dD2 for ; Wed, 7 Aug 2024 20:03:41 +1000 (AEST) Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1fc5296e214so15873745ad.0 for ; Wed, 07 Aug 2024 03:03:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723025020; x=1723629820; darn=lists.ozlabs.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=L6yyg1kIMG7SVeWDWABjZdm83++6QaBLVs76T+TLdz8=; b=GgEDUpF5scucUt8jqBER59iq9ql6hvaTkUfHRBfDMYEFdFegdaytD8mmypolzMxuor cXnnmN3s9hQbZPxEnqQQv33xYOvqNArPYGmW5il2GatuZDMjlJA4MPBI3mPb3abJyEB9 F5gX9PF73OjeSx8MFR/WKxWVKaYTF/Q9oJSE89UAOvXx8BVNZWQsZxartDZ8sk/6RdJX eGLZXfhUqI3PgrLzpRTXKAwh7J2Lw4V9IP46kFAtYi9buFMjBHEbdQ1EIVrARLY37Ahc LJ3/3KaFEYiuDRVJtXdJaZlxfx7AsUxGl5cR/nUmz3zG58+flPz+xPcGfdUJ7dlF2qFb 54Jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723025020; x=1723629820; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=L6yyg1kIMG7SVeWDWABjZdm83++6QaBLVs76T+TLdz8=; b=jtKSpwalDcL++CDelkAqdrYbbqf0srBRBPHYM664KpNRhO4CWJVjK/t6Zv0d/3mRHa jOKUG7x7YPJWfkIzhG6pBLXjB9QkkwO+YEPPBaPzx1mDyIgM/SNQqwoMTqB72juw814S 4WEiRs/WI2d7zE59gxiNyO5fSMWPbwtQ8jutXFXeVqg6KMc/ZGWjACY9ifbXRIDSjEft uUGKr9olD3VVQQ2AosKi9AKdI2Nhrmk1MAG131KYIqsNw86+CfDWDPsj66el72623v7Y K0JI+ueVLT1mu0oho9tTUHjFcX+N18ufauuq9cJtyMcUGnE3Ra4UlFUrJIhV8blP7D78 KHYA== X-Forwarded-Encrypted: i=1; AJvYcCUkaovQW7t78Jt/ZVxURJI4ml8f10RbnHWx8vdpuz3p2mb91A9VKG1PHZ2ERCvj60JbRjNEhl8hKHXweKXJYq09/PkJwV5GDy0= X-Gm-Message-State: AOJu0YxJMAcH5xpM9k806nwICjzBkflg3tKipjxQy9K4yg4nepHQ87r4 7K/U0jVeSkjyEBPDGG+dcyJZ3kse7zJrjp1XutnRiKdUdXFPQLQ= X-Google-Smtp-Source: AGHT+IFE859a4z6aYQ+kKCDEwzwC899q7prVUXzLyaJijagUlplWhlLfQPtUbWQOx/7W4elpJ2Cpww== X-Received: by 2002:a17:902:dac1:b0:1fc:2ee3:d46f with SMTP id d9443c01a7336-1ff5725106amr236748365ad.11.1723025019906; Wed, 07 Aug 2024 03:03:39 -0700 (PDT) Received: from localhost (2001-b400-e352-b705-880f-4661-e7a1-4abb.emome-ip6.hinet.net. [2001:b400:e352:b705:880f:4661:e7a1:4abb]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ff591750fesm102297885ad.191.2024.08.07.03.03.38 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 07 Aug 2024 03:03:39 -0700 (PDT) From: warp5tw@gmail.com X-Google-Original-From: kfting@nuvoton.com To: tali.perry@nuvoton.com, Avi.Fishman@nuvoton.com, tomer.maimon@nuvoton.com, avifishman70@gmail.com, tmaimon77@gmail.com, tali.perry1@gmail.com, venture@google.com, yuenn@google.com, benjaminfair@google.com, andi.shyti@kernel.org, wsa+renesas@sang-engineering.com, rand.sec96@gmail.com, kwliu@nuvoton.com, jjliu0@nuvoton.com, kfting@nuvoton.com, warp5tw@gmail.com Subject: [PATCH v1 3/7] i2c: npcm: Modify timeout evaluation mechanism Date: Wed, 7 Aug 2024 18:02:40 +0800 Message-Id: <20240807100244.16872-4-kfting@nuvoton.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240807100244.16872-1-kfting@nuvoton.com> References: <20240807100244.16872-1-kfting@nuvoton.com> 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: openbmc@lists.ozlabs.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" From: Tyrone Ting Increase the timeout and treat it as the total timeout, including retries. The total timeout is 2 seconds now. The i2c core layer will have chances to retry to call the i2c driver transfer function if the i2c driver reports that the bus is busy and returns EAGAIN. Fixes: 48acf8292280 ("i2c: Remove redundant comparison in npcm_i2c_reg_slave") Signed-off-by: Tyrone Ting --- drivers/i2c/busses/i2c-npcm7xx.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm7xx.c index bd444ff83a8c..d115ac659900 100644 --- a/drivers/i2c/busses/i2c-npcm7xx.c +++ b/drivers/i2c/busses/i2c-npcm7xx.c @@ -2130,19 +2130,12 @@ static int npcm_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, } } - /* - * Adaptive TimeOut: estimated time in usec + 100% margin: - * 2: double the timeout for clock stretching case - * 9: bits per transaction (including the ack/nack) - */ - timeout_usec = (2 * 9 * USEC_PER_SEC / bus->bus_freq) * (2 + nread + nwrite); - timeout = max_t(unsigned long, bus->adap.timeout, usecs_to_jiffies(timeout_usec)); if (nwrite >= 32 * 1024 || nread >= 32 * 1024) { dev_err(bus->dev, "i2c%d buffer too big\n", bus->num); return -EINVAL; } - time_left = jiffies + timeout + 1; + time_left = jiffies + bus->adap.timeout / bus->adap.retries + 1; do { /* * we must clear slave address immediately when the bus is not @@ -2181,6 +2174,14 @@ static int npcm_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, if (npcm_i2c_master_start_xmit(bus, slave_addr, nwrite, nread, write_data, read_data, read_PEC, read_block)) { + /* + * Adaptive TimeOut: estimated time in usec + 100% margin: + * 2: double the timeout for clock stretching case + * 9: bits per transaction (including the ack/nack) + */ + timeout_usec = (2 * 9 * USEC_PER_SEC / bus->bus_freq) * (2 + nread + nwrite); + timeout = max_t(unsigned long, bus->adap.timeout / bus->adap.retries, + usecs_to_jiffies(timeout_usec)); time_left = wait_for_completion_timeout(&bus->cmd_complete, timeout); @@ -2306,7 +2307,7 @@ static int npcm_i2c_probe_bus(struct platform_device *pdev) adap = &bus->adap; adap->owner = THIS_MODULE; adap->retries = 3; - adap->timeout = msecs_to_jiffies(35); + adap->timeout = 2 * HZ; adap->algo = &npcm_i2c_algo; adap->quirks = &npcm_i2c_quirks; adap->algo_data = bus; From patchwork Wed Aug 7 10:02:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tyrone Ting X-Patchwork-Id: 1969964 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=UcWSFysn; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wf5Sp1QR6z1yXs for ; Wed, 7 Aug 2024 20:07:22 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=UcWSFysn; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Wf5Sp0cgFz3ckk for ; Wed, 7 Aug 2024 20:07:22 +1000 (AEST) X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=UcWSFysn; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::62e; helo=mail-pl1-x62e.google.com; envelope-from=warp5tw@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Wf5Nf2nL2z3d2S for ; Wed, 7 Aug 2024 20:03:46 +1000 (AEST) Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1fc66fc35f2so5553125ad.0 for ; Wed, 07 Aug 2024 03:03:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723025024; x=1723629824; darn=lists.ozlabs.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=65hWRo84ajW0lRVkSWXUeq2TzEhPxVKIyrTffKYFoGM=; b=UcWSFysngbZqFa5whAtdo0RNTjHj6qztwYGCjolh7NFd0i2hVzDA9uLgdycBsWA4Si 0VKnLDoK8JawRzl6pCSvrTznXeJtamHK1LHRi9dFfGDBNP7MUIIOsRwpveEyrni4xNjm 8pIXMYVvUjvCqQU2U7BQuBq5EcYJf0ggNOmXUzZOy0s/kByvwQzFW+Hkobz1QMEdfghm Z6uaeLzB+6qiYPgJo/DsBTI40og8Wms1f8BerLGmyobouVpJZJnk65f+h74GdJXS/UCJ kZg5YWYeLPPZAtOvdxxrMW4wmIWfCzwRn3j2jb7SaL2oao5x0Emmh6BSJlmFGxVxGJk1 61gA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723025024; x=1723629824; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=65hWRo84ajW0lRVkSWXUeq2TzEhPxVKIyrTffKYFoGM=; b=gQwp3AnvXEX9uYciuviy15fu2kDeSjBploz5lAuHR/o8JvLvrugUEvwB0MGTZkgPqA TfLP67lVi80I1X3BWxF4ivkCZLZO70JT6g0QlWz/rAkh6duBa+YoJan6tytz4pVMf8Ln 46CYaczoE927AZDGzbUBXJyiTDamP2ExUqNRUslH4rFXa5MjnlVRTEsUfHfWKLG8DiiZ jMx+ZxTLtfcAK1zcOKqbY8qnYKgDDgqSV0k69DUsYnO2IqlIkrKN7lKE+UOH0Iip5uYo I2v1JwKiijZ1NEJMw+9vJRBVPOiOyyWHKGYVcCSyw/g4pPKLztiwBDSGOiW53pkfwYk4 Z0kw== X-Forwarded-Encrypted: i=1; AJvYcCX8Ts9/zia/j2+VP1AP6SzJ5MT5UymU/+ZBDSg7NwVEsSpmV0f2QY4AoUukLjSeKeq0tcjVdQSadjNHqsHzHfwa2Q+XH2f+J5A= X-Gm-Message-State: AOJu0Yx1Mgb0p1bxJ5pxecfkQnisHNAJMnLkhZcspnYE11jgIVB0S0uW mONRvZMJ6bVMykeSvsJbRu2CRcovB5hZ44tytzdzyn3DretwohU= X-Google-Smtp-Source: AGHT+IFUAvPzPEGgfDcOWxF5s64WDqDfWyHHIPJ5yd/HojF5g7uCqnKGmgzEpjnXwTeU7xoKYdeSfg== X-Received: by 2002:a17:902:f64f:b0:1fb:7654:4a40 with SMTP id d9443c01a7336-20085492a0cmr22836605ad.14.1723025023921; Wed, 07 Aug 2024 03:03:43 -0700 (PDT) Received: from localhost (2001-b400-e352-b705-880f-4661-e7a1-4abb.emome-ip6.hinet.net. [2001:b400:e352:b705:880f:4661:e7a1:4abb]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ff59053847sm103141165ad.170.2024.08.07.03.03.43 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 07 Aug 2024 03:03:43 -0700 (PDT) From: warp5tw@gmail.com X-Google-Original-From: kfting@nuvoton.com To: tali.perry@nuvoton.com, Avi.Fishman@nuvoton.com, tomer.maimon@nuvoton.com, avifishman70@gmail.com, tmaimon77@gmail.com, tali.perry1@gmail.com, venture@google.com, yuenn@google.com, benjaminfair@google.com, andi.shyti@kernel.org, wsa+renesas@sang-engineering.com, rand.sec96@gmail.com, kwliu@nuvoton.com, jjliu0@nuvoton.com, kfting@nuvoton.com, warp5tw@gmail.com Subject: [PATCH v1 4/7] i2c: npcm: Modify the client address assignment Date: Wed, 7 Aug 2024 18:02:41 +0800 Message-Id: <20240807100244.16872-5-kfting@nuvoton.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240807100244.16872-1-kfting@nuvoton.com> References: <20240807100244.16872-1-kfting@nuvoton.com> 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: openbmc@lists.ozlabs.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" From: Tyrone Ting Store the client address earlier since it's used in the i2c_recover_bus logic flow. Fixes: 48acf8292280 ("i2c: Remove redundant comparison in npcm_i2c_reg_slave") Signed-off-by: Tyrone Ting --- drivers/i2c/busses/i2c-npcm7xx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm7xx.c index d115ac659900..c6f72c0e3464 100644 --- a/drivers/i2c/busses/i2c-npcm7xx.c +++ b/drivers/i2c/busses/i2c-npcm7xx.c @@ -2153,6 +2153,7 @@ static int npcm_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, } while (time_is_after_jiffies(time_left) && bus_busy); + bus->dest_addr = slave_addr << 1; if (bus_busy || bus->ber_state) { iowrite8(NPCM_I2CCST_BB, bus->reg + NPCM_I2CCST); npcm_i2c_reset(bus); @@ -2161,7 +2162,6 @@ static int npcm_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, } npcm_i2c_init_params(bus); - bus->dest_addr = slave_addr; bus->msgs = msgs; bus->msgs_num = num; bus->cmd_err = 0; From patchwork Wed Aug 7 10:02:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tyrone Ting X-Patchwork-Id: 1969965 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Y1W17gwR; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wf5Tl3mKZz1yXs for ; Wed, 7 Aug 2024 20:08:11 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Y1W17gwR; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Wf5Tl2lV4z3d8x for ; Wed, 7 Aug 2024 20:08:11 +1000 (AEST) X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Y1W17gwR; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::631; helo=mail-pl1-x631.google.com; envelope-from=warp5tw@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Wf5Nk6B0yz3cWG for ; Wed, 7 Aug 2024 20:03:50 +1000 (AEST) Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1fc66fc35f2so5553885ad.0 for ; Wed, 07 Aug 2024 03:03:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723025029; x=1723629829; darn=lists.ozlabs.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=CcI+Jyhb9Q3IkK+/vK+3g+X4+pq3JUeN+lsGpBQ4Os8=; b=Y1W17gwRouerxJk+LT657otv7ALrhNqAdlSHvRT9ONLgvYk5cUsZOgGq7ZcnXh0XtZ FOT0o05XmoQEVs+t9yMnsicYrA2qXLCAE5BeB9i2jQ1EYBj2EyvTG9iKc1NUk8X95hZR c7PxSj4B+Gnnn3wPryZ/u7lMO/hNIYTWK+E5vOvxwpk2e7yRQXUGWBjH/xbNN/hUSQm6 rqw6q8LWxDED3K/BXULEdhJGSX5i4QYadWK3K/GxGjTKsEVqaGpfBaL/lHqJmnW7zort SeXXA7T9L/cQORnyUdbDIVjbldF0uYNYZg71b2ihoNLLgZdq8UktQVd+xMTx5rw4Wmh/ 3stg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723025029; x=1723629829; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=CcI+Jyhb9Q3IkK+/vK+3g+X4+pq3JUeN+lsGpBQ4Os8=; b=eKOhFXPe/toLoBrRtrw8+yFNjVLGAvUKw7h44nmYdYnv6/DsJZtqVPdteRMWJWNBfm vdPgSc9y28UOizd58IHyaWA5M4zdW3YUvfFOVKfDM4UMDNj6KlDedFJK6ka6TEkoGNMP HPALJG1H/rBAPaCkd97p+Ia5Y/2zrnI/HcS9IHDx0q73ghPLd/C5lOHrI6cGd2ZO3LoE lCMHst/2sYnq1S/ehB9TJlun7fhdGhNTfrgWigD94V6fkOYaccvCRjO2fqrmLIilveZV zLHkQTugf6WSqKCaCWb97M4ch8E98eQ7+AagUu2iROfTw64SlhVpURPEEzeRvXqL3JY1 mqgA== X-Forwarded-Encrypted: i=1; AJvYcCUYZSVscAHTNNlYVHP7IrSBRquLPgyu60ceAOnGsc653ULRYu/H8TUgjUxANxM1KrryyErvGUAhTSbw7C8gzXAGlpv0rmryFaU= X-Gm-Message-State: AOJu0YzrtDDSotN1vXyRWlmTD49tFJcEygFOOGF7xR/nhcYubcC3DWWI ADVKcvgTxAlwFuNjxq9FHxkkxmQ2fDiZqL3/VH3wudu0gBZMbCw= X-Google-Smtp-Source: AGHT+IGwBLZOE7LcRRsdNndDg9PB4lB2xZzfrHQBg7GHeqM/R/h0JqOMG3zBCJOjXxbUAvn1c1Vjcw== X-Received: by 2002:a17:903:1c5:b0:1fd:96c7:24f5 with SMTP id d9443c01a7336-200853a437fmr27463705ad.5.1723025029152; Wed, 07 Aug 2024 03:03:49 -0700 (PDT) Received: from localhost (2001-b400-e352-b705-880f-4661-e7a1-4abb.emome-ip6.hinet.net. [2001:b400:e352:b705:880f:4661:e7a1:4abb]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ff5905b4ddsm102777315ad.173.2024.08.07.03.03.47 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 07 Aug 2024 03:03:48 -0700 (PDT) From: warp5tw@gmail.com X-Google-Original-From: kfting@nuvoton.com To: tali.perry@nuvoton.com, Avi.Fishman@nuvoton.com, tomer.maimon@nuvoton.com, avifishman70@gmail.com, tmaimon77@gmail.com, tali.perry1@gmail.com, venture@google.com, yuenn@google.com, benjaminfair@google.com, andi.shyti@kernel.org, wsa+renesas@sang-engineering.com, rand.sec96@gmail.com, kwliu@nuvoton.com, jjliu0@nuvoton.com, kfting@nuvoton.com, warp5tw@gmail.com Subject: [PATCH v1 5/7] drivers: i2c: use i2c frequency table Date: Wed, 7 Aug 2024 18:02:42 +0800 Message-Id: <20240807100244.16872-6-kfting@nuvoton.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240807100244.16872-1-kfting@nuvoton.com> References: <20240807100244.16872-1-kfting@nuvoton.com> 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: openbmc@lists.ozlabs.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" From: Tyrone Ting Modify i2c frequency from table parameters for NPCM i2c modules. Supported frequencies are: 1. 100KHz 2. 400KHz 3. 1MHz Signed-off-by: Tyrone Ting --- drivers/i2c/busses/i2c-npcm7xx.c | 226 +++++++++++++++++++------------ 1 file changed, 143 insertions(+), 83 deletions(-) diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm7xx.c index c6f72c0e3464..1537fb7baa8c 100644 --- a/drivers/i2c/busses/i2c-npcm7xx.c +++ b/drivers/i2c/busses/i2c-npcm7xx.c @@ -261,6 +261,121 @@ static const int npcm_i2caddr[I2C_NUM_OWN_ADDR] = { #define I2C_FREQ_MIN_HZ 10000 #define I2C_FREQ_MAX_HZ I2C_MAX_FAST_MODE_PLUS_FREQ +struct SMB_TIMING_T { + u32 core_clk; + u8 hldt; + u8 dbcnt; + u16 sclfrq; + u8 scllt; + u8 sclht; + bool fast_mode; +}; + +static struct SMB_TIMING_T SMB_TIMING_100KHZ[] = { + {.core_clk = 100000000, .hldt = 0x2A, .dbcnt = 0x4, .sclfrq = 0xFB, .scllt = 0x0, + .sclht = 0x0, .fast_mode = false }, + {.core_clk = 62500000, .hldt = 0x2A, .dbcnt = 0x1, .sclfrq = 0x9D, .scllt = 0x0, + .sclht = 0x0, .fast_mode = false }, + {.core_clk = 50000000, .hldt = 0x2A, .dbcnt = 0x1, .sclfrq = 0x7E, .scllt = 0x0, + .sclht = 0x0, .fast_mode = false }, + {.core_clk = 48000000, .hldt = 0x2A, .dbcnt = 0x1, .sclfrq = 0x79, .scllt = 0x0, + .sclht = 0x0, .fast_mode = false }, + {.core_clk = 40000000, .hldt = 0x2A, .dbcnt = 0x1, .sclfrq = 0x65, .scllt = 0x0, + .sclht = 0x0, .fast_mode = false }, + {.core_clk = 30000000, .hldt = 0x2A, .dbcnt = 0x1, .sclfrq = 0x4C, .scllt = 0x0, + .sclht = 0x0, .fast_mode = false }, + {.core_clk = 29000000, .hldt = 0x2A, .dbcnt = 0x1, .sclfrq = 0x49, .scllt = 0x0, + .sclht = 0x0, .fast_mode = false }, + {.core_clk = 26000000, .hldt = 0x2A, .dbcnt = 0x1, .sclfrq = 0x42, .scllt = 0x0, + .sclht = 0x0, .fast_mode = false }, + {.core_clk = 25000000, .hldt = 0x2A, .dbcnt = 0x1, .sclfrq = 0x3F, .scllt = 0x0, + .sclht = 0x0, .fast_mode = false }, + {.core_clk = 24000000, .hldt = 0x2A, .dbcnt = 0x1, .sclfrq = 0x3D, .scllt = 0x0, + .sclht = 0x0, .fast_mode = false }, + {.core_clk = 20000000, .hldt = 0x2A, .dbcnt = 0x1, .sclfrq = 0x33, .scllt = 0x0, + .sclht = 0x0, .fast_mode = false }, + {.core_clk = 16180000, .hldt = 0x2A, .dbcnt = 0x1, .sclfrq = 0x29, .scllt = 0x0, + .sclht = 0x0, .fast_mode = false }, + {.core_clk = 15000000, .hldt = 0x23, .dbcnt = 0x1, .sclfrq = 0x26, .scllt = 0x0, + .sclht = 0x0, .fast_mode = false }, + {.core_clk = 13000000, .hldt = 0x1D, .dbcnt = 0x1, .sclfrq = 0x21, .scllt = 0x0, + .sclht = 0x0, .fast_mode = false }, + {.core_clk = 12000000, .hldt = 0x1B, .dbcnt = 0x1, .sclfrq = 0x1F, .scllt = 0x0, + .sclht = 0x0, .fast_mode = false }, + {.core_clk = 10000000, .hldt = 0x18, .dbcnt = 0x1, .sclfrq = 0x1A, .scllt = 0x0, + .sclht = 0x0, .fast_mode = false }, + {.core_clk = 9000000, .hldt = 0x16, .dbcnt = 0x1, .sclfrq = 0x17, .scllt = 0x0, + .sclht = 0x0, .fast_mode = false }, + {.core_clk = 8090000, .hldt = 0x14, .dbcnt = 0x1, .sclfrq = 0x15, .scllt = 0x0, + .sclht = 0x0, .fast_mode = false }, + {.core_clk = 7500000, .hldt = 0x7, .dbcnt = 0x1, .sclfrq = 0x13, .scllt = 0x0, + .sclht = 0x0, .fast_mode = false }, + {.core_clk = 6500000, .hldt = 0xE, .dbcnt = 0x1, .sclfrq = 0x11, .scllt = 0x0, + .sclht = 0x0, .fast_mode = false }, + {.core_clk = 4000000, .hldt = 0x9, .dbcnt = 0x1, .sclfrq = 0xB, .scllt = 0x0, + .sclht = 0x0, .fast_mode = false } +}; + +static struct SMB_TIMING_T SMB_TIMING_400KHZ[] = { + {.core_clk = 100000000, .hldt = 0x2A, .dbcnt = 0x3, .sclfrq = 0x0, .scllt = 0x47, + .sclht = 0x35, .fast_mode = true }, + {.core_clk = 62500000, .hldt = 0x2A, .dbcnt = 0x2, .sclfrq = 0x0, .scllt = 0x2C, + .sclht = 0x22, .fast_mode = true }, + {.core_clk = 50000000, .hldt = 0x21, .dbcnt = 0x1, .sclfrq = 0x0, .scllt = 0x24, + .sclht = 0x1B, .fast_mode = true }, + {.core_clk = 48000000, .hldt = 0x1E, .dbcnt = 0x1, .sclfrq = 0x0, .scllt = 0x24, + .sclht = 0x19, .fast_mode = true }, + {.core_clk = 40000000, .hldt = 0x1B, .dbcnt = 0x1, .sclfrq = 0x0, .scllt = 0x1E, + .sclht = 0x14, .fast_mode = true }, + {.core_clk = 33000000, .hldt = 0x15, .dbcnt = 0x1, .sclfrq = 0x0, .scllt = 0x19, + .sclht = 0x11, .fast_mode = true }, + {.core_clk = 30000000, .hldt = 0x15, .dbcnt = 0x1, .sclfrq = 0x0, .scllt = 0x19, + .sclht = 0xD, .fast_mode = true }, + {.core_clk = 29000000, .hldt = 0x11, .dbcnt = 0x1, .sclfrq = 0x0, .scllt = 0x15, + .sclht = 0x10, .fast_mode = true }, + {.core_clk = 26000000, .hldt = 0x10, .dbcnt = 0x1, .sclfrq = 0x0, .scllt = 0x13, + .sclht = 0xE, .fast_mode = true }, + {.core_clk = 25000000, .hldt = 0xF, .dbcnt = 0x1, .sclfrq = 0x0, .scllt = 0x13, + .sclht = 0xD, .fast_mode = true }, + {.core_clk = 24000000, .hldt = 0xD, .dbcnt = 0x1, .sclfrq = 0x0, .scllt = 0x12, + .sclht = 0xD, .fast_mode = true }, + {.core_clk = 20000000, .hldt = 0xB, .dbcnt = 0x1, .sclfrq = 0x0, .scllt = 0xF, + .sclht = 0xA, .fast_mode = true }, + {.core_clk = 16180000, .hldt = 0xA, .dbcnt = 0x1, .sclfrq = 0x0, .scllt = 0xC, + .sclht = 0x9, .fast_mode = true }, + {.core_clk = 15000000, .hldt = 0x9, .dbcnt = 0x1, .sclfrq = 0x0, .scllt = 0xB, + .sclht = 0x8, .fast_mode = true }, + {.core_clk = 13000000, .hldt = 0x7, .dbcnt = 0x1, .sclfrq = 0x0, .scllt = 0xA, + .sclht = 0x7, .fast_mode = true }, + {.core_clk = 12000000, .hldt = 0x7, .dbcnt = 0x1, .sclfrq = 0x0, .scllt = 0xA, + .sclht = 0x6, .fast_mode = true }, + {.core_clk = 10000000, .hldt = 0x6, .dbcnt = 0x1, .sclfrq = 0x0, .scllt = 0x8, + .sclht = 0x5, .fast_mode = true }, +}; + +static struct SMB_TIMING_T SMB_TIMING_1000KHZ[] = { + {.core_clk = 100000000, .hldt = 0x15, .dbcnt = 0x4, .sclfrq = 0x0, .scllt = 0x1C, + .sclht = 0x15, .fast_mode = true }, + {.core_clk = 62500000, .hldt = 0xF, .dbcnt = 0x3, .sclfrq = 0x0, .scllt = 0x11, + .sclht = 0xE, .fast_mode = true }, + {.core_clk = 50000000, .hldt = 0xA, .dbcnt = 0x2, .sclfrq = 0x0, .scllt = 0xE, + .sclht = 0xB, .fast_mode = true }, + {.core_clk = 48000000, .hldt = 0x9, .dbcnt = 0x2, .sclfrq = 0x0, .scllt = 0xD, + .sclht = 0xB, .fast_mode = true }, + {.core_clk = 41000000, .hldt = 0x9, .dbcnt = 0x2, .sclfrq = 0x0, .scllt = 0xC, + .sclht = 0x9, .fast_mode = true }, + {.core_clk = 40000000, .hldt = 0x8, .dbcnt = 0x2, .sclfrq = 0x0, .scllt = 0xB, + .sclht = 0x9, .fast_mode = true }, + {.core_clk = 33000000, .hldt = 0x7, .dbcnt = 0x1, .sclfrq = 0x0, .scllt = 0xA, + .sclht = 0x7, .fast_mode = true }, + {.core_clk = 25000000, .hldt = 0x4, .dbcnt = 0x1, .sclfrq = 0x0, .scllt = 0x7, + .sclht = 0x6, .fast_mode = true }, + {.core_clk = 24000000, .hldt = 0x7, .dbcnt = 0x1, .sclfrq = 0x0, .scllt = 0x8, + .sclht = 0x5, .fast_mode = true }, + {.core_clk = 20000000, .hldt = 0x4, .dbcnt = 0x1, .sclfrq = 0x0, .scllt = 0x6, + .sclht = 0x4, .fast_mode = true }, +}; + struct npcm_i2c_data { u8 fifo_size; u32 segctl_init_val; @@ -1803,11 +1918,9 @@ static void npcm_i2c_recovery_init(struct i2c_adapter *_adap) */ static int npcm_i2c_init_clk(struct npcm_i2c *bus, u32 bus_freq_hz) { - u32 k1 = 0; - u32 k2 = 0; - u8 dbnct = 0; - u32 sclfrq = 0; - u8 hldt = 7; + struct SMB_TIMING_T *smb_timing; + u8 scl_table_cnt = 0, table_size = 0; + u8 fast_mode = 0; u32 src_clk_khz; u32 bus_freq_khz; @@ -1816,89 +1929,36 @@ static int npcm_i2c_init_clk(struct npcm_i2c *bus, u32 bus_freq_hz) bus_freq_khz = bus_freq_hz / 1000; bus->bus_freq = bus_freq_hz; - /* 100KHz and below: */ - if (bus_freq_hz <= I2C_MAX_STANDARD_MODE_FREQ) { - sclfrq = src_clk_khz / (bus_freq_khz * 4); - - if (sclfrq < SCLFRQ_MIN || sclfrq > SCLFRQ_MAX) - return -EDOM; - - if (src_clk_khz >= 40000) - hldt = 17; - else if (src_clk_khz >= 12500) - hldt = 15; - else - hldt = 7; - } - - /* 400KHz: */ - else if (bus_freq_hz <= I2C_MAX_FAST_MODE_FREQ) { - sclfrq = 0; + switch (bus_freq_hz) { + case I2C_MAX_STANDARD_MODE_FREQ: + smb_timing = SMB_TIMING_100KHZ; + table_size = ARRAY_SIZE(SMB_TIMING_100KHZ); + break; + case I2C_MAX_FAST_MODE_FREQ: + smb_timing = SMB_TIMING_400KHZ; + table_size = ARRAY_SIZE(SMB_TIMING_400KHZ); fast_mode = I2CCTL3_400K_MODE; - - if (src_clk_khz < 7500) - /* 400KHZ cannot be supported for core clock < 7.5MHz */ - return -EDOM; - - else if (src_clk_khz >= 50000) { - k1 = 80; - k2 = 48; - hldt = 12; - dbnct = 7; - } - - /* Master or Slave with frequency > 25MHz */ - else if (src_clk_khz > 25000) { - hldt = clk_coef(src_clk_khz, 300) + 7; - k1 = clk_coef(src_clk_khz, 1600); - k2 = clk_coef(src_clk_khz, 900); - } - } - - /* 1MHz: */ - else if (bus_freq_hz <= I2C_MAX_FAST_MODE_PLUS_FREQ) { - sclfrq = 0; + break; + case I2C_MAX_FAST_MODE_PLUS_FREQ: + smb_timing = SMB_TIMING_1000KHZ; + table_size = ARRAY_SIZE(SMB_TIMING_1000KHZ); fast_mode = I2CCTL3_400K_MODE; - - /* 1MHZ cannot be supported for core clock < 24 MHz */ - if (src_clk_khz < 24000) - return -EDOM; - - k1 = clk_coef(src_clk_khz, 620); - k2 = clk_coef(src_clk_khz, 380); - - /* Core clk > 40 MHz */ - if (src_clk_khz > 40000) { - /* - * Set HLDT: - * SDA hold time: (HLDT-7) * T(CLK) >= 120 - * HLDT = 120/T(CLK) + 7 = 120 * FREQ(CLK) + 7 - */ - hldt = clk_coef(src_clk_khz, 120) + 7; - } else { - hldt = 7; - dbnct = 2; - } - } - - /* Frequency larger than 1 MHz is not supported */ - else + break; + default: return -EINVAL; - - if (bus_freq_hz >= I2C_MAX_FAST_MODE_FREQ) { - k1 = round_up(k1, 2); - k2 = round_up(k2 + 1, 2); - if (k1 < SCLFRQ_MIN || k1 > SCLFRQ_MAX || - k2 < SCLFRQ_MIN || k2 > SCLFRQ_MAX) - return -EDOM; } + for (scl_table_cnt = 0 ; scl_table_cnt < table_size ; scl_table_cnt++) + if (bus->apb_clk >= smb_timing[scl_table_cnt].core_clk) + break; + /* write sclfrq value. bits [6:0] are in I2CCTL2 reg */ - iowrite8(FIELD_PREP(I2CCTL2_SCLFRQ6_0, sclfrq & 0x7F), + iowrite8(FIELD_PREP(I2CCTL2_SCLFRQ6_0, smb_timing[scl_table_cnt].sclfrq & 0x7F), bus->reg + NPCM_I2CCTL2); /* bits [8:7] are in I2CCTL3 reg */ - iowrite8(fast_mode | FIELD_PREP(I2CCTL3_SCLFRQ8_7, (sclfrq >> 7) & 0x3), + iowrite8(fast_mode | FIELD_PREP(I2CCTL3_SCLFRQ8_7, (smb_timing[scl_table_cnt].sclfrq >> 7) + & 0x3), bus->reg + NPCM_I2CCTL3); /* Select Bank 0 to access NPCM_I2CCTL4/NPCM_I2CCTL5 */ @@ -1910,13 +1970,13 @@ static int npcm_i2c_init_clk(struct npcm_i2c *bus, u32 bus_freq_hz) * k1 = 2 * SCLLT7-0 -> Low Time = k1 / 2 * k2 = 2 * SCLLT7-0 -> High Time = k2 / 2 */ - iowrite8(k1 / 2, bus->reg + NPCM_I2CSCLLT); - iowrite8(k2 / 2, bus->reg + NPCM_I2CSCLHT); + iowrite8(smb_timing[scl_table_cnt].scllt, bus->reg + NPCM_I2CSCLLT); + iowrite8(smb_timing[scl_table_cnt].sclht, bus->reg + NPCM_I2CSCLHT); - iowrite8(dbnct, bus->reg + NPCM_I2CCTL5); + iowrite8(smb_timing[scl_table_cnt].dbcnt, bus->reg + NPCM_I2CCTL5); } - iowrite8(hldt, bus->reg + NPCM_I2CCTL4); + iowrite8(smb_timing[scl_table_cnt].hldt, bus->reg + NPCM_I2CCTL4); /* Return to Bank 1, and stay there by default: */ npcm_i2c_select_bank(bus, I2C_BANK_1); From patchwork Wed Aug 7 10:02:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tyrone Ting X-Patchwork-Id: 1969966 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=axJF8ehb; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wf5Vg6TQHz1yXs for ; Wed, 7 Aug 2024 20:08:59 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=axJF8ehb; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Wf5Vg5QcFz3dHR for ; Wed, 7 Aug 2024 20:08:59 +1000 (AEST) X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=axJF8ehb; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::52c; helo=mail-pg1-x52c.google.com; envelope-from=warp5tw@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Wf5Nx40Msz3d2S for ; Wed, 7 Aug 2024 20:04:01 +1000 (AEST) Received: by mail-pg1-x52c.google.com with SMTP id 41be03b00d2f7-70b2421471aso1085101a12.0 for ; Wed, 07 Aug 2024 03:04:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723025039; x=1723629839; darn=lists.ozlabs.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=W94oTh1WrpjtYbDe0PsjN6io4lhC/2PtOkavVHNKo6A=; b=axJF8ehbyIrfoYo54qRd/2Guu4DHZF+K6xXzOZuxapo7uIKKVB1z8VHcr6lD+9PXt0 X932iWdpdaDlFCwgPnUvfSkiXsVaP73mbiKiHaqGvM8+q2ubmlunD7PC3MqYrapl7fVN dSXRShMrAl3iOUVSm8LM7bqPjoShWnKSCcE6Z3C9hWIMBzaK1SuaEB1X560AiieqX2uC OqTu8Qlw30KdfxhdDCE/3O+xqhnPZDuVKGaNw2ZDIp0EUD0bI1CTBh0zcgz1wCQSlxAL IeoqDuAYOhSNi3aK6T905uZ8suRRmcDRk7w0ompn8mqscR31e3+LGtyym0BN3ruF032H VQww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723025039; x=1723629839; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=W94oTh1WrpjtYbDe0PsjN6io4lhC/2PtOkavVHNKo6A=; b=clMTOu+Ty0cvEAXztd/hynG+g19x41aDTMJRx1Q48LDrQTqbrmvg0KN8BDwgEYCFFO BMAT13sjI0zCtrmGtmeXnBxg1uZlZvw0MHbbRU5zP1E1cXM/fc3Xa1pOMv+5AyciGyt7 +1ePYYrT/vzp+Kj/8n5WiS6pALDY+KKedY9454SPiryjwlilXexko5MbFDwIrFqY1YK7 5KlDyWedXUoWd7q6XG2bwEAYHq8kT3KZB/2MhbWq03FUuC2DkFeVPEO11JJ4QgK+2Doo nvdjcAHZsUvryUhMOe1wJSMTT2eMn5Ev5yzVoWHQwlBRD+sfWbX8YzhyOe+/1SBicIdQ P6AA== X-Forwarded-Encrypted: i=1; AJvYcCU4UWjiW7GZNBQfEQI0ZW+G2nY6k/0O+sM0YktFn1+5Qily8lIpeIkdY4WAwNl7CYJAQVOUwD3DOzyMbTj3gUYIgc+tDYe/YCY= X-Gm-Message-State: AOJu0Ywu8NPVHabsHqKTktRkBNk9667UBkC4srlmKvDzgy6eymNO+kXw Rlq5q4nVY0rhcILGKs3I8GEL1VIJkkC+YVGhOR0kll7WlHlqWx0= X-Google-Smtp-Source: AGHT+IEtErHrkaTLB2321lpC9Qnp5UW5M58gOw9LihcCHDK4055uDANBVYx2t8DdEPxzwS/tqCkoxw== X-Received: by 2002:a17:90b:4c05:b0:2c8:85c:750b with SMTP id 98e67ed59e1d1-2cff952f21emr16992766a91.34.1723025038868; Wed, 07 Aug 2024 03:03:58 -0700 (PDT) Received: from localhost (2001-b400-e352-b705-880f-4661-e7a1-4abb.emome-ip6.hinet.net. [2001:b400:e352:b705:880f:4661:e7a1:4abb]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d1b3aee9acsm1116910a91.26.2024.08.07.03.03.57 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 07 Aug 2024 03:03:58 -0700 (PDT) From: warp5tw@gmail.com X-Google-Original-From: kfting@nuvoton.com To: tali.perry@nuvoton.com, Avi.Fishman@nuvoton.com, tomer.maimon@nuvoton.com, avifishman70@gmail.com, tmaimon77@gmail.com, tali.perry1@gmail.com, venture@google.com, yuenn@google.com, benjaminfair@google.com, andi.shyti@kernel.org, wsa+renesas@sang-engineering.com, rand.sec96@gmail.com, kwliu@nuvoton.com, jjliu0@nuvoton.com, kfting@nuvoton.com, warp5tw@gmail.com Subject: [PATCH v1 6/7] i2c-npcm7xx.c: Enable slave in eob interrupt Date: Wed, 7 Aug 2024 18:02:43 +0800 Message-Id: <20240807100244.16872-7-kfting@nuvoton.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240807100244.16872-1-kfting@nuvoton.com> References: <20240807100244.16872-1-kfting@nuvoton.com> 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: openbmc@lists.ozlabs.org, Charles Boyer , Vivekanand Veeracholan , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" From: Charles Boyer Nuvoton slave enable was in user space API call master_xfer, so it is subject to delays from the OS scheduler. If the BMC is not enabled for slave mode in time for master to send response, then it will NAK the address match. Then the PLDM request timeout occurs. If the slave enable is moved to the EOB interrupt service routine, then the BMC can be ready in slave mode by the time it needs to receive a response. Signed-off-by: Charles Boyer Signed-off-by: Vivekanand Veeracholan Signed-off-by: Tyrone Ting --- drivers/i2c/busses/i2c-npcm7xx.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm7xx.c index 1537fb7baa8c..1af6a927b9c1 100644 --- a/drivers/i2c/busses/i2c-npcm7xx.c +++ b/drivers/i2c/busses/i2c-npcm7xx.c @@ -1779,6 +1779,12 @@ static int npcm_i2c_int_master_handler(struct npcm_i2c *bus) (FIELD_GET(NPCM_I2CCST3_EO_BUSY, ioread8(bus->reg + NPCM_I2CCST3)))) { npcm_i2c_irq_handle_eob(bus); +#if IS_ENABLED(CONFIG_I2C_SLAVE) + /* reenable slave if it was enabled */ + if (bus->slave) + iowrite8((bus->slave->addr & 0x7F) | NPCM_I2CADDR_SAEN, + bus->reg + NPCM_I2CADDR1); +#endif return 0; } From patchwork Wed Aug 7 10:02:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tyrone Ting X-Patchwork-Id: 1969967 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=N8dGHlmZ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wf5Wc1p1Pz1yXs for ; Wed, 7 Aug 2024 20:09:48 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=N8dGHlmZ; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Wf5Wc0m4vz3dBg for ; Wed, 7 Aug 2024 20:09:48 +1000 (AEST) X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=N8dGHlmZ; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::531; helo=mail-pg1-x531.google.com; envelope-from=warp5tw@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Wf5P15467z3dFL for ; Wed, 7 Aug 2024 20:04:05 +1000 (AEST) Received: by mail-pg1-x531.google.com with SMTP id 41be03b00d2f7-7a92098ec97so1336089a12.2 for ; Wed, 07 Aug 2024 03:04:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723025043; x=1723629843; darn=lists.ozlabs.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=1JQZAPTxcfDOXPbIWl9UOyALCV+YMvtNIVhFTIQlcJQ=; b=N8dGHlmZgp61AmJWBiXlS09r0z51pd9RpuiLLT+xpQp8BuzlL+AwH1YA+UOD3x0Y6c OyImTo7eZwq0wxv+P++22vzRJ3PYwfUu5h5/oumqPeuSC2qgtUtfC2uPT318MmDDHAJ1 6ky82FqDHUrAbtMjWRdZ9My3Gmrjw0B2xrDrLqWOJnSJ+1q/qEldDf9Pvew5GawfcCJN mJHgUe50uF2Dl55XhYpQ8m4s5aNma0bJqG7V9MsI+/O75b0aMdQWHsyjGi0A2Am9k5xt 39sA//VF7kcPZOW9cVlcLTnrToOCGd8kMpst83tamGROCHytAPD1OiYDWPCfTbicqpSU 8gcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723025043; x=1723629843; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=1JQZAPTxcfDOXPbIWl9UOyALCV+YMvtNIVhFTIQlcJQ=; b=IhfIJLoqrYk6Fe1gl56npRyyrDRxbKCpIXf5YGi+ahKcmofpQyDPsFdULf/83x/nrl WDcvxMqgs7p6VjwafPlCoe2rcXTFpSe27L668A2aSJC4+VC8u3fFkerZR/DxEv2wGBaP h9ch7fZWZOfrLatIqhsHEHouxQ0rM1aS1/SvxXbEzUJ+McuCpE/MY+Z5SMTU6jpV54Q1 xYR5yEVaBJW5i5bNFtHcE6x7wASk3uo30/qoHs+EItO9+ag7KzMKITlVRhPTyNwBvpNw QvM6lD6KDD4u7cXWthYu+CwProeRpmsNl18Ty1M7JoUeGULfRFvOGPXWuzlrsSJ4mfCr Vqow== X-Forwarded-Encrypted: i=1; AJvYcCWiM4I+e3oxLeJdo5cRHz0hXt+Eu17vpa4VdJ2wZ4VIWeB+V2pT1mEPyDuJPY1rskRxvf/bjtDC2MlxyOk8+h6WbiA53nHXQPA= X-Gm-Message-State: AOJu0YxlyyFbkK2ub923TuptXBLoUKNJwZK2O27V5mkJSCqxZx7MEJuz bJQ735kjC9ZUM58znQYptEgQjj3QLvOc8mfRnmgdFdDcXPz/sh0= X-Google-Smtp-Source: AGHT+IHLo+ice5A1u5x85W8GsjViC9J2LkR5NJKcSzy4BETbX/PdHIGxniL82sI4lZtiaksXi+tBjg== X-Received: by 2002:a05:6a20:7346:b0:1c4:986a:de71 with SMTP id adf61e73a8af0-1c69960e1a1mr20396150637.35.1723025043040; Wed, 07 Aug 2024 03:04:03 -0700 (PDT) Received: from localhost (2001-b400-e352-b705-880f-4661-e7a1-4abb.emome-ip6.hinet.net. [2001:b400:e352:b705:880f:4661:e7a1:4abb]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7106ed15a42sm8111594b3a.182.2024.08.07.03.04.01 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 07 Aug 2024 03:04:02 -0700 (PDT) From: warp5tw@gmail.com X-Google-Original-From: kfting@nuvoton.com To: tali.perry@nuvoton.com, Avi.Fishman@nuvoton.com, tomer.maimon@nuvoton.com, avifishman70@gmail.com, tmaimon77@gmail.com, tali.perry1@gmail.com, venture@google.com, yuenn@google.com, benjaminfair@google.com, andi.shyti@kernel.org, wsa+renesas@sang-engineering.com, rand.sec96@gmail.com, kwliu@nuvoton.com, jjliu0@nuvoton.com, kfting@nuvoton.com, warp5tw@gmail.com Subject: [PATCH v1 7/7] i2c: npcm: fix checkpatch Date: Wed, 7 Aug 2024 18:02:44 +0800 Message-Id: <20240807100244.16872-8-kfting@nuvoton.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240807100244.16872-1-kfting@nuvoton.com> References: <20240807100244.16872-1-kfting@nuvoton.com> 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: openbmc@lists.ozlabs.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" From: Tyrone Ting Fix checkpatch warning. Fixes: 48acf8292280 ("i2c: Remove redundant comparison in npcm_i2c_reg_slave") Signed-off-by: Tyrone Ting --- drivers/i2c/busses/i2c-npcm7xx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm7xx.c index 1af6a927b9c1..dbe652d628ee 100644 --- a/drivers/i2c/busses/i2c-npcm7xx.c +++ b/drivers/i2c/busses/i2c-npcm7xx.c @@ -1783,7 +1783,7 @@ static int npcm_i2c_int_master_handler(struct npcm_i2c *bus) /* reenable slave if it was enabled */ if (bus->slave) iowrite8((bus->slave->addr & 0x7F) | NPCM_I2CADDR_SAEN, - bus->reg + NPCM_I2CADDR1); + bus->reg + NPCM_I2CADDR1); #endif return 0; }