xref: /openbmc/linux/drivers/media/test-drivers/vivid/vivid-touch-cap.c (revision 7ae9fb1b7ecbb5d85d07857943f677fd1a559b18)
1dacca5f0SHans Verkuil // SPDX-License-Identifier: GPL-2.0-only
2dacca5f0SHans Verkuil /*
3dacca5f0SHans Verkuil  * vivid-touch-cap.c - touch support functions.
4dacca5f0SHans Verkuil  */
5dacca5f0SHans Verkuil 
6dacca5f0SHans Verkuil #include "vivid-core.h"
7dacca5f0SHans Verkuil #include "vivid-kthread-touch.h"
8dacca5f0SHans Verkuil #include "vivid-vid-common.h"
9dacca5f0SHans Verkuil #include "vivid-touch-cap.h"
10dacca5f0SHans Verkuil 
touch_cap_queue_setup(struct vb2_queue * vq,unsigned int * nbuffers,unsigned int * nplanes,unsigned int sizes[],struct device * alloc_devs[])11dacca5f0SHans Verkuil static int touch_cap_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers,
12dacca5f0SHans Verkuil 				 unsigned int *nplanes, unsigned int sizes[],
13dacca5f0SHans Verkuil 				 struct device *alloc_devs[])
14dacca5f0SHans Verkuil {
15dacca5f0SHans Verkuil 	struct vivid_dev *dev = vb2_get_drv_priv(vq);
16dacca5f0SHans Verkuil 	struct v4l2_pix_format *f = &dev->tch_format;
17dacca5f0SHans Verkuil 	unsigned int size = f->sizeimage;
18dacca5f0SHans Verkuil 
19dacca5f0SHans Verkuil 	if (*nplanes) {
20dacca5f0SHans Verkuil 		if (sizes[0] < size)
21dacca5f0SHans Verkuil 			return -EINVAL;
22dacca5f0SHans Verkuil 	} else {
23dacca5f0SHans Verkuil 		sizes[0] = size;
24dacca5f0SHans Verkuil 	}
25dacca5f0SHans Verkuil 
26dacca5f0SHans Verkuil 	if (vq->num_buffers + *nbuffers < 2)
27dacca5f0SHans Verkuil 		*nbuffers = 2 - vq->num_buffers;
28dacca5f0SHans Verkuil 
29dacca5f0SHans Verkuil 	*nplanes = 1;
30dacca5f0SHans Verkuil 	return 0;
31dacca5f0SHans Verkuil }
32dacca5f0SHans Verkuil 
touch_cap_buf_prepare(struct vb2_buffer * vb)33dacca5f0SHans Verkuil static int touch_cap_buf_prepare(struct vb2_buffer *vb)
34dacca5f0SHans Verkuil {
35dacca5f0SHans Verkuil 	struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
36dacca5f0SHans Verkuil 	struct v4l2_pix_format *f = &dev->tch_format;
37dacca5f0SHans Verkuil 	unsigned int size = f->sizeimage;
38dacca5f0SHans Verkuil 
39dacca5f0SHans Verkuil 	if (dev->buf_prepare_error) {
40dacca5f0SHans Verkuil 		/*
41dacca5f0SHans Verkuil 		 * Error injection: test what happens if buf_prepare() returns
42dacca5f0SHans Verkuil 		 * an error.
43dacca5f0SHans Verkuil 		 */
44dacca5f0SHans Verkuil 		dev->buf_prepare_error = false;
45dacca5f0SHans Verkuil 		return -EINVAL;
46dacca5f0SHans Verkuil 	}
47dacca5f0SHans Verkuil 	if (vb2_plane_size(vb, 0) < size) {
48dacca5f0SHans Verkuil 		dprintk(dev, 1, "%s data will not fit into plane (%lu < %u)\n",
49dacca5f0SHans Verkuil 			__func__, vb2_plane_size(vb, 0), size);
50dacca5f0SHans Verkuil 		return -EINVAL;
51dacca5f0SHans Verkuil 	}
52dacca5f0SHans Verkuil 	vb2_set_plane_payload(vb, 0, size);
53dacca5f0SHans Verkuil 
54dacca5f0SHans Verkuil 	return 0;
55dacca5f0SHans Verkuil }
56dacca5f0SHans Verkuil 
touch_cap_buf_queue(struct vb2_buffer * vb)57dacca5f0SHans Verkuil static void touch_cap_buf_queue(struct vb2_buffer *vb)
58dacca5f0SHans Verkuil {
59dacca5f0SHans Verkuil 	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
60dacca5f0SHans Verkuil 	struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
61dacca5f0SHans Verkuil 	struct vivid_buffer *buf = container_of(vbuf, struct vivid_buffer, vb);
62dacca5f0SHans Verkuil 
63dacca5f0SHans Verkuil 	vbuf->field = V4L2_FIELD_NONE;
64dacca5f0SHans Verkuil 	spin_lock(&dev->slock);
65dacca5f0SHans Verkuil 	list_add_tail(&buf->list, &dev->touch_cap_active);
66dacca5f0SHans Verkuil 	spin_unlock(&dev->slock);
67dacca5f0SHans Verkuil }
68dacca5f0SHans Verkuil 
touch_cap_start_streaming(struct vb2_queue * vq,unsigned int count)69dacca5f0SHans Verkuil static int touch_cap_start_streaming(struct vb2_queue *vq, unsigned int count)
70dacca5f0SHans Verkuil {
71dacca5f0SHans Verkuil 	struct vivid_dev *dev = vb2_get_drv_priv(vq);
72dacca5f0SHans Verkuil 	int err;
73dacca5f0SHans Verkuil 
74dacca5f0SHans Verkuil 	dev->touch_cap_seq_count = 0;
75dacca5f0SHans Verkuil 	if (dev->start_streaming_error) {
76dacca5f0SHans Verkuil 		dev->start_streaming_error = false;
77dacca5f0SHans Verkuil 		err = -EINVAL;
78dacca5f0SHans Verkuil 	} else {
79dacca5f0SHans Verkuil 		err = vivid_start_generating_touch_cap(dev);
80dacca5f0SHans Verkuil 	}
81dacca5f0SHans Verkuil 	if (err) {
82dacca5f0SHans Verkuil 		struct vivid_buffer *buf, *tmp;
83dacca5f0SHans Verkuil 
84dacca5f0SHans Verkuil 		list_for_each_entry_safe(buf, tmp,
85dacca5f0SHans Verkuil 					 &dev->touch_cap_active, list) {
86dacca5f0SHans Verkuil 			list_del(&buf->list);
87dacca5f0SHans Verkuil 			vb2_buffer_done(&buf->vb.vb2_buf,
88dacca5f0SHans Verkuil 					VB2_BUF_STATE_QUEUED);
89dacca5f0SHans Verkuil 		}
90dacca5f0SHans Verkuil 	}
91dacca5f0SHans Verkuil 	return err;
92dacca5f0SHans Verkuil }
93dacca5f0SHans Verkuil 
94dacca5f0SHans Verkuil /* abort streaming and wait for last buffer */
touch_cap_stop_streaming(struct vb2_queue * vq)95dacca5f0SHans Verkuil static void touch_cap_stop_streaming(struct vb2_queue *vq)
96dacca5f0SHans Verkuil {
97dacca5f0SHans Verkuil 	struct vivid_dev *dev = vb2_get_drv_priv(vq);
98dacca5f0SHans Verkuil 
99dacca5f0SHans Verkuil 	vivid_stop_generating_touch_cap(dev);
100dacca5f0SHans Verkuil }
101dacca5f0SHans Verkuil 
touch_cap_buf_request_complete(struct vb2_buffer * vb)102dacca5f0SHans Verkuil static void touch_cap_buf_request_complete(struct vb2_buffer *vb)
103dacca5f0SHans Verkuil {
104dacca5f0SHans Verkuil 	struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
105dacca5f0SHans Verkuil 
106dacca5f0SHans Verkuil 	v4l2_ctrl_request_complete(vb->req_obj.req, &dev->ctrl_hdl_touch_cap);
107dacca5f0SHans Verkuil }
108dacca5f0SHans Verkuil 
109dacca5f0SHans Verkuil const struct vb2_ops vivid_touch_cap_qops = {
110dacca5f0SHans Verkuil 	.queue_setup		= touch_cap_queue_setup,
111dacca5f0SHans Verkuil 	.buf_prepare		= touch_cap_buf_prepare,
112dacca5f0SHans Verkuil 	.buf_queue		= touch_cap_buf_queue,
113dacca5f0SHans Verkuil 	.start_streaming	= touch_cap_start_streaming,
114dacca5f0SHans Verkuil 	.stop_streaming		= touch_cap_stop_streaming,
115dacca5f0SHans Verkuil 	.buf_request_complete	= touch_cap_buf_request_complete,
116dacca5f0SHans Verkuil 	.wait_prepare		= vb2_ops_wait_prepare,
117dacca5f0SHans Verkuil 	.wait_finish		= vb2_ops_wait_finish,
118dacca5f0SHans Verkuil };
119dacca5f0SHans Verkuil 
vivid_enum_fmt_tch(struct file * file,void * priv,struct v4l2_fmtdesc * f)120dacca5f0SHans Verkuil int vivid_enum_fmt_tch(struct file *file, void  *priv, struct v4l2_fmtdesc *f)
121dacca5f0SHans Verkuil {
122dacca5f0SHans Verkuil 	if (f->index)
123dacca5f0SHans Verkuil 		return -EINVAL;
124dacca5f0SHans Verkuil 
125dacca5f0SHans Verkuil 	f->pixelformat = V4L2_TCH_FMT_DELTA_TD16;
126dacca5f0SHans Verkuil 	return 0;
127dacca5f0SHans Verkuil }
128dacca5f0SHans Verkuil 
vivid_g_fmt_tch(struct file * file,void * priv,struct v4l2_format * f)129dacca5f0SHans Verkuil int vivid_g_fmt_tch(struct file *file, void *priv, struct v4l2_format *f)
130dacca5f0SHans Verkuil {
131dacca5f0SHans Verkuil 	struct vivid_dev *dev = video_drvdata(file);
132dacca5f0SHans Verkuil 
133dacca5f0SHans Verkuil 	if (dev->multiplanar)
134dacca5f0SHans Verkuil 		return -ENOTTY;
135dacca5f0SHans Verkuil 	f->fmt.pix = dev->tch_format;
136dacca5f0SHans Verkuil 	return 0;
137dacca5f0SHans Verkuil }
138dacca5f0SHans Verkuil 
vivid_g_fmt_tch_mplane(struct file * file,void * priv,struct v4l2_format * f)139dacca5f0SHans Verkuil int vivid_g_fmt_tch_mplane(struct file *file, void *priv, struct v4l2_format *f)
140dacca5f0SHans Verkuil {
141dacca5f0SHans Verkuil 	struct vivid_dev *dev = video_drvdata(file);
142dacca5f0SHans Verkuil 	struct v4l2_format sp_fmt;
143dacca5f0SHans Verkuil 
144dacca5f0SHans Verkuil 	if (!dev->multiplanar)
145dacca5f0SHans Verkuil 		return -ENOTTY;
146dacca5f0SHans Verkuil 	sp_fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
147dacca5f0SHans Verkuil 	sp_fmt.fmt.pix = dev->tch_format;
148dacca5f0SHans Verkuil 	fmt_sp2mp(&sp_fmt, f);
149dacca5f0SHans Verkuil 	return 0;
150dacca5f0SHans Verkuil }
151dacca5f0SHans Verkuil 
vivid_g_parm_tch(struct file * file,void * priv,struct v4l2_streamparm * parm)152dacca5f0SHans Verkuil int vivid_g_parm_tch(struct file *file, void *priv,
153dacca5f0SHans Verkuil 		     struct v4l2_streamparm *parm)
154dacca5f0SHans Verkuil {
155dacca5f0SHans Verkuil 	struct vivid_dev *dev = video_drvdata(file);
156dacca5f0SHans Verkuil 
157dacca5f0SHans Verkuil 	if (parm->type != (dev->multiplanar ?
158dacca5f0SHans Verkuil 			   V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE :
159dacca5f0SHans Verkuil 			   V4L2_BUF_TYPE_VIDEO_CAPTURE))
160dacca5f0SHans Verkuil 		return -EINVAL;
161dacca5f0SHans Verkuil 
162dacca5f0SHans Verkuil 	parm->parm.capture.capability   = V4L2_CAP_TIMEPERFRAME;
163dacca5f0SHans Verkuil 	parm->parm.capture.timeperframe = dev->timeperframe_tch_cap;
164dacca5f0SHans Verkuil 	parm->parm.capture.readbuffers  = 1;
165dacca5f0SHans Verkuil 	return 0;
166dacca5f0SHans Verkuil }
167dacca5f0SHans Verkuil 
vivid_enum_input_tch(struct file * file,void * priv,struct v4l2_input * inp)168dacca5f0SHans Verkuil int vivid_enum_input_tch(struct file *file, void *priv, struct v4l2_input *inp)
169dacca5f0SHans Verkuil {
170dacca5f0SHans Verkuil 	if (inp->index)
171dacca5f0SHans Verkuil 		return -EINVAL;
172dacca5f0SHans Verkuil 
173dacca5f0SHans Verkuil 	inp->type = V4L2_INPUT_TYPE_TOUCH;
174dacca5f0SHans Verkuil 	strscpy(inp->name, "Vivid Touch", sizeof(inp->name));
175dacca5f0SHans Verkuil 	inp->capabilities = 0;
176dacca5f0SHans Verkuil 	return 0;
177dacca5f0SHans Verkuil }
178dacca5f0SHans Verkuil 
vivid_g_input_tch(struct file * file,void * priv,unsigned int * i)179dacca5f0SHans Verkuil int vivid_g_input_tch(struct file *file, void *priv, unsigned int *i)
180dacca5f0SHans Verkuil {
181dacca5f0SHans Verkuil 	*i = 0;
182dacca5f0SHans Verkuil 	return 0;
183dacca5f0SHans Verkuil }
184dacca5f0SHans Verkuil 
vivid_set_touch(struct vivid_dev * dev,unsigned int i)185dacca5f0SHans Verkuil int vivid_set_touch(struct vivid_dev *dev, unsigned int i)
186dacca5f0SHans Verkuil {
187dacca5f0SHans Verkuil 	struct v4l2_pix_format *f = &dev->tch_format;
188dacca5f0SHans Verkuil 
189dacca5f0SHans Verkuil 	if (i)
190dacca5f0SHans Verkuil 		return -EINVAL;
191dacca5f0SHans Verkuil 
192dacca5f0SHans Verkuil 	f->pixelformat = V4L2_TCH_FMT_DELTA_TD16;
193dacca5f0SHans Verkuil 	f->width =  VIVID_TCH_WIDTH;
194dacca5f0SHans Verkuil 	f->height = VIVID_TCH_HEIGHT;
195dacca5f0SHans Verkuil 	f->field = V4L2_FIELD_NONE;
196dacca5f0SHans Verkuil 	f->colorspace = V4L2_COLORSPACE_RAW;
197dacca5f0SHans Verkuil 	f->bytesperline = f->width * sizeof(s16);
198dacca5f0SHans Verkuil 	f->sizeimage = f->width * f->height * sizeof(s16);
199dacca5f0SHans Verkuil 	return 0;
200dacca5f0SHans Verkuil }
201dacca5f0SHans Verkuil 
vivid_s_input_tch(struct file * file,void * priv,unsigned int i)202dacca5f0SHans Verkuil int vivid_s_input_tch(struct file *file, void *priv, unsigned int i)
203dacca5f0SHans Verkuil {
204dacca5f0SHans Verkuil 	return vivid_set_touch(video_drvdata(file), i);
205dacca5f0SHans Verkuil }
206dacca5f0SHans Verkuil 
vivid_fill_buff_noise(__s16 * tch_buf,int size)207dacca5f0SHans Verkuil static void vivid_fill_buff_noise(__s16 *tch_buf, int size)
208dacca5f0SHans Verkuil {
209dacca5f0SHans Verkuil 	int i;
210dacca5f0SHans Verkuil 
211dacca5f0SHans Verkuil 	/* Fill 10% of the values within range -3 and 3, zero the others */
212dacca5f0SHans Verkuil 	for (i = 0; i < size; i++) {
213a251c17aSJason A. Donenfeld 		unsigned int rand = get_random_u32();
214dacca5f0SHans Verkuil 
215dacca5f0SHans Verkuil 		if (rand % 10)
216dacca5f0SHans Verkuil 			tch_buf[i] = 0;
217dacca5f0SHans Verkuil 		else
218dacca5f0SHans Verkuil 			tch_buf[i] = (rand / 10) % 7 - 3;
219dacca5f0SHans Verkuil 	}
220dacca5f0SHans Verkuil }
221dacca5f0SHans Verkuil 
get_random_pressure(void)222dacca5f0SHans Verkuil static inline int get_random_pressure(void)
223dacca5f0SHans Verkuil {
224*8032bf12SJason A. Donenfeld 	return get_random_u32_below(VIVID_PRESSURE_LIMIT);
225dacca5f0SHans Verkuil }
226dacca5f0SHans Verkuil 
vivid_tch_buf_set(struct v4l2_pix_format * f,__s16 * tch_buf,int index)227dacca5f0SHans Verkuil static void vivid_tch_buf_set(struct v4l2_pix_format *f,
228dacca5f0SHans Verkuil 			      __s16 *tch_buf,
229dacca5f0SHans Verkuil 			      int index)
230dacca5f0SHans Verkuil {
231dacca5f0SHans Verkuil 	unsigned int x = index % f->width;
232dacca5f0SHans Verkuil 	unsigned int y = index / f->width;
233dacca5f0SHans Verkuil 	unsigned int offset = VIVID_MIN_PRESSURE;
234dacca5f0SHans Verkuil 
235dacca5f0SHans Verkuil 	tch_buf[index] = offset + get_random_pressure();
236dacca5f0SHans Verkuil 	offset /= 2;
237dacca5f0SHans Verkuil 	if (x)
238dacca5f0SHans Verkuil 		tch_buf[index - 1] = offset + get_random_pressure();
239dacca5f0SHans Verkuil 	if (x < f->width - 1)
240dacca5f0SHans Verkuil 		tch_buf[index + 1] = offset + get_random_pressure();
241dacca5f0SHans Verkuil 	if (y)
242dacca5f0SHans Verkuil 		tch_buf[index - f->width] = offset + get_random_pressure();
243dacca5f0SHans Verkuil 	if (y < f->height - 1)
244dacca5f0SHans Verkuil 		tch_buf[index + f->width] = offset + get_random_pressure();
245dacca5f0SHans Verkuil 	offset /= 2;
246dacca5f0SHans Verkuil 	if (x && y)
247dacca5f0SHans Verkuil 		tch_buf[index - 1 - f->width] = offset + get_random_pressure();
248dacca5f0SHans Verkuil 	if (x < f->width - 1 && y)
249dacca5f0SHans Verkuil 		tch_buf[index + 1 - f->width] = offset + get_random_pressure();
250dacca5f0SHans Verkuil 	if (x && y < f->height - 1)
251dacca5f0SHans Verkuil 		tch_buf[index - 1 + f->width] = offset + get_random_pressure();
252dacca5f0SHans Verkuil 	if (x < f->width - 1 && y < f->height - 1)
253dacca5f0SHans Verkuil 		tch_buf[index + 1 + f->width] = offset + get_random_pressure();
254dacca5f0SHans Verkuil }
255dacca5f0SHans Verkuil 
vivid_fillbuff_tch(struct vivid_dev * dev,struct vivid_buffer * buf)256dacca5f0SHans Verkuil void vivid_fillbuff_tch(struct vivid_dev *dev, struct vivid_buffer *buf)
257dacca5f0SHans Verkuil {
258dacca5f0SHans Verkuil 	struct v4l2_pix_format *f = &dev->tch_format;
259dacca5f0SHans Verkuil 	int size = f->width * f->height;
260dacca5f0SHans Verkuil 	int x, y, xstart, ystart, offset_x, offset_y;
261dacca5f0SHans Verkuil 	unsigned int test_pattern, test_pat_idx, rand;
262dacca5f0SHans Verkuil 
263dacca5f0SHans Verkuil 	__s16 *tch_buf = vb2_plane_vaddr(&buf->vb.vb2_buf, 0);
264dacca5f0SHans Verkuil 
26557c1d5deSDeborah Brouwer 	buf->vb.sequence = dev->touch_cap_with_seq_wrap_count;
266dacca5f0SHans Verkuil 	test_pattern = (buf->vb.sequence / TCH_SEQ_COUNT) % TEST_CASE_MAX;
267dacca5f0SHans Verkuil 	test_pat_idx = buf->vb.sequence % TCH_SEQ_COUNT;
268dacca5f0SHans Verkuil 
269dacca5f0SHans Verkuil 	vivid_fill_buff_noise(tch_buf, size);
270dacca5f0SHans Verkuil 
271dacca5f0SHans Verkuil 	if (test_pat_idx >= TCH_PATTERN_COUNT)
272dacca5f0SHans Verkuil 		return;
273dacca5f0SHans Verkuil 
274dacca5f0SHans Verkuil 	if (test_pat_idx == 0)
275a251c17aSJason A. Donenfeld 		dev->tch_pat_random = get_random_u32();
276dacca5f0SHans Verkuil 	rand = dev->tch_pat_random;
277dacca5f0SHans Verkuil 
278dacca5f0SHans Verkuil 	switch (test_pattern) {
279dacca5f0SHans Verkuil 	case SINGLE_TAP:
280dacca5f0SHans Verkuil 		if (test_pat_idx == 2)
281dacca5f0SHans Verkuil 			vivid_tch_buf_set(f, tch_buf, rand % size);
282dacca5f0SHans Verkuil 		break;
283dacca5f0SHans Verkuil 	case DOUBLE_TAP:
284dacca5f0SHans Verkuil 		if (test_pat_idx == 2 || test_pat_idx == 4)
285dacca5f0SHans Verkuil 			vivid_tch_buf_set(f, tch_buf, rand % size);
286dacca5f0SHans Verkuil 		break;
287dacca5f0SHans Verkuil 	case TRIPLE_TAP:
288dacca5f0SHans Verkuil 		if (test_pat_idx == 2 || test_pat_idx == 4 || test_pat_idx == 6)
289dacca5f0SHans Verkuil 			vivid_tch_buf_set(f, tch_buf, rand % size);
290dacca5f0SHans Verkuil 		break;
291dacca5f0SHans Verkuil 	case MOVE_LEFT_TO_RIGHT:
292dacca5f0SHans Verkuil 		vivid_tch_buf_set(f, tch_buf,
293dacca5f0SHans Verkuil 				  (rand % f->height) * f->width +
294dacca5f0SHans Verkuil 				  test_pat_idx *
295dacca5f0SHans Verkuil 				  (f->width / TCH_PATTERN_COUNT));
296dacca5f0SHans Verkuil 		break;
297dacca5f0SHans Verkuil 	case ZOOM_IN:
298dacca5f0SHans Verkuil 		x = f->width / 2;
299dacca5f0SHans Verkuil 		y = f->height / 2;
300dacca5f0SHans Verkuil 		offset_x = ((TCH_PATTERN_COUNT - 1 - test_pat_idx) * x) /
301dacca5f0SHans Verkuil 				TCH_PATTERN_COUNT;
302dacca5f0SHans Verkuil 		offset_y = ((TCH_PATTERN_COUNT - 1 - test_pat_idx) * y) /
303dacca5f0SHans Verkuil 				TCH_PATTERN_COUNT;
304dacca5f0SHans Verkuil 		vivid_tch_buf_set(f, tch_buf,
305dacca5f0SHans Verkuil 				  (x - offset_x) + f->width * (y - offset_y));
306dacca5f0SHans Verkuil 		vivid_tch_buf_set(f, tch_buf,
307dacca5f0SHans Verkuil 				  (x + offset_x) + f->width * (y + offset_y));
308dacca5f0SHans Verkuil 		break;
309dacca5f0SHans Verkuil 	case ZOOM_OUT:
310dacca5f0SHans Verkuil 		x = f->width / 2;
311dacca5f0SHans Verkuil 		y = f->height / 2;
312dacca5f0SHans Verkuil 		offset_x = (test_pat_idx * x) / TCH_PATTERN_COUNT;
313dacca5f0SHans Verkuil 		offset_y = (test_pat_idx * y) / TCH_PATTERN_COUNT;
314dacca5f0SHans Verkuil 		vivid_tch_buf_set(f, tch_buf,
315dacca5f0SHans Verkuil 				  (x - offset_x) + f->width * (y - offset_y));
316dacca5f0SHans Verkuil 		vivid_tch_buf_set(f, tch_buf,
317dacca5f0SHans Verkuil 				  (x + offset_x) + f->width * (y + offset_y));
318dacca5f0SHans Verkuil 		break;
319dacca5f0SHans Verkuil 	case PALM_PRESS:
320dacca5f0SHans Verkuil 		for (x = 0; x < f->width; x++)
321dacca5f0SHans Verkuil 			for (y = f->height / 2; y < f->height; y++)
322dacca5f0SHans Verkuil 				tch_buf[x + f->width * y] = VIVID_MIN_PRESSURE +
323dacca5f0SHans Verkuil 							get_random_pressure();
324dacca5f0SHans Verkuil 		break;
325dacca5f0SHans Verkuil 	case MULTIPLE_PRESS:
326dacca5f0SHans Verkuil 		/* 16 pressure points */
327dacca5f0SHans Verkuil 		for (y = 0; y < 4; y++) {
328dacca5f0SHans Verkuil 			for (x = 0; x < 4; x++) {
329dacca5f0SHans Verkuil 				ystart = (y * f->height) / 4 + f->height / 8;
330dacca5f0SHans Verkuil 				xstart = (x * f->width) / 4 + f->width / 8;
331dacca5f0SHans Verkuil 				vivid_tch_buf_set(f, tch_buf,
332dacca5f0SHans Verkuil 						  ystart * f->width + xstart);
333dacca5f0SHans Verkuil 			}
334dacca5f0SHans Verkuil 		}
335dacca5f0SHans Verkuil 		break;
336dacca5f0SHans Verkuil 	}
337dacca5f0SHans Verkuil #ifdef __BIG_ENDIAN__
338dacca5f0SHans Verkuil 	for (x = 0; x < size; x++)
339dacca5f0SHans Verkuil 		tch_buf[x] = (__force s16)__cpu_to_le16((u16)tch_buf[x]);
340dacca5f0SHans Verkuil #endif
341dacca5f0SHans Verkuil }
342