Lines Matching +full:max +full:- +full:bitrate

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 saa6752hs - i2c-driver for the saa6752hs by Philips
7 AC-3 support:
26 #include <media/v4l2-device.h>
27 #include <media/v4l2-ctrls.h>
28 #include <media/v4l2-common.h>
33 #define MPEG_PID_MAX ((1 << 14) - 1)
84 struct { /* video bitrate mode control cluster */
113 /* ---------------------------------------------------------------------- */
220 /* ---------------------------------------------------------------------- */
260 return -EINVAL; in saa6752hs_chip_command()
275 status = -ETIMEDOUT; in saa6752hs_chip_command()
311 struct saa6752hs_mpeg_params *params = &h->params; in saa6752hs_set_bitrate()
315 /* set the bitrate mode */ in saa6752hs_set_bitrate()
317 params->vi_bitrate_mode != V4L2_MPEG_VIDEO_BITRATE_MODE_VBR); in saa6752hs_set_bitrate()
319 /* set the video bitrate */ in saa6752hs_set_bitrate()
320 if (params->vi_bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_VBR) { in saa6752hs_set_bitrate()
321 /* set the target bitrate */ in saa6752hs_set_bitrate()
322 set_reg16(client, 0x80, params->vi_bitrate); in saa6752hs_set_bitrate()
324 /* set the max bitrate */ in saa6752hs_set_bitrate()
325 set_reg16(client, 0x81, params->vi_bitrate_peak); in saa6752hs_set_bitrate()
326 tot_bitrate = params->vi_bitrate_peak; in saa6752hs_set_bitrate()
328 /* set the target bitrate (no max bitrate for CBR) */ in saa6752hs_set_bitrate()
329 set_reg16(client, 0x81, params->vi_bitrate); in saa6752hs_set_bitrate()
330 tot_bitrate = params->vi_bitrate; in saa6752hs_set_bitrate()
335 params->au_encoding == V4L2_MPEG_AUDIO_ENCODING_AC3); in saa6752hs_set_bitrate()
337 /* set the audio bitrate */ in saa6752hs_set_bitrate()
338 if (params->au_encoding == V4L2_MPEG_AUDIO_ENCODING_AC3) in saa6752hs_set_bitrate()
339 is_384k = V4L2_MPEG_AUDIO_AC3_BITRATE_384K == params->au_ac3_bitrate; in saa6752hs_set_bitrate()
341 is_384k = V4L2_MPEG_AUDIO_L2_BITRATE_384K == params->au_l2_bitrate; in saa6752hs_set_bitrate()
345 /* Note: the total max bitrate is determined by adding the video and audio in saa6752hs_set_bitrate()
353 /* set the total bitrate */ in saa6752hs_set_bitrate()
361 container_of(ctrl->handler, struct saa6752hs_state, hdl); in saa6752hs_try_ctrl()
363 switch (ctrl->id) { in saa6752hs_try_ctrl()
365 /* peak bitrate shall be >= normal bitrate */ in saa6752hs_try_ctrl()
366 if (ctrl->val == V4L2_MPEG_VIDEO_BITRATE_MODE_VBR && in saa6752hs_try_ctrl()
367 h->video_bitrate_peak->val < h->video_bitrate->val) in saa6752hs_try_ctrl()
368 h->video_bitrate_peak->val = h->video_bitrate->val; in saa6752hs_try_ctrl()
377 container_of(ctrl->handler, struct saa6752hs_state, hdl); in saa6752hs_s_ctrl()
378 struct saa6752hs_mpeg_params *params = &h->params; in saa6752hs_s_ctrl()
380 switch (ctrl->id) { in saa6752hs_s_ctrl()
384 params->ts_pid_pmt = ctrl->val; in saa6752hs_s_ctrl()
387 params->ts_pid_audio = ctrl->val; in saa6752hs_s_ctrl()
390 params->ts_pid_video = ctrl->val; in saa6752hs_s_ctrl()
393 params->ts_pid_pcr = ctrl->val; in saa6752hs_s_ctrl()
396 params->au_encoding = ctrl->val; in saa6752hs_s_ctrl()
399 params->au_l2_bitrate = ctrl->val; in saa6752hs_s_ctrl()
402 params->au_ac3_bitrate = ctrl->val; in saa6752hs_s_ctrl()
409 params->vi_aspect = ctrl->val; in saa6752hs_s_ctrl()
412 params->vi_bitrate_mode = ctrl->val; in saa6752hs_s_ctrl()
413 params->vi_bitrate = h->video_bitrate->val / 1000; in saa6752hs_s_ctrl()
414 params->vi_bitrate_peak = h->video_bitrate_peak->val / 1000; in saa6752hs_s_ctrl()
415 v4l2_ctrl_activate(h->video_bitrate_peak, in saa6752hs_s_ctrl()
416 ctrl->val == V4L2_MPEG_VIDEO_BITRATE_MODE_VBR); in saa6752hs_s_ctrl()
419 return -EINVAL; in saa6752hs_s_ctrl()
434 /* Set video format - must be done first as it resets other settings */ in saa6752hs_init()
435 set_reg8(client, 0x41, h->video_format); in saa6752hs_init()
438 set_reg8(client, 0x40, (h->standard & V4L2_STD_525_60) ? 1 : 0); in saa6752hs_init()
440 /* set bitrate */ in saa6752hs_init()
446 /* Set minimum Q-scale {4} */ in saa6752hs_init()
449 /* Set maximum Q-scale {12} */ in saa6752hs_init()
463 localPAT[17] = 0xe0 | ((h->params.ts_pid_pmt >> 8) & 0x0f); in saa6752hs_init()
464 localPAT[18] = h->params.ts_pid_pmt & 0xff; in saa6752hs_init()
465 crc = crc32_be(~0, &localPAT[7], sizeof(PAT) - 7 - 4); in saa6752hs_init()
466 localPAT[sizeof(PAT) - 4] = (crc >> 24) & 0xFF; in saa6752hs_init()
467 localPAT[sizeof(PAT) - 3] = (crc >> 16) & 0xFF; in saa6752hs_init()
468 localPAT[sizeof(PAT) - 2] = (crc >> 8) & 0xFF; in saa6752hs_init()
469 localPAT[sizeof(PAT) - 1] = crc & 0xFF; in saa6752hs_init()
472 if (h->params.au_encoding == V4L2_MPEG_AUDIO_ENCODING_AC3) { in saa6752hs_init()
479 localPMT[3] = 0x40 | ((h->params.ts_pid_pmt >> 8) & 0x0f); in saa6752hs_init()
480 localPMT[4] = h->params.ts_pid_pmt & 0xff; in saa6752hs_init()
481 localPMT[15] = 0xE0 | ((h->params.ts_pid_pcr >> 8) & 0x0F); in saa6752hs_init()
482 localPMT[16] = h->params.ts_pid_pcr & 0xFF; in saa6752hs_init()
483 localPMT[20] = 0xE0 | ((h->params.ts_pid_video >> 8) & 0x0F); in saa6752hs_init()
484 localPMT[21] = h->params.ts_pid_video & 0xFF; in saa6752hs_init()
485 localPMT[25] = 0xE0 | ((h->params.ts_pid_audio >> 8) & 0x0F); in saa6752hs_init()
486 localPMT[26] = h->params.ts_pid_audio & 0xFF; in saa6752hs_init()
487 crc = crc32_be(~0, &localPMT[7], size - 7 - 4); in saa6752hs_init()
488 localPMT[size - 4] = (crc >> 24) & 0xFF; in saa6752hs_init()
489 localPMT[size - 3] = (crc >> 16) & 0xFF; in saa6752hs_init()
490 localPMT[size - 2] = (crc >> 8) & 0xFF; in saa6752hs_init()
491 localPMT[size - 1] = crc & 0xFF; in saa6752hs_init()
494 set_reg16(client, 0xc1, h->params.ts_pid_audio); in saa6752hs_init()
497 set_reg16(client, 0xc0, h->params.ts_pid_video); in saa6752hs_init()
500 set_reg16(client, 0xc4, h->params.ts_pid_pcr); in saa6752hs_init()
529 switch (h->params.vi_aspect) { in saa6752hs_init()
549 struct v4l2_mbus_framefmt *f = &format->format; in saa6752hs_get_fmt()
552 if (format->pad) in saa6752hs_get_fmt()
553 return -EINVAL; in saa6752hs_get_fmt()
555 if (h->video_format == SAA6752HS_VF_UNKNOWN) in saa6752hs_get_fmt()
556 h->video_format = SAA6752HS_VF_D1; in saa6752hs_get_fmt()
557 f->width = v4l2_format_table[h->video_format].fmt.pix.width; in saa6752hs_get_fmt()
558 f->height = v4l2_format_table[h->video_format].fmt.pix.height; in saa6752hs_get_fmt()
559 f->code = MEDIA_BUS_FMT_FIXED; in saa6752hs_get_fmt()
560 f->field = V4L2_FIELD_INTERLACED; in saa6752hs_get_fmt()
561 f->colorspace = V4L2_COLORSPACE_SMPTE170M; in saa6752hs_get_fmt()
569 struct v4l2_mbus_framefmt *f = &format->format; in saa6752hs_set_fmt()
573 if (format->pad) in saa6752hs_set_fmt()
574 return -EINVAL; in saa6752hs_set_fmt()
576 f->code = MEDIA_BUS_FMT_FIXED; in saa6752hs_set_fmt()
578 dist_352 = abs(f->width - 352); in saa6752hs_set_fmt()
579 dist_480 = abs(f->width - 480); in saa6752hs_set_fmt()
580 dist_720 = abs(f->width - 720); in saa6752hs_set_fmt()
582 f->width = 720; in saa6752hs_set_fmt()
583 f->height = 576; in saa6752hs_set_fmt()
585 f->width = 480; in saa6752hs_set_fmt()
586 f->height = 576; in saa6752hs_set_fmt()
588 f->width = 352; in saa6752hs_set_fmt()
589 if (abs(f->height - 576) < abs(f->height - 288)) in saa6752hs_set_fmt()
590 f->height = 576; in saa6752hs_set_fmt()
592 f->height = 288; in saa6752hs_set_fmt()
594 f->field = V4L2_FIELD_INTERLACED; in saa6752hs_set_fmt()
595 f->colorspace = V4L2_COLORSPACE_SMPTE170M; in saa6752hs_set_fmt()
597 if (format->which == V4L2_SUBDEV_FORMAT_TRY) in saa6752hs_set_fmt()
605 --------------------------- in saa6752hs_set_fmt()
612 if (f->code != MEDIA_BUS_FMT_FIXED) in saa6752hs_set_fmt()
613 return -EINVAL; in saa6752hs_set_fmt()
615 if (f->width == 720) in saa6752hs_set_fmt()
616 h->video_format = SAA6752HS_VF_D1; in saa6752hs_set_fmt()
617 else if (f->width == 480) in saa6752hs_set_fmt()
618 h->video_format = SAA6752HS_VF_2_3_D1; in saa6752hs_set_fmt()
619 else if (f->height == 576) in saa6752hs_set_fmt()
620 h->video_format = SAA6752HS_VF_1_2_D1; in saa6752hs_set_fmt()
622 h->video_format = SAA6752HS_VF_SIF; in saa6752hs_set_fmt()
630 h->standard = std; in saa6752hs_s_std()
634 /* ----------------------------------------------------------------------- */
669 client->addr << 1, client->adapter->name); in saa6752hs_probe()
671 h = devm_kzalloc(&client->dev, sizeof(*h), GFP_KERNEL); in saa6752hs_probe()
673 return -ENOMEM; in saa6752hs_probe()
674 sd = &h->sd; in saa6752hs_probe()
679 h->revision = (data[8] << 8) | data[9]; in saa6752hs_probe()
680 h->has_ac3 = 0; in saa6752hs_probe()
681 if (h->revision == 0x0206) { in saa6752hs_probe()
682 h->has_ac3 = 1; in saa6752hs_probe()
683 v4l_info(client, "supports AC-3\n"); in saa6752hs_probe()
685 h->params = param_defaults; in saa6752hs_probe()
687 hdl = &h->hdl; in saa6752hs_probe()
691 h->has_ac3 ? V4L2_MPEG_AUDIO_ENCODING_AC3 : in saa6752hs_probe()
702 if (h->has_ac3) in saa6752hs_probe()
727 h->video_bitrate_peak = v4l2_ctrl_new_std(hdl, &saa6752hs_ctrl_ops, in saa6752hs_probe()
737 h->video_bitrate_mode = v4l2_ctrl_new_std_menu(hdl, &saa6752hs_ctrl_ops, in saa6752hs_probe()
741 h->video_bitrate = v4l2_ctrl_new_std(hdl, &saa6752hs_ctrl_ops, in saa6752hs_probe()
744 V4L2_CID_MPEG_STREAM_PID_PMT, 0, (1 << 14) - 1, 1, 16); in saa6752hs_probe()
746 V4L2_CID_MPEG_STREAM_PID_AUDIO, 0, (1 << 14) - 1, 1, 260); in saa6752hs_probe()
748 V4L2_CID_MPEG_STREAM_PID_VIDEO, 0, (1 << 14) - 1, 1, 256); in saa6752hs_probe()
750 V4L2_CID_MPEG_STREAM_PID_PCR, 0, (1 << 14) - 1, 1, 259); in saa6752hs_probe()
751 sd->ctrl_handler = hdl; in saa6752hs_probe()
752 if (hdl->error) { in saa6752hs_probe()
753 int err = hdl->error; in saa6752hs_probe()
758 v4l2_ctrl_cluster(3, &h->video_bitrate_mode); in saa6752hs_probe()
760 h->standard = 0; /* Assume 625 input lines */ in saa6752hs_probe()
769 v4l2_ctrl_handler_free(&to_state(sd)->hdl); in saa6752hs_remove()