Re: [patch 2/2] Touchscreen support for sharp sl-5500

2005-07-23 Thread Pavel Machek
Hi!

> > This adds support for touchscreen on Sharp Zaurus sl-5500. Vojtech,
> > please apply,
> 
> I have couple more commnets...

Sorry, I never really worked with kthreads. Applied all those, 

> > +static int ucb1x00_ts_open(struct input_dev *idev)
> > +{
> > +   struct ucb1x00_ts *ts = (struct ucb1x00_ts *)idev;
> > +   int ret = 0;
> > +   struct task_struct *task;
> > +
> > +   if (ts->rtask)
> > +   panic("ucb1x00: rtask running?");
> > +
> 
> Do you really need to panic here???

Does BUG_ON() seem better :-). We could also just return failure here,
but I do not see how it could happen => I guess I'd better catch it
with BUG().

Here's what I did, updated patch will follow.
Pavel

diff --git a/drivers/input/touchscreen/collie_ts.c 
b/drivers/input/touchscreen/collie_ts.c
--- a/drivers/input/touchscreen/collie_ts.c
+++ b/drivers/input/touchscreen/collie_ts.c
@@ -41,7 +41,6 @@ struct ucb1x00_ts {
struct ucb1x00  *ucb;
 
struct semaphoreirq_wait;
-   struct completion   init_exit;
struct task_struct  *rtask;
u16 x_res;
u16 y_res;
@@ -160,7 +159,6 @@ static int ucb1x00_thread(void *_ts)
int valid;
 
ts->rtask = tsk;
-   allow_signal(SIGKILL);
 
/*
 * We run as a real-time thread.  However, thus far
@@ -169,10 +167,7 @@ static int ucb1x00_thread(void *_ts)
tsk->policy = SCHED_FIFO;
tsk->rt_priority = 1;
 
-   complete(&ts->init_exit);
-
valid = 0;
-
for (;;) {
unsigned int x, y, p, val;
 
@@ -237,12 +232,12 @@ static int ucb1x00_thread(void *_ts)
msleep_interruptible(10);
}
 
-   if (signal_pending(tsk))
+   if (kthread_should_stop())
break;
}
 
ts->rtask = NULL;
-   complete_and_exit(&ts->init_exit, 0);
+   return 0;
 }
 
 /*
@@ -262,8 +257,7 @@ static int ucb1x00_ts_open(struct input_
int ret = 0;
struct task_struct *task;
 
-   if (ts->rtask)
-   panic("ucb1x00: rtask running?");
+   BUG_ON(ts->rtask);
 
sema_init(&ts->irq_wait, 0);
ret = ucb1x00_hook_irq(ts->ucb, UCB_IRQ_TSPX, ucb1x00_ts_irq, ts);
@@ -279,10 +273,8 @@ static int ucb1x00_ts_open(struct input_
ts->y_res = ucb1x00_ts_read_yres(ts);
ucb1x00_adc_disable(ts->ucb);
 
-   init_completion(&ts->init_exit);
task = kthread_run(ucb1x00_thread, ts, "ktsd");
if (!IS_ERR(task)) {
-   wait_for_completion(&ts->init_exit);
ret = 0;
} else {
ucb1x00_free_irq(ts->ucb, UCB_IRQ_TSPX, ts);
@@ -300,10 +292,8 @@ static void ucb1x00_ts_close(struct inpu
 {
struct ucb1x00_ts *ts = (struct ucb1x00_ts *)idev;
 
-   if (ts->rtask) {
-   send_sig(SIGKILL, ts->rtask, 1);
-   wait_for_completion(&ts->init_exit);
-   }
+   if (ts->rtask)
+   kthread_stop(ts->rtask);
 
ucb1x00_enable(ts->ucb);
ucb1x00_free_irq(ts->ucb, UCB_IRQ_TSPX, ts);



-- 
teflon -- maybe it is a trademark, but it should not be.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [patch 2/2] Touchscreen support for sharp sl-5500

2005-07-23 Thread Pavel Machek

This adds support for touchscreen on Sharp Zaurus sl-5500. Please
apply,
Pavel

Signed-off-by: Pavel Machek <[EMAIL PROTECTED]>

diff --git a/drivers/input/touchscreen/Kconfig 
b/drivers/input/touchscreen/Kconfig
--- a/drivers/input/touchscreen/Kconfig
+++ b/drivers/input/touchscreen/Kconfig
@@ -36,6 +36,15 @@ config TOUCHSCREEN_CORGI
  To compile this driver as a module, choose M here: the
  module will be called ads7846_ts.
 
+config TOUCHSCREEN_COLLIE
+   tristate "Collie touchscreen (for Sharp SL-5500)"
+   depends on MCP_UCB1200
+   help
+ Say Y here to enable the driver for the touchscreen on the 
+ Sharp SL-5500 series of PDAs.
+
+ If unsure, say N.
+
 config TOUCHSCREEN_GUNZE
tristate "Gunze AHL-51S touchscreen"
select SERIO
diff --git a/drivers/input/touchscreen/Makefile 
b/drivers/input/touchscreen/Makefile
--- a/drivers/input/touchscreen/Makefile
+++ b/drivers/input/touchscreen/Makefile
@@ -6,6 +6,7 @@
 
 obj-$(CONFIG_TOUCHSCREEN_BITSY)+= h3600_ts_input.o
 obj-$(CONFIG_TOUCHSCREEN_CORGI)+= corgi_ts.o
+obj-$(CONFIG_TOUCHSCREEN_COLLIE)+= collie_ts.o
 obj-$(CONFIG_TOUCHSCREEN_GUNZE)+= gunze.o
 obj-$(CONFIG_TOUCHSCREEN_ELO)  += elo.o
 obj-$(CONFIG_TOUCHSCREEN_MTOUCH) += mtouch.o
diff --git a/drivers/input/touchscreen/collie_ts.c 
b/drivers/input/touchscreen/collie_ts.c
new file mode 100644
--- /dev/null
+++ b/drivers/input/touchscreen/collie_ts.c
@@ -0,0 +1,367 @@
+/*
+ *  linux/drivers/input/touchscreen/collie_ts.c
+ *
+ *  Copyright (C) 2001 Russell King, 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 version 2 as
+ * published by the Free Software Foundation.
+ *
+ * 21-Jan-2002 <[EMAIL PROTECTED]> :
+ *
+ * Added support for synchronous A/D mode. This mode is useful to
+ * avoid noise induced in the touchpanel by the LCD, provided that
+ * the UCB1x00 has a valid LCD sync signal routed to its ADCSYNC pin.
+ * It is important to note that the signal connected to the ADCSYNC
+ * pin should provide pulses even when the LCD is blanked, otherwise
+ * a pen touch needed to unblank the LCD will never be read.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+#include 
+
+
+struct ucb1x00_ts {
+   struct input_devidev;
+   struct ucb1x00  *ucb;
+
+   struct semaphoreirq_wait;
+   struct task_struct  *rtask;
+   u16 x_res;
+   u16 y_res;
+
+   int restart:1;
+   int adcsync:1;
+};
+
+/*
+ * Switch to interrupt mode.
+ */
+static inline void ucb1x00_ts_mode_int(struct ucb1x00_ts *ts)
+{
+   int val = UCB_TS_CR_TSMX_POW | UCB_TS_CR_TSPX_POW |
+ UCB_TS_CR_TSMY_GND | UCB_TS_CR_TSPY_GND |
+ UCB_TS_CR_MODE_INT;
+   if (ts->ucb->id == UCB_ID_1400_BUGGY)
+   val &= ~(UCB_TS_CR_TSMX_POW | UCB_TS_CR_TSPX_POW);
+   ucb1x00_reg_write(ts->ucb, UCB_TS_CR, val);
+}
+
+/*
+ * Switch to pressure mode, and read pressure.  We don't need to wait
+ * here, since both plates are being driven.
+ */
+static inline unsigned int ucb1x00_ts_read_pressure(struct ucb1x00_ts *ts)
+{
+   ucb1x00_reg_write(ts->ucb, UCB_TS_CR,
+   UCB_TS_CR_TSMX_POW | UCB_TS_CR_TSPX_POW |
+   UCB_TS_CR_TSMY_GND | UCB_TS_CR_TSPY_GND |
+   UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA);
+
+   return ucb1x00_adc_read(ts->ucb, UCB_ADC_INP_TSPY, ts->adcsync);
+}
+
+/*
+ * Switch to X position mode and measure Y plate.  We switch the plate
+ * configuration in pressure mode, then switch to position mode.  This
+ * gives a faster response time.  Even so, we need to wait about 55us
+ * for things to stabilise.
+ */
+static inline unsigned int ucb1x00_ts_read_xpos(struct ucb1x00_ts *ts)
+{
+   ucb1x00_reg_write(ts->ucb, UCB_TS_CR,
+   UCB_TS_CR_TSMX_GND | UCB_TS_CR_TSPX_POW |
+   UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA);
+   ucb1x00_reg_write(ts->ucb, UCB_TS_CR,
+   UCB_TS_CR_TSMX_GND | UCB_TS_CR_TSPX_POW |
+   UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA);
+   ucb1x00_reg_write(ts->ucb, UCB_TS_CR,
+   UCB_TS_CR_TSMX_GND | UCB_TS_CR_TSPX_POW |
+   UCB_TS_CR_MODE_POS | UCB_TS_CR_BIAS_ENA);
+
+   udelay(55);
+
+   return ucb1x00_adc_read(ts->ucb, UCB_ADC_INP_TSPY, ts->adcsync);
+}
+
+/*
+ * Switch to Y position mode and measure X plate.  We switch the plate
+ * configuration in pressure mode, then switch to position mode.  This
+ * gives a faster response time.  Even so, we need to wait about 55us
+ *

Re: [patch 2/2] Touchscreen support for sharp sl-5500

2005-07-22 Thread Dmitry Torokhov
On Friday 22 July 2005 19:28, Pavel Machek wrote:
> This adds support for touchscreen on Sharp Zaurus sl-5500. Vojtech,
> please apply,

I have couple more commnets...

> +static int ucb1x00_thread(void *_ts)
> +{
> + struct ucb1x00_ts *ts = _ts;
> + struct task_struct *tsk = current;
> + int valid;
> +
> + ts->rtask = tsk;
> + allow_signal(SIGKILL);

This is not needed...

> +
> + /*
> +  * We run as a real-time thread.  However, thus far
> +  * this doesn't seem to be necessary.
> +  */
> + tsk->policy = SCHED_FIFO;
> + tsk->rt_priority = 1;
> +
> + complete(&ts->init_exit);
> +

Neither this one - kthread_create does not return until thread is actually
created and started.

> +
> + if (signal_pending(tsk))
> + break;

if (kthread_should_stop(..))
break;

> + }
> +
> + ts->rtask = NULL;
> + complete_and_exit(&ts->init_exit, 0);

This is not needed.

> +static int ucb1x00_ts_open(struct input_dev *idev)
> +{
> + struct ucb1x00_ts *ts = (struct ucb1x00_ts *)idev;
> + int ret = 0;
> + struct task_struct *task;
> +
> + if (ts->rtask)
> + panic("ucb1x00: rtask running?");
> +

Do you really need to panic here???

> +
> + init_completion(&ts->init_exit);
> + task = kthread_run(ucb1x00_thread, ts, "ktsd");
> + if (!IS_ERR(task)) {
> + wait_for_completion(&ts->init_exit);

Just call kthread_run() and kill that init_exit completion. 

> +static void ucb1x00_ts_close(struct input_dev *idev)
> +{
> + struct ucb1x00_ts *ts = (struct ucb1x00_ts *)idev;
> +
> + if (ts->rtask) {
> + send_sig(SIGKILL, ts->rtask, 1);
> + wait_for_completion(&ts->init_exit);

kthread_stop().

-- 
Dmitry
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[patch 2/2] Touchscreen support for sharp sl-5500

2005-07-22 Thread Pavel Machek
This adds support for touchscreen on Sharp Zaurus sl-5500. Vojtech,
please apply,

Signed-off-by: Pavel Machek <[EMAIL PROTECTED]>

diff --git a/drivers/input/touchscreen/Kconfig 
b/drivers/input/touchscreen/Kconfig
--- a/drivers/input/touchscreen/Kconfig
+++ b/drivers/input/touchscreen/Kconfig
@@ -36,6 +36,15 @@ config TOUCHSCREEN_CORGI
  To compile this driver as a module, choose M here: the
  module will be called ads7846_ts.
 
+config TOUCHSCREEN_COLLIE
+   tristate "Collie touchscreen (for Sharp SL-5500)"
+   depends on MCP_UCB1200
+   help
+ Say Y here to enable the driver for the touchscreen on the 
+ Sharp SL-5500 series of PDAs.
+
+ If unsure, say N.
+
 config TOUCHSCREEN_GUNZE
tristate "Gunze AHL-51S touchscreen"
select SERIO
diff --git a/drivers/input/touchscreen/Makefile 
b/drivers/input/touchscreen/Makefile
--- a/drivers/input/touchscreen/Makefile
+++ b/drivers/input/touchscreen/Makefile
@@ -6,6 +6,7 @@
 
 obj-$(CONFIG_TOUCHSCREEN_BITSY)+= h3600_ts_input.o
 obj-$(CONFIG_TOUCHSCREEN_CORGI)+= corgi_ts.o
+obj-$(CONFIG_TOUCHSCREEN_COLLIE)+= collie_ts.o
 obj-$(CONFIG_TOUCHSCREEN_GUNZE)+= gunze.o
 obj-$(CONFIG_TOUCHSCREEN_ELO)  += elo.o
 obj-$(CONFIG_TOUCHSCREEN_MTOUCH) += mtouch.o
diff --git a/drivers/input/touchscreen/collie_ts.c 
b/drivers/input/touchscreen/collie_ts.c
new file mode 100644
--- /dev/null
+++ b/drivers/input/touchscreen/collie_ts.c
@@ -0,0 +1,377 @@
+/*
+ *  linux/drivers/input/touchscreen/collie_ts.c
+ *
+ *  Copyright (C) 2001 Russell King, 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 version 2 as
+ * published by the Free Software Foundation.
+ *
+ * 21-Jan-2002 <[EMAIL PROTECTED]> :
+ *
+ * Added support for synchronous A/D mode. This mode is useful to
+ * avoid noise induced in the touchpanel by the LCD, provided that
+ * the UCB1x00 has a valid LCD sync signal routed to its ADCSYNC pin.
+ * It is important to note that the signal connected to the ADCSYNC
+ * pin should provide pulses even when the LCD is blanked, otherwise
+ * a pen touch needed to unblank the LCD will never be read.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+#include 
+
+
+struct ucb1x00_ts {
+   struct input_devidev;
+   struct ucb1x00  *ucb;
+
+   struct semaphoreirq_wait;
+   struct completion   init_exit;
+   struct task_struct  *rtask;
+   u16 x_res;
+   u16 y_res;
+
+   int restart:1;
+   int adcsync:1;
+};
+
+/*
+ * Switch to interrupt mode.
+ */
+static inline void ucb1x00_ts_mode_int(struct ucb1x00_ts *ts)
+{
+   int val = UCB_TS_CR_TSMX_POW | UCB_TS_CR_TSPX_POW |
+ UCB_TS_CR_TSMY_GND | UCB_TS_CR_TSPY_GND |
+ UCB_TS_CR_MODE_INT;
+   if (ts->ucb->id == UCB_ID_1400_BUGGY)
+   val &= ~(UCB_TS_CR_TSMX_POW | UCB_TS_CR_TSPX_POW);
+   ucb1x00_reg_write(ts->ucb, UCB_TS_CR, val);
+}
+
+/*
+ * Switch to pressure mode, and read pressure.  We don't need to wait
+ * here, since both plates are being driven.
+ */
+static inline unsigned int ucb1x00_ts_read_pressure(struct ucb1x00_ts *ts)
+{
+   ucb1x00_reg_write(ts->ucb, UCB_TS_CR,
+   UCB_TS_CR_TSMX_POW | UCB_TS_CR_TSPX_POW |
+   UCB_TS_CR_TSMY_GND | UCB_TS_CR_TSPY_GND |
+   UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA);
+
+   return ucb1x00_adc_read(ts->ucb, UCB_ADC_INP_TSPY, ts->adcsync);
+}
+
+/*
+ * Switch to X position mode and measure Y plate.  We switch the plate
+ * configuration in pressure mode, then switch to position mode.  This
+ * gives a faster response time.  Even so, we need to wait about 55us
+ * for things to stabilise.
+ */
+static inline unsigned int ucb1x00_ts_read_xpos(struct ucb1x00_ts *ts)
+{
+   ucb1x00_reg_write(ts->ucb, UCB_TS_CR,
+   UCB_TS_CR_TSMX_GND | UCB_TS_CR_TSPX_POW |
+   UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA);
+   ucb1x00_reg_write(ts->ucb, UCB_TS_CR,
+   UCB_TS_CR_TSMX_GND | UCB_TS_CR_TSPX_POW |
+   UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA);
+   ucb1x00_reg_write(ts->ucb, UCB_TS_CR,
+   UCB_TS_CR_TSMX_GND | UCB_TS_CR_TSPX_POW |
+   UCB_TS_CR_MODE_POS | UCB_TS_CR_BIAS_ENA);
+
+   udelay(55);
+
+   return ucb1x00_adc_read(ts->ucb, UCB_ADC_INP_TSPY, ts->adcsync);
+}
+
+/*
+ * Switch to Y position mode and measure X plate.  We switch the plate
+ * configuration in pressure mode, then switch to position mode.  This
+ * gives a faster response time.  Even so, we need to wait about 55us
+ * for things