* [PATCH 1/2] touchscreen/ads7846.c: Alloc filter data only when needed.
@ 2012-10-24 11:38 Matthias Brugger
2012-10-24 11:38 ` [PATCH 2/2] touchscreen/ads7846.c: move filter variables to global include Matthias Brugger
2012-10-24 18:21 ` [PATCH 1/2] touchscreen/ads7846.c: Alloc filter data only when needed Dmitry Torokhov
0 siblings, 2 replies; 4+ messages in thread
From: Matthias Brugger @ 2012-10-24 11:38 UTC (permalink / raw)
To: Dmitry Torokhov, linux-input, grinberg; +Cc: Matthias Brugger
This patch encapsulates the variables used by the default debounce
filter in a struct. The values are allocated only if the debounce filter
is used by the platform.
Signed-off-by: Matthias Brugger <matthias.bgg@gmail.com>
---
drivers/input/touchscreen/ads7846.c | 42 ++++++++++++++++++++++-------------
1 file changed, 27 insertions(+), 15 deletions(-)
diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c
index f02028e..9e61a4b 100644
--- a/drivers/input/touchscreen/ads7846.c
+++ b/drivers/input/touchscreen/ads7846.c
@@ -90,6 +90,15 @@ struct ads7846_packet {
u8 read_x_cmd[3], read_y_cmd[3], pwrdown_cmd[3];
};
+struct ads7846_filterd {
+ int read_cnt;
+ int read_rep;
+ int last_read;
+ u16 debounce_max;
+ u16 debounce_tol;
+ u16 debounce_rep;
+};
+
struct ads7846 {
struct input_dev *input;
char phys[32];
@@ -121,14 +130,6 @@ struct ads7846 {
bool pendown;
- int read_cnt;
- int read_rep;
- int last_read;
-
- u16 debounce_max;
- u16 debounce_tol;
- u16 debounce_rep;
-
u16 penirq_recheck_delay_usecs;
struct mutex lock;
@@ -643,9 +644,14 @@ static void null_wait_for_sync(void)
{
}
+static void ads7864_filter_cleanup(void *data)
+{
+ kfree(data);
+}
+
static int ads7846_debounce_filter(void *ads, int data_idx, int *val)
{
- struct ads7846 *ts = ads;
+ struct ads7846_filterd *ts = (struct ads7846_filterd*) ads;
if (!ts->read_cnt || (abs(ts->last_read - *val) > ts->debounce_tol)) {
/* Start over collecting consistent readings. */
@@ -1261,13 +1267,19 @@ static int __devinit ads7846_probe(struct spi_device *spi)
ts->filter = pdata->filter;
ts->filter_cleanup = pdata->filter_cleanup;
} else if (pdata->debounce_max) {
- ts->debounce_max = pdata->debounce_max;
- if (ts->debounce_max < 2)
- ts->debounce_max = 2;
- ts->debounce_tol = pdata->debounce_tol;
- ts->debounce_rep = pdata->debounce_rep;
+ struct ads7846_filterd *fdata = kmalloc(sizeof(struct ads7846_filterd), GFP_KERNEL);
+ if (!fdata) {
+ err = -ENOMEM;
+ goto err_free_mem;
+ }
+ fdata->debounce_max = pdata->debounce_max;
+ if (fdata->debounce_max < 2)
+ fdata->debounce_max = 2;
+ fdata->debounce_tol = pdata->debounce_tol;
+ fdata->debounce_rep = pdata->debounce_rep;
ts->filter = ads7846_debounce_filter;
- ts->filter_data = ts;
+ ts->filter_cleanup = ads7864_filter_cleanup;
+ ts->filter_data = fdata;
} else {
ts->filter = ads7846_no_filter;
}
--
1.7.9.5
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH 2/2] touchscreen/ads7846.c: move filter variables to global include
2012-10-24 11:38 [PATCH 1/2] touchscreen/ads7846.c: Alloc filter data only when needed Matthias Brugger
@ 2012-10-24 11:38 ` Matthias Brugger
2012-10-24 18:17 ` Dmitry Torokhov
2012-10-24 18:21 ` [PATCH 1/2] touchscreen/ads7846.c: Alloc filter data only when needed Dmitry Torokhov
1 sibling, 1 reply; 4+ messages in thread
From: Matthias Brugger @ 2012-10-24 11:38 UTC (permalink / raw)
To: Dmitry Torokhov, linux-input, grinberg; +Cc: Matthias Brugger
To implement a custom filter in the board platform code,
the struct ads7846_filterd might be needed. This patch moves the struct
to the global include file of the driver.
Signed-off-by: Matthias Brugger <matthias.bgg@gmail.com>
---
drivers/input/touchscreen/ads7846.c | 9 ---------
include/linux/spi/ads7846.h | 9 +++++++++
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c
index 9e61a4b..cc3b048 100644
--- a/drivers/input/touchscreen/ads7846.c
+++ b/drivers/input/touchscreen/ads7846.c
@@ -90,15 +90,6 @@ struct ads7846_packet {
u8 read_x_cmd[3], read_y_cmd[3], pwrdown_cmd[3];
};
-struct ads7846_filterd {
- int read_cnt;
- int read_rep;
- int last_read;
- u16 debounce_max;
- u16 debounce_tol;
- u16 debounce_rep;
-};
-
struct ads7846 {
struct input_dev *input;
char phys[32];
diff --git a/include/linux/spi/ads7846.h b/include/linux/spi/ads7846.h
index c64de9d..cc7b34d 100644
--- a/include/linux/spi/ads7846.h
+++ b/include/linux/spi/ads7846.h
@@ -58,3 +58,12 @@ struct ads7846_platform_data {
unsigned long irq_flags;
};
+struct ads7846_filterd {
+ int read_cnt;
+ int read_rep;
+ int last_read;
+ u16 debounce_max;
+ u16 debounce_tol;
+ u16 debounce_rep;
+};
+
--
1.7.9.5
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH 2/2] touchscreen/ads7846.c: move filter variables to global include
2012-10-24 11:38 ` [PATCH 2/2] touchscreen/ads7846.c: move filter variables to global include Matthias Brugger
@ 2012-10-24 18:17 ` Dmitry Torokhov
0 siblings, 0 replies; 4+ messages in thread
From: Dmitry Torokhov @ 2012-10-24 18:17 UTC (permalink / raw)
To: Matthias Brugger; +Cc: linux-input, grinberg, Matthias Brugger
On Wed, Oct 24, 2012 at 01:38:56PM +0200, Matthias Brugger wrote:
> To implement a custom filter in the board platform code,
> the struct ads7846_filterd might be needed. This patch moves the struct
> to the global include file of the driver.
Why would a custom filer care about debounce filter's private data?
Just have it define its very own structure, no need to export.
Thanks.
>
> Signed-off-by: Matthias Brugger <matthias.bgg@gmail.com>
> ---
> drivers/input/touchscreen/ads7846.c | 9 ---------
> include/linux/spi/ads7846.h | 9 +++++++++
> 2 files changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c
> index 9e61a4b..cc3b048 100644
> --- a/drivers/input/touchscreen/ads7846.c
> +++ b/drivers/input/touchscreen/ads7846.c
> @@ -90,15 +90,6 @@ struct ads7846_packet {
> u8 read_x_cmd[3], read_y_cmd[3], pwrdown_cmd[3];
> };
>
> -struct ads7846_filterd {
> - int read_cnt;
> - int read_rep;
> - int last_read;
> - u16 debounce_max;
> - u16 debounce_tol;
> - u16 debounce_rep;
> -};
> -
> struct ads7846 {
> struct input_dev *input;
> char phys[32];
> diff --git a/include/linux/spi/ads7846.h b/include/linux/spi/ads7846.h
> index c64de9d..cc7b34d 100644
> --- a/include/linux/spi/ads7846.h
> +++ b/include/linux/spi/ads7846.h
> @@ -58,3 +58,12 @@ struct ads7846_platform_data {
> unsigned long irq_flags;
> };
>
> +struct ads7846_filterd {
> + int read_cnt;
> + int read_rep;
> + int last_read;
> + u16 debounce_max;
> + u16 debounce_tol;
> + u16 debounce_rep;
> +};
> +
> --
> 1.7.9.5
>
--
Dmitry
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] touchscreen/ads7846.c: Alloc filter data only when needed.
2012-10-24 11:38 [PATCH 1/2] touchscreen/ads7846.c: Alloc filter data only when needed Matthias Brugger
2012-10-24 11:38 ` [PATCH 2/2] touchscreen/ads7846.c: move filter variables to global include Matthias Brugger
@ 2012-10-24 18:21 ` Dmitry Torokhov
1 sibling, 0 replies; 4+ messages in thread
From: Dmitry Torokhov @ 2012-10-24 18:21 UTC (permalink / raw)
To: Matthias Brugger; +Cc: linux-input, grinberg, Matthias Brugger
On Wed, Oct 24, 2012 at 01:38:55PM +0200, Matthias Brugger wrote:
> This patch encapsulates the variables used by the default debounce
> filter in a struct. The values are allocated only if the debounce filter
> is used by the platform.
>
> Signed-off-by: Matthias Brugger <matthias.bgg@gmail.com>
> ---
> drivers/input/touchscreen/ads7846.c | 42 ++++++++++++++++++++++-------------
> 1 file changed, 27 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c
> index f02028e..9e61a4b 100644
> --- a/drivers/input/touchscreen/ads7846.c
> +++ b/drivers/input/touchscreen/ads7846.c
> @@ -90,6 +90,15 @@ struct ads7846_packet {
> u8 read_x_cmd[3], read_y_cmd[3], pwrdown_cmd[3];
> };
>
> +struct ads7846_filterd {
> + int read_cnt;
> + int read_rep;
> + int last_read;
> + u16 debounce_max;
> + u16 debounce_tol;
> + u16 debounce_rep;
> +};
> +
> struct ads7846 {
> struct input_dev *input;
> char phys[32];
> @@ -121,14 +130,6 @@ struct ads7846 {
>
> bool pendown;
>
> - int read_cnt;
> - int read_rep;
> - int last_read;
> -
> - u16 debounce_max;
> - u16 debounce_tol;
> - u16 debounce_rep;
> -
> u16 penirq_recheck_delay_usecs;
>
> struct mutex lock;
> @@ -643,9 +644,14 @@ static void null_wait_for_sync(void)
> {
> }
>
> +static void ads7864_filter_cleanup(void *data)
> +{
> + kfree(data);
> +}
> +
> static int ads7846_debounce_filter(void *ads, int data_idx, int *val)
> {
> - struct ads7846 *ts = ads;
> + struct ads7846_filterd *ts = (struct ads7846_filterd*) ads;
>
> if (!ts->read_cnt || (abs(ts->last_read - *val) > ts->debounce_tol)) {
> /* Start over collecting consistent readings. */
> @@ -1261,13 +1267,19 @@ static int __devinit ads7846_probe(struct spi_device *spi)
> ts->filter = pdata->filter;
> ts->filter_cleanup = pdata->filter_cleanup;
> } else if (pdata->debounce_max) {
> - ts->debounce_max = pdata->debounce_max;
> - if (ts->debounce_max < 2)
> - ts->debounce_max = 2;
> - ts->debounce_tol = pdata->debounce_tol;
> - ts->debounce_rep = pdata->debounce_rep;
> + struct ads7846_filterd *fdata = kmalloc(sizeof(struct ads7846_filterd), GFP_KERNEL);
> + if (!fdata) {
> + err = -ENOMEM;
> + goto err_free_mem;
> + }
> + fdata->debounce_max = pdata->debounce_max;
> + if (fdata->debounce_max < 2)
> + fdata->debounce_max = 2;
> + fdata->debounce_tol = pdata->debounce_tol;
> + fdata->debounce_rep = pdata->debounce_rep;
> ts->filter = ads7846_debounce_filter;
> - ts->filter_data = ts;
> + ts->filter_cleanup = ads7864_filter_cleanup;
> + ts->filter_data = fdata;
So you are maybe saving 18 bytes if data in ads7846 at the expense
of more code... Not really see the great benefit. Maybe just embed
your new ads7846_debounce_data structure in ads7846 to provide logical
separation?
--
Dmitry
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-10-24 18:22 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-24 11:38 [PATCH 1/2] touchscreen/ads7846.c: Alloc filter data only when needed Matthias Brugger
2012-10-24 11:38 ` [PATCH 2/2] touchscreen/ads7846.c: move filter variables to global include Matthias Brugger
2012-10-24 18:17 ` Dmitry Torokhov
2012-10-24 18:21 ` [PATCH 1/2] touchscreen/ads7846.c: Alloc filter data only when needed Dmitry Torokhov
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.