37 #include <linux/module.h>
39 #include <linux/errno.h>
40 #include <linux/kernel.h>
41 #include <linux/i2c.h>
42 #include <linux/videodev2.h>
43 #include <linux/slab.h>
53 #define I2C_KS0127_ADDON 0xD8
54 #define I2C_KS0127_ONBOARD 0xDA
72 #define KS_PORTAB 0x0e
76 #define KS_CHROMA 0x12
77 #define KS_CHROMB 0x13
81 #define KS_VERTIA 0x17
82 #define KS_VERTIB 0x18
83 #define KS_VERTIC 0x19
90 #define KS_VBICTL 0x20
91 #define KS_CCDAT2 0x21
92 #define KS_CCDAT1 0x22
93 #define KS_VBIL30 0x23
94 #define KS_VBIL74 0x24
95 #define KS_VBIL118 0x25
96 #define KS_VBIL1512 0x26
97 #define KS_TTFRAM 0x27
99 #define KS_UVOFFH 0x29
100 #define KS_UVOFFL 0x2a
101 #define KS_UGAIN 0x2b
102 #define KS_VGAIN 0x2c
105 #define KS_CTRACK 0x2f
106 #define KS_POLCTL 0x30
107 #define KS_REFCOD 0x31
108 #define KS_INVALY 0x32
109 #define KS_INVALU 0x33
110 #define KS_INVALV 0x34
111 #define KS_UNUSEY 0x35
112 #define KS_UNUSEU 0x36
113 #define KS_UNUSEV 0x37
114 #define KS_USRSAV 0x38
115 #define KS_USREAV 0x39
116 #define KS_SHS1A 0x3a
117 #define KS_SHS1B 0x3b
118 #define KS_SHS1C 0x3c
120 #define KS_VSDEL 0x3e
122 #define KS_GAMMA0 0x40
123 #define KS_GAMMA1 0x41
124 #define KS_GAMMA2 0x42
125 #define KS_GAMMA3 0x43
126 #define KS_GAMMA4 0x44
127 #define KS_GAMMA5 0x45
128 #define KS_GAMMA6 0x46
129 #define KS_GAMMA7 0x47
130 #define KS_GAMMA8 0x48
131 #define KS_GAMMA9 0x49
132 #define KS_GAMMA10 0x4a
133 #define KS_GAMMA11 0x4b
134 #define KS_GAMMA12 0x4c
135 #define KS_GAMMA13 0x4d
136 #define KS_GAMMA14 0x4e
137 #define KS_GAMMA15 0x4f
138 #define KS_GAMMA16 0x50
139 #define KS_GAMMA17 0x51
140 #define KS_GAMMA18 0x52
141 #define KS_GAMMA19 0x53
142 #define KS_GAMMA20 0x54
143 #define KS_GAMMA21 0x55
144 #define KS_GAMMA22 0x56
145 #define KS_GAMMA23 0x57
146 #define KS_GAMMA24 0x58
147 #define KS_GAMMA25 0x59
148 #define KS_GAMMA26 0x5a
149 #define KS_GAMMA27 0x5b
150 #define KS_GAMMA28 0x5c
151 #define KS_GAMMA29 0x5d
152 #define KS_GAMMA30 0x5e
153 #define KS_GAMMA31 0x5f
154 #define KS_GAMMAD0 0x60
155 #define KS_GAMMAD1 0x61
156 #define KS_GAMMAD2 0x62
157 #define KS_GAMMAD3 0x63
158 #define KS_GAMMAD4 0x64
159 #define KS_GAMMAD5 0x65
160 #define KS_GAMMAD6 0x66
161 #define KS_GAMMAD7 0x67
162 #define KS_GAMMAD8 0x68
163 #define KS_GAMMAD9 0x69
164 #define KS_GAMMAD10 0x6a
165 #define KS_GAMMAD11 0x6b
166 #define KS_GAMMAD12 0x6c
167 #define KS_GAMMAD13 0x6d
168 #define KS_GAMMAD14 0x6e
169 #define KS_GAMMAD15 0x6f
170 #define KS_GAMMAD16 0x70
171 #define KS_GAMMAD17 0x71
172 #define KS_GAMMAD18 0x72
173 #define KS_GAMMAD19 0x73
174 #define KS_GAMMAD20 0x74
175 #define KS_GAMMAD21 0x75
176 #define KS_GAMMAD22 0x76
177 #define KS_GAMMAD23 0x77
178 #define KS_GAMMAD24 0x78
179 #define KS_GAMMAD25 0x79
180 #define KS_GAMMAD26 0x7a
181 #define KS_GAMMAD27 0x7b
182 #define KS_GAMMAD28 0x7c
183 #define KS_GAMMAD29 0x7d
184 #define KS_GAMMAD30 0x7e
185 #define KS_GAMMAD31 0x7f
218 static u8 reg_defaults[64];
220 static void init_reg_defaults(
void)
328 .addr = client->
addr,
346 struct i2c_client *client = v4l2_get_subdevdata(sd);
348 char msg[] = {
reg, val };
360 struct ks0127 *ks = to_ks0127(sd);
363 val = (val & and_v) | or_v;
364 ks0127_write(sd, reg, val);
374 struct ks0127 *ks = to_ks0127(sd);
375 u8 *table = reg_defaults;
386 for (i = 1; i < 33; i++)
387 ks0127_write(sd, i, table[i]);
389 for (i = 35; i < 40; i++)
390 ks0127_write(sd, i, table[i]);
392 for (i = 41; i < 56; i++)
393 ks0127_write(sd, i, table[i]);
395 for (i = 58; i < 64; i++)
396 ks0127_write(sd, i, table[i]);
399 if ((ks0127_read(sd,
KS_STAT) & 0x80) == 0) {
405 switch (ks0127_read(sd,
KS_CMDE) & 0x0f) {
421 static int ks0127_s_routing(
struct v4l2_subdev *sd,
424 struct ks0127 *ks = to_ks0127(sd);
434 "s_routing %d: Composite\n", input);
436 ks0127_and_or(sd,
KS_CMDA, 0xfc, 0x00);
438 ks0127_and_or(sd,
KS_CMDA, ~0x40, 0x00);
440 ks0127_and_or(sd,
KS_CMDB, 0xb0, input);
442 ks0127_and_or(sd,
KS_CMDC, 0x70, 0x0a);
444 ks0127_and_or(sd,
KS_CMDD, 0x03, 0x00);
446 ks0127_and_or(sd,
KS_CTRACK, 0xcf, 0x00);
448 ks0127_and_or(sd,
KS_LUMA, 0x00,
451 ks0127_and_or(sd,
KS_VERTIA, 0x08, 0x81);
453 ks0127_and_or(sd,
KS_VERTIC, 0x0f, 0x90);
456 ks0127_and_or(sd,
KS_CHROMB, 0x0f, 0x90);
468 "s_routing %d: S-Video\n", input);
470 ks0127_and_or(sd,
KS_CMDA, 0xfc, 0x00);
472 ks0127_and_or(sd,
KS_CMDA, ~0x40, 0x00);
474 ks0127_and_or(sd,
KS_CMDB, 0xb0, input);
476 ks0127_and_or(sd,
KS_CMDC, 0x70, 0x0a);
478 ks0127_and_or(sd,
KS_CMDD, 0x03, 0x00);
480 ks0127_and_or(sd,
KS_CTRACK, 0xcf, 0x00);
481 ks0127_and_or(sd,
KS_LUMA, 0x00,
502 ks0127_and_or(sd,
KS_CMDA, 0xfc, 0x03);
505 ks0127_and_or(sd,
KS_CMDA, 0xfc, 0x02);
507 ks0127_and_or(sd,
KS_CMDA, 0xff, 0x40);
509 ks0127_and_or(sd,
KS_CMDB, 0xb0, (input | 0x40));
512 ks0127_and_or(sd,
KS_CMDC, 0x70, 0x87);
514 ks0127_and_or(sd,
KS_CMDD, 0x03, 0x08);
516 ks0127_and_or(sd,
KS_CTRACK, 0xcf, 0x30);
518 ks0127_and_or(sd,
KS_LUMA, 0x00, 0x71);
523 ks0127_and_or(sd,
KS_VERTIA, 0x08, 0x81);
528 ks0127_and_or(sd,
KS_CON, 0x00, 0x00);
529 ks0127_and_or(sd,
KS_BRT, 0x00, 32);
531 ks0127_and_or(sd,
KS_SAT, 0x00, 0xe8);
532 ks0127_and_or(sd,
KS_HUE, 0x00, 0);
534 ks0127_and_or(sd,
KS_UGAIN, 0x00, 238);
535 ks0127_and_or(sd,
KS_VGAIN, 0x00, 0x00);
538 ks0127_and_or(sd,
KS_UVOFFH, 0x00, 0x4f);
539 ks0127_and_or(sd,
KS_UVOFFL, 0x00, 0x00);
544 "s_routing: Unknown input %d\n", input);
556 struct ks0127 *ks = to_ks0127(sd);
559 ks0127_and_or(sd,
KS_DEMOD, 0xf0, 0x00);
565 ks0127_and_or(sd,
KS_CHROMA, 0x9f, 0x20);
568 "s_std: NTSC_N (fixme)\n");
569 ks0127_and_or(sd,
KS_CHROMA, 0x9f, 0x40);
573 ks0127_and_or(sd,
KS_CHROMA, 0x9f, 0x20);
576 "s_std: PAL_M (fixme)\n");
577 ks0127_and_or(sd,
KS_CHROMA, 0x9f, 0x40);
583 ks0127_and_or(sd,
KS_CHROMA, 0xdf, 0x20);
584 ks0127_and_or(sd,
KS_DEMOD, 0xf0, 0x00);
588 if (!(ks0127_read(sd,
KS_DEMOD) & 0x40))
590 ks0127_and_or(sd,
KS_DEMOD, 0xf0, 0x0f);
593 (
unsigned long long)std);
603 ks0127_and_or(sd,
KS_OFMTA, 0xcf, 0x30);
605 ks0127_and_or(sd,
KS_CDEM, 0x7f, 0x00);
608 ks0127_and_or(sd,
KS_OFMTA, 0xcf, 0x00);
610 ks0127_and_or(sd,
KS_CDEM, 0x7f, 0x80);
621 status = ks0127_read(sd,
KS_STAT);
622 if (!(status & 0x20))
624 if (!(status & 0x01))
640 return ks0127_status(sd,
NULL, std);
643 static int ks0127_g_input_status(
struct v4l2_subdev *sd,
u32 *status)
646 return ks0127_status(sd, status,
NULL);
651 struct i2c_client *client = v4l2_get_subdevdata(sd);
652 struct ks0127 *ks = to_ks0127(sd);
660 .g_chip_ident = ks0127_g_chip_ident,
661 .s_std = ks0127_s_std,
665 .s_routing = ks0127_s_routing,
666 .s_stream = ks0127_s_stream,
667 .querystd = ks0127_querystd,
668 .g_input_status = ks0127_g_input_status,
672 .core = &ks0127_core_ops,
673 .video = &ks0127_video_ops,
684 v4l_info(client,
"%s chip found @ 0x%x (%s)\n",
696 ks0127_write(sd,
KS_CMDA, 0x2c);
704 static int ks0127_remove(
struct i2c_client *client)
706 struct v4l2_subdev *sd = i2c_get_clientdata(client);
710 ks0127_write(sd,
KS_CMDA, 0x2c | 0x80);
711 kfree(to_ks0127(sd));
728 .probe = ks0127_probe,
729 .remove = ks0127_remove,
730 .id_table = ks0127_id,