ARM: tizen_tm1_defconfig: Enable missing features related with CGROUPS
[profile/mobile/platform/kernel/linux-3.10-sc7730.git] / kernel / swap / 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/swap_kprobes.h>
27 #include <linux/backlight.h>
28 #include "lcd_base.h"
29
30
31
32 static const char path_backlight[]      =
33         "/sys/class/backlight/emulator/brightness";
34 static const char path_backlight_min[]  =
35         "/sys/class/backlight/emulator/min_brightness";
36 static const char path_backlight_max[]  =
37         "/sys/class/backlight/emulator/max_brightness";
38 static const char path_power[]          =
39         "/sys/class/lcd/emulator/lcd_power";
40
41 static const char * const all_path[] = {
42         path_backlight,
43         path_backlight_min,
44         path_backlight_max,
45         path_power
46 };
47
48 enum {
49         all_path_cnt = sizeof(all_path) / sizeof(char *)
50 };
51
52
53 static int maru_check(struct lcd_ops *ops)
54 {
55         int i;
56
57         for (i = 0; i < all_path_cnt; ++i) {
58                 int ret = read_val(all_path[i]);
59
60                 if (IS_ERR_VALUE(ret))
61                         return 0;
62         }
63
64         return 1;
65 }
66
67 static unsigned long maru_get_parameter(struct lcd_ops *ops,
68                                         enum lcd_parameter_type type)
69 {
70         switch (type) {
71         case LPD_MIN_BRIGHTNESS:
72                 return read_val(path_backlight_min);
73         case LPD_MAX_BRIGHTNESS:
74                 return read_val(path_backlight_max);
75         case LPD_BRIGHTNESS:
76                 return read_val(path_backlight);
77         case LPD_POWER:
78                 return read_val(path_power);
79         default:
80                 return -EINVAL;
81         }
82 }
83
84
85
86
87
88 static int entry_handler_set_backlight(struct kretprobe_instance *ri,
89                                        struct pt_regs *regs);
90 static int ret_handler_set_backlight(struct kretprobe_instance *ri,
91                                      struct pt_regs *regs);
92
93 static struct kretprobe set_backlight_krp = {
94         .kp.symbol_name = "marubl_send_intensity",
95         .entry_handler = entry_handler_set_backlight,
96         .handler = ret_handler_set_backlight,
97         .data_size = sizeof(int)
98 };
99
100
101
102
103
104 static int maru_set(struct lcd_ops *ops)
105 {
106         return swap_register_kretprobe(&set_backlight_krp);
107 }
108
109 static int maru_unset(struct lcd_ops *ops)
110 {
111         swap_unregister_kretprobe(&set_backlight_krp);
112         return 0;
113 }
114
115 static struct lcd_ops maru_ops = {
116         .name = "maru",
117         .check = maru_check,
118         .set = maru_set,
119         .unset = maru_unset,
120         .get = maru_get_parameter
121 };
122
123 struct lcd_ops *LCD_MAKE_FNAME(maru)(void)
124 {
125         return &maru_ops;
126 }
127
128
129
130
131
132 static int entry_handler_set_backlight(struct kretprobe_instance *ri,
133                                        struct pt_regs *regs)
134 {
135         int *brightness = (int *)ri->data;
136         struct backlight_device *bd;
137
138         bd = (struct backlight_device *)swap_get_karg(regs, 0);
139         *brightness = bd->props.brightness;
140
141         return 0;
142 }
143
144 static int ret_handler_set_backlight(struct kretprobe_instance *ri,
145                                      struct pt_regs *regs)
146 {
147         int ret = regs_return_value(regs);
148         int *brightness = (int *)ri->data;
149
150         if (!ret && maru_ops.notifier)
151                 maru_ops.notifier(&maru_ops, LAT_BRIGHTNESS,
152                                   (void *)*brightness);
153
154         return 0;
155 }