Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp10458484imu; Thu, 6 Dec 2018 01:12:30 -0800 (PST) X-Google-Smtp-Source: AFSGD/Xw5Mpv+r7McTbT9pg44/i1laxbY4GQzVHvF7SW7rTEaiB1qluMNeUddIqVErXUzu/26LB7 X-Received: by 2002:a17:902:9345:: with SMTP id g5mr15847055plp.148.1544087550052; Thu, 06 Dec 2018 01:12:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544087550; cv=none; d=google.com; s=arc-20160816; b=Ha35XPGEHnWmLlo87yRbrS9o3oEJP/RVsCvCURya5oTztRaDv//zoim+uHiYs2iuPz ApmzCo4pba+M8ME4SCdapsnYRxSVCOpffebLCqBZEZQt9UlZzNMZQwRvoFYX11nqfDeg b2CYea4i5hdbQbbwqEcksqvBZbSZT3rfCyubsxmTMPuHImsF5g7jK4MjplQYkKAjQUNL A8rLqsM+3kqS/gCMtrn9+2AsYB65HxE1zqrwtTGHoKQBUR2QgWc3psBn19hskMPSX5jh 1itGe1HsOXORaQyq3Ac6+Tox70mLD4iWnmpaebTvhoNGKUpyFNxZs8S/M1u6tt9JUUuR /+aQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:mime-version:message-id:date:subject:cc:to :from:dkim-signature; bh=YFQYdvt3P3vcjUzbWrVN9s6XVYt1Na2quepBDhRGbbc=; b=t5eYZco2XUY+kKC1+RT4Vc0ttkUcHZkiZjVHKwuChfN3f7XeU1Sk9lyve3Ft4KrzC3 udA7emS7ZyefKEjzIPdUJxmD9PTixN57zfoF8Zfa8Vltrn2EiwObmPfOmR3EKto2vdbn KeYVRzssxYxZWqM8a1UaHAdu7bpOvYouY9gJ9uCFYPHcL8lQSE2WRNtD8v8pvvVgb8AA 9gMU1826QzeVeJniIw59W0EzPlXcumozMVzhj5XyBi1jaQyYIVDj1/6MDYLuU95z/Jmr F5ttYfLDXeoNxIplwK4fHu6/XQ6Is5nphGuiSm39A/U4OTBBcWnbOFsul8SCUxmsc+DX oulQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@analog.onmicrosoft.com header.s=selector1-analog-com header.b=pIDXCY7R; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 28si19629091pgz.593.2018.12.06.01.12.14; Thu, 06 Dec 2018 01:12:30 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@analog.onmicrosoft.com header.s=selector1-analog-com header.b=pIDXCY7R; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729319AbeLFJLP (ORCPT + 99 others); Thu, 6 Dec 2018 04:11:15 -0500 Received: from mail-eopbgr720088.outbound.protection.outlook.com ([40.107.72.88]:31616 "EHLO NAM05-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728245AbeLFJLP (ORCPT ); Thu, 6 Dec 2018 04:11:15 -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:X-MS-Exchange-SenderADCheck; bh=YFQYdvt3P3vcjUzbWrVN9s6XVYt1Na2quepBDhRGbbc=; b=pIDXCY7RakH9MYigVXRvFsZ1wmCl5rBWpSx/BQc1CilsW42vEu9C0LZtXXMFjlu4xQUI8QuWad8ftkcoNAa9fiXVz1BeS+UdsTiYTEuLby6P7QgNvW9cGrnEf3s6e9tXOjIXtIjzpWaBBfNnYhPFnFxScql24TzE5ayTDYZNcWQ= Received: from BYAPR03CA0006.namprd03.prod.outlook.com (2603:10b6:a02:a8::19) by DM5PR03MB3132.namprd03.prod.outlook.com (2603:10b6:4:3c::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1404.17; Thu, 6 Dec 2018 09:11:11 +0000 Received: from BN1AFFO11FD008.protection.gbl (2a01:111:f400:7c10::160) by BYAPR03CA0006.outlook.office365.com (2603:10b6:a02:a8::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1404.17 via Frontend Transport; Thu, 6 Dec 2018 09:11:10 +0000 Authentication-Results: spf=pass (sender IP is 137.71.25.57) smtp.mailfrom=analog.com; gmx.de; dkim=none (message not signed) header.d=none;gmx.de; 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=nwd2mta2.analog.com; Received: from nwd2mta2.analog.com (137.71.25.57) by BN1AFFO11FD008.mail.protection.outlook.com (10.58.52.68) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.1404.13 via Frontend Transport; Thu, 6 Dec 2018 09:11:10 +0000 Received: from NWD2HUBCAS7.ad.analog.com (nwd2hubcas7.ad.analog.com [10.64.69.107]) by nwd2mta2.analog.com (8.13.8/8.13.8) with ESMTP id wB69B9kn032403 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=OK); Thu, 6 Dec 2018 01:11:09 -0800 Received: from mircea-Latitude-E6540.analog.com (10.50.1.101) by NWD2HUBCAS7.ad.analog.com (10.64.69.107) with Microsoft SMTP Server id 14.3.408.0; Thu, 6 Dec 2018 04:11:08 -0500 From: Mircea Caprioru To: CC: , , , , , , , , Mircea Caprioru Subject: [PATCH 1/2] staging: iio: adc: ad7192: Add clock for external clock reference Date: Thu, 6 Dec 2018 11:10:51 +0200 Message-ID: <20181206091052.7644-1-mircea.caprioru@analog.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-ADIRoutedOnPrem: True 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)(39860400002)(396003)(136003)(346002)(376002)(2980300002)(199004)(189003)(478600001)(6916009)(8936002)(305945005)(1076002)(50226002)(7636002)(5660300001)(426003)(336012)(8676002)(356004)(6666004)(106002)(107886003)(72206003)(53416004)(2616005)(36756003)(476003)(126002)(16586007)(54906003)(486006)(4326008)(7696005)(186003)(86362001)(246002)(51416003)(14444005)(316002)(2906002)(44832011)(47776003)(48376002)(50466002)(77096007)(2351001)(26005)(106466001);DIR:OUT;SFP:1101;SCL:1;SRVR:DM5PR03MB3132;H:nwd2mta2.analog.com;FPR:;SPF:Pass;LANG:en;PTR:nwd2mail11.analog.com;A:1;MX:1; X-Microsoft-Exchange-Diagnostics: 1;BN1AFFO11FD008;1:CVHFVYDNM1mrPa9JJNir/0wZwNB0I2Gd+RiX1XVJXLBP+wLCZ/l5CKfQNB6/Ux4hUmx5UWuxheaWJc/W8ZzE+Rom25em1C6fZSQAHz7gZ8ZpelrnVIA9E3a+1H3cNU8K X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ede5c8f8-a0e2-4343-56a1-08d65b5ac35f X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(2390098)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4608076)(2017052603328)(7153060);SRVR:DM5PR03MB3132; X-Microsoft-Exchange-Diagnostics: 1;DM5PR03MB3132;3:JCOWbc0+UVDs/thi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Xsmw7W+qWbXmIkMlOuXq2X90zmp9ukpuwXffKZ9Hayskw+c8bNFNGMqZVaytJf+FDjaMH5BNHdMx2womTq7MkEIu/VL6isGEboOZvblk170RudTfW7wdJne1B31RLGAyUVkbR7FiOJOdvIPBSwTpefD/YURs6kVx0+tlTbzvzvYxqllDekwZLGyHP5fI6W4nxNt49xZTiyKv6MSPHtBjMNbZFDJrin9rOpN1YKbX3hjrtyBSeP6xhdN+SM0fbTNt5ViesxWddMRg6vmRxyXCGG1Es2z1CXK6vsVV7QD64z7liqAJEx96E0mZhjPksPZCXuOtdgN3KTdYPCibHcZKHJDk8IbT1tIppPj5ESDsLjh2e8yb4hUIniuGQ1qHjnrBjoGG7aFSghS2flvebSjK3QrqL8xcQurQgUXnsKyyZssXohS3RQtX X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(10201501046)(93006095)(93004095)(3231455)(999002)(944501520)(52105112)(3002001)(6055026)(148016)(149066)(150057)(6041310)(20161123562045)(20161123558120)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699051)(76991095);SRVR:DM5PR03MB3132;BCL:0;PCL:0;RULEID:;SRVR:DM5PR03MB3132; X-Microsoft-Exchange-Diagnostics: 1;DM5PR03MB3132;4:Iq6I8CNZcJJnaUgwplCMTW5rWVPHg7BDC6ERHRlXTHoxOO49rwWbfv8waf8z+1352rxmbP0RDNj3yZGhMB0FTR/He7aFSEvEGf6Najc8i8n8HgU/J3QJeg3kKEgfpuuONVcC/Yvjm6A1cQ3MfsEOMrjje5lGEEOUDVDB0pd9v0kL3akVg5qvO+hRwgh0zRC4Eryfpib7yfQUQ6fQ6nMI7I1z0nqqmpjfOwHs8rKbgEXHMqiLpWhzgJgo481otsh/R9F10rnxMdSVBIZgBTgz6Q== X-Forefront-PRVS: 087894CD3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g7Zui47LPjwg1NYcNPtg75aboIrYSMtmab3MKvE/jC9Hk1DB?= =?us-ascii?Q?Fj7pR8aejI15NYsDp07V86lPdpRxCOk9AjYk2gc8JksqwnbQCEP7iWoAah5I?= =?us-ascii?Q?KiUyzcnYLjUKLTkxR5QzD9euoKVuZNhQKGUk+vlosFEoDwOrztlr+LcD8ouo?= =?us-ascii?Q?flNuJHiKwWk9fF9Cnio9aEN0AvzVBXxJydJyhsQz9gCY1S05vczNHgsBwtIn?= =?us-ascii?Q?9e8lKRtyiZqF5o5PLm8lAmSJ9HC?= X-Microsoft-Antispam-Message-Info: YTteSsggqygAjhL+6XxpMStOJWIqc/bns4yJYLuSbyawhWMgz8969gJ3KU0/HcEfNk/jZOLoJEz+YGswvtyH09MLxUXEX8u+TOq8lmDcJ3Xj4RQ+ydHmt8e5pX43f191Oy7rsH/pU7Z6BNoTIjOz/m5Sv58CAxUy7nEkn6UQsperbrNGGEPTGX64T+PXDWpPt/aI5RhGK2fgHd88PLThUJjEhLuellm43N2KlNUsg+53HpvYUZhI3y9arL0Bg583dvaGNfx17xjIvC+LZEsZOMhuQh5L5KUukfVYiWDTgpYIPUXlC8+qQRYrb2VObBbAVeww/BNBwsQ9YiKXnaL6zQT4qA542tMp3HXbELxIuUg= X-Microsoft-Exchange-Diagnostics: 1;DM5PR03MB3132;6:hYZfIJ64Oth8zD1L5xKLEqbYVnx4roJqHzLTbscaZLlBMwid8mb6jFh53a/11sbiA+Ye7v5TPpxA6DZpFlJtPQ1LSzBf303IhJina/ezahvTX7MZaV58mKBi/SmJUYj6tFRO79UNa7PjkTaLOnJrbuSLoyW0yXuCXKLh6qAyPCy7p30C7FD6T2IXw5I8eEwixLkMnQtirK+GfKV+lCPtfu+tvnMMYwRYt9X4Q+l/wPJS1sWxnsxfIScvp/1CAYjvrMQRwSjNuZa1IVyCigAhohFSTlPsToE+7DgJL6VDkbkgGMSv6Orc33HmFjuPaTH+o3CkwXEd8A88YzAri/8Qj66a3oJKBUu5xji9NQGigQQMQkyVlekAUxM7G9YpOxCkbLB9zjGOjVlnyntjoqjvAQ+jlQeUqdhOoznnipZbedz8U7oa6SZeHxZGGgcDRPRWoJnM7YTOAg/TFU4cUGAIzQ==;5:i/59qmQHH0jzq3DkXwvrdGA1WtPXBOaKK6OM6PgYMGLGXqX2yEv9hXiM9j8gxi1Q0F5Uerjxvqmlaye6AiiSXTsPh10kM6IWeqOVbaO60hRrz0XV4zoX8e1VFiOSqT1UWrF8Gk/uJefqV1ltsdnbhRVyrPVR12Zi7Cs1xL4ZMjA=;7:7azyvdvRYANQhJUm4YtqxC8gwi9zlCz5UqmtM1skGZLj4rpN4DW4mUBP21Is3INwxX9f7mA4tc2HB/Q1Sazt8JcWH/PBKNiBodqpQOONt64p+2dlOE76vIajpaCPbzTdofjLOIJJOc+C1MZ2+uG6Ig== SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: analog.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Dec 2018 09:11:10.1399 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ede5c8f8-a0e2-4343-56a1-08d65b5ac35f 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=[nwd2mta2.analog.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR03MB3132 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds a clock to the state structure of ad7192 for getting the external clock frequency. This modifications is in accordance with clock framework dt bindings documentation. Signed-off-by: Mircea Caprioru --- drivers/staging/iio/adc/ad7192.c | 74 +++++++++++++++++++++----------- drivers/staging/iio/adc/ad7192.h | 2 - 2 files changed, 50 insertions(+), 26 deletions(-) diff --git a/drivers/staging/iio/adc/ad7192.c b/drivers/staging/iio/adc/ad7192.c index acdbc07fd259..8a4e6ede42b3 100644 --- a/drivers/staging/iio/adc/ad7192.c +++ b/drivers/staging/iio/adc/ad7192.c @@ -6,6 +6,7 @@ * Licensed under the GPL-2. */ +#include #include #include #include @@ -156,8 +157,9 @@ struct ad7192_state { struct regulator *avdd; struct regulator *dvdd; + struct clk *mclk; u16 int_vref_mv; - u32 mclk; + u32 fclk; u32 f_order; u32 mode; u32 conf; @@ -165,6 +167,7 @@ struct ad7192_state { u8 gpocon; u8 devid; struct mutex lock; /* protect sensor state */ + u8 clock_sel; struct ad_sigma_delta sd; }; @@ -250,28 +253,8 @@ static int ad7192_setup(struct ad7192_state *st, dev_warn(&st->sd.spi->dev, "device ID query failed (0x%X)\n", id); - switch (pdata->clock_source_sel) { - case AD7192_CLK_INT: - case AD7192_CLK_INT_CO: - 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; - } - st->mode = AD7192_MODE_SEL(AD7192_MODE_IDLE) | - AD7192_MODE_CLKSRC(pdata->clock_source_sel) | + AD7192_MODE_CLKSRC(st->clock_sel) | AD7192_MODE_RATE(480); st->conf = AD7192_CONF_GAIN(0); @@ -499,7 +482,7 @@ static int ad7192_read_raw(struct iio_dev *indio_dev, *val -= 273 * ad7192_get_temp_scale(unipolar); return IIO_VAL_INT; case IIO_CHAN_INFO_SAMP_FREQ: - *val = st->mclk / + *val = st->fclk / (st->f_order * 1024 * AD7192_MODE_RATE(st->mode)); return IIO_VAL_INT; } @@ -546,7 +529,7 @@ static int ad7192_write_raw(struct iio_dev *indio_dev, break; } - div = st->mclk / (val * st->f_order * 1024); + div = st->fclk / (val * st->f_order * 1024); if (div < 1 || div > 1023) { ret = -EINVAL; break; @@ -625,6 +608,42 @@ static const struct iio_chan_spec ad7193_channels[] = { IIO_CHAN_SOFT_TIMESTAMP(14), }; +static int ad7192_clock_select(struct spi_device *spi, struct ad7192_state *st) +{ + int ret; + + st->clock_sel = AD7192_CLK_EXT_MCLK2; + st->mclk = devm_clk_get(&spi->dev, "clk"); + if (IS_ERR(st->mclk)) { + if (PTR_ERR(st->mclk) != -ENOENT) + return PTR_ERR(st->mclk); + + /* try xtal option */ + st->mclk = devm_clk_get(&spi->dev, "xtal"); + st->clock_sel = AD7192_CLK_EXT_MCLK1_2; + if (IS_ERR(st->mclk)) { + if (PTR_ERR(st->mclk) != -ENOENT) + return PTR_ERR(st->mclk); + + /* use internal clock */ + st->clock_sel = AD7192_CLK_INT; + st->fclk = AD7192_INT_FREQ_MHZ; + } + } + if (st->clock_sel == AD7192_CLK_EXT_MCLK2 || + st->clock_sel == AD7192_CLK_EXT_MCLK1_2) { + ret = clk_prepare_enable(st->mclk); + if (ret < 0) + return ret; + + st->fclk = clk_get_rate(st->mclk); + if (!ad7192_valid_external_frequency(st->fclk)) + return -EINVAL; + } + + return 0; +} + static int ad7192_probe(struct spi_device *spi) { const struct ad7192_platform_data *pdata = dev_get_platdata(&spi->dev); @@ -672,6 +691,10 @@ static int ad7192_probe(struct spi_device *spi) goto error_disable_avdd; } + ret = ad7192_clock_select(spi, st); + if (ret < 0) + goto error_clk_disable_unprepare; + voltage_uv = regulator_get_voltage(st->avdd); if (pdata->vref_mv) @@ -720,6 +743,8 @@ static int ad7192_probe(struct spi_device *spi) error_remove_trigger: ad_sd_cleanup_buffer_and_trigger(indio_dev); +error_clk_disable_unprepare: + clk_disable_unprepare(st->mclk); error_disable_dvdd: regulator_disable(st->dvdd); error_disable_avdd: @@ -735,6 +760,7 @@ static int ad7192_remove(struct spi_device *spi) iio_device_unregister(indio_dev); ad_sd_cleanup_buffer_and_trigger(indio_dev); + clk_disable_unprepare(st->mclk); regulator_disable(st->dvdd); regulator_disable(st->avdd); diff --git a/drivers/staging/iio/adc/ad7192.h b/drivers/staging/iio/adc/ad7192.h index 7433a43c2611..3be3ee269ed5 100644 --- a/drivers/staging/iio/adc/ad7192.h +++ b/drivers/staging/iio/adc/ad7192.h @@ -33,8 +33,6 @@ struct ad7192_platform_data { u16 vref_mv; - u8 clock_source_sel; - u32 ext_clk_hz; bool refin2_en; bool rej60_en; bool sinc3_en; -- 2.17.1