Blame view

include/linux/leds.h 6.09 KB
c72a1d608   Richard Purdie   [PATCH] LED: add ...
1
2
3
4
5
6
7
8
9
10
11
12
13
  /*
   * Driver model for leds and led triggers
   *
   * Copyright (C) 2005 John Lenz <lenz@cs.wisc.edu>
   * Copyright (C) 2005 Richard Purdie <rpurdie@openedhand.com>
   *
   * This program is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License version 2 as
   * published by the Free Software Foundation.
   *
   */
  #ifndef __LINUX_LEDS_H_INCLUDED
  #define __LINUX_LEDS_H_INCLUDED
af410fc13   Johannes Berg   [PATCH] make leds...
14
  #include <linux/list.h>
df96efd73   Yoichi Yuasa   leds: Add missing...
15
  #include <linux/spinlock.h>
dc47206e5   Richard Purdie   leds: Fix led tri...
16
  #include <linux/rwsem.h>
5ada28bf7   Johannes Berg   led-class: always...
17
  #include <linux/timer.h>
af410fc13   Johannes Berg   [PATCH] make leds...
18

c72a1d608   Richard Purdie   [PATCH] LED: add ...
19
  struct device;
c72a1d608   Richard Purdie   [PATCH] LED: add ...
20
21
22
23
24
  /*
   * LED Core
   */
  
  enum led_brightness {
fb5035dbb   Ben Dooks   [PATCH] leds: re-...
25
26
27
  	LED_OFF		= 0,
  	LED_HALF	= 127,
  	LED_FULL	= 255,
c72a1d608   Richard Purdie   [PATCH] LED: add ...
28
29
30
  };
  
  struct led_classdev {
fb5035dbb   Ben Dooks   [PATCH] leds: re-...
31
32
  	const char		*name;
  	int			 brightness;
1bd465e6b   Guennadi Liakhovetski   leds: allow led-d...
33
  	int			 max_brightness;
fb5035dbb   Ben Dooks   [PATCH] leds: re-...
34
  	int			 flags;
c72a1d608   Richard Purdie   [PATCH] LED: add ...
35

859cb7f2a   Richard Purdie   leds: Add suspend...
36
  	/* Lower 16 bits reflect status */
fb5035dbb   Ben Dooks   [PATCH] leds: re-...
37
  #define LED_SUSPENDED		(1 << 0)
859cb7f2a   Richard Purdie   leds: Add suspend...
38
39
  	/* Upper 16 bits reflect control information */
  #define LED_CORE_SUSPENDRESUME	(1 << 16)
c72a1d608   Richard Purdie   [PATCH] LED: add ...
40

fb5035dbb   Ben Dooks   [PATCH] leds: re-...
41
  	/* Set LED brightness level */
2e214e0fa   Richard Purdie   leds: Document th...
42
  	/* Must not sleep, use a workqueue if needed */
fb5035dbb   Ben Dooks   [PATCH] leds: re-...
43
44
  	void		(*brightness_set)(struct led_classdev *led_cdev,
  					  enum led_brightness brightness);
29d76dfa2   Henrique de Moraes Holschuh   leds: Add support...
45
46
  	/* Get LED brightness level */
  	enum led_brightness (*brightness_get)(struct led_classdev *led_cdev);
fb5035dbb   Ben Dooks   [PATCH] leds: re-...
47

5ada28bf7   Johannes Berg   led-class: always...
48
49
50
51
52
53
54
55
  	/*
  	 * Activate hardware accelerated blink, delays are in milliseconds
  	 * and if both are zero then a sensible default should be chosen.
  	 * The call should adjust the timings in that case and if it can't
  	 * match the values specified exactly.
  	 * Deactivate blinking again when the brightness is set to a fixed
  	 * value via the brightness_set() callback.
  	 */
4c79141d2   Márton Németh   leds: Add support...
56
57
58
  	int		(*blink_set)(struct led_classdev *led_cdev,
  				     unsigned long *delay_on,
  				     unsigned long *delay_off);
f8a7c6fe1   Richard Purdie   leds: Convert fro...
59
  	struct device		*dev;
fb5035dbb   Ben Dooks   [PATCH] leds: re-...
60
  	struct list_head	 node;			/* LED Device list */
781a54e76   Anton Vorontsov   leds: mark led_cl...
61
  	const char		*default_trigger;	/* Trigger to use */
c72a1d608   Richard Purdie   [PATCH] LED: add ...
62

5ada28bf7   Johannes Berg   led-class: always...
63
64
65
  	unsigned long		 blink_delay_on, blink_delay_off;
  	struct timer_list	 blink_timer;
  	int			 blink_brightness;
c3bc9956e   Richard Purdie   [PATCH] LED: add ...
66
  #ifdef CONFIG_LEDS_TRIGGERS
c3bc9956e   Richard Purdie   [PATCH] LED: add ...
67
  	/* Protects the trigger data below */
dc47206e5   Richard Purdie   leds: Fix led tri...
68
  	struct rw_semaphore	 trigger_lock;
c3bc9956e   Richard Purdie   [PATCH] LED: add ...
69

fb5035dbb   Ben Dooks   [PATCH] leds: re-...
70
71
72
  	struct led_trigger	*trigger;
  	struct list_head	 trig_list;
  	void			*trigger_data;
c3bc9956e   Richard Purdie   [PATCH] LED: add ...
73
  #endif
c72a1d608   Richard Purdie   [PATCH] LED: add ...
74
75
76
  };
  
  extern int led_classdev_register(struct device *parent,
fb5035dbb   Ben Dooks   [PATCH] leds: re-...
77
  				 struct led_classdev *led_cdev);
e2387d6c2   Wolfram Sang   leds: Make header...
78
  extern void led_classdev_unregister(struct led_classdev *led_cdev);
c72a1d608   Richard Purdie   [PATCH] LED: add ...
79
80
  extern void led_classdev_suspend(struct led_classdev *led_cdev);
  extern void led_classdev_resume(struct led_classdev *led_cdev);
5ada28bf7   Johannes Berg   led-class: always...
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
  /**
   * led_blink_set - set blinking with software fallback
   * @led_cdev: the LED to start blinking
   * @delay_on: the time it should be on (in ms)
   * @delay_off: the time it should ble off (in ms)
   *
   * This function makes the LED blink, attempting to use the
   * hardware acceleration if possible, but falling back to
   * software blinking if there is no hardware blinking or if
   * the LED refuses the passed values.
   *
   * Note that if software blinking is active, simply calling
   * led_cdev->brightness_set() will not stop the blinking,
   * use led_classdev_brightness_set() instead.
   */
  extern void led_blink_set(struct led_classdev *led_cdev,
  			  unsigned long *delay_on,
  			  unsigned long *delay_off);
  /**
   * led_brightness_set - set LED brightness
   * @led_cdev: the LED to set
   * @brightness: the brightness to set it to
   *
   * Set an LED's brightness, and, if necessary, cancel the
   * software blink timer that implements blinking when the
   * hardware doesn't.
   */
  extern void led_brightness_set(struct led_classdev *led_cdev,
  			       enum led_brightness brightness);
c3bc9956e   Richard Purdie   [PATCH] LED: add ...
110
111
112
113
114
115
116
117
118
  /*
   * LED Triggers
   */
  #ifdef CONFIG_LEDS_TRIGGERS
  
  #define TRIG_NAME_MAX 50
  
  struct led_trigger {
  	/* Trigger Properties */
fb5035dbb   Ben Dooks   [PATCH] leds: re-...
119
120
121
  	const char	 *name;
  	void		(*activate)(struct led_classdev *led_cdev);
  	void		(*deactivate)(struct led_classdev *led_cdev);
c3bc9956e   Richard Purdie   [PATCH] LED: add ...
122
123
  
  	/* LEDs under control by this trigger (for simple triggers) */
fb5035dbb   Ben Dooks   [PATCH] leds: re-...
124
125
  	rwlock_t	  leddev_list_lock;
  	struct list_head  led_cdevs;
c3bc9956e   Richard Purdie   [PATCH] LED: add ...
126
127
  
  	/* Link to next registered trigger */
fb5035dbb   Ben Dooks   [PATCH] leds: re-...
128
  	struct list_head  next_trig;
c3bc9956e   Richard Purdie   [PATCH] LED: add ...
129
130
131
132
133
134
135
136
137
138
139
140
141
142
  };
  
  /* Registration functions for complex triggers */
  extern int led_trigger_register(struct led_trigger *trigger);
  extern void led_trigger_unregister(struct led_trigger *trigger);
  
  /* Registration functions for simple triggers */
  #define DEFINE_LED_TRIGGER(x)		static struct led_trigger *x;
  #define DEFINE_LED_TRIGGER_GLOBAL(x)	struct led_trigger *x;
  extern void led_trigger_register_simple(const char *name,
  				struct led_trigger **trigger);
  extern void led_trigger_unregister_simple(struct led_trigger *trigger);
  extern void led_trigger_event(struct led_trigger *trigger,
  				enum led_brightness event);
0b9536c95   Vasily Khoruzhick   leds: Add ability...
143
144
145
  extern void led_trigger_blink(struct led_trigger *trigger,
  			      unsigned long *delay_on,
  			      unsigned long *delay_off);
c3bc9956e   Richard Purdie   [PATCH] LED: add ...
146
147
148
149
150
151
152
153
154
155
156
  
  #else
  
  /* Triggers aren't active - null macros */
  #define DEFINE_LED_TRIGGER(x)
  #define DEFINE_LED_TRIGGER_GLOBAL(x)
  #define led_trigger_register_simple(x, y) do {} while(0)
  #define led_trigger_unregister_simple(x) do {} while(0)
  #define led_trigger_event(x, y) do {} while(0)
  
  #endif
2bfb646cd   Richard Purdie   [PATCH] LED: Add ...
157
158
159
160
161
162
163
  
  /* Trigger specific functions */
  #ifdef CONFIG_LEDS_TRIGGER_IDE_DISK
  extern void ledtrig_ide_activity(void);
  #else
  #define ledtrig_ide_activity() do {} while(0)
  #endif
f46e9203d   Nate Case   leds: Add support...
164
165
166
167
168
  /*
   * Generic LED platform data for describing LED names and default triggers.
   */
  struct led_info {
  	const char	*name;
326bb8a5a   Trent Piepho   leds: Make defaul...
169
  	const char	*default_trigger;
f46e9203d   Nate Case   leds: Add support...
170
171
172
173
174
175
176
  	int		flags;
  };
  
  struct led_platform_data {
  	int		num_leds;
  	struct led_info	*leds;
  };
22e03f3b5   Raphael Assenat   leds: Add generic...
177
178
179
  /* For the leds-gpio driver */
  struct gpio_led {
  	const char *name;
326bb8a5a   Trent Piepho   leds: Make defaul...
180
  	const char *default_trigger;
22e03f3b5   Raphael Assenat   leds: Add generic...
181
  	unsigned 	gpio;
ed88bae69   Trent Piepho   leds: Add options...
182
183
184
185
  	unsigned	active_low : 1;
  	unsigned	retain_state_suspended : 1;
  	unsigned	default_state : 2;
  	/* default_state should be one of LEDS_GPIO_DEFSTATE_(ON|OFF|KEEP) */
22e03f3b5   Raphael Assenat   leds: Add generic...
186
  };
2146325df   Benjamin Herrenschmidt   leds: leds-gpio: ...
187
188
189
  #define LEDS_GPIO_DEFSTATE_OFF		0
  #define LEDS_GPIO_DEFSTATE_ON		1
  #define LEDS_GPIO_DEFSTATE_KEEP		2
22e03f3b5   Raphael Assenat   leds: Add generic...
190
191
192
  
  struct gpio_led_platform_data {
  	int 		num_leds;
9517f925f   Uwe Kleine-König   leds: make *struc...
193
  	const struct gpio_led *leds;
2146325df   Benjamin Herrenschmidt   leds: leds-gpio: ...
194
195
196
  
  #define GPIO_LED_NO_BLINK_LOW	0	/* No blink GPIO state low */
  #define GPIO_LED_NO_BLINK_HIGH	1	/* No blink GPIO state high */
9517f925f   Uwe Kleine-König   leds: make *struc...
197
  #define GPIO_LED_BLINK		2	/* Please, blink */
2146325df   Benjamin Herrenschmidt   leds: leds-gpio: ...
198
  	int		(*gpio_blink_set)(unsigned gpio, int state,
ca3259b36   Herbert Valerio Riedel   leds: enable supp...
199
200
  					unsigned long *delay_on,
  					unsigned long *delay_off);
22e03f3b5   Raphael Assenat   leds: Add generic...
201
  };
4440673a9   Uwe Kleine-König   leds: provide hel...
202
203
  struct platform_device *gpio_led_register_device(
  		int id, const struct gpio_led_platform_data *pdata);
22e03f3b5   Raphael Assenat   leds: Add generic...
204

c72a1d608   Richard Purdie   [PATCH] LED: add ...
205
  #endif		/* __LINUX_LEDS_H_INCLUDED */