From patchwork Fri Nov 9 14:04:38 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 1720701 Return-Path: X-Original-To: patchwork-linux-fbdev@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 1ACF8E0010 for ; Fri, 9 Nov 2012 14:05:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753615Ab2KIOE4 (ORCPT ); Fri, 9 Nov 2012 09:04:56 -0500 Received: from moutng.kundenserver.de ([212.227.17.9]:60297 "EHLO moutng.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753188Ab2KIOEx (ORCPT ); Fri, 9 Nov 2012 09:04:53 -0500 Received: from mailbox.adnet.avionic-design.de (mailbox.avionic-design.de [109.75.18.3]) by mrelayeu.kundenserver.de (node=mrbap2) with ESMTP (Nemesis) id 0MhO2U-1Tkf5G2l2g-00MAUX; Fri, 09 Nov 2012 15:04:40 +0100 Received: from localhost (localhost [127.0.0.1]) by mailbox.adnet.avionic-design.de (Postfix) with ESMTP id F16992A280F2; Fri, 9 Nov 2012 15:04:39 +0100 (CET) X-Virus-Scanned: amavisd-new at avionic-design.de Received: from mailbox.adnet.avionic-design.de ([127.0.0.1]) by localhost (mailbox.avionic-design.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id U8+DZ4YSTVKQ; Fri, 9 Nov 2012 15:04:38 +0100 (CET) Received: from mailman.adnet.avionic-design.de (mailman.adnet.avionic-design.de [172.20.31.172]) by mailbox.adnet.avionic-design.de (Postfix) with ESMTP id B71372A2802D; Fri, 9 Nov 2012 15:04:38 +0100 (CET) Received: from localhost (avionic-0098.adnet.avionic-design.de [172.20.31.233]) by mailman.adnet.avionic-design.de (Postfix) with ESMTP id 4C93110060C; Fri, 9 Nov 2012 15:04:34 +0100 (CET) From: Thierry Reding To: Richard Purdie , Florian Tobias Schandinat Cc: linux-fbdev@vger.kernel.org, devicetree-discuss@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH] backlight: Add of_find_backlight_by_node() function Date: Fri, 9 Nov 2012 15:04:38 +0100 Message-Id: <1352469878-4532-1-git-send-email-thierry.reding@avionic-design.de> X-Mailer: git-send-email 1.8.0 X-Provags-ID: V02:K0:0CF3TaqZbHuuaA5Of5bNs8B5Ct6Cjc63q4ZfrBMmFFS SDj5NzLAuwPiTmMkO4/k3o5FcXjRM4kqnZ02i1MzjR0x27CFI+ cr1XZaJYvIw7McUlA8ml/KgeDdTpyXfYtNBn0stFiiWu/b1jor jNbL4VnXuwYdn7ev3KHHtwteegZy7lrIfviXoR5ugBtgpj4Ae8 ucWqTHoCTgufq0KqYPuwU1uccuOp0v/Ee0NkJ3jaSOg2oNaT9d djlQ4OC2qsf1MPRYCRWcPrE+q0HT/sIM1xO3gdQj43Y80fERi4 zw2Tw5cKBAoBrFx+zzU3KAqzO7S0XUO/gfdZc5TiARCePJWDrn /CLcejudZPxeYyZRAELu51alqoND+TB8a9LdH0wmVPub0Te7m/ peuRuDyr+HlHUEcnlb/7NVMsIOveAht+Gy8lH+Un1DDJOpHFUn dwsh1 Sender: linux-fbdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org This function finds the struct backlight_device for a given device tree node. A dummy function is provided so that it safely compiles out if OF support is disabled. Signed-off-by: Thierry Reding Acked-by: Jingoo Han --- drivers/video/backlight/backlight.c | 17 +++++++++++++++++ include/linux/backlight.h | 10 ++++++++++ 2 files changed, 27 insertions(+) diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c index 297db2f..0d1ed4f 100644 --- a/drivers/video/backlight/backlight.c +++ b/drivers/video/backlight/backlight.c @@ -370,6 +370,23 @@ void backlight_device_unregister(struct backlight_device *bd) } EXPORT_SYMBOL(backlight_device_unregister); +#if IS_ENABLED(CONFIG_OF) +static int of_parent_match(struct device *dev, void *data) +{ + return dev->parent && dev->parent->of_node == data; +} + +struct backlight_device *of_find_backlight_by_node(struct device_node *node) +{ + struct device *dev; + + dev = class_find_device(backlight_class, NULL, node, of_parent_match); + + return dev ? to_backlight_device(dev) : NULL; +} +EXPORT_SYMBOL(of_find_backlight_by_node); +#endif + static void __exit backlight_class_exit(void) { class_destroy(backlight_class); diff --git a/include/linux/backlight.h b/include/linux/backlight.h index 5ffc6dd..11840e9 100644 --- a/include/linux/backlight.h +++ b/include/linux/backlight.h @@ -134,4 +134,14 @@ struct generic_bl_info { void (*kick_battery)(void); }; +#if IS_ENABLED(CONFIG_OF) +struct backlight_device *of_find_backlight_by_node(struct device_node *node); +#else +static inline struct backlight_device * +of_find_backlight_by_node(struct device_node *node) +{ + return NULL; +} +#endif + #endif