From patchwork Wed Apr 13 07:32:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Lu X-Patchwork-Id: 8819081 Return-Path: X-Original-To: patchwork-linux-acpi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 7431BC0554 for ; Wed, 13 Apr 2016 07:33:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8430420154 for ; Wed, 13 Apr 2016 07:33:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7D21B2024F for ; Wed, 13 Apr 2016 07:32:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759899AbcDMHc4 (ORCPT ); Wed, 13 Apr 2016 03:32:56 -0400 Received: from mga02.intel.com ([134.134.136.20]:2058 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757911AbcDMHcz (ORCPT ); Wed, 13 Apr 2016 03:32:55 -0400 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga101.jf.intel.com with ESMTP; 13 Apr 2016 00:32:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,478,1455004800"; d="scan'208";a="783872392" Received: from aaronlu.sh.intel.com ([10.239.13.110]) by orsmga003.jf.intel.com with ESMTP; 13 Apr 2016 00:32:54 -0700 From: Aaron Lu To: Jingoo Han , Zhang Rui , "Rafael J. Wysocki" Cc: linux-fbdev@vger.kernel.org, linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org, srinivas.pandruvada@intel.com Subject: [PATCH 1/3] video / backlight: add two APIs for drivers to use Date: Wed, 13 Apr 2016 15:32:49 +0800 Message-Id: <1460532771-22779-2-git-send-email-aaron.lu@intel.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1460532771-22779-1-git-send-email-aaron.lu@intel.com> References: <1460532771-22779-1-git-send-email-aaron.lu@intel.com> Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP It is useful to get the backlight device's pointer and use it to set backlight in some cases(the following patch will make use of it) so add the two APIs and export them. Signed-off-by: Aaron Lu Acked-by: Jingoo Han --- drivers/video/backlight/backlight.c | 43 +++++++++++++++++++++++++------------ include/linux/backlight.h | 2 ++ 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c index bddc8b17a4d8..18901b9b1eb4 100644 --- a/drivers/video/backlight/backlight.c +++ b/drivers/video/backlight/backlight.c @@ -164,18 +164,10 @@ static ssize_t brightness_show(struct device *dev, return sprintf(buf, "%d\n", bd->props.brightness); } -static ssize_t brightness_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) +int backlight_device_set_brightness(struct backlight_device *bd, + unsigned long brightness) { - int rc; - struct backlight_device *bd = to_backlight_device(dev); - unsigned long brightness; - - rc = kstrtoul(buf, 0, &brightness); - if (rc) - return rc; - - rc = -ENXIO; + int rc = -ENXIO; mutex_lock(&bd->ops_lock); if (bd->ops) { @@ -185,7 +177,7 @@ static ssize_t brightness_store(struct device *dev, pr_debug("set brightness to %lu\n", brightness); bd->props.brightness = brightness; backlight_update_status(bd); - rc = count; + rc = 0; } } mutex_unlock(&bd->ops_lock); @@ -194,6 +186,23 @@ static ssize_t brightness_store(struct device *dev, return rc; } +EXPORT_SYMBOL(backlight_device_set_brightness); + +static ssize_t brightness_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + int rc; + struct backlight_device *bd = to_backlight_device(dev); + unsigned long brightness; + + rc = kstrtoul(buf, 0, &brightness); + if (rc) + return rc; + + rc = backlight_device_set_brightness(bd, brightness); + + return rc ? rc : count; +} static DEVICE_ATTR_RW(brightness); static ssize_t type_show(struct device *dev, struct device_attribute *attr, @@ -380,7 +389,7 @@ struct backlight_device *backlight_device_register(const char *name, } EXPORT_SYMBOL(backlight_device_register); -bool backlight_device_registered(enum backlight_type type) +struct backlight_device *backlight_device_get_by_type(enum backlight_type type) { bool found = false; struct backlight_device *bd; @@ -394,7 +403,13 @@ bool backlight_device_registered(enum backlight_type type) } mutex_unlock(&backlight_dev_list_mutex); - return found; + return found ? bd : NULL; +} +EXPORT_SYMBOL(backlight_device_get_by_type); + +bool backlight_device_registered(enum backlight_type type) +{ + return backlight_device_get_by_type(type) ? true : false; } EXPORT_SYMBOL(backlight_device_registered); diff --git a/include/linux/backlight.h b/include/linux/backlight.h index 1e7a69adbe6f..f46b88fa4a09 100644 --- a/include/linux/backlight.h +++ b/include/linux/backlight.h @@ -144,6 +144,8 @@ extern void backlight_force_update(struct backlight_device *bd, extern bool backlight_device_registered(enum backlight_type type); extern int backlight_register_notifier(struct notifier_block *nb); extern int backlight_unregister_notifier(struct notifier_block *nb); +extern struct backlight_device *backlight_device_get_by_type(enum backlight_type type); +extern int backlight_device_set_brightness(struct backlight_device *bd, unsigned long brightness); #define to_backlight_device(obj) container_of(obj, struct backlight_device, dev)