From nobody Thu Nov 28 13:42:00 2024 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 126D01BCA15; Tue, 1 Oct 2024 06:29:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727764159; cv=none; b=nZd+EKuTDjQkgT/oneBKIjOJfNN+eEUI8Cfs+3Dir6CQHWvYkTMewUApC9+uv1FM9hdLjmysm14nbOHwO0uiN9SDh5qMOM9frBmthMTTUYhGzdyfz+IFt+iL6YQSJTTW24/IokWDBoqKg8fDbfefcVrkM8032k+0TEoPHL/eYEc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727764159; c=relaxed/simple; bh=Z0EgJkSV+YBVAMFiQyi04yGgkhMhHKzXytf1IQwWUic=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=u8Woj4uXzUqzeDIdeyaAWUPTM/5mFtRoj6PSCbIrKVIhmpOBdy4Fe3d+aRkAE+RoEJcBh/ZqKncRRvBVgsk1zxnizPij3Kf2h8gJJjSGS7LWSrtEn1KTfPRAY4DGRB2AQ8agFaNaD6tQtQlaantYSxR6LAy9N7bh1XcQTvsKI7g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=nYsJwjuV; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nYsJwjuV" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-20b58f2e1f4so18530985ad.2; Mon, 30 Sep 2024 23:29:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727764157; x=1728368957; darn=vger.kernel.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=nYsJwjuVVi8tR6gK2cta5eWL5JbDPTk37lI19oUyYbhtutdpymbEQ5grurLkBTG8kZ GA3paxxSKXY94vkxIUYQhpKzLbWGoPW61Co3ixCza2QhPJBW1qbqWv0evnz37J7scFiE y5AoEBLvkqeLm0M2OcYZgfNWPVHfGoAQp+9RQIn/eC/8a73R00h7LtQwCNEeWXeCTUym bfrVa+N1jTLG9yny9xbIaJ1mzKwMZI27c25wBKRJCcOmcYIswZWIxsuiWTuef/hiPYTH sdW75SI+BZMfanIv7t2uRZOd2/zMlXuu+DBkrtvK3HhQrpQCc2hi9ViMmrFiVnkCvNnu 59aA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727764157; x=1728368957; 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=PERnbKm+zoNXu20nwbZisdrX0rIw4DK2IB0XVDhiPqzampToDGf4ocoelUK4He6P/t +Ti9d06Z/edXp8cHMF7awauHG5PbcNU5ZQidZeFJ7SuHKb7ZEoQMDoDumnirrXrLCUXi g4Edf93F894pGu6lKLtSNWR7TJwiTrwmxekPDUza2/SYm0ccfAuBB3uyZyzNDBk+CZLD WKoAUGARBtlNl0zKf8JHmdlOPp5Kw9PsrdpCMpDR1AgqlhEbL1qyoc5HxHEIgpSiKtUW Y15usI9nFLzlOe9VYa45SraE9+DJBmYOOdjthrGyxpfvjWSvE80BM3DtS4HPmKrBf5w/ Fx1g== X-Forwarded-Encrypted: i=1; AJvYcCVGKqLtA69Y+VW+DiYO8X4rvEVYaRDUMSVtewACPKiUfhaNaMVvXkL7dpjBKC3OCC1Lt/PEhtxAsnU=@vger.kernel.org, AJvYcCVrdIVE0mJjRJopVQC6dJ0RuJLuRdGKQs/ftSdsHvR9oBy0fYlTOyYqzBcbNlenl/lC2OzT9bodxBg0/p+r@vger.kernel.org X-Gm-Message-State: AOJu0YxWcMmIONh/oRgrUzyyYWz96n/ecLE65EKH/OXsOCwxwic/ttV0 AJJSk1TdBzMxp7+sLH5G8CqeOHVOlxae/GpO27N5KwYR/vHXPWE= X-Google-Smtp-Source: AGHT+IEGgc2H9KW6IF6JSqvVGEvxrh93vP8PdPD3gKW/pW7XUuaAD+zCQEBtQ//63IbUWmT78h4MFQ== X-Received: by 2002:a17:903:184:b0:20b:57f0:b394 with SMTP id d9443c01a7336-20b57f0b612mr7096065ad.20.1727764157085; Mon, 30 Sep 2024 23:29:17 -0700 (PDT) Received: from localhost (2001-b400-e30e-7f15-c94a-d42b-025a-8ff3.emome-ip6.hinet.net. [2001:b400:e30e:7f15:c94a:d42b:25a:8ff3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20b37da012fsm63736375ad.96.2024.09.30.23.29.16 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 30 Sep 2024 23:29:16 -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 Cc: openbmc@lists.ozlabs.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 1/6] i2c: npcm: correct the read/write operation procedure Date: Tue, 1 Oct 2024 14:28:50 +0800 Message-Id: <20241001062855.6928-2-kfting@nuvoton.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20241001062855.6928-1-kfting@nuvoton.com> References: <20241001062855.6928-1-kfting@nuvoton.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 =3D 1 during writing and XMIT =3D 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-npcm= 7xx.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 =3D I2C_WRITE_OPER; + if (bus->operation =3D=3D I2C_WRITE_OPER) npcm_i2c_irq_master_handler_write(bus); - } else { - bus->operation =3D I2C_READ_OPER; + else if (bus->operation =3D=3D I2C_READ_OPER) npcm_i2c_irq_master_handler_read(bus); - } } } =20 --=20 2.34.1 From nobody Thu Nov 28 13:42:00 2024 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0F8A21BC070; Tue, 1 Oct 2024 06:29:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727764185; cv=none; b=g+ynOXPd67yjfWc4fkQ9M8JqIOBEoUjDvUQk7UHgBjZRLKqkvgoZ8N6KQGZ9fDWfUBuqEnvWDXE1YsTlbuFbxr6883qL0PR9PykXCQh0dKwRHq3+tY5x0shkNqjWKrBYSlvjomlpWa/1iF4xShnnK1OB+A60of6+711R6GZoK/4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727764185; c=relaxed/simple; bh=OkYg7NWlOVU9VKRfqHFVtlKyNBN/7BNgGLNzYJzYJeQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=bJYKXnczKsJ9YYL6+F79YiW+e99HGGceiW1jMxCiGlD8bEOOGbYD0jSOPfk52tE4c90A4/2wbIpBsZ4a0WFQsgrZu1TZ06bjZaMi26nu0tpu8kzt25CkLcVCGF0yVZy+L6RlEy6w5aToWYP7TNsd4RhJt8/M4hIZtaKivF8Dvsg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=iUKRVfxy; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iUKRVfxy" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-20b93887decso13824765ad.3; Mon, 30 Sep 2024 23:29:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727764183; x=1728368983; darn=vger.kernel.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=WxtrrtK7dkUabLTe2HlhaHOfop29J15CnaNw+gioQGM=; b=iUKRVfxyFJOg03lchRtPmkqK4VYuZBF7NWRCBA0MoKk9/RXgLN9fmFchsWo+yxrJAu 8kgYK7G5Zygf5EmVpECWoZsrdm+OBthlczjL2/5CKvjoqiNyMP//V2Huk3oUhXTKOBGo RxGfaAG/ikdDc7gpc/AAxKDWOOxhY0FcoP0O6rfdZZwssG2xTU9PWWvy/Vkw8QOGWOW9 /HhSDmHT2E6SsGpj/dY2hfIMNjWbi1TYFmhnUa6Psx3n66sdpxyQ4M8Dm7ggMLqJlqY+ zfBo/Ifr9T7O5oI7Tq/bD8tA2L9qvnt4ox0npQSBxp0OOX/oqSBFKBPvllwLV0r3pN/i VZtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727764183; x=1728368983; 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=WxtrrtK7dkUabLTe2HlhaHOfop29J15CnaNw+gioQGM=; b=fTRKn7tsBM+RGHBvA/Y28ZBOwixlTBnKSom6FzEe/rkzcZ82x16Ih6OSPLk/yXrmoM CEyFBBVBUhPFtvpYblp3Vl74K3C7Yt88HpapgJLlZ44+ogcsaqtjsVjLaLFNbjpZrmmJ e/WW//MICIim5DdNZqCezv7SHKNTmfhy125DN0gW+ZL4eZjEbDYh4HBtzzN8WsED+6pZ L5a6nMEdiHhZ2SWfvrNRwq+ASsgb0vsDOgnIwMQDJUJGgVfg+Idf8ICtWLSytieU5jhq 3UpQg8siZLKk3JlQos+N/u1L18tH7STNFO2XL60DRrjI9VOuvofn8T3xJUe7QmnMSRs1 AvBA== X-Forwarded-Encrypted: i=1; AJvYcCU05UkCBd5bmFzlr/L0mNt3ooV6lS+vuQQ2k7IK0tBhVbCOT2X5cU+bA8Oz/8FX+SSF/drF8e6A6nA=@vger.kernel.org, AJvYcCW20Ob92f9nwjRBOjj7zdXUpjRRWh3Mxi8bfaxuIa88Ai/gCkGJV0QxBjc+NntqNuNIe5pAo7vIjHhEzETm@vger.kernel.org X-Gm-Message-State: AOJu0YxOrpZvnal+TyOjnfL7ldsZg/yALS7qSfyp+t22gyZ7GhUMghSJ 0nOHhN7P4JFrqJswV/Yifvb5U181lcVatfCiXWhL2bhy70EL82s= X-Google-Smtp-Source: AGHT+IE37FEF80rldr/cNKepWtQJ5ahhtOq33h6U28/y3zagN8dDe1+p1X3DN/bUulyLUI9t1XyGBw== X-Received: by 2002:a17:902:ce12:b0:205:8275:768 with SMTP id d9443c01a7336-20b36aee9edmr213250335ad.21.1727764183341; Mon, 30 Sep 2024 23:29:43 -0700 (PDT) Received: from localhost (2001-b400-e30e-7f15-c94a-d42b-025a-8ff3.emome-ip6.hinet.net. [2001:b400:e30e:7f15:c94a:d42b:25a:8ff3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20b37e65a48sm63454465ad.297.2024.09.30.23.29.42 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 30 Sep 2024 23:29:42 -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 Cc: openbmc@lists.ozlabs.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 2/6] i2c: npcm: use a software flag to indicate a BER condition Date: Tue, 1 Oct 2024 14:28:51 +0800 Message-Id: <20241001062855.6928-3-kfting@nuvoton.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20241001062855.6928-1-kfting@nuvoton.com> References: <20241001062855.6928-1-kfting@nuvoton.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm= 7xx.c index 2b76dbfba438..7620bdcdc235 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; /* Indicate the bus error state */ }; =20 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 =3D true; npcm_i2c_clear_master_status(bus); =20 /* 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 =3D false; return 0; } =20 @@ -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 =3D false; return status; } =20 @@ -2158,7 +2162,16 @@ static int npcm_i2c_master_xfer(struct i2c_adapter *= adap, struct i2c_msg *msgs, =20 } while (time_is_after_jiffies(time_left) && bus_busy); =20 - if (bus_busy) { + /* + * Check the BER (bus error) state, when ber_state is true, it means that= the module + * detects the bus error which is caused by some factor like that the ele= ctricity + * noise occurs on the bus. Under this condition, the module is reset and= the bus + * gets recovered. + * + * While ber_state is false, the module reset and bus recovery also get d= one as the + * bus is busy. + */ + if (bus_busy || bus->ber_state) { iowrite8(NPCM_I2CCST_BB, bus->reg + NPCM_I2CCST); npcm_i2c_reset(bus); i2c_recover_bus(adap); --=20 2.34.1 From nobody Thu Nov 28 13:42:00 2024 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0903A1BCA0D; Tue, 1 Oct 2024 06:29:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727764189; cv=none; b=Fx0xrQN0+oXP5RvrXxe/HzHJJ25MqP1I/wfDSJcKk8IrRYI4ecAIDosNBYPzTISPImYMjB+MnmEtm41VS4Aieik3PB5RbFTUvT3/9477i7mXs3d/TpnnlkqlgLb9FQ9GgNeNtZpol6eK3E4spXKAkdtPQc2G00gyQ6hW7bHFnKE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727764189; c=relaxed/simple; bh=1AUI4uXXdSOLC8A2cHZJloUv1kubbaJnCumBXJIF0qY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=ZDZNjx8YX4gxneG26tQ9GRjqvD+/EuSinWMOOwNnOHJ+1kUkG5+23RTh4OZHa6pmaBymYLSq4wA7nPFWO7JMdxXKd/UZmBmaOzsANMQZ6s/4c9ghHeB6BSNgx2g4jngLMi298iB2cSw65W+DkGfFt6ft/IO4IJvw+r059KsBqtQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=aLigGwt5; arc=none smtp.client-ip=209.85.216.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aLigGwt5" Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-2e06fade5eeso3909510a91.2; Mon, 30 Sep 2024 23:29:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727764187; x=1728368987; darn=vger.kernel.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=oZTR7VWZlUhx2yQtNiZmirEwYuAooSCpN3CWuoP2Uac=; b=aLigGwt571PcVvgNsqvbT02+6b2U0dhU2F9DiTDKPyIekFV02Lo3jna/SfVuExHxzN 2Zat266J+QU4mkyb+nfAlwOM+ipIBmSNhNyCUrHXhOyTHafQuwQxgGD3R2gYimx2D7C5 7MjXgodfrdk8FYOKoOhWR/yvBpCm49CrVJq4ayHSG1UIGyY6MXaOJzq/WRu3s4+Xw9Oh rc5ZezPN2wfzjZ91nvxM6UgtRLYsIcbrR7V1egJe9y1pXivzy/9j6aZQyfq38YZsJVlA 7xpd+Mwbz2UzBVHDNy+oKk7QnyTJ/ZPdq/B1HMdRw+NRsvWOfEDrXPxUZFWhMQzPKkgG fBhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727764187; x=1728368987; 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=oZTR7VWZlUhx2yQtNiZmirEwYuAooSCpN3CWuoP2Uac=; b=k+ed57oa8RZizr6mpAiE9TFh+9owAAudbR2M78hlLdoPAo9Bq5hzIxod3jce0LUSts U3G4ROIEsPdLzdnFbCf1P5H0Juj1SNMweui4Z8MWxfhPvvK/w0B7XW3sDmPK/c/PatlO 60hFQEwLLAWtf67tQhjYMruOX5/di8WbUG0qs10Po2K5kBhTiXAiytlNI/fO0pjJoylC Jod3hF4savSRZDZvNmekqJdypnOsac3pq21pUdMcDG9q0btI4XhctpMLMROF4bE7krgB 3u1clPyrWoZR+7BkexC+qPMWh7cbQEUOSjpUOQL4tiY4Tk58oWqGBULZ1yk9YiAGOYRm jGWg== X-Forwarded-Encrypted: i=1; AJvYcCUK+OOWJUAfoZdtZGpR9Nu4T6XCcwo/4EPCvllOoFibEu9jhHYlSIe07kD0CGMeIc+ayZTzDgTQpFI=@vger.kernel.org, AJvYcCUSkXqmifkaMhCn90Z/LMrURhD2suufIVoyIAPOrFrU7aoDI61ubX24vc50Uywj8w46mz2bip2TWDogXMAU@vger.kernel.org X-Gm-Message-State: AOJu0Yx95elY8tH8hKqoZaOyxOsNa1gNWcR779DxG8qbfBLsRIzgxjQ6 GiFHmDDezU/1jk5Y4gGl5ZEcle0sh3Kh7Z8M8OlOVpNOTvU76aM= X-Google-Smtp-Source: AGHT+IEfyPM2bsYwU45GdSmrXMiZ6q9HsEacf6Me68JtTyniOZIOco8TVIapaymb385TIN8YRuKDAw== X-Received: by 2002:a17:90a:8c18:b0:2d8:c17b:5018 with SMTP id 98e67ed59e1d1-2e0b89f0613mr17616802a91.11.1727764187176; Mon, 30 Sep 2024 23:29:47 -0700 (PDT) Received: from localhost (2001-b400-e30e-7f15-c94a-d42b-025a-8ff3.emome-ip6.hinet.net. [2001:b400:e30e:7f15:c94a:d42b:25a:8ff3]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e0b6e29081sm9228277a91.53.2024.09.30.23.29.46 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 30 Sep 2024 23:29:46 -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 Cc: openbmc@lists.ozlabs.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 3/6] i2c: npcm: Modify timeout evaluation mechanism Date: Tue, 1 Oct 2024 14:28:52 +0800 Message-Id: <20241001062855.6928-4-kfting@nuvoton.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20241001062855.6928-1-kfting@nuvoton.com> References: <20241001062855.6928-1-kfting@nuvoton.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm= 7xx.c index 7620bdcdc235..03d6c8702ecf 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, } } =20 - /* - * 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 =3D (2 * 9 * USEC_PER_SEC / bus->bus_freq) * (2 + nread + nw= rite); - timeout =3D max_t(unsigned long, bus->adap.timeout, usecs_to_jiffies(time= out_usec)); if (nwrite >=3D 32 * 1024 || nread >=3D 32 * 1024) { dev_err(bus->dev, "i2c%d buffer too big\n", bus->num); return -EINVAL; } =20 - time_left =3D jiffies + timeout + 1; + time_left =3D jiffies + bus->adap.timeout / bus->adap.retries + 1; do { /* * we must clear slave address immediately when the bus is not @@ -2192,6 +2185,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 =3D (2 * 9 * USEC_PER_SEC / bus->bus_freq) * (2 + nread + n= write); + timeout =3D max_t(unsigned long, bus->adap.timeout / bus->adap.retries, + usecs_to_jiffies(timeout_usec)); time_left =3D wait_for_completion_timeout(&bus->cmd_complete, timeout); =20 @@ -2317,7 +2318,12 @@ static int npcm_i2c_probe_bus(struct platform_device= *pdev) adap =3D &bus->adap; adap->owner =3D THIS_MODULE; adap->retries =3D 3; - adap->timeout =3D msecs_to_jiffies(35); + /* + * 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 owners= hip. + * The transactions are very long, so waiting 35ms is not enough. + */ + adap->timeout =3D 2 * HZ; adap->algo =3D &npcm_i2c_algo; adap->quirks =3D &npcm_i2c_quirks; adap->algo_data =3D bus; --=20 2.34.1 From nobody Thu Nov 28 13:42:00 2024 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3371E1BD510; Tue, 1 Oct 2024 06:29:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727764192; cv=none; b=icrsauHlh0bOrDzy53wsrYDJyWVOmUPPUpaRbrE4yfVFQ45gjJtuHynbZ9c/ebCfIaYHYmmMVJHceEIiYDLoXdgY95SBzqUi+/Dc7q5zwlBB4unJ/EiCKq2tyclkOT8UvC+q+28wAfWs8Mvidtg/DkRPi5VJbtVGkCIqmL7mXxI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727764192; c=relaxed/simple; bh=JK4cHd2S+muHXVItg6eODd/tPfPm+RDywU9zUcKcoic=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=EGNS+FLBy7m+ojeh++pKChIC3SP50pzytXisft/11hFvFxyOU/i8p6N9qltp7MSZXZZ6cfx3eKxJSSBtE2ZIR0LjvEA3j+hUwWD2Hj5OIrQAhqKIhc4JGdItWHNhtj62y5Kt6Pme8DZgwwTM6j37h/71fKfLWvAmZ+eW5qzu/do= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=mnl1Btz6; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mnl1Btz6" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-20b90ab6c19so16470445ad.0; Mon, 30 Sep 2024 23:29:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727764190; x=1728368990; darn=vger.kernel.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=sVINhRisx7tHA2uWGJZ1rYfyR16go1Qbe2bSN3dCkJs=; b=mnl1Btz6pi5diPkolecnEAeldoAxJWZfBxXjkCrCsF6pqq4NI4SjRC50/cPgIySMtb +ZO4bpF+JSiwLqtURAXnAkoosaU1vwvRT56WIhT+vkoLc4UM9DiyLqMJrF0axKLAhny1 zhK+zWF17pUA53LYFoqL2TrdA8XCxkQgnjnt7A9XXsSKuQoYwXt3Yl01qqP4wzu+P4qg S+v+iZqDuxigbzIrdPteH8qKJJO29+c+FkV0LcECyw+LASrdpjFqqeL/DU7XO8w+emdv ITEZf4AE3c9mxt+f4ZjBVRTJowc0uzyHvK74Q7DqgqSd39eEQlDpekT1TCG6WxQy+3uv f1/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727764190; x=1728368990; 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=sVINhRisx7tHA2uWGJZ1rYfyR16go1Qbe2bSN3dCkJs=; b=TL5V2KxhW//KxCEQXrvlYhpLsCuM+eJMSFOL7GPemLfsljg53avgKbdabgvYu4eOhJ kOkU1kosQEBdyEO5ueFk8W+TFz0Ncwuo9KCgFATL46n0Yh/chD0hMy62Ak6K4FXyR04F QJjJn75yObJw5lq1CoHk0rshzkYB6JxpB1aDva47OO5EsoPvj24GZsCFglxQ4fLOAJNZ utRqIRYrY5utvCzrmje5mPVnaPjgZV89g0fSY01Du/7w34Nv0uH4UjyaC/LKVIGtiy25 msCc9raTkihCifeBuR9J5hJpFXtD9a43x7/KTNI9up0hD692iuSwJ/gGsj8eUTnP9+HK nkyg== X-Forwarded-Encrypted: i=1; AJvYcCUl66y9xCCU5Rkvgbkt93UGRhjrokvT27M1M/WEE/VkNJAon7S0Hm+kKem36lB8Jk67nnp+k7ur+Tc=@vger.kernel.org, AJvYcCXiv+Rke0wk7Qls7+IXeGf0zyU74LfJVZPaXQbytUypMkKHFyKcilFPJdhN58RNEB7X2DoWXryc8ADl/M4R@vger.kernel.org X-Gm-Message-State: AOJu0YyyAdRZii5/iWaaxr91kuTZ4LtYfJgyGOWa1l3tNYB2I2SV73VI pIv1613g2cU0vP/MowLDd+B6SF5cvuDyzbjLj1AVv3rMmLsr/s5ctp9dCC4= X-Google-Smtp-Source: AGHT+IGCkLE3x8E2oi3I+0hAAwg49dV46n8uUHwJq3wdp083muDYwMdqM2bQc6gqMV0beAmdPRwTBA== X-Received: by 2002:a17:903:2305:b0:20b:84cc:5937 with SMTP id d9443c01a7336-20b84cc5f89mr89980095ad.31.1727764190444; Mon, 30 Sep 2024 23:29:50 -0700 (PDT) Received: from localhost (2001-b400-e30e-7f15-c94a-d42b-025a-8ff3.emome-ip6.hinet.net. [2001:b400:e30e:7f15:c94a:d42b:25a:8ff3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20b37e5de0asm63596585ad.265.2024.09.30.23.29.49 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 30 Sep 2024 23:29:50 -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 Cc: openbmc@lists.ozlabs.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 4/6] i2c: npcm: Modify the client address assignment Date: Tue, 1 Oct 2024 14:28:53 +0800 Message-Id: <20241001062855.6928-5-kfting@nuvoton.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20241001062855.6928-1-kfting@nuvoton.com> References: <20241001062855.6928-1-kfting@nuvoton.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 npcm_i2c_master_xfer(). Signed-off-by: Tyrone Ting Reviewed-by: Tali Perry --- drivers/i2c/busses/i2c-npcm7xx.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm= 7xx.c index 03d6c8702ecf..0ee77e1fbc08 100644 --- a/drivers/i2c/busses/i2c-npcm7xx.c +++ b/drivers/i2c/busses/i2c-npcm7xx.c @@ -2155,6 +2155,19 @@ static int npcm_i2c_master_xfer(struct i2c_adapter *= adap, struct i2c_msg *msgs, =20 } while (time_is_after_jiffies(time_left) && bus_busy); =20 + /* + * 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 npcm_i2c_master_xfer(), the address is stored with + * the shift and used in the i2c_recover_bus(). + * + * 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 =3D slave_addr << 1; + /* * Check the BER (bus error) state, when ber_state is true, it means that= the module * detects the bus error which is caused by some factor like that the ele= ctricity @@ -2172,7 +2185,6 @@ static int npcm_i2c_master_xfer(struct i2c_adapter *a= dap, struct i2c_msg *msgs, } =20 npcm_i2c_init_params(bus); - bus->dest_addr =3D slave_addr; bus->msgs =3D msgs; bus->msgs_num =3D num; bus->cmd_err =3D 0; --=20 2.34.1 From nobody Thu Nov 28 13:42:00 2024 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AF7FD1BD517; Tue, 1 Oct 2024 06:29:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727764196; cv=none; b=rZm9cJwk1zUhS9OnpxBTpiGtQmq2TM09LL1uyhYQjeukrRa6D/3qIMHxIBDYzIXdCdcsAl9qiN3rUVD4Ax5bm8MzgOGlH9JMtef+0oUyjNTwKx+r8y/jnvbEANms2mJvXm9EKQp8u7SyKQzhue83QjI8HjQS1eei4wLXlOtCa+k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727764196; c=relaxed/simple; bh=uV8iWwN6dVtoqJz4MUZNhdtwgWE792mqtPkMFuC6l8E=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=Z6vMxPodlpNwBsp4Vl8tdWH8sbTdr7JvYlEvPscCmOcqkgyjHMSq7sHy80RiAx4iii2WSQj8eavL5H2K9WheM2DUVUdpyWi720TWAfx1JoexVNEu0FFiqZRTBt7nPgfOVg91hteLAz7anxxWQONvvdDjMxRCionXn15e+A8IXK8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=lnPbNdp/; arc=none smtp.client-ip=209.85.210.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lnPbNdp/" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-71788bfe60eso3823212b3a.1; Mon, 30 Sep 2024 23:29:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727764194; x=1728368994; darn=vger.kernel.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=YqzdmEu2UR4QBOUCnQBa7ZbtSWN8HvAvdUKdNjbDuIM=; b=lnPbNdp/SvifcA+rMM22Jca0vhDIZldU8XDF4bz/g3cT2WPwJoehWkYJtrt2c4y3Zz XjNqN5qwS0nGV4quH0GYT0MLc4TikF4DLyILCqYcfLA+SuY/zktW9aXn16NnZG2vWZ2L 6XcZfDzyswQfSsWaGyuGbsoC+0aQEGdyT0JmJcjMs6/fow3ZS5r1qXESXWOLb9BJQIO+ QnieNpDQGO5v/hkgLdBPYHF6tL6Spw+GyNwzfPi+Nu9L6FM2iKt1/c/uiTuYSTh7io6s 7hZkiEAIRSZ8n8PHiuMBI6zY4yE3hlID8V6mcLgkfwWNTdj5mn6LUuY4ih+40QDzNhqZ 6nqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727764194; x=1728368994; 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=YqzdmEu2UR4QBOUCnQBa7ZbtSWN8HvAvdUKdNjbDuIM=; b=O33fNB5s6Q+d4wlony9JJwZMGooz2+kDDhPOYf1plpq1ydq3INQ6lO4y5dPG2GK5f2 OwYkuF041Ry9cdy8yIxTYs4//GdmFyMHmuB/MhacPcNNk433KnLJatGYPqncl8FQhJbZ lUyBal+JfRSLWqp0KljHdehR4MndW0awB7mJOoq3QTkDy6Zaq5/OP/k/lSOuN/Fi653o RF4vzQlFWnGznm4oBniQDfWrynHz1l8bElZbs0hdkULa0x7C5bDDVQ/1gEHAs0yPmtE5 Vsn6QEjTUkZN39AdOhVWMMjFKSPlFMVXH9vuD0VYTDtOhjd11YE6//mC5NuMihJ2qSjb 11MA== X-Forwarded-Encrypted: i=1; AJvYcCU/T+8e1u+/hdUmQdymiQmvRFYDUupnGaNEJwX3MJwkNWssyixJ6w9JkXcux7dN27tETCK1BlT4HjI=@vger.kernel.org, AJvYcCXmoMkdS5Pm9wMtfUkDhaZNVt4QZwbigZXnnBUcaqoBK52lOWi2qnkQa8NhByUG5JFGU3QpZmu/JrO4j9J1@vger.kernel.org X-Gm-Message-State: AOJu0Yys/xWbbWEid4X1ut/7F5rw7ZjIpXzgcbxhttFMw6ZCjHv9WmKP 8C9Q9fDvSyt/ZadQ6j7376gZvamw4CMiRy/xQBLKQpvaqz84OFM= X-Google-Smtp-Source: AGHT+IFAynLD7Y6INIeHChoWuMPGG7kXyaw3SFtjQ+rhKIWR6q8jEBeLr3s9/T+mqw663JthV2If0g== X-Received: by 2002:a05:6a00:cd4:b0:718:edeb:5a35 with SMTP id d2e1a72fcca58-71b2607ec59mr21161483b3a.28.1727764193783; Mon, 30 Sep 2024 23:29:53 -0700 (PDT) Received: from localhost (2001-b400-e30e-7f15-c94a-d42b-025a-8ff3.emome-ip6.hinet.net. [2001:b400:e30e:7f15:c94a:d42b:25a:8ff3]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71b264bcc30sm7296746b3a.68.2024.09.30.23.29.52 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 30 Sep 2024 23:29:53 -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 Cc: openbmc@lists.ozlabs.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 5/6] i2c: npcm: use i2c frequency table Date: Tue, 1 Oct 2024 14:28:54 +0800 Message-Id: <20241001062855.6928-6-kfting@nuvoton.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20241001062855.6928-1-kfting@nuvoton.com> References: <20241001062855.6928-1-kfting@nuvoton.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 | 374 ++++++++++++++++++++++++------- 1 file changed, 288 insertions(+), 86 deletions(-) diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm= 7xx.c index 0ee77e1fbc08..2ed69e92edf6 100644 --- a/drivers/i2c/busses/i2c-npcm7xx.c +++ b/drivers/i2c/busses/i2c-npcm7xx.c @@ -263,6 +263,265 @@ static const int npcm_i2caddr[I2C_NUM_OWN_ADDR] =3D { #define I2C_FREQ_MIN_HZ 10000 #define I2C_FREQ_MAX_HZ I2C_MAX_FAST_MODE_PLUS_FREQ =20 +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[] =3D { + { + .core_clk =3D 100000000, .hldt =3D 0x2A, .dbcnt =3D 0x4, + .sclfrq =3D 0xFB, .scllt =3D 0x0, .sclht =3D 0x0, + .fast_mode =3D false, + }, + { + .core_clk =3D 62500000, .hldt =3D 0x2A, .dbcnt =3D 0x1, + .sclfrq =3D 0x9D, .scllt =3D 0x0, .sclht =3D 0x0, + .fast_mode =3D false, + }, + { + .core_clk =3D 50000000, .hldt =3D 0x2A, .dbcnt =3D 0x1, + .sclfrq =3D 0x7E, .scllt =3D 0x0, .sclht =3D 0x0, + .fast_mode =3D false, + }, + { + .core_clk =3D 48000000, .hldt =3D 0x2A, .dbcnt =3D 0x1, + .sclfrq =3D 0x79, .scllt =3D 0x0, .sclht =3D 0x0, + .fast_mode =3D false, + }, + { + .core_clk =3D 40000000, .hldt =3D 0x2A, .dbcnt =3D 0x1, + .sclfrq =3D 0x65, .scllt =3D 0x0, .sclht =3D 0x0, + .fast_mode =3D false, + }, + { + .core_clk =3D 30000000, .hldt =3D 0x2A, .dbcnt =3D 0x1, + .sclfrq =3D 0x4C, .scllt =3D 0x0, .sclht =3D 0x0, + .fast_mode =3D false, + }, + { + .core_clk =3D 29000000, .hldt =3D 0x2A, .dbcnt =3D 0x1, + .sclfrq =3D 0x49, .scllt =3D 0x0, .sclht =3D 0x0, + .fast_mode =3D false, + }, + { + .core_clk =3D 26000000, .hldt =3D 0x2A, .dbcnt =3D 0x1, + .sclfrq =3D 0x42, .scllt =3D 0x0, .sclht =3D 0x0, + .fast_mode =3D false, + }, + { + .core_clk =3D 25000000, .hldt =3D 0x2A, .dbcnt =3D 0x1, + .sclfrq =3D 0x3F, .scllt =3D 0x0, .sclht =3D 0x0, + .fast_mode =3D false, + }, + { + .core_clk =3D 24000000, .hldt =3D 0x2A, .dbcnt =3D 0x1, + .sclfrq =3D 0x3D, .scllt =3D 0x0, .sclht =3D 0x0, + .fast_mode =3D false, + }, + { + .core_clk =3D 20000000, .hldt =3D 0x2A, .dbcnt =3D 0x1, + .sclfrq =3D 0x33, .scllt =3D 0x0, .sclht =3D 0x0, + .fast_mode =3D false, + }, + { + .core_clk =3D 16180000, .hldt =3D 0x2A, .dbcnt =3D 0x1, + .sclfrq =3D 0x29, .scllt =3D 0x0, .sclht =3D 0x0, + .fast_mode =3D false, + }, + { + .core_clk =3D 15000000, .hldt =3D 0x23, .dbcnt =3D 0x1, + .sclfrq =3D 0x26, .scllt =3D 0x0, .sclht =3D 0x0, + .fast_mode =3D false, + }, + { + .core_clk =3D 13000000, .hldt =3D 0x1D, .dbcnt =3D 0x1, + .sclfrq =3D 0x21, .scllt =3D 0x0, .sclht =3D 0x0, + .fast_mode =3D false, + }, + { + .core_clk =3D 12000000, .hldt =3D 0x1B, .dbcnt =3D 0x1, + .sclfrq =3D 0x1F, .scllt =3D 0x0, .sclht =3D 0x0, + .fast_mode =3D false, + }, + { + .core_clk =3D 10000000, .hldt =3D 0x18, .dbcnt =3D 0x1, + .sclfrq =3D 0x1A, .scllt =3D 0x0, .sclht =3D 0x0, + .fast_mode =3D false, + }, + { + .core_clk =3D 9000000, .hldt =3D 0x16, .dbcnt =3D 0x1, + .sclfrq =3D 0x17, .scllt =3D 0x0, .sclht =3D 0x0, + .fast_mode =3D false, + }, + { + .core_clk =3D 8090000, .hldt =3D 0x14, .dbcnt =3D 0x1, + .sclfrq =3D 0x15, .scllt =3D 0x0, .sclht =3D 0x0, + .fast_mode =3D false, + }, + { + .core_clk =3D 7500000, .hldt =3D 0x7, .dbcnt =3D 0x1, + .sclfrq =3D 0x13, .scllt =3D 0x0, .sclht =3D 0x0, + .fast_mode =3D false, + }, + { + .core_clk =3D 6500000, .hldt =3D 0xE, .dbcnt =3D 0x1, + .sclfrq =3D 0x11, .scllt =3D 0x0, .sclht =3D 0x0, + .fast_mode =3D false, + }, + { + .core_clk =3D 4000000, .hldt =3D 0x9, .dbcnt =3D 0x1, + .sclfrq =3D 0xB, .scllt =3D 0x0, .sclht =3D 0x0, + .fast_mode =3D false, + }, +}; + +static struct smb_timing_t smb_timing_400khz[] =3D { + { + .core_clk =3D 100000000, .hldt =3D 0x2A, .dbcnt =3D 0x3, + .sclfrq =3D 0x0, .scllt =3D 0x47, .sclht =3D 0x35, + .fast_mode =3D true, + }, + { + .core_clk =3D 62500000, .hldt =3D 0x2A, .dbcnt =3D 0x2, + .sclfrq =3D 0x0, .scllt =3D 0x2C, .sclht =3D 0x22, + .fast_mode =3D true, + }, + { + .core_clk =3D 50000000, .hldt =3D 0x21, .dbcnt =3D 0x1, + .sclfrq =3D 0x0, .scllt =3D 0x24, .sclht =3D 0x1B, + .fast_mode =3D true, + }, + { + .core_clk =3D 48000000, .hldt =3D 0x1E, .dbcnt =3D 0x1, + .sclfrq =3D 0x0, .scllt =3D 0x24, .sclht =3D 0x19, + .fast_mode =3D true, + }, + { + .core_clk =3D 40000000, .hldt =3D 0x1B, .dbcnt =3D 0x1, + .sclfrq =3D 0x0, .scllt =3D 0x1E, .sclht =3D 0x14, + .fast_mode =3D true, + }, + { + .core_clk =3D 33000000, .hldt =3D 0x15, .dbcnt =3D 0x1, + .sclfrq =3D 0x0, .scllt =3D 0x19, .sclht =3D 0x11, + .fast_mode =3D true, + }, + { + .core_clk =3D 30000000, .hldt =3D 0x15, .dbcnt =3D 0x1, + .sclfrq =3D 0x0, .scllt =3D 0x19, .sclht =3D 0xD, + .fast_mode =3D true, + }, + { + .core_clk =3D 29000000, .hldt =3D 0x11, .dbcnt =3D 0x1, + .sclfrq =3D 0x0, .scllt =3D 0x15, .sclht =3D 0x10, + .fast_mode =3D true, + }, + { + .core_clk =3D 26000000, .hldt =3D 0x10, .dbcnt =3D 0x1, + .sclfrq =3D 0x0, .scllt =3D 0x13, .sclht =3D 0xE, + .fast_mode =3D true, + }, + { + .core_clk =3D 25000000, .hldt =3D 0xF, .dbcnt =3D 0x1, + .sclfrq =3D 0x0, .scllt =3D 0x13, .sclht =3D 0xD, + .fast_mode =3D true, + }, + { + .core_clk =3D 24000000, .hldt =3D 0xD, .dbcnt =3D 0x1, + .sclfrq =3D 0x0, .scllt =3D 0x12, .sclht =3D 0xD, + .fast_mode =3D true, + }, + { + .core_clk =3D 20000000, .hldt =3D 0xB, .dbcnt =3D 0x1, + .sclfrq =3D 0x0, .scllt =3D 0xF, .sclht =3D 0xA, + .fast_mode =3D true, + }, + { + .core_clk =3D 16180000, .hldt =3D 0xA, .dbcnt =3D 0x1, + .sclfrq =3D 0x0, .scllt =3D 0xC, .sclht =3D 0x9, + .fast_mode =3D true, + }, + { + .core_clk =3D 15000000, .hldt =3D 0x9, .dbcnt =3D 0x1, + .sclfrq =3D 0x0, .scllt =3D 0xB, .sclht =3D 0x8, + .fast_mode =3D true, + }, + { + .core_clk =3D 13000000, .hldt =3D 0x7, .dbcnt =3D 0x1, + .sclfrq =3D 0x0, .scllt =3D 0xA, .sclht =3D 0x7, + .fast_mode =3D true, + }, + { + .core_clk =3D 12000000, .hldt =3D 0x7, .dbcnt =3D 0x1, + .sclfrq =3D 0x0, .scllt =3D 0xA, .sclht =3D 0x6, + .fast_mode =3D true, + }, + { + .core_clk =3D 10000000, .hldt =3D 0x6, .dbcnt =3D 0x1, + .sclfrq =3D 0x0, .scllt =3D 0x8, .sclht =3D 0x5, + .fast_mode =3D true, + }, +}; + +static struct smb_timing_t smb_timing_1000khz[] =3D { + { + .core_clk =3D 100000000, .hldt =3D 0x15, .dbcnt =3D 0x4, + .sclfrq =3D 0x0, .scllt =3D 0x1C, .sclht =3D 0x15, + .fast_mode =3D true, + }, + { + .core_clk =3D 62500000, .hldt =3D 0xF, .dbcnt =3D 0x3, + .sclfrq =3D 0x0, .scllt =3D 0x11, .sclht =3D 0xE, + .fast_mode =3D true, + }, + { + .core_clk =3D 50000000, .hldt =3D 0xA, .dbcnt =3D 0x2, + .sclfrq =3D 0x0, .scllt =3D 0xE, .sclht =3D 0xB, + .fast_mode =3D true, + }, + { + .core_clk =3D 48000000, .hldt =3D 0x9, .dbcnt =3D 0x2, + .sclfrq =3D 0x0, .scllt =3D 0xD, .sclht =3D 0xB, + .fast_mode =3D true, + }, + { + .core_clk =3D 41000000, .hldt =3D 0x9, .dbcnt =3D 0x2, + .sclfrq =3D 0x0, .scllt =3D 0xC, .sclht =3D 0x9, + .fast_mode =3D true, + }, + { + .core_clk =3D 40000000, .hldt =3D 0x8, .dbcnt =3D 0x2, + .sclfrq =3D 0x0, .scllt =3D 0xB, .sclht =3D 0x9, + .fast_mode =3D true, + }, + { + .core_clk =3D 33000000, .hldt =3D 0x7, .dbcnt =3D 0x1, + .sclfrq =3D 0x0, .scllt =3D 0xA, .sclht =3D 0x7, + .fast_mode =3D true, + }, + { + .core_clk =3D 25000000, .hldt =3D 0x4, .dbcnt =3D 0x1, + .sclfrq =3D 0x0, .scllt =3D 0x7, .sclht =3D 0x6, + .fast_mode =3D true, + }, + { + .core_clk =3D 24000000, .hldt =3D 0x7, .dbcnt =3D 0x1, + .sclfrq =3D 0x0, .scllt =3D 0x8, .sclht =3D 0x5, + .fast_mode =3D true, + }, + { + .core_clk =3D 20000000, .hldt =3D 0x4, .dbcnt =3D 0x1, + .sclfrq =3D 0x0, .scllt =3D 0x6, .sclht =3D 0x4, + .fast_mode =3D true, + }, +}; + struct npcm_i2c_data { u8 fifo_size; u32 segctl_init_val; @@ -1805,102 +2064,45 @@ static void npcm_i2c_recovery_init(struct i2c_adap= ter *_adap) */ static int npcm_i2c_init_clk(struct npcm_i2c *bus, u32 bus_freq_hz) { - u32 k1 =3D 0; - u32 k2 =3D 0; - u8 dbnct =3D 0; - u32 sclfrq =3D 0; - u8 hldt =3D 7; + struct smb_timing_t *smb_timing; + u8 scl_table_cnt =3D 0, table_size =3D 0; u8 fast_mode =3D 0; - u32 src_clk_khz; - u32 bus_freq_khz; =20 - src_clk_khz =3D bus->apb_clk / 1000; - bus_freq_khz =3D bus_freq_hz / 1000; bus->bus_freq =3D bus_freq_hz; =20 - /* 100KHz and below: */ - if (bus_freq_hz <=3D I2C_MAX_STANDARD_MODE_FREQ) { - sclfrq =3D src_clk_khz / (bus_freq_khz * 4); - - if (sclfrq < SCLFRQ_MIN || sclfrq > SCLFRQ_MAX) - return -EDOM; - - if (src_clk_khz >=3D 40000) - hldt =3D 17; - else if (src_clk_khz >=3D 12500) - hldt =3D 15; - else - hldt =3D 7; - } - - /* 400KHz: */ - else if (bus_freq_hz <=3D I2C_MAX_FAST_MODE_FREQ) { - sclfrq =3D 0; + switch (bus_freq_hz) { + case I2C_MAX_STANDARD_MODE_FREQ: + smb_timing =3D smb_timing_100khz; + table_size =3D ARRAY_SIZE(smb_timing_100khz); + break; + case I2C_MAX_FAST_MODE_FREQ: + smb_timing =3D smb_timing_400khz; + table_size =3D ARRAY_SIZE(smb_timing_400khz); fast_mode =3D I2CCTL3_400K_MODE; - - if (src_clk_khz < 7500) - /* 400KHZ cannot be supported for core clock < 7.5MHz */ - return -EDOM; - - else if (src_clk_khz >=3D 50000) { - k1 =3D 80; - k2 =3D 48; - hldt =3D 12; - dbnct =3D 7; - } - - /* Master or Slave with frequency > 25MHz */ - else if (src_clk_khz > 25000) { - hldt =3D clk_coef(src_clk_khz, 300) + 7; - k1 =3D clk_coef(src_clk_khz, 1600); - k2 =3D clk_coef(src_clk_khz, 900); - } - } - - /* 1MHz: */ - else if (bus_freq_hz <=3D I2C_MAX_FAST_MODE_PLUS_FREQ) { - sclfrq =3D 0; + break; + case I2C_MAX_FAST_MODE_PLUS_FREQ: + smb_timing =3D smb_timing_1000khz; + table_size =3D ARRAY_SIZE(smb_timing_1000khz); fast_mode =3D I2CCTL3_400K_MODE; - - /* 1MHZ cannot be supported for core clock < 24 MHz */ - if (src_clk_khz < 24000) - return -EDOM; - - k1 =3D clk_coef(src_clk_khz, 620); - k2 =3D clk_coef(src_clk_khz, 380); - - /* Core clk > 40 MHz */ - if (src_clk_khz > 40000) { - /* - * Set HLDT: - * SDA hold time: (HLDT-7) * T(CLK) >=3D 120 - * HLDT =3D 120/T(CLK) + 7 =3D 120 * FREQ(CLK) + 7 - */ - hldt =3D clk_coef(src_clk_khz, 120) + 7; - } else { - hldt =3D 7; - dbnct =3D 2; - } + break; + default: + return -EINVAL; } =20 - /* Frequency larger than 1 MHz is not supported */ - else - return -EINVAL; + for (scl_table_cnt =3D 0; scl_table_cnt < table_size; scl_table_cnt++) + if (bus->apb_clk >=3D smb_timing[scl_table_cnt].core_clk) + break; =20 - if (bus_freq_hz >=3D I2C_MAX_FAST_MODE_FREQ) { - k1 =3D round_up(k1, 2); - k2 =3D round_up(k2 + 1, 2); - if (k1 < SCLFRQ_MIN || k1 > SCLFRQ_MAX || - k2 < SCLFRQ_MIN || k2 > SCLFRQ_MAX) - return -EDOM; - } + if (scl_table_cnt =3D=3D table_size) + return -EINVAL; =20 /* 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); =20 /* bits [8:7] are in I2CCTL3 reg */ - iowrite8(fast_mode | FIELD_PREP(I2CCTL3_SCLFRQ8_7, (sclfrq >> 7) & 0x3), + iowrite8(FIELD_PREP(I2CCTL3_SCLFRQ8_7, (smb_timing[scl_table_cnt].sclfrq = >> 7) & 0x3) | + fast_mode, bus->reg + NPCM_I2CCTL3); =20 /* Select Bank 0 to access NPCM_I2CCTL4/NPCM_I2CCTL5 */ @@ -1912,13 +2114,13 @@ static int npcm_i2c_init_clk(struct npcm_i2c *bus, = u32 bus_freq_hz) * k1 =3D 2 * SCLLT7-0 -> Low Time =3D k1 / 2 * k2 =3D 2 * SCLLT7-0 -> High Time =3D 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); =20 - iowrite8(dbnct, bus->reg + NPCM_I2CCTL5); + iowrite8(smb_timing[scl_table_cnt].dbcnt, bus->reg + NPCM_I2CCTL5); } =20 - iowrite8(hldt, bus->reg + NPCM_I2CCTL4); + iowrite8(smb_timing[scl_table_cnt].hldt, bus->reg + NPCM_I2CCTL4); =20 /* Return to Bank 1, and stay there by default: */ npcm_i2c_select_bank(bus, I2C_BANK_1); --=20 2.34.1 From nobody Thu Nov 28 13:42:00 2024 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC39D1BDA97; Tue, 1 Oct 2024 06:29:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727764199; cv=none; b=MOriK80tFmeOc7Wcs+Sg76fzLRNPVnvP9Ya86dw3zfW2Zo/gsrpYTpYOZ30RH0hssg4iqrMzWWOVd64d+qITdH7Lgf7iRq+DbFk9zojxOdyoGqh4uKJR13fJqzVGne29EK/dL3dMoF7BSAAEyhYhgcgQLCAoA89QIEKYzr6pOY4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727764199; c=relaxed/simple; bh=FzFLPt/0JAGGGSdk8dm26jWdm7n54H3fssDUKBnwl9s=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=E9KYjWIehObJBdlO+ZoKv8+Un9FCwGEA16RzFwosZVARIuKZUksrBSBe8g6lo3WpvcEuKK6ZprpfrgFUx1IX8vCclpWUMnMk9Uh8MooIpaZGZBaQdN5YzNKPd9ZFwFB7/NfpF/tPRYjgaJRd72SxNNo1zR1ywj5IETnazJfIizk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=aYHZ2ywc; arc=none smtp.client-ip=209.85.215.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aYHZ2ywc" Received: by mail-pg1-f169.google.com with SMTP id 41be03b00d2f7-7ae3d7222d4so4419549a12.3; Mon, 30 Sep 2024 23:29:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727764197; x=1728368997; darn=vger.kernel.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=vCToa1pjp5BirUNjWfkXpacYwQOG9xkkvltlLzTKSjY=; b=aYHZ2ywcSbgZuMCAI2E9zrIo6lXPvLOukzNvM9AfkN/oWT6KbDEE9JHTH9IX8iYt96 A3Nx1knZ+o9P73hEy2rGOUibABF2MubJXKak+vgvySS3a7/KnW2daKbChPyrastvXLwU +mpcBUxidJefR3ZxHV6KvS6GF9AR8SrvWIjkLDsLZljaYRNIAsQib/GBbvt0GKztbf0d g1QR9gW/SXST2mL5S7Qc+DlXdWdZ2ryrN+ovVi2Epj09ozbzIe7O0fGScGLgEGUPbSia ILUxfojZyCc8ezLYHei74R60XUFXNP1BaQx1YYC/0VNuZeVV2QpzHGm20i61e8zq/oVZ 0sOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727764197; x=1728368997; 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=vCToa1pjp5BirUNjWfkXpacYwQOG9xkkvltlLzTKSjY=; b=eVtzUzLn491q5qmz6/hnPjCwkgFJqKJ7O+gX3ZVfFRsuPdrgKwLcYFZvh1PzLKuk/c pY+qQdrdgMlgwHBZTCx8y7VgZKj0UiQUVNahfdMDr0ZyYQbj/Nbnfqmgi0sKIew6dCcq 5xZrgLt0b75gf6s/NY9QcFEpTyMfh8waBE+oFeGHYSHodid0T3h329WFfqJ0FepyOy4v c31PEQOM8lVY3/TV3GcDu02styauRxhi/Dp9TfY/K0d49S01yPuV82K8SITHtah60XeL tKid6Y5o5IpdVKcX4WVSZWVK4oJP2vMXmBAIOQY1bh+CC5kbziPY380TQgOjidHc6QnV NV7Q== X-Forwarded-Encrypted: i=1; AJvYcCUJImqFV5Z1NCM4OgTamD7h4IfTgsx0Tll+7eqcqgtIQdSRsx4F5qWyEuiq1Ag7fIidaRNoRMDwYNI=@vger.kernel.org, AJvYcCXhegEpHVIxmHw/NyzkwgDzrCFlkXZwSsES18/fdcNBThNAiHoFRGA2akgmqaF9n6PkNZI9GSh0grpVqYRr@vger.kernel.org X-Gm-Message-State: AOJu0YxlZz1hMHyGNq5drpE6VpPPG3lbw8S/qp5K2Bo+OsOWb5t9kLNK 3+XVh+xsq2Jw4y/s27vJJo/9EL8sto55oxsrzURaglkZ8dgXVsPi7oQ6nAY= X-Google-Smtp-Source: AGHT+IFYXUPQMked64r/OKkWQ4ip1SeDQ9qqr8pVe+NEbLmATxtjewrRe7p5N32WGEjBTzYrpoL6rg== X-Received: by 2002:a05:6a21:e85:b0:1cf:37f8:7a1f with SMTP id adf61e73a8af0-1d4fa6358b3mr21680011637.6.1727764197089; Mon, 30 Sep 2024 23:29:57 -0700 (PDT) Received: from localhost (2001-b400-e30e-7f15-c94a-d42b-025a-8ff3.emome-ip6.hinet.net. [2001:b400:e30e:7f15:c94a:d42b:25a:8ff3]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71b264bb694sm7313243b3a.65.2024.09.30.23.29.56 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 30 Sep 2024 23:29:56 -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 Cc: openbmc@lists.ozlabs.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, Charles Boyer , Vivekanand Veeracholan Subject: [PATCH v5 6/6] i2c: npcm: Enable slave in eob interrupt Date: Tue, 1 Oct 2024 14:28:55 +0800 Message-Id: <20241001062855.6928-7-kfting@nuvoton.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20241001062855.6928-1-kfting@nuvoton.com> References: <20241001062855.6928-1-kfting@nuvoton.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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-npcm= 7xx.c index 2ed69e92edf6..90a6e6842c6b 100644 --- a/drivers/i2c/busses/i2c-npcm7xx.c +++ b/drivers/i2c/busses/i2c-npcm7xx.c @@ -1925,6 +1925,12 @@ static int npcm_i2c_int_master_handler(struct npcm_i= 2c *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; } =20 --=20 2.34.1