[REFACTOR] Buffer: move getting next queue element into separate function
[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
36 static const char *all_path[] = {
37         path_backlight,
38         path_backlight_min,
39         path_backlight_max
40 };
41
42 enum {
43         all_path_cnt = sizeof(all_path) / sizeof(char *)
44 };
45
46
47 static int maru_check(struct lcd_ops *ops)
48 {
49         int i;
50
51         for (i = 0; i < all_path_cnt; ++i) {
52                 int ret = read_val(all_path[i]);
53
54                 if (IS_ERR_VALUE(ret))
55                         return 0;
56         }
57
58         return 1;
59 }
60
61 static unsigned long maru_get_parameter(struct lcd_ops *ops,
62                                         enum lcd_parameter_type type)
63 {
64         switch (type) {
65         case LPD_MIN_BRIGHTNESS:
66                 return read_val(path_backlight_min);
67         case LPD_MAX_BRIGHTNESS:
68                 return read_val(path_backlight_max);
69         case LPD_BRIGHTNESS:
70                 return read_val(path_backlight);
71         }
72
73         return -EINVAL;
74 }
75
76
77
78
79
80 static int entry_handler_set_backlight(struct kretprobe_instance *ri,
81                                        struct pt_regs *regs);
82 static int ret_handler_set_backlight(struct kretprobe_instance *ri,
83                                      struct pt_regs *regs);
84
85 static struct kretprobe set_backlight_krp = {
86         .kp.symbol_name = "marubl_send_intensity",
87         .entry_handler = entry_handler_set_backlight,
88         .handler = ret_handler_set_backlight,
89         .data_size = sizeof(int)
90 };
91
92
93
94
95
96 static int maru_set(struct lcd_ops *ops)
97 {
98         return dbi_register_kretprobe(&set_backlight_krp);
99 }
100
101 static int maru_unset(struct lcd_ops *ops)
102 {
103         dbi_unregister_kretprobe(&set_backlight_krp);
104         return 0;
105 }
106
107 static struct lcd_ops maru_ops = {
108         .name = "maru",
109         .check = maru_check,
110         .set = maru_set,
111         .unset = maru_unset,
112         .get = maru_get_parameter
113 };
114
115 struct lcd_ops *LCD_MAKE_FNAME(maru)(void)
116 {
117         return &maru_ops;
118 }
119
120
121
122
123
124 static int entry_handler_set_backlight(struct kretprobe_instance *ri,
125                                        struct pt_regs *regs)
126 {
127         int *brightness = (int *)ri->data;
128         struct backlight_device *bd;
129
130         bd = (struct backlight_device *)swap_get_karg(regs, 0);
131         *brightness = bd->props.brightness;
132
133         return 0;
134 }
135
136 static int ret_handler_set_backlight(struct kretprobe_instance *ri,
137                                      struct pt_regs *regs)
138 {
139         int ret = regs_return_value(regs);
140         int *brightness = (int *)ri->data;
141
142         if (!ret && maru_ops.notifier)
143                 maru_ops.notifier(&maru_ops, LAT_BRIGHTNESS,
144                                   (void *)*brightness);
145
146         return 0;
147 }