From patchwork Thu Jan 18 14:44:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 10173461 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 9106E603B5 for ; Thu, 18 Jan 2018 14:45:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8056D1FE8A for ; Thu, 18 Jan 2018 14:45:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 72A6D26861; Thu, 18 Jan 2018 14:45:01 +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 B5A6D1FE8A for ; Thu, 18 Jan 2018 14:45:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756407AbeAROpA (ORCPT ); Thu, 18 Jan 2018 09:45:00 -0500 Received: from mail-bn3nam01on0066.outbound.protection.outlook.com ([104.47.33.66]:52512 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756455AbeAROo6 (ORCPT ); Thu, 18 Jan 2018 09:44:58 -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=wjeFqcvPVLrIUo+iHcyGa/VIAMb0waT7X8qali6cLnc=; b=cGFSe0QX8pUluYa0oFWaSydMuR6WZnyIXBhWQXVh4YRQP0wVKZN56UJvfSUzl6/fLvD2+RE51PMBXgiCChwVuYcOBSj/oyVw22In1CCmmJa+LLEY4eBFRi+KH0bLwAdW3mjzew1StdxiqB6qzjUVRNMAiNFwJyXvFGCRIVhkjVs= Received: from CY4PR03CA0102.namprd03.prod.outlook.com (10.171.242.171) by CY1PR0301MB0700.namprd03.prod.outlook.com (10.160.159.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.407.7; Thu, 18 Jan 2018 14:44:56 +0000 Received: from BY2FFO11FD005.protection.gbl (2a01:111:f400:7c0c::120) by CY4PR03CA0102.outlook.office365.com (2603:10b6:910:4d::43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.407.7 via Frontend Transport; Thu, 18 Jan 2018 14:44:56 +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 BY2FFO11FD005.mail.protection.outlook.com (10.1.14.126) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.345.12 via Frontend Transport; Thu, 18 Jan 2018 14:44:55 +0000 Received: from NWD2HUBCAS9.ad.analog.com (nwd2hubcas9.ad.analog.com [10.64.69.109]) by nwd2mta4.analog.com (8.13.8/8.13.8) with ESMTP id w0IEisEl018139 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=OK) for ; Thu, 18 Jan 2018 06:44:54 -0800 Received: from zeus.spd.analog.com (10.64.82.11) by NWD2HUBCAS9.ad.analog.com (10.64.69.109) with Microsoft SMTP Server id 14.3.210.2; Thu, 18 Jan 2018 09:44:54 -0500 Received: from saturn.analog.com ([10.50.1.244]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id w0IEipFS001783; Thu, 18 Jan 2018 09:44:52 -0500 From: To: CC: , Alexandru Ardelean Subject: [PATCH v2] staging: iio: adc: ad7192: fix external frequency setting Date: Thu, 18 Jan 2018 16:44:49 +0200 Message-ID: <20180118144449.20115-1-alexandru.ardelean@analog.com> X-Mailer: git-send-email 2.14.1 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)(39380400002)(39860400002)(376002)(396003)(346002)(2980300002)(438002)(189003)(199004)(2906002)(1076002)(246002)(2876002)(50226002)(36756003)(575784001)(8676002)(5660300001)(7636002)(8936002)(86362001)(86152003)(6666003)(26005)(316002)(305945005)(6916009)(50466002)(478600001)(107886003)(356003)(4326008)(48376002)(106466001)(7696005)(2351001)(53416004)(106002)(47776003)(54906003)(77096007)(51416003)(16586007); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR0301MB0700; H:nwd2mta4.analog.com; FPR:; SPF:Pass; PTR:nwd2mail11.analog.com; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11FD005; 1:v4PigU0NJp3yzpgo+qVtfzjC+JPdCmNcKFeAB/wbZTSl9EOG4yeLjPclzhfr12gHj1C+SjzeCkBk109en/vudJRJg86pqwRDurgOzM/8O3/bCjVzw+b9CViDywUH4hHZ X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4b367563-f839-467e-409e-08d55e820ab8 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(4608076)(4534125)(4602075)(4627221)(201703031133081)(201702281549075)(2017052603307)(7153060); SRVR:CY1PR0301MB0700; X-Microsoft-Exchange-Diagnostics: 1; CY1PR0301MB0700; 3:SJ+q3llt6GgZ8Mr4A/u8p0rhzXLBYpVWeXRIcHZ2n2J9mxG6gkIr/URAd2RQkMOJaHnEOO4Z9XQ2o8dQVj+fynE6NjA9TpHL7HO6zw1YYjlxVHXGIdSxCMHcz5Qjlm9keZpaTi0mySc+POWC+jpt1GkIdNOmOBPq1Bfuok9+56G3SY9bQ+2+ltKO97dz9Bsn9gygntXMGKD+71YSDvbv+f56va6x9fvu6TWagrJ5bzMtxiWJg2FO+iH0S9B2jqGfhdUUkSEu/A1pL2Ri2sTNMmfgY2BVcDfhVqR0ijue8rOeen3wsyigWuzLLM/ZEdMfrk20waviO6NlbtUlH1rQsg==; 25:cma0bnGwJoD29LnlIU4mW51m2CR6xAAWT5q/BWRfNZuLtaKZbIsLUYClCziwyIYMcGeMwif3/eR6K6ohSqhL+tFcQFeSYxuLlFoBsd1c19ifDNxDKC+GTz7IIJW8ZSRn5Dq3C2XC8QYA8d7BsRc6RpGAlYLXv5nuQLK5VdxroPuwgnbwoDeMWIlJZ0nfKc0qAFToSpFPrQUVkvwjAWE0qPypTp9qUooSli42Ve1n+TlEGdTScbG1yv8L08CIBvjcplz+EgQVtNG2mJQR25rM5Ndv5Q3uHGuuxubUxY6vIqIMm5im+UOU7Rs2VSSQQguqKM4f1qk/ARf3Gms4PSmf3g==; 31:wgRurnWnbedCYIVoobdYYNvczoc9VwHw/986CrijxOd+BSoE8wgmtUuX7qJvD1GOt2hKJsjulzNQI95KUkO5HHADFSaqQdIUUwNonCjt8g9/qj7AebYDNoh6iBD8sWpq9Wsh6rRCWWzGdvARPrLSnGKs8JiHmgXirsrZwxG0CCqot1ySTCqrGb7T3yQhNZwj/NrNGhrkEogeEeK7lcA6hriSpIAECk2qBaNLuVdLIOE= X-MS-TrafficTypeDiagnostic: CY1PR0301MB0700: X-Microsoft-Exchange-Diagnostics: 1; CY1PR0301MB0700; 20:qkxRXvaa4gm1Y28pU43OFAZ5wvkc8avMOZyz5sFqmiFQGJkKBwJqyyFlbyiRdde857pI3m2UVmHVxnHizpgJr1irg0Nc+7wsIMZ5RGcP6ozUJtRkhZwUcD0p+LWNVlDXHlViQJlDvaz6Tm55xTPDPZKLsfqHycudwcW071TkeImMBoP0a1+MC1WX65GpFWu3RNPM0tRfrLZrty7Me5oHTzmcY2bK1usg9rp3JKJERHazdIQBnSjm5uD9WigPsGWAFFlf1UvnzijgAS1sla8/1xBeriuXmSVbs9Xu27xWUsc7ARRMRJ7+dXVmE/tjlrP4dDXdA2kgwo4jbJY+I0kExQWiA9g7rbNaleKPyPCj3tmcE6RSMtW0Xt1bP6jBGVwY3IrVDPElhRU9frPjaxV3xUS40MBFmmeLu7uf+sDSq7Gj1TyHNzDnF1hws3f7nc59DrAYqFmoZkBmLo/n0jgol2Ch+5f1XDuZFp1h42qA+0mRKvu+0c/w312x1yT1lgPD; 4:dGv0jdNQs0ECV50I8xSO8NPUG1A1uPWZKqY0avSqqImxqjZW0RuQObMy5WXuiR2TVjnIlDFma5xSRHIfpk6HBIHsQDvReBPU5BU9jZJ+6aTbE+usODsNLW8s5yZ2qCKkGUPhNJBpxZjWMg1p1CwKC71t2zihpCoflBloLt92TJpluUblS/ApVhaq65/Xf08ApUibAXfLNfidUjpB+D4mi5HGwExuqCU1P6yZVcjwurHjWQUa4W4tsMjRpZDodOSo4T/YHIjLPN2R1awbKV4xexAIz40QPJe2DXKyM+NzAikaK0Gfssl9LEacAmGqQ+bi X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(232431446821674); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040470)(2401047)(8121501046)(5005006)(93006095)(93004095)(3231023)(2400063)(944501161)(3002001)(10201501046)(6055026)(6041268)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:CY1PR0301MB0700; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:CY1PR0301MB0700; X-Forefront-PRVS: 05568D1FF7 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY1PR0301MB0700; 23:iskEr3wbU4xIWjTPGyQf9zM9ek7l3Qe3N4X6XUC?= =?us-ascii?Q?hf/dX1HMGR0K7IrK1nxoH8QHZGVNI2g+dbG/Lmep9hYXcteXsdj42YMVcNWf?= =?us-ascii?Q?VKNXU6Has4ofmKFZi1lKab3gKoSOCvPvNwzIYLRhMjJDcRU7J2Lm71n1/4IR?= =?us-ascii?Q?dE2jeJ/U2cLvohG5etPcRtFlZhctDx2mr4HkA5lGLeQ3uRDNFw7rV3KN1qml?= =?us-ascii?Q?aeiKOmrWFWZsDNVSHbT2kV6Xx4J/UftypdIx3gTHie20orH0XF0qpMWuEdf6?= =?us-ascii?Q?Nn03DLI0sn7UEw4+VV1JL/WF7rWtA4PsC+0nHc1RAPKyVJXBEs2rAa7XZ9yj?= =?us-ascii?Q?SNl9sLcstS8cU+EeXzonvi3ep3UW+c41Y10cQcM3xg29jCRaPC/Wt10yeKpf?= =?us-ascii?Q?825HcLu8CSCrplFEbEISRrnMhdxNFH1RF4IZBXnfIHXlrqlThfajgsoBEM2I?= =?us-ascii?Q?o2FRiFVW7e9vY5mVUwurPdf4QfehIMVqByaUlX6AzG3jbDrheIyjkd6LSIh4?= =?us-ascii?Q?9CTFhUlKSXdIjR12TNRjOYmWsrV6N1v8sM0ReEaqVYUI9LI3Bp5h4AtgckAV?= =?us-ascii?Q?E7WnbEA1EnfaCkyfG2wMd54/sEKWUvcHSOKMrT3yZ0nS458yxNMmZNXFeMnI?= =?us-ascii?Q?3v05h4hVkia4i3yFLzWPN1jInk3OYagwunhd0dj3DczTD95EnyNMsEHRqSLX?= =?us-ascii?Q?g3YVSZJ14W8amRvwnEjtwewr1eJpE0h1f2f7G/kFwCh8xa4SLTuGrgq0Ii7P?= =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kcfwcEAffurL7+N8kX0eYNnVzTVOrz1ll0B/iIZaYoT3EmcQnSNrM2YIQ0pKvA8hk4FrVwb3tVdMI4/N75tPkQH5dmidqNfrWkJ8s16oWBFzK+josVsiKUl73Nw4uMM4ZG5WUhfC0D0Dj6NokSoh8LZuWi6SspYkGQEXP2aRd6SE1pdX/Iw2rMn6GuE9Jh3coeQYVwLOFMj9 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: analog.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jan 2018 14:44:55.7343 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4b367563-f839-467e-409e-08d55e820ab8 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: CY1PR0301MB0700 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 validating the external (crystal/clock) frequency setting. Valid values are between 2.4576 and 5.12 Mhz. Signed-off-by: Alexandru Ardelean --- Changes since v1: * assign frequency from `pdata->ext_clk_hz`, not `pdata->ext_clk_hz` * check frequency range for both crystal & (external) clock * print error if clock range is invalid * patch was split away from patch-series (for device-tree bindings) drivers/staging/iio/adc/ad7192.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/drivers/staging/iio/adc/ad7192.c b/drivers/staging/iio/adc/ad7192.c index aebbc3b58194..6d110f817b4e 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,19 @@ 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); + /* FALLTHROUGH */ default: ret = -EINVAL; goto out;