Richard Purdie | c72a1d6 | 2006-03-31 02:31:04 -0800 | [diff] [blame] | 1 | /* |
| 2 | * LED Core |
| 3 | * |
| 4 | * Copyright 2005 Openedhand Ltd. |
| 5 | * |
| 6 | * Author: Richard Purdie <rpurdie@openedhand.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | * |
| 12 | */ |
| 13 | #ifndef __LEDS_H_INCLUDED |
| 14 | #define __LEDS_H_INCLUDED |
| 15 | |
Richard Purdie | f8a7c6f | 2007-07-08 23:19:31 +0100 | [diff] [blame] | 16 | #include <linux/device.h> |
Richard Purdie | 72f8da3 | 2007-12-31 23:09:44 +0000 | [diff] [blame] | 17 | #include <linux/rwsem.h> |
Richard Purdie | c72a1d6 | 2006-03-31 02:31:04 -0800 | [diff] [blame] | 18 | #include <linux/leds.h> |
| 19 | |
Jacek Anaszewski | 4d71a4a | 2014-11-14 02:50:18 -0800 | [diff] [blame] | 20 | static inline void led_set_brightness_async(struct led_classdev *led_cdev, |
Richard Purdie | c72a1d6 | 2006-03-31 02:31:04 -0800 | [diff] [blame] | 21 | enum led_brightness value) |
| 22 | { |
Gabriele Mazzotta | 56d06fd | 2014-12-23 10:59:23 -0800 | [diff] [blame^] | 23 | value = min(value, led_cdev->max_brightness); |
| 24 | led_cdev->brightness = value; |
Jacek Anaszewski | 4d71a4a | 2014-11-14 02:50:18 -0800 | [diff] [blame] | 25 | |
Richard Purdie | c72a1d6 | 2006-03-31 02:31:04 -0800 | [diff] [blame] | 26 | if (!(led_cdev->flags & LED_SUSPENDED)) |
| 27 | led_cdev->brightness_set(led_cdev, value); |
| 28 | } |
| 29 | |
Jacek Anaszewski | 4d71a4a | 2014-11-14 02:50:18 -0800 | [diff] [blame] | 30 | static inline int led_set_brightness_sync(struct led_classdev *led_cdev, |
| 31 | enum led_brightness value) |
| 32 | { |
| 33 | int ret = 0; |
| 34 | |
| 35 | led_cdev->brightness = min(value, led_cdev->max_brightness); |
| 36 | |
| 37 | if (!(led_cdev->flags & LED_SUSPENDED)) |
| 38 | ret = led_cdev->brightness_set_sync(led_cdev, |
| 39 | led_cdev->brightness); |
| 40 | return ret; |
| 41 | } |
| 42 | |
Németh Márton | 0013b23 | 2008-03-09 20:54:37 +0000 | [diff] [blame] | 43 | static inline int led_get_brightness(struct led_classdev *led_cdev) |
| 44 | { |
| 45 | return led_cdev->brightness; |
| 46 | } |
| 47 | |
Fabio Baltieri | d23a22a | 2012-08-15 21:44:34 +0800 | [diff] [blame] | 48 | void led_stop_software_blink(struct led_classdev *led_cdev); |
| 49 | |
Richard Purdie | 72f8da3 | 2007-12-31 23:09:44 +0000 | [diff] [blame] | 50 | extern struct rw_semaphore leds_list_lock; |
Richard Purdie | c72a1d6 | 2006-03-31 02:31:04 -0800 | [diff] [blame] | 51 | extern struct list_head leds_list; |
| 52 | |
Richard Purdie | c3bc995 | 2006-03-31 02:31:05 -0800 | [diff] [blame] | 53 | #ifdef CONFIG_LEDS_TRIGGERS |
| 54 | void led_trigger_set_default(struct led_classdev *led_cdev); |
| 55 | void led_trigger_set(struct led_classdev *led_cdev, |
| 56 | struct led_trigger *trigger); |
Németh Márton | 0013b23 | 2008-03-09 20:54:37 +0000 | [diff] [blame] | 57 | void led_trigger_remove(struct led_classdev *led_cdev); |
Esben Haabendal | fff26f8 | 2011-05-24 17:13:22 -0700 | [diff] [blame] | 58 | |
| 59 | static inline void *led_get_trigger_data(struct led_classdev *led_cdev) |
| 60 | { |
| 61 | return led_cdev->trigger_data; |
| 62 | } |
| 63 | |
Richard Purdie | c3bc995 | 2006-03-31 02:31:05 -0800 | [diff] [blame] | 64 | #else |
Németh Márton | 4d404fd | 2008-03-09 20:59:57 +0000 | [diff] [blame] | 65 | #define led_trigger_set_default(x) do {} while (0) |
| 66 | #define led_trigger_set(x, y) do {} while (0) |
| 67 | #define led_trigger_remove(x) do {} while (0) |
Esben Haabendal | fff26f8 | 2011-05-24 17:13:22 -0700 | [diff] [blame] | 68 | #define led_get_trigger_data(x) (NULL) |
Richard Purdie | c3bc995 | 2006-03-31 02:31:05 -0800 | [diff] [blame] | 69 | #endif |
| 70 | |
Richard Purdie | f8a7c6f | 2007-07-08 23:19:31 +0100 | [diff] [blame] | 71 | ssize_t led_trigger_store(struct device *dev, struct device_attribute *attr, |
| 72 | const char *buf, size_t count); |
| 73 | ssize_t led_trigger_show(struct device *dev, struct device_attribute *attr, |
| 74 | char *buf); |
Richard Purdie | c3bc995 | 2006-03-31 02:31:05 -0800 | [diff] [blame] | 75 | |
Richard Purdie | c72a1d6 | 2006-03-31 02:31:04 -0800 | [diff] [blame] | 76 | #endif /* __LEDS_H_INCLUDED */ |