hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/media/platform/rockchip/isp/isp_rockit.c
....@@ -240,10 +240,16 @@
240240 rockit_cfg->frame.u64PTS = stream->curr_buf->vb.vb2_buf.timestamp;
241241
242242 rockit_cfg->frame.u32TimeRef = stream->curr_buf->vb.sequence;
243
+ v4l2_dbg(2, rkisp_debug, &dev->v4l2_dev,
244
+ "%s stream:%d seq:%d buf:0x%x done\n",
245
+ __func__, stream->id,
246
+ stream->curr_buf->vb.sequence,
247
+ stream->curr_buf->buff_addr[0]);
243248 } else {
244249 if (stream->ispdev->cap_dev.wrap_line &&
245250 stream->id == RKISP_STREAM_MP) {
246
- if (stream_cfg->is_discard || stream->ops->is_stream_stopped(stream))
251
+ if (dev->is_first_double || stream_cfg->is_discard ||
252
+ stream->ops->is_stream_stopped(stream))
247253 return 0;
248254 } else if (stream_cfg->dst_fps) {
249255 if (!stream_cfg->is_discard && !stream->curr_buf) {
....@@ -259,7 +265,7 @@
259265 rkisp_dmarx_get_frame(stream->ispdev, &seq, NULL, &ns, true);
260266
261267 if (!ns)
262
- ns = ktime_get_ns();
268
+ ns = rkisp_time_get_ns(dev);
263269
264270 rockit_cfg->frame.u64PTS = ns;
265271
....@@ -316,8 +322,9 @@
316322 int width, int height, int wrap_line)
317323 {
318324 struct rkisp_stream *stream = NULL;
319
- struct rkisp_buffer *isp_buf;
325
+ struct rkisp_buffer *isp_buf, *buf_temp;
320326 int offset, i, ret;
327
+ unsigned long lock_flags = 0;
321328
322329 stream = rkisp_rockit_get_stream(input_rockit_cfg);
323330
....@@ -337,16 +344,18 @@
337344 if (stream->ispdev->cap_dev.wrap_line && stream->id == RKISP_STREAM_MP)
338345 rkisp_dvbm_init(stream);
339346
347
+ spin_lock_irqsave(&stream->vbq_lock, lock_flags);
340348 if (stream->curr_buf) {
341349 list_add_tail(&stream->curr_buf->queue, &stream->buf_queue);
350
+ if (stream->curr_buf == stream->next_buf)
351
+ stream->next_buf = NULL;
342352 stream->curr_buf = NULL;
343353 }
344354 if (stream->next_buf) {
345355 list_add_tail(&stream->next_buf->queue, &stream->buf_queue);
346356 stream->next_buf = NULL;
347357 }
348
-
349
- list_for_each_entry(isp_buf, &stream->buf_queue, queue) {
358
+ list_for_each_entry_safe(isp_buf, buf_temp, &stream->buf_queue, queue) {
350359 if (stream->out_isp_fmt.mplanes == 1) {
351360 for (i = 0; i < stream->out_isp_fmt.cplanes - 1; i++) {
352361 height = stream->out_fmt.height;
....@@ -358,6 +367,7 @@
358367 }
359368 }
360369 }
370
+ spin_unlock_irqrestore(&stream->vbq_lock, lock_flags);
361371
362372 return 0;
363373 }
....@@ -421,6 +431,46 @@
421431 }
422432 EXPORT_SYMBOL(rkisp_rockit_free_tb_stream_buf);
423433
434
+int rkisp_rockit_free_stream_buf(struct rockit_cfg *input_rockit_cfg)
435
+{
436
+ struct rkisp_stream *stream;
437
+ struct rkisp_buffer *buf;
438
+ unsigned long lock_flags = 0;
439
+
440
+ if (!input_rockit_cfg)
441
+ return -EINVAL;
442
+ stream = rkisp_rockit_get_stream(input_rockit_cfg);
443
+ if (!stream)
444
+ return -EINVAL;
445
+
446
+ if (stream->streaming)
447
+ return 0;
448
+
449
+ spin_lock_irqsave(&stream->vbq_lock, lock_flags);
450
+ if (stream->curr_buf) {
451
+ list_add_tail(&stream->curr_buf->queue, &stream->buf_queue);
452
+ if (stream->curr_buf == stream->next_buf)
453
+ stream->next_buf = NULL;
454
+ stream->curr_buf = NULL;
455
+ }
456
+ if (stream->next_buf) {
457
+ list_add_tail(&stream->next_buf->queue, &stream->buf_queue);
458
+ stream->next_buf = NULL;
459
+ }
460
+
461
+ while (!list_empty(&stream->buf_queue)) {
462
+ buf = list_first_entry(&stream->buf_queue,
463
+ struct rkisp_buffer, queue);
464
+ list_del(&buf->queue);
465
+ }
466
+ rkisp_rockit_buf_state_clear(stream);
467
+ spin_unlock_irqrestore(&stream->vbq_lock, lock_flags);
468
+ rkisp_rockit_buf_free(stream);
469
+
470
+ return 0;
471
+}
472
+EXPORT_SYMBOL(rkisp_rockit_free_stream_buf);
473
+
424474 void rkisp_rockit_buf_state_clear(struct rkisp_stream *stream)
425475 {
426476 struct rkisp_stream_cfg *stream_cfg;
....@@ -446,6 +496,7 @@
446496 return -EINVAL;
447497
448498 stream_cfg = &rockit_cfg->rkisp_dev_cfg[dev_id].rkisp_stream_cfg[stream->id];
499
+ mutex_lock(&stream_cfg->freebuf_lock);
449500 for (i = 0; i < ROCKIT_BUF_NUM_MAX; i++) {
450501 if (stream_cfg->rkisp_buff[i]) {
451502 isprk_buf = (struct rkisp_rockit_buffer *)stream_cfg->rkisp_buff[i];
....@@ -458,12 +509,14 @@
458509 stream_cfg->rkisp_buff[i] = NULL;
459510 }
460511 }
512
+ mutex_unlock(&stream_cfg->freebuf_lock);
461513 return 0;
462514 }
463515
464516 void rkisp_rockit_dev_init(struct rkisp_device *dev)
465517 {
466
- int i;
518
+ struct rkisp_stream_cfg *stream_cfg;
519
+ int i, j;
467520
468521 if (rockit_cfg == NULL) {
469522 rockit_cfg = kzalloc(sizeof(struct rockit_cfg), GFP_KERNEL);
....@@ -477,6 +530,10 @@
477530 dev->hw_dev->isp[i]->name;
478531 rockit_cfg->rkisp_dev_cfg[i].isp_dev =
479532 dev->hw_dev->isp[i];
533
+ for (j = 0; j < RKISP_MAX_STREAM; j++) {
534
+ stream_cfg = &rockit_cfg->rkisp_dev_cfg[i].rkisp_stream_cfg[j];
535
+ mutex_init(&stream_cfg->freebuf_lock);
536
+ }
480537 }
481538 }
482539 }