Received: by 10.223.176.46 with SMTP id f43csp2996929wra; Mon, 22 Jan 2018 06:53:21 -0800 (PST) X-Google-Smtp-Source: AH8x226v5GrXdj63yvAChuZLrMmDQM63a4aAsuSSZ60NvPB15EWmvlLnBUf7zoOib7VN+65/Z3c1 X-Received: by 2002:a17:902:d24:: with SMTP id 33-v6mr3775257plu.40.1516632801525; Mon, 22 Jan 2018 06:53:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516632801; cv=none; d=google.com; s=arc-20160816; b=usEOmXVFwlY+FizOgAQQJjD6YwPJJRzS3SBboeq3NXgFNYMEpF45BwMVyapU46VCeR DwgzRYXhkoVi7c0EwkOyVjF6vYAk6i1VbwxYXUj76gpqoIJ/LO//sdFyBtYxar68GuaQ VBcom2fHVQyZVowEAqxUofQM/e6elL+Rl0+ancevgBk/6wNwX/u2maRl7uwMw8W9BfBJ IwVypanoBSgEGUc2aZp1TEdehy6WDbeprWZsgZk3GR7KCv6U0lrAyI2oMw6kbLJ9j6sM yDPz2XT9jZpDEJV49JlxUVOFH2cr/IyYS2AjBCOfEF8/BOUpWtr0S0KwDJ0M5FTikYc8 FXjA== 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=baxk0GNem+jauXeg5eVLSoLG8POqNyE8kX42xV+o7FQ=; b=e5Y0KIIy5rlEJGi3LnmIc3JpuLJpv7PVyATHif5kZBKwSVvqq2DI1CpbsdCn/wpoup n3EpqUAHi8CEQQqZT2JGKl97v+KojMmZ4QQ8+orKlFhA9+dqd+3e3HtGvLxwrSSdpGlK Fpd4J4CgOponxs48rwP7KnjeGyeGdlIeQM/PmYyp3nlKDhGVOdyDEmd4aESnCQwaQiFt KY+tzyg6Kjp/e/C3mqRmxH+peCbJ+qUK8ZGgNaeO8iEmAZsqHcoPVDR4rF2eRwrsReXn HbxykrN0GH36Hwu5TT/yZzAASGfJGVLKYxj+YynRb/sAr4d7aoS+zchTzlyM57l8oJa4 eviQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=dvHeFSSw; 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 u12-v6si3561973plz.222.2018.01.22.06.53.07; Mon, 22 Jan 2018 06:53:21 -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=dvHeFSSw; 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 S1751191AbeAVOvK (ORCPT + 99 others); Mon, 22 Jan 2018 09:51:10 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:45453 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751020AbeAVOvJ (ORCPT ); Mon, 22 Jan 2018 09:51:09 -0500 Received: by mail-pg0-f66.google.com with SMTP id m136so319697pga.12 for ; Mon, 22 Jan 2018 06:51:09 -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=baxk0GNem+jauXeg5eVLSoLG8POqNyE8kX42xV+o7FQ=; b=dvHeFSSwxZPDqUvo50B2x/QgPYdvWLgqWc0m5RcF+3KgBP0LTXQ8hXBrnRQCLtbttE ENXHjvmAAwNaUp+obOg3oHUQ3a+Pz/kiHBxyaO/qXe41neV1MB9kBIDJ7MDqvXR/kUbA j2KEV+pdPZTTo1oVqtNLoWyEn54GcBU1CPZxSna+f2mz/2LVZOqqb7Mhcfut1o2Wc8GX 2QC9s+dbKx8mc9znahkdFAI96PdFniUpwL2QhOnIPoPXly8NodRcjmNWwiw4SOUROyEZ ZSPSxzzItQm6XT/dDq00xsTnc19IiZfld8/BLQysOGb8CFtdtmOeFQak7YmgqInWmBkI +NLw== 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=baxk0GNem+jauXeg5eVLSoLG8POqNyE8kX42xV+o7FQ=; b=NK6a+WwdvqABjraO1cHztYU7K6AfvHcbv+s3d2PR+DG2Ic0k9flMWFX/0slYjWEHoa i1BHmDn6/0/quP4RJtbRkxgN7o3WUa2M1vuuuKtKw3ZJsuQMIgU1FyOr8rYJViJesTQH i+iGu8nUvospjKm+cooCCRPRCEDlySogV5x1L+rB4r6Cl/e3sxGJh+aNNd2YQwuAUby3 Ni1S08/q0X4bZQspGMsU5hxDIznsU17v+qGpvkx0aVNUK7E1B92GwmVGYYPXR714Kl+z 3HFbZ4RuDTZryPgTX26942T8AP8HMsf9yWN34tZdlnr2BIdYCNzn0sEthsIpn5/cUPp7 BYEw== X-Gm-Message-State: AKwxytd7acaJ/wrqEIGypVma61gBJYdjuX3CKZDYUIDueLR0ZhAPznN4 xBp2xtGDl8SQZsKLisFyxD8= X-Received: by 2002:a17:902:40a:: with SMTP id 10-v6mr3742981ple.88.1516632668672; Mon, 22 Jan 2018 06:51:08 -0800 (PST) Received: from raspberrypi ([122.171.92.137]) by smtp.gmail.com with ESMTPSA id i9sm2093180pfi.154.2018.01.22.06.51.05 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 22 Jan 2018 06:51:07 -0800 (PST) Date: Mon, 22 Jan 2018 14:51:02 +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 v18 03/10] video: backlight: Add of_find_backlight helper in backlight.c Message-ID: <116d160ba78be2e6dcbdcb6855622bce67da9472.1516632388.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. Signed-off-by: Meghana Madhyastha --- Acked-by: Daniel Thompson Reviewed-by: Noralf Tr?nnes Reviewed-by: Sean Paul 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