ARM: tizen_tm1_defconfig: Enable missing features related with CGROUPS
[profile/mobile/platform/kernel/linux-3.10-sc7730.git] / kernel / swap / energy / lcd / lcd_debugfs.c
1 /*
2  *  Dynamic Binary Instrumentation Module based on KProbes
3  *  energy/lcd/lcd_debugfs.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 <linux/debugfs.h>
27 #include <linux/module.h>
28 #include <linux/slab.h>
29 #include <energy/lcd/lcd_base.h>
30 #include <energy/debugfs_energy.h>
31 #include <energy/rational_debugfs.h>
32
33
34 static int get_system(void *data, u64 *val)
35 {
36         struct lcd_ops *ops = (struct lcd_ops *)data;
37         const size_t size = get_lcd_size_array(ops);
38         const size_t size_1 = size - 1;
39         u64 i_max, j_min, t, e = 0;
40         u64 *array_time;
41         int i, j;
42
43         array_time = kmalloc(sizeof(*array_time) * size, GFP_KERNEL);
44         if (array_time == NULL)
45                 return -ENOMEM;
46
47         get_lcd_array_time(ops, array_time);
48
49         for (i = 0; i < size; ++i) {
50                 t = array_time[i];
51
52                 /* e = (i * max + (k - i) * min) * t / k */
53                 j = size_1 - i;
54                 i_max = div_u64(i * ops->max_coef.num * t,
55                                 ops->max_coef.denom);
56                 j_min = div_u64(j * ops->min_coef.num * t,
57                                 ops->min_coef.denom);
58                 e += div_u64(i_max + j_min, size_1);
59         }
60
61         kfree(array_time);
62
63         *val = e;
64
65         return 0;
66 }
67
68 SWAP_DEFINE_SIMPLE_ATTRIBUTE(fops_get_system, get_system, NULL, "%llu\n");
69
70
71 static struct dentry *lcd_dir;
72
73 /**
74  * @brief Register LCD in debugfs
75  *
76  * @param ops LCD operations
77  * @return Error code
78  */
79 int register_lcd_debugfs(struct lcd_ops *ops)
80 {
81         int ret;
82         struct dentry *dentry, *system;
83
84         if (lcd_dir == NULL)
85                 return -EINVAL;
86
87         dentry = debugfs_create_dir(ops->name, lcd_dir);
88         if (dentry == NULL)
89                 return -ENOMEM;
90
91         ret = create_rational_files(dentry, &ops->min_coef,
92                                     "min_num", "min_denom");
93         if (ret)
94                 goto fail;
95
96         ret = create_rational_files(dentry, &ops->max_coef,
97                                     "max_num", "max_denom");
98         if (ret)
99                 goto fail;
100
101         system = debugfs_create_file("system", 0600, dentry, (void *)ops,
102                                      &fops_get_system);
103         if (system == NULL)
104                 goto fail;
105
106         ops->dentry = dentry;
107
108         return 0;
109 fail:
110         debugfs_remove_recursive(dentry);
111         return -ENOMEM;
112 }
113
114 /**
115  * @brief Unregister LCD in debugfs
116  *
117  * @param ops LCD operations
118  * @return Void
119  */
120 void unregister_lcd_debugfs(struct lcd_ops *ops)
121 {
122         debugfs_remove_recursive(ops->dentry);
123 }
124
125 /**
126  * @brief Destroy debugfs for LCD
127  *
128  * @return Void
129  */
130 void exit_lcd_debugfs(void)
131 {
132         if (lcd_dir)
133                 debugfs_remove_recursive(lcd_dir);
134
135         lcd_dir = NULL;
136 }
137
138 /**
139  * @brief Create debugfs for LCD
140  *
141  * @param dentry Dentry
142  * @return Error code
143  */
144 int init_lcd_debugfs(struct dentry *energy_dir)
145 {
146         lcd_dir = debugfs_create_dir("lcd", energy_dir);
147         if (lcd_dir == NULL)
148                 return -ENOMEM;
149
150         return 0;
151 }