From patchwork Wed Jul 29 14:51:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 1338351 X-Patchwork-Delegate: eugen.hristev@microchip.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=quarantine dis=none) header.from=microchip.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=microchip.com header.i=@microchip.com header.a=rsa-sha256 header.s=mchp header.b=o181oLVm; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BGxN84LWPz9sRN for ; Thu, 30 Jul 2020 00:52:24 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0C2B0825F3; Wed, 29 Jul 2020 16:52:21 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=quarantine dis=none) header.from=microchip.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=microchip.com header.i=@microchip.com header.b="o181oLVm"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BB900825BD; Wed, 29 Jul 2020 16:52:00 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from esa3.microchip.iphmx.com (esa3.microchip.iphmx.com [68.232.153.233]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 79CCA825A7 for ; Wed, 29 Jul 2020 16:51:54 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=microchip.com Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=Claudiu.Beznea@microchip.com DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1596034314; x=1627570314; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=AtVP4Zh1R/ODUW5KPnFDV3JNfpwIHw+Jgw7/qltfxG4=; b=o181oLVm6EUgWXkKkSBwLPFDzD6LdFdGjLTt/7iKv707uWIJMVv4C5Iz BcZPxLfu8X74Yo/yYdytY6aaxi1xDgAdWuMHN/sGl2pEl5IY/vg9/lFda ++GQ4dXx5ERkxAsHE/AEC8FnYc1D6+X/lVkEW3nKmrx733jSxbQ2dZXaB rtksPjEajco+KDpaVOiUgZWKicBWqDYNsUNm0iYfV9tDg/Xte5+lakBCC FFRWqm9kJM815rW1dGsZHFMJpHj5YB4h+A01/Y1B9LDpqVJZBIbnOtB7r OVSDKG57fDWMcGS+4ytE6VTqU1xpykSCwQwGP5T4mZW6ErUt26b+6eoLq w==; IronPort-SDR: /OcGBa4uT9lz988aTedUvMQV/KPLVX1AM/QlM2ncv0p8Fx+y8SPulBZDP2vhkslVVG6Dc0Sgv5 +pWJznfZiqb9RBZjU/5aKb0O8j2m7GhKCIML4UzUZp1r2aKxnkLpRXN2KyV+jEM4CmGV2B+tSA XTqwHezxsBhqsDmzXCZ34tqL6Dx7CtO1oKmWucA3NwmA59OYSCFH3TC2RGm0G37SX7+zysBIjd 1LCPNy1fklyBmu+hOllMGXTm1knv9B4BUQwDzxCPtXxvLiGL+LTzwWB161yAGfOW/+HuBq/EV3 ckc= X-IronPort-AV: E=Sophos;i="5.75,410,1589266800"; d="scan'208";a="85826021" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa3.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 29 Jul 2020 07:51:52 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 29 Jul 2020 07:51:03 -0700 Received: from m18063-ThinkPad-T460p.microchip.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.1979.3 via Frontend Transport; Wed, 29 Jul 2020 07:51:48 -0700 From: Claudiu Beznea To: , CC: , Subject: [PATCH 03/22] dm: core: add support for device re-parenting Date: Wed, 29 Jul 2020 17:51:22 +0300 Message-ID: <1596034301-5428-4-git-send-email-claudiu.beznea@microchip.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1596034301-5428-1-git-send-email-claudiu.beznea@microchip.com> References: <1596034301-5428-1-git-send-email-claudiu.beznea@microchip.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean In common clock framework the relation b/w parent and child clocks is determined based on the udevice parent/child information. A clock parent could be changed based on devices needs. In case this is happen the functionalities for clock who's parent is changed are broken. Add a function that reparent a device. This will be used in clk-uclass.c to reparent a clock device. Signed-off-by: Claudiu Beznea --- drivers/core/device.c | 26 ++++++++++++++++++++++++++ include/dm/device-internal.h | 9 +++++++++ 2 files changed, 35 insertions(+) diff --git a/drivers/core/device.c b/drivers/core/device.c index a7408d9c76c6..f149d55ac1e1 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -267,6 +267,32 @@ int device_bind_by_name(struct udevice *parent, bool pre_reloc_only, devp); } +int device_reparent(struct udevice *dev, struct udevice *new_parent) +{ + struct udevice *cparent; + struct udevice *pos, *n; + + if (!dev || !new_parent) + return -EINVAL; + + if (!dev->parent) + return -ENODEV; + + list_for_each_entry_safe(pos, n, &dev->parent->child_head, + sibling_node) { + if (pos->driver != dev->driver) + continue; + + list_del(&dev->sibling_node); + list_add_tail(&dev->sibling_node, &new_parent->child_head); + dev->parent = new_parent; + + return 0; + } + + return -ENODEV; +} + static void *alloc_priv(int size, uint flags) { void *priv; diff --git a/include/dm/device-internal.h b/include/dm/device-internal.h index 294d6c18105a..c5d7ec0650f9 100644 --- a/include/dm/device-internal.h +++ b/include/dm/device-internal.h @@ -84,6 +84,15 @@ int device_bind_by_name(struct udevice *parent, bool pre_reloc_only, const struct driver_info *info, struct udevice **devp); /** + * device_reparent: reparent the device to a new parent + * + * @dev: pointer to device to be reparented + * @new_parent: pointer to new parent device + * @return 0 if OK, -ve on error + */ +int device_reparent(struct udevice *dev, struct udevice *new_parent); + +/** * device_ofdata_to_platdata() - Read platform data for a device * * Read platform data for a device (typically from the device tree) so that