Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp5272154imm; Tue, 16 Oct 2018 07:49:24 -0700 (PDT) X-Google-Smtp-Source: ACcGV607qpHRnSoo/I6gnTiCui8jzZi0B0Hf7Z9vrbmk1AwgdlV2C4ykFBTQUqBOShxrwf0IvCCd X-Received: by 2002:a62:60c1:: with SMTP id u184-v6mr22493399pfb.114.1539701364914; Tue, 16 Oct 2018 07:49:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539701364; cv=none; d=google.com; s=arc-20160816; b=DGxFCE1aupWdRJT3o4sogIA9WBuF+QosyzYVbK2/Ujst09U935qNZyXbu0Uvd9+AFu qwe9ObHyQbN7T3gMBO23XFsgxkjUGswOoFhUsYZiy+vJRSDsvVWDTUNIqlkjzCu4ChhA UWg1O9xlq3rqIR7wU/zUPF7L6oH/iTbPAxkZlgUmusRsvwDrCFftDwX4oQrL7v4n9G6w gM0rYsvJiix4qyCtvSE3T8gz3sLMLMNgzfAHmWaZmygFWnK9h20VV2nt7SajmgOlPDBo cUmzaYb5IG9y+2myZvzq40Zq4fsrSjbYd2pw6oZTdj8MaW9MePSAPec3ceNQZPrNg0cI 3WQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature; bh=SZZEzm89nUQYCZIMdozLX5yhM1cilHIoym83KXh9g1U=; b=am0kjum/nij2KsmStGnCJcTUn91M0dDWZk1Y+UQzYx3oUmjeIgPnBf5XqSmprTK2Yt gbVJUGC04B48wCAw7CmnMuHdTaPqAvoAYite/jYWuStblEjM7ZxVCSYZQmUbFAsbpltZ MiRWRdGoCA3f82nCF+CnHmzBCGmhk3+5u0u+1sHKA4yuDKEh3bCi0riyXPYONBM72CrK uZZe3kp3GWdFoRQmCnZbvTvRFQG3zocXE2e3mFBJj8ju+C8sTtDWsRybuzWXrJPtn303 2t0r0acVj9huG0+S6VJtKm0ITnFcptW4kdgb9CAQiKW37sO/RA0Px68qYR3883EG0R8M EgEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=YLKfNX93; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k192-v6si13862395pgc.415.2018.10.16.07.49.08; Tue, 16 Oct 2018 07:49:24 -0700 (PDT) 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=@gmail.com header.s=20161025 header.b=YLKfNX93; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727229AbeJPWhX (ORCPT + 99 others); Tue, 16 Oct 2018 18:37:23 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:42874 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726986AbeJPWhW (ORCPT ); Tue, 16 Oct 2018 18:37:22 -0400 Received: by mail-pf1-f196.google.com with SMTP id f26-v6so11565381pfn.9; Tue, 16 Oct 2018 07:46:35 -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:mime-version:content-disposition :user-agent; bh=SZZEzm89nUQYCZIMdozLX5yhM1cilHIoym83KXh9g1U=; b=YLKfNX93ypOxOhED1Qthu0CAvblmwfBelOC5Lfeb3YiK65TvFdTeQerATwZYbYNAwh lEaSNnik7ocSrJya5HtruL9Z+RJ4GI7lP2ODBRl4wIHIPw5QNLspkEvgpeegAWIC4Qls cFTxBhxC04jdypypm7MA+eFN3tSK5SfsIZjOnRogj4up2KfTnQNeq7SmjXz5EzOk1vum g087R7XYfXwcnHkNzVbCZspMKBy7otx39/D7qHg3FzaaF04hFMy9qxmoLjolg14C8gNf voo/Y7h0BBQhJXF7YB/92/JxxVUi77axvEm0c5HAO1aB8cRIdgsO7tuYgSHHOdCXJdRH k2bw== 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:mime-version :content-disposition:user-agent; bh=SZZEzm89nUQYCZIMdozLX5yhM1cilHIoym83KXh9g1U=; b=ToxANUpBi9Xm4d1E2ru7ash58u5olBGF5hxCXFVUTsEh6a5Tp0+BRQumrdFy42w/Zq T/zGl5JbO/e6b10/ZowXBDzPGwAjHJg7nsHPylMVpSDeXtVFZUK0htTMJik+Dj3ldz7K O9zuQ3ep2jZk8x/05kCWuqabfR5WhaEUhK+T/Q3M88g7LkiweuwDcqt6WWOBNgHHRY90 /SvtWqo1ZOpB97MmG8eh7oeDtsHsFsPzPjwaxxsZBlstfNra2OD8r6b7w8uGA3+UwT7y sqlL+xP5/rWwyNZnLlORWcUoPSoVQam3/9YQGzrrcLenpeiVT98Bsdy+sTtLnjonail4 nNrA== X-Gm-Message-State: ABuFfojhgTyPaxK4ynTO6wwChodoBp8h+S5r23xbUdwANnerwo3IwGGz pyWhRZOHP3CE1/WE6oQyLsY= X-Received: by 2002:a63:9712:: with SMTP id n18-v6mr20848352pge.182.1539701194878; Tue, 16 Oct 2018 07:46:34 -0700 (PDT) Received: from nishad ([106.51.27.228]) by smtp.gmail.com with ESMTPSA id c8-v6sm16944694pfi.142.2018.10.16.07.46.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 16 Oct 2018 07:46:34 -0700 (PDT) Date: Tue, 16 Oct 2018 20:16:27 +0530 From: Nishad Kamdar To: Lars-Peter Clausen Cc: Michael Hennerich , Jonathan Cameron , Hartmut Knaack , Peter Meerwald-Stadler , Greg Kroah-Hartman , linux-iio@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, outreachy-kernel@googlegroups.com Subject: [PATCH] staging: iio: ad7816: Switch to the gpio descriptor interface Message-ID: <20181016144623.GA9890@nishad> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use the gpiod interface for rdwr_pin, convert_pin and busy_pin instead of the deprecated old non-descriptor interface. Signed-off-by: Nishad Kamdar --- drivers/staging/iio/adc/ad7816.c | 72 +++++++++++++------------------- 1 file changed, 30 insertions(+), 42 deletions(-) diff --git a/drivers/staging/iio/adc/ad7816.c b/drivers/staging/iio/adc/ad7816.c index bf76a8620bdb..190b751af866 100644 --- a/drivers/staging/iio/adc/ad7816.c +++ b/drivers/staging/iio/adc/ad7816.c @@ -7,7 +7,7 @@ */ #include -#include +#include #include #include #include @@ -44,9 +44,9 @@ struct ad7816_chip_info { struct spi_device *spi_dev; - u16 rdwr_pin; - u16 convert_pin; - u16 busy_pin; + struct gpio_desc *rdwr_pin; + struct gpio_desc *convert_pin; + struct gpio_desc *busy_pin; u8 oti_data[AD7816_CS_MAX + 1]; u8 channel_id; /* 0 always be temperature */ u8 mode; @@ -61,28 +61,28 @@ static int ad7816_spi_read(struct ad7816_chip_info *chip, u16 *data) int ret = 0; __be16 buf; - gpio_set_value(chip->rdwr_pin, 1); - gpio_set_value(chip->rdwr_pin, 0); + gpiod_set_value(chip->rdwr_pin, 1); + gpiod_set_value(chip->rdwr_pin, 0); ret = spi_write(spi_dev, &chip->channel_id, sizeof(chip->channel_id)); if (ret < 0) { dev_err(&spi_dev->dev, "SPI channel setting error\n"); return ret; } - gpio_set_value(chip->rdwr_pin, 1); + gpiod_set_value(chip->rdwr_pin, 1); if (chip->mode == AD7816_PD) { /* operating mode 2 */ - gpio_set_value(chip->convert_pin, 1); - gpio_set_value(chip->convert_pin, 0); + gpiod_set_value(chip->convert_pin, 1); + gpiod_set_value(chip->convert_pin, 0); } else { /* operating mode 1 */ - gpio_set_value(chip->convert_pin, 0); - gpio_set_value(chip->convert_pin, 1); + gpiod_set_value(chip->convert_pin, 0); + gpiod_set_value(chip->convert_pin, 1); } - while (gpio_get_value(chip->busy_pin)) + while (gpiod_get_value(chip->busy_pin)) cpu_relax(); - gpio_set_value(chip->rdwr_pin, 0); - gpio_set_value(chip->rdwr_pin, 1); + gpiod_set_value(chip->rdwr_pin, 0); + gpiod_set_value(chip->rdwr_pin, 1); ret = spi_read(spi_dev, &buf, sizeof(*data)); if (ret < 0) { dev_err(&spi_dev->dev, "SPI data read error\n"); @@ -99,8 +99,8 @@ static int ad7816_spi_write(struct ad7816_chip_info *chip, u8 data) struct spi_device *spi_dev = chip->spi_dev; int ret = 0; - gpio_set_value(chip->rdwr_pin, 1); - gpio_set_value(chip->rdwr_pin, 0); + gpiod_set_value(chip->rdwr_pin, 1); + gpiod_set_value(chip->rdwr_pin, 0); ret = spi_write(spi_dev, &data, sizeof(data)); if (ret < 0) dev_err(&spi_dev->dev, "SPI oti data write error\n"); @@ -129,10 +129,10 @@ static ssize_t ad7816_store_mode(struct device *dev, struct ad7816_chip_info *chip = iio_priv(indio_dev); if (strcmp(buf, "full")) { - gpio_set_value(chip->rdwr_pin, 1); + gpiod_set_value(chip->rdwr_pin, 1); chip->mode = AD7816_FULL; } else { - gpio_set_value(chip->rdwr_pin, 0); + gpiod_set_value(chip->rdwr_pin, 0); chip->mode = AD7816_PD; } @@ -345,15 +345,9 @@ static int ad7816_probe(struct spi_device *spi_dev) { struct ad7816_chip_info *chip; struct iio_dev *indio_dev; - unsigned short *pins = dev_get_platdata(&spi_dev->dev); int ret = 0; int i; - if (!pins) { - dev_err(&spi_dev->dev, "No necessary GPIO platform data.\n"); - return -EINVAL; - } - indio_dev = devm_iio_device_alloc(&spi_dev->dev, sizeof(*chip)); if (!indio_dev) return -ENOMEM; @@ -364,34 +358,28 @@ static int ad7816_probe(struct spi_device *spi_dev) chip->spi_dev = spi_dev; for (i = 0; i <= AD7816_CS_MAX; i++) chip->oti_data[i] = 203; - chip->rdwr_pin = pins[0]; - chip->convert_pin = pins[1]; - chip->busy_pin = pins[2]; - ret = devm_gpio_request(&spi_dev->dev, chip->rdwr_pin, - spi_get_device_id(spi_dev)->name); - if (ret) { + chip->rdwr_pin = devm_gpiod_get(&spi_dev->dev, "rdwr", GPIOD_IN); + if (IS_ERR(chip->rdwr_pin)) { + ret = PTR_ERR(chip->rdwr_pin); dev_err(&spi_dev->dev, "Fail to request rdwr gpio PIN %d.\n", - chip->rdwr_pin); + ret); return ret; } - gpio_direction_input(chip->rdwr_pin); - ret = devm_gpio_request(&spi_dev->dev, chip->convert_pin, - spi_get_device_id(spi_dev)->name); - if (ret) { + chip->convert_pin = devm_gpiod_get(&spi_dev->dev, "convert", GPIOD_IN); + if (IS_ERR(chip->convert_pin)) { + ret = PTR_ERR(chip->convert_pin); dev_err(&spi_dev->dev, "Fail to request convert gpio PIN %d.\n", - chip->convert_pin); + ret); return ret; } - gpio_direction_input(chip->convert_pin); - ret = devm_gpio_request(&spi_dev->dev, chip->busy_pin, - spi_get_device_id(spi_dev)->name); - if (ret) { + chip->busy_pin = devm_gpiod_get(&spi_dev->dev, "busy", GPIOD_IN); + if (IS_ERR(chip->busy_pin)) { + ret = PTR_ERR(chip->busy_pin); dev_err(&spi_dev->dev, "Fail to request busy gpio PIN %d.\n", - chip->busy_pin); + ret); return ret; } - gpio_direction_input(chip->busy_pin); indio_dev->name = spi_get_device_id(spi_dev)->name; indio_dev->dev.parent = &spi_dev->dev; -- 2.17.1