Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965194AbbHKJxw (ORCPT ); Tue, 11 Aug 2015 05:53:52 -0400 Received: from mailout1.samsung.com ([203.254.224.24]:58769 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933788AbbHKJi3 (ORCPT ); Tue, 11 Aug 2015 05:38:29 -0400 X-AuditID: cbfee61a-f79a06d000005c6f-cc-55c9c294adb9 From: Jacek Anaszewski To: linux-leds@vger.kernel.org Cc: linux-kernel@vger.kernel.org, cooloney@gmail.com, rpurdie@rpsys.net, stsp@users.sourceforge.net, Jacek Anaszewski , Andrew Lunn , Sakari Ailus , Pavel Machek Subject: [PATCH/RFC v5 03/57] leds: Add led_set_brightness_sync to the public LED subsystem API Date: Tue, 11 Aug 2015 11:37:16 +0200 Message-id: <1439285890-27329-4-git-send-email-j.anaszewski@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1439285890-27329-1-git-send-email-j.anaszewski@samsung.com> References: <1439285890-27329-1-git-send-email-j.anaszewski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrLLMWRmVeSWpSXmKPExsVy+t9jQd0ph06GGrzZxGVx/u4hZoujOycy WfRefc5ocXnXHDaLrW/WMVrcPXWUzWL3rqesFp+2fGOy6OybxuLA6bFz1l12j3knAz127vjM 5LFn/g9Wj74tqxg9Vqz+zu7RdKqd1ePzJrkAjigum5TUnMyy1CJ9uwSujEML57AWHJKraLpw k7mBcYtkFyMHh4SAicSiX5pdjJxAppjEhXvr2boYuTiEBGYxSvTN7GCEcH4ySkw9tYAdpIpN wFDi54vXTCDNIgJyEjvPVILUMAv8Y5SY9eopG0iNsECixOwZr1hAbBYBVYm1H48xg9i8Ah4S q192MkMsVpCYM8kGJMwp4Clx/fkiRhBbCKjk+OwmtgmMvAsYGVYxSqQWJBcUJ6XnGuallusV J+YWl+al6yXn525iBAfiM6kdjAd3uR9iFOBgVOLhFfA8GSrEmlhWXJl7iFGCg1lJhLdwKlCI NyWxsiq1KD++qDQntfgQozQHi5I4r+yGzaFCAumJJanZqakFqUUwWSYOTqkGRrOmyK5AK/Fp Dps+TTr4+/m2W4J3OGftP6H7dL/fqkv3WvmNbRq676ru19hSKLw27j3zrh96DNov5kWeWlV4 puaffbbTiV+7ombunvSWo7ZoK1dwsJ6rcLeAyqfm5w8aHcuE+TtfzD18e4GtjW+9sfKKTXcu cpctXbB80VXtsB39+ze3fbzQuUmJpTgj0VCLuag4EQBPEjBpQAIAAA== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4037 Lines: 119 led_set_brightness_sync function was visible only internally to the LED subsystem. It is now being made publicly available since it has become apparent that this is a caller who should decide whether brightness is to be set in a synchronous or an asynchronous way. The function is modified to use brightness_set_nonblocking or brightness_set op if brightness_set_sync is not implemented. Eventually all LED subsystem drivers will be modfified to set brightness only in a synchronous way with use of brightness_set_nonblocking or brightness_set op (brightness_set_sync op will be removed). LED core will take care of delegating brightness_set op to the work queue task, if needed. Signed-off-by: Jacek Anaszewski Cc: Bryan Wu Cc: Andrew Lunn Cc: Sakari Ailus Cc: Pavel Machek Cc: Stas Sergeev --- drivers/leds/led-core.c | 25 +++++++++++++++++++++++++ drivers/leds/leds.h | 13 ------------- include/linux/leds.h | 15 +++++++++++++++ 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/drivers/leds/led-core.c b/drivers/leds/led-core.c index 549de7e..192071d 100644 --- a/drivers/leds/led-core.c +++ b/drivers/leds/led-core.c @@ -141,6 +141,31 @@ void led_set_brightness(struct led_classdev *led_cdev, } EXPORT_SYMBOL(led_set_brightness); +int led_set_brightness_sync(struct led_classdev *led_cdev, + enum led_brightness value) +{ + int ret = 0; + + led_cdev->brightness = min(value, led_cdev->max_brightness); + + if (led_cdev->flags & LED_SUSPENDED) + return 0; + + if (led_cdev->brightness_set_sync) + ret = led_cdev->brightness_set_sync(led_cdev, + led_cdev->brightness); + else if (led_cdev->brightness_set_nonblocking) + led_cdev->brightness_set_nonblocking(led_cdev, + led_cdev->brightness); + else if (led_cdev->brightness_set) + led_cdev->brightness_set(led_cdev, led_cdev->brightness); + else + ret = -EINVAL; + + return ret; +} +EXPORT_SYMBOL(led_set_brightness_sync); + int led_update_brightness(struct led_classdev *led_cdev) { int ret = 0; diff --git a/drivers/leds/leds.h b/drivers/leds/leds.h index bc89d7a..1c026c9 100644 --- a/drivers/leds/leds.h +++ b/drivers/leds/leds.h @@ -26,19 +26,6 @@ static inline void led_set_brightness_async(struct led_classdev *led_cdev, led_cdev->brightness_set(led_cdev, value); } -static inline int led_set_brightness_sync(struct led_classdev *led_cdev, - enum led_brightness value) -{ - int ret = 0; - - led_cdev->brightness = min(value, led_cdev->max_brightness); - - if (!(led_cdev->flags & LED_SUSPENDED)) - ret = led_cdev->brightness_set_sync(led_cdev, - led_cdev->brightness); - return ret; -} - static inline int led_get_brightness(struct led_classdev *led_cdev) { return led_cdev->brightness; diff --git a/include/linux/leds.h b/include/linux/leds.h index ac9efe1..0c3098ea 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -164,6 +164,21 @@ extern void led_blink_set_oneshot(struct led_classdev *led_cdev, */ extern void led_set_brightness(struct led_classdev *led_cdev, enum led_brightness brightness); + +/** + * led_set_brightness_sync - set LED brightness synchronously + * @led_cdev: the LED to set + * @brightness: the brightness to set it to + * + * Set an LED's brightness immediately. This function will block + * the caller for the time required for accessing device register, + * and it can sleep. + * + * Returns: 0 on success or negative error value on failure + */ +extern int led_set_brightness_sync(struct led_classdev *led_cdev, + enum led_brightness value); + /** * led_update_brightness - update LED brightness * @led_cdev: the LED to query -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/