Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp3034523imj; Mon, 11 Feb 2019 12:40:20 -0800 (PST) X-Google-Smtp-Source: AHgI3IaMJhP6PhWggomrxX2y+5eB2krorZBymLBzwzS6ZV/xPkdkGJroQ7TVnaYk+KWroj44ZQrZ X-Received: by 2002:a62:1992:: with SMTP id 140mr105293pfz.33.1549917620099; Mon, 11 Feb 2019 12:40:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549917620; cv=none; d=google.com; s=arc-20160816; b=ya4/2wCVcD64g3nmNrnxoQgrSEARR+qmfKWfA8VOVXkbg8RGRo70qRP2iC2GvV2nOZ /reE62XQ5V0tslMXVPDMPO9EU7W68IVQkqms2/KC+tTsZFTlg7LsYIRpjWq3nXzk8SVL fkLVrr1rPEr80xYnVfZc3Xj6SkcoDfNyppyEv4puRX1ur/EgIMtD3F9umzEE+5kEAbBG 9xsU+MsU9/3oZBSPPecAZGgBzawOFAPZQX//z7qSS8kOf9icDd5jRjFj0K48iCVUtQgh dalYC4ZTkdd4g3VoFdPQAUHXmkuLAnFeKBtQPyXLOrqgT2ZF5Gd325Tn3GT3snSydiGT SkHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=4kIi6imB3sTO+Y3yqh3o33hWNkd609CJ/DT7ZurWkF4=; b=LeGvN5x29jQkCfUlQioGxS/ZKjqxKIYxjEwjtGU0tMuPkJyOReqoEbETg5ZaBtg4gf LElemXH/BD1nmvaH2r+dAnsJlN2xhXRx419/lpfhs2+dtPFgv2yPS1nWOEeep7noCIqY 9n828zC5Cvv9nKhd/wJ3IXG8LBrFfvRXX2BKoQ6lWfK4gPNph+1hoCo9LcMhjHcieVGn tl+yJvmZ1+Cccf7CpbbNWQxIFqc/Bf/mHoSBa4DZAdMV4sgwGIjAymrD4b4GeuZ7TzJ9 fOunwUsDYxRoivypWT+O3MbKdwpJaAzfinNk8KJh/kMi9emwIBHKRpZh38EuEG10YLli KI4A== ARC-Authentication-Results: i=1; mx.google.com; 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 l7si10826317plt.25.2019.02.11.12.40.04; Mon, 11 Feb 2019 12:40:20 -0800 (PST) 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; 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 S1732849AbfBKTGi (ORCPT + 99 others); Mon, 11 Feb 2019 14:06:38 -0500 Received: from metis.ext.pengutronix.de ([85.220.165.71]:54393 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731751AbfBKTGi (ORCPT ); Mon, 11 Feb 2019 14:06:38 -0500 Received: from pty.hi.pengutronix.de ([2001:67c:670:100:1d::c5]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gtGuU-00066d-Ph; Mon, 11 Feb 2019 20:06:30 +0100 Received: from ukl by pty.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1gtGuS-0007sp-If; Mon, 11 Feb 2019 20:06:28 +0100 Date: Mon, 11 Feb 2019 20:06:28 +0100 From: Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= To: Fabrice Gasnier Cc: thierry.reding@gmail.com, robh+dt@kernel.org, tduszyns@gmail.com, mark.rutland@arm.com, alexandre.torgue@st.com, mcoquelin.stm32@gmail.com, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-pwm@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com Subject: Re: [PATCH v2 3/3] pwm: core: add consumer device link Message-ID: <20190211190628.eisyi6wjus4ltrrn@pengutronix.de> References: <1549901522-15071-1-git-send-email-fabrice.gasnier@st.com> <1549901522-15071-4-git-send-email-fabrice.gasnier@st.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1549901522-15071-4-git-send-email-fabrice.gasnier@st.com> User-Agent: NeoMutt/20170113 (1.7.2) X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c5 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello Fabrice, On Mon, Feb 11, 2019 at 05:12:02PM +0100, Fabrice Gasnier wrote: > Add a device link between the PWM consumer and the PWM provider. This > enforces the PWM user to get suspended before the PWM provider. It > allows proper synchronization of suspend/resume sequences: the PWM user > is responsible for properly stopping PWM, before the provider gets > suspended: see [1]. Add the device link in: > - pwm_get() > - devm_pwm_get() > - devm_of_pwm_get() > as it requires a reference to the device for the PWM consumer. > > [1] https://lkml.org/lkml/2019/2/5/770 > > Suggested-by: Thierry Reding > Signed-off-by: Fabrice Gasnier > --- > drivers/pwm/core.c | 13 +++++++++++-- > 1 file changed, 11 insertions(+), 2 deletions(-) > > diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c > index 1581f6a..2835e27 100644 > --- a/drivers/pwm/core.c > +++ b/drivers/pwm/core.c > @@ -770,8 +770,13 @@ struct pwm_device *pwm_get(struct device *dev, const char *con_id) > int err; > > /* look up via DT first */ > - if (IS_ENABLED(CONFIG_OF) && dev && dev->of_node) > - return of_pwm_get(dev->of_node, con_id); > + if (IS_ENABLED(CONFIG_OF) && dev && dev->of_node) { > + pwm = of_pwm_get(dev->of_node, con_id); > + if (!IS_ERR(pwm)) > + device_link_add(dev, pwm->chip->dev, > + DL_FLAG_AUTOREMOVE_CONSUMER); > + return pwm; > + } > > /* > * We look up the provider in the static table typically provided by > @@ -851,6 +856,8 @@ struct pwm_device *pwm_get(struct device *dev, const char *con_id) > pwm->args.period = chosen->period; > pwm->args.polarity = chosen->polarity; > > + device_link_add(dev, pwm->chip->dev, DL_FLAG_AUTOREMOVE_CONSUMER); > + > return pwm; > } > EXPORT_SYMBOL_GPL(pwm_get); > @@ -943,6 +950,8 @@ struct pwm_device *devm_of_pwm_get(struct device *dev, struct device_node *np, > if (!IS_ERR(pwm)) { > *ptr = pwm; > devres_add(dev, ptr); > + device_link_add(dev, pwm->chip->dev, > + DL_FLAG_AUTOREMOVE_CONSUMER); IMHO it's surprising that devm_of_pwm_get() does more than of_pwm_get() + devres stuff. I'd put device_link_add() into of_pwm_get(). Best regards Uwe -- Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |