11 #define KMSG_COMPONENT "appldata"
12 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
14 #include <linux/module.h>
16 #include <linux/slab.h>
17 #include <linux/errno.h>
23 #include <linux/sysctl.h>
31 #include <asm/uaccess.h>
38 #define APPLDATA_CPU_INTERVAL 10000
42 #define TOD_MICRO 0x01000
52 void __user *
buffer,
size_t *lenp, loff_t *ppos);
55 size_t *lenp, loff_t *ppos);
58 static struct ctl_table appldata_table[] = {
62 .proc_handler = appldata_timer_handler,
65 .procname =
"interval",
67 .proc_handler = appldata_interval_handler,
72 static struct ctl_table appldata_dir_table[] = {
74 .procname = appldata_proc_name,
77 .child = appldata_table,
89 static int appldata_timer_active;
90 static int appldata_timer_suspended = 0;
113 static void appldata_timer_function(
unsigned long data)
147 .
prod_nr = {0xD3, 0xC9, 0xD5, 0xE4,
150 .version_nr = 0xF2F6,
151 .release_nr = 0xF0F1,
155 id.mod_lvl = (mod_lvl[0]) << 8 | mod_lvl[1];
156 return appldata_asm(&
id,
function, (
void *) buffer, length);
163 #define APPLDATA_ADD_TIMER 0
164 #define APPLDATA_DEL_TIMER 1
165 #define APPLDATA_MOD_TIMER 2
173 static void __appldata_vtimer_setup(
int cmd)
179 if (appldata_timer_active)
183 appldata_timer_active = 1;
187 if (!appldata_timer_active)
189 appldata_timer_active = 0;
192 if (!appldata_timer_active)
205 void __user *
buffer,
size_t *lenp, loff_t *ppos)
210 if (!*lenp || *ppos) {
215 len =
sprintf(buf, appldata_timer_active ?
"1\n" :
"0\n");
223 if (
copy_from_user(buf, buffer, len >
sizeof(buf) ?
sizeof(buf) : len))
225 spin_lock(&appldata_timer_lock);
228 else if (buf[0] ==
'0')
230 spin_unlock(&appldata_timer_lock);
244 appldata_interval_handler(
ctl_table *ctl,
int write,
245 void __user *buffer,
size_t *lenp, loff_t *ppos)
250 if (!*lenp || *ppos) {
255 len =
sprintf(buf,
"%i\n", appldata_interval);
263 if (
copy_from_user(buf, buffer, len >
sizeof(buf) ?
sizeof(buf) : len))
266 sscanf(buf,
"%i", &interval);
270 spin_lock(&appldata_timer_lock);
273 spin_unlock(&appldata_timer_lock);
287 appldata_generic_handler(
ctl_table *ctl,
int write,
288 void __user *buffer,
size_t *lenp, loff_t *ppos)
299 if (&tmp_ops->ctl_table[2] == ctl) {
308 if (!try_module_get(ops->
owner)) {
314 if (!*lenp || *ppos) {
316 module_put(ops->
owner);
324 module_put(ops->
owner);
331 len >
sizeof(buf) ?
sizeof(buf) : len)) {
332 module_put(ops->
owner);
337 if ((buf[0] ==
'1') && (ops->
active == 0)) {
339 if (!try_module_get(ops->
owner)) {
341 module_put(ops->
owner);
347 (
unsigned long) ops->
data, ops->
size,
350 pr_err(
"Starting the data collection for %s "
351 "failed with rc=%d\n", ops->
name, rc);
352 module_put(ops->
owner);
355 }
else if ((buf[0] ==
'0') && (ops->
active == 1)) {
358 (
unsigned long) ops->
data, ops->
size,
361 pr_err(
"Stopping the data collection for %s "
362 "failed with rc=%d\n", ops->
name, rc);
363 module_put(ops->
owner);
369 module_put(ops->
owner);
392 list_add(&ops->
list, &appldata_ops_list);
395 ops->
ctl_table[0].procname = appldata_proc_name;
402 ops->
ctl_table[2].proc_handler = appldata_generic_handler;
434 static int appldata_freeze(
struct device *
dev)
440 spin_lock(&appldata_timer_lock);
441 if (appldata_timer_active) {
443 appldata_timer_suspended = 1;
445 spin_unlock(&appldata_timer_lock);
452 (
unsigned long) ops->
data, ops->
size,
455 pr_err(
"Stopping the data collection for %s "
456 "failed with rc=%d\n", ops->
name, rc);
463 static int appldata_restore(
struct device *dev)
469 spin_lock(&appldata_timer_lock);
470 if (appldata_timer_suspended) {
472 appldata_timer_suspended = 0;
474 spin_unlock(&appldata_timer_lock);
483 (
unsigned long) ops->
data, ops->
size,
486 pr_err(
"Starting the data collection for %s "
487 "failed with rc=%d\n", ops->
name, rc);
495 static int appldata_thaw(
struct device *dev)
497 return appldata_restore(dev);
500 static const struct dev_pm_ops appldata_pm_ops = {
501 .freeze = appldata_freeze,
502 .thaw = appldata_thaw,
503 .restore = appldata_restore,
510 .pm = &appldata_pm_ops,
523 static int __init appldata_init(
void)
527 appldata_timer.function = appldata_timer_function;
528 appldata_timer.data = (
unsigned long) &appldata_work;
534 appldata_pdev = platform_device_register_simple(
"appldata", -1,
NULL,
536 if (IS_ERR(appldata_pdev)) {
537 rc = PTR_ERR(appldata_pdev);