From patchwork Wed Mar 28 12:38:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Six X-Patchwork-Id: 892146 X-Patchwork-Delegate: mario.six@gdsys.cc 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; dmarc=none (p=none dis=none) header.from=gdsys.cc Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 40B6wB103Jz9s0R for ; Wed, 28 Mar 2018 23:42:17 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id A09D8C220F0; Wed, 28 Mar 2018 12:40:37 +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_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS 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 7B7DCC220B0; Wed, 28 Mar 2018 12:39:07 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id C0A5FC220A0; Wed, 28 Mar 2018 12:38:42 +0000 (UTC) Received: from smtprelay04.ispgateway.de (smtprelay04.ispgateway.de [80.67.31.27]) by lists.denx.de (Postfix) with ESMTPS id B4A5AC220B1 for ; Wed, 28 Mar 2018 12:38:38 +0000 (UTC) Received: from [87.191.40.34] (helo=bob3.testumgebung.local) by smtprelay04.ispgateway.de with esmtpa (Exim 4.90_1) (envelope-from ) id 1f1ALl-0004sA-AR; Wed, 28 Mar 2018 14:38:45 +0200 From: Mario Six To: U-Boot Mailing List , Simon Glass Date: Wed, 28 Mar 2018 14:38:25 +0200 Message-Id: <20180328123832.16401-1-mario.six@gdsys.cc> X-Mailer: git-send-email 2.11.0 X-Df-Sender: bWFyaW8uc2l4QGdkc3lzLmNj Subject: [U-Boot] [PATCH 1/8] core: Add uclass_{first,next}_device_compat 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" A lot of times one wants to cycle through the devices in a uclass, but only certain ones, especially ones identified by their compatibility string, and ignore all others (in the best case this procedure should not even activate the devices one is not interested in). Hence, we add a pair of functions similar to uclass_{first,next}_device, but taking a compatibility string as an additional argument, which cycle through the devices of a uclass that conform to this compatibility string. Signed-off-by: Mario Six --- drivers/core/uclass.c | 33 +++++++++++++++++++++++++++++++++ include/dm/uclass.h | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index 1aedaa08f0..19cec1e929 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -469,6 +469,23 @@ int uclass_get_device_by_phandle(enum uclass_id id, struct udevice *parent, } #endif +int uclass_first_device_compat(enum uclass_id id, struct udevice **devp, + const char *compat) +{ + struct udevice *dev; + int ret; + + *devp = NULL; + ret = uclass_find_first_device(id, &dev); + if (!dev) + return 0; + if (!device_is_compatible(dev, compat)) { + *devp = dev; + return uclass_next_device_compat(devp, compat); + } + return uclass_get_device_tail(dev, ret, devp); +} + int uclass_first_device(enum uclass_id id, struct udevice **devp) { struct udevice *dev; @@ -494,6 +511,22 @@ int uclass_first_device_err(enum uclass_id id, struct udevice **devp) return 0; } +int uclass_next_device_compat(struct udevice **devp, const char *compat) +{ + struct udevice *dev = *devp; + int ret; + + *devp = NULL; + ret = uclass_find_next_device(&dev); + if (!dev) + return 0; + if (!device_is_compatible(dev, compat)) { + *devp = dev; + return uclass_next_device_compat(devp, compat); + } + return uclass_get_device_tail(dev, ret, devp); +} + int uclass_next_device(struct udevice **devp) { struct udevice *dev = *devp; diff --git a/include/dm/uclass.h b/include/dm/uclass.h index 3a01abc239..0320f1fbee 100644 --- a/include/dm/uclass.h +++ b/include/dm/uclass.h @@ -260,6 +260,25 @@ int uclass_get_device_by_driver(enum uclass_id id, const struct driver *drv, */ int uclass_first_device(enum uclass_id id, struct udevice **devp); +/** + * uclass_first_device_compat() - Get the first device in a uclass compatible + * to a given compat string + * + * The device returned is probed if necessary, and ready for use. + * + * This function is useful to start iterating through a list of devices which + * are functioning correctly, can be probed, and are compatible with a certain + * compat string. + * + * @id: Uclass ID to look up + * @devp: Returns pointer to the first device in that uclass if no error + * occurred, or NULL if there is no first device, or an error occurred with + * that device. + * @compat: The compatible string the device has to adhere to + * @return 0 if OK (found or not found), other -ve on error + */ +int uclass_first_device_compat(enum uclass_id id, struct udevice **devp, const char *compat); + /** * uclass_first_device_err() - Get the first device in a uclass * @@ -286,6 +305,24 @@ int uclass_first_device_err(enum uclass_id id, struct udevice **devp); */ int uclass_next_device(struct udevice **devp); +/** + * uclass_next_device_compat() - Get the next device in a uclass compatible to + * a given compat string + * + * The device returned is probed if necessary, and ready for use + * + * This function is useful to start iterating through a list of devices which + * are functioning correctly, can be probed, and are compatible with a certain + * compat string. + * + * @devp: On entry, pointer to device to lookup. On exit, returns pointer + * to the next device in the uclass if no error occurred, or NULL if there is + * no next device, or an error occurred with that next device. + * @compat: The compatible string the device has to adhere to + * @return 0 if OK (found or not found), other -ve on error + */ +int uclass_next_device_compat(struct udevice **devp, const char *compat); + /** * uclass_first_device() - Get the first device in a uclass *