From patchwork Fri Sep 13 10:14: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: 1985129 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=hKARZx2Y; 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 4X4qtz2g81z1y1y for ; Fri, 13 Sep 2024 20:15:23 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4X4qtf0HjVz3cbQ for ; Fri, 13 Sep 2024 20:15:06 +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::102d" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1726222501; cv=none; b=I2pZw/v2sKesJ+ubyw6fMySNX/JQ4Zeq65gGvoTny3ajYhN/y02C/sg+PJ+xeHS7FmhQyJrE+0mI0ddEThrQbT3PfoIYzctbQPBYHtxoU9pXjzRiEWBL2I61vLPKH8gBOW4lt1wAbh/km/gYKPRM09lotiEXBXNYvAfSoI8fTcBqIjtMu9NrE8rPcHfEZb7zW93wYZsEVhQ11N3ltEubNKmlnWLwmMl+GYViK/JFY4gHsyebbkAH5aCOYEwOlZ9ywBo+0qkQnNH2OoZQjRXKKJPRch3y/rrHKhNkBCjnoGeiZT8VHjnBCht02OLfhiCOOqNcLrEAuEbn55uXNzHrOw== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1726222501; c=relaxed/relaxed; bh=mgfOidgW6QQd83F5+t8/o7O3J5kWPZhDUGZrc2VOvL0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=ivsGCJxxPnm01gLdUL/r/A6ibMIxYPHlPfXKF7uynl+dFddMzoyPAH7t72uAvx4D5l+aUhUIu/Q830UJZiUd9GX9gIWTlHEz55jkQXqaUud17dl3Log+2vwp+BEz6V/exnQ6YvxB2QxUrns0MGlf1BpV6Gz+PnJsA7dHVfkVldVil8dU08jymQNfg9wxU2bBw6VfRV6gzB4mz2aDlltA2U050an4cVH5d33TTp1ZQ6TcMYEBg25x5O7j3UCFsffSxpqq9nj00mBDWaon9pz2HKjEwTbACpux14j1CoqQhulSG9PPsglm0YCihgyA8ILeGDa0IoKs9h9TTQ2a2XJoyA== 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=hKARZx2Y; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::102d; helo=mail-pj1-x102d.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=hKARZx2Y; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::102d; helo=mail-pj1-x102d.google.com; envelope-from=warp5tw@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) (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 4X4qtY2RRmz2xmC for ; Fri, 13 Sep 2024 20:15:01 +1000 (AEST) Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-2d8a54f1250so1385858a91.0 for ; Fri, 13 Sep 2024 03:15:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726222499; x=1726827299; 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=mgfOidgW6QQd83F5+t8/o7O3J5kWPZhDUGZrc2VOvL0=; b=hKARZx2Yt3nau2ehXsB/RuKkgMVybs9K/W45bB+3UxMsE5V5GPlUjaTpKxw6pXYLZy x5QOvxkv6qn5OhtRxLgeMP4UMLg8DA1Z0P/WCs+iq/YWusJI6LKN0Ujmkz0k1pOes3kv QjzMigcSlbCYa+vLJaaQDvr+FEoTdg3QEeDa46JlU2HSK/had2/0bQjCatfGKWtuPnai zFLyNhv7SDCQBXG6fekd+u1o93nMz3ccMopwX3WcoQZ3EapO4+8rXzotNoq95EZabjwO MINnWd7MMb+l15r+tBh7dfrgALheDZi3hUrbaLOvcmzuUxG6r/yMC+9+JhDyII7+ZuNu 16bA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726222499; x=1726827299; 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=mgfOidgW6QQd83F5+t8/o7O3J5kWPZhDUGZrc2VOvL0=; b=aviUhwXb4b/UNoK5g3dLDpG7ByY7ylGBvNTWPbRhh4izpRCvNO4DJICBiFP9s9IM0v IK9Luo2p36X9XnxzH8Dw03QeJrgbn0IsuqD1O1GYvUyyz+frmFt2TL1XtSgDh3/nlT/V kVCN5VIZb6nemi6k2L4bzbiqFs/rKiBXRH5QxYwUUDtRAxLCPFvQps3OmgfsO0Xorkeo UPnd4s8Jllx7HbxPUb48ni8ZxQJINLfKkAH8qvVoa1lfKsPfnguW9048YlUEfFMnAee4 +YZTVri8ekFlU7IAri/fTJq4zCMndHswjJynpM/mlOOSZfMFkjTPqnNXAwSo0fixnJvb eyzg== X-Gm-Message-State: AOJu0YwgJn43wcdDWdd+faB8qYUYAb6YC7FWat5vXVdn9b0fZwW4VNlz vmn3ShPuJCIC4OFKcXVRVuKvLfeLwJ+DiEJq7nRRMPO8ocO5IhM= X-Google-Smtp-Source: AGHT+IGYenqOVhVnCvgeCN41uV0ql81wR0Eu1V6J2NcQ2jh3zcbTj94rIYBZr8B6KrzAZyPWuGrRcA== X-Received: by 2002:a17:90b:b83:b0:2d8:7307:3f73 with SMTP id 98e67ed59e1d1-2dba008231dmr6286966a91.39.1726222498365; Fri, 13 Sep 2024 03:14:58 -0700 (PDT) Received: from localhost (2001-b400-e334-c33a-b4cd-4a8f-209a-cf54.emome-ip6.hinet.net. [2001:b400:e334:c33a:b4cd:4a8f:209a:cf54]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2dbb9c4a253sm1347026a91.4.2024.09.13.03.14.57 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Sep 2024 03:14:57 -0700 (PDT) From: warp5tw@gmail.com X-Google-Original-From: kfting@nuvoton.com 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 v3 1/6] i2c: npcm: correct the read/write operation procedure Date: Fri, 13 Sep 2024 18:14:41 +0800 Message-Id: <20240913101445.16513-2-kfting@nuvoton.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240913101445.16513-1-kfting@nuvoton.com> References: <20240913101445.16513-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. In slave mode the XMIT bit can simply be used directly to set the state. XMIT bit can be used as an indication to the current state of the state machine during slave operation. (meaning XMIT = 1 during writing and XMIT = 0 during reading). In master operation XMIT is valid only if there are no bus errors. For example: in a multi master where the same module is switching from master to slave at runtime, and there are collisions, the XMIT bit cannot be trusted. However the maser already "knows" what the bus state is, so this bit is not needed and the driver can just track what it is currently doing. Signed-off-by: Tyrone Ting Reviewed-by: Tali Perry --- 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 Sep 13 10:14: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: 1985130 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=YCbbbpIq; 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 4X4qvB2llbz1y1y for ; Fri, 13 Sep 2024 20:15:34 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4X4qtj0wB6z3dX0 for ; Fri, 13 Sep 2024 20:15:09 +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::530" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1726222505; cv=none; b=fiIV3i6or/JJAWKc5veMRV6JVTcFcx496fykrd7Yt0Fe5WvF7IIjWBCurHH1+D3V+5bmKdA5JiPdCNlocOpFuY54a+QdPQH7MJairTYnQTu3Myo9rU/Ch1LCkwVsz146f3l1P8iqjnTd4Ll9IgGSYuK/gDV4IpLdu6mSNzh/tlxv4Dzf9I6M7loLapq95Wgut3VFUgdXV/Fz2fo5zCCRLI6H5XfefuyEa2lQN3ld39U/yVOEzLnufhcRPNyxGurjV2tppdvLsuwaukfxQQqY5bL/Bh/RyqvF9It7WwbIX7aykInr+8VTdYFDiAFliUZG6xREdgXkoVj5O64in8s9Sg== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1726222505; c=relaxed/relaxed; bh=1BGcthvFE7iZ7GLQ5GBYdiVKahiHTHcdNQMsIVlcYPg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=GVMPwsLBsZO12cjjNRWyljPazrseQbN8mH27afJjtqkh2DYszgi2TvGNVz+jF/lPAaoReikth1KoiG5HMPZMf/YW/YLY4n+dQv0H6bZUt1pnAK1C+7Vx+e0NRaX6BKICUWykjxHXWl72hsXB25HA1BwrxPK5Zta3r6U1KcA15EEvpjUtovwMLQNw6g8URfZfvqGiKbcCZhfzN3EPVuktxXLHwQdyf7D5CvfGzWtXthBTuWxWxiWfix8EYOs+C8gze6zUQ+8GyRJyxLKMP3MIBwP95IX7CBtt6UxCs9OpPmnP8E+T8pgh7vnk27eamQqS/HIGTrZ0Nl+kugydMFBqeg== 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=YCbbbpIq; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::530; helo=mail-pg1-x530.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=YCbbbpIq; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::530; helo=mail-pg1-x530.google.com; envelope-from=warp5tw@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) (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 4X4qtd0Llfz3cVG for ; Fri, 13 Sep 2024 20:15:04 +1000 (AEST) Received: by mail-pg1-x530.google.com with SMTP id 41be03b00d2f7-7db12af2f31so1855427a12.1 for ; Fri, 13 Sep 2024 03:15:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726222502; x=1726827302; 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=1BGcthvFE7iZ7GLQ5GBYdiVKahiHTHcdNQMsIVlcYPg=; b=YCbbbpIq0mFc6XjW5saUy3sHNTjbYdH5QoUKrHO8fdA8muOu4BEF/vPi6QmuK9NZ16 vUvsLAPKNONju7dFMVi7j3Cfua4m2QQiIWYNGTPhacZB36kWfQmV+SkC+bDmr4Vdc8P4 yy5BqwCmPwZNJskgk+6gRvWnlmsJNA8MoYGncHon/6JONlBQcXQdAKMHQUvFS0ZaWjLM +JV7fMBC+eBPfuijSbX68KIvPkPI6XZ+qfJPn1+ZaEYHqPPz2fMsbUby0ghCiMdaKHrD gOQsZxAwO/c1CLRaHCAyhhfj9aiDbHOaJKCQK4VGQCj594t1IPrKhLyKq7Gm4JDUntTE 5+nQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726222502; x=1726827302; 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=1BGcthvFE7iZ7GLQ5GBYdiVKahiHTHcdNQMsIVlcYPg=; b=YotCUPM43KbsulQZ05kHPKOEs/RvPFhl7wefWR8MltYhnw7jbTCpmw75gtIKWgO+1i ySRMG4weunRDoghUp2TcPi/96CqH1loN4YncbDDEBGeNroZYMD//FunlP5nJJGnBDcoL NuEPm6UAjV3lz+sdG7ezw53EippoRQPdDtDQ73Na6B23pvHY81sZ/bysgUEH/EGsYk3a hzOD0WiSkZP+xxiuK3s8DGqR2ndnEJgCuJGv/egcUO9SmSNgh5aMtN2ALqs8rJW9fDxK jW3AukfugK2rZX1cFLt1eiUQnj3JORoOuQ/d4DJ1E2eoMiRZcaFy7cmtWKDT0FDwI/sN Hkyw== X-Gm-Message-State: AOJu0YxNcMMZ3LQeDrAHMtzrga4h7TGtn1qtSk17ORiyJtOYEVoATwAJ cYVtVdaJGXi9rYUZNuZuZoHIBucIjIbvZvVEzsuyNl3ebEPfGnU= X-Google-Smtp-Source: AGHT+IFN/+8+evtZLjVKFw6cYdVaoUYs3aUOmN15pQaGNz/9tKq8F0s/IxmSII3BTDfiXTypDRemBA== X-Received: by 2002:a05:6a21:58b:b0:1cf:6953:2872 with SMTP id adf61e73a8af0-1cf764c27f2mr7849092637.48.1726222502190; Fri, 13 Sep 2024 03:15:02 -0700 (PDT) Received: from localhost (2001-b400-e334-c33a-b4cd-4a8f-209a-cf54.emome-ip6.hinet.net. [2001:b400:e334:c33a:b4cd:4a8f:209a:cf54]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7190909256csm5804618b3a.125.2024.09.13.03.15.01 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Sep 2024 03:15:01 -0700 (PDT) From: warp5tw@gmail.com X-Google-Original-From: kfting@nuvoton.com 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 v3 2/6] i2c: npcm: use a software flag to indicate a BER condition Date: Fri, 13 Sep 2024 18:14:42 +0800 Message-Id: <20240913101445.16513-3-kfting@nuvoton.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240913101445.16513-1-kfting@nuvoton.com> References: <20240913101445.16513-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. Signed-off-by: Tyrone Ting Reviewed-by: Tali Perry --- 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 Sep 13 10:14: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: 1985132 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=gvcHt3Ms; 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 4X4qvP0yGkz1y1y for ; Fri, 13 Sep 2024 20:15:45 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4X4qtm68xwz3fpr for ; Fri, 13 Sep 2024 20:15: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::42f" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1726222508; cv=none; b=QfGOBuhHRMnq+f5jfrLwCNmkZdux9l61HYESVOFraAESiiPUbFLmcDoJ4wwRBzNejvz+rzWAaqWWehS1OhK44wugARH30+cQNBBKSVdkOBsBktK6BRoq5NwEJu03VK+B47jfsrLsTkpF3c07Wy6NJJHbD00hB5ube+A1Bu+DuxOkC5qrTUWcVx/OjKpw/HGwheB990mbNvEIbjZZ2ib3xbpzzg4uD6fLTYnBLYfAdgBpgASSGUkiFkQxcL8IL721W3ULVWfBI7Fb5gLNSBq4t9t6qN5zAiT8I26L+uoLLxub6rYKHL69/bkXkDmILa7bNnzHzSjGSsR1aipFENldzA== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1726222508; c=relaxed/relaxed; bh=+lNWH+DWa3eDq8AH3LvUTVIxzt2zHamk6bE/zjqY3t4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=aiVZdxKVyH1W48e+63sryFk3QcJz0DOx0oQd8hKjfxqUlShy2w6ScqB4+7M2lMy8cwetJJXUArqdI//MwTVDaRS1F+h+zigvlEC2TBxsjI/Ti783F2VSpr07R++ScdJ+Xeo582gJybSCGJM2wdsTkOiYTBQgKYZC5lK/hjsVZY7yeqb1XVW/AUDGREVXbFSSNNRXcHkM3E/BZz0boATyqa1+ikHkq89c1UoZXlFkyL3uN9gkk/m0wKEOkNr8wpMPc2KHJZFDIo0NgB114AJSkPhbacLsxnldNBlxfFKjS+BvmruI0CyzpnjJBP/vFIsRBG9BR9lvoOuEPfvVqoI1sQ== 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=gvcHt3Ms; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::42f; helo=mail-pf1-x42f.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=gvcHt3Ms; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::42f; helo=mail-pf1-x42f.google.com; envelope-from=warp5tw@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) (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 4X4qth3ytYz2yvn for ; Fri, 13 Sep 2024 20:15:08 +1000 (AEST) Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-718e1ce7e84so1454585b3a.1 for ; Fri, 13 Sep 2024 03:15:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726222506; x=1726827306; 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=+lNWH+DWa3eDq8AH3LvUTVIxzt2zHamk6bE/zjqY3t4=; b=gvcHt3Mscz1EPhYthIfHkDc01DYSbLjkILCDMu3UQVIePVKu8TQKsYnjH0APiq5BBT z1SbKjBSJMv61knJ8YaU631AVWP3fLaFLB3V3xSsK6R4kwvZYlFbzhoUzCcDEBKAxLD0 sW76Z6DXwp2vtbrcG4+r84Z23d6Z1Ots4w58s4bXOUkRHGb62k7KWEfPWTWpGJYUW3Ki 3eOybq0fk0Dklg6hGQaFg/o3yKFfoJt57WlCPXjqPR1B7GVqhLadHz1Pp6O3BAvzzFBO wvPepT91RcEGQwlMLdjCVPD2zyD1CK4i1U17E/151I3BXJK/W2Vv96mD5t2B6r0uj5Cm AR/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726222506; x=1726827306; 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=+lNWH+DWa3eDq8AH3LvUTVIxzt2zHamk6bE/zjqY3t4=; b=qh9AbB/dzbNqOM1fikLuwo/DEmjb9CDJOFqVcqwL0ao1m8AmRaZ/E1tTXxSGN9YqgO 7YPuzQgCn51dnlWXroBxOYG3msQvcLb2Nra8LosASasxvCfPLZYWQ7uaQhr6vwaJ6+4c oxkHLt7/gy8HqmHtjDpZI/ErRCuCrLcHDwUvqlITJEfsvJhWBPXa25orAB6BPXhF/rGv p8ddLS/NdqcGvfvwZIibXKooEd0vWwtsR2T5SZcDbueChIYZkn40f8uyj5LT/y5zl7IT hj9d8EwzognK5KGN6b0xIw+UDnaxuu85NsHJG17DkAM3irGsJwF2DCp7mOP51zlI9p2G Hutw== X-Gm-Message-State: AOJu0YxfBVnPElNhPtvhY0yvegqnWyiuIBhOfuWUEa3E5HcDs4X3Zxz4 dCeDv4HHfsSN8Qo3ixTLBfJT4TTB4/vyTGspiz0rIyeRRrKk7yM= X-Google-Smtp-Source: AGHT+IFkQIjgXHiTd94AxNDF3ip5YtwQx/bfdofzs4R3oG35nn/iGiGqXD6Kv+age9FTZZNr2xySig== X-Received: by 2002:a05:6a00:139d:b0:714:28eb:ff5d with SMTP id d2e1a72fcca58-7192606bc67mr9246021b3a.8.1726222505742; Fri, 13 Sep 2024 03:15:05 -0700 (PDT) Received: from localhost (2001-b400-e334-c33a-b4cd-4a8f-209a-cf54.emome-ip6.hinet.net. [2001:b400:e334:c33a:b4cd:4a8f:209a:cf54]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71909003d0esm6008428b3a.93.2024.09.13.03.15.04 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Sep 2024 03:15:05 -0700 (PDT) From: warp5tw@gmail.com X-Google-Original-From: kfting@nuvoton.com 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 v3 3/6] i2c: npcm: Modify timeout evaluation mechanism Date: Fri, 13 Sep 2024 18:14:43 +0800 Message-Id: <20240913101445.16513-4-kfting@nuvoton.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240913101445.16513-1-kfting@nuvoton.com> References: <20240913101445.16513-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 The users want to connect a lot of masters on the same bus. This timeout is used to determine the time it takes to take bus ownership. The transactions are very long, so waiting 35ms is not enough. 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. Signed-off-by: Tyrone Ting Reviewed-by: Tali Perry --- 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 Sep 13 10:14: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: 1985133 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=SAuPpvtg; 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 4X4qvm7144z1y1y for ; Fri, 13 Sep 2024 20:16:04 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4X4qts6x6Tz3g5B for ; Fri, 13 Sep 2024 20:15:17 +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::42d" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1726222513; cv=none; b=eC4uAFRDCIIJSq8A3q99SyUpzPx6ccNfOi46DDlK8xT/GffIqjCmL3B7lMxz8iaHftyY29UJf7JN35hFw5JOXHVSPF4H4TgDvWAoYtetdGSTtePuGjjUinWgqXjqVdBWSVQygZAaL2SJQWhCnUJ36WJMQ06Vo6myQoHre+vF3brrAH8c4voGfsXMnRONVYCy65Lh1JK5p16LZNtPODIBLjTiBvLyroTnGMVwteR9gC1dLDIh8w8p78Bl+6vhZHXrDNqAH6RwQkqmN9zVfgT/RgNoNC563nVrg9HMOaLgqLCGH5xOyT8SVZhzHIxY3Xoq5BDwfcXClIm4ahtBhkltLg== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1726222513; c=relaxed/relaxed; bh=Ld5dlQNPUQTUFF/Ssx2WQipHo3yFKCbKn/t6dhaVrDQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=mmMgM8FuAEZcoJ3yaSHu8d/CvDIOTpJOo4iYbF69rrvbigkA4O9TVJsX+98SfgmCKAimFaHqk1Txs7dE1OAbKQqsu4RVIJnP1+k7bvhuGvJrjGWZ/6Z4rg2HX0rIQJNnwJb8GRr5aY6Jc3i9Vmf8QJC+1pd7gcIErevKfw11O1NFgbAHA0N94nSlmsCdwY6gjNqyyzWOup7d8OdRCt5pqVQn6A7AuQLr/5/HOTHEdxZw/zfQj3Djt4JLMl0UB8OB/DxpXzUvd/yu8U5YIuKI36bGZqvLK9g81UVg0BFIM8lIf07+0vhJHn0qb/yR8MhQ0Z4mq0hDVYcok9lMsRqrZQ== 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=SAuPpvtg; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::42d; helo=mail-pf1-x42d.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=SAuPpvtg; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::42d; helo=mail-pf1-x42d.google.com; envelope-from=warp5tw@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) (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 4X4qtn1gkxz3c8H for ; Fri, 13 Sep 2024 20:15:13 +1000 (AEST) Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-718e9c8bd83so2232877b3a.1 for ; Fri, 13 Sep 2024 03:15:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726222510; x=1726827310; 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=Ld5dlQNPUQTUFF/Ssx2WQipHo3yFKCbKn/t6dhaVrDQ=; b=SAuPpvtgUFyQ7L+qnxXRszN3qH8AnzvNL35uzj/Efnt3YWn9YxeunS9nPn/9HMj69N K4K7uvNPBagITnSs2ymA1ceTMB6ckXYTb2Sa3mwriWBvjg7qtCvxdXQIHSemFVkQD6SR 34uwLVJd+K5Kvp0ShGSFOAP6Rc26DrN76FVrcimRPH3IVksq3HYjFqVoICnHO0INHLmw u5E1iyjZ07pSbJO4z+3/vypl7RoT0USEqivD2gUODcyHJ/Hg5d+5ty2qORz0qM/znPUg dwDGAs8MpEguLxtDQoSkUlMp06CsCB4iBpPTzrfAp0SwLqHyzzN4eL/cpPYNHW4yHW8t J/0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726222510; x=1726827310; 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=Ld5dlQNPUQTUFF/Ssx2WQipHo3yFKCbKn/t6dhaVrDQ=; b=Wfn4nMkSV2ijc/Snq+yFixrSQ7ukUBTUniKgN6YpNmAyxO6StXypveSNWYuCeXHEeP 83TUSInnNmRH0B/pXA9V42klzwv9CYVxWWE5FkZ/jLbpZzL/5RQe9r700qZS7lFgVE9Q NUnAMaxycs5gMKvxwQpcol07NritsHV/E5SaOtN+qOlIj3YqYM/uoLQb4DjsJ35xQ7lF Tg2RmNgtGn3SbiG78aGYHkp0rp7+PlX0lgdb8qsIe5sfZ0Z799bLeO6/hyM/BQ3f1I0p bbv1+HVoYByLliQLhpetxMCOCt2LQMRZXAryvJ7PmbM3x37dCUwN/oYUczAtD4idUG7x c4Qg== X-Gm-Message-State: AOJu0YwUtnyLN7LlHMWGWoXaNuTd9vizNAuXJtn5vPf//MTiAqWK8M8z Ze7LG0VIU13D/srqyDEfZ4YDyHNB6Gu3RFI+T1vFfUqoIC7sY7o= X-Google-Smtp-Source: AGHT+IGt26oOAshFJlW/po5/WtDlvLOL1IGJhw4CdzWN+MaBv+2N3YYu0lqY/H1NjONEpq76mTw+/w== X-Received: by 2002:a05:6a00:6f18:b0:717:98e7:3d0 with SMTP id d2e1a72fcca58-71907ba053fmr23661051b3a.0.1726222510134; Fri, 13 Sep 2024 03:15:10 -0700 (PDT) Received: from localhost (2001-b400-e334-c33a-b4cd-4a8f-209a-cf54.emome-ip6.hinet.net. [2001:b400:e334:c33a:b4cd:4a8f:209a:cf54]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71909003c57sm5813143b3a.89.2024.09.13.03.15.09 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Sep 2024 03:15:09 -0700 (PDT) From: warp5tw@gmail.com X-Google-Original-From: kfting@nuvoton.com 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 v3 4/6] i2c: npcm: Modify the client address assignment Date: Fri, 13 Sep 2024 18:14:44 +0800 Message-Id: <20240913101445.16513-5-kfting@nuvoton.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240913101445.16513-1-kfting@nuvoton.com> References: <20240913101445.16513-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 might get called in the i2c_recover_bus logic flow at the early stage of the function npcm_i2c_master_xfer. Signed-off-by: Tyrone Ting Reviewed-by: Tali Perry --- drivers/i2c/busses/i2c-npcm7xx.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm7xx.c index 68f3d47323ab..e52e65e63600 100644 --- a/drivers/i2c/busses/i2c-npcm7xx.c +++ b/drivers/i2c/busses/i2c-npcm7xx.c @@ -2155,6 +2155,18 @@ static int npcm_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, } while (time_is_after_jiffies(time_left) && bus_busy); + /* + * Previously, the address was stored w/o left-shift by one bit and + * with that shift in the following call to npcm_i2c_master_start_xmit. + * + * Since there are cases that the i2c_recover_bus gets called at the + * early stage of the function npcm_i2c_master_xfer, the address is + * stored with the shift and used in the i2c_recover_bus call. + * + * The address is stored from bit 1 to bit 7 in the register for + * sending the i2c address later so it's left-shifted by 1 bit. + */ + 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 +2175,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 Sep 13 10:14:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tyrone Ting X-Patchwork-Id: 1985134 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=Hoxbd5M8; 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 4X4qw30gSxz1y1y for ; Fri, 13 Sep 2024 20:16:19 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4X4qtw4yR4z3cMc for ; Fri, 13 Sep 2024 20:15:20 +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::42d" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1726222516; cv=none; b=fFVtb+t7l6wHVGAx57aFINxXL4NwVVsMdPox6qd7rHcNb+m84sftykukle2AKitFHyElfu+5g7hulAEVRpLeasR686ljc9mkAWPp7TpvtnpQjW15t2MwiBfgSa7NVZ7kD8FIssscRtsYZslxjk20ErxRc1h3XpomNd7y/BX5Xt0aiRfJ47ZoeAkNdUBeMjXvsCVPCFlHPX9NfKjBncQg5gFhOYJCslhUOTima83jzlVY9yJUX8zgTRdNHMKqmdRJxwonjM5y0m9ddd6nsVjc4gW+6hvwMjb26YsHgOSs21tFEbnByG6hF1V+inomgTOVoXEECdpcf63BPKMPxW2z7w== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1726222516; c=relaxed/relaxed; bh=0eguWvSS5P4dW/hNwJ4ktkTJaC1X3VaAFzHSPVI2Av8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=jU6pFU6K4EroWw7als4Vt2YpzJEDotTwL/gge5guhwYpm22+HIPK6SWdwMo/u7ob5cd76TFZ+2RQuLQz4XL1Px71AA1bdl/Noz8HHUosW0EO4AIae4jjsm9NVaG98edLVSA+8TbIfWHzxR43vuTGuGzRNB88Gnb9CGhpm6+WECBZlJa4aN6DZSGfG/vR2pKDMpDTrX9a0nu5KtOdCZX81blr9j6zibZbClW0Df5GCNE3UA+3re04a5wOaFQHN/UlRgHghfGBBOjnE5Q7ZYgMdPfaylLgOQ3W6PXMwLUY4ysQR2Tih+YTXA9gDHrYyKTTVV1Fu2HiLgSea6F3QyDKDw== 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=Hoxbd5M8; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::42d; helo=mail-pf1-x42d.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=Hoxbd5M8; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::42d; helo=mail-pf1-x42d.google.com; envelope-from=warp5tw@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) (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 4X4qtr3v0Jz3g19 for ; Fri, 13 Sep 2024 20:15:16 +1000 (AEST) Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-717911ef035so1331206b3a.3 for ; Fri, 13 Sep 2024 03:15:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726222515; x=1726827315; 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=0eguWvSS5P4dW/hNwJ4ktkTJaC1X3VaAFzHSPVI2Av8=; b=Hoxbd5M8ohBEpaKsyZrZ7C/q0CrGC4EFIU0G+J/1O+g/D9LAd7Zwlq3bxXdNRHqN2F nIWp61QLcBpdiyaKyoyBvG2Lb59hBaliwte/RL8AUj0HlgjQj5ShJw+Vjv6EirLYdSBY gfYy5+vcDQwzDHlnrTFX5SUG/j59ySwvO+XvOcG8FtnhSDhRUyIzOiWzT1tjP7nspkco RUQWKz95z1oVTHzbyc4IZWZoTC7GwM25ZfNF62zSHDYvmxbsV0U2d0OoTxRBIll8+6yv AQugqEyQxcFRBbgsUYit5bLD3lM+dhEHyZogK96nSx40ehR276X+yo1cNaN4rftW1bpi 1MHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726222515; x=1726827315; 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=0eguWvSS5P4dW/hNwJ4ktkTJaC1X3VaAFzHSPVI2Av8=; b=CPJ0AXCnpmIctHE1L3+BQEgn6IAk8qUcfYlqiZHSEBoZ0sgrYG8+Tx/sWlmBXn+DEl /cPAJ4vvJvXx/KzKY1JaqV4djb+QysFg556qUjSTOeSwGakkBu1+3d9w49pEmAshbble kMB3bQ4oC96piVPMuWpw0PkCxBOI3LgQpXxJAELJYN8kPXPEaCjJOd2WtTDGeJz4qK+a RKXRO/KExAyhOzWSz8yK1+cZ4OmS66AhF3xEbVGX7+nQJIdZs/gh7DYMLfVzKDsrGfNg HQquEbTaiJXSPQgT4TKG3/xaRDYy2OBPe3c/scfpfSmW74eHU1CfLBTbQWgaavmmARwl BCyg== X-Gm-Message-State: AOJu0YxbKISORQ2Z65wUhZLSsnAw+hJZQGcbu04Z4BWa2DSHAbK26nDf rFsp0gOc36r9x0xBzd39BNKULX3xWopIPnKdz9NIygJOJIEE8YA= X-Google-Smtp-Source: AGHT+IHxOd9Zhdm7hKK68OvHzroEnayKX5kQbkXIa7Ti+l7PfcUUcYeuW59Up5Uz8ZhNaBonDJcf7Q== X-Received: by 2002:a05:6a00:1827:b0:70d:2a4d:2edc with SMTP id d2e1a72fcca58-719261cc770mr8490207b3a.20.1726222514783; Fri, 13 Sep 2024 03:15:14 -0700 (PDT) Received: from localhost (2001-b400-e334-c33a-b4cd-4a8f-209a-cf54.emome-ip6.hinet.net. [2001:b400:e334:c33a:b4cd:4a8f:209a:cf54]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-719090d11e6sm5762869b3a.205.2024.09.13.03.15.13 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Sep 2024 03:15:14 -0700 (PDT) From: warp5tw@gmail.com X-Google-Original-From: kfting@nuvoton.com 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 v3 5/6] i2c: npcm: use i2c frequency table Date: Fri, 13 Sep 2024 18:14:45 +0800 Message-Id: <20240913101445.16513-6-kfting@nuvoton.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240913101445.16513-1-kfting@nuvoton.com> References: <20240913101445.16513-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 The original equations were tested on a variety of chips and base clocks. Since we added devices that use higher frequencies of the module we saw that there is a mismatch between the equation and the actual results on the bus itself, measured on scope. Meanwhile, the equations were not accurate to begin with. They are an approximation of the ideal value. The ideal value is calculated per frequency of the core module. So instead of using the equations we did an optimization per module frequency, verified on a device. Most of the work was focused on the rise time of the SCL and SDA, which depends on external load of the bus and PU. Different PCB designs, or specifically to this case: the number and type of targets on the bus, impact the required values for the timing registers. Users can recalculate the numbers for each bus and get an even better optimization, but our users chose not to. We manually picked values per frequency that match the entire valid range of targets (from 1 to max number). Then we check against the AMR described in SMB spec and make sure that none of the values is exceeding. This process was led by the chip architect and included a lot of testing. Signed-off-by: Tyrone Ting Reviewed-by: Tali Perry --- 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 e52e65e63600..03de1353ad6e 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 Sep 13 10:15:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tyrone Ting X-Patchwork-Id: 1985136 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=e1/wHTQM; 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 4X4qwH15s2z1y1y for ; Fri, 13 Sep 2024 20:16:31 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4X4qvL3GVfz3cYh for ; Fri, 13 Sep 2024 20:15:42 +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=1726222539; cv=none; b=Cg/T+AtMSqEn0TP1LIiUsxgzbgupQxsFum9hlAF3yl0gu61EZpo4P8AhsV/VyFUpKTDAbWW2h25MqCtFTVyYR1wb9grqCpprbB/GeU/0JzySJyeoB1fXB7cWszBtQtjmvDeHzvoQAyY9FqgEnECrZmaG0u8NGh41Afa0/n+GO1RGGGloDHOTN4aVnmUmGrq3gAGDJlR6KIjZowvn3Qp89fKDiddQ++mNv3NNMVt3qxCMfsapG6HrfT3WjAlW5X2x4moZ1IxL3bfpkhmFHJIWAP7dVIUkuoSS1HbiIWSUBXVbWjyq1fSO2sK1kKmQAsRvpYiBbdhguuUmbkovwVhBmQ== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1726222539; c=relaxed/relaxed; bh=jVTHLdi2Mm542zmwkkAlJabphNlWmnDQC/mhVmCZ97o=; h=From:To:Cc:Subject:Date:Message-Id; b=ZZI/fg1nrGiMijiPEHR9ZeFPJawj2QiDF9GdJLERpJtcr1xk2MgUWml9g8DBypKY+wYbfzKjqgLX7UGIPKAQW/JYgnpBJmd7hd7J2dPWm4gZIyUgwnT02fzVyPwJth3T7GYglD6hdqLlZEtG6JUIHFb4aVwx8R+AN/1u7idg3RmIhgVwhnOZotGSL9+OcidJxfA+N64FJbE8j/jLjrEjb6VX8bqP2LSJB/3K0yHj8+qv5F/O9IIm5b6ZNLu3KxBq/+qft9nLGuUVop4fCNJEkCXwVUZ81zne6q7UFCAwaimU4ng4OACt4U1vbsmKg6juYAttNMo+6EHsMy4sArX9OA== 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=e1/wHTQM; 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=e1/wHTQM; 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 4X4qvH3Bg2z2yYK for ; Fri, 13 Sep 2024 20:15:39 +1000 (AEST) Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-20551e2f1f8so8025155ad.2 for ; Fri, 13 Sep 2024 03:15:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726222537; x=1726827337; darn=lists.ozlabs.org; h=message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jVTHLdi2Mm542zmwkkAlJabphNlWmnDQC/mhVmCZ97o=; b=e1/wHTQM5O1FIXv4KribQdYDN0Cn98soiD8b3OB2MZSKadD94gti3u+NcC7qoKkjE0 DjDgZxgIsnyiF21EwXNdHQg/7imV1jdw9RQduF7TRRCEsXj8gderH0wCXhsgHEux0nfF T2aONRNbr3Qw0cIsggtVtfM7COLwVdao8d7KmWyrdpbAjSqi671d11r7mitQtDT3e/L9 UXBfd/wWbDV/658KaXSN6ofup7qylSCuHSnxvd3W6ydqynrxzBM1nMHeif8ON2c8Se5o +h9pzbH64Ug4HTIMcDRKOhEmsAMxtmstRmbokodyXhQxuFoVGeE0BugNQ4Nq9BOmMCR8 AcSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726222537; x=1726827337; h=message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jVTHLdi2Mm542zmwkkAlJabphNlWmnDQC/mhVmCZ97o=; b=E6v+IKpVV79l8LX1F5i/KsZ4dKXF1wGtvpm2LJI8zP7zLNC/qK9cXAYBt9cLEd0ZfL RNmEDlrV8dyOkxkNOQEd4nAOnPQ8jGttwD685WXlw5KGfZlw6IvQgtALEHQqtA8R+IRC GKJ0CdinjHSDb9ji4ANYDTtmcniP1rHCiMzj85K3hqAzdtMitP15nRyPT54BTn4upT54 oT+WAWF9jt9uJW7zpRV0t3IKDCmIoCNQFXAd2E2dU8p3MIDuwdKtFU/FTnLSAYaewlS5 +lbPfqS9Fp50O6r0t+/ojL5Tyet3TUsn3BPpQ9B5P+O7cT4fnONzhtZg+BTblIIigT2A ALGQ== X-Gm-Message-State: AOJu0Yx8OlxR4y1WzkJ4OGdpyWv343JYBI6v1EDuyxwOEp0gVFgc22oD 3tzfW7LNUnWY6s+Or4FNHlAZHxCwcEBiljdaIH3LfmzbUh7gzao= X-Google-Smtp-Source: AGHT+IEqBgm2LjVIYJxzm7H8JtO4VCPi7B8otV/hieFQza1fVLggbc0vnIC/IgXxwUmecHv9UgzFEQ== X-Received: by 2002:a17:902:e54e:b0:1fd:791d:1437 with SMTP id d9443c01a7336-20781b476efmr34377225ad.6.1726222536829; Fri, 13 Sep 2024 03:15:36 -0700 (PDT) Received: from localhost (2001-b400-e334-c33a-b4cd-4a8f-209a-cf54.emome-ip6.hinet.net. [2001:b400:e334:c33a:b4cd:4a8f:209a:cf54]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2076afdd48esm25709495ad.178.2024.09.13.03.15.35 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Sep 2024 03:15:35 -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 v3 6/6] i2c: npcm: Enable slave in eob interrupt Date: Fri, 13 Sep 2024 18:15:32 +0800 Message-Id: <20240913101532.16571-1-kfting@nuvoton.com> X-Mailer: git-send-email 2.17.1 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 03de1353ad6e..bb4586563c0c 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; }