Lines Matching +full:0 +full:- +full:576

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)
41 SAA6752HS_VF_D1 = 0, /* standard D1 video format: 720x576 */
70 { .fmt = { .pix = { .width = 720, .height = 576 }}},
72 { .fmt = { .pix = { .width = 480, .height = 576 }}},
74 { .fmt = { .pix = { .width = 352, .height = 576 }}},
78 { .fmt = { .pix = { .width = 0, .height = 0}}},
97 SAA6752HS_COMMAND_RESET = 0,
113 /* ---------------------------------------------------------------------- */
116 0xc2, /* i2c register */
117 0x00, /* table number for encoder */
119 0x47, /* sync */
1200x40, 0x00, /* transport_error_indicator(0), payload_unit_start(1), transport_priority(0), pid(0) …
121 0x10, /* transport_scrambling_control(00), adaptation_field_control(01), continuity_counter(0) */
123 0x00, /* PSI pointer to start of table */
125 0x00, /* tid(0) */
126 0xb0, 0x0d, /* section_syntax_indicator(1), section_length(13) */
128 0x00, 0x01, /* transport_stream_id(1) */
130 0xc1, /* version_number(0), current_next_indicator(1) */
132 0x00, 0x00, /* section_number(0), last_section_number(0) */
134 0x00, 0x01, /* program_number(1) */
136 0xe0, 0x00, /* PMT PID */
138 0x00, 0x00, 0x00, 0x00 /* CRC32 */
142 0xc2, /* i2c register */
143 0x01, /* table number for encoder */
145 0x47, /* sync */
146 0x40, 0x00, /* transport_error_indicator(0), payload_unit_start(1), transport_priority(0), pid */
147 0x10, /* transport_scrambling_control(00), adaptation_field_control(01), continuity_counter(0) */
149 0x00, /* PSI pointer to start of table */
151 0x02, /* tid(2) */
152 0xb0, 0x17, /* section_syntax_indicator(1), section_length(23) */
154 0x00, 0x01, /* program_number(1) */
156 0xc1, /* version_number(0), current_next_indicator(1) */
158 0x00, 0x00, /* section_number(0), last_section_number(0) */
160 0xe0, 0x00, /* PCR_PID */
162 0xf0, 0x00, /* program_info_length(0) */
164 0x02, 0xe0, 0x00, 0xf0, 0x00, /* video stream type(2), pid */
165 0x04, 0xe0, 0x00, 0xf0, 0x00, /* audio stream type(4), pid */
167 0x00, 0x00, 0x00, 0x00 /* CRC32 */
171 0xc2, /* i2c register */
172 0x01, /* table number for encoder(1) */
173 0x47, /* sync */
175 0x40, /* transport_error_indicator(0), payload_unit_start(1), transport_priority(0) */
176 0x10, /* PMT PID (0x0010) */
177 0x10, /* transport_scrambling_control(00), adaptation_field_control(01), continuity_counter(0) */
179 0x00, /* PSI pointer to start of table */
181 0x02, /* TID (2) */
182 0xb0, 0x1a, /* section_syntax_indicator(1), section_length(26) */
184 0x00, 0x01, /* program_number(1) */
186 0xc1, /* version_number(0), current_next_indicator(1) */
188 0x00, 0x00, /* section_number(0), last_section_number(0) */
190 0xe1, 0x04, /* PCR_PID (0x0104) */
192 0xf0, 0x00, /* program_info_length(0) */
194 0x02, 0xe1, 0x00, 0xf0, 0x00, /* video stream type(2), pid */
195 0x06, 0xe1, 0x03, 0xf0, 0x03, /* audio stream type(6), pid */
196 0x6a, /* AC3 */
197 0x01, /* Descriptor_length(1) */
198 0x00, /* component_type_flag(0), bsid_flag(0), mainid_flag(0), asvc_flag(0), reserved flags(0) */
200 0xED, 0xDE, 0x2D, 0xF3 /* CRC32 BE */
220 /* ---------------------------------------------------------------------- */
227 int status = 0; in saa6752hs_chip_command()
232 buf[0] = 0x00; in saa6752hs_chip_command()
236 buf[0] = 0x03; in saa6752hs_chip_command()
240 buf[0] = 0x02; in saa6752hs_chip_command()
244 buf[0] = 0x04; in saa6752hs_chip_command()
248 buf[0] = 0x05; in saa6752hs_chip_command()
252 buf[0] = 0x06; in saa6752hs_chip_command()
256 buf[0] = 0x07; in saa6752hs_chip_command()
260 return -EINVAL; in saa6752hs_chip_command()
268 buf[0] = 0x10; in saa6752hs_chip_command()
272 if (!(buf[0] & 0x20)) in saa6752hs_chip_command()
275 status = -ETIMEDOUT; in saa6752hs_chip_command()
293 buf[0] = reg; in set_reg8()
302 buf[0] = reg; in set_reg16()
304 buf[2] = val & 0xff; in set_reg16()
311 struct saa6752hs_mpeg_params *params = &h->params; in saa6752hs_set_bitrate()
316 set_reg8(client, 0x71, in saa6752hs_set_bitrate()
317 params->vi_bitrate_mode != V4L2_MPEG_VIDEO_BITRATE_MODE_VBR); in saa6752hs_set_bitrate()
320 if (params->vi_bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_VBR) { in saa6752hs_set_bitrate()
322 set_reg16(client, 0x80, params->vi_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()
329 set_reg16(client, 0x81, params->vi_bitrate); in saa6752hs_set_bitrate()
330 tot_bitrate = params->vi_bitrate; in saa6752hs_set_bitrate()
334 set_reg8(client, 0x93, in saa6752hs_set_bitrate()
335 params->au_encoding == V4L2_MPEG_AUDIO_ENCODING_AC3); 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()
342 set_reg8(client, 0x94, is_384k); in saa6752hs_set_bitrate()
354 set_reg16(client, 0xb1, tot_bitrate); in saa6752hs_set_bitrate()
355 return 0; 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()
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()
371 return 0; 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()
421 return 0; 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()
444 set_reg16(client, 0x72, 0x030d); in saa6752hs_init()
446 /* Set minimum Q-scale {4} */ in saa6752hs_init()
447 set_reg8(client, 0x82, 0x04); in saa6752hs_init()
449 /* Set maximum Q-scale {12} */ in saa6752hs_init()
450 set_reg8(client, 0x83, 0x0c); in saa6752hs_init()
453 set_reg8(client, 0xd0, 0x81); in saa6752hs_init()
456 set_reg8(client, 0xb0, 0x05); in saa6752hs_init()
459 set_reg16(client, 0xf6, leading_null_bytes); 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()
507 set_reg8(client, 0xa4, 1); in saa6752hs_init()
508 set_reg8(client, 0xa4, 0); in saa6752hs_init()
514 buf[0] = 0xE1; in saa6752hs_init()
515 buf[1] = 0xA7; in saa6752hs_init()
516 buf[2] = 0xFE; in saa6752hs_init()
517 buf[3] = 0x82; in saa6752hs_init()
518 buf[4] = 0xB0; in saa6752hs_init()
523 buf[0] = 0xE0; in saa6752hs_init()
524 buf[1] = 0xA7; in saa6752hs_init()
525 buf[2] = 0xFE; in saa6752hs_init()
526 buf[3] = 0x82; in saa6752hs_init()
527 buf[4] = 0xB0; in saa6752hs_init()
528 buf[5] = buf2[0]; in saa6752hs_init()
529 switch (h->params.vi_aspect) { in saa6752hs_init()
531 buf[6] = buf2[1] | 0x40; in saa6752hs_init()
535 buf[6] = buf2[1] & 0xBF; in saa6752hs_init()
542 return 0; 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()
562 return 0; 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()
598 sd_state->pads->try_fmt = *f; in saa6752hs_set_fmt()
599 return 0; in saa6752hs_set_fmt()
607 --------------------------- in saa6752hs_set_fmt()
614 if (f->code != MEDIA_BUS_FMT_FIXED) in saa6752hs_set_fmt()
615 return -EINVAL; in saa6752hs_set_fmt()
617 if (f->width == 720) in saa6752hs_set_fmt()
618 h->video_format = SAA6752HS_VF_D1; in saa6752hs_set_fmt()
619 else if (f->width == 480) in saa6752hs_set_fmt()
620 h->video_format = SAA6752HS_VF_2_3_D1; in saa6752hs_set_fmt()
621 else if (f->height == 576) in saa6752hs_set_fmt()
622 h->video_format = SAA6752HS_VF_1_2_D1; in saa6752hs_set_fmt()
624 h->video_format = SAA6752HS_VF_SIF; in saa6752hs_set_fmt()
625 return 0; in saa6752hs_set_fmt()
632 h->standard = std; in saa6752hs_s_std()
633 return 0; in saa6752hs_s_std()
636 /* ----------------------------------------------------------------------- */
667 u8 addr = 0x13; in saa6752hs_probe()
670 v4l_info(client, "chip found @ 0x%x (%s)\n", in saa6752hs_probe()
671 client->addr << 1, client->adapter->name); in saa6752hs_probe()
673 h = devm_kzalloc(&client->dev, sizeof(*h), GFP_KERNEL); in saa6752hs_probe()
675 return -ENOMEM; in saa6752hs_probe()
676 sd = &h->sd; in saa6752hs_probe()
681 h->revision = (data[8] << 8) | data[9]; in saa6752hs_probe()
682 h->has_ac3 = 0; in saa6752hs_probe()
683 if (h->revision == 0x0206) { in saa6752hs_probe()
684 h->has_ac3 = 1; in saa6752hs_probe()
685 v4l_info(client, "supports AC-3\n"); in saa6752hs_probe()
687 h->params = param_defaults; in saa6752hs_probe()
689 hdl = &h->hdl; in saa6752hs_probe()
693 h->has_ac3 ? V4L2_MPEG_AUDIO_ENCODING_AC3 : in saa6752hs_probe()
695 0x0d, V4L2_MPEG_AUDIO_ENCODING_LAYER_2); in saa6752hs_probe()
704 if (h->has_ac3) in saa6752hs_probe()
726 V4L2_MPEG_VIDEO_ASPECT_16x9, 0x01, in saa6752hs_probe()
729 h->video_bitrate_peak = v4l2_ctrl_new_std(hdl, &saa6752hs_ctrl_ops, in saa6752hs_probe()
739 h->video_bitrate_mode = v4l2_ctrl_new_std_menu(hdl, &saa6752hs_ctrl_ops, in saa6752hs_probe()
741 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR, 0, in saa6752hs_probe()
743 h->video_bitrate = v4l2_ctrl_new_std(hdl, &saa6752hs_ctrl_ops, in saa6752hs_probe()
746 V4L2_CID_MPEG_STREAM_PID_PMT, 0, (1 << 14) - 1, 1, 16); in saa6752hs_probe()
748 V4L2_CID_MPEG_STREAM_PID_AUDIO, 0, (1 << 14) - 1, 1, 260); in saa6752hs_probe()
750 V4L2_CID_MPEG_STREAM_PID_VIDEO, 0, (1 << 14) - 1, 1, 256); in saa6752hs_probe()
752 V4L2_CID_MPEG_STREAM_PID_PCR, 0, (1 << 14) - 1, 1, 259); in saa6752hs_probe()
753 sd->ctrl_handler = hdl; in saa6752hs_probe()
754 if (hdl->error) { in saa6752hs_probe()
755 int err = hdl->error; in saa6752hs_probe()
760 v4l2_ctrl_cluster(3, &h->video_bitrate_mode); in saa6752hs_probe()
762 h->standard = 0; /* Assume 625 input lines */ in saa6752hs_probe()
763 return 0; in saa6752hs_probe()
771 v4l2_ctrl_handler_free(&to_state(sd)->hdl); in saa6752hs_remove()
775 { "saa6752hs", 0 },