Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1127174rda; Mon, 23 Oct 2023 03:34:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHrREdVWZm+VyVJLb6GUblMLox4yTSoDXk/XVmhVRvnL18KVUEH41wWX931AlkN5CwtjYFH X-Received: by 2002:a17:903:887:b0:1ca:57ff:9bfa with SMTP id kt7-20020a170903088700b001ca57ff9bfamr8086298plb.24.1698057284947; Mon, 23 Oct 2023 03:34:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698057284; cv=none; d=google.com; s=arc-20160816; b=B5sks5BE+o1ME3B1Gpf1EBwX4QBcR3LxuTHNHHdexTLWZtgZGasbpntM6Jd6M2YLBu NbimdOWbSOJ4amYAIQTLj9a8p0pobPjyE49ZcIOYKGIdjkFHbW7VFu6+GsxKZD0n94Wo pjvgwQQ5WBI1Dayo9zc+4ZqVsxgdl1z4fSaiudWl60UNUbjYocihZKaB+xEjDhi/0GGP VdwKBFn+HKcoM0k28hs6g7dYo3LFl0+n88c40rAKhRfHgUFFP++gIHvlejWoxtLS/HXU N2PtG3HK75rv7PblkYHARQpzQI5zfkp9sesSpLYxdc9H7hqC+omIfuA8qy/RJTqNdouX kutA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:cms-type:content-transfer-encoding :in-reply-to:from:cc:to:content-language:subject:user-agent :mime-version:date:message-id:dkim-signature:dkim-filter; bh=+4MmQRCPRm1zC57C8sermfjVMdXQDabRKp9YfYkNBNk=; fh=jyeskKvaSwKupx7ustwewSfYAsWYE6VIu1N3RMfW//I=; b=vEW2Suh7x+yXhyPakdR0prrhn7NEKBvVmlXNAkXcE2LGe1qhq5wYTPdGBru+H5/rAJ ZdPwV1zO+AzLIaT7yzxf8pkzJhep88dgCZLEN4Op15F+pdQ2chN4gvAZ+p+4QnSHRoXI NcpLtB0OMPYe8XPPfYChFev4Ev5P7D3MVF5aCHKvum0NAgZLcSnOXKhK22f7ag9k3V+J AGXfD5gNpOo198Car3dRYopcV4hot4w7iPVG2TUCWvRI+Szl4o/o2+b4jwldsi5Y82oM h/9481n9+6FjfrqoZPvGOZn5Ofm357b8ilXpFgAhO/20a6DYfCI+vaJXK80P96ayw/mp VsQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=jiD5YOOG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id x10-20020a170902ec8a00b001b8ba81d04dsi6421825plg.395.2023.10.23.03.34.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 03:34:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=jiD5YOOG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 2E3A280ABB0E; Mon, 23 Oct 2023 03:34:42 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230064AbjJWKea (ORCPT + 99 others); Mon, 23 Oct 2023 06:34:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229572AbjJWKe2 (ORCPT ); Mon, 23 Oct 2023 06:34:28 -0400 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47C95D66 for ; Mon, 23 Oct 2023 03:34:25 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20231023103422euoutp023e4078d4d549632a6c0499271c3be2ac~QthVGpYcw2390723907euoutp02B for ; Mon, 23 Oct 2023 10:34:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20231023103422euoutp023e4078d4d549632a6c0499271c3be2ac~QthVGpYcw2390723907euoutp02B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1698057262; bh=+4MmQRCPRm1zC57C8sermfjVMdXQDabRKp9YfYkNBNk=; h=Date:Subject:To:Cc:From:In-Reply-To:References:From; b=jiD5YOOGtsq7tL80jKyfJTzXuPikSrWT2ycxLNk/tmKpPixlNp72EO2ZUED6zlXK0 yWNTne7r39csOHJSU3Ftyy6ZbLCm0BrbRbs6fP2UulvmTsoqmCmPl/9SAYIKO8F1Tn slF8slEEXutWLxYqJrtmaxKg4uduQGGrBng3eoiY= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20231023103421eucas1p20cfc4bc17f36b18063aff1aa2970bcb8~QthU1bdxM0499004990eucas1p2E; Mon, 23 Oct 2023 10:34:21 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id CA.3C.11320.D2C46356; Mon, 23 Oct 2023 11:34:21 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20231023103421eucas1p2f1415d69dd979036ef8bcb1a2dc88978~QthUXfml21979119791eucas1p2b; Mon, 23 Oct 2023 10:34:21 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20231023103421eusmtrp28be71d7e5f38d4dcc15cd54aacba43b8~QthUWwFFr0425004250eusmtrp2L; Mon, 23 Oct 2023 10:34:21 +0000 (GMT) X-AuditID: cbfec7f4-993ff70000022c38-ca-65364c2dc562 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 7A.C7.25043.D2C46356; Mon, 23 Oct 2023 11:34:21 +0100 (BST) Received: from [106.210.134.192] (unknown [106.210.134.192]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20231023103420eusmtip21cb536a4edfc919ec8b7ab907f5830bc~QthTtwqQ42361923619eusmtip2B; Mon, 23 Oct 2023 10:34:20 +0000 (GMT) Message-ID: <55812f75-3053-4970-bbbe-8ca563f33721@samsung.com> Date: Mon, 23 Oct 2023 12:34:19 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] i2c: exynos5: Calculate t_scl_l, t_scl_h according to i2c spec Content-Language: en-US To: Camel Guo , Krzysztof Kozlowski Cc: Alim Akhtar , linux-i2c@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@axis.com From: Marek Szyprowski In-Reply-To: <20220912085943.1098651-1-camel.guo@axis.com> Content-Transfer-Encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprHKsWRmVeSWpSXmKPExsWy7djP87q6PmapBlPnqFo8mLeNzeL76wdM Fp9aVC32vt7KbrHp8TVWi46/XxgtLu+aw2Yx4/w+JgcOj+vrAjzuXNvD5rF5Sb1H35ZVjB6f N8kFsEZx2aSk5mSWpRbp2yVwZSxZvJG14LVsxYJNnA2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+vrAjzuXNvD5rF5Sb1H35ZVjB6f N8kFsEbp2RTll5akKmTkF5fYKkUbWhjpGVpa6BmZWOoZGpvHWhmZKunb2aSk5mSWpRbp2yXo ZSxZvJG14LVsxYJNnA2Mn8W6GDk5JARMJK5+P8bYxcjFISSwlFHi0etTbBAJGYmT0xpYIWxh iT/Xutggit4zSnxqusgMkuAVsJPouDsRrIFFQFXi4KkNjBBxQYmTM5+wgNiiAvIS92/NYAex hQVCJe4unwHWyywgLnHryXwmEFtEIEri/uZXLCALmAUOMEqcXnEOrEFIwFLi7beDYIPYBAwl ut6CXMHBwSlgJXF4tw/EHDOJrq1djBC2vMT2t3OYJzAKzUJyxiwk62YhaZmFpGUBI8sqRpHU 0uLc9NxiI73ixNzi0rx0veT83E2MwLjbduznlh2MK1991DvEyMTBeIhRgoNZSYR3drhJqhBv SmJlVWpRfnxRaU5q8SFGU2BYTGSWEk3OB0Z+Xkm8oZmBqaGJmaWBqaWZsZI4r2dBR6KQQHpi SWp2ampBahFMHxMHp1QDk2Ql/8Mvqzp23JExn/qXwVBRqag810gkjTugwT5Z4Py8j9cCD0w6 FJztMcGwSGLN+U0OvcE6Pw7c4libu1WFn+EfS5/mBPfG7tpz16cYTJT6p7Tm4I9Dmxf7Xj+6 Xbl5vkH8eSXdBMuHltpz1nzOd77JvvFnTU5pHZvl3OK29T32y3jCrmrYyXRsm8huMf2CwZEz 4onJxQtmdbeq3kiKs+yU9O8NDA6TuRxt37h6nt+Pc0n9gtqvrc6JzHh+J1JL6nrWyvIFU7Ue SX8MlprzdN3FL093bTF/fuRi93mJCnORF+vWCZ3rLWNn+nnqCn8hy9cJS4p7J7v8+xBdMeNS wdYtT1ju/r46N/WQ06UEcyWW4oxEQy3mouJEAMYOsqFEAwAA X-CMS-MailID: 20231023103421eucas1p2f1415d69dd979036ef8bcb1a2dc88978 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20231023103421eucas1p2f1415d69dd979036ef8bcb1a2dc88978 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20231023103421eucas1p2f1415d69dd979036ef8bcb1a2dc88978 References: <20220912085943.1098651-1-camel.guo@axis.com> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 23 Oct 2023 03:34:42 -0700 (PDT) On 12.09.2022 10:59, Camel Guo wrote: > Previously the duty cycle was divided equally into h_scl_l, t_scl_h. > This makes the low period of the SCL clock in Fast Mode is only 1.25us > which is way lower than the minimal value (1.3) specified in i2c > specification. In order to make sure t_scl_l, t_scl_h always fullfill > i2c specification, this commit calculates t_scl_l using this formula: > > t_scl_l = clk_cycle * > ((t_low_min + (scl_clock - t_low_min - t_high_min) / 2) / scl_clock) > > where: > t_low_min is the minimal value of low period of the SCL clock in us; > t_high_min is the minimal value of high period of the SCL clock in us; > scl_clock is converted from SCL clock frequency into us. > > Signed-off-by: Camel Guo This sounds reasonable and works fine on all Exynos-based test board I have. Feel free to add: Tested-by: Marek Szyprowski Reviewed-by: Marek Szyprowski > --- > drivers/i2c/busses/i2c-exynos5.c | 34 +++++++++++++++++++++++++++++--- > 1 file changed, 31 insertions(+), 3 deletions(-) > > diff --git a/drivers/i2c/busses/i2c-exynos5.c b/drivers/i2c/busses/i2c-exynos5.c > index 4a6260d04db2..72bc8adea8d5 100644 > --- a/drivers/i2c/busses/i2c-exynos5.c > +++ b/drivers/i2c/busses/i2c-exynos5.c > @@ -267,7 +267,7 @@ static void exynos5_i2c_clr_pend_irq(struct exynos5_i2c *i2c) > * exynos5_i2c_set_timing: updates the registers with appropriate > * timing values calculated > * > - * Timing values for operation are calculated against either 100kHz > + * Timing values for operation are calculated against 100kHz, 400kHz > * or 1MHz controller operating frequency. > * > * Returns 0 on success, -EINVAL if the cycle length cannot > @@ -330,6 +330,23 @@ static int exynos5_i2c_set_timing(struct exynos5_i2c *i2c, bool hs_timings) > * > * Constraints: 4 <= temp, 0 <= CLK_DIV < 256, 2 <= clk_cycle <= 510 > * > + * To split SCL clock into low, high periods appropriately, one > + * proportion factor for each I2C mode is used, which is calculated > + * using this formula. > + * ``` > + * ((t_low_min + (scl_clock - t_low_min - t_high_min) / 2) / scl_clock) > + * ``` > + * where: > + * t_low_min is the minimal value of low period of the SCL clock in us; > + * t_high_min is the minimal value of high period of the SCL clock in us; > + * scl_clock is converted from SCL clock frequency into us. > + * > + * Below are the proportion factors for these I2C modes: > + * t_low_min, t_high_min, scl_clock, proportion > + * Standard Mode: 4.7us, 4.0us, 10us, 0.535 > + * Fast Mode: 1.3us, 0.6us, 2.5us, 0.64 > + * Fast-Plus Mode: 0.5us, 0.26us, 1us, 0.62 > + * > */ > t_ftl_cycle = (readl(i2c->regs + HSI2C_CONF) >> 16) & 0x7; > temp = clkin / op_clk - 8 - t_ftl_cycle; > @@ -343,8 +360,19 @@ static int exynos5_i2c_set_timing(struct exynos5_i2c *i2c, bool hs_timings) > return -EINVAL; > } > > - t_scl_l = clk_cycle / 2; > - t_scl_h = clk_cycle / 2; > + /* > + * Scale clk_cycle to get t_scl_l using the proption factors for individual I2C modes. > + */ > + if (op_clk <= I2C_MAX_STANDARD_MODE_FREQ) > + t_scl_l = clk_cycle * 535 / 1000; > + else if (op_clk <= I2C_MAX_FAST_MODE_FREQ) > + t_scl_l = clk_cycle * 64 / 100; > + else > + t_scl_l = clk_cycle * 62 / 100; > + > + if (t_scl_l > 0xFF) > + t_scl_l = 0xFF; > + t_scl_h = clk_cycle - t_scl_l; > t_start_su = t_scl_l; > t_start_hd = t_scl_l; > t_stop_su = t_scl_l; > > base-commit: ce888220d5c7a805e0e155302a318d5d23e62950 Best regards -- Marek Szyprowski, PhD Samsung R&D Institute Poland