Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp2983835imw; Sun, 17 Jul 2022 22:47:47 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uFDC9w3KCm7MMkjpM7205e+QJUPA7w7Fh9UwXiF5PBO6/6N8XyNNrSD31TUJjQKwTFR7U7 X-Received: by 2002:a63:2ccd:0:b0:411:54ac:5c7e with SMTP id s196-20020a632ccd000000b0041154ac5c7emr22792164pgs.561.1658123267655; Sun, 17 Jul 2022 22:47:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658123267; cv=none; d=google.com; s=arc-20160816; b=iFVP+otbmGvY9GLMhLaVH83NYJR7mmzNXqgxnLcYZhRKa7LdmeCp5zxISJoKVh6IGJ CFxe8/9FWezpjsnQDIwKlekVOTPJ7eJrj+6JMCvAywjUkICMnr0dfwr9fkGmyVH/gbDl 2wL6XL4u1qh2IimtB9P5ZXEu63bY6eOl6Hq0450LkNvef3etE3hJHUlx3L6GEW3cyuve xVvgYmFoT1rglvqYBaH1tw1gYQ095dx0lYS7A3kG36EydSeDk3bp8KAy9SytUO5eRagr ohQshiFQE0Zpn+QlDiCEjstPmXeIC6WYc5CJwUbSqkamY2AsKI1FhYU494oOhvv+/XsQ rrXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=WPUM0QjY/sxRNhLvinK04kERO7bObycKQncweFYJTkI=; b=fZIik2BMzItSUc7CgcxJG9JWKi6UeWoXGVLVgwI47fRcKE8vMBGLf9uAIr80TB4MWG diiq/cBKPeGmeYneLtip819DQizo70F7RpMz7UdOoBS+HS05TFVuVmSTk8clhVHlwUay UnZ2CxdqnZQEY7rT4j4BzSOCk8bkvnNOYgaIKaNZxcWDGMzrfKCw+K5XItyJje2YW8sj ZhDztYIqQsz7dFg0hvdra/np+jQT3YriREraqC3ADRB8/hkfTjleLlzudy+Z1m9nzh3V ZvWrvoRwLYY0sWfBPb7vrvcNDKP+QydNvriGqSsAt1+V5uHG4X6i36DpbD9sigZix/zY Q8Uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=oRBzt0Fh; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d6-20020a637346000000b00412791245ccsi14718998pgn.850.2022.07.17.22.47.33; Sun, 17 Jul 2022 22:47:47 -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=@gmail.com header.s=20210112 header.b=oRBzt0Fh; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233316AbiGRFo0 (ORCPT + 99 others); Mon, 18 Jul 2022 01:44:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233194AbiGRFoU (ORCPT ); Mon, 18 Jul 2022 01:44:20 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC4DD1A9; Sun, 17 Jul 2022 22:44:19 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id v16so15415543wrd.13; Sun, 17 Jul 2022 22:44:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=WPUM0QjY/sxRNhLvinK04kERO7bObycKQncweFYJTkI=; b=oRBzt0FhFYqXVzXAEtQw556Tw5w86B0t4yYZKTStAMu9eCDhzx2sl9KNdD/vJ0c6o1 ABLv7b+7D7gVjtkipmrJZJaDwLtnsL4JmQYEu9GfR2MRTsGTsu05mn8z3W5spa5Y4gH4 HJsTbEbM1E1EIY2e5liIry5z2VzdoQgmQLeYRWCoxTcWi5QRv5ih8PjaSiXQr8Cq1YUm olRmc6KeUWJldSZaOtSr763eBBtG5MV/zKNOrSht0oTO4m6HYFHg9yeDcULGyoGFmtFL /F1GX4gDpcXQOriy5J+yciwR3P33K7erMiXHG78KaIiy7C+if+UDI0Gd+AEcAXuYrkEd 5V5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=WPUM0QjY/sxRNhLvinK04kERO7bObycKQncweFYJTkI=; b=vepxofrptM8gQltsdp7oGfMFvnNrVozHiIk6QJU/UY/X/7Mpi3dFW5O6zDH6yy2WoA n0tXK7CjokqyxIBNaia5e+zS5/xlVdDVQrNAOb6GM9LtC5D5OVWlc5ow55+t5gcX1Rpk 4V0ezqHhCVWT0e4OdIlm7CAt6k9EgYu0pZk46UWd3Hjhf7hgvJ1UXPqMYtZtwrl/bBId A7LLB5hzOZ4ycCfnKsDKWlZdglAbhp7IL/upOmJdf01hbB4JAPiXbujW4J+OVNMshexA hI3j0NeMGzBjdjzIW3iHMVhZsjB5YXhx8MvaX6xDhGW790oGW/LcjE1TeU3vjS+bLgv8 zXlg== X-Gm-Message-State: AJIora+n84X2lv0HkpzmYDgrZQR1SAWlffozoeAbP2NJ1FAPZbn+F5Fi QMNaJYC62Sm+5cTaGeAQWD0uxqCGVkL0U9IgDgY= X-Received: by 2002:adf:f043:0:b0:21d:6a90:f3e6 with SMTP id t3-20020adff043000000b0021d6a90f3e6mr21496516wro.277.1658123058101; Sun, 17 Jul 2022 22:44:18 -0700 (PDT) MIME-Version: 1.0 References: <1657116702-24161-1-git-send-email-u0084500@gmail.com> <1657116702-24161-3-git-send-email-u0084500@gmail.com> <20220707183027.342f6c88@jic23-huawei> <20220716183916.7b40d9d5@jic23-huawei> In-Reply-To: <20220716183916.7b40d9d5@jic23-huawei> From: ChiYuan Huang Date: Mon, 18 Jul 2022 13:44:06 +0800 Message-ID: Subject: Re: [PATCH v5 2/2] iio: adc: Add rtq6056 support To: Jonathan Cameron Cc: Rob Herring , Krzysztof Kozlowski , Lars-Peter Clausen , cy_huang , linux-iio , lkml , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,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 HI, Jonathan Jonathan Cameron =E6=96=BC 2022=E5=B9=B47=E6=9C=8817=E6= =97=A5 =E9=80=B1=E6=97=A5 =E5=87=8C=E6=99=A81:29=E5=AF=AB=E9=81=93=EF=BC=9A > > > > > > > + > > > > > +static int rtq6056_probe(struct i2c_client *i2c) > > > > > +{ > > > > > + struct iio_dev *indio_dev; > > > > > + struct rtq6056_priv *priv; > > > > > + struct device *dev =3D &i2c->dev; > > > > > + struct regmap *regmap; > > > > > + unsigned int vendor_id, shunt_resistor_uohm; > > > > > + int ret; > > > > > + > > > > > + if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_W= ORD_DATA)) > > > > > + return -EOPNOTSUPP; > > > > > + > > > > > + indio_dev =3D devm_iio_device_alloc(dev, sizeof(*priv)); > > > > > + if (!indio_dev) > > > > > + return -ENOMEM; > > > > > + > > > > > + priv =3D iio_priv(indio_dev); > > > > > + priv->dev =3D dev; > > > > > + priv->vshuntct_us =3D priv->vbusct_us =3D 1037; > > > > > + priv->avg_sample =3D 1; > > > > > + i2c_set_clientdata(i2c, priv); > > > > > + > > > > > + regmap =3D 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 =3D regmap; > > > > > + > > > > > + ret =3D regmap_read(regmap, RTQ6056_REG_MANUFACTID, &vendor= _id); > > > > > + if (ret) > > > > > + return dev_err_probe(dev, ret, > > > > > + "Failed to get manufacturer in= fo\n"); > > > > > + > > > > > + if (vendor_id !=3D RTQ6056_VENDOR_ID) > > > > > + return dev_err_probe(dev, -ENODEV, > > > > > + "Invalid vendor id 0x%04x\n", = vendor_id); > > > > > + > > > > > + ret =3D devm_regmap_field_bulk_alloc(dev, regmap, priv->rm_= fields, > > > > > + rtq6056_reg_fields, F_MA= X_FIELDS); > > > > > + if (ret) > > > > > + return dev_err_probe(dev, ret, "Failed to init regm= ap field\n"); > > > > > + > > > > > + /* > > > > > + * By default, configure average sample as 1, bus and shunt= conversion > > > > > + * timea as 1037 microsecond, and operating mode to all on. > > > > > + */ > > > > > + ret =3D regmap_write(regmap, RTQ6056_REG_CONFIG, RTQ6056_DE= FAULT_CONFIG); > > > > > + if (ret) > > > > > + return dev_err_probe(dev, ret, > > > > > + "Failed to enable continuous s= ensing\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 wi= thout > > > > 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 aft= er disabling > > > > runtime pm. So I'd expect a devm_add_action_or_reset() call to unw= ind > > > > 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. > In v6, I already fixed most about the comment in v5. Only the 'DEFINE_RUNTIME_DEV_PM_OPS' is left. Now all are clear. Please review the v7. It includes all the fixes. Thanks. > Jonathan