/
led.c
3339 lines (2798 loc) · 86.9 KB
1
2
3
4
/**
* @file led.c
* LED module -- this handles the LED logic for MCE
* <p>
5
6
7
* Copyright (c) 2006 - 2011 Nokia Corporation and/or its subsidiary(-ies).
* Copyright (c) 2012 - 2020 Jolla Ltd.
* Copyright (c) 2020 Open Mobile Platform LLC.
8
9
* <p>
* @author David Weinehall <david.weinehall@nokia.com>
10
11
12
13
14
15
* @author Tapio Rantala <ext-tapio.rantala@nokia.com>
* @author Santtu Lakkala <ext-santtu.1.lakkala@nokia.com>
* @author Jukka Turunen <ext-jukka.t.turunen@nokia.com>
* @author Simo Piiroinen <simo.piiroinen@jollamobile.com>
* @author Islam Amer <islam.amer@jollamobile.com>
* @author Filip Matijević <filip.matijevic.pz@gmail.com>
16
17
18
19
20
21
22
23
24
25
26
27
28
*
* mce is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License
* version 2.1 as published by the Free Software Foundation.
*
* mce is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with mce. If not, see <http://www.gnu.org/licenses/>.
*/
29
30
#include "led.h"
31
32
#include "../mce.h"
33
#include "../mce-log.h"
34
35
#include "../mce-io.h"
#include "../mce-lib.h"
36
#include "../mce-hal.h"
37
#include "../mce-conf.h"
38
#include "../mce-setting.h"
39
#include "../mce-dbus.h"
40
#include "../mce-hbtimer.h"
41
42
43
44
45
#ifdef ENABLE_HYBRIS
# include "../mce-hybris.h"
#endif
46
47
#include "../libwakelock.h"
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <linux/i2c.h>
#include <linux/i2c-dev.h>
#include <sys/time.h>
#include <sys/ioctl.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <mce/dbus-names.h>
61
#include <mce/mode-names.h>
62
63
64
#include <gmodule.h>
65
66
67
68
69
70
#if 0 // DEBUG: make all logging from this module "critical"
# undef mce_log
# define mce_log(LEV, FMT, ARGS...) \
mce_log_file(LL_CRIT, __FILE__, __FUNCTION__, FMT , ## ARGS)
#endif
71
72
73
74
75
76
77
78
79
80
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/** Module name */
#define MODULE_NAME "led"
/** Functionality provided by this module */
static const gchar *const provides[] = { MODULE_NAME, NULL };
/** Module information */
G_MODULE_EXPORT module_info_struct module_info = {
/** Name of the module */
.name = MODULE_NAME,
/** Module provides */
.provides = provides,
/** Module priority */
.priority = 100
};
/** The pattern queue */
static GQueue *pattern_stack = NULL;
/** The pattern combination rule queue */
static GQueue *combination_rule_list = NULL;
/** The pattern combination rule queue */
static GQueue *combination_rule_xref_list = NULL;
/** The D-Bus controlled LED switch */
static gboolean led_enabled = FALSE;
/** Fields in the patterns */
typedef enum {
/** Pattern priority field */
PATTERN_PRIO_FIELD = 0,
/** Pattern screen display policy field */
PATTERN_SCREEN_ON_FIELD = 1,
/** Pattern timeout field */
PATTERN_TIMEOUT_FIELD = 2,
/** On-period field for direct-controlled monochrome patterns */
PATTERN_ON_PERIOD_FIELD = 3,
/** R-channel pattern field for NJoy-controlled RGB patterns */
PATTERN_R_CHANNEL_FIELD = 3,
/** LED-muxing field for Lysti-controlled RGB patterns */
PATTERN_MUXING_FIELD = 3,
/**
* Engine channel field for Lysti-controlled monochrome patterns
* and NJoy-controlled monochrome patterns
*/
PATTERN_E_CHANNEL_FIELD = 3,
/** Number of fields used by Lysti-controlled monochrome patterns */
NUMBER_OF_PATTERN_FIELDS_LYSTI_MONO = 4,
/** Number of fields used by NJoy-controlled monochrome patterns */
NUMBER_OF_PATTERN_FIELDS_NJOY_MONO = 4,
/** Off-period field for direct-controlled monochrome patterns */
PATTERN_OFF_PERIOD_FIELD = 4,
/** G-channel pattern field for NJoy-controlled RGB patterns */
PATTERN_G_CHANNEL_FIELD = 4,
/** Engine channel 1 field for Lysti-controlled RGB patterns */
PATTERN_E1_CHANNEL_FIELD = 4,
/** Pattern brightness field for direct-controlled monochrome patterns */
PATTERN_BRIGHTNESS_FIELD = 5,
/** B-channel pattern field for NJoy-controlled RGB patterns */
PATTERN_B_CHANNEL_FIELD = 5,
/** Engine channel 2 field for Lysti-controlled RGB patterns */
PATTERN_E2_CHANNEL_FIELD = 5,
/**
* Number of fields used by Lysti-controlled RGB patterns,
* NJoy-controlled RGB patterns,
* and monochrome direct-controlled patterns
*/
NUMBER_OF_PATTERN_FIELDS = 6
} pattern_field;
/**
* Size of each LED channel
*
* Multiply the channel size by 2 since we store hexadecimal ASCII
*/
#define CHANNEL_SIZE 32 * 2
/** Structure holding LED patterns */
typedef struct {
gchar *name; /**< Pattern name */
gint priority; /**< Pattern priority */
gint policy; /**< Show pattern when screen is on? */
151
152
gint timeout; /**< Auto-deactivate timeout in seconds */
mce_hbtimer_t *timeout_id; /**< Timer for auto-deactivate */
153
154
155
156
157
158
159
160
161
162
163
164
165
gint on_period; /**< Pattern on-period in ms */
gint off_period; /**< Pattern off-period in ms */
gint brightness; /**< Pattern brightness */
gboolean active; /**< Is the pattern active? */
gboolean enabled; /**< Is the pattern enabled? */
guint engine1_mux; /**< Muxing for engine 1 */
guint engine2_mux; /**< Muxing for engine 2 */
/** Pattern for the R-channel/engine 1 */
gchar channel1[CHANNEL_SIZE + 1];
/** Pattern for the G-channel/engine 2 */
gchar channel2[CHANNEL_SIZE + 1];
/** Pattern for the B-channel */
gchar channel3[CHANNEL_SIZE + 1];
166
guint setting_id; /**< Callback ID for GConf entry */
167
guint rgb_color; /**< RGB24 data for libhybris use */
168
gboolean undecided; /**< Flag for policy=6 lock in */
169
170
171
172
173
174
175
176
177
178
179
180
} pattern_struct;
/** Pattern combination rule struct; this is also used for cross-referencing */
typedef struct {
/** Name of the combined pattern */
gchar *rulename;
/** List of pre-requisite patterns */
GQueue *pre_requisites;
} combination_rule_struct;
/** Pointer to the top pattern */
static pattern_struct *active_pattern = NULL;
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/** The active brightness */
static gint active_brightness = -1;
/** Currently driven leds */
static guint current_lysti_led_pattern = 0;
/** Brightness levels for the mono-LED */
static const gchar *const brightness_map[] = {
BRIGHTNESS_LEVEL_0,
BRIGHTNESS_LEVEL_1,
BRIGHTNESS_LEVEL_2,
BRIGHTNESS_LEVEL_3,
BRIGHTNESS_LEVEL_4,
BRIGHTNESS_LEVEL_5,
BRIGHTNESS_LEVEL_6,
BRIGHTNESS_LEVEL_7,
BRIGHTNESS_LEVEL_8,
BRIGHTNESS_LEVEL_9,
BRIGHTNESS_LEVEL_10,
BRIGHTNESS_LEVEL_11,
BRIGHTNESS_LEVEL_12,
BRIGHTNESS_LEVEL_13,
BRIGHTNESS_LEVEL_14,
BRIGHTNESS_LEVEL_15
};
/** LED type */
typedef enum {
/** LED type unset */
LED_TYPE_UNSET = -1,
/** No LED available */
LED_TYPE_NONE = 0,
/** Monochrome LED, direct LED control */
LED_TYPE_DIRECT_MONO = 1,
/** RGB LED, NJoy (LP5521) LED controller */
LED_TYPE_NJOY_RGB = 2,
/** Monochrome LED, NJoy (LP5521) LED controller */
LED_TYPE_NJOY_MONO = 3,
/** RGB LED, Lysti (LP5523) LED controller */
LED_TYPE_LYSTI_RGB = 4,
/** Monochrome LED, Lysti (LP5523) LED controller */
LED_TYPE_LYSTI_MONO = 5,
224
225
226
227
#ifdef ENABLE_HYBRIS
/** Android adaptation via libhybris */
LED_TYPE_HYBRIS = 6,
#endif
228
229
230
231
232
233
234
235
} led_type_t;
/**
* The configuration group containing the LED pattern
*/
static const gchar *led_pattern_group = NULL;
/** Path to monochrome/red channel LED current path */
236
237
static output_state_t led_current_rm_output =
{
238
239
240
.context = "led_current_rm",
.truncate_file = TRUE,
.close_on_exit = FALSE,
241
242
};
243
/** Path to green channel LED current path */
244
245
static output_state_t led_current_g_output =
{
246
247
248
.context = "led_current_g",
.truncate_file = TRUE,
.close_on_exit = FALSE,
249
250
};
251
/** Path to blue channel LED current path */
252
253
static output_state_t led_current_b_output =
{
254
255
256
.context = "led_current_b",
.truncate_file = TRUE,
.close_on_exit = FALSE,
257
};
258
259
/** Path to monochrome/red channel LED brightness path */
260
261
static output_state_t led_brightness_rm_output =
{
262
263
264
.context = "led_brightness_rm",
.truncate_file = TRUE,
.close_on_exit = FALSE,
265
266
};
267
/** Path to red channel LED brightness path */
268
269
static output_state_t led_brightness_g_output =
{
270
271
272
.context = "led_brightness_g",
.truncate_file = TRUE,
.close_on_exit = FALSE,
273
274
};
275
/** Path to blue channel LED brightness path */
276
277
static output_state_t led_brightness_b_output =
{
278
279
280
.context = "led_brightness_b",
.truncate_file = TRUE,
.close_on_exit = FALSE,
281
};
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
/** Path to engine 1 mode */
static gchar *engine1_mode_path = NULL;
/** Path to engine 2 mode */
static gchar *engine2_mode_path = NULL;
/** Path to engine 3 mode */
static gchar *engine3_mode_path = NULL;
/** Path to engine 1 load */
static gchar *engine1_load_path = NULL;
/** Path to engine 2 load */
static gchar *engine2_load_path = NULL;
/** Path to engine 3 load */
static gchar *engine3_load_path = NULL;
/** Path to engine 1 leds */
static gchar *engine1_leds_path = NULL;
/** Path to engine 2 leds */
static gchar *engine2_leds_path = NULL;
/** Path to engine 3 leds */
static gchar *engine3_leds_path = NULL;
304
/** Cached display state */
305
static display_state_t display_state_curr = MCE_DISPLAY_UNDEF;
306
307
/** Cached system state */
308
static system_state_t system_state = MCE_SYSTEM_STATE_UNDEF;
309
310
311
312
/** Cached led brightness */
static gint led_brightness = 0;
313
314
315
316
317
318
319
/** Maximum LED brightness
*
* The led_brightness_pipe is initialized to maximum_led_brightness
* value and never modified. There is an ALS based filter for
* led_brightness_pipe that converts the led brightness profile
* values [%] into 0 ... maximum_led_brightness range. The latter are
* then handled by the led_brightness_trigger() function below. */
320
321
static guint maximum_led_brightness = MAXIMUM_LYSTI_MONOCHROME_LED_CURRENT;
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
/* Function prototypes */
static void disable_reno (void);
static led_type_t get_led_type (void);
static gint queue_find (gconstpointer data, gconstpointer userdata);
static gint queue_prio_compare (gconstpointer entry1, gconstpointer entry2, gpointer userdata);
static void lysti_set_brightness (gint brightness);
static void njoy_set_brightness (gint brightness);
static void mono_set_brightness (gint brightness);
static void hybris_set_brightness (gint brightness);
static void lysti_disable_led (void);
static void njoy_disable_led (void);
static void mono_disable_led (void);
static void hybris_disable_led (void);
static void disable_led (void);
static pattern_struct *led_pattern_create (void);
static void led_pattern_delete (pattern_struct *self);
static void led_pattern_set_active (pattern_struct *self, gboolean active);
339
static bool led_pattern_should_breathe (const pattern_struct *self);
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
static bool led_pattern_can_breathe (const pattern_struct *self);
static gboolean led_pattern_timeout_cb (gpointer data);
static void lysti_program_led (const pattern_struct *const pattern);
static void njoy_program_led (const pattern_struct *const pattern);
static void mono_program_led (const pattern_struct *const pattern);
static void hybris_program_led (const pattern_struct *const pattern);
static void program_led (const pattern_struct *const pattern);
static void allow_sw_breathing (bool enable);
static void led_set_active_pattern (pattern_struct *pattern);
static gboolean display_off_p (display_state_t state);
static void led_update_active_pattern (void);
static pattern_struct *find_pattern_struct (const gchar *const name);
static void update_combination_rule (gpointer name, gpointer data);
static void update_combination_rules (const gchar *const name);
static void led_activate_pattern (const gchar *const name);
static void led_deactivate_pattern (const gchar *const name);
static void led_enable (void);
static void led_disable (void);
static void system_state_trigger (gconstpointer data);
static void get_monotime (struct timeval *tv);
static void type6_lock_in_cb (void *data, void *aptr);
static void type6_revert_cb (void *data, void *aptr);
static void type6_deactivate_cb (void *data, void *aptr);
static void led_pattern_op (GFunc cb);
364
365
static void user_activity_event_trigger (gconstpointer data);
static void display_state_curr_trigger (gconstpointer data);
366
367
368
static void led_brightness_trigger (gconstpointer data);
static void led_pattern_activate_trigger (gconstpointer data);
static void led_pattern_deactivate_trigger (gconstpointer data);
369
370
371
static gint setting_id_find (gconstpointer data, gconstpointer userdata);
static void led_setting_cb (GConfClient *const gcc, const guint id, GConfEntry *const entry, gpointer const data);
static gboolean pattern_get_enabled (const gchar *const patternname, guint *setting_id);
372
373
374
375
376
377
378
379
380
381
382
383
384
385
static gboolean led_activate_pattern_dbus_cb (DBusMessage *const msg);
static gboolean led_deactivate_pattern_dbus_cb (DBusMessage *const msg);
static gboolean led_enable_dbus_cb (DBusMessage *const msg);
static gboolean led_disable_dbus_cb (DBusMessage *const msg);
static gboolean init_combination_rules (void);
static gboolean init_lysti_patterns (void);
static gboolean init_njoy_patterns (void);
static gboolean init_mono_patterns (void);
static int list_compare_item (const void *a, const void *b);
static void list_remove_duplicates (gchar **list);
static gboolean list_includes_item (gchar **list, const gchar *elem);
static gboolean init_hybris_patterns (void);
static gboolean init_patterns (void);
static void sw_breathing_rethink (void);
386
static void sw_breathing_setting_cb (GConfClient *const gcc, const guint id, GConfEntry *const entry, gpointer const data);
387
388
389
390
391
392
393
394
395
static void sw_breathing_quit (void);
static void sw_breathing_init (void);
static void charger_state_trigger (gconstpointer data);
static void battery_level_trigger (gconstpointer data);
static void mce_led_init_dbus (void);
static void mce_led_quit_dbus (void);
G_MODULE_EXPORT const gchar *g_module_check_init (GModule *module);
G_MODULE_EXPORT void g_module_unload (GModule *module);
396
397
398
399
400
401
402
403
/**
* Disable the Reno LED controller
*/
static void disable_reno(void)
{
int fd;
404
405
406
407
408
409
410
411
412
if (access("/dev/i2c-0", F_OK) == 0) {
mce_log(LL_DEBUG, "Skipping Reno disable - suitable kernel detected");
/* Reset errno,
* to avoid false positives down the line
*/
errno = 0;
return;
}
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
mce_log(LL_DEBUG, "Disabling Reno");
if ((fd = open("/dev/i2c-1", O_RDWR)) == -1) {
mce_log(LL_CRIT, "Failed to open /dev/i2c-1; %s",
g_strerror(errno));
/* Reset errno,
* to avoid false positives down the line
*/
errno = 0;
goto EXIT;
}
if (ioctl(fd, I2C_SLAVE_FORCE, TWL5031_BCC) == -1) {
mce_log(LL_CRIT,
"ioctl() I2C_SLAVE_FORCE (%d) failed on `%s'; %s",
TWL5031_BCC, "/dev/i2c-1", g_strerror(errno));
/* Reset errno,
* to avoid false positives down the line
*/
errno = 0;
goto EXIT;
}
438
439
440
441
442
443
444
445
446
447
struct i2c_smbus_ioctl_data args;
union i2c_smbus_data data;
data.byte = LEDC_DISABLE;
args.read_write = I2C_SMBUS_WRITE;
args.command = LED_DRIVER_CTRL;
args.size = I2C_SMBUS_BYTE_DATA;
args.data = &data;
if (ioctl(fd, I2C_SMBUS, &args) == -1) {
448
mce_log(LL_ERR,
449
450
451
"ioctl() I2C_SMBUS (write LED_DRIVER_CTRL %d) failed on `%s'; %s",
LEDC_DISABLE, "/dev/i2c-1", g_strerror(errno));
errno = 0;
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
}
EXIT:
if (fd != -1) {
if (close(fd) == -1) {
mce_log(LL_ERR,
"Failed to close `%s': %s",
"/dev/i2c-1", g_strerror(errno));
/* Reset errno,
* to avoid false positives down the line
*/
errno = 0;
}
}
return;
}
/**
* Get the LED type
*
* @return The LED type
*/
static led_type_t get_led_type(void)
{
478
product_id_t product_id = PRODUCT_UNKNOWN;
479
480
481
482
483
484
static led_type_t led_type = LED_TYPE_UNSET;
/* If we have the LED type already, return it */
if (led_type != LED_TYPE_UNSET)
goto EXIT;
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
#ifdef ENABLE_HYBRIS
/* Use mce-plugin-libhybris if available */
if( mce_hybris_indicator_init() ) {
led_type = LED_TYPE_HYBRIS;
led_pattern_group = MCE_CONF_LED_PATTERN_HYBRIS_GROUP;
maximum_led_brightness = MAXIMUM_HYBRIS_LED_BRIGHTNESS;
goto DONE;
}
#endif
/* Otherwise use product id for determining led type */
product_id = get_product_id();
// FIXME: The code below is defunct as get_product_id()
// does not work without sysinfod.
501
/* First build the paths needed to check */
502
switch ( product_id ) {
503
504
505
506
507
508
509
case PRODUCT_RM716:
case PRODUCT_RM696:
led_type = LED_TYPE_NJOY_MONO;
led_pattern_group = MCE_CONF_LED_PATTERN_RM696_GROUP;
maximum_led_brightness = MAXIMUM_NJOY_MONOCHROME_LED_CURRENT;
/* Build paths */
510
511
led_current_rm_output.path = g_strconcat(MCE_LED_DIRECT_SYS_PATH, MCE_LED_LP5521_PREFIX, MCE_LED_CHANNEL0, MCE_LED_CURRENT_SUFFIX, NULL);
led_brightness_rm_output.path = g_strconcat(MCE_LED_DIRECT_SYS_PATH, MCE_LED_LP5521_PREFIX, MCE_LED_CHANNEL0, MCE_LED_BRIGHTNESS_SUFFIX, NULL);
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
engine1_mode_path = g_strconcat(MCE_LED_DIRECT_SYS_PATH, MCE_LED_LP5521_PREFIX, MCE_LED_CHANNEL0, MCE_LED_DEVICE, MCE_LED_ENGINE1, MCE_LED_MODE_SUFFIX, NULL);
engine2_mode_path = g_strconcat(MCE_LED_DIRECT_SYS_PATH, MCE_LED_LP5521_PREFIX, MCE_LED_CHANNEL0, MCE_LED_DEVICE, MCE_LED_ENGINE2, MCE_LED_MODE_SUFFIX, NULL);
engine3_mode_path = g_strconcat(MCE_LED_DIRECT_SYS_PATH, MCE_LED_LP5521_PREFIX, MCE_LED_CHANNEL0, MCE_LED_DEVICE, MCE_LED_ENGINE3, MCE_LED_MODE_SUFFIX, NULL);
/* We have 3 engines, but only 1 LED,
* so while we need to be able to set the mode of all
* engines (to disable the unused ones), we don't need
* to program them
*/
engine1_load_path = g_strconcat(MCE_LED_DIRECT_SYS_PATH, MCE_LED_LP5521_PREFIX, MCE_LED_CHANNEL0, MCE_LED_DEVICE, MCE_LED_ENGINE1, MCE_LED_LOAD_SUFFIX, NULL);
disable_reno();
break;
case PRODUCT_RM690:
case PRODUCT_RM680:
led_type = LED_TYPE_LYSTI_MONO;
led_pattern_group = MCE_CONF_LED_PATTERN_RM680_GROUP;
maximum_led_brightness = MAXIMUM_LYSTI_MONOCHROME_LED_CURRENT;
/* Build paths */
534
535
led_current_rm_output.path = g_strconcat(MCE_LED_DIRECT_SYS_PATH, MCE_LED_LP5523_PREFIX, MCE_LED_CHANNEL8, MCE_LED_CURRENT_SUFFIX, NULL);
led_brightness_rm_output.path = g_strconcat(MCE_LED_DIRECT_SYS_PATH, MCE_LED_LP5523_PREFIX, MCE_LED_CHANNEL8, MCE_LED_BRIGHTNESS_SUFFIX, NULL);
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
/* Engine 3 is used by keyboard backlight */
engine1_mode_path = g_strconcat(MCE_LED_DIRECT_SYS_PATH, MCE_LED_LP5523_PREFIX, MCE_LED_CHANNEL0, MCE_LED_DEVICE, MCE_LED_ENGINE1, MCE_LED_MODE_SUFFIX, NULL);
engine2_mode_path = g_strconcat(MCE_LED_DIRECT_SYS_PATH, MCE_LED_LP5523_PREFIX, MCE_LED_CHANNEL0, MCE_LED_DEVICE, MCE_LED_ENGINE2, MCE_LED_MODE_SUFFIX, NULL);
engine1_load_path = g_strconcat(MCE_LED_DIRECT_SYS_PATH, MCE_LED_LP5523_PREFIX, MCE_LED_CHANNEL0, MCE_LED_DEVICE, MCE_LED_ENGINE1, MCE_LED_LOAD_SUFFIX, NULL);
engine2_load_path = g_strconcat(MCE_LED_DIRECT_SYS_PATH, MCE_LED_LP5523_PREFIX, MCE_LED_CHANNEL0, MCE_LED_DEVICE, MCE_LED_ENGINE2, MCE_LED_LOAD_SUFFIX, NULL);
engine1_leds_path = g_strconcat(MCE_LED_DIRECT_SYS_PATH, MCE_LED_LP5523_PREFIX, MCE_LED_CHANNEL0, MCE_LED_DEVICE, MCE_LED_ENGINE1, MCE_LED_LEDS_SUFFIX, NULL);
engine2_leds_path = g_strconcat(MCE_LED_DIRECT_SYS_PATH, MCE_LED_LP5523_PREFIX, MCE_LED_CHANNEL0, MCE_LED_DEVICE, MCE_LED_ENGINE2, MCE_LED_LEDS_SUFFIX, NULL);
disable_reno();
break;
case PRODUCT_RX51:
led_type = LED_TYPE_LYSTI_RGB;
led_pattern_group = MCE_CONF_LED_PATTERN_RX51_GROUP;
maximum_led_brightness = MAXIMUM_LYSTI_RGB_LED_CURRENT;
/* Build paths */
556
557
558
559
560
561
led_current_rm_output.path = g_strconcat(MCE_LED_DIRECT_SYS_PATH, MCE_LED_LP5523_PREFIX, MCE_LED_CHANNEL0, MCE_LED_CURRENT_SUFFIX, NULL);
led_current_g_output.path = g_strconcat(MCE_LED_DIRECT_SYS_PATH, MCE_LED_LP5523_PREFIX, MCE_LED_CHANNEL1, MCE_LED_CURRENT_SUFFIX, NULL);
led_current_b_output.path = g_strconcat(MCE_LED_DIRECT_SYS_PATH, MCE_LED_LP5523_PREFIX, MCE_LED_CHANNEL2, MCE_LED_CURRENT_SUFFIX, NULL);
led_brightness_rm_output.path = g_strconcat(MCE_LED_DIRECT_SYS_PATH, MCE_LED_LP5523_PREFIX, MCE_LED_CHANNEL0, MCE_LED_BRIGHTNESS_SUFFIX, NULL);
led_brightness_g_output.path = g_strconcat(MCE_LED_DIRECT_SYS_PATH, MCE_LED_LP5523_PREFIX, MCE_LED_CHANNEL1, MCE_LED_BRIGHTNESS_SUFFIX, NULL);
led_brightness_b_output.path = g_strconcat(MCE_LED_DIRECT_SYS_PATH, MCE_LED_LP5523_PREFIX, MCE_LED_CHANNEL2, MCE_LED_BRIGHTNESS_SUFFIX, NULL);
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
engine1_mode_path = g_strconcat(MCE_LED_DIRECT_SYS_PATH, MCE_LED_LP5523_PREFIX, MCE_LED_CHANNEL0, MCE_LED_DEVICE, MCE_LED_ENGINE1, MCE_LED_MODE_SUFFIX, NULL);
engine2_mode_path = g_strconcat(MCE_LED_DIRECT_SYS_PATH, MCE_LED_LP5523_PREFIX, MCE_LED_CHANNEL0, MCE_LED_DEVICE, MCE_LED_ENGINE2, MCE_LED_MODE_SUFFIX, NULL);
engine3_mode_path = g_strconcat(MCE_LED_DIRECT_SYS_PATH, MCE_LED_LP5523_PREFIX, MCE_LED_CHANNEL0, MCE_LED_DEVICE, MCE_LED_ENGINE3, MCE_LED_MODE_SUFFIX, NULL);
engine1_load_path = g_strconcat(MCE_LED_DIRECT_SYS_PATH, MCE_LED_LP5523_PREFIX, MCE_LED_CHANNEL0, MCE_LED_DEVICE, MCE_LED_ENGINE1, MCE_LED_LOAD_SUFFIX, NULL);
engine2_load_path = g_strconcat(MCE_LED_DIRECT_SYS_PATH, MCE_LED_LP5523_PREFIX, MCE_LED_CHANNEL0, MCE_LED_DEVICE, MCE_LED_ENGINE2, MCE_LED_LOAD_SUFFIX, NULL);
engine3_load_path = g_strconcat(MCE_LED_DIRECT_SYS_PATH, MCE_LED_LP5523_PREFIX, MCE_LED_CHANNEL0, MCE_LED_DEVICE, MCE_LED_ENGINE3, MCE_LED_LOAD_SUFFIX, NULL);
engine1_leds_path = g_strconcat(MCE_LED_DIRECT_SYS_PATH, MCE_LED_LP5523_PREFIX, MCE_LED_CHANNEL0, MCE_LED_DEVICE, MCE_LED_ENGINE1, MCE_LED_LEDS_SUFFIX, NULL);
engine2_leds_path = g_strconcat(MCE_LED_DIRECT_SYS_PATH, MCE_LED_LP5523_PREFIX, MCE_LED_CHANNEL0, MCE_LED_DEVICE, MCE_LED_ENGINE2, MCE_LED_LEDS_SUFFIX, NULL);
engine3_leds_path = g_strconcat(MCE_LED_DIRECT_SYS_PATH, MCE_LED_LP5523_PREFIX, MCE_LED_CHANNEL0, MCE_LED_DEVICE, MCE_LED_ENGINE3, MCE_LED_LEDS_SUFFIX, NULL);
break;
case PRODUCT_RX44:
case PRODUCT_RX48:
led_type = LED_TYPE_NJOY_RGB;
maximum_led_brightness = MAXIMUM_NJOY_RGB_LED_CURRENT;
if (product_id == PRODUCT_RX48)
led_pattern_group = MCE_CONF_LED_PATTERN_RX48_GROUP;
else
led_pattern_group = MCE_CONF_LED_PATTERN_RX44_GROUP;
/* Build paths */
587
588
led_current_rm_output.path = g_strconcat(MCE_LED_DIRECT_SYS_PATH, MCE_LED_LP5521_PREFIX, MCE_LED_CHANNEL0, MCE_LED_CURRENT_SUFFIX, NULL);
led_brightness_rm_output.path = g_strconcat(MCE_LED_DIRECT_SYS_PATH, MCE_LED_LP5521_PREFIX, MCE_LED_CHANNEL0, MCE_LED_BRIGHTNESS_SUFFIX, NULL);
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
engine1_mode_path = g_strconcat(MCE_LED_DIRECT_SYS_PATH, MCE_LED_LP5521_PREFIX, MCE_LED_CHANNEL0, MCE_LED_DEVICE, MCE_LED_ENGINE1, MCE_LED_MODE_SUFFIX, NULL);
engine2_mode_path = g_strconcat(MCE_LED_DIRECT_SYS_PATH, MCE_LED_LP5521_PREFIX, MCE_LED_CHANNEL1, MCE_LED_DEVICE, MCE_LED_ENGINE2, MCE_LED_MODE_SUFFIX, NULL);
engine3_mode_path = g_strconcat(MCE_LED_DIRECT_SYS_PATH, MCE_LED_LP5521_PREFIX, MCE_LED_CHANNEL2, MCE_LED_DEVICE, MCE_LED_ENGINE3, MCE_LED_MODE_SUFFIX, NULL);
engine1_load_path = g_strconcat(MCE_LED_DIRECT_SYS_PATH, MCE_LED_LP5521_PREFIX, MCE_LED_CHANNEL0, MCE_LED_DEVICE, MCE_LED_ENGINE1, MCE_LED_LOAD_SUFFIX, NULL);
engine2_load_path = g_strconcat(MCE_LED_DIRECT_SYS_PATH, MCE_LED_LP5521_PREFIX, MCE_LED_CHANNEL1, MCE_LED_DEVICE, MCE_LED_ENGINE2, MCE_LED_LOAD_SUFFIX, NULL);
engine3_load_path = g_strconcat(MCE_LED_DIRECT_SYS_PATH, MCE_LED_LP5521_PREFIX, MCE_LED_CHANNEL2, MCE_LED_DEVICE, MCE_LED_ENGINE3, MCE_LED_LOAD_SUFFIX, NULL);
break;
case PRODUCT_RX34:
led_type = LED_TYPE_DIRECT_MONO;
led_pattern_group = MCE_CONF_LED_PATTERN_RX34_GROUP;
/* Build paths */
604
led_brightness_rm_output.path = g_strconcat(MCE_LED_DIRECT_SYS_PATH, MCE_LED_KEYPAD_PREFIX, MCE_LED_BRIGHTNESS_SUFFIX, NULL);
605
606
607
608
609
610
611
break;
default:
led_type = LED_TYPE_NONE;
break;
}
612
613
614
#ifdef ENABLE_HYBRIS
DONE:
#endif
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
mce_log(LL_DEBUG, "LED-type: %d", led_type);
EXIT:
return led_type;
}
/**
* Custom find function to get a particular entry in the pattern stack
*
* @param data The pattern_struct entry
* @param userdata The pattern name
* @return Less than, equal to, or greater than zero depending
* whether the name of the pattern struct pointed to by data
* is less than, equal to, or greater than entry2
*/
static gint queue_find(gconstpointer data, gconstpointer userdata) G_GNUC_PURE;
static gint queue_find(gconstpointer data, gconstpointer userdata)
{
pattern_struct *psp;
if (data == NULL || userdata == NULL)
return -1;
psp = (pattern_struct *)data;
if (psp->name == NULL)
return -1;
return strcmp(psp->name, (gchar *)userdata);
}
/**
* Custom compare function used for priority insertions
*
* @param entry1 Queue entry 1
* @param entry2 Queue entry 2
* @param userdata The pattern name
* @return Less than, equal to, or greater than zero depending
* whether the priority of entry1 is less than, equal to,
* or greater than the priority of entry2
*/
static gint queue_prio_compare(gconstpointer entry1,
gconstpointer entry2,
gpointer userdata) G_GNUC_PURE;
static gint queue_prio_compare(gconstpointer entry1,
gconstpointer entry2,
gpointer userdata)
{
pattern_struct *psp1 = (pattern_struct *)entry1;
pattern_struct *psp2 = (pattern_struct *)entry2;
(void)userdata;
return psp1->priority - psp2->priority;
}
/**
* Set Lysti-LED brightness
*
* @param brightness The brightness of the LED
* (0 - maximum_led_brightness),
676
677
* or -1 to adjust colour hues without changing brightness,
* and to reset brightness when the LED has been disabled
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
*/
static void lysti_set_brightness(gint brightness)
{
guint r_brightness = 0;
guint g_brightness = 0;
guint b_brightness = 0;
if (brightness < -1 || brightness > (gint)maximum_led_brightness) {
mce_log(LL_WARN, "Invalid brightness value %d", brightness);
return;
}
if (brightness != -1) {
if (active_brightness == brightness)
return;
active_brightness = brightness;
}
if ((current_lysti_led_pattern & MCE_LYSTI_RED_MASK_RX51) &&
(get_led_type() == LED_TYPE_LYSTI_RGB)) {
/* Red is on, tweaking is needed */
if ((current_lysti_led_pattern & MCE_LYSTI_GREEN_MASK_RX51) &&
(current_lysti_led_pattern & MCE_LYSTI_BLUE_MASK_RX51)) {
/* White */
r_brightness = (unsigned)active_brightness * 4;
r_brightness = (r_brightness < maximum_led_brightness) ? r_brightness : maximum_led_brightness;
g_brightness = r_brightness / 4;
b_brightness = r_brightness / 4;
} else if (current_lysti_led_pattern & MCE_LYSTI_GREEN_MASK_RX51) {
/* Orange */
r_brightness = (unsigned)active_brightness * 10;
r_brightness = (r_brightness < maximum_led_brightness) ? r_brightness : maximum_led_brightness;
g_brightness = r_brightness / 10;
b_brightness = 0;
} else {
/* Purple */
r_brightness = (unsigned)active_brightness * 4;
r_brightness = (r_brightness < maximum_led_brightness) ? r_brightness : maximum_led_brightness;
b_brightness = r_brightness / 4;
g_brightness = 0;
}
} else {
/* When red is not on, we use brightness as is */
r_brightness = (unsigned)active_brightness;
g_brightness = (unsigned)active_brightness;
b_brightness = (unsigned)active_brightness;
}
if (get_led_type() == LED_TYPE_LYSTI_MONO) {
/* If we have a monochrome LED only set one brightness */
729
mce_write_number_string_to_file(&led_current_rm_output, r_brightness);
730
731
732
733
734
735
mce_log(LL_DEBUG,
"Brightness set to %d",
active_brightness);
} else if (get_led_type() == LED_TYPE_LYSTI_RGB) {
/* If we have an RGB LED set the brightness for all channels */
736
737
738
mce_write_number_string_to_file(&led_current_rm_output, r_brightness);
mce_write_number_string_to_file(&led_current_g_output, g_brightness);
mce_write_number_string_to_file(&led_current_b_output, b_brightness);
739
740
741
742
743
744
745
746
747
748
749
mce_log(LL_DEBUG,
"Brightness set to %d (%d, %d, %d)",
active_brightness, r_brightness,
g_brightness, b_brightness);
}
}
/**
* Set NJoy-LED brightness
*
750
751
752
* @param brightness The brightness of the LED
* (0 - maximum_led_brightness),
* or -1 to reset brightness when the LED has been disabled
753
754
755
*/
static void njoy_set_brightness(gint brightness)
{
756
if (brightness < -1 || brightness > (gint)maximum_led_brightness) {
757
758
759
760
mce_log(LL_WARN, "Invalid brightness value %d", brightness);
return;
}
761
762
763
764
765
766
767
768
769
770
771
772
/* This is a bit questionable, but currently 696 does not have any
* use for brightness setting, it only causes unwanted LED
* turn-ons when used with ALS. Let zero brightnesses through to
* be a bit safer.
*/
if ((get_product_id() == PRODUCT_RM696) &&
((brightness > 0) ||
(brightness == -1 && active_brightness != 0))) {
mce_log(LL_DEBUG, "don't set useless brightness value %d", brightness);
return;
}
773
774
775
776
777
778
if (brightness != -1) {
if (active_brightness == brightness)
return;
active_brightness = brightness;
}
779
780
781
mce_write_number_string_to_file(&led_brightness_rm_output,
(unsigned)active_brightness);
782
783
mce_log(LL_DEBUG, "Brightness set to %d", active_brightness);
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
}
/**
* Set mono-LED brightness
*
* @param brightness The brightness of the LED (0-15)
*/
static void mono_set_brightness(gint brightness)
{
if (brightness < 0 || brightness > 15) {
mce_log(LL_WARN, "Invalid brightness value %d", brightness);
return;
}
if (active_brightness == brightness)
return;
active_brightness = brightness;
802
803
mce_write_string_to_file(led_brightness_rm_output.path,
brightness_map[brightness]);
804
805
806
807
mce_log(LL_DEBUG, "Brightness set to %d", brightness);
}
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
#ifdef ENABLE_HYBRIS
static void hybris_program_led(const pattern_struct *const pattern);
/**
* Set libhybris-LED brightness
*
* @param brightness The brightness of the LED
* (0 - maximum_led_brightness),
* or -1 to reset brightness when the LED has been disabled
*/
static void hybris_set_brightness(gint brightness)
{
if (brightness < -1 || brightness > (gint)maximum_led_brightness) {
mce_log(LL_WARN, "Invalid brightness value %d", brightness);
return;
}
if( active_brightness == brightness )
return;
if( brightness != -1 )
active_brightness = brightness;
mce_log(LL_DEBUG, "Brightness set to %d", active_brightness);
833
834
835
/* Scale from [1...100%] to [1...255] range */
brightness = mce_xlat_int(1,maximum_led_brightness, 1,255, brightness);
mce_hybris_indicator_set_brightness(brightness);
836
837
838
}
#endif /* ENABLE_HYBRIS */
839
840
841
842
843
844
/**
* Disable the Lysti-LED
*/
static void lysti_disable_led(void)
{
/* Disable engine 1 */
845
846
mce_write_string_to_file(engine1_mode_path,
MCE_LED_DISABLED_MODE);
847
848
849
if (get_led_type() == LED_TYPE_LYSTI_MONO) {
/* Turn off the led */
850
mce_write_number_string_to_file(&led_brightness_rm_output, 0);
851
852
} else if (get_led_type() == LED_TYPE_LYSTI_RGB) {
/* Disable engine 2 */
853
854
mce_write_string_to_file(engine2_mode_path,
MCE_LED_DISABLED_MODE);
855
856
/* Turn off all three leds */
857
858
859
mce_write_number_string_to_file(&led_brightness_rm_output, 0);
mce_write_number_string_to_file(&led_brightness_g_output, 0);
mce_write_number_string_to_file(&led_brightness_b_output, 0);
860
861
862
863
864
865
866
867
868
}
}
/**
* Disable the NJoy-LED
*/
static void njoy_disable_led(void)
{
/* Disable engine 1 */
869
870
mce_write_string_to_file(engine1_mode_path,
MCE_LED_DISABLED_MODE);
871
872
873
if (get_led_type() == LED_TYPE_NJOY_MONO) {
/* Turn off the led */
874
mce_write_number_string_to_file(&led_brightness_rm_output, 0);
875
876
} else if (get_led_type() == LED_TYPE_NJOY_RGB) {
/* Disable engine 2 */
877
878
mce_write_string_to_file(engine2_mode_path,
MCE_LED_DISABLED_MODE);
879
880
/* Disable engine 3 */
881
882
mce_write_string_to_file(engine3_mode_path,
MCE_LED_DISABLED_MODE);
883
884
/* Turn off all three leds */
885
886
887
mce_write_number_string_to_file(&led_brightness_rm_output, 0);
mce_write_number_string_to_file(&led_brightness_g_output, 0);
mce_write_number_string_to_file(&led_brightness_b_output, 0);
888
889
890
891
892
893
894
895
}
}
/**
* Disable the mono-LED
*/
static void mono_disable_led(void)
{
896
897
mce_write_string_to_file(MCE_LED_TRIGGER_PATH,
MCE_LED_TRIGGER_NONE);
898
899
900
mono_set_brightness(0);
}
901
902
903
904
905
906
907
908
909
#ifdef ENABLE_HYBRIS
/** Disable the libhybris-LED
*/
static void hybris_disable_led(void)
{
mce_hybris_indicator_set_pattern(0,0,0, 0,0);
}
#endif /* ENABLE_HYBRIS */
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
/**
* Disable the LED
*/
static void disable_led(void)
{
switch (get_led_type()) {
case LED_TYPE_LYSTI_RGB:
case LED_TYPE_LYSTI_MONO:
lysti_disable_led();
break;
case LED_TYPE_NJOY_RGB:
case LED_TYPE_NJOY_MONO:
njoy_disable_led();
break;
case LED_TYPE_DIRECT_MONO:
mono_disable_led();
break;
930
931
932
933
934
935
#ifdef ENABLE_HYBRIS
case LED_TYPE_HYBRIS:
hybris_disable_led();
break;
#endif
936
937
938
939
940
default:
break;
}
}
941
942
943
944
945
946
947
948
949
950
951
/** Allocate and initialize led pattern object
*
* @return initialzied led pattern object, or NULL
*/
static pattern_struct *led_pattern_create(void)
{
pattern_struct *self = g_slice_new0(pattern_struct);
if( !self )
goto EXIT;
952
953
954
self->name = 0;
self->timeout_id = 0;
self->setting_id = 0;
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
EXIT:
return self;
}
/** Destroy led pattern object
*
* @param initialzied led pattern object, or NULL
*/
static void led_pattern_delete(pattern_struct *self)
{
if( !self )
goto EXIT;
mce_hbtimer_delete(self->timeout_id);
970
mce_setting_notifier_remove(self->setting_id);
971
972
973
974
975
976
977
978
free(self->name);
g_slice_free(pattern_struct, self);
EXIT:
return;
}
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/** Setter for led pattern active property
*
* Apart from initialization to FALSE state, all active
* property changes must go through this function.
*
* If the active property actually changes and the pattern
* is not disabled an appropriate D-Bus signal is broadcast
* over the system bus.
*
* @param self pattern object
* @param active new value for active property
*/
static void led_pattern_set_active(pattern_struct *self, gboolean active)
{
DBusMessage *msg = NULL;
if( !self )
goto EXIT;
if( self->active == active )
goto EXIT;