@@ -47,9 +47,8 @@ MODULE_PARM_DESC(flip_y, "flip y coordinate");
4747struct eeti_ts {
4848 struct i2c_client * client ;
4949 struct input_dev * input ;
50- struct work_struct work ;
51- struct mutex mutex ;
5250 int irq_gpio , irq_active_high ;
51+ bool running ;
5352};
5453
5554#define EETI_TS_BITDEPTH (11)
@@ -66,29 +65,11 @@ static inline int eeti_ts_irq_active(struct eeti_ts *eeti)
6665 return gpio_get_value_cansleep (eeti -> irq_gpio ) == eeti -> irq_active_high ;
6766}
6867
69- static void eeti_ts_read (struct work_struct * work )
68+ static void eeti_ts_report_event (struct eeti_ts * eeti , u8 * buf )
7069{
71- char buf [6 ];
72- unsigned int x , y , res , pressed , to = 100 ;
73- struct eeti_ts * eeti =
74- container_of (work , struct eeti_ts , work );
75-
76- mutex_lock (& eeti -> mutex );
77-
78- while (eeti_ts_irq_active (eeti ) && -- to )
79- i2c_master_recv (eeti -> client , buf , sizeof (buf ));
80-
81- if (!to ) {
82- dev_err (& eeti -> client -> dev ,
83- "unable to clear IRQ - line stuck?\n" );
84- goto out ;
85- }
70+ unsigned int res ;
71+ u16 x , y ;
8672
87- /* drop non-report packets */
88- if (!(buf [0 ] & 0x80 ))
89- goto out ;
90-
91- pressed = buf [0 ] & REPORT_BIT_PRESSED ;
9273 res = REPORT_RES_BITS (buf [0 ] & (REPORT_BIT_AD0 | REPORT_BIT_AD1 ));
9374
9475 x = get_unaligned_be16 (& buf [1 ]);
@@ -109,35 +90,48 @@ static void eeti_ts_read(struct work_struct *work)
10990
11091 input_report_abs (eeti -> input , ABS_X , x );
11192 input_report_abs (eeti -> input , ABS_Y , y );
112- input_report_key (eeti -> input , BTN_TOUCH , !! pressed );
93+ input_report_key (eeti -> input , BTN_TOUCH , buf [ 0 ] & REPORT_BIT_PRESSED );
11394 input_sync (eeti -> input );
114-
115- out :
116- mutex_unlock (& eeti -> mutex );
11795}
11896
11997static irqreturn_t eeti_ts_isr (int irq , void * dev_id )
12098{
12199 struct eeti_ts * eeti = dev_id ;
100+ int len ;
101+ int error ;
102+ char buf [6 ];
122103
123- /* postpone I2C transactions as we are atomic */
124- schedule_work (& eeti -> work );
104+ do {
105+ len = i2c_master_recv (eeti -> client , buf , sizeof (buf ));
106+ if (len != sizeof (buf )) {
107+ error = len < 0 ? len : - EIO ;
108+ dev_err (& eeti -> client -> dev ,
109+ "failed to read touchscreen data: %d\n" ,
110+ error );
111+ break ;
112+ }
113+
114+ if (buf [0 ] & 0x80 ) {
115+ /* Motion packet */
116+ eeti_ts_report_event (eeti , buf );
117+ }
118+ } while (eeti -> running && eeti_ts_irq_active (eeti ));
125119
126120 return IRQ_HANDLED ;
127121}
128122
129123static void eeti_ts_start (struct eeti_ts * eeti )
130124{
125+ eeti -> running = true;
126+ wmb ();
131127 enable_irq (eeti -> client -> irq );
132-
133- /* Read the events once to arm the IRQ */
134- eeti_ts_read (& eeti -> work );
135128}
136129
137130static void eeti_ts_stop (struct eeti_ts * eeti )
138131{
132+ eeti -> running = false;
133+ wmb ();
139134 disable_irq (eeti -> client -> irq );
140- cancel_work_sync (& eeti -> work );
141135}
142136
143137static int eeti_ts_open (struct input_dev * dev )
@@ -179,8 +173,6 @@ static int eeti_ts_probe(struct i2c_client *client,
179173 return - ENOMEM ;
180174 }
181175
182- mutex_init (& eeti -> mutex );
183-
184176 input = devm_input_allocate_device (dev );
185177 if (!input ) {
186178 dev_err (dev , "Failed to allocate input device.\n" );
@@ -210,18 +202,15 @@ static int eeti_ts_probe(struct i2c_client *client,
210202 eeti -> irq_active_high = pdata -> irq_active_high ;
211203
212204 irq_flags = eeti -> irq_active_high ?
213- IRQF_TRIGGER_RISING : IRQF_TRIGGER_FALLING ;
205+ IRQF_TRIGGER_HIGH : IRQF_TRIGGER_LOW ;
214206
215- INIT_WORK (& eeti -> work , eeti_ts_read );
216207 i2c_set_clientdata (client , eeti );
217208 input_set_drvdata (input , eeti );
218209
219- error = input_register_device (input );
220- if (error )
221- return error ;
222-
223- error = devm_request_irq (dev , client -> irq , eeti_ts_isr , irq_flags ,
224- client -> name , eeti );
210+ error = devm_request_threaded_irq (dev , client -> irq ,
211+ NULL , eeti_ts_isr ,
212+ irq_flags | IRQF_ONESHOT ,
213+ client -> name , eeti );
225214 if (error ) {
226215 dev_err (dev , "Unable to request touchscreen IRQ: %d\n" ,
227216 error );
@@ -234,6 +223,10 @@ static int eeti_ts_probe(struct i2c_client *client,
234223 */
235224 eeti_ts_stop (eeti );
236225
226+ error = input_register_device (input );
227+ if (error )
228+ return error ;
229+
237230 return 0 ;
238231}
239232
0 commit comments