blob: c387faf5a66626f13ef5de88fd8eb72697c60fe6
1 | #include <stdio.h> |
2 | #include <unistd.h> |
3 | #include <fcntl.h> |
4 | #include <errno.h> |
5 | #include <hardware/lights.h> |
6 | #include <hardware/hardware.h> |
7 | |
8 | #define BACKLIGHT "/sys/class/backlight/aml-bl/brightness" |
9 | |
10 | static int set_light_backlight(struct light_device_t* dev, |
11 | struct light_state_t const* state) |
12 | { |
13 | int nwr, ret = -1, fd; |
14 | char value[20]; |
15 | int light_level; |
16 | light_level =state->color&0xff; |
17 | |
18 | fd = open(BACKLIGHT, O_RDWR); |
19 | if (fd > 0) { |
20 | nwr = sprintf(value, "%d\n", light_level); |
21 | ret = write(fd, value, nwr); |
22 | close(fd); |
23 | } |
24 | |
25 | return ret; |
26 | } |
27 | |
28 | static int open_lights(const struct hw_module_t* module, char const* name, |
29 | struct hw_device_t** device) |
30 | { |
31 | int res = -EINVAL; |
32 | |
33 | if (strcmp(LIGHT_ID_BACKLIGHT, name) == 0) { |
34 | struct light_device_t *dev = malloc(sizeof(struct light_device_t)); |
35 | if (!dev) { |
36 | return res; |
37 | } |
38 | |
39 | memset(dev, 0, sizeof(*dev)); |
40 | dev->common.tag = HARDWARE_DEVICE_TAG; |
41 | dev->common.version = 0; |
42 | dev->common.module = (struct hw_module_t*)module; |
43 | dev->common.close = NULL; |
44 | dev->set_light = set_light_backlight; |
45 | |
46 | *device = (struct hw_device_t*)dev; |
47 | res = 0; |
48 | } |
49 | |
50 | return res; |
51 | } |
52 | |
53 | static struct hw_module_methods_t lights_module_methods = { |
54 | .open = open_lights, |
55 | }; |
56 | |
57 | const struct hw_module_t HAL_MODULE_INFO_SYM = { |
58 | .tag = HARDWARE_MODULE_TAG, |
59 | .version_major = 1, |
60 | .version_minor = 0, |
61 | .id = LIGHTS_HARDWARE_MODULE_ID, |
62 | .name = "Backlight", |
63 | .author = "Amlogic", |
64 | .methods = &lights_module_methods, |
65 | }; |
66 |