forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 072de836f53be56a70cecf70b43ae43b7ce17376
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;
....@@ -137,19 +146,38 @@
137146 struct rkisp_buffer *params_buf = to_rkisp_buffer(vbuf);
138147 struct vb2_queue *vq = vb->vb2_queue;
139148 struct rkisp_isp_params_vdev *params_vdev = vq->drv_priv;
149
+ struct rkisp_device *dev = params_vdev->dev;
140150 void *first_param;
141151 unsigned long flags;
142
-
143152 unsigned int cur_frame_id = -1;
144
- cur_frame_id = atomic_read(&params_vdev->dev->isp_sdev.frm_sync_seq) - 1;
153
+
154
+ cur_frame_id = atomic_read(&dev->isp_sdev.frm_sync_seq) - 1;
145155 if (params_vdev->first_params) {
146156 first_param = vb2_plane_vaddr(vb, 0);
147157 params_vdev->ops->save_first_param(params_vdev, first_param);
158
+ params_vdev->is_first_cfg = true;
148159 vbuf->sequence = cur_frame_id;
149160 vb2_buffer_done(&params_buf->vb.vb2_buf, VB2_BUF_STATE_DONE);
150161 params_vdev->first_params = false;
151162 wake_up(&params_vdev->dev->sync_onoff);
152
- dev_info(params_vdev->dev->dev, "first params buf queue\n");
163
+ if (dev->is_first_double) {
164
+ dev_info(dev->dev, "first params for fast\n");
165
+ dev->is_first_double = false;
166
+ dev->sw_rd_cnt = 0;
167
+ if (dev->hw_dev->unite == ISP_UNITE_ONE) {
168
+ dev->unite_index = ISP_UNITE_LEFT;
169
+ dev->sw_rd_cnt += dev->hw_dev->is_multi_overflow ? 3 : 1;
170
+ }
171
+ params_vdev->rdbk_times = dev->sw_rd_cnt + 1;
172
+ rkisp_trigger_read_back(dev, false, false, false);
173
+ }
174
+ dev_info(dev->dev, "first params buf queue\n");
175
+ return;
176
+ }
177
+
178
+ if (dev->procfs.mode &
179
+ (RKISP_PROCFS_FIL_AIQ | RKISP_PROCFS_FIL_SW)) {
180
+ vb2_buffer_done(&params_buf->vb.vb2_buf, VB2_BUF_STATE_DONE);
153181 return;
154182 }
155183
....@@ -187,9 +215,7 @@
187215 break;
188216 }
189217
190
- if (buf)
191
- vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
192
- buf = NULL;
218
+ vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
193219 }
194220
195221 if (params_vdev->cur_buf) {
....@@ -198,6 +224,10 @@
198224 params_vdev->cur_buf = NULL;
199225 }
200226
227
+ if (dev->is_pre_on) {
228
+ params_vdev->first_cfg_params = true;
229
+ return;
230
+ }
201231 rkisp_params_disable_isp(params_vdev);
202232 /* clean module params */
203233 params_vdev->ops->clear_first_param(params_vdev);
....@@ -210,8 +240,8 @@
210240 struct rkisp_isp_params_vdev *params_vdev = queue->drv_priv;
211241 unsigned long flags;
212242
213
- params_vdev->is_first_cfg = true;
214243 params_vdev->hdrtmo_en = false;
244
+ params_vdev->afaemode_en = false;
215245 params_vdev->cur_buf = NULL;
216246 spin_lock_irqsave(&params_vdev->config_lock, flags);
217247 params_vdev->streamon = true;
....@@ -235,9 +265,12 @@
235265 struct rkisp_isp_params_vdev *params = video_drvdata(filp);
236266 int ret;
237267
268
+ if (!params->dev->is_probe_end)
269
+ return -EINVAL;
270
+
238271 ret = v4l2_fh_open(filp);
239272 if (!ret) {
240
- ret = v4l2_pipeline_pm_use(&params->vnode.vdev.entity, 1);
273
+ ret = v4l2_pipeline_pm_get(&params->vnode.vdev.entity);
241274 if (ret < 0)
242275 vb2_fop_release(filp);
243276 }
....@@ -248,26 +281,29 @@
248281 static int rkisp_params_fop_release(struct file *file)
249282 {
250283 struct rkisp_isp_params_vdev *params = video_drvdata(file);
251
- struct video_device *vdev = video_devdata(file);
252284 int ret;
253285
254
- if (file->private_data == vdev->queue->owner && params->ops->fop_release)
255
- params->ops->fop_release(params);
256
-
257286 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
- }
287
+ if (!ret)
288
+ v4l2_pipeline_pm_put(&params->vnode.vdev.entity);
264289 return ret;
290
+}
291
+
292
+static __poll_t rkisp_params_fop_poll(struct file *file, poll_table *wait)
293
+{
294
+ struct video_device *vdev = video_devdata(file);
295
+
296
+ /* buf done or subscribe event */
297
+ if (vdev->queue->owner == file->private_data)
298
+ return vb2_fop_poll(file, wait);
299
+ else
300
+ return v4l2_ctrl_poll(file, wait);
265301 }
266302
267303 struct v4l2_file_operations rkisp_params_fops = {
268304 .mmap = vb2_fop_mmap,
269305 .unlocked_ioctl = video_ioctl2,
270
- .poll = vb2_fop_poll,
306
+ .poll = rkisp_params_fop_poll,
271307 .open = rkisp_params_fh_open,
272308 .release = rkisp_params_fop_release
273309 };
....@@ -291,17 +327,25 @@
291327
292328 static int rkisp_init_params_vdev(struct rkisp_isp_params_vdev *params_vdev)
293329 {
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);
330
+ int ret;
298331
299332 if (params_vdev->dev->isp_ver <= ISP_V13)
300
- return rkisp_init_params_vdev_v1x(params_vdev);
333
+ ret = rkisp_init_params_vdev_v1x(params_vdev);
301334 else if (params_vdev->dev->isp_ver == ISP_V21)
302
- return rkisp_init_params_vdev_v21(params_vdev);
335
+ ret = rkisp_init_params_vdev_v21(params_vdev);
336
+ else if (params_vdev->dev->isp_ver == ISP_V20)
337
+ ret = rkisp_init_params_vdev_v2x(params_vdev);
338
+ else if (params_vdev->dev->isp_ver == ISP_V30)
339
+ ret = rkisp_init_params_vdev_v3x(params_vdev);
303340 else
304
- return rkisp_init_params_vdev_v2x(params_vdev);
341
+ ret = rkisp_init_params_vdev_v32(params_vdev);
342
+
343
+ params_vdev->vdev_fmt.fmt.meta.dataformat =
344
+ V4L2_META_FMT_RK_ISP1_PARAMS;
345
+ if (params_vdev->ops && params_vdev->ops->get_param_size)
346
+ params_vdev->ops->get_param_size(params_vdev,
347
+ &params_vdev->vdev_fmt.fmt.meta.buffersize);
348
+ return ret;
305349 }
306350
307351 static void rkisp_uninit_params_vdev(struct rkisp_isp_params_vdev *params_vdev)
....@@ -310,8 +354,12 @@
310354 rkisp_uninit_params_vdev_v1x(params_vdev);
311355 else if (params_vdev->dev->isp_ver == ISP_V21)
312356 rkisp_uninit_params_vdev_v21(params_vdev);
313
- else
357
+ else if (params_vdev->dev->isp_ver == ISP_V20)
314358 rkisp_uninit_params_vdev_v2x(params_vdev);
359
+ else if (params_vdev->dev->isp_ver == ISP_V30)
360
+ rkisp_uninit_params_vdev_v3x(params_vdev);
361
+ else
362
+ rkisp_uninit_params_vdev_v32(params_vdev);
315363 }
316364
317365 void rkisp_params_cfg(struct rkisp_isp_params_vdev *params_vdev, u32 frame_id)
....@@ -322,6 +370,9 @@
322370
323371 void rkisp_params_cfgsram(struct rkisp_isp_params_vdev *params_vdev)
324372 {
373
+ if (params_vdev->dev->procfs.mode & RKISP_PROCFS_FIL_SW)
374
+ return;
375
+
325376 /* multi device to switch sram config */
326377 if (params_vdev->dev->hw_dev->is_single)
327378 return;
....@@ -341,6 +392,8 @@
341392 struct ispsd_in_fmt *in_fmt,
342393 enum v4l2_quantization quantization)
343394 {
395
+ struct rkisp_device *dev = params_vdev->dev;
396
+
344397 if (!params_vdev->is_first_cfg)
345398 return;
346399 params_vdev->is_first_cfg = false;
....@@ -348,6 +401,19 @@
348401 params_vdev->raw_type = in_fmt->bayer_pat;
349402 params_vdev->in_mbus_code = in_fmt->mbus_code;
350403 params_vdev->ops->first_cfg(params_vdev);
404
+ /* update selfpath range if it output rgb format */
405
+ if (params_vdev->quantization != quantization) {
406
+ struct rkisp_stream *stream = &dev->cap_dev.stream[RKISP_STREAM_SP];
407
+ u32 mask = CIF_MI_SP_Y_FULL_YUV2RGB | CIF_MI_SP_CBCR_FULL_YUV2RGB;
408
+
409
+ quantization = params_vdev->quantization;
410
+ if (stream->streaming &&
411
+ stream->out_isp_fmt.fmt_type == FMT_RGB)
412
+ rkisp_unite_set_bits(dev, ISP3X_MI_WR_CTRL, mask,
413
+ quantization == V4L2_QUANTIZATION_FULL_RANGE ?
414
+ mask : 0, false);
415
+ dev->isp_sdev.quantization = quantization;
416
+ }
351417 }
352418
353419 /* Not called when the camera active, thus not isr protection. */
....@@ -364,17 +430,50 @@
364430 params_vdev->ops->get_meshbuf_inf(params_vdev, meshbuf);
365431 }
366432
367
-void rkisp_params_set_meshbuf_size(struct rkisp_isp_params_vdev *params_vdev,
368
- void *meshsize)
433
+int rkisp_params_set_meshbuf_size(struct rkisp_isp_params_vdev *params_vdev,
434
+ void *meshsize)
369435 {
370436 if (params_vdev->ops->set_meshbuf_size)
371
- params_vdev->ops->set_meshbuf_size(params_vdev, meshsize);
437
+ return params_vdev->ops->set_meshbuf_size(params_vdev,
438
+ meshsize);
439
+ else
440
+ return -EINVAL;
441
+}
442
+
443
+void rkisp_params_meshbuf_free(struct rkisp_isp_params_vdev *params_vdev, u64 id)
444
+{
445
+ /* isp working no to free buf */
446
+ if (params_vdev->ops->free_meshbuf &&
447
+ !(params_vdev->dev->isp_state & ISP_START))
448
+ params_vdev->ops->free_meshbuf(params_vdev, id);
372449 }
373450
374451 void rkisp_params_stream_stop(struct rkisp_isp_params_vdev *params_vdev)
375452 {
453
+ /* isp stop to free buf */
376454 if (params_vdev->ops->stream_stop)
377455 params_vdev->ops->stream_stop(params_vdev);
456
+ if (params_vdev->ops->fop_release)
457
+ params_vdev->ops->fop_release(params_vdev);
458
+}
459
+
460
+bool rkisp_params_check_bigmode(struct rkisp_isp_params_vdev *params_vdev)
461
+{
462
+ if (params_vdev->ops->check_bigmode)
463
+ return params_vdev->ops->check_bigmode(params_vdev);
464
+
465
+ return 0;
466
+}
467
+
468
+int rkisp_params_info2ddr_cfg(struct rkisp_isp_params_vdev *params_vdev,
469
+ void *arg)
470
+{
471
+ int ret = -EINVAL;
472
+
473
+ if (params_vdev->ops->info2ddr_cfg)
474
+ ret = params_vdev->ops->info2ddr_cfg(params_vdev, arg);
475
+
476
+ return ret;
378477 }
379478
380479 int rkisp_register_params_vdev(struct rkisp_isp_params_vdev *params_vdev,
....@@ -414,7 +513,7 @@
414513 ret = media_entity_pads_init(&vdev->entity, 1, &node->pad);
415514 if (ret < 0)
416515 goto err_release_queue;
417
- ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
516
+ ret = video_register_device(vdev, VFL_TYPE_VIDEO, -1);
418517 if (ret < 0) {
419518 dev_err(&vdev->dev,
420519 "could not register Video for Linux device\n");