2 * Dynamic Binary Instrumentation Module based on KProbes
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.
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.
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.
19 * Copyright (C) Samsung Electronics, 2013
21 * 2013 Vyacheslav Cherkashin <v.cherkashin@samsung.com>
26 #include <kprobe/dbi_kprobes.h>
27 #include <linux/backlight.h>
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";
36 static const char *all_path[] = {
43 all_path_cnt = sizeof(all_path) / sizeof(char *)
47 static int maru_check(void)
51 for (i = 0; i < all_path_cnt; ++i) {
52 int ret = read_val(all_path[i]);
54 if (IS_ERR_VALUE(ret))
61 static unsigned long maru_get_parameter(struct lcd_ops *ops,
62 enum lcd_parameter_type 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);
70 return read_val(path_backlight);
76 static struct lcd_ops ops = {
79 .get = maru_get_parameter
86 /* ============================================================================
88 * ============================================================================
90 static int entry_handler_set_backlight(struct kretprobe_instance *ri,
93 int *brightness = (int *)ri->data;
94 struct backlight_device *bd;
96 bd = (struct backlight_device *)swap_get_karg(regs, 0);
97 *brightness = bd->props.brightness;
102 static int ret_handler_set_backlight(struct kretprobe_instance *ri,
103 struct pt_regs *regs)
105 int ret = regs_return_value(regs);
106 int *brightness = (int *)ri->data;
108 if (!ret && ops.notifier)
109 ops.notifier(&ops, LAT_BRIGHTNESS, (void *)*brightness);
114 static struct kretprobe set_backlight_krp = {
115 .kp.symbol_name = "marubl_send_intensity",
116 .entry_handler = entry_handler_set_backlight,
117 .handler = ret_handler_set_backlight,
118 .data_size = sizeof(int)
125 /* ============================================================================
126 * === REGISTER/UNREGISTER ===
127 * ============================================================================
129 void maru_register(void)
133 dbi_register_kretprobe(&set_backlight_krp);
135 ret = register_lcd(&ops);
137 printk("error maru_register()\n");
141 void maru_unregister(void)
143 unregister_lcd(&ops);
144 dbi_unregister_kretprobe(&set_backlight_krp);