Received: by 10.223.176.46 with SMTP id f43csp969764wra; Wed, 24 Jan 2018 08:36:49 -0800 (PST) X-Google-Smtp-Source: AH8x226IlC0ccc2ZJKchC3FlBK3xO3yi1oleX5hdt6BsvvK0ZkLw+0qRjATyqsqvk2tGDvAVOehY X-Received: by 10.101.72.197 with SMTP id o5mr11730741pgs.64.1516811809168; Wed, 24 Jan 2018 08:36:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516811809; cv=none; d=google.com; s=arc-20160816; b=lh7rBc67PXFm8LvwxFmfNdIncrSnwe+vX6xp5TsuNNbpF5L41i2+I0i4VpUTJrpBBS LnxlVDJoSpaKtWLjxJEoAx7co9U0s+VsPZ5weBKsGF+2frDVFwAPLavT2x/H2OmxU5H0 hAPWQr0PGMEM73krjBEe3COHCPIBKvP+BLhjRxBclSGQr2hodlZg0gkIZ6J5Nid3/7Wr rWHFqjAevg9YAdQa6sxxu6TIi3BDGb2E9t29iD8MNpqz9WytekFqtQKoLgAEnSJc2xU9 Vex78W1IAGjSHQBAdtlHRmjudxjMoATJoky4ZkLmgZJvLqFoEoFw61pgA/WaqDTJIQrv dAYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:to:from:date:dkim-signature :arc-authentication-results; bh=Ozw4PnL02AGi73VZqqJ2Q62HxDscexpjHE8x2431dyU=; b=ymycfAQ03Jxrw0QEcIMTHD4nch2p47dpydgLpLzUP+HqepeUJhnpdju5p9qAKs+7ks WBgsYQSatwy9kyI3+hafXly3V7iLXSkXkFJQCfLa6zHTVS9oD50OY9+sw8o4x+dghiHI 3Vbrq4b0SBlHg2gaulz6RN6PKkVPLXtE0L7eqIb5/7KP3kwC8ggy3LFfqJkc487UT5l0 0PNwFwlrMunG+foqhFxqtdmTsv9/F7Qh43ol/zrV2mhIrbqtYqt0W3Bk1WDpFYvl4lWo NVUjU3/EVv7uQ1N7ObMHwsl9dnABwLKLYz8z0e5eSS67xWegFWnOOcgGv7lOqusAtgui Y3qQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=GcMnhnaR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b12si320810pgu.734.2018.01.24.08.36.35; Wed, 24 Jan 2018 08:36:49 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=GcMnhnaR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964956AbeAXQfk (ORCPT + 99 others); Wed, 24 Jan 2018 11:35:40 -0500 Received: from mail-pg0-f68.google.com ([74.125.83.68]:41303 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934274AbeAXQfh (ORCPT ); Wed, 24 Jan 2018 11:35:37 -0500 Received: by mail-pg0-f68.google.com with SMTP id 136so3060664pgd.8 for ; Wed, 24 Jan 2018 08:35:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=Ozw4PnL02AGi73VZqqJ2Q62HxDscexpjHE8x2431dyU=; b=GcMnhnaRamVRY2I3oMFVBRXJnQflBeu9vYB9Sjuidh23/oG5ecnoZ0COO0BYUVxcef ZphLJQkC0QI2QFcLSSx4Bf3uCS6EDH03ipMOE4DepCSIJZXyLs4pJ5aFPuDsmsrcTEbS XXJJUDQes2Md5jl9AgjE3LZVRF9n8RZudN+XxvemvN+pS1Ik7Ud/afHgB0pY00tgrgiJ f7POrl8SgO035FBh+CZLR0yyKFbhPxhgZHK14uoqYG0lSEyOBR+o67PWsiEWxoNnAP6N MfIzhsavY3MY8qVRSmeKmw6R5G1VNfCwwkbTOtmrS3SxpEtTRmfSSKBFp4DWIjr2CPAk 3Opg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=Ozw4PnL02AGi73VZqqJ2Q62HxDscexpjHE8x2431dyU=; b=LOeVYsQzVHnlQU14nRAJyhr5c0SJPnF9keFM2i6wTjM6r6caIZwyUt1UY2qgk5esGs yhWS4nWTUE5gU0ZZCf6DjILCag0xo0te4CAtHJrUIlfssmg8eFPnYGSswdnbtxQrNOPK PZ8e2wBDYJ7EtXfoMH1OY/SGUM9Y/YU0Vuld/SAfuH+wBScfGj0yVlm2uVWIpDt1GNTA no8LjVE3q3/AuFPE0xIsmIykxuWaFJVtionbyqHN0+AjoZO98PrJqMsEJy7+FxkDgPxh xv7US8yaARObUu2HhK+QMktQrMASHZmIa0UwAuHEpOmgyfv+kQ0+8CJpLIeTZ2E3YvT2 6V5Q== X-Gm-Message-State: AKwxyteaqFgGLbn9Aqcp3fv5arQkLl4aDREAUGaT5VQO2iXa0AT8rqiC cNhrZiHQ2Ty2LIwgQ7ZwRgM= X-Received: by 10.99.170.10 with SMTP id e10mr2059901pgf.81.1516811736897; Wed, 24 Jan 2018 08:35:36 -0800 (PST) Received: from raspberrypi ([122.172.61.122]) by smtp.gmail.com with ESMTPSA id 76sm10663876pfp.54.2018.01.24.08.35.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 24 Jan 2018 08:35:36 -0800 (PST) Date: Wed, 24 Jan 2018 16:35:30 +0000 From: Meghana Madhyastha To: Lee Jones , Daniel Thompson , Jingoo Han , Thierry Reding , Noralf =?iso-8859-1?Q?Tr=F8nnes?= , Tomi Valkeinen , Daniel Vetter , Sean Paul , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH v19 03/10] video: backlight: Add of_find_backlight helper in backlight.c Message-ID: <116d160ba78be2e6dcbdcb6855622bce67da9472.1516810725.git.meghana.madhyastha@gmail.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add of_find_backlight, a helper function which is a generic version of tinydrm_of_find_backlight that can be used by other drivers to avoid repetition of code and simplify things. Acked-by: Daniel Thompson Reviewed-by: Noralf Tr?nnes Reviewed-by: Sean Paul Signed-off-by: Meghana Madhyastha --- drivers/video/backlight/backlight.c | 43 +++++++++++++++++++++++++++++++++++++ include/linux/backlight.h | 19 ++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c index 8049e7656..553bf5c48 100644 --- a/drivers/video/backlight/backlight.c +++ b/drivers/video/backlight/backlight.c @@ -580,6 +580,49 @@ struct backlight_device *of_find_backlight_by_node(struct device_node *node) EXPORT_SYMBOL(of_find_backlight_by_node); #endif +/** + * of_find_backlight - Get backlight device + * @dev: Device + * + * This function looks for a property named 'backlight' on the DT node + * connected to @dev and looks up the backlight device. + * + * Call backlight_put() to drop the reference on the backlight device. + * + * Returns: + * A pointer to the backlight device if found. + * Error pointer -EPROBE_DEFER if the DT property is set, but no backlight + * device is found. + * NULL if there's no backlight property. + */ +struct backlight_device *of_find_backlight(struct device *dev) +{ + struct backlight_device *bd = NULL; + struct device_node *np; + + if (!dev) + return NULL; + + if (IS_ENABLED(CONFIG_OF) && dev->of_node) { + np = of_parse_phandle(dev->of_node, "backlight", 0); + if (np) { + bd = of_find_backlight_by_node(np); + of_node_put(np); + if (!bd) + return ERR_PTR(-EPROBE_DEFER); + /* + * Note: gpio_backlight uses brightness as + * power state during probe + */ + if (!bd->props.brightness) + bd->props.brightness = bd->props.max_brightness; + } + } + + return bd; +} +EXPORT_SYMBOL(of_find_backlight); + static void __exit backlight_class_exit(void) { class_destroy(backlight_class); diff --git a/include/linux/backlight.h b/include/linux/backlight.h index ace825e2c..ddc9bade4 100644 --- a/include/linux/backlight.h +++ b/include/linux/backlight.h @@ -162,6 +162,16 @@ static inline int backlight_disable(struct backlight_device *bd) return backlight_update_status(bd); } +/** + * backlight_put - Drop backlight reference + * @bd: the backlight device to put + */ +static inline void backlight_put(struct backlight_device *bd) +{ + if (bd) + put_device(&bd->dev); +} + extern struct backlight_device *backlight_device_register(const char *name, struct device *dev, void *devdata, const struct backlight_ops *ops, const struct backlight_properties *props); @@ -205,4 +215,13 @@ of_find_backlight_by_node(struct device_node *node) } #endif +#if IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE) +struct backlight_device *of_find_backlight(struct device *dev); +#else +static inline struct backlight_device *of_find_backlight(struct device *dev) +{ + return NULL; +} +#endif + #endif -- 2.11.0