Lines Matching refs:s

103 #define X_TRANSFORM(s)			\  argument
104 ((s->y * s->tr[0] - s->x * s->tr[1]) / s->tr[2] + s->tr[3])
105 #define Y_TRANSFORM(s) \ argument
106 ((s->y * s->tr[4] - s->x * s->tr[5]) / s->tr[6] + s->tr[7])
107 #define Z1_TRANSFORM(s) \ argument
108 ((400 - ((s)->x >> 7) + ((s)->pressure << 10)) << 4)
109 #define Z2_TRANSFORM(s) \ argument
110 ((4000 + ((s)->y >> 7) - ((s)->pressure << 10)) << 4)
116 static uint16_t tsc2005_read(TSC2005State *s, int reg) in tsc2005_read() argument
122 s->dav &= ~mode_regs[TSC_MODE_X]; in tsc2005_read()
123 return TSC_CUT_RESOLUTION(X_TRANSFORM(s), s->precision) + in tsc2005_read()
124 (s->noise & 3); in tsc2005_read()
126 s->dav &= ~mode_regs[TSC_MODE_Y]; in tsc2005_read()
127 s->noise ++; in tsc2005_read()
128 return TSC_CUT_RESOLUTION(Y_TRANSFORM(s), s->precision) ^ in tsc2005_read()
129 (s->noise & 3); in tsc2005_read()
131 s->dav &= 0xdfff; in tsc2005_read()
132 return TSC_CUT_RESOLUTION(Z1_TRANSFORM(s), s->precision) - in tsc2005_read()
133 (s->noise & 3); in tsc2005_read()
135 s->dav &= 0xefff; in tsc2005_read()
136 return TSC_CUT_RESOLUTION(Z2_TRANSFORM(s), s->precision) | in tsc2005_read()
137 (s->noise & 3); in tsc2005_read()
140 s->dav &= ~mode_regs[TSC_MODE_AUX]; in tsc2005_read()
141 return TSC_CUT_RESOLUTION(AUX_VAL, s->precision); in tsc2005_read()
144 s->dav &= ~mode_regs[TSC_MODE_TEMP1]; in tsc2005_read()
145 return TSC_CUT_RESOLUTION(TEMP1_VAL, s->precision) - in tsc2005_read()
146 (s->noise & 5); in tsc2005_read()
148 s->dav &= 0xdfff; in tsc2005_read()
149 s->dav &= ~mode_regs[TSC_MODE_TEMP2]; in tsc2005_read()
150 return TSC_CUT_RESOLUTION(TEMP2_VAL, s->precision) ^ in tsc2005_read()
151 (s->noise & 3); in tsc2005_read()
154 ret = s->dav | (s->reset << 7) | (s->pdst << 2) | 0x0; in tsc2005_read()
155 s->dav &= ~(mode_regs[TSC_MODE_X_TEST] | mode_regs[TSC_MODE_Y_TEST] | in tsc2005_read()
157 s->reset = true; in tsc2005_read()
161 return s->aux_thr[1]; in tsc2005_read()
163 return s->aux_thr[0]; in tsc2005_read()
166 return s->temp_thr[1]; in tsc2005_read()
168 return s->temp_thr[0]; in tsc2005_read()
171 return (s->pressure << 15) | ((!s->busy) << 14) | in tsc2005_read()
172 (s->nextprecision << 13) | s->timing[0]; in tsc2005_read()
174 return s->timing[1]; in tsc2005_read()
176 return (s->pin_func << 14) | s->filter; in tsc2005_read()
179 return s->function >= 0 ? 1 << s->function : 0; in tsc2005_read()
186 static void tsc2005_write(TSC2005State *s, int reg, uint16_t data) in tsc2005_write() argument
190 s->aux_thr[1] = data; in tsc2005_write()
193 s->aux_thr[0] = data; in tsc2005_write()
197 s->temp_thr[1] = data; in tsc2005_write()
200 s->temp_thr[0] = data; in tsc2005_write()
204 s->host_mode = (data >> 15) != 0; in tsc2005_write()
205 if (s->enabled != !(data & 0x4000)) { in tsc2005_write()
206 s->enabled = !(data & 0x4000); in tsc2005_write()
207 trace_tsc2005_sense(s->enabled ? "enabled" : "disabled"); in tsc2005_write()
208 if (s->busy && !s->enabled) in tsc2005_write()
209 timer_del(s->timer); in tsc2005_write()
210 s->busy = s->busy && s->enabled; in tsc2005_write()
212 s->nextprecision = (data >> 13) & 1; in tsc2005_write()
213 s->timing[0] = data & 0x1fff; in tsc2005_write()
214 if ((s->timing[0] >> 11) == 3) { in tsc2005_write()
220 s->timing[1] = data & 0xf07; in tsc2005_write()
223 s->pin_func = (data >> 14) & 3; in tsc2005_write()
224 s->filter = data & 0x3fff; in tsc2005_write()
235 static void tsc2005_pin_update(TSC2005State *s) in tsc2005_pin_update() argument
240 switch (s->pin_func) { in tsc2005_pin_update()
242 pin_state = !s->pressure && !!s->dav; in tsc2005_pin_update()
247 pin_state = !s->dav; in tsc2005_pin_update()
250 pin_state = !s->pressure; in tsc2005_pin_update()
253 if (pin_state != s->irq) { in tsc2005_pin_update()
254 s->irq = pin_state; in tsc2005_pin_update()
255 qemu_set_irq(s->pint, s->irq); in tsc2005_pin_update()
258 switch (s->nextfunction) { in tsc2005_pin_update()
261 if (!s->host_mode && s->dav) in tsc2005_pin_update()
262 s->enabled = false; in tsc2005_pin_update()
263 if (!s->pressure) in tsc2005_pin_update()
272 if (!s->pressure) in tsc2005_pin_update()
281 if (s->dav) in tsc2005_pin_update()
282 s->enabled = false; in tsc2005_pin_update()
293 if (!s->enabled || s->busy) in tsc2005_pin_update()
296 s->busy = true; in tsc2005_pin_update()
297 s->precision = s->nextprecision; in tsc2005_pin_update()
298 s->function = s->nextfunction; in tsc2005_pin_update()
299 s->pdst = !s->pnd0; /* Synchronised on internal clock */ in tsc2005_pin_update()
302 timer_mod(s->timer, expires); in tsc2005_pin_update()
305 static void tsc2005_reset(TSC2005State *s) in tsc2005_reset() argument
307 s->state = 0; in tsc2005_reset()
308 s->pin_func = 0; in tsc2005_reset()
309 s->enabled = false; in tsc2005_reset()
310 s->busy = false; in tsc2005_reset()
311 s->nextprecision = false; in tsc2005_reset()
312 s->nextfunction = 0; in tsc2005_reset()
313 s->timing[0] = 0; in tsc2005_reset()
314 s->timing[1] = 0; in tsc2005_reset()
315 s->irq = false; in tsc2005_reset()
316 s->dav = 0; in tsc2005_reset()
317 s->reset = false; in tsc2005_reset()
318 s->pdst = true; in tsc2005_reset()
319 s->pnd0 = false; in tsc2005_reset()
320 s->function = -1; in tsc2005_reset()
321 s->temp_thr[0] = 0x000; in tsc2005_reset()
322 s->temp_thr[1] = 0xfff; in tsc2005_reset()
323 s->aux_thr[0] = 0x000; in tsc2005_reset()
324 s->aux_thr[1] = 0xfff; in tsc2005_reset()
326 tsc2005_pin_update(s); in tsc2005_reset()
331 TSC2005State *s = opaque; in tsc2005_txrx_word() local
334 switch (s->state ++) { in tsc2005_txrx_word()
339 tsc2005_reset(s); in tsc2005_txrx_word()
341 s->nextfunction = (value >> 3) & 0xf; in tsc2005_txrx_word()
342 s->nextprecision = (value >> 2) & 1; in tsc2005_txrx_word()
343 if (s->enabled != !(value & 1)) { in tsc2005_txrx_word()
344 s->enabled = !(value & 1); in tsc2005_txrx_word()
345 trace_tsc2005_sense(s->enabled ? "enabled" : "disabled"); in tsc2005_txrx_word()
346 if (s->busy && !s->enabled) in tsc2005_txrx_word()
347 timer_del(s->timer); in tsc2005_txrx_word()
348 s->busy = s->busy && s->enabled; in tsc2005_txrx_word()
350 tsc2005_pin_update(s); in tsc2005_txrx_word()
353 s->state = 0; in tsc2005_txrx_word()
356 s->reg = (value >> 3) & 0xf; in tsc2005_txrx_word()
357 s->pnd0 = (value >> 1) & 1; in tsc2005_txrx_word()
358 s->command = value & 1; in tsc2005_txrx_word()
360 if (s->command) { in tsc2005_txrx_word()
362 s->data = tsc2005_read(s, s->reg); in tsc2005_txrx_word()
363 tsc2005_pin_update(s); in tsc2005_txrx_word()
365 s->data = 0; in tsc2005_txrx_word()
367 s->state = 0; in tsc2005_txrx_word()
371 if (s->command) in tsc2005_txrx_word()
372 ret = (s->data >> 8) & 0xff; in tsc2005_txrx_word()
374 s->data |= value << 8; in tsc2005_txrx_word()
378 if (s->command) in tsc2005_txrx_word()
379 ret = s->data & 0xff; in tsc2005_txrx_word()
381 s->data |= value; in tsc2005_txrx_word()
382 tsc2005_write(s, s->reg, s->data); in tsc2005_txrx_word()
383 tsc2005_pin_update(s); in tsc2005_txrx_word()
386 s->state = 0; in tsc2005_txrx_word()
408 TSC2005State *s = opaque; in tsc2005_timer_tick() local
412 if (!s->busy) in tsc2005_timer_tick()
415 s->busy = false; in tsc2005_timer_tick()
416 s->dav |= mode_regs[s->function]; in tsc2005_timer_tick()
417 s->function = -1; in tsc2005_timer_tick()
418 tsc2005_pin_update(s); in tsc2005_timer_tick()
424 TSC2005State *s = opaque; in tsc2005_touchscreen_event() local
425 int p = s->pressure; in tsc2005_touchscreen_event()
428 s->x = x; in tsc2005_touchscreen_event()
429 s->y = y; in tsc2005_touchscreen_event()
431 s->pressure = !!buttons_state; in tsc2005_touchscreen_event()
438 if (p != s->pressure) in tsc2005_touchscreen_event()
439 tsc2005_pin_update(s); in tsc2005_touchscreen_event()
444 TSC2005State *s = (TSC2005State *) opaque; in tsc2005_post_load() local
446 s->busy = timer_pending(s->timer); in tsc2005_post_load()
447 tsc2005_pin_update(s); in tsc2005_post_load()
490 TSC2005State *s; in tsc2005_init() local
492 s = g_new0(TSC2005State, 1); in tsc2005_init()
493 s->x = 400; in tsc2005_init()
494 s->y = 240; in tsc2005_init()
495 s->pressure = false; in tsc2005_init()
496 s->precision = s->nextprecision = false; in tsc2005_init()
497 s->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, tsc2005_timer_tick, s); in tsc2005_init()
498 s->pint = pintdav; in tsc2005_init()
499 s->model = 0x2005; in tsc2005_init()
501 s->tr[0] = 0; in tsc2005_init()
502 s->tr[1] = 1; in tsc2005_init()
503 s->tr[2] = 1; in tsc2005_init()
504 s->tr[3] = 0; in tsc2005_init()
505 s->tr[4] = 1; in tsc2005_init()
506 s->tr[5] = 0; in tsc2005_init()
507 s->tr[6] = 1; in tsc2005_init()
508 s->tr[7] = 0; in tsc2005_init()
510 tsc2005_reset(s); in tsc2005_init()
512 qemu_add_mouse_event_handler(tsc2005_touchscreen_event, s, 1, in tsc2005_init()
515 qemu_register_reset((void *) tsc2005_reset, s); in tsc2005_init()
516 vmstate_register(NULL, 0, &vmstate_tsc2005, s); in tsc2005_init()
518 return s; in tsc2005_init()
528 TSC2005State *s = (TSC2005State *) opaque; in tsc2005_set_transform() local
533 s->tr[0] = 0; in tsc2005_set_transform()
534 s->tr[1] = -info->a[6] * info->x; in tsc2005_set_transform()
535 s->tr[2] = info->a[0]; in tsc2005_set_transform()
536 s->tr[3] = -info->a[2] / info->a[0]; in tsc2005_set_transform()
537 s->tr[4] = info->a[6] * info->y; in tsc2005_set_transform()
538 s->tr[5] = 0; in tsc2005_set_transform()
539 s->tr[6] = info->a[4]; in tsc2005_set_transform()
540 s->tr[7] = -info->a[5] / info->a[4]; in tsc2005_set_transform()
542 s->tr[0] = info->a[6] * info->y; in tsc2005_set_transform()
543 s->tr[1] = 0; in tsc2005_set_transform()
544 s->tr[2] = info->a[1]; in tsc2005_set_transform()
545 s->tr[3] = -info->a[2] / info->a[1]; in tsc2005_set_transform()
546 s->tr[4] = 0; in tsc2005_set_transform()
547 s->tr[5] = -info->a[6] * info->x; in tsc2005_set_transform()
548 s->tr[6] = info->a[3]; in tsc2005_set_transform()
549 s->tr[7] = -info->a[5] / info->a[3]; in tsc2005_set_transform()
552 s->tr[0] >>= 11; in tsc2005_set_transform()
553 s->tr[1] >>= 11; in tsc2005_set_transform()
554 s->tr[3] <<= 4; in tsc2005_set_transform()
555 s->tr[4] >>= 11; in tsc2005_set_transform()
556 s->tr[5] >>= 11; in tsc2005_set_transform()
557 s->tr[7] <<= 4; in tsc2005_set_transform()