Blame view
drivers/mfd/ucb1x00-ts.c
10.7 KB
d2912cb15 treewide: Replace... |
1 |
// SPDX-License-Identifier: GPL-2.0-only |
acb45439a [MFD] Add code UC... |
2 |
/* |
5437775e0 [MFD] Cleanups su... |
3 |
* Touchscreen driver for UCB1x00-based touchscreens |
acb45439a [MFD] Add code UC... |
4 5 |
* * Copyright (C) 2001 Russell King, All Rights Reserved. |
5437775e0 [MFD] Cleanups su... |
6 |
* Copyright (C) 2005 Pavel Machek |
acb45439a [MFD] Add code UC... |
7 |
* |
acb45439a [MFD] Add code UC... |
8 9 10 11 12 13 14 15 16 |
* 21-Jan-2002 <jco@ict.es> : * * 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. */ |
acb45439a [MFD] Add code UC... |
17 18 19 |
#include <linux/module.h> #include <linux/moduleparam.h> #include <linux/init.h> |
a3364409c MFD: ucb1x00: con... |
20 |
#include <linux/interrupt.h> |
acb45439a [MFD] Add code UC... |
21 |
#include <linux/sched.h> |
a3364409c MFD: ucb1x00: con... |
22 |
#include <linux/spinlock.h> |
acb45439a [MFD] Add code UC... |
23 24 25 26 27 |
#include <linux/completion.h> #include <linux/delay.h> #include <linux/string.h> #include <linux/input.h> #include <linux/device.h> |
7dfb71030 [PATCH] Add inclu... |
28 |
#include <linux/freezer.h> |
acb45439a [MFD] Add code UC... |
29 |
#include <linux/slab.h> |
5437775e0 [MFD] Cleanups su... |
30 |
#include <linux/kthread.h> |
c8602edf3 move drivers/mfd/... |
31 |
#include <linux/mfd/ucb1x00.h> |
acb45439a [MFD] Add code UC... |
32 |
|
a09e64fbc [ARM] Move includ... |
33 |
#include <mach/collie.h> |
175329894 [ARM] Sharp sl-55... |
34 |
#include <asm/mach-types.h> |
acb45439a [MFD] Add code UC... |
35 |
|
acb45439a [MFD] Add code UC... |
36 37 38 |
struct ucb1x00_ts { |
bd6226631 [PATCH] Input: co... |
39 |
struct input_dev *idev; |
acb45439a [MFD] Add code UC... |
40 |
struct ucb1x00 *ucb; |
a3364409c MFD: ucb1x00: con... |
41 42 |
spinlock_t irq_lock; unsigned irq_disabled; |
acb45439a [MFD] Add code UC... |
43 |
wait_queue_head_t irq_wait; |
acb45439a [MFD] Add code UC... |
44 |
struct task_struct *rtask; |
acb45439a [MFD] Add code UC... |
45 46 |
u16 x_res; u16 y_res; |
6b9ea4213 [MFD] Fix "bious ... |
47 |
unsigned int adcsync:1; |
acb45439a [MFD] Add code UC... |
48 49 50 51 52 53 |
}; static int adcsync; static inline void ucb1x00_ts_evt_add(struct ucb1x00_ts *ts, u16 pressure, u16 x, u16 y) { |
1393c3edc [PATCH] input: fi... |
54 |
struct input_dev *idev = ts->idev; |
08c67d2a5 [PATCH] ucb1x00-t... |
55 |
|
1393c3edc [PATCH] input: fi... |
56 57 58 |
input_report_abs(idev, ABS_X, x); input_report_abs(idev, ABS_Y, y); input_report_abs(idev, ABS_PRESSURE, pressure); |
de8c8b068 mfd: Add BTN_TOUC... |
59 |
input_report_key(idev, BTN_TOUCH, 1); |
1393c3edc [PATCH] input: fi... |
60 |
input_sync(idev); |
acb45439a [MFD] Add code UC... |
61 62 63 64 |
} static inline void ucb1x00_ts_event_release(struct ucb1x00_ts *ts) { |
1393c3edc [PATCH] input: fi... |
65 |
struct input_dev *idev = ts->idev; |
08c67d2a5 [PATCH] ucb1x00-t... |
66 |
|
1393c3edc [PATCH] input: fi... |
67 |
input_report_abs(idev, ABS_PRESSURE, 0); |
de8c8b068 mfd: Add BTN_TOUC... |
68 |
input_report_key(idev, BTN_TOUCH, 0); |
1393c3edc [PATCH] input: fi... |
69 |
input_sync(idev); |
acb45439a [MFD] Add code UC... |
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
} /* * Switch to interrupt mode. */ static inline void ucb1x00_ts_mode_int(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_INT); } /* * 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) { |
175329894 [ARM] Sharp sl-55... |
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
if (machine_is_collie()) { ucb1x00_io_write(ts->ucb, COLLIE_TC35143_GPIO_TBL_CHK, 0); ucb1x00_reg_write(ts->ucb, UCB_TS_CR, UCB_TS_CR_TSPX_POW | UCB_TS_CR_TSMX_POW | UCB_TS_CR_MODE_POS | UCB_TS_CR_BIAS_ENA); udelay(55); return ucb1x00_adc_read(ts->ucb, UCB_ADC_INP_AD2, ts->adcsync); } else { 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); } |
acb45439a [MFD] Add code UC... |
106 107 108 109 110 111 112 113 114 115 |
} /* * 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) { |
175329894 [ARM] Sharp sl-55... |
116 117 118 119 120 121 122 123 124 125 |
if (machine_is_collie()) ucb1x00_io_write(ts->ucb, 0, COLLIE_TC35143_GPIO_TBL_CHK); else { 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); } |
acb45439a [MFD] Add code UC... |
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
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 to stabilise. */ static inline unsigned int ucb1x00_ts_read_ypos(struct ucb1x00_ts *ts) { |
175329894 [ARM] Sharp sl-55... |
143 144 145 146 147 148 149 150 151 152 |
if (machine_is_collie()) ucb1x00_io_write(ts->ucb, 0, COLLIE_TC35143_GPIO_TBL_CHK); else { ucb1x00_reg_write(ts->ucb, UCB_TS_CR, UCB_TS_CR_TSMY_GND | UCB_TS_CR_TSPY_POW | UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA); ucb1x00_reg_write(ts->ucb, UCB_TS_CR, UCB_TS_CR_TSMY_GND | UCB_TS_CR_TSPY_POW | UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA); } |
acb45439a [MFD] Add code UC... |
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
ucb1x00_reg_write(ts->ucb, UCB_TS_CR, UCB_TS_CR_TSMY_GND | UCB_TS_CR_TSPY_POW | UCB_TS_CR_MODE_POS | UCB_TS_CR_BIAS_ENA); udelay(55); return ucb1x00_adc_read(ts->ucb, UCB_ADC_INP_TSPX, ts->adcsync); } /* * Switch to X plate resistance mode. Set MX to ground, PX to * supply. Measure current. */ static inline unsigned int ucb1x00_ts_read_xres(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); return ucb1x00_adc_read(ts->ucb, 0, ts->adcsync); } /* * Switch to Y plate resistance mode. Set MY to ground, PY to * supply. Measure current. */ static inline unsigned int ucb1x00_ts_read_yres(struct ucb1x00_ts *ts) { ucb1x00_reg_write(ts->ucb, UCB_TS_CR, UCB_TS_CR_TSMY_GND | UCB_TS_CR_TSPY_POW | UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA); return ucb1x00_adc_read(ts->ucb, 0, ts->adcsync); } |
175329894 [ARM] Sharp sl-55... |
185 186 187 |
static inline int ucb1x00_ts_pen_down(struct ucb1x00_ts *ts) { unsigned int val = ucb1x00_reg_read(ts->ucb, UCB_TS_CR); |
08c67d2a5 [PATCH] ucb1x00-t... |
188 |
|
175329894 [ARM] Sharp sl-55... |
189 190 191 192 193 |
if (machine_is_collie()) return (!(val & (UCB_TS_CR_TSPX_LOW))); else return (val & (UCB_TS_CR_TSPX_LOW | UCB_TS_CR_TSMX_LOW)); } |
acb45439a [MFD] Add code UC... |
194 195 196 197 198 199 200 201 |
/* * This is a RT kernel thread that handles the ADC accesses * (mainly so we can use semaphores in the UCB1200 core code * to serialise accesses to the ADC). */ static int ucb1x00_thread(void *_ts) { struct ucb1x00_ts *ts = _ts; |
f7440b0ec mfd: use shorter ... |
202 |
DECLARE_WAITQUEUE(wait, current); |
0af5e4c36 MFD: ucb1x00-ts: ... |
203 |
bool frozen, ignore = false; |
1124d5ca7 Input: ucb1x00-ts... |
204 |
int valid = 0; |
acb45439a [MFD] Add code UC... |
205 |
|
831441862 Freezer: make ker... |
206 |
set_freezable(); |
acb45439a [MFD] Add code UC... |
207 |
add_wait_queue(&ts->irq_wait, &wait); |
0af5e4c36 MFD: ucb1x00-ts: ... |
208 |
while (!kthread_freezable_should_stop(&frozen)) { |
175329894 [ARM] Sharp sl-55... |
209 |
unsigned int x, y, p; |
acb45439a [MFD] Add code UC... |
210 |
signed long timeout; |
0af5e4c36 MFD: ucb1x00-ts: ... |
211 212 |
if (frozen) ignore = true; |
acb45439a [MFD] Add code UC... |
213 214 215 216 217 218 219 220 221 222 223 224 |
ucb1x00_adc_enable(ts->ucb); x = ucb1x00_ts_read_xpos(ts); y = ucb1x00_ts_read_ypos(ts); p = ucb1x00_ts_read_pressure(ts); /* * Switch back to interrupt mode. */ ucb1x00_ts_mode_int(ts); ucb1x00_adc_disable(ts->ucb); |
5437775e0 [MFD] Cleanups su... |
225 |
msleep(10); |
acb45439a [MFD] Add code UC... |
226 227 |
ucb1x00_enable(ts->ucb); |
acb45439a [MFD] Add code UC... |
228 |
|
175329894 [ARM] Sharp sl-55... |
229 230 |
if (ucb1x00_ts_pen_down(ts)) { |
f7440b0ec mfd: use shorter ... |
231 |
set_current_state(TASK_INTERRUPTIBLE); |
acb45439a [MFD] Add code UC... |
232 |
|
a3364409c MFD: ucb1x00: con... |
233 234 235 236 237 238 |
spin_lock_irq(&ts->irq_lock); if (ts->irq_disabled) { ts->irq_disabled = 0; enable_irq(ts->ucb->irq_base + UCB_IRQ_TSPX); } spin_unlock_irq(&ts->irq_lock); |
acb45439a [MFD] Add code UC... |
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
ucb1x00_disable(ts->ucb); /* * If we spat out a valid sample set last time, * spit out a "pen off" sample here. */ if (valid) { ucb1x00_ts_event_release(ts); valid = 0; } timeout = MAX_SCHEDULE_TIMEOUT; } else { ucb1x00_disable(ts->ucb); /* * Filtering is policy. Policy belongs in user * space. We therefore leave it to user space * to do any filtering they please. */ |
0af5e4c36 MFD: ucb1x00-ts: ... |
259 |
if (!ignore) { |
acb45439a [MFD] Add code UC... |
260 261 262 |
ucb1x00_ts_evt_add(ts, p, x, y); valid = 1; } |
f7440b0ec mfd: use shorter ... |
263 |
set_current_state(TASK_INTERRUPTIBLE); |
acb45439a [MFD] Add code UC... |
264 265 |
timeout = HZ / 100; } |
acb45439a [MFD] Add code UC... |
266 |
schedule_timeout(timeout); |
acb45439a [MFD] Add code UC... |
267 268 269 270 271 |
} remove_wait_queue(&ts->irq_wait, &wait); ts->rtask = NULL; |
5437775e0 [MFD] Cleanups su... |
272 |
return 0; |
acb45439a [MFD] Add code UC... |
273 274 275 276 277 278 |
} /* * We only detect touch screen _touches_ with this interrupt * handler, and even then we just schedule our task. */ |
a3364409c MFD: ucb1x00: con... |
279 |
static irqreturn_t ucb1x00_ts_irq(int irq, void *id) |
acb45439a [MFD] Add code UC... |
280 281 |
{ struct ucb1x00_ts *ts = id; |
08c67d2a5 [PATCH] ucb1x00-t... |
282 |
|
a3364409c MFD: ucb1x00: con... |
283 284 285 286 |
spin_lock(&ts->irq_lock); ts->irq_disabled = 1; disable_irq_nosync(ts->ucb->irq_base + UCB_IRQ_TSPX); spin_unlock(&ts->irq_lock); |
acb45439a [MFD] Add code UC... |
287 |
wake_up(&ts->irq_wait); |
a3364409c MFD: ucb1x00: con... |
288 289 |
return IRQ_HANDLED; |
acb45439a [MFD] Add code UC... |
290 291 292 293 |
} static int ucb1x00_ts_open(struct input_dev *idev) { |
26be5a509 Input: ucb1x00 - ... |
294 |
struct ucb1x00_ts *ts = input_get_drvdata(idev); |
a3364409c MFD: ucb1x00: con... |
295 |
unsigned long flags = 0; |
acb45439a [MFD] Add code UC... |
296 |
int ret = 0; |
5437775e0 [MFD] Cleanups su... |
297 |
BUG_ON(ts->rtask); |
acb45439a [MFD] Add code UC... |
298 |
|
a3364409c MFD: ucb1x00: con... |
299 300 301 302 303 304 |
if (machine_is_collie()) flags = IRQF_TRIGGER_RISING; else flags = IRQF_TRIGGER_FALLING; ts->irq_disabled = 0; |
acb45439a [MFD] Add code UC... |
305 |
init_waitqueue_head(&ts->irq_wait); |
a3364409c MFD: ucb1x00: con... |
306 307 |
ret = request_irq(ts->ucb->irq_base + UCB_IRQ_TSPX, ucb1x00_ts_irq, flags, "ucb1x00-ts", ts); |
acb45439a [MFD] Add code UC... |
308 309 310 311 312 313 314 315 316 317 318 |
if (ret < 0) goto out; /* * If we do this at all, we should allow the user to * measure and read the X and Y resistance at any time. */ ucb1x00_adc_enable(ts->ucb); ts->x_res = ucb1x00_ts_read_xres(ts); ts->y_res = ucb1x00_ts_read_yres(ts); ucb1x00_adc_disable(ts->ucb); |
5437775e0 [MFD] Cleanups su... |
319 320 |
ts->rtask = kthread_run(ucb1x00_thread, ts, "ktsd"); if (!IS_ERR(ts->rtask)) { |
acb45439a [MFD] Add code UC... |
321 322 |
ret = 0; } else { |
a3364409c MFD: ucb1x00: con... |
323 |
free_irq(ts->ucb->irq_base + UCB_IRQ_TSPX, ts); |
5437775e0 [MFD] Cleanups su... |
324 325 |
ts->rtask = NULL; ret = -EFAULT; |
acb45439a [MFD] Add code UC... |
326 327 328 |
} out: |
acb45439a [MFD] Add code UC... |
329 330 331 332 333 334 335 336 |
return ret; } /* * Release touchscreen resources. Disable IRQs. */ static void ucb1x00_ts_close(struct input_dev *idev) { |
26be5a509 Input: ucb1x00 - ... |
337 |
struct ucb1x00_ts *ts = input_get_drvdata(idev); |
acb45439a [MFD] Add code UC... |
338 |
|
5437775e0 [MFD] Cleanups su... |
339 340 |
if (ts->rtask) kthread_stop(ts->rtask); |
acb45439a [MFD] Add code UC... |
341 |
|
5437775e0 [MFD] Cleanups su... |
342 |
ucb1x00_enable(ts->ucb); |
a3364409c MFD: ucb1x00: con... |
343 |
free_irq(ts->ucb->irq_base + UCB_IRQ_TSPX, ts); |
5437775e0 [MFD] Cleanups su... |
344 345 |
ucb1x00_reg_write(ts->ucb, UCB_TS_CR, 0); ucb1x00_disable(ts->ucb); |
acb45439a [MFD] Add code UC... |
346 |
} |
acb45439a [MFD] Add code UC... |
347 348 349 350 351 352 353 |
/* * Initialisation. */ static int ucb1x00_ts_add(struct ucb1x00_dev *dev) { struct ucb1x00_ts *ts; |
08c67d2a5 [PATCH] ucb1x00-t... |
354 355 |
struct input_dev *idev; int err; |
acb45439a [MFD] Add code UC... |
356 |
|
bd6226631 [PATCH] Input: co... |
357 |
ts = kzalloc(sizeof(struct ucb1x00_ts), GFP_KERNEL); |
08c67d2a5 [PATCH] ucb1x00-t... |
358 359 360 361 |
idev = input_allocate_device(); if (!ts || !idev) { err = -ENOMEM; goto fail; |
bd6226631 [PATCH] Input: co... |
362 |
} |
acb45439a [MFD] Add code UC... |
363 364 |
ts->ucb = dev->ucb; |
08c67d2a5 [PATCH] ucb1x00-t... |
365 |
ts->idev = idev; |
acb45439a [MFD] Add code UC... |
366 |
ts->adcsync = adcsync ? UCB_SYNC : UCB_NOSYNC; |
a3364409c MFD: ucb1x00: con... |
367 |
spin_lock_init(&ts->irq_lock); |
acb45439a [MFD] Add code UC... |
368 |
|
08c67d2a5 [PATCH] ucb1x00-t... |
369 |
idev->name = "Touchscreen panel"; |
65f2e753f Revert "ARM: sa11... |
370 |
idev->id.product = ts->ucb->id; |
08c67d2a5 [PATCH] ucb1x00-t... |
371 372 |
idev->open = ucb1x00_ts_open; idev->close = ucb1x00_ts_close; |
945f6310d MFD: ucb1x00-ts: ... |
373 |
idev->dev.parent = &ts->ucb->dev; |
acb45439a [MFD] Add code UC... |
374 |
|
de8c8b068 mfd: Add BTN_TOUC... |
375 376 |
idev->evbit[0] = BIT_MASK(EV_ABS) | BIT_MASK(EV_KEY); idev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); |
acb45439a [MFD] Add code UC... |
377 |
|
26be5a509 Input: ucb1x00 - ... |
378 |
input_set_drvdata(idev, ts); |
9063f1f15 mfd: Fix NULL poi... |
379 380 381 382 383 384 385 386 |
ucb1x00_adc_enable(ts->ucb); ts->x_res = ucb1x00_ts_read_xres(ts); ts->y_res = ucb1x00_ts_read_yres(ts); ucb1x00_adc_disable(ts->ucb); input_set_abs_params(idev, ABS_X, 0, ts->x_res, 0, 0); input_set_abs_params(idev, ABS_Y, 0, ts->y_res, 0, 0); input_set_abs_params(idev, ABS_PRESSURE, 0, 0, 0, 0); |
08c67d2a5 [PATCH] ucb1x00-t... |
387 388 389 |
err = input_register_device(idev); if (err) goto fail; |
acb45439a [MFD] Add code UC... |
390 391 392 393 |
dev->priv = ts; return 0; |
08c67d2a5 [PATCH] ucb1x00-t... |
394 395 396 397 398 |
fail: input_free_device(idev); kfree(ts); return err; |
acb45439a [MFD] Add code UC... |
399 400 401 402 403 |
} static void ucb1x00_ts_remove(struct ucb1x00_dev *dev) { struct ucb1x00_ts *ts = dev->priv; |
bd6226631 [PATCH] Input: co... |
404 405 |
input_unregister_device(ts->idev); |
acb45439a [MFD] Add code UC... |
406 407 408 409 410 411 |
kfree(ts); } static struct ucb1x00_driver ucb1x00_ts_driver = { .add = ucb1x00_ts_add, .remove = ucb1x00_ts_remove, |
acb45439a [MFD] Add code UC... |
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 |
}; static int __init ucb1x00_ts_init(void) { return ucb1x00_register_driver(&ucb1x00_ts_driver); } static void __exit ucb1x00_ts_exit(void) { ucb1x00_unregister_driver(&ucb1x00_ts_driver); } module_param(adcsync, int, 0444); module_init(ucb1x00_ts_init); module_exit(ucb1x00_ts_exit); MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>"); MODULE_DESCRIPTION("UCB1x00 touchscreen driver"); MODULE_LICENSE("GPL"); |