Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp1640683imw; Sat, 16 Jul 2022 11:08:46 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v/zrCx+fCt1sd3uUgYaVDDRrwgEV1DAW7WY/2Dr1GuAeY8oUXdraUsn8Fg6Uo/47xI0C8N X-Received: by 2002:a63:88c1:0:b0:419:9526:680 with SMTP id l184-20020a6388c1000000b0041995260680mr17106973pgd.130.1657994926224; Sat, 16 Jul 2022 11:08:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657994926; cv=none; d=google.com; s=arc-20160816; b=uA3oWUbyHOKTTcwBsY877nTkRHpvZPRZvT0DA4T46bvIxAh38sBuJ74V1Gl/uppO+E UhsB1V9goLbBMUyIxV7i90eQQ1X1exZhlS2eECApHW4wWoKlHnoIKjugSnK2wvssY6cj 1Y7iT5YsbI5UFGyF/od8LpQbTANqVGM8iKoi9iO62dI7dRehU/eyicKvOsfjn3As+m8r HoiR0WUYXDl9urozH2vEg2hsoJyIErToJmT9iKmffhO8g1aAPAWNH4b/oqXaNtcXoFwX br1gIkPsluzPQWd3kSqctXL5fl0rLoAITF7PaI7sdGQogi1ft4Ov4SFX9xzi7dV5b9Jo R5Ow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=lo8O1n30OVaPNSJyIvL7uVNjJsPxF8BfNJKW9+iDHF4=; b=jqXAiPx7XPFqSGS/3rxJMobQCfyqqzhpDjf7C46bp3jocXXfgQgtklmPmFXSc6qKPB YbWW3w/8WZQIGcGH20D610LWJrwL4DjbM4zp9b2IzLpVCKCREB15pv6g3/soML6PEjIG Vhy758eisaiJYNJIO0f5W+JRddgazCAHPEnARIX6jKJp3ZogKe8STg86MpsHgLTQ74LK M+svALHOtgdid6GUh22NK0x6KdFurT6XK9jyQlD62M4aiPsm7CZks4otBa++MKsR/W1H 7xkjP8cRYsimDriV7hdXZ0KR8in2Iy3nHtbaSkx71KPLvzhVUIxFW6YzfQ/n178IFlgd 5GVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RzYkRM9J; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d67-20020a636846000000b00415ed5db5absi8079471pgc.772.2022.07.16.11.08.32; Sat, 16 Jul 2022 11:08:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RzYkRM9J; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S231624AbiGPR31 (ORCPT + 99 others); Sat, 16 Jul 2022 13:29:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229558AbiGPR3Z (ORCPT ); Sat, 16 Jul 2022 13:29:25 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0AC17658C; Sat, 16 Jul 2022 10:29:25 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 99DC3611A6; Sat, 16 Jul 2022 17:29:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C6AB4C34114; Sat, 16 Jul 2022 17:29:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1657992564; bh=s8zWDI7l/NEtm0Ui8Ues2MDYedJLomU5WQ+1kwrGMTc=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=RzYkRM9JYVwJFJLryAPipOhrM/XTg33zf9V5Qw46GjTEvCx+MR1Nf+91hJyf4jnu8 VQgnvKCuVquFBKAZYJvBZpaz/RLgxT0AnbB39bsxVSwKe/nzD2WqCXNhdjizKnJJO9 KKUbH9rCWRPBaAjha1TwQ+YG81Zv1+4Qhy9JYQHVeQid7O7/Ei0OIzEHxQzBoYwWRf EZusq9rIeWXhGTf8F1vw6ELestdytxXTej/AQymc4lr0O/g5pBo0LD6uvOUCS0DZWD miOTetATkThg/oN6H15XWhJ0PVToeZE9g+/xtDJknHM4kJXkynWV31h7ejxjxUvKC9 tEhQdIKH0pKjg== Date: Sat, 16 Jul 2022 18:39:16 +0100 From: Jonathan Cameron To: ChiYuan Huang Cc: Rob Herring , Krzysztof Kozlowski , Lars-Peter Clausen , cy_huang , linux-iio , lkml , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" Subject: Re: [PATCH v5 2/2] iio: adc: Add rtq6056 support Message-ID: <20220716183916.7b40d9d5@jic23-huawei> In-Reply-To: References: <1657116702-24161-1-git-send-email-u0084500@gmail.com> <1657116702-24161-3-git-send-email-u0084500@gmail.com> <20220707183027.342f6c88@jic23-huawei> X-Mailer: Claws Mail 4.1.0 (GTK 3.24.34; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > > > > + > > > > +static int rtq6056_probe(struct i2c_client *i2c) > > > > +{ > > > > + struct iio_dev *indio_dev; > > > > + struct rtq6056_priv *priv; > > > > + struct device *dev = &i2c->dev; > > > > + struct regmap *regmap; > > > > + unsigned int vendor_id, shunt_resistor_uohm; > > > > + int ret; > > > > + > > > > + if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_WORD_DATA)) > > > > + return -EOPNOTSUPP; > > > > + > > > > + indio_dev = devm_iio_device_alloc(dev, sizeof(*priv)); > > > > + if (!indio_dev) > > > > + return -ENOMEM; > > > > + > > > > + priv = iio_priv(indio_dev); > > > > + priv->dev = dev; > > > > + priv->vshuntct_us = priv->vbusct_us = 1037; > > > > + priv->avg_sample = 1; > > > > + i2c_set_clientdata(i2c, priv); > > > > + > > > > + regmap = devm_regmap_init_i2c(i2c, &rtq6056_regmap_config); > > > > + if (IS_ERR(regmap)) > > > > + return dev_err_probe(dev, PTR_ERR(regmap), > > > > + "Failed to init regmap\n"); > > > > + > > > > + priv->regmap = regmap; > > > > + > > > > + ret = regmap_read(regmap, RTQ6056_REG_MANUFACTID, &vendor_id); > > > > + if (ret) > > > > + return dev_err_probe(dev, ret, > > > > + "Failed to get manufacturer info\n"); > > > > + > > > > + if (vendor_id != RTQ6056_VENDOR_ID) > > > > + return dev_err_probe(dev, -ENODEV, > > > > + "Invalid vendor id 0x%04x\n", vendor_id); > > > > + > > > > + ret = devm_regmap_field_bulk_alloc(dev, regmap, priv->rm_fields, > > > > + rtq6056_reg_fields, F_MAX_FIELDS); > > > > + if (ret) > > > > + return dev_err_probe(dev, ret, "Failed to init regmap field\n"); > > > > + > > > > + /* > > > > + * By default, configure average sample as 1, bus and shunt conversion > > > > + * timea as 1037 microsecond, and operating mode to all on. > > > > + */ > > > > + ret = regmap_write(regmap, RTQ6056_REG_CONFIG, RTQ6056_DEFAULT_CONFIG); > > > > + if (ret) > > > > + return dev_err_probe(dev, ret, > > > > + "Failed to enable continuous sensing\n"); > > > > + > > > > + pm_runtime_set_autosuspend_delay(dev, MSEC_PER_SEC); > > > > + pm_runtime_use_autosuspend(dev); > > > > + pm_runtime_set_active(dev); > > > > + pm_runtime_mark_last_busy(dev); > > > > + pm_runtime_enable(dev); > > > > > > Look at whether you can use devm_pm_runtime_enable() > > > Note it handles disabling autosuspend for you. > > > > > > When using runtime_pm() you want to ensure that the device works without > > > runtime pm support being enabled. As such, you turn the device on before > > > enabling runtime_pm() and (this is missing I think) turn it off after disabling > > > runtime pm. So I'd expect a devm_add_action_or_reset() call to unwind > > > setting the device into continuous sending above. > > > > > If so, I think it's better to configure the device keep in off state > > in probe stage. > > The calling order may need to be changed as below > > devm_add_action_or_reset... > > > > pm_runtime_set_autosuspend_delay > > pm_runtime_use_auto_suspend > > devm_pm_runtime_enable > > > Ah, not correct. How about if 'PM_RUNTIME' is not enabled? > Do we need to consider about this case? > > If yes, the original flow about 'pm_runtime' is correct. I don't follow. Perhaps next version will make it clear what you mean. Jonathan