From patchwork Mon Jan 4 15:17:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Suthikulpanit, Suravee" X-Patchwork-Id: 59137 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp5416588lbb; Mon, 4 Jan 2016 07:18:11 -0800 (PST) X-Received: by 10.66.122.36 with SMTP id lp4mr117216811pab.31.1451920690957; Mon, 04 Jan 2016 07:18:10 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z4si40090856pfi.118.2016.01.04.07.18.10; Mon, 04 Jan 2016 07:18:10 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-i2c-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-i2c-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-i2c-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751913AbcADPSI (ORCPT + 1 other); Mon, 4 Jan 2016 10:18:08 -0500 Received: from mail-by2on0053.outbound.protection.outlook.com ([207.46.100.53]:55316 "EHLO na01-by2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751581AbcADPSG (ORCPT ); Mon, 4 Jan 2016 10:18:06 -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 BLUPR12MB0433.namprd12.prod.outlook.com (10.162.92.139) with Microsoft SMTP Server (TLS) id 15.1.361.13; Mon, 4 Jan 2016 15:17:58 +0000 From: Suravee Suthikulpanit To: , , , CC: , , , , , "Suravee Suthikulpanit" Subject: [PATCH v4] i2c: designware: Do not require clock when SSCN and FFCN are provided Date: Mon, 4 Jan 2016 09:17:35 -0600 Message-ID: <1451920655-10798-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: SN2PR10CA0038.namprd10.prod.outlook.com (25.160.12.176) To BLUPR12MB0433.namprd12.prod.outlook.com (25.162.92.139) X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0433; 2:FYJTgtlDzUD0M36w3NSqjO+SctruuHgP9w/Ln4hSHf4kaJu/8y8URHPNvYjq9DsWemnsgUui8d/OGwmehu2rh6ondVA8YXQUyUckOrmbZD0NuRO4ELngCPGySMJRHwoDtPiNydAmieCkauEp3qwsCQ==; 3:BiR1pql28TXJ/U0YHemVgfZfO+IbkRef4TUDTC26BHVPJzrhyRZTJvyhvWzMwx7mraZIKA86rem9xlq5LqHZ309+4W6osCEM/LMkev8WLKaK2Kcx8n4vYGOx7LEfeeNQ; 25:tyIO1UkmHXx/kWZQiXS1ytJwRLlJ8/pxAr4WlrpFNlfdGqLJ0nOja41Ka2R+LYrfKW17r3J+Lf1KDApp5mzhkT6s9v81QGQ0aubezsCFNHEfqtupHeDoeltL4LDCKL8hxyOa0kLAvWiBs0Sxfqionyt++PNT0QWi36+RaBCqd1uLjhZY9E7nMMy6VoqIghMuNB72gH7D/+9BAGkb/13YvLYraj8Ri2fO2D8vpNkyNAUPLYPlh7lxVQOkiHAvEfX6pkbb6kdhGp95caZnGQf0pA== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BLUPR12MB0433; X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0433; 20:lZWVPx1bgaO7anNrGCpE3chL3b3b7yipVxr4hpZoHZuuKY3FhI2WUNugHr9BpZPKWCbZwGzP9+8q5dQerhg824H0PvT7rAygz15ZfCqDACTYZW6fHnWA80YzYrouqkvoEQKaDIEziI8J3queC/xklDdi3nVEznGoHtLd/bjaOoHFcuh/ZQMtQ9mTOW1wFUzhzjWY8Aw4Ig0Sj3Z8PZihF23cqv82RhA9LIwNZrJlIxUrfFfuDyhTRrWED08Bo1cd8vTqa4qwJS1gLMOdx/daDQZ7RIN3GkTntv35VUVD7OQhLrTWVeTl3DuyqLH4kC6le7e33ryVf8e6nw1/MB93J0/4JBh4ersz/BiUViptoymywCtBfopV0Rdl9NtHy4+IfuM5PUUpkRpG/k/8mbcqhyEfmkk2T2PnHMDfSnUDJHOs/Pufj/Zl2xrZlabsE+btrqGTkmm1UQpEuucjF1ZuHBDc9ZnvG/Y9OPigJnnENuT+qlRZtja/QlnRg20Oty6j; 4:xDJCnIv2qyoqp5ys9+rwiaRIwjNCPV3DxVpIF2rkEWaZFhrbbL5mWY+GbyV/A5UzNXy9VwQw84umsZEpedpC508stgLujj1hS+BuKfNavcy4eFgEmsiA9DhzBh90QihPb4nu7PNFGpvLmKAO0JL4AY+k2fbJpOh62D1Cg1Gyd6H9QCCjetCs4hYXH5dnNTVDRGjQ4PI07e6FwhNMDbVM+FU1ATMdnwuv5SmrOOVr4HJjZrDe4H1xtgK0SCSYlN8aMtmreLAax5A8cDXBxnJme/8xQdL/fvAtyrfMMlXqKa4HvvBhRhmeZjp33USJqOQxoIkWKdLlEfAvc+AOOA+Gm6lRLL/O3ryCIosy1UQ6KAG8KRN9LiSMtCT1W9CJ0v1BKUA4HrFNnXeLAQy1TTz9Mqbh7hWkWoW5TUfoNOSvFW8= 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)(10201501046)(3002001); SRVR:BLUPR12MB0433; BCL:0; PCL:0; RULEID:; SRVR:BLUPR12MB0433; X-Forefront-PRVS: 08118EFC2B X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(199003)(189002)(42186005)(97736004)(3846002)(6116002)(2201001)(5008740100001)(5003940100001)(36756003)(586003)(50986999)(101416001)(48376002)(77096005)(19580395003)(1096002)(92566002)(189998001)(86362001)(5004730100002)(40100003)(5001770100001)(66066001)(4326007)(47776003)(53416004)(15975445007)(19580405001)(105586002)(106356001)(229853001)(87976001)(50466002)(50226001)(122386002); DIR:OUT; SFP:1101; SCL:1; SRVR:BLUPR12MB0433; H:ssuthiku-ubuntu-lt.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX: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; BLUPR12MB0433; 23:WOHFtWFGLllLw5oip5n/7qZ1kdbKUsld59rG0u/bP?= =?us-ascii?Q?riVpUy9T1vfASaAqHBxMhvwhklEEPtu0Xd8poTd0VDtagSkoBjP7fIFj7Tqo?= =?us-ascii?Q?3aLEGARWA2sMninI45XVhUalS4OV8JBK6dqA0NgChCTrJXbHHteKJ339gFoH?= =?us-ascii?Q?0GwomYCNDxOkUDipLjPEpiTDdGfmze9DhGOKwoCvN6gLfBZtO+jB0ruWxlnl?= =?us-ascii?Q?OTK4VnLS3HbKXr9zX/bEISWHWHBeC4NZt2dBFABbSjWnIkG3NUK3cLs/I8C5?= =?us-ascii?Q?v1Owxa06QEBTCr0kBn3RYD9qpsAgrksrhb3RYB4km1/iWjlFd6KXR0yAiz9K?= =?us-ascii?Q?J0uA6oA1sXC/aQTVUIiNnqpGNWgUjQjh3Be005lB8T1QAXDhQWPDEKhwDlh+?= =?us-ascii?Q?sV8kjsU4rVpkNE2vYPe+Anp+KLRhm7E1HzTZjPIecPfxJuNsQcoAmGPFqbGy?= =?us-ascii?Q?Zp+UoVeZFi6P7yWMpkt/OMnENOCDJbqt0YoVZOZcPvsyHXRPAIpd9/wnAPPM?= =?us-ascii?Q?gNA0mSwl6pG/3JG24TR9zEyJztmys6afQne6eBF7jJZCL6lS0k6UJdDyaVHl?= =?us-ascii?Q?SvO0smVqJ21f2NPQMU7TdfgC8jUaH4SmUWSkOcCFrY4XQyVKn3qwpFkJFZ0N?= =?us-ascii?Q?R2sULqq+tXJ8So7GS2WN6Qidw21Mg7UdiEQvMCbMH8wFulKoGWEqE2rlw01G?= =?us-ascii?Q?xad/I411cjAK+3HIrS7sgtXL/1fayygGK9i7f6BZqaOZDuqDjb0NSiVfw93f?= =?us-ascii?Q?5wv30RuHKBTiscAwVCMiDiLFewKEeDqK+JxL5mvhiFOzp1CqYI+vyh3wpOU2?= =?us-ascii?Q?ESIy1IQAKCV++PipSKg3bzpXn+MDZGDZ2Gr3OciBdYqSRPq6r+OTB2tHE1ba?= =?us-ascii?Q?i6tOM0KFDgk+Bw2bx+EeOMs58SfoNRI1KiPOn2H9wYI3G7li/spGHyLBor78?= =?us-ascii?Q?45Zjm3KkzPQBMOBMqkXq3aEOTkAglL05ud9cMuf5yNN8Nq47i6QWz9D4g1Bb?= =?us-ascii?Q?YE=3D?= X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0433; 5:9DRrVTQHf6VY1dbXDbDjd3OBYxN+QHzRArq7e8X5hEq/KYh+cwoBzjeBUR+QF7lrqDlaQhFJB/C21VPSC6CebrxzpUjYYS2oEOuISZK9lqv2zYSoCk2gCIdwQENq7ZZlvNpI8j2h9nvanZCQH0aUjA==; 24:pW1ftnhhjQtMtKVa5VzSy+BDV//OKqumsDskZdtPFA2zMhZxS6TTcNLoCFHMlPyg7nJuv+ujPepQViCjNTaGRPorVszRyO/VgtNXDglzlgk=; 20:ANj7V8JnDaQyauigwXUGkVb7EfoUUzZjPUKRm8bbYK6clKI5lVdw8ci88LwuVjIR2KyQGeJSERr5NmCd6DL/8DigfkvuB61RPuBqURZ8SB2waJRTucKF0nJNAPVuisnXVtwfHk98LhF0IkGJFYGKcg5usWRliUFeBsb5ToAEWsk7YuJUyJ7sNsZ/995AZV2segU5Hha9NdkvwamGSloO1n24mt2QS/FeZscflk7NI8PDFz5bPlX08UtRM4xOhDty X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Jan 2016 15:17:58.7790 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR12MB0433 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@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 Tested-by: Loc Ho --- Note: This has been tested on AMD Seattle RevB for both DT and ACPI. Changes from V3 (https://lkml.org/lkml/2015/12/22/596): * Add i2c_dw_plat_prepare_clk() per Andy's suggestion * Add tested-by Loc Ho. 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 | 31 +++++++++++++++++++---------- 2 files changed, 35 insertions(+), 18 deletions(-) -- 2.5.0 -- To unsubscribe from this list: send the line "unsubscribe linux-i2c" 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..965512c 100644 --- a/drivers/i2c/busses/i2c-designware-platdrv.c +++ b/drivers/i2c/busses/i2c-designware-platdrv.c @@ -128,6 +128,18 @@ static inline int dw_i2c_acpi_configure(struct platform_device *pdev) } #endif +static int i2c_dw_plat_prepare_clk(struct dw_i2c_dev *i_dev, bool prepare) +{ + if (IS_ERR(i_dev->clk)) + return PTR_ERR(i_dev->clk); + + if (prepare) + return clk_prepare_enable(i_dev->clk); + + clk_disable_unprepare(i_dev->clk); + return 0; +} + static int dw_i2c_plat_probe(struct platform_device *pdev) { struct dw_i2c_dev *dev; @@ -205,16 +217,13 @@ 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 (!i2c_dw_plat_prepare_clk(dev, true)) { + dev->get_clk_rate_khz = i2c_dw_get_clk_rate_khz; - 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 (!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 +306,7 @@ 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); + i2c_dw_plat_prepare_clk(i_dev, false); return 0; } @@ -307,7 +316,7 @@ 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); + i2c_dw_plat_prepare_clk(i_dev, true); if (!i_dev->pm_runtime_disabled) i2c_dw_init(i_dev);