From nobody Fri Nov 29 10:47:10 2024 Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) (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 9C9041428E4; Fri, 20 Sep 2024 10:18:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726827516; cv=none; b=JcDHUgqPLrbmOsVTCPPT9UozsXuJ+LLvYCBzxWoFvOuMjg3dcaUHmOzJmSUxnon9BSam759Pdje3BlSQi3lUsEGgU+X9HsKZ+JX2vbsq+OG0j6K/Ben3Z/wH+a7AAl1vTrBljkrXnu1TsqBLBmPpJYrMWNnLB8MAurkrIKnPcQE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726827516; c=relaxed/simple; bh=iYCX3RYL/EHVpLJdEhvdt2zVPvzBLqXunrCXVnQgazY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=YyG3VNBavAd4PTJlS8VLNTCoYUHIS1m+YzlB+zLdaXC5PTONCxovi26RZbCxmydr34aiKZsNSNN3T7yPTFElAH+h2+9z2KghzuiGtdK+Zvp2tL8iQoXH8PQFU0JGtiHPzqTQcmS5i8aOvaKwCEAswIKRV2+xC6C7Qxcm2de8SOk= 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=bSRJSWiw; arc=none smtp.client-ip=209.85.215.177 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="bSRJSWiw" Received: by mail-pg1-f177.google.com with SMTP id 41be03b00d2f7-7cf5e179b68so1619802a12.1; Fri, 20 Sep 2024 03:18:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726827514; x=1727432314; 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=b5x6COaWYuBZ+I/ktGSPVnQK2t9IfKl2Gymo5GZUYVM=; b=bSRJSWiwCzTOvGwo8D6L3V96PXAJFmeOjTaUnwz+0/e0yu3kQea9B24xXduS2j1k9d zZpCXrvvu0ENHDBz6oQvUVvuLusESzvKR19NNroiAXS+IphC3ZZOPgGjdgoo7+BOz8Xx N5da3xRsk2je/rfpegQhCAeqBhPnDiLmn7831WCdK50sl7MMA4uUjw/lIXf8hwCejSRC uk+tBQH1mj3hajTxe4QPAWNJh/mybb+/HG/VwJCjLY4hbmxjJX5y5DDrqvisKk+eYLXi lOv6g/G/D0Fj7gEAXdPUqW1v6q8ZWHQi3obsynKhG06C8pshFC3+3rcwQPyhzdJ3tk6g sVgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726827514; x=1727432314; 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=b5x6COaWYuBZ+I/ktGSPVnQK2t9IfKl2Gymo5GZUYVM=; b=ovzIAr5jJkEsh0nU6cR41sStxCBR7YQburUh77EwYAmBC8B7T48T0AKTZTEpd5l/Ge 6W0NUEUZSP2K2NM9ADAkC3qsocA2WRGD8jQgE5PbHAVeCph6RssbVm8q0BA5PBUDlmIS Dr5TgCl0htNIvMlLJYrApZDBINnl2wxIdT3qvWe1Z13QYkDZVndy7eqx3izH7BiEJzyV Cxt8mhNwPjjHbu4nXKvcFNQJgmo77PBlcvzi0Pz5axeV9WObxV0uJP65AhX5xAmKY9ki 1R//q8l7nXyCXnuFcmX+FNbcFxJQlJ/gi67wNo0rv5+S+RxM116BCEEJGYEpKb+oamJd rigA== X-Forwarded-Encrypted: i=1; AJvYcCWgR3xOfsOkBJEq+oEXRWLFdnbUM/yzoE0z9o7ruqNjJtM6YEfXr5xVXMYu1DbGOCLoxUYiYQFMFcLQM3Sx@vger.kernel.org, AJvYcCXIeEOqcSzCwkcwXk+RC9eXZVqGU3aAxefCz6B8+cGm8Va8X0USjKyQZkRzmK/HkVhEijWNmUT7UfU=@vger.kernel.org X-Gm-Message-State: AOJu0YyjJ9V3AtihZlvUnCG439mGM9ti1OZsJNMO/MJKEef87b/GVaJn Jmt9WL4pfsLeemtqREInCtnUx16Gn+4dA8iLy+T8TAoBcd1wQSc= X-Google-Smtp-Source: AGHT+IEHwBHrwTHTEv0Pp/iXOeAFo6lVrY7n+mRIq3slFlGs00IXkri4xKe99XIYbrrJH0TpeFpgOA== X-Received: by 2002:a05:6a21:83:b0:1ce:d403:612d with SMTP id adf61e73a8af0-1d2fca71fe1mr6873701637.13.1726827513723; Fri, 20 Sep 2024 03:18:33 -0700 (PDT) Received: from localhost (2001-b400-e35c-9cc2-447a-d760-d4f6-01f4.emome-ip6.hinet.net. [2001:b400:e35c:9cc2:447a:d760:d4f6:1f4]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7db4998b4f3sm10636251a12.72.2024.09.20.03.18.32 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Sep 2024 03:18:33 -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 Cc: openbmc@lists.ozlabs.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 1/6] i2c: npcm: correct the read/write operation procedure Date: Fri, 20 Sep 2024 18:18:15 +0800 Message-Id: <20240920101820.44850-2-kfting@nuvoton.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240920101820.44850-1-kfting@nuvoton.com> References: <20240920101820.44850-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 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 Fri Nov 29 10:47:10 2024 Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) (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 B43C514BF9B; Fri, 20 Sep 2024 10:18:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726827522; cv=none; b=domYprPMd3/gg8nvExhhCKiSvi9wfRdDM4OcBN3jso0Vq3V9tFnWOtiqmmkVrjlT5DKTmQRvN7wmmspOYHTp2x8+cW2a25EbD83PZXZVrn0YY4fGFBsXBwyaLDcjO+pHquV55htzUey4Q7oMAzeh89jjdJdWqNfA533rpEQCOJY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726827522; c=relaxed/simple; bh=BXdwMKUSnQqMpgIUV4DlPMKSV70vqCh/Y61QD8mcvAw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=eyMhA/uqX0jcEs0vFtFcLUhU8Xwrr/eybrxLa2qLLQX3EImoCTVQIh5FIM0hTTDyiZ5dxtwUT+PTRnFczycX4teDb07LQm5jeLPTKA4geWv+u/U5ElaTpBG6evoBFgHEEoFI0hV2ufJq2Y6BsF34pOiNwEh2qSd7RZ4yPu2Pc2Y= 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=Hkzhrcgq; arc=none smtp.client-ip=209.85.216.45 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="Hkzhrcgq" Received: by mail-pj1-f45.google.com with SMTP id 98e67ed59e1d1-2d889207d1aso1270467a91.3; Fri, 20 Sep 2024 03:18:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726827520; x=1727432320; 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=Hqji9tGtt8x3XWnj49TDJpJlGjDL6hysOmPTOIryTb0=; b=HkzhrcgqEeeiNwv6lqgJYDF/x09FfbjlwTT1NrDYOKfH/f/njRW+3yxLk8KxAPx6xA PdrN7FwCOhCfjiFgVaOUKVj4f2276B24DqzeEnFNvgAWdc5/bJ7wP3WZpe8MJtojoXB0 05t6KgDMFbOpDExiWolEoJWms5cd736MiTBE3l0W5kAu/uB1E++ET6ZW7ijp7IGECw8q GWllM4lGtRTrMD6G8tMfRieOEqAXUwadLAnCY4vGyN/rRsg4qCgalb+FqmxVFbhApDkR Q5MVMkEJn969rPoxoppsRuGOeoQNvgltF91ve8a2cwEfb6RBHwxZwRdn8U3RPLU7O8+T Uhzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726827520; x=1727432320; 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=Hqji9tGtt8x3XWnj49TDJpJlGjDL6hysOmPTOIryTb0=; b=uMYLm5PY26oD2U8WYDXXcO8yglTTEfd3vKL01uaxUASRYI3QdL6gTC7LDDrLa7SWl8 jVzPRxP8dMOJFQ5/abfrF4lwMkpHtcrMP6gAEh6FH8LkhNfbc8bX5BNCqQlAfHmrtEK2 Bz7D0+8sBwzowJ+CJvIR3j3W80N4dHYRUnsR794uuJCNBpMCd+pdHDc7z6eOpOZDhI+t XtOIoSw2PBFyt1hVipVhdue0WZk2Twr+4wRn22xI4L9gStuBIidBAcLWL0gLNj3w7iIz hu5JdK+X6N7ZexnHbW/RjtqGnVmsmecLqFWOlha6wAPywfryMooN6g8TM/41oDX3NhDO zqFQ== X-Forwarded-Encrypted: i=1; AJvYcCVFFL+tN9QkrqW+Idax7ipamRG+0AYy3+iue2ez8pfhskiORqtDIui/iJIOluAM1rO+a4FD/fTgcnw=@vger.kernel.org, AJvYcCVcxCt2rpEN2zXqWjWwkjhD1KBU6kjIVWUfHtny0RYa34Xv/yIcAHjrUUIsRKfZiB3xzpkHkqTNJkQQkmls@vger.kernel.org X-Gm-Message-State: AOJu0YwrfUUsIqqaNGi/ZCH5Ri//8k+QScvsZBd4yLcLejE3Ox2jPB9y v/zZupdqHVE3uiWYXgmV174lDiTBD8nVThFXYAU2MavmulGfiI8= X-Google-Smtp-Source: AGHT+IFHbMVlFKHZ2gmmAnVDb59au+HAvbAe/HCOI0X6F2Mkg0p9TL07e1HiiSAyfNluOEgtpfy6Xw== X-Received: by 2002:a17:90b:4f8b:b0:2c8:64a:5f77 with SMTP id 98e67ed59e1d1-2dd80e7191emr2734760a91.37.1726827519832; Fri, 20 Sep 2024 03:18:39 -0700 (PDT) Received: from localhost (2001-b400-e35c-9cc2-447a-d760-d4f6-01f4.emome-ip6.hinet.net. [2001:b400:e35c:9cc2:447a:d760:d4f6:1f4]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2dd7f9004fcsm1496423a91.44.2024.09.20.03.18.39 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Sep 2024 03:18:39 -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 Cc: openbmc@lists.ozlabs.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 2/6] i2c: npcm: use a software flag to indicate a BER condition Date: Fri, 20 Sep 2024 18:18:16 +0800 Message-Id: <20240920101820.44850-3-kfting@nuvoton.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240920101820.44850-1-kfting@nuvoton.com> References: <20240920101820.44850-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 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-npcm= 7xx.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; }; =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,7 @@ static int npcm_i2c_master_xfer(struct i2c_adapter *a= dap, struct i2c_msg *msgs, =20 } while (time_is_after_jiffies(time_left) && bus_busy); =20 - 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); --=20 2.34.1 From nobody Fri Nov 29 10:47:10 2024 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (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 D527A13B2B0; Fri, 20 Sep 2024 10:18:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726827528; cv=none; b=git7WPP1FUIjNc5Iu2wZ7P65EicDb7bpHU+T0D5YnCvgmUwMpxknR9jTSmlGLgFEhOETCj3IXym97iZtkxVdBllBM8HfG6njTCgEGswD7Md+unXn84SEWaffiu5y2NYDOII9jH62NLvRqWUMf/ux9WrA4zEpB5Ai/ecehvMre7U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726827528; c=relaxed/simple; bh=Ul6x+Spxm/J5BUMskh67v9HqKC0N3fbB+m5zysgr4d4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=QHL18iniixvL7rxqfQBcvjlHAffmnTfMATxnK1iDK7SsYgi3dy5vaL2uE07U12LOLcH3YHOh8Vj0+ddUZUACxOq+BU95XQFoucCkpbJQACPRVSVNgqdjAucZCPpkcj+z86+j/ShYh2AZiLaihZdSz3DwDJcNHBC9XMKKcyeBlqU= 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=a+CzXtAW; arc=none smtp.client-ip=209.85.210.179 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="a+CzXtAW" Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-718e2855479so1366642b3a.1; Fri, 20 Sep 2024 03:18:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726827526; x=1727432326; 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=lZSv8oOEI8/EIuYdQcnCnzx+K0Uspaq3vNp+9LNmgdQ=; b=a+CzXtAWr+axL4JqUso53a7T3jujFF3hyFpTQOfMeUXqbGd6ktC4H0kHI+OTxT4xo7 Fo9zHvcP0jLvdg7fub1zFAJPaaHyYte4g//GeRgi/Q4lvlX3LRNEcB96ufsANDxPQoEz SKBmqI6b+v154ZMqWTV6fZaqkhW7RK+WSwNxd65EH5x6iTTFxTsJKE26q6XWrg0Ut0Ep rTEUt/iLd9oEmGHtzT1Uh6o97cQsVWi4EN3cLq9rLeb0IXUbc0NZOpuA1yJVdbc2tA0w aMWk79PtWcNNjCgQIJb9mUQqgSFdDIU3Z23olIpL5fI6TxGvK6mW3h88gmRSmavMIcJI HY6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726827526; x=1727432326; 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=lZSv8oOEI8/EIuYdQcnCnzx+K0Uspaq3vNp+9LNmgdQ=; b=LCGy3g2otV7YwjCv1Z8b/4Muw3e5Mor77ow9bT2aHb2Lg6580SkEjUAgQAmAGoqRtu L8O9lY6ksOqwfjxyZ379qiyXeVKWwO3hksIikswBkGXA82PtN9oLDnNfXSvjxzMPzqQB zC2hP4Wu6uWQk2uxhaxHktUijMaCvma2K3TBp/zCEA9l2N/OGrHSZQeW/Ws0fDDcxpmU a4h1EDjzMptqFtB7Cs7kROoSmPuJ2niNVUATN/vMvB6PSM+6H+ux5S4KUgwO9XlRlu50 nuYDpV3S7SdMtbgUUbQTW0UmGJwXXvz/j8s+PMG9B3cuzmINkMtYTuuJGfWOT7UsJg8O 9Byw== X-Forwarded-Encrypted: i=1; AJvYcCULOtT7t084lvot5zZHUboeP+ea6bz94hMHn8hmwY1lt+D8Uf2lT9WCnTomoiPBDtpmsvwt/LWYuE3e4xV5@vger.kernel.org, AJvYcCV4cDS2zI6msMTVu41bXSo7jAnCCejk5WwvtrQa2pz+TLGd+F73LcXa05A64u/aUcs/pF7YsCN7fqs=@vger.kernel.org X-Gm-Message-State: AOJu0YzAbHHQJArCUhn7NcH0aNRO9l3+/O4AsR7Iy/4mROwK8EcE7Y33 1aof+KvHMsQN2jp4+G//RzHjcqc6yDsGqpsFfit528YUzpTtXSU= X-Google-Smtp-Source: AGHT+IHSDCa/ky7wcHHV42EjmxrVc3NqFczZgvBBAeriIPMSqpxv8ezg6gAsrGgsDVcTzPcy7dQWKg== X-Received: by 2002:a05:6a00:1956:b0:719:7475:f07e with SMTP id d2e1a72fcca58-7199cd7abe1mr3335249b3a.4.1726827525919; Fri, 20 Sep 2024 03:18:45 -0700 (PDT) Received: from localhost (2001-b400-e35c-9cc2-447a-d760-d4f6-01f4.emome-ip6.hinet.net. [2001:b400:e35c:9cc2:447a:d760:d4f6:1f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71944ab50cbsm9550284b3a.53.2024.09.20.03.18.45 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Sep 2024 03:18:45 -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 Cc: openbmc@lists.ozlabs.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 3/6] i2c: npcm: Modify timeout evaluation mechanism Date: Fri, 20 Sep 2024 18:18:17 +0800 Message-Id: <20240920101820.44850-4-kfting@nuvoton.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240920101820.44850-1-kfting@nuvoton.com> References: <20240920101820.44850-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 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-npcm= 7xx.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, } } =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 @@ -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 =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 @@ -2308,7 +2309,7 @@ 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); + 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 Fri Nov 29 10:47:10 2024 Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) (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 91E2214E2E1; Fri, 20 Sep 2024 10:18:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726827532; cv=none; b=GPTC7wsZUPHuuQcIwlcPh3gtNv4A1Ssw0aKtOP6j3F2fP9N2+HMFu8oCYzQKUBA/SaD3hJ1f/WzRVsSwWI278VtTMsmBpg2Dp2Tb2dY8Lk45Dgypju2xA6jgqxtJIc3LB4ySJ4E+UuT5foy/CSuj598te4JUThgAGxIPBba3+lg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726827532; c=relaxed/simple; bh=7kive0qkjdyFwez2JrdykzAXBDAI298fkcuv8OPhE64=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=K7XrvJZj/CUXjHZWmni3NahjwyP07dBW5QdVwZKedpG9nDaRY1ruB6/kHxq6sBFE6quW5NE1YND21zNhc5POVZGtnn+QUL3NcTn4ieWPcwWt/6fs6TfhbzlCUlMRB7oK7XdsMb9v5vgevE1ckgcnHMLhdUnVhIJkdOsrn21uLkg= 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=GdPzlCBL; arc=none smtp.client-ip=209.85.215.179 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="GdPzlCBL" Received: by mail-pg1-f179.google.com with SMTP id 41be03b00d2f7-70b2421471aso1204162a12.0; Fri, 20 Sep 2024 03:18:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726827531; x=1727432331; 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=R0BORBW6QOc0S5wwx7/xMWlE8WZqalSOuRW0pFDdCkk=; b=GdPzlCBLm/xvDGjgiymjmvc1dxv7+MTnQDOYzGcNa6AnbXWwE8er82sN+DJ2XbuvQA QdRkopaXZ9JgDvqOb7cFJfAya6h5al6tzPZaBdBNtmZuf9c+Jrz1PHYSJl/s4NKPfYte EFyS2IWcEjsZGMeXSicWJzAQwVnfvfFvUKPD3fRmbfhQporeHIbovnfGHISdGS5MeekN 3irAmh7QAH8ZlQvnIR5KTQ1SDgoDCeQx1iaLyOMdaIJUtBX/kBh8SuZka2JdZEO4ZY4f Bh41Haw3qF71yVmumAIBYXaU4nq1tS9luQDmpThG17sBLpqE1W4kM32hKTPf60xE7wtU fgfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726827531; x=1727432331; 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=R0BORBW6QOc0S5wwx7/xMWlE8WZqalSOuRW0pFDdCkk=; b=R/WObPoL8NvkZSskjO9A32vOFQlD92CftO3q5bfGqLK30+6isRAcKIkIhdgq1bTYce 1VOMm3ZMURn3WDP51Uw2ujJjxo6xPmWCBTDUxtXyGB2cYyVWvZTnLTWSJUaLMoFIPPbi swjHwZubOccGS3fil/Z3Wcn8Y/Zy96HGAP+AzN4lhJ+52YkQXTuNfAHZ0mdLvzuj4/gc FDux7nTZE0UFdyKlo8sh/Z+FRLAaEG4G8UQjZmli0tpNpNPlAxGiPe8P/IcxIt9fbwuQ YGG+Vgu6XVeDPDzNMT894azaLsy8kArcT4LmpVLL5D8irTuECUJeRom3RY2U/ffZcMgL 2wAw== X-Forwarded-Encrypted: i=1; AJvYcCUmWfpWPaB1VEdboJavNPoi46CAR06P/M/4XXff/iGsKI6AV/fmwVDEPlCb5QjKf4kBdJM7sXx34e6J0sSb@vger.kernel.org, AJvYcCVlTCFuuvOTIPQBKKhAOtw9MNBVbqti9NH34gDhIoz6y9GjToBcC9C4aJgbilKsD5DQpQQTlcEScls=@vger.kernel.org X-Gm-Message-State: AOJu0YzlIOQ9VURdUyNM0c4rBJ2J/hVEkXx1UwuaCeZxygUuPBQp2NW0 3j1kxFK9LHPLoNNjGjyBFaGgKg+81YP/z5+sazkrUsyGp/hxhN4= X-Google-Smtp-Source: AGHT+IG4FpRxofnrPdGJ9W7cgP0YW7D7iB+Tp3jNOdzdQP8ud98xgyHONsXPA7bEu1klbUawA9o4yQ== X-Received: by 2002:a05:6a21:30cc:b0:1d0:7df2:cf39 with SMTP id adf61e73a8af0-1d30a8bbfa8mr3321659637.7.1726827530660; Fri, 20 Sep 2024 03:18:50 -0700 (PDT) Received: from localhost (2001-b400-e35c-9cc2-447a-d760-d4f6-01f4.emome-ip6.hinet.net. [2001:b400:e35c:9cc2:447a:d760:d4f6:1f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71944b9a144sm9846698b3a.178.2024.09.20.03.18.48 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Sep 2024 03:18:49 -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 Cc: openbmc@lists.ozlabs.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 4/6] i2c: npcm: Modify the client address assignment Date: Fri, 20 Sep 2024 18:18:18 +0800 Message-Id: <20240920101820.44850-5-kfting@nuvoton.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240920101820.44850-1-kfting@nuvoton.com> References: <20240920101820.44850-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 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 func() 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-npcm= 7xx.c index 68f3d47323ab..248835220c86 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, =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 the func() 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 =3D 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 *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 Fri Nov 29 10:47:10 2024 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (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 93814150997; Fri, 20 Sep 2024 10:18:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726827537; cv=none; b=WvMjn6ftgNPbKQFWuXFb3mSc4LhGMllF/aztx4BjcEa2XNd10cLjSFh+3Io9liQlKZxQiw0f8t6RuHAjRHU15gc4Dm6dvDp9piMg61qAJ1qgObRM1HXijSlNIm2X3YA/OF6n2MtVdB0ARsFJhBHYTbua07KtM4QG9Jn0mcjY7kI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726827537; c=relaxed/simple; bh=nSldDNLELpj/wr+PBPXOADOHBG1s6JmVReWahXVOb04=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=gF1hDgKUCVstI+do8qyQQxAxhW+HeOyvqE46yj1yO6TQJl79BZyRPY7D59AlRUF7Pd652ZHEGTRIy1kDTR0HPVj/1ia5iT8FQYLS+cNnzkJlwRJgFBMJ/ThXK8DW2zMEm/VznzF1n8ewprUPIpsSlmgHMq+Ivotci7HOoEgnynw= 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=jkoIwYM9; arc=none smtp.client-ip=209.85.214.170 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="jkoIwYM9" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-207115e3056so15416285ad.2; Fri, 20 Sep 2024 03:18:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726827535; x=1727432335; 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=UH9kA9JWD+tVJWzEqr9eClxvqxO6z1+m9W6qbS/HMVQ=; b=jkoIwYM9ZeRXatQt4g+M8tZ1d4gJlOUTGQnc731vasU6Axsw62oYx5+/0gNBlSnPVj oZ/j1+rm+A94vCn/pvQFE20DJk3fGlsFNVe9S9fagX8PEZ4irzfdqyUXnmrbzV+RW/xj 38OOMB4LrSKb/xOPFm1pgO50wLQpws4DbBUIAYm4eVI093kEz7wELpW0yuzB1QXILV+R oQ/Tb3jitrYSb1gMvMBdqjE4tL8m011LRrv8yYfXdq7F2DUrpchhCgMjScqnYHz6uMQp jgX/mTmkN98yBpRf3BCRPRMnTkaReDXFRD4Kqr0PkCrjjv7TSFSqzW363UKJNB0v4hLS oiWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726827535; x=1727432335; 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=UH9kA9JWD+tVJWzEqr9eClxvqxO6z1+m9W6qbS/HMVQ=; b=qHcqv3vgZMJQ0zxEjJ4zadmUGF3H0ybmoMFILxapJWFs7yreNHbbd20Wze1DO49Ft6 3baF5wqGbTDPAAMOg8mXtgZ/E4BBfUkfbE4tBDnauCH7w9bIU/rF/2W1/ulEFaWQrGjo O7P+VY+cXkrDysa3vcIUbQoWFAPl+jNe0LoLTLgsCyeccSWCU2G9O9rGUslNzWSlcJk6 9Q24lrU1Y+WN0UFaCyuwIITtkXpXCcPStZH4k/UcLARgytpwQFtbb96IakjsNty5hT5r mrH8tcJgSIG6uVwZeMzeViAL6IhMR0RN1OZbmKUTs5uZ+/0QlrN2V7xwOsixjv2a5epV AiZQ== X-Forwarded-Encrypted: i=1; AJvYcCUHdnVzM8Yl3Mo0zEvyflnaowesVTlm84uIeET+bzi+jQPxJVJjU9T/Bln2Dzfm2B4oD3jo5Dy+hZ1BMopw@vger.kernel.org, AJvYcCWf45PyRLny8qXJQeBSkaKZdpEFCQneZkMMYjJeadWtNezfFK9okqogbfpFeG21hcApxRwrXSAyM7U=@vger.kernel.org X-Gm-Message-State: AOJu0Yz0tSCypI6cBA+8NqCMjHAezvqKelsp3iVbIQXmDxNA2bgj0SwQ 14gNCILS/JgljIiWzd15aTVyVtXDPbNLRsG3x1+Vbu6u/QuO/Pg= X-Google-Smtp-Source: AGHT+IHdceeTTlHzcpQIv7czEig7kJcoLhGOtCj3reepT8EtT67xY5W8H0utvE94U3qi0J/S6BfxQg== X-Received: by 2002:a17:902:ce8c:b0:206:fd9b:f4f1 with SMTP id d9443c01a7336-208d98d0779mr25157575ad.56.1726827534625; Fri, 20 Sep 2024 03:18:54 -0700 (PDT) Received: from localhost (2001-b400-e35c-9cc2-447a-d760-d4f6-01f4.emome-ip6.hinet.net. [2001:b400:e35c:9cc2:447a:d760:d4f6:1f4]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2079460255asm92326695ad.107.2024.09.20.03.18.53 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Sep 2024 03:18:54 -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 Cc: openbmc@lists.ozlabs.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 5/6] i2c: npcm: use i2c frequency table Date: Fri, 20 Sep 2024 18:18:19 +0800 Message-Id: <20240920101820.44850-6-kfting@nuvoton.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240920101820.44850-1-kfting@nuvoton.com> References: <20240920101820.44850-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 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 248835220c86..9d533873e477 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 Fri Nov 29 10:47:10 2024 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) (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 AF56713DDC2; Fri, 20 Sep 2024 10:18:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726827540; cv=none; b=B14niUCf5vTn6hzrBVSFUHyU+jx/DwhKV6fZ4gxjPCT5w+TJs3/g2TaApF8ouKFZOup21qlxwH3s7ZSIuah3Owshkh+8F+bfcUqBC2uagk8grHMWap99XZd2X0AiNpnogIrtZT5C7NzbKEpyNR3LI9nI4fYFkqvfjr41geWL5SI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726827540; c=relaxed/simple; bh=gvKR/LNghQAQ4Rj9o8ccB3IHJzGgbJQW1c9wlwaTIC4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=DbkxyHEZFO8HjcUkN2k891hGHgdaYwVuwxnQKvyn05u2zo5HVXkVLEl1UDJ6ZCkcjJl3rURAfEJPZOpVbhW1iavqE4TIaxN9ugehgArtlEHRjS6E3AE7hhNJA52fKwqEgFU9lUhIESK2cjkkqXU8Gx2QvLRrFJOy4/2nELOfw4w= 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=MOCbzs3k; arc=none smtp.client-ip=209.85.216.42 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="MOCbzs3k" Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-2d88690837eso1647718a91.2; Fri, 20 Sep 2024 03:18:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726827538; x=1727432338; 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=MOSQS2phhZy9vhfSdqHxVy6juQR6vrzN7E2tXsy++5Y=; b=MOCbzs3kHVg7AcL2Gdru/A9Bb6on3Pn9wbNqtRKhlRlewMkdl7hqRMQ8z0Qv+clqZc 5xL7Hi9UOBpidJ1JdYHpCZcMj7LqaY9fpg08NagbmlBR1Me1NkuO/lSoApObQwXaNI66 uFTyChU8e8jKPV+xuWaUGbYFzhqxNEqvOq6UDA1OTCrad+TUOed61menGq9hZ5bO9JN8 k4yA6zOvgO2jSpa+o2GZqJV/sggG5hsWZBSKs3N7QWSwISeRgx8W2LusSW3wYQ9hI5UA ka/MMHx/UmM5DK00wSv72FZhmIPlwQSi0HTywswFiwRTGJruLxAEbnIGlzoFSX6GojGS eTjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726827538; x=1727432338; 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=MOSQS2phhZy9vhfSdqHxVy6juQR6vrzN7E2tXsy++5Y=; b=lSGLjYEaqp2mXGA3K1fPbd4VowqYJjb4/sAa51aHVGb0FglFs5H9oAU0bVUDS59di6 /lXsvLgaxl14tkrr1XIsQzXtusc09gMXxHFI3R5/EUgDN2ELd+ApLCezykK8rPJ7J/Qz uE1xoGSUB4zhwTNb/Tf+GC4AHzg+G/2EbZZByBAJ4H93z4bZbDI2Mc4Xy16zNJZbeEe5 3fvVhpuIXoHxv1g1GvKCC61BoQwZ2SSU/rmRofcS7yX0rGtNAZFQ0HQQu/R2/eA6QUt0 023en3iNShTVgiJCSOO/VoBh9RWdH+fnCnGvydWbNcEVlRWwi5Oqa07e625mNVEhaqnv iO3Q== X-Forwarded-Encrypted: i=1; AJvYcCVnHZTZcPTZMvTYsj6fRuRUr8ERG9N9mUXjG5EOwU+cIZFPrr3kfY6Q0hdwEP0T/WheGidIEpizqCI=@vger.kernel.org, AJvYcCWnG70oKE54QVFi/CC37Lyz8cCDfYfEgy0lq0/ra82fKCFduIjvZFfItpHSUt3vdOGro3g/s6ZI6y/Gzl/w@vger.kernel.org X-Gm-Message-State: AOJu0YwV8d2Y/iamkHsDjhdiq3X1Vu9GEI458Y6vsHgFjDknv7YDK6XX Te+OsDLUzNdT8oI7v92Es1RumW8nd29cYegSXXyFim+S0rEhx3o= X-Google-Smtp-Source: AGHT+IFG40FXFa7cL/Nwmch53MN0BC+f2vfZG29tfUmd80whMxH/9pjTgZnrwZksfCx6vZxpzJKgrA== X-Received: by 2002:a17:90a:9313:b0:2d3:cd22:e66f with SMTP id 98e67ed59e1d1-2dd865e77e5mr1171550a91.9.1726827537966; Fri, 20 Sep 2024 03:18:57 -0700 (PDT) Received: from localhost (2001-b400-e35c-9cc2-447a-d760-d4f6-01f4.emome-ip6.hinet.net. [2001:b400:e35c:9cc2:447a:d760:d4f6:1f4]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2dd7f947427sm1487476a91.48.2024.09.20.03.18.57 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Sep 2024 03:18: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 Cc: openbmc@lists.ozlabs.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, Charles Boyer , Vivekanand Veeracholan Subject: [PATCH v4 6/6] i2c: npcm: Enable slave in eob interrupt Date: Fri, 20 Sep 2024 18:18:20 +0800 Message-Id: <20240920101820.44850-7-kfting@nuvoton.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240920101820.44850-1-kfting@nuvoton.com> References: <20240920101820.44850-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 9d533873e477..aa3310afbf6d 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