From patchwork Wed Sep 27 14:52:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kamlakant Patel X-Patchwork-Id: 9974199 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 7E187602D6 for ; Wed, 27 Sep 2017 14:52:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6F9B628BEA for ; Wed, 27 Sep 2017 14:52:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6427928D4A; Wed, 27 Sep 2017 14:52:40 +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=-5.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_WEB, T_DKIM_INVALID 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 E4A5B28BEA for ; Wed, 27 Sep 2017 14:52:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751915AbdI0Owi (ORCPT ); Wed, 27 Sep 2017 10:52:38 -0400 Received: from mail-sn1nam01on0064.outbound.protection.outlook.com ([104.47.32.64]:21856 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751856AbdI0Owf (ORCPT ); Wed, 27 Sep 2017 10:52:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=8eDkXi/BKtdGUvPcaNxdsOIejENPCda1Boz8xJrwBTo=; b=emxR1ZhlMTb3Hvd2MhvLp/Fy/EpP/8WK5BPPagtLAF/24GC40y6AJy+tOqc4CIhUDUDCk/NL79/KGJz/HCrJBg3DROqqlPuNI3HY64RpJ8AXg1NeVsTC1t8jxaHGWwWQotZpHAO4XllhOK/xUC5oSDOb+jpGeJbqoQhWeQrgEVw= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Kamlakant.Patel@cavium.com; Received: from kamlakant--T110-II.caveonetworks.com (111.93.218.67) by BN4PR07MB2129.namprd07.prod.outlook.com (10.164.63.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.77.7; Wed, 27 Sep 2017 14:52:31 +0000 From: Kamlakant Patel To: linux-i2c@vger.kernel.org, linux-acpi@vger.kernel.org Cc: Jayachandran C , Wolfram Sang , Mika Westerberg , Kamlakant Patel Subject: [PATCH 2/3] i2c: xlp9xx: Get clock frequency with clk API Date: Wed, 27 Sep 2017 20:22:22 +0530 Message-Id: <1506523943-8632-3-git-send-email-kamlakant.patel@cavium.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1506523943-8632-1-git-send-email-kamlakant.patel@cavium.com> References: <1506523943-8632-1-git-send-email-kamlakant.patel@cavium.com> MIME-Version: 1.0 X-Originating-IP: [111.93.218.67] X-ClientProxiedBy: BMXPR01CA0043.INDPRD01.PROD.OUTLOOK.COM (10.174.214.29) To BN4PR07MB2129.namprd07.prod.outlook.com (10.164.63.11) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2fb33e8c-8371-42a2-94f3-08d505b76267 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(2017030254152)(2017052603199)(201703131423075)(201703031133081)(201702281549075); SRVR:BN4PR07MB2129; X-Microsoft-Exchange-Diagnostics: 1; BN4PR07MB2129; 3:vlZCfrae/Mt3UY7Es8dTj2DS58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PlR1reyEIhauFQbRA+Jt2caBntV9bNkOxcuSulxLO16GW5dL6tw//9AsUBO66cShLi0N4Y/mzmjk0wBfLo5aCb+zMvwrC4dhdbO8uXAgd8ZvSyU0cZNfHmFpCesYu4/TV0Zio/kDZ+82uYNM3bInXG9TULb48Sl0C+DpxWUeo46adYhv//8fQd6WlU/2r7lwzNl4DMZu8kEgvoncA6VB+hfGyZQgc5Bmm+pWWwDx1BfEarfvx6DnMaBELTlT60FRsPFnDsgAguHmNkDSfkwrlIlEMdpeY9G/MhtW94z1iA6oGjv+85M; 4:HBYsyFlAFz92MeuHTNcc6g5sszrroeqyeM9uwZRYttNVJ0zs0F48GRa6YkjVyWouuTsxVBqW/0dVRA1itwLwnSS5IH1/Z2aNFdCfjj1/ufStD04309BKi1KlFAwPiaKbLUMk9efKT+zFoMnyT81JtMsWlgA5U/AZxOtWEvPVWts2M4mQ5gaqffEHjzVSt8ZT9Wuy3EQOsUOoYGbcw7B/ObavF7pF54L5/xEHZ5rfL2X0rRlhg/X8m8vkgp+b1QF1 X-Exchange-Antispam-Report-Test: UriScan:; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(8121501046)(5005006)(10201501046)(93006095)(93001095)(100000703101)(100105400095)(3002001)(6041248)(20161123558100)(20161123555025)(20161123562025)(20161123564025)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:BN4PR07MB2129; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:BN4PR07MB2129; X-Forefront-PRVS: 04433051BF X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(346002)(376002)(199003)(189002)(2950100002)(47776003)(33646002)(48376002)(8936002)(66066001)(68736007)(305945005)(76176999)(50986999)(69596002)(5009440100003)(54906003)(53936002)(105586002)(106356001)(50226002)(101416001)(25786009)(53416004)(6512007)(50466002)(16526017)(6506006)(81156014)(81166006)(8676002)(3846002)(6486002)(6116002)(16586007)(6666003)(5660300001)(4326008)(5003940100001)(107886003)(36756003)(316002)(97736004)(72206003)(7736002)(189998001)(478600001)(2906002)(86362001)(575784001); DIR:OUT; SFP:1101; SCL:1; SRVR:BN4PR07MB2129; H:kamlakant--T110-II.caveonetworks.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN4PR07MB2129; 23:3mJ+GsDJUeGZjOAqmgaIuBWJtzZwmF1/otHiZIlYt?= =?us-ascii?Q?v3WISuXfLIRnWWWEVNckdqXfaAczp87nXVaI5FxTcesZNqY4fxQo/CrFKHvh?= =?us-ascii?Q?/mcmnK7FWyjra5BJ5k9cOJexe5D69+1W2aoTrvIzVCEqg5aZTI2+hJkiHjv5?= =?us-ascii?Q?nwzRdssIKQZU0JWN11FHoRewb5io2+ddNkEiJLlRq4UENp3d9fIAV/E4Rg+y?= =?us-ascii?Q?rsIaJ8Ymc9zoJM51L52fcT3h13FtbFfPtcO89mGwltyxDLzpbFlt+tQv3Sze?= =?us-ascii?Q?v3lBoMja2Jf8pe4fCV0ehVYeKZ2CYqxZ/kwtv0u7Q9BvP3VQ7inMpmS//K77?= =?us-ascii?Q?+Uf/Nq1guWyAk0GcpOfBfloSjP9peoVRy2Am4eaKJjVSVxZsEI9z+IVoDq11?= =?us-ascii?Q?oJsgbIc/7+i9KDf0G/K7VwQzmO2ErnxUCisQeO2lal700lmmGxB1g9USkfDi?= =?us-ascii?Q?Z9aamCCHTBPcR7k8fRZMn/QtiyKRmju+InPyli20XHJqyWuT16/AfUVt8nsy?= =?us-ascii?Q?k7MIixGxe1YeW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NcXTBfsNQpX5fTM0eRF75TMtPg8CJvTeCzmY0FuE6zL42vknjo6RfuqwDngmgPyuem6uPpE25RkpGSd5n23OSSdVaqawtKu0DxdooS0W0CHuALsCvYt/+KpgbCLXjEZYtbZk64ifZutpW8sA==; 5:9j7ezTd1z5awMVTlQmuA8aNVssPjKp2fZg8p8BKHOSxxBclN3fR3yFuFxsYaY3up5J435VDatd7J+tL3U4iltzb0/t5BXCbSBZNQHWzif2SYDOVstykj1KF9K1ntaQRxTh0/PJtDBtrlUbscyPRFRA==; 24:Z55aEhgginrLXUDpadSc4yevAtb2vafQnlXons/r5E6K8mUWeFIZ2eqwa4n5D419CQxlsdaDOlxInoWX+rtqmKXJSLUobX5lSA/8hUsEP/0=; 7:0ZeAZKg2K5+J1y7bs+yTtxcSBJZQVkpAgYUKZ1IjoEdZXlKIAQDJ+/8k91ONAlrlR7d0orb06qFXpvelYvrseYclrLOrjUMm6PEgoL7nrkreETyyTGuMF2VRJobPy6AiIkSDrDpC77I7OPH/t2w1tpbA/NecOkI526otW9Pp00zwi9zXGB85EipdkK8AnCwETOJb+jckmiPtiKEQjcGKR9lDfTHMub864ar2RmaaQZc= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: cavium.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Sep 2017 14:52:31.2308 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN4PR07MB2129 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Jayachandran C Get the input clock frequency to the controller from the linux clk API, if it is available. This allows us to pass in the block input frequency either from ACPI (using APD) or from device tree. The old hardcoded frequency is used as default for backwards compatibility. Signed-off-by: Jayachandran C Signed-off-by: Kamlakant Patel Reviewed-by: Mika Westerberg --- drivers/i2c/busses/i2c-xlp9xx.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-xlp9xx.c b/drivers/i2c/busses/i2c-xlp9xx.c index 6b106e9..f0bef2d 100644 --- a/drivers/i2c/busses/i2c-xlp9xx.c +++ b/drivers/i2c/busses/i2c-xlp9xx.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -84,6 +85,7 @@ struct xlp9xx_i2c_dev { u32 __iomem *base; u32 msg_buf_remaining; u32 msg_len; + u32 ip_clk_hz; u32 clk_hz; u32 msg_err; u8 *msg_buf; @@ -213,7 +215,7 @@ static int xlp9xx_i2c_init(struct xlp9xx_i2c_dev *priv) * The controller uses 5 * SCL clock internally. * So prescale value should be divided by 5. */ - prescale = DIV_ROUND_UP(XLP9XX_I2C_IP_CLK_FREQ, priv->clk_hz); + prescale = DIV_ROUND_UP(priv->ip_clk_hz, priv->clk_hz); prescale = ((prescale - 8) / 5) - 1; xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_CTRL, XLP9XX_I2C_CTRL_RST); xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_CTRL, XLP9XX_I2C_CTRL_EN | @@ -342,9 +344,19 @@ static const struct i2c_algorithm xlp9xx_i2c_algo = { static int xlp9xx_i2c_get_frequency(struct platform_device *pdev, struct xlp9xx_i2c_dev *priv) { + struct clk *clk; u32 freq; int err; + clk = devm_clk_get(&pdev->dev, NULL); + if (IS_ERR(clk)) { + priv->ip_clk_hz = XLP9XX_I2C_IP_CLK_FREQ; + dev_dbg(&pdev->dev, "using default input frequency %u\n", + priv->ip_clk_hz); + } else { + priv->ip_clk_hz = clk_get_rate(clk); + } + err = device_property_read_u32(&pdev->dev, "clock-frequency", &freq); if (err) { freq = XLP9XX_I2C_DEFAULT_FREQ;