summaryrefslogtreecommitdiff
path: root/drivers/cpuquiet/cpuquiet_attribute.c
diff options
context:
space:
mode:
authorPeter De Schrijver <pdeschrijver@nvidia.com>2012-06-11 20:43:59 +0300
committerSimone Willett <swillett@nvidia.com>2012-07-03 16:58:09 -0700
commit890a7b1b7409d3f867033533f691179f1daab633 (patch)
tree1f70114183808bd3ff122af87398b453e62257de /drivers/cpuquiet/cpuquiet_attribute.c
parent233acfbfe5910956f09ba9b9541ce0f1996ca190 (diff)
ARM: tegra: add sysfs support for tegra cpuquiet driver
Change-Id: I215c5de8e98d139a93113978e1e27adb5a6b252c Signed-off-by: Sai Charan Gurrappadi <sgurrappadi@nvidia.com> Reviewed-on: http://git-master/r/111283 Reviewed-by: Simone Willett <swillett@nvidia.com> Tested-by: Simone Willett <swillett@nvidia.com>
Diffstat (limited to 'drivers/cpuquiet/cpuquiet_attribute.c')
-rw-r--r--drivers/cpuquiet/cpuquiet_attribute.c133
1 files changed, 133 insertions, 0 deletions
diff --git a/drivers/cpuquiet/cpuquiet_attribute.c b/drivers/cpuquiet/cpuquiet_attribute.c
new file mode 100644
index 000000000000..9f1aa430149d
--- /dev/null
+++ b/drivers/cpuquiet/cpuquiet_attribute.c
@@ -0,0 +1,133 @@
+/*
+ * Copyright (c) 2012 NVIDIA CORPORATION. All rights reserved.
+ *
+ * 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; version 2 of the License.
+ *
+ * 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include <linux/cpuquiet.h>
+
+ssize_t show_int_attribute(struct cpuquiet_attribute *cattr, char *buf)
+{
+ return sprintf(buf, "%d\n", *((int *)cattr->param));
+}
+
+ssize_t store_int_attribute(struct cpuquiet_attribute *cattr,
+ const char *buf, size_t count)
+{
+ int err, val;
+
+ err = kstrtoint(buf, 0, &val);
+ if (err < 0)
+ return err;
+
+ *((int *)(cattr->param)) = val;
+
+ if (cattr->store_callback)
+ cattr->store_callback(cattr);
+
+ return count;
+}
+
+ssize_t show_bool_attribute(struct cpuquiet_attribute *cattr, char *buf)
+{
+ return sprintf(buf, "%d\n", *((bool *)cattr->param));
+}
+
+ssize_t store_bool_attribute(struct cpuquiet_attribute *cattr,
+ const char *buf, size_t count)
+{
+ int err, val;
+
+ err = kstrtoint(buf, 0, &val);
+ if (err < 0)
+ return err;
+
+ if (val < 0 || val > 1)
+ return -EINVAL;
+
+ *((bool *)(cattr->param)) = val;
+
+ if (cattr->store_callback)
+ cattr->store_callback(cattr);
+
+ return count;
+}
+
+ssize_t show_uint_attribute(struct cpuquiet_attribute *cattr, char *buf)
+{
+ return sprintf(buf, "%u\n", *((unsigned int *)cattr->param));
+}
+
+ssize_t store_uint_attribute(struct cpuquiet_attribute *cattr,
+ const char *buf, size_t count)
+{
+ int err;
+ unsigned int val;
+
+ err = kstrtouint(buf, 0, &val);
+ if (err < 0)
+ return err;
+
+ *((unsigned int *)(cattr->param)) = val;
+
+ if (cattr->store_callback)
+ cattr->store_callback(cattr);
+
+ return count;
+}
+
+ssize_t store_ulong_attribute(struct cpuquiet_attribute *cattr,
+ const char *buf, size_t count)
+{
+ int err;
+ unsigned long val;
+
+ err = kstrtoul(buf, 0, &val);
+ if (err < 0)
+ return err;
+
+ *((unsigned long *)(cattr->param)) = val;
+
+ if (cattr->store_callback)
+ cattr->store_callback(cattr);
+
+ return count;
+}
+
+ssize_t show_ulong_attribute(struct cpuquiet_attribute *cattr,
+ char *buf)
+{
+ return sprintf(buf, "%lu\n", *((unsigned long *)cattr->param));
+}
+
+ssize_t cpuquiet_auto_sysfs_store(struct kobject *kobj,
+ struct attribute *attr, const char *buf, size_t count)
+{
+ struct cpuquiet_attribute *cattr =
+ container_of(attr, struct cpuquiet_attribute, attr);
+
+ if (cattr->store)
+ return cattr->store(cattr, buf, count);
+
+ return -EINVAL;
+}
+
+ssize_t cpuquiet_auto_sysfs_show(struct kobject *kobj,
+ struct attribute *attr, char *buf)
+{
+ struct cpuquiet_attribute *cattr =
+ container_of(attr, struct cpuquiet_attribute, attr);
+
+ return cattr->show(cattr, buf);
+}