summaryrefslogtreecommitdiff
path: root/energy/lcd/maru.c
blob: fb75f884f5cff5722bf4bd6a335e912a6b6c4674 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
 *  Dynamic Binary Instrumentation Module based on KProbes
 *  energy/lcd/maru.c
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 * Copyright (C) Samsung Electronics, 2013
 *
 * 2013         Vyacheslav Cherkashin <v.cherkashin@samsung.com>
 *
 */


#include <kprobe/dbi_kprobes.h>
#include <linux/backlight.h>
#include "lcd_base.h"



static const char path_backlight[]	= "/sys/class/backlight/emulator/brightness";
static const char path_backlight_min[]	= "/sys/class/backlight/emulator/min_brightness";
static const char path_backlight_max[]	= "/sys/class/backlight/emulator/max_brightness";
static const char path_power[]		= "/sys/class/lcd/emulator/lcd_power";

static const char *all_path[] = {
	path_backlight,
	path_backlight_min,
	path_backlight_max,
	path_power
};

enum {
	all_path_cnt = sizeof(all_path) / sizeof(char *)
};


static int maru_check(struct lcd_ops *ops)
{
	int i;

	for (i = 0; i < all_path_cnt; ++i) {
		int ret = read_val(all_path[i]);

		if (IS_ERR_VALUE(ret))
			return 0;
	}

	return 1;
}

static unsigned long maru_get_parameter(struct lcd_ops *ops,
					enum lcd_parameter_type type)
{
	switch (type) {
	case LPD_MIN_BRIGHTNESS:
		return read_val(path_backlight_min);
	case LPD_MAX_BRIGHTNESS:
		return read_val(path_backlight_max);
	case LPD_BRIGHTNESS:
		return read_val(path_backlight);
	case LPD_POWER:
		return read_val(path_power);
	default:
		return -EINVAL;
	}
}





static int entry_handler_set_backlight(struct kretprobe_instance *ri,
				       struct pt_regs *regs);
static int ret_handler_set_backlight(struct kretprobe_instance *ri,
				     struct pt_regs *regs);

static struct kretprobe set_backlight_krp = {
	.kp.symbol_name = "marubl_send_intensity",
	.entry_handler = entry_handler_set_backlight,
	.handler = ret_handler_set_backlight,
	.data_size = sizeof(int)
};





static int maru_set(struct lcd_ops *ops)
{
	return dbi_register_kretprobe(&set_backlight_krp);
}

static int maru_unset(struct lcd_ops *ops)
{
	dbi_unregister_kretprobe(&set_backlight_krp);
	return 0;
}

static struct lcd_ops maru_ops = {
	.name = "maru",
	.check = maru_check,
	.set = maru_set,
	.unset = maru_unset,
	.get = maru_get_parameter
};

struct lcd_ops *LCD_MAKE_FNAME(maru)(void)
{
	return &maru_ops;
}





static int entry_handler_set_backlight(struct kretprobe_instance *ri,
				       struct pt_regs *regs)
{
	int *brightness = (int *)ri->data;
	struct backlight_device *bd;

	bd = (struct backlight_device *)swap_get_karg(regs, 0);
	*brightness = bd->props.brightness;

	return 0;
}

static int ret_handler_set_backlight(struct kretprobe_instance *ri,
				     struct pt_regs *regs)
{
	int ret = regs_return_value(regs);
	int *brightness = (int *)ri->data;

	if (!ret && maru_ops.notifier)
		maru_ops.notifier(&maru_ops, LAT_BRIGHTNESS,
				  (void *)*brightness);

	return 0;
}