1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * Copyright (c) 2012-2016, The Linux Foundation. All rights reserved. 4 * Copyright (C) 2017 Linaro Ltd. 5 */ 6 #include <linux/clk.h> 7 #include <linux/module.h> 8 #include <linux/mod_devicetable.h> 9 #include <linux/platform_device.h> 10 #include <linux/pm_runtime.h> 11 #include <linux/slab.h> 12 #include <media/v4l2-mem2mem.h> 13 #include <media/videobuf2-dma-contig.h> 14 #include <media/v4l2-ioctl.h> 15 #include <media/v4l2-event.h> 16 #include <media/v4l2-ctrls.h> 17 18 #include "hfi_venus_io.h" 19 #include "hfi_parser.h" 20 #include "core.h" 21 #include "helpers.h" 22 #include "venc.h" 23 #include "pm_helpers.h" 24 25 #define NUM_B_FRAMES_MAX 4 26 27 /* 28 * Three resons to keep MPLANE formats (despite that the number of planes 29 * currently is one): 30 * - the MPLANE formats allow only one plane to be used 31 * - the downstream driver use MPLANE formats too 32 * - future firmware versions could add support for >1 planes 33 */ 34 static const struct venus_format venc_formats[] = { 35 { 36 .pixfmt = V4L2_PIX_FMT_NV12, 37 .num_planes = 1, 38 .type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, 39 }, { 40 .pixfmt = V4L2_PIX_FMT_MPEG4, 41 .num_planes = 1, 42 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, 43 }, { 44 .pixfmt = V4L2_PIX_FMT_H263, 45 .num_planes = 1, 46 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, 47 }, { 48 .pixfmt = V4L2_PIX_FMT_H264, 49 .num_planes = 1, 50 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, 51 }, { 52 .pixfmt = V4L2_PIX_FMT_VP8, 53 .num_planes = 1, 54 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, 55 }, { 56 .pixfmt = V4L2_PIX_FMT_HEVC, 57 .num_planes = 1, 58 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, 59 }, 60 }; 61 62 static const struct venus_format * 63 find_format(struct venus_inst *inst, u32 pixfmt, u32 type) 64 { 65 const struct venus_format *fmt = venc_formats; 66 unsigned int size = ARRAY_SIZE(venc_formats); 67 unsigned int i; 68 69 for (i = 0; i < size; i++) { 70 if (fmt[i].pixfmt == pixfmt) 71 break; 72 } 73 74 if (i == size || fmt[i].type != type) 75 return NULL; 76 77 if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE && 78 !venus_helper_check_codec(inst, fmt[i].pixfmt)) 79 return NULL; 80 81 return &fmt[i]; 82 } 83 84 static const struct venus_format * 85 find_format_by_index(struct venus_inst *inst, unsigned int index, u32 type) 86 { 87 const struct venus_format *fmt = venc_formats; 88 unsigned int size = ARRAY_SIZE(venc_formats); 89 unsigned int i, k = 0; 90 91 if (index > size) 92 return NULL; 93 94 for (i = 0; i < size; i++) { 95 bool valid; 96 97 if (fmt[i].type != type) 98 continue; 99 valid = type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE || 100 venus_helper_check_codec(inst, fmt[i].pixfmt); 101 if (k == index && valid) 102 break; 103 if (valid) 104 k++; 105 } 106 107 if (i == size) 108 return NULL; 109 110 return &fmt[i]; 111 } 112 113 static int venc_v4l2_to_hfi(int id, int value) 114 { 115 switch (id) { 116 case V4L2_CID_MPEG_VIDEO_H264_ENTROPY_MODE: 117 switch (value) { 118 case V4L2_MPEG_VIDEO_H264_ENTROPY_MODE_CAVLC: 119 default: 120 return HFI_H264_ENTROPY_CAVLC; 121 case V4L2_MPEG_VIDEO_H264_ENTROPY_MODE_CABAC: 122 return HFI_H264_ENTROPY_CABAC; 123 } 124 case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE: 125 switch (value) { 126 case V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_ENABLED: 127 default: 128 return HFI_H264_DB_MODE_ALL_BOUNDARY; 129 case V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_DISABLED: 130 return HFI_H264_DB_MODE_DISABLE; 131 case V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_DISABLED_AT_SLICE_BOUNDARY: 132 return HFI_H264_DB_MODE_SKIP_SLICE_BOUNDARY; 133 } 134 } 135 136 return 0; 137 } 138 139 static int 140 venc_querycap(struct file *file, void *fh, struct v4l2_capability *cap) 141 { 142 strscpy(cap->driver, "qcom-venus", sizeof(cap->driver)); 143 strscpy(cap->card, "Qualcomm Venus video encoder", sizeof(cap->card)); 144 strscpy(cap->bus_info, "platform:qcom-venus", sizeof(cap->bus_info)); 145 146 return 0; 147 } 148 149 static int venc_enum_fmt(struct file *file, void *fh, struct v4l2_fmtdesc *f) 150 { 151 struct venus_inst *inst = to_inst(file); 152 const struct venus_format *fmt; 153 154 fmt = find_format_by_index(inst, f->index, f->type); 155 156 memset(f->reserved, 0, sizeof(f->reserved)); 157 158 if (!fmt) 159 return -EINVAL; 160 161 f->pixelformat = fmt->pixfmt; 162 163 return 0; 164 } 165 166 static const struct venus_format * 167 venc_try_fmt_common(struct venus_inst *inst, struct v4l2_format *f) 168 { 169 struct v4l2_pix_format_mplane *pixmp = &f->fmt.pix_mp; 170 struct v4l2_plane_pix_format *pfmt = pixmp->plane_fmt; 171 const struct venus_format *fmt; 172 u32 sizeimage; 173 174 memset(pfmt[0].reserved, 0, sizeof(pfmt[0].reserved)); 175 memset(pixmp->reserved, 0, sizeof(pixmp->reserved)); 176 177 fmt = find_format(inst, pixmp->pixelformat, f->type); 178 if (!fmt) { 179 if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) 180 pixmp->pixelformat = V4L2_PIX_FMT_H264; 181 else if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) 182 pixmp->pixelformat = V4L2_PIX_FMT_NV12; 183 else 184 return NULL; 185 fmt = find_format(inst, pixmp->pixelformat, f->type); 186 } 187 188 pixmp->width = clamp(pixmp->width, frame_width_min(inst), 189 frame_width_max(inst)); 190 pixmp->height = clamp(pixmp->height, frame_height_min(inst), 191 frame_height_max(inst)); 192 193 if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) 194 pixmp->height = ALIGN(pixmp->height, 32); 195 196 pixmp->width = ALIGN(pixmp->width, 2); 197 pixmp->height = ALIGN(pixmp->height, 2); 198 199 if (pixmp->field == V4L2_FIELD_ANY) 200 pixmp->field = V4L2_FIELD_NONE; 201 pixmp->num_planes = fmt->num_planes; 202 pixmp->flags = 0; 203 204 sizeimage = venus_helper_get_framesz(pixmp->pixelformat, 205 pixmp->width, 206 pixmp->height); 207 pfmt[0].sizeimage = max(ALIGN(pfmt[0].sizeimage, SZ_4K), sizeimage); 208 209 if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) 210 pfmt[0].bytesperline = ALIGN(pixmp->width, 128); 211 else 212 pfmt[0].bytesperline = 0; 213 214 return fmt; 215 } 216 217 static int venc_try_fmt(struct file *file, void *fh, struct v4l2_format *f) 218 { 219 struct venus_inst *inst = to_inst(file); 220 221 venc_try_fmt_common(inst, f); 222 223 return 0; 224 } 225 226 static int venc_s_fmt(struct file *file, void *fh, struct v4l2_format *f) 227 { 228 struct venus_inst *inst = to_inst(file); 229 struct v4l2_pix_format_mplane *pixmp = &f->fmt.pix_mp; 230 struct v4l2_pix_format_mplane orig_pixmp; 231 const struct venus_format *fmt; 232 struct v4l2_format format; 233 u32 pixfmt_out = 0, pixfmt_cap = 0; 234 struct vb2_queue *q; 235 236 q = v4l2_m2m_get_vq(inst->m2m_ctx, f->type); 237 if (!q) 238 return -EINVAL; 239 240 if (vb2_is_busy(q)) 241 return -EBUSY; 242 243 orig_pixmp = *pixmp; 244 245 fmt = venc_try_fmt_common(inst, f); 246 if (!fmt) 247 return -EINVAL; 248 249 if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { 250 pixfmt_out = pixmp->pixelformat; 251 pixfmt_cap = inst->fmt_cap->pixfmt; 252 } else if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) { 253 pixfmt_cap = pixmp->pixelformat; 254 pixfmt_out = inst->fmt_out->pixfmt; 255 } 256 257 memset(&format, 0, sizeof(format)); 258 259 format.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; 260 format.fmt.pix_mp.pixelformat = pixfmt_out; 261 format.fmt.pix_mp.width = orig_pixmp.width; 262 format.fmt.pix_mp.height = orig_pixmp.height; 263 venc_try_fmt_common(inst, &format); 264 265 if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { 266 inst->out_width = format.fmt.pix_mp.width; 267 inst->out_height = format.fmt.pix_mp.height; 268 inst->colorspace = pixmp->colorspace; 269 inst->ycbcr_enc = pixmp->ycbcr_enc; 270 inst->quantization = pixmp->quantization; 271 inst->xfer_func = pixmp->xfer_func; 272 } 273 274 memset(&format, 0, sizeof(format)); 275 276 format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; 277 format.fmt.pix_mp.pixelformat = pixfmt_cap; 278 format.fmt.pix_mp.width = orig_pixmp.width; 279 format.fmt.pix_mp.height = orig_pixmp.height; 280 venc_try_fmt_common(inst, &format); 281 282 inst->width = format.fmt.pix_mp.width; 283 inst->height = format.fmt.pix_mp.height; 284 285 if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) 286 inst->fmt_out = fmt; 287 else if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) { 288 inst->fmt_cap = fmt; 289 inst->output_buf_size = pixmp->plane_fmt[0].sizeimage; 290 } 291 292 return 0; 293 } 294 295 static int venc_g_fmt(struct file *file, void *fh, struct v4l2_format *f) 296 { 297 struct v4l2_pix_format_mplane *pixmp = &f->fmt.pix_mp; 298 struct venus_inst *inst = to_inst(file); 299 const struct venus_format *fmt; 300 301 if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) 302 fmt = inst->fmt_cap; 303 else if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) 304 fmt = inst->fmt_out; 305 else 306 return -EINVAL; 307 308 pixmp->pixelformat = fmt->pixfmt; 309 310 if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) { 311 pixmp->width = inst->width; 312 pixmp->height = inst->height; 313 pixmp->colorspace = inst->colorspace; 314 pixmp->ycbcr_enc = inst->ycbcr_enc; 315 pixmp->quantization = inst->quantization; 316 pixmp->xfer_func = inst->xfer_func; 317 } else if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { 318 pixmp->width = inst->out_width; 319 pixmp->height = inst->out_height; 320 } 321 322 venc_try_fmt_common(inst, f); 323 324 return 0; 325 } 326 327 static int 328 venc_g_selection(struct file *file, void *fh, struct v4l2_selection *s) 329 { 330 struct venus_inst *inst = to_inst(file); 331 332 if (s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) 333 return -EINVAL; 334 335 switch (s->target) { 336 case V4L2_SEL_TGT_CROP_DEFAULT: 337 case V4L2_SEL_TGT_CROP_BOUNDS: 338 s->r.width = inst->width; 339 s->r.height = inst->height; 340 break; 341 case V4L2_SEL_TGT_CROP: 342 s->r.width = inst->out_width; 343 s->r.height = inst->out_height; 344 break; 345 default: 346 return -EINVAL; 347 } 348 349 s->r.top = 0; 350 s->r.left = 0; 351 352 return 0; 353 } 354 355 static int 356 venc_s_selection(struct file *file, void *fh, struct v4l2_selection *s) 357 { 358 struct venus_inst *inst = to_inst(file); 359 360 if (s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) 361 return -EINVAL; 362 363 switch (s->target) { 364 case V4L2_SEL_TGT_CROP: 365 if (s->r.width != inst->out_width || 366 s->r.height != inst->out_height || 367 s->r.top != 0 || s->r.left != 0) 368 return -EINVAL; 369 break; 370 default: 371 return -EINVAL; 372 } 373 374 return 0; 375 } 376 377 static int venc_s_parm(struct file *file, void *fh, struct v4l2_streamparm *a) 378 { 379 struct venus_inst *inst = to_inst(file); 380 struct v4l2_outputparm *out = &a->parm.output; 381 struct v4l2_fract *timeperframe = &out->timeperframe; 382 u64 us_per_frame, fps; 383 384 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE && 385 a->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) 386 return -EINVAL; 387 388 memset(out->reserved, 0, sizeof(out->reserved)); 389 390 if (!timeperframe->denominator) 391 timeperframe->denominator = inst->timeperframe.denominator; 392 if (!timeperframe->numerator) 393 timeperframe->numerator = inst->timeperframe.numerator; 394 395 out->capability = V4L2_CAP_TIMEPERFRAME; 396 397 us_per_frame = timeperframe->numerator * (u64)USEC_PER_SEC; 398 do_div(us_per_frame, timeperframe->denominator); 399 400 if (!us_per_frame) 401 return -EINVAL; 402 403 fps = (u64)USEC_PER_SEC; 404 do_div(fps, us_per_frame); 405 406 inst->timeperframe = *timeperframe; 407 inst->fps = fps; 408 409 return 0; 410 } 411 412 static int venc_g_parm(struct file *file, void *fh, struct v4l2_streamparm *a) 413 { 414 struct venus_inst *inst = to_inst(file); 415 416 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE && 417 a->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) 418 return -EINVAL; 419 420 a->parm.output.capability |= V4L2_CAP_TIMEPERFRAME; 421 a->parm.output.timeperframe = inst->timeperframe; 422 423 return 0; 424 } 425 426 static int venc_enum_framesizes(struct file *file, void *fh, 427 struct v4l2_frmsizeenum *fsize) 428 { 429 struct venus_inst *inst = to_inst(file); 430 const struct venus_format *fmt; 431 432 fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE; 433 434 fmt = find_format(inst, fsize->pixel_format, 435 V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE); 436 if (!fmt) { 437 fmt = find_format(inst, fsize->pixel_format, 438 V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE); 439 if (!fmt) 440 return -EINVAL; 441 } 442 443 if (fsize->index) 444 return -EINVAL; 445 446 fsize->stepwise.min_width = frame_width_min(inst); 447 fsize->stepwise.max_width = frame_width_max(inst); 448 fsize->stepwise.step_width = frame_width_step(inst); 449 fsize->stepwise.min_height = frame_height_min(inst); 450 fsize->stepwise.max_height = frame_height_max(inst); 451 fsize->stepwise.step_height = frame_height_step(inst); 452 453 return 0; 454 } 455 456 static int venc_enum_frameintervals(struct file *file, void *fh, 457 struct v4l2_frmivalenum *fival) 458 { 459 struct venus_inst *inst = to_inst(file); 460 const struct venus_format *fmt; 461 unsigned int framerate_factor = 1; 462 463 fival->type = V4L2_FRMIVAL_TYPE_STEPWISE; 464 465 fmt = find_format(inst, fival->pixel_format, 466 V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE); 467 if (!fmt) { 468 fmt = find_format(inst, fival->pixel_format, 469 V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE); 470 if (!fmt) 471 return -EINVAL; 472 } 473 474 if (fival->index) 475 return -EINVAL; 476 477 if (!fival->width || !fival->height) 478 return -EINVAL; 479 480 if (fival->width > frame_width_max(inst) || 481 fival->width < frame_width_min(inst) || 482 fival->height > frame_height_max(inst) || 483 fival->height < frame_height_min(inst)) 484 return -EINVAL; 485 486 if (IS_V1(inst->core)) { 487 /* framerate is reported in 1/65535 fps unit */ 488 framerate_factor = (1 << 16); 489 } 490 491 fival->stepwise.min.numerator = 1; 492 fival->stepwise.min.denominator = frate_max(inst) / framerate_factor; 493 fival->stepwise.max.numerator = 1; 494 fival->stepwise.max.denominator = frate_min(inst) / framerate_factor; 495 fival->stepwise.step.numerator = 1; 496 fival->stepwise.step.denominator = frate_max(inst) / framerate_factor; 497 498 return 0; 499 } 500 501 static const struct v4l2_ioctl_ops venc_ioctl_ops = { 502 .vidioc_querycap = venc_querycap, 503 .vidioc_enum_fmt_vid_cap = venc_enum_fmt, 504 .vidioc_enum_fmt_vid_out = venc_enum_fmt, 505 .vidioc_s_fmt_vid_cap_mplane = venc_s_fmt, 506 .vidioc_s_fmt_vid_out_mplane = venc_s_fmt, 507 .vidioc_g_fmt_vid_cap_mplane = venc_g_fmt, 508 .vidioc_g_fmt_vid_out_mplane = venc_g_fmt, 509 .vidioc_try_fmt_vid_cap_mplane = venc_try_fmt, 510 .vidioc_try_fmt_vid_out_mplane = venc_try_fmt, 511 .vidioc_g_selection = venc_g_selection, 512 .vidioc_s_selection = venc_s_selection, 513 .vidioc_reqbufs = v4l2_m2m_ioctl_reqbufs, 514 .vidioc_querybuf = v4l2_m2m_ioctl_querybuf, 515 .vidioc_create_bufs = v4l2_m2m_ioctl_create_bufs, 516 .vidioc_prepare_buf = v4l2_m2m_ioctl_prepare_buf, 517 .vidioc_qbuf = v4l2_m2m_ioctl_qbuf, 518 .vidioc_expbuf = v4l2_m2m_ioctl_expbuf, 519 .vidioc_dqbuf = v4l2_m2m_ioctl_dqbuf, 520 .vidioc_streamon = v4l2_m2m_ioctl_streamon, 521 .vidioc_streamoff = v4l2_m2m_ioctl_streamoff, 522 .vidioc_s_parm = venc_s_parm, 523 .vidioc_g_parm = venc_g_parm, 524 .vidioc_enum_framesizes = venc_enum_framesizes, 525 .vidioc_enum_frameintervals = venc_enum_frameintervals, 526 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, 527 .vidioc_unsubscribe_event = v4l2_event_unsubscribe, 528 }; 529 530 static int venc_set_properties(struct venus_inst *inst) 531 { 532 struct venc_controls *ctr = &inst->controls.enc; 533 struct hfi_intra_period intra_period; 534 struct hfi_framerate frate; 535 struct hfi_bitrate brate; 536 struct hfi_idr_period idrp; 537 struct hfi_quantization quant; 538 struct hfi_quantization_range quant_range; 539 u32 ptype, rate_control, bitrate; 540 u32 profile, level; 541 int ret; 542 543 ret = venus_helper_set_work_mode(inst, VIDC_WORK_MODE_2); 544 if (ret) 545 return ret; 546 547 ptype = HFI_PROPERTY_CONFIG_FRAME_RATE; 548 frate.buffer_type = HFI_BUFFER_OUTPUT; 549 frate.framerate = inst->fps * (1 << 16); 550 551 ret = hfi_session_set_property(inst, ptype, &frate); 552 if (ret) 553 return ret; 554 555 if (inst->fmt_cap->pixfmt == V4L2_PIX_FMT_H264) { 556 struct hfi_h264_vui_timing_info info; 557 struct hfi_h264_entropy_control entropy; 558 struct hfi_h264_db_control deblock; 559 560 ptype = HFI_PROPERTY_PARAM_VENC_H264_VUI_TIMING_INFO; 561 info.enable = 1; 562 info.fixed_framerate = 1; 563 info.time_scale = NSEC_PER_SEC; 564 565 ret = hfi_session_set_property(inst, ptype, &info); 566 if (ret) 567 return ret; 568 569 ptype = HFI_PROPERTY_PARAM_VENC_H264_ENTROPY_CONTROL; 570 entropy.entropy_mode = venc_v4l2_to_hfi( 571 V4L2_CID_MPEG_VIDEO_H264_ENTROPY_MODE, 572 ctr->h264_entropy_mode); 573 entropy.cabac_model = HFI_H264_CABAC_MODEL_0; 574 575 ret = hfi_session_set_property(inst, ptype, &entropy); 576 if (ret) 577 return ret; 578 579 ptype = HFI_PROPERTY_PARAM_VENC_H264_DEBLOCK_CONTROL; 580 deblock.mode = venc_v4l2_to_hfi( 581 V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE, 582 ctr->h264_loop_filter_mode); 583 deblock.slice_alpha_offset = ctr->h264_loop_filter_alpha; 584 deblock.slice_beta_offset = ctr->h264_loop_filter_beta; 585 586 ret = hfi_session_set_property(inst, ptype, &deblock); 587 if (ret) 588 return ret; 589 } 590 591 /* IDR periodicity, n: 592 * n = 0 - only the first I-frame is IDR frame 593 * n = 1 - all I-frames will be IDR frames 594 * n > 1 - every n-th I-frame will be IDR frame 595 */ 596 ptype = HFI_PROPERTY_CONFIG_VENC_IDR_PERIOD; 597 idrp.idr_period = 0; 598 ret = hfi_session_set_property(inst, ptype, &idrp); 599 if (ret) 600 return ret; 601 602 if (ctr->num_b_frames) { 603 u32 max_num_b_frames = NUM_B_FRAMES_MAX; 604 605 ptype = HFI_PROPERTY_PARAM_VENC_MAX_NUM_B_FRAMES; 606 ret = hfi_session_set_property(inst, ptype, &max_num_b_frames); 607 if (ret) 608 return ret; 609 } 610 611 ptype = HFI_PROPERTY_CONFIG_VENC_INTRA_PERIOD; 612 intra_period.pframes = ctr->num_p_frames; 613 intra_period.bframes = ctr->num_b_frames; 614 615 ret = hfi_session_set_property(inst, ptype, &intra_period); 616 if (ret) 617 return ret; 618 619 if (!ctr->rc_enable) 620 rate_control = HFI_RATE_CONTROL_OFF; 621 else if (ctr->bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_VBR) 622 rate_control = ctr->frame_skip_mode ? HFI_RATE_CONTROL_VBR_VFR : 623 HFI_RATE_CONTROL_VBR_CFR; 624 else if (ctr->bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_CBR) 625 rate_control = ctr->frame_skip_mode ? HFI_RATE_CONTROL_CBR_VFR : 626 HFI_RATE_CONTROL_CBR_CFR; 627 else if (ctr->bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_CQ) 628 rate_control = HFI_RATE_CONTROL_CQ; 629 630 ptype = HFI_PROPERTY_PARAM_VENC_RATE_CONTROL; 631 ret = hfi_session_set_property(inst, ptype, &rate_control); 632 if (ret) 633 return ret; 634 635 if (rate_control == HFI_RATE_CONTROL_CQ && ctr->const_quality) { 636 struct hfi_heic_frame_quality quality = {}; 637 638 ptype = HFI_PROPERTY_CONFIG_HEIC_FRAME_QUALITY; 639 quality.frame_quality = ctr->const_quality; 640 ret = hfi_session_set_property(inst, ptype, &quality); 641 if (ret) 642 return ret; 643 } 644 645 if (!ctr->bitrate) 646 bitrate = 64000; 647 else 648 bitrate = ctr->bitrate; 649 650 ptype = HFI_PROPERTY_CONFIG_VENC_TARGET_BITRATE; 651 brate.bitrate = bitrate; 652 brate.layer_id = 0; 653 654 ret = hfi_session_set_property(inst, ptype, &brate); 655 if (ret) 656 return ret; 657 658 if (!ctr->bitrate_peak) 659 bitrate *= 2; 660 else 661 bitrate = ctr->bitrate_peak; 662 663 ptype = HFI_PROPERTY_CONFIG_VENC_MAX_BITRATE; 664 brate.bitrate = bitrate; 665 brate.layer_id = 0; 666 667 ret = hfi_session_set_property(inst, ptype, &brate); 668 if (ret) 669 return ret; 670 671 ptype = HFI_PROPERTY_PARAM_VENC_SESSION_QP; 672 if (inst->fmt_cap->pixfmt == V4L2_PIX_FMT_HEVC) { 673 quant.qp_i = ctr->hevc_i_qp; 674 quant.qp_p = ctr->hevc_p_qp; 675 quant.qp_b = ctr->hevc_b_qp; 676 } else { 677 quant.qp_i = ctr->h264_i_qp; 678 quant.qp_p = ctr->h264_p_qp; 679 quant.qp_b = ctr->h264_b_qp; 680 } 681 quant.layer_id = 0; 682 ret = hfi_session_set_property(inst, ptype, &quant); 683 if (ret) 684 return ret; 685 686 ptype = HFI_PROPERTY_PARAM_VENC_SESSION_QP_RANGE; 687 if (inst->fmt_cap->pixfmt == V4L2_PIX_FMT_HEVC) { 688 quant_range.min_qp = ctr->hevc_min_qp; 689 quant_range.max_qp = ctr->hevc_max_qp; 690 } else { 691 quant_range.min_qp = ctr->h264_min_qp; 692 quant_range.max_qp = ctr->h264_max_qp; 693 } 694 quant_range.layer_id = 0; 695 ret = hfi_session_set_property(inst, ptype, &quant_range); 696 if (ret) 697 return ret; 698 699 switch (inst->hfi_codec) { 700 case HFI_VIDEO_CODEC_H264: 701 profile = ctr->profile.h264; 702 level = ctr->level.h264; 703 break; 704 case HFI_VIDEO_CODEC_MPEG4: 705 profile = ctr->profile.mpeg4; 706 level = ctr->level.mpeg4; 707 break; 708 case HFI_VIDEO_CODEC_VP8: 709 profile = ctr->profile.vp8; 710 level = 0; 711 break; 712 case HFI_VIDEO_CODEC_VP9: 713 profile = ctr->profile.vp9; 714 level = ctr->level.vp9; 715 break; 716 case HFI_VIDEO_CODEC_HEVC: 717 profile = ctr->profile.hevc; 718 level = ctr->level.hevc; 719 break; 720 case HFI_VIDEO_CODEC_MPEG2: 721 default: 722 profile = 0; 723 level = 0; 724 break; 725 } 726 727 ret = venus_helper_set_profile_level(inst, profile, level); 728 if (ret) 729 return ret; 730 731 return 0; 732 } 733 734 static int venc_init_session(struct venus_inst *inst) 735 { 736 int ret; 737 738 ret = venus_helper_session_init(inst); 739 if (ret == -EALREADY) 740 return 0; 741 else if (ret) 742 return ret; 743 744 ret = venus_helper_set_input_resolution(inst, inst->width, 745 inst->height); 746 if (ret) 747 goto deinit; 748 749 ret = venus_helper_set_output_resolution(inst, inst->width, 750 inst->height, 751 HFI_BUFFER_OUTPUT); 752 if (ret) 753 goto deinit; 754 755 ret = venus_helper_set_color_format(inst, inst->fmt_out->pixfmt); 756 if (ret) 757 goto deinit; 758 759 ret = venc_set_properties(inst); 760 if (ret) 761 goto deinit; 762 763 return 0; 764 deinit: 765 hfi_session_deinit(inst); 766 return ret; 767 } 768 769 static int venc_out_num_buffers(struct venus_inst *inst, unsigned int *num) 770 { 771 struct hfi_buffer_requirements bufreq; 772 int ret; 773 774 ret = venus_helper_get_bufreq(inst, HFI_BUFFER_INPUT, &bufreq); 775 if (ret) 776 return ret; 777 778 *num = bufreq.count_actual; 779 780 return 0; 781 } 782 783 static int venc_queue_setup(struct vb2_queue *q, 784 unsigned int *num_buffers, unsigned int *num_planes, 785 unsigned int sizes[], struct device *alloc_devs[]) 786 { 787 struct venus_inst *inst = vb2_get_drv_priv(q); 788 unsigned int num, min = 4; 789 int ret; 790 791 if (*num_planes) { 792 if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE && 793 *num_planes != inst->fmt_out->num_planes) 794 return -EINVAL; 795 796 if (q->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE && 797 *num_planes != inst->fmt_cap->num_planes) 798 return -EINVAL; 799 800 if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE && 801 sizes[0] < inst->input_buf_size) 802 return -EINVAL; 803 804 if (q->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE && 805 sizes[0] < inst->output_buf_size) 806 return -EINVAL; 807 808 return 0; 809 } 810 811 mutex_lock(&inst->lock); 812 ret = venc_init_session(inst); 813 mutex_unlock(&inst->lock); 814 815 if (ret) 816 return ret; 817 818 switch (q->type) { 819 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: 820 *num_planes = inst->fmt_out->num_planes; 821 822 ret = venc_out_num_buffers(inst, &num); 823 if (ret) 824 break; 825 826 num = max(num, min); 827 *num_buffers = max(*num_buffers, num); 828 inst->num_input_bufs = *num_buffers; 829 830 sizes[0] = venus_helper_get_framesz(inst->fmt_out->pixfmt, 831 inst->width, 832 inst->height); 833 inst->input_buf_size = sizes[0]; 834 break; 835 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: 836 *num_planes = inst->fmt_cap->num_planes; 837 *num_buffers = max(*num_buffers, min); 838 inst->num_output_bufs = *num_buffers; 839 sizes[0] = venus_helper_get_framesz(inst->fmt_cap->pixfmt, 840 inst->width, 841 inst->height); 842 sizes[0] = max(sizes[0], inst->output_buf_size); 843 inst->output_buf_size = sizes[0]; 844 break; 845 default: 846 ret = -EINVAL; 847 break; 848 } 849 850 return ret; 851 } 852 853 static int venc_buf_init(struct vb2_buffer *vb) 854 { 855 struct venus_inst *inst = vb2_get_drv_priv(vb->vb2_queue); 856 857 inst->buf_count++; 858 859 return venus_helper_vb2_buf_init(vb); 860 } 861 862 static void venc_release_session(struct venus_inst *inst) 863 { 864 int ret; 865 866 mutex_lock(&inst->lock); 867 868 ret = hfi_session_deinit(inst); 869 if (ret || inst->session_error) 870 hfi_session_abort(inst); 871 872 mutex_unlock(&inst->lock); 873 874 venus_pm_load_scale(inst); 875 INIT_LIST_HEAD(&inst->registeredbufs); 876 venus_pm_release_core(inst); 877 } 878 879 static void venc_buf_cleanup(struct vb2_buffer *vb) 880 { 881 struct venus_inst *inst = vb2_get_drv_priv(vb->vb2_queue); 882 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); 883 struct venus_buffer *buf = to_venus_buffer(vbuf); 884 885 mutex_lock(&inst->lock); 886 if (vb->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) 887 if (!list_empty(&inst->registeredbufs)) 888 list_del_init(&buf->reg_list); 889 mutex_unlock(&inst->lock); 890 891 inst->buf_count--; 892 if (!inst->buf_count) 893 venc_release_session(inst); 894 } 895 896 static int venc_verify_conf(struct venus_inst *inst) 897 { 898 enum hfi_version ver = inst->core->res->hfi_version; 899 struct hfi_buffer_requirements bufreq; 900 int ret; 901 902 if (!inst->num_input_bufs || !inst->num_output_bufs) 903 return -EINVAL; 904 905 ret = venus_helper_get_bufreq(inst, HFI_BUFFER_OUTPUT, &bufreq); 906 if (ret) 907 return ret; 908 909 if (inst->num_output_bufs < bufreq.count_actual || 910 inst->num_output_bufs < HFI_BUFREQ_COUNT_MIN(&bufreq, ver)) 911 return -EINVAL; 912 913 ret = venus_helper_get_bufreq(inst, HFI_BUFFER_INPUT, &bufreq); 914 if (ret) 915 return ret; 916 917 if (inst->num_input_bufs < bufreq.count_actual || 918 inst->num_input_bufs < HFI_BUFREQ_COUNT_MIN(&bufreq, ver)) 919 return -EINVAL; 920 921 return 0; 922 } 923 924 static int venc_start_streaming(struct vb2_queue *q, unsigned int count) 925 { 926 struct venus_inst *inst = vb2_get_drv_priv(q); 927 int ret; 928 929 mutex_lock(&inst->lock); 930 931 if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) 932 inst->streamon_out = 1; 933 else 934 inst->streamon_cap = 1; 935 936 if (!(inst->streamon_out & inst->streamon_cap)) { 937 mutex_unlock(&inst->lock); 938 return 0; 939 } 940 941 venus_helper_init_instance(inst); 942 943 inst->sequence_cap = 0; 944 inst->sequence_out = 0; 945 946 ret = venus_pm_acquire_core(inst); 947 if (ret) 948 goto error; 949 950 ret = venc_set_properties(inst); 951 if (ret) 952 goto error; 953 954 ret = venc_verify_conf(inst); 955 if (ret) 956 goto error; 957 958 ret = venus_helper_set_num_bufs(inst, inst->num_input_bufs, 959 inst->num_output_bufs, 0); 960 if (ret) 961 goto error; 962 963 ret = venus_helper_vb2_start_streaming(inst); 964 if (ret) 965 goto error; 966 967 mutex_unlock(&inst->lock); 968 969 return 0; 970 971 error: 972 venus_helper_buffers_done(inst, q->type, VB2_BUF_STATE_QUEUED); 973 if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) 974 inst->streamon_out = 0; 975 else 976 inst->streamon_cap = 0; 977 mutex_unlock(&inst->lock); 978 return ret; 979 } 980 981 static void venc_vb2_buf_queue(struct vb2_buffer *vb) 982 { 983 struct venus_inst *inst = vb2_get_drv_priv(vb->vb2_queue); 984 985 mutex_lock(&inst->lock); 986 venus_helper_vb2_buf_queue(vb); 987 mutex_unlock(&inst->lock); 988 } 989 990 static const struct vb2_ops venc_vb2_ops = { 991 .queue_setup = venc_queue_setup, 992 .buf_init = venc_buf_init, 993 .buf_cleanup = venc_buf_cleanup, 994 .buf_prepare = venus_helper_vb2_buf_prepare, 995 .start_streaming = venc_start_streaming, 996 .stop_streaming = venus_helper_vb2_stop_streaming, 997 .buf_queue = venc_vb2_buf_queue, 998 }; 999 1000 static void venc_buf_done(struct venus_inst *inst, unsigned int buf_type, 1001 u32 tag, u32 bytesused, u32 data_offset, u32 flags, 1002 u32 hfi_flags, u64 timestamp_us) 1003 { 1004 struct vb2_v4l2_buffer *vbuf; 1005 struct vb2_buffer *vb; 1006 unsigned int type; 1007 1008 if (buf_type == HFI_BUFFER_INPUT) 1009 type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; 1010 else 1011 type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; 1012 1013 vbuf = venus_helper_find_buf(inst, type, tag); 1014 if (!vbuf) 1015 return; 1016 1017 vbuf->flags = flags; 1018 1019 if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) { 1020 vb = &vbuf->vb2_buf; 1021 vb2_set_plane_payload(vb, 0, bytesused + data_offset); 1022 vb->planes[0].data_offset = data_offset; 1023 vb->timestamp = timestamp_us * NSEC_PER_USEC; 1024 vbuf->sequence = inst->sequence_cap++; 1025 } else { 1026 vbuf->sequence = inst->sequence_out++; 1027 } 1028 1029 v4l2_m2m_buf_done(vbuf, VB2_BUF_STATE_DONE); 1030 } 1031 1032 static void venc_event_notify(struct venus_inst *inst, u32 event, 1033 struct hfi_event_data *data) 1034 { 1035 struct device *dev = inst->core->dev_enc; 1036 1037 if (event == EVT_SESSION_ERROR) { 1038 inst->session_error = true; 1039 dev_err(dev, "enc: event session error %x\n", inst->error); 1040 } 1041 } 1042 1043 static const struct hfi_inst_ops venc_hfi_ops = { 1044 .buf_done = venc_buf_done, 1045 .event_notify = venc_event_notify, 1046 }; 1047 1048 static const struct v4l2_m2m_ops venc_m2m_ops = { 1049 .device_run = venus_helper_m2m_device_run, 1050 .job_abort = venus_helper_m2m_job_abort, 1051 }; 1052 1053 static int m2m_queue_init(void *priv, struct vb2_queue *src_vq, 1054 struct vb2_queue *dst_vq) 1055 { 1056 struct venus_inst *inst = priv; 1057 int ret; 1058 1059 src_vq->type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; 1060 src_vq->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF; 1061 src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; 1062 src_vq->ops = &venc_vb2_ops; 1063 src_vq->mem_ops = &vb2_dma_contig_memops; 1064 src_vq->drv_priv = inst; 1065 src_vq->buf_struct_size = sizeof(struct venus_buffer); 1066 src_vq->allow_zero_bytesused = 1; 1067 src_vq->min_buffers_needed = 1; 1068 src_vq->dev = inst->core->dev; 1069 if (inst->core->res->hfi_version == HFI_VERSION_1XX) 1070 src_vq->bidirectional = 1; 1071 ret = vb2_queue_init(src_vq); 1072 if (ret) 1073 return ret; 1074 1075 dst_vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; 1076 dst_vq->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF; 1077 dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; 1078 dst_vq->ops = &venc_vb2_ops; 1079 dst_vq->mem_ops = &vb2_dma_contig_memops; 1080 dst_vq->drv_priv = inst; 1081 dst_vq->buf_struct_size = sizeof(struct venus_buffer); 1082 dst_vq->allow_zero_bytesused = 1; 1083 dst_vq->min_buffers_needed = 1; 1084 dst_vq->dev = inst->core->dev; 1085 return vb2_queue_init(dst_vq); 1086 } 1087 1088 static void venc_inst_init(struct venus_inst *inst) 1089 { 1090 inst->fmt_cap = &venc_formats[3]; 1091 inst->fmt_out = &venc_formats[0]; 1092 inst->width = 1280; 1093 inst->height = ALIGN(720, 32); 1094 inst->out_width = 1280; 1095 inst->out_height = 720; 1096 inst->fps = 15; 1097 inst->timeperframe.numerator = 1; 1098 inst->timeperframe.denominator = 15; 1099 inst->hfi_codec = HFI_VIDEO_CODEC_H264; 1100 } 1101 1102 static int venc_open(struct file *file) 1103 { 1104 struct venus_core *core = video_drvdata(file); 1105 struct venus_inst *inst; 1106 int ret; 1107 1108 inst = kzalloc(sizeof(*inst), GFP_KERNEL); 1109 if (!inst) 1110 return -ENOMEM; 1111 1112 INIT_LIST_HEAD(&inst->dpbbufs); 1113 INIT_LIST_HEAD(&inst->registeredbufs); 1114 INIT_LIST_HEAD(&inst->internalbufs); 1115 INIT_LIST_HEAD(&inst->list); 1116 mutex_init(&inst->lock); 1117 1118 inst->core = core; 1119 inst->session_type = VIDC_SESSION_TYPE_ENC; 1120 inst->clk_data.core_id = VIDC_CORE_ID_DEFAULT; 1121 inst->core_acquired = false; 1122 1123 venus_helper_init_instance(inst); 1124 1125 ret = pm_runtime_get_sync(core->dev_enc); 1126 if (ret < 0) 1127 goto err_put_sync; 1128 1129 ret = venc_ctrl_init(inst); 1130 if (ret) 1131 goto err_put_sync; 1132 1133 ret = hfi_session_create(inst, &venc_hfi_ops); 1134 if (ret) 1135 goto err_ctrl_deinit; 1136 1137 venc_inst_init(inst); 1138 1139 /* 1140 * create m2m device for every instance, the m2m context scheduling 1141 * is made by firmware side so we do not need to care about. 1142 */ 1143 inst->m2m_dev = v4l2_m2m_init(&venc_m2m_ops); 1144 if (IS_ERR(inst->m2m_dev)) { 1145 ret = PTR_ERR(inst->m2m_dev); 1146 goto err_session_destroy; 1147 } 1148 1149 inst->m2m_ctx = v4l2_m2m_ctx_init(inst->m2m_dev, inst, m2m_queue_init); 1150 if (IS_ERR(inst->m2m_ctx)) { 1151 ret = PTR_ERR(inst->m2m_ctx); 1152 goto err_m2m_release; 1153 } 1154 1155 v4l2_fh_init(&inst->fh, core->vdev_enc); 1156 1157 inst->fh.ctrl_handler = &inst->ctrl_handler; 1158 v4l2_fh_add(&inst->fh); 1159 inst->fh.m2m_ctx = inst->m2m_ctx; 1160 file->private_data = &inst->fh; 1161 1162 return 0; 1163 1164 err_m2m_release: 1165 v4l2_m2m_release(inst->m2m_dev); 1166 err_session_destroy: 1167 hfi_session_destroy(inst); 1168 err_ctrl_deinit: 1169 venc_ctrl_deinit(inst); 1170 err_put_sync: 1171 pm_runtime_put_sync(core->dev_enc); 1172 kfree(inst); 1173 return ret; 1174 } 1175 1176 static int venc_close(struct file *file) 1177 { 1178 struct venus_inst *inst = to_inst(file); 1179 1180 v4l2_m2m_ctx_release(inst->m2m_ctx); 1181 v4l2_m2m_release(inst->m2m_dev); 1182 venc_ctrl_deinit(inst); 1183 hfi_session_destroy(inst); 1184 mutex_destroy(&inst->lock); 1185 v4l2_fh_del(&inst->fh); 1186 v4l2_fh_exit(&inst->fh); 1187 1188 pm_runtime_put_sync(inst->core->dev_enc); 1189 1190 kfree(inst); 1191 return 0; 1192 } 1193 1194 static const struct v4l2_file_operations venc_fops = { 1195 .owner = THIS_MODULE, 1196 .open = venc_open, 1197 .release = venc_close, 1198 .unlocked_ioctl = video_ioctl2, 1199 .poll = v4l2_m2m_fop_poll, 1200 .mmap = v4l2_m2m_fop_mmap, 1201 }; 1202 1203 static int venc_probe(struct platform_device *pdev) 1204 { 1205 struct device *dev = &pdev->dev; 1206 struct video_device *vdev; 1207 struct venus_core *core; 1208 int ret; 1209 1210 if (!dev->parent) 1211 return -EPROBE_DEFER; 1212 1213 core = dev_get_drvdata(dev->parent); 1214 if (!core) 1215 return -EPROBE_DEFER; 1216 1217 platform_set_drvdata(pdev, core); 1218 1219 if (core->pm_ops->venc_get) { 1220 ret = core->pm_ops->venc_get(dev); 1221 if (ret) 1222 return ret; 1223 } 1224 1225 vdev = video_device_alloc(); 1226 if (!vdev) 1227 return -ENOMEM; 1228 1229 strscpy(vdev->name, "qcom-venus-encoder", sizeof(vdev->name)); 1230 vdev->release = video_device_release; 1231 vdev->fops = &venc_fops; 1232 vdev->ioctl_ops = &venc_ioctl_ops; 1233 vdev->vfl_dir = VFL_DIR_M2M; 1234 vdev->v4l2_dev = &core->v4l2_dev; 1235 vdev->device_caps = V4L2_CAP_VIDEO_M2M_MPLANE | V4L2_CAP_STREAMING; 1236 1237 ret = video_register_device(vdev, VFL_TYPE_VIDEO, -1); 1238 if (ret) 1239 goto err_vdev_release; 1240 1241 core->vdev_enc = vdev; 1242 core->dev_enc = dev; 1243 1244 video_set_drvdata(vdev, core); 1245 pm_runtime_enable(dev); 1246 1247 return 0; 1248 1249 err_vdev_release: 1250 video_device_release(vdev); 1251 return ret; 1252 } 1253 1254 static int venc_remove(struct platform_device *pdev) 1255 { 1256 struct venus_core *core = dev_get_drvdata(pdev->dev.parent); 1257 1258 video_unregister_device(core->vdev_enc); 1259 pm_runtime_disable(core->dev_enc); 1260 1261 if (core->pm_ops->venc_put) 1262 core->pm_ops->venc_put(core->dev_enc); 1263 1264 return 0; 1265 } 1266 1267 static __maybe_unused int venc_runtime_suspend(struct device *dev) 1268 { 1269 struct venus_core *core = dev_get_drvdata(dev); 1270 const struct venus_pm_ops *pm_ops = core->pm_ops; 1271 int ret = 0; 1272 1273 if (pm_ops->venc_power) 1274 ret = pm_ops->venc_power(dev, POWER_OFF); 1275 1276 return ret; 1277 } 1278 1279 static __maybe_unused int venc_runtime_resume(struct device *dev) 1280 { 1281 struct venus_core *core = dev_get_drvdata(dev); 1282 const struct venus_pm_ops *pm_ops = core->pm_ops; 1283 int ret = 0; 1284 1285 if (pm_ops->venc_power) 1286 ret = pm_ops->venc_power(dev, POWER_ON); 1287 1288 return ret; 1289 } 1290 1291 static const struct dev_pm_ops venc_pm_ops = { 1292 SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, 1293 pm_runtime_force_resume) 1294 SET_RUNTIME_PM_OPS(venc_runtime_suspend, venc_runtime_resume, NULL) 1295 }; 1296 1297 static const struct of_device_id venc_dt_match[] = { 1298 { .compatible = "venus-encoder" }, 1299 { } 1300 }; 1301 MODULE_DEVICE_TABLE(of, venc_dt_match); 1302 1303 static struct platform_driver qcom_venus_enc_driver = { 1304 .probe = venc_probe, 1305 .remove = venc_remove, 1306 .driver = { 1307 .name = "qcom-venus-encoder", 1308 .of_match_table = venc_dt_match, 1309 .pm = &venc_pm_ops, 1310 }, 1311 }; 1312 module_platform_driver(qcom_venus_enc_driver); 1313 1314 MODULE_ALIAS("platform:qcom-venus-encoder"); 1315 MODULE_DESCRIPTION("Qualcomm Venus video encoder driver"); 1316 MODULE_LICENSE("GPL v2"); 1317