aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2016-10-11 16:22:22 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-10-11 16:22:22 -0400
commitde34f4da7f62ff59ac6e1ef320b0fcfa3296fce3 (patch)
tree88b5db2fc7fbbb0353edd8447a832a5225a49d01 /drivers/input
parent56e520c7a0a490b63b042b047ec9659fc08762a4 (diff)
parent9fce0c226536fc36c7fb0a80000ca38a995be43e (diff)
Merge tag 'media/v4.9-1' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media
Pull media updates from Mauro Carvalho Chehab: - Documentation improvements: conversion of all non-DocBook documents to Sphinx and lots of fixes to the uAPI media book - New PCI driver for Techwell TW5864 media grabber boards - New SoC driver for ATMEL Image Sensor Controller - Removal of some obsolete SoC drivers (s5p-tv driver and soc_camera drivers) - Addition of ST CEC driver - Lots of drivers fixes, improvements and additions * tag 'media/v4.9-1' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media: (464 commits) [media] ttusb_dec: avoid the risk of go past buffer [media] cx23885: Fix some smatch warnings [media] si2165: switch to regmap [media] si2165: use i2c_client->dev instead of i2c_adapter->dev for logging [media] si2165: Remove legacy attach [media] cx231xx: attach si2165 driver via i2c_client [media] cx231xx: Prepare for attaching new style i2c_client DVB demod drivers [media] cx23885: attach si2165 driver via i2c_client [media] si2165: support i2c_client attach [media] si2165: avoid division by zero [media] rcar-vin: add R-Car gen2 fallback compatibility string [media] lgdt3306a: remove 20*50 msec unnecessary timeout [media] cx25821: Remove deprecated create_singlethread_workqueue [media] cx25821: Drop Freeing of Workqueue [media] cxd2841er: force 8MHz bandwidth for DVB-C if specified bw not supported [media] redrat3: hardware-specific parameters [media] redrat3: remove hw_timeout member [media] cxd2841er: BER and SNR reading for ISDB-T [media] dvb-usb: avoid link error with dib3000m{b,c| [media] dvb-usb: split out common parts of dibusb ...
Diffstat (limited to 'drivers/input')
-rw-r--r--drivers/input/rmi4/Kconfig11
-rw-r--r--drivers/input/rmi4/Makefile1
-rw-r--r--drivers/input/rmi4/rmi_bus.c3
-rw-r--r--drivers/input/rmi4/rmi_driver.h1
-rw-r--r--drivers/input/rmi4/rmi_f54.c757
-rw-r--r--drivers/input/touchscreen/Kconfig9
-rw-r--r--drivers/input/touchscreen/atmel_mxt_ts.c521
-rw-r--r--drivers/input/touchscreen/sur40.c142
8 files changed, 1411 insertions, 34 deletions
diff --git a/drivers/input/rmi4/Kconfig b/drivers/input/rmi4/Kconfig
index f73df2495fed..4c8a55857e00 100644
--- a/drivers/input/rmi4/Kconfig
+++ b/drivers/input/rmi4/Kconfig
@@ -61,3 +61,14 @@ config RMI4_F30
61 61
62 Function 30 provides GPIO and LED support for RMI4 devices. This 62 Function 30 provides GPIO and LED support for RMI4 devices. This
63 includes support for buttons on TouchPads and ClickPads. 63 includes support for buttons on TouchPads and ClickPads.
64
65config RMI4_F54
66 bool "RMI4 Function 54 (Analog diagnostics)"
67 depends on RMI4_CORE
68 depends on VIDEO_V4L2=y || (RMI4_CORE=m && VIDEO_V4L2=m)
69 select VIDEOBUF2_VMALLOC
70 help
71 Say Y here if you want to add support for RMI4 function 54
72
73 Function 54 provides access to various diagnostic features in certain
74 RMI4 touch sensors.
diff --git a/drivers/input/rmi4/Makefile b/drivers/input/rmi4/Makefile
index 95c00a783992..0bafc8502c4b 100644
--- a/drivers/input/rmi4/Makefile
+++ b/drivers/input/rmi4/Makefile
@@ -7,6 +7,7 @@ rmi_core-$(CONFIG_RMI4_2D_SENSOR) += rmi_2d_sensor.o
7rmi_core-$(CONFIG_RMI4_F11) += rmi_f11.o 7rmi_core-$(CONFIG_RMI4_F11) += rmi_f11.o
8rmi_core-$(CONFIG_RMI4_F12) += rmi_f12.o 8rmi_core-$(CONFIG_RMI4_F12) += rmi_f12.o
9rmi_core-$(CONFIG_RMI4_F30) += rmi_f30.o 9rmi_core-$(CONFIG_RMI4_F30) += rmi_f30.o
10rmi_core-$(CONFIG_RMI4_F54) += rmi_f54.o
10 11
11# Transports 12# Transports
12obj-$(CONFIG_RMI4_I2C) += rmi_i2c.o 13obj-$(CONFIG_RMI4_I2C) += rmi_i2c.o
diff --git a/drivers/input/rmi4/rmi_bus.c b/drivers/input/rmi4/rmi_bus.c
index a73580654c6b..09c769c6e91f 100644
--- a/drivers/input/rmi4/rmi_bus.c
+++ b/drivers/input/rmi4/rmi_bus.c
@@ -312,6 +312,9 @@ static struct rmi_function_handler *fn_handlers[] = {
312#ifdef CONFIG_RMI4_F30 312#ifdef CONFIG_RMI4_F30
313 &rmi_f30_handler, 313 &rmi_f30_handler,
314#endif 314#endif
315#ifdef CONFIG_RMI4_F54
316 &rmi_f54_handler,
317#endif
315}; 318};
316 319
317static void __rmi_unregister_function_handlers(int start_idx) 320static void __rmi_unregister_function_handlers(int start_idx)
diff --git a/drivers/input/rmi4/rmi_driver.h b/drivers/input/rmi4/rmi_driver.h
index 6e140fa3cce1..8dfbebe9bf86 100644
--- a/drivers/input/rmi4/rmi_driver.h
+++ b/drivers/input/rmi4/rmi_driver.h
@@ -102,4 +102,5 @@ extern struct rmi_function_handler rmi_f01_handler;
102extern struct rmi_function_handler rmi_f11_handler; 102extern struct rmi_function_handler rmi_f11_handler;
103extern struct rmi_function_handler rmi_f12_handler; 103extern struct rmi_function_handler rmi_f12_handler;
104extern struct rmi_function_handler rmi_f30_handler; 104extern struct rmi_function_handler rmi_f30_handler;
105extern struct rmi_function_handler rmi_f54_handler;
105#endif 106#endif
diff --git a/drivers/input/rmi4/rmi_f54.c b/drivers/input/rmi4/rmi_f54.c
new file mode 100644
index 000000000000..cf805b960866
--- /dev/null
+++ b/drivers/input/rmi4/rmi_f54.c
@@ -0,0 +1,757 @@
1/*
2 * Copyright (c) 2012-2015 Synaptics Incorporated
3 * Copyright (C) 2016 Zodiac Inflight Innovations
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published by
7 * the Free Software Foundation.
8 */
9
10#include <linux/kernel.h>
11#include <linux/rmi.h>
12#include <linux/input.h>
13#include <linux/slab.h>
14#include <linux/delay.h>
15#include <linux/i2c.h>
16#include <media/v4l2-device.h>
17#include <media/v4l2-ioctl.h>
18#include <media/videobuf2-v4l2.h>
19#include <media/videobuf2-vmalloc.h>
20#include "rmi_driver.h"
21
22#define F54_NAME "rmi4_f54"
23
24/* F54 data offsets */
25#define F54_REPORT_DATA_OFFSET 3
26#define F54_FIFO_OFFSET 1
27#define F54_NUM_TX_OFFSET 1
28#define F54_NUM_RX_OFFSET 0
29
30/* F54 commands */
31#define F54_GET_REPORT 1
32#define F54_FORCE_CAL 2
33
34/* Fixed sizes of reports */
35#define F54_QUERY_LEN 27
36
37/* F54 capabilities */
38#define F54_CAP_BASELINE (1 << 2)
39#define F54_CAP_IMAGE8 (1 << 3)
40#define F54_CAP_IMAGE16 (1 << 6)
41
42/**
43 * enum rmi_f54_report_type - RMI4 F54 report types
44 *
45 * @F54_8BIT_IMAGE: Normalized 8-Bit Image Report. The capacitance variance
46 * from baseline for each pixel.
47 *
48 * @F54_16BIT_IMAGE: Normalized 16-Bit Image Report. The capacitance variance
49 * from baseline for each pixel.
50 *
51 * @F54_RAW_16BIT_IMAGE:
52 * Raw 16-Bit Image Report. The raw capacitance for each
53 * pixel.
54 *
55 * @F54_TRUE_BASELINE: True Baseline Report. The baseline capacitance for each
56 * pixel.
57 *
58 * @F54_FULL_RAW_CAP: Full Raw Capacitance Report. The raw capacitance with
59 * low reference set to its minimum value and high
60 * reference set to its maximum value.
61 *
62 * @F54_FULL_RAW_CAP_RX_OFFSET_REMOVED:
63 * Full Raw Capacitance with Receiver Offset Removed
64 * Report. Set Low reference to its minimum value and high
65 * references to its maximum value, then report the raw
66 * capacitance for each pixel.
67 */
68enum rmi_f54_report_type {
69 F54_REPORT_NONE = 0,
70 F54_8BIT_IMAGE = 1,
71 F54_16BIT_IMAGE = 2,
72 F54_RAW_16BIT_IMAGE = 3,
73 F54_TRUE_BASELINE = 9,
74 F54_FULL_RAW_CAP = 19,
75 F54_FULL_RAW_CAP_RX_OFFSET_REMOVED = 20,
76 F54_MAX_REPORT_TYPE,
77};
78
79const char *rmi_f54_report_type_names[] = {
80 [F54_REPORT_NONE] = "Unknown",
81 [F54_8BIT_IMAGE] = "Normalized 8-Bit Image",
82 [F54_16BIT_IMAGE] = "Normalized 16-Bit Image",
83 [F54_RAW_16BIT_IMAGE] = "Raw 16-Bit Image",
84 [F54_TRUE_BASELINE] = "True Baseline",
85 [F54_FULL_RAW_CAP] = "Full Raw Capacitance",
86 [F54_FULL_RAW_CAP_RX_OFFSET_REMOVED]
87 = "Full Raw Capacitance RX Offset Removed",
88};
89
90struct rmi_f54_reports {
91 int start;
92 int size;
93};
94
95struct f54_data {
96 struct rmi_function *fn;
97
98 u8 qry[F54_QUERY_LEN];
99 u8 num_rx_electrodes;
100 u8 num_tx_electrodes;
101 u8 capabilities;
102 u16 clock_rate;
103 u8 family;
104
105 enum rmi_f54_report_type report_type;
106 u8 *report_data;
107 int report_size;
108 struct rmi_f54_reports standard_report[2];
109
110 bool is_busy;
111 struct mutex status_mutex;
112 struct mutex data_mutex;
113
114 struct workqueue_struct *workqueue;
115 struct delayed_work work;
116 unsigned long timeout;
117
118 struct completion cmd_done;
119
120 /* V4L2 support */
121 struct v4l2_device v4l2;
122 struct v4l2_pix_format format;
123 struct video_device vdev;
124 struct vb2_queue queue;
125 struct mutex lock;
126 int input;
127 enum rmi_f54_report_type inputs[F54_MAX_REPORT_TYPE];
128};
129
130/*
131 * Basic checks on report_type to ensure we write a valid type
132 * to the sensor.
133 */
134static bool is_f54_report_type_valid(struct f54_data *f54,
135 enum rmi_f54_report_type reptype)
136{
137 switch (reptype) {
138 case F54_8BIT_IMAGE:
139 return f54->capabilities & F54_CAP_IMAGE8;
140 case F54_16BIT_IMAGE:
141 case F54_RAW_16BIT_IMAGE:
142 return f54->capabilities & F54_CAP_IMAGE16;
143 case F54_TRUE_BASELINE:
144 return f54->capabilities & F54_CAP_IMAGE16;
145 case F54_FULL_RAW_CAP:
146 case F54_FULL_RAW_CAP_RX_OFFSET_REMOVED:
147 return true;
148 default:
149 return false;
150 }
151}
152
153static enum rmi_f54_report_type rmi_f54_get_reptype(struct f54_data *f54,
154 unsigned int i)
155{
156 if (i >= F54_MAX_REPORT_TYPE)
157 return F54_REPORT_NONE;
158
159 return f54->inputs[i];
160}
161
162static void rmi_f54_create_input_map(struct f54_data *f54)
163{
164 int i = 0;
165 enum rmi_f54_report_type reptype;
166
167 for (reptype = 1; reptype < F54_MAX_REPORT_TYPE; reptype++) {
168 if (!is_f54_report_type_valid(f54, reptype))
169 continue;
170
171 f54->inputs[i++] = reptype;
172 }
173
174 /* Remaining values are zero via kzalloc */
175}
176
177static int rmi_f54_request_report(struct rmi_function *fn, u8 report_type)
178{
179 struct f54_data *f54 = dev_get_drvdata(&fn->dev);
180 struct rmi_device *rmi_dev = fn->rmi_dev;
181 int error;
182
183 /* Write Report Type into F54_AD_Data0 */
184 if (f54->report_type != report_type) {
185 error = rmi_write(rmi_dev, f54->fn->fd.data_base_addr,
186 report_type);
187 if (error)
188 return error;
189 f54->report_type = report_type;
190 }
191
192 /*
193 * Small delay after disabling interrupts to avoid race condition
194 * in firmare. This value is a bit higher than absolutely necessary.
195 * Should be removed once issue is resolved in firmware.
196 */
197 usleep_range(2000, 3000);
198
199 mutex_lock(&f54->data_mutex);
200
201 error = rmi_write(rmi_dev, fn->fd.command_base_addr, F54_GET_REPORT);
202 if (error < 0)
203 return error;
204
205 init_completion(&f54->cmd_done);
206
207 f54->is_busy = 1;
208 f54->timeout = jiffies + msecs_to_jiffies(100);
209
210 queue_delayed_work(f54->workqueue, &f54->work, 0);
211
212 mutex_unlock(&f54->data_mutex);
213
214 return 0;
215}
216
217static size_t rmi_f54_get_report_size(struct f54_data *f54)
218{
219 u8 rx = f54->num_rx_electrodes ? : f54->num_rx_electrodes;
220 u8 tx = f54->num_tx_electrodes ? : f54->num_tx_electrodes;
221 size_t size;
222
223 switch (rmi_f54_get_reptype(f54, f54->input)) {
224 case F54_8BIT_IMAGE:
225 size = rx * tx;
226 break;
227 case F54_16BIT_IMAGE:
228 case F54_RAW_16BIT_IMAGE:
229 case F54_TRUE_BASELINE:
230 case F54_FULL_RAW_CAP:
231 case F54_FULL_RAW_CAP_RX_OFFSET_REMOVED:
232 size = sizeof(u16) * rx * tx;
233 break;
234 default:
235 size = 0;
236 }
237
238 return size;
239}
240
241static int rmi_f54_get_pixel_fmt(enum rmi_f54_report_type reptype, u32 *pixfmt)
242{
243 int ret = 0;
244
245 switch (reptype) {
246 case F54_8BIT_IMAGE:
247 *pixfmt = V4L2_TCH_FMT_DELTA_TD08;
248 break;
249
250 case F54_16BIT_IMAGE:
251 *pixfmt = V4L2_TCH_FMT_DELTA_TD16;
252 break;
253
254 case F54_RAW_16BIT_IMAGE:
255 case F54_TRUE_BASELINE:
256 case F54_FULL_RAW_CAP:
257 case F54_FULL_RAW_CAP_RX_OFFSET_REMOVED:
258 *pixfmt = V4L2_TCH_FMT_TU16;
259 break;
260
261 case F54_REPORT_NONE:
262 case F54_MAX_REPORT_TYPE:
263 ret = -EINVAL;
264 break;
265 }
266
267 return ret;
268}
269
270static const struct v4l2_file_operations rmi_f54_video_fops = {
271 .owner = THIS_MODULE,
272 .open = v4l2_fh_open,
273 .release = vb2_fop_release,
274 .unlocked_ioctl = video_ioctl2,
275 .read = vb2_fop_read,
276 .mmap = vb2_fop_mmap,
277 .poll = vb2_fop_poll,
278};
279
280static int rmi_f54_queue_setup(struct vb2_queue *q, unsigned int *nbuffers,
281 unsigned int *nplanes, unsigned int sizes[],
282 struct device *alloc_devs[])
283{
284 struct f54_data *f54 = q->drv_priv;
285
286 if (*nplanes)
287 return sizes[0] < rmi_f54_get_report_size(f54) ? -EINVAL : 0;
288
289 *nplanes = 1;
290 sizes[0] = rmi_f54_get_report_size(f54);
291
292 return 0;
293}
294
295static void rmi_f54_buffer_queue(struct vb2_buffer *vb)
296{
297 struct f54_data *f54 = vb2_get_drv_priv(vb->vb2_queue);
298 u16 *ptr;
299 enum vb2_buffer_state state;
300 enum rmi_f54_report_type reptype;
301 int ret;
302
303 mutex_lock(&f54->status_mutex);
304
305 reptype = rmi_f54_get_reptype(f54, f54->input);
306 if (reptype == F54_REPORT_NONE) {
307 state = VB2_BUF_STATE_ERROR;
308 goto done;
309 }
310
311 if (f54->is_busy) {
312 state = VB2_BUF_STATE_ERROR;
313 goto done;
314 }
315
316 ret = rmi_f54_request_report(f54->fn, reptype);
317 if (ret) {
318 dev_err(&f54->fn->dev, "Error requesting F54 report\n");
319 state = VB2_BUF_STATE_ERROR;
320 goto done;
321 }
322
323 /* get frame data */
324 mutex_lock(&f54->data_mutex);
325
326 while (f54->is_busy) {
327 mutex_unlock(&f54->data_mutex);
328 if (!wait_for_completion_timeout(&f54->cmd_done,
329 msecs_to_jiffies(1000))) {
330 dev_err(&f54->fn->dev, "Timed out\n");
331 state = VB2_BUF_STATE_ERROR;
332 goto done;
333 }
334 mutex_lock(&f54->data_mutex);
335 }
336
337 ptr = vb2_plane_vaddr(vb, 0);
338 if (!ptr) {
339 dev_err(&f54->fn->dev, "Error acquiring frame ptr\n");
340 state = VB2_BUF_STATE_ERROR;
341 goto data_done;
342 }
343
344 memcpy(ptr, f54->report_data, f54->report_size);
345 vb2_set_plane_payload(vb, 0, rmi_f54_get_report_size(f54));
346 state = VB2_BUF_STATE_DONE;
347
348data_done:
349 mutex_unlock(&f54->data_mutex);
350done:
351 vb2_buffer_done(vb, state);
352 mutex_unlock(&f54->status_mutex);
353}
354
355/* V4L2 structures */
356static const struct vb2_ops rmi_f54_queue_ops = {
357 .queue_setup = rmi_f54_queue_setup,
358 .buf_queue = rmi_f54_buffer_queue,
359 .wait_prepare = vb2_ops_wait_prepare,
360 .wait_finish = vb2_ops_wait_finish,
361};
362
363static const struct vb2_queue rmi_f54_queue = {
364 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
365 .io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF | VB2_READ,
366 .buf_struct_size = sizeof(struct vb2_buffer),
367 .ops = &rmi_f54_queue_ops,
368 .mem_ops = &vb2_vmalloc_memops,
369 .timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC,
370 .min_buffers_needed = 1,
371};
372
373static int rmi_f54_vidioc_querycap(struct file *file, void *priv,
374 struct v4l2_capability *cap)
375{
376 struct f54_data *f54 = video_drvdata(file);
377
378 strlcpy(cap->driver, F54_NAME, sizeof(cap->driver));
379 strlcpy(cap->card, SYNAPTICS_INPUT_DEVICE_NAME, sizeof(cap->card));
380 snprintf(cap->bus_info, sizeof(cap->bus_info),
381 "rmi4:%s", dev_name(&f54->fn->dev));
382
383 return 0;
384}
385
386static int rmi_f54_vidioc_enum_input(struct file *file, void *priv,
387 struct v4l2_input *i)
388{
389 struct f54_data *f54 = video_drvdata(file);
390 enum rmi_f54_report_type reptype;
391
392 reptype = rmi_f54_get_reptype(f54, i->index);
393 if (reptype == F54_REPORT_NONE)
394 return -EINVAL;
395
396 i->type = V4L2_INPUT_TYPE_TOUCH;
397
398 strlcpy(i->name, rmi_f54_report_type_names[reptype], sizeof(i->name));
399 return 0;
400}
401
402static int rmi_f54_set_input(struct f54_data *f54, unsigned int i)
403{
404 struct v4l2_pix_format *f = &f54->format;
405 enum rmi_f54_report_type reptype;
406 int ret;
407
408 reptype = rmi_f54_get_reptype(f54, i);
409 if (reptype == F54_REPORT_NONE)
410 return -EINVAL;
411
412 ret = rmi_f54_get_pixel_fmt(reptype, &f->pixelformat);
413 if (ret)
414 return ret;
415
416 f54->input = i;
417
418 f->width = f54->num_rx_electrodes;
419 f->height = f54->num_tx_electrodes;
420 f->field = V4L2_FIELD_NONE;
421 f->colorspace = V4L2_COLORSPACE_RAW;
422 f->bytesperline = f->width * sizeof(u16);
423 f->sizeimage = f->width * f->height * sizeof(u16);
424
425 return 0;
426}
427
428static int rmi_f54_vidioc_s_input(struct file *file, void *priv, unsigned int i)
429{
430 return rmi_f54_set_input(video_drvdata(file), i);
431}
432
433static int rmi_f54_vidioc_g_input(struct file *file, void *priv,
434 unsigned int *i)
435{
436 struct f54_data *f54 = video_drvdata(file);
437
438 *i = f54->input;
439
440 return 0;
441}
442
443static int rmi_f54_vidioc_fmt(struct file *file, void *priv,
444 struct v4l2_format *f)
445{
446 struct f54_data *f54 = video_drvdata(file);
447
448 f->fmt.pix = f54->format;
449
450 return 0;
451}
452
453static int rmi_f54_vidioc_enum_fmt(struct file *file, void *priv,
454 struct v4l2_fmtdesc *fmt)
455{
456 if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
457 return -EINVAL;
458
459 switch (fmt->index) {
460 case 0:
461 fmt->pixelformat = V4L2_TCH_FMT_DELTA_TD16;
462 break;
463
464 case 1:
465 fmt->pixelformat = V4L2_TCH_FMT_DELTA_TD08;
466 break;
467
468 case 2:
469 fmt->pixelformat = V4L2_TCH_FMT_TU16;
470 break;
471
472 default:
473 return -EINVAL;
474 }
475
476 return 0;
477}
478
479static int rmi_f54_vidioc_g_parm(struct file *file, void *fh,
480 struct v4l2_streamparm *a)
481{
482 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
483 return -EINVAL;
484
485 a->parm.capture.readbuffers = 1;
486 a->parm.capture.timeperframe.numerator = 1;
487 a->parm.capture.timeperframe.denominator = 10;
488 return 0;
489}
490
491static const struct v4l2_ioctl_ops rmi_f54_video_ioctl_ops = {
492 .vidioc_querycap = rmi_f54_vidioc_querycap,
493
494 .vidioc_enum_fmt_vid_cap = rmi_f54_vidioc_enum_fmt,
495 .vidioc_s_fmt_vid_cap = rmi_f54_vidioc_fmt,
496 .vidioc_g_fmt_vid_cap = rmi_f54_vidioc_fmt,
497 .vidioc_try_fmt_vid_cap = rmi_f54_vidioc_fmt,
498 .vidioc_g_parm = rmi_f54_vidioc_g_parm,
499
500 .vidioc_enum_input = rmi_f54_vidioc_enum_input,
501 .vidioc_g_input = rmi_f54_vidioc_g_input,
502 .vidioc_s_input = rmi_f54_vidioc_s_input,
503
504 .vidioc_reqbufs = vb2_ioctl_reqbufs,
505 .vidioc_create_bufs = vb2_ioctl_create_bufs,
506 .vidioc_querybuf = vb2_ioctl_querybuf,
507 .vidioc_qbuf = vb2_ioctl_qbuf,
508 .vidioc_dqbuf = vb2_ioctl_dqbuf,
509 .vidioc_expbuf = vb2_ioctl_expbuf,
510
511 .vidioc_streamon = vb2_ioctl_streamon,
512 .vidioc_streamoff = vb2_ioctl_streamoff,
513};
514
515static const struct video_device rmi_f54_video_device = {
516 .name = "Synaptics RMI4",
517 .fops = &rmi_f54_video_fops,
518 .ioctl_ops = &rmi_f54_video_ioctl_ops,
519 .release = video_device_release_empty,
520 .device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_TOUCH |
521 V4L2_CAP_READWRITE | V4L2_CAP_STREAMING,
522};
523
524static void rmi_f54_work(struct work_struct *work)
525{
526 struct f54_data *f54 = container_of(work, struct f54_data, work.work);
527 struct rmi_function *fn = f54->fn;
528 u8 fifo[2];
529 struct rmi_f54_reports *report;
530 int report_size;
531 u8 command;
532 u8 *data;
533 int error;
534
535 data = f54->report_data;
536 report_size = rmi_f54_get_report_size(f54);
537 if (report_size == 0) {
538 dev_err(&fn->dev, "Bad report size, report type=%d\n",
539 f54->report_type);
540 error = -EINVAL;
541 goto error; /* retry won't help */
542 }
543 f54->standard_report[0].size = report_size;
544 report = f54->standard_report;
545
546 mutex_lock(&f54->data_mutex);
547
548 /*
549 * Need to check if command has completed.
550 * If not try again later.
551 */
552 error = rmi_read(fn->rmi_dev, f54->fn->fd.command_base_addr,
553 &command);
554 if (error) {
555 dev_err(&fn->dev, "Failed to read back command\n");
556 goto error;
557 }
558 if (command & F54_GET_REPORT) {
559 if (time_after(jiffies, f54->timeout)) {
560 dev_err(&fn->dev, "Get report command timed out\n");
561 error = -ETIMEDOUT;
562 }
563 report_size = 0;
564 goto error;
565 }
566
567 rmi_dbg(RMI_DEBUG_FN, &fn->dev, "Get report command completed, reading data\n");
568
569 report_size = 0;
570 for (; report->size; report++) {
571 fifo[0] = report->start & 0xff;
572 fifo[1] = (report->start >> 8) & 0xff;
573 error = rmi_write_block(fn->rmi_dev,
574 fn->fd.data_base_addr + F54_FIFO_OFFSET,
575 fifo, sizeof(fifo));
576 if (error) {
577 dev_err(&fn->dev, "Failed to set fifo start offset\n");
578 goto abort;
579 }
580
581 error = rmi_read_block(fn->rmi_dev, fn->fd.data_base_addr +
582 F54_REPORT_DATA_OFFSET, data,
583 report->size);
584 if (error) {
585 dev_err(&fn->dev, "%s: read [%d bytes] returned %d\n",
586 __func__, report->size, error);
587 goto abort;
588 }
589 data += report->size;
590 report_size += report->size;
591 }
592
593abort:
594 f54->report_size = error ? 0 : report_size;
595error:
596 if (error)
597 report_size = 0;
598
599 if (report_size == 0 && !error) {
600 queue_delayed_work(f54->workqueue, &f54->work,
601 msecs_to_jiffies(1));
602 } else {
603 f54->is_busy = false;
604 complete(&f54->cmd_done);
605 }
606
607 mutex_unlock(&f54->data_mutex);
608}
609
610static int rmi_f54_attention(struct rmi_function *fn, unsigned long *irqbits)
611{
612 return 0;
613}
614
615static int rmi_f54_config(struct rmi_function *fn)
616{
617 struct rmi_driver *drv = fn->rmi_dev->driver;
618
619 drv->set_irq_bits(fn->rmi_dev, fn->irq_mask);
620
621 return 0;
622}
623
624static int rmi_f54_detect(struct rmi_function *fn)
625{
626 int error;
627 struct f54_data *f54;
628
629 f54 = dev_get_drvdata(&fn->dev);
630
631 error = rmi_read_block(fn->rmi_dev, fn->fd.query_base_addr,
632 &f54->qry, sizeof(f54->qry));
633 if (error) {
634 dev_err(&fn->dev, "%s: Failed to query F54 properties\n",
635 __func__);
636 return error;
637 }
638
639 f54->num_rx_electrodes = f54->qry[0];
640 f54->num_tx_electrodes = f54->qry[1];
641 f54->capabilities = f54->qry[2];
642 f54->clock_rate = f54->qry[3] | (f54->qry[4] << 8);
643 f54->family = f54->qry[5];
644
645 rmi_dbg(RMI_DEBUG_FN, &fn->dev, "F54 num_rx_electrodes: %d\n",
646 f54->num_rx_electrodes);
647 rmi_dbg(RMI_DEBUG_FN, &fn->dev, "F54 num_tx_electrodes: %d\n",
648 f54->num_tx_electrodes);
649 rmi_dbg(RMI_DEBUG_FN, &fn->dev, "F54 capabilities: 0x%x\n",
650 f54->capabilities);
651 rmi_dbg(RMI_DEBUG_FN, &fn->dev, "F54 clock rate: 0x%x\n",
652 f54->clock_rate);
653 rmi_dbg(RMI_DEBUG_FN, &fn->dev, "F54 family: 0x%x\n",
654 f54->family);
655
656 f54->is_busy = false;
657
658 return 0;
659}
660
661static int rmi_f54_probe(struct rmi_function *fn)
662{
663 struct f54_data *f54;
664 int ret;
665 u8 rx, tx;
666
667 f54 = devm_kzalloc(&fn->dev, sizeof(struct f54_data), GFP_KERNEL);
668 if (!f54)
669 return -ENOMEM;
670
671 f54->fn = fn;
672 dev_set_drvdata(&fn->dev, f54);
673
674 ret = rmi_f54_detect(fn);
675 if (ret)
676 return ret;
677
678 mutex_init(&f54->data_mutex);
679 mutex_init(&f54->status_mutex);
680
681 rx = f54->num_rx_electrodes;
682 tx = f54->num_tx_electrodes;
683 f54->report_data = devm_kzalloc(&fn->dev,
684 sizeof(u16) * tx * rx,
685 GFP_KERNEL);
686 if (f54->report_data == NULL)
687 return -ENOMEM;
688
689 INIT_DELAYED_WORK(&f54->work, rmi_f54_work);
690
691 f54->workqueue = create_singlethread_workqueue("rmi4-poller");
692 if (!f54->workqueue)
693 return -ENOMEM;
694
695 rmi_f54_create_input_map(f54);
696
697 /* register video device */
698 strlcpy(f54->v4l2.name, F54_NAME, sizeof(f54->v4l2.name));
699 ret = v4l2_device_register(&fn->dev, &f54->v4l2);
700 if (ret) {
701 dev_err(&fn->dev, "Unable to register video dev.\n");
702 goto remove_wq;
703 }
704
705 /* initialize the queue */
706 mutex_init(&f54->lock);
707 f54->queue = rmi_f54_queue;
708 f54->queue.drv_priv = f54;
709 f54->queue.lock = &f54->lock;
710 f54->queue.dev = &fn->dev;
711
712 ret = vb2_queue_init(&f54->queue);
713 if (ret)
714 goto remove_v4l2;
715
716 f54->vdev = rmi_f54_video_device;
717 f54->vdev.v4l2_dev = &f54->v4l2;
718 f54->vdev.lock = &f54->lock;
719 f54->vdev.vfl_dir = VFL_DIR_RX;
720 f54->vdev.queue = &f54->queue;
721 video_set_drvdata(&f54->vdev, f54);
722
723 ret = video_register_device(&f54->vdev, VFL_TYPE_TOUCH, -1);
724 if (ret) {
725 dev_err(&fn->dev, "Unable to register video subdevice.");
726 goto remove_v4l2;
727 }
728
729 return 0;
730
731remove_v4l2:
732 v4l2_device_unregister(&f54->v4l2);
733remove_wq:
734 cancel_delayed_work_sync(&f54->work);
735 flush_workqueue(f54->workqueue);
736 destroy_workqueue(f54->workqueue);
737 return ret;
738}
739
740static void rmi_f54_remove(struct rmi_function *fn)
741{
742 struct f54_data *f54 = dev_get_drvdata(&fn->dev);
743
744 video_unregister_device(&f54->vdev);
745 v4l2_device_unregister(&f54->v4l2);
746}
747
748struct rmi_function_handler rmi_f54_handler = {
749 .driver = {
750 .name = F54_NAME,
751 },
752 .func = 0x54,
753 .probe = rmi_f54_probe,
754 .config = rmi_f54_config,
755 .attention = rmi_f54_attention,
756 .remove = rmi_f54_remove,
757};
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig
index 507981356921..efca0133e266 100644
--- a/drivers/input/touchscreen/Kconfig
+++ b/drivers/input/touchscreen/Kconfig
@@ -115,6 +115,15 @@ config TOUCHSCREEN_ATMEL_MXT
115 To compile this driver as a module, choose M here: the 115 To compile this driver as a module, choose M here: the
116 module will be called atmel_mxt_ts. 116 module will be called atmel_mxt_ts.
117 117
118config TOUCHSCREEN_ATMEL_MXT_T37
119 bool "Support T37 Diagnostic Data"
120 depends on TOUCHSCREEN_ATMEL_MXT
121 depends on VIDEO_V4L2=y || (TOUCHSCREEN_ATMEL_MXT=m && VIDEO_V4L2=m)
122 select VIDEOBUF2_VMALLOC
123 help
124 Say Y here if you want support to output data from the T37
125 Diagnostic Data object using a V4L device.
126
118config TOUCHSCREEN_AUO_PIXCIR 127config TOUCHSCREEN_AUO_PIXCIR
119 tristate "AUO in-cell touchscreen using Pixcir ICs" 128 tristate "AUO in-cell touchscreen using Pixcir ICs"
120 depends on I2C 129 depends on I2C
diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index 5af7907d0af4..e5d185fe69b9 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -4,6 +4,7 @@
4 * Copyright (C) 2010 Samsung Electronics Co.Ltd 4 * Copyright (C) 2010 Samsung Electronics Co.Ltd
5 * Copyright (C) 2011-2014 Atmel Corporation 5 * Copyright (C) 2011-2014 Atmel Corporation
6 * Copyright (C) 2012 Google, Inc. 6 * Copyright (C) 2012 Google, Inc.
7 * Copyright (C) 2016 Zodiac Inflight Innovations
7 * 8 *
8 * Author: Joonyoung Shim <jy0922.shim@samsung.com> 9 * Author: Joonyoung Shim <jy0922.shim@samsung.com>
9 * 10 *
@@ -28,6 +29,10 @@
28#include <linux/of.h> 29#include <linux/of.h>
29#include <linux/slab.h> 30#include <linux/slab.h>
30#include <asm/unaligned.h> 31#include <asm/unaligned.h>
32#include <media/v4l2-device.h>
33#include <media/v4l2-ioctl.h>
34#include <media/videobuf2-v4l2.h>
35#include <media/videobuf2-vmalloc.h>
31 36
32/* Firmware files */ 37/* Firmware files */
33#define MXT_FW_NAME "maxtouch.fw" 38#define MXT_FW_NAME "maxtouch.fw"
@@ -99,6 +104,8 @@ struct t7_config {
99 104
100/* MXT_TOUCH_MULTI_T9 field */ 105/* MXT_TOUCH_MULTI_T9 field */
101#define MXT_T9_CTRL 0 106#define MXT_T9_CTRL 0
107#define MXT_T9_XSIZE 3
108#define MXT_T9_YSIZE 4
102#define MXT_T9_ORIENT 9 109#define MXT_T9_ORIENT 9
103#define MXT_T9_RANGE 18 110#define MXT_T9_RANGE 18
104 111
@@ -119,11 +126,31 @@ struct t9_range {
119 126
120/* MXT_TOUCH_MULTI_T9 orient */ 127/* MXT_TOUCH_MULTI_T9 orient */
121#define MXT_T9_ORIENT_SWITCH (1 << 0) 128#define MXT_T9_ORIENT_SWITCH (1 << 0)
129#define MXT_T9_ORIENT_INVERTX (1 << 1)
130#define MXT_T9_ORIENT_INVERTY (1 << 2)
122 131
123/* MXT_SPT_COMMSCONFIG_T18 */ 132/* MXT_SPT_COMMSCONFIG_T18 */
124#define MXT_COMMS_CTRL 0 133#define MXT_COMMS_CTRL 0
125#define MXT_COMMS_CMD 1 134#define MXT_COMMS_CMD 1
126 135
136/* MXT_DEBUG_DIAGNOSTIC_T37 */
137#define MXT_DIAGNOSTIC_PAGEUP 0x01
138#define MXT_DIAGNOSTIC_DELTAS 0x10
139#define MXT_DIAGNOSTIC_REFS 0x11
140#define MXT_DIAGNOSTIC_SIZE 128
141
142#define MXT_FAMILY_1386 160
143#define MXT1386_COLUMNS 3
144#define MXT1386_PAGES_PER_COLUMN 8
145
146struct t37_debug {
147#ifdef CONFIG_TOUCHSCREEN_ATMEL_MXT_T37
148 u8 mode;
149 u8 page;
150 u8 data[MXT_DIAGNOSTIC_SIZE];
151#endif
152};
153
127/* Define for MXT_GEN_COMMAND_T6 */ 154/* Define for MXT_GEN_COMMAND_T6 */
128#define MXT_BOOT_VALUE 0xa5 155#define MXT_BOOT_VALUE 0xa5
129#define MXT_RESET_VALUE 0x01 156#define MXT_RESET_VALUE 0x01
@@ -133,10 +160,14 @@ struct t9_range {
133#define MXT_T100_CTRL 0 160#define MXT_T100_CTRL 0
134#define MXT_T100_CFG1 1 161#define MXT_T100_CFG1 1
135#define MXT_T100_TCHAUX 3 162#define MXT_T100_TCHAUX 3
163#define MXT_T100_XSIZE 9
136#define MXT_T100_XRANGE 13 164#define MXT_T100_XRANGE 13
165#define MXT_T100_YSIZE 20
137#define MXT_T100_YRANGE 24 166#define MXT_T100_YRANGE 24
138 167
139#define MXT_T100_CFG_SWITCHXY BIT(5) 168#define MXT_T100_CFG_SWITCHXY BIT(5)
169#define MXT_T100_CFG_INVERTY BIT(6)
170#define MXT_T100_CFG_INVERTX BIT(7)
140 171
141#define MXT_T100_TCHAUX_VECT BIT(0) 172#define MXT_T100_TCHAUX_VECT BIT(0)
142#define MXT_T100_TCHAUX_AMPL BIT(1) 173#define MXT_T100_TCHAUX_AMPL BIT(1)
@@ -205,6 +236,37 @@ struct mxt_object {
205 u8 num_report_ids; 236 u8 num_report_ids;
206} __packed; 237} __packed;
207 238
239struct mxt_dbg {
240 u16 t37_address;
241 u16 diag_cmd_address;
242 struct t37_debug *t37_buf;
243 unsigned int t37_pages;
244 unsigned int t37_nodes;
245
246 struct v4l2_device v4l2;
247 struct v4l2_pix_format format;
248 struct video_device vdev;
249 struct vb2_queue queue;
250 struct mutex lock;
251 int input;
252};
253
254enum v4l_dbg_inputs {
255 MXT_V4L_INPUT_DELTAS,
256 MXT_V4L_INPUT_REFS,
257 MXT_V4L_INPUT_MAX,
258};
259
260static const struct v4l2_file_operations mxt_video_fops = {
261 .owner = THIS_MODULE,
262 .open = v4l2_fh_open,
263 .release = vb2_fop_release,
264 .unlocked_ioctl = video_ioctl2,
265 .read = vb2_fop_read,
266 .mmap = vb2_fop_mmap,
267 .poll = vb2_fop_poll,
268};
269
208/* Each client has this additional data */ 270/* Each client has this additional data */
209struct mxt_data { 271struct mxt_data {
210 struct i2c_client *client; 272 struct i2c_client *client;
@@ -216,7 +278,11 @@ struct mxt_data {
216 unsigned int irq; 278 unsigned int irq;
217 unsigned int max_x; 279 unsigned int max_x;
218 unsigned int max_y; 280 unsigned int max_y;
281 bool invertx;
282 bool inverty;
219 bool xy_switch; 283 bool xy_switch;
284 u8 xsize;
285 u8 ysize;
220 bool in_bootloader; 286 bool in_bootloader;
221 u16 mem_size; 287 u16 mem_size;
222 u8 t100_aux_ampl; 288 u8 t100_aux_ampl;
@@ -233,6 +299,7 @@ struct mxt_data {
233 u8 num_touchids; 299 u8 num_touchids;
234 u8 multitouch; 300 u8 multitouch;
235 struct t7_config t7_cfg; 301 struct t7_config t7_cfg;
302 struct mxt_dbg dbg;
236 303
237 /* Cached parameters from object table */ 304 /* Cached parameters from object table */
238 u16 T5_address; 305 u16 T5_address;
@@ -257,6 +324,11 @@ struct mxt_data {
257 struct completion crc_completion; 324 struct completion crc_completion;
258}; 325};
259 326
327struct mxt_vb2_buffer {
328 struct vb2_buffer vb;
329 struct list_head list;
330};
331
260static size_t mxt_obj_size(const struct mxt_object *obj) 332static size_t mxt_obj_size(const struct mxt_object *obj)
261{ 333{
262 return obj->size_minus_one + 1; 334 return obj->size_minus_one + 1;
@@ -1503,6 +1575,11 @@ static void mxt_free_input_device(struct mxt_data *data)
1503 1575
1504static void mxt_free_object_table(struct mxt_data *data) 1576static void mxt_free_object_table(struct mxt_data *data)
1505{ 1577{
1578#ifdef CONFIG_TOUCHSCREEN_ATMEL_MXT_T37
1579 video_unregister_device(&data->dbg.vdev);
1580 v4l2_device_unregister(&data->dbg.v4l2);
1581#endif
1582
1506 kfree(data->object_table); 1583 kfree(data->object_table);
1507 data->object_table = NULL; 1584 data->object_table = NULL;
1508 kfree(data->msg_buf); 1585 kfree(data->msg_buf);
@@ -1661,6 +1738,18 @@ static int mxt_read_t9_resolution(struct mxt_data *data)
1661 return -EINVAL; 1738 return -EINVAL;
1662 1739
1663 error = __mxt_read_reg(client, 1740 error = __mxt_read_reg(client,
1741 object->start_address + MXT_T9_XSIZE,
1742 sizeof(data->xsize), &data->xsize);
1743 if (error)
1744 return error;
1745
1746 error = __mxt_read_reg(client,
1747 object->start_address + MXT_T9_YSIZE,
1748 sizeof(data->ysize), &data->ysize);
1749 if (error)
1750 return error;
1751
1752 error = __mxt_read_reg(client,
1664 object->start_address + MXT_T9_RANGE, 1753 object->start_address + MXT_T9_RANGE,
1665 sizeof(range), &range); 1754 sizeof(range), &range);
1666 if (error) 1755 if (error)
@@ -1676,6 +1765,8 @@ static int mxt_read_t9_resolution(struct mxt_data *data)
1676 return error; 1765 return error;
1677 1766
1678 data->xy_switch = orient & MXT_T9_ORIENT_SWITCH; 1767 data->xy_switch = orient & MXT_T9_ORIENT_SWITCH;
1768 data->invertx = orient & MXT_T9_ORIENT_INVERTX;
1769 data->inverty = orient & MXT_T9_ORIENT_INVERTY;
1679 1770
1680 return 0; 1771 return 0;
1681} 1772}
@@ -1710,6 +1801,18 @@ static int mxt_read_t100_config(struct mxt_data *data)
1710 1801
1711 data->max_y = get_unaligned_le16(&range_y); 1802 data->max_y = get_unaligned_le16(&range_y);
1712 1803
1804 error = __mxt_read_reg(client,
1805 object->start_address + MXT_T100_XSIZE,
1806 sizeof(data->xsize), &data->xsize);
1807 if (error)
1808 return error;
1809
1810 error = __mxt_read_reg(client,
1811 object->start_address + MXT_T100_YSIZE,
1812 sizeof(data->ysize), &data->ysize);
1813 if (error)
1814 return error;
1815
1713 /* read orientation config */ 1816 /* read orientation config */
1714 error = __mxt_read_reg(client, 1817 error = __mxt_read_reg(client,
1715 object->start_address + MXT_T100_CFG1, 1818 object->start_address + MXT_T100_CFG1,
@@ -1718,6 +1821,8 @@ static int mxt_read_t100_config(struct mxt_data *data)
1718 return error; 1821 return error;
1719 1822
1720 data->xy_switch = cfg & MXT_T100_CFG_SWITCHXY; 1823 data->xy_switch = cfg & MXT_T100_CFG_SWITCHXY;
1824 data->invertx = cfg & MXT_T100_CFG_INVERTX;
1825 data->inverty = cfg & MXT_T100_CFG_INVERTY;
1721 1826
1722 /* allocate aux bytes */ 1827 /* allocate aux bytes */
1723 error = __mxt_read_reg(client, 1828 error = __mxt_read_reg(client,
@@ -2043,6 +2148,420 @@ recheck:
2043 return 0; 2148 return 0;
2044} 2149}
2045 2150
2151#ifdef CONFIG_TOUCHSCREEN_ATMEL_MXT_T37
2152static u16 mxt_get_debug_value(struct mxt_data *data, unsigned int x,
2153 unsigned int y)
2154{
2155 struct mxt_info *info = &data->info;
2156 struct mxt_dbg *dbg = &data->dbg;
2157 unsigned int ofs, page;
2158 unsigned int col = 0;
2159 unsigned int col_width;
2160
2161 if (info->family_id == MXT_FAMILY_1386) {
2162 col_width = info->matrix_ysize / MXT1386_COLUMNS;
2163 col = y / col_width;
2164 y = y % col_width;
2165 } else {
2166 col_width = info->matrix_ysize;
2167 }
2168
2169 ofs = (y + (x * col_width)) * sizeof(u16);
2170 page = ofs / MXT_DIAGNOSTIC_SIZE;
2171 ofs %= MXT_DIAGNOSTIC_SIZE;
2172
2173 if (info->family_id == MXT_FAMILY_1386)
2174 page += col * MXT1386_PAGES_PER_COLUMN;
2175
2176 return get_unaligned_le16(&dbg->t37_buf[page].data[ofs]);
2177}
2178
2179static int mxt_convert_debug_pages(struct mxt_data *data, u16 *outbuf)
2180{
2181 struct mxt_dbg *dbg = &data->dbg;
2182 unsigned int x = 0;
2183 unsigned int y = 0;
2184 unsigned int i, rx, ry;
2185
2186 for (i = 0; i < dbg->t37_nodes; i++) {
2187 /* Handle orientation */
2188 rx = data->xy_switch ? y : x;
2189 ry = data->xy_switch ? x : y;
2190 rx = data->invertx ? (data->xsize - 1 - rx) : rx;
2191 ry = data->inverty ? (data->ysize - 1 - ry) : ry;
2192
2193 outbuf[i] = mxt_get_debug_value(data, rx, ry);
2194
2195 /* Next value */
2196 if (++x >= (data->xy_switch ? data->ysize : data->xsize)) {
2197 x = 0;
2198 y++;
2199 }
2200 }
2201
2202 return 0;
2203}
2204
2205static int mxt_read_diagnostic_debug(struct mxt_data *data, u8 mode,
2206 u16 *outbuf)
2207{
2208 struct mxt_dbg *dbg = &data->dbg;
2209 int retries = 0;
2210 int page;
2211 int ret;
2212 u8 cmd = mode;
2213 struct t37_debug *p;
2214 u8 cmd_poll;
2215
2216 for (page = 0; page < dbg->t37_pages; page++) {
2217 p = dbg->t37_buf + page;
2218
2219 ret = mxt_write_reg(data->client, dbg->diag_cmd_address,
2220 cmd);
2221 if (ret)
2222 return ret;
2223
2224 retries = 0;
2225 msleep(20);
2226wait_cmd:
2227 /* Read back command byte */
2228 ret = __mxt_read_reg(data->client, dbg->diag_cmd_address,
2229 sizeof(cmd_poll), &cmd_poll);
2230 if (ret)
2231 return ret;
2232
2233 /* Field is cleared once the command has been processed */
2234 if (cmd_poll) {
2235 if (retries++ > 100)
2236 return -EINVAL;
2237
2238 msleep(20);
2239 goto wait_cmd;
2240 }
2241
2242 /* Read T37 page */
2243 ret = __mxt_read_reg(data->client, dbg->t37_address,
2244 sizeof(struct t37_debug), p);
2245 if (ret)
2246 return ret;
2247
2248 if (p->mode != mode || p->page != page) {
2249 dev_err(&data->client->dev, "T37 page mismatch\n");
2250 return -EINVAL;
2251 }
2252
2253 dev_dbg(&data->client->dev, "%s page:%d retries:%d\n",
2254 __func__, page, retries);
2255
2256 /* For remaining pages, write PAGEUP rather than mode */
2257 cmd = MXT_DIAGNOSTIC_PAGEUP;
2258 }
2259
2260 return mxt_convert_debug_pages(data, outbuf);
2261}
2262
2263static int mxt_queue_setup(struct vb2_queue *q,
2264 unsigned int *nbuffers, unsigned int *nplanes,
2265 unsigned int sizes[], struct device *alloc_devs[])
2266{
2267 struct mxt_data *data = q->drv_priv;
2268 size_t size = data->dbg.t37_nodes * sizeof(u16);
2269
2270 if (*nplanes)
2271 return sizes[0] < size ? -EINVAL : 0;
2272
2273 *nplanes = 1;
2274 sizes[0] = size;
2275
2276 return 0;
2277}
2278
2279static void mxt_buffer_queue(struct vb2_buffer *vb)
2280{
2281 struct mxt_data *data = vb2_get_drv_priv(vb->vb2_queue);
2282 u16 *ptr;
2283 int ret;
2284 u8 mode;
2285
2286 ptr = vb2_plane_vaddr(vb, 0);
2287 if (!ptr) {
2288 dev_err(&data->client->dev, "Error acquiring frame ptr\n");
2289 goto fault;
2290 }
2291
2292 switch (data->dbg.input) {
2293 case MXT_V4L_INPUT_DELTAS:
2294 default:
2295 mode = MXT_DIAGNOSTIC_DELTAS;
2296 break;
2297
2298 case MXT_V4L_INPUT_REFS:
2299 mode = MXT_DIAGNOSTIC_REFS;
2300 break;
2301 }
2302
2303 ret = mxt_read_diagnostic_debug(data, mode, ptr);
2304 if (ret)
2305 goto fault;
2306
2307 vb2_set_plane_payload(vb, 0, data->dbg.t37_nodes * sizeof(u16));
2308 vb2_buffer_done(vb, VB2_BUF_STATE_DONE);
2309 return;
2310
2311fault:
2312 vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
2313}
2314
2315/* V4L2 structures */
2316static const struct vb2_ops mxt_queue_ops = {
2317 .queue_setup = mxt_queue_setup,
2318 .buf_queue = mxt_buffer_queue,
2319 .wait_prepare = vb2_ops_wait_prepare,
2320 .wait_finish = vb2_ops_wait_finish,
2321};
2322
2323static const struct vb2_queue mxt_queue = {
2324 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
2325 .io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF | VB2_READ,
2326 .buf_struct_size = sizeof(struct mxt_vb2_buffer),
2327 .ops = &mxt_queue_ops,
2328 .mem_ops = &vb2_vmalloc_memops,
2329 .timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC,
2330 .min_buffers_needed = 1,
2331};
2332
2333static int mxt_vidioc_querycap(struct file *file, void *priv,
2334 struct v4l2_capability *cap)
2335{
2336 struct mxt_data *data = video_drvdata(file);
2337
2338 strlcpy(cap->driver, "atmel_mxt_ts", sizeof(cap->driver));
2339 strlcpy(cap->card, "atmel_mxt_ts touch", sizeof(cap->card));
2340 snprintf(cap->bus_info, sizeof(cap->bus_info),
2341 "I2C:%s", dev_name(&data->client->dev));
2342 return 0;
2343}
2344
2345static int mxt_vidioc_enum_input(struct file *file, void *priv,
2346 struct v4l2_input *i)
2347{
2348 if (i->index >= MXT_V4L_INPUT_MAX)
2349 return -EINVAL;
2350
2351 i->type = V4L2_INPUT_TYPE_TOUCH;
2352
2353 switch (i->index) {
2354 case MXT_V4L_INPUT_REFS:
2355 strlcpy(i->name, "Mutual Capacitance References",
2356 sizeof(i->name));
2357 break;
2358 case MXT_V4L_INPUT_DELTAS:
2359 strlcpy(i->name, "Mutual Capacitance Deltas", sizeof(i->name));
2360 break;
2361 }
2362
2363 return 0;
2364}
2365
2366static int mxt_set_input(struct mxt_data *data, unsigned int i)
2367{
2368 struct v4l2_pix_format *f = &data->dbg.format;
2369
2370 if (i >= MXT_V4L_INPUT_MAX)
2371 return -EINVAL;
2372
2373 if (i == MXT_V4L_INPUT_DELTAS)
2374 f->pixelformat = V4L2_TCH_FMT_DELTA_TD16;
2375 else
2376 f->pixelformat = V4L2_TCH_FMT_TU16;
2377
2378 f->width = data->xy_switch ? data->ysize : data->xsize;
2379 f->height = data->xy_switch ? data->xsize : data->ysize;
2380 f->field = V4L2_FIELD_NONE;
2381 f->colorspace = V4L2_COLORSPACE_RAW;
2382 f->bytesperline = f->width * sizeof(u16);
2383 f->sizeimage = f->width * f->height * sizeof(u16);
2384
2385 data->dbg.input = i;
2386
2387 return 0;
2388}
2389
2390static int mxt_vidioc_s_input(struct file *file, void *priv, unsigned int i)
2391{
2392 return mxt_set_input(video_drvdata(file), i);
2393}
2394
2395static int mxt_vidioc_g_input(struct file *file, void *priv, unsigned int *i)
2396{
2397 struct mxt_data *data = video_drvdata(file);
2398
2399 *i = data->dbg.input;
2400
2401 return 0;
2402}
2403
2404static int mxt_vidioc_fmt(struct file *file, void *priv, struct v4l2_format *f)
2405{
2406 struct mxt_data *data = video_drvdata(file);
2407
2408 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
2409 f->fmt.pix = data->dbg.format;
2410
2411 return 0;
2412}
2413
2414static int mxt_vidioc_enum_fmt(struct file *file, void *priv,
2415 struct v4l2_fmtdesc *fmt)
2416{
2417 if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
2418 return -EINVAL;
2419
2420 switch (fmt->index) {
2421 case 0:
2422 fmt->pixelformat = V4L2_TCH_FMT_TU16;
2423 break;
2424
2425 case 1:
2426 fmt->pixelformat = V4L2_TCH_FMT_DELTA_TD16;
2427 break;
2428
2429 default:
2430 return -EINVAL;
2431 }
2432
2433 return 0;
2434}
2435
2436static int mxt_vidioc_g_parm(struct file *file, void *fh,
2437 struct v4l2_streamparm *a)
2438{
2439 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
2440 return -EINVAL;
2441
2442 a->parm.capture.readbuffers = 1;
2443 a->parm.capture.timeperframe.numerator = 1;
2444 a->parm.capture.timeperframe.denominator = 10;
2445 return 0;
2446}
2447
2448static const struct v4l2_ioctl_ops mxt_video_ioctl_ops = {
2449 .vidioc_querycap = mxt_vidioc_querycap,
2450
2451 .vidioc_enum_fmt_vid_cap = mxt_vidioc_enum_fmt,
2452 .vidioc_s_fmt_vid_cap = mxt_vidioc_fmt,
2453 .vidioc_g_fmt_vid_cap = mxt_vidioc_fmt,
2454 .vidioc_try_fmt_vid_cap = mxt_vidioc_fmt,
2455 .vidioc_g_parm = mxt_vidioc_g_parm,
2456
2457 .vidioc_enum_input = mxt_vidioc_enum_input,
2458 .vidioc_g_input = mxt_vidioc_g_input,
2459 .vidioc_s_input = mxt_vidioc_s_input,
2460
2461 .vidioc_reqbufs = vb2_ioctl_reqbufs,
2462 .vidioc_create_bufs = vb2_ioctl_create_bufs,
2463 .vidioc_querybuf = vb2_ioctl_querybuf,
2464 .vidioc_qbuf = vb2_ioctl_qbuf,
2465 .vidioc_dqbuf = vb2_ioctl_dqbuf,
2466 .vidioc_expbuf = vb2_ioctl_expbuf,
2467
2468 .vidioc_streamon = vb2_ioctl_streamon,
2469 .vidioc_streamoff = vb2_ioctl_streamoff,
2470};
2471
2472static const struct video_device mxt_video_device = {
2473 .name = "Atmel maxTouch",
2474 .fops = &mxt_video_fops,
2475 .ioctl_ops = &mxt_video_ioctl_ops,
2476 .release = video_device_release_empty,
2477 .device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_TOUCH |
2478 V4L2_CAP_READWRITE | V4L2_CAP_STREAMING,
2479};
2480
2481static void mxt_debug_init(struct mxt_data *data)
2482{
2483 struct mxt_info *info = &data->info;
2484 struct mxt_dbg *dbg = &data->dbg;
2485 struct mxt_object *object;
2486 int error;
2487
2488 object = mxt_get_object(data, MXT_GEN_COMMAND_T6);
2489 if (!object)
2490 goto error;
2491
2492 dbg->diag_cmd_address = object->start_address + MXT_COMMAND_DIAGNOSTIC;
2493
2494 object = mxt_get_object(data, MXT_DEBUG_DIAGNOSTIC_T37);
2495 if (!object)
2496 goto error;
2497
2498 if (mxt_obj_size(object) != sizeof(struct t37_debug)) {
2499 dev_warn(&data->client->dev, "Bad T37 size");
2500 goto error;
2501 }
2502
2503 dbg->t37_address = object->start_address;
2504
2505 /* Calculate size of data and allocate buffer */
2506 dbg->t37_nodes = data->xsize * data->ysize;
2507
2508 if (info->family_id == MXT_FAMILY_1386)
2509 dbg->t37_pages = MXT1386_COLUMNS * MXT1386_PAGES_PER_COLUMN;
2510 else
2511 dbg->t37_pages = DIV_ROUND_UP(data->xsize *
2512 data->info.matrix_ysize *
2513 sizeof(u16),
2514 sizeof(dbg->t37_buf->data));
2515
2516 dbg->t37_buf = devm_kmalloc_array(&data->client->dev, dbg->t37_pages,
2517 sizeof(struct t37_debug), GFP_KERNEL);
2518 if (!dbg->t37_buf)
2519 goto error;
2520
2521 /* init channel to zero */
2522 mxt_set_input(data, 0);
2523
2524 /* register video device */
2525 snprintf(dbg->v4l2.name, sizeof(dbg->v4l2.name), "%s", "atmel_mxt_ts");
2526 error = v4l2_device_register(&data->client->dev, &dbg->v4l2);
2527 if (error)
2528 goto error;
2529
2530 /* initialize the queue */
2531 mutex_init(&dbg->lock);
2532 dbg->queue = mxt_queue;
2533 dbg->queue.drv_priv = data;
2534 dbg->queue.lock = &dbg->lock;
2535 dbg->queue.dev = &data->client->dev;
2536
2537 error = vb2_queue_init(&dbg->queue);
2538 if (error)
2539 goto error_unreg_v4l2;
2540
2541 dbg->vdev = mxt_video_device;
2542 dbg->vdev.v4l2_dev = &dbg->v4l2;
2543 dbg->vdev.lock = &dbg->lock;
2544 dbg->vdev.vfl_dir = VFL_DIR_RX;
2545 dbg->vdev.queue = &dbg->queue;
2546 video_set_drvdata(&dbg->vdev, data);
2547
2548 error = video_register_device(&dbg->vdev, VFL_TYPE_TOUCH, -1);
2549 if (error)
2550 goto error_unreg_v4l2;
2551
2552 return;
2553
2554error_unreg_v4l2:
2555 v4l2_device_unregister(&dbg->v4l2);
2556error:
2557 dev_warn(&data->client->dev, "Error initializing T37\n");
2558}
2559#else
2560static void mxt_debug_init(struct mxt_data *data)
2561{
2562}
2563#endif
2564
2046static int mxt_configure_objects(struct mxt_data *data, 2565static int mxt_configure_objects(struct mxt_data *data,
2047 const struct firmware *cfg) 2566 const struct firmware *cfg)
2048{ 2567{
@@ -2070,6 +2589,8 @@ static int mxt_configure_objects(struct mxt_data *data,
2070 dev_warn(dev, "No touch object detected\n"); 2589 dev_warn(dev, "No touch object detected\n");
2071 } 2590 }
2072 2591
2592 mxt_debug_init(data);
2593
2073 dev_info(dev, 2594 dev_info(dev,
2074 "Family: %u Variant: %u Firmware V%u.%u.%02X Objects: %u\n", 2595 "Family: %u Variant: %u Firmware V%u.%u.%02X Objects: %u\n",
2075 info->family_id, info->variant_id, info->version >> 4, 2596 info->family_id, info->variant_id, info->version >> 4,
diff --git a/drivers/input/touchscreen/sur40.c b/drivers/input/touchscreen/sur40.c
index 4ea475775d58..aefb6e11f88a 100644
--- a/drivers/input/touchscreen/sur40.c
+++ b/drivers/input/touchscreen/sur40.c
@@ -139,6 +139,27 @@ struct sur40_image_header {
139#define SUR40_GET_STATE 0xc5 /* 4 bytes state (?) */ 139#define SUR40_GET_STATE 0xc5 /* 4 bytes state (?) */
140#define SUR40_GET_SENSORS 0xb1 /* 8 bytes sensors */ 140#define SUR40_GET_SENSORS 0xb1 /* 8 bytes sensors */
141 141
142static const struct v4l2_pix_format sur40_pix_format[] = {
143 {
144 .pixelformat = V4L2_TCH_FMT_TU08,
145 .width = SENSOR_RES_X / 2,
146 .height = SENSOR_RES_Y / 2,
147 .field = V4L2_FIELD_NONE,
148 .colorspace = V4L2_COLORSPACE_SRGB,
149 .bytesperline = SENSOR_RES_X / 2,
150 .sizeimage = (SENSOR_RES_X/2) * (SENSOR_RES_Y/2),
151 },
152 {
153 .pixelformat = V4L2_PIX_FMT_GREY,
154 .width = SENSOR_RES_X / 2,
155 .height = SENSOR_RES_Y / 2,
156 .field = V4L2_FIELD_NONE,
157 .colorspace = V4L2_COLORSPACE_SRGB,
158 .bytesperline = SENSOR_RES_X / 2,
159 .sizeimage = (SENSOR_RES_X/2) * (SENSOR_RES_Y/2),
160 }
161};
162
142/* master device state */ 163/* master device state */
143struct sur40_state { 164struct sur40_state {
144 165
@@ -149,6 +170,7 @@ struct sur40_state {
149 struct v4l2_device v4l2; 170 struct v4l2_device v4l2;
150 struct video_device vdev; 171 struct video_device vdev;
151 struct mutex lock; 172 struct mutex lock;
173 struct v4l2_pix_format pix_fmt;
152 174
153 struct vb2_queue queue; 175 struct vb2_queue queue;
154 struct list_head buf_list; 176 struct list_head buf_list;
@@ -169,7 +191,6 @@ struct sur40_buffer {
169 191
170/* forward declarations */ 192/* forward declarations */
171static const struct video_device sur40_video_device; 193static const struct video_device sur40_video_device;
172static const struct v4l2_pix_format sur40_video_format;
173static const struct vb2_queue sur40_queue; 194static const struct vb2_queue sur40_queue;
174static void sur40_process_video(struct sur40_state *sur40); 195static void sur40_process_video(struct sur40_state *sur40);
175 196
@@ -420,7 +441,7 @@ static void sur40_process_video(struct sur40_state *sur40)
420 goto err_poll; 441 goto err_poll;
421 } 442 }
422 443
423 if (le32_to_cpu(img->size) != sur40_video_format.sizeimage) { 444 if (le32_to_cpu(img->size) != sur40->pix_fmt.sizeimage) {
424 dev_err(sur40->dev, "image size mismatch\n"); 445 dev_err(sur40->dev, "image size mismatch\n");
425 goto err_poll; 446 goto err_poll;
426 } 447 }
@@ -431,7 +452,7 @@ static void sur40_process_video(struct sur40_state *sur40)
431 452
432 result = usb_sg_init(&sgr, sur40->usbdev, 453 result = usb_sg_init(&sgr, sur40->usbdev,
433 usb_rcvbulkpipe(sur40->usbdev, VIDEO_ENDPOINT), 0, 454 usb_rcvbulkpipe(sur40->usbdev, VIDEO_ENDPOINT), 0,
434 sgt->sgl, sgt->nents, sur40_video_format.sizeimage, 0); 455 sgt->sgl, sgt->nents, sur40->pix_fmt.sizeimage, 0);
435 if (result < 0) { 456 if (result < 0) {
436 dev_err(sur40->dev, "error %d in usb_sg_init\n", result); 457 dev_err(sur40->dev, "error %d in usb_sg_init\n", result);
437 goto err_poll; 458 goto err_poll;
@@ -586,13 +607,14 @@ static int sur40_probe(struct usb_interface *interface,
586 if (error) 607 if (error)
587 goto err_unreg_v4l2; 608 goto err_unreg_v4l2;
588 609
610 sur40->pix_fmt = sur40_pix_format[0];
589 sur40->vdev = sur40_video_device; 611 sur40->vdev = sur40_video_device;
590 sur40->vdev.v4l2_dev = &sur40->v4l2; 612 sur40->vdev.v4l2_dev = &sur40->v4l2;
591 sur40->vdev.lock = &sur40->lock; 613 sur40->vdev.lock = &sur40->lock;
592 sur40->vdev.queue = &sur40->queue; 614 sur40->vdev.queue = &sur40->queue;
593 video_set_drvdata(&sur40->vdev, sur40); 615 video_set_drvdata(&sur40->vdev, sur40);
594 616
595 error = video_register_device(&sur40->vdev, VFL_TYPE_GRABBER, -1); 617 error = video_register_device(&sur40->vdev, VFL_TYPE_TOUCH, -1);
596 if (error) { 618 if (error) {
597 dev_err(&interface->dev, 619 dev_err(&interface->dev,
598 "Unable to register video subdevice."); 620 "Unable to register video subdevice.");
@@ -647,14 +669,16 @@ static int sur40_queue_setup(struct vb2_queue *q,
647 unsigned int *nbuffers, unsigned int *nplanes, 669 unsigned int *nbuffers, unsigned int *nplanes,
648 unsigned int sizes[], struct device *alloc_devs[]) 670 unsigned int sizes[], struct device *alloc_devs[])
649{ 671{
672 struct sur40_state *sur40 = vb2_get_drv_priv(q);
673
650 if (q->num_buffers + *nbuffers < 3) 674 if (q->num_buffers + *nbuffers < 3)
651 *nbuffers = 3 - q->num_buffers; 675 *nbuffers = 3 - q->num_buffers;
652 676
653 if (*nplanes) 677 if (*nplanes)
654 return sizes[0] < sur40_video_format.sizeimage ? -EINVAL : 0; 678 return sizes[0] < sur40->pix_fmt.sizeimage ? -EINVAL : 0;
655 679
656 *nplanes = 1; 680 *nplanes = 1;
657 sizes[0] = sur40_video_format.sizeimage; 681 sizes[0] = sur40->pix_fmt.sizeimage;
658 682
659 return 0; 683 return 0;
660} 684}
@@ -666,7 +690,7 @@ static int sur40_queue_setup(struct vb2_queue *q,
666static int sur40_buffer_prepare(struct vb2_buffer *vb) 690static int sur40_buffer_prepare(struct vb2_buffer *vb)
667{ 691{
668 struct sur40_state *sur40 = vb2_get_drv_priv(vb->vb2_queue); 692 struct sur40_state *sur40 = vb2_get_drv_priv(vb->vb2_queue);
669 unsigned long size = sur40_video_format.sizeimage; 693 unsigned long size = sur40->pix_fmt.sizeimage;
670 694
671 if (vb2_plane_size(vb, 0) < size) { 695 if (vb2_plane_size(vb, 0) < size) {
672 dev_err(&sur40->usbdev->dev, "buffer too small (%lu < %lu)\n", 696 dev_err(&sur40->usbdev->dev, "buffer too small (%lu < %lu)\n",
@@ -741,7 +765,7 @@ static int sur40_vidioc_querycap(struct file *file, void *priv,
741 strlcpy(cap->driver, DRIVER_SHORT, sizeof(cap->driver)); 765 strlcpy(cap->driver, DRIVER_SHORT, sizeof(cap->driver));
742 strlcpy(cap->card, DRIVER_LONG, sizeof(cap->card)); 766 strlcpy(cap->card, DRIVER_LONG, sizeof(cap->card));
743 usb_make_path(sur40->usbdev, cap->bus_info, sizeof(cap->bus_info)); 767 usb_make_path(sur40->usbdev, cap->bus_info, sizeof(cap->bus_info));
744 cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | 768 cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_TOUCH |
745 V4L2_CAP_READWRITE | 769 V4L2_CAP_READWRITE |
746 V4L2_CAP_STREAMING; 770 V4L2_CAP_STREAMING;
747 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS; 771 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
@@ -753,7 +777,7 @@ static int sur40_vidioc_enum_input(struct file *file, void *priv,
753{ 777{
754 if (i->index != 0) 778 if (i->index != 0)
755 return -EINVAL; 779 return -EINVAL;
756 i->type = V4L2_INPUT_TYPE_CAMERA; 780 i->type = V4L2_INPUT_TYPE_TOUCH;
757 i->std = V4L2_STD_UNKNOWN; 781 i->std = V4L2_STD_UNKNOWN;
758 strlcpy(i->name, "In-Cell Sensor", sizeof(i->name)); 782 strlcpy(i->name, "In-Cell Sensor", sizeof(i->name));
759 i->capabilities = 0; 783 i->capabilities = 0;
@@ -771,19 +795,70 @@ static int sur40_vidioc_g_input(struct file *file, void *priv, unsigned int *i)
771 return 0; 795 return 0;
772} 796}
773 797
774static int sur40_vidioc_fmt(struct file *file, void *priv, 798static int sur40_vidioc_try_fmt(struct file *file, void *priv,
799 struct v4l2_format *f)
800{
801 switch (f->fmt.pix.pixelformat) {
802 case V4L2_PIX_FMT_GREY:
803 f->fmt.pix = sur40_pix_format[1];
804 break;
805
806 default:
807 f->fmt.pix = sur40_pix_format[0];
808 break;
809 }
810
811 return 0;
812}
813
814static int sur40_vidioc_s_fmt(struct file *file, void *priv,
815 struct v4l2_format *f)
816{
817 struct sur40_state *sur40 = video_drvdata(file);
818
819 switch (f->fmt.pix.pixelformat) {
820 case V4L2_PIX_FMT_GREY:
821 sur40->pix_fmt = sur40_pix_format[1];
822 break;
823
824 default:
825 sur40->pix_fmt = sur40_pix_format[0];
826 break;
827 }
828
829 f->fmt.pix = sur40->pix_fmt;
830 return 0;
831}
832
833static int sur40_vidioc_g_fmt(struct file *file, void *priv,
775 struct v4l2_format *f) 834 struct v4l2_format *f)
776{ 835{
777 f->fmt.pix = sur40_video_format; 836 struct sur40_state *sur40 = video_drvdata(file);
837
838 f->fmt.pix = sur40->pix_fmt;
839 return 0;
840}
841
842static int sur40_ioctl_parm(struct file *file, void *priv,
843 struct v4l2_streamparm *p)
844{
845 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
846 return -EINVAL;
847
848 p->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
849 p->parm.capture.timeperframe.numerator = 1;
850 p->parm.capture.timeperframe.denominator = 60;
851 p->parm.capture.readbuffers = 3;
778 return 0; 852 return 0;
779} 853}
780 854
781static int sur40_vidioc_enum_fmt(struct file *file, void *priv, 855static int sur40_vidioc_enum_fmt(struct file *file, void *priv,
782 struct v4l2_fmtdesc *f) 856 struct v4l2_fmtdesc *f)
783{ 857{
784 if (f->index != 0) 858 if (f->index >= ARRAY_SIZE(sur40_pix_format))
785 return -EINVAL; 859 return -EINVAL;
786 f->pixelformat = V4L2_PIX_FMT_GREY; 860
861 f->pixelformat = sur40_pix_format[f->index].pixelformat;
787 f->flags = 0; 862 f->flags = 0;
788 return 0; 863 return 0;
789} 864}
@@ -791,25 +866,31 @@ static int sur40_vidioc_enum_fmt(struct file *file, void *priv,
791static int sur40_vidioc_enum_framesizes(struct file *file, void *priv, 866static int sur40_vidioc_enum_framesizes(struct file *file, void *priv,
792 struct v4l2_frmsizeenum *f) 867 struct v4l2_frmsizeenum *f)
793{ 868{
794 if ((f->index != 0) || (f->pixel_format != V4L2_PIX_FMT_GREY)) 869 struct sur40_state *sur40 = video_drvdata(file);
870
871 if ((f->index != 0) || ((f->pixel_format != V4L2_TCH_FMT_TU08)
872 && (f->pixel_format != V4L2_PIX_FMT_GREY)))
795 return -EINVAL; 873 return -EINVAL;
796 874
797 f->type = V4L2_FRMSIZE_TYPE_DISCRETE; 875 f->type = V4L2_FRMSIZE_TYPE_DISCRETE;
798 f->discrete.width = sur40_video_format.width; 876 f->discrete.width = sur40->pix_fmt.width;
799 f->discrete.height = sur40_video_format.height; 877 f->discrete.height = sur40->pix_fmt.height;
800 return 0; 878 return 0;
801} 879}
802 880
803static int sur40_vidioc_enum_frameintervals(struct file *file, void *priv, 881static int sur40_vidioc_enum_frameintervals(struct file *file, void *priv,
804 struct v4l2_frmivalenum *f) 882 struct v4l2_frmivalenum *f)
805{ 883{
806 if ((f->index > 1) || (f->pixel_format != V4L2_PIX_FMT_GREY) 884 struct sur40_state *sur40 = video_drvdata(file);
807 || (f->width != sur40_video_format.width) 885
808 || (f->height != sur40_video_format.height)) 886 if ((f->index > 0) || ((f->pixel_format != V4L2_TCH_FMT_TU08)
809 return -EINVAL; 887 && (f->pixel_format != V4L2_PIX_FMT_GREY))
888 || (f->width != sur40->pix_fmt.width)
889 || (f->height != sur40->pix_fmt.height))
890 return -EINVAL;
810 891
811 f->type = V4L2_FRMIVAL_TYPE_DISCRETE; 892 f->type = V4L2_FRMIVAL_TYPE_DISCRETE;
812 f->discrete.denominator = 60/(f->index+1); 893 f->discrete.denominator = 60;
813 f->discrete.numerator = 1; 894 f->discrete.numerator = 1;
814 return 0; 895 return 0;
815} 896}
@@ -862,13 +943,16 @@ static const struct v4l2_ioctl_ops sur40_video_ioctl_ops = {
862 .vidioc_querycap = sur40_vidioc_querycap, 943 .vidioc_querycap = sur40_vidioc_querycap,
863 944
864 .vidioc_enum_fmt_vid_cap = sur40_vidioc_enum_fmt, 945 .vidioc_enum_fmt_vid_cap = sur40_vidioc_enum_fmt,
865 .vidioc_try_fmt_vid_cap = sur40_vidioc_fmt, 946 .vidioc_try_fmt_vid_cap = sur40_vidioc_try_fmt,
866 .vidioc_s_fmt_vid_cap = sur40_vidioc_fmt, 947 .vidioc_s_fmt_vid_cap = sur40_vidioc_s_fmt,
867 .vidioc_g_fmt_vid_cap = sur40_vidioc_fmt, 948 .vidioc_g_fmt_vid_cap = sur40_vidioc_g_fmt,
868 949
869 .vidioc_enum_framesizes = sur40_vidioc_enum_framesizes, 950 .vidioc_enum_framesizes = sur40_vidioc_enum_framesizes,
870 .vidioc_enum_frameintervals = sur40_vidioc_enum_frameintervals, 951 .vidioc_enum_frameintervals = sur40_vidioc_enum_frameintervals,
871 952
953 .vidioc_g_parm = sur40_ioctl_parm,
954 .vidioc_s_parm = sur40_ioctl_parm,
955
872 .vidioc_enum_input = sur40_vidioc_enum_input, 956 .vidioc_enum_input = sur40_vidioc_enum_input,
873 .vidioc_g_input = sur40_vidioc_g_input, 957 .vidioc_g_input = sur40_vidioc_g_input,
874 .vidioc_s_input = sur40_vidioc_s_input, 958 .vidioc_s_input = sur40_vidioc_s_input,
@@ -891,16 +975,6 @@ static const struct video_device sur40_video_device = {
891 .release = video_device_release_empty, 975 .release = video_device_release_empty,
892}; 976};
893 977
894static const struct v4l2_pix_format sur40_video_format = {
895 .pixelformat = V4L2_PIX_FMT_GREY,
896 .width = SENSOR_RES_X / 2,
897 .height = SENSOR_RES_Y / 2,
898 .field = V4L2_FIELD_NONE,
899 .colorspace = V4L2_COLORSPACE_SRGB,
900 .bytesperline = SENSOR_RES_X / 2,
901 .sizeimage = (SENSOR_RES_X/2) * (SENSOR_RES_Y/2),
902};
903
904/* USB-specific object needed to register this driver with the USB subsystem. */ 978/* USB-specific object needed to register this driver with the USB subsystem. */
905static struct usb_driver sur40_driver = { 979static struct usb_driver sur40_driver = {
906 .name = DRIVER_SHORT, 980 .name = DRIVER_SHORT,