From patchwork Thu May 30 13:18:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 10968709 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4E55B18A6 for ; Thu, 30 May 2019 13:18:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 40660286E5 for ; Thu, 30 May 2019 13:18:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 34995289FA; Thu, 30 May 2019 13:18:23 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 CFA50286E5 for ; Thu, 30 May 2019 13:18:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726587AbfE3NSW (ORCPT ); Thu, 30 May 2019 09:18:22 -0400 Received: from mail-eopbgr720050.outbound.protection.outlook.com ([40.107.72.50]:3802 "EHLO NAM05-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725919AbfE3NSW (ORCPT ); Thu, 30 May 2019 09:18:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=analog.onmicrosoft.com; s=selector1-analog-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=sO/bcZDCRaN8q62TyTkRmVhEwCcDp6w+4lCAwjrM+1M=; b=l9E1yUaLVih8E2vl0wABlJ9TDDG0TJqfMFr30EupnMVjRC6u3BZwdTrvFeWJODosXX8vd9LzyClwJCeRZuXYyD69/gKZxGuRaXPW4By5CZbjcws4e2MxhHGa7cROB/pJ/lfpTAFBCSuqYFZHzGi0N0j+tYsO32Ugw2M2kEOaiXI= Received: from BN6PR03CA0084.namprd03.prod.outlook.com (2603:10b6:405:6f::22) by DM2PR03MB560.namprd03.prod.outlook.com (2a01:111:e400:241c::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1943.17; Thu, 30 May 2019 13:18:19 +0000 Received: from BL2NAM02FT040.eop-nam02.prod.protection.outlook.com (2a01:111:f400:7e46::203) by BN6PR03CA0084.outlook.office365.com (2603:10b6:405:6f::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1943.16 via Frontend Transport; Thu, 30 May 2019 13:18:19 +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=nwd2mta2.analog.com; Received: from nwd2mta2.analog.com (137.71.25.57) by BL2NAM02FT040.mail.protection.outlook.com (10.152.77.193) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.1922.16 via Frontend Transport; Thu, 30 May 2019 13:18:19 +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 x4UDIImo024223 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=OK) for ; Thu, 30 May 2019 06:18:18 -0700 Received: from saturn.analog.com (10.50.1.244) by NWD2HUBCAS7.ad.analog.com (10.64.69.107) with Microsoft SMTP Server id 14.3.408.0; Thu, 30 May 2019 09:18:18 -0400 From: Alexandru Ardelean To: CC: Alexandru Ardelean Subject: [PATCH 1/5] iio: amplifiers: update license information Date: Thu, 30 May 2019 16:18:08 +0300 Message-ID: <20190530131812.3476-1-alexandru.ardelean@analog.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 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)(136003)(39860400002)(346002)(396003)(376002)(2980300002)(199004)(189003)(8676002)(14444005)(2870700001)(186003)(50226002)(8936002)(2616005)(305945005)(1076003)(6916009)(44832011)(246002)(36756003)(86362001)(7636002)(336012)(5660300002)(77096007)(2906002)(26005)(50466002)(476003)(2351001)(106002)(70206006)(53416004)(15650500001)(486006)(316002)(4326008)(47776003)(6666004)(51416003)(7696005)(426003)(48376002)(107886003)(126002)(478600001)(70586007)(356004);DIR:OUT;SFP:1101;SCL:1;SRVR:DM2PR03MB560;H:nwd2mta2.analog.com;FPR:;SPF:Pass;LANG:en;PTR:nwd2mail11.analog.com;A:1;MX:1; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 90e74167-df49-4c2f-c5d6-08d6e5014858 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(5600148)(711020)(4605104)(4709054)(1401327)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328);SRVR:DM2PR03MB560; X-MS-TrafficTypeDiagnostic: DM2PR03MB560: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3826; X-Forefront-PRVS: 00531FAC2C X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: z55HagO/cxG+uL2u7bMNk6rDTvo7/JgPBodBdDEpDcpv3T0/hsHw00k6EMgEHdytQ7JFBVC1o+3mSmD80tqYXGoQARvZzWkRNT1U/aFZXpPEAZDIpy4LzQzhneak0Jycm4fwrgmWdczWD5vyLL8FtSQ+jx4AzYq5RbExJ3Zec5rPD65Wmr3YQqhBKWpfQ/OhRRzA+aNl8M93Mp12Y7kSDuSqjGts/WmZgbGaY9g54X1K2X/fsfkklxiZLwg6gy67g3m0HlgRNGgA/QCtwGkVwuHuQlT6m+QYHKtaS8MDVZIhwY6CHtfA7vNU/9waNu5GmSkqkHKh5zMWb4WmjTFQgCn4auhV5Bn84lJ3CL1JB1JyfwktUiWhVeWlcE3i/vO+S2Vpbo5JWyxlQyPrvccBGQ5TKZDKFSCx8RKJ1UQeg2k= X-OriginatorOrg: analog.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 May 2019 13:18:19.0058 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 90e74167-df49-4c2f-c5d6-08d6e5014858 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: DM2PR03MB560 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 Use the new `SPDX-License-Identifier` tag to specify the license. For ad8366, also update copyright years in the header part. Signed-off-by: Alexandru Ardelean --- drivers/iio/amplifiers/Kconfig | 1 + drivers/iio/amplifiers/ad8366.c | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/iio/amplifiers/Kconfig b/drivers/iio/amplifiers/Kconfig index e9c5f2cd9257..da5830da9bcf 100644 --- a/drivers/iio/amplifiers/Kconfig +++ b/drivers/iio/amplifiers/Kconfig @@ -1,3 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0 # # Gain Amplifiers, etc. # diff --git a/drivers/iio/amplifiers/ad8366.c b/drivers/iio/amplifiers/ad8366.c index 4b76b61ba4be..82ac15914ff3 100644 --- a/drivers/iio/amplifiers/ad8366.c +++ b/drivers/iio/amplifiers/ad8366.c @@ -1,9 +1,8 @@ +// SPDX-License-Identifier: GPL-2.0 /* * AD8366 SPI Dual-Digital Variable Gain Amplifier (VGA) * - * Copyright 2012 Analog Devices Inc. - * - * Licensed under the GPL-2. + * Copyright 2012-2019 Analog Devices Inc. */ #include From patchwork Thu May 30 13:18:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 10968711 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CFFC392A for ; Thu, 30 May 2019 13:18:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BEBC72884A for ; Thu, 30 May 2019 13:18:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B259728899; Thu, 30 May 2019 13:18:23 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 4940528A5B for ; Thu, 30 May 2019 13:18:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726128AbfE3NSW (ORCPT ); Thu, 30 May 2019 09:18:22 -0400 Received: from mail-eopbgr820089.outbound.protection.outlook.com ([40.107.82.89]:54493 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726031AbfE3NSW (ORCPT ); Thu, 30 May 2019 09:18:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=analog.onmicrosoft.com; s=selector1-analog-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XbXdM6CAoYE+Nce9Vna2B3m0+HU1GVp/oI4PApUVn3c=; b=sqH8X2jDCU30bze75XOZDN0/291TI3629nMg8S+DqTOSdJRQN3KlE5KoYcEtE4yadTONCTmRALBwaKqrT9CeXFqTQDRZ+yTVvO6frNclqkQTshLWkAfBplk0hmdJcGjN6IoICTUXFiMeDv8lnC83uFDh2T+blOx4ImW69ygEaRA= Received: from BN3PR03CA0067.namprd03.prod.outlook.com (2a01:111:e400:7a4d::27) by SN2PR03MB2272.namprd03.prod.outlook.com (2603:10b6:804:e::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1922.23; Thu, 30 May 2019 13:18:20 +0000 Received: from BL2NAM02FT016.eop-nam02.prod.protection.outlook.com (2a01:111:f400:7e46::205) by BN3PR03CA0067.outlook.office365.com (2a01:111:e400:7a4d::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1943.17 via Frontend Transport; Thu, 30 May 2019 13:18:20 +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=nwd2mta2.analog.com; Received: from nwd2mta2.analog.com (137.71.25.57) by BL2NAM02FT016.mail.protection.outlook.com (10.152.77.171) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.1922.16 via Frontend Transport; Thu, 30 May 2019 13:18:19 +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 x4UDIJGp024234 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=OK) for ; Thu, 30 May 2019 06:18:19 -0700 Received: from saturn.analog.com (10.50.1.244) by NWD2HUBCAS7.ad.analog.com (10.64.69.107) with Microsoft SMTP Server id 14.3.408.0; Thu, 30 May 2019 09:18:19 -0400 From: Alexandru Ardelean To: CC: Alexandru Ardelean Subject: [PATCH 2/5] iio: amplifiers: ad8366: use own lock to guard state Date: Thu, 30 May 2019 16:18:09 +0300 Message-ID: <20190530131812.3476-2-alexandru.ardelean@analog.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190530131812.3476-1-alexandru.ardelean@analog.com> References: <20190530131812.3476-1-alexandru.ardelean@analog.com> MIME-Version: 1.0 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)(346002)(376002)(136003)(396003)(2980300002)(189003)(199004)(36756003)(47776003)(5660300002)(316002)(6666004)(486006)(7636002)(86362001)(305945005)(14444005)(1076003)(2870700001)(106002)(2906002)(478600001)(356004)(26005)(446003)(2351001)(2616005)(336012)(8676002)(53416004)(44832011)(11346002)(426003)(126002)(476003)(50466002)(246002)(48376002)(7696005)(51416003)(186003)(70206006)(8936002)(6916009)(70586007)(76176011)(107886003)(4326008)(77096007)(50226002);DIR:OUT;SFP:1101;SCL:1;SRVR:SN2PR03MB2272;H:nwd2mta2.analog.com;FPR:;SPF:Pass;LANG:en;PTR:nwd2mail11.analog.com;MX:1;A:1; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 87cd3f18-4b89-4e9f-a628-08d6e50148eb X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(4709054)(1401327)(2017052603328);SRVR:SN2PR03MB2272; X-MS-TrafficTypeDiagnostic: SN2PR03MB2272: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-Forefront-PRVS: 00531FAC2C X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: WKwxg0paOM/KFgy+f0yCbjInnnu+Tg7c0GPFmAx75KJapPYD6sHRi2+ZNFZY2ei/uaYmDmK/HzFNhPxX4/Bvk9RDC1q9CRb0zcZ/fzX3/qMw4HWqL+JNtI5PlPnEaT1lqiNcj4TgueqgnSpE4POoGcuGkt69z1JunIOyaedkLx8lDvGvvLKl/nlFZqDAPUvxwKL3jmWSEVSV9AVVYMA0XWoDyEahlz0iDYIMcjMelnZtQAwcecUA05iy810v/xHq/VEV2l9G68tswbkCVpVeTUpB51Y3SKU9uwy9iKHGGrcr0+VUvJbx6LISb/20Bx1lH+0ML9/h757L+O9ksY61Rnp0fPJRw8dQfyOEyNB9R/UnJsq6SBmg1WkEyTPe5DgJe9WWE36sJqZKHg1yzSCiUTaNcJYpmKU/6lUU98x1oXY= X-OriginatorOrg: analog.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 May 2019 13:18:19.9704 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 87cd3f18-4b89-4e9f-a628-08d6e50148eb 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: SN2PR03MB2272 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 This driver is still using iio_dev's mlock to guard against inconsistent state. This has been discouraged for some time. This change switches to using it's own mutex, defined on the state struct. Signed-off-by: Alexandru Ardelean --- drivers/iio/amplifiers/ad8366.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/iio/amplifiers/ad8366.c b/drivers/iio/amplifiers/ad8366.c index 82ac15914ff3..24ff5475d9f2 100644 --- a/drivers/iio/amplifiers/ad8366.c +++ b/drivers/iio/amplifiers/ad8366.c @@ -21,6 +21,7 @@ struct ad8366_state { struct spi_device *spi; struct regulator *reg; + struct mutex lock; /* protect sensor state */ unsigned char ch[2]; /* * DMA (thus cache coherency maintenance) requires the @@ -58,7 +59,7 @@ static int ad8366_read_raw(struct iio_dev *indio_dev, int ret; unsigned code; - mutex_lock(&indio_dev->mlock); + mutex_lock(&st->lock); switch (m) { case IIO_CHAN_INFO_HARDWAREGAIN: code = st->ch[chan->channel]; @@ -73,7 +74,7 @@ static int ad8366_read_raw(struct iio_dev *indio_dev, default: ret = -EINVAL; } - mutex_unlock(&indio_dev->mlock); + mutex_unlock(&st->lock); return ret; }; @@ -99,7 +100,7 @@ static int ad8366_write_raw(struct iio_dev *indio_dev, code = (code - 4500) / 253; - mutex_lock(&indio_dev->mlock); + mutex_lock(&st->lock); switch (mask) { case IIO_CHAN_INFO_HARDWAREGAIN: st->ch[chan->channel] = code; @@ -108,7 +109,7 @@ static int ad8366_write_raw(struct iio_dev *indio_dev, default: ret = -EINVAL; } - mutex_unlock(&indio_dev->mlock); + mutex_unlock(&st->lock); return ret; } @@ -151,6 +152,7 @@ static int ad8366_probe(struct spi_device *spi) } spi_set_drvdata(spi, indio_dev); + mutex_init(&st->lock); st->spi = spi; indio_dev->dev.parent = &spi->dev; From patchwork Thu May 30 13:18:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 10968713 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CEDFE14C0 for ; Thu, 30 May 2019 13:18:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C0CB128739 for ; Thu, 30 May 2019 13:18:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B503F2884A; Thu, 30 May 2019 13:18:25 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 0E81B288F7 for ; Thu, 30 May 2019 13:18:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726031AbfE3NSY (ORCPT ); Thu, 30 May 2019 09:18:24 -0400 Received: from mail-eopbgr790044.outbound.protection.outlook.com ([40.107.79.44]:43084 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726557AbfE3NSY (ORCPT ); Thu, 30 May 2019 09:18:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=analog.onmicrosoft.com; s=selector1-analog-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/nqCcnM0fIyA+uAqeJ/aznZCWdOyU4mW+lzWkFXNqqU=; b=htqAoUxrDyJkjs7h2t5XWFxD91KCrtZ+FZgaYDurx8hdhZpF41m09Nr3JRqlGlJeiOT0WYvuOUbSyUU8u7Z5WOhiDI4sgat5eLV3/DaYBgLxyJ9lKKBKPlAEV6uuYTfFUGJ72bbLtksdbsYjmeG2iyqcmt/OZ5+WHfBn/fSJWS8= Received: from DM6PR03CA0026.namprd03.prod.outlook.com (2603:10b6:5:40::39) by DM2PR03MB557.namprd03.prod.outlook.com (2a01:111:e400:241b::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1922.20; Thu, 30 May 2019 13:18:21 +0000 Received: from BL2NAM02FT017.eop-nam02.prod.protection.outlook.com (2a01:111:f400:7e46::209) by DM6PR03CA0026.outlook.office365.com (2603:10b6:5:40::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1943.17 via Frontend Transport; Thu, 30 May 2019 13:18:21 +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=nwd2mta2.analog.com; Received: from nwd2mta2.analog.com (137.71.25.57) by BL2NAM02FT017.mail.protection.outlook.com (10.152.77.174) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.1922.16 via Frontend Transport; Thu, 30 May 2019 13:18:21 +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 x4UDIKof024240 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=OK) for ; Thu, 30 May 2019 06:18:20 -0700 Received: from saturn.analog.com (10.50.1.244) by NWD2HUBCAS7.ad.analog.com (10.64.69.107) with Microsoft SMTP Server id 14.3.408.0; Thu, 30 May 2019 09:18:20 -0400 From: Alexandru Ardelean To: CC: Alexandru Ardelean Subject: [PATCH 3/5] iio: amplifiers: ad8366: rework driver to allow other chips Date: Thu, 30 May 2019 16:18:10 +0300 Message-ID: <20190530131812.3476-3-alexandru.ardelean@analog.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190530131812.3476-1-alexandru.ardelean@analog.com> References: <20190530131812.3476-1-alexandru.ardelean@analog.com> MIME-Version: 1.0 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)(376002)(396003)(39860400002)(136003)(346002)(2980300002)(199004)(189003)(107886003)(2870700001)(356004)(446003)(126002)(6916009)(426003)(336012)(5660300002)(11346002)(486006)(478600001)(2906002)(70586007)(305945005)(7636002)(53416004)(4326008)(7696005)(51416003)(476003)(2616005)(76176011)(186003)(6666004)(8676002)(316002)(77096007)(26005)(86362001)(44832011)(106002)(1076003)(36756003)(246002)(50466002)(8936002)(2351001)(14444005)(70206006)(50226002)(47776003)(48376002);DIR:OUT;SFP:1101;SCL:1;SRVR:DM2PR03MB557;H:nwd2mta2.analog.com;FPR:;SPF:Pass;LANG:en;PTR:nwd2mail11.analog.com;A:1;MX:1; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: beeed77c-2558-4df5-0ca2-08d6e5014989 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(4709054)(1401327)(2017052603328);SRVR:DM2PR03MB557; X-MS-TrafficTypeDiagnostic: DM2PR03MB557: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-Forefront-PRVS: 00531FAC2C X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: GwJfzcVnhQyEZSYAK/elS0shECeb0++lfDFUx3bKiWD8FfDJNaA/s767xEGjyz/lcmtvZxTreFDhCUis0jPV7iZi4mX6dm+oWp7fM+ttu6AkMw1Y+ggiZvHvlwqBwrtR5XZkCS3IL2TCnYYg+yKUn+8MNvmgXgukDZPEc8zPdjnPwtQzioEoi5nVFWpqYrMgEYxwVqSXtRq7keO/0DQaZxivOqDFSJNz8/JQwdO8cgrRQp3Q94bKxFk9iXmB4FODMX19uJ9s/kfwwmXZncftRu2qVQytGgnOETIrzc3XHRrS0DoPPlo/i6SuNOvpTzi7FWa+Ym3blZcQzlcSjVIPeMFr1IX2XXfdXCRcDjXTsyDaYYywLlXeAuscSLjaRusBlVLvNBNogI0SAhPxbpxwNKZF+7mTNOMngA4HmvKMwFE= X-OriginatorOrg: analog.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 May 2019 13:18:21.0049 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: beeed77c-2558-4df5-0ca2-08d6e5014989 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: DM2PR03MB557 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 The SPI gain amplifiers are simple devices, with 1 or 2 channels, to which are read-from/written-to. The gain computation in ad8366_write_raw() has been updated to compute gain in dB for negative values. This driver will be extended to support other chips as well. To do that, this rework handles the AD8366 device as a special-case (via switch-statements). This will make things easier when adding new chips. Signed-off-by: Alexandru Ardelean --- drivers/iio/amplifiers/ad8366.c | 81 +++++++++++++++++++++++++-------- 1 file changed, 62 insertions(+), 19 deletions(-) diff --git a/drivers/iio/amplifiers/ad8366.c b/drivers/iio/amplifiers/ad8366.c index 24ff5475d9f2..1beda6409301 100644 --- a/drivers/iio/amplifiers/ad8366.c +++ b/drivers/iio/amplifiers/ad8366.c @@ -18,11 +18,22 @@ #include #include +enum ad8366_type { + ID_AD8366, +}; + +struct ad8366_info { + int gain_min; + int gain_max; +}; + struct ad8366_state { struct spi_device *spi; struct regulator *reg; struct mutex lock; /* protect sensor state */ unsigned char ch[2]; + enum ad8366_type type; + struct ad8366_info *info; /* * DMA (thus cache coherency maintenance) requires the * transfer buffers to live in their own cache lines. @@ -30,19 +41,30 @@ struct ad8366_state { unsigned char data[2] ____cacheline_aligned; }; +static struct ad8366_info ad8366_infos[] = { + [ID_AD8366] = { + .gain_min = 4500, + .gain_max = 20500, + }, +}; + static int ad8366_write(struct iio_dev *indio_dev, unsigned char ch_a, unsigned char ch_b) { struct ad8366_state *st = iio_priv(indio_dev); int ret; - ch_a = bitrev8(ch_a & 0x3F); - ch_b = bitrev8(ch_b & 0x3F); + switch (st->type) { + case ID_AD8366: + ch_a = bitrev8(ch_a & 0x3F); + ch_b = bitrev8(ch_b & 0x3F); - st->data[0] = ch_b >> 4; - st->data[1] = (ch_b << 4) | (ch_a >> 2); + st->data[0] = ch_b >> 4; + st->data[1] = (ch_b << 4) | (ch_a >> 2); + break; + } - ret = spi_write(st->spi, st->data, ARRAY_SIZE(st->data)); + ret = spi_write(st->spi, st->data, indio_dev->num_channels); if (ret < 0) dev_err(&indio_dev->dev, "write failed (%d)", ret); @@ -57,17 +79,22 @@ static int ad8366_read_raw(struct iio_dev *indio_dev, { struct ad8366_state *st = iio_priv(indio_dev); int ret; - unsigned code; + int code, gain = 0; mutex_lock(&st->lock); switch (m) { case IIO_CHAN_INFO_HARDWAREGAIN: code = st->ch[chan->channel]; + switch (st->type) { + case ID_AD8366: + gain = code * 253 + 4500; + break; + } + /* Values in dB */ - code = code * 253 + 4500; - *val = code / 1000; - *val2 = (code % 1000) * 1000; + *val = gain / 1000; + *val2 = (gain % 1000) * 1000; ret = IIO_VAL_INT_PLUS_MICRO_DB; break; @@ -86,19 +113,24 @@ static int ad8366_write_raw(struct iio_dev *indio_dev, long mask) { struct ad8366_state *st = iio_priv(indio_dev); - unsigned code; + struct ad8366_info *inf = st->info; + int code = 0, gain; int ret; - if (val < 0 || val2 < 0) - return -EINVAL; - /* Values in dB */ - code = (((u8)val * 1000) + ((u32)val2 / 1000)); + if (val < 0) + gain = (val * 1000) - (val2 / 1000); + else + gain = (val * 1000) + (val2 / 1000); - if (code > 20500 || code < 4500) + if (gain > inf->gain_max || gain < inf->gain_min) return -EINVAL; - code = (code - 4500) / 253; + switch (st->type) { + case ID_AD8366: + code = (gain - 4500) / 253; + break; + } mutex_lock(&st->lock); switch (mask) { @@ -154,13 +186,24 @@ static int ad8366_probe(struct spi_device *spi) spi_set_drvdata(spi, indio_dev); mutex_init(&st->lock); st->spi = spi; + st->type = spi_get_device_id(spi)->driver_data; + + switch (st->type) { + case ID_AD8366: + indio_dev->channels = ad8366_channels; + indio_dev->num_channels = ARRAY_SIZE(ad8366_channels); + break; + default: + dev_err(&spi->dev, "Invalid device ID\n"); + ret = -EINVAL; + goto error_disable_reg; + } + st->info = &ad8366_infos[st->type]; indio_dev->dev.parent = &spi->dev; indio_dev->name = spi_get_device_id(spi)->name; indio_dev->info = &ad8366_info; indio_dev->modes = INDIO_DIRECT_MODE; - indio_dev->channels = ad8366_channels; - indio_dev->num_channels = ARRAY_SIZE(ad8366_channels); ret = ad8366_write(indio_dev, 0 , 0); if (ret < 0) @@ -194,7 +237,7 @@ static int ad8366_remove(struct spi_device *spi) } static const struct spi_device_id ad8366_id[] = { - {"ad8366", 0}, + {"ad8366", ID_AD8366}, {} }; MODULE_DEVICE_TABLE(spi, ad8366_id); From patchwork Thu May 30 13:18:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 10968715 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D7B4C14C0 for ; Thu, 30 May 2019 13:18:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C8B5028658 for ; Thu, 30 May 2019 13:18:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BD52C288F7; Thu, 30 May 2019 13:18:26 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 27A6828739 for ; Thu, 30 May 2019 13:18:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726557AbfE3NSZ (ORCPT ); Thu, 30 May 2019 09:18:25 -0400 Received: from mail-eopbgr720053.outbound.protection.outlook.com ([40.107.72.53]:5062 "EHLO NAM05-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725919AbfE3NSZ (ORCPT ); Thu, 30 May 2019 09:18:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=analog.onmicrosoft.com; s=selector1-analog-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WPNoV7LAFcqtIErQgXV/LKzyp/cD2BJ5GqozgM8s4ZM=; b=Dqpr15KDN5SKHGnLQBRBSTODdd1MJZTapXDgY0CZcs4O/+TXuYz55YpLhwbY5nYPbQnNytcNp13gRnvE2v98hg06M4qqD9JyccXTvkbstKPG5bQB4FQ8oKytAVFK1vUACamZxcI98G//M/BfpPr/l50jsCiUP8pTc0Sx7dwtK+Y= Received: from DM6PR03CA0063.namprd03.prod.outlook.com (2603:10b6:5:100::40) by DM2PR03MB560.namprd03.prod.outlook.com (2a01:111:e400:241c::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1943.17; Thu, 30 May 2019 13:18:22 +0000 Received: from BL2NAM02FT057.eop-nam02.prod.protection.outlook.com (2a01:111:f400:7e46::208) by DM6PR03CA0063.outlook.office365.com (2603:10b6:5:100::40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1943.17 via Frontend Transport; Thu, 30 May 2019 13:18:22 +0000 Authentication-Results: spf=pass (sender IP is 137.71.25.55) 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.55 as permitted sender) receiver=protection.outlook.com; client-ip=137.71.25.55; helo=nwd2mta1.analog.com; Received: from nwd2mta1.analog.com (137.71.25.55) by BL2NAM02FT057.mail.protection.outlook.com (10.152.77.36) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.1922.16 via Frontend Transport; Thu, 30 May 2019 13:18:22 +0000 Received: from NWD2HUBCAS7.ad.analog.com (nwd2hubcas7.ad.analog.com [10.64.69.107]) by nwd2mta1.analog.com (8.13.8/8.13.8) with ESMTP id x4UDIMeV015965 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=OK) for ; Thu, 30 May 2019 06:18:22 -0700 Received: from saturn.analog.com (10.50.1.244) by NWD2HUBCAS7.ad.analog.com (10.64.69.107) with Microsoft SMTP Server id 14.3.408.0; Thu, 30 May 2019 09:18:21 -0400 From: Alexandru Ardelean To: CC: Paul Cercueil , Michael Hennerich , Alexandru Ardelean Subject: [PATCH 4/5] iio: amplifiers: ad8366: Add support for the ADA4961 DGA Date: Thu, 30 May 2019 16:18:11 +0300 Message-ID: <20190530131812.3476-4-alexandru.ardelean@analog.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190530131812.3476-1-alexandru.ardelean@analog.com> References: <20190530131812.3476-1-alexandru.ardelean@analog.com> MIME-Version: 1.0 X-ADIRoutedOnPrem: True X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:137.71.25.55;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(136003)(39860400002)(346002)(396003)(376002)(2980300002)(199004)(189003)(8676002)(14444005)(2870700001)(186003)(50226002)(8936002)(2616005)(305945005)(11346002)(1076003)(54906003)(6916009)(44832011)(246002)(36756003)(86362001)(7636002)(336012)(5660300002)(77096007)(2906002)(26005)(50466002)(476003)(2351001)(106002)(70206006)(966005)(446003)(53416004)(486006)(316002)(4326008)(47776003)(6306002)(6666004)(51416003)(7696005)(426003)(48376002)(107886003)(126002)(478600001)(70586007)(356004)(76176011);DIR:OUT;SFP:1101;SCL:1;SRVR:DM2PR03MB560;H:nwd2mta1.analog.com;FPR:;SPF:Pass;LANG:en;PTR:nwd2mail10.analog.com;A:1;MX:1; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 777fb962-2284-4428-0506-08d6e5014a45 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(5600148)(711020)(4605104)(4709054)(1401327)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328);SRVR:DM2PR03MB560; X-MS-TrafficTypeDiagnostic: DM2PR03MB560: X-MS-Exchange-PUrlCount: 1 X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-Forefront-PRVS: 00531FAC2C X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: xqZFtYv6IGLjxote4dhQZzKxrv3gRl8TipdrreEnjKN1bq9Hj5UGUfRAT6TbhtPM7aCaWb1GMNFLGDuBC9MrS77DixBpSiYO8OVbqqGoC64jpJQDT7z24GAwhVlDYCzmBC7L1v0/erHQU3L2kPOt55OVKMk657nJO5FUMcVqLdNz86hLBMrNLtei0WSEcmuSw/bhM0JFYkzzfChTQl1MDpLDTWBkKp1BfClG9lAn/aPjDYwLL78IcOtKpCfM2syW7pTJbWOjo0Fe/e8lbI5D/jNjqntWlqTmqIXfoAXFFp3Miv9SpJ24rslN3X/FuDxXl49jUUJSykH+r3kWJmHJczYvkU8PR/s2LYT6OWaHpKr5gAYrGwE4CRwO6kn9eqeowSgR2RSSz8e2UuJ/fEych6WwtIaQWjjhtCNqd31Qa/A= X-OriginatorOrg: analog.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 May 2019 13:18:22.2348 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 777fb962-2284-4428-0506-08d6e5014a45 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.55];Helo=[nwd2mta1.analog.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR03MB560 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: Paul Cercueil This change adds support for the ADA4961 BiCMOS RF Digital Gain Amplifier, (DGA), which is optimized for driving heavy loads out 2.0 GHz and beyond. The device typically achieves -90 dBc IMD3 performance at 500 MHz and -85 dBc at 1.5 GHz. Datasheet link: http://www.analog.com/media/en/technical-documentation/data-sheets/ADA4961.pdf This change re-uses the existing ad8366 driver, as most logic is similar. Also, this chip has a reset pin which is initialized during probe. Signed-off-by: Paul Cercueil Signed-off-by: Michael Hennerich Signed-off-by: Alexandru Ardelean --- drivers/iio/amplifiers/Kconfig | 9 ++++++--- drivers/iio/amplifiers/ad8366.c | 34 +++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/drivers/iio/amplifiers/Kconfig b/drivers/iio/amplifiers/Kconfig index da5830da9bcf..259058da8811 100644 --- a/drivers/iio/amplifiers/Kconfig +++ b/drivers/iio/amplifiers/Kconfig @@ -7,12 +7,15 @@ menu "Amplifiers" config AD8366 - tristate "Analog Devices AD8366 VGA" + tristate "Analog Devices AD8366 and similar Gain Amplifiers" depends on SPI select BITREVERSE help - Say yes here to build support for Analog Devices AD8366 - SPI Dual-Digital Variable Gain Amplifier (VGA). + Say yes here to build support for Analog Devices AD8366 and similar + gain amplifiers. This driver supports the following gain amplifiers + from Analog Devices: + AD8366 Dual-Digital Variable Gain Amplifier (VGA) + ADA4961 BiCMOS RF Digital Gain Amplifier (DGA) To compile this driver as a module, choose M here: the module will be called ad8366. diff --git a/drivers/iio/amplifiers/ad8366.c b/drivers/iio/amplifiers/ad8366.c index 1beda6409301..0a9883e8eb2e 100644 --- a/drivers/iio/amplifiers/ad8366.c +++ b/drivers/iio/amplifiers/ad8366.c @@ -1,6 +1,9 @@ // SPDX-License-Identifier: GPL-2.0 /* - * AD8366 SPI Dual-Digital Variable Gain Amplifier (VGA) + * AD8366 and similar Gain Amplifiers + * This driver supports the following gain amplifiers: + * AD8366 Dual-Digital Variable Gain Amplifier (VGA) + * ADA4961 BiCMOS RF Digital Gain Amplifier (DGA) * * Copyright 2012-2019 Analog Devices Inc. */ @@ -11,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -20,6 +24,7 @@ enum ad8366_type { ID_AD8366, + ID_ADA4961, }; struct ad8366_info { @@ -31,6 +36,7 @@ struct ad8366_state { struct spi_device *spi; struct regulator *reg; struct mutex lock; /* protect sensor state */ + struct gpio_desc *reset_gpio; unsigned char ch[2]; enum ad8366_type type; struct ad8366_info *info; @@ -46,6 +52,10 @@ static struct ad8366_info ad8366_infos[] = { .gain_min = 4500, .gain_max = 20500, }, + [ID_ADA4961] = { + .gain_min = -6000, + .gain_max = 15000, + }, }; static int ad8366_write(struct iio_dev *indio_dev, @@ -62,6 +72,9 @@ static int ad8366_write(struct iio_dev *indio_dev, st->data[0] = ch_b >> 4; st->data[1] = (ch_b << 4) | (ch_a >> 2); break; + case ID_ADA4961: + st->data[0] = ch_a & 0x1F; + break; } ret = spi_write(st->spi, st->data, indio_dev->num_channels); @@ -90,6 +103,9 @@ static int ad8366_read_raw(struct iio_dev *indio_dev, case ID_AD8366: gain = code * 253 + 4500; break; + case ID_ADA4961: + gain = 15000 - code * 1000; + break; } /* Values in dB */ @@ -130,6 +146,9 @@ static int ad8366_write_raw(struct iio_dev *indio_dev, case ID_AD8366: code = (gain - 4500) / 253; break; + case ID_ADA4961: + code = (15000 - gain) / 1000; + break; } mutex_lock(&st->lock); @@ -164,6 +183,10 @@ static const struct iio_chan_spec ad8366_channels[] = { AD8366_CHAN(1), }; +static const struct iio_chan_spec ada4961_channels[] = { + AD8366_CHAN(0), +}; + static int ad8366_probe(struct spi_device *spi) { struct iio_dev *indio_dev; @@ -193,6 +216,12 @@ static int ad8366_probe(struct spi_device *spi) indio_dev->channels = ad8366_channels; indio_dev->num_channels = ARRAY_SIZE(ad8366_channels); break; + case ID_ADA4961: + st->reset_gpio = devm_gpiod_get(&spi->dev, "reset", + GPIOD_OUT_HIGH); + indio_dev->channels = ada4961_channels; + indio_dev->num_channels = ARRAY_SIZE(ada4961_channels); + break; default: dev_err(&spi->dev, "Invalid device ID\n"); ret = -EINVAL; @@ -238,6 +267,7 @@ static int ad8366_remove(struct spi_device *spi) static const struct spi_device_id ad8366_id[] = { {"ad8366", ID_AD8366}, + {"ada4961", ID_ADA4961}, {} }; MODULE_DEVICE_TABLE(spi, ad8366_id); @@ -254,5 +284,5 @@ static struct spi_driver ad8366_driver = { module_spi_driver(ad8366_driver); MODULE_AUTHOR("Michael Hennerich "); -MODULE_DESCRIPTION("Analog Devices AD8366 VGA"); +MODULE_DESCRIPTION("Analog Devices AD8366 and similar Gain Amplifiers"); MODULE_LICENSE("GPL v2"); From patchwork Thu May 30 13:18:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 10968719 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0570B14C0 for ; Thu, 30 May 2019 13:18:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ECDCC285D9 for ; Thu, 30 May 2019 13:18:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E12A6288F7; Thu, 30 May 2019 13:18:42 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 691C2285D9 for ; Thu, 30 May 2019 13:18:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726604AbfE3NSl (ORCPT ); Thu, 30 May 2019 09:18:41 -0400 Received: from mail-eopbgr720068.outbound.protection.outlook.com ([40.107.72.68]:23787 "EHLO NAM05-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725919AbfE3NSk (ORCPT ); Thu, 30 May 2019 09:18:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=analog.onmicrosoft.com; s=selector1-analog-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Trlajzb0awiOTSvrQOKtls3/+u4AKlRVcMYz9lJR3rg=; b=bOvm4J2MuvGqwkk/cqY9G0OZOxwB9/qPryHyMNPJ22z+2QJtPgh53AOokd/iufhrrmb5tWIS+BvPeNbUKnxTHEaK9euZplpSwQIm5JqpsloZd6KOb+J2hq6PronCkjI4DThY1P/e0aUN5h2ZhHgjQADiIIEwsHxh9mm41bcc/BY= Received: from BN3PR03CA0063.namprd03.prod.outlook.com (2a01:111:e400:7a4d::23) by DM5PR03MB3129.namprd03.prod.outlook.com (2603:10b6:4:3c::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1943.17; Thu, 30 May 2019 13:18:24 +0000 Received: from BL2NAM02FT026.eop-nam02.prod.protection.outlook.com (2a01:111:f400:7e46::209) by BN3PR03CA0063.outlook.office365.com (2a01:111:e400:7a4d::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1943.16 via Frontend Transport; Thu, 30 May 2019 13:18:24 +0000 Authentication-Results: spf=pass (sender IP is 137.71.25.55) 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.55 as permitted sender) receiver=protection.outlook.com; client-ip=137.71.25.55; helo=nwd2mta1.analog.com; Received: from nwd2mta1.analog.com (137.71.25.55) by BL2NAM02FT026.mail.protection.outlook.com (10.152.77.156) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.1922.16 via Frontend Transport; Thu, 30 May 2019 13:18:23 +0000 Received: from NWD2HUBCAS7.ad.analog.com (nwd2hubcas7.ad.analog.com [10.64.69.107]) by nwd2mta1.analog.com (8.13.8/8.13.8) with ESMTP id x4UDINjp015968 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=OK) for ; Thu, 30 May 2019 06:18:23 -0700 Received: from saturn.analog.com (10.50.1.244) by NWD2HUBCAS7.ad.analog.com (10.64.69.107) with Microsoft SMTP Server id 14.3.408.0; Thu, 30 May 2019 09:18:23 -0400 From: Alexandru Ardelean To: CC: Alexandru Ardelean Subject: [PATCH 5/5] iio: amplifiers: ad8366: Add support for ADL5240 VGA Date: Thu, 30 May 2019 16:18:12 +0300 Message-ID: <20190530131812.3476-5-alexandru.ardelean@analog.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190530131812.3476-1-alexandru.ardelean@analog.com> References: <20190530131812.3476-1-alexandru.ardelean@analog.com> MIME-Version: 1.0 X-ADIRoutedOnPrem: True X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:137.71.25.55;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(136003)(39860400002)(346002)(376002)(396003)(2980300002)(189003)(199004)(356004)(6666004)(7636002)(8936002)(77096007)(8676002)(6916009)(50226002)(246002)(186003)(26005)(336012)(426003)(966005)(6306002)(305945005)(70586007)(316002)(70206006)(478600001)(107886003)(47776003)(5820100001)(2351001)(53416004)(36756003)(2906002)(4326008)(1076003)(5660300002)(50466002)(76176011)(7696005)(14444005)(106002)(23676004)(486006)(2870700001)(446003)(11346002)(2616005)(476003)(126002)(44832011)(86362001);DIR:OUT;SFP:1101;SCL:1;SRVR:DM5PR03MB3129;H:nwd2mta1.analog.com;FPR:;SPF:Pass;LANG:en;PTR:nwd2mail10.analog.com;MX:1;A:1; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 83d88d08-04e3-45db-47e5-08d6e5014b20 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(4709054)(1401327)(2017052603328);SRVR:DM5PR03MB3129; X-MS-TrafficTypeDiagnostic: DM5PR03MB3129: X-MS-Exchange-PUrlCount: 1 X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-Forefront-PRVS: 00531FAC2C X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: cBlueqRDPnpvoN0pkphdaCB9/rBd9MthFQORhut+wOnlmf6+aogUb1Lu4ghbHkmmiRiAkzBJZrWRNUDROghOZERxsW8TFAiZUP0WcaXOps/RwwapJd2EavFFgq0c3zn7rGRxem8CMMhnRHBTinMPo8nFik7JA6fKzKwJ3ctNpYlkR0ZWwEc5BgZWq+aLMzCv6INPq6EJ4XT7T+iMsO2UXirtdFLQi1i+0IYlOdejEbG+yUg9od1U5TXvAimI7RLAhaT3mkiSyr7IMZzfAXhm+Y+MuN4xpbW6Yz4uzN6d+25v+mnAvhe02GXAGytdi3VGS/vxY24G1r/4pOF2hOgZ0kT5oHa0SgCFBb0nc8Zt+6Cd7GVBhvC5Pz+u1rO0nUuNEZL2g2/uVXC+1cPAY5+A+j1EA/RjtNOsedUKoB7ubGc= X-OriginatorOrg: analog.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 May 2019 13:18:23.6707 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 83d88d08-04e3-45db-47e5-08d6e5014b20 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.55];Helo=[nwd2mta1.analog.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR03MB3129 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 The ADL5240 is a high performance, digitally controlled variable gain amplifier (VGA) operating from 100 MHz to 4000 MHz. The VGA integrates a high performance, 20 dB gain, internally matched amplifier (AMP) with a 6-bit digital step attenuator (DSA) that has a gain control range of 31.5 dB in 0.5 dB steps with ±0.25 dB step accuracy. Datasheet link: https://www.analog.com/media/en/technical-documentation/data-sheets/adl5240.pdf Signed-off-by: Alexandru Ardelean --- drivers/iio/amplifiers/Kconfig | 1 + drivers/iio/amplifiers/ad8366.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/drivers/iio/amplifiers/Kconfig b/drivers/iio/amplifiers/Kconfig index 259058da8811..871e8060d996 100644 --- a/drivers/iio/amplifiers/Kconfig +++ b/drivers/iio/amplifiers/Kconfig @@ -16,6 +16,7 @@ config AD8366 from Analog Devices: AD8366 Dual-Digital Variable Gain Amplifier (VGA) ADA4961 BiCMOS RF Digital Gain Amplifier (DGA) + ADL5240 Digitally controlled variable gain amplifier (VGA) To compile this driver as a module, choose M here: the module will be called ad8366. diff --git a/drivers/iio/amplifiers/ad8366.c b/drivers/iio/amplifiers/ad8366.c index 0a9883e8eb2e..0176d3d8cc9c 100644 --- a/drivers/iio/amplifiers/ad8366.c +++ b/drivers/iio/amplifiers/ad8366.c @@ -4,6 +4,7 @@ * This driver supports the following gain amplifiers: * AD8366 Dual-Digital Variable Gain Amplifier (VGA) * ADA4961 BiCMOS RF Digital Gain Amplifier (DGA) + * ADL5240 Digitally controlled variable gain amplifier (VGA) * * Copyright 2012-2019 Analog Devices Inc. */ @@ -25,6 +26,7 @@ enum ad8366_type { ID_AD8366, ID_ADA4961, + ID_ADL5240, }; struct ad8366_info { @@ -56,6 +58,10 @@ static struct ad8366_info ad8366_infos[] = { .gain_min = -6000, .gain_max = 15000, }, + [ID_ADL5240] = { + .gain_min = -11500, + .gain_max = 20000, + }, }; static int ad8366_write(struct iio_dev *indio_dev, @@ -75,6 +81,9 @@ static int ad8366_write(struct iio_dev *indio_dev, case ID_ADA4961: st->data[0] = ch_a & 0x1F; break; + case ID_ADL5240: + st->data[0] = (ch_a & 0x3F); + break; } ret = spi_write(st->spi, st->data, indio_dev->num_channels); @@ -106,6 +115,9 @@ static int ad8366_read_raw(struct iio_dev *indio_dev, case ID_ADA4961: gain = 15000 - code * 1000; break; + case ID_ADL5240: + gain = 20000 - 31500 + code * 500; + break; } /* Values in dB */ @@ -149,6 +161,9 @@ static int ad8366_write_raw(struct iio_dev *indio_dev, case ID_ADA4961: code = (15000 - gain) / 1000; break; + case ID_ADL5240: + code = ((gain - 500 - 20000) / 500) & 0x3F; + break; } mutex_lock(&st->lock); @@ -217,6 +232,7 @@ static int ad8366_probe(struct spi_device *spi) indio_dev->num_channels = ARRAY_SIZE(ad8366_channels); break; case ID_ADA4961: + case ID_ADL5240: st->reset_gpio = devm_gpiod_get(&spi->dev, "reset", GPIOD_OUT_HIGH); indio_dev->channels = ada4961_channels; @@ -268,6 +284,7 @@ static int ad8366_remove(struct spi_device *spi) static const struct spi_device_id ad8366_id[] = { {"ad8366", ID_AD8366}, {"ada4961", ID_ADA4961}, + {"adl5240", ID_ADL5240}, {} }; MODULE_DEVICE_TABLE(spi, ad8366_id);