From patchwork Thu Feb 23 16:47:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Hajda X-Patchwork-Id: 9588601 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id ED3CD6051E for ; Thu, 23 Feb 2017 16:50:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD6D92894E for ; Thu, 23 Feb 2017 16:50:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D1D6928953; Thu, 23 Feb 2017 16:50:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4840E28956 for ; Thu, 23 Feb 2017 16:50:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751119AbdBWQuI (ORCPT ); Thu, 23 Feb 2017 11:50:08 -0500 Received: from mailout3.w1.samsung.com ([210.118.77.13]:48377 "EHLO mailout3.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751110AbdBWQuI (ORCPT ); Thu, 23 Feb 2017 11:50:08 -0500 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout3.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0OLU00KOH6NB1980@mailout3.w1.samsung.com>; Thu, 23 Feb 2017 16:47:35 +0000 (GMT) Received: from eusmges4.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20170223164734eucas1p1d92acd180bf088e6b0c68496ad14230f~l_Hn1sPoK0304503045eucas1p1K; Thu, 23 Feb 2017 16:47:34 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges4.samsung.com (EUCPMTA) with SMTP id E6.ED.28517.6221FA85; Thu, 23 Feb 2017 16:47:34 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20170223164733eucas1p11ad37a2334fe709a062ecc82b5224e1a~l_Hm_OWAY0453304533eucas1p1D; Thu, 23 Feb 2017 16:47:33 +0000 (GMT) X-AuditID: cbfec7f4-f79716d000006f65-26-58af12260cff Received: from eusync1.samsung.com ( [203.254.199.211]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id DF.56.10233.C221FA85; Thu, 23 Feb 2017 16:47:40 +0000 (GMT) Received: from AMDC2768.DIGITAL.local ([106.120.43.17]) by eusync1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0OLU00LRQ6N8NU90@eusync1.samsung.com>; Thu, 23 Feb 2017 16:47:33 +0000 (GMT) From: Andrzej Hajda To: Wolfram Sang , Krzysztof Kozlowski , Javier Martinez Canillas , linux-i2c@vger.kernel.org, linux-samsung-soc@vger.kernel.org Cc: Andrzej Hajda , Bartlomiej Zolnierkiewicz , Marek Szyprowski Subject: [PATCH] i2c: exynos5: simplify timings calculation Date: Thu, 23 Feb 2017 17:47:26 +0100 Message-id: <1487868446-5339-1-git-send-email-a.hajda@samsung.com> X-Mailer: git-send-email 2.7.4 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrKIsWRmVeSWpSXmKPExsWy7djPc7pqQusjDJ72iFrcWneO1WLjjPWs Fm/ermGyOH9+A7tFx98vjBYzzu9jslh75C67xcoTs5gdODw2repk89jSf5fdo2/LKkaPk6ee sHh83iQXwBrFZZOSmpNZllqkb5f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VSICBxgltp39xw7iMAv0MUo0/l3FBlIl LGAt0dp8nxnEZhFQlbi99xc7iM0r4CTxpe00E8Q+OYmb5zqZJzByL2BkWMUoklpanJueW2yk V5yYW1yal66XnJ+7iREYqtuO/dyyg7HrXfAhRgEORiUe3o4X6yKEWBPLiitzDzFKcDArifAe +wYU4k1JrKxKLcqPLyrNSS0+xGgKtHwis5Rocj4wjvJK4g1NDM0tDY2MLSzMjYyUxHmnfrgS LiSQnliSmp2aWpBaBNPHxMEp1cB4zbApu9TCZa778up5M29n+x3Y6v8rYHUOw/K6DYa+qzjP zFZvmOXy8mcc57TKxO/7bGYevDONZd7yvxc7/z145Ln8eOorHY85W65+ZvobdClQk8lS47Dm lM8vpi2NffZwhdE5EdNfBw6rFfysiC42Lfl2K7rk4OT1HZYb94ks5oqaVt8q/jPgqxJLcUai oRZzUXEiABF7ZZxrAgAA X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20170223164733eucas1p11ad37a2334fe709a062ecc82b5224e1a X-Msg-Generator: CA X-Sender-IP: 182.198.249.180 X-Local-Sender: =?UTF-8?B?QW5kcnplaiBIYWpkYRtTUlBPTC1LZXJuZWwgKFRQKRvsgrw=?= =?UTF-8?B?7ISx7KCE7J6QG1NlbmlvciBTb2Z0d2FyZSBFbmdpbmVlcg==?= X-Global-Sender: =?UTF-8?B?QW5kcnplaiBIYWpkYRtTUlBPTC1LZXJuZWwgKFRQKRtTYW1z?= =?UTF-8?B?dW5nIEVsZWN0cm9uaWNzG1NlbmlvciBTb2Z0d2FyZSBFbmdpbmVlcg==?= X-Sender-Code: =?UTF-8?B?QzEwG0VIURtDMTBDRDAyQ0QwMjczOTI=?= CMS-TYPE: 201P X-HopCount: 7 X-CMS-RootMailID: 20170223164733eucas1p11ad37a2334fe709a062ecc82b5224e1a X-RootMTR: 20170223164733eucas1p11ad37a2334fe709a062ecc82b5224e1a References: Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Instead of using cryptic loop direct calculation of timings can be used. Signed-off-by: Andrzej Hajda Tested-by: Javier Martinez Canillas Reviewed-by: Andi Shyti --- drivers/i2c/busses/i2c-exynos5.c | 40 ++++++++++++++-------------------------- 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/drivers/i2c/busses/i2c-exynos5.c b/drivers/i2c/busses/i2c-exynos5.c index cbd93ce..04127b8 100644 --- a/drivers/i2c/busses/i2c-exynos5.c +++ b/drivers/i2c/busses/i2c-exynos5.c @@ -292,9 +292,9 @@ static int exynos5_i2c_set_timing(struct exynos5_i2c *i2c, int mode) unsigned int t_sr_release; unsigned int t_ftl_cycle; unsigned int clkin = clk_get_rate(i2c->clk); - unsigned int div, utemp0 = 0, utemp1 = 0, clk_cycle; unsigned int op_clk = (mode == HSI2C_HIGH_SPD) ? i2c->hs_clock : i2c->fs_clock; + int div, clk_cycle, temp; /* * In case of HSI2C controller in Exynos5 series @@ -305,33 +305,21 @@ static int exynos5_i2c_set_timing(struct exynos5_i2c *i2c, int mode) * FPCLK / FI2C = * (CLK_DIV + 1) * (TSCLK_L + TSCLK_H + 2) + 8 + FLT_CYCLE * - * utemp0 = (CLK_DIV + 1) * (TSCLK_L + TSCLK_H + 2) - * utemp1 = (TSCLK_L + TSCLK_H + 2) + * clk_cycle := TSCLK_L + TSCLK_H + * temp := (CLK_DIV + 1) * (clk_cycle + 2) + * + * Constraints: 4 <= temp, 0 <= CLK_DIV < 256, 2 <= clk_cycle <= 510 + * */ t_ftl_cycle = (readl(i2c->regs + HSI2C_CONF) >> 16) & 0x7; - utemp0 = (clkin / op_clk) - 8; - - if (i2c->variant->hw == HSI2C_EXYNOS7) - utemp0 -= t_ftl_cycle; - else - utemp0 -= 2 * t_ftl_cycle; - - /* CLK_DIV max is 256 */ - for (div = 0; div < 256; div++) { - utemp1 = utemp0 / (div + 1); - - /* - * SCL_L and SCL_H each has max value of 255 - * Hence, For the clk_cycle to the have right value - * utemp1 has to be less then 512 and more than 4. - */ - if ((utemp1 < 512) && (utemp1 > 4)) { - clk_cycle = utemp1 - 2; - break; - } else if (div == 255) { - dev_warn(i2c->dev, "Failed to calculate divisor"); - return -EINVAL; - } + temp = clkin / op_clk - 8 - t_ftl_cycle; + if (i2c->variant->hw != HSI2C_EXYNOS7) + temp -= t_ftl_cycle; + div = temp / 512; + clk_cycle = temp / (div + 1) - 2; + if (temp < 4 || div >= 256 || clk_cycle < 2) { + dev_warn(i2c->dev, "Failed to calculate divisor"); + return -EINVAL; } t_scl_l = clk_cycle / 2;