From patchwork Wed Jan 10 11:29:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 10154949 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 536CC601A1 for ; Wed, 10 Jan 2018 11:30:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4444E26E75 for ; Wed, 10 Jan 2018 11:30:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3897627CEA; Wed, 10 Jan 2018 11:30:57 +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 876A926E75 for ; Wed, 10 Jan 2018 11:30:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932525AbeAJLaz (ORCPT ); Wed, 10 Jan 2018 06:30:55 -0500 Received: from mail-by2nam03on0084.outbound.protection.outlook.com ([104.47.42.84]:11584 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932174AbeAJLax (ORCPT ); Wed, 10 Jan 2018 06:30:53 -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=m8zugV2Prcx1V8vnBNIQDRzqoQFoqzCClsn6NosSTKQ=; b=KKmuQn3RNpKYDwfTqCNPzNoWg5gBjvZ2cj6tZlIYR6ANgKzqGdT73rTMWvgqt+/9xi7SAHIO+pXFAl4lowVr3WeWp0/5dUj0sAjYq9u0Mr+DapdLWkXLC4NZ8u1OAH20aN0xBZmUMU4iTyymdHzf81T735y50eR/GA8HYms6Dc8= Received: from BN6PR03CA0020.namprd03.prod.outlook.com (10.168.230.158) 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.366.8; Wed, 10 Jan 2018 11:30:52 +0000 Received: from BL2FFO11FD012.protection.gbl (2a01:111:f400:7c09::134) by BN6PR03CA0020.outlook.office365.com (2603:10b6:404:23::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.386.5 via Frontend Transport; Wed, 10 Jan 2018 11:30:51 +0000 Authentication-Results: spf=pass (sender IP is 137.71.25.57) smtp.mailfrom=analog.com; arm.com; dkim=none (message not signed) header.d=none;arm.com; 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 BL2FFO11FD012.mail.protection.outlook.com (10.173.161.18) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.345.12 via Frontend Transport; Wed, 10 Jan 2018 11:30:20 +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 w0ABUpA5020556 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=OK); Wed, 10 Jan 2018 03:30:51 -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; Wed, 10 Jan 2018 06:30:51 -0500 Received: from saturn.analog.com ([10.50.1.244]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id w0ABUWKp022377; Wed, 10 Jan 2018 06:30:33 -0500 From: To: , , , CC: , Alexandru Ardelean Subject: [PATCH 1/3] staging: iio: adc: ad7192: fix external frequency setting Date: Wed, 10 Jan 2018 13:29:54 +0200 Message-ID: <20180110112956.23931-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)(396003)(39860400002)(346002)(39380400002)(376002)(2980300002)(438002)(3190300001)(199004)(189003)(106002)(4326008)(54906003)(51416003)(16586007)(106466001)(50466002)(8936002)(77096006)(1076002)(107886003)(86152003)(86362001)(575784001)(47776003)(110136005)(50226002)(7636002)(2906002)(36756003)(2876002)(8676002)(48376002)(305945005)(478600001)(316002)(53416004)(246002)(6666003)(5660300001)(7696005)(356003); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR0301MB0700; H:nwd2mta4.analog.com; FPR:; SPF:Pass; PTR:nwd2mail11.analog.com; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11FD012; 1:U5l1s5191pb9suyFJc+GfGvTVpWYDIUafVR+1zcWbqjdkbz2TelJ7bNEwprkEoLlXs9kZ5Cqt0P7t3vytzhNKlmgMlnPxPNc69D6refPUmCG50NIvfNkwYGyDow8xI79 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: db55b913-1f83-4981-120a-08d5581d8811 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(5600026)(4604075)(4608076)(2017052603307)(7153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BuIwzcrVWvJ0=; 20:9ketwMzzLrdZgSqELfQprb0AUewZ9doUZTuOzKYIJFbUiQaC9v1pCvpWJ8uUTc0+s8uUEM1sVRloyT1QFE5LvH9uD2MEq/+FL0XARcJ1Fnolq1EJPdQxxx4Xv1KBCX3TZFEbdmL+TWZIqTDiJvA8kPCiOLMf++5K7aLntC8n6aHx/O8kYxb2tZQzuAiG8xVFYxV7Xgyf953BrBr6KbYlWgxmZDQ0T6+O1x/vUknfmCBXgJk0a831uDn3HE3F1OUU/BKzztInkt7enT1kNpk+MILf/jLm+SdP7wL/jTu1vl6QG46ZOkpr1gn+uGA46TEeZSsVBFrtWKXvyKoQxmSySnT+M4hFvpY4+NeR2Ud+HPPeX2/TG0H4gsaaBpVKzW2Q2uhBT/pCKq80iAUsKTLdnRRMOlUCzvTk788QKgjZeQ+4Yw/GCVQY7TspuQZ5mXVkzRYs5w9f+njKHNo3/iksLNz4ZfgPxQaljSzw4dXQK6zj6kI1K+49ZKksWULb6Rj1 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)(3002001)(93006095)(93004095)(10201501046)(3231023)(944501075)(6055026)(6041268)(20161123564045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123562045)(6072148)(201708071742011); SRVR:CY1PR0301MB0700; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:CY1PR0301MB0700; X-Microsoft-Exchange-Diagnostics: 1; CY1PR0301MB0700; 4:eIYfikPIH1Qqg0YOeH20pFWE3sn4BcCpQXL0cqHWQEuzT4u79h2DgxA6PSwJy/qhFZ+Pga48Vl8WZzGQTsjbUCR6h5LyOTZxKhHLAXyxOmrU4VEPPYZUCrI5GUbdJdwwSrxQ8L9g0TSAHGm3crGbkO2xhzUkTjiWNWecUQKAP9OKDVPtSHUSLyBq/Gol8kO9qlUjwPi4QVRUULoBGSS70LUj/Niu9rLEzPTDMAdg5bmyOQGn3vwJGwZkhRp/6D/MZ3pCWAF3F1OSgLVKUrRuAT3B2wJVutMZc9OXyiWGJ5SxsajthtCFxOUyMSJANUMe X-Forefront-PRVS: 0548586081 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY1PR0301MB0700; 23:wycX/m8diIhlKkLGYXIUTKz95En3tlrV29L75wR?= =?us-ascii?Q?Fxw7DZ2HjAaEthlEYYrgDjohTrUae7xnB9xInpaZpVHqOZiA+TTupw7azgsC?= =?us-ascii?Q?oLCdWrH2mBtxvT2lJx/i/1Y5mh+/ndrCk8wCOXDkRNqKCLZQN+bbcliVdYX1?= =?us-ascii?Q?bl9f8NkIaMe+wx+kqle+X+YHKl+uA0aBduKKbqePmKSraFHjRWcMTYtR9Ljh?= =?us-ascii?Q?snRaevGagOV/QuzjTg6X3wuBAInc4kZZh7ivGegAXMWkbws/KIMc3GGbMqtE?= =?us-ascii?Q?azR3QhYcgphqr9vTtn97R2Lr4uguXye/NXu/q353Zkk+1gvujYt5HRnchQbc?= =?us-ascii?Q?9snF8HApJlTL6w8Lv6PhAPev1Rv15fPRW4OrxZY0nFn/sWN+BPIA3wBBPedk?= =?us-ascii?Q?L+uXTYL+4EzSd59ETgqutt4KTqwFZ56uKMYq1RXV7pfNZcdHR2T7jBGq9bZU?= =?us-ascii?Q?qvCpx092I73Zrwge0HQI5AaUFM4ndwvszxZHLWFQryGrOboQqwF3lKiQJ7uA?= =?us-ascii?Q?KqXQv1b2UZGcfWzm/9Pj1txyZ6PsyizI+jKv5fMUjx2vWZtuo46Fz14KoG8O?= =?us-ascii?Q?mjAWDTdfsFdlQKwqtcdj0yv2XsNpDqA7LbSGqNjVyZoJQIkbh3zRJWzQVtmR?= =?us-ascii?Q?cF8F1amR0YffjbQ5TRi4cdSr8qyLIGOnSCT/4pdIhYg0olkiY7NrQ73jC4N7?= =?us-ascii?Q?K0ktHKDnvphq7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lgmh7aVWA1VDF3mS5WOnR5NgQ4seEb6OEovmVwnf85Rjt3GFQL6phE/3jCm+YTLo5vxGAAPfAmC71tNLCeDAwKptNerexbFqFSm3gu3JvOecXuLGM8OvBsQyGyFBf9CnIGsmzakTkrRtuSoUqXCz76JzPS6qOJGccJNukAz6Xkkvpiej0cxuE2z1ceLwn7Zk9VCfnACLbVXGChDXeOVsqV1kIA8n1+bIwUhUdR7ZLtGkfM7Twrx SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: analog.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jan 2018 11:30:20.1817 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: db55b913-1f83-4981-120a-08d5581d8811 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 According to the datasheet: * 0 - external crystal, connected from pin MCLK1 to MCLK2 * 1 - external clock, applied to MCLK2 pin * 2 - internal 4.92 Mhz clock; pin MCLK2 is tristated * 3 - internal 4.92 Mhz clock; internal clock is available on MCLK2 Which means that the external clock value only has sense for value 1 (AD7192_CLK_EXT_MCLK2). Also added range validation for the external frequency setting, which the datasheet mentions that it's between 2.4576 and 5.12 Mhz. Signed-off-by: Alexandru Ardelean --- drivers/staging/iio/adc/ad7192.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/drivers/staging/iio/adc/ad7192.c b/drivers/staging/iio/adc/ad7192.c index 7f204013d6d4..7bc04101d133 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) { @@ -245,16 +253,16 @@ static int ad7192_setup(struct ad7192_state *st, 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_MCLK2: + if (ad7192_valid_external_frequency(pdata->clock_source_sel)) { + st->mclk = pdata->clock_source_sel; + break; + } + /* FALLTHROUGH */ default: ret = -EINVAL; goto out;