mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-31 04:01:48 -04:00
LEDs for 4.11
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
iQIcBAABCAAGBQJYq0qJAAoJEL1qUBy3i3wmPCgP/3XMatJDziwedPfs1qZXNXPM
LLFGsmCtSC79TXyWYg9jgDoLKbt2G8Rb1KAvfhhPd7H/HRQD0YjwEHEzYv6BYE7O
yns6t1ea1pZUGtqwPjSwvVybdZZgOsDI8T6OxIv2Tj7m4sI9w26undFPnWF7dIyG
Kv14fLncXh1q4iwaXSfjFokI3V+o1xUH/fvLaLQ7w0EgbQn6VTgdn+fJr6aM1LH5
tcMyBnmaRg4D++erXPeqYxhRtG+Fn3NGolFjDWAXAxyxooVcyD9zJpdx65I2T03U
eVUI7gIpB/niOnskVTwJsd/hKI/aow3lDU+tRWgZvicuM6Sj7GI1zKuVU13aoKFw
TwcAnEE7oQJFuU4AmbDlHjso31cWcOOStKNFQXjOP1qbU6O5Q3SWaYET5cWaUNWM
hanY/hoU3U40x7m64HM67TT6frz6jEbNorY/bUvVX+JHrJcKTFFReBeIMgrIT/St
0wZNHptYeOjkLHB+jURgnBVm6bTc4DJjtjnCTFQ/kOOiPgo6CikXFzzBzJHgPI9L
/NfOsT13v2R6BJlvHgjNqIbj1gRCFHSYGloI5PBWAG5hk5z38GcJPlqvWxCQWOXs
NSfzLPUiavkfOW1U/OQTNHeeDZXKBuWMui1QlpTX3XkGPviDwtoGxezzgSAltdMo
LxIt/v0G4q5xJV3nDR19
=amlj
-----END PGP SIGNATURE-----
Merge tag 'leds_for_4.11' of git://git.kernel.org/pub/scm/linux/kernel/git/j.anaszewski/linux-leds
Pull LED updates from Jacek Anaszewski:
"New features and improvements:
- add new optional brightness_hw_changed attribute for the LEDs that
may have their brightness level changed autonomously (outside of
kernel control) by hardware / firmware. The attribute supports
userspace notifications through POLLPRI events
- add led_brightness_hw_mon tool that demonstrates how to use the
aforementioned feature
- add LED_ON enum for LEDs that can be only turned on/off, and don't
allow setting other brightness levels
- allow for adjusting heartbeat trigger blink brightness level
Fixes and cleanups:
- avoid harmless maybe-uninitialized warning in leds-ktd2692.c
- add context to the existing example entries in common LED bindings
to make the documentation more clear"
* tag 'leds_for_4.11' of git://git.kernel.org/pub/scm/linux/kernel/git/j.anaszewski/linux-leds:
leds: ledtrig-heartbeat: Make top brightness adjustable
tools/leds: Add led_hw_brightness_mon program
leds: class: Add new optional brightness_hw_changed attribute
leds: ktd2692: avoid harmless maybe-uninitialized warning
leds: add LED_ON brightness as boolean value
DT: leds: Improve examples by adding some context
This commit is contained in:
commit
7aa7d60811
10 changed files with 252 additions and 20 deletions
|
|
@ -3,11 +3,11 @@
|
|||
CC = $(CROSS_COMPILE)gcc
|
||||
CFLAGS = -Wall -Wextra -g -I../../include/uapi
|
||||
|
||||
all: uledmon
|
||||
all: uledmon led_hw_brightness_mon
|
||||
%: %.c
|
||||
$(CC) $(CFLAGS) -o $@ $^
|
||||
|
||||
clean:
|
||||
$(RM) uledmon
|
||||
$(RM) uledmon led_hw_brightness_mon
|
||||
|
||||
.PHONY: all clean
|
||||
|
|
|
|||
84
tools/leds/led_hw_brightness_mon.c
Normal file
84
tools/leds/led_hw_brightness_mon.c
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* led_hw_brightness_mon.c
|
||||
*
|
||||
* This program monitors LED brightness level changes having its origin
|
||||
* in hardware/firmware, i.e. outside of kernel control.
|
||||
* A timestamp and brightness value is printed each time the brightness changes.
|
||||
*
|
||||
* Usage: led_hw_brightness_mon <device-name>
|
||||
*
|
||||
* <device-name> is the name of the LED class device to be monitored. Pressing
|
||||
* CTRL+C will exit.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <poll.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <linux/uleds.h>
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
int fd, ret;
|
||||
char brightness_file_path[LED_MAX_NAME_SIZE + 11];
|
||||
struct pollfd pollfd;
|
||||
struct timespec ts;
|
||||
char buf[11];
|
||||
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Requires <device-name> argument\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
snprintf(brightness_file_path, LED_MAX_NAME_SIZE,
|
||||
"/sys/class/leds/%s/brightness_hw_changed", argv[1]);
|
||||
|
||||
fd = open(brightness_file_path, O_RDONLY);
|
||||
if (fd == -1) {
|
||||
printf("Failed to open %s file\n", brightness_file_path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* read may fail if no hw brightness change has occurred so far,
|
||||
* but it is required to avoid spurious poll notifications in
|
||||
* the opposite case.
|
||||
*/
|
||||
read(fd, buf, sizeof(buf));
|
||||
|
||||
pollfd.fd = fd;
|
||||
pollfd.events = POLLPRI;
|
||||
|
||||
while (1) {
|
||||
ret = poll(&pollfd, 1, -1);
|
||||
if (ret == -1) {
|
||||
printf("Failed to poll %s file (%d)\n",
|
||||
brightness_file_path, ret);
|
||||
ret = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
|
||||
ret = read(fd, buf, sizeof(buf));
|
||||
if (ret < 0)
|
||||
break;
|
||||
|
||||
ret = lseek(pollfd.fd, 0, SEEK_SET);
|
||||
if (ret < 0) {
|
||||
printf("lseek failed (%d)\n", ret);
|
||||
break;
|
||||
}
|
||||
|
||||
printf("[%ld.%09ld] %d\n", ts.tv_sec, ts.tv_nsec, atoi(buf));
|
||||
}
|
||||
|
||||
close(fd);
|
||||
|
||||
return ret;
|
||||
}
|
||||
Loading…
Reference in a new issue