| .. | .. |
|---|
| 240 | 240 | rockit_cfg->frame.u64PTS = stream->curr_buf->vb.vb2_buf.timestamp; |
|---|
| 241 | 241 | |
|---|
| 242 | 242 | 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]); |
|---|
| 243 | 248 | } else { |
|---|
| 244 | 249 | if (stream->ispdev->cap_dev.wrap_line && |
|---|
| 245 | 250 | 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)) |
|---|
| 247 | 253 | return 0; |
|---|
| 248 | 254 | } else if (stream_cfg->dst_fps) { |
|---|
| 249 | 255 | if (!stream_cfg->is_discard && !stream->curr_buf) { |
|---|
| .. | .. |
|---|
| 259 | 265 | rkisp_dmarx_get_frame(stream->ispdev, &seq, NULL, &ns, true); |
|---|
| 260 | 266 | |
|---|
| 261 | 267 | if (!ns) |
|---|
| 262 | | - ns = ktime_get_ns(); |
|---|
| 268 | + ns = rkisp_time_get_ns(dev); |
|---|
| 263 | 269 | |
|---|
| 264 | 270 | rockit_cfg->frame.u64PTS = ns; |
|---|
| 265 | 271 | |
|---|
| .. | .. |
|---|
| 316 | 322 | int width, int height, int wrap_line) |
|---|
| 317 | 323 | { |
|---|
| 318 | 324 | struct rkisp_stream *stream = NULL; |
|---|
| 319 | | - struct rkisp_buffer *isp_buf; |
|---|
| 325 | + struct rkisp_buffer *isp_buf, *buf_temp; |
|---|
| 320 | 326 | int offset, i, ret; |
|---|
| 327 | + unsigned long lock_flags = 0; |
|---|
| 321 | 328 | |
|---|
| 322 | 329 | stream = rkisp_rockit_get_stream(input_rockit_cfg); |
|---|
| 323 | 330 | |
|---|
| .. | .. |
|---|
| 337 | 344 | if (stream->ispdev->cap_dev.wrap_line && stream->id == RKISP_STREAM_MP) |
|---|
| 338 | 345 | rkisp_dvbm_init(stream); |
|---|
| 339 | 346 | |
|---|
| 347 | + spin_lock_irqsave(&stream->vbq_lock, lock_flags); |
|---|
| 340 | 348 | if (stream->curr_buf) { |
|---|
| 341 | 349 | list_add_tail(&stream->curr_buf->queue, &stream->buf_queue); |
|---|
| 350 | + if (stream->curr_buf == stream->next_buf) |
|---|
| 351 | + stream->next_buf = NULL; |
|---|
| 342 | 352 | stream->curr_buf = NULL; |
|---|
| 343 | 353 | } |
|---|
| 344 | 354 | if (stream->next_buf) { |
|---|
| 345 | 355 | list_add_tail(&stream->next_buf->queue, &stream->buf_queue); |
|---|
| 346 | 356 | stream->next_buf = NULL; |
|---|
| 347 | 357 | } |
|---|
| 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) { |
|---|
| 350 | 359 | if (stream->out_isp_fmt.mplanes == 1) { |
|---|
| 351 | 360 | for (i = 0; i < stream->out_isp_fmt.cplanes - 1; i++) { |
|---|
| 352 | 361 | height = stream->out_fmt.height; |
|---|
| .. | .. |
|---|
| 358 | 367 | } |
|---|
| 359 | 368 | } |
|---|
| 360 | 369 | } |
|---|
| 370 | + spin_unlock_irqrestore(&stream->vbq_lock, lock_flags); |
|---|
| 361 | 371 | |
|---|
| 362 | 372 | return 0; |
|---|
| 363 | 373 | } |
|---|
| .. | .. |
|---|
| 421 | 431 | } |
|---|
| 422 | 432 | EXPORT_SYMBOL(rkisp_rockit_free_tb_stream_buf); |
|---|
| 423 | 433 | |
|---|
| 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 | + |
|---|
| 424 | 474 | void rkisp_rockit_buf_state_clear(struct rkisp_stream *stream) |
|---|
| 425 | 475 | { |
|---|
| 426 | 476 | struct rkisp_stream_cfg *stream_cfg; |
|---|
| .. | .. |
|---|
| 446 | 496 | return -EINVAL; |
|---|
| 447 | 497 | |
|---|
| 448 | 498 | stream_cfg = &rockit_cfg->rkisp_dev_cfg[dev_id].rkisp_stream_cfg[stream->id]; |
|---|
| 499 | + mutex_lock(&stream_cfg->freebuf_lock); |
|---|
| 449 | 500 | for (i = 0; i < ROCKIT_BUF_NUM_MAX; i++) { |
|---|
| 450 | 501 | if (stream_cfg->rkisp_buff[i]) { |
|---|
| 451 | 502 | isprk_buf = (struct rkisp_rockit_buffer *)stream_cfg->rkisp_buff[i]; |
|---|
| .. | .. |
|---|
| 458 | 509 | stream_cfg->rkisp_buff[i] = NULL; |
|---|
| 459 | 510 | } |
|---|
| 460 | 511 | } |
|---|
| 512 | + mutex_unlock(&stream_cfg->freebuf_lock); |
|---|
| 461 | 513 | return 0; |
|---|
| 462 | 514 | } |
|---|
| 463 | 515 | |
|---|
| 464 | 516 | void rkisp_rockit_dev_init(struct rkisp_device *dev) |
|---|
| 465 | 517 | { |
|---|
| 466 | | - int i; |
|---|
| 518 | + struct rkisp_stream_cfg *stream_cfg; |
|---|
| 519 | + int i, j; |
|---|
| 467 | 520 | |
|---|
| 468 | 521 | if (rockit_cfg == NULL) { |
|---|
| 469 | 522 | rockit_cfg = kzalloc(sizeof(struct rockit_cfg), GFP_KERNEL); |
|---|
| .. | .. |
|---|
| 477 | 530 | dev->hw_dev->isp[i]->name; |
|---|
| 478 | 531 | rockit_cfg->rkisp_dev_cfg[i].isp_dev = |
|---|
| 479 | 532 | 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 | + } |
|---|
| 480 | 537 | } |
|---|
| 481 | 538 | } |
|---|
| 482 | 539 | } |
|---|