From patchwork Fri Feb 9 02:56:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kever Yang X-Patchwork-Id: 871189 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="YWpceS8q"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3zd08C2zVdz9sP1 for ; Fri, 9 Feb 2018 13:56:43 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id ED3C4C21EFE; Fri, 9 Feb 2018 02:56:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id B29AFC21D6A; Fri, 9 Feb 2018 02:56:36 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 6ED10C21D6A; Fri, 9 Feb 2018 02:56:35 +0000 (UTC) Received: from mail-pl0-f65.google.com (mail-pl0-f65.google.com [209.85.160.65]) by lists.denx.de (Postfix) with ESMTPS id C2C32C21C4F for ; Fri, 9 Feb 2018 02:56:34 +0000 (UTC) Received: by mail-pl0-f65.google.com with SMTP id j19so850713pll.2 for ; Thu, 08 Feb 2018 18:56:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=iB2TsV3ESSKhNYMj93ePwzA0T5ljCfpi8KHGUI6Mvv0=; b=YWpceS8qiYEllYKsFETbBtaK4bnG+rXceeKCWFGgAnFzjt3zdKfJS0Hw/lVBa/TZkv 7pnruQ48hnY10HRdR0tHGCHJDDXT9swu6LUkbhwGZE3Aw2Nuxx5nBQ84o+g2JSHJ/72p TMVZIZrWACAgWRoO9SSroUSoD1DjbO/Z+EBjjk9wBT62/Zi5cHU//YCmEpP9hiVzQ1wp CPqbYv52/xcFn0cWhtKJrYv2VuKmlUi6TPkFA+3GhbB/ZoW5iQoXGqNH62btTHAAs2UF BaLqVlyfYLOJIrnl/iSP7pOEugLpOiWa575woYr4c+zskcc/JPDF6GgAAZLI8R10aTwb K5ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=iB2TsV3ESSKhNYMj93ePwzA0T5ljCfpi8KHGUI6Mvv0=; b=TPhEO6I5QMHiZ64V9ObG/2ozdWcSuG4PrD8ND5OPpBLl6T7KZKdqcdlwGt/CS80EFd EifoaS5Yzwe4lu5VPONDBISyUVOVbSY7IXwjGybqkO7cgUIlhBmI/zpt6gSovoA1N0Lb WZZlL4NiB1A56tYA0Y1UcAECeTqQfHpymr+f1Um2GuvxX7yUHy1Bu0I19AgN8sclK1fu 7g+8gsuVCQlAjYyeyPuiNvIfpUoD/hhtHNTCqyTcAk0WdnL6fm96O/EPPhY37ynbTRmp gN7Vv6lTXdZB/D7EeSAuIW+feINPykYUHrDut9VqQT/Hsq+LB1tna/AhpT5EihhAyiJT C9BA== X-Gm-Message-State: APf1xPANjrG8ifiRZNC045Oj4/YMQYe6WKjPUP0mZBmZhOc6QprFsa1y hKcFuf+Vth7QJiOV4K72bjHXlA== X-Google-Smtp-Source: AH8x2247LkZa1F4MoEgRIPgdh/3T2Q6JqWRLfEZ8Rb+RzAG2Z2WN/NQa9assd3iy9o5lTMYZy0UvEg== X-Received: by 2002:a17:902:e65:: with SMTP id 92-v6mr1125320plw.148.1518144992821; Thu, 08 Feb 2018 18:56:32 -0800 (PST) Received: from localhost.localdomain ([103.29.142.67]) by smtp.gmail.com with ESMTPSA id b81sm6456721pfm.89.2018.02.08.18.56.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 08 Feb 2018 18:56:31 -0800 (PST) From: Kever Yang To: u-boot@lists.denx.de Date: Fri, 9 Feb 2018 10:56:23 +0800 Message-Id: <1518144984-22127-1-git-send-email-kever.yang@rock-chips.com> X-Mailer: git-send-email 1.9.1 Subject: [U-Boot] [PATCH v2 1/2] core: add uclass_get_device_by_phandle_id() api X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Add api for who can not get phandle from a device property. Signed-off-by: Kever Yang Reviewed-by: Philipp Tomsich --- Changes in v2: - use uint instead of int for phandle - address comment from Philipp drivers/core/uclass.c | 26 ++++++++++++++++++++++++++ include/dm/uclass.h | 16 ++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index f5e4067..274b833 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -443,6 +443,32 @@ int uclass_get_device_by_ofnode(enum uclass_id id, ofnode node, } #if CONFIG_IS_ENABLED(OF_CONTROL) +int uclass_get_device_by_phandle_id(enum uclass_id id, uint phandle_id, + struct udevice **devp) +{ + struct udevice *dev; + struct uclass *uc; + int ret; + + *devp = NULL; + ret = uclass_get(id, &uc); + if (ret) + return ret; + + list_for_each_entry(dev, &uc->dev_head, uclass_node) { + uint phandle; + + phandle = dev_read_phandle(dev); + + if (phandle == phandle_id) { + *devp = dev; + return uclass_get_device_tail(dev, ret, devp); + } + } + + return -ENODEV; +} + int uclass_get_device_by_phandle(enum uclass_id id, struct udevice *parent, const char *name, struct udevice **devp) { diff --git a/include/dm/uclass.h b/include/dm/uclass.h index 1818849..63cb6e9 100644 --- a/include/dm/uclass.h +++ b/include/dm/uclass.h @@ -203,6 +203,22 @@ int uclass_get_device_by_ofnode(enum uclass_id id, ofnode node, struct udevice **devp); /** + * uclass_get_device_by_phandle_id() - Get a uclass device by phandle id + * + * This searches the devices in the uclass for one with the given phandle id. + * + * The device is probed to activate it ready for use. + * + * @id: uclass ID to look up + * @phandle_id: the phandle id to look up + * @devp: Returns pointer to device (there is only one for each node) + * @return 0 if OK, -ENODEV if there is no device match the phandle, other + * -ve on error + */ +int uclass_get_device_by_phandle_id(enum uclass_id id, uint phandle_id, + struct udevice **devp); + +/** * uclass_get_device_by_phandle() - Get a uclass device by phandle * * This searches the devices in the uclass for one with the given phandle.