From: Shem Multinymous <multinymous@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: Robert Love <rlove@rlove.org>, Pavel Machek <pavel@suse.cz>,
Jean Delvare <khali@linux-fr.org>,
Greg Kroah-Hartman <gregkh@suse.de>,
Andrew Morton <akpm@osdl.org>,
hdaps-devel@lists.sourceforge.net
Subject: [PATCH 09/12] hdaps: Add new sysfs attributes
Date: Thu, 10 Aug 2006 12:48:47 +0300 [thread overview]
Message-ID: <11552033912199-git-send-email-multinymous@gmail.com> (raw)
In-Reply-To: <1155203330179-git-send-email-multinymous@gmail.com>
This patch adds 4 new r/w sysfs attributes to the hdaps driver:
/sys/devices/platform/hdaps/sampling_rate:
This determines the frequency of hardware queries and input device updates.
Default=50.
/sys/devices/platform/hdaps/oversampling_ratio:
When set to X, the embedded controller is told to do physical accelerometer
measurements at a rate that is X times higher than the rate at which
the driver reads those measurements (i.e., X*sampling_rate). This
reduces sample phase difference is, and useful for the running average
filter (see next). Default=5
/sys/devices/platform/hdaps/running_avg_filter_order:
When set to X, reported readouts will be the average of the last X physical
accelerometer measurements. Current firmware allows 1<=X<=8. Setting to a
high value decreases readout fluctuations. The averaging is handled
by the embedded controller, so no CPU resources are used. Default=2.
/sys/devices/platform/hdaps/fake_data_mode:
If set to 1, enables a test mode where the physical accelerometer readouts
are replaced with an incrementing counter. This is useful for checking the
regularity of the sampling interval and driver<->userspace communication,
which is useful for development and testing of the hdapd userspace daemon.
Signed-off-by: Shem Multinymous <multinymous@gmail.com>
Signed-off-by: Pavel Machek <pavel@suse.cz>
---
drivers/hwmon/hdaps.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 107 insertions(+)
--- a/drivers/hwmon/hdaps.c
+++ b/drivers/hwmon/hdaps.c
@@ -521,6 +521,99 @@ static ssize_t hdaps_invert_store(struct
return count;
}
+static ssize_t hdaps_sampling_rate_show(
+ struct device *dev, struct device_attribute *attr, char *buf)
+{
+ return sprintf(buf, "%d\n", sampling_rate);
+}
+
+static ssize_t hdaps_sampling_rate_store(
+ struct device *dev, struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ int rate, ret;
+ if (sscanf(buf, "%d", &rate) != 1 || rate>HZ || rate<0) {
+ printk(KERN_WARNING
+ "must have 0<input_sampling_rate<=HZ=%d\n", HZ);
+ return -EINVAL;
+ }
+ ret = hdaps_set_ec_config(rate*oversampling_ratio,
+ running_avg_filter_order);
+ if (ret)
+ return ret;
+ sampling_rate = rate;
+ return count;
+}
+
+static ssize_t hdaps_oversampling_ratio_show(
+ struct device *dev, struct device_attribute *attr, char *buf)
+{
+ int ec_rate, order;
+ int ret = hdaps_get_ec_config(&ec_rate, &order);
+ if (ret)
+ return ret;
+ return sprintf(buf, "%u\n", ec_rate / sampling_rate);
+}
+
+static ssize_t hdaps_oversampling_ratio_store(
+ struct device *dev, struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ int ratio, ret;
+ if (sscanf(buf, "%d", &ratio) != 1 || ratio<1)
+ return -EINVAL;
+ ret = hdaps_set_ec_config(sampling_rate*ratio,
+ running_avg_filter_order);
+ if (ret)
+ return ret;
+ oversampling_ratio = ratio;
+ return count;
+}
+
+static ssize_t hdaps_running_avg_filter_order_show(
+ struct device *dev, struct device_attribute *attr, char *buf)
+{
+ int rate, order;
+ int ret = hdaps_get_ec_config(&rate, &order);
+ if (ret)
+ return ret;
+ return sprintf(buf, "%u\n", order);
+}
+
+static ssize_t hdaps_running_avg_filter_order_store(
+ struct device *dev, struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ int order, ret;
+ if (sscanf(buf, "%d", &order) != 1)
+ return -EINVAL;
+ ret = hdaps_set_ec_config(sampling_rate*oversampling_ratio, order);
+ if (ret)
+ return ret;
+ running_avg_filter_order = order;
+ return count;
+}
+
+static ssize_t hdaps_fake_data_mode_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ int on, ret;
+ if (sscanf(buf, "%d", &on) != 1 || on<0 || on>1)
+ return -EINVAL;
+ ret = hdaps_set_fake_data_mode(on);
+ if (ret)
+ return ret;
+ fake_data_mode = on;
+ return count;
+}
+
+static ssize_t hdaps_fake_data_mode_show(
+ struct device *dev, struct device_attribute *attr, char *buf)
+{
+ return sprintf(buf, "%d\n", fake_data_mode);
+}
+
static DEVICE_ATTR(position, 0444, hdaps_position_show, NULL);
static DEVICE_ATTR(temp1, 0444, hdaps_temp1_show, NULL);
/* "temp1" instead of "temperature" is hwmon convention */
@@ -528,6 +621,16 @@ static DEVICE_ATTR(keyboard_activity, 04
static DEVICE_ATTR(mouse_activity, 0444, hdaps_mouse_activity_show, NULL);
static DEVICE_ATTR(calibrate, 0644, hdaps_calibrate_show,hdaps_calibrate_store);
static DEVICE_ATTR(invert, 0644, hdaps_invert_show, hdaps_invert_store);
+static DEVICE_ATTR(sampling_rate, 0644,
+ hdaps_sampling_rate_show, hdaps_sampling_rate_store);
+static DEVICE_ATTR(oversampling_ratio, 0644,
+ hdaps_oversampling_ratio_show,
+ hdaps_oversampling_ratio_store);
+static DEVICE_ATTR(running_avg_filter_order, 0644,
+ hdaps_running_avg_filter_order_show,
+ hdaps_running_avg_filter_order_store);
+static DEVICE_ATTR(fake_data_mode, 0644,
+ hdaps_fake_data_mode_show, hdaps_fake_data_mode_store);
static struct attribute *hdaps_attributes[] = {
&dev_attr_position.attr,
@@ -536,6 +639,10 @@ static struct attribute *hdaps_attribute
&dev_attr_mouse_activity.attr,
&dev_attr_calibrate.attr,
&dev_attr_invert.attr,
+ &dev_attr_sampling_rate.attr,
+ &dev_attr_oversampling_ratio.attr,
+ &dev_attr_running_avg_filter_order.attr,
+ &dev_attr_fake_data_mode.attr,
NULL,
};
next prev parent reply other threads:[~2006-08-10 9:56 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-08-10 9:48 [PATCH 00/12] ThinkPad embedded controller and hdaps drivers (version 2) Shem Multinymous
2006-08-10 9:48 ` [PATCH 01/12] thinkpad_ec: New driver for ThinkPad embedded controller access Shem Multinymous
2006-08-10 9:48 ` [PATCH 02/12] hdaps: Use thinkpad_ec instead of direct port access Shem Multinymous
2006-08-10 9:48 ` [PATCH 03/12] hdaps: Unify and cache hdaps readouts Shem Multinymous
2006-08-10 9:48 ` [PATCH 04/12] hdaps: Correct readout and remove nonsensical attributes Shem Multinymous
2006-08-10 9:48 ` [PATCH 05/12] hdaps: Remember keyboard and mouse activity Shem Multinymous
2006-08-10 9:48 ` [PATCH 06/12] hdaps: Limit hardware query rate Shem Multinymous
2006-08-10 21:26 ` Pavel Machek
2006-08-10 21:46 ` Evgeni Golov
2006-08-10 9:48 ` [PATCH 07/12] hdaps: delay calibration to first hardware query Shem Multinymous
2006-08-10 9:48 ` [PATCH 08/12] hdaps: Add explicit hardware configuration functions Shem Multinymous
2006-08-10 9:48 ` Shem Multinymous [this message]
2006-08-10 9:48 ` [PATCH 10/12] hdaps: Power off accelerometer on suspend and unload Shem Multinymous
2006-08-10 9:48 ` [PATCH 11/12] hdaps: Stop polling timer when suspended Shem Multinymous
2006-08-10 9:48 ` [PATCH 12/12] hdaps: Simplify whitelist Shem Multinymous
2006-08-10 13:46 ` [PATCH 00/12] ThinkPad embedded controller and hdaps drivers (version 2) Robert Love
2006-08-10 19:53 ` Robert Love
2006-08-10 20:18 ` Andrew Morton
2006-08-10 20:37 ` Greg KH
2006-08-10 21:05 ` Jean Delvare
2006-08-10 23:11 ` Jesper Juhl
2006-08-11 1:38 ` Shem Multinymous
2006-08-11 0:01 ` Shem Multinymous
2006-08-10 22:52 ` Pavel Machek
2006-08-10 23:26 ` Shem Multinymous
-- strict thread matches above, loose matches on Subject: below --
2006-08-06 7:26 [PATCH 00/12] ThinkPad embedded controller and hdaps drivers Shem Multinymous
2006-08-06 7:26 ` [PATCH 09/12] hdaps: Add new sysfs attributes Shem Multinymous
2006-08-08 12:19 ` Pavel Machek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=11552033912199-git-send-email-multinymous@gmail.com \
--to=multinymous@gmail.com \
--cc=akpm@osdl.org \
--cc=gregkh@suse.de \
--cc=hdaps-devel@lists.sourceforge.net \
--cc=khali@linux-fr.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pavel@suse.cz \
--cc=rlove@rlove.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.