Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1402335pxk; Thu, 10 Sep 2020 14:32:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxI/U7DXJIXum+pyRqdpoiM0EtuSgcaUZXM9XBmG823AFeIU/zWmkTPibfQvHarj1oMjnoo X-Received: by 2002:a17:906:4093:: with SMTP id u19mr11232443ejj.520.1599773567201; Thu, 10 Sep 2020 14:32:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599773567; cv=none; d=google.com; s=arc-20160816; b=lfL6xPNZGh/LO94+h9tc1hPwM7Jrm+6ZmbdTxCN6Jvf5H73b8DmjqzsiQm5YrD+I9V d1zJFBqkBjSit/xFfyyfL0xhXwplNvwo4xqC/BVR9kSBen7SQE+RJzIsJfjxtkC5Zkjb vV1MSnJJ2SozgDey7veUkqutB59Q5ElB6DnKxfXSnEdCCUoULQGR7zhumqNl/iNNMF0u 6qokz/ZfCleSuwzzC28AQO/VTtM/AAKy48i1v0VDVwIO97Cy3Y1ataT/iMVY7J5QGy0m JoEcha72VQJu0+0jJwP1u2NXN37aN3aRF5Fi7uiyFoZ0Av65DHvhNXkN3BybCwGhnKXj z/Qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=s8hpTJ5jpmu25r8Rx3Kgs3iF4PPo1Ln9S4YDeFEjnfs=; b=qffRT+fw61LYHcQp3m40AA7gSDogBCfneF5SyiwkiITcDzGQvMWmhcVqEYDcBp5BvN qjZ6HHm7cyR5VVv51GehvE6CcWmIFXv6cAeyNKzNfHL0KjNCPBi5VZDejPvLfeoMKNI1 d23CbIUOBlDvMtHyusSmvaRUZnzC8D+Z2RVFi0JJkrjLO4eN7PkaKtXxzvR12wOpp72f H9ONkL48mtemDeq+ZIROL8V93tjdugvaJLVuOH2zo3M82uIq1SscXCU0/Pq5t4zk7A8E 7+epKloS8K4seLajnrCJR3oFqoJvmt4B49IUXNCS7K4LQ6B1fLiGSBgZtVQvZiqpFa+T Ui1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=CFF9tYL5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id j14si4530042edp.315.2020.09.10.14.32.24; Thu, 10 Sep 2020 14:32:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=CFF9tYL5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1728284AbgIJVbw (ORCPT + 99 others); Thu, 10 Sep 2020 17:31:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730637AbgIJNvp (ORCPT ); Thu, 10 Sep 2020 09:51:45 -0400 Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC4FDC061796; Thu, 10 Sep 2020 06:51:44 -0700 (PDT) Received: by mail-pl1-x641.google.com with SMTP id j7so949550plk.11; Thu, 10 Sep 2020 06:51:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=s8hpTJ5jpmu25r8Rx3Kgs3iF4PPo1Ln9S4YDeFEjnfs=; b=CFF9tYL5KeE0BlS/F84CUI6dKWsCH+MrmT4ZuZWKR13iqL116kIqKL1o6m842w8bVD uL3e4eicEGPy/IHrqguM7QLSYYW7C670Ce4wGcGxAFE/UhiV7fP/g0A+WRGqYVpvb6km 6PsnW0mkpB6++hV7TRwnFNtuEP8NLhrl7AJqWNtqhbahlOluKnClxol2j9+Yz3OcI6SR b3Qt5+w7r6toPI1LyCNeQ69qBZSbkPYmdCiqKsItJ52yw5JZX1zA3PWDzj3wtN0REcCU mfxd6ssCbAHJrJbOfDmX4Qr8f232lXABltZ2Zf1ltrrCO3/h4Y5RlHmUtdyPO4RHu5fI JU9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=s8hpTJ5jpmu25r8Rx3Kgs3iF4PPo1Ln9S4YDeFEjnfs=; b=agJNeE9Qq5U8Ja391WdDkYiboOOZLC+53W9iFwBOqASmyHlWqaI1mZOPX4v+qBrEGX iZRnJBKENF200tx25dGKFI0cD4TAkDz/tNi6Kci+AVGkszGwSLwXk8KDz/KVeNB4hS8k DAdEfWiIMcHFoGowBX7IBAh1JeAh9rUfI4nBHVyOM0v0m/GaWTGoZD/jbEC5JX8ag7u9 gATMYXNMZ696PUsMp4+lVtZSyUNoWWyRiBH4dWlhpkNQEIx08s6irSfiyoQtACE01IxO vLwCLoFf4N1zytTURq7qGUVQVpUJbZCMpTWwdLEXwQ4vE0vkaZmbJl101fMFTCBp9aio 14cQ== X-Gm-Message-State: AOAM532opxQFTHNok+Nkux0pEdl5u3l2nzENiZVKJgufT6I1HyhIJnGB C4LudZM4tSbufB6EDvsr4KQ/JdDdkpKqeGpvbJJcrPkX9yrWM+F3 X-Received: by 2002:a17:90a:fd98:: with SMTP id cx24mr23153pjb.181.1599745904138; Thu, 10 Sep 2020 06:51:44 -0700 (PDT) MIME-Version: 1.0 References: <20200910122711.16670-1-nish.malpani25@gmail.com> In-Reply-To: <20200910122711.16670-1-nish.malpani25@gmail.com> From: Andy Shevchenko Date: Thu, 10 Sep 2020 16:51:26 +0300 Message-ID: Subject: Re: [PATCH] iio: gyro: adxrs290: use hook for devm resource unwinding To: Nishant Malpani Cc: Jonathan Cameron , Linux Kernel Mailing List , linux-iio Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 10, 2020 at 3:27 PM Nishant Malpani wrote: > > Make use of devm_add_action_or_reset() hook to switch device into STANDBY > mode during standard resource unwinding. The patch includes a helper > function, in the form of adxrs290_set_mode(), to realise driving the > device into STANDBY mode. Reviewed-by: Andy Shevchenko > Signed-off-by: Nishant Malpani > --- > drivers/iio/gyro/adxrs290.c | 61 +++++++++++++++++++++++++++++++++++-- > 1 file changed, 58 insertions(+), 3 deletions(-) > > diff --git a/drivers/iio/gyro/adxrs290.c b/drivers/iio/gyro/adxrs290.c > index ff989536d2fb..2864eb443957 100644 > --- a/drivers/iio/gyro/adxrs290.c > +++ b/drivers/iio/gyro/adxrs290.c > @@ -192,15 +192,70 @@ static int adxrs290_set_filter_freq(struct iio_dev *indio_dev, > return adxrs290_spi_write_reg(st->spi, ADXRS290_REG_FILTER, val); > } > > +static int adxrs290_set_mode(struct iio_dev *indio_dev, enum adxrs290_mode mode) > +{ > + struct adxrs290_state *st = iio_priv(indio_dev); > + int val, ret; > + > + if (st->mode == mode) > + return 0; > + > + mutex_lock(&st->lock); > + > + ret = spi_w8r8(st->spi, ADXRS290_READ_REG(ADXRS290_REG_POWER_CTL)); > + if (ret < 0) > + goto out_unlock; > + > + val = ret; > + > + switch (mode) { > + case ADXRS290_MODE_STANDBY: > + val &= ~ADXRS290_MEASUREMENT; > + break; > + case ADXRS290_MODE_MEASUREMENT: > + val |= ADXRS290_MEASUREMENT; > + break; > + default: > + ret = -EINVAL; > + goto out_unlock; > + } > + > + ret = adxrs290_spi_write_reg(st->spi, ADXRS290_REG_POWER_CTL, val); > + if (ret < 0) { > + dev_err(&st->spi->dev, "unable to set mode: %d\n", ret); > + goto out_unlock; > + } > + > + /* update cached mode */ > + st->mode = mode; > + > +out_unlock: > + mutex_unlock(&st->lock); > + return ret; > +} > + > +static void adxrs290_chip_off_action(void *data) > +{ > + struct iio_dev *indio_dev = data; > + > + adxrs290_set_mode(indio_dev, ADXRS290_MODE_STANDBY); > +} > + > static int adxrs290_initial_setup(struct iio_dev *indio_dev) > { > struct adxrs290_state *st = iio_priv(indio_dev); > + struct spi_device *spi = st->spi; > + int ret; > + > + ret = adxrs290_spi_write_reg(spi, ADXRS290_REG_POWER_CTL, > + ADXRS290_MEASUREMENT | ADXRS290_TSM); > + if (ret < 0) > + return ret; > > st->mode = ADXRS290_MODE_MEASUREMENT; > > - return adxrs290_spi_write_reg(st->spi, > - ADXRS290_REG_POWER_CTL, > - ADXRS290_MEASUREMENT | ADXRS290_TSM); > + return devm_add_action_or_reset(&spi->dev, adxrs290_chip_off_action, > + indio_dev); > } > > static int adxrs290_read_raw(struct iio_dev *indio_dev, > -- > 2.20.1 > -- With Best Regards, Andy Shevchenko