25 #include <linux/module.h>
26 #include <linux/kernel.h>
27 #include <linux/string.h>
30 #include <linux/errno.h>
31 #include <linux/slab.h>
32 #include <linux/poll.h>
33 #include <linux/i2c.h>
34 #include <linux/types.h>
35 #include <linux/videodev2.h>
42 #define MPEG_VIDEO_TARGET_BITRATE_MAX 27000
43 #define MPEG_VIDEO_MAX_BITRATE_MAX 27000
44 #define MPEG_TOTAL_TARGET_BITRATE_MAX 27000
45 #define MPEG_PID_MAX ((1 << 14) - 1)
79 static const struct v4l2_format v4l2_format_table[] =
82 { .fmt = { .pix = { .width = 720, .height = 576 }}},
84 { .fmt = { .pix = { .width = 480, .height = 576 }}},
86 { .fmt = { .pix = { .width = 352, .height = 576 }}},
88 { .fmt = { .pix = { .width = 352, .height = 288 }}},
90 { .fmt = { .pix = { .width = 0, .height = 0}}},
145 0x00, 0x00, 0x00, 0x00
171 0x02, 0xe0, 0x00, 0xf0, 0x00,
172 0x04, 0xe0, 0x00, 0xf0, 0x00,
174 0x00, 0x00, 0x00, 0x00
177 static u8 PMT_AC3[] = {
201 0x02, 0xe1, 0x00, 0xf0, 0x00,
202 0x06, 0xe1, 0x03, 0xf0, 0x03,
207 0xED, 0xDE, 0x2D, 0xF3
219 .vi_bitrate_peak = 6000,
232 unsigned char buf[3];
279 if (!(buf[0] & 0x20))
315 static int saa6752hs_set_bitrate(
struct i2c_client *client,
323 set_reg8(client, 0x71,
341 set_reg8(client, 0x93,
349 set_reg8(client, 0x94, is_384k);
350 tot_bitrate += is_384k ? 384 : 256;
361 set_reg16(client, 0xb1, tot_bitrate);
429 if (
set &&
new != old)
498 if (
set &&
new != old)
504 if (
set &&
new != old)
519 new = 1000 * (
new / 1000);
528 new = 1000 * (
new / 1000);
559 1, V4L2_MPEG_AUDIO_ENCODING_LAYER_2);
631 static const u32 mpeg_audio_encoding[] = {
635 static const u32 mpeg_audio_ac3_encoding[] = {
640 static u32 mpeg_audio_l2_bitrate[] = {
645 static u32 mpeg_audio_ac3_bitrate[] = {
654 qctrl.
id = qmenu->
id;
655 err = saa6752hs_queryctrl(sd, &qctrl);
661 mpeg_audio_l2_bitrate);
666 mpeg_audio_ac3_bitrate);
669 h->
has_ac3 ? mpeg_audio_ac3_encoding :
670 mpeg_audio_encoding);
675 static int saa6752hs_init(
struct v4l2_subdev *sd,
u32 leading_null_bytes)
677 unsigned char buf[9], buf2[4];
679 struct i2c_client *client = v4l2_get_subdevdata(sd);
682 unsigned char localPAT[256];
683 unsigned char localPMT[256];
692 saa6752hs_set_bitrate(client, h);
695 set_reg16(client, 0x72, 0x030d);
698 set_reg8(client, 0x82, 0x04);
701 set_reg8(client, 0x83, 0x0c);
704 set_reg8(client, 0xd0, 0x81);
707 set_reg8(client, 0xb0, 0x05);
710 set_reg16(client, 0xf6, leading_null_bytes);
714 localPAT[17] = 0xe0 | ((h->
params.ts_pid_pmt >> 8) & 0x0f);
715 localPAT[18] = h->
params.ts_pid_pmt & 0xff;
716 crc =
crc32_be(~0, &localPAT[7],
sizeof(
PAT) - 7 - 4);
717 localPAT[
sizeof(
PAT) - 4] = (crc >> 24) & 0xFF;
718 localPAT[
sizeof(
PAT) - 3] = (crc >> 16) & 0xFF;
719 localPAT[
sizeof(
PAT) - 2] = (crc >> 8) & 0xFF;
720 localPAT[
sizeof(
PAT) - 1] = crc & 0xFF;
724 size =
sizeof(PMT_AC3);
725 memcpy(localPMT, PMT_AC3, size);
728 memcpy(localPMT, PMT, size);
730 localPMT[3] = 0x40 | ((h->
params.ts_pid_pmt >> 8) & 0x0f);
731 localPMT[4] = h->
params.ts_pid_pmt & 0xff;
732 localPMT[15] = 0xE0 | ((h->
params.ts_pid_pcr >> 8) & 0x0F);
733 localPMT[16] = h->
params.ts_pid_pcr & 0xFF;
734 localPMT[20] = 0xE0 | ((h->
params.ts_pid_video >> 8) & 0x0F);
735 localPMT[21] = h->
params.ts_pid_video & 0xFF;
736 localPMT[25] = 0xE0 | ((h->
params.ts_pid_audio >> 8) & 0x0F);
737 localPMT[26] = h->
params.ts_pid_audio & 0xFF;
738 crc =
crc32_be(~0, &localPMT[7], size - 7 - 4);
739 localPMT[size - 4] = (crc >> 24) & 0xFF;
740 localPMT[size - 3] = (crc >> 16) & 0xFF;
741 localPMT[size - 2] = (crc >> 8) & 0xFF;
742 localPMT[size - 1] = crc & 0xFF;
745 set_reg16(client, 0xc1, h->
params.ts_pid_audio);
748 set_reg16(client, 0xc0, h->
params.ts_pid_video);
751 set_reg16(client, 0xc4, h->
params.ts_pid_pcr);
758 set_reg8(client, 0xa4, 1);
759 set_reg8(client, 0xa4, 0);
780 switch (h->
params.vi_aspect) {
782 buf[6] = buf2[1] | 0x40;
786 buf[6] = buf2[1] & 0xBF;
806 for (i = 0; i < ctrls->
count; i++) {
821 return saa6752hs_do_ext_ctrls(sd, ctrls, 1);
826 return saa6752hs_do_ext_ctrls(sd, ctrls, 0);
837 for (i = 0; i < ctrls->
count; i++) {
848 static int saa6752hs_g_mbus_fmt(
struct v4l2_subdev *sd,
struct v4l2_mbus_framefmt *
f)
862 static int saa6752hs_s_mbus_fmt(
struct v4l2_subdev *sd,
struct v4l2_mbus_framefmt *f)
865 int dist_352, dist_480, dist_720;
882 dist_352 =
abs(f->width - 352);
883 dist_480 =
abs(f->width - 480);
884 dist_720 =
abs(f->width - 720);
885 if (dist_720 < dist_480) {
889 }
else if (dist_480 < dist_352) {
895 if (
abs(f->height - 576) <
896 abs(f->height - 288)) {
919 struct i2c_client *client = v4l2_get_subdevdata(sd);
929 .g_chip_ident = saa6752hs_g_chip_ident,
930 .init = saa6752hs_init,
931 .queryctrl = saa6752hs_queryctrl,
932 .querymenu = saa6752hs_querymenu,
933 .g_ext_ctrls = saa6752hs_g_ext_ctrls,
934 .s_ext_ctrls = saa6752hs_s_ext_ctrls,
935 .try_ext_ctrls = saa6752hs_try_ext_ctrls,
936 .s_std = saa6752hs_s_std,
940 .s_mbus_fmt = saa6752hs_s_mbus_fmt,
941 .g_mbus_fmt = saa6752hs_g_mbus_fmt,
945 .core = &saa6752hs_core_ops,
946 .video = &saa6752hs_video_ops,
949 static int saa6752hs_probe(
struct i2c_client *client,
957 v4l_info(client,
"chip found @ 0x%x (%s)\n",
967 h->
revision = (data[8] << 8) | data[9];
974 h->
params = param_defaults;
979 static int saa6752hs_remove(
struct i2c_client *client)
981 struct v4l2_subdev *sd = i2c_get_clientdata(client);
999 .probe = saa6752hs_probe,
1000 .remove = saa6752hs_remove,
1001 .id_table = saa6752hs_id,