From patchwork Sun Mar 18 13:36:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Veenstra X-Patchwork-Id: 10291169 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 2C21E600F6 for ; Sun, 18 Mar 2018 13:36:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1942B28E11 for ; Sun, 18 Mar 2018 13:36:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0D8C52900F; Sun, 18 Mar 2018 13:36:39 +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_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, 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 9E05728E11 for ; Sun, 18 Mar 2018 13:36:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753922AbeCRNgi (ORCPT ); Sun, 18 Mar 2018 09:36:38 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:53910 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752372AbeCRNgh (ORCPT ); Sun, 18 Mar 2018 09:36:37 -0400 Received: by mail-wm0-f66.google.com with SMTP id e194so10715342wmd.3 for ; Sun, 18 Mar 2018 06:36:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=vKaxad3mFzeymFKRnohGAf2jHLrKSHaLBz2+xbieyn4=; b=t2dYbBLd0D3PKTNzFPNvL4YosmHdaAFZu/DqYlApVyrZckAv+M0RJa8h4bjrPYjbB7 Me9yjWfVnVhNx08SONLWl+vA6Gq7OIM+ZVjsh3FD+fH+R+pXeMnLQXl/qhTXfQKa7/e1 jvY2U8Iquf9QBuzoyUchDb92ioVRWdAvkPv/qFo6exm3AkepqzfeVRilyLKOJgHARceC XJlQ/TUjezfMeoDyrxR5rbsVLaTeTXtxvWEmlvpeZ+4wCqBMtt1edv63YqnKxkuvdgjQ VFM3bg7kTToN/xbCrd2Pgi40gSUYLtQFyXLTckpbl+AAOZcIImatsPv6H5VVab36coWC 7fGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=vKaxad3mFzeymFKRnohGAf2jHLrKSHaLBz2+xbieyn4=; b=kpMr49oCrAnd1G+9HiKMCXI/JBWZYy8d1CU5U+xHxUpUvBnSmwls3OohDJzZNgVmBA LGsbsyLmmHQH36dG88+8aJSsqN5mWZvcJWQTZJLxpqWwbAiNYNvfvkDOZTZi6dIuYbHe BhSaveFG8RQf8/+Ln0cTkOxASPowWBfX3eWbCVRmrciwhWPMfgAzyIvaTu99r/9AuDGo oxRnUGTgG282TPJpwlat4QNqn88wfs7VxFODF0HGwNfntIHjZwLrmYdjwo6U8Myv4tNB wnrdpUAgoer6WQFppHP68WjvpSIR9sQDVEHpGwEwd2RwIGdJthuwF/x1sBM+UKsO9xoD vjWQ== X-Gm-Message-State: AElRT7Ho1GOUh2oeZaXzM3dGsXtAnG8drxVyA5LJj8exw/5DQ70BAeJZ vxHN2s9FKKg+qPeHbpTk6wdT0xGx X-Google-Smtp-Source: AG47ELsGSozG5ZM6s8+8subsulg6BPZ/SHoP87aOi9+hrqlglgIR8uaGncnwh6L0hIWdgNP5G5kndg== X-Received: by 10.80.171.166 with SMTP id u35mr5625688edc.259.1521380196345; Sun, 18 Mar 2018 06:36:36 -0700 (PDT) Received: from zenbook-arch (s559434a1.adsl.online.nl. [85.148.52.161]) by smtp.gmail.com with ESMTPSA id 93sm6602149edi.19.2018.03.18.06.36.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 18 Mar 2018 06:36:35 -0700 (PDT) Date: Sun, 18 Mar 2018 14:36:33 +0100 From: David Veenstra To: lars@metafoo.de, jic23@kernel.org Cc: Michael.Hennerich@analog.com, knaack.h@gmx.de, linux-iio@vger.kernel.org, devel@driverdev.osuosl.org Subject: [PATCH 08/11] staging: iio: ad2s1200: Replace legacy gpio ABI with modern ABI Message-ID: <0591e04105efe97eed662059ac8771a70fca5b46.1521379685.git.davidjulianveenstra@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) 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 legacy, integer based gpio ABI is replaced with the descriptor based ABI. For compatibility, it is first tried to use the platform data to request the gpio's. Otherwise, it looks for the "sample" and "rdvel" gpio function. Signed-off-by: David Veenstra --- drivers/staging/iio/resolver/ad2s1200.c | 51 ++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/drivers/staging/iio/resolver/ad2s1200.c b/drivers/staging/iio/resolver/ad2s1200.c index 6ce9ca13094a..7ee1d9f76dfb 100644 --- a/drivers/staging/iio/resolver/ad2s1200.c +++ b/drivers/staging/iio/resolver/ad2s1200.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -45,8 +46,8 @@ struct ad2s1200_state { struct mutex lock; struct spi_device *sdev; - int sample; - int rdvel; + struct gpio_desc *sample; + struct gpio_desc *rdvel; u8 rx[2] ____cacheline_aligned; }; @@ -61,12 +62,12 @@ static int ad2s1200_read_raw(struct iio_dev *indio_dev, u16 vel; mutex_lock(&st->lock); - gpio_set_value(st->sample, 0); + gpiod_set_value(st->sample, 0); /* delay (6 * AD2S1200_TSCLK + 20) nano seconds */ udelay(1); - gpio_set_value(st->sample, 1); - gpio_set_value(st->rdvel, !!(chan->type == IIO_ANGL)); + gpiod_set_value(st->sample, 1); + gpiod_set_value(st->rdvel, !!(chan->type == IIO_ANGL)); ret = spi_read(st->sdev, st->rx, 2); if (ret < 0) { @@ -124,13 +125,18 @@ static int ad2s1200_probe(struct spi_device *spi) dev = &spi->dev; - for (pn = 0; pn < AD2S1200_PN; pn++) { - ret = devm_gpio_request_one(dev, pins[pn], GPIOF_DIR_OUT, - DRV_NAME); - if (ret) { - dev_err(dev, "request gpio pin %d failed\n", - pins[pn]); - return ret; + if (pins) { + for (pn = 0; pn < AD2S1200_PN; pn++) { + ret = devm_gpio_request_one(dev, pins[pn], + GPIOF_DIR_OUT, + DRV_NAME); + if (ret) { + dev_err(dev, + "Failed to claim gpio %d\n: err=%d", + pins[pn], + ret); + return ret; + } } } @@ -142,8 +148,25 @@ static int ad2s1200_probe(struct spi_device *spi) st = iio_priv(indio_dev); mutex_init(&st->lock); st->sdev = spi; - st->sample = pins[0]; - st->rdvel = pins[1]; + + if (pins) { + st->sample = gpio_to_desc(pins[0]); + st->rdvel = gpio_to_desc(pins[1]); + } else { + st->sample = devm_gpiod_get(dev, "sample", GPIOD_OUT_LOW); + if (IS_ERR(st->sample)) { + dev_err(dev, "Failed to claim SAMPLE gpio: err=%ld\n", + PTR_ERR(st->sample)); + return PTR_ERR(st->sample); + } + + st->rdvel = devm_gpiod_get(dev, "rdvel", GPIOD_OUT_LOW); + if (IS_ERR(st->rdvel)) { + dev_err(dev, "Failed to claim RDVEL gpio: err=%ld\n", + PTR_ERR(st->rdvel)); + return PTR_ERR(st->rdvel); + } + } indio_dev->dev.parent = dev; indio_dev->info = &ad2s1200_info;