From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from e31.co.us.ibm.com (e31.co.us.ibm.com [32.97.110.149]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "e31.co.us.ibm.com", Issuer "Equifax" (verified OK)) by ozlabs.org (Postfix) with ESMTP id 5FCA9DDDFC for ; Sun, 2 Mar 2008 10:50:37 +1100 (EST) Received: from d03relay04.boulder.ibm.com (d03relay04.boulder.ibm.com [9.17.195.106]) by e31.co.us.ibm.com (8.13.8/8.13.8) with ESMTP id m21NoYpr025997 for ; Sat, 1 Mar 2008 18:50:34 -0500 Received: from d03av02.boulder.ibm.com (d03av02.boulder.ibm.com [9.17.195.168]) by d03relay04.boulder.ibm.com (8.13.8/8.13.8/NCO v8.7) with ESMTP id m21NoYU3124792 for ; Sat, 1 Mar 2008 16:50:34 -0700 Received: from d03av02.boulder.ibm.com (loopback [127.0.0.1]) by d03av02.boulder.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id m21NoYJ9003009 for ; Sat, 1 Mar 2008 16:50:34 -0700 Date: Sat, 1 Mar 2008 17:48:25 -0600 From: Josh Boyer To: paulus@samba.org, sfr@canb.auug.org.au Subject: [RESEND] [PATCH 1/2 v2] [OF] Add of_device_is_available function Message-ID: <20080301174825.57715d46@zod.rchland.ibm.com> In-Reply-To: <20080301081600.74598ce4@zod.rchland.ibm.com> References: <20080301081600.74598ce4@zod.rchland.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Cc: linuxppc-dev@ozlabs.org List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , IEEE 1275 defined a standard "status" property to indicate the operational status of a device. The property has four possible values: okay, disabled, fail, fail-xxx. The absence of this property means the operational status of the device is unknown or okay. This adds a function called of_device_is_available that checks the state of the status property of a device. If the property is absent or set to either "okay" or "ok", it returns 1. Otherwise it returns 0. Signed-off-by: Josh Boyer --- drivers/of/base.c | 26 ++++++++++++++++++++++++++ include/linux/of.h | 1 + 2 files changed, 27 insertions(+) --- linux-2.6.orig/drivers/of/base.c +++ linux-2.6/drivers/of/base.c @@ -117,6 +117,32 @@ int of_device_is_compatible(const struct EXPORT_SYMBOL(of_device_is_compatible); /** + * of_device_is_available - check if a device is available for use + * + * @device: Node to check for availability + * + * Returns 1 if the status property is absent or set to "okay" or "ok", + * 0 otherwise + */ +int of_device_is_available(const struct device_node *device) +{ + const char *status; + int statlen; + + status = of_get_property(device, "status", &statlen); + if (status == NULL) + return 1; + + if (statlen > 0) { + if (!strncmp(status, "okay", 4) || !strncmp(status, "ok", 2)) + return 1; + } + + return 0; +} +EXPORT_SYMBOL(of_device_is_available); + +/** * of_get_parent - Get a node's parent if any * @node: Node to get parent * --- linux-2.6.orig/include/linux/of.h +++ linux-2.6/include/linux/of.h @@ -62,6 +62,7 @@ extern struct property *of_find_property int *lenp); extern int of_device_is_compatible(const struct device_node *device, const char *); +extern int of_device_is_available(const struct device_node *device); extern const void *of_get_property(const struct device_node *node, const char *name, int *lenp);