2 * Copyright (c) 2012 NVIDIA CORPORATION. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 #include <linux/cpuquiet.h>
20 ssize_t show_int_attribute(struct cpuquiet_attribute *cattr, char *buf)
22 return sprintf(buf, "%d\n", *((int *)cattr->param));
25 ssize_t store_int_attribute(struct cpuquiet_attribute *cattr,
26 const char *buf, size_t count)
30 err = kstrtoint(buf, 0, &val);
34 *((int *)(cattr->param)) = val;
36 if (cattr->store_callback)
37 cattr->store_callback(cattr);
42 ssize_t show_bool_attribute(struct cpuquiet_attribute *cattr, char *buf)
44 return sprintf(buf, "%d\n", *((bool *)cattr->param));
47 ssize_t store_bool_attribute(struct cpuquiet_attribute *cattr,
48 const char *buf, size_t count)
52 err = kstrtoint(buf, 0, &val);
56 if (val < 0 || val > 1)
59 *((bool *)(cattr->param)) = val;
61 if (cattr->store_callback)
62 cattr->store_callback(cattr);
67 ssize_t show_uint_attribute(struct cpuquiet_attribute *cattr, char *buf)
69 return sprintf(buf, "%u\n", *((unsigned int *)cattr->param));
72 ssize_t store_uint_attribute(struct cpuquiet_attribute *cattr,
73 const char *buf, size_t count)
78 err = kstrtouint(buf, 0, &val);
82 *((unsigned int *)(cattr->param)) = val;
84 if (cattr->store_callback)
85 cattr->store_callback(cattr);
90 ssize_t store_ulong_attribute(struct cpuquiet_attribute *cattr,
91 const char *buf, size_t count)
96 err = kstrtoul(buf, 0, &val);
100 *((unsigned long *)(cattr->param)) = val;
102 if (cattr->store_callback)
103 cattr->store_callback(cattr);
108 ssize_t show_ulong_attribute(struct cpuquiet_attribute *cattr,
111 return sprintf(buf, "%lu\n", *((unsigned long *)cattr->param));
114 ssize_t cpuquiet_auto_sysfs_store(struct kobject *kobj,
115 struct attribute *attr, const char *buf, size_t count)
117 struct cpuquiet_attribute *cattr =
118 container_of(attr, struct cpuquiet_attribute, attr);
121 return cattr->store(cattr, buf, count);
126 ssize_t cpuquiet_auto_sysfs_show(struct kobject *kobj,
127 struct attribute *attr, char *buf)
129 struct cpuquiet_attribute *cattr =
130 container_of(attr, struct cpuquiet_attribute, attr);
132 return cattr->show(cattr, buf);