Skip to content

Commit 78bb397

Browse files
Cai YiWeirkhuangtao
authored andcommitted
media: rockchip: isp: thunderboot for isp32
Change-Id: Id9e7ee4f009ae18f4943ac3252ee766ea4532b80 Signed-off-by: Cai YiWei <[email protected]>
1 parent 9fde394 commit 78bb397

File tree

11 files changed

+195
-45
lines changed

11 files changed

+195
-45
lines changed

drivers/media/platform/rockchip/isp/capture.c

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <media/videobuf2-dma-contig.h>
1212
#include "dev.h"
1313
#include "regs.h"
14+
#include "rkisp_tb_helper.h"
1415

1516
#define STREAM_MAX_MP_RSZ_OUTPUT_WIDTH 4416
1617
#define STREAM_MAX_MP_RSZ_OUTPUT_HEIGHT 3312
@@ -1143,6 +1144,7 @@ int rkisp_fh_open(struct file *filp)
11431144
struct rkisp_stream *stream = video_drvdata(filp);
11441145
int ret;
11451146

1147+
stream->is_using_resmem = false;
11461148
ret = v4l2_fh_open(filp);
11471149
if (!ret) {
11481150
ret = v4l2_pipeline_pm_get(&stream->vnode.vdev.entity);
@@ -1449,16 +1451,14 @@ static int rkisp_set_wrap_line(struct rkisp_stream *stream, int *line)
14491451
{
14501452
struct rkisp_device *dev = stream->ispdev;
14511453

1452-
if (dev->isp_ver != ISP_V32)
1453-
return -EINVAL;
1454-
1455-
if (dev->hw_dev->dev_link_num > 1 || stream->id != RKISP_STREAM_MP) {
1454+
if (dev->isp_ver != ISP_V32 ||
1455+
dev->hw_dev->dev_link_num > 1 ||
1456+
!stream->ops->set_wrap) {
14561457
v4l2_err(&dev->v4l2_dev,
14571458
"wrap only support for single sensor and mainpath\n");
14581459
return -EINVAL;
14591460
}
1460-
dev->cap_dev.wrap_line = *line;
1461-
return 0;
1461+
return stream->ops->set_wrap(stream, *line);
14621462
}
14631463

14641464
static int rkisp_set_fps(struct rkisp_stream *stream, int *fps)
@@ -1796,6 +1796,32 @@ static const struct v4l2_ioctl_ops rkisp_v4l2_ioctl_ops = {
17961796
.vidioc_default = rkisp_ioctl_default,
17971797
};
17981798

1799+
static void rkisp_stream_fast(struct work_struct *work)
1800+
{
1801+
struct rkisp_capture_device *cap_dev =
1802+
container_of(work, struct rkisp_capture_device, fast_work);
1803+
struct rkisp_stream *stream = &cap_dev->stream[0];
1804+
struct vb2_queue *q = &stream->vnode.buf_queue;
1805+
struct rkisp_device *ispdev = cap_dev->ispdev;
1806+
1807+
v4l2_pipeline_pm_get(&stream->vnode.vdev.entity);
1808+
rkisp_chk_tb_over(ispdev);
1809+
if (ispdev->tb_head.complete != RKISP_TB_OK) {
1810+
v4l2_pipeline_pm_put(&stream->vnode.vdev.entity);
1811+
return;
1812+
}
1813+
stream->is_pre_on = true;
1814+
stream->is_using_resmem = true;
1815+
ispdev->resmem_addr_curr = ispdev->resmem_addr;
1816+
if (ispdev->resmem_size < stream->out_fmt.plane_fmt[0].sizeimage) {
1817+
stream->is_using_resmem = false;
1818+
v4l2_warn(&ispdev->v4l2_dev,
1819+
"resmem size:%zu no enough for image:%d\n",
1820+
ispdev->resmem_size, stream->out_fmt.plane_fmt[0].sizeimage);
1821+
}
1822+
q->ops->start_streaming(q, 1);
1823+
}
1824+
17991825
void rkisp_unregister_stream_vdev(struct rkisp_stream *stream)
18001826
{
18011827
media_entity_cleanup(&stream->vnode.vdev.entity);
@@ -1902,6 +1928,8 @@ int rkisp_register_stream_vdevs(struct rkisp_device *dev)
19021928
st_cfg->max_rsz_height = CIF_ISP_INPUT_H_MAX_V32;
19031929
ret = rkisp_register_stream_v32(dev);
19041930
}
1931+
1932+
INIT_WORK(&cap_dev->fast_work, rkisp_stream_fast);
19051933
return ret;
19061934
}
19071935

drivers/media/platform/rockchip/isp/capture.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ struct streams_ops {
221221
void (*update_mi)(struct rkisp_stream *stream);
222222
int (*frame_end)(struct rkisp_stream *stream);
223223
int (*frame_start)(struct rkisp_stream *stream, u32 mis);
224+
int (*set_wrap)(struct rkisp_stream *stream, int line);
224225
};
225226

226227
struct rockit_isp_ops {
@@ -276,6 +277,8 @@ struct rkisp_stream {
276277
bool is_flip;
277278
bool is_pause;
278279
bool is_crop_upd;
280+
bool is_pre_on;
281+
bool is_using_resmem;
279282
wait_queue_head_t done;
280283
unsigned int burst;
281284
atomic_t sequence;
@@ -308,6 +311,8 @@ struct rkisp_capture_device {
308311
u32 wrap_line;
309312
bool is_done_early;
310313
bool is_mirror;
314+
315+
struct work_struct fast_work;
311316
};
312317

313318
extern struct stream_config rkisp_mp_stream_config;

drivers/media/platform/rockchip/isp/capture_v32.c

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
static int mi_frame_end(struct rkisp_stream *stream);
2828
static int mi_frame_start(struct rkisp_stream *stream, u32 mis);
29+
static int rkisp_create_dummy_buf(struct rkisp_stream *stream);
2930

3031
static const struct capture_fmt bp_fmts[] = {
3132
{
@@ -781,6 +782,7 @@ static void update_mi(struct rkisp_stream *stream)
781782
stream->next_buf = NULL;
782783
}
783784
} else if (dummy_buf->mem_priv) {
785+
/* wrap buf ENC */
784786
val = dummy_buf->dma_addr;
785787
reg = stream->config->mi.y_base_ad_init;
786788
rkisp_write(dev, reg, val, false);
@@ -791,6 +793,22 @@ static void update_mi(struct rkisp_stream *stream)
791793
reg = stream->config->mi.cr_base_ad_init;
792794
rkisp_write(dev, reg, val, false);
793795
}
796+
} else if (stream->is_using_resmem) {
797+
/* resmem for fast stream NV12 output */
798+
dma_addr_t max_addr = dev->resmem_addr + dev->resmem_size;
799+
u32 bytesperline = stream->out_fmt.plane_fmt[0].bytesperline;
800+
u32 buf_size = bytesperline * ALIGN(stream->out_fmt.height, 16) * 3 / 2;
801+
802+
reg = stream->config->mi.y_base_ad_init;
803+
val = dev->resmem_addr_curr;
804+
rkisp_write(dev, reg, val, false);
805+
806+
reg = stream->config->mi.cb_base_ad_init;
807+
val += bytesperline * stream->out_fmt.height;
808+
rkisp_write(dev, reg, val, false);
809+
810+
if (dev->resmem_addr_curr + buf_size * 2 <= max_addr)
811+
dev->resmem_addr_curr += buf_size;
794812
} else if (!stream->is_pause) {
795813
stream->is_pause = true;
796814
stream->ops->disable_mi(stream);
@@ -933,6 +951,29 @@ static int luma_frame_end(struct rkisp_stream *stream)
933951
return 0;
934952
}
935953

954+
static int mp_set_wrap(struct rkisp_stream *stream, int line)
955+
{
956+
struct rkisp_device *dev = stream->ispdev;
957+
int ret = 0;
958+
959+
dev->cap_dev.wrap_line = line;
960+
if (stream->is_pre_on &&
961+
stream->streaming &&
962+
!stream->dummy_buf.mem_priv) {
963+
ret = rkisp_create_dummy_buf(stream);
964+
if (ret)
965+
return ret;
966+
stream->ops->config_mi(stream);
967+
if (stream->is_pause) {
968+
stream->ops->enable_mi(stream);
969+
if (!ISP3X_ISP_OUT_LINE(rkisp_read(dev, ISP3X_ISP_DEBUG2, true)))
970+
stream_self_update(stream);
971+
stream->is_pause = false;
972+
}
973+
}
974+
return ret;
975+
}
976+
936977
static struct streams_ops rkisp_mp_streams_ops = {
937978
.config_mi = mp_config_mi,
938979
.enable_mi = mp_enable_mi,
@@ -942,6 +983,7 @@ static struct streams_ops rkisp_mp_streams_ops = {
942983
.update_mi = update_mi,
943984
.frame_end = mi_frame_end,
944985
.frame_start = mi_frame_start,
986+
.set_wrap = mp_set_wrap,
945987
};
946988

947989
static struct streams_ops rkisp_sp_streams_ops = {
@@ -1258,7 +1300,7 @@ static int rkisp_create_dummy_buf(struct rkisp_stream *stream)
12581300
buf->size = dev->isp_sdev.in_crop.width * dev->cap_dev.wrap_line * 2;
12591301
if (stream->out_isp_fmt.output_format == ISP32_MI_OUTPUT_YUV420)
12601302
buf->size = buf->size - buf->size / 4;
1261-
1303+
buf->size = stream->out_fmt.plane_fmt[0].sizeimage;
12621304
buf->is_need_dbuf = true;
12631305
ret = rkisp_alloc_buffer(stream->ispdev, buf);
12641306
if (ret == 0) {
@@ -1354,6 +1396,11 @@ static void rkisp_stop_streaming(struct vb2_queue *queue)
13541396

13551397
end:
13561398
mutex_unlock(&dev->hw_dev->dev_lock);
1399+
1400+
if (stream->is_pre_on) {
1401+
stream->is_pre_on = false;
1402+
v4l2_pipeline_pm_put(&stream->vnode.vdev.entity);
1403+
}
13571404
}
13581405

13591406
static int rkisp_stream_start(struct rkisp_stream *stream)
@@ -1406,7 +1453,10 @@ rkisp_start_streaming(struct vb2_queue *queue, unsigned int count)
14061453

14071454
if (WARN_ON(stream->streaming)) {
14081455
mutex_unlock(&dev->hw_dev->dev_lock);
1409-
return -EBUSY;
1456+
if (stream->is_pre_on)
1457+
return 0;
1458+
else
1459+
return -EBUSY;
14101460
}
14111461

14121462
memset(&stream->dbg, 0, sizeof(stream->dbg));

drivers/media/platform/rockchip/isp/dev.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -413,10 +413,15 @@ static int _set_pipeline_default_fmt(struct rkisp_device *dev)
413413
memset(&fmt, 0, sizeof(fmt));
414414
isp = &dev->isp_sdev.sd;
415415

416-
if (dev->active_sensor)
416+
if (dev->active_sensor) {
417417
fmt = dev->active_sensor->fmt[0];
418-
else
418+
if (fmt.format.code == dev->isp_sdev.in_frm.code &&
419+
fmt.format.width == dev->isp_sdev.in_frm.width &&
420+
fmt.format.height == dev->isp_sdev.in_frm.height)
421+
return 0;
422+
} else {
419423
fmt.format = dev->isp_sdev.in_frm;
424+
}
420425
code = fmt.format.code;
421426
fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
422427
fmt.pad = RKISP_ISP_PAD_SINK;
@@ -549,6 +554,8 @@ static int subdev_notifier_complete(struct v4l2_async_notifier *notifier)
549554

550555
unlock:
551556
mutex_unlock(&dev->media_dev.graph_mutex);
557+
if (!ret && dev->is_thunderboot)
558+
schedule_work(&dev->cap_dev.fast_work);
552559
return ret;
553560
}
554561

@@ -781,9 +788,8 @@ static int rkisp_get_reserved_mem(struct rkisp_device *isp_dev)
781788
sizeof(struct rkisp_thunderboot_resmem_head),
782789
DMA_BIDIRECTIONAL);
783790
ret = dma_mapping_error(dev, isp_dev->resmem_addr);
784-
785-
dev_info(dev, "Allocated reserved memory, paddr: 0x%x\n",
786-
(u32)isp_dev->resmem_pa);
791+
isp_dev->is_thunderboot = true;
792+
dev_info(dev, "Allocated reserved memory, paddr: 0x%x\n", (u32)isp_dev->resmem_pa);
787793
return ret;
788794
}
789795

@@ -830,9 +836,11 @@ static int rkisp_plat_probe(struct platform_device *pdev)
830836
strscpy(isp_dev->media_dev.driver_name, isp_dev->name,
831837
sizeof(isp_dev->media_dev.driver_name));
832838

833-
ret = rkisp_get_reserved_mem(isp_dev);
834-
if (ret)
835-
return ret;
839+
if (isp_dev->hw_dev->is_thunderboot) {
840+
ret = rkisp_get_reserved_mem(isp_dev);
841+
if (ret)
842+
return ret;
843+
}
836844

837845
mutex_init(&isp_dev->apilock);
838846
mutex_init(&isp_dev->iqlock);

drivers/media/platform/rockchip/isp/dev.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,10 @@ struct rkisp_device {
212212
wait_queue_head_t sync_onoff;
213213
dma_addr_t resmem_addr;
214214
phys_addr_t resmem_pa;
215+
dma_addr_t resmem_addr_curr;
215216
size_t resmem_size;
217+
struct rkisp_thunderboot_resmem_head tb_head;
218+
bool is_thunderboot;
216219
int dev_id;
217220
unsigned int skip_frame;
218221
unsigned int irq_ends;

drivers/media/platform/rockchip/isp/isp_params.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ static void rkisp_params_vb2_buf_queue(struct vb2_buffer *vb)
147147
if (params_vdev->first_params) {
148148
first_param = vb2_plane_vaddr(vb, 0);
149149
params_vdev->ops->save_first_param(params_vdev, first_param);
150+
params_vdev->is_first_cfg = true;
150151
vbuf->sequence = cur_frame_id;
151152
vb2_buffer_done(&params_buf->vb.vb2_buf, VB2_BUF_STATE_DONE);
152153
params_vdev->first_params = false;
@@ -212,7 +213,6 @@ rkisp_params_vb2_start_streaming(struct vb2_queue *queue, unsigned int count)
212213
struct rkisp_isp_params_vdev *params_vdev = queue->drv_priv;
213214
unsigned long flags;
214215

215-
params_vdev->is_first_cfg = true;
216216
params_vdev->hdrtmo_en = false;
217217
params_vdev->afaemode_en = false;
218218
params_vdev->cur_buf = NULL;

drivers/media/platform/rockchip/isp/isp_params_v32.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4684,6 +4684,13 @@ rkisp_params_isr_v32(struct rkisp_isp_params_vdev *params_vdev,
46844684
struct rkisp_device *dev = params_vdev->dev;
46854685
u32 cur_frame_id;
46864686

4687+
if (params_vdev->is_first_cfg) {
4688+
rkisp_params_first_cfg(params_vdev, &dev->isp_sdev.in_fmt,
4689+
dev->isp_sdev.quantization);
4690+
rkisp_set_bits(dev, ISP3X_ISP_CTRL0, 0, CIF_ISP_CTRL_ISP_CFG_UPD, true);
4691+
return;
4692+
}
4693+
46874694
rkisp_dmarx_get_frame(dev, &cur_frame_id, NULL, NULL, true);
46884695
if (isp_mis & CIF_ISP_V_START) {
46894696
if (params_vdev->rdbk_times)

drivers/media/platform/rockchip/isp/isp_stats_v32.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -674,14 +674,13 @@ void rkisp_stats_first_ddr_config_v32(struct rkisp_isp_stats_vdev *stats_vdev)
674674
struct rkisp_device *dev = stats_vdev->dev;
675675
u32 size = stats_vdev->vdev_fmt.fmt.meta.buffersize;
676676

677-
if (!stats_vdev->streamon)
677+
if (dev->isp_sdev.in_fmt.fmt_type == FMT_YUV)
678678
return;
679679

680680
stats_vdev->stats_buf[0].is_need_vaddr = true;
681681
stats_vdev->stats_buf[0].size = sizeof(struct rkisp32_isp_stat_buffer);
682682
if (rkisp_alloc_buffer(dev, &stats_vdev->stats_buf[0]))
683-
v4l2_warn(&dev->v4l2_dev,
684-
"stats alloc buf fail\n");
683+
v4l2_warn(&dev->v4l2_dev, "stats alloc buf fail\n");
685684
rkisp_stats_update_buf(stats_vdev);
686685
rkisp_write(dev, ISP3X_MI_DBR_WR_SIZE, size, false);
687686
rkisp_set_bits(dev, ISP3X_SWS_CFG, 0, ISP3X_3A_DDR_WRITE_EN, false);

0 commit comments

Comments
 (0)