Skip to content

Commit f745a93

Browse files
Wenping Zhangrkhuangtao
authored andcommitted
leds: add multi-control for leds's trigger.
userspace can control all leds by one ioctl through file node: /dev/led_multi_ctrl. Change-Id: I10ac19b86b46b3dc9a88809f1be5ebc95398212c Signed-off-by: Wenping Zhang <wenping.zhang@rock-chips.com>
1 parent a0505a7 commit f745a93

6 files changed

Lines changed: 623 additions & 0 deletions

File tree

drivers/leds/led-triggers.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,26 @@ void led_trigger_set_default(struct led_classdev *led_cdev)
175175
}
176176
EXPORT_SYMBOL_GPL(led_trigger_set_default);
177177

178+
#ifdef CONFIG_LEDS_TRIGGER_MULTI_CTRL
179+
void led_trigger_set_by_name(struct led_classdev *led_cdev, char *trig_name)
180+
{
181+
struct led_trigger *trig;
182+
183+
if (!trig_name)
184+
return;
185+
186+
down_read(&triggers_list_lock);
187+
down_write(&led_cdev->trigger_lock);
188+
list_for_each_entry(trig, &trigger_list, next_trig) {
189+
if (!strcmp(trig_name, trig->name))
190+
led_trigger_set(led_cdev, trig);
191+
}
192+
up_write(&led_cdev->trigger_lock);
193+
up_read(&triggers_list_lock);
194+
}
195+
EXPORT_SYMBOL_GPL(led_trigger_set_by_name);
196+
#endif
197+
178198
void led_trigger_rename_static(const char *name, struct led_trigger *trig)
179199
{
180200
/* new name must be on a temporary string to prevent races */

drivers/leds/leds-multi.h

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* LED MULTI-CONTROL
3+
*
4+
* Copyright 2017 Allen Zhang <zwp@rock-chips.com>
5+
*
6+
* This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License version 2 as
8+
* published by the Free Software Foundation.
9+
*
10+
*/
11+
#ifndef __LEDS_MULTI_H_INCLUDED
12+
#define __LEDS_MULTI_H_INCLUDED
13+
14+
enum {
15+
TRIG_NONE = 0,
16+
TRIG_DEF_ON,
17+
TRIG_TIMER,
18+
TRIG_ONESHOT,
19+
TRIG_MAX,
20+
};
21+
22+
struct led_ctrl_data {
23+
u32 trigger;
24+
/* the delay time(ms) of triggering a trigger */
25+
u32 delayed_trigger_ms;
26+
u32 brightness;
27+
u32 delay_on;
28+
u32 delay_off;
29+
} __packed;
30+
31+
struct led_ctrl_scroll_data {
32+
u64 init_bitmap;
33+
/* the shift bits on every scrolling time*/
34+
u32 shifts;
35+
u32 shift_delay_ms;
36+
} __packed;
37+
38+
struct led_ctrl_breath_data {
39+
u64 background_bitmap;
40+
u64 breath_bitmap;
41+
u32 change_delay_ms;
42+
u32 breath_steps;
43+
} __packed;
44+
45+
#define MAX_LEDS_NUMBER 64
46+
47+
#define LEDS_MULTI_CTRL_IOCTL_MAGIC 'z'
48+
49+
#define LEDS_MULTI_CTRL_IOCTL_MULTI_SET \
50+
_IOW(LEDS_MULTI_CTRL_IOCTL_MAGIC, 0x01, struct led_ctrl_data*)
51+
#define LEDS_MULTI_CTRL_IOCTL_GET_LED_NUMBER \
52+
_IOR(LEDS_MULTI_CTRL_IOCTL_MAGIC, 0x02, int)
53+
#define LEDS_MULTI_CTRL_IOCTL_MULTI_SET_SCROLL \
54+
_IOW(LEDS_MULTI_CTRL_IOCTL_MAGIC, 0x03, struct led_ctrl_scroll_data*)
55+
#define LEDS_MULTI_CTRL_IOCTL_MULTI_SET_BREATH \
56+
_IOW(LEDS_MULTI_CTRL_IOCTL_MAGIC, 0x04, struct led_ctrl_breath_data*)
57+
58+
int led_multi_control_register(struct led_classdev *led_cdev);
59+
int led_multi_control_unregister(struct led_classdev *led_cdev);
60+
int led_multi_control_init(struct device *dev);
61+
int led_multi_control_exit(struct device *dev);
62+
63+
#endif /* __LEDS_MULTI_H_INCLUDED */

drivers/leds/leds.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,11 @@ void led_stop_software_blink(struct led_classdev *led_cdev);
5050
extern struct rw_semaphore leds_list_lock;
5151
extern struct list_head leds_list;
5252

53+
#ifdef CONFIG_LEDS_TRIGGER_MULTI_CTRL
54+
void led_trigger_set_by_name(struct led_classdev *led_cdev, char *trig_name);
55+
#else
56+
static inline void led_trigger_set_by_name(struct led_classdev *led_cdev,
57+
char *trig_name) {}
58+
#endif
59+
5360
#endif /* __LEDS_H_INCLUDED */

drivers/leds/trigger/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,10 @@ config LEDS_TRIGGER_CAMERA
108108
This enables direct flash/torch on/off by the driver, kernel space.
109109
If unsure, say Y.
110110

111+
config LEDS_TRIGGER_MULTI_CTRL
112+
tristate "LED Multi-Control Trigger"
113+
depends on LEDS_TRIGGERS && LEDS_TRIGGER_DEFAULT_ON && LEDS_TRIGGER_TIMER && LEDS_TRIGGER_ONESHOT
114+
help
115+
This allows userspace control all the leds at one time by ioctl operation.
116+
111117
endif # LEDS_TRIGGERS

drivers/leds/trigger/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ obj-$(CONFIG_LEDS_TRIGGER_CPU) += ledtrig-cpu.o
88
obj-$(CONFIG_LEDS_TRIGGER_DEFAULT_ON) += ledtrig-default-on.o
99
obj-$(CONFIG_LEDS_TRIGGER_TRANSIENT) += ledtrig-transient.o
1010
obj-$(CONFIG_LEDS_TRIGGER_CAMERA) += ledtrig-camera.o
11+
obj-$(CONFIG_LEDS_TRIGGER_MULTI_CTRL) += ledtrig-multi-control.o

0 commit comments

Comments
 (0)