hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/drivers/input/rmi4/rmi_f54.c
....@@ -1,10 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (c) 2012-2015 Synaptics Incorporated
34 * 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.
85 */
96
107 #include <linux/kernel.h>
....@@ -26,6 +23,12 @@
2623 #define F54_FIFO_OFFSET 1
2724 #define F54_NUM_TX_OFFSET 1
2825 #define F54_NUM_RX_OFFSET 0
26
+
27
+/*
28
+ * The smbus protocol can read only 32 bytes max at a time.
29
+ * But this should be fine for i2c/spi as well.
30
+ */
31
+#define F54_REPORT_DATA_SIZE 32
2932
3033 /* F54 commands */
3134 #define F54_GET_REPORT 1
....@@ -84,11 +87,6 @@
8487 = "Full Raw Capacitance RX Offset Removed",
8588 };
8689
87
-struct rmi_f54_reports {
88
- int start;
89
- int size;
90
-};
91
-
9290 struct f54_data {
9391 struct rmi_function *fn;
9492
....@@ -101,7 +99,6 @@
10199 enum rmi_f54_report_type report_type;
102100 u8 *report_data;
103101 int report_size;
104
- struct rmi_f54_reports standard_report[2];
105102
106103 bool is_busy;
107104 struct mutex status_mutex;
....@@ -119,6 +116,7 @@
119116 struct video_device vdev;
120117 struct vb2_queue queue;
121118 struct mutex lock;
119
+ u32 sequence;
122120 int input;
123121 enum rmi_f54_report_type inputs[F54_MAX_REPORT_TYPE];
124122 };
....@@ -293,6 +291,7 @@
293291
294292 static void rmi_f54_buffer_queue(struct vb2_buffer *vb)
295293 {
294
+ struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
296295 struct f54_data *f54 = vb2_get_drv_priv(vb->vb2_queue);
297296 u16 *ptr;
298297 enum vb2_buffer_state state;
....@@ -301,6 +300,7 @@
301300
302301 mutex_lock(&f54->status_mutex);
303302
303
+ vb2_set_plane_payload(vb, 0, 0);
304304 reptype = rmi_f54_get_reptype(f54, f54->input);
305305 if (reptype == F54_REPORT_NONE) {
306306 state = VB2_BUF_STATE_ERROR;
....@@ -347,14 +347,25 @@
347347 data_done:
348348 mutex_unlock(&f54->data_mutex);
349349 done:
350
+ vb->timestamp = ktime_get_ns();
351
+ vbuf->field = V4L2_FIELD_NONE;
352
+ vbuf->sequence = f54->sequence++;
350353 vb2_buffer_done(vb, state);
351354 mutex_unlock(&f54->status_mutex);
355
+}
356
+
357
+static void rmi_f54_stop_streaming(struct vb2_queue *q)
358
+{
359
+ struct f54_data *f54 = vb2_get_drv_priv(q);
360
+
361
+ f54->sequence = 0;
352362 }
353363
354364 /* V4L2 structures */
355365 static const struct vb2_ops rmi_f54_queue_ops = {
356366 .queue_setup = rmi_f54_queue_setup,
357367 .buf_queue = rmi_f54_buffer_queue,
368
+ .stop_streaming = rmi_f54_stop_streaming,
358369 .wait_prepare = vb2_ops_wait_prepare,
359370 .wait_finish = vb2_ops_wait_finish,
360371 };
....@@ -366,7 +377,6 @@
366377 .ops = &rmi_f54_queue_ops,
367378 .mem_ops = &vb2_vmalloc_memops,
368379 .timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC,
369
- .min_buffers_needed = 1,
370380 };
371381
372382 static int rmi_f54_vidioc_querycap(struct file *file, void *priv,
....@@ -456,25 +466,15 @@
456466 static int rmi_f54_vidioc_enum_fmt(struct file *file, void *priv,
457467 struct v4l2_fmtdesc *fmt)
458468 {
469
+ struct f54_data *f54 = video_drvdata(file);
470
+
459471 if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
460472 return -EINVAL;
461473
462
- switch (fmt->index) {
463
- case 0:
464
- fmt->pixelformat = V4L2_TCH_FMT_DELTA_TD16;
465
- break;
466
-
467
- case 1:
468
- fmt->pixelformat = V4L2_TCH_FMT_DELTA_TD08;
469
- break;
470
-
471
- case 2:
472
- fmt->pixelformat = V4L2_TCH_FMT_TU16;
473
- break;
474
-
475
- default:
474
+ if (fmt->index)
476475 return -EINVAL;
477
- }
476
+
477
+ fmt->pixelformat = f54->format.pixelformat;
478478
479479 return 0;
480480 }
....@@ -529,13 +529,11 @@
529529 struct f54_data *f54 = container_of(work, struct f54_data, work.work);
530530 struct rmi_function *fn = f54->fn;
531531 u8 fifo[2];
532
- struct rmi_f54_reports *report;
533532 int report_size;
534533 u8 command;
535
- u8 *data;
536534 int error;
535
+ int i;
537536
538
- data = f54->report_data;
539537 report_size = rmi_f54_get_report_size(f54);
540538 if (report_size == 0) {
541539 dev_err(&fn->dev, "Bad report size, report type=%d\n",
....@@ -543,8 +541,6 @@
543541 error = -EINVAL;
544542 goto error; /* retry won't help */
545543 }
546
- f54->standard_report[0].size = report_size;
547
- report = f54->standard_report;
548544
549545 mutex_lock(&f54->data_mutex);
550546
....@@ -569,10 +565,11 @@
569565
570566 rmi_dbg(RMI_DEBUG_FN, &fn->dev, "Get report command completed, reading data\n");
571567
572
- report_size = 0;
573
- for (; report->size; report++) {
574
- fifo[0] = report->start & 0xff;
575
- fifo[1] = (report->start >> 8) & 0xff;
568
+ for (i = 0; i < report_size; i += F54_REPORT_DATA_SIZE) {
569
+ int size = min(F54_REPORT_DATA_SIZE, report_size - i);
570
+
571
+ fifo[0] = i & 0xff;
572
+ fifo[1] = i >> 8;
576573 error = rmi_write_block(fn->rmi_dev,
577574 fn->fd.data_base_addr + F54_FIFO_OFFSET,
578575 fifo, sizeof(fifo));
....@@ -582,15 +579,13 @@
582579 }
583580
584581 error = rmi_read_block(fn->rmi_dev, fn->fd.data_base_addr +
585
- F54_REPORT_DATA_OFFSET, data,
586
- report->size);
582
+ F54_REPORT_DATA_OFFSET,
583
+ f54->report_data + i, size);
587584 if (error) {
588585 dev_err(&fn->dev, "%s: read [%d bytes] returned %d\n",
589
- __func__, report->size, error);
586
+ __func__, size, error);
590587 goto abort;
591588 }
592
- data += report->size;
593
- report_size += report->size;
594589 }
595590
596591 abort:
....@@ -692,6 +687,7 @@
692687 return -ENOMEM;
693688
694689 rmi_f54_create_input_map(f54);
690
+ rmi_f54_set_input(f54, 0);
695691
696692 /* register video device */
697693 strlcpy(f54->v4l2.name, F54_NAME, sizeof(f54->v4l2.name));