Lines Matching +full:touchscreen +full:- +full:average +full:- +full:samples
4 * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
36 #define MAX_12BIT ((1 << 12) - 1)
65 return readl(ts->mfd_tscadc->tscadc_base + reg); in titsc_readl()
71 writel(val, tsc->mfd_tscadc->tscadc_base + reg); in titsc_writel()
85 analog_line[i] = (ts_dev->config_inp[i] & 0xF0) >> 4; in titsc_config_wires()
86 wire_order[i] = ts_dev->config_inp[i] & 0x0F; in titsc_config_wires()
88 return -EINVAL; in titsc_config_wires()
90 return -EINVAL; in titsc_config_wires()
101 return -EINVAL; in titsc_config_wires()
104 ts_dev->bit_xp = bit_cfg; in titsc_config_wires()
105 ts_dev->inp_xp = an_line; in titsc_config_wires()
109 ts_dev->bit_xn = bit_cfg; in titsc_config_wires()
110 ts_dev->inp_xn = an_line; in titsc_config_wires()
114 ts_dev->bit_yp = bit_cfg; in titsc_config_wires()
115 ts_dev->inp_yp = an_line; in titsc_config_wires()
118 ts_dev->bit_yn = bit_cfg; in titsc_config_wires()
119 ts_dev->inp_yn = an_line; in titsc_config_wires()
134 STEPCONFIG_AVG_16 | ts_dev->bit_xp; in titsc_step_config()
135 switch (ts_dev->wires) { in titsc_step_config()
137 config |= STEPCONFIG_INP(ts_dev->inp_yp) | ts_dev->bit_xn; in titsc_step_config()
140 config |= ts_dev->bit_yn | in titsc_step_config()
141 STEPCONFIG_INP_AN4 | ts_dev->bit_xn | in titsc_step_config()
142 ts_dev->bit_yp; in titsc_step_config()
145 config |= STEPCONFIG_INP(ts_dev->inp_yp) | ts_dev->bit_xn; in titsc_step_config()
149 tsc_steps = ts_dev->coordinate_readouts * 2 + 2; in titsc_step_config()
150 first_step = TOTAL_STEPS - tsc_steps; in titsc_step_config()
151 /* Steps 16 to 16-coordinate_readouts is for X */ in titsc_step_config()
153 for (i = end_step - ts_dev->coordinate_readouts; i < end_step; i++) { in titsc_step_config()
160 STEPCONFIG_AVG_16 | ts_dev->bit_yn | in titsc_step_config()
162 switch (ts_dev->wires) { in titsc_step_config()
164 config |= ts_dev->bit_yp | STEPCONFIG_INP(ts_dev->inp_xp); in titsc_step_config()
167 config |= ts_dev->bit_xp | STEPCONFIG_INP_AN4 | in titsc_step_config()
171 config |= ts_dev->bit_yp | STEPCONFIG_INP(ts_dev->inp_xp); in titsc_step_config()
176 end_step = first_step + ts_dev->coordinate_readouts; in titsc_step_config()
186 titsc_writel(ts_dev, REG_CHARGEDELAY, ts_dev->charge_delay); in titsc_step_config()
190 STEPCONFIG_AVG_16 | ts_dev->bit_yp | in titsc_step_config()
191 ts_dev->bit_xn | STEPCONFIG_INM_ADCREFM | in titsc_step_config()
192 STEPCONFIG_INP(ts_dev->inp_xp); in titsc_step_config()
198 config |= STEPCONFIG_INP(ts_dev->inp_yn); in titsc_step_config()
203 /* The steps end ... end - readouts * 2 + 2 and bit 0 for TS_Charge */ in titsc_step_config()
208 ts_dev->step_mask = stepenable; in titsc_step_config()
209 am335x_tsc_se_set_cache(ts_dev->mfd_tscadc, ts_dev->step_mask); in titsc_step_config()
214 return *(int *)a - *(int *)b; in titsc_cmp_coord()
222 unsigned int creads = ts_dev->coordinate_readouts; in titsc_read_coordinates()
240 * If co-ordinates readouts is less than 4 then in titsc_read_coordinates()
241 * report the average. In case of 4 or more in titsc_read_coordinates()
242 * readouts, sort the co-ordinate samples, drop in titsc_read_coordinates()
243 * min and max values and report the average of in titsc_read_coordinates()
258 for (i = 1; i < creads - 1; i++) { in titsc_read_coordinates()
262 ysum /= creads - 2; in titsc_read_coordinates()
263 xsum /= creads - 2; in titsc_read_coordinates()
272 struct input_dev *input_dev = ts_dev->input; in titsc_irq()
279 ts_dev->pen_down = true; in titsc_irq()
281 pm_stay_awake(ts_dev->dev); in titsc_irq()
287 ts_dev->pen_down = false; in titsc_irq()
291 pm_relax(ts_dev->dev); in titsc_irq()
293 ts_dev->pen_down = true; in titsc_irq()
302 * ADC and touchscreen share the IRQ line. in titsc_irq()
309 if (ts_dev->pen_down && z1 != 0 && z2 != 0) { in titsc_irq()
313 * x postion/4096 * ((z2 / z1) - 1) in titsc_irq()
315 z = z1 - z2; in titsc_irq()
317 z *= ts_dev->x_plate_resistance; in titsc_irq()
334 am335x_tsc_se_set_cache(ts_dev->mfd_tscadc, in titsc_irq()
335 ts_dev->step_mask); in titsc_irq()
344 struct device_node *node = pdev->dev.of_node; in titsc_parse_dt()
348 return -EINVAL; in titsc_parse_dt()
350 err = of_property_read_u32(node, "ti,wires", &ts_dev->wires); in titsc_parse_dt()
353 switch (ts_dev->wires) { in titsc_parse_dt()
359 return -EINVAL; in titsc_parse_dt()
362 err = of_property_read_u32(node, "ti,x-plate-resistance", in titsc_parse_dt()
363 &ts_dev->x_plate_resistance); in titsc_parse_dt()
369 * bogus, miss-spelled version. in titsc_parse_dt()
371 err = of_property_read_u32(node, "ti,coordinate-readouts", in titsc_parse_dt()
372 &ts_dev->coordinate_readouts); in titsc_parse_dt()
374 dev_warn(&pdev->dev, "please use 'ti,coordinate-readouts' instead\n"); in titsc_parse_dt()
375 err = of_property_read_u32(node, "ti,coordiante-readouts", in titsc_parse_dt()
376 &ts_dev->coordinate_readouts); in titsc_parse_dt()
382 if (ts_dev->coordinate_readouts <= 0) { in titsc_parse_dt()
383 dev_warn(&pdev->dev, in titsc_parse_dt()
384 "invalid co-ordinate readouts, resetting it to 5\n"); in titsc_parse_dt()
385 ts_dev->coordinate_readouts = 5; in titsc_parse_dt()
388 err = of_property_read_u32(node, "ti,charge-delay", in titsc_parse_dt()
389 &ts_dev->charge_delay); in titsc_parse_dt()
391 * If ti,charge-delay value is not specified, then use in titsc_parse_dt()
395 ts_dev->charge_delay = CHARGEDLY_OPENDLY; in titsc_parse_dt()
396 dev_warn(&pdev->dev, "ti,charge-delay not specified\n"); in titsc_parse_dt()
399 return of_property_read_u32_array(node, "ti,wire-config", in titsc_parse_dt()
400 ts_dev->config_inp, ARRAY_SIZE(ts_dev->config_inp)); in titsc_parse_dt()
418 dev_err(&pdev->dev, "failed to allocate memory.\n"); in titsc_probe()
419 err = -ENOMEM; in titsc_probe()
423 tscadc_dev->tsc = ts_dev; in titsc_probe()
424 ts_dev->mfd_tscadc = tscadc_dev; in titsc_probe()
425 ts_dev->input = input_dev; in titsc_probe()
426 ts_dev->irq = tscadc_dev->irq; in titsc_probe()
427 ts_dev->dev = &pdev->dev; in titsc_probe()
431 dev_err(&pdev->dev, "Could not find valid DT data.\n"); in titsc_probe()
435 err = request_irq(ts_dev->irq, titsc_irq, in titsc_probe()
436 IRQF_SHARED, pdev->dev.driver->name, ts_dev); in titsc_probe()
438 dev_err(&pdev->dev, "failed to allocate irq.\n"); in titsc_probe()
442 device_init_wakeup(&pdev->dev, true); in titsc_probe()
443 err = dev_pm_set_wake_irq(&pdev->dev, ts_dev->irq); in titsc_probe()
445 dev_err(&pdev->dev, "irq wake enable failed.\n"); in titsc_probe()
452 dev_err(&pdev->dev, "wrong i/p wire configuration\n"); in titsc_probe()
457 ts_dev->coordinate_readouts * 2 + 2 - 1); in titsc_probe()
459 input_dev->name = "ti-tsc"; in titsc_probe()
460 input_dev->dev.parent = &pdev->dev; in titsc_probe()
462 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); in titsc_probe()
463 input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); in titsc_probe()
478 dev_pm_clear_wake_irq(&pdev->dev); in titsc_probe()
479 device_init_wakeup(&pdev->dev, false); in titsc_probe()
480 free_irq(ts_dev->irq, ts_dev); in titsc_probe()
492 dev_pm_clear_wake_irq(&pdev->dev); in titsc_remove()
493 device_init_wakeup(&pdev->dev, false); in titsc_remove()
494 free_irq(ts_dev->irq, ts_dev); in titsc_remove()
497 steps = 2 * ts_dev->coordinate_readouts + 2; in titsc_remove()
498 steps = (1 << steps) - 1; in titsc_remove()
499 am335x_tsc_se_clr(ts_dev->mfd_tscadc, steps); in titsc_remove()
501 input_unregister_device(ts_dev->input); in titsc_remove()
534 ts_dev->coordinate_readouts * 2 + 2 - 1); in titsc_resume()
541 { .compatible = "ti,am3359-tsc", },
550 .name = "TI-am335x-tsc",
557 MODULE_DESCRIPTION("TI touchscreen controller driver");