From patchwork Tue Oct 14 05:41:50 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 399336 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 15737140140 for ; Tue, 14 Oct 2014 16:44:00 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 94A70A76EF; Tue, 14 Oct 2014 07:43:50 +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 8L+ooykJYNUQ; Tue, 14 Oct 2014 07:43:50 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 22742A751C; Tue, 14 Oct 2014 07:43:34 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id BCB8EA7429 for ; Tue, 14 Oct 2014 07:43:17 +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 YExfjnC39gca for ; Tue, 14 Oct 2014 07:43:17 +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-yh0-f73.google.com (mail-yh0-f73.google.com [209.85.213.73]) by theia.denx.de (Postfix) with ESMTPS id 4EA89A74CA for ; Tue, 14 Oct 2014 07:43:13 +0200 (CEST) Received: by mail-yh0-f73.google.com with SMTP id i57so770694yha.4 for ; Mon, 13 Oct 2014 22:43:12 -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=gKcmYPpa8NZ7RfqRnmjpj/BRarBbyHdr1hVz9ZlLNKw=; b=OROBrfMsGG7op9mKLBtjNemxIgbbWRUN3Y9Dm5TkYHuv7dTp7UJEwGiakhww4/LAVj 3nto3VFZr3ORxl4mWAP01J41eYVOD9PPoOcaRRJIQokZ2L7Xk9QT9T7qQtDV+DhG07lR dzjfuyZQ2Y+NC+TuThGSTZJ3ZEgbCxicktAnTQVvZtvRRDzJy83ToDbtoyhNwTnD3hFz XXc9+8MqIUhgS/TTkmW1ZbUWRjvVFoXuSGZoYJ2PrOBNPVsRJCvIYt3YZjc1sUrsvkdP iuPfI/pmgOWiJEHULCWRiLfMlRR+1idu6qud/vq/9qRfn5oNAz4vHH+ISI7UJduJebta 9RXg== X-Gm-Message-State: ALoCoQnQnyOCchBNUSzjoEag72urkI00bfRmyeHJDSOnKIJl1GIG9iYFsv6peuNodb2/9a4QDqZO X-Received: by 10.236.66.102 with SMTP id g66mr2184157yhd.3.1413265392406; Mon, 13 Oct 2014 22:43:12 -0700 (PDT) Received: from corpmail-nozzle1-1.hot.corp.google.com ([100.108.1.104]) by gmr-mx.google.com with ESMTPS id n63si807681yho.5.2014.10.13.22.43.11 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Oct 2014 22:43:12 -0700 (PDT) Received: from kaki.bld.corp.google.com ([172.29.216.32]) by corpmail-nozzle1-1.hot.corp.google.com with ESMTP id t4tbLax5.1; Mon, 13 Oct 2014 22:43:12 -0700 Received: by kaki.bld.corp.google.com (Postfix, from userid 121222) id 6C2AE220D31; Mon, 13 Oct 2014 23:43:11 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 13 Oct 2014 23:41:50 -0600 Message-Id: <1413265336-9571-4-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 2.1.0.rc2.206.gedb03e5 In-Reply-To: <1413265336-9571-1-git-send-email-sjg@chromium.org> References: <1413265336-9571-1-git-send-email-sjg@chromium.org> Cc: u-boot-review@google.com, Jagannadha Sutradharudu Teki Subject: [U-Boot] [PATCH v4 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 Acked-by: Jagannadha Sutradharudu Teki --- Changes in v4: None 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.