S3C: Backported openmoko's touchscreen filters
[linux-2.6/mini2440.git] / drivers / input / touchscreen / ts_filter.c
blob832844da55f7695ee9cbfa7ab53b8763fa4c0ba3
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 * Copyright (c) 2008 Andy Green <andy@openmoko.com>
19 #include <linux/kernel.h>
20 #include <linux/device.h>
21 #include "ts_filter.h"
23 static DEFINE_MUTEX(chain_mutex);
25 int ts_filter_create_chain(struct platform_device *pdev,
26 struct ts_filter_api **api, void **config,
27 struct ts_filter **arr, int count_coords)
29 int count = 0;
30 struct ts_filter *last = NULL;
32 if (!api)
33 return 0;
35 mutex_lock(&chain_mutex);
37 while (*api) {
38 *arr = ((*api)->create)(pdev, *config++, count_coords);
39 if (!*arr) {
40 printk(KERN_ERR "Filter %d failed init\n", count);
41 return count;
43 (*arr)->api = *api++;
44 if (last)
45 last->next = *arr;
46 last = *arr;
47 arr++;
48 count++;
51 mutex_unlock(&chain_mutex);
53 return count;
55 EXPORT_SYMBOL_GPL(ts_filter_create_chain);
57 void ts_filter_destroy_chain(struct platform_device *pdev,
58 struct ts_filter **arr)
60 struct ts_filter **first = arr;
62 mutex_lock(&chain_mutex);
64 while (*arr) {
65 ((*arr)->api->destroy)(pdev, *arr);
66 arr++;
68 *first = NULL;
70 mutex_unlock(&chain_mutex);
72 EXPORT_SYMBOL_GPL(ts_filter_destroy_chain);