Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp562005yba; Wed, 15 May 2019 06:14:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqzunwP7iqlshsnrtqlU7Zz5oVcju5gHUoyK9m9H9XnDh3VwBU33ZsK4ih2TCtokhsPZ8uGC X-Received: by 2002:a17:902:b191:: with SMTP id s17mr21907954plr.262.1557926083679; Wed, 15 May 2019 06:14:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557926083; cv=none; d=google.com; s=arc-20160816; b=Mm76uVeRPANw/BUENn45IjIKPhAK2eUiWG1XbH3e96imp/2tUwFI7BwcbyPasITIJ4 Y/U8yz1M2SabW7eBXGIwhel0lUQNAydTP0xQPdD4+6G8cMAvcCfylVXEjpvXnJOuEJOs gNqfAfE7WtptYTLQlaFDD7bLj+fJR8TJxTljDkNF3nAd9uz/cGefTFO8fQiDCArac8o8 hi/2lbTSERYxbKHvRMw0r4Gaohs6LjpnF6Y/a04dZ7AXo2p0ZiCiosNVE+HiF8K2fJRo EJVCQIk3qkmrF/z9YWZVKJi6FiSWPVcq/Pv7T7T+TlbsimOjJQYQkTK0WhCarMgRPTf9 4txw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=Nushr9Q4ATrGXX1cBhEzuz9GYEidZFGLJO4tbBczcbM=; b=CpBHRzAfRrR+/Kv+gNFtl1WaerNPkMZ9UgcFv1X4+N/fx2NT279U27zucLbQSCtx92 ct2ExC6LlKdF+3PVxbzRMvPkJgluBOOPlYQDBYTUL6bUKsOxRdUoqKc2QRVtqz7dXLQc 4kCoRVZdeuMAh5ryXvKMleFdinf11oAn3FgC2t0jQ80vXS2Z5EddT0wQsMscvLTENmaN +0agfC2azvQR4tSEmR55zMmVe62BUFYd78PsNhROV4qgxtYqCasiQhOeYsyydb5bBppn vDTvw+ZRZmgH3Y7ys2j1zT2GfhBboP46kaBIdGhPO6i8a4i1vyW1yjenXP5gElWNd3Jf z3jA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@st.com header.s=STMicroelectronics header.b=Db2STe7U; 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 o66si2111069pfa.23.2019.05.15.06.14.29; Wed, 15 May 2019 06:14:43 -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=@st.com header.s=STMicroelectronics header.b=Db2STe7U; 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 S1727685AbfEONMh (ORCPT + 99 others); Wed, 15 May 2019 09:12:37 -0400 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:60882 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727279AbfEONMT (ORCPT ); Wed, 15 May 2019 09:12:19 -0400 Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx08-00178001.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x4FDBiB6004311; Wed, 15 May 2019 15:12:05 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=STMicroelectronics; bh=Nushr9Q4ATrGXX1cBhEzuz9GYEidZFGLJO4tbBczcbM=; b=Db2STe7UxW1FEPSN2ItGT+VUAYbPjDC1xrsS1tpWJ7Tv2hE3wen+CCsnWMIHe9ShUpqf onpkGHkNa/6Yuda/EDs3zbtZxspgLtQtNg12lK2joxVNplB/LtJwOneWk+7sThnXtZAT 6OGLPg7WXkEFTPPnRKJ5JuUbMlc4dcFB/QwxXKvC3uxGvJqGAr6HbhhZG3y+sJN8moqt huIkibREvpjfkJ0lNE/k0dfNkv0m/t2zS7XfECGz0osM1iZBzQ9E4ReAxbO2Ly4JA8Da 1z9bDngVfndzZBdF+XtTb5ls4RUjtHdUzdBNm0ZYRbPLdIEdGK4937XbD2otIkpd77kf TQ== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 2sdn9g0yej-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Wed, 15 May 2019 15:12:05 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id D352E34; Wed, 15 May 2019 13:12:02 +0000 (GMT) Received: from Webmail-eu.st.com (Safex1hubcas24.st.com [10.75.90.94]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id A844127F6; Wed, 15 May 2019 13:12:02 +0000 (GMT) Received: from SAFEX1HUBCAS22.st.com (10.75.90.93) by Safex1hubcas24.st.com (10.75.90.94) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 15 May 2019 15:12:02 +0200 Received: from localhost (10.201.20.122) by Webmail-ga.st.com (10.75.90.48) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 15 May 2019 15:12:01 +0200 From: Benjamin Gaignard To: , , , , , , , , CC: , , , , , Benjamin Gaignard Subject: [PATCH v2 1/5] of/device: Add of_device_link_add function Date: Wed, 15 May 2019 15:11:50 +0200 Message-ID: <20190515131154.18373-2-benjamin.gaignard@st.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20190515131154.18373-1-benjamin.gaignard@st.com> References: <20190515131154.18373-1-benjamin.gaignard@st.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.201.20.122] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-05-15_07:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use 'suspend-dependencies' property from device node to ensure that the listed devices will suspended after it and resumed before it. Signed-off-by: Benjamin Gaignard --- CC: Rafael J. Wysocki version 2: - only keep of_device_links_add() and use DL_FLAG_PM_RUNTIME and DL_FLAG_AUTOREMOVE_CONSUMER flags to follow Rafael advices - reword function description - try to use a more explicit property name drivers/of/device.c | 37 +++++++++++++++++++++++++++++++++++++ include/linux/of_device.h | 7 +++++++ 2 files changed, 44 insertions(+) diff --git a/drivers/of/device.c b/drivers/of/device.c index 3717f2a20d0d..44ec84eee310 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -336,3 +336,40 @@ int of_device_uevent_modalias(struct device *dev, struct kobj_uevent_env *env) return 0; } EXPORT_SYMBOL_GPL(of_device_uevent_modalias); + +/** + * of_device_links_add - Create links between a consumer device + * and it listed dependencies from device tree data + * + * @consumer: consumer device + * + * Ensure that consumer's dependencies will be suspended after it + * and resumed before it. + * + * Returns 0 on success, < 0 on failure. + */ +int of_device_links_add(struct device *consumer) +{ + struct device_node *np; + struct platform_device *pdev; + int i = 0; + + np = of_parse_phandle(consumer->of_node, "suspend-dependencies", i++); + while (np) { + pdev = of_find_device_by_node(np); + of_node_put(np); + if (!pdev) + return -EINVAL; + + device_link_add(consumer, &pdev->dev, + DL_FLAG_PM_RUNTIME | + DL_FLAG_AUTOREMOVE_CONSUMER); + platform_device_put(pdev); + + np = of_parse_phandle(consumer->of_node, "suspend-dependencies", + i++); + } + + return 0; +} +EXPORT_SYMBOL_GPL(of_device_links_add); diff --git a/include/linux/of_device.h b/include/linux/of_device.h index 8d31e39dd564..83f24c386d51 100644 --- a/include/linux/of_device.h +++ b/include/linux/of_device.h @@ -41,6 +41,8 @@ extern int of_device_request_module(struct device *dev); extern void of_device_uevent(struct device *dev, struct kobj_uevent_env *env); extern int of_device_uevent_modalias(struct device *dev, struct kobj_uevent_env *env); +extern int of_device_links_add(struct device *consumer); + static inline void of_device_node_put(struct device *dev) { of_node_put(dev->of_node); @@ -91,6 +93,11 @@ static inline int of_device_uevent_modalias(struct device *dev, return -ENODEV; } +static int of_device_links_add(struct device *consumer) +{ + return 0; +} + static inline void of_device_node_put(struct device *dev) { } static inline const struct of_device_id *__of_match_device( -- 2.15.0