Lines Matching +full:1 +full:- +full:sd

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Video Capture Driver (Video for Linux 1/2)
4 * for the Matrox Marvel G200,G400 and Rainbow Runner-G series
20 * V1.1 Gerard v.d. Horst Added some debugoutput, reset the video-standard
31 #include <media/v4l2-device.h>
179 struct v4l2_subdev sd; member
184 static inline struct ks0127 *to_ks0127(struct v4l2_subdev *sd) in to_ks0127() argument
186 return container_of(sd, struct ks0127, sd); in to_ks0127()
204 initialized = 1; in init_reg_defaults()
209 /* clock & input select, write 1 to PORTA */ in init_reg_defaults()
230 /* Vertical Processing Control B, luma 1 line delayed */ in init_reg_defaults()
268 /* User Defined SHS1 B, ALT656=1 on 0127B */ in init_reg_defaults()
273 /* Command Register F, update -immediately- */ in init_reg_defaults()
290 * workaround in i2c-algo-bit
294 static u8 ks0127_read(struct v4l2_subdev *sd, u8 reg) in ks0127_read() argument
296 struct i2c_client *client = v4l2_get_subdevdata(sd); in ks0127_read()
300 .addr = client->addr, in ks0127_read()
305 .addr = client->addr, in ks0127_read()
313 ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); in ks0127_read()
315 v4l2_dbg(1, debug, sd, "read error\n"); in ks0127_read()
321 static void ks0127_write(struct v4l2_subdev *sd, u8 reg, u8 val) in ks0127_write() argument
323 struct i2c_client *client = v4l2_get_subdevdata(sd); in ks0127_write()
324 struct ks0127 *ks = to_ks0127(sd); in ks0127_write()
328 v4l2_dbg(1, debug, sd, "write error\n"); in ks0127_write()
330 ks->regs[reg] = val; in ks0127_write()
334 /* generic bit-twiddling */
335 static void ks0127_and_or(struct v4l2_subdev *sd, u8 reg, u8 and_v, u8 or_v) in ks0127_and_or() argument
337 struct ks0127 *ks = to_ks0127(sd); in ks0127_and_or()
339 u8 val = ks->regs[reg]; in ks0127_and_or()
341 ks0127_write(sd, reg, val); in ks0127_and_or()
349 static void ks0127_init(struct v4l2_subdev *sd) in ks0127_init() argument
354 v4l2_dbg(1, debug, sd, "reset\n"); in ks0127_init()
355 msleep(1); in ks0127_init()
360 for (i = 1; i < 33; i++) in ks0127_init()
361 ks0127_write(sd, i, table[i]); in ks0127_init()
364 ks0127_write(sd, i, table[i]); in ks0127_init()
367 ks0127_write(sd, i, table[i]); in ks0127_init()
370 ks0127_write(sd, i, table[i]); in ks0127_init()
373 if ((ks0127_read(sd, KS_STAT) & 0x80) == 0) { in ks0127_init()
374 v4l2_dbg(1, debug, sd, "ks0122s found\n"); in ks0127_init()
378 switch (ks0127_read(sd, KS_CMDE) & 0x0f) { in ks0127_init()
380 v4l2_dbg(1, debug, sd, "ks0127 found\n"); in ks0127_init()
384 v4l2_dbg(1, debug, sd, "ks0127B Revision A found\n"); in ks0127_init()
388 v4l2_dbg(1, debug, sd, "unknown revision\n"); in ks0127_init()
393 static int ks0127_s_routing(struct v4l2_subdev *sd, in ks0127_s_routing() argument
396 struct ks0127 *ks = to_ks0127(sd); in ks0127_s_routing()
405 v4l2_dbg(1, debug, sd, in ks0127_s_routing()
408 ks0127_and_or(sd, KS_CMDA, 0xfc, 0x00); in ks0127_s_routing()
410 ks0127_and_or(sd, KS_CMDA, ~0x40, 0x00); in ks0127_s_routing()
412 ks0127_and_or(sd, KS_CMDB, 0xb0, input); in ks0127_s_routing()
413 /* non-freerunning mode */ in ks0127_s_routing()
414 ks0127_and_or(sd, KS_CMDC, 0x70, 0x0a); in ks0127_s_routing()
416 ks0127_and_or(sd, KS_CMDD, 0x03, 0x00); in ks0127_s_routing()
418 ks0127_and_or(sd, KS_CTRACK, 0xcf, 0x00); in ks0127_s_routing()
419 /* chroma trap, HYBWR=1 */ in ks0127_s_routing()
420 ks0127_and_or(sd, KS_LUMA, 0x00, in ks0127_s_routing()
423 ks0127_and_or(sd, KS_VERTIA, 0x08, 0x81); in ks0127_s_routing()
425 ks0127_and_or(sd, KS_VERTIC, 0x0f, 0x90); in ks0127_s_routing()
428 ks0127_and_or(sd, KS_CHROMB, 0x0f, 0x90); in ks0127_s_routing()
430 ks0127_write(sd, KS_UGAIN, reg_defaults[KS_UGAIN]); in ks0127_s_routing()
431 ks0127_write(sd, KS_VGAIN, reg_defaults[KS_VGAIN]); in ks0127_s_routing()
432 ks0127_write(sd, KS_UVOFFH, reg_defaults[KS_UVOFFH]); in ks0127_s_routing()
433 ks0127_write(sd, KS_UVOFFL, reg_defaults[KS_UVOFFL]); in ks0127_s_routing()
439 v4l2_dbg(1, debug, sd, in ks0127_s_routing()
440 "s_routing %d: S-Video\n", input); in ks0127_s_routing()
442 ks0127_and_or(sd, KS_CMDA, 0xfc, 0x00); in ks0127_s_routing()
444 ks0127_and_or(sd, KS_CMDA, ~0x40, 0x00); in ks0127_s_routing()
446 ks0127_and_or(sd, KS_CMDB, 0xb0, input); in ks0127_s_routing()
447 /* non-freerunning mode */ in ks0127_s_routing()
448 ks0127_and_or(sd, KS_CMDC, 0x70, 0x0a); in ks0127_s_routing()
450 ks0127_and_or(sd, KS_CMDD, 0x03, 0x00); in ks0127_s_routing()
452 ks0127_and_or(sd, KS_CTRACK, 0xcf, 0x00); in ks0127_s_routing()
453 ks0127_and_or(sd, KS_LUMA, 0x00, in ks0127_s_routing()
456 ks0127_and_or(sd, KS_VERTIA, 0x08, in ks0127_s_routing()
458 ks0127_and_or(sd, KS_VERTIC, 0x0f, in ks0127_s_routing()
461 ks0127_and_or(sd, KS_CHROMB, 0x0f, in ks0127_s_routing()
464 ks0127_write(sd, KS_UGAIN, reg_defaults[KS_UGAIN]); in ks0127_s_routing()
465 ks0127_write(sd, KS_VGAIN, reg_defaults[KS_VGAIN]); in ks0127_s_routing()
466 ks0127_write(sd, KS_UVOFFH, reg_defaults[KS_UVOFFH]); in ks0127_s_routing()
467 ks0127_write(sd, KS_UVOFFL, reg_defaults[KS_UVOFFL]); in ks0127_s_routing()
471 v4l2_dbg(1, debug, sd, "s_routing 15: YUV656\n"); in ks0127_s_routing()
472 if (ks->norm & V4L2_STD_525_60) in ks0127_s_routing()
474 ks0127_and_or(sd, KS_CMDA, 0xfc, 0x03); in ks0127_s_routing()
477 ks0127_and_or(sd, KS_CMDA, 0xfc, 0x02); in ks0127_s_routing()
479 ks0127_and_or(sd, KS_CMDA, 0xff, 0x40); /* VSE=1 */ in ks0127_s_routing()
481 ks0127_and_or(sd, KS_CMDB, 0xb0, (input | 0x40)); in ks0127_s_routing()
483 /* TSTGEN = 1 TSTGFR=11 TSTGPH=0 TSTGPK=0 VMEM=1*/ in ks0127_s_routing()
484 ks0127_and_or(sd, KS_CMDC, 0x70, 0x87); in ks0127_s_routing()
486 ks0127_and_or(sd, KS_CMDD, 0x03, 0x08); in ks0127_s_routing()
488 ks0127_and_or(sd, KS_CTRACK, 0xcf, 0x30); in ks0127_s_routing()
489 /* HYPK =01 CTRAP = 0 HYBWR=0 PED=1 RGBH=1 UNIT=1 */ in ks0127_s_routing()
490 ks0127_and_or(sd, KS_LUMA, 0x00, 0x71); in ks0127_s_routing()
491 ks0127_and_or(sd, KS_VERTIC, 0x0f, in ks0127_s_routing()
495 ks0127_and_or(sd, KS_VERTIA, 0x08, 0x81); in ks0127_s_routing()
497 ks0127_and_or(sd, KS_CHROMB, 0x0f, in ks0127_s_routing()
500 ks0127_and_or(sd, KS_CON, 0x00, 0x00); in ks0127_s_routing()
501 ks0127_and_or(sd, KS_BRT, 0x00, 32); /* spec: 34 */ in ks0127_s_routing()
503 ks0127_and_or(sd, KS_SAT, 0x00, 0xe8); in ks0127_s_routing()
504 ks0127_and_or(sd, KS_HUE, 0x00, 0); in ks0127_s_routing()
506 ks0127_and_or(sd, KS_UGAIN, 0x00, 238); in ks0127_s_routing()
507 ks0127_and_or(sd, KS_VGAIN, 0x00, 0x00); in ks0127_s_routing()
509 /*UOFF:0x30, VOFF:0x30, TSTCGN=1 */ in ks0127_s_routing()
510 ks0127_and_or(sd, KS_UVOFFH, 0x00, 0x4f); in ks0127_s_routing()
511 ks0127_and_or(sd, KS_UVOFFL, 0x00, 0x00); in ks0127_s_routing()
515 v4l2_dbg(1, debug, sd, in ks0127_s_routing()
522 ks0127_write(sd, KS_DEMOD, reg_defaults[KS_DEMOD]); in ks0127_s_routing()
526 static int ks0127_s_std(struct v4l2_subdev *sd, v4l2_std_id std) in ks0127_s_std() argument
528 struct ks0127 *ks = to_ks0127(sd); in ks0127_s_std()
531 ks0127_and_or(sd, KS_DEMOD, 0xf0, 0x00); in ks0127_s_std()
533 ks->norm = std; in ks0127_s_std()
535 v4l2_dbg(1, debug, sd, in ks0127_s_std()
537 ks0127_and_or(sd, KS_CHROMA, 0x9f, 0x20); in ks0127_s_std()
539 v4l2_dbg(1, debug, sd, in ks0127_s_std()
541 ks0127_and_or(sd, KS_CHROMA, 0x9f, 0x40); in ks0127_s_std()
543 v4l2_dbg(1, debug, sd, in ks0127_s_std()
545 ks0127_and_or(sd, KS_CHROMA, 0x9f, 0x20); in ks0127_s_std()
547 v4l2_dbg(1, debug, sd, in ks0127_s_std()
549 ks0127_and_or(sd, KS_CHROMA, 0x9f, 0x40); in ks0127_s_std()
551 v4l2_dbg(1, debug, sd, in ks0127_s_std()
555 ks0127_and_or(sd, KS_CHROMA, 0xdf, 0x20); in ks0127_s_std()
556 ks0127_and_or(sd, KS_DEMOD, 0xf0, 0x00); in ks0127_s_std()
557 schedule_timeout_interruptible(HZ/10+1); in ks0127_s_std()
560 if (!(ks0127_read(sd, KS_DEMOD) & 0x40)) in ks0127_s_std()
562 ks0127_and_or(sd, KS_DEMOD, 0xf0, 0x0f); in ks0127_s_std()
564 v4l2_dbg(1, debug, sd, "s_std: Unknown norm %llx\n", in ks0127_s_std()
570 static int ks0127_s_stream(struct v4l2_subdev *sd, int enable) in ks0127_s_stream() argument
572 v4l2_dbg(1, debug, sd, "s_stream(%d)\n", enable); in ks0127_s_stream()
575 ks0127_and_or(sd, KS_OFMTA, 0xcf, 0x30); in ks0127_s_stream()
577 ks0127_and_or(sd, KS_CDEM, 0x7f, 0x00); in ks0127_s_stream()
580 ks0127_and_or(sd, KS_OFMTA, 0xcf, 0x00); in ks0127_s_stream()
582 ks0127_and_or(sd, KS_CDEM, 0x7f, 0x80); in ks0127_s_stream()
587 static int ks0127_status(struct v4l2_subdev *sd, u32 *pstatus, v4l2_std_id *pstd) in ks0127_status() argument
593 status = ks0127_read(sd, KS_STAT); in ks0127_status()
616 static int ks0127_querystd(struct v4l2_subdev *sd, v4l2_std_id *std) in ks0127_querystd() argument
618 v4l2_dbg(1, debug, sd, "querystd\n"); in ks0127_querystd()
619 return ks0127_status(sd, NULL, std); in ks0127_querystd()
622 static int ks0127_g_input_status(struct v4l2_subdev *sd, u32 *status) in ks0127_g_input_status() argument
624 v4l2_dbg(1, debug, sd, "g_input_status\n"); in ks0127_g_input_status()
625 return ks0127_status(sd, status, NULL); in ks0127_g_input_status()
628 /* ----------------------------------------------------------------------- */
642 /* ----------------------------------------------------------------------- */
648 struct v4l2_subdev *sd; in ks0127_probe() local
651 client->addr == (I2C_KS0127_ADDON >> 1) ? "addon" : "on-board", in ks0127_probe()
652 client->addr << 1, client->adapter->name); in ks0127_probe()
654 ks = devm_kzalloc(&client->dev, sizeof(*ks), GFP_KERNEL); in ks0127_probe()
656 return -ENOMEM; in ks0127_probe()
657 sd = &ks->sd; in ks0127_probe()
658 v4l2_i2c_subdev_init(sd, client, &ks0127_ops); in ks0127_probe()
662 ks0127_write(sd, KS_CMDA, 0x2c); in ks0127_probe()
666 ks0127_init(sd); in ks0127_probe()
672 struct v4l2_subdev *sd = i2c_get_clientdata(client); in ks0127_remove() local
674 v4l2_device_unregister_subdev(sd); in ks0127_remove()
675 ks0127_write(sd, KS_OFMTA, 0x20); /* tristate */ in ks0127_remove()
676 ks0127_write(sd, KS_CMDA, 0x2c | 0x80); /* power down */ in ks0127_remove()