From patchwork Fri Jan 5 15:21:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 10146675 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 CA2FF60244 for ; Fri, 5 Jan 2018 15:21:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A2D9928497 for ; Fri, 5 Jan 2018 15:21:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 975D428936; Fri, 5 Jan 2018 15:21:43 +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 DE5472893A for ; Fri, 5 Jan 2018 15:21:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751622AbeAEPVm (ORCPT ); Fri, 5 Jan 2018 10:21:42 -0500 Received: from mail-by2nam03on0065.outbound.protection.outlook.com ([104.47.42.65]:47744 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751624AbeAEPVk (ORCPT ); Fri, 5 Jan 2018 10:21:40 -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=lzK49GTpbAsFSvmb6MJopx4I/DmCPGvJFjjHSOAABxE=; b=Fm2V8Z4XcxlMmMqVFz1vi64e9cuFpaqX1o8sn61zqeTfqN4cqCLLwPuiYH3U32epleDZc1C+5I3iHgjOB54RwBg6IB/oKSQR/b6kANxn037n3CdG1ZheO+9oLR30VJQ4L2ujkurQP5Q3+ZEldHhrEnKKHRsDA7ofSK0k9x4EXp8= Received: from BN6PR03CA0094.namprd03.prod.outlook.com (10.164.122.160) by BLUPR0301MB2049.namprd03.prod.outlook.com (10.164.22.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.386.5; Fri, 5 Jan 2018 15:21:39 +0000 Received: from BN1BFFO11FD015.protection.gbl (2a01:111:f400:7c10::1:135) by BN6PR03CA0094.outlook.office365.com (2603:10b6:405:6f::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.386.5 via Frontend Transport; Fri, 5 Jan 2018 15:21:39 +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 BN1BFFO11FD015.mail.protection.outlook.com (10.58.144.78) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.345.12 via Frontend Transport; Fri, 5 Jan 2018 15:21:12 +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 w05FLcgK019940 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=OK) for ; Fri, 5 Jan 2018 07:21:38 -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; Fri, 5 Jan 2018 10:21:38 -0500 Received: from saturn.analog.com ([10.50.1.244]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id w05FLbnt027464; Fri, 5 Jan 2018 10:21:37 -0500 From: To: CC: Alexandru Ardelean Subject: [PATCH 1/2] staging: iio: adc: ad7192: add device-tree support to driver Date: Fri, 5 Jan 2018 17:21:32 +0200 Message-ID: <20180105152133.9681-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)(346002)(376002)(39380400002)(39860400002)(396003)(2980300002)(438002)(199004)(189003)(1076002)(7696005)(106002)(53416004)(4326008)(2906002)(16586007)(2876002)(8936002)(47776003)(50226002)(316002)(51416003)(8676002)(2351001)(106466001)(5660300001)(36756003)(305945005)(6916009)(77096006)(7636002)(478600001)(86362001)(86152003)(356003)(107886003)(246002)(48376002)(6666003)(50466002); DIR:OUT; SFP:1101; SCL:1; SRVR:BLUPR0301MB2049; H:nwd2mta4.analog.com; FPR:; SPF:Pass; PTR:nwd2mail11.analog.com; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1BFFO11FD015; 1:++sRxp8yW3rglBjHzZ1OO1/j1r3b0iQIdbDZfhTDV1mzJaMfxN1+/BJmLmRSLfG8PI6MR15km2fhfHLguM2hRxAcJYU2v23SiC+4r30PdMJ1aaS1qoidxA6fzUHS1alY X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 47b03d8b-0dec-4fbf-0e7f-08d5544ff467 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(5600026)(4604075)(4608076)(2017052603307)(7153060); SRVR:BLUPR0301MB2049; X-Microsoft-Exchange-Diagnostics: 1; BLUPR0301MB2049; 3:6ywuCcHrrD3O3gpDYmUE6K2mvUw6l/F5msP3kxw4NOkTqgcCh1vR08wPhl7OQhQpp7UeHlSFY9X1EZUbPJ43WZp3je7+t0icKPNjhUCOJGxU5SfYmHAsPUShSahLuEWQM8+foPC/slkv1cS4J1f7IUo48l1OSWh7QyA5UwOqn5JnFC8AR6DZlXsf8Ny2lq4HREB/1yVcUDi89VYcby1BstB1+HkBWurcjr1LIvlCJm8t9gQ9mRcMIIrPlnqO6RnJLXsh02EyRrblIRA5emciZtAyJkkKk4XAySn74LP+/uCcRCbp3M8nutAqKSdU6WC2EvxNv7AQ72yXtdLCg1TIog==; 25:7Hm/OA4ubrUkPmuvCVty1om6BNlwGJgpVrhZP3qjazG0euKhlxnCLMcHdXyOJd10lxOOAqn58Fnq8yQhomQm+IItwW+uwZkO+Fi/6zcEAIF/64aeu8pcqF42ILKuSiLc55wdk+GkOgcf2mIa/lgUEgTgO3q1zAE/nW/EpN7y6OLaVV+WEusJz1LjWHjjJaSHoWE4d4HPEnBmH0fViFzHP3yhNtfKs/IOnh1IuIXr6T3pIExoZRPgCR2X5hhTUgTcvHnoogeueNbwZe/adIrxlBuIAlhMPmXDK/nN7d2uyx3ot4th2E/FymHKZnfUNkUOh+FCyZlM2zQEwvyD77035A==; 31:4aCP9bWWry2+YwK6YXItVZwo1F2SfuDticEiC8Opc2kumWMycyIulQXZUvyYJOqV+UUun/RLGkMQEKdXx0x1DfnQ+xjBVMHHUbLP6lW3k2qQuNbFW3kb1NQeDHHbng963U0RlKHzXg7zmVp8S+4YaqLyS+nuTHM6z99gQp0iKWP4c79qJgfzyPB1JrbRjVU1e8YVV5nSst5dktiL43jhQQRRy0PcSCCc55mdEskXk6Q= X-MS-TrafficTypeDiagnostic: BLUPR0301MB2049: X-Microsoft-Exchange-Diagnostics: 1; BLUPR0301MB2049; 20:wiQ+HsB5T9oOK7Agq5qW7zicfWpM07oTTYsp/VGWtfuccPiRpAPNAa0skG7XkKEC8bIJsK6AZuf2dGHS3Ia0ERuoHTd9E/XWMF4MyaqHsTWyNMG71BN/9zNx0LokGGBMRc8lmENPkBVYOXVaCctegi29RQZTYVoWCaVkPHQwwPsvrNPT6Hz/19wu1kCi7IboclQUOloZaISRfqNzqEaElDdehptBvilpdAwRdEzWHdC9QGkd4wkdJEDw4Z7d2DEA/tQEk08N1VcYXD5d0fb8ojY9T/fuWmL2LR07gUy+OxG7PZYCUXLEx/v2CKAZnUhquRs5IOuw7BkW3FDV3mKFRqCoWi/G3lDXopNC+T7JxhbKBbug5N26pJgUkPyGg9kUUvURn7F4+C8T2o92JQzebKQweko9Kw4rV4f/TA/BMvj/HkivVouHavjErnnRS6qQnFrzLujphaQkBsa/JUUEUZKyqd/6q8j0gWTHUiBSGVpfZgf8LY7IW5MY1VfCwUoR; 4:NuHWDyxzo6wta0VNeEMGR3K+rHc5q3YSJipJq79sfZ7usu0me8RD8s6yBnriQKUVf/RFkYLa6j4P1XDb53YedQffusJwvgcsDUPJvrwl7gd+rVqU4UK83obWM+dgndsnXPiVg4EsuY8f94BTzcpIXgC7MPEtgW9yzfaOkmMApxhBCJgjB+Osrng26ILUGWZ2c6jWVaTOyFj0MHKcZPhnIBtQEd5sANv8RFoXEQsW5awSCdF7x1ml+HHEa4lG7Jgo9w6scVcbrtFUVwLu+UiXoWYdrxxfzKEErx62Bkfw6kuBVlb5/IXoRIwcbSy9woqy 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)(3231023)(944501075)(3002001)(10201501046)(93006095)(93004095)(6055026)(6041268)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123564045)(20161123558120)(20161123562045)(6072148)(201708071742011); SRVR:BLUPR0301MB2049; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:BLUPR0301MB2049; X-Forefront-PRVS: 05437568AA X-Microsoft-Exchange-Diagnostics: 1; BLUPR0301MB2049; 23:yD4aQZZ6EHK4xG31OOuWwcvhnKsvdUOLlub5ZveN7Mn2ijMs2P94zperKfxZCg8kebl9SpTNkdzAMv6E4EJYokAoPudur4TuM4X5vTtQSw2KREsTwpaMT1gM2iuxwEM37SDq2ihNsj0w46IR0BsJtaTjHSG669Gm6+iQPcpZVUoe2dTiuCXLDWuIFVSCkqXcfBFzoEvNNg/egzKGrnn2Tnre3Jv6IrwrvNhvyBYQ0qwvIaCz6W4rRDjAWakTtDD7P9+HOLPrpM827vJbovUFVdHWT73vwKz27kz93Xlzoa4XljvikeL15doXyTLJvnlfGcXAxUKbZwhx2dwViaHQyafFdck4QaQT6A3thlpQuWlWTEnF/74aMk1vVHysoo3kuseHJaOHK9ue6n3/7PCub9XhSCR5HHJh7oPgzEW4ywXAo9FTIv7wvCRMIx+FV1lUOC7JzFV33UYYKPW01eYEsZKy4sNiN/Ya0mDPrZzFWJjE8D77zKnPd0wMSedRB1VXWRUFW8JRLakYbG+s+IqlhDjdU7Cw0+V1l3nx6e6wljTX28yO8j1Sq8xmzEqUMXhZFMuulBxdtPJqbC/qAg3LXTkSXNg35PbJnpJB49akjLoFYnmH1WICRlLc+KjmfCgScyhsWeKOEwgUkipcKAORJDMx8aafclxVUBAISI0bVWwRE3TCJdudObspSPS8pFyjtkdeoZJThYOGJ9v7MdQy4X3vQWkl71kk3IG5CjeVNTx0SM/krrLuqx5A1kltqT+LbKpHX3QR722FmdEWIKCN1gmvie5sNA14VijQzSPnQwlzx/PoOIDl44x6JPH3lhy9xGZ3dD6PeP7WUr+u2d/6iLoWqgGJsxs1mCm98vQcnG0uY3vwcpYW6AqceokwShFPCjy6t8Vpn8/tmqkfmaDUobWIMQbetvPUv1js9H4 EAsM= X-Microsoft-Exchange-Diagnostics: 1; BLUPR0301MB2049; 6:qYLOCihopgQg+wfhdsabHg6vgAs6RcTtpljzTw5bo4lyDali5daJcRAem/Pb0/BsE39xbFlbbTt7Wn8BS4oP9o4Bc1Lgb4qk5m6RVSw3IdWb+Xb08BhWnbVpJeK4bRJCoXiJvfaB+bWulriApDFfRN4qAJI0bgIWianPYuBv52hiBtl7pT/rTlNe6LFdA0Z73Ct3DoyX/QAG8w+y04xVyIbATcnfsQgGLQtyIwR+syZBLpgPrIwpSlWmw7QdpB/GdtcVeZ7ckyUNPFMUgqaMkmjHXs0dLDPr2IFDjdbE3GiokG7VeuJKaSmuHhZpaUMZW071Jxpj49Hrx8Ib3KxIIg1XMjpUXGCnhf+OB8r/AFU=; 5:QL2Q0lM1fRhit6h626h6RZjMBS38+ROq9jfOJOV8BxVdFnPkQ4KDcuqUe73J9aH8S8coWUEKAZC8Z3DyJgO2TTnuzIIB3UukCj1pUP+X+jBMZSn7YEIf+lO2WuD6BKA2UtZ8+omqoGtoQTSHQQo7qiIf5vaN6hoJVDk1D6nHvYY=; 24:UhItYIGfFpoRncH54wTQhT0oYrW72MPdeg7/IJ37mvSVU7xPrpDrGGgZmMGNolI/9K951w8wOR0Mi18ebdgCHhbZg5DFc3Vd6VlIF73U7+I=; 7:ndV1o+hESaWH6EWxX7wmWfsQoVafli6tGK4TFTZ8Yi5p7n3NbtKsJMU7cmcWaz/V4dQsv5oCq0XVVCXcnjzq9RECBIyorq/gHMmhguqV0UGPLf1USCxbKSRX0PJZolqGnrkqYpdzDXRg0p27tZ+ittkOIdjk40/yGo5GicetWz2cef3V75putOx9A0/rWWAtO7ShYEveRQu9eAECcTgN1KJZcytyebCHD4qAxQT4sh4BPRX8e28Id8+hpQbnWGZ8 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: analog.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Jan 2018 15:21:12.0933 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 47b03d8b-0dec-4fbf-0e7f-08d5544ff467 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: BLUPR0301MB2049 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 Admittedly, this will always use up to sizeof(struct ad7192_platform_data) bytes (~12 bytes at most) on the stack, during the probing of the device. But this will maintain most of the other init code unchanged. Signed-off-by: Alexandru Ardelean --- drivers/staging/iio/adc/ad7192.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/drivers/staging/iio/adc/ad7192.c b/drivers/staging/iio/adc/ad7192.c index cadfb96734ed..fca988330588 100644 --- a/drivers/staging/iio/adc/ad7192.c +++ b/drivers/staging/iio/adc/ad7192.c @@ -610,18 +610,41 @@ static const struct iio_chan_spec ad7193_channels[] = { IIO_CHAN_SOFT_TIMESTAMP(14), }; +static void ad7192_parse_dt(struct device_node *np, + struct ad7192_platform_data *pdata) +{ + of_property_read_u16(np, "adi,reference-voltage-mv", &pdata->vref_mv); + of_property_read_u8(np, "adi,clock-source-select", &pdata->clock_source_sel); + of_property_read_u32(np, "adi,external-clock-Hz", &pdata->ext_clk_hz); + pdata->refin2_en = of_property_read_bool(np, "adi,refin2-pins-enable"); + pdata->rej60_en = of_property_read_bool(np, "adi,rejection-60-Hz-enable"); + pdata->sinc3_en = of_property_read_bool(np, "adi,sinc3-filter-enable"); + pdata->chop_en = of_property_read_bool(np, "adi,chop-enable"); + pdata->buf_en = of_property_read_bool(np, "adi,buffer-enable"); + pdata->unipolar_en = of_property_read_bool(np, "adi,unipolar-enable"); + pdata->burnout_curr_en = of_property_read_bool(np, "adi,burnout-currents-enable"); +} + static int ad7192_probe(struct spi_device *spi) { const struct ad7192_platform_data *pdata = dev_get_platdata(&spi->dev); + const struct device_node *of_node = dev_of_node(&spi->dev); + struct ad7192_platform_data lpdata; struct ad7192_state *st; struct iio_dev *indio_dev; int ret, voltage_uv = 0; - if (!pdata) { - dev_err(&spi->dev, "no platform data?\n"); + if (!pdata && !of_node) { + dev_err(&spi->dev, "no platform data or device tree configuration?\n"); return -ENODEV; } + if (!pdata) { + memset(&lpdata, 0, sizeof(lpdata)); + pdata = &lpdata; + ad7192_parse_dt(of_node, pdata); + } + if (!spi->irq) { dev_err(&spi->dev, "no IRQ?\n"); return -ENODEV;