Linux Audio

Check our new training course

Loading...
v4.6
 
  1/*
  2 * Toradex Colibri VF50 Touchscreen driver
  3 *
  4 * Copyright 2015 Toradex AG
  5 *
  6 * Originally authored by Stefan Agner for 3.0 kernel
  7 *
  8 * This program is free software; you can redistribute it and/or modify
  9 * it under the terms of the GNU General Public License as published by
 10 * the Free Software Foundation; either version 2 of the License, or
 11 * (at your option) any later version.
 12 */
 13
 14#include <linux/delay.h>
 15#include <linux/err.h>
 16#include <linux/gpio.h>
 17#include <linux/gpio/consumer.h>
 18#include <linux/iio/consumer.h>
 19#include <linux/iio/types.h>
 20#include <linux/input.h>
 21#include <linux/interrupt.h>
 22#include <linux/kernel.h>
 23#include <linux/module.h>
 24#include <linux/of.h>
 25#include <linux/pinctrl/consumer.h>
 26#include <linux/platform_device.h>
 27#include <linux/slab.h>
 28#include <linux/types.h>
 29
 30#define DRIVER_NAME			"colibri-vf50-ts"
 31#define DRV_VERSION			"1.0"
 32
 33#define VF_ADC_MAX			((1 << 12) - 1)
 34
 35#define COLI_TOUCH_MIN_DELAY_US		1000
 36#define COLI_TOUCH_MAX_DELAY_US		2000
 37#define COLI_PULLUP_MIN_DELAY_US	10000
 38#define COLI_PULLUP_MAX_DELAY_US	11000
 39#define COLI_TOUCH_NO_OF_AVGS		5
 40#define COLI_TOUCH_REQ_ADC_CHAN		4
 41
 42struct vf50_touch_device {
 43	struct platform_device *pdev;
 44	struct input_dev *ts_input;
 45	struct iio_channel *channels;
 46	struct gpio_desc *gpio_xp;
 47	struct gpio_desc *gpio_xm;
 48	struct gpio_desc *gpio_yp;
 49	struct gpio_desc *gpio_ym;
 50	int pen_irq;
 51	int min_pressure;
 52	bool stop_touchscreen;
 53};
 54
 55/*
 56 * Enables given plates and measures touch parameters using ADC
 57 */
 58static int adc_ts_measure(struct iio_channel *channel,
 59			  struct gpio_desc *plate_p, struct gpio_desc *plate_m)
 60{
 61	int i, value = 0, val = 0;
 62	int error;
 63
 64	gpiod_set_value(plate_p, 1);
 65	gpiod_set_value(plate_m, 1);
 66
 67	usleep_range(COLI_TOUCH_MIN_DELAY_US, COLI_TOUCH_MAX_DELAY_US);
 68
 69	for (i = 0; i < COLI_TOUCH_NO_OF_AVGS; i++) {
 70		error = iio_read_channel_raw(channel, &val);
 71		if (error < 0) {
 72			value = error;
 73			goto error_iio_read;
 74		}
 75
 76		value += val;
 77	}
 78
 79	value /= COLI_TOUCH_NO_OF_AVGS;
 80
 81error_iio_read:
 82	gpiod_set_value(plate_p, 0);
 83	gpiod_set_value(plate_m, 0);
 84
 85	return value;
 86}
 87
 88/*
 89 * Enable touch detection using falling edge detection on XM
 90 */
 91static void vf50_ts_enable_touch_detection(struct vf50_touch_device *vf50_ts)
 92{
 93	/* Enable plate YM (needs to be strong GND, high active) */
 94	gpiod_set_value(vf50_ts->gpio_ym, 1);
 95
 96	/*
 97	 * Let the platform mux to idle state in order to enable
 98	 * Pull-Up on GPIO
 99	 */
100	pinctrl_pm_select_idle_state(&vf50_ts->pdev->dev);
101
102	/* Wait for the pull-up to be stable on high */
103	usleep_range(COLI_PULLUP_MIN_DELAY_US, COLI_PULLUP_MAX_DELAY_US);
104}
105
106/*
107 * ADC touch screen sampling bottom half irq handler
108 */
109static irqreturn_t vf50_ts_irq_bh(int irq, void *private)
110{
111	struct vf50_touch_device *vf50_ts = private;
112	struct device *dev = &vf50_ts->pdev->dev;
113	int val_x, val_y, val_z1, val_z2, val_p = 0;
114	bool discard_val_on_start = true;
115
116	/* Disable the touch detection plates */
117	gpiod_set_value(vf50_ts->gpio_ym, 0);
118
119	/* Let the platform mux to default state in order to mux as ADC */
120	pinctrl_pm_select_default_state(dev);
121
122	while (!vf50_ts->stop_touchscreen) {
123		/* X-Direction */
124		val_x = adc_ts_measure(&vf50_ts->channels[0],
125				vf50_ts->gpio_xp, vf50_ts->gpio_xm);
126		if (val_x < 0)
127			break;
128
129		/* Y-Direction */
130		val_y = adc_ts_measure(&vf50_ts->channels[1],
131				vf50_ts->gpio_yp, vf50_ts->gpio_ym);
132		if (val_y < 0)
133			break;
134
135		/*
136		 * Touch pressure
137		 * Measure on XP/YM
138		 */
139		val_z1 = adc_ts_measure(&vf50_ts->channels[2],
140				vf50_ts->gpio_yp, vf50_ts->gpio_xm);
141		if (val_z1 < 0)
142			break;
143		val_z2 = adc_ts_measure(&vf50_ts->channels[3],
144				vf50_ts->gpio_yp, vf50_ts->gpio_xm);
145		if (val_z2 < 0)
146			break;
147
148		/* Validate signal (avoid calculation using noise) */
149		if (val_z1 > 64 && val_x > 64) {
150			/*
151			 * Calculate resistance between the plates
152			 * lower resistance means higher pressure
153			 */
154			int r_x = (1000 * val_x) / VF_ADC_MAX;
155
156			val_p = (r_x * val_z2) / val_z1 - r_x;
157
158		} else {
159			val_p = 2000;
160		}
161
162		val_p = 2000 - val_p;
163		dev_dbg(dev,
164			"Measured values: x: %d, y: %d, z1: %d, z2: %d, p: %d\n",
165			val_x, val_y, val_z1, val_z2, val_p);
166
167		/*
168		 * If touch pressure is too low, stop measuring and reenable
169		 * touch detection
170		 */
171		if (val_p < vf50_ts->min_pressure || val_p > 2000)
172			break;
173
174		/*
175		 * The pressure may not be enough for the first x and the
176		 * second y measurement, but, the pressure is ok when the
177		 * driver is doing the third and fourth measurement. To
178		 * take care of this, we drop the first measurement always.
179		 */
180		if (discard_val_on_start) {
181			discard_val_on_start = false;
182		} else {
183			/*
184			 * Report touch position and sleep for
185			 * the next measurement.
186			 */
187			input_report_abs(vf50_ts->ts_input,
188					ABS_X, VF_ADC_MAX - val_x);
189			input_report_abs(vf50_ts->ts_input,
190					ABS_Y, VF_ADC_MAX - val_y);
191			input_report_abs(vf50_ts->ts_input,
192					ABS_PRESSURE, val_p);
193			input_report_key(vf50_ts->ts_input, BTN_TOUCH, 1);
194			input_sync(vf50_ts->ts_input);
195		}
196
197		usleep_range(COLI_PULLUP_MIN_DELAY_US,
198			     COLI_PULLUP_MAX_DELAY_US);
199	}
200
201	/* Report no more touch, re-enable touch detection */
202	input_report_abs(vf50_ts->ts_input, ABS_PRESSURE, 0);
203	input_report_key(vf50_ts->ts_input, BTN_TOUCH, 0);
204	input_sync(vf50_ts->ts_input);
205
206	vf50_ts_enable_touch_detection(vf50_ts);
207
208	return IRQ_HANDLED;
209}
210
211static int vf50_ts_open(struct input_dev *dev_input)
212{
213	struct vf50_touch_device *touchdev = input_get_drvdata(dev_input);
214	struct device *dev = &touchdev->pdev->dev;
215
216	dev_dbg(dev, "Input device %s opened, starting touch detection\n",
217		dev_input->name);
218
219	touchdev->stop_touchscreen = false;
220
221	/* Mux detection before request IRQ, wait for pull-up to settle */
222	vf50_ts_enable_touch_detection(touchdev);
223
224	return 0;
225}
226
227static void vf50_ts_close(struct input_dev *dev_input)
228{
229	struct vf50_touch_device *touchdev = input_get_drvdata(dev_input);
230	struct device *dev = &touchdev->pdev->dev;
231
232	touchdev->stop_touchscreen = true;
233
234	/* Make sure IRQ is not running past close */
235	mb();
236	synchronize_irq(touchdev->pen_irq);
237
238	gpiod_set_value(touchdev->gpio_ym, 0);
239	pinctrl_pm_select_default_state(dev);
240
241	dev_dbg(dev, "Input device %s closed, disable touch detection\n",
242		dev_input->name);
243}
244
245static int vf50_ts_get_gpiod(struct device *dev, struct gpio_desc **gpio_d,
246			     const char *con_id, enum gpiod_flags flags)
247{
248	int error;
249
250	*gpio_d = devm_gpiod_get(dev, con_id, flags);
251	if (IS_ERR(*gpio_d)) {
252		error = PTR_ERR(*gpio_d);
253		dev_err(dev, "Could not get gpio_%s %d\n", con_id, error);
254		return error;
255	}
256
257	return 0;
258}
259
260static void vf50_ts_channel_release(void *data)
261{
262	struct iio_channel *channels = data;
263
264	iio_channel_release_all(channels);
265}
266
267static int vf50_ts_probe(struct platform_device *pdev)
268{
269	struct input_dev *input;
270	struct iio_channel *channels;
271	struct device *dev = &pdev->dev;
272	struct vf50_touch_device *touchdev;
273	int num_adc_channels;
274	int error;
275
276	channels = iio_channel_get_all(dev);
277	if (IS_ERR(channels))
278		return PTR_ERR(channels);
279
280	error = devm_add_action(dev, vf50_ts_channel_release, channels);
281	if (error) {
282		iio_channel_release_all(channels);
283		dev_err(dev, "Failed to register iio channel release action");
284		return error;
285	}
286
287	num_adc_channels = 0;
288	while (channels[num_adc_channels].indio_dev)
289		num_adc_channels++;
290
291	if (num_adc_channels != COLI_TOUCH_REQ_ADC_CHAN) {
292		dev_err(dev, "Inadequate ADC channels specified\n");
293		return -EINVAL;
294	}
295
296	touchdev = devm_kzalloc(dev, sizeof(*touchdev), GFP_KERNEL);
297	if (!touchdev)
298		return -ENOMEM;
299
300	touchdev->pdev = pdev;
301	touchdev->channels = channels;
302
303	error = of_property_read_u32(dev->of_node, "vf50-ts-min-pressure",
304				 &touchdev->min_pressure);
305	if (error)
306		return error;
307
308	input = devm_input_allocate_device(dev);
309	if (!input) {
310		dev_err(dev, "Failed to allocate TS input device\n");
311		return -ENOMEM;
312	}
313
314	platform_set_drvdata(pdev, touchdev);
315
316	input->name = DRIVER_NAME;
317	input->id.bustype = BUS_HOST;
318	input->dev.parent = dev;
319	input->open = vf50_ts_open;
320	input->close = vf50_ts_close;
321
322	input_set_capability(input, EV_KEY, BTN_TOUCH);
323	input_set_abs_params(input, ABS_X, 0, VF_ADC_MAX, 0, 0);
324	input_set_abs_params(input, ABS_Y, 0, VF_ADC_MAX, 0, 0);
325	input_set_abs_params(input, ABS_PRESSURE, 0, VF_ADC_MAX, 0, 0);
326
327	touchdev->ts_input = input;
328	input_set_drvdata(input, touchdev);
329
330	error = input_register_device(input);
331	if (error) {
332		dev_err(dev, "Failed to register input device\n");
333		return error;
334	}
335
336	error = vf50_ts_get_gpiod(dev, &touchdev->gpio_xp, "xp", GPIOD_OUT_LOW);
337	if (error)
338		return error;
339
340	error = vf50_ts_get_gpiod(dev, &touchdev->gpio_xm,
341				"xm", GPIOD_OUT_LOW);
342	if (error)
343		return error;
344
345	error = vf50_ts_get_gpiod(dev, &touchdev->gpio_yp, "yp", GPIOD_OUT_LOW);
346	if (error)
347		return error;
348
349	error = vf50_ts_get_gpiod(dev, &touchdev->gpio_ym, "ym", GPIOD_OUT_LOW);
350	if (error)
351		return error;
352
353	touchdev->pen_irq = platform_get_irq(pdev, 0);
354	if (touchdev->pen_irq < 0)
355		return touchdev->pen_irq;
356
357	error = devm_request_threaded_irq(dev, touchdev->pen_irq,
358					  NULL, vf50_ts_irq_bh, IRQF_ONESHOT,
359					  "vf50 touch", touchdev);
360	if (error) {
361		dev_err(dev, "Failed to request IRQ %d: %d\n",
362			touchdev->pen_irq, error);
363		return error;
364	}
365
366	return 0;
367}
368
369static const struct of_device_id vf50_touch_of_match[] = {
370	{ .compatible = "toradex,vf50-touchscreen", },
371	{ }
372};
373MODULE_DEVICE_TABLE(of, vf50_touch_of_match);
374
375static struct platform_driver vf50_touch_driver = {
376	.driver = {
377		.name = "toradex,vf50_touchctrl",
378		.of_match_table = vf50_touch_of_match,
379	},
380	.probe = vf50_ts_probe,
381};
382module_platform_driver(vf50_touch_driver);
383
384MODULE_AUTHOR("Sanchayan Maity");
385MODULE_DESCRIPTION("Colibri VF50 Touchscreen driver");
386MODULE_LICENSE("GPL");
387MODULE_VERSION(DRV_VERSION);
v5.4
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/*
  3 * Toradex Colibri VF50 Touchscreen driver
  4 *
  5 * Copyright 2015 Toradex AG
  6 *
  7 * Originally authored by Stefan Agner for 3.0 kernel
 
 
 
 
 
  8 */
  9
 10#include <linux/delay.h>
 11#include <linux/err.h>
 12#include <linux/gpio.h>
 13#include <linux/gpio/consumer.h>
 14#include <linux/iio/consumer.h>
 15#include <linux/iio/types.h>
 16#include <linux/input.h>
 17#include <linux/interrupt.h>
 18#include <linux/kernel.h>
 19#include <linux/module.h>
 20#include <linux/of.h>
 21#include <linux/pinctrl/consumer.h>
 22#include <linux/platform_device.h>
 23#include <linux/slab.h>
 24#include <linux/types.h>
 25
 26#define DRIVER_NAME			"colibri-vf50-ts"
 
 27
 28#define VF_ADC_MAX			((1 << 12) - 1)
 29
 30#define COLI_TOUCH_MIN_DELAY_US		1000
 31#define COLI_TOUCH_MAX_DELAY_US		2000
 32#define COLI_PULLUP_MIN_DELAY_US	10000
 33#define COLI_PULLUP_MAX_DELAY_US	11000
 34#define COLI_TOUCH_NO_OF_AVGS		5
 35#define COLI_TOUCH_REQ_ADC_CHAN		4
 36
 37struct vf50_touch_device {
 38	struct platform_device *pdev;
 39	struct input_dev *ts_input;
 40	struct iio_channel *channels;
 41	struct gpio_desc *gpio_xp;
 42	struct gpio_desc *gpio_xm;
 43	struct gpio_desc *gpio_yp;
 44	struct gpio_desc *gpio_ym;
 45	int pen_irq;
 46	int min_pressure;
 47	bool stop_touchscreen;
 48};
 49
 50/*
 51 * Enables given plates and measures touch parameters using ADC
 52 */
 53static int adc_ts_measure(struct iio_channel *channel,
 54			  struct gpio_desc *plate_p, struct gpio_desc *plate_m)
 55{
 56	int i, value = 0, val = 0;
 57	int error;
 58
 59	gpiod_set_value(plate_p, 1);
 60	gpiod_set_value(plate_m, 1);
 61
 62	usleep_range(COLI_TOUCH_MIN_DELAY_US, COLI_TOUCH_MAX_DELAY_US);
 63
 64	for (i = 0; i < COLI_TOUCH_NO_OF_AVGS; i++) {
 65		error = iio_read_channel_raw(channel, &val);
 66		if (error < 0) {
 67			value = error;
 68			goto error_iio_read;
 69		}
 70
 71		value += val;
 72	}
 73
 74	value /= COLI_TOUCH_NO_OF_AVGS;
 75
 76error_iio_read:
 77	gpiod_set_value(plate_p, 0);
 78	gpiod_set_value(plate_m, 0);
 79
 80	return value;
 81}
 82
 83/*
 84 * Enable touch detection using falling edge detection on XM
 85 */
 86static void vf50_ts_enable_touch_detection(struct vf50_touch_device *vf50_ts)
 87{
 88	/* Enable plate YM (needs to be strong GND, high active) */
 89	gpiod_set_value(vf50_ts->gpio_ym, 1);
 90
 91	/*
 92	 * Let the platform mux to idle state in order to enable
 93	 * Pull-Up on GPIO
 94	 */
 95	pinctrl_pm_select_idle_state(&vf50_ts->pdev->dev);
 96
 97	/* Wait for the pull-up to be stable on high */
 98	usleep_range(COLI_PULLUP_MIN_DELAY_US, COLI_PULLUP_MAX_DELAY_US);
 99}
100
101/*
102 * ADC touch screen sampling bottom half irq handler
103 */
104static irqreturn_t vf50_ts_irq_bh(int irq, void *private)
105{
106	struct vf50_touch_device *vf50_ts = private;
107	struct device *dev = &vf50_ts->pdev->dev;
108	int val_x, val_y, val_z1, val_z2, val_p = 0;
109	bool discard_val_on_start = true;
110
111	/* Disable the touch detection plates */
112	gpiod_set_value(vf50_ts->gpio_ym, 0);
113
114	/* Let the platform mux to default state in order to mux as ADC */
115	pinctrl_pm_select_default_state(dev);
116
117	while (!vf50_ts->stop_touchscreen) {
118		/* X-Direction */
119		val_x = adc_ts_measure(&vf50_ts->channels[0],
120				vf50_ts->gpio_xp, vf50_ts->gpio_xm);
121		if (val_x < 0)
122			break;
123
124		/* Y-Direction */
125		val_y = adc_ts_measure(&vf50_ts->channels[1],
126				vf50_ts->gpio_yp, vf50_ts->gpio_ym);
127		if (val_y < 0)
128			break;
129
130		/*
131		 * Touch pressure
132		 * Measure on XP/YM
133		 */
134		val_z1 = adc_ts_measure(&vf50_ts->channels[2],
135				vf50_ts->gpio_yp, vf50_ts->gpio_xm);
136		if (val_z1 < 0)
137			break;
138		val_z2 = adc_ts_measure(&vf50_ts->channels[3],
139				vf50_ts->gpio_yp, vf50_ts->gpio_xm);
140		if (val_z2 < 0)
141			break;
142
143		/* Validate signal (avoid calculation using noise) */
144		if (val_z1 > 64 && val_x > 64) {
145			/*
146			 * Calculate resistance between the plates
147			 * lower resistance means higher pressure
148			 */
149			int r_x = (1000 * val_x) / VF_ADC_MAX;
150
151			val_p = (r_x * val_z2) / val_z1 - r_x;
152
153		} else {
154			val_p = 2000;
155		}
156
157		val_p = 2000 - val_p;
158		dev_dbg(dev,
159			"Measured values: x: %d, y: %d, z1: %d, z2: %d, p: %d\n",
160			val_x, val_y, val_z1, val_z2, val_p);
161
162		/*
163		 * If touch pressure is too low, stop measuring and reenable
164		 * touch detection
165		 */
166		if (val_p < vf50_ts->min_pressure || val_p > 2000)
167			break;
168
169		/*
170		 * The pressure may not be enough for the first x and the
171		 * second y measurement, but, the pressure is ok when the
172		 * driver is doing the third and fourth measurement. To
173		 * take care of this, we drop the first measurement always.
174		 */
175		if (discard_val_on_start) {
176			discard_val_on_start = false;
177		} else {
178			/*
179			 * Report touch position and sleep for
180			 * the next measurement.
181			 */
182			input_report_abs(vf50_ts->ts_input,
183					ABS_X, VF_ADC_MAX - val_x);
184			input_report_abs(vf50_ts->ts_input,
185					ABS_Y, VF_ADC_MAX - val_y);
186			input_report_abs(vf50_ts->ts_input,
187					ABS_PRESSURE, val_p);
188			input_report_key(vf50_ts->ts_input, BTN_TOUCH, 1);
189			input_sync(vf50_ts->ts_input);
190		}
191
192		usleep_range(COLI_PULLUP_MIN_DELAY_US,
193			     COLI_PULLUP_MAX_DELAY_US);
194	}
195
196	/* Report no more touch, re-enable touch detection */
197	input_report_abs(vf50_ts->ts_input, ABS_PRESSURE, 0);
198	input_report_key(vf50_ts->ts_input, BTN_TOUCH, 0);
199	input_sync(vf50_ts->ts_input);
200
201	vf50_ts_enable_touch_detection(vf50_ts);
202
203	return IRQ_HANDLED;
204}
205
206static int vf50_ts_open(struct input_dev *dev_input)
207{
208	struct vf50_touch_device *touchdev = input_get_drvdata(dev_input);
209	struct device *dev = &touchdev->pdev->dev;
210
211	dev_dbg(dev, "Input device %s opened, starting touch detection\n",
212		dev_input->name);
213
214	touchdev->stop_touchscreen = false;
215
216	/* Mux detection before request IRQ, wait for pull-up to settle */
217	vf50_ts_enable_touch_detection(touchdev);
218
219	return 0;
220}
221
222static void vf50_ts_close(struct input_dev *dev_input)
223{
224	struct vf50_touch_device *touchdev = input_get_drvdata(dev_input);
225	struct device *dev = &touchdev->pdev->dev;
226
227	touchdev->stop_touchscreen = true;
228
229	/* Make sure IRQ is not running past close */
230	mb();
231	synchronize_irq(touchdev->pen_irq);
232
233	gpiod_set_value(touchdev->gpio_ym, 0);
234	pinctrl_pm_select_default_state(dev);
235
236	dev_dbg(dev, "Input device %s closed, disable touch detection\n",
237		dev_input->name);
238}
239
240static int vf50_ts_get_gpiod(struct device *dev, struct gpio_desc **gpio_d,
241			     const char *con_id, enum gpiod_flags flags)
242{
243	int error;
244
245	*gpio_d = devm_gpiod_get(dev, con_id, flags);
246	if (IS_ERR(*gpio_d)) {
247		error = PTR_ERR(*gpio_d);
248		dev_err(dev, "Could not get gpio_%s %d\n", con_id, error);
249		return error;
250	}
251
252	return 0;
253}
254
255static void vf50_ts_channel_release(void *data)
256{
257	struct iio_channel *channels = data;
258
259	iio_channel_release_all(channels);
260}
261
262static int vf50_ts_probe(struct platform_device *pdev)
263{
264	struct input_dev *input;
265	struct iio_channel *channels;
266	struct device *dev = &pdev->dev;
267	struct vf50_touch_device *touchdev;
268	int num_adc_channels;
269	int error;
270
271	channels = iio_channel_get_all(dev);
272	if (IS_ERR(channels))
273		return PTR_ERR(channels);
274
275	error = devm_add_action(dev, vf50_ts_channel_release, channels);
276	if (error) {
277		iio_channel_release_all(channels);
278		dev_err(dev, "Failed to register iio channel release action");
279		return error;
280	}
281
282	num_adc_channels = 0;
283	while (channels[num_adc_channels].indio_dev)
284		num_adc_channels++;
285
286	if (num_adc_channels != COLI_TOUCH_REQ_ADC_CHAN) {
287		dev_err(dev, "Inadequate ADC channels specified\n");
288		return -EINVAL;
289	}
290
291	touchdev = devm_kzalloc(dev, sizeof(*touchdev), GFP_KERNEL);
292	if (!touchdev)
293		return -ENOMEM;
294
295	touchdev->pdev = pdev;
296	touchdev->channels = channels;
297
298	error = of_property_read_u32(dev->of_node, "vf50-ts-min-pressure",
299				 &touchdev->min_pressure);
300	if (error)
301		return error;
302
303	input = devm_input_allocate_device(dev);
304	if (!input) {
305		dev_err(dev, "Failed to allocate TS input device\n");
306		return -ENOMEM;
307	}
308
 
 
309	input->name = DRIVER_NAME;
310	input->id.bustype = BUS_HOST;
311	input->dev.parent = dev;
312	input->open = vf50_ts_open;
313	input->close = vf50_ts_close;
314
315	input_set_capability(input, EV_KEY, BTN_TOUCH);
316	input_set_abs_params(input, ABS_X, 0, VF_ADC_MAX, 0, 0);
317	input_set_abs_params(input, ABS_Y, 0, VF_ADC_MAX, 0, 0);
318	input_set_abs_params(input, ABS_PRESSURE, 0, VF_ADC_MAX, 0, 0);
319
320	touchdev->ts_input = input;
321	input_set_drvdata(input, touchdev);
322
323	error = input_register_device(input);
324	if (error) {
325		dev_err(dev, "Failed to register input device\n");
326		return error;
327	}
328
329	error = vf50_ts_get_gpiod(dev, &touchdev->gpio_xp, "xp", GPIOD_OUT_LOW);
330	if (error)
331		return error;
332
333	error = vf50_ts_get_gpiod(dev, &touchdev->gpio_xm,
334				"xm", GPIOD_OUT_LOW);
335	if (error)
336		return error;
337
338	error = vf50_ts_get_gpiod(dev, &touchdev->gpio_yp, "yp", GPIOD_OUT_LOW);
339	if (error)
340		return error;
341
342	error = vf50_ts_get_gpiod(dev, &touchdev->gpio_ym, "ym", GPIOD_OUT_LOW);
343	if (error)
344		return error;
345
346	touchdev->pen_irq = platform_get_irq(pdev, 0);
347	if (touchdev->pen_irq < 0)
348		return touchdev->pen_irq;
349
350	error = devm_request_threaded_irq(dev, touchdev->pen_irq,
351					  NULL, vf50_ts_irq_bh, IRQF_ONESHOT,
352					  "vf50 touch", touchdev);
353	if (error) {
354		dev_err(dev, "Failed to request IRQ %d: %d\n",
355			touchdev->pen_irq, error);
356		return error;
357	}
358
359	return 0;
360}
361
362static const struct of_device_id vf50_touch_of_match[] = {
363	{ .compatible = "toradex,vf50-touchscreen", },
364	{ }
365};
366MODULE_DEVICE_TABLE(of, vf50_touch_of_match);
367
368static struct platform_driver vf50_touch_driver = {
369	.driver = {
370		.name = "toradex,vf50_touchctrl",
371		.of_match_table = vf50_touch_of_match,
372	},
373	.probe = vf50_ts_probe,
374};
375module_platform_driver(vf50_touch_driver);
376
377MODULE_AUTHOR("Sanchayan Maity");
378MODULE_DESCRIPTION("Colibri VF50 Touchscreen driver");
379MODULE_LICENSE("GPL");