Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1440605pxk; Sun, 13 Sep 2020 02:50:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJykIgNXJpNn3gwEqh8iNAiTSfIjxqQvezIA6YrksPNW6nFQCBfe8g6FaKmgzILuN/XLE6CX X-Received: by 2002:a17:906:7e42:: with SMTP id z2mr9436581ejr.206.1599990607253; Sun, 13 Sep 2020 02:50:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599990607; cv=none; d=google.com; s=arc-20160816; b=z8ItaQzTKzGgqZHeXvUk6APx/HfnMg2rtlZtfr+SR+0bss64cqfTfzLbvayt0vcHn/ 2nVO5o3RQ4JFrMJwhFT0g9e61jtE6DuVYq/ZNJ1vldWb0oey4191Z/uC4sfSRKzO3zP+ sirGKsINSI38m9dc26H48Ew0N9gw0JqQFYQBNomY0T7ZPQNbSYlX0S2jrwtgmdWz92TV hna9FhawCOXBVTJtm5NygOz/QzZby0k9YCv7/3zrk85iJZvQV8Xo2kkzWh9lo1ZaGkSY zbyjtpVzl3LFZA7kU/ARWcwl7wrd7FYfRG7gIA4NRRPggNCCyJJUkZd+g/2HXOAz4ERa MFuA== 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=osV6HIDXjI0WBCYRzGlq/n5kgVbrODsczHz9uj1eIYs=; b=R2LIfLkTPZKS2YMjyeKBPpcVAkC+1xrwxsHAItp3ZdzhXcidaqJYGOvVbmb5K1rtoP G0Ovgi/F18sGTzyJzIVuh/NRz8YD7bY0Fz4GKIkAL+J8p3ORGzCOn5cgrhRMRJ7vaJIq Dbbii2XlwNgaJA6ZnZAr7d2ewEKr1ZCyMA0J77BfHTgdYROynVzVNm9xRtYbW0K4HoUs cc4ymA/tRMQgntWahOeiZ3QRbJ6/kSWPvbIzCdyICpJEpibngqBOrVEhmx1yoGVSB0KQ J4KBfzRQBVy7lvviktKfdbyErUPIeO2Bn2geyNJMU7biB4Ivqc5lNHolRUzkEzuRz3P6 T/AQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hbXYJuHP; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m3si4964416edr.29.2020.09.13.02.49.44; Sun, 13 Sep 2020 02:50:07 -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=@kernel.org header.s=default header.b=hbXYJuHP; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725946AbgIMJqe (ORCPT + 99 others); Sun, 13 Sep 2020 05:46:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:46604 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725916AbgIMJqe (ORCPT ); Sun, 13 Sep 2020 05:46:34 -0400 Received: from archlinux (cpc149474-cmbg20-2-0-cust94.5-4.cable.virginm.net [82.4.196.95]) (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 96871207EA; Sun, 13 Sep 2020 09:46:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599990393; bh=nS7tdwelFh1tMDsGOhcEjwoqLslSJaYJdCD723Z0GVA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=hbXYJuHPbYKFDX4NZRTPDoxACdWSUEtWP/vt3NwBum9tw+bafmeSqofldmcelpLHW Z4LqTJdXCsOkxhNZeI1G8h3yu2dwxq/RCLNapzCQbPjBE3uamFKv8swpuTI2/2oKej gBq0Egid5h4tglLY8BLD4ZJG0X3ZrPZjeiv9VVe0= Date: Sun, 13 Sep 2020 10:46:29 +0100 From: Jonathan Cameron To: Andy Shevchenko Cc: Nishant Malpani , Linux Kernel Mailing List , linux-iio Subject: Re: [PATCH] iio: gyro: adxrs290: use hook for devm resource unwinding Message-ID: <20200913104629.1b5db509@archlinux> In-Reply-To: References: <20200910122711.16670-1-nish.malpani25@gmail.com> X-Mailer: Claws Mail 3.17.6 (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 Thu, 10 Sep 2020 16:51:26 +0300 Andy Shevchenko wrote: > 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 Great thanks. Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to poke at it. Thanks, Jonathan > > > 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 > > > >