From patchwork Fri Oct 11 05:52:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tyrone Ting X-Patchwork-Id: 1995890 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Z3kU3+eC; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XPwlN48q0z1xsc for ; Fri, 11 Oct 2024 16:53:04 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4XPwl62dzqz3dBW for ; Fri, 11 Oct 2024 16:52:50 +1100 (AEDT) X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::431" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1728625968; cv=none; b=jhFQdilR5fZl7ql2RnDhqiytLaLbBViDFR7tehq9O0bjbnaRUfD8BZ7a/ZHBQbfJQHvHOEnDrti5QJzbMgyk1uMhNmpuX+iN3yE7iO9zx5Au6B4mq8G7ZMDApH9Uz1Ol88LMkXuB63adPT0GDPYnvzyzDMpBCn2ZAHzHXvLcZLGgqbWocz/i6IsKS0Fs//9uTYEMWYrIQDKC6n94jGR9/VRGgT9zetVhhcfMU8n9JIigpe8wUf9Gff4njvt4pMPGd2guYyTdP12YilLq4W+dfbNLH7Bci0AhAdxOcc2VK9lI6MApEEMCKTDSBJdBo/dyeCBbzEuD7Ad/Qp44W6+JdQ== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1728625968; c=relaxed/relaxed; bh=sUTvgfGYPu+IPYUs2nFsjwTZ63vlpmHE9eVnRYu8l/s=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=SLz2RJ+24ZjdQOXYpTWYWYOXo6dQqhRohl/fyA1VSXPUnlPnsL3Hx0dvXM/a7kycSseqcg/Shw+fo+fwdQ16Sk7N5gnZgiPGpiuKYgxT1MymRHoYI4XLyaAeKcqRIHBj8e9Ualraj/6b/+XG5oRSEn5B2uaxk9kcACPBm1hIcUKuEF6526uiZbuzq3Im8VLh9b/Gbe/P6XTLTRd7gXjlrqxdTsOAswmoWR0AF18ypNM5NnBo5mXf2Y179IJSXFczU9Tnf/fLEAhnGEUZDBmRksXMjzzMVeFm4hBVCjCnkuOJc1z0TGLathJlx0SpQCBo0UUEegO4LXXw3tsiyGWmpA== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Z3kU3+eC; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::431; helo=mail-pf1-x431.google.com; envelope-from=warp5tw@gmail.com; receiver=lists.ozlabs.org) smtp.mailfrom=gmail.com Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Z3kU3+eC; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::431; helo=mail-pf1-x431.google.com; envelope-from=warp5tw@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4XPwl24Qmrz3cMg for ; Fri, 11 Oct 2024 16:52:46 +1100 (AEDT) Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-71de9e1f431so1377909b3a.3 for ; Thu, 10 Oct 2024 22:52:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728625963; x=1729230763; darn=lists.ozlabs.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=sUTvgfGYPu+IPYUs2nFsjwTZ63vlpmHE9eVnRYu8l/s=; b=Z3kU3+eCNGNecI0xW6g6hXGFwcwmbvleE2JZsKxQViA0kUlgqInIbEPwVlDBsudOSg BPcVIIPdeaEHE+QIUMZF2pc+geVFYwv6ExuUAw9pF9Mz3P1nX1jsaZjopMVpvQzMftBf rHKsB+w3mZOmiLyiXTs9Bg5MJ26vuFu30Tdy718wHfJoeTgLMvoOLEzw0Ymz1x1hEu5c HhE2dGBIpxuMua+nlSAljDoa7dm+y464XJXy1DD7fcLl8jJzbpTjlL7rqZMb2WJZmVjG Tdv3B3jqKQC9NmY+bSxQl2k3VvaVDRgYl74XKmFBI9z6+c1ucuhQFVYULKs1IO09W9Fr ZKkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728625963; x=1729230763; 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=sUTvgfGYPu+IPYUs2nFsjwTZ63vlpmHE9eVnRYu8l/s=; b=nToAN+2Mb50NHoY6s62+1NZuLhHUOofo6VHaK/WCsHf1D++Q8dF+1SxX4IPNU7HHhE Pz37u3AIFdovBtku3KMuY/VNc82I1Buc+HwsS+Pscg239NFByZ2ktPWpNPikRWEJkJJo 5+CTZexhtIILRJKwGelxePtfRxEEvoW23TBtPgFbiHN7IpS+/GylFrZKSLWhYOJHbrRv RR8NSDGkgpjWfgwrnZ71P2OyiM300qKTzXp5O378Nv6f/tukgd/rNU9zZc+YEN4IpTX2 45ZmEXr8M1WgQwpul2l1196fY4o4sX8GMVDaQ3ikZqhYfntFiOjg/NRBe12z1lmNMxzb 0jHA== X-Gm-Message-State: AOJu0Yx7zse6osajAujJegagzUR7xyZFGFYSDV2STg3UMyTEPJhpvdS2 CHemWAe47ONfvABjDNQAaySAbqyDyso//bEl/+ry6KUE9632YKo= X-Google-Smtp-Source: AGHT+IFUResKRCt/Fii5kWLbwdloA/fVaIaBv1jKqdZe/ZzANW3Qrd8tnYf+Z9klWGEAE9MrDIuY4w== X-Received: by 2002:a05:6a00:13a6:b0:71e:5de:ad6d with SMTP id d2e1a72fcca58-71e38095deamr2504286b3a.24.1728625963465; Thu, 10 Oct 2024 22:52:43 -0700 (PDT) Received: from localhost (2001-b400-e38a-6880-f424-8486-7476-9f9d.emome-ip6.hinet.net. [2001:b400:e38a:6880:f424:8486:7476:9f9d]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71e2aa93876sm1946980b3a.114.2024.10.10.22.52.42 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 10 Oct 2024 22:52:43 -0700 (PDT) From: Tyrone Ting X-Google-Original-From: Tyrone Ting To: avifishman70@gmail.com, tmaimon77@gmail.com, tali.perry1@gmail.com, venture@google.com, yuenn@google.com, benjaminfair@google.com, andi.shyti@kernel.org, andriy.shevchenko@linux.intel.com, wsa@kernel.org, rand.sec96@gmail.com, wsa+renesas@sang-engineering.com, warp5tw@gmail.com, tali.perry@nuvoton.com, Avi.Fishman@nuvoton.com, tomer.maimon@nuvoton.com, KWLIU@nuvoton.com, JJLIU0@nuvoton.com, kfting@nuvoton.com Subject: [PATCH v6 1/4] i2c: npcm: Modify timeout evaluation mechanism Date: Fri, 11 Oct 2024 13:52:28 +0800 Message-Id: <20241011055231.9826-2-kfting@nuvoton.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20241011055231.9826-1-kfting@nuvoton.com> References: <20241011055231.9826-1-kfting@nuvoton.com> X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on lists.ozlabs.org X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: openbmc@lists.ozlabs.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" From: Tyrone Ting The users want to connect a lot of masters on the same bus. This timeout is used to determine the time it takes to take bus ownership. The transactions are very long, so waiting 35ms is not enough. Increase the timeout and treat it as the total timeout, including retries. The total timeout is 2 seconds now. The i2c core layer will have chances to retry to call the i2c driver transfer function if the i2c driver reports that the bus is busy and returns -EAGAIN. Signed-off-by: Tyrone Ting Reviewed-by: Tali Perry --- drivers/i2c/busses/i2c-npcm7xx.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm7xx.c index 482a0074d448..c96a25d37c14 100644 --- a/drivers/i2c/busses/i2c-npcm7xx.c +++ b/drivers/i2c/busses/i2c-npcm7xx.c @@ -2132,19 +2132,12 @@ static int npcm_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, } } - /* - * Adaptive TimeOut: estimated time in usec + 100% margin: - * 2: double the timeout for clock stretching case - * 9: bits per transaction (including the ack/nack) - */ - timeout_usec = (2 * 9 * USEC_PER_SEC / bus->bus_freq) * (2 + nread + nwrite); - timeout = max_t(unsigned long, bus->adap.timeout, usecs_to_jiffies(timeout_usec)); if (nwrite >= 32 * 1024 || nread >= 32 * 1024) { dev_err(bus->dev, "i2c%d buffer too big\n", bus->num); return -EINVAL; } - time_left = jiffies + timeout + 1; + time_left = jiffies + bus->adap.timeout / bus->adap.retries + 1; do { /* * we must clear slave address immediately when the bus is not @@ -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 = (2 * 9 * USEC_PER_SEC / bus->bus_freq) * (2 + nread + nwrite); + timeout = max_t(unsigned long, bus->adap.timeout / bus->adap.retries, + usecs_to_jiffies(timeout_usec)); time_left = wait_for_completion_timeout(&bus->cmd_complete, timeout); @@ -2317,7 +2318,12 @@ static int npcm_i2c_probe_bus(struct platform_device *pdev) adap = &bus->adap; adap->owner = THIS_MODULE; adap->retries = 3; - adap->timeout = msecs_to_jiffies(35); + /* + * 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. + */ + adap->timeout = 2 * HZ; adap->algo = &npcm_i2c_algo; adap->quirks = &npcm_i2c_quirks; adap->algo_data = bus; From patchwork Fri Oct 11 05:52:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tyrone Ting X-Patchwork-Id: 1995891 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=HZ7jzTDl; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XPwlb5FcDz1xv0 for ; Fri, 11 Oct 2024 16:53:15 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4XPwlC2QvWz3fR2 for ; Fri, 11 Oct 2024 16:52:55 +1100 (AEDT) X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::331" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1728625972; cv=none; b=hNyl4pAWTw1n/pgBPzQcjVANwBeTpgH0K6+9ggZVK/Uef271jcv6PrZGkHDmrEFa+nbKdIgnVygCy+aYPSt/HFfrLwsdLS+D0Y+4+TMcJ06mdn0meDh2uL+vEKrUEUwJufd3cqqaYDdt3owneOCds2g6UBHsllKcjOgoRIcun/hJ0lmgPkV30ImvOA2tSLLG1ilkAvym3orKtEyYEhSR+PikAf5JMJWo3MmUrVDatqoAKe8WLJqtQh0rkX/Bfc/0y31rn8wF1LJ5UX3uTHR0VU72e2TcD6U0LEBbBt7s8MVqiD4FDtQJsqMbln822QBuEKKGeK5GhUAcfy5vbcqJwg== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1728625972; c=relaxed/relaxed; bh=xuEkmyRTVFltpV0RlR/fXEwLbNM+hNheAUnuQYiB238=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=lNMdO3vsBVrWB3QV97LA4W3fhcRlcif9GsxuGg5w3WqS6lrlU5y7f0bQdt/ujx2npMO4VDFdO00OR13Gsdg0rYGVThFVSdxo9rrZW3UZQmNn2vHx9FKYuS31nM8TOrnquwoaU2bRc+ZGxC5yqiu15lHriZywTPAFQg6nr1+BU4DGoEdbznnukINN8ycRUFABwJbFVBZfB7DlM52p0G63GiV8zmcbElpyGh2qUWyphECxzBAzKOr2+PeoB8L9I8tLK2eRMp1Af//CokXTQqFL2UqLrC38rYS4q2nLfbSpzaGEpfX9UiSDdy70U6073G+4eYMt5ctrC50iVOLcu3kFFg== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=HZ7jzTDl; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::331; helo=mail-ot1-x331.google.com; envelope-from=warp5tw@gmail.com; receiver=lists.ozlabs.org) smtp.mailfrom=gmail.com Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=HZ7jzTDl; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::331; helo=mail-ot1-x331.google.com; envelope-from=warp5tw@gmail.com; receiver=lists.ozlabs.org) Received: from mail-ot1-x331.google.com (mail-ot1-x331.google.com [IPv6:2607:f8b0:4864:20::331]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4XPwl737pwz3dSR for ; Fri, 11 Oct 2024 16:52:51 +1100 (AEDT) Received: by mail-ot1-x331.google.com with SMTP id 46e09a7af769-717da7cb71fso47211a34.1 for ; Thu, 10 Oct 2024 22:52:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728625968; x=1729230768; darn=lists.ozlabs.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=xuEkmyRTVFltpV0RlR/fXEwLbNM+hNheAUnuQYiB238=; b=HZ7jzTDlzZeJOogVuILhNFrH68kySHyVlyJcnEAtwpk9agvab3v1LQj9UX7ICZ5M0a am27v+S001jzllxELK/Dtd+IoRb0aQf27Gv1/shyQVnO++0wflEpKTdY9OBBcM2Tdne8 lIeJUkvpOYRgsgJ5fa7XemToy3/qUNgGWxgvi/oNMXM+hWosAZ4ySgMsxYLqwhIsrPjO JPVQzOOwrNm9Ja/sJJro6LNJPqHSlPum2iksxMAr8t1CanYUeIIidn8XzInSvkdRNQ+J kzKCmmhamPisWTe5dbl0/NZqZEBvvUKQz1aGusPgjDUmju2Kydd5whB1UyO4kTanpUw/ laVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728625968; x=1729230768; 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=xuEkmyRTVFltpV0RlR/fXEwLbNM+hNheAUnuQYiB238=; b=XFznuo0BP3ECdesMSpYBEu/O6sByHqENsXRliGPZsZXDczWgX1dCC59LlvEiSQ8Xck T4uflInWXaWcwTdyDE0jYG/DxDYlXruLps8Zqj2st9HIsuloeI3J0GgvV82GGmSkZa4n 0O5N2Kk+2a8re98xEer7JzRfqAM5ECB6FkJ2Z9qjRnDru8I4ADpOTSAjtdFUqMxlLlMb yiqIZFc15IhoLEt+psHC6bdjvfpCITmvb3BNIR368+YHnXcNViWhROKp+D8qWJXAPGka U8jf1E3M3jlTaGdmtJ9UWQpTcGHYZwCPTsSkYj2bOQT1938AmDcQmTu9Gss0qNP+dURb VsCA== X-Gm-Message-State: AOJu0Yyq4WBkZS4yPq5DwkDVlu7hJLiJU0aMni79esxkLdb28DdvamWq ujG+NHH/zxV74/+rw/qO8CM6dxTy9nprq5s9aY6qWxs4kKszzOI= X-Google-Smtp-Source: AGHT+IFI+YEgKjTOGlTjgbwnkQl3Sg69mjhkL5/43+Y++zB1j0ROyjoHxWdrtmO/E8N04+bukogyeg== X-Received: by 2002:a05:6830:2587:b0:710:f7b8:c4ed with SMTP id 46e09a7af769-717d64972d1mr1211821a34.28.1728625968193; Thu, 10 Oct 2024 22:52:48 -0700 (PDT) Received: from localhost (2001-b400-e38a-6880-f424-8486-7476-9f9d.emome-ip6.hinet.net. [2001:b400:e38a:6880:f424:8486:7476:9f9d]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7ea449663e7sm1910843a12.76.2024.10.10.22.52.47 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 10 Oct 2024 22:52:47 -0700 (PDT) From: Tyrone Ting X-Google-Original-From: Tyrone Ting To: avifishman70@gmail.com, tmaimon77@gmail.com, tali.perry1@gmail.com, venture@google.com, yuenn@google.com, benjaminfair@google.com, andi.shyti@kernel.org, andriy.shevchenko@linux.intel.com, wsa@kernel.org, rand.sec96@gmail.com, wsa+renesas@sang-engineering.com, warp5tw@gmail.com, tali.perry@nuvoton.com, Avi.Fishman@nuvoton.com, tomer.maimon@nuvoton.com, KWLIU@nuvoton.com, JJLIU0@nuvoton.com, kfting@nuvoton.com Subject: [PATCH v6 2/4] i2c: npcm: Modify the client address assignment Date: Fri, 11 Oct 2024 13:52:29 +0800 Message-Id: <20241011055231.9826-3-kfting@nuvoton.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20241011055231.9826-1-kfting@nuvoton.com> References: <20241011055231.9826-1-kfting@nuvoton.com> X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on lists.ozlabs.org X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: openbmc@lists.ozlabs.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" From: Tyrone Ting Store the client address earlier since it might get called in the i2c_recover_bus() logic flow at the early stage of npcm_i2c_master_xfer(). Signed-off-by: Tyrone Ting Reviewed-by: Tali Perry --- drivers/i2c/busses/i2c-npcm7xx.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm7xx.c index c96a25d37c14..349492f114e7 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, } while (time_is_after_jiffies(time_left) && bus_busy); + /* + * Previously, the address was stored w/o left-shift by one bit and + * with that shift in the following call to npcm_i2c_master_start_xmit(). + * + * Since there are cases that the i2c_recover_bus() gets called at the + * early stage of 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 = i2c_8bit_addr_from_msg(msg0); + /* * 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 electricity @@ -2165,6 +2178,16 @@ static int npcm_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, * bus is busy. */ if (bus_busy || bus->ber_state) { + /* + * Since the transfer might be a read operation, remove the I2C_M_RD flag + * from the bus->dest_addr for the i2c_recover_bus() call later. + * + * The i2c_recover_bus() uses the address in a write direction to recover + * the i2c bus if some error condition occurs. + */ + if (bus->dest_addr & I2C_M_RD) + bus->dest_addr &= ~I2C_M_RD; + iowrite8(NPCM_I2CCST_BB, bus->reg + NPCM_I2CCST); npcm_i2c_reset(bus); i2c_recover_bus(adap); @@ -2172,7 +2195,6 @@ static int npcm_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, } npcm_i2c_init_params(bus); - bus->dest_addr = slave_addr; bus->msgs = msgs; bus->msgs_num = num; bus->cmd_err = 0; From patchwork Fri Oct 11 05:52:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tyrone Ting X-Patchwork-Id: 1995893 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=km3d4QU7; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XPwlp4lLnz1xsc for ; Fri, 11 Oct 2024 16:53:26 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4XPwlH2T4jz3fr2 for ; Fri, 11 Oct 2024 16:52:59 +1100 (AEDT) X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::1033" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1728625977; cv=none; b=etBZn3g6UJXREBKawuO4w3MtYI7a8/h2I6WXYpUmdPRb32UgOpRAYSLDduKZoauhBgfi/DmjaYShk69UpYoGSlRTIjcfiqiNwEd0Jasfq3FpXJ34AjYwx0Pzf3msBwg8+7AZQOEYwb03wznxdyjS+SNdL9rEBIdUCkuY5Y3olHqbO5MHDM5xmBLEA4lK+SX6Y2r0rRtDrjDkj8lO1+1WNqqI0K0GZOv9zu1mtCNWkCQWl9i4IZ7kiePwx9DM/sYGwp98/I59UJXpnAPAUgUZrzyDIAtq0ImFQnoVhlgmAdQmRDJEgZgWfDrhOyxP27f91n/Cs9G1crOB2ujZFLKOyw== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1728625977; c=relaxed/relaxed; bh=r9deFa3EazRwzr47uk7mbD5Xv91NCzC1Edzbw63mWXM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=KwCz1bYWTVn/2Plveb8rcBdRO3sHOvqgnf+5XZmRylztfJVPchF1fQBRvd7SdOmyUZcZ+YQYkkbQ8a50qfsmgQRSPbckzbwRanRMu3I5NhiJWuW0Iae9Au0fs4JMkLykAtr/cC9yuUViOgV+BNoB62JGojYLE9MvBWKMLKB04Kj2hUWwkJRvncBe+iLVzG/CGQnPMvO/cTIrE0Iw1mgSHyUxd1vRK4x/TyXO/isln2T41q8R5Qrm71ooTkc7PzKtpq/SMfnoe33l6lZu6PcOxYo/g/DbFK+V+z4gNC/n8wKuBuq1n30v5rl4lHu2KJhMSrPiJflJWuG+LgdLaK+6Nw== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=km3d4QU7; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::1033; helo=mail-pj1-x1033.google.com; envelope-from=warp5tw@gmail.com; receiver=lists.ozlabs.org) smtp.mailfrom=gmail.com Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=km3d4QU7; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::1033; helo=mail-pj1-x1033.google.com; envelope-from=warp5tw@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4XPwlB5sBDz3cP5 for ; Fri, 11 Oct 2024 16:52:54 +1100 (AEDT) Received: by mail-pj1-x1033.google.com with SMTP id 98e67ed59e1d1-2e3010478e6so66159a91.1 for ; Thu, 10 Oct 2024 22:52:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728625972; x=1729230772; darn=lists.ozlabs.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=r9deFa3EazRwzr47uk7mbD5Xv91NCzC1Edzbw63mWXM=; b=km3d4QU7c+QHHne0X0es0+ybKeK5fziUBKBFQaBMf+QGTULAL+Md+4fXp1eHxpI+OP wmLhsvR8gmfl1bTpj1/32SYNArJUeJwf6KhSUPlI4u2Ge+zphpUosNuqcX2V5BAHbZiq l7zgXvfZL5Eum1SRQsI8N5OodONMHdK67Rok3fud5Xb8UjcDLAbpHaj8JwF27tO+Wr+N MtsszEgnjzI5kZ3voJqf3vQF4D0IyWZArToOjji+SSj4c0vSq1M2Q72e34nwpyE5wmUM xn39fplhNYPXtVjz9FdA3E9d4EUbzqoLkjqtfwdVN6TszAFigkp6FHmGSuZAiLwXuL3H /hWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728625972; x=1729230772; 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=r9deFa3EazRwzr47uk7mbD5Xv91NCzC1Edzbw63mWXM=; b=CrJDBApmVbNPa2Yx/it8woRBbsV9BsLri7JUgFn4rYrghfrBknXVnV5hhGk2XGFglJ ZE68pNHReHjYkV6ZWO28jTpuupDCdxP2JPtG2bNuo6jFr8fnudZLBwJDCdyF68TLIAG7 Dk8+kK1J+HMF//uvsbS/tfBClpnkkTt+U+2EqiFSHNUtL/GTEW5QQNnYa+7m6U8UbHaY /5pm1TyTjXr08u6GucKVNwn3OrmXQGqeri+Y+0RL6Vbmq++jypAV6gvUk4XmJWtHZFFY DIHRyFxhIhy6PNhxaea8RrfzXdCS3S2BR+TzvlpUCVBJZ698pqdbpiF/Ly7q25diMD6y KVUg== X-Gm-Message-State: AOJu0YxngOyMNfxfdQHG/cfOKyIEz5R6mHy5jNqgDoQE5VxDJ8HTxF15 w/d+ww425NU/RQIr81XvM0OMHcbVtn38OJgdUpTbcJI8tgHX7bI= X-Google-Smtp-Source: AGHT+IE6Zg1xsUZ59crJPToTtwOO5diITSD8mxT0bqWraLXk3hd9NPw1H/G6nZSGxAWWIKv/CRugvQ== X-Received: by 2002:a17:90b:11d5:b0:2e2:d87f:3cc with SMTP id 98e67ed59e1d1-2e2f0b3dc62mr2268483a91.23.1728625971848; Thu, 10 Oct 2024 22:52:51 -0700 (PDT) Received: from localhost (2001-b400-e38a-6880-f424-8486-7476-9f9d.emome-ip6.hinet.net. [2001:b400:e38a:6880:f424:8486:7476:9f9d]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e2d5fc5e35sm2393669a91.54.2024.10.10.22.52.51 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 10 Oct 2024 22:52:51 -0700 (PDT) From: Tyrone Ting X-Google-Original-From: Tyrone Ting To: avifishman70@gmail.com, tmaimon77@gmail.com, tali.perry1@gmail.com, venture@google.com, yuenn@google.com, benjaminfair@google.com, andi.shyti@kernel.org, andriy.shevchenko@linux.intel.com, wsa@kernel.org, rand.sec96@gmail.com, wsa+renesas@sang-engineering.com, warp5tw@gmail.com, tali.perry@nuvoton.com, Avi.Fishman@nuvoton.com, tomer.maimon@nuvoton.com, KWLIU@nuvoton.com, JJLIU0@nuvoton.com, kfting@nuvoton.com Subject: [PATCH v6 3/4] i2c: npcm: use i2c frequency table Date: Fri, 11 Oct 2024 13:52:30 +0800 Message-Id: <20241011055231.9826-4-kfting@nuvoton.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20241011055231.9826-1-kfting@nuvoton.com> References: <20241011055231.9826-1-kfting@nuvoton.com> X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on lists.ozlabs.org X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: openbmc@lists.ozlabs.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" From: Tyrone Ting Modify i2c frequency from table parameters for NPCM i2c modules. Supported frequencies are: 1. 100KHz 2. 400KHz 3. 1MHz The original equations were tested on a variety of chips and base clocks. Since we added devices that use higher frequencies of the module we saw that there is a mismatch between the equation and the actual results on the bus itself, measured on scope. Meanwhile, the equations were not accurate to begin with. They are an approximation of the ideal value. The ideal value is calculated per frequency of the core module. So instead of using the equations we did an optimization per module frequency, verified on a device. Most of the work was focused on the rise time of the SCL and SDA, which depends on external load of the bus and PU. Different PCB designs, or specifically to this case: the number and type of targets on the bus, impact the required values for the timing registers. Users can recalculate the numbers for each bus and get an even better optimization, but our users chose not to. We manually picked values per frequency that match the entire valid range of targets (from 1 to max number). Then we check against the AMR described in SMB spec and make sure that none of the values is exceeding. This process was led by the chip architect and included a lot of testing. Signed-off-by: Tyrone Ting Reviewed-by: Tali Perry --- drivers/i2c/busses/i2c-npcm7xx.c | 374 ++++++++++++++++++++++++------- 1 file changed, 288 insertions(+), 86 deletions(-) diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm7xx.c index 349492f114e7..fcecb098298f 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] = { #define I2C_FREQ_MIN_HZ 10000 #define I2C_FREQ_MAX_HZ I2C_MAX_FAST_MODE_PLUS_FREQ +struct smb_timing_t { + u32 core_clk; + u8 hldt; + u8 dbcnt; + u16 sclfrq; + u8 scllt; + u8 sclht; + bool fast_mode; +}; + +static struct smb_timing_t smb_timing_100khz[] = { + { + .core_clk = 100000000, .hldt = 0x2A, .dbcnt = 0x4, + .sclfrq = 0xFB, .scllt = 0x0, .sclht = 0x0, + .fast_mode = false, + }, + { + .core_clk = 62500000, .hldt = 0x2A, .dbcnt = 0x1, + .sclfrq = 0x9D, .scllt = 0x0, .sclht = 0x0, + .fast_mode = false, + }, + { + .core_clk = 50000000, .hldt = 0x2A, .dbcnt = 0x1, + .sclfrq = 0x7E, .scllt = 0x0, .sclht = 0x0, + .fast_mode = false, + }, + { + .core_clk = 48000000, .hldt = 0x2A, .dbcnt = 0x1, + .sclfrq = 0x79, .scllt = 0x0, .sclht = 0x0, + .fast_mode = false, + }, + { + .core_clk = 40000000, .hldt = 0x2A, .dbcnt = 0x1, + .sclfrq = 0x65, .scllt = 0x0, .sclht = 0x0, + .fast_mode = false, + }, + { + .core_clk = 30000000, .hldt = 0x2A, .dbcnt = 0x1, + .sclfrq = 0x4C, .scllt = 0x0, .sclht = 0x0, + .fast_mode = false, + }, + { + .core_clk = 29000000, .hldt = 0x2A, .dbcnt = 0x1, + .sclfrq = 0x49, .scllt = 0x0, .sclht = 0x0, + .fast_mode = false, + }, + { + .core_clk = 26000000, .hldt = 0x2A, .dbcnt = 0x1, + .sclfrq = 0x42, .scllt = 0x0, .sclht = 0x0, + .fast_mode = false, + }, + { + .core_clk = 25000000, .hldt = 0x2A, .dbcnt = 0x1, + .sclfrq = 0x3F, .scllt = 0x0, .sclht = 0x0, + .fast_mode = false, + }, + { + .core_clk = 24000000, .hldt = 0x2A, .dbcnt = 0x1, + .sclfrq = 0x3D, .scllt = 0x0, .sclht = 0x0, + .fast_mode = false, + }, + { + .core_clk = 20000000, .hldt = 0x2A, .dbcnt = 0x1, + .sclfrq = 0x33, .scllt = 0x0, .sclht = 0x0, + .fast_mode = false, + }, + { + .core_clk = 16180000, .hldt = 0x2A, .dbcnt = 0x1, + .sclfrq = 0x29, .scllt = 0x0, .sclht = 0x0, + .fast_mode = false, + }, + { + .core_clk = 15000000, .hldt = 0x23, .dbcnt = 0x1, + .sclfrq = 0x26, .scllt = 0x0, .sclht = 0x0, + .fast_mode = false, + }, + { + .core_clk = 13000000, .hldt = 0x1D, .dbcnt = 0x1, + .sclfrq = 0x21, .scllt = 0x0, .sclht = 0x0, + .fast_mode = false, + }, + { + .core_clk = 12000000, .hldt = 0x1B, .dbcnt = 0x1, + .sclfrq = 0x1F, .scllt = 0x0, .sclht = 0x0, + .fast_mode = false, + }, + { + .core_clk = 10000000, .hldt = 0x18, .dbcnt = 0x1, + .sclfrq = 0x1A, .scllt = 0x0, .sclht = 0x0, + .fast_mode = false, + }, + { + .core_clk = 9000000, .hldt = 0x16, .dbcnt = 0x1, + .sclfrq = 0x17, .scllt = 0x0, .sclht = 0x0, + .fast_mode = false, + }, + { + .core_clk = 8090000, .hldt = 0x14, .dbcnt = 0x1, + .sclfrq = 0x15, .scllt = 0x0, .sclht = 0x0, + .fast_mode = false, + }, + { + .core_clk = 7500000, .hldt = 0x7, .dbcnt = 0x1, + .sclfrq = 0x13, .scllt = 0x0, .sclht = 0x0, + .fast_mode = false, + }, + { + .core_clk = 6500000, .hldt = 0xE, .dbcnt = 0x1, + .sclfrq = 0x11, .scllt = 0x0, .sclht = 0x0, + .fast_mode = false, + }, + { + .core_clk = 4000000, .hldt = 0x9, .dbcnt = 0x1, + .sclfrq = 0xB, .scllt = 0x0, .sclht = 0x0, + .fast_mode = false, + }, +}; + +static struct smb_timing_t smb_timing_400khz[] = { + { + .core_clk = 100000000, .hldt = 0x2A, .dbcnt = 0x3, + .sclfrq = 0x0, .scllt = 0x47, .sclht = 0x35, + .fast_mode = true, + }, + { + .core_clk = 62500000, .hldt = 0x2A, .dbcnt = 0x2, + .sclfrq = 0x0, .scllt = 0x2C, .sclht = 0x22, + .fast_mode = true, + }, + { + .core_clk = 50000000, .hldt = 0x21, .dbcnt = 0x1, + .sclfrq = 0x0, .scllt = 0x24, .sclht = 0x1B, + .fast_mode = true, + }, + { + .core_clk = 48000000, .hldt = 0x1E, .dbcnt = 0x1, + .sclfrq = 0x0, .scllt = 0x24, .sclht = 0x19, + .fast_mode = true, + }, + { + .core_clk = 40000000, .hldt = 0x1B, .dbcnt = 0x1, + .sclfrq = 0x0, .scllt = 0x1E, .sclht = 0x14, + .fast_mode = true, + }, + { + .core_clk = 33000000, .hldt = 0x15, .dbcnt = 0x1, + .sclfrq = 0x0, .scllt = 0x19, .sclht = 0x11, + .fast_mode = true, + }, + { + .core_clk = 30000000, .hldt = 0x15, .dbcnt = 0x1, + .sclfrq = 0x0, .scllt = 0x19, .sclht = 0xD, + .fast_mode = true, + }, + { + .core_clk = 29000000, .hldt = 0x11, .dbcnt = 0x1, + .sclfrq = 0x0, .scllt = 0x15, .sclht = 0x10, + .fast_mode = true, + }, + { + .core_clk = 26000000, .hldt = 0x10, .dbcnt = 0x1, + .sclfrq = 0x0, .scllt = 0x13, .sclht = 0xE, + .fast_mode = true, + }, + { + .core_clk = 25000000, .hldt = 0xF, .dbcnt = 0x1, + .sclfrq = 0x0, .scllt = 0x13, .sclht = 0xD, + .fast_mode = true, + }, + { + .core_clk = 24000000, .hldt = 0xD, .dbcnt = 0x1, + .sclfrq = 0x0, .scllt = 0x12, .sclht = 0xD, + .fast_mode = true, + }, + { + .core_clk = 20000000, .hldt = 0xB, .dbcnt = 0x1, + .sclfrq = 0x0, .scllt = 0xF, .sclht = 0xA, + .fast_mode = true, + }, + { + .core_clk = 16180000, .hldt = 0xA, .dbcnt = 0x1, + .sclfrq = 0x0, .scllt = 0xC, .sclht = 0x9, + .fast_mode = true, + }, + { + .core_clk = 15000000, .hldt = 0x9, .dbcnt = 0x1, + .sclfrq = 0x0, .scllt = 0xB, .sclht = 0x8, + .fast_mode = true, + }, + { + .core_clk = 13000000, .hldt = 0x7, .dbcnt = 0x1, + .sclfrq = 0x0, .scllt = 0xA, .sclht = 0x7, + .fast_mode = true, + }, + { + .core_clk = 12000000, .hldt = 0x7, .dbcnt = 0x1, + .sclfrq = 0x0, .scllt = 0xA, .sclht = 0x6, + .fast_mode = true, + }, + { + .core_clk = 10000000, .hldt = 0x6, .dbcnt = 0x1, + .sclfrq = 0x0, .scllt = 0x8, .sclht = 0x5, + .fast_mode = true, + }, +}; + +static struct smb_timing_t smb_timing_1000khz[] = { + { + .core_clk = 100000000, .hldt = 0x15, .dbcnt = 0x4, + .sclfrq = 0x0, .scllt = 0x1C, .sclht = 0x15, + .fast_mode = true, + }, + { + .core_clk = 62500000, .hldt = 0xF, .dbcnt = 0x3, + .sclfrq = 0x0, .scllt = 0x11, .sclht = 0xE, + .fast_mode = true, + }, + { + .core_clk = 50000000, .hldt = 0xA, .dbcnt = 0x2, + .sclfrq = 0x0, .scllt = 0xE, .sclht = 0xB, + .fast_mode = true, + }, + { + .core_clk = 48000000, .hldt = 0x9, .dbcnt = 0x2, + .sclfrq = 0x0, .scllt = 0xD, .sclht = 0xB, + .fast_mode = true, + }, + { + .core_clk = 41000000, .hldt = 0x9, .dbcnt = 0x2, + .sclfrq = 0x0, .scllt = 0xC, .sclht = 0x9, + .fast_mode = true, + }, + { + .core_clk = 40000000, .hldt = 0x8, .dbcnt = 0x2, + .sclfrq = 0x0, .scllt = 0xB, .sclht = 0x9, + .fast_mode = true, + }, + { + .core_clk = 33000000, .hldt = 0x7, .dbcnt = 0x1, + .sclfrq = 0x0, .scllt = 0xA, .sclht = 0x7, + .fast_mode = true, + }, + { + .core_clk = 25000000, .hldt = 0x4, .dbcnt = 0x1, + .sclfrq = 0x0, .scllt = 0x7, .sclht = 0x6, + .fast_mode = true, + }, + { + .core_clk = 24000000, .hldt = 0x7, .dbcnt = 0x1, + .sclfrq = 0x0, .scllt = 0x8, .sclht = 0x5, + .fast_mode = true, + }, + { + .core_clk = 20000000, .hldt = 0x4, .dbcnt = 0x1, + .sclfrq = 0x0, .scllt = 0x6, .sclht = 0x4, + .fast_mode = true, + }, +}; + struct npcm_i2c_data { u8 fifo_size; u32 segctl_init_val; @@ -1805,102 +2064,45 @@ static void npcm_i2c_recovery_init(struct i2c_adapter *_adap) */ static int npcm_i2c_init_clk(struct npcm_i2c *bus, u32 bus_freq_hz) { - u32 k1 = 0; - u32 k2 = 0; - u8 dbnct = 0; - u32 sclfrq = 0; - u8 hldt = 7; + struct smb_timing_t *smb_timing; + u8 scl_table_cnt = 0, table_size = 0; u8 fast_mode = 0; - u32 src_clk_khz; - u32 bus_freq_khz; - src_clk_khz = bus->apb_clk / 1000; - bus_freq_khz = bus_freq_hz / 1000; bus->bus_freq = bus_freq_hz; - /* 100KHz and below: */ - if (bus_freq_hz <= I2C_MAX_STANDARD_MODE_FREQ) { - sclfrq = src_clk_khz / (bus_freq_khz * 4); - - if (sclfrq < SCLFRQ_MIN || sclfrq > SCLFRQ_MAX) - return -EDOM; - - if (src_clk_khz >= 40000) - hldt = 17; - else if (src_clk_khz >= 12500) - hldt = 15; - else - hldt = 7; - } - - /* 400KHz: */ - else if (bus_freq_hz <= I2C_MAX_FAST_MODE_FREQ) { - sclfrq = 0; + switch (bus_freq_hz) { + case I2C_MAX_STANDARD_MODE_FREQ: + smb_timing = smb_timing_100khz; + table_size = ARRAY_SIZE(smb_timing_100khz); + break; + case I2C_MAX_FAST_MODE_FREQ: + smb_timing = smb_timing_400khz; + table_size = ARRAY_SIZE(smb_timing_400khz); fast_mode = I2CCTL3_400K_MODE; - - if (src_clk_khz < 7500) - /* 400KHZ cannot be supported for core clock < 7.5MHz */ - return -EDOM; - - else if (src_clk_khz >= 50000) { - k1 = 80; - k2 = 48; - hldt = 12; - dbnct = 7; - } - - /* Master or Slave with frequency > 25MHz */ - else if (src_clk_khz > 25000) { - hldt = clk_coef(src_clk_khz, 300) + 7; - k1 = clk_coef(src_clk_khz, 1600); - k2 = clk_coef(src_clk_khz, 900); - } - } - - /* 1MHz: */ - else if (bus_freq_hz <= I2C_MAX_FAST_MODE_PLUS_FREQ) { - sclfrq = 0; + break; + case I2C_MAX_FAST_MODE_PLUS_FREQ: + smb_timing = smb_timing_1000khz; + table_size = ARRAY_SIZE(smb_timing_1000khz); fast_mode = I2CCTL3_400K_MODE; - - /* 1MHZ cannot be supported for core clock < 24 MHz */ - if (src_clk_khz < 24000) - return -EDOM; - - k1 = clk_coef(src_clk_khz, 620); - k2 = clk_coef(src_clk_khz, 380); - - /* Core clk > 40 MHz */ - if (src_clk_khz > 40000) { - /* - * Set HLDT: - * SDA hold time: (HLDT-7) * T(CLK) >= 120 - * HLDT = 120/T(CLK) + 7 = 120 * FREQ(CLK) + 7 - */ - hldt = clk_coef(src_clk_khz, 120) + 7; - } else { - hldt = 7; - dbnct = 2; - } + break; + default: + return -EINVAL; } - /* Frequency larger than 1 MHz is not supported */ - else - return -EINVAL; + for (scl_table_cnt = 0; scl_table_cnt < table_size; scl_table_cnt++) + if (bus->apb_clk >= smb_timing[scl_table_cnt].core_clk) + break; - if (bus_freq_hz >= I2C_MAX_FAST_MODE_FREQ) { - k1 = round_up(k1, 2); - k2 = round_up(k2 + 1, 2); - if (k1 < SCLFRQ_MIN || k1 > SCLFRQ_MAX || - k2 < SCLFRQ_MIN || k2 > SCLFRQ_MAX) - return -EDOM; - } + if (scl_table_cnt == table_size) + return -EINVAL; /* write sclfrq value. bits [6:0] are in I2CCTL2 reg */ - iowrite8(FIELD_PREP(I2CCTL2_SCLFRQ6_0, sclfrq & 0x7F), + iowrite8(FIELD_PREP(I2CCTL2_SCLFRQ6_0, smb_timing[scl_table_cnt].sclfrq & 0x7F), bus->reg + NPCM_I2CCTL2); /* bits [8:7] are in I2CCTL3 reg */ - iowrite8(fast_mode | FIELD_PREP(I2CCTL3_SCLFRQ8_7, (sclfrq >> 7) & 0x3), + iowrite8(FIELD_PREP(I2CCTL3_SCLFRQ8_7, (smb_timing[scl_table_cnt].sclfrq >> 7) & 0x3) | + fast_mode, bus->reg + NPCM_I2CCTL3); /* 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 = 2 * SCLLT7-0 -> Low Time = k1 / 2 * k2 = 2 * SCLLT7-0 -> High Time = k2 / 2 */ - iowrite8(k1 / 2, bus->reg + NPCM_I2CSCLLT); - iowrite8(k2 / 2, bus->reg + NPCM_I2CSCLHT); + iowrite8(smb_timing[scl_table_cnt].scllt, bus->reg + NPCM_I2CSCLLT); + iowrite8(smb_timing[scl_table_cnt].sclht, bus->reg + NPCM_I2CSCLHT); - iowrite8(dbnct, bus->reg + NPCM_I2CCTL5); + iowrite8(smb_timing[scl_table_cnt].dbcnt, bus->reg + NPCM_I2CCTL5); } - iowrite8(hldt, bus->reg + NPCM_I2CCTL4); + iowrite8(smb_timing[scl_table_cnt].hldt, bus->reg + NPCM_I2CCTL4); /* Return to Bank 1, and stay there by default: */ npcm_i2c_select_bank(bus, I2C_BANK_1); From patchwork Fri Oct 11 05:52:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tyrone Ting X-Patchwork-Id: 1995896 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Y1F5p5rk; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XPwm813tJz1xsc for ; Fri, 11 Oct 2024 16:53:44 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4XPwlN5dDTz3g4j for ; Fri, 11 Oct 2024 16:53:04 +1100 (AEDT) X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::62d" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1728625980; cv=none; b=fni2lxY76A2jHGAkB7GBTHmTtWDgw7agSFk3RfXEbWoG386jevJpGomHr1TWYB6xIihxVKJwcZ2Jnyei2ZfmsYxmEzDA3QgA6NkKMpHHYmLEkGG86Q9EA4ypo62bJWU/ADpxhbimau4NQPwviBb5mma0A7uWwm5H69CmeAASLgFxC5G6f6UjyOR6HhiDzmYRv1ul5prY2IN8udCokE+ZySEkLftBb8pm/u+Ezws0pWn3/9X60S0SI1hAeD4w8Y7CJXg6alj7pUAD3tyDd3EZejIp68vStEyp2Z4IgLm0jQHzeLkFbavxrzhStIneGhP701PlCbD9/ijsf1TO/kC7SQ== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1728625980; c=relaxed/relaxed; bh=an4kJkObmODiz76Q4UVu1DA+oIFDSnR7hQ7Vqq3zxdA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=SY9eNt9FnZfKiX6Inbi/KO0dYt9qCmOJl4YjjS9dciTE7IFQuu7rvJ/epK2BMFV3OPrCkrlbtobCHf/1gHD7iLCcrPwlGCNmcBlxAskH16lOAlTg8tUQv40NnmPxIF6lxgZXhI2UlHi3M6rLyATxLO6d2Y5B2vgSQJoSyX5gyQxYOUGEFXo9rH8J4Zm2XcAfozUnvojFLtJy5NMUKfH4mEQRSyFbuQcGQ1w+8h0Yx30rROAUj6ipamQB/DluxNAXcSF8joiSW0WfdJzum4KXJK8+uTQluD8gDeRrPhgq33ERnSAc2JftbQsgx74THo3d88gVMo9b+8DMg5xPh/EQ0A== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Y1F5p5rk; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::62d; helo=mail-pl1-x62d.google.com; envelope-from=warp5tw@gmail.com; receiver=lists.ozlabs.org) smtp.mailfrom=gmail.com Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Y1F5p5rk; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::62d; helo=mail-pl1-x62d.google.com; envelope-from=warp5tw@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4XPwlG5ymJz3fpf for ; Fri, 11 Oct 2024 16:52:58 +1100 (AEDT) Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-20bc506347dso13597015ad.0 for ; Thu, 10 Oct 2024 22:52:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728625976; x=1729230776; darn=lists.ozlabs.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=an4kJkObmODiz76Q4UVu1DA+oIFDSnR7hQ7Vqq3zxdA=; b=Y1F5p5rkhPNCHAAyde4OfOwV/sej6cb+00kWARzLNj6Tjs+T0/QBIAiVKn8qGGSKsT gjEcJuv4yizbIuveiDYJoLxmDZe5GQA+Pp9X3HRJOJpDLr7NWmMAmyuEQu17Awt9Troa bKtgWJsaAd7Ki5BoQeYBD2h4ubBaq+K/T48rQpehnszxAv/lPhIoJLR0AqxDXFOo2MIB JapH/cH/IW9Bd3nbvf7BLGqohhZyflBAJ2gjzmLaVDv7EfMu/eE21eKpFNl+drEk1rPG S0CoHVCi3nFbT9dsqGF0ZRTwxIqdD178hXaRAUwRkgxSt7OORAm+lpIwB658dX+sqBPE Y9TA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728625976; x=1729230776; 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=an4kJkObmODiz76Q4UVu1DA+oIFDSnR7hQ7Vqq3zxdA=; b=DEpb0TG/7kq87bLxIWx9bAc4ikOJ+lvDpHflONV5OZqj0QqGiLFNqzLgKuBHmoqScU Ymr+CYpmKRzxiYwqQzAzZKv4XYRpJGPM5P8DohoBcHbUqRFtiK+wqNkxOE8g7jrj4RxM V/ggxnmr5pFmscfQ26cnwf+AsrLiCwbk7gFpiqDWAtWfGc3bWOkvlK/vJcCUgPf5zxoM q7/wb0zOea7cyjEkUUjPZwgt+0YHERu8D1pruodcj39kGNKkXrmPq0wgd9JQ4xUWyf+j P+G5E8mzGvs7GBSsfXP4mX6VP1rZBYx8pGkSuQlz1Joc3DnxxonXKyLHg+xQPSA+FvCN QVBQ== X-Gm-Message-State: AOJu0Yx/LVt9EyQO2Mh5d12CgTqPqwxNAUWRgt1jlLH5DwXCyt7mS9tH 0Zzn/MJ1+04klR6SxCAdgco4Rt64UgdBhPbCLIH3xlncSwVgER0= X-Google-Smtp-Source: AGHT+IFtD2PAQaGCcS0aatXtbrM9Qrv/jGG0koL0ZE3kSwlOkv9I/91XaMLJiU2fAyxNUYLV22uZCw== X-Received: by 2002:a17:903:2b07:b0:207:13a3:a896 with SMTP id d9443c01a7336-20ca1466468mr20257185ad.23.1728625975936; Thu, 10 Oct 2024 22:52:55 -0700 (PDT) Received: from localhost (2001-b400-e38a-6880-f424-8486-7476-9f9d.emome-ip6.hinet.net. [2001:b400:e38a:6880:f424:8486:7476:9f9d]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20c8bc13394sm17764775ad.108.2024.10.10.22.52.55 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 10 Oct 2024 22:52:55 -0700 (PDT) From: Tyrone Ting X-Google-Original-From: Tyrone Ting To: avifishman70@gmail.com, tmaimon77@gmail.com, tali.perry1@gmail.com, venture@google.com, yuenn@google.com, benjaminfair@google.com, andi.shyti@kernel.org, andriy.shevchenko@linux.intel.com, wsa@kernel.org, rand.sec96@gmail.com, wsa+renesas@sang-engineering.com, warp5tw@gmail.com, tali.perry@nuvoton.com, Avi.Fishman@nuvoton.com, tomer.maimon@nuvoton.com, KWLIU@nuvoton.com, JJLIU0@nuvoton.com, kfting@nuvoton.com Subject: [PATCH v6 4/4] i2c: npcm: Enable slave in eob interrupt Date: Fri, 11 Oct 2024 13:52:31 +0800 Message-Id: <20241011055231.9826-5-kfting@nuvoton.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20241011055231.9826-1-kfting@nuvoton.com> References: <20241011055231.9826-1-kfting@nuvoton.com> X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on lists.ozlabs.org X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: openbmc@lists.ozlabs.org, Charles Boyer , Vivekanand Veeracholan , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" From: Charles Boyer Nuvoton slave enable was in user space API call master_xfer, so it is subject to delays from the OS scheduler. If the BMC is not enabled for slave mode in time for master to send response, then it will NAK the address match. Then the PLDM request timeout occurs. If the slave enable is moved to the EOB interrupt service routine, then the BMC can be ready in slave mode by the time it needs to receive a response. Signed-off-by: Charles Boyer Signed-off-by: Vivekanand Veeracholan Signed-off-by: Tyrone Ting Reviewed-by: Tali Perry --- drivers/i2c/busses/i2c-npcm7xx.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm7xx.c index fcecb098298f..55348308b992 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_i2c *bus) (FIELD_GET(NPCM_I2CCST3_EO_BUSY, ioread8(bus->reg + NPCM_I2CCST3)))) { npcm_i2c_irq_handle_eob(bus); +#if IS_ENABLED(CONFIG_I2C_SLAVE) + /* reenable slave if it was enabled */ + if (bus->slave) + iowrite8((bus->slave->addr & 0x7F) | NPCM_I2CADDR_SAEN, + bus->reg + NPCM_I2CADDR1); +#endif return 0; }