Commit a2f99330 authored by Marco Felsch's avatar Marco Felsch Committed by Dmitry Torokhov
Browse files

Input: ads7846 - add support for general touchscreen bindings



A few vendor specific bindings are now covered by common bindings.

Let the driver parse the common bindings to make use of common
inverting and swapping mechnism. Aslo make use of
touchscreen_report_pos() to ensure the correct inverting-swapping
order.

The vendor specific properties are used as default (backward
compatibility) and gets overwritten by common bindings.

Signed-off-by: default avatarMarco Felsch <m.felsch@pengutronix.de>
Reviewed-by: default avatarRob Herring <robh@kernel.org>
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent f0fbeaa8
Loading
Loading
Loading
Loading
+21 −8
Original line number Diff line number Diff line
@@ -32,7 +32,6 @@ Optional properties:
					(ADS7846).
	ti,keep-vref-on			set to keep vref on for differential
					measurements as well
	ti,swap-xy			swap x and y axis
	ti,settle-delay-usec		Settling time of the analog signals;
					a function of Vcc and the capacitance
					on the X/Y drivers.  If set to non-zero,
@@ -51,13 +50,6 @@ Optional properties:
					in Ohms (u16).
	ti,x-min			Minimum value on the X axis (u16).
	ti,y-min			Minimum value on the Y axis (u16).
	ti,x-max			Maximum value on the X axis (u16).
	ti,y-max			Maximum value on the Y axis (u16).
	ti,pressure-min			Minimum reported pressure value
					(threshold) - u16.
	ti,pressure-max			Maximum reported pressure value (u16).
	ti,debounce-max			Max number of additional readings per
					sample (u16).
	ti,debounce-tol			Tolerance used for filtering (u16).
	ti,debounce-rep			Additional consecutive good readings
					required after the first two (u16).
@@ -67,7 +59,28 @@ Optional properties:
					line is connected to.
	wakeup-source			use any event on touchscreen as wakeup event.
					(Legacy property support: "linux,wakeup")
	touchscreen-size-x		General touchscreen binding, see [1].
	touchscreen-size-y		General touchscreen binding, see [1].
	touchscreen-max-pressure	General touchscreen binding, see [1].
	touchscreen-min-pressure	General touchscreen binding, see [1].
	touchscreen-average-samples	General touchscreen binding, see [1].
	touchscreen-inverted-x		General touchscreen binding, see [1].
	touchscreen-inverted-y		General touchscreen binding, see [1].
	touchscreen-swapped-x-y		General touchscreen binding, see [1].

[1] All general touchscreen properties are described in
    Documentation/devicetree/bindings/input/touchscreen/touchscreen.txt.

Deprecated properties:

	ti,swap-xy			swap x and y axis
	ti,x-max			Maximum value on the X axis (u16).
	ti,y-max			Maximum value on the Y axis (u16).
	ti,pressure-min			Minimum reported pressure value
					(threshold) - u16.
	ti,pressure-max			Maximum reported pressure value (u16).
	ti,debounce-max			Max number of additional readings per
					sample (u16).

Example for a TSC2046 chip connected to an McSPI controller of an OMAP SoC::

+30 −8
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include <linux/sched.h>
#include <linux/delay.h>
#include <linux/input.h>
#include <linux/input/touchscreen.h>
#include <linux/interrupt.h>
#include <linux/slab.h>
#include <linux/pm.h>
@@ -129,6 +130,8 @@ struct ads7846 {

	u16			penirq_recheck_delay_usecs;

	struct touchscreen_properties core_prop;

	struct mutex		lock;
	bool			stopped;	/* P: lock */
	bool			disabled;	/* P: lock */
@@ -823,17 +826,13 @@ static void ads7846_report_state(struct ads7846 *ts)
	if (Rt) {
		struct input_dev *input = ts->input;

		if (ts->swap_xy)
			swap(x, y);

		if (!ts->pendown) {
			input_report_key(input, BTN_TOUCH, 1);
			ts->pendown = true;
			dev_vdbg(&ts->spi->dev, "DOWN\n");
		}

		input_report_abs(input, ABS_X, x);
		input_report_abs(input, ABS_Y, y);
		touchscreen_report_pos(input, &ts->core_prop, x, y, false);
		input_report_abs(input, ABS_PRESSURE, ts->pressure_max - Rt);

		input_sync(input);
@@ -1185,6 +1184,7 @@ static const struct ads7846_platform_data *ads7846_probe_dt(struct device *dev)
	struct ads7846_platform_data *pdata;
	struct device_node *node = dev->of_node;
	const struct of_device_id *match;
	u32 value;

	if (!node) {
		dev_err(dev, "Device does not have associated DT data\n");
@@ -1223,10 +1223,18 @@ static const struct ads7846_platform_data *ads7846_probe_dt(struct device *dev)
	of_property_read_u16(node, "ti,x-max", &pdata->x_max);
	of_property_read_u16(node, "ti,y-max", &pdata->y_max);

	/*
	 * touchscreen-max-pressure gets parsed during
	 * touchscreen_parse_properties()
	 */
	of_property_read_u16(node, "ti,pressure-min", &pdata->pressure_min);
	if (!of_property_read_u32(node, "touchscreen-min-pressure", &value))
		pdata->pressure_min = (u16) value;
	of_property_read_u16(node, "ti,pressure-max", &pdata->pressure_max);

	of_property_read_u16(node, "ti,debounce-max", &pdata->debounce_max);
	if (!of_property_read_u32(node, "touchscreen-average-samples", &value))
		pdata->debounce_max = (u16) value;
	of_property_read_u16(node, "ti,debounce-tol", &pdata->debounce_tol);
	of_property_read_u16(node, "ti,debounce-rep", &pdata->debounce_rep);

@@ -1309,10 +1317,7 @@ static int ads7846_probe(struct spi_device *spi)
	ts->model = pdata->model ? : 7846;
	ts->vref_delay_usecs = pdata->vref_delay_usecs ? : 100;
	ts->x_plate_ohms = pdata->x_plate_ohms ? : 400;
	ts->pressure_max = pdata->pressure_max ? : ~0;

	ts->vref_mv = pdata->vref_mv;
	ts->swap_xy = pdata->swap_xy;

	if (pdata->filter != NULL) {
		if (pdata->filter_init != NULL) {
@@ -1364,6 +1369,23 @@ static int ads7846_probe(struct spi_device *spi)
	input_set_abs_params(input_dev, ABS_PRESSURE,
			pdata->pressure_min, pdata->pressure_max, 0, 0);

	/*
	 * Parse common framework properties. Must be done here to ensure the
	 * correct behaviour in case of using the legacy vendor bindings. The
	 * general binding value overrides the vendor specific one.
	 */
	touchscreen_parse_properties(ts->input, false, &ts->core_prop);
	ts->pressure_max = input_abs_get_max(input_dev, ABS_PRESSURE) ? : ~0;

	/*
	 * Check if legacy ti,swap-xy binding is used instead of
	 * touchscreen-swapped-x-y
	 */
	if (!ts->core_prop.swap_x_y && pdata->swap_xy) {
		swap(input_dev->absinfo[ABS_X], input_dev->absinfo[ABS_Y]);
		ts->core_prop.swap_x_y = true;
	}

	ads7846_setup_spi_msg(ts, pdata);

	ts->reg = regulator_get(&spi->dev, "vcc");