Lines Matching +full:timing +full:- +full:0
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * bt819 - BT819A VideoStream Decoder (Rockwell Part)
12 * - moved over to linux>=2.4.x i2c protocol (9/9/2002)
25 #include <media/v4l2-device.h>
26 #include <media/v4l2-ctrls.h>
29 MODULE_DESCRIPTION("Brooktree-819 video decoder driver");
34 module_param(debug, int, 0);
35 MODULE_PARM_DESC(debug, "Debug level (0-1)");
38 /* ----------------------------------------------------------------------- */
57 return &container_of(ctrl->handler, struct bt819, hdl)->sd; in to_sd()
60 struct timing { struct
70 static struct timing timing_data[] = { argument
71 {864 - 24, 20, 625 - 2, 1, 0x0504, 0x0000},
72 {858 - 24, 20, 525 - 2, 1, 0x00f8, 0x0000},
75 /* ----------------------------------------------------------------------- */
79 struct i2c_client *client = v4l2_get_subdevdata(&decoder->sd); in bt819_write()
81 decoder->reg[reg] = value; in bt819_write()
88 (decoder->reg[reg] & ~(1 << bit)) | (value ? (1 << bit) : 0)); in bt819_setbit()
93 struct i2c_client *client = v4l2_get_subdevdata(&decoder->sd); in bt819_write_block()
94 int ret = -1; in bt819_write_block()
99 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { in bt819_write_block()
105 block_len = 0; in bt819_write_block()
106 block_data[block_len++] = reg = data[0]; in bt819_write_block()
109 decoder->reg[reg++] = data[1]; in bt819_write_block()
110 len -= 2; in bt819_write_block()
112 } while (len >= 2 && data[0] == reg && block_len < 32); in bt819_write_block()
114 if (ret < 0) in bt819_write_block()
122 if (ret < 0) in bt819_write_block()
124 len -= 2; in bt819_write_block()
133 struct i2c_client *client = v4l2_get_subdevdata(&decoder->sd); in bt819_read()
141 /*0x1f, 0x00,*/ /* Reset */ in bt819_init()
142 0x01, 0x59, /* 0x01 input format */ in bt819_init()
143 0x02, 0x00, /* 0x02 temporal decimation */ in bt819_init()
144 0x03, 0x12, /* 0x03 Cropping msb */ in bt819_init()
145 0x04, 0x16, /* 0x04 Vertical Delay, lsb */ in bt819_init()
146 0x05, 0xe0, /* 0x05 Vertical Active lsb */ in bt819_init()
147 0x06, 0x80, /* 0x06 Horizontal Delay lsb */ in bt819_init()
148 0x07, 0xd0, /* 0x07 Horizontal Active lsb */ in bt819_init()
149 0x08, 0x00, /* 0x08 Horizontal Scaling msb */ in bt819_init()
150 0x09, 0xf8, /* 0x09 Horizontal Scaling lsb */ in bt819_init()
151 0x0a, 0x00, /* 0x0a Brightness control */ in bt819_init()
152 0x0b, 0x30, /* 0x0b Miscellaneous control */ in bt819_init()
153 0x0c, 0xd8, /* 0x0c Luma Gain lsb */ in bt819_init()
154 0x0d, 0xfe, /* 0x0d Chroma Gain (U) lsb */ in bt819_init()
155 0x0e, 0xb4, /* 0x0e Chroma Gain (V) msb */ in bt819_init()
156 0x0f, 0x00, /* 0x0f Hue control */ in bt819_init()
157 0x12, 0x04, /* 0x12 Output Format */ in bt819_init()
158 0x13, 0x20, /* 0x13 Vertical Scaling msb 0x00 in bt819_init()
163 0x14, 0x00, /* 0x14 Vertical Scaling lsb */ in bt819_init()
164 0x16, 0x07, /* 0x16 Video Timing Polarity in bt819_init()
169 0x18, 0x68, /* 0x18 AGC Delay */ in bt819_init()
170 0x19, 0x5d, /* 0x19 Burst Gate Delay */ in bt819_init()
171 0x1a, 0x80, /* 0x1a ADC Interface */ in bt819_init()
175 struct timing *timing = &timing_data[(decoder->norm & V4L2_STD_525_60) ? 1 : 0]; in bt819_init() local
177 init[0x03 * 2 - 1] = in bt819_init()
178 (((timing->vdelay >> 8) & 0x03) << 6) | in bt819_init()
179 (((timing->vactive >> 8) & 0x03) << 4) | in bt819_init()
180 (((timing->hdelay >> 8) & 0x03) << 2) | in bt819_init()
181 ((timing->hactive >> 8) & 0x03); in bt819_init()
182 init[0x04 * 2 - 1] = timing->vdelay & 0xff; in bt819_init()
183 init[0x05 * 2 - 1] = timing->vactive & 0xff; in bt819_init()
184 init[0x06 * 2 - 1] = timing->hdelay & 0xff; in bt819_init()
185 init[0x07 * 2 - 1] = timing->hactive & 0xff; in bt819_init()
186 init[0x08 * 2 - 1] = timing->hscale >> 8; in bt819_init()
187 init[0x09 * 2 - 1] = timing->hscale & 0xff; in bt819_init()
188 /* 0x15 in array is address 0x19 */ in bt819_init()
189 init[0x15 * 2 - 1] = (decoder->norm & V4L2_STD_625_50) ? 115 : 93; /* Chroma burst delay */ in bt819_init()
191 bt819_write(decoder, 0x1f, 0x00); in bt819_init()
198 /* ----------------------------------------------------------------------- */
203 int status = bt819_read(decoder, 0x00); in bt819_status()
207 if ((status & 0x80)) in bt819_status()
208 res = 0; in bt819_status()
212 if ((status & 0x10)) in bt819_status()
222 return 0; in bt819_status()
238 struct timing *timing = NULL; in bt819_s_std() local
242 if (sd->v4l2_dev == NULL || sd->v4l2_dev->notify == NULL) in bt819_s_std()
247 bt819_setbit(decoder, 0x01, 0, 1); in bt819_s_std()
248 bt819_setbit(decoder, 0x01, 1, 0); in bt819_s_std()
249 bt819_setbit(decoder, 0x01, 5, 0); in bt819_s_std()
250 bt819_write(decoder, 0x18, 0x68); in bt819_s_std()
251 bt819_write(decoder, 0x19, 0x5d); in bt819_s_std()
252 /* bt819_setbit(decoder, 0x1a, 5, 1); */ in bt819_s_std()
253 timing = &timing_data[1]; in bt819_s_std()
256 bt819_setbit(decoder, 0x01, 0, 1); in bt819_s_std()
257 bt819_setbit(decoder, 0x01, 1, 1); in bt819_s_std()
258 bt819_setbit(decoder, 0x01, 5, 1); in bt819_s_std()
259 bt819_write(decoder, 0x18, 0x7f); in bt819_s_std()
260 bt819_write(decoder, 0x19, 0x72); in bt819_s_std()
261 /* bt819_setbit(decoder, 0x1a, 5, 0); */ in bt819_s_std()
262 timing = &timing_data[0]; in bt819_s_std()
266 return -EINVAL; in bt819_s_std()
268 bt819_write(decoder, 0x03, in bt819_s_std()
269 (((timing->vdelay >> 8) & 0x03) << 6) | in bt819_s_std()
270 (((timing->vactive >> 8) & 0x03) << 4) | in bt819_s_std()
271 (((timing->hdelay >> 8) & 0x03) << 2) | in bt819_s_std()
272 ((timing->hactive >> 8) & 0x03)); in bt819_s_std()
273 bt819_write(decoder, 0x04, timing->vdelay & 0xff); in bt819_s_std()
274 bt819_write(decoder, 0x05, timing->vactive & 0xff); in bt819_s_std()
275 bt819_write(decoder, 0x06, timing->hdelay & 0xff); in bt819_s_std()
276 bt819_write(decoder, 0x07, timing->hactive & 0xff); in bt819_s_std()
277 bt819_write(decoder, 0x08, (timing->hscale >> 8) & 0xff); in bt819_s_std()
278 bt819_write(decoder, 0x09, timing->hscale & 0xff); in bt819_s_std()
279 decoder->norm = std; in bt819_s_std()
281 return 0; in bt819_s_std()
292 return -EINVAL; in bt819_s_routing()
294 if (sd->v4l2_dev == NULL || sd->v4l2_dev->notify == NULL) in bt819_s_routing()
297 if (decoder->input != input) { in bt819_s_routing()
299 decoder->input = input; in bt819_s_routing()
301 if (decoder->input == 0) { in bt819_s_routing()
302 bt819_setbit(decoder, 0x0b, 6, 0); in bt819_s_routing()
303 bt819_setbit(decoder, 0x1a, 1, 1); in bt819_s_routing()
305 bt819_setbit(decoder, 0x0b, 6, 1); in bt819_s_routing()
306 bt819_setbit(decoder, 0x1a, 1, 0); in bt819_s_routing()
310 return 0; in bt819_s_routing()
319 if (decoder->enable != enable) { in bt819_s_stream()
320 decoder->enable = enable; in bt819_s_stream()
321 bt819_setbit(decoder, 0x16, 7, !enable); in bt819_s_stream()
323 return 0; in bt819_s_stream()
332 switch (ctrl->id) { in bt819_s_ctrl()
334 bt819_write(decoder, 0x0a, ctrl->val); in bt819_s_ctrl()
338 bt819_write(decoder, 0x0c, ctrl->val & 0xff); in bt819_s_ctrl()
339 bt819_setbit(decoder, 0x0b, 2, ((ctrl->val >> 8) & 0x01)); in bt819_s_ctrl()
343 bt819_write(decoder, 0x0d, (ctrl->val >> 7) & 0xff); in bt819_s_ctrl()
344 bt819_setbit(decoder, 0x0b, 1, ((ctrl->val >> 15) & 0x01)); in bt819_s_ctrl()
348 temp = (ctrl->val * 180) / 254; in bt819_s_ctrl()
349 bt819_write(decoder, 0x0e, (temp >> 7) & 0xff); in bt819_s_ctrl()
350 bt819_setbit(decoder, 0x0b, 0, (temp >> 15) & 0x01); in bt819_s_ctrl()
354 bt819_write(decoder, 0x0f, ctrl->val); in bt819_s_ctrl()
358 return -EINVAL; in bt819_s_ctrl()
360 return 0; in bt819_s_ctrl()
363 /* ----------------------------------------------------------------------- */
381 /* ----------------------------------------------------------------------- */
391 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) in bt819_probe()
392 return -ENODEV; in bt819_probe()
394 decoder = devm_kzalloc(&client->dev, sizeof(*decoder), GFP_KERNEL); in bt819_probe()
396 return -ENOMEM; in bt819_probe()
397 sd = &decoder->sd; in bt819_probe()
400 ver = bt819_read(decoder, 0x17); in bt819_probe()
401 switch (ver & 0xf0) { in bt819_probe()
402 case 0x70: in bt819_probe()
405 case 0x60: in bt819_probe()
408 case 0x20: in bt819_probe()
413 "unknown chip version 0x%02x\n", ver); in bt819_probe()
414 return -ENODEV; in bt819_probe()
417 v4l_info(client, "%s found @ 0x%x (%s)\n", name, in bt819_probe()
418 client->addr << 1, client->adapter->name); in bt819_probe()
420 decoder->norm = V4L2_STD_NTSC; in bt819_probe()
421 decoder->input = 0; in bt819_probe()
422 decoder->enable = 1; in bt819_probe()
425 if (i < 0) in bt819_probe()
428 v4l2_ctrl_handler_init(&decoder->hdl, 4); in bt819_probe()
429 v4l2_ctrl_new_std(&decoder->hdl, &bt819_ctrl_ops, in bt819_probe()
430 V4L2_CID_BRIGHTNESS, -128, 127, 1, 0); in bt819_probe()
431 v4l2_ctrl_new_std(&decoder->hdl, &bt819_ctrl_ops, in bt819_probe()
432 V4L2_CID_CONTRAST, 0, 511, 1, 0xd8); in bt819_probe()
433 v4l2_ctrl_new_std(&decoder->hdl, &bt819_ctrl_ops, in bt819_probe()
434 V4L2_CID_SATURATION, 0, 511, 1, 0xfe); in bt819_probe()
435 v4l2_ctrl_new_std(&decoder->hdl, &bt819_ctrl_ops, in bt819_probe()
436 V4L2_CID_HUE, -128, 127, 1, 0); in bt819_probe()
437 sd->ctrl_handler = &decoder->hdl; in bt819_probe()
438 if (decoder->hdl.error) { in bt819_probe()
439 int err = decoder->hdl.error; in bt819_probe()
441 v4l2_ctrl_handler_free(&decoder->hdl); in bt819_probe()
444 v4l2_ctrl_handler_setup(&decoder->hdl); in bt819_probe()
445 return 0; in bt819_probe()
454 v4l2_ctrl_handler_free(&decoder->hdl); in bt819_remove()
457 /* ----------------------------------------------------------------------- */