From patchwork Mon Jan 22 09:53:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 10178025 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 1953660224 for ; Mon, 22 Jan 2018 09:53:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0B57E27F88 for ; Mon, 22 Jan 2018 09:53:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F3A2327FA3; Mon, 22 Jan 2018 09:53:38 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,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 3FB0E27F88 for ; Mon, 22 Jan 2018 09:53:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750890AbeAVJxg (ORCPT ); Mon, 22 Jan 2018 04:53:36 -0500 Received: from mail-sn1nam01on0052.outbound.protection.outlook.com ([104.47.32.52]:31904 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751101AbeAVJxd (ORCPT ); Mon, 22 Jan 2018 04:53:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=analog.onmicrosoft.com; s=selector1-analog-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=8wxBjqVHyE7oN4Zvakb152snmG8ifavn2xDqgto3oQg=; b=nWJtDV3oypY0D8hfkx4seqIY3y+UyNky7aT1ZZsXgTtFrLHYFyn503DbR7BmNbJAKEetPNG4HVDVd5fXILmM9A3/zqQA4X1bT+5A5nQdb3K5idIxS8mI/EStAYWBCWDvG8Vp3e2zplIPNPZyW/Tk+CNE4/wKzEEZ2W1rVNMUom0= Received: from MWHPR03CA0012.namprd03.prod.outlook.com (2603:10b6:300:117::22) by DM2PR0301MB0703.namprd03.prod.outlook.com (2a01:111:e400:3c0c::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.428.17; Mon, 22 Jan 2018 09:53:31 +0000 Received: from BY2FFO11FD018.protection.gbl (2a01:111:f400:7c0c::191) by MWHPR03CA0012.outlook.office365.com (2603:10b6:300:117::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.428.17 via Frontend Transport; Mon, 22 Jan 2018 09:53:30 +0000 Authentication-Results: spf=pass (sender IP is 137.71.25.57) smtp.mailfrom=analog.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=bestguesspass action=none header.from=analog.com; Received-SPF: Pass (protection.outlook.com: domain of analog.com designates 137.71.25.57 as permitted sender) receiver=protection.outlook.com; client-ip=137.71.25.57; helo=nwd2mta4.analog.com; Received: from nwd2mta4.analog.com (137.71.25.57) by BY2FFO11FD018.mail.protection.outlook.com (10.1.14.106) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.428.12 via Frontend Transport; Mon, 22 Jan 2018 09:53:30 +0000 Received: from NWD2HUBCAS8.ad.analog.com (nwd2hubcas8.ad.analog.com [10.64.69.108]) by nwd2mta4.analog.com (8.13.8/8.13.8) with ESMTP id w0M9rTU1023214 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=OK) for ; Mon, 22 Jan 2018 01:53:29 -0800 Received: from zeus.spd.analog.com (10.64.82.11) by NWD2HUBCAS8.ad.analog.com (10.64.69.108) with Microsoft SMTP Server id 14.3.301.0; Mon, 22 Jan 2018 04:53:29 -0500 Received: from saturn.analog.com ([10.50.1.244]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id w0M9rR7h023350; Mon, 22 Jan 2018 04:53:28 -0500 From: To: CC: , Alexandru Ardelean Subject: [PATCH v3] staging: iio: adc: ad7192: fix external frequency setting Date: Mon, 22 Jan 2018 11:53:12 +0200 Message-ID: <20180122095312.1150-1-alexandru.ardelean@analog.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180118144449.20115-1-alexandru.ardelean@analog.com> References: <20180118144449.20115-1-alexandru.ardelean@analog.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:137.71.25.57; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(396003)(376002)(39860400002)(39380400002)(346002)(2980300002)(438002)(199004)(189003)(2906002)(76176011)(50226002)(7696005)(51416003)(8936002)(1076002)(246002)(2876002)(8676002)(2950100002)(6916009)(356003)(86362001)(575784001)(86152003)(7636002)(305945005)(5660300001)(6666003)(36756003)(47776003)(106466001)(50466002)(2351001)(48376002)(53416004)(336011)(107886003)(26005)(77096007)(54906003)(4326008)(316002)(478600001)(106002)(16586007); DIR:OUT; SFP:1101; SCL:1; SRVR:DM2PR0301MB0703; H:nwd2mta4.analog.com; FPR:; SPF:Pass; PTR:nwd2mail11.analog.com; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11FD018; 1:UvihoFJ70ChmkSgma0Og8nU10IM01hYzOlW1jc2t6/YnRlx+5/dGm0cME+VhvC93U2/R0tauzugHpmzlNYfLqFjtbPNif8YNQDnJEVkPVEtcj8K36bw2/gNDsmWZVakm X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d44b08bd-a4f8-4169-00c2-08d5617dfe25 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(4608076)(4534125)(4602075)(4627221)(201703031133081)(201702281549075)(2017052603307)(7153060); SRVR:DM2PR0301MB0703; X-Microsoft-Exchange-Diagnostics: 1; DM2PR0301MB0703; 3:ogrkKq6azoux4qDX/HGo35e75Ea6A4CH1U0Y1dpxZC3zmCrqv0bmXT/NKH5imIamQvE0A783K26qhNmiqjF9FAQuvBrrnaxFmb2M6GJLNmKDQxzoSunkfQbqUtVGGEjLhNx/v7qaVxNMt75I/TUloN+ThMYT7Zlgz4gUQCjprL7Wd7eV9ODjqVE4RpG/bgwz3s59BK3ZV2k0SH4TMFDaYJAgNz7XJpOqXnPDVA6sxbZblUd1kk3K+2OC98mLwd83jg5qBpfvp5pK+7t04ny3d4Edq1To59sCt7RqjS6mcPRebI0t6uOtSocD0VNR3dz+QJNCapf++SdIWVwpEqHDAg==; 25:UKUisGxSlc2H2likbzCag0pkTlJcohFFlA0et7KR8hTVd1V4fxBcczD1mNMjsx5j/jpaQ9Uyaw28Dn4WFYsE4bGYDdlKnD0huPJaOObhURKo71u0Jv6bUWbJ3BTnl62UCrnxqUnpV2lOer98NSSGLWKjLJrC91nL+plR9EZhihc218+BAoWNzjrLTGLeT5T6yaAvv7tUF51Vk7rY3sgjc5JQ6wUPKXcq3wSTBKmdPA32fbrTXr1Emo+qmbwZ/NeHSCqwhf56y0ir5BNxGRc8R0zLORppe6K33ARDO0sbIeJUv3m6qTe8BXmrM7tt+qztLsoZd7jcCCuQwiDbFOXuSQ==; 31:5Ei6qmJCvzKCu/Ca+PFznCoe6zEUtmjXsQG3J52cxcmKdtoCy8KPP/mCCJa34fuewPg1cGGdCBcxJjBGHjo9sDLZpjy0LfeNKOD/mrxZGOwo0uWQnsBNtf8NomUr64lXVSnqNuYPKy14h54panEtB8Dzsdb86vR0qVJfyc6bc23EZ5s9vW2rZJDqK87q3xE7/ch8GGsZYXxj0ycGr+dSVD/lyqGhzdCDRsApkISN33A= X-MS-TrafficTypeDiagnostic: DM2PR0301MB0703: X-Microsoft-Exchange-Diagnostics: 1; DM2PR0301MB0703; 20:3s1LeJQpvn8V9O/aOcU3hgZtfbpSnacyKAONgP1fSoKP3/91/xBICcxH+CTK723TCW0hsiPdS6qvcOsYisQATSRgT8KGWmb7EPh8//0mgHItNRf4EgQP1JEIH+DyTUt3HxXnGvWBVwAcRWSDpZvSxADHuxP6UMeFU6G8GiE1B5w3qDnl7QY2zinhjnM1Alei5u1Q8JF9Ym7DtWQNLiVNyoO2FpeWbz1wpbhwO3VkC9oGkZHhtixrtyNuN+VaUUsb5KLlYC4VmbbHSgcow2DnHqW6cp1wgOlRfZw29fybN4YN9JjCt5WRIihMg2QuwrmKpKM9vA66SF8ad2GLR00PpB+cRZXIbSfcXE4T/nZhZ0xuhebo9uhkqFJAnWQhrVutl7GcZc36FnvB1qzaZuS2U5KFzPgy/9dWWtjlmzyZZbAuCGZSVNpgY8T9xzgd7WBbM+5j4D4yKva5nqaVXWbuW1BWnxObiBPml6GEb0lNjlpx2LPK54L8sduNmPncUF0v; 4:Jwc0BbgbN13+CkLHgEOA26/05EZZmIzFssyGwVwwHmgXOofVMoBhvmHD33hruA8VJzPOtDkIuOsfbAlnYBo6jah9Yma4nu6EiJnmQGztdnsfVkVGmCQLZEaqemW6aIWehfj2ojZpbBVZuxr78ibsfE75WxFId7zFxi+bNO6rWxMho+6F4RG2Y2k7/lhS3iiZpjOUQjP5qTlQIh1GVwZO42n7kmx0TNKeb4DgSTXjSKU6b3JuVuBGsjdN4tL8JS22nIrbzUGGtqIOGFup6cz++ndNez+M40bYICaQFDXph52bR2v/F2w9GpwWM0DxPCRR X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(232431446821674); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040501)(2401047)(5005006)(8121501046)(3231023)(2400081)(944501161)(93006095)(93004095)(3002001)(10201501046)(6055026)(6041288)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123564045)(20161123560045)(6072148)(201708071742011); SRVR:DM2PR0301MB0703; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:DM2PR0301MB0703; X-Forefront-PRVS: 0560A2214D X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM2PR0301MB0703; 23:tzlyuNzP6rtbQlyRTrPLzPey0ythIvn89Q+TvXz?= =?us-ascii?Q?J3s3hwAXmUwypOVXFJACmQXiIpsyYaS/q9DlBgTBME2SCaEX+SOiOhcsD5b1?= =?us-ascii?Q?oNNek2hCSueBblJILLP2FWUd9HHKrRlrxIf7cOBztDYo3OCBl43YT4IUcXiN?= =?us-ascii?Q?A44WRaBeXOEbgrUj9gBvHncK1gn+KNIljF3Z+SqJS4gFFeVi3qsJogZ1n4Pf?= =?us-ascii?Q?ZFCB1l8rJ3x9vgYJb/92rGILsMXN60ETF4rfAOTsRJmfdCaCKTDeaND9Tu9L?= =?us-ascii?Q?npVNg23p9ZVhvJA+23pUq9w49yljnwMHgdDRhs3x+CruMHucOwm3eVVN5Vkr?= =?us-ascii?Q?OA+6AVBB4axAtStW7Ar2aqqTlJV6FrpaVhZHaNDQ1KxVDdAA6Soxy21KlZ9r?= =?us-ascii?Q?5JlYnDPpU8gVKl7L5qUT7kxAWEZYdVN86K+19aTW+3KDO+3/11p0wgZpZnyP?= =?us-ascii?Q?KBbWrV2scZD7mMXj7Fntjqg51Li8XYZKDf8CWtkY11MEyNycOgBaH/VI7Tk3?= =?us-ascii?Q?WESHVBsXcO+WwrZIqrGPEvI8ylrsPDW7S48EUPIdABpRebFuGMURqcJttIcb?= =?us-ascii?Q?hReea20OKmkeA8rzXBtVXwL7JzykxqNOWIi4HX+xZSpwFNlwjWZGZjRjB24v?= =?us-ascii?Q?MPaw/4bZDQZxGzxgrNXOjCMB3lAWa6JS8qPl63/KxuAsePKUJTuuCI+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XTVOj8uQ2ey+bAoPbAXiifwsYdNcEYxPMhtLGLa3ML94XM4+Py3wWbBtsKBA5aYhEDz2nqPoZekH6MBXEa4=; 7:dyqiuV0TfVXIW4AWl9xs8Yf6/Lwy9b/HGOrpe8l73lP6b+ab4a1LyIFPZP7WGlKRlWlUhazEn5FcMFyLIvsY42Pt7bQap7fP05/SWhpjZzsaIlOXmWl0rSyRvaopJBDFKmGrMjjtZQziIhfP6D+Na+ydQUs9aRNP7qMAJHaXa5Z6k94plBA39P1OPmbROoeHDBoRZW4ZoPj+SrrQUGl8ADLMrx/K+F/geUzwOhTGClegGliTclpYvW0Z/Ivoq2wa SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: analog.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jan 2018 09:53:30.2629 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d44b08bd-a4f8-4169-00c2-08d5617dfe25 X-MS-Exchange-CrossTenant-Id: eaa689b4-8f87-40e0-9c6f-7228de4d754a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=eaa689b4-8f87-40e0-9c6f-7228de4d754a; Ip=[137.71.25.57]; Helo=[nwd2mta4.analog.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR0301MB0703 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Alexandru Ardelean The external clock frequency was set only when selecting the internal clock, which is fixed at 4.9152 Mhz. This is incorrect, since it should be set when any of the external clock or crystal settings is selected. Added range validation for the external (crystal/clock) frequency setting. Valid values are between 2.4576 and 5.12 Mhz. Signed-off-by: Alexandru Ardelean --- Changes v2 -> v3: * changed fallthrough for AD7192_CLK_EXT_MCLK1_2 & AD7192_CLK_EXT_MCLK2 to `ret = -EINVAL` + `goto out` * re-phrased commit comment; to make it more simple/direct drivers/staging/iio/adc/ad7192.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/drivers/staging/iio/adc/ad7192.c b/drivers/staging/iio/adc/ad7192.c index 9287b50b7870..03aba22093a8 100644 --- a/drivers/staging/iio/adc/ad7192.c +++ b/drivers/staging/iio/adc/ad7192.c @@ -141,6 +141,8 @@ #define AD7192_GPOCON_P1DAT BIT(1) /* P1 state */ #define AD7192_GPOCON_P0DAT BIT(0) /* P0 state */ +#define AD7192_EXT_FREQ_MHZ_MIN 2457600 +#define AD7192_EXT_FREQ_MHZ_MAX 5120000 #define AD7192_INT_FREQ_MHZ 4915200 /* NOTE: @@ -217,6 +219,12 @@ static int ad7192_calibrate_all(struct ad7192_state *st) ARRAY_SIZE(ad7192_calib_arr)); } +static inline bool ad7192_valid_external_frequency(u32 freq) +{ + return (freq >= AD7192_EXT_FREQ_MHZ_MIN && + freq <= AD7192_EXT_FREQ_MHZ_MAX); +} + static int ad7192_setup(struct ad7192_state *st, const struct ad7192_platform_data *pdata) { @@ -244,17 +252,20 @@ static int ad7192_setup(struct ad7192_state *st, id); switch (pdata->clock_source_sel) { - case AD7192_CLK_EXT_MCLK1_2: - case AD7192_CLK_EXT_MCLK2: - st->mclk = AD7192_INT_FREQ_MHZ; - break; case AD7192_CLK_INT: case AD7192_CLK_INT_CO: - if (pdata->ext_clk_hz) - st->mclk = pdata->ext_clk_hz; - else - st->mclk = AD7192_INT_FREQ_MHZ; + st->mclk = AD7192_INT_FREQ_MHZ; break; + case AD7192_CLK_EXT_MCLK1_2: + case AD7192_CLK_EXT_MCLK2: + if (ad7192_valid_external_frequency(pdata->ext_clk_hz)) { + st->mclk = pdata->ext_clk_hz; + break; + } + dev_err(&st->sd.spi->dev, "Invalid frequency setting %u\n", + pdata->ext_clk_hz); + ret = -EINVAL; + goto out; default: ret = -EINVAL; goto out;