From patchwork Fri Aug 30 03:46:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tyrone Ting X-Patchwork-Id: 1978699 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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=huublalg; 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 4Ww3zv2nTlz1ygJ for ; Fri, 30 Aug 2024 13:49:15 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Ww3zd2Yl5z30TQ for ; Fri, 30 Aug 2024 13:49:01 +1000 (AEST) X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::535" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724989739; cv=none; b=W7iQF0h49N1ZasbzW7qqQ35xDdIkiz3zXyYkITAmv55x5BQCGwzHV/grfxN1IOJsAUWzQ3xbS1pSaT1CEMOU91WsToKIfHSEHdXxcg7tQDRrosKa718iS+6hkwy5Dp8XPrBM12Wx3o2/aYKWUud52PeLytqzHhOEYDV/Okn5OWRe88al2NIfNZf8fsdrrgJ/GF8m9JxMm5a20IWmUyxY+2VWdpnkUn8ZUDD0aklzAVy4/YoE2pfZjimbOsI737y2+39tqSXCp9BaVDsFNbMXx4Q/WwkGucmBNkYY9M2LGlJDbdJmajFwhIUMWtXA+PAm1SAyGorq1m/0VSsjeAAkpg== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724989739; c=relaxed/relaxed; bh=0Yuwb6+ZqfPT0JtISqh7yyK1d1c60sdj5zghOt5FrDU=; h=Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Google-Smtp-Source:X-Received:Received:From: X-Google-Original-From:To:Cc:Subject:Date:Message-Id:X-Mailer: In-Reply-To:References; b=jdwvEF8dtzknHngO659P4Se4ph99+3WcIACEgWGCw66DzMWrMewcLOJLlSH+4ltWozA/HFU++EGiOdZYW+AGRyv86J6R493MPFsFpXukv5BJfIuwsqtb6PvBWF9Hs7eebQUBBt4c18sAHkJrTVIBFqmDxvP5jcPXzjcYfA2fh/exaIVcf/o4/r/uhd0hiPGKArwHk+fvoDYI/qD2dW3f0p0zmkn9q5hBTcrbq+oFWQFDLFNIN7hQlB/OagR7xsBDr7TeTJ/OFmIFLzk6dJmf5wX7hdizXtXx+LnNurSO1a1Ou0tBdpyxa710SfhrS4RJBlnEdbbx7ifoHPdryHJySA== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=huublalg; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::535; helo=mail-pg1-x535.google.com; envelope-from=warp5tw@gmail.com; receiver=lists.ozlabs.org) smtp.mailfrom=gmail.com 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=huublalg; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::535; helo=mail-pg1-x535.google.com; envelope-from=warp5tw@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) (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 4Ww3zZ5k93z2ytl for ; Fri, 30 Aug 2024 13:48:58 +1000 (AEST) Received: by mail-pg1-x535.google.com with SMTP id 41be03b00d2f7-7cb3db0932cso966849a12.1 for ; Thu, 29 Aug 2024 20:48:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724989735; x=1725594535; 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=0Yuwb6+ZqfPT0JtISqh7yyK1d1c60sdj5zghOt5FrDU=; b=huublalg7U4e3BpMkxRYyEZecpFs8UojJxv0cxZQL+uEK8WzSR3HgQ1va052OVNfSV Rqs62t/+74xbPpqE+je+DCdP1dyOAagbK6qSbeJw2ig2Gp5hrgayHs4T4xnXAHvSyYdo qg9cdvPYd5dhSzNOFrrEG1ivYTOGpRxgabDMG9hkPCIG71UAFMd8jZ3Bg7oS9mfohsaf j41V9cDbe07y5bjXa1A9kXUTbAnCg8yVvbHsw7b6Q2VvIG45UbzcLj2IT7eUHE63czgl 3bD9U56VTe77wT3MSbs/u09CvNFuro/Nq++9N6achkDLUnL5FM3DuO6iY4fUW52S5xt4 zF9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724989735; x=1725594535; 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=0Yuwb6+ZqfPT0JtISqh7yyK1d1c60sdj5zghOt5FrDU=; b=XB9BpFraJXr5PGy/6Sv1biTU8/s0rYEPy/l1I4OqUr18x4dMMJYpJfNch9anVeF6Mx BtWe3EhLyXNx+1kYBMkBb/g4qJAKt24YoM9noQ1hL8hTQf28Rsz/feCvUvdzSFiO3QF8 43u+dTN9A9ruyehVkN1WOgFSLv3g5lJwdsxcf+RmK0gTd7WsbIPUToOdfO7pwMVcBexG MilR9aD0tShIsbYyepeYDGkAYjn7arHMnPs8XevRw6PM2td+co+K8slX7oZLerSBbucr MhbN1ZIDR6baXBIl2LC4w9vCh+OyB4WbvQghu4L1ziDE3IQu+pr9GRmXAmZ1IoGwGEa4 renA== X-Gm-Message-State: AOJu0Yx7qeAMYW8Hnj0PkFwaRg320X+CvAswWLegBTY5BeeEdmMxp8F6 n1sGxhXPhvSHOxxsXBqSzrCPBbqeztg5r75svIj1771qnlHJ7vA= X-Google-Smtp-Source: AGHT+IFQRsKAjsdhrL2+vAvZzE83PEnwKYSeTkwNNHy+5kcEHFwYymLvN94tr8b32+bjiWubAZNy8A== X-Received: by 2002:a17:902:c94c:b0:201:e646:4d8 with SMTP id d9443c01a7336-2050c3a7166mr62180945ad.26.1724989734783; Thu, 29 Aug 2024 20:48:54 -0700 (PDT) Received: from localhost (2001-b400-e338-dab5-746d-1a82-f21e-bb0a.emome-ip6.hinet.net. [2001:b400:e338:dab5:746d:1a82:f21e:bb0a]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-205152b1225sm18350175ad.22.2024.08.29.20.48.53 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 29 Aug 2024 20:48:54 -0700 (PDT) From: Tyrone Ting X-Google-Original-From: Tyrone Ting To: avifishman70@gmail.com, tmaimon77@gmail.com, tali.perry1@gmail.com, venture@google.com, yuenn@google.com, benjaminfair@google.com, andi.shyti@kernel.org, andriy.shevchenko@linux.intel.com, wsa@kernel.org, rand.sec96@gmail.com, wsa+renesas@sang-engineering.com, warp5tw@gmail.com, tali.perry@nuvoton.com, Avi.Fishman@nuvoton.com, tomer.maimon@nuvoton.com, KWLIU@nuvoton.com, JJLIU0@nuvoton.com, kfting@nuvoton.com Subject: [PATCH v2 1/7] i2c: npcm: restore slave addresses array length Date: Fri, 30 Aug 2024 11:46:34 +0800 Message-Id: <20240830034640.7049-2-kfting@nuvoton.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240830034640.7049-1-kfting@nuvoton.com> References: <20240830034640.7049-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" The smatch check warning is "buffer overflow 'npcm_i2caddr' 2 <= 9". The original design supports 10 slave addresses although only 2 addresses are required for current implementation. Restore the npcm_i2caddr array length to fix the smatch warning. Fixes: 47d506d1a28f ("i2c: npcm: Remove own slave addresses 2:10") Reported-by: Dan Carpenter Closes: https://lore.kernel.org/r/202408130818.FgDP5uNm-lkp@intel.com/ Signed-off-by: Tyrone Ting Reviewed-by: Andi Shyti --- drivers/i2c/busses/i2c-npcm7xx.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm7xx.c index 2fe68615942e..bbcb4d6668ce 100644 --- a/drivers/i2c/busses/i2c-npcm7xx.c +++ b/drivers/i2c/busses/i2c-npcm7xx.c @@ -136,11 +136,13 @@ enum i2c_addr { * Since the addr regs are sprinkled all over the address space, * use this array to get the address or each register. */ -#define I2C_NUM_OWN_ADDR 2 +#define I2C_NUM_OWN_ADDR 10 #define I2C_NUM_OWN_ADDR_SUPPORTED 2 static const int npcm_i2caddr[I2C_NUM_OWN_ADDR] = { - NPCM_I2CADDR1, NPCM_I2CADDR2, + NPCM_I2CADDR1, NPCM_I2CADDR2, NPCM_I2CADDR3, NPCM_I2CADDR4, + NPCM_I2CADDR5, NPCM_I2CADDR6, NPCM_I2CADDR7, NPCM_I2CADDR8, + NPCM_I2CADDR9, NPCM_I2CADDR10, }; #endif From patchwork Fri Aug 30 03:46:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tyrone Ting X-Patchwork-Id: 1978700 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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=KbwP6nJs; 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 4Ww4083pfmz1ydy for ; Fri, 30 Aug 2024 13:49:28 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Ww3zj0pP4z30jV for ; Fri, 30 Aug 2024 13:49:05 +1000 (AEST) X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::102b" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724989741; cv=none; b=IdhGDwbqVDxba9RbnrzaHcptfohF4JiwHnz+RP1/o1EdE8D3rP9cvMzcvHdVfeVZ13PI1Pdzw2HYsN+lFcp5am8D0W+hNjvYnbHXQjDN1MFJyHooCqIp1yyDu/ldEuJSqIhHbrKHR/Af4Qc683rexeNoSqhNb1WVB4twhcNxDZ1blOn8VWkuoCPXn6ffOUFaAggLdGNSgdsPLhgYbjMJg3QaWLwoynrGCFjN/J13saHd5maTm4UMRJg1h70neQo3jSHQcoiobNBpMA44exq5d/3AdttWK68Pez+ZVutoqcliH4wx7dW/orUbkt9tGeSstm4uWNVL29LO/HJeqfJ7Zw== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724989741; c=relaxed/relaxed; bh=nuaU/FEUSJ1zDJhf2kq5x0CsZK8UIXnkrpW0Xmu9tsI=; h=Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Google-Smtp-Source:X-Received:Received:From: X-Google-Original-From:To:Cc:Subject:Date:Message-Id:X-Mailer: In-Reply-To:References; b=VBbGSbox78f9WHxv1hjWPcCq62laAptKLS8C/fXZsGnGs0lK/sbld9rATQW0pBtNQoarS4fygyNlKhD5hoqgMZGayxwkSLSQhsNbdeSuGX6TmTHAZz8v+tQ3NtiUEkPUQedIIEst9/HkHc9KhDFsJxVr6uRAZORYTX0YhrxqR4YlIuANDoA4cl4/porvVKXCoMu38FLscUWCSEyWUleVf6O+EotZxkQxekOJxI+acFlaUuJwBRWxBQFD2/nbXyt6oj8IyxJUS8/AEB3uL4rN6A1klDLKGzUrw/dRKxypiylOcGtGhVNanKQ8tGFFh/mF6jZoDJ/Mlh+8ZwrHFI8UcA== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=KbwP6nJs; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::102b; helo=mail-pj1-x102b.google.com; envelope-from=warp5tw@gmail.com; receiver=lists.ozlabs.org) smtp.mailfrom=gmail.com 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=KbwP6nJs; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::102b; helo=mail-pj1-x102b.google.com; envelope-from=warp5tw@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) (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 4Ww3zd2L90z3bqs for ; Fri, 30 Aug 2024 13:49:01 +1000 (AEST) Received: by mail-pj1-x102b.google.com with SMTP id 98e67ed59e1d1-2d3c99033d6so1047529a91.0 for ; Thu, 29 Aug 2024 20:49:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724989738; x=1725594538; 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=nuaU/FEUSJ1zDJhf2kq5x0CsZK8UIXnkrpW0Xmu9tsI=; b=KbwP6nJs/XUfiQh0fs9SA3JPst8B5BTKXd5Iz+BJfItBh2LGqt9JpXG2kzcxo/TeS2 hmz/jEfofokoVk73kxtSNjgpkXS25vUYJbEsLxX+CTowbSODxRETCMFjOLzaIw1A1MlB 8NyJI0Am6G85gM9T1rrx1e3Xs5pBL4ZIWITKOk20Jb9F2xJv9ooC4pfhU+kjJNxbvgt3 3GAxBBe/ONeL6MFYfB3OEU4M2d5Lo0h6f9oXmLTHFubpPBqvVLNMupytUQ4ajzdcRNS5 zdlRE/ZCFsSf0FDY60bYWopnyw3jhF5rrxhk82QYbG0IpN/SNDStr1R7CHEyYaaMRQVh kT0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724989738; x=1725594538; 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=nuaU/FEUSJ1zDJhf2kq5x0CsZK8UIXnkrpW0Xmu9tsI=; b=Ufd6oYOIu/+FJ7pQ6Fsw/xJlJtwSB0mkGqJO/mLVN6x+Zp6VGZsdPz17HxLncr3eQc g0hWjDqxd2MoCqPxOm1V1p2uu5rc42uTD9phMtj8/NJQ1APhYqkumYuV13zmeG5SVEQH HiepotANUhWSXhaqHMVoYSnbKMsKdO0RRQ42ugRZhYjxX4FpzJPxoEMQHsZTM1o6Lg44 UMsgkcA+tL/4WvIbLf6WJKu2ILSnGm6nFXbgBl5KZinIFmuCcxDsEz2GBgKd2o5PKDO4 98+5KxJzBBSqRt19hAoEvnohMUtq+z+OYPXO74LnaYKHn8Sm4so7qQfsP0nc6jsuZZZd 3mCg== X-Gm-Message-State: AOJu0Yyote2q0QhUyzAKYhSPyDIqygUb97ioWJnkZXpJsULmzgYkhRiD Cqcw2HRloDRg5FNeV87xqZsJRNhvg8XaaTZM0FIDIDzFgm2bbXYyXno5yZo= X-Google-Smtp-Source: AGHT+IFvcywH8BJHv9GFcHbrQr1DMuLwHzrwh4tiQWWXNGDKDjjMuTvElE/5TNzEIJwRDxb0/LFeSA== X-Received: by 2002:a17:90b:d8f:b0:2d8:7a29:838f with SMTP id 98e67ed59e1d1-2d87a298613mr29080a91.10.1724989738433; Thu, 29 Aug 2024 20:48:58 -0700 (PDT) Received: from localhost (2001-b400-e338-dab5-746d-1a82-f21e-bb0a.emome-ip6.hinet.net. [2001:b400:e338:dab5:746d:1a82:f21e:bb0a]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d85b11b7e0sm2616978a91.17.2024.08.29.20.48.57 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 29 Aug 2024 20:48:57 -0700 (PDT) From: Tyrone Ting X-Google-Original-From: Tyrone Ting To: avifishman70@gmail.com, tmaimon77@gmail.com, tali.perry1@gmail.com, venture@google.com, yuenn@google.com, benjaminfair@google.com, andi.shyti@kernel.org, andriy.shevchenko@linux.intel.com, wsa@kernel.org, rand.sec96@gmail.com, wsa+renesas@sang-engineering.com, warp5tw@gmail.com, tali.perry@nuvoton.com, Avi.Fishman@nuvoton.com, tomer.maimon@nuvoton.com, KWLIU@nuvoton.com, JJLIU0@nuvoton.com, kfting@nuvoton.com Subject: [PATCH v2 2/7] i2c: npcm: correct the read/write operation procedure Date: Fri, 30 Aug 2024 11:46:35 +0800 Message-Id: <20240830034640.7049-3-kfting@nuvoton.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240830034640.7049-1-kfting@nuvoton.com> References: <20240830034640.7049-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" 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 bbcb4d6668ce..2b76dbfba438 100644 --- a/drivers/i2c/busses/i2c-npcm7xx.c +++ b/drivers/i2c/busses/i2c-npcm7xx.c @@ -1628,13 +1628,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 Fri Aug 30 03:46:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tyrone Ting X-Patchwork-Id: 1978702 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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=LxQc5yQ1; 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 4Ww40N1hR3z1ydy for ; Fri, 30 Aug 2024 13:49:40 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Ww3zl5g0tz3dK7 for ; Fri, 30 Aug 2024 13:49:07 +1000 (AEST) X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::429" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724989745; cv=none; b=RaKA01WqY9PytWNuta2N+xCLTIitc97eOXQ279y2tpoxsLZrTa8C0O6n+pqdW5b02+e/MQX1DommxsPEIw0q7JABbgB791VNp9C+6tXjBegVVpvN/Ui0hMzMXjvbLwv/+sitrz95zwUlBTjUaoR/ayjmRNLtAE3H4p71yWSk2BNVPdnJiPGZemHT1+8G6kErQfhP7ZNWnsciPcEn/zCsslqRuwumAb7b3rDVeJXCvwVEhbw4RvJxk9zHE+pKZc/OUTAAsnEZtpSTJH/WX1k8uCAiHEYsKYn2v9WvEayGy5bpfOquTXG7dWPZoCcuEARm3Q6Hyvwo4k0D2ewCYWObvA== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724989745; c=relaxed/relaxed; bh=VnrTLojAZPBUqXV+IxATkeEOOYkS6IQOxRjyLV//KxQ=; h=Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Google-Smtp-Source:X-Received:Received:From: X-Google-Original-From:To:Cc:Subject:Date:Message-Id:X-Mailer: In-Reply-To:References; b=mfoTy+S5qi+qL0N7pJfJKQezKcrRtS9iRxxSkOXItkAzOT81hwCpcseI8IwR9AMjdrthtv7gTLj5wCXoLJFJdwmFo6kdl3yqmREO9weA6mBccB0pRSrx4P34C5OSoMdS4uXHIOjkdAZi6x5hsUGEIZ+1IQGJyxzg4JKPGoHeFh25bphLTDVkAdxYIozsy6hjNVBHLptbPDqXe1Y6C0bQlJxsBD2NNCiwZau9Gwe9LifMYRAGR4LNvq4gQPhw79kYqOemy9H3/X4ZoeMVaJcFHZ+ZafalqmUI5TFqWTCFjy6p3xKwjoNPO7r0aokxqmmE4S2lrlAVXCD9pA2l3Fo4pw== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=LxQc5yQ1; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::429; helo=mail-pf1-x429.google.com; envelope-from=warp5tw@gmail.com; receiver=lists.ozlabs.org) smtp.mailfrom=gmail.com 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=LxQc5yQ1; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::429; helo=mail-pf1-x429.google.com; envelope-from=warp5tw@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) (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 4Ww3zh6QhNz3cQH for ; Fri, 30 Aug 2024 13:49:04 +1000 (AEST) Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-71431524f33so1031774b3a.1 for ; Thu, 29 Aug 2024 20:49:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724989742; x=1725594542; 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=VnrTLojAZPBUqXV+IxATkeEOOYkS6IQOxRjyLV//KxQ=; b=LxQc5yQ1F9VSLEs3nIEacoKiCXHxcb7UlO1xiMtqyg2mGTCsfQMhraF0YcP/wCgXEs sm6ivSUJAgbDtpW3QWkFiTXDBv5npO2CtmfieHFd8XJ3wrQi8fb+g6gFMpDnlNdqy+fp M39ua3KS8yIkOMgXSf1hZ50Q7pyAj6e2W9UbdFCy0DCrDOtxHIPWZ+VTT5stv9+vYBLy mvbA5ev2edKicWm/pnwpe+vpD8iwu7elegRN2ovf1/+/zM79NIY5yuNtKRGmcrH41p4K Nfo26vLFZ80j5GbH99XuZD23v2uGKqiMre/SqWtMQQB7dvY6fVwQ4oR7iLWOULK4JvjQ fa3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724989742; x=1725594542; 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=VnrTLojAZPBUqXV+IxATkeEOOYkS6IQOxRjyLV//KxQ=; b=LVQiwYb1n7vqFH9WVlLSq9dQ42Pl0758eqPyCIZj1CqArvnEFMdGr+XXhxwk0yRDqa 4HJ6FF+rBqJPgdcErN8a4D1Xt4aaDn/yp7puoN5+PX06MjmX12KWhbbxgRNwejOnTjvK fZ27CeNJ1IJlbYK86RUHwlF42D9/TeMjRJ4YhdOADQay44rQgXzzwcNQgvcooGswSWbP k0rKsJ4t6m5mzznzREXcd6ylT23z+HTFnrznTrGy6kptCpxmhZuZzU41iMQgm1Rrtg9z IHPANPbxSNQ+M6P9kpnY4Q3KE1hkkXLdKmQdK81OHPBShwS8keQ3Wv5V5vzZFBTDgjyt 2VYg== X-Gm-Message-State: AOJu0YyPILxiS5l5DnVqmOprld2EET9d87ToDudx/HFqdmcagYkcLIzn tYqN5GLnfN5VWnbwy+7OBqXoLBm+q7m1S4AkbR3R45rV1S3gTB8= X-Google-Smtp-Source: AGHT+IGG8X0DXHUFSFQGLI9Izd2j/MNhoYs9RHnKyE5Q3GWJUcqI+sbWLul0dVdBJ9mmrPY4THzgpw== X-Received: by 2002:a05:6a20:4f9a:b0:1cc:e4be:5fae with SMTP id adf61e73a8af0-1cce4be5fd5mr3165746637.7.1724989741837; Thu, 29 Aug 2024 20:49:01 -0700 (PDT) Received: from localhost (2001-b400-e338-dab5-746d-1a82-f21e-bb0a.emome-ip6.hinet.net. [2001:b400:e338:dab5:746d:1a82:f21e:bb0a]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-715e55b9cf0sm1907320b3a.96.2024.08.29.20.49.00 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 29 Aug 2024 20:49:01 -0700 (PDT) From: Tyrone Ting X-Google-Original-From: Tyrone Ting To: avifishman70@gmail.com, tmaimon77@gmail.com, tali.perry1@gmail.com, venture@google.com, yuenn@google.com, benjaminfair@google.com, andi.shyti@kernel.org, andriy.shevchenko@linux.intel.com, wsa@kernel.org, rand.sec96@gmail.com, wsa+renesas@sang-engineering.com, warp5tw@gmail.com, tali.perry@nuvoton.com, Avi.Fishman@nuvoton.com, tomer.maimon@nuvoton.com, KWLIU@nuvoton.com, JJLIU0@nuvoton.com, kfting@nuvoton.com Subject: [PATCH v2 3/7] i2c: npcm: use a software flag to indicate a BER condition Date: Fri, 30 Aug 2024 11:46:36 +0800 Message-Id: <20240830034640.7049-4-kfting@nuvoton.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240830034640.7049-1-kfting@nuvoton.com> References: <20240830034640.7049-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" 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 2b76dbfba438..2d034503d8bc 100644 --- a/drivers/i2c/busses/i2c-npcm7xx.c +++ b/drivers/i2c/busses/i2c-npcm7xx.c @@ -334,6 +334,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, @@ -1521,6 +1522,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 */ @@ -1699,6 +1701,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; } @@ -1763,6 +1766,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; } @@ -2158,7 +2162,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 Fri Aug 30 03:46:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tyrone Ting X-Patchwork-Id: 1978704 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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=khq7AvsY; 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)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Ww40k3vCXz1ydy for ; Fri, 30 Aug 2024 13:49:58 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Ww3zr2wB6z3fwt for ; Fri, 30 Aug 2024 13:49:12 +1000 (AEST) X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::430" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724989747; cv=none; b=CPpy153+/AVUw8lkS2r3gfXdedSw8ryotrJQQMYPHs5YNd6aUyvr23BOZiE2TA1rMumA5tUPgHcG4wqvMTqCxP9v+XPspAKocqH9zQ/TDj1luSQyn6EXnQBqa1lhHH31E0jrfWgdz4I7B2vTAGbC/3eBVKxRz7rQdn38pZU9v/wBCdOSefT1IpY+IATf6d3IRcI8Kmax9KtFt3F/xvSmz+6HmRg0QkCR+h0UZJvakPdNU9WifGWafO/kf6WjBpNJjdpNlnJgJnvsXEp8SC5Hc3aLSV7KxAiyLC8bkeK8GLKH5sXjtILCVqo2sNpo6QGroZwi/x2I5JzKenvrG1sNCQ== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724989747; c=relaxed/relaxed; bh=cFFhN9HcVpSrQjxOStAWMyvSooZCtuwnj1m4QBUIlEc=; h=Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Google-Smtp-Source:X-Received:Received:From: X-Google-Original-From:To:Cc:Subject:Date:Message-Id:X-Mailer: In-Reply-To:References; b=lv+mrFyKdhhjtA/CRD58XE1we9CTqsOlsucJAHBZm18k4iqF43wpRd7r1YEgZ4t/rlBz8vVDnfdFEG5fgMz3Mz/9snQDVw8AXtmblux756pezN6E1x3sI0wiauXhHndGFVulf51RmWUVmZim6Z8N7oWV0OXJq8l7ifZtTecegjQZ6qmRCy8fwJgPTZtsw49pQbIILi4KP2VBH7RgUHjY6MGELfzPo2fwE+Yg/Aw1hQcq5GQjAscyhr/ew7keKG3zbBKD8rhDsdb7i6W+TY+nbkXwIxoyjICs7dVo4/Iey1OfTUjTd+2wfOIquicdxuFFSZXohbIVSltdFy0ZLzYh+w== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=khq7AvsY; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::430; helo=mail-pf1-x430.google.com; envelope-from=warp5tw@gmail.com; receiver=lists.ozlabs.org) smtp.mailfrom=gmail.com 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=khq7AvsY; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::430; helo=mail-pf1-x430.google.com; envelope-from=warp5tw@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) (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 4Ww3zl29mvz3dBb for ; Fri, 30 Aug 2024 13:49:07 +1000 (AEST) Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-715e3e03831so1302897b3a.2 for ; Thu, 29 Aug 2024 20:49:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724989745; x=1725594545; 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=cFFhN9HcVpSrQjxOStAWMyvSooZCtuwnj1m4QBUIlEc=; b=khq7AvsYgfbXesS6EPgM3AJXVR/RkyiyhObNsLS6B1wWo2rzZL70KKRvCNQXeEpQ9v 5GQ+YNmIeRZz0B5RtcQDlY8fet7sZwJ4iZyb13MTJMy1bKbwQT7NeeNr2g2mm8xRM2oo d7oUQ3owxXJzbzTQEZpziGuRrcVGU2nUob/TEv8rnykttVEbCWj+6Hm0OQyrtIFn6OGA y2JWrUk027DNnp3ZISJYEyEJEAZQXR++hJ0Qu17lHmRbyIam3beEQ88HaE9kMkUVNEs6 rItFu6Eji5Du11vDRxJQG0UaPubJGgNmfwuZ33zzTMMiBBUoP7nnVLiUECxVmpWjohor UGUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724989745; x=1725594545; 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=cFFhN9HcVpSrQjxOStAWMyvSooZCtuwnj1m4QBUIlEc=; b=ir2sTbHZLryUDY7jMNrtgM7IIGdqnf/vQmzIX8tnHToUTddDhvsW4XR17ZhXBC8c8V L8A3vqg6PWc/tMNJ/ClXkW5t5ktZb72SmZxRA+LLqTZhJmhd3nss7eqHRBawo9l0EFlL lnnjXNuJCepdNSdrgCaUKc1eBekV9DEVnrS9zIUrGN6lB5NY5ekZ5TUu1n4qnTtLRoII +ugNBtoRrNCujTSlGQaf2U9qSeeDUWg7NRGUEwASyOnf//zi9Wl1ouryUR548kXABmms ZbGi+AawEAJqRf54/bfbJw+CXpd0lB1xoX58iOF1f7+O+kx9Wz4KXh0Mb1XjrRSey9Du eFaA== X-Gm-Message-State: AOJu0YxS6B5JbRuVtOUDy17HHdXiWA5DIhk5CN49eS6knkbAnXMVFKkX PJVvq01IJIiKUwnpwXqV+v1YZSkhiAt0CzNjZRfh1ThSq6ErRk8= X-Google-Smtp-Source: AGHT+IHEpVXKGjF2LZ1pVuYVBlpa86aRvwDx4kouHAiEOcK2KSzv5yMkj9qgS93kkIrDko4JqIg0wA== X-Received: by 2002:a05:6a20:d046:b0:1c4:944c:41c5 with SMTP id adf61e73a8af0-1cce0fe9b8cmr5467725637.8.1724989745036; Thu, 29 Aug 2024 20:49:05 -0700 (PDT) Received: from localhost (2001-b400-e338-dab5-746d-1a82-f21e-bb0a.emome-ip6.hinet.net. [2001:b400:e338:dab5:746d:1a82:f21e:bb0a]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20515544c78sm18342555ad.201.2024.08.29.20.49.04 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 29 Aug 2024 20:49:04 -0700 (PDT) From: Tyrone Ting X-Google-Original-From: Tyrone Ting To: avifishman70@gmail.com, tmaimon77@gmail.com, tali.perry1@gmail.com, venture@google.com, yuenn@google.com, benjaminfair@google.com, andi.shyti@kernel.org, andriy.shevchenko@linux.intel.com, wsa@kernel.org, rand.sec96@gmail.com, wsa+renesas@sang-engineering.com, warp5tw@gmail.com, tali.perry@nuvoton.com, Avi.Fishman@nuvoton.com, tomer.maimon@nuvoton.com, KWLIU@nuvoton.com, JJLIU0@nuvoton.com, kfting@nuvoton.com Subject: [PATCH v2 4/7] i2c: npcm: Modify timeout evaluation mechanism Date: Fri, 30 Aug 2024 11:46:37 +0800 Message-Id: <20240830034640.7049-5-kfting@nuvoton.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240830034640.7049-1-kfting@nuvoton.com> References: <20240830034640.7049-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" 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 2d034503d8bc..68f3d47323ab 100644 --- a/drivers/i2c/busses/i2c-npcm7xx.c +++ b/drivers/i2c/busses/i2c-npcm7xx.c @@ -2132,19 +2132,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 @@ -2183,6 +2176,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); @@ -2308,7 +2309,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 Fri Aug 30 03:46: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: 1978706 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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=NsIpMRo8; 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 4Ww40y5TQPz1yZ9 for ; Fri, 30 Aug 2024 13:50:10 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Ww3zv139qz3g6r for ; Fri, 30 Aug 2024 13:49:15 +1000 (AEST) X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::62f" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724989750; cv=none; b=EAsbzyn/T1rLAkEEgtAkca28Wuu6k9FOTRPOjqzDcsaqhiuP3NiEFYioXsoCPoRHA67N05FM8xTrQn5c2USgTpGDAByq/0uv5xf/5b9XiHIgn+BIChtiZMGSugeYlaNH2kfG+RYX8+ruSRLT1oaSIeuDSHAuMBegAijVV+Tijmm5jJAESkQCcoeTtTqLkt8XfMFH+uGtYFLOyGroIi8An4hjQXFHOEt4tXnkvew6o66HksNuedmRR1yT/c2gkktbxvR5Gk00AOHCZNjjiJNVWXz5k3QJzNL1gO8VpcEimXeYC2kt1+GUCkKf/y4vlrR6G8hMJG5k4sqVCfhOBqnwiQ== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724989750; c=relaxed/relaxed; bh=XqFq8EWoNEfLfpi6AmZzlGu/jzM8vHDtRNwp/7NnlVU=; h=Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Google-Smtp-Source:X-Received:Received:From: X-Google-Original-From:To:Cc:Subject:Date:Message-Id:X-Mailer: In-Reply-To:References; b=dHTxSUuzXN9dl2dlmaT8LFx+wYo39Kl5MGQ88UXjazrLaQy5hP0Dp9yeNBi+oyuZYVf2wGw2SThzjTIoLf9Ymk5iyk4Os9fKJ6H/nTzYWLhHXr/t1LKTEye39cSM//AuJzIuGYxqZflzelLaSoNlLVmdfY0KPI7L4CASZM2OUIek9orNQNgnFf0aqq/0gBnJGFqmTMy9qIrBPMy1eUqiyZsSFxwsSFLYiLEIeop6HTv9E+qRFB50yPVti6BPinaYYKiDJRum0yuKd7JQWgDEO9PzdcG7IbKxMPRT7v8zQfd/GMoKEF+qtbfXQrFQDUDOFxudAmOwuN3zDuUzryj21w== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=NsIpMRo8; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::62f; helo=mail-pl1-x62f.google.com; envelope-from=warp5tw@gmail.com; receiver=lists.ozlabs.org) smtp.mailfrom=gmail.com 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=NsIpMRo8; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::62f; helo=mail-pl1-x62f.google.com; envelope-from=warp5tw@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) (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 4Ww3zp4Kx2z3frS for ; Fri, 30 Aug 2024 13:49:10 +1000 (AEST) Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-201e52ca0caso9588735ad.3 for ; Thu, 29 Aug 2024 20:49:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724989748; x=1725594548; 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=XqFq8EWoNEfLfpi6AmZzlGu/jzM8vHDtRNwp/7NnlVU=; b=NsIpMRo8v3uQ72Dweyo4jyuPHh85HdYN5oqO1N2NvBQQpd1TOaX4/mpdkbfxqMPr1q dJBh/4BR/8ez0poMM5+Bc5Fybj+e/+oUAn5ignNub8lyK06wxEpxoAsDOIjzLVu/X5sV f1ZFxiZBWf1pTUZEXcxqprjBRHfKd0Ui2bj70Au3H1x/nX4hikXIjWRRD9Ebe8qtJ20g 0qyscyJ2UaQoFrtelrVZhEUeoHmveTi5Mf7QQCm25HzU2oa4X8hKnLPLb29OGXsMSp3B d6IzfXZKGDmW6RkgDJOVbRwr7ows+s0n8gk0KncfulZdFnjHcTHoCzuu4J4MpIwmKrLO NoEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724989748; x=1725594548; 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=XqFq8EWoNEfLfpi6AmZzlGu/jzM8vHDtRNwp/7NnlVU=; b=JBw9fMcJcwgGAvAE83bUGG4dF7Ar6PBuRnAmbxcUIwVZcCjYMRn1aw8T1XVJtx498o PZ+rMbbPU0N4fUCc65BHgzrflTS4neAw/svpeKvgV2k8GcQY6FsaTLJ6aM+fYE3YFgWS RaAncpeAEPpx/k/iPbPynU+dlMAOxs1QJqVFkJt/bzE9tt+KYIiLQFzZtvKqiSvYHJaI 3Gct1pWxd83BEMekXtVI5Cz2iEmFgfXCUe769nwYVnJYkkdNN/Hsw1t3CFUOnh3hG2q9 XyfQ3ydO8J4b3zvCuy3iktUjOyu17wm+DtyA2t/W3n2g/Sn2llaA3Vbm/7nf56NKE3EE Ts7w== X-Gm-Message-State: AOJu0YzvNJ0Y58J1Ve8oKp14bCr1EucJtbUTUn/hRpc2DCFJliEHXywo 69biiYxKvT3hsCe11Iuwf5wVFHHIlfNJ3PHlqE85cV2LujkA6lk= X-Google-Smtp-Source: AGHT+IHizkeEALsJJzSovFZ2tihJcLdkSMPu2gI6fgOxc/IwZpNGYjr2kbuSimtekmZnUMXCtYDQ6g== X-Received: by 2002:a17:902:da8c:b0:1fb:8cab:ccc9 with SMTP id d9443c01a7336-2050c423fabmr63064475ad.45.1724989747578; Thu, 29 Aug 2024 20:49:07 -0700 (PDT) Received: from localhost (2001-b400-e338-dab5-746d-1a82-f21e-bb0a.emome-ip6.hinet.net. [2001:b400:e338:dab5:746d:1a82:f21e:bb0a]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20515545329sm18341245ad.215.2024.08.29.20.49.06 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 29 Aug 2024 20:49:07 -0700 (PDT) From: Tyrone Ting X-Google-Original-From: Tyrone Ting To: avifishman70@gmail.com, tmaimon77@gmail.com, tali.perry1@gmail.com, venture@google.com, yuenn@google.com, benjaminfair@google.com, andi.shyti@kernel.org, andriy.shevchenko@linux.intel.com, wsa@kernel.org, rand.sec96@gmail.com, wsa+renesas@sang-engineering.com, warp5tw@gmail.com, tali.perry@nuvoton.com, Avi.Fishman@nuvoton.com, tomer.maimon@nuvoton.com, KWLIU@nuvoton.com, JJLIU0@nuvoton.com, kfting@nuvoton.com Subject: [PATCH v2 5/7] i2c: npcm: Modify the client address assignment Date: Fri, 30 Aug 2024 11:46:38 +0800 Message-Id: <20240830034640.7049-6-kfting@nuvoton.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240830034640.7049-1-kfting@nuvoton.com> References: <20240830034640.7049-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" 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 68f3d47323ab..67d156ed29b9 100644 --- a/drivers/i2c/busses/i2c-npcm7xx.c +++ b/drivers/i2c/busses/i2c-npcm7xx.c @@ -2155,6 +2155,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); @@ -2163,7 +2164,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 Fri Aug 30 03:46: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: 1978708 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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=asI6OeWk; 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 4Ww41C06xNz1yZ9 for ; Fri, 30 Aug 2024 13:50:23 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Ww3zz022Rz3gGr for ; Fri, 30 Aug 2024 13:49:19 +1000 (AEST) X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::236" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724989754; cv=none; b=YTKaKCsJGeDpwYKIBs4r9unLSXxFcV5IvxzTjR+xcrwJ1g51R0VWJ2BEv4JbphgE7HjLOquguf4jN4TxmzHam8sLdlN1jXzSQbC2BYV2XfTNgJU9r3YdSqx35obcvmAUObXpw8p1tygOsdYQWcljR/RqGDpkq/h9c/hpvHHRZCxj5COJRkkm4S5bXmK4qSYv5ZctK1E+bgcjxD4cseHLZPqe79O27Tc5rntpqxNfqMdX/O8GSdNXv6/SQhwUK4LuXqdN7C/H/ssrh2snl42vcB/CdnUS/IBnMP8qIDhA3eNPUth651zBCHzHhs0tMvPMjDgJpkfalETZW2JRYTOkUQ== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724989754; c=relaxed/relaxed; bh=2L454eIDBLlnhGWV2AoOWGsI5wsfWExAXNrzW47/oEs=; h=Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Google-Smtp-Source:X-Received:Received:From: X-Google-Original-From:To:Cc:Subject:Date:Message-Id:X-Mailer: In-Reply-To:References; b=YKXikJZENlKRK1LGQyxk38knYS15z62kCJO9UXC5iMxXogXPPcVk8X6VcYJxlfEO0FM2wBFD7hQdvgRX1zrrWCVzfOtBOCyaFuHUFTIi5ZnZCHldqhvfam+uVdudLpOXtJaUYgFEfEAuggox42vSsLgB6zls0aA2RN+iLS4MSxxLq5KttjArTNtYsp4tjBLDq7TXTFTP5A0iRRQZfeast/3QeTpHmuG4DTLK+bsBeVvDThjgEQR2X1hbh0lIwamp607AiJinHnKRjEZULrVg8Qflw2c2yDckDYk2hcQpw6eoufx8df11P4e5EfnQpsFF2kNqGSIjZjrxxkFNYLqW3Q== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=asI6OeWk; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::236; helo=mail-oi1-x236.google.com; envelope-from=warp5tw@gmail.com; receiver=lists.ozlabs.org) smtp.mailfrom=gmail.com 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=asI6OeWk; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::236; helo=mail-oi1-x236.google.com; envelope-from=warp5tw@gmail.com; receiver=lists.ozlabs.org) Received: from mail-oi1-x236.google.com (mail-oi1-x236.google.com [IPv6:2607:f8b0:4864:20::236]) (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 4Ww3zs5ZYFz3g2X for ; Fri, 30 Aug 2024 13:49:13 +1000 (AEST) Received: by mail-oi1-x236.google.com with SMTP id 5614622812f47-3df08d53820so753600b6e.0 for ; Thu, 29 Aug 2024 20:49:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724989750; x=1725594550; 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=2L454eIDBLlnhGWV2AoOWGsI5wsfWExAXNrzW47/oEs=; b=asI6OeWkzhrIKU88WaVrBZ3FyMWzTO1+2POLj/F7anfrvb9o3OqxCvMqTwjGxkvIrV p1tVVCm+G+xWZrXb1Ymr9RpJbFKZ7KAXhuQ3z9E+kcc7tmX7tWG5yoKFvzpYsmgQm/rX 1zFQxpptdDPKMw+MLyCc5y48Nj7UY3vUZrIjzTzzkjwUcwbGofQszbFZxq9BDoaOGvAk HU+4G8S6z+5v00iwokKZRmCjCYJ1kvQXyrYIEZYaTDJACz5eXBDLKk9o49h5RXehiYiu GltPdXYvsaPo/XKwQ6ZE402j17gg6bq8h3IUwmH8HgWojLS7hwrFtyKZIjjpQ1giiz3I EolQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724989750; x=1725594550; 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=2L454eIDBLlnhGWV2AoOWGsI5wsfWExAXNrzW47/oEs=; b=h8m4BgmU9NG2XvdNtXeiqMLteuh7UcgClKehFqPaVikfFKk5pcEv0TlGfEsN8oCFfF EUmFJeRfCfrYtVlP1fy1j7DP/1dgJmzF4CaBflHu4fHbz3JcaTerDm5Yj0ts7UmVLK9T aXMUfKvYmA9R3uynuiHzPlr1ZzRWJb1qiSkQo/7jBO3QEOy7FGLEw/TFf43c1qTna0yd 79TFdOeSC6leKwWGHMbO3iOka8X6hBO/NcYETgetAfKbqYUN0GMknmIclztqgntonLtH p8mGaivnYmNbn0etZO+OqVQyrUe2Dl7NIukgAPT5apP+I3yz+02GguAan+RtkpY0f92M FyhQ== X-Gm-Message-State: AOJu0Yx+UeHNsvyaeFYbdRy28YdGdRfIJqRbBFtGObnYUYbJo4qYBjXP SErdmrF84Evomw4t+j/GCeyRwHSqoLRrCseypeeZd1Mz0VRfeMs= X-Google-Smtp-Source: AGHT+IGwidesUKI82CPYAGh+W1ieZRNF+5w82gFIAHwY6Qk0VuD4TCzaj+YRUNr+4/vPjVQUAB6OdA== X-Received: by 2002:a05:6808:1809:b0:3de:13dd:3c30 with SMTP id 5614622812f47-3df05d99f8fmr5510291b6e.10.1724989750502; Thu, 29 Aug 2024 20:49:10 -0700 (PDT) Received: from localhost (2001-b400-e338-dab5-746d-1a82-f21e-bb0a.emome-ip6.hinet.net. [2001:b400:e338:dab5:746d:1a82:f21e:bb0a]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-715e575b7dfsm1866058b3a.190.2024.08.29.20.49.09 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 29 Aug 2024 20:49:10 -0700 (PDT) From: Tyrone Ting X-Google-Original-From: Tyrone Ting To: avifishman70@gmail.com, tmaimon77@gmail.com, tali.perry1@gmail.com, venture@google.com, yuenn@google.com, benjaminfair@google.com, andi.shyti@kernel.org, andriy.shevchenko@linux.intel.com, wsa@kernel.org, rand.sec96@gmail.com, wsa+renesas@sang-engineering.com, warp5tw@gmail.com, tali.perry@nuvoton.com, Avi.Fishman@nuvoton.com, tomer.maimon@nuvoton.com, KWLIU@nuvoton.com, JJLIU0@nuvoton.com, kfting@nuvoton.com Subject: [PATCH v2 6/7] i2c: npcm: use i2c frequency table Date: Fri, 30 Aug 2024 11:46:39 +0800 Message-Id: <20240830034640.7049-7-kfting@nuvoton.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240830034640.7049-1-kfting@nuvoton.com> References: <20240830034640.7049-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" 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 | 230 +++++++++++++++++++------------ 1 file changed, 144 insertions(+), 86 deletions(-) diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm7xx.c index 67d156ed29b9..cac4ea0b69b8 100644 --- a/drivers/i2c/busses/i2c-npcm7xx.c +++ b/drivers/i2c/busses/i2c-npcm7xx.c @@ -263,6 +263,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; @@ -1805,102 +1920,45 @@ 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; - src_clk_khz = bus->apb_clk / 1000; - 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; - } + break; + default: + return -EINVAL; } - /* Frequency larger than 1 MHz is not supported */ - else - return -EINVAL; + 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; - 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; - } + if (scl_table_cnt == table_size) + return -EINVAL; /* 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 */ @@ -1912,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 Fri Aug 30 03:46: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: 1978711 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=Q0QCjWOE; 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 4Ww41Y6R1Wz1yZ9 for ; Fri, 30 Aug 2024 13:50:41 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Ww40356tTz3vfD for ; Fri, 30 Aug 2024 13:49:23 +1000 (AEST) X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::630" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724989757; cv=none; b=nPlruWPp5d8OT0fu/k29nN0jj+xh2W4E+qZbute1AIJJDtCbVe50qfmn2DZnHHXk3xsF78XJ3sjPaWvptD3Fgy4PyRcw+8+KQ0lzi4/bwIc+jpdy/piz7F6nGzG+wLwcqwOAUH4aBnd79e3ROYGriyK1oS+pJ98TKBFtKj/DfDP/7VZT/UYxpiGsJ1rwuzdctIew6Orb8F4VW6XQm716euuhG45RbVKPL6JaGWqmcwVWRtQFUO8OiMDI8uxNyiIDfyyHzQs7CSWR70ItKsESmKXqUBIowxXkpJhjo6uhTY1O6USdvyYVyJ21sS8eCJRmLj/OMqn3CjSw3DywKohDjQ== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724989757; c=relaxed/relaxed; bh=R1w8U38LxbqsHMWFXxaIYW4AXwoQS5Rj9y5ARnmh8Yw=; h=Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Google-Smtp-Source:X-Received:Received:From: X-Google-Original-From:To:Cc:Subject:Date:Message-Id:X-Mailer: In-Reply-To:References; b=A3OYueR20m1JRC4ceH7dt9Dvr23BHIA3ZbXAq4qu1JS2fTgNIvID5AnK1u0Oa4flTu9MN2q8KzZqkvbFcv/zw7VdMEaMnqBnluK67WjIP8T272EnCCgwdnF4FU21Fr4BBYELfFqiuv4NN3T8FisabkpansVM5sr0NKZTYkFjgDCgz+0VADS6I6EevCH6jTurET0Di0+M7giFb07FX1L5y1q+Z4+20UPp4/C/tSyhM0k6Zwj8DJJtaNPsmgSf2rszYB+dzhOoS4dPrZgUwdEpEGgdHvWfXHXiCeKVtL8LfOYa3FaKF/Ak0JOE3XeX6oVwYBgjoMaDXGByDZJ7ZAfdpg== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Q0QCjWOE; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::630; helo=mail-pl1-x630.google.com; envelope-from=warp5tw@gmail.com; receiver=lists.ozlabs.org) smtp.mailfrom=gmail.com 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=Q0QCjWOE; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::630; helo=mail-pl1-x630.google.com; envelope-from=warp5tw@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) (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 4Ww3zx2MB3z304l for ; Fri, 30 Aug 2024 13:49:16 +1000 (AEST) Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-20230059241so12529415ad.3 for ; Thu, 29 Aug 2024 20:49:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724989754; x=1725594554; 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=R1w8U38LxbqsHMWFXxaIYW4AXwoQS5Rj9y5ARnmh8Yw=; b=Q0QCjWOEI4P8WHmlQuXzCyRZILd7TPkkCMn9iOTQB/mR5DORaXrFE4NmSRD115HQBg EpZQ98bPRBFY7w7OdabHf5KUWwaYhPWf/IWfPNQ3BTXxn59jTvMmGbw6YvCrsaJ4JUCd F6GupWhNW9JnIdUvTZgfj4XV87rkNOuiGUj8xjIBzknQqFtVXDYfIx1jZBgPXxMPwbGW B3ZIq+dfni7iUUhCLhnciTPZ8B/t5B9lad/PIoqH724VrLsv6M0QwSNU3KvRt6KCmMHv XjWgcJHUstyWJEgENc3bFOmRvun75WpF93jMhCSwPEbf1wU/leFHkM23Vh8oz80kSd4a n8cA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724989754; x=1725594554; 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=R1w8U38LxbqsHMWFXxaIYW4AXwoQS5Rj9y5ARnmh8Yw=; b=gxQ24yn+m4+CHM9mLdMqYjf+Q2T/F7W6WPjEDn+DSqtfkEpeMIvz/Iw5uij+PL3gQi 3KFqW6obJKhuA+a1VAZnnHNEy5XOTFsGKTZo8+xelg4V00dFN5Y829W1eCBUW6XB9Dgy wC8lSlSlr1yrXYyHlgbVbJUGZuM6E+sd1tbS6+Omf4DwTwOmDWEyVB97QtRToqEiRZWj tZIy78S1eO+xoZsO+HbnbPM/WXjXNfTgc/P654OsciLE6fwvrEry5Pk6WO9w0Z8020v0 N9xWbJpw0c3hg7zc+Ce+TfuKi5VNHw10TE8/j1mjcJOtYK8CW89VV1AzjbH+a0Wurivl jpkw== X-Gm-Message-State: AOJu0YzDXtTu75rJw+5HXoogXy6KzjH4dnuTYoc9tvu+CktF8hopxqmr KLgDx/S0hduDgtv9KOpO95T7J6hGzhu2gSZw4W37oqV07t8t1CM= X-Google-Smtp-Source: AGHT+IGrJD1LOrRYZRsGSK8KrWyqBhIIUuxqyDXZM8UZXfrS+XZ4T7TqZJ1nRpyYmsA8M78lXul8eg== X-Received: by 2002:a17:903:234c:b0:1fb:8419:8384 with SMTP id d9443c01a7336-2050c37255emr62935835ad.13.1724989754013; Thu, 29 Aug 2024 20:49:14 -0700 (PDT) Received: from localhost (2001-b400-e338-dab5-746d-1a82-f21e-bb0a.emome-ip6.hinet.net. [2001:b400:e338:dab5:746d:1a82:f21e:bb0a]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-205155452ecsm18259455ad.219.2024.08.29.20.49.13 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 29 Aug 2024 20:49:13 -0700 (PDT) From: Tyrone Ting X-Google-Original-From: Tyrone Ting To: avifishman70@gmail.com, tmaimon77@gmail.com, tali.perry1@gmail.com, venture@google.com, yuenn@google.com, benjaminfair@google.com, andi.shyti@kernel.org, andriy.shevchenko@linux.intel.com, wsa@kernel.org, rand.sec96@gmail.com, wsa+renesas@sang-engineering.com, warp5tw@gmail.com, tali.perry@nuvoton.com, Avi.Fishman@nuvoton.com, tomer.maimon@nuvoton.com, KWLIU@nuvoton.com, JJLIU0@nuvoton.com, kfting@nuvoton.com Subject: [PATCH v2 7/7] i2c: npcm: Enable slave in eob interrupt Date: Fri, 30 Aug 2024 11:46:40 +0800 Message-Id: <20240830034640.7049-8-kfting@nuvoton.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240830034640.7049-1-kfting@nuvoton.com> References: <20240830034640.7049-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 Reviewed-by: Tali Perry --- 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 cac4ea0b69b8..5bdc1b5895ac 100644 --- a/drivers/i2c/busses/i2c-npcm7xx.c +++ b/drivers/i2c/busses/i2c-npcm7xx.c @@ -1781,6 +1781,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; }