Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp632951pxb; Mon, 7 Feb 2022 21:33:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJzxwiXsy7tSC6wJI4MgYMWndN09ydJDamtflaC+vHCPpKamSipM2x+DHKNGZ7YlRHRAhTQ9 X-Received: by 2002:a63:4605:: with SMTP id t5mr1180484pga.41.1644298418238; Mon, 07 Feb 2022 21:33:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644298418; cv=none; d=google.com; s=arc-20160816; b=Gclk/oy61f0MNcwfkwRtqoUMxtXE+3nhhKJz2Cd1M8kQYSiS0Ht6dtGls7huKrBQXy yecUerQH97fZ1NaeJzS7rGN/dqbqkVWjW7DXin7fDr2tUpF7gVJrXsGnTqVEOLPLfaZ/ TU4XIReKUC/J0my11frAuexaCI0kE5fQaQirs5d0lgy1umJ98SW4x+O0TM0REe0cARXd yb199scqtXHfwEif2/ntJ6rtfRI4/j63FY2oasx78YV+9C2rEd8P1HtjE33jo+RX109c 0WYxg2GFxnEEc7XRVsQBDolJCFTfjMx20uE4qO29Z1VNPukgNKWf726V7B0PPWmSDI03 b5tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=0TH+KvK70vqF4R3xRGxJlT+5PeKHKYQ4Msc0Pdr7t5o=; b=1KaotsK1bMvE7v1LYc4vN3bTLn+pPyt6NDnErJAOVkB4vaK9oMhKI5Jc8aTMQcwy41 B+xIjYKxd8YSSLsRe0+LQ8K/VmNvosM0BsghS0hh6W2VhVfggcUgiwu6/bWeDzQ4BMKB IoXyJ7a1iI5gykuQtNqgKdvZTF0bosVFgjgQwtEguTZ65+J1k4D8VvK3XheFmIByQBP1 UKaLkVs6NqhLeFOGwJ0/qFGhyIt8+V2lJnkkGQDY0wfaJIcbe1eUsWxWA2e7UXtcAsdu kM/WA77c51dvwdfrUqCZ6j3XkBm2oVYdPFqecaD/ry+JgKnlmEtESMfQ2ieDG2t06rII vu+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=iGQGr9yT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e126si12007620pgc.578.2022.02.07.21.33.25; Mon, 07 Feb 2022 21:33:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=iGQGr9yT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354204AbiBGGiI (ORCPT + 99 others); Mon, 7 Feb 2022 01:38:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241646AbiBGGdx (ORCPT ); Mon, 7 Feb 2022 01:33:53 -0500 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C400DC043187; Sun, 6 Feb 2022 22:33:52 -0800 (PST) Received: by mail-pl1-x632.google.com with SMTP id w1so833614plb.6; Sun, 06 Feb 2022 22:33:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=0TH+KvK70vqF4R3xRGxJlT+5PeKHKYQ4Msc0Pdr7t5o=; b=iGQGr9yTud19lEw7Dzfe5qe038Er/9pvs3h8C7e0pWiTdPaUGN2IEVMolqlvz99+Y6 tK7qS1nMdqUQyNLrVdRrMnFqel0S3jLhmpVpUHBBb2dR05fkqnzBU/aM7w+9WR1tS7e0 KGMtPoortuyKjv+zYfywy21NoWucdf3Y8BGMoATM0kauUin7LrFTjqllS4lAPTV47Bx+ obA3zAzgjlvjQyZRkzO4aHpgLM3TFrdNyOnwxD/Z1nETDY7UzSvEd8NRWM5VCefEHaOE Y+8ls8E5ujDrKHLlaewlDheGpptcJ+S0fsF2mSvkfFp6VlGHMYu/A8ONI8iAjJzWoVAx kPWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=0TH+KvK70vqF4R3xRGxJlT+5PeKHKYQ4Msc0Pdr7t5o=; b=ATaTBTPjBTUwoGMa60wFHlcizJl+qYmaRH9ANc77ZtB+4KVm896Fy62+Ad+WV3udnK naU9KBcDmQVaaQRGIp09rmgLBOBMm6obUqHYFSghcTcd38TeTzmTXpWRFsdjdAFLrJeE C5un2J2Gf/hVHvkE5jLZi5atGlWWnK4kZ9Nw3VNan/iNEFM8HEVsupN7YHX2qTeI5khR sU9RpXh+DbEugnHjddI7c+Uy63DG8PPg/nTFQ1oy0cBrDxnUEoyvyOizhnsi0xWKqVX0 Z7LEuXH8/GSLQsI0q8YhYzHgaKJJpZgiXQpfapj8Pt6WdgtNhLuGxxgjRHbQGuas9NAX qTXQ== X-Gm-Message-State: AOAM531LM1a0BChwDIdFQlMhwa5pkCOvcLy/tCaQ3STrf785Ac6jasoK ZMRpTz9vwSbCDAn6V9k0EA== X-Received: by 2002:a17:903:404b:: with SMTP id n11mr14679060pla.129.1644215632267; Sun, 06 Feb 2022 22:33:52 -0800 (PST) Received: from localhost ([2401:e180:8894:9737:7848:1ec7:b697:7d50]) by smtp.gmail.com with ESMTPSA id i12sm914768pjw.25.2022.02.06.22.33.51 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 06 Feb 2022 22:33:51 -0800 (PST) From: Tyrone Ting To: avifishman70@gmail.com, tmaimon77@gmail.com, tali.perry1@gmail.com, venture@google.com, yuenn@google.com, benjaminfair@google.com, robh+dt@kernel.org, krzysztof.kozlowski@canonical.com, semen.protsenko@linaro.org, yangyicong@hisilicon.com, wsa@kernel.org, jie.deng@intel.com, sven@svenpeter.dev, bence98@sch.bme.hu, lukas.bulwahn@gmail.com, arnd@arndb.de, olof@lixom.net, andriy.shevchenko@linux.intel.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, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 2/6] i2c: npcm: Fix timeout calculation Date: Mon, 7 Feb 2022 14:33:34 +0800 Message-Id: <20220207063338.6570-3-warp5tw@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220207063338.6570-1-warp5tw@gmail.com> References: <20220207063338.6570-1-warp5tw@gmail.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tali Perry Use adap.timeout for timeout calculation instead of hard-coded value of 35ms. Use syscon to access gcr, instead of "compatible". Fixes: 56a1485b102e ("i2c: npcm7xx: Add Nuvoton NPCM I2C controller driver") Signed-off-by: Tali Perry Signed-off-by: Tyrone Ting --- drivers/i2c/busses/i2c-npcm7xx.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm7xx.c index 2ad166355ec9..ddeee6f53621 100644 --- a/drivers/i2c/busses/i2c-npcm7xx.c +++ b/drivers/i2c/busses/i2c-npcm7xx.c @@ -2047,7 +2047,7 @@ static int npcm_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, u16 nwrite, nread; u8 *write_data, *read_data; u8 slave_addr; - int timeout; + unsigned long timeout; int ret = 0; bool read_block = false; bool read_PEC = false; @@ -2099,13 +2099,13 @@ static int npcm_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, * 9: bits per transaction (including the ack/nack) */ timeout_usec = (2 * 9 * USEC_PER_SEC / bus->bus_freq) * (2 + nread + nwrite); - timeout = max(msecs_to_jiffies(35), usecs_to_jiffies(timeout_usec)); + timeout = max(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 + msecs_to_jiffies(DEFAULT_STALL_COUNT) + 1; + time_left = jiffies + timeout + 1; do { /* * we must clear slave address immediately when the bus is not @@ -2131,7 +2131,7 @@ 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->dest_addr = slave_addr << 1; bus->msgs = msgs; bus->msgs_num = num; bus->cmd_err = 0; @@ -2233,9 +2233,9 @@ static int npcm_i2c_probe_bus(struct platform_device *pdev) struct i2c_adapter *adap; struct clk *i2c_clk; static struct regmap *gcr_regmap; - static struct regmap *clk_regmap; int irq; int ret; + struct device_node *np = pdev->dev.of_node; bus = devm_kzalloc(&pdev->dev, sizeof(*bus), GFP_KERNEL); if (!bus) @@ -2250,15 +2250,11 @@ static int npcm_i2c_probe_bus(struct platform_device *pdev) return PTR_ERR(i2c_clk); bus->apb_clk = clk_get_rate(i2c_clk); - gcr_regmap = syscon_regmap_lookup_by_compatible("nuvoton,npcm750-gcr"); + gcr_regmap = syscon_regmap_lookup_by_phandle(np, "syscon"); if (IS_ERR(gcr_regmap)) return PTR_ERR(gcr_regmap); regmap_write(gcr_regmap, NPCM_I2CSEGCTL, NPCM_I2CSEGCTL_INIT_VAL); - clk_regmap = syscon_regmap_lookup_by_compatible("nuvoton,npcm750-clk"); - if (IS_ERR(clk_regmap)) - return PTR_ERR(clk_regmap); - bus->reg = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(bus->reg)) return PTR_ERR(bus->reg); @@ -2269,7 +2265,7 @@ static int npcm_i2c_probe_bus(struct platform_device *pdev) adap = &bus->adap; adap->owner = THIS_MODULE; adap->retries = 3; - adap->timeout = HZ; + adap->timeout = msecs_to_jiffies(35); adap->algo = &npcm_i2c_algo; adap->quirks = &npcm_i2c_quirks; adap->algo_data = bus; -- 2.17.1