Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp6321575imd; Wed, 31 Oct 2018 09:57:59 -0700 (PDT) X-Google-Smtp-Source: AJdET5edp6UXdLDgZ5vldSOogxechUor826GU1/i0ZIrqIb0ksAJClW71Whz+yNzu8gIFG95M/qB X-Received: by 2002:a62:475c:: with SMTP id u89-v6mr4137038pfa.225.1541005079399; Wed, 31 Oct 2018 09:57:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541005079; cv=none; d=google.com; s=arc-20160816; b=Oedrk+rN8kuh1OU4i86b7W7LO+lJHPwu+DMU9Btngzxh6+6Ss9MSGVPPZWFPzaS+Yn 9p7AWUZXITyZ1C/CT+wqAySvxN7SHWy2VlpNMcHdmVBpaCLQXgq6ypXi0Ob8e2tqoIm/ 4m2hEd8ID5dOEx77Ll0yRKgG6FKYL/rvuBcT+2op6Zi/LJGSxK9J6qdytyKh8S984zfM GBYHosW9VattaGcXn7wtgoolGDKZFMgYYtgjYgx0/B3CVxDoZ14TJ6yA3xhbpSVxl+th S9GTd4sCdI6wzc834YPuKNtlkYws7DoDcVaUeVEbl2e1iNx94cY9KxmFTd+hZOAnaDQZ Fq4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=2w9Mcpjm7MYB5Rop0fmMMmUwu5zTLpOe3lPx2S6vcfU=; b=JlzGdsoktogu7jI71uEpNuIQ2crvYn2Z9mJoJJmeb508ab/S7gveClwGRxYakjFiWK dfsLA8/p6unDsSNIMo+YlSSQTGLgGr9E9eUgSUlYiMnxNk6vAfu/+jVizfNWPTGbHQEU IIhrNXzG2D7Yxcdt1xXRbJ7wDwJDJzDTWAqSd9LYDseBCBrBROjp4hLAl6xIK8TR/IHx HQuz2wOS9n5fJ8V2K2Yx06IwYE1/X+90SWg56Ks7VQ+1TWccYc2g/mnjZQSpzqVwVRQZ cVhNXQUMjK76alY4n4DVA2cShbNBX4n68SXngWiBI5olZ7UvqMQG8aF65yjDRRa51HUL BkZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=KSTrDzaa; 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 x21-v6si26521851pll.221.2018.10.31.09.57.44; Wed, 31 Oct 2018 09:57:59 -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=KSTrDzaa; 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 S1729748AbeKAA5g (ORCPT + 99 others); Wed, 31 Oct 2018 20:57:36 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:38642 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729613AbeKAA5g (ORCPT ); Wed, 31 Oct 2018 20:57:36 -0400 Received: by mail-pf1-f195.google.com with SMTP id b11-v6so7828985pfi.5; Wed, 31 Oct 2018 08:59:00 -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=2w9Mcpjm7MYB5Rop0fmMMmUwu5zTLpOe3lPx2S6vcfU=; b=KSTrDzaaRgCJv3I5gePJ41GHeWAsPzM6ALuCEm0TNTbbhIA+F3j6uTUVyJn8H3y2gU IuUYOJq2n5BmHbO/pPuwqxlXGUhGnT/HpYwmWIjo5r4V7tVvJvIXFl2wOLFkuS2TYvmI mFKi98u6Tl2k/zKbWlm8MJwOKriVBTXY2TY0SMEuP2sh2bT4sD40mkKUzjEx94cxOiME ieOtINq0u4QJETc47eWT3Fycvd8UTXfhTEYDPAB+68DLWO1bTGH5HaQ1RdTa8Pup9DRN 7PsxRyEQqGfFawsqLAr+wfYn2dp+KYZxhIDksMaHXAsu+aYSa6bV5XJ1VI3WxW6rH0a8 t1rQ== 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=2w9Mcpjm7MYB5Rop0fmMMmUwu5zTLpOe3lPx2S6vcfU=; b=uQmaR+EWOQTMZGN0XmQYGbabMtQCiMK1+Vv3waLTyHSxX+T6aUNzTqPtsFzCxIsg+d VIgRcMr5uJANyh0Xql9WD6+nbbvV/FgUyuXY5wCUO/zSL/sJSqrQYQxtQrXT7ij3CJUm Q7NfuzrEowSOsX+4+vgR1wCtwNZdU992Psx0P15MDP1KVWCvmg+qGNtMqELl3+vKGtvq 28UO8Q5xqEzKdpqTBOJPVkc0uTXf6h9KvvDLVKIQuiT4eZ1u0rh0wfVVedylCX0E27RA Kp/f5KoE76ML9nvfaVsShYU0gqgz5LmcJb4m982gQ902U8ouhOp1jt7AxqaMsl2CQNv2 dy+A== X-Gm-Message-State: AGRZ1gJSWj3mksfcqDNOZgXP1fmgahpQmfKyXxRwiP8S5qEMVPwWQWxZ GqKiryBqPbRXJb2KzoQLDIw= X-Received: by 2002:a63:1848:: with SMTP id 8mr3645014pgy.81.1541001539893; Wed, 31 Oct 2018 08:58:59 -0700 (PDT) Received: from nishad ([106.51.27.228]) by smtp.gmail.com with ESMTPSA id k72-v6sm60536001pfj.63.2018.10.31.08.58.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 Oct 2018 08:58:59 -0700 (PDT) Date: Wed, 31 Oct 2018 21:28:52 +0530 From: Nishad Kamdar To: Jonathan Cameron 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: [PATCH v7 1/3] staging: iio: ad2s1210: Switch to the gpio descriptor interface Message-ID: <1626698317a8f0b1caf5596374088f6d5b6141c9.1541000375.git.nishadkamdar@gmail.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 instead of the deprecated old non-descriptor interface. Signed-off-by: Nishad Kamdar --- 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 */ -- 2.17.1