aboutsummaryrefslogtreecommitdiff
path: root/drivers/input/touchscreen/ts_filter_linear.c
diff options
context:
space:
mode:
authorNelson Castillo <arhuaco@freaks-unidos.net>2009-03-10 12:04:05 +0000
committerAndy Green <agreen@octopus.localdomain>2009-03-10 12:04:05 +0000
commitbd88fa696f505a8a71484341e4fcde581b2d12a6 (patch)
treebca483a0c57848ca6d122907c42a0c7c04fbeb4a /drivers/input/touchscreen/ts_filter_linear.c
parent45aeeebf673b03329c423c2382a836ca878dd851 (diff)
Improve filter API and update filters
This patch turns upstream feedback into API modifications and code improvements. There will be more patches implementing upstream corrections but this one is the that will make most of the invasive changes and make the most important improvements to the API. Tested in a GTA02/rev06. The goals of this patch are: * Replace recursive calls with iteration. * General code improvements. * Make ts_filter_mean.c a reference for the rest of the filters. * Make the (almost)minimum number of changes to the other filters so that they compile and work, patches for cleaning these up will come next. * Filters should do what they were doing before. Some important changes: * Move "struct ts_filter tsf" in the private structures to force a crash (or break things) if we forget to remove an open-coded cast. * ts_filter.c/ts_filter.h ~ API modifications. * s3c2410_ts.c: ~ Use the new API. ~ Cleanups. * ts_filter_mean.c ~ Replace with a simple mean. ~ Use as a reference for the new API. ~ Move private structure from the .h to the .c. * ts_filter_group.c ~ Update to use the new API. * ts_filter_median.c ~ Update to use the new API. * ts_filter_linear.c ~ Remove functions that are no longer needed. Note: I might leave some TODOs and FIXMEs with this patch. Most of them will be removed shortly. Signed-off-by: Nelson Castillo <arhuaco@freaks-unidos.net>
Diffstat (limited to 'drivers/input/touchscreen/ts_filter_linear.c')
-rw-r--r--drivers/input/touchscreen/ts_filter_linear.c87
1 files changed, 55 insertions, 32 deletions
diff --git a/drivers/input/touchscreen/ts_filter_linear.c b/drivers/input/touchscreen/ts_filter_linear.c
index c336252d0ff..72a362f7567 100644
--- a/drivers/input/touchscreen/ts_filter_linear.c
+++ b/drivers/input/touchscreen/ts_filter_linear.c
@@ -13,7 +13,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Copyright (C) 2008 by Openmoko, Inc.
+ * Copyright (C) 2008,2009 by Openmoko, Inc.
* Author: Nelson Castillo <arhuaco@freaks-unidos.net>
* All rights reserved.
*
@@ -29,9 +29,52 @@
#include <linux/slab.h>
#include <linux/string.h>
+struct ts_filter_linear;
-/* sysfs functions */
+/* Sysfs. */
+/* FIXME: Comment all structure attributes. */
+
+struct const_obj {
+ struct ts_filter_linear *tsfl;
+ struct kobject kobj;
+};
+
+#define to_const_obj(x) container_of(x, struct const_obj, kobj)
+
+struct const_attribute {
+ struct attribute attr;
+ ssize_t (*show)(struct const_obj *const, struct const_attribute *attr,
+ char *buf);
+ ssize_t (*store)(struct const_obj *const, struct const_attribute *attr,
+ const char *buf, size_t count);
+};
+
+#define to_const_attr(x) container_of(x, struct const_attribute, attr)
+
+
+/* Private linear filter structure. */
+
+struct ts_filter_linear {
+ struct ts_filter tsf; /* TODO: don't use as first */
+
+ struct ts_filter_linear_configuration *config;
+
+
+ int constants[TS_FILTER_LINEAR_NCONSTANTS];
+
+ /* Sysfs. */
+ struct const_obj c_obj;
+ struct kobj_type const_ktype;
+ struct const_attribute kattrs[TS_FILTER_LINEAR_NCONSTANTS];
+ struct attribute *attrs[TS_FILTER_LINEAR_NCONSTANTS + 1];
+ char attr_names[TS_FILTER_LINEAR_NCONSTANTS][2];
+};
+
+#define ts_filter_to_filter_linear(f) \
+ container_of(f, struct ts_filter_linear, tsf)
+
+/* Sysfs functions. */
static ssize_t const_attr_show(struct kobject *kobj,
struct attribute *attr,
@@ -80,7 +123,7 @@ static ssize_t const_store(struct const_obj *obj, struct const_attribute *attr,
return count;
}
-/* filter functions */
+/* Filter functions. */
static struct ts_filter *ts_filter_linear_create(struct platform_device *pdev,
void *conf, int count_coords)
@@ -121,53 +164,33 @@ static struct ts_filter *ts_filter_linear_create(struct platform_device *pdev,
return NULL;
}
- printk(KERN_INFO" Created Linear ts filter depth %d\n", count_coords);
+ dev_info(&pdev->dev, "Created Linear filter coords:%d\n", count_coords);
return &tsfl->tsf;
}
-static void ts_filter_linear_destroy(struct platform_device *pdev,
- struct ts_filter *tsf)
+static void ts_filter_linear_destroy(struct ts_filter *tsf)
{
- struct ts_filter_linear *tsfl = (struct ts_filter_linear *)tsf;
+ struct ts_filter_linear *tsfl = ts_filter_to_filter_linear(tsf);
- /* kernel frees tsfl in const_release */
+ /* Kernel frees tsfl in const_release. */
kobject_put(&tsfl->c_obj.kobj);
}
-static void ts_filter_linear_clear(struct ts_filter *tsf)
-{
- if (tsf->next) /* chain */
- (tsf->next->api->clear)(tsf->next);
-}
-
-
static void ts_filter_linear_scale(struct ts_filter *tsf, int *coords)
{
- struct ts_filter_linear *tsfl = (struct ts_filter_linear *)tsf;
+ struct ts_filter_linear *tsfl = ts_filter_to_filter_linear(tsf);
+
int *k = tsfl->constants;
int c0 = coords[tsfl->config->coord0];
int c1 = coords[tsfl->config->coord1];
coords[tsfl->config->coord0] = (k[2] + k[0] * c0 + k[1] * c1) / k[6];
coords[tsfl->config->coord1] = (k[5] + k[3] * c0 + k[4] * c1) / k[6];
-
- if (tsf->next)
- (tsf->next->api->scale)(tsf->next, coords);
-}
-
-static int ts_filter_linear_process(struct ts_filter *tsf, int *coords)
-{
- if (tsf->next)
- return (tsf->next->api->process)(tsf->next, coords);
-
- return 1;
}
struct ts_filter_api ts_filter_linear_api = {
- .create = ts_filter_linear_create,
- .destroy = ts_filter_linear_destroy,
- .clear = ts_filter_linear_clear,
- .process = ts_filter_linear_process,
- .scale = ts_filter_linear_scale,
+ .create = ts_filter_linear_create,
+ .destroy = ts_filter_linear_destroy,
+ .scale = ts_filter_linear_scale,
};