| .. | .. |
|---|
| 12 | 12 | #include "isp_params_v1x.h" |
|---|
| 13 | 13 | #include "isp_params_v2x.h" |
|---|
| 14 | 14 | #include "isp_params_v21.h" |
|---|
| 15 | +#include "isp_params_v3x.h" |
|---|
| 16 | +#include "isp_params_v32.h" |
|---|
| 17 | +#include "regs.h" |
|---|
| 15 | 18 | |
|---|
| 16 | 19 | #define PARAMS_NAME DRIVER_NAME "-input-params" |
|---|
| 17 | 20 | #define RKISP_ISP_PARAMS_REQ_BUFS_MIN 2 |
|---|
| .. | .. |
|---|
| 126 | 129 | params_vdev->ops->get_param_size(params_vdev, sizes); |
|---|
| 127 | 130 | |
|---|
| 128 | 131 | INIT_LIST_HEAD(¶ms_vdev->params); |
|---|
| 132 | + |
|---|
| 133 | + if (params_vdev->first_cfg_params) { |
|---|
| 134 | + params_vdev->first_cfg_params = false; |
|---|
| 135 | + return 0; |
|---|
| 136 | + } |
|---|
| 137 | + |
|---|
| 129 | 138 | params_vdev->first_params = true; |
|---|
| 130 | 139 | |
|---|
| 131 | 140 | return 0; |
|---|
| .. | .. |
|---|
| 137 | 146 | struct rkisp_buffer *params_buf = to_rkisp_buffer(vbuf); |
|---|
| 138 | 147 | struct vb2_queue *vq = vb->vb2_queue; |
|---|
| 139 | 148 | struct rkisp_isp_params_vdev *params_vdev = vq->drv_priv; |
|---|
| 149 | + struct rkisp_device *dev = params_vdev->dev; |
|---|
| 140 | 150 | void *first_param; |
|---|
| 141 | 151 | unsigned long flags; |
|---|
| 142 | | - |
|---|
| 143 | 152 | unsigned int cur_frame_id = -1; |
|---|
| 144 | | - cur_frame_id = atomic_read(¶ms_vdev->dev->isp_sdev.frm_sync_seq) - 1; |
|---|
| 153 | + |
|---|
| 154 | + cur_frame_id = atomic_read(&dev->isp_sdev.frm_sync_seq) - 1; |
|---|
| 145 | 155 | if (params_vdev->first_params) { |
|---|
| 146 | 156 | first_param = vb2_plane_vaddr(vb, 0); |
|---|
| 147 | 157 | params_vdev->ops->save_first_param(params_vdev, first_param); |
|---|
| 158 | + params_vdev->is_first_cfg = true; |
|---|
| 148 | 159 | vbuf->sequence = cur_frame_id; |
|---|
| 149 | 160 | vb2_buffer_done(¶ms_buf->vb.vb2_buf, VB2_BUF_STATE_DONE); |
|---|
| 150 | 161 | params_vdev->first_params = false; |
|---|
| 151 | 162 | wake_up(¶ms_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(¶ms_buf->vb.vb2_buf, VB2_BUF_STATE_DONE); |
|---|
| 153 | 181 | return; |
|---|
| 154 | 182 | } |
|---|
| 155 | 183 | |
|---|
| .. | .. |
|---|
| 187 | 215 | break; |
|---|
| 188 | 216 | } |
|---|
| 189 | 217 | |
|---|
| 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); |
|---|
| 193 | 219 | } |
|---|
| 194 | 220 | |
|---|
| 195 | 221 | if (params_vdev->cur_buf) { |
|---|
| .. | .. |
|---|
| 198 | 224 | params_vdev->cur_buf = NULL; |
|---|
| 199 | 225 | } |
|---|
| 200 | 226 | |
|---|
| 227 | + if (dev->is_pre_on) { |
|---|
| 228 | + params_vdev->first_cfg_params = true; |
|---|
| 229 | + return; |
|---|
| 230 | + } |
|---|
| 201 | 231 | rkisp_params_disable_isp(params_vdev); |
|---|
| 202 | 232 | /* clean module params */ |
|---|
| 203 | 233 | params_vdev->ops->clear_first_param(params_vdev); |
|---|
| .. | .. |
|---|
| 210 | 240 | struct rkisp_isp_params_vdev *params_vdev = queue->drv_priv; |
|---|
| 211 | 241 | unsigned long flags; |
|---|
| 212 | 242 | |
|---|
| 213 | | - params_vdev->is_first_cfg = true; |
|---|
| 214 | 243 | params_vdev->hdrtmo_en = false; |
|---|
| 244 | + params_vdev->afaemode_en = false; |
|---|
| 215 | 245 | params_vdev->cur_buf = NULL; |
|---|
| 216 | 246 | spin_lock_irqsave(¶ms_vdev->config_lock, flags); |
|---|
| 217 | 247 | params_vdev->streamon = true; |
|---|
| .. | .. |
|---|
| 235 | 265 | struct rkisp_isp_params_vdev *params = video_drvdata(filp); |
|---|
| 236 | 266 | int ret; |
|---|
| 237 | 267 | |
|---|
| 268 | + if (!params->dev->is_probe_end) |
|---|
| 269 | + return -EINVAL; |
|---|
| 270 | + |
|---|
| 238 | 271 | ret = v4l2_fh_open(filp); |
|---|
| 239 | 272 | if (!ret) { |
|---|
| 240 | | - ret = v4l2_pipeline_pm_use(¶ms->vnode.vdev.entity, 1); |
|---|
| 273 | + ret = v4l2_pipeline_pm_get(¶ms->vnode.vdev.entity); |
|---|
| 241 | 274 | if (ret < 0) |
|---|
| 242 | 275 | vb2_fop_release(filp); |
|---|
| 243 | 276 | } |
|---|
| .. | .. |
|---|
| 248 | 281 | static int rkisp_params_fop_release(struct file *file) |
|---|
| 249 | 282 | { |
|---|
| 250 | 283 | struct rkisp_isp_params_vdev *params = video_drvdata(file); |
|---|
| 251 | | - struct video_device *vdev = video_devdata(file); |
|---|
| 252 | 284 | int ret; |
|---|
| 253 | 285 | |
|---|
| 254 | | - if (file->private_data == vdev->queue->owner && params->ops->fop_release) |
|---|
| 255 | | - params->ops->fop_release(params); |
|---|
| 256 | | - |
|---|
| 257 | 286 | ret = vb2_fop_release(file); |
|---|
| 258 | | - if (!ret) { |
|---|
| 259 | | - ret = v4l2_pipeline_pm_use(¶ms->vnode.vdev.entity, 0); |
|---|
| 260 | | - if (ret < 0) |
|---|
| 261 | | - v4l2_err(¶ms->dev->v4l2_dev, |
|---|
| 262 | | - "set pipeline power failed %d\n", ret); |
|---|
| 263 | | - } |
|---|
| 287 | + if (!ret) |
|---|
| 288 | + v4l2_pipeline_pm_put(¶ms->vnode.vdev.entity); |
|---|
| 264 | 289 | 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); |
|---|
| 265 | 301 | } |
|---|
| 266 | 302 | |
|---|
| 267 | 303 | struct v4l2_file_operations rkisp_params_fops = { |
|---|
| 268 | 304 | .mmap = vb2_fop_mmap, |
|---|
| 269 | 305 | .unlocked_ioctl = video_ioctl2, |
|---|
| 270 | | - .poll = vb2_fop_poll, |
|---|
| 306 | + .poll = rkisp_params_fop_poll, |
|---|
| 271 | 307 | .open = rkisp_params_fh_open, |
|---|
| 272 | 308 | .release = rkisp_params_fop_release |
|---|
| 273 | 309 | }; |
|---|
| .. | .. |
|---|
| 291 | 327 | |
|---|
| 292 | 328 | static int rkisp_init_params_vdev(struct rkisp_isp_params_vdev *params_vdev) |
|---|
| 293 | 329 | { |
|---|
| 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; |
|---|
| 298 | 331 | |
|---|
| 299 | 332 | 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); |
|---|
| 301 | 334 | 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); |
|---|
| 303 | 340 | 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 | + ¶ms_vdev->vdev_fmt.fmt.meta.buffersize); |
|---|
| 348 | + return ret; |
|---|
| 305 | 349 | } |
|---|
| 306 | 350 | |
|---|
| 307 | 351 | static void rkisp_uninit_params_vdev(struct rkisp_isp_params_vdev *params_vdev) |
|---|
| .. | .. |
|---|
| 310 | 354 | rkisp_uninit_params_vdev_v1x(params_vdev); |
|---|
| 311 | 355 | else if (params_vdev->dev->isp_ver == ISP_V21) |
|---|
| 312 | 356 | rkisp_uninit_params_vdev_v21(params_vdev); |
|---|
| 313 | | - else |
|---|
| 357 | + else if (params_vdev->dev->isp_ver == ISP_V20) |
|---|
| 314 | 358 | 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); |
|---|
| 315 | 363 | } |
|---|
| 316 | 364 | |
|---|
| 317 | 365 | void rkisp_params_cfg(struct rkisp_isp_params_vdev *params_vdev, u32 frame_id) |
|---|
| .. | .. |
|---|
| 322 | 370 | |
|---|
| 323 | 371 | void rkisp_params_cfgsram(struct rkisp_isp_params_vdev *params_vdev) |
|---|
| 324 | 372 | { |
|---|
| 373 | + if (params_vdev->dev->procfs.mode & RKISP_PROCFS_FIL_SW) |
|---|
| 374 | + return; |
|---|
| 375 | + |
|---|
| 325 | 376 | /* multi device to switch sram config */ |
|---|
| 326 | 377 | if (params_vdev->dev->hw_dev->is_single) |
|---|
| 327 | 378 | return; |
|---|
| .. | .. |
|---|
| 341 | 392 | struct ispsd_in_fmt *in_fmt, |
|---|
| 342 | 393 | enum v4l2_quantization quantization) |
|---|
| 343 | 394 | { |
|---|
| 395 | + struct rkisp_device *dev = params_vdev->dev; |
|---|
| 396 | + |
|---|
| 344 | 397 | if (!params_vdev->is_first_cfg) |
|---|
| 345 | 398 | return; |
|---|
| 346 | 399 | params_vdev->is_first_cfg = false; |
|---|
| .. | .. |
|---|
| 348 | 401 | params_vdev->raw_type = in_fmt->bayer_pat; |
|---|
| 349 | 402 | params_vdev->in_mbus_code = in_fmt->mbus_code; |
|---|
| 350 | 403 | 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 | + } |
|---|
| 351 | 417 | } |
|---|
| 352 | 418 | |
|---|
| 353 | 419 | /* Not called when the camera active, thus not isr protection. */ |
|---|
| .. | .. |
|---|
| 364 | 430 | params_vdev->ops->get_meshbuf_inf(params_vdev, meshbuf); |
|---|
| 365 | 431 | } |
|---|
| 366 | 432 | |
|---|
| 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) |
|---|
| 369 | 435 | { |
|---|
| 370 | 436 | 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); |
|---|
| 372 | 449 | } |
|---|
| 373 | 450 | |
|---|
| 374 | 451 | void rkisp_params_stream_stop(struct rkisp_isp_params_vdev *params_vdev) |
|---|
| 375 | 452 | { |
|---|
| 453 | + /* isp stop to free buf */ |
|---|
| 376 | 454 | if (params_vdev->ops->stream_stop) |
|---|
| 377 | 455 | 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; |
|---|
| 378 | 477 | } |
|---|
| 379 | 478 | |
|---|
| 380 | 479 | int rkisp_register_params_vdev(struct rkisp_isp_params_vdev *params_vdev, |
|---|
| .. | .. |
|---|
| 414 | 513 | ret = media_entity_pads_init(&vdev->entity, 1, &node->pad); |
|---|
| 415 | 514 | if (ret < 0) |
|---|
| 416 | 515 | goto err_release_queue; |
|---|
| 417 | | - ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1); |
|---|
| 516 | + ret = video_register_device(vdev, VFL_TYPE_VIDEO, -1); |
|---|
| 418 | 517 | if (ret < 0) { |
|---|
| 419 | 518 | dev_err(&vdev->dev, |
|---|
| 420 | 519 | "could not register Video for Linux device\n"); |
|---|