From patchwork Tue May 13 16:24:54 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Moll X-Patchwork-Id: 30109 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f200.google.com (mail-ve0-f200.google.com [209.85.128.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id F40DB20446 for ; Tue, 13 May 2014 16:25:23 +0000 (UTC) Received: by mail-ve0-f200.google.com with SMTP id pa12sf1700174veb.7 for ; Tue, 13 May 2014 09:25:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=QOSqq8co9tDP7gF3ty5b3GOVZlPI3dKv7L8rR1XqBOU=; b=lIsDB/n6bJWUxnN/0iHCyGYynR4RZHZHymM5Qrtn75SnhJf38MxTeLu+8a3lGG31Fh d6vUkJjCAGN9wqfZLtm9h/1TDtARe0woLaFFlK8zTZb1JwWxcCVzK6iJJX2maxzqbwRA MUgYYgbFMgcFmgtxdT7mqTQk4yYuNT4vFmzR72/p41OK/1n2vDhA+st/G/eq5JBzGJRr br7LYuvukaRvEaiPpiZemZb9KLUgFZJA36AVCEzG4zHY86fhMVA3ch+grmSBbX3n4SAC WhpTVYQrxo3FlitO/L2MoQa5U78fOckwoI0cNutUuXzZACjLTgkugbLVMLl9MEoQv5Vv K1BA== X-Gm-Message-State: ALoCoQkkgljp+jYSaBPvZxUS4C9/RnFMxZ+p5cZrU/lpzE+m4cPP2Z5tV8gNzlMXEZCqN3Of+Zfj X-Received: by 10.236.11.194 with SMTP id 42mr14475751yhx.49.1399998323667; Tue, 13 May 2014 09:25:23 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.23.147 with SMTP id 19ls1952167qgp.68.gmail; Tue, 13 May 2014 09:25:23 -0700 (PDT) X-Received: by 10.58.178.130 with SMTP id cy2mr1145620vec.55.1399998323464; Tue, 13 May 2014 09:25:23 -0700 (PDT) Received: from mail-vc0-f175.google.com (mail-vc0-f175.google.com [209.85.220.175]) by mx.google.com with ESMTPS id sv4si1263605vdc.205.2014.05.13.09.25.23 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 13 May 2014 09:25:23 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.175 as permitted sender) client-ip=209.85.220.175; Received: by mail-vc0-f175.google.com with SMTP id hu19so770361vcb.20 for ; Tue, 13 May 2014 09:25:23 -0700 (PDT) X-Received: by 10.220.5.129 with SMTP id 1mr901911vcv.71.1399998323347; Tue, 13 May 2014 09:25:23 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp164700vcb; Tue, 13 May 2014 09:25:22 -0700 (PDT) X-Received: by 10.68.202.167 with SMTP id kj7mr6409197pbc.160.1399998322169; Tue, 13 May 2014 09:25:22 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id xt10si13784609pab.8.2014.05.13.09.25.21; Tue, 13 May 2014 09:25:21 -0700 (PDT) Received-SPF: none (google.com: devicetree-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754094AbaEMQZU (ORCPT + 8 others); Tue, 13 May 2014 12:25:20 -0400 Received: from fw-tnat.austin.arm.com ([217.140.110.23]:41508 "EHLO collaborate-mta1.arm.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750916AbaEMQZR (ORCPT ); Tue, 13 May 2014 12:25:17 -0400 Received: from hornet.Cambridge.Arm.com (hornet.cambridge.arm.com [10.2.201.45]) by collaborate-mta1.arm.com (Postfix) with ESMTP id 17D6013F8B8; Tue, 13 May 2014 11:25:05 -0500 (CDT) From: Pawel Moll To: Grant Likely , Rob Herring Cc: devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Pawel Moll Subject: [PATCH v2] of/platform: Add of_platform_depopulate() helper Date: Tue, 13 May 2014 17:24:54 +0100 Message-Id: <1399998294-24447-1-git-send-email-pawel.moll@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1399997324.3657.35.camel@hornet> References: <1399997324.3657.35.camel@hornet> Sender: devicetree-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: devicetree@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: pawel.moll@arm.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.175 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Drivers can us of_platform_populate() to create platform devices for children of the device main node (this can particularly happen in case of MFD devices). Unfortunately, there was no standard way of removing such sub-devices when the main one is being removed. This patch adds of_platform_depopulate() as a complementary operation for the _populate() one. It removes all platform and amba devices that have been created from the Device Tree, but leaves all other ones untouched (returning -EBUSY in such case). Signed-off-by: Pawel Moll Acked-by: Grant Likely --- Changes since v1: - using bool rather than int to signal remaining children - recursing using of_platform_depopulate() itself drivers/of/platform.c | 50 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/of_platform.h | 5 +++++ 2 files changed, 55 insertions(+) diff --git a/drivers/of/platform.c b/drivers/of/platform.c index 236f47e..3b51e04 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -495,4 +495,54 @@ int of_platform_populate(struct device_node *root, return rc; } EXPORT_SYMBOL_GPL(of_platform_populate); + +static int of_platform_device_destroy(struct device *dev, void *data) +{ + bool *children_left = data; + + /* Do not touch devices not populated from the device tree */ + if (!dev->of_node || !of_node_check_flag(dev->of_node, OF_POPULATED)) { + *children_left = true; + return 0; + } + + /* Recurse, but don't touch this device if it has any children left */ + if (of_platform_depopulate(dev) != 0) { + *children_left = true; + return 0; + } + + if (dev->bus == &platform_bus_type) + platform_device_unregister(to_platform_device(dev)); + else if (dev->bus == &amba_bustype) + amba_device_unregister(to_amba_device(dev)); + else + *children_left = true; + + return 0; +} + +/** + * of_platform_depopulate() - Remove devices populated from device tree + * @parent: device which childred will be removed + * + * Complementary to of_platform_populate(), this function removes children + * of the given device (and, recurrently, their children) that have been + * created from their respective device tree nodes (and only those, + * leaving others - eg. manually created - unharmed). + * + * Returns 0 when all children devices have been removed or + * -EBUSY when some children remained. + */ +int of_platform_depopulate(struct device *parent) +{ + bool children_left = false; + + device_for_each_child(parent, &children_left, + of_platform_device_destroy); + + return children_left ? -EBUSY : 0; +} +EXPORT_SYMBOL_GPL(of_platform_depopulate); + #endif /* CONFIG_OF_ADDRESS */ diff --git a/include/linux/of_platform.h b/include/linux/of_platform.h index 05cb4a9..b1010ee 100644 --- a/include/linux/of_platform.h +++ b/include/linux/of_platform.h @@ -72,6 +72,7 @@ extern int of_platform_populate(struct device_node *root, const struct of_device_id *matches, const struct of_dev_auxdata *lookup, struct device *parent); +extern int of_platform_depopulate(struct device *parent); #else static inline int of_platform_populate(struct device_node *root, const struct of_device_id *matches, @@ -80,6 +81,10 @@ static inline int of_platform_populate(struct device_node *root, { return -ENODEV; } +static inline int of_platform_depopulate(struct device *parent) +{ + return -ENODEV; +} #endif #endif /* _LINUX_OF_PLATFORM_H */