51 #include <linux/kernel.h>
52 #include <linux/module.h>
53 #include <linux/slab.h>
54 #include <linux/i2c.h>
55 #include <linux/videodev2.h>
61 static int test_image;
76 #define SAA7127_REG_STATUS 0x00
77 #define SAA7127_REG_WIDESCREEN_CONFIG 0x26
78 #define SAA7127_REG_WIDESCREEN_ENABLE 0x27
79 #define SAA7127_REG_BURST_START 0x28
80 #define SAA7127_REG_BURST_END 0x29
81 #define SAA7127_REG_COPYGEN_0 0x2a
82 #define SAA7127_REG_COPYGEN_1 0x2b
83 #define SAA7127_REG_COPYGEN_2 0x2c
84 #define SAA7127_REG_OUTPUT_PORT_CONTROL 0x2d
85 #define SAA7127_REG_GAIN_LUMINANCE_RGB 0x38
86 #define SAA7127_REG_GAIN_COLORDIFF_RGB 0x39
87 #define SAA7127_REG_INPUT_PORT_CONTROL_1 0x3a
88 #define SAA7129_REG_FADE_KEY_COL2 0x4f
89 #define SAA7127_REG_CHROMA_PHASE 0x5a
90 #define SAA7127_REG_GAINU 0x5b
91 #define SAA7127_REG_GAINV 0x5c
92 #define SAA7127_REG_BLACK_LEVEL 0x5d
93 #define SAA7127_REG_BLANKING_LEVEL 0x5e
94 #define SAA7127_REG_VBI_BLANKING 0x5f
95 #define SAA7127_REG_DAC_CONTROL 0x61
96 #define SAA7127_REG_BURST_AMP 0x62
97 #define SAA7127_REG_SUBC3 0x63
98 #define SAA7127_REG_SUBC2 0x64
99 #define SAA7127_REG_SUBC1 0x65
100 #define SAA7127_REG_SUBC0 0x66
101 #define SAA7127_REG_LINE_21_ODD_0 0x67
102 #define SAA7127_REG_LINE_21_ODD_1 0x68
103 #define SAA7127_REG_LINE_21_EVEN_0 0x69
104 #define SAA7127_REG_LINE_21_EVEN_1 0x6a
105 #define SAA7127_REG_RCV_PORT_CONTROL 0x6b
106 #define SAA7127_REG_VTRIG 0x6c
107 #define SAA7127_REG_HTRIG_HI 0x6d
108 #define SAA7127_REG_MULTI 0x6e
109 #define SAA7127_REG_CLOSED_CAPTION 0x6f
110 #define SAA7127_REG_RCV2_OUTPUT_START 0x70
111 #define SAA7127_REG_RCV2_OUTPUT_END 0x71
112 #define SAA7127_REG_RCV2_OUTPUT_MSBS 0x72
113 #define SAA7127_REG_TTX_REQUEST_H_START 0x73
114 #define SAA7127_REG_TTX_REQUEST_H_DELAY_LENGTH 0x74
115 #define SAA7127_REG_CSYNC_ADVANCE_VSYNC_SHIFT 0x75
116 #define SAA7127_REG_TTX_ODD_REQ_VERT_START 0x76
117 #define SAA7127_REG_TTX_ODD_REQ_VERT_END 0x77
118 #define SAA7127_REG_TTX_EVEN_REQ_VERT_START 0x78
119 #define SAA7127_REG_TTX_EVEN_REQ_VERT_END 0x79
120 #define SAA7127_REG_FIRST_ACTIVE 0x7a
121 #define SAA7127_REG_LAST_ACTIVE 0x7b
122 #define SAA7127_REG_MSB_VERTICAL 0x7c
123 #define SAA7127_REG_DISABLE_TTX_LINE_LO_0 0x7e
124 #define SAA7127_REG_DISABLE_TTX_LINE_LO_1 0x7f
139 static const struct i2c_reg_value saa7129_init_config_extra[] = {
145 static const struct i2c_reg_value saa7127_init_config_common[] = {
180 #define SAA7127_60HZ_DAC_CONTROL 0x15
181 static const struct i2c_reg_value saa7127_init_config_60hz[] = {
202 #define SAA7127_50HZ_PAL_DAC_CONTROL 0x02
203 static struct i2c_reg_value saa7127_init_config_50hz_pal[] = {
224 #define SAA7127_50HZ_SECAM_DAC_CONTROL 0x08
225 static struct i2c_reg_value saa7127_init_config_50hz_secam[] = {
280 static const char *
const output_strs[] =
282 "S-Video + Composite",
290 static const char *
const wss_strs[] = {
292 "letterbox 14:9 center",
293 "letterbox 14:9 top",
295 "letterbox 16:9 top",
298 "16:9 full format anamorphic",
302 "letterbox 16:9 center",
304 "letterbox >16:9 center",
305 "14:9 full format center",
325 for (i = 0; i < 3; i++) {
329 v4l2_err(sd,
"I2C Write Problem\n");
335 static int saa7127_write_inittab(
struct v4l2_subdev *sd,
338 while (regs->
reg != 0) {
339 saa7127_write(sd, regs->
reg, regs->
value);
352 if (enable && (data->
field != 0 || data->
line != 16))
355 v4l2_dbg(1,
debug, sd,
"Turn VPS Signal %s\n", enable ?
"on" :
"off");
356 saa7127_write(sd, 0x54, enable << 7);
368 saa7127_write(sd, 0x55, state->
vps_data[0]);
369 saa7127_write(sd, 0x56, state->
vps_data[1]);
370 saa7127_write(sd, 0x57, state->
vps_data[2]);
371 saa7127_write(sd, 0x58, state->
vps_data[3]);
372 saa7127_write(sd, 0x59, state->
vps_data[4]);
382 int enable = (data->
line != 0);
384 if (enable && (data->
field != 0 || data->
line != 21))
388 "Turn CC %s\n", enable ?
"on" :
"off");
390 (state->
xds_enable << 7) | (enable << 6) | 0x11);
409 int enable = (data->
line != 0);
411 if (enable && (data->
field != 1 || data->
line != 21))
414 v4l2_dbg(1,
debug, sd,
"Turn XDS %s\n", enable ?
"on" :
"off");
416 (enable << 7) | (state->
cc_enable << 6) | 0x11);
434 int enable = (data->
line != 0);
436 if (enable && (data->
field != 0 || data->
line != 23))
439 v4l2_dbg(1,
debug, sd,
"Turn WSS %s\n", enable ?
"on" :
"off");
440 saa7127_write(sd, 0x27, enable << 7);
446 saa7127_write(sd, 0x26, data->
data[0]);
447 saa7127_write(sd, 0x27, 0x80 | (data->
data[1] & 0x3f));
449 "WSS mode: %s\n", wss_strs[data->
data[0] & 0xf]);
456 static int saa7127_set_video_enable(
struct v4l2_subdev *sd,
int enable)
462 saa7127_write(sd, 0x2d, state->
reg_2d);
463 saa7127_write(sd, 0x61, state->
reg_61);
466 saa7127_write(sd, 0x2d, (state->
reg_2d & 0xf0));
467 saa7127_write(sd, 0x61, (state->
reg_61 | 0xc0));
482 inittab = saa7127_init_config_60hz;
491 "Selecting 50 Hz SECAM video Standard\n");
492 inittab = saa7127_init_config_50hz_secam;
496 v4l2_dbg(1,
debug, sd,
"Selecting 50 Hz PAL video Standard\n");
497 inittab = saa7127_init_config_50hz_pal;
502 saa7127_write_inittab(sd, inittab);
509 static int saa7127_set_output_type(
struct v4l2_subdev *sd,
int output)
557 "Selecting %s output type\n", output_strs[output]);
560 saa7127_write(sd, 0x2d, state->
reg_2d);
597 if (state->
std == std)
599 return saa7127_set_std(sd, std);
602 static int saa7127_s_routing(
struct v4l2_subdev *sd,
609 rc = saa7127_set_input_type(sd, input);
611 rc = saa7127_set_output_type(sd, output);
615 static int saa7127_s_stream(
struct v4l2_subdev *sd,
int enable)
621 return saa7127_set_video_enable(sd, enable);
648 return saa7127_set_wss(sd, data);
650 return saa7127_set_vps(sd, data);
652 if (data->
field == 0)
653 return saa7127_set_cc(sd, data);
654 return saa7127_set_xds(sd, data);
661 #ifdef CONFIG_VIDEO_ADV_DEBUG
664 struct i2c_client *client = v4l2_get_subdevdata(sd);
670 reg->
val = saa7127_read(sd, reg->
reg & 0xff);
677 struct i2c_client *client = v4l2_get_subdevdata(sd);
683 saa7127_write(sd, reg->
reg & 0xff, reg->
val & 0xff);
691 struct i2c_client *client = v4l2_get_subdevdata(sd);
696 static int saa7127_log_status(
struct v4l2_subdev *sd)
700 v4l2_info(sd,
"Standard: %s\n", (state->
std & V4L2_STD_525_60) ?
"60 Hz" :
"50 Hz");
705 wss_strs[state->
wss_mode] :
"disabled");
714 .log_status = saa7127_log_status,
715 .g_chip_ident = saa7127_g_chip_ident,
716 #ifdef CONFIG_VIDEO_ADV_DEBUG
717 .g_register = saa7127_g_register,
718 .s_register = saa7127_s_register,
723 .s_std_output = saa7127_s_std_output,
724 .s_routing = saa7127_s_routing,
725 .s_stream = saa7127_s_stream,
729 .s_vbi_data = saa7127_s_vbi_data,
730 .g_sliced_fmt = saa7127_g_sliced_fmt,
734 .core = &saa7127_core_ops,
735 .video = &saa7127_video_ops,
736 .vbi = &saa7127_vbi_ops,
741 static int saa7127_probe(
struct i2c_client *client,
752 v4l_dbg(1,
debug, client,
"detecting saa7127 client on address 0x%x\n",
767 if ((saa7127_read(sd, 0) & 0xe4) != 0 ||
768 (saa7127_read(sd, 0x29) & 0x3f) != 0x1d) {
774 if (id->driver_data) {
775 state->
ident =
id->driver_data;
797 saa7127_write_inittab(sd, saa7127_init_config_common);
800 saa7127_set_vps(sd, &vbi);
801 saa7127_set_wss(sd, &vbi);
802 saa7127_set_cc(sd, &vbi);
803 saa7127_set_xds(sd, &vbi);
810 saa7127_set_video_enable(sd, 1);
813 saa7127_write_inittab(sd, saa7129_init_config_extra);
819 static int saa7127_remove(
struct i2c_client *client)
821 struct v4l2_subdev *sd = i2c_get_clientdata(client);
825 saa7127_set_video_enable(sd, 0);
833 {
"saa7127_auto", 0 },
847 .probe = saa7127_probe,
848 .remove = saa7127_remove,
849 .id_table = saa7127_id,