From patchwork Tue May 13 11:50:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Moll X-Patchwork-Id: 30041 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f71.google.com (mail-yh0-f71.google.com [209.85.213.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E103C20446 for ; Tue, 13 May 2014 11:50:45 +0000 (UTC) Received: by mail-yh0-f71.google.com with SMTP id 29sf682673yhl.10 for ; Tue, 13 May 2014 04:50:45 -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:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=Qrczj4htEy54vFWM1xq5Fhkg7Bw6Vl4neLx7CUVg0J4=; b=GxAdbBmx3ZiPaujKUDtjkWxfFOoE0qy9qXkQChfqqgzCBms2sJPUXv1hLTYwqvj7hT d5uPiWmqRnS5bbkOMgQr4Wtaq8SjwpXx6BRXSiaxcie8bSNtZTz6aMfALuyf9FA2aJEP DFvLfzMT7iY9o1UWMw6vjo+k+Bzaf6v+tVbv4cLtDjvI+/Lw0mXMBAe1uDHFGb23f/99 1HZssjHUwmzhtpMfbMzazvsm0XMwVkpy1TYgQ28Fxh5Hp/2JenQS4BlR0SVG9IrOoe6b S6nu6BvnBx/DOOMqcXCFgWDlET8z9WFt31cTlIavKthsvLyvPjbyU1UztivutRuH73mS 0vzg== X-Gm-Message-State: ALoCoQnUeaFWD2zIgphMAmVU/ENkMM8sgHdbTaqvVW9FWs86S1mEU1K1eXjJ3aGd8XYp9ck1oVDa X-Received: by 10.58.141.200 with SMTP id rq8mr17016505veb.31.1399981845599; Tue, 13 May 2014 04:50:45 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.24.42 with SMTP id 39ls1765961qgq.26.gmail; Tue, 13 May 2014 04:50:45 -0700 (PDT) X-Received: by 10.52.90.37 with SMTP id bt5mr24377054vdb.7.1399981845519; Tue, 13 May 2014 04:50:45 -0700 (PDT) Received: from mail-ve0-f173.google.com (mail-ve0-f173.google.com [209.85.128.173]) by mx.google.com with ESMTPS id sj10si2599698vcb.123.2014.05.13.04.50.45 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 13 May 2014 04:50:45 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.173 as permitted sender) client-ip=209.85.128.173; Received: by mail-ve0-f173.google.com with SMTP id pa12so261008veb.4 for ; Tue, 13 May 2014 04:50:45 -0700 (PDT) X-Received: by 10.58.13.104 with SMTP id g8mr28300751vec.16.1399981845432; Tue, 13 May 2014 04:50:45 -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 ib8csp144555vcb; Tue, 13 May 2014 04:50:45 -0700 (PDT) X-Received: by 10.68.215.40 with SMTP id of8mr4642358pbc.15.1399981844592; Tue, 13 May 2014 04:50:44 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id gr2si13042369pac.221.2014.05.13.04.50.43; Tue, 13 May 2014 04:50:43 -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 S1753580AbaEMLun (ORCPT + 8 others); Tue, 13 May 2014 07:50:43 -0400 Received: from fw-tnat.austin.arm.com ([217.140.110.23]:18056 "EHLO collaborate-mta1.arm.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753453AbaEMLum (ORCPT ); Tue, 13 May 2014 07:50:42 -0400 Received: from hornet.Cambridge.Arm.com (hornet.cambridge.arm.com [10.2.201.45]) by collaborate-mta1.arm.com (Postfix) with ESMTP id C9E8913F8B8; Tue, 13 May 2014 06:50:41 -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] of: Add of_platform_depopulate() helper Date: Tue, 13 May 2014 12:50:36 +0100 Message-Id: <1399981836-24837-1-git-send-email-pawel.moll@arm.com> X-Mailer: git-send-email 1.9.1 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.128.173 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 --- drivers/of/platform.c | 52 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/of_platform.h | 5 +++++ 2 files changed, 57 insertions(+) diff --git a/drivers/of/platform.c b/drivers/of/platform.c index 2d0c8b7..b5c49c3 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -495,4 +495,56 @@ 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) +{ + int *parents_children_left = data; + int my_children_left = 0; + + /* Do not touch devices not populated from the device tree */ + if (!dev->of_node || !of_node_check_flag(dev->of_node, OF_POPULATED)) { + (*parents_children_left)++; + return 0; + } + + device_for_each_child(dev, &my_children_left, + of_platform_device_destroy); + if (my_children_left) { + (*parents_children_left)++; + 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 + (*parents_children_left)++; + + 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) +{ + int children_left = 0; + + 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 */