Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2236213pxk; Sat, 5 Sep 2020 13:50:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxXWTtu7ol5s0Tr5YkaFHbfszYpzrLwMsHd52K8OMaBgxAh7YhNjc38NnLVnbKZcnFKTro9 X-Received: by 2002:a05:6402:17f6:: with SMTP id t22mr822234edy.374.1599339057868; Sat, 05 Sep 2020 13:50:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599339057; cv=none; d=google.com; s=arc-20160816; b=AH7ud6EJfKYLOuqxRm4a3OCjjI2GV/1YiEhUtiJJs9JtiDQkL1gxIbG6HUqh5bspvo Jn2xFGoZWwrLlyKNIEdP/3Yv4vCkWDWNIJAuIHvGTq4uWQouKdU8HreB0k4kocl7VM+l hmD++Ihus0sA6vvyZ0hA4VvZ8UUdlfhlGlXZVYySHaQUUoCG8lT089ZEpmobR/TOaGSH SthV1CXJUNUc/QrMfVVgYfjbBwi2Tw1mdvOzTLhyHIM2hDYnqBD6JOZOEuYviyFBM1qz J6yGHsR/nBQahnwNZ7psAkYi6boSDp4BW3leLAkmo/02Rws99PNq5dgGoTjuBFRVmQcA vlNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=QMj/s4K97H8grdOpygKSw68Mm/Tx/Oq6EnRbophVBOI=; b=Qk43/Twx+at4mv+bt5Z9DU4x7Oz05UN/Bj9M5jFRwCnZd6z5GhqhtIRupjyU+48dk5 VFLSO1cpM6Ud+aTso4OzR7OEq5No1bRTNYUchAcBajwat4PTtXoOcPSjwq4N9BwhyPgt G9XSExV5VA23ZdxD/Mxl8XJfw0KsBRDv3vElGqc71XB9TVS72y+GDaD+QElAVgcSL/o0 kNtEiokdnU45/LBcN9rEOl5olwT+3ADVzErRmRXx2W2XUJ8poUHGm1J0uxplF+cTtcCj qIMGHOlwkRbdGOWNU04clF0AvWx5U53ybSxh+pGxY10HCJOBEHkQlVMm4bHe4OLjU9Hd EgJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=EIthBN+1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v21si7580938ejg.482.2020.09.05.13.50.35; Sat, 05 Sep 2020 13:50:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=EIthBN+1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1729041AbgIEUq7 (ORCPT + 99 others); Sat, 5 Sep 2020 16:46:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728665AbgIEUmd (ORCPT ); Sat, 5 Sep 2020 16:42:33 -0400 Received: from mail-lf1-x142.google.com (mail-lf1-x142.google.com [IPv6:2a00:1450:4864:20::142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97271C061246; Sat, 5 Sep 2020 13:42:30 -0700 (PDT) Received: by mail-lf1-x142.google.com with SMTP id w11so5627810lfn.2; Sat, 05 Sep 2020 13:42:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QMj/s4K97H8grdOpygKSw68Mm/Tx/Oq6EnRbophVBOI=; b=EIthBN+16r3Z0wTV7VPAVeJH3TqEeOEPRvQa83kBY0blFCdtkp2sMwDsY31rWX/3In p99eBv+4Yb2yNxkf2NboXT1ysxEYgX6x57F5kmkQBhi+aIqeYMtgxFGEdiF+oHq1X8qS JOI99SfzF2vQPM2faY8X2fzOKo1gjB9JwZ/ZPXXLiLRye2yUjoL/iH+qcDHQVuC0V/W8 Q2rgtWvQgrs/nh/BmhQVJRIEU9Rn3tplWa1P7lmSg4C/ch6J6pdPO13+Su4nOJecLgXi 2TEdIv3BdPKp77pqbAzqXkUe5F582osI3Oaq6ZrDw5S+6PmxgdhzglgYskSA14sHgMj+ oULQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QMj/s4K97H8grdOpygKSw68Mm/Tx/Oq6EnRbophVBOI=; b=TISwiSwtC013635m1G+NtZFP3hc9mFx5a6Nqyi/s6PldGqWdM1BBWks0BGqxUAEgpS hnfTf8EMMbtzXWzyR05Wybz7Ld4U9OAOLqqUhnNpOlbVXghzs/k1ItCH+4OiMchoxBj6 BFADMnEoPkkrh1umrKc3dzma0RCc221galz0YlXsIknOAS35x7SyNwPBRDw1HuNBLewP Mp810YU9R29IjY8EWGOeFoiO25DFSfhNsTFCxYPg2Jn6J+XlH3NkwsaNTL+22AXT7GnT 2fmcWZ9NeCvaB9VTxjKJRCtIgws+snjCGO6fnkt6cGCddzlOZWfm24DFOMnNhpxlIhxf IEPQ== X-Gm-Message-State: AOAM532sJFf/uv8taDwPkTqUfqRWjDcNeyPTap/rPyPMQqcuks2L39+g nI2Z1vem7yUg+SMts11Ys8xN9qjqwi8= X-Received: by 2002:a19:915b:: with SMTP id y27mr6819862lfj.134.1599338548671; Sat, 05 Sep 2020 13:42:28 -0700 (PDT) Received: from localhost.localdomain (109-252-170-211.dynamic.spd-mgts.ru. [109.252.170.211]) by smtp.gmail.com with ESMTPSA id e17sm1677763ljn.18.2020.09.05.13.42.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Sep 2020 13:42:28 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Laxman Dewangan , Wolfram Sang , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Andy Shevchenko Cc: linux-i2c@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 04/31] i2c: tegra: Remove i2c_dev.clk_divisor_non_hs_mode member Date: Sat, 5 Sep 2020 23:41:24 +0300 Message-Id: <20200905204151.25343-5-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200905204151.25343-1-digetx@gmail.com> References: <20200905204151.25343-1-digetx@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The "non_hs_mode" divisor value is fixed, thus there is no need to have the variable i2c_dev.clk_divisor_non_hs_mode struct member. Let's remove it and move the mode selection into tegra_i2c_init() where it can be united with the timing selection. Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 45 +++++++++++++++------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 56c5aff579b6..f5b9cdb65182 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -250,7 +250,6 @@ struct tegra_i2c_hw_feature { * @msg_buf_remaining: size of unsent data in the message buffer * @msg_read: identifies read transfers * @bus_clk_rate: current I2C bus clock rate - * @clk_divisor_non_hs_mode: clock divider for non-high-speed modes * @is_multimaster_mode: track if I2C controller is in multi-master mode * @tx_dma_chan: DMA transmit channel * @rx_dma_chan: DMA receive channel @@ -281,7 +280,6 @@ struct tegra_i2c_dev { size_t msg_buf_remaining; int msg_read; u32 bus_clk_rate; - u16 clk_divisor_non_hs_mode; bool is_multimaster_mode; struct dma_chan *tx_dma_chan; struct dma_chan *rx_dma_chan; @@ -783,6 +781,7 @@ static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev) u32 val; int err; u32 clk_divisor, clk_multiplier; + u32 non_hs_mode; u32 tsu_thd; u8 tlow, thigh; @@ -805,24 +804,32 @@ static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev) if (i2c_dev->is_vi) tegra_i2c_vi_init(i2c_dev); - /* Make sure clock divisor programmed correctly */ - clk_divisor = FIELD_PREP(I2C_CLK_DIVISOR_HSMODE, - i2c_dev->hw->clk_divisor_hs_mode) | - FIELD_PREP(I2C_CLK_DIVISOR_STD_FAST_MODE, - i2c_dev->clk_divisor_non_hs_mode); - i2c_writel(i2c_dev, clk_divisor, I2C_CLK_DIVISOR); - - if (i2c_dev->bus_clk_rate > I2C_MAX_STANDARD_MODE_FREQ && - i2c_dev->bus_clk_rate <= I2C_MAX_FAST_MODE_PLUS_FREQ) { + switch (i2c_dev->bus_clk_rate) { + case I2C_MAX_STANDARD_MODE_FREQ + 1 ... I2C_MAX_FAST_MODE_PLUS_FREQ: tlow = i2c_dev->hw->tlow_fast_fastplus_mode; thigh = i2c_dev->hw->thigh_fast_fastplus_mode; tsu_thd = i2c_dev->hw->setup_hold_time_fast_fast_plus_mode; - } else { + + if (i2c_dev->bus_clk_rate > I2C_MAX_FAST_MODE_FREQ) + non_hs_mode = i2c_dev->hw->clk_divisor_fast_plus_mode; + else + non_hs_mode = i2c_dev->hw->clk_divisor_fast_mode; + break; + + default: tlow = i2c_dev->hw->tlow_std_mode; thigh = i2c_dev->hw->thigh_std_mode; tsu_thd = i2c_dev->hw->setup_hold_time_std_mode; + non_hs_mode = i2c_dev->hw->clk_divisor_std_mode; + break; } + /* Make sure clock divisor programmed correctly */ + clk_divisor = FIELD_PREP(I2C_CLK_DIVISOR_HSMODE, + i2c_dev->hw->clk_divisor_hs_mode) | + FIELD_PREP(I2C_CLK_DIVISOR_STD_FAST_MODE, non_hs_mode); + i2c_writel(i2c_dev, clk_divisor, I2C_CLK_DIVISOR); + if (i2c_dev->hw->has_interface_timing_reg) { val = FIELD_PREP(I2C_INTERFACE_TIMING_THIGH, thigh) | FIELD_PREP(I2C_INTERFACE_TIMING_TLOW, tlow); @@ -837,7 +844,7 @@ static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev) i2c_writel(i2c_dev, tsu_thd, I2C_INTERFACE_TIMING_1); clk_multiplier = tlow + thigh + 2; - clk_multiplier *= i2c_dev->clk_divisor_non_hs_mode + 1; + clk_multiplier *= non_hs_mode + 1; err = clk_set_rate(i2c_dev->div_clk, i2c_dev->bus_clk_rate * clk_multiplier); @@ -1748,18 +1755,6 @@ static int tegra_i2c_probe(struct platform_device *pdev) goto unprepare_fast_clk; } - if (i2c_dev->bus_clk_rate > I2C_MAX_FAST_MODE_FREQ && - i2c_dev->bus_clk_rate <= I2C_MAX_FAST_MODE_PLUS_FREQ) - i2c_dev->clk_divisor_non_hs_mode = - i2c_dev->hw->clk_divisor_fast_plus_mode; - else if (i2c_dev->bus_clk_rate > I2C_MAX_STANDARD_MODE_FREQ && - i2c_dev->bus_clk_rate <= I2C_MAX_FAST_MODE_FREQ) - i2c_dev->clk_divisor_non_hs_mode = - i2c_dev->hw->clk_divisor_fast_mode; - else - i2c_dev->clk_divisor_non_hs_mode = - i2c_dev->hw->clk_divisor_std_mode; - ret = clk_prepare(i2c_dev->div_clk); if (ret < 0) { dev_err(i2c_dev->dev, "Clock prepare failed %d\n", ret); -- 2.27.0