From patchwork Tue Oct 2 12:34:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 10623599 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 2B71017E0 for ; Tue, 2 Oct 2018 12:35:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 29C8B288B6 for ; Tue, 2 Oct 2018 12:35:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1D42A288BC; Tue, 2 Oct 2018 12:35:29 +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 65D0E288B9 for ; Tue, 2 Oct 2018 12:35:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727714AbeJBTSe (ORCPT ); Tue, 2 Oct 2018 15:18:34 -0400 Received: from mail-cys01nam02on0066.outbound.protection.outlook.com ([104.47.37.66]:53165 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727555AbeJBTSe (ORCPT ); Tue, 2 Oct 2018 15:18:34 -0400 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=+FJB2fGZO+v4Cbeyzv1Yql4TS5SdUY9b+tF2oo5n5Do=; b=QyfEqviMaECs1M82i8PWB3blJWhid/jL18+LkX50O2GsFWkxjy1FsJVIZ4Q9xVqzirrgHY/Us03Vv1TRGIavYtuF9qGVGTd+oAWRWlP/1O2hkUl+e58taDRBWsCSRw3TknKTwyskhmeyW5+SFJgp9w2Ai/lE3cQ0bFmKyXsVZwo= Received: from BN3PR03CA0083.namprd03.prod.outlook.com (2a01:111:e400:7a4d::43) by BLUPR03MB550.namprd03.prod.outlook.com (2a01:111:e400:880::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1185.20; Tue, 2 Oct 2018 12:35:23 +0000 Received: from BY2FFO11FD021.protection.gbl (2a01:111:f400:7c0c::116) by BN3PR03CA0083.outlook.office365.com (2a01:111:e400:7a4d::43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1207.18 via Frontend Transport; Tue, 2 Oct 2018 12:35:23 +0000 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 BY2FFO11FD021.mail.protection.outlook.com (10.1.15.210) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.1164.13 via Frontend Transport; Tue, 2 Oct 2018 12:35:23 +0000 Received: from NWD2HUBCAS7.ad.analog.com (nwd2hubcas7.ad.analog.com [10.64.69.107]) by nwd2mta4.analog.com (8.13.8/8.13.8) with ESMTP id w92CZMvQ029538 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=OK); Tue, 2 Oct 2018 05:35:22 -0700 Received: from zeus.spd.analog.com (10.64.82.11) by NWD2HUBCAS7.ad.analog.com (10.64.69.107) with Microsoft SMTP Server id 14.3.301.0; Tue, 2 Oct 2018 08:35:23 -0400 Received: from saturn.analog.com ([10.50.1.244]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id w92CZD40026273; Tue, 2 Oct 2018 08:35:13 -0400 From: Alexandru Ardelean To: , CC: , , , , Paul Cercueil , "Michael Hennerich" , Alexandru Ardelean Subject: [PATCH] iio: amplifiers: ad8366: Add support for the ADA4961 DGA Date: Tue, 2 Oct 2018 15:34:46 +0300 Message-ID: <20181002123446.27121-1-alexandru.ardelean@analog.com> X-Mailer: git-send-email 2.17.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)(39860400002)(136003)(376002)(346002)(396003)(2980300002)(438002)(199004)(189003)(305945005)(8676002)(7636002)(336012)(8936002)(14444005)(186003)(316002)(1857600001)(1076002)(7696005)(86362001)(6306002)(107886003)(26005)(110136005)(54906003)(36756003)(2906002)(16586007)(50226002)(48376002)(51416003)(966005)(106002)(77096007)(50466002)(6346003)(47776003)(5660300001)(106466001)(6666003)(426003)(6636002)(478600001)(476003)(126002)(2616005)(486006)(246002)(44832011)(356003)(53416004)(4326008);DIR:OUT;SFP:1101;SCL:1;SRVR:BLUPR03MB550;H:nwd2mta4.analog.com;FPR:;SPF:Pass;LANG:en;PTR:nwd2mail11.analog.com;A:1;MX:1; X-Microsoft-Exchange-Diagnostics: 1;BY2FFO11FD021;1:IqazgQPqBZrb4mH9WD2YRtGJ2CDT31v7E/3Nfc1uCEurzjw8wjNGANyLCdtVyRtilmYqP/0dpLgc5f7VVATkgYlKoOqWREC/Zk1L5E6eOFK75lBO0LMa+yS3VSB4YBQb X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 22926a8e-5841-4118-6cfd-08d6286385ee X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989299)(4534165)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4608076)(2017052603328)(7153060);SRVR:BLUPR03MB550; X-Microsoft-Exchange-Diagnostics: 1;BLUPR03MB550;3:kQ158KgU+tqXqU9dhwQPSXSsyR/mERGealVjJ+9oiBxi1ufL87zacHNXnzmCedYR+/kgE3G8YX0UxU69fWV0ifVJTWLu3uURqRytd82XCTJrePZXRdWFkiwvvqU5Ez1LPlQ8qPil71XdCE05lnsBC1CAhi12pQTRdmVbP6IYsiqpZ23hKOLB5YoOrLc/mzQttJ/CJxrkRYBVOXWEVSsL0xLG3LZfjzDjciVLTxIZ3tpdVeMXycflO/7GF7aIGxxID3Iwvgyc2Pt0+EfPQmHq7+kEkOTk5wnkCo5MMC0yu3cgX2bBaQgbTfRxG5x0hkzSc7dFqWWsJ6gDM8R6WFSBlluPe7Qkl6uj36p1LbPBh6k=;25:btDXN0K7887YRhBxDB5XkgGaw3VibOie+7xy+GNmc6k86P1IbEHbX/7nngMsLIwFypn9iN3xlDnFObqdD4Rd1y7g3KuHpSngMsfbCXXdQqm3DxLc6MOWr5AjLjbDryRHrW1cDj5EikZcig/CZPZtHt7AV7mxsuhzMEZnvOL8xN9mU7j0b371Fv0V85Y1D5NDYWzJPSRCAVkzIuPonQxsV2HC035XhE0pWpkwYR4jE8ANiqP9xWNa7kJqUDcD8FI4JPfXFKCQrMCvMuc0j6R5ecZuYUjpeF2OodZEEFbKsylZKtcglLVvG6199qPTyAQVgriTZi79bzd8xwYzQI/NUA== X-MS-TrafficTypeDiagnostic: BLUPR03MB550: X-Microsoft-Exchange-Diagnostics: 1;BLUPR03MB550;31:HkD/tfsjDUJhf2Jxj1reHLo3pcsaXAohc/Mt1PY/5ieiMK3xxvykbjfZb2w+fvEzhGSgSiPZjuHVNr+phQqdV5VGesCQzL+eqRLAlRhtvA5mcOcDYfjNM5ZxlkBVDSd3YDdYde+f9YcCx5jlcyBX5YxcUqNTw5UWOMOoETynj7EeiyA0qqCuu+mteFzbkZ8jWktk4LGM2YA0vEEw50tMN6bmbPNQLELxHip+zsBuuEs=;20:H+y+SmQmwcTH2iWGXHkHmbwrGXUaj85WpSmTUQ0hWNLDOxTptGNaPpi2DLEaf770izGDyZy9SVcpAw+NCM0XRAKgDnjIVYlUDnEDCNzTuipiaeJwMyClphQlUFePkCc0Cqf/aIxow5a8ayWVxRj+MKDbhGeVJ6pn0VjxotmeMGqUJnfojfWEkUq1W+D8oSovGWbsUJ3pSzczr23LxDif4U1B+KK4PEYcXrqVjTPbCmO/kn8qVxM8Xvg3+AHpw2avpM99WCxQjaVPt9PG1Sq5P7BglUSuhJzESu/AyvShPZSiY43uDBzFUMdvHymVZKhRcDN1IQknz8m2eS+WaxIBkKSVq7w0xbqEU7mwRm+yrQifkPp2UmgpXwglFFi9a1fw/334DZK3Xw/Arl9Wo8S3vs/qN/SktkoYdOS451HKb6yNe0vKpdkioERLjrLrTztxxfiH+8THfXC7YdTAR5UP/MDsXaO1fI1cKfovT/dUkUA1qe5/vS+1YCmGyX6xjYMJ X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(232431446821674)(270121546159015); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3231355)(944501410)(4982022)(52105095)(3002001)(10201501046)(93006095)(93004095)(6055026)(149066)(150057)(6041310)(20161123558120)(20161123560045)(20161123564045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699051)(76991041);SRVR:BLUPR03MB550;BCL:0;PCL:0;RULEID:;SRVR:BLUPR03MB550; X-Microsoft-Exchange-Diagnostics: 1;BLUPR03MB550;4:aH8Ewb9YR3Ff8suM/srk94Fon0yrrW74/tdIqIqK73Kg94ho0riypbXyVNmRa6QYQiODSB69TsZChpzAT5aYUcE3RbrLnF0zuiuW1NyMxz0afFIcLe96GVwl5QgZPub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YMMCD8Q3NAjBCzKIG34Cf5u6iUeVs8BfQIy9BM36Oau9VFCbU1KghmI3cSDBHhEKuM1ac3ldhxep7ui377NxNQJ55p+Xk2HvqRHZ3+6g7tb9eBRh8tVMt2kHN9TavaEZI1aPiQ3J6rfp2siGUwOmxwaKfFdSksQ9fpDJw6Q3BgdUfmdTqduRqST5+pL+2Yx8u//ugT5WlV753Q==;5:ixDwIBziLgQuZVDR02SvTnrpj8Z+m8gOF9bFqvuUaN4Mt2Fb8DWzJc+6j5zMxSkzuJ90hc1nc7NRP/2RYNYzKCi8wLi4RBHliW8ad9BABbLJjToZASW5Xde79gaMKZbnmJ+PFreAGr2p7rmB7GUA8OGtSnElpdGWc//JJAiNlpQ=;7:xGTg9x/IJH6/5c4IxlWquWbQlVI0YjIdmf1abB354qOedL7ErLr/eB89ro/m9+pLe3FjtCO7lPK/HGg0aAiNMG8+PcdxwotL7JI3bmqftEz+WALTbo4LbTnxWphBun1qQQtHLzaN/SdlFhjC8PnMz/YbP4SpOKLfL9xyg/dBWWCE7+gBhEWb6foXnKHmyS1cWn2t930kaJi3kLUCrXMzTQd87yqCURYJ5nRKlv+asI239xKw/c31bJ0fR5EICXEz SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: analog.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Oct 2018 12:35:23.0403 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 22926a8e-5841-4118-6cfd-08d6286385ee 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: BLUPR03MB550 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. 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 | 100 +++++++++++++++++++++++++------- 2 files changed, 84 insertions(+), 25 deletions(-) diff --git a/drivers/iio/amplifiers/Kconfig b/drivers/iio/amplifiers/Kconfig index e9c5f2cd9257..db7ebf3effc8 100644 --- a/drivers/iio/amplifiers/Kconfig +++ b/drivers/iio/amplifiers/Kconfig @@ -6,12 +6,15 @@ menu "Amplifiers" config AD8366 - tristate "Analog Devices AD8366 VGA" + tristate "Analog Devices AD8366 and similar SPI 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 SPI Dual-Digital Variable Gain Amplifier (VGA) + ADA4961 SPI 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 4b76b61ba4be..04396c23e067 100644 --- a/drivers/iio/amplifiers/ad8366.c +++ b/drivers/iio/amplifiers/ad8366.c @@ -1,7 +1,10 @@ /* - * AD8366 SPI Dual-Digital Variable Gain Amplifier (VGA) + * AD8366 and similar SPI Gain Amplifiers + * This driver supports the following gain amplifiers: + * AD8366 SPI Dual-Digital Variable Gain Amplifier (VGA) + * ADA4961 SPI BiCMOS RF Digital Gain Amplifier (DGA) * - * Copyright 2012 Analog Devices Inc. + * Copyright 2012-2018 Analog Devices Inc. * * Licensed under the GPL-2. */ @@ -19,10 +22,17 @@ #include #include +enum ad8366_type { + ID_AD8366, + ID_ADA4961, +}; + struct ad8366_state { struct spi_device *spi; struct regulator *reg; unsigned char ch[2]; + enum ad8366_type type; + /* * DMA (thus cache coherency maintenance) requires the * transfer buffers to live in their own cache lines. @@ -36,13 +46,20 @@ static int ad8366_write(struct iio_dev *indio_dev, 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; + case ID_ADA4961: + st->data[0] = ch_a & 0x1F; + 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,15 +74,23 @@ static int ad8366_read_raw(struct iio_dev *indio_dev, { struct ad8366_state *st = iio_priv(indio_dev); int ret; - unsigned code; + int code; mutex_lock(&indio_dev->mlock); switch (m) { case IIO_CHAN_INFO_HARDWAREGAIN: code = st->ch[chan->channel]; + switch (st->type) { + case ID_AD8366: + code = code * 253 + 4500; + break; + case ID_ADA4961: + code = 15000 - code * 1000; + break; + } + /* Values in dB */ - code = code * 253 + 4500; *val = code / 1000; *val2 = (code % 1000) * 1000; @@ -86,19 +111,24 @@ static int ad8366_write_raw(struct iio_dev *indio_dev, long mask) { struct ad8366_state *st = iio_priv(indio_dev); - unsigned code; + int code; int ret; - if (val < 0 || val2 < 0) - return -EINVAL; - /* Values in dB */ - code = (((u8)val * 1000) + ((u32)val2 / 1000)); + code = (((s8)val * 1000) + ((s32)val2 / 1000)); - if (code > 20500 || code < 4500) - return -EINVAL; - - code = (code - 4500) / 253; + switch (st->type) { + case ID_AD8366: + if (code > 20500 || code < 4500) + return -EINVAL; + code = (code - 4500) / 253; + break; + case ID_ADA4961: + if (code > 15000 || code < -6000) + return -EINVAL; + code = (15000 - code) / 1000; + break; + } mutex_lock(&indio_dev->mlock); switch (mask) { @@ -132,6 +162,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; @@ -155,11 +189,32 @@ static int ad8366_probe(struct spi_device *spi) st->spi = spi; indio_dev->dev.parent = &spi->dev; - indio_dev->name = spi_get_device_id(spi)->name; + + /* try to get a unique name */ + if (spi->dev.platform_data) + indio_dev->name = spi->dev.platform_data; + else if (spi->dev.of_node) + indio_dev->name = spi->dev.of_node->name; + else + indio_dev->name = spi_get_device_id(spi)->name; + + 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; + case ID_ADA4961: + indio_dev->channels = ada4961_channels; + indio_dev->num_channels = ARRAY_SIZE(ada4961_channels); + break; + default: + dev_err(&spi->dev, "Invalid device ID\n"); + return -EINVAL; + } + 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) @@ -193,7 +248,8 @@ static int ad8366_remove(struct spi_device *spi) } static const struct spi_device_id ad8366_id[] = { - {"ad8366", 0}, + {"ad8366", ID_AD8366}, + {"ada4961", ID_ADA4961}, {} }; MODULE_DEVICE_TABLE(spi, ad8366_id);