From patchwork Tue Dec 22 21:35:41 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Suthikulpanit, Suravee" X-Patchwork-Id: 58961 Delivered-To: patch@linaro.org Received: by 10.112.89.199 with SMTP id bq7csp3491632lbb; Tue, 22 Dec 2015 13:36:25 -0800 (PST) X-Received: by 10.98.0.140 with SMTP id 134mr4015107pfa.82.1450820184951; Tue, 22 Dec 2015 13:36:24 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c7si20946447pfj.114.2015.12.22.13.36.24; Tue, 22 Dec 2015 13:36:24 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-acpi-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932402AbbLVVgX (ORCPT + 6 others); Tue, 22 Dec 2015 16:36:23 -0500 Received: from mail-bn1bon0058.outbound.protection.outlook.com ([157.56.111.58]:9208 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932397AbbLVVgW (ORCPT ); Tue, 22 Dec 2015 16:36:22 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Suravee.Suthikulpanit@amd.com; Received: from ssuthiku-ubuntu-lt.amd.com (165.204.77.1) by BY1PR12MB0439.namprd12.prod.outlook.com (10.162.147.140) with Microsoft SMTP Server (TLS) id 15.1.361.13; Tue, 22 Dec 2015 21:36:16 +0000 From: Suravee Suthikulpanit To: , CC: , , , , , , , "Suravee Suthikulpanit" Subject: [PATCH v3] i2c: designware: Do not require clock when SSCN and FFCN are provided Date: Tue, 22 Dec 2015 15:35:41 -0600 Message-ID: <1450820141-1720-1-git-send-email-Suravee.Suthikulpanit@amd.com> X-Mailer: git-send-email 2.5.0 MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: BY2PR1001CA0012.namprd10.prod.outlook.com (25.164.163.150) To BY1PR12MB0439.namprd12.prod.outlook.com (25.162.147.140) X-Microsoft-Exchange-Diagnostics: 1; BY1PR12MB0439; 2:g4G8TA6aVcnFFcGXjyHDex0nlG0uH9MYyvKtL2sBgOq+36fnmi+mRMaDuIwBU+HwoO70CcmtX5n/LnMZz3qtQTgEQVbtpRKd/W+GTzeGhrvHZ/TQ+JrAOD2jj3kkIJYoaJkoFT8W+3ZK8997onyg3w==; 3:8nY8GNnDMQRNUe9Vk14yJ/2CnIjuWiUbAC434IMqieW92mWL56jg6Ej4XiWvWsxXksVweKgQwmdYeqQAB/ACHs6OSLal2ZZqgafx+D1Za4I6XCpBDZfhlxOgjo92cyk1; 25:eRvlMbrc8yKrU8b3mw5GztjMQyxDbxSFlZIliGqFOn9WzUg/a5oLzMIDcB5LcS9IeGvMLBKT9L72Ip03bhvwsCT3DQ2cH7wuViXLMnpciBRQ9GTGQsUSundU29NgL12SUHUgPG0fXQQ/tCUODU8Dq9GgT0GvWDgAm+mgBNIKxkHR2d/3NYuuSjL774yqUNilCzRevXjnWocbRJ0TeFxuKKg4N8Xij5dhgZMpctatOBHXaYSWMf3zfcttxQYvq3nClB07F6BbtnwFyMmw3S9IHg== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY1PR12MB0439; X-Microsoft-Exchange-Diagnostics: 1; BY1PR12MB0439; 20:HPKVJQbOtcLgElvyKeVzHNkIVBJbk5id0HWhWkOqQKvJkGujCm6ZSdZXZGcBizu/8OlmPIugHvh/IHuQyNXDYZWVWzJ9lPUM7llCAsME3+7IXeRBiV7zit5STM0Jv2JOLALT8z+CmgQmoJ97+C1eT5Ecx3smLQFO27nbqjrcWMt2BhNyvrGPwamobgczn6Q1fZAPCKLhDTt7JOWqspVTptcXJkBxj6cE3+DZxuMO/gNOSAQYXwXYUxQHyzD4cd5jKsL5vIwM9OzQE/iB0mCpGyNbdOoDIfUqtx1sHFFtsQnO8f5lmGj0pd76qIUjYgp56rdTPIu2asF9nF48HHkGV5g+THMkCDHxYqxNk1XlTGy/sgBoel2N0lvGCajlIqbpzkHvXN3yxWirkZIMsPvNk1x7R7r9v/hcwZ3j/yvf37rL5li4lKuHxw/dUAo2KImdsOBPrEJoX0HClWqOfnn01ZUe8UBkzhtFgPSYsvkzEAe3oxYVgEyUDTFUtJS+yBow; 4:qzcK0kRxjJMZViNbtc3f8T8Q435Bq5z3mqqTTx6/XS0pTOyz+y0FddBnNpLAHAcwfM22rZ6bzSx6Fj76Cc8VrqOjnPGdm/NxY6LABTx+usAzENbAUio4shs3MLM4C+GuU2uploCopDgRSMwGtdvtiPtJf61jJcSduERMJ3vSnpRPafQUhVPQBOV6TEa9fBN+O7nKyjSHsAa6Qoof1BlZgHIc9WkASQ/SaLwiRXK03GTyl/L2An1vtbZGy6uQOr511bk5y6ghKBnF+b4wxsbMjbixCiYqck3wk4dE9ZgKVbW6Mb93trwj1j+LWu3Rf4IJe8FLkwDLzGys7qRJ7kqObz3p0vo0MUZqUkK5sqsqSRtJKeAty7kH9rDvTpNA7BI+hdPk2DArpwkytbQA1ys2oQHp6JUStRRLFXEpMq4GALk= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(520078)(5005006)(8121501046)(3002001)(10201501046); SRVR:BY1PR12MB0439; BCL:0; PCL:0; RULEID:; SRVR:BY1PR12MB0439; X-Forefront-PRVS: 0798146F16 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(189002)(199003)(5008740100001)(48376002)(586003)(6116002)(3846002)(15975445007)(97736004)(101416001)(92566002)(77096005)(5004730100002)(36756003)(53416004)(50226001)(66066001)(47776003)(1096002)(50986999)(122386002)(105586002)(40100003)(229853001)(50466002)(19580405001)(19580395003)(189998001)(86362001)(42186005)(106356001)(5001770100001)(87976001)(5003940100001); DIR:OUT; SFP:1101; SCL:1; SRVR:BY1PR12MB0439; H:ssuthiku-ubuntu-lt.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BY1PR12MB0439; 23:sGNzIUFDkQS21FEekSoHz4TnM8hAkYoPq2ELa5nU1?= =?us-ascii?Q?Odp+/Dp0f9uc+xvu4VO/HHuwJrC/Q5XqsYCFhCytPgUmCQbOY/hNFTdpA8Qi?= =?us-ascii?Q?ymln3g9oSIWJ9K7rz5zlg3RxpO+7gIKK3EJ9d/5EARX5j59yEGaMfcp2RbvL?= =?us-ascii?Q?FCa5H6oLrGzrgsYAbGROucuPGvpvTmQPGjZfTqy18NTPNSyyixAD+vrCaEef?= =?us-ascii?Q?4/095kZV4g9T4ZhT1XqdsVwdSNTEwszvuk8LFp9XR4kz1YEq35S4Y6W3LFMn?= =?us-ascii?Q?CfYX/gcmIhN+pucPy2uwlmBWgTKDhmjRgfm42ytu5r/gCAkDpfOQL6yTm3Rh?= =?us-ascii?Q?fGK9i36txapt13oX8UUKPl1FkuhtzDUYQUth9qyHWiXSQyqoOzSQCKVT21KT?= =?us-ascii?Q?42ZMpB43sxgREmPhgARvskoRjvmJtyWCRc07hCxwMVKdeax5OZmCg4irrJ9K?= =?us-ascii?Q?DWqlgBkNoMP8sDxJLJ5hRACBynB5VerniTEtOkX0z3HaHH7oq38QVVMOfCPB?= =?us-ascii?Q?tIUcPqZk8pfMxh/6kdFV0GKHo3dCZDKd8kvD5KUBytoiEPOGn9CQehZAs/9H?= =?us-ascii?Q?nHDJZSbjugk2W5z04hjtaLi2IwJoc2/KK+X4XzkIFkOz49elhhAWqSkKxlTS?= =?us-ascii?Q?hX8cRme0lTsIagPoHeE2zFLLSlZ+q3FZ56Zw6ZwNVTsRXqoFt934FbiPYy1o?= =?us-ascii?Q?64jhJLtHPijY7u+o+5qd9HzemwSFH9O5vpMFp9eKv6kMlx/bre3yJVf5aKwf?= =?us-ascii?Q?1yC8Zp9Qr88fubDHbXaPhni6eLNJmGIdeo9xmQmqtz5J69FGo6csTXPqOo9p?= =?us-ascii?Q?cSLDTGn1tbNanrGKdkZKQbwLnVLu75yDMC1NJXZYUp6hoWIv2Kvp0Fh+0p+h?= =?us-ascii?Q?HQsmhaRVMzWCenNAeuQ1QcPfg/Zrerwu4TmQSQlISA58xqpLoXpWqh+5Tdpk?= =?us-ascii?Q?wNe4A5LfS861p4jZ6LSQ5OD3y4vK0eL6DRYT8Xqug=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; BY1PR12MB0439; 5:P91dkKeEVaFrXMkvLM3DUsW5imzEojJEPfX79VjE5s79FCivtbwTaAfiU8+iCAdBCtQMrgzTRzk2xISRtxOtM4tdjdvRaoUEkwM7gb5WhKVmM9yQJ/9IwtnC7jis0KtWwpxIjajPZUHUS93Di8UzJg==; 24:x0b/AMlhgsCr4owH5flFRs1ZH5A8srKfMDg3lQItFtqLg2FjhZ+M84+8hVxR+1A+ovCrNkD/SYLw+8jfF2GUuZ8EHltGt220jXKcUCeWsXI=; 20:Ytj+wwZgnZC9WrSIaDIDwv5o6PYgvEi1l+kuSd8OsCIZYH/txKfN9D80zhK4cHgWQ6R/dIWPR0Eo1VwcW3NAELSFwmkYWv55rLYTsJgFyk3vv11Owfira8gFnI/iZjJQc3IXbEeWl7+p8zr/F8KZrAbvxe5DjzNs9WSV13R6b1JHKI20OWifZx2/2ikBeAFxSTtORH8U78PkUrk975bB7I+amuhAIv8RFRKrvVII8rMEsxtSmBR/jzGa/p6ecC4L X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Dec 2015 21:36:16.4205 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY1PR12MB0439 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org The current driver uses input clock source frequency to calculate values for [SS|FS]_[HC|LC] registers. However, when booting ACPI, we do not currently have a good way to provide the frequency information. Instead, we can leverage the SSCN and FFCN ACPI methods, which can be used to directly provide these values. So, the clock information should no longer be required during probing. However, since clk can be invalid, additional checks must be done where we are making use of it. Signed-off-by: Mika Westerberg Signed-off-by: Suravee Suthikulpanit --- Note: This has been tested on AMD Seattle RevB for both DT and ACPI. Changes from V2 (https://lkml.org/lkml/2015/12/22/584): * Add the i2c_dw_clk_rate from Mika. * Add check if get_clk_rate_khz is set before setting sda_hold_time Changes from V1 (https://lkml.org/lkml/2015/12/15/792): In v1, I disregarded the clock if SSCN and FMCN are provided, assuming that it was not needed. That was incorrect assumption, and is now fixed in v2. drivers/i2c/busses/i2c-designware-core.c | 22 +++++++++++++++------- drivers/i2c/busses/i2c-designware-platdrv.c | 24 ++++++++++++------------ 2 files changed, 27 insertions(+), 19 deletions(-) -- 2.5.0 -- To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/i2c/busses/i2c-designware-core.c b/drivers/i2c/busses/i2c-designware-core.c index 8c48b27..25dccd8 100644 --- a/drivers/i2c/busses/i2c-designware-core.c +++ b/drivers/i2c/busses/i2c-designware-core.c @@ -271,6 +271,17 @@ static void __i2c_dw_enable(struct dw_i2c_dev *dev, bool enable) enable ? "en" : "dis"); } +static unsigned long i2c_dw_clk_rate(struct dw_i2c_dev *dev) +{ + /* + * Clock is not necessary if we got LCNT/HCNT values directly from + * the platform code. + */ + if (WARN_ON_ONCE(!dev->get_clk_rate_khz)) + return 0; + return dev->get_clk_rate_khz(dev); +} + /** * i2c_dw_init() - initialize the designware i2c master hardware * @dev: device private data @@ -281,7 +292,6 @@ static void __i2c_dw_enable(struct dw_i2c_dev *dev, bool enable) */ int i2c_dw_init(struct dw_i2c_dev *dev) { - u32 input_clock_khz; u32 hcnt, lcnt; u32 reg; u32 sda_falling_time, scl_falling_time; @@ -295,8 +305,6 @@ int i2c_dw_init(struct dw_i2c_dev *dev) } } - input_clock_khz = dev->get_clk_rate_khz(dev); - reg = dw_readl(dev, DW_IC_COMP_TYPE); if (reg == ___constant_swab32(DW_IC_COMP_TYPE_VALUE)) { /* Configure register endianess access */ @@ -325,12 +333,12 @@ int i2c_dw_init(struct dw_i2c_dev *dev) hcnt = dev->ss_hcnt; lcnt = dev->ss_lcnt; } else { - hcnt = i2c_dw_scl_hcnt(input_clock_khz, + hcnt = i2c_dw_scl_hcnt(i2c_dw_clk_rate(dev), 4000, /* tHD;STA = tHIGH = 4.0 us */ sda_falling_time, 0, /* 0: DW default, 1: Ideal */ 0); /* No offset */ - lcnt = i2c_dw_scl_lcnt(input_clock_khz, + lcnt = i2c_dw_scl_lcnt(i2c_dw_clk_rate(dev), 4700, /* tLOW = 4.7 us */ scl_falling_time, 0); /* No offset */ @@ -344,12 +352,12 @@ int i2c_dw_init(struct dw_i2c_dev *dev) hcnt = dev->fs_hcnt; lcnt = dev->fs_lcnt; } else { - hcnt = i2c_dw_scl_hcnt(input_clock_khz, + hcnt = i2c_dw_scl_hcnt(i2c_dw_clk_rate(dev), 600, /* tHD;STA = tHIGH = 0.6 us */ sda_falling_time, 0, /* 0: DW default, 1: Ideal */ 0); /* No offset */ - lcnt = i2c_dw_scl_lcnt(input_clock_khz, + lcnt = i2c_dw_scl_lcnt(i2c_dw_clk_rate(dev), 1300, /* tLOW = 1.3 us */ scl_falling_time, 0); /* No offset */ diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c index 8ffc36b..04edd09 100644 --- a/drivers/i2c/busses/i2c-designware-platdrv.c +++ b/drivers/i2c/busses/i2c-designware-platdrv.c @@ -205,16 +205,14 @@ static int dw_i2c_plat_probe(struct platform_device *pdev) DW_IC_CON_RESTART_EN | DW_IC_CON_SPEED_FAST; dev->clk = devm_clk_get(&pdev->dev, NULL); - dev->get_clk_rate_khz = i2c_dw_get_clk_rate_khz; - if (IS_ERR(dev->clk)) - return PTR_ERR(dev->clk); - clk_prepare_enable(dev->clk); - - if (!dev->sda_hold_time && ht) { - u32 ic_clk = dev->get_clk_rate_khz(dev); - - dev->sda_hold_time = div_u64((u64)ic_clk * ht + 500000, - 1000000); + if (!IS_ERR(dev->clk)) { + dev->get_clk_rate_khz = i2c_dw_get_clk_rate_khz; + clk_prepare_enable(dev->clk); + + if (!dev->sda_hold_time && ht) + dev->sda_hold_time = div_u64( + (u64)dev->get_clk_rate_khz(dev) * ht + 500000, + 1000000); } if (!dev->tx_fifo_depth) { @@ -297,7 +295,8 @@ static int dw_i2c_plat_suspend(struct device *dev) struct dw_i2c_dev *i_dev = platform_get_drvdata(pdev); i2c_dw_disable(i_dev); - clk_disable_unprepare(i_dev->clk); + if (!IS_ERR(i_dev->clk)) + clk_disable_unprepare(i_dev->clk); return 0; } @@ -307,7 +306,8 @@ static int dw_i2c_plat_resume(struct device *dev) struct platform_device *pdev = to_platform_device(dev); struct dw_i2c_dev *i_dev = platform_get_drvdata(pdev); - clk_prepare_enable(i_dev->clk); + if (!IS_ERR(i_dev->clk)) + clk_prepare_enable(i_dev->clk); if (!i_dev->pm_runtime_disabled) i2c_dw_init(i_dev);