forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 9999e48639b3cecb08ffb37358bcba3b48161b29
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
....@@ -157,6 +185,28 @@
157185 spin_lock_irqsave(&params_vdev->config_lock, flags);
158186 list_add_tail(&params_buf->queue, &params_vdev->params);
159187 spin_unlock_irqrestore(&params_vdev->config_lock, flags);
188
+
189
+ if (params_vdev->dev->is_first_double) {
190
+ struct isp32_isp_params_cfg *params = params_buf->vaddr[0];
191
+ struct rkisp_buffer *buf;
192
+
193
+ if (!(params->module_cfg_update & ISP32_MODULE_RTT_FST))
194
+ return;
195
+ spin_lock_irqsave(&params_vdev->config_lock, flags);
196
+ while (!list_empty(&params_vdev->params)) {
197
+ buf = list_first_entry(&params_vdev->params,
198
+ struct rkisp_buffer, queue);
199
+ if (buf == params_buf)
200
+ break;
201
+ list_del(&buf->queue);
202
+ vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_DONE);
203
+ }
204
+ spin_unlock_irqrestore(&params_vdev->config_lock, flags);
205
+ dev_info(params_vdev->dev->dev,
206
+ "first params:%d for rtt resume\n", params->frame_id);
207
+ params_vdev->dev->is_first_double = false;
208
+ rkisp_trigger_read_back(params_vdev->dev, false, false, false);
209
+ }
160210 }
161211
162212 static void rkisp_params_vb2_stop_streaming(struct vb2_queue *vq)
....@@ -165,39 +215,28 @@
165215 struct rkisp_device *dev = params_vdev->dev;
166216 struct rkisp_buffer *buf;
167217 unsigned long flags;
168
- int i;
169218
170219 /* stop params input firstly */
171220 spin_lock_irqsave(&params_vdev->config_lock, flags);
172221 params_vdev->streamon = false;
173222 wake_up(&dev->sync_onoff);
174
- spin_unlock_irqrestore(&params_vdev->config_lock, flags);
175
-
176
- for (i = 0; i < RKISP_ISP_PARAMS_REQ_BUFS_MAX; i++) {
177
- spin_lock_irqsave(&params_vdev->config_lock, flags);
178
- if (!list_empty(&params_vdev->params)) {
179
- buf = list_first_entry(&params_vdev->params,
180
- struct rkisp_buffer, queue);
181
- list_del(&buf->queue);
182
- spin_unlock_irqrestore(&params_vdev->config_lock,
183
- flags);
184
- } else {
185
- spin_unlock_irqrestore(&params_vdev->config_lock,
186
- flags);
187
- break;
188
- }
189
-
190
- if (buf)
191
- vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
192
- buf = NULL;
223
+ while (!list_empty(&params_vdev->params)) {
224
+ buf = list_first_entry(&params_vdev->params,
225
+ struct rkisp_buffer, queue);
226
+ list_del(&buf->queue);
227
+ vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
193228 }
194
-
195229 if (params_vdev->cur_buf) {
196230 buf = params_vdev->cur_buf;
197231 vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
198232 params_vdev->cur_buf = NULL;
199233 }
234
+ spin_unlock_irqrestore(&params_vdev->config_lock, flags);
200235
236
+ if (dev->is_pre_on) {
237
+ params_vdev->first_cfg_params = true;
238
+ return;
239
+ }
201240 rkisp_params_disable_isp(params_vdev);
202241 /* clean module params */
203242 params_vdev->ops->clear_first_param(params_vdev);
....@@ -210,8 +249,8 @@
210249 struct rkisp_isp_params_vdev *params_vdev = queue->drv_priv;
211250 unsigned long flags;
212251
213
- params_vdev->is_first_cfg = true;
214252 params_vdev->hdrtmo_en = false;
253
+ params_vdev->afaemode_en = false;
215254 params_vdev->cur_buf = NULL;
216255 spin_lock_irqsave(&params_vdev->config_lock, flags);
217256 params_vdev->streamon = true;
....@@ -235,9 +274,12 @@
235274 struct rkisp_isp_params_vdev *params = video_drvdata(filp);
236275 int ret;
237276
277
+ if (!params->dev->is_probe_end)
278
+ return -EINVAL;
279
+
238280 ret = v4l2_fh_open(filp);
239281 if (!ret) {
240
- ret = v4l2_pipeline_pm_use(&params->vnode.vdev.entity, 1);
282
+ ret = v4l2_pipeline_pm_get(&params->vnode.vdev.entity);
241283 if (ret < 0)
242284 vb2_fop_release(filp);
243285 }
....@@ -248,26 +290,29 @@
248290 static int rkisp_params_fop_release(struct file *file)
249291 {
250292 struct rkisp_isp_params_vdev *params = video_drvdata(file);
251
- struct video_device *vdev = video_devdata(file);
252293 int ret;
253294
254
- if (file->private_data == vdev->queue->owner && params->ops->fop_release)
255
- params->ops->fop_release(params);
256
-
257295 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
- }
296
+ if (!ret)
297
+ v4l2_pipeline_pm_put(&params->vnode.vdev.entity);
264298 return ret;
299
+}
300
+
301
+static __poll_t rkisp_params_fop_poll(struct file *file, poll_table *wait)
302
+{
303
+ struct video_device *vdev = video_devdata(file);
304
+
305
+ /* buf done or subscribe event */
306
+ if (vdev->queue->owner == file->private_data)
307
+ return vb2_fop_poll(file, wait);
308
+ else
309
+ return v4l2_ctrl_poll(file, wait);
265310 }
266311
267312 struct v4l2_file_operations rkisp_params_fops = {
268313 .mmap = vb2_fop_mmap,
269314 .unlocked_ioctl = video_ioctl2,
270
- .poll = vb2_fop_poll,
315
+ .poll = rkisp_params_fop_poll,
271316 .open = rkisp_params_fh_open,
272317 .release = rkisp_params_fop_release
273318 };
....@@ -291,17 +336,25 @@
291336
292337 static int rkisp_init_params_vdev(struct rkisp_isp_params_vdev *params_vdev)
293338 {
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);
339
+ int ret;
298340
299341 if (params_vdev->dev->isp_ver <= ISP_V13)
300
- return rkisp_init_params_vdev_v1x(params_vdev);
342
+ ret = rkisp_init_params_vdev_v1x(params_vdev);
301343 else if (params_vdev->dev->isp_ver == ISP_V21)
302
- return rkisp_init_params_vdev_v21(params_vdev);
344
+ ret = rkisp_init_params_vdev_v21(params_vdev);
345
+ else if (params_vdev->dev->isp_ver == ISP_V20)
346
+ ret = rkisp_init_params_vdev_v2x(params_vdev);
347
+ else if (params_vdev->dev->isp_ver == ISP_V30)
348
+ ret = rkisp_init_params_vdev_v3x(params_vdev);
303349 else
304
- return rkisp_init_params_vdev_v2x(params_vdev);
350
+ ret = rkisp_init_params_vdev_v32(params_vdev);
351
+
352
+ params_vdev->vdev_fmt.fmt.meta.dataformat =
353
+ V4L2_META_FMT_RK_ISP1_PARAMS;
354
+ if (params_vdev->ops && params_vdev->ops->get_param_size)
355
+ params_vdev->ops->get_param_size(params_vdev,
356
+ &params_vdev->vdev_fmt.fmt.meta.buffersize);
357
+ return ret;
305358 }
306359
307360 static void rkisp_uninit_params_vdev(struct rkisp_isp_params_vdev *params_vdev)
....@@ -310,8 +363,12 @@
310363 rkisp_uninit_params_vdev_v1x(params_vdev);
311364 else if (params_vdev->dev->isp_ver == ISP_V21)
312365 rkisp_uninit_params_vdev_v21(params_vdev);
313
- else
366
+ else if (params_vdev->dev->isp_ver == ISP_V20)
314367 rkisp_uninit_params_vdev_v2x(params_vdev);
368
+ else if (params_vdev->dev->isp_ver == ISP_V30)
369
+ rkisp_uninit_params_vdev_v3x(params_vdev);
370
+ else
371
+ rkisp_uninit_params_vdev_v32(params_vdev);
315372 }
316373
317374 void rkisp_params_cfg(struct rkisp_isp_params_vdev *params_vdev, u32 frame_id)
....@@ -320,12 +377,16 @@
320377 params_vdev->ops->param_cfg(params_vdev, frame_id, RKISP_PARAMS_IMD);
321378 }
322379
323
-void rkisp_params_cfgsram(struct rkisp_isp_params_vdev *params_vdev)
380
+void rkisp_params_cfgsram(struct rkisp_isp_params_vdev *params_vdev, bool is_check)
324381 {
325
- /* multi device to switch sram config */
326
- if (params_vdev->dev->hw_dev->is_single)
327
- return;
382
+ if (is_check) {
383
+ if (params_vdev->dev->procfs.mode & RKISP_PROCFS_FIL_SW)
384
+ return;
328385
386
+ /* multi device to switch sram config */
387
+ if (params_vdev->dev->hw_dev->is_single)
388
+ return;
389
+ }
329390 if (params_vdev->ops->param_cfgsram)
330391 params_vdev->ops->param_cfgsram(params_vdev);
331392 }
....@@ -341,6 +402,8 @@
341402 struct ispsd_in_fmt *in_fmt,
342403 enum v4l2_quantization quantization)
343404 {
405
+ struct rkisp_device *dev = params_vdev->dev;
406
+
344407 if (!params_vdev->is_first_cfg)
345408 return;
346409 params_vdev->is_first_cfg = false;
....@@ -348,6 +411,19 @@
348411 params_vdev->raw_type = in_fmt->bayer_pat;
349412 params_vdev->in_mbus_code = in_fmt->mbus_code;
350413 params_vdev->ops->first_cfg(params_vdev);
414
+ /* update selfpath range if it output rgb format */
415
+ if (params_vdev->quantization != quantization) {
416
+ struct rkisp_stream *stream = &dev->cap_dev.stream[RKISP_STREAM_SP];
417
+ u32 mask = CIF_MI_SP_Y_FULL_YUV2RGB | CIF_MI_SP_CBCR_FULL_YUV2RGB;
418
+
419
+ quantization = params_vdev->quantization;
420
+ if (stream->streaming &&
421
+ stream->out_isp_fmt.fmt_type == FMT_RGB)
422
+ rkisp_unite_set_bits(dev, ISP3X_MI_WR_CTRL, mask,
423
+ quantization == V4L2_QUANTIZATION_FULL_RANGE ?
424
+ mask : 0, false);
425
+ dev->isp_sdev.quantization = quantization;
426
+ }
351427 }
352428
353429 /* Not called when the camera active, thus not isr protection. */
....@@ -364,17 +440,51 @@
364440 params_vdev->ops->get_meshbuf_inf(params_vdev, meshbuf);
365441 }
366442
367
-void rkisp_params_set_meshbuf_size(struct rkisp_isp_params_vdev *params_vdev,
368
- void *meshsize)
443
+int rkisp_params_set_meshbuf_size(struct rkisp_isp_params_vdev *params_vdev,
444
+ void *meshsize)
369445 {
370446 if (params_vdev->ops->set_meshbuf_size)
371
- params_vdev->ops->set_meshbuf_size(params_vdev, meshsize);
447
+ return params_vdev->ops->set_meshbuf_size(params_vdev,
448
+ meshsize);
449
+ else
450
+ return -EINVAL;
451
+}
452
+
453
+void rkisp_params_meshbuf_free(struct rkisp_isp_params_vdev *params_vdev, u64 id)
454
+{
455
+ /* isp working no to free buf */
456
+ if (params_vdev->ops->free_meshbuf &&
457
+ !(params_vdev->dev->isp_state & ISP_START))
458
+ params_vdev->ops->free_meshbuf(params_vdev, id);
372459 }
373460
374461 void rkisp_params_stream_stop(struct rkisp_isp_params_vdev *params_vdev)
375462 {
463
+ /* isp stop to free buf */
376464 if (params_vdev->ops->stream_stop)
377465 params_vdev->ops->stream_stop(params_vdev);
466
+ if (params_vdev->ops->fop_release)
467
+ params_vdev->ops->fop_release(params_vdev);
468
+ params_vdev->first_cfg_params = false;
469
+}
470
+
471
+bool rkisp_params_check_bigmode(struct rkisp_isp_params_vdev *params_vdev)
472
+{
473
+ if (params_vdev->ops->check_bigmode)
474
+ return params_vdev->ops->check_bigmode(params_vdev);
475
+
476
+ return 0;
477
+}
478
+
479
+int rkisp_params_info2ddr_cfg(struct rkisp_isp_params_vdev *params_vdev,
480
+ void *arg)
481
+{
482
+ int ret = -EINVAL;
483
+
484
+ if (params_vdev->ops->info2ddr_cfg)
485
+ ret = params_vdev->ops->info2ddr_cfg(params_vdev, arg);
486
+
487
+ return ret;
378488 }
379489
380490 int rkisp_register_params_vdev(struct rkisp_isp_params_vdev *params_vdev,
....@@ -414,7 +524,7 @@
414524 ret = media_entity_pads_init(&vdev->entity, 1, &node->pad);
415525 if (ret < 0)
416526 goto err_release_queue;
417
- ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
527
+ ret = video_register_device(vdev, VFL_TYPE_VIDEO, -1);
418528 if (ret < 0) {
419529 dev_err(&vdev->dev,
420530 "could not register Video for Linux device\n");