Received: by 10.192.165.156 with SMTP id m28csp1605579imm; Wed, 18 Apr 2018 12:27:17 -0700 (PDT) X-Google-Smtp-Source: AIpwx48hEtm6ZC/vOmo1MGlvge8XZGQfUeQj2qF7CDt7qHj9Fv1ONltYsFIO6k2L0vaQp4SWyvGy X-Received: by 10.98.71.141 with SMTP id p13mr1081973pfi.164.1524079636983; Wed, 18 Apr 2018 12:27:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524079636; cv=none; d=google.com; s=arc-20160816; b=zgb3O+Paf1Ol5UDUjPZFdhEnDrSxk9ALCgkgIqMafV+yAFl8P1GNYNhXcAp0goPS1b WniLLCm5DFXng2RiNTv4Gtc2f1+IbO/4tOQNxGiLH8PXbSgNx5FglUnSDHUbqsnBbWNX YiTth1acrhz5NTpTf2d063RMaXGGy0QAh5Bt208DUk44fcc5A6VbDc6qsI2wTqFV6W6d /4BzHmI7wNlu6s2oj4MOQbPfKkoc0hm23D8Cj3UwAFobK4WkS8JZIQDtfMftaP/iNX1t c8GGFuFx8WkZFOzHXZC82j2TWQPrUaSa3P8fVpaal/6K2PAb9IkU73NLUCTGN87E3zsH hqyw== 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:cc:to:subject :message-id:date:from:references:in-reply-to:mime-version :dkim-signature:arc-authentication-results; bh=iGMYr65QkVTEegNDcMCDSJsNo9oxl3Tyrvuty4PzWIM=; b=RcNYkEBFeDE/gY9kFcNy/Q3A/Xe2mb/bmC0GVjpjwx2B6AlNC4ht6ME8kTWqiVSXmc Bws+3bx7KQW0bdEqU3KfsjC6tltDR0b6XUhYGFNCwbCtlJdcT8Du4oHBYJ7dYpHBHB0D yUPFupBPe4xOssK2lTccZxZ0Nxmd7DM0iH3/ALlIQDGh1fgY9lerV6zVOP1DztNMX+Ix IH6yyA0qvKk2V2pZ7hNKX+Mfid5JoPCrSbSNVgrjuFtHpJOdhuK0UXEKnSGtFSF4z5c4 evddBBCIupKsWI2YAACgOkMzt45RoHlNisqWFCH0kOAYimuJ6ZgcE+6x+ubkng76rLfW ylfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@vanguardiasur-com-ar.20150623.gappssmtp.com header.s=20150623 header.b=qb4GVd8l; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e4si1564330pga.1.2018.04.18.12.27.00; Wed, 18 Apr 2018 12:27:16 -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=@vanguardiasur-com-ar.20150623.gappssmtp.com header.s=20150623 header.b=qb4GVd8l; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752247AbeDRTZk (ORCPT + 99 others); Wed, 18 Apr 2018 15:25:40 -0400 Received: from mail-io0-f196.google.com ([209.85.223.196]:39398 "EHLO mail-io0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751299AbeDRTZi (ORCPT ); Wed, 18 Apr 2018 15:25:38 -0400 Received: by mail-io0-f196.google.com with SMTP id v13-v6so3783871iob.6 for ; Wed, 18 Apr 2018 12:25:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vanguardiasur-com-ar.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=iGMYr65QkVTEegNDcMCDSJsNo9oxl3Tyrvuty4PzWIM=; b=qb4GVd8loa2T92Fit1MQjytTHe2IHWY7YH7Q+4EF5Y8mtSYafEt2lOAXR0fRhY+zOg TUUpgU7cDkX9SjjrdlWE/+bWB/1C0XWzOmmPxFLHIOkgYUIVvPbR2GWxy/B+G67dN9pn JP7h5iy+NeChHaqtpfF+DXlMhy2HKuzerMqG2DBpGbUeS8LrlsRYdvjHeVOyAuDCXiXt SoakiXCyk63fUw7YNBA0pbHjWkSqhQ2etwSoz0TtXteoQIoGlS+Zf6ZvhhwVcALCoOwa w0J4HjyncrJEIo0c5zMbp8HURfj1DPTrC0ff0KQBruk1L7Xyi4mEB1LaslSSYoE2xCai yWIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=iGMYr65QkVTEegNDcMCDSJsNo9oxl3Tyrvuty4PzWIM=; b=RLfs5qQgqQWzddHa4FDO77fzb5vasev7biFlfJL8Sm9316ILyJvyY4ihqbHpkQwUAx La4kJ9n85ZQLqWl9Lkcs8M6c67ZyQbiQxXbNxFKFSpqlehBoa0WTFn6baIQMe6YguH8Q asBaVw+G9S6mYRhLDsPJrQL3YlLscndr7CZYi56vmmxepddFPfGXEQjR/V0VLk79m9oX tVeIgirApBK4D4qU98+DwatvGvQ1Ls5a9xXdoBcASiecutpnfs4n54pWg/S2JnXaBeXM o74YoCJYAhxTJ0baGD/ghClGWwWGGh9j1nkMK5ru8xmMfrqC+GDvA+9BdluRzf4A4lFR mdEw== X-Gm-Message-State: ALQs6tDzt002t5FuliBg1yrYKGvuM5FiDPJyFfUm4sCFSW85tewgSbz+ hosQFkLe3T9yNOoJFqrEslnv2AtNcbi3NelpY2Y9Uw== X-Received: by 2002:a6b:450e:: with SMTP id s14-v6mr3317821ioa.278.1524079538032; Wed, 18 Apr 2018 12:25:38 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.63.196 with HTTP; Wed, 18 Apr 2018 12:25:17 -0700 (PDT) In-Reply-To: <20180415163101.6ab15cbc@archlinux> References: <1523637411-8531-1-git-send-email-hernan@vanguardiasur.com.ar> <1523637411-8531-10-git-send-email-hernan@vanguardiasur.com.ar> <20180415163101.6ab15cbc@archlinux> From: =?UTF-8?Q?Hern=C3=A1n_Gonzalez?= Date: Wed, 18 Apr 2018 16:25:17 -0300 Message-ID: Subject: Re: [PATCH v2 09/14] staging: iio: ad7746: Add remove() To: Jonathan Cameron Cc: knaack.h@gmx.de, lars@metafoo.de, Peter Meerwald-Stadler , gregkh@linuxfoundation.org, Michael.Hennerich@analog.com, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Apr 15, 2018 at 12:31 PM, Jonathan Cameron wrote= : > On Fri, 13 Apr 2018 13:36:46 -0300 > Hern=C3=A1n Gonzalez wrote: > >> This allows the driver to be probed and removed as a module powering it >> down on remove(). >> >> Signed-off-by: Hern=C3=A1n Gonzalez >> --- >> drivers/staging/iio/cdc/ad7746.c | 26 ++++++++++++++++++++++++++ >> 1 file changed, 26 insertions(+) >> >> diff --git a/drivers/staging/iio/cdc/ad7746.c b/drivers/staging/iio/cdc/= ad7746.c >> index c29a221..05506bf9 100644 >> --- a/drivers/staging/iio/cdc/ad7746.c >> +++ b/drivers/staging/iio/cdc/ad7746.c >> @@ -775,6 +775,31 @@ static int ad7746_probe(struct i2c_client *client, >> return 0; >> } >> >> +static int ad7746_remove(struct i2c_client *client) >> +{ >> + struct iio_dev *indio_dev =3D i2c_get_clientdata(client); >> + struct ad7746_chip_info *chip =3D iio_priv(indio_dev); >> + unsigned char regval; >> + int ret; >> + >> + mutex_lock(&chip->lock); >> + >> + regval =3D chip->config | AD7746_CONF_MODE_PWRDN; >> + ret =3D i2c_smbus_write_byte_data(chip->client, AD7746_REG_CFG, re= gval); > As this is a one off operation, perhaps it would be better to factor > it out to a utility function then use devm_add_action_or_reset in > the probe? > > Also, I am nervous about this change as there doesn't seem to be > path in probe by which this is deliberately reversed? > It seems to be 'accidentally' handled by the read_raw write to the > CFG register. > > The data sheet doesn't really mention much about this register > at all. It may have special requirements to exit from power down - I hav= e > no idea, but if it is costless, why do we bother with idle mode? > > Perhaps Michael can confirm if this is safe to do or not. > > I guess it'll be better to just drop this until Michael answers. I've been trying to get a hold of the hw but with no success (or I have to pay 3 times its cost in shipping), will keep searching though. >> + >> + mutex_unlock(&chip->lock); >> + >> + if (ret < 0) { >> + dev_warn(&client->dev, "Could NOT Power Down!\n"); >> + goto out; >> + } >> + >> + iio_device_unregister(indio_dev); > You can't safely do this against the devm_iio_device_register. > >> + >> +out: >> + return ret; >> +} >> + >> static const struct i2c_device_id ad7746_id[] =3D { >> { "ad7745", 7745 }, >> { "ad7746", 7746 }, >> @@ -799,6 +824,7 @@ static struct i2c_driver ad7746_driver =3D { >> .of_match_table =3D of_match_ptr(ad7746_of_match), >> }, >> .probe =3D ad7746_probe, >> + .remove =3D ad7746_remove, >> .id_table =3D ad7746_id, >> }; >> module_i2c_driver(ad7746_driver); >