Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp1086608pxv; Fri, 16 Jul 2021 01:01:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxz0a9NOVT1WS2VV6okfkTCJm/yU7uKj3dJL1XdQwUyouCLxd7q2JYVlSpomLjOSTAoBTGa X-Received: by 2002:a17:906:6b1b:: with SMTP id q27mr10337760ejr.169.1626422511635; Fri, 16 Jul 2021 01:01:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626422511; cv=none; d=google.com; s=arc-20160816; b=qkEudL/7of5LXTEFiXJoUo2PqGGGrI+Aq0AK35KfubsBqpltsSeJK9TFIv7Oqjq42y pQsx+/dXz5Xh+EqAzaeeWmyU4isIkz+AVLk7uAWJch6w6Gl7JsfEYR1wGnvzVsBiu6TD P3+ooxuAGAFeSwarxgAKeiyZQyHo2jhCpiUnvVnPYHaMnJtDL4J9ezGMlzYCagYJdU1U rW5R1i8bisuEKKj/9F85YkTSXvRG0cksG1B65XRJAXg8S+wv7CV8wlTovMyZf8JsvZ9x zvVycLMRlk2h3Mk60suXCM54ERAgUp5exqNz9obQiRFCDe3sAy0AheONlTjc/Qkf+6qB 6+Ag== 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 :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=1FthCIF+OIpyfdECQwKtAj2wkHCqwfhDYzYQJ3D8E9I=; b=x3lLsm1e+F7Irjh9ucH6nfaac68tuPiTswibLBRc9eb6d9SeBEebZObv2V9q5Xefjt 2Bdy8KPNOhD8PB352uHlXgRMGNl6uvhajHMIaex6EoqSrVKeDsjTjCeBVcXEY13hW1jG BaQF/1qefF3Vq/mqZZTHo0ZF+pHlZSPqP5UjQi/6z3A7P8NQpB/wTjKNS3JGpGZH+tix +puRDmfj3DOgNL6UGzJg6x6w+FJwlDE4C6pM0C93zh5u8cvI5MERZyU34T6fH0jTOhUg 7Xo9NEQff+yNZMQ4JBfCb8LTjpq02zXCtxnWB9GTwzkMu2TO1BTzZVKhrPdmSRKNlqEU eFVQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dk16si10146805edb.510.2021.07.16.01.01.28; Fri, 16 Jul 2021 01:01:51 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236809AbhGPIC6 convert rfc822-to-8bit (ORCPT + 99 others); Fri, 16 Jul 2021 04:02:58 -0400 Received: from relay6-d.mail.gandi.net ([217.70.183.198]:60603 "EHLO relay6-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236777AbhGPIC4 (ORCPT ); Fri, 16 Jul 2021 04:02:56 -0400 Received: (Authenticated sender: miquel.raynal@bootlin.com) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id 23726C0007; Fri, 16 Jul 2021 07:59:59 +0000 (UTC) Date: Fri, 16 Jul 2021 09:59:58 +0200 From: Miquel Raynal To: Clark Wang Cc: conor.culhane@silvaco.com, alexandre.belloni@bootlin.com, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH V2 5/5] i3c: master: svc: add runtime pm support Message-ID: <20210716095958.4e27d574@xps13> In-Reply-To: <20210716073723.3490180-6-xiaoning.wang@nxp.com> References: <20210716073723.3490180-1-xiaoning.wang@nxp.com> <20210716073723.3490180-6-xiaoning.wang@nxp.com> Organization: Bootlin X-Mailer: Claws Mail 3.17.7 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Clark, > @@ -1431,7 +1502,7 @@ static int svc_i3c_master_probe(struct platform_device *pdev) > GFP_KERNEL); > if (!master->ibi.slots) { > ret = -ENOMEM; > - goto err_disable_sclk; > + goto rpm_disable; > } > > platform_set_drvdata(pdev, master); > @@ -1442,18 +1513,17 @@ static int svc_i3c_master_probe(struct platform_device *pdev) > ret = i3c_master_register(&master->base, &pdev->dev, > &svc_i3c_master_ops, false); > if (ret) > - goto err_disable_sclk; > + goto rpm_disable; > > - return 0; > - > -err_disable_sclk: > - clk_disable_unprepare(master->sclk); > + pm_runtime_mark_last_busy(&pdev->dev); > + pm_runtime_put_autosuspend(&pdev->dev); > > -err_disable_fclk: > - clk_disable_unprepare(master->fclk); > + return 0; > > -err_disable_pclk: > - clk_disable_unprepare(master->pclk); It's not clear to me why you drop the disable_*clk labels to move them back in place? I would rather prefer to keep a clean error path. > +rpm_disable: > + pm_runtime_dont_use_autosuspend(&pdev->dev); > + pm_runtime_put_sync(&pdev->dev); > + pm_runtime_disable(&pdev->dev); > > return ret; > } > @@ -1467,13 +1537,57 @@ static int svc_i3c_master_remove(struct platform_device *pdev) > if (ret) > return ret; > > + pm_runtime_dont_use_autosuspend(&pdev->dev); > + pm_runtime_disable(&pdev->dev); > + > + return 0; > +} > + > +static int __maybe_unused svc_i3c_runtime_suspend(struct device *dev) > +{ > + struct svc_i3c_master *master = dev_get_drvdata(dev); > + > clk_disable_unprepare(master->pclk); > clk_disable_unprepare(master->fclk); > clk_disable_unprepare(master->sclk); > + pinctrl_pm_select_sleep_state(dev); > > return 0; > } > > +static int __maybe_unused svc_i3c_runtime_resume(struct device *dev) > +{ > + struct svc_i3c_master *master = dev_get_drvdata(dev); > + int ret = 0; > + > + pinctrl_pm_select_default_state(dev); > + ret = clk_prepare_enable(master->pclk); > + if (ret) > + return ret; > + > + ret = clk_prepare_enable(master->fclk); > + if (ret) { > + clk_disable_unprepare(master->pclk); > + return ret; > + } > + > + ret = clk_prepare_enable(master->sclk); > + if (ret) { > + clk_disable_unprepare(master->pclk); > + clk_disable_unprepare(master->fclk); > + return ret; > + } > + > + return ret; > +} > + > +static const struct dev_pm_ops svc_i3c_pm_ops = { > + SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, > + pm_runtime_force_resume) > + SET_RUNTIME_PM_OPS(svc_i3c_runtime_suspend, > + svc_i3c_runtime_resume, NULL) > +}; > + > static const struct of_device_id svc_i3c_master_of_match_tbl[] = { > { .compatible = "silvaco,i3c-master" }, > { /* sentinel */ }, > @@ -1485,6 +1599,7 @@ static struct platform_driver svc_i3c_master = { > .driver = { > .name = "silvaco-i3c-master", > .of_match_table = svc_i3c_master_of_match_tbl, > + .pm = &svc_i3c_pm_ops, > }, > }; > module_platform_driver(svc_i3c_master); Thanks, Miquèl