Lines Matching +full:gain +full:- +full:scaling +full:- +full:n
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * saa717x - Philips SAA717xHL video decoder driver
8 * - Apply to SAA717x,NEC uPD64031,uPD64083. (1/31/2004)
10 * Changes by T.Adachi (tadachi@tadachi-net.com)
11 * - support audio, video scaler etc, and checked the initialize sequence.
27 #include <media/v4l2-device.h>
28 #include <media/v4l2-ctrls.h>
36 MODULE_PARM_DESC(debug, "Debug level (0-1)");
70 return &container_of(ctrl->handler, struct saa717x_state, hdl)->sd; in to_sd()
73 /* ----------------------------------------------------------------------- */
84 /* ----------------------------------------------------------------------- */
89 struct i2c_adapter *adap = client->adapter; in saa717x_write()
95 msg.addr = client->addr; in saa717x_write()
108 v4l2_dbg(2, debug, sd, "wrote: reg 0x%03x=%08x\n", reg, value); in saa717x_write()
123 struct i2c_adapter *adap = client->adapter; in saa717x_read()
132 msgs[0].addr = msgs[1].addr = client->addr; in saa717x_read()
146 v4l2_dbg(2, debug, sd, "read: reg 0x%03x=0x%08x\n", reg, value); in saa717x_read()
150 /* ----------------------------------------------------------------------- */
164 0x10f, 0x02a, /* Chroma gain control */
169 0x118, 0x040, /* RAW data gain */
186 0x068, 0x000, /* VBI horizontal scaling increment (L) TASK A */
187 0x069, 0x004, /* VBI horizontal scaling increment (H) TASK A */
209 0x0a8, 0x000, /* VBI horizontal scaling increment (L) TASK B */
210 0x0a9, 0x004, /* VBI horizontal scaling increment (H) TASK B */
222 0x010, 0x010, /* GREEN path gamma curve --- */
237 0x01f, 0x0ff, /* --- GREEN path gamma curve */
239 0x020, 0x010, /* BLUE path gamma curve --- */
254 0x02f, 0x0ff, /* --- BLUE path gamma curve */
256 0x030, 0x010, /* RED path gamma curve --- */
271 0x03f, 0x0ff, /* --- RED path gamma curve */
276 0x584, 0x000, /* AGC gain control */
295 0x46c, 0xbbbb10, /* Digital output selection1-3 */
296 0x470, 0x101010, /* Digital output selection4-6 */
639 /* S-Video */
652 7-4: DMA2, 3-0: DMA1 ch. DMA4, DMA3 DMA2, DMA1
663 7-4:DAC right ch. 3-0:DAC left ch.
721 v4l2_dbg(1, debug, sd, "tvaudio thread status: 0x%x [%s%s%s]\n", in get_inf_dev_status()
726 "%s#%s#%s#%s#%s#%s#%s#%s#%s#%s#%s#%s#%s#%s\n", in get_inf_dev_status()
746 v4l2_dbg(1, debug, sd, "ST!!!\n"); in get_inf_dev_status()
751 v4l2_dbg(1, debug, sd, "DUAL!!!\n"); in get_inf_dev_status()
759 v4l2_dbg(1, debug, sd, "writing registers to set audio mode by set %d\n", in set_audio_mode()
770 u8 mute = 0xac; /* -84 dB */ in set_audio_regs()
775 saa717x_write(sd, 0x0594, decoder->audio_input); in set_audio_regs()
776 v4l2_dbg(1, debug, sd, "set audio input %d\n", in set_audio_regs()
777 decoder->audio_input); in set_audio_regs()
779 /* normalize ( 65535 to 0 -> 24 to -40 (not -84)) */ in set_audio_regs()
780 work_l = (min(65536 - decoder->audio_main_balance, 32768) * decoder->audio_main_volume) / 32768; in set_audio_regs()
781 work_r = (min(decoder->audio_main_balance, (u16)32768) * decoder->audio_main_volume) / 32768; in set_audio_regs()
782 decoder->audio_main_vol_l = (long)work_l * (24 - (-40)) / 65535 - 40; in set_audio_regs()
783 decoder->audio_main_vol_r = (long)work_r * (24 - (-40)) / 65535 - 40; in set_audio_regs()
786 /* main volume L[7-0],R[7-0],0x00 24=24dB,-83dB, -84(mute) */ in set_audio_regs()
787 /* def:0dB->6dB(MPG600GR) */ in set_audio_regs()
789 if (decoder->audio_main_mute) { in set_audio_regs()
792 val = (u8)decoder->audio_main_vol_l | in set_audio_regs()
793 ((u8)decoder->audio_main_vol_r << 8); in set_audio_regs()
799 val = decoder->audio_main_bass & 0x1f; in set_audio_regs()
800 val |= (decoder->audio_main_treble & 0x1f) << 5; in set_audio_regs()
805 /********** scaling staff ***********/
850 /********** scaling staff ***********/
856 /* Vertical scaling ratio (LOW) */ in set_v_scale()
858 /* Vertical scaling ratio (HI) */ in set_v_scale()
867 switch (ctrl->id) { in saa717x_s_ctrl()
869 saa717x_write(sd, 0x10a, ctrl->val); in saa717x_s_ctrl()
873 saa717x_write(sd, 0x10b, ctrl->val); in saa717x_s_ctrl()
877 saa717x_write(sd, 0x10c, ctrl->val); in saa717x_s_ctrl()
881 saa717x_write(sd, 0x10d, ctrl->val); in saa717x_s_ctrl()
885 state->audio_main_mute = ctrl->val; in saa717x_s_ctrl()
889 state->audio_main_volume = ctrl->val; in saa717x_s_ctrl()
893 state->audio_main_balance = ctrl->val; in saa717x_s_ctrl()
897 state->audio_main_treble = ctrl->val; in saa717x_s_ctrl()
901 state->audio_main_bass = ctrl->val; in saa717x_s_ctrl()
919 v4l2_dbg(1, debug, sd, "decoder set input (%d)\n", input); in saa717x_s_video_routing()
920 /* inputs from 0-9 are available*/ in saa717x_s_video_routing()
921 /* saa717x have mode0-mode9 but mode5 is reserved. */ in saa717x_s_video_routing()
923 return -EINVAL; in saa717x_s_video_routing()
925 if (decoder->input != input) { in saa717x_s_video_routing()
928 decoder->input = input_line; in saa717x_s_video_routing()
929 v4l2_dbg(1, debug, sd, "now setting %s input %d\n", in saa717x_s_video_routing()
930 input_line >= 6 ? "S-Video" : "Composite", in saa717x_s_video_routing()
946 set_audio_mode(sd, decoder->tuner_audio_mode); in saa717x_s_video_routing()
949 * S-Video were chosen */ in saa717x_s_video_routing()
952 /* change initialize procedure (Composite/S-Video) */ in saa717x_s_video_routing()
967 reg->val = saa717x_read(sd, reg->reg); in saa717x_g_register()
968 reg->size = 1; in saa717x_g_register()
974 u16 addr = reg->reg & 0xffff; in saa717x_s_register()
975 u8 val = reg->val & 0xff; in saa717x_s_register()
986 struct v4l2_mbus_framefmt *fmt = &format->format; in saa717x_set_fmt()
989 v4l2_dbg(1, debug, sd, "decoder set size\n"); in saa717x_set_fmt()
991 if (format->pad || fmt->code != MEDIA_BUS_FMT_FIXED) in saa717x_set_fmt()
992 return -EINVAL; in saa717x_set_fmt()
995 if (fmt->width < 1 || fmt->width > 1440) in saa717x_set_fmt()
996 return -EINVAL; in saa717x_set_fmt()
997 if (fmt->height < 1 || fmt->height > 960) in saa717x_set_fmt()
998 return -EINVAL; in saa717x_set_fmt()
1000 fmt->field = V4L2_FIELD_INTERLACED; in saa717x_set_fmt()
1001 fmt->colorspace = V4L2_COLORSPACE_SMPTE170M; in saa717x_set_fmt()
1003 if (format->which == V4L2_SUBDEV_FORMAT_TRY) in saa717x_set_fmt()
1006 /* scaling setting */ in saa717x_set_fmt()
1008 prescale = SAA717X_NTSC_WIDTH / fmt->width; in saa717x_set_fmt()
1011 h_scale = 1024 * SAA717X_NTSC_WIDTH / prescale / fmt->width; in saa717x_set_fmt()
1013 v_scale = 512 * 2 * SAA717X_NTSC_HEIGHT / fmt->height; in saa717x_set_fmt()
1019 /* Horizontal scaling increment */ in saa717x_set_fmt()
1034 saa717x_write(sd, 0x5C, (u8)(fmt->width & 0xFF)); in saa717x_set_fmt()
1035 saa717x_write(sd, 0x5D, (u8)((fmt->width >> 8) & 0xFF)); in saa717x_set_fmt()
1037 saa717x_write(sd, 0x9C, (u8)(fmt->width & 0xFF)); in saa717x_set_fmt()
1038 saa717x_write(sd, 0x9D, (u8)((fmt->width >> 8) & 0xFF)); in saa717x_set_fmt()
1042 saa717x_write(sd, 0x5E, (u8)(fmt->height & 0xFF)); in saa717x_set_fmt()
1043 saa717x_write(sd, 0x5F, (u8)((fmt->height >> 8) & 0xFF)); in saa717x_set_fmt()
1045 saa717x_write(sd, 0x9E, (u8)(fmt->height & 0xFF)); in saa717x_set_fmt()
1046 saa717x_write(sd, 0x9F, (u8)((fmt->height >> 8) & 0xFF)); in saa717x_set_fmt()
1054 decoder->radio = 1; in saa717x_s_radio()
1063 v4l2_dbg(1, debug, sd, "(not yet implemented)\n"); in saa717x_s_std()
1065 decoder->radio = 0; in saa717x_s_std()
1066 decoder->std = std; in saa717x_s_std()
1075 if (input < 3) { /* FIXME! --tadachi */ in saa717x_s_audio_routing()
1076 decoder->audio_input = input; in saa717x_s_audio_routing()
1078 "set decoder audio input to %d\n", in saa717x_s_audio_routing()
1079 decoder->audio_input); in saa717x_s_audio_routing()
1083 return -ERANGE; in saa717x_s_audio_routing()
1090 v4l2_dbg(1, debug, sd, "decoder %s output\n", in saa717x_s_stream()
1092 decoder->enable = enable; in saa717x_s_stream()
1108 switch (vt->audmode) { in saa717x_s_tuner()
1123 v4l2_dbg(1, debug, sd, "change audio mode to %s\n", in saa717x_s_tuner()
1125 decoder->tuner_audio_mode = audio_mode; in saa717x_s_tuner()
1128 set_audio_mode(sd, decoder->tuner_audio_mode); in saa717x_s_tuner()
1137 if (decoder->radio) in saa717x_g_tuner()
1141 v4l2_dbg(1, debug, sd, "DETECT==st:%d dual:%d\n", in saa717x_g_tuner()
1146 vt->rxsubchans = V4L2_TUNER_SUB_MONO; in saa717x_g_tuner()
1147 v4l2_dbg(1, debug, sd, "DETECT==MONO\n"); in saa717x_g_tuner()
1152 if (vt->audmode == V4L2_TUNER_MODE_STEREO || in saa717x_g_tuner()
1153 vt->audmode == V4L2_TUNER_MODE_LANG1) { in saa717x_g_tuner()
1154 vt->rxsubchans = V4L2_TUNER_SUB_STEREO; in saa717x_g_tuner()
1155 v4l2_dbg(1, debug, sd, "DETECT==ST(ST)\n"); in saa717x_g_tuner()
1157 vt->rxsubchans = V4L2_TUNER_SUB_MONO; in saa717x_g_tuner()
1158 v4l2_dbg(1, debug, sd, "DETECT==ST(MONO)\n"); in saa717x_g_tuner()
1164 if (vt->audmode == V4L2_TUNER_MODE_LANG2) { in saa717x_g_tuner()
1165 vt->rxsubchans = V4L2_TUNER_SUB_LANG2 | V4L2_TUNER_SUB_MONO; in saa717x_g_tuner()
1166 v4l2_dbg(1, debug, sd, "DETECT==DUAL1\n"); in saa717x_g_tuner()
1168 vt->rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_MONO; in saa717x_g_tuner()
1169 v4l2_dbg(1, debug, sd, "DETECT==DUAL2\n"); in saa717x_g_tuner()
1179 v4l2_ctrl_handler_log_status(&state->hdl, sd->name); in saa717x_log_status()
1183 /* ----------------------------------------------------------------------- */
1225 /* ----------------------------------------------------------------------- */
1230 /* ----------------------------------------------------------------------- */
1240 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) in saa717x_probe()
1241 return -EIO; in saa717x_probe()
1243 decoder = devm_kzalloc(&client->dev, sizeof(*decoder), GFP_KERNEL); in saa717x_probe()
1245 return -ENOMEM; in saa717x_probe()
1247 sd = &decoder->sd; in saa717x_probe()
1256 v4l2_dbg(1, debug, sd, "saa717x not found (id=%02x)\n", id); in saa717x_probe()
1257 return -ENODEV; in saa717x_probe()
1267 v4l2_info(sd, "%s found @ 0x%x (%s)\n", p, in saa717x_probe()
1268 client->addr << 1, client->adapter->name); in saa717x_probe()
1270 hdl = &decoder->hdl; in saa717x_probe()
1280 V4L2_CID_HUE, -128, 127, 1, 0); in saa717x_probe()
1286 V4L2_CID_AUDIO_BASS, -16, 15, 1, 0); in saa717x_probe()
1288 V4L2_CID_AUDIO_TREBLE, -16, 15, 1, 0); in saa717x_probe()
1291 sd->ctrl_handler = hdl; in saa717x_probe()
1292 if (hdl->error) { in saa717x_probe()
1293 int err = hdl->error; in saa717x_probe()
1299 decoder->std = V4L2_STD_NTSC; in saa717x_probe()
1300 decoder->input = -1; in saa717x_probe()
1301 decoder->enable = 1; in saa717x_probe()
1304 decoder->playback = 0; /* initially capture mode used */ in saa717x_probe()
1305 decoder->audio = 1; /* DECODER_AUDIO_48_KHZ */ in saa717x_probe()
1307 decoder->audio_input = 2; /* FIXME!! */ in saa717x_probe()
1309 decoder->tuner_audio_mode = TUNER_AUDIO_STEREO; in saa717x_probe()
1311 decoder->audio_main_vol_l = 6; in saa717x_probe()
1312 decoder->audio_main_vol_r = 6; in saa717x_probe()
1314 v4l2_dbg(1, debug, sd, "writing init values\n"); in saa717x_probe()
1331 v4l2_ctrl_handler_free(sd->ctrl_handler); in saa717x_remove()
1334 /* ----------------------------------------------------------------------- */