Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp547384imd; Sat, 3 Nov 2018 05:45:52 -0700 (PDT) X-Google-Smtp-Source: AJdET5eCZrmeicemEikbKvQuejnT4dnBk3+jBnbpcm0didxS6QNm2lbZBjM5LejhaoRVcfcN2j0r X-Received: by 2002:a63:6205:: with SMTP id w5mr13997176pgb.53.1541249152718; Sat, 03 Nov 2018 05:45:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541249152; cv=none; d=google.com; s=arc-20160816; b=DE920iBpYPxDYs5znmHc+zlTXITTREkmxBvWRO0HezHvRCq37nIQG1LjddtCQKf7Z7 gX32ax9ltxY/U8Kp4xt0/3TPP5PhalTR7terIMSsBpPL4D3AmM9WqkaBrcnzXBBe4Ncp EgP0qUmU7ojWn/sqbu9uxBBZVxg3NP8g6XM2MQ4Kp1/yFn4fM2a5k0OIRCBXuOCEi8dg NrEYmX+aQbPOP7kfnNDPNhc02UiQMBKt9PgsSbp+sORdV/EGIXd6rS2FBKjnA4mIXIkY 280oCGI5sR5qV5gmAdBj9eH/gZvCLJfdfA2+a67McnebVNppJdeNrLowT7C/NfP5VY4j jpQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=ayQxQQbXWWg5mSi5/Bj/wnVob4UsSafeKk0yxh3dYok=; b=omLMUTBKQGDh5NA78bpT+ceSOhdsI41WwByFINYCvnBelFOHqo/Y4ErZKzg90kCrAR HJS4wKLTiF6pvfUXI9tcQgO0HtoOGBKAh8xoDLR3FjipaffRNC/C9GajhaQ0PILywWJw NXH3mbKURILfIWsjHLckzdPPV73L0rLPQJ7plscfJxedVF19Ca2eG+Jroi4alrYdMgdd PlqOn/LgEUK+2a0Tu5FJZYUB3g/6/QP8XRXy7lolrLnVj55WaHsoa+rLtYhg3criIduE AWOICP+x0mvOj0TSHXvVQvgkuWTKWyuN5BK0dPxF6wS448Q4YPmvD331D10CzMaBNRcH VUcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Nd9QZXho; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z16-v6si35552891pgu.525.2018.11.03.05.45.37; Sat, 03 Nov 2018 05:45:52 -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=@kernel.org header.s=default header.b=Nd9QZXho; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728451AbeKCV42 (ORCPT + 99 others); Sat, 3 Nov 2018 17:56:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:39958 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727658AbeKCV42 (ORCPT ); Sat, 3 Nov 2018 17:56:28 -0400 Received: from archlinux (cpc91196-cmbg18-2-0-cust659.5-4.cable.virginm.net [81.96.234.148]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3F6A12082D; Sat, 3 Nov 2018 12:45:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541249114; bh=/8AtL2qUxiFz+eal/GbiU3NOqgMyPioX2fYCspKZ02A=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Nd9QZXhof2HbXYO+ilTxDz2oqDfuL4QfbjKg1Us5nc87y5quO2nF2lO1V+ql7EadD oRna5M1LnbQo7wTmwGngP56wVdtdqq6tsMcXLZ1e/4vz1SHddyZ1YsvJA3t1KQz1U8 f9clgzxY1N3zxOy6ttF7FgoR08z/DsdVotZ9FZO4= Date: Sat, 3 Nov 2018 12:45:09 +0000 From: Jonathan Cameron To: Nishad Kamdar Cc: Slawomir Stepien , Lars-Peter Clausen , Michael Hennerich , Hartmut Knaack , Peter Meerwald-Stadler , Greg Kroah-Hartman , linux-iio@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v7 1/3] staging: iio: ad2s1210: Switch to the gpio descriptor interface Message-ID: <20181103124509.102204a5@archlinux> In-Reply-To: <1626698317a8f0b1caf5596374088f6d5b6141c9.1541000375.git.nishadkamdar@gmail.com> References: <1626698317a8f0b1caf5596374088f6d5b6141c9.1541000375.git.nishadkamdar@gmail.com> X-Mailer: Claws Mail 3.17.1 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 31 Oct 2018 21:28:52 +0530 Nishad Kamdar wrote: > Use the gpiod interface instead of the deprecated old non-descriptor > interface. > > Signed-off-by: Nishad Kamdar It would have been less 'noisy' to do these in the reverse order (drop the flag and support first, then do the gpiod conversion), but I suppose it doesn't really matter. Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to play with it. Thanks, Jonathan > --- > drivers/staging/iio/resolver/ad2s1210.c | 106 ++++++++++++++---------- > drivers/staging/iio/resolver/ad2s1210.h | 3 - > 2 files changed, 62 insertions(+), 47 deletions(-) > > diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c > index ac13b99bd9cb..82ac9847f6f4 100644 > --- a/drivers/staging/iio/resolver/ad2s1210.c > +++ b/drivers/staging/iio/resolver/ad2s1210.c > @@ -15,7 +15,7 @@ > #include > #include > #include > -#include > +#include > #include > > #include > @@ -67,12 +67,42 @@ enum ad2s1210_mode { > MOD_RESERVED, > }; > > +enum ad2s1210_gpios { > + AD2S1210_SAMPLE, > + AD2S1210_A0, > + AD2S1210_A1, > + AD2S1210_RES0, > + AD2S1210_RES1, > +}; > + > +struct ad2s1210_gpio { > + const char *name; > + unsigned long flags; > +}; > + > +static const struct ad2s1210_gpio gpios_in[] = { > + [AD2S1210_SAMPLE] = { .name = "adi,sample", .flags = GPIOD_IN }, > + [AD2S1210_A0] = { .name = "adi,a0", .flags = GPIOD_IN }, > + [AD2S1210_A1] = { .name = "adi,a1", .flags = GPIOD_IN }, > + [AD2S1210_RES0] = { .name = "adi,res0", .flags = GPIOD_IN }, > + [AD2S1210_RES1] = { .name = "adi,res1", .flags = GPIOD_IN }, > +}; > + > +static const struct ad2s1210_gpio gpios_out[] = { > + [AD2S1210_SAMPLE] = { .name = "adi,sample", .flags = GPIOD_OUT_LOW }, > + [AD2S1210_A0] = { .name = "adi,a0", .flags = GPIOD_OUT_LOW }, > + [AD2S1210_A1] = { .name = "adi,a1", .flags = GPIOD_OUT_LOW }, > + [AD2S1210_RES0] = { .name = "adi,res0", .flags = GPIOD_OUT_LOW }, > + [AD2S1210_RES1] = { .name = "adi,res1", .flags = GPIOD_OUT_LOW }, > +}; > + > static const unsigned int ad2s1210_resolution_value[] = { 10, 12, 14, 16 }; > > struct ad2s1210_state { > const struct ad2s1210_platform_data *pdata; > struct mutex lock; > struct spi_device *sdev; > + struct gpio_desc *gpios[5]; > unsigned int fclkin; > unsigned int fexcit; > bool hysteresis; > @@ -91,8 +121,8 @@ static const int ad2s1210_mode_vals[4][2] = { > static inline void ad2s1210_set_mode(enum ad2s1210_mode mode, > struct ad2s1210_state *st) > { > - gpio_set_value(st->pdata->a[0], ad2s1210_mode_vals[mode][0]); > - gpio_set_value(st->pdata->a[1], ad2s1210_mode_vals[mode][1]); > + gpiod_set_value(st->gpios[AD2S1210_A0], ad2s1210_mode_vals[mode][0]); > + gpiod_set_value(st->gpios[AD2S1210_A1], ad2s1210_mode_vals[mode][1]); > st->mode = mode; > } > > @@ -152,8 +182,8 @@ int ad2s1210_update_frequency_control_word(struct ad2s1210_state *st) > > static unsigned char ad2s1210_read_resolution_pin(struct ad2s1210_state *st) > { > - int resolution = (gpio_get_value(st->pdata->res[0]) << 1) | > - gpio_get_value(st->pdata->res[1]); > + int resolution = (gpiod_get_value(st->gpios[AD2S1210_RES0]) << 1) | > + gpiod_get_value(st->gpios[AD2S1210_RES1]); > > return ad2s1210_resolution_value[resolution]; > } > @@ -164,10 +194,10 @@ static const int ad2s1210_res_pins[4][2] = { > > static inline void ad2s1210_set_resolution_pin(struct ad2s1210_state *st) > { > - gpio_set_value(st->pdata->res[0], > - ad2s1210_res_pins[(st->resolution - 10) / 2][0]); > - gpio_set_value(st->pdata->res[1], > - ad2s1210_res_pins[(st->resolution - 10) / 2][1]); > + gpiod_set_value(st->gpios[AD2S1210_RES0], > + ad2s1210_res_pins[(st->resolution - 10) / 2][0]); > + gpiod_set_value(st->gpios[AD2S1210_RES1], > + ad2s1210_res_pins[(st->resolution - 10) / 2][1]); > } > > static inline int ad2s1210_soft_reset(struct ad2s1210_state *st) > @@ -401,15 +431,15 @@ static ssize_t ad2s1210_clear_fault(struct device *dev, > int ret; > > mutex_lock(&st->lock); > - gpio_set_value(st->pdata->sample, 0); > + gpiod_set_value(st->gpios[AD2S1210_SAMPLE], 0); > /* delay (2 * tck + 20) nano seconds */ > udelay(1); > - gpio_set_value(st->pdata->sample, 1); > + gpiod_set_value(st->gpios[AD2S1210_SAMPLE], 1); > ret = ad2s1210_config_read(st, AD2S1210_REG_FAULT); > if (ret < 0) > goto error_ret; > - gpio_set_value(st->pdata->sample, 0); > - gpio_set_value(st->pdata->sample, 1); > + gpiod_set_value(st->gpios[AD2S1210_SAMPLE], 0); > + gpiod_set_value(st->gpios[AD2S1210_SAMPLE], 1); > error_ret: > mutex_unlock(&st->lock); > > @@ -466,7 +496,7 @@ static int ad2s1210_read_raw(struct iio_dev *indio_dev, > s16 vel; > > mutex_lock(&st->lock); > - gpio_set_value(st->pdata->sample, 0); > + gpiod_set_value(st->gpios[AD2S1210_SAMPLE], 0); > /* delay (6 * tck + 20) nano seconds */ > udelay(1); > > @@ -512,7 +542,7 @@ static int ad2s1210_read_raw(struct iio_dev *indio_dev, > } > > error_ret: > - gpio_set_value(st->pdata->sample, 1); > + gpiod_set_value(st->gpios[AD2S1210_SAMPLE], 1); > /* delay (2 * tck + 20) nano seconds */ > udelay(1); > mutex_unlock(&st->lock); > @@ -630,30 +660,23 @@ static const struct iio_info ad2s1210_info = { > > static int ad2s1210_setup_gpios(struct ad2s1210_state *st) > { > - unsigned long flags = st->pdata->gpioin ? GPIOF_DIR_IN : GPIOF_DIR_OUT; > - struct gpio ad2s1210_gpios[] = { > - { st->pdata->sample, GPIOF_DIR_IN, "sample" }, > - { st->pdata->a[0], flags, "a0" }, > - { st->pdata->a[1], flags, "a1" }, > - { st->pdata->res[0], flags, "res0" }, > - { st->pdata->res[0], flags, "res1" }, > - }; > - > - return gpio_request_array(ad2s1210_gpios, ARRAY_SIZE(ad2s1210_gpios)); > -} > - > -static void ad2s1210_free_gpios(struct ad2s1210_state *st) > -{ > - unsigned long flags = st->pdata->gpioin ? GPIOF_DIR_IN : GPIOF_DIR_OUT; > - struct gpio ad2s1210_gpios[] = { > - { st->pdata->sample, GPIOF_DIR_IN, "sample" }, > - { st->pdata->a[0], flags, "a0" }, > - { st->pdata->a[1], flags, "a1" }, > - { st->pdata->res[0], flags, "res0" }, > - { st->pdata->res[0], flags, "res1" }, > - }; > + struct ad2s1210_gpio *pin = st->pdata->gpioin ? &gpios_in[0] : &gpios_out[0]; > + struct spi_device *spi = st->sdev; > + int i, ret; > + > + for (i = 0; i < ARRAY_SIZE(gpios_in); i++) { > + st->gpios[i] = devm_gpiod_get(&spi->dev, pin[i].name, > + pin[i].flags); > + if (IS_ERR(st->gpios[i])) { > + ret = PTR_ERR(st->gpios[i]); > + dev_err(&spi->dev, > + "ad2s1210: failed to request %s GPIO: %d\n", > + pin[i].name, ret); > + return ret; > + } > + } > > - gpio_free_array(ad2s1210_gpios, ARRAY_SIZE(ad2s1210_gpios)); > + return 0; > } > > static int ad2s1210_probe(struct spi_device *spi) > @@ -692,7 +715,7 @@ static int ad2s1210_probe(struct spi_device *spi) > > ret = iio_device_register(indio_dev); > if (ret) > - goto error_free_gpios; > + return ret; > > st->fclkin = spi->max_speed_hz; > spi->mode = SPI_MODE_3; > @@ -700,10 +723,6 @@ static int ad2s1210_probe(struct spi_device *spi) > ad2s1210_initial(st); > > return 0; > - > -error_free_gpios: > - ad2s1210_free_gpios(st); > - return ret; > } > > static int ad2s1210_remove(struct spi_device *spi) > @@ -711,7 +730,6 @@ static int ad2s1210_remove(struct spi_device *spi) > struct iio_dev *indio_dev = spi_get_drvdata(spi); > > iio_device_unregister(indio_dev); > - ad2s1210_free_gpios(iio_priv(indio_dev)); > > return 0; > } > diff --git a/drivers/staging/iio/resolver/ad2s1210.h b/drivers/staging/iio/resolver/ad2s1210.h > index e9b2147701fc..63d479b20a6c 100644 > --- a/drivers/staging/iio/resolver/ad2s1210.h > +++ b/drivers/staging/iio/resolver/ad2s1210.h > @@ -12,9 +12,6 @@ > #define _AD2S1210_H > > struct ad2s1210_platform_data { > - unsigned int sample; > - unsigned int a[2]; > - unsigned int res[2]; > bool gpioin; > }; > #endif /* _AD2S1210_H */