forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/drivers/media/platform/rockchip/isp/isp_params.c
....@@ -12,6 +12,9 @@
1212 #include "isp_params_v1x.h"
1313 #include "isp_params_v2x.h"
1414 #include "isp_params_v21.h"
15
+#include "isp_params_v3x.h"
16
+#include "isp_params_v32.h"
17
+#include "regs.h"
1518
1619 #define PARAMS_NAME DRIVER_NAME "-input-params"
1720 #define RKISP_ISP_PARAMS_REQ_BUFS_MIN 2
....@@ -126,6 +129,12 @@
126129 params_vdev->ops->get_param_size(params_vdev, sizes);
127130
128131 INIT_LIST_HEAD(&params_vdev->params);
132
+
133
+ if (params_vdev->first_cfg_params) {
134
+ params_vdev->first_cfg_params = false;
135
+ return 0;
136
+ }
137
+
129138 params_vdev->first_params = true;
130139
131140 return 0;
....@@ -139,17 +148,29 @@
139148 struct rkisp_isp_params_vdev *params_vdev = vq->drv_priv;
140149 void *first_param;
141150 unsigned long flags;
142
-
143151 unsigned int cur_frame_id = -1;
152
+
144153 cur_frame_id = atomic_read(&params_vdev->dev->isp_sdev.frm_sync_seq) - 1;
145154 if (params_vdev->first_params) {
146155 first_param = vb2_plane_vaddr(vb, 0);
147156 params_vdev->ops->save_first_param(params_vdev, first_param);
157
+ params_vdev->is_first_cfg = true;
148158 vbuf->sequence = cur_frame_id;
149159 vb2_buffer_done(&params_buf->vb.vb2_buf, VB2_BUF_STATE_DONE);
150160 params_vdev->first_params = false;
151161 wake_up(&params_vdev->dev->sync_onoff);
162
+ if (params_vdev->dev->is_first_double) {
163
+ dev_info(params_vdev->dev->dev, "first params for fast\n");
164
+ params_vdev->dev->is_first_double = false;
165
+ rkisp_trigger_read_back(params_vdev->dev, false, false, false);
166
+ }
152167 dev_info(params_vdev->dev->dev, "first params buf queue\n");
168
+ return;
169
+ }
170
+
171
+ if (params_vdev->dev->procfs.mode &
172
+ (RKISP_PROCFS_FIL_AIQ | RKISP_PROCFS_FIL_SW)) {
173
+ vb2_buffer_done(&params_buf->vb.vb2_buf, VB2_BUF_STATE_DONE);
153174 return;
154175 }
155176
....@@ -198,6 +219,10 @@
198219 params_vdev->cur_buf = NULL;
199220 }
200221
222
+ if (dev->is_pre_on) {
223
+ params_vdev->first_cfg_params = true;
224
+ return;
225
+ }
201226 rkisp_params_disable_isp(params_vdev);
202227 /* clean module params */
203228 params_vdev->ops->clear_first_param(params_vdev);
....@@ -210,8 +235,8 @@
210235 struct rkisp_isp_params_vdev *params_vdev = queue->drv_priv;
211236 unsigned long flags;
212237
213
- params_vdev->is_first_cfg = true;
214238 params_vdev->hdrtmo_en = false;
239
+ params_vdev->afaemode_en = false;
215240 params_vdev->cur_buf = NULL;
216241 spin_lock_irqsave(&params_vdev->config_lock, flags);
217242 params_vdev->streamon = true;
....@@ -235,9 +260,12 @@
235260 struct rkisp_isp_params_vdev *params = video_drvdata(filp);
236261 int ret;
237262
263
+ if (!params->dev->is_probe_end)
264
+ return -EINVAL;
265
+
238266 ret = v4l2_fh_open(filp);
239267 if (!ret) {
240
- ret = v4l2_pipeline_pm_use(&params->vnode.vdev.entity, 1);
268
+ ret = v4l2_pipeline_pm_get(&params->vnode.vdev.entity);
241269 if (ret < 0)
242270 vb2_fop_release(filp);
243271 }
....@@ -248,19 +276,11 @@
248276 static int rkisp_params_fop_release(struct file *file)
249277 {
250278 struct rkisp_isp_params_vdev *params = video_drvdata(file);
251
- struct video_device *vdev = video_devdata(file);
252279 int ret;
253280
254
- if (file->private_data == vdev->queue->owner && params->ops->fop_release)
255
- params->ops->fop_release(params);
256
-
257281 ret = vb2_fop_release(file);
258
- if (!ret) {
259
- ret = v4l2_pipeline_pm_use(&params->vnode.vdev.entity, 0);
260
- if (ret < 0)
261
- v4l2_err(&params->dev->v4l2_dev,
262
- "set pipeline power failed %d\n", ret);
263
- }
282
+ if (!ret)
283
+ v4l2_pipeline_pm_put(&params->vnode.vdev.entity);
264284 return ret;
265285 }
266286
....@@ -291,17 +311,25 @@
291311
292312 static int rkisp_init_params_vdev(struct rkisp_isp_params_vdev *params_vdev)
293313 {
294
- params_vdev->vdev_fmt.fmt.meta.dataformat =
295
- V4L2_META_FMT_RK_ISP1_PARAMS;
296
- params_vdev->vdev_fmt.fmt.meta.buffersize =
297
- sizeof(struct rkisp1_isp_params_cfg);
314
+ int ret;
298315
299316 if (params_vdev->dev->isp_ver <= ISP_V13)
300
- return rkisp_init_params_vdev_v1x(params_vdev);
317
+ ret = rkisp_init_params_vdev_v1x(params_vdev);
301318 else if (params_vdev->dev->isp_ver == ISP_V21)
302
- return rkisp_init_params_vdev_v21(params_vdev);
319
+ ret = rkisp_init_params_vdev_v21(params_vdev);
320
+ else if (params_vdev->dev->isp_ver == ISP_V20)
321
+ ret = rkisp_init_params_vdev_v2x(params_vdev);
322
+ else if (params_vdev->dev->isp_ver == ISP_V30)
323
+ ret = rkisp_init_params_vdev_v3x(params_vdev);
303324 else
304
- return rkisp_init_params_vdev_v2x(params_vdev);
325
+ ret = rkisp_init_params_vdev_v32(params_vdev);
326
+
327
+ params_vdev->vdev_fmt.fmt.meta.dataformat =
328
+ V4L2_META_FMT_RK_ISP1_PARAMS;
329
+ if (params_vdev->ops && params_vdev->ops->get_param_size)
330
+ params_vdev->ops->get_param_size(params_vdev,
331
+ &params_vdev->vdev_fmt.fmt.meta.buffersize);
332
+ return ret;
305333 }
306334
307335 static void rkisp_uninit_params_vdev(struct rkisp_isp_params_vdev *params_vdev)
....@@ -310,8 +338,12 @@
310338 rkisp_uninit_params_vdev_v1x(params_vdev);
311339 else if (params_vdev->dev->isp_ver == ISP_V21)
312340 rkisp_uninit_params_vdev_v21(params_vdev);
313
- else
341
+ else if (params_vdev->dev->isp_ver == ISP_V20)
314342 rkisp_uninit_params_vdev_v2x(params_vdev);
343
+ else if (params_vdev->dev->isp_ver == ISP_V30)
344
+ rkisp_uninit_params_vdev_v3x(params_vdev);
345
+ else
346
+ rkisp_uninit_params_vdev_v32(params_vdev);
315347 }
316348
317349 void rkisp_params_cfg(struct rkisp_isp_params_vdev *params_vdev, u32 frame_id)
....@@ -322,6 +354,9 @@
322354
323355 void rkisp_params_cfgsram(struct rkisp_isp_params_vdev *params_vdev)
324356 {
357
+ if (params_vdev->dev->procfs.mode & RKISP_PROCFS_FIL_SW)
358
+ return;
359
+
325360 /* multi device to switch sram config */
326361 if (params_vdev->dev->hw_dev->is_single)
327362 return;
....@@ -341,6 +376,8 @@
341376 struct ispsd_in_fmt *in_fmt,
342377 enum v4l2_quantization quantization)
343378 {
379
+ struct rkisp_device *dev = params_vdev->dev;
380
+
344381 if (!params_vdev->is_first_cfg)
345382 return;
346383 params_vdev->is_first_cfg = false;
....@@ -348,6 +385,20 @@
348385 params_vdev->raw_type = in_fmt->bayer_pat;
349386 params_vdev->in_mbus_code = in_fmt->mbus_code;
350387 params_vdev->ops->first_cfg(params_vdev);
388
+ /* update selfpath range if it output rgb format */
389
+ if (params_vdev->quantization != quantization) {
390
+ struct rkisp_stream *stream = &dev->cap_dev.stream[RKISP_STREAM_SP];
391
+ u32 mask = CIF_MI_SP_Y_FULL_YUV2RGB | CIF_MI_SP_CBCR_FULL_YUV2RGB;
392
+
393
+ quantization = params_vdev->quantization;
394
+ if (stream->streaming &&
395
+ stream->out_isp_fmt.fmt_type == FMT_RGB)
396
+ rkisp_unite_set_bits(dev, ISP3X_MI_WR_CTRL, mask,
397
+ quantization == V4L2_QUANTIZATION_FULL_RANGE ?
398
+ mask : 0,
399
+ false, dev->hw_dev->is_unite);
400
+ dev->isp_sdev.quantization = quantization;
401
+ }
351402 }
352403
353404 /* Not called when the camera active, thus not isr protection. */
....@@ -364,17 +415,50 @@
364415 params_vdev->ops->get_meshbuf_inf(params_vdev, meshbuf);
365416 }
366417
367
-void rkisp_params_set_meshbuf_size(struct rkisp_isp_params_vdev *params_vdev,
368
- void *meshsize)
418
+int rkisp_params_set_meshbuf_size(struct rkisp_isp_params_vdev *params_vdev,
419
+ void *meshsize)
369420 {
370421 if (params_vdev->ops->set_meshbuf_size)
371
- params_vdev->ops->set_meshbuf_size(params_vdev, meshsize);
422
+ return params_vdev->ops->set_meshbuf_size(params_vdev,
423
+ meshsize);
424
+ else
425
+ return -EINVAL;
426
+}
427
+
428
+void rkisp_params_meshbuf_free(struct rkisp_isp_params_vdev *params_vdev, u64 id)
429
+{
430
+ /* isp working no to free buf */
431
+ if (params_vdev->ops->free_meshbuf &&
432
+ !(params_vdev->dev->isp_state & ISP_START))
433
+ params_vdev->ops->free_meshbuf(params_vdev, id);
372434 }
373435
374436 void rkisp_params_stream_stop(struct rkisp_isp_params_vdev *params_vdev)
375437 {
438
+ /* isp stop to free buf */
376439 if (params_vdev->ops->stream_stop)
377440 params_vdev->ops->stream_stop(params_vdev);
441
+ if (params_vdev->ops->fop_release)
442
+ params_vdev->ops->fop_release(params_vdev);
443
+}
444
+
445
+bool rkisp_params_check_bigmode(struct rkisp_isp_params_vdev *params_vdev)
446
+{
447
+ if (params_vdev->ops->check_bigmode)
448
+ return params_vdev->ops->check_bigmode(params_vdev);
449
+
450
+ return 0;
451
+}
452
+
453
+int rkisp_params_info2ddr_cfg(struct rkisp_isp_params_vdev *params_vdev,
454
+ void *arg)
455
+{
456
+ int ret = -EINVAL;
457
+
458
+ if (params_vdev->ops->info2ddr_cfg)
459
+ ret = params_vdev->ops->info2ddr_cfg(params_vdev, arg);
460
+
461
+ return ret;
378462 }
379463
380464 int rkisp_register_params_vdev(struct rkisp_isp_params_vdev *params_vdev,
....@@ -414,7 +498,7 @@
414498 ret = media_entity_pads_init(&vdev->entity, 1, &node->pad);
415499 if (ret < 0)
416500 goto err_release_queue;
417
- ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
501
+ ret = video_register_device(vdev, VFL_TYPE_VIDEO, -1);
418502 if (ret < 0) {
419503 dev_err(&vdev->dev,
420504 "could not register Video for Linux device\n");