From patchwork Mon Sep 29 19:35:00 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 394593 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 56FB3140111 for ; Tue, 30 Sep 2014 05:38:50 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id E35ACA7438; Mon, 29 Sep 2014 21:38:21 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id C9pePdMLY1R8; Mon, 29 Sep 2014 21:38:21 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id EF0A4A7439; Mon, 29 Sep 2014 21:37:56 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 079754B61F for ; Mon, 29 Sep 2014 21:37:33 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1A-ix3qyHcp5 for ; Mon, 29 Sep 2014 21:37:32 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-oi0-f74.google.com (mail-oi0-f74.google.com [209.85.218.74]) by theia.denx.de (Postfix) with ESMTPS id 699524B622 for ; Mon, 29 Sep 2014 21:37:27 +0200 (CEST) Received: by mail-oi0-f74.google.com with SMTP id u20so3586847oif.5 for ; Mon, 29 Sep 2014 12:37:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=G3sAdJLwt1m3ZfvFj4fwqt2iFjAcwSlPt56H+TXVGk0=; b=lwTnHOZ2qpCmtqxny6rlTUacPeWS5x2RMVfk8KkhraTPqbRl1W486mmWlLB2pCDuxu KLAzMEU/fj2n35Sk6JjGp0whtFrYka9ym0jF+rWokVtHow4pjWAl728ECur44yhHM9wy qOqVq9/vOMP3swdQAi5hWKYTZuWNOwOoiXTFYfw4T9rT+OcKWLXxv2bm7jyPtLAUxhlH Dl74fxNT4K5q7OVEn4Q8YU0crpUcciHQM6kgSDovOJyCMQly3W+lQuQKk59YCOYU76aR mYlwzh1csZ64/jP/EXkE/wZJ/dWBVyk3FgT3zQfz4pixW7VN9WZDY0n+99w9JP/Gx2z4 2M4g== X-Gm-Message-State: ALoCoQkrLpBvgmm1UMvF/8cxtjh/9WlyeDnr868RTGdqTZgPkQaLgeIq5vKgzsMVWK9DLZsgLWAz X-Received: by 10.43.155.134 with SMTP id li6mr38512510icc.3.1412019446785; Mon, 29 Sep 2014 12:37:26 -0700 (PDT) Received: from corpmail-nozzle1-2.hot.corp.google.com ([100.108.1.103]) by gmr-mx.google.com with ESMTPS id l45si773838yha.2.2014.09.29.12.37.26 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Sep 2014 12:37:26 -0700 (PDT) Received: from kaki.bld.corp.google.com ([172.29.216.32]) by corpmail-nozzle1-2.hot.corp.google.com with ESMTP id MZ0KdhT9.1; Mon, 29 Sep 2014 12:37:26 -0700 Received: by kaki.bld.corp.google.com (Postfix, from userid 121222) id 9507A220DC9; Mon, 29 Sep 2014 13:37:25 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 29 Sep 2014 13:35:00 -0600 Message-Id: <1412019326-6721-4-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 2.1.0.rc2.206.gedb03e5 In-Reply-To: <1412019326-6721-1-git-send-email-sjg@chromium.org> References: <1412019326-6721-1-git-send-email-sjg@chromium.org> Cc: u-boot-review@google.com, Jagannadha Sutradharudu Teki Subject: [U-Boot] [PATCH v3 03/29] dm: core: Allow parents to pass data to children during probe X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.13 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Buses sometimes want to pass data to their children when they are probed. For example, a SPI bus may want to tell the slave device about the chip select it is connected to. Add a new function to permit the parent data to be supplied to the child. Signed-off-by: Simon Glass --- Changes in v3: - Add new patch to allow parents to pass data to children during probe Changes in v2: None drivers/core/device.c | 9 ++++++++- include/dm/device-internal.h | 13 +++++++++++++ include/dm/device.h | 4 ++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/drivers/core/device.c b/drivers/core/device.c index 9538874..49faa29 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -232,7 +232,7 @@ static void device_free(struct udevice *dev) } } -int device_probe(struct udevice *dev) +int device_probe_child(struct udevice *dev, void *parent_priv) { struct driver *drv; int size = 0; @@ -282,6 +282,8 @@ int device_probe(struct udevice *dev) ret = -ENOMEM; goto fail; } + if (parent_priv) + memcpy(dev->parent_priv, parent_priv, size); } ret = device_probe(dev->parent); @@ -335,6 +337,11 @@ fail: return ret; } +int device_probe(struct udevice *dev) +{ + return device_probe_child(dev, NULL); +} + int device_remove(struct udevice *dev) { struct driver *drv; diff --git a/include/dm/device-internal.h b/include/dm/device-internal.h index 7005d03..44cb7ef 100644 --- a/include/dm/device-internal.h +++ b/include/dm/device-internal.h @@ -66,6 +66,19 @@ int device_bind_by_name(struct udevice *parent, bool pre_reloc_only, int device_probe(struct udevice *dev); /** + * device_probe() - Probe a child device, activating it + * + * Activate a device so that it is ready for use. All its parents are probed + * first. The child is provided with parent data if parent_priv is not NULL. + * + * @dev: Pointer to device to probe + * @parent_priv: Pointer to parent data. If non-NULL then this is provided to + * the child. + * @return 0 if OK, -ve on error + */ +int device_probe_child(struct udevice *dev, void *parent_priv); + +/** * device_remove() - Remove a device, de-activating it * * De-activate a device so that it is no longer ready for use. All its diff --git a/include/dm/device.h b/include/dm/device.h index 4d277db..c24707e 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -133,6 +133,10 @@ struct udevice_id { * @per_child_auto_alloc_size: Each device can hold private data owned by * its parent. If required this will be automatically allocated if this * value is non-zero. + * TODO(sjg@chromium.org): I'm considering dropping this, and just having + * device_probe_child() pass it in. So far the use case for allocating it + * is SPI, but I found that unsatisfactory. Since it is here I will leave it + * until things are clearer. * @ops: Driver-specific operations. This is typically a list of function * pointers defined by the driver, to implement driver functions required by * the uclass.