Merge "[IMPROVE] Buffer: implement initialization with structure"
[kernel/swap-modules.git] / energy / lcd / maru.c
1 /*
2  *  Dynamic Binary Instrumentation Module based on KProbes
3  *  energy/lcd/maru.c
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  *
19  * Copyright (C) Samsung Electronics, 2013
20  *
21  * 2013         Vyacheslav Cherkashin <v.cherkashin@samsung.com>
22  *
23  */
24
25
26 #include <kprobe/dbi_kprobes.h>
27 #include <linux/backlight.h>
28 #include "lcd_base.h"
29
30
31
32 static const char path_backlight[]      = "/sys/class/backlight/emulator/brightness";
33 static const char path_backlight_min[]  = "/sys/class/backlight/emulator/min_brightness";
34 static const char path_backlight_max[]  = "/sys/class/backlight/emulator/max_brightness";
35 static const char path_power[]          = "/sys/class/lcd/emulator/lcd_power";
36
37 static const char *all_path[] = {
38         path_backlight,
39         path_backlight_min,
40         path_backlight_max,
41         path_power
42 };
43
44 enum {
45         all_path_cnt = sizeof(all_path) / sizeof(char *)
46 };
47
48
49 static int maru_check(struct lcd_ops *ops)
50 {
51         int i;
52
53         for (i = 0; i < all_path_cnt; ++i) {
54                 int ret = read_val(all_path[i]);
55
56                 if (IS_ERR_VALUE(ret))
57                         return 0;
58         }
59
60         return 1;
61 }
62
63 static unsigned long maru_get_parameter(struct lcd_ops *ops,
64                                         enum lcd_parameter_type type)
65 {
66         switch (type) {
67         case LPD_MIN_BRIGHTNESS:
68                 return read_val(path_backlight_min);
69         case LPD_MAX_BRIGHTNESS:
70                 return read_val(path_backlight_max);
71         case LPD_BRIGHTNESS:
72                 return read_val(path_backlight);
73         case LPD_POWER:
74                 return read_val(path_power);
75         default:
76                 return -EINVAL;
77         }
78 }
79
80
81
82
83
84 static int entry_handler_set_backlight(struct kretprobe_instance *ri,
85                                        struct pt_regs *regs);
86 static int ret_handler_set_backlight(struct kretprobe_instance *ri,
87                                      struct pt_regs *regs);
88
89 static struct kretprobe set_backlight_krp = {
90         .kp.symbol_name = "marubl_send_intensity",
91         .entry_handler = entry_handler_set_backlight,
92         .handler = ret_handler_set_backlight,
93         .data_size = sizeof(int)
94 };
95
96
97
98
99
100 static int maru_set(struct lcd_ops *ops)
101 {
102         return dbi_register_kretprobe(&set_backlight_krp);
103 }
104
105 static int maru_unset(struct lcd_ops *ops)
106 {
107         dbi_unregister_kretprobe(&set_backlight_krp);
108         return 0;
109 }
110
111 static struct lcd_ops maru_ops = {
112         .name = "maru",
113         .check = maru_check,
114         .set = maru_set,
115         .unset = maru_unset,
116         .get = maru_get_parameter
117 };
118
119 struct lcd_ops *LCD_MAKE_FNAME(maru)(void)
120 {
121         return &maru_ops;
122 }
123
124
125
126
127
128 static int entry_handler_set_backlight(struct kretprobe_instance *ri,
129                                        struct pt_regs *regs)
130 {
131         int *brightness = (int *)ri->data;
132         struct backlight_device *bd;
133
134         bd = (struct backlight_device *)swap_get_karg(regs, 0);
135         *brightness = bd->props.brightness;
136
137         return 0;
138 }
139
140 static int ret_handler_set_backlight(struct kretprobe_instance *ri,
141                                      struct pt_regs *regs)
142 {
143         int ret = regs_return_value(regs);
144         int *brightness = (int *)ri->data;
145
146         if (!ret && maru_ops.notifier)
147                 maru_ops.notifier(&maru_ops, LAT_BRIGHTNESS,
148                                   (void *)*brightness);
149
150         return 0;
151 }