From patchwork Mon Oct 13 05:39:27 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 399037 X-Patchwork-Delegate: hs@denx.de 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 552801400D5 for ; Mon, 13 Oct 2014 16:40:25 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id ED533A7858; Mon, 13 Oct 2014 07:40:20 +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 1pH99aooCF6T; Mon, 13 Oct 2014 07:40:20 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id F38F7A786D; Mon, 13 Oct 2014 07:40:16 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 64D88A785F for ; Mon, 13 Oct 2014 07:40:10 +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 MQ1N2MaOB4rk for ; Mon, 13 Oct 2014 07:40:10 +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-yk0-f201.google.com (mail-yk0-f201.google.com [209.85.160.201]) by theia.denx.de (Postfix) with ESMTPS id 0BEB8A7850 for ; Mon, 13 Oct 2014 07:40:06 +0200 (CEST) Received: by mail-yk0-f201.google.com with SMTP id 19so608738ykq.4 for ; Sun, 12 Oct 2014 22:40:05 -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=Lmt/Fg0xnAwBLVj/0Ocd3oj1twTrMJDgPBFf5bLC8CU=; b=a0rY1i/HRpLVWkawNV6jCKcT7Z6iVKEHDG4X+xsKI7MaZr/cPy0Aobpcy6eX2BMwWl 9Kbm7+6KtoemboTCwzmgyFMddKLhQ4pRAK2NZ7ZsV2z7Csq3sDb3X/gPHHXjq8UJ9g9A hWgM2Ab1UzDpfP9Vg4O+5qt/syI/f/izyo+32Fi90duEg5yhv0b92ErSTLYvYiUsXEaA 3HRXil4rh0fUZe9Z0BcljM3f8qTWl0ylmjbSdPNOusSqjQgzqcw5TwHkoq0M0CSLPAPQ YuXt9ryBZM3oTdiLL7bjhRNin6kYe1kTKgWpd/9tzY1CnfPmhp50g2TIiwI60PIUqQUl 7/gw== X-Gm-Message-State: ALoCoQnht/nA8H7xvGG9QDX9GPeK1Wn+ymVzkYCgXDRtpoc08RoFJPbSqZUav+zxnwTVNPWv5+0T X-Received: by 10.236.25.99 with SMTP id y63mr9282636yhy.50.1413178804977; Sun, 12 Oct 2014 22:40:04 -0700 (PDT) Received: from corpmail-nozzle1-2.hot.corp.google.com ([100.108.1.103]) by gmr-mx.google.com with ESMTPS id n63si676503yho.5.2014.10.12.22.40.04 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 Oct 2014 22:40:04 -0700 (PDT) Received: from kaki.bld.corp.google.com ([172.29.216.32]) by corpmail-nozzle1-2.hot.corp.google.com with ESMTP id nswvEAms.1; Sun, 12 Oct 2014 22:40:04 -0700 Received: by kaki.bld.corp.google.com (Postfix, from userid 121222) id 3EBF422086F; Sun, 12 Oct 2014 23:40:04 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Sun, 12 Oct 2014 23:39:27 -0600 Message-Id: <1413178778-30846-2-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 2.1.0.rc2.206.gedb03e5 In-Reply-To: <1413178778-30846-1-git-send-email-sjg@chromium.org> References: <1413178778-30846-1-git-send-email-sjg@chromium.org> Cc: u-boot-review@google.com Subject: [U-Boot] [RFC PATCH 01/12] dm: core: Allow access to the device's driver_id data 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 When the device is created from a device tree node, it matches a compatible string. Allow access to that string and the associated data. Signed-off-by: Simon Glass --- drivers/core/device.c | 5 +++++ drivers/core/lists.c | 17 ++++++++++++----- include/dm/device.h | 11 +++++++++++ 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/drivers/core/device.c b/drivers/core/device.c index 49faa29..0d84776 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -548,3 +548,8 @@ int device_find_next_child(struct udevice **devp) return 0; } + +ulong dev_get_of_data(struct udevice *dev) +{ + return dev->of_id->data; +} diff --git a/drivers/core/lists.c b/drivers/core/lists.c index 699f94b..f170ae7 100644 --- a/drivers/core/lists.c +++ b/drivers/core/lists.c @@ -96,22 +96,26 @@ int lists_bind_drivers(struct udevice *parent, bool pre_reloc_only) * tree error */ static int driver_check_compatible(const void *blob, int offset, - const struct udevice_id *of_match) + const struct udevice_id *of_match, + const struct udevice_id **of_idp) { int ret; + *of_idp = NULL; if (!of_match) return -ENOENT; while (of_match->compatible) { ret = fdt_node_check_compatible(blob, offset, of_match->compatible); - if (!ret) + if (!ret) { + *of_idp = of_match; return 0; - else if (ret == -FDT_ERR_NOTFOUND) + } else if (ret == -FDT_ERR_NOTFOUND) { return -ENODEV; - else if (ret < 0) + } else if (ret < 0) { return -EINVAL; + } of_match++; } @@ -123,6 +127,7 @@ int lists_bind_fdt(struct udevice *parent, const void *blob, int offset, { struct driver *driver = ll_entry_start(struct driver, driver); const int n_ents = ll_entry_count(struct driver, driver); + const struct udevice_id *id; struct driver *entry; struct udevice *dev; bool found = false; @@ -134,7 +139,8 @@ int lists_bind_fdt(struct udevice *parent, const void *blob, int offset, if (devp) *devp = NULL; for (entry = driver; entry != driver + n_ents; entry++) { - ret = driver_check_compatible(blob, offset, entry->of_match); + ret = driver_check_compatible(blob, offset, entry->of_match, + &id); name = fdt_get_name(blob, offset, NULL); if (ret == -ENOENT) { continue; @@ -154,6 +160,7 @@ int lists_bind_fdt(struct udevice *parent, const void *blob, int offset, dm_warn("Error binding driver '%s'\n", entry->name); return ret; } else { + dev->of_id = id; found = true; if (devp) *devp = dev; diff --git a/include/dm/device.h b/include/dm/device.h index b8d4e7a..a712156 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -47,6 +47,7 @@ struct driver_info; * @name: Name of device, typically the FDT node name * @platdata: Configuration data for this device * @of_offset: Device tree node offset for this device (- for none) + * @of_id: Pointer to the udevice_id structure which created the device * @parent: Parent of this device, or NULL for the top level device * @priv: Private data for this device * @uclass: Pointer to uclass for this device @@ -65,6 +66,7 @@ struct udevice { const char *name; void *platdata; int of_offset; + const struct udevice_id *of_id; struct udevice *parent; void *priv; struct uclass *uclass; @@ -200,6 +202,15 @@ void *dev_get_parentdata(struct udevice *dev); void *dev_get_priv(struct udevice *dev); /** + * dev_get_of_data() - get the device tree data used to bind a device + * + * When a device is bound using a device tree node, it matches a + * particular compatible string as in struct udevice_id. This function + * returns the associated data value for that compatible string + */ +ulong dev_get_of_data(struct udevice *dev); + +/** * device_get_child() - Get the child of a device by index * * Returns the numbered child, 0 being the first. This does not use