Lines Matching +full:static +full:- +full:enable

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * saa7127 - Philips SAA7127/SAA7129 video encoder driver
9 * Copyright (C) 2000-2001 Gillem <htoa@gmx.net>
12 * Based on Stadis 4:2:2 MPEG-2 Decoder Driver by Nathan Laredo
32 * macrovision anti-taping support. This driver will almost certainly
33 * work fine for those chips, except of course for the missing anti-taping
43 #include <media/v4l2-device.h>
46 static int debug;
47 static int test_image;
54 MODULE_PARM_DESC(debug, "debug level (0-2)");
55 MODULE_PARM_DESC(test_image, "test_image (0-1)");
125 static const struct i2c_reg_value saa7129_init_config_extra[] = {
131 static const struct i2c_reg_value saa7127_init_config_common[] = {
136 { SAA7127_REG_COPYGEN_2, 0x00 }, /* Macrovision enable/disable */
167 static const struct i2c_reg_value saa7127_init_config_60hz[] = {
189 static struct i2c_reg_value saa7127_init_config_50hz_pal[] = {
211 static struct i2c_reg_value saa7127_init_config_50hz_secam[] = {
266 static inline struct saa7127_state *to_state(struct v4l2_subdev *sd) in to_state()
271 static const char * const output_strs[] =
273 "S-Video + Composite",
275 "S-Video",
281 static const char * const wss_strs[] = {
300 /* ----------------------------------------------------------------------- */
302 static int saa7127_read(struct v4l2_subdev *sd, u8 reg) in saa7127_read()
309 /* ----------------------------------------------------------------------- */
311 static int saa7127_write(struct v4l2_subdev *sd, u8 reg, u8 val) in saa7127_write()
321 return -1; in saa7127_write()
324 /* ----------------------------------------------------------------------- */
326 static int saa7127_write_inittab(struct v4l2_subdev *sd, in saa7127_write_inittab()
329 while (regs->reg != 0) { in saa7127_write_inittab()
330 saa7127_write(sd, regs->reg, regs->value); in saa7127_write_inittab()
336 /* ----------------------------------------------------------------------- */
338 static int saa7127_set_vps(struct v4l2_subdev *sd, const struct v4l2_sliced_vbi_data *data) in saa7127_set_vps()
341 int enable = (data->line != 0); in saa7127_set_vps() local
343 if (enable && (data->field != 0 || data->line != 16)) in saa7127_set_vps()
344 return -EINVAL; in saa7127_set_vps()
345 if (state->vps_enable != enable) { in saa7127_set_vps()
346 v4l2_dbg(1, debug, sd, "Turn VPS Signal %s\n", enable ? "on" : "off"); in saa7127_set_vps()
347 saa7127_write(sd, 0x54, enable << 7); in saa7127_set_vps()
348 state->vps_enable = enable; in saa7127_set_vps()
350 if (!enable) in saa7127_set_vps()
353 state->vps_data[0] = data->data[2]; in saa7127_set_vps()
354 state->vps_data[1] = data->data[8]; in saa7127_set_vps()
355 state->vps_data[2] = data->data[9]; in saa7127_set_vps()
356 state->vps_data[3] = data->data[10]; in saa7127_set_vps()
357 state->vps_data[4] = data->data[11]; in saa7127_set_vps()
358 v4l2_dbg(1, debug, sd, "Set VPS data %*ph\n", 5, state->vps_data); in saa7127_set_vps()
359 saa7127_write(sd, 0x55, state->vps_data[0]); in saa7127_set_vps()
360 saa7127_write(sd, 0x56, state->vps_data[1]); in saa7127_set_vps()
361 saa7127_write(sd, 0x57, state->vps_data[2]); in saa7127_set_vps()
362 saa7127_write(sd, 0x58, state->vps_data[3]); in saa7127_set_vps()
363 saa7127_write(sd, 0x59, state->vps_data[4]); in saa7127_set_vps()
367 /* ----------------------------------------------------------------------- */
369 static int saa7127_set_cc(struct v4l2_subdev *sd, const struct v4l2_sliced_vbi_data *data) in saa7127_set_cc()
372 u16 cc = data->data[1] << 8 | data->data[0]; in saa7127_set_cc()
373 int enable = (data->line != 0); in saa7127_set_cc() local
375 if (enable && (data->field != 0 || data->line != 21)) in saa7127_set_cc()
376 return -EINVAL; in saa7127_set_cc()
377 if (state->cc_enable != enable) { in saa7127_set_cc()
379 "Turn CC %s\n", enable ? "on" : "off"); in saa7127_set_cc()
381 (state->xds_enable << 7) | (enable << 6) | 0x11); in saa7127_set_cc()
382 state->cc_enable = enable; in saa7127_set_cc()
384 if (!enable) in saa7127_set_cc()
390 state->cc_data = cc; in saa7127_set_cc()
394 /* ----------------------------------------------------------------------- */
396 static int saa7127_set_xds(struct v4l2_subdev *sd, const struct v4l2_sliced_vbi_data *data) in saa7127_set_xds()
399 u16 xds = data->data[1] << 8 | data->data[0]; in saa7127_set_xds()
400 int enable = (data->line != 0); in saa7127_set_xds() local
402 if (enable && (data->field != 1 || data->line != 21)) in saa7127_set_xds()
403 return -EINVAL; in saa7127_set_xds()
404 if (state->xds_enable != enable) { in saa7127_set_xds()
405 v4l2_dbg(1, debug, sd, "Turn XDS %s\n", enable ? "on" : "off"); in saa7127_set_xds()
407 (enable << 7) | (state->cc_enable << 6) | 0x11); in saa7127_set_xds()
408 state->xds_enable = enable; in saa7127_set_xds()
410 if (!enable) in saa7127_set_xds()
416 state->xds_data = xds; in saa7127_set_xds()
420 /* ----------------------------------------------------------------------- */
422 static int saa7127_set_wss(struct v4l2_subdev *sd, const struct v4l2_sliced_vbi_data *data) in saa7127_set_wss()
425 int enable = (data->line != 0); in saa7127_set_wss() local
427 if (enable && (data->field != 0 || data->line != 23)) in saa7127_set_wss()
428 return -EINVAL; in saa7127_set_wss()
429 if (state->wss_enable != enable) { in saa7127_set_wss()
430 v4l2_dbg(1, debug, sd, "Turn WSS %s\n", enable ? "on" : "off"); in saa7127_set_wss()
431 saa7127_write(sd, 0x27, enable << 7); in saa7127_set_wss()
432 state->wss_enable = enable; in saa7127_set_wss()
434 if (!enable) in saa7127_set_wss()
437 saa7127_write(sd, 0x26, data->data[0]); in saa7127_set_wss()
438 saa7127_write(sd, 0x27, 0x80 | (data->data[1] & 0x3f)); in saa7127_set_wss()
440 "WSS mode: %s\n", wss_strs[data->data[0] & 0xf]); in saa7127_set_wss()
441 state->wss_mode = (data->data[1] & 0x3f) << 8 | data->data[0]; in saa7127_set_wss()
445 /* ----------------------------------------------------------------------- */
447 static int saa7127_set_video_enable(struct v4l2_subdev *sd, int enable) in saa7127_set_video_enable() argument
451 if (enable) { in saa7127_set_video_enable()
452 v4l2_dbg(1, debug, sd, "Enable Video Output\n"); in saa7127_set_video_enable()
453 saa7127_write(sd, 0x2d, state->reg_2d); in saa7127_set_video_enable()
454 saa7127_write(sd, 0x61, state->reg_61); in saa7127_set_video_enable()
457 saa7127_write(sd, 0x2d, (state->reg_2d & 0xf0)); in saa7127_set_video_enable()
458 saa7127_write(sd, 0x61, (state->reg_61 | 0xc0)); in saa7127_set_video_enable()
460 state->video_enable = enable; in saa7127_set_video_enable()
464 /* ----------------------------------------------------------------------- */
466 static int saa7127_set_std(struct v4l2_subdev *sd, v4l2_std_id std) in saa7127_set_std()
474 state->reg_61 = SAA7127_60HZ_DAC_CONTROL; in saa7127_set_std()
476 } else if (state->ident == SAA7129 && in saa7127_set_std()
484 state->reg_61 = SAA7127_50HZ_SECAM_DAC_CONTROL; in saa7127_set_std()
489 state->reg_61 = SAA7127_50HZ_PAL_DAC_CONTROL; in saa7127_set_std()
494 state->std = std; in saa7127_set_std()
498 /* ----------------------------------------------------------------------- */
500 static int saa7127_set_output_type(struct v4l2_subdev *sd, int output) in saa7127_set_output_type()
506 state->reg_2d = 0x0f; /* RGB + CVBS (for sync) */ in saa7127_set_output_type()
507 state->reg_3a = 0x13; /* by default switch YUV to RGB-matrix on */ in saa7127_set_output_type()
511 if (state->ident == SAA7129) in saa7127_set_output_type()
512 state->reg_2d = 0x20; /* CVBS only */ in saa7127_set_output_type()
514 state->reg_2d = 0x08; /* 00001000 CVBS only, RGB DAC's off (high impedance mode) */ in saa7127_set_output_type()
515 state->reg_3a = 0x13; /* by default switch YUV to RGB-matrix on */ in saa7127_set_output_type()
519 if (state->ident == SAA7129) in saa7127_set_output_type()
520 state->reg_2d = 0x18; /* Y + C */ in saa7127_set_output_type()
522 state->reg_2d = 0xff; /*11111111 croma -> R, luma -> CVBS + G + B */ in saa7127_set_output_type()
523 state->reg_3a = 0x13; /* by default switch YUV to RGB-matrix on */ in saa7127_set_output_type()
527 state->reg_2d = 0x4f; /* reg 2D = 01001111, all DAC's on, RGB + VBS */ in saa7127_set_output_type()
528 state->reg_3a = 0x0b; /* reg 3A = 00001011, bypass RGB-matrix */ in saa7127_set_output_type()
532 state->reg_2d = 0x0f; /* reg 2D = 00001111, all DAC's on, RGB + CVBS */ in saa7127_set_output_type()
533 state->reg_3a = 0x0b; /* reg 3A = 00001011, bypass RGB-matrix */ in saa7127_set_output_type()
537 if (state->ident == SAA7129) in saa7127_set_output_type()
538 state->reg_2d = 0x38; in saa7127_set_output_type()
540 state->reg_2d = 0xbf; in saa7127_set_output_type()
541 state->reg_3a = 0x13; /* by default switch YUV to RGB-matrix on */ in saa7127_set_output_type()
545 return -EINVAL; in saa7127_set_output_type()
551 saa7127_write(sd, 0x2d, state->reg_2d); in saa7127_set_output_type()
552 saa7127_write(sd, 0x3a, state->reg_3a | state->reg_3a_cb); in saa7127_set_output_type()
553 state->output_type = output; in saa7127_set_output_type()
557 /* ----------------------------------------------------------------------- */
559 static int saa7127_set_input_type(struct v4l2_subdev *sd, int input) in saa7127_set_input_type()
566 state->reg_3a_cb = 0; in saa7127_set_input_type()
571 state->reg_3a_cb = 0x80; in saa7127_set_input_type()
575 return -EINVAL; in saa7127_set_input_type()
577 saa7127_write(sd, 0x3a, state->reg_3a | state->reg_3a_cb); in saa7127_set_input_type()
578 state->input_type = input; in saa7127_set_input_type()
582 /* ----------------------------------------------------------------------- */
584 static int saa7127_s_std_output(struct v4l2_subdev *sd, v4l2_std_id std) in saa7127_s_std_output()
588 if (state->std == std) in saa7127_s_std_output()
593 static int saa7127_s_routing(struct v4l2_subdev *sd, in saa7127_s_routing()
599 if (state->input_type != input) in saa7127_s_routing()
601 if (rc == 0 && state->output_type != output) in saa7127_s_routing()
606 static int saa7127_s_stream(struct v4l2_subdev *sd, int enable) in saa7127_s_stream() argument
610 if (state->video_enable == enable) in saa7127_s_stream()
612 return saa7127_set_video_enable(sd, enable); in saa7127_s_stream()
615 static int saa7127_g_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *fmt) in saa7127_g_sliced_fmt()
619 memset(fmt->service_lines, 0, sizeof(fmt->service_lines)); in saa7127_g_sliced_fmt()
620 if (state->vps_enable) in saa7127_g_sliced_fmt()
621 fmt->service_lines[0][16] = V4L2_SLICED_VPS; in saa7127_g_sliced_fmt()
622 if (state->wss_enable) in saa7127_g_sliced_fmt()
623 fmt->service_lines[0][23] = V4L2_SLICED_WSS_625; in saa7127_g_sliced_fmt()
624 if (state->cc_enable) { in saa7127_g_sliced_fmt()
625 fmt->service_lines[0][21] = V4L2_SLICED_CAPTION_525; in saa7127_g_sliced_fmt()
626 fmt->service_lines[1][21] = V4L2_SLICED_CAPTION_525; in saa7127_g_sliced_fmt()
628 fmt->service_set = in saa7127_g_sliced_fmt()
629 (state->vps_enable ? V4L2_SLICED_VPS : 0) | in saa7127_g_sliced_fmt()
630 (state->wss_enable ? V4L2_SLICED_WSS_625 : 0) | in saa7127_g_sliced_fmt()
631 (state->cc_enable ? V4L2_SLICED_CAPTION_525 : 0); in saa7127_g_sliced_fmt()
635 static int saa7127_s_vbi_data(struct v4l2_subdev *sd, const struct v4l2_sliced_vbi_data *data) in saa7127_s_vbi_data()
637 switch (data->id) { in saa7127_s_vbi_data()
643 if (data->field == 0) in saa7127_s_vbi_data()
647 return -EINVAL; in saa7127_s_vbi_data()
653 static int saa7127_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) in saa7127_g_register()
655 reg->val = saa7127_read(sd, reg->reg & 0xff); in saa7127_g_register()
656 reg->size = 1; in saa7127_g_register()
660 static int saa7127_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg) in saa7127_s_register()
662 saa7127_write(sd, reg->reg & 0xff, reg->val & 0xff); in saa7127_s_register()
667 static int saa7127_log_status(struct v4l2_subdev *sd) in saa7127_log_status()
671 v4l2_info(sd, "Standard: %s\n", (state->std & V4L2_STD_525_60) ? "60 Hz" : "50 Hz"); in saa7127_log_status()
672 v4l2_info(sd, "Input: %s\n", state->input_type ? "color bars" : "normal"); in saa7127_log_status()
673 v4l2_info(sd, "Output: %s\n", state->video_enable ? in saa7127_log_status()
674 output_strs[state->output_type] : "disabled"); in saa7127_log_status()
675 v4l2_info(sd, "WSS: %s\n", state->wss_enable ? in saa7127_log_status()
676 wss_strs[state->wss_mode] : "disabled"); in saa7127_log_status()
677 v4l2_info(sd, "VPS: %s\n", state->vps_enable ? "enabled" : "disabled"); in saa7127_log_status()
678 v4l2_info(sd, "CC: %s\n", state->cc_enable ? "enabled" : "disabled"); in saa7127_log_status()
682 /* ----------------------------------------------------------------------- */
684 static const struct v4l2_subdev_core_ops saa7127_core_ops = {
692 static const struct v4l2_subdev_video_ops saa7127_video_ops = {
698 static const struct v4l2_subdev_vbi_ops saa7127_vbi_ops = {
703 static const struct v4l2_subdev_ops saa7127_ops = {
709 /* ----------------------------------------------------------------------- */
711 static int saa7127_probe(struct i2c_client *client, in saa7127_probe()
719 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) in saa7127_probe()
720 return -EIO; in saa7127_probe()
723 client->addr << 1); in saa7127_probe()
725 state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL); in saa7127_probe()
727 return -ENOMEM; in saa7127_probe()
729 sd = &state->sd; in saa7127_probe()
732 /* First test register 0: Bits 5-7 are a version ID (should be 0), in saa7127_probe()
740 return -ENODEV; in saa7127_probe()
743 if (id->driver_data) { /* Chip type is already known */ in saa7127_probe()
744 state->ident = id->driver_data; in saa7127_probe()
754 state->ident = SAA7129; in saa7127_probe()
755 strscpy(client->name, "saa7129", I2C_NAME_SIZE); in saa7127_probe()
757 state->ident = SAA7127; in saa7127_probe()
758 strscpy(client->name, "saa7127", I2C_NAME_SIZE); in saa7127_probe()
762 v4l2_info(sd, "%s found @ 0x%x (%s)\n", client->name, in saa7127_probe()
763 client->addr << 1, client->adapter->name); in saa7127_probe()
781 if (state->ident == SAA7129) in saa7127_probe()
786 /* ----------------------------------------------------------------------- */
788 static int saa7127_remove(struct i2c_client *client) in saa7127_remove()
798 /* ----------------------------------------------------------------------- */
800 static const struct i2c_device_id saa7127_id[] = {
801 { "saa7127_auto", 0 }, /* auto-detection */
810 static struct i2c_driver saa7127_driver = {