32 u32 reg = 0xc40000 + (addr & ~3);
34 int shift = (addr & 3) * 8;
35 u32 x = cx18_read_reg(cx, reg);
37 x = (x & ~(mask << shift)) | ((
u32)value << shift);
38 cx18_write_reg(cx, x, reg);
44 u32 reg = 0xc40000 + (addr & ~3);
45 int shift = (addr & 3) * 8;
46 u32 x = cx18_read_reg(cx, reg);
48 x = (x & ~((
u32)0xff << shift)) | ((
u32)value << shift);
49 cx18_write_reg_expect(cx, x, reg,
50 ((
u32)eval << shift), ((
u32)mask << shift));
56 cx18_write_reg(cx, value, 0xc40000 + addr);
63 cx18_write_reg_expect(cx, value, 0xc40000 + addr, eval, mask);
69 cx18_write_reg_noretry(cx, value, 0xc40000 + addr);
75 u32 x = cx18_read_reg(cx, 0xc40000 + (addr & ~3));
76 int shift = (addr & 3) * 8;
78 return (x >> shift) & 0xff;
83 return cx18_read_reg(cx, 0xc40000 + addr);
102 static void cx18_av_init(
struct cx18 *cx)
131 struct cx18 *cx = v4l2_get_subdevdata(sd);
138 0x03000000, 0x13000000);
169 v & 0xFFFFFFFE, v & 0xFFFFFFFE, 0x03009F0F);
256 if (default_volume > 228) {
258 default_volume = 228;
260 }
else if (default_volume < 20) {
265 default_volume = (((228 - default_volume) >> 1) + 23) << 9;
266 state->
volume->cur.val = state->
volume->default_value = default_volume;
272 cx18_av_initialize(sd);
283 cx18_av_initialize(sd);
298 const int src_decimation = 0x21f;
300 int hblank, hactive, burst, vblank, vactive,
sc;
302 int luma_lpf, uv_lpf, comb;
303 u32 pll_int, pll_frac, pll_post;
459 pll_int, pll_frac, pll_post);
465 pll = (28636360
L * ((((
u64)pll_int) << 25) + pll_frac)) >> 25;
468 pll / 1000000, pll % 1000000);
470 pll / 8000000, (pll / 8) % 1000000);
473 "= %d.%03d\n", src_decimation / 256,
474 ((src_decimation % 256) * 1000) / 256);
476 tmp = 28636360 * (
u64) sc;
477 do_div(tmp, src_decimation);
480 "Chroma sub-carrier initial freq = %d.%06d "
481 "MHz\n", fsc / 1000000, fsc % 1000000);
484 "vactive %i, vblank656 %i, src_dec %i, "
485 "burst 0x%02x, luma_lpf %i, uv_lpf %i, "
486 "comb 0x%02x, sc 0x%06x\n",
487 hblank, hactive, vblank, vactive, vblank656,
488 src_decimation, burst, luma_lpf, uv_lpf,
513 cx18_av_write(cx, 0x47a, luma_lpf << 6 | ((uv_lpf << 4) & 0x30));
523 if (std & V4L2_STD_625_50) {
533 static void input_change(
struct cx18 *cx)
578 static int cx18_av_s_frequency(
struct v4l2_subdev *sd,
581 struct cx18 *cx = v4l2_get_subdevdata(sd);
592 enum analog_signal_type {
593 NONE, CVBS, Y,
C, SIF, Pb, Pr
603 vid_input, aud_input);
611 int luma = vid_input & 0xf000;
612 int r_chroma = vid_input & 0xf0000;
613 int b_chroma = vid_input & 0xf00000;
615 if ((vid_input & ~0xfff000) ||
622 CX18_ERR_DEV(sd,
"0x%06x is not a valid video input!\n",
634 int luma = vid_input & 0xf0;
635 int chroma = vid_input & 0xf00;
637 if ((vid_input & ~0xff0) ||
642 CX18_ERR_DEV(sd,
"0x%06x is not a valid video input!\n",
666 afe_mux_cfg &= ~0x30;
670 afe_mux_cfg = (afe_mux_cfg & ~0x30) | 0x10;
674 afe_mux_cfg = (afe_mux_cfg & ~0x30) | 0x20;
678 afe_mux_cfg &= ~0xc0;
682 afe_mux_cfg = (afe_mux_cfg & ~0xc0) | 0x40;
687 CX18_ERR_DEV(sd,
"0x%04x is not a valid audio input!\n",
713 afe_cfg &= 0xff000000;
714 afe_cfg |= 0x00005000;
716 afe_cfg |= 0x00000030;
718 for (i = 0; i < 3; i++) {
723 afe_cfg |= (0x00000200 <<
i);
728 afe_cfg |= 0x00002000;
734 afe_cfg |= (0x00000200 <<
i);
735 if (i == 0 && ch[i] ==
C)
736 afe_cfg &= ~0x00001000;
743 afe_cfg |= (0x00000240 <<
i);
745 afe_cfg &= ~0x00004000;
759 static int cx18_av_s_video_routing(
struct v4l2_subdev *sd,
763 struct cx18 *cx = v4l2_get_subdevdata(sd);
764 return set_input(cx, input, state->
aud_input);
767 static int cx18_av_s_audio_routing(
struct v4l2_subdev *sd,
771 struct cx18 *cx = v4l2_get_subdevdata(sd);
772 return set_input(cx, state->
vid_input, input);
778 struct cx18 *cx = v4l2_get_subdevdata(sd);
787 vt->
signal = vpres ? 0xffff : 0x0;
796 if ((mode & 0xf) == 1)
801 if (mode == 2 || mode == 4)
815 struct cx18 *cx = v4l2_get_subdevdata(sd);
860 struct cx18 *cx = v4l2_get_subdevdata(sd);
865 if (state->
radio == 0 && state->
std == norm)
889 else if (state->
std & V4L2_STD_PAL)
891 else if (state->
std & V4L2_STD_SECAM)
900 if (fmt >= 4 && fmt < 8) {
923 struct cx18 *cx = v4l2_get_subdevdata(sd);
949 static int cx18_av_s_mbus_fmt(
struct v4l2_subdev *sd,
struct v4l2_mbus_framefmt *fmt)
952 struct cx18 *cx = v4l2_get_subdevdata(sd);
953 int HSC, VSC, Vsrc, Hsrc,
filter, Vlines;
975 Vlines = fmt->height + (is_50Hz ? 3 : 1);
984 if ((fmt->width * 16 < Hsrc) || (Hsrc < fmt->width) ||
985 (Vlines * 8 < Vsrc) || (Vsrc < Vlines)) {
987 fmt->width, fmt->height);
991 HSC = (Hsrc * (1 << 20)) / fmt->width - (1 << 20);
992 VSC = (1 << 16) - (Vsrc * (1 << 9) / Vlines - (1 << 9));
995 if (fmt->width >= 385)
997 else if (fmt->width > 192)
999 else if (fmt->width > 96)
1005 "decoder set size %dx%d -> scale %ux%u\n",
1006 fmt->width, fmt->height, HSC, VSC);
1022 struct cx18 *cx = v4l2_get_subdevdata(sd);
1035 static void log_video_status(
struct cx18 *cx)
1037 static const char *
const fmt_strs[] = {
1039 "NTSC-M",
"NTSC-J",
"NTSC-4.43",
1040 "PAL-BDGHI",
"PAL-M",
"PAL-N",
"PAL-Nc",
"PAL-60",
1041 "0x9",
"0xA",
"0xB",
1054 (gen_stat2 & 0x20) ?
"" :
"not ");
1056 fmt_strs[gen_stat1 & 0xf]);
1059 vidfmt_sel ? fmt_strs[vidfmt_sel]
1060 :
"automatic detection");
1068 "S-Video (Luma In%d, Chroma In%d)\n",
1069 (vid_input & 0xf0) >> 4,
1070 (vid_input & 0xf00) >> 8);
1077 static void log_audio_status(
struct cx18 *cx)
1091 switch (mod_det_stat0) {
1092 case 0x00: p =
"mono";
break;
1093 case 0x01: p =
"stereo";
break;
1094 case 0x02: p =
"dual";
break;
1095 case 0x04: p =
"tri";
break;
1096 case 0x10: p =
"mono with SAP";
break;
1097 case 0x11: p =
"stereo with SAP";
break;
1098 case 0x12: p =
"dual with SAP";
break;
1099 case 0x14: p =
"tri with SAP";
break;
1100 case 0xfe: p =
"forced mode";
break;
1101 default: p =
"not defined";
break;
1105 switch (mod_det_stat1) {
1106 case 0x00: p =
"not defined";
break;
1107 case 0x01: p =
"EIAJ";
break;
1108 case 0x02: p =
"A2-M";
break;
1109 case 0x03: p =
"A2-BG";
break;
1110 case 0x04: p =
"A2-DK1";
break;
1111 case 0x05: p =
"A2-DK2";
break;
1112 case 0x06: p =
"A2-DK3";
break;
1113 case 0x07: p =
"A1 (6.0 MHz FM Mono)";
break;
1114 case 0x08: p =
"AM-L";
break;
1115 case 0x09: p =
"NICAM-BG";
break;
1116 case 0x0a: p =
"NICAM-DK";
break;
1117 case 0x0b: p =
"NICAM-I";
break;
1118 case 0x0c: p =
"NICAM-L";
break;
1119 case 0x0d: p =
"BTSC/EIAJ/A2-M Mono (4.5 MHz FMMono)";
break;
1120 case 0x0e: p =
"IF FM Radio";
break;
1121 case 0x0f: p =
"BTSC";
break;
1122 case 0x10: p =
"detected chrominance";
break;
1123 case 0xfd: p =
"unknown audio standard";
break;
1124 case 0xfe: p =
"forced audio standard";
break;
1125 case 0xff: p =
"no detected audio standard";
break;
1126 default: p =
"not defined";
break;
1130 (mute_ctl & 0x2) ?
"yes" :
"no");
1132 (download_ctl & 0x10) ?
"running" :
"stopped");
1134 switch (audio_config >> 4) {
1135 case 0x00: p =
"undefined";
break;
1136 case 0x01: p =
"BTSC";
break;
1137 case 0x02: p =
"EIAJ";
break;
1138 case 0x03: p =
"A2-M";
break;
1139 case 0x04: p =
"A2-BG";
break;
1140 case 0x05: p =
"A2-DK1";
break;
1141 case 0x06: p =
"A2-DK2";
break;
1142 case 0x07: p =
"A2-DK3";
break;
1143 case 0x08: p =
"A1 (6.0 MHz FM Mono)";
break;
1144 case 0x09: p =
"AM-L";
break;
1145 case 0x0a: p =
"NICAM-BG";
break;
1146 case 0x0b: p =
"NICAM-DK";
break;
1147 case 0x0c: p =
"NICAM-I";
break;
1148 case 0x0d: p =
"NICAM-L";
break;
1149 case 0x0e: p =
"FM radio";
break;
1150 case 0x0f: p =
"automatic detection";
break;
1151 default: p =
"undefined";
break;
1155 if ((audio_config >> 4) < 0xF) {
1156 switch (audio_config & 0xF) {
1157 case 0x00: p =
"MONO1 (LANGUAGE A/Mono L+R channel for BTSC, EIAJ, A2)";
break;
1158 case 0x01: p =
"MONO2 (LANGUAGE B)";
break;
1159 case 0x02: p =
"MONO3 (STEREO forced MONO)";
break;
1160 case 0x03: p =
"MONO4 (NICAM ANALOG-Language C/Analog Fallback)";
break;
1161 case 0x04: p =
"STEREO";
break;
1162 case 0x05: p =
"DUAL1 (AC)";
break;
1163 case 0x06: p =
"DUAL2 (BC)";
break;
1164 case 0x07: p =
"DUAL3 (AB)";
break;
1165 default: p =
"undefined";
1169 switch (audio_config & 0xF) {
1170 case 0x00: p =
"BG";
break;
1171 case 0x01: p =
"DK1";
break;
1172 case 0x02: p =
"DK2";
break;
1173 case 0x03: p =
"DK3";
break;
1174 case 0x04: p =
"I";
break;
1175 case 0x05: p =
"L";
break;
1176 case 0x06: p =
"BTSC";
break;
1177 case 0x07: p =
"EIAJ";
break;
1178 case 0x08: p =
"A2-M";
break;
1179 case 0x09: p =
"FM Radio (4.5 MHz)";
break;
1180 case 0x0a: p =
"FM Radio (5.5 MHz)";
break;
1181 case 0x0b: p =
"S-Video";
break;
1182 case 0x0f: p =
"automatic standard and mode detection";
break;
1183 default: p =
"undefined";
break;
1194 switch (pref_mode & 0xf) {
1195 case 0: p =
"mono/language A";
break;
1196 case 1: p =
"language B";
break;
1197 case 2: p =
"language C";
break;
1198 case 3: p =
"analog fallback";
break;
1199 case 4: p =
"stereo";
break;
1200 case 5: p =
"language AC";
break;
1201 case 6: p =
"language BC";
break;
1202 case 7: p =
"language AB";
break;
1203 default: p =
"undefined";
break;
1207 if ((audio_config & 0xf) == 0xf) {
1208 switch ((afc0 >> 3) & 0x1) {
1209 case 0: p =
"system DK";
break;
1210 case 1: p =
"system L";
break;
1214 switch (afc0 & 0x7) {
1215 case 0: p =
"Chroma";
break;
1216 case 1: p =
"BTSC";
break;
1217 case 2: p =
"EIAJ";
break;
1218 case 3: p =
"A2-M";
break;
1219 case 4: p =
"autodetect";
break;
1220 default: p =
"undefined";
break;
1226 static int cx18_av_log_status(
struct v4l2_subdev *sd)
1228 struct cx18 *cx = v4l2_get_subdevdata(sd);
1229 log_video_status(cx);
1230 log_audio_status(cx);
1239 static int cx18_av_g_chip_ident(
struct v4l2_subdev *sd,
1244 if (cx18_av_dbg_match(&chip->
match)) {
1251 #ifdef CONFIG_VIDEO_ADV_DEBUG
1252 static int cx18_av_g_register(
struct v4l2_subdev *sd,
1255 struct cx18 *cx = v4l2_get_subdevdata(sd);
1257 if (!cx18_av_dbg_match(®->
match))
1259 if ((reg->
reg & 0x3) != 0)
1268 static int cx18_av_s_register(
struct v4l2_subdev *sd,
1271 struct cx18 *cx = v4l2_get_subdevdata(sd);
1273 if (!cx18_av_dbg_match(®->
match))
1275 if ((reg->
reg & 0x3) != 0)
1285 .s_ctrl = cx18_av_s_ctrl,
1289 .g_chip_ident = cx18_av_g_chip_ident,
1290 .log_status = cx18_av_log_status,
1291 .load_fw = cx18_av_load_fw,
1292 .reset = cx18_av_reset,
1300 .s_std = cx18_av_s_std,
1301 #ifdef CONFIG_VIDEO_ADV_DEBUG
1302 .g_register = cx18_av_g_register,
1303 .s_register = cx18_av_s_register,
1308 .s_radio = cx18_av_s_radio,
1309 .s_frequency = cx18_av_s_frequency,
1310 .g_tuner = cx18_av_g_tuner,
1311 .s_tuner = cx18_av_s_tuner,
1316 .s_routing = cx18_av_s_audio_routing,
1320 .s_routing = cx18_av_s_video_routing,
1321 .s_stream = cx18_av_s_stream,
1322 .s_mbus_fmt = cx18_av_s_mbus_fmt,
1333 .core = &cx18_av_general_ops,
1334 .tuner = &cx18_av_tuner_ops,
1335 .audio = &cx18_av_audio_ops,
1336 .video = &cx18_av_video_ops,
1337 .vbi = &cx18_av_vbi_ops,
1359 v4l2_set_subdevdata(sd, cx);
1375 0, 65535, 65535 / 100, 0);
1381 0, 65535, 65535 / 100, 32768);
1384 0, 65535, 65535 / 100, 32768);
1387 0, 65535, 65535 / 100, 32768);
1389 if (state->
hdl.error) {
1390 int err = state->
hdl.error;