2 * tvp5150 - Texas Instruments TVP5150A(M) video decoder driver
4 * Copyright (c) 2005 Mauro Carvalho Chehab (mchehab@brturbo.com.br)
5 * This code is placed under the terms of the GNU General Public License
9 #include <linux/videodev.h>
10 #include <linux/delay.h>
11 #include <linux/video_decoder.h>
13 #include "tvp5150_reg.h"
15 MODULE_DESCRIPTION("Texas Instruments TVP5150A video decoder driver"); /* standard i2c insmod options */
16 MODULE_AUTHOR("Mauro Carvalho Chehab");
17 MODULE_LICENSE("GPL");
19 static unsigned short normal_i2c[] = {
28 module_param(debug, int, 0);
29 MODULE_PARM_DESC(debug, "Debug level (0-1)");
31 #define dprintk(num, format, args...) \
34 printk(format, ##args); \
37 /* supported controls */
38 static struct v4l2_queryctrl tvp5150_qctrl[] = {
40 .id = V4L2_CID_BRIGHTNESS,
41 .type = V4L2_CTRL_TYPE_INTEGER,
49 .id = V4L2_CID_CONTRAST,
50 .type = V4L2_CTRL_TYPE_INTEGER,
55 .default_value = 0x10,
58 .id = V4L2_CID_SATURATION,
59 .type = V4L2_CTRL_TYPE_INTEGER,
64 .default_value = 0x10,
68 .type = V4L2_CTRL_TYPE_INTEGER,
73 .default_value = 0x10,
79 struct i2c_client *client;
90 static inline int tvp5150_read(struct i2c_client *c, unsigned char addr)
92 unsigned char buffer[1];
96 if (1 != (rc = i2c_master_send(c, buffer, 1)))
97 dprintk(0, "i2c i/o error: rc == %d (should be 1)\n", rc);
101 if (1 != (rc = i2c_master_recv(c, buffer, 1)))
102 dprintk(0, "i2c i/o error: rc == %d (should be 1)\n", rc);
107 static inline void tvp5150_write(struct i2c_client *c, unsigned char addr,
110 unsigned char buffer[2];
112 /* struct tvp5150 *core = i2c_get_clientdata(c); */
116 dprintk(1, "tvp5150: writing 0x%02x 0x%02x\n", buffer[0], buffer[1]);
117 if (2 != (rc = i2c_master_send(c, buffer, 2)))
118 dprintk(0, "i2c i/o error: rc == %d (should be 2)\n", rc);
121 static void dump_reg(struct i2c_client *c)
123 printk("tvp5150: Video input source selection #1 = 0x%02x\n",
124 tvp5150_read(c, TVP5150_VD_IN_SRC_SEL_1));
125 printk("tvp5150: Analog channel controls = 0x%02x\n",
126 tvp5150_read(c, TVP5150_ANAL_CHL_CTL));
127 printk("tvp5150: Operation mode controls = 0x%02x\n",
128 tvp5150_read(c, TVP5150_OP_MODE_CTL));
129 printk("tvp5150: Miscellaneous controls = 0x%02x\n",
130 tvp5150_read(c, TVP5150_MISC_CTL));
131 printk("tvp5150: Autoswitch mask: TVP5150A / TVP5150AM = 0x%02x\n",
132 tvp5150_read(c, TVP5150_AUTOSW_MSK));
133 printk("tvp5150: Color killer threshold control = 0x%02x\n",
134 tvp5150_read(c, TVP5150_COLOR_KIL_THSH_CTL));
135 printk("tvp5150: Luminance processing control #1 = 0x%02x\n",
136 tvp5150_read(c, TVP5150_LUMA_PROC_CTL_1));
137 printk("tvp5150: Luminance processing control #2 = 0x%02x\n",
138 tvp5150_read(c, TVP5150_LUMA_PROC_CTL_2));
139 printk("tvp5150: Brightness control = 0x%02x\n",
140 tvp5150_read(c, TVP5150_BRIGHT_CTL));
141 printk("tvp5150: Color saturation control = 0x%02x\n",
142 tvp5150_read(c, TVP5150_SATURATION_CTL));
143 printk("tvp5150: Hue control = 0x%02x\n",
144 tvp5150_read(c, TVP5150_HUE_CTL));
145 printk("tvp5150: Contrast control = 0x%02x\n",
146 tvp5150_read(c, TVP5150_CONTRAST_CTL));
147 printk("tvp5150: Outputs and data rates select = 0x%02x\n",
148 tvp5150_read(c, TVP5150_DATA_RATE_SEL));
149 printk("tvp5150: Luminance processing control #3 = 0x%02x\n",
150 tvp5150_read(c, TVP5150_LUMA_PROC_CTL_3));
151 printk("tvp5150: Configuration shared pins = 0x%02x\n",
152 tvp5150_read(c, TVP5150_CONF_SHARED_PIN));
153 printk("tvp5150: Active video cropping start MSB = 0x%02x\n",
154 tvp5150_read(c, TVP5150_ACT_VD_CROP_ST_MSB));
155 printk("tvp5150: Active video cropping start LSB = 0x%02x\n",
156 tvp5150_read(c, TVP5150_ACT_VD_CROP_ST_LSB));
157 printk("tvp5150: Active video cropping stop MSB = 0x%02x\n",
158 tvp5150_read(c, TVP5150_ACT_VD_CROP_STP_MSB));
159 printk("tvp5150: Active video cropping stop LSB = 0x%02x\n",
160 tvp5150_read(c, TVP5150_ACT_VD_CROP_STP_LSB));
161 printk("tvp5150: Genlock/RTC = 0x%02x\n",
162 tvp5150_read(c, TVP5150_GENLOCK));
163 printk("tvp5150: Horizontal sync start = 0x%02x\n",
164 tvp5150_read(c, TVP5150_HORIZ_SYNC_START));
165 printk("tvp5150: Vertical blanking start = 0x%02x\n",
166 tvp5150_read(c, TVP5150_VERT_BLANKING_START));
167 printk("tvp5150: Vertical blanking stop = 0x%02x\n",
168 tvp5150_read(c, TVP5150_VERT_BLANKING_STOP));
169 printk("tvp5150: Chrominance processing control #1 = 0x%02x\n",
170 tvp5150_read(c, TVP5150_CHROMA_PROC_CTL_1));
171 printk("tvp5150: Chrominance processing control #2 = 0x%02x\n",
172 tvp5150_read(c, TVP5150_CHROMA_PROC_CTL_2));
173 printk("tvp5150: Interrupt reset register B = 0x%02x\n",
174 tvp5150_read(c, TVP5150_INT_RESET_REG_B));
175 printk("tvp5150: Interrupt enable register B = 0x%02x\n",
176 tvp5150_read(c, TVP5150_INT_ENABLE_REG_B));
177 printk("tvp5150: Interrupt configuration register B = 0x%02x\n",
178 tvp5150_read(c, TVP5150_INTT_CONFIG_REG_B));
179 printk("tvp5150: Video standard = 0x%02x\n",
180 tvp5150_read(c, TVP5150_VIDEO_STD));
181 printk("tvp5150: Cb gain factor = 0x%02x\n",
182 tvp5150_read(c, TVP5150_CB_GAIN_FACT));
183 printk("tvp5150: Cr gain factor = 0x%02x\n",
184 tvp5150_read(c, TVP5150_CR_GAIN_FACTOR));
185 printk("tvp5150: Macrovision on counter = 0x%02x\n",
186 tvp5150_read(c, TVP5150_MACROVISION_ON_CTR));
187 printk("tvp5150: Macrovision off counter = 0x%02x\n",
188 tvp5150_read(c, TVP5150_MACROVISION_OFF_CTR));
189 printk("tvp5150: revision select (TVP5150AM1 only) = 0x%02x\n",
190 tvp5150_read(c, TVP5150_REV_SELECT));
191 printk("tvp5150: MSB of device ID = 0x%02x\n",
192 tvp5150_read(c, TVP5150_MSB_DEV_ID));
193 printk("tvp5150: LSB of device ID = 0x%02x\n",
194 tvp5150_read(c, TVP5150_LSB_DEV_ID));
195 printk("tvp5150: ROM major version = 0x%02x\n",
196 tvp5150_read(c, TVP5150_ROM_MAJOR_VER));
197 printk("tvp5150: ROM minor version = 0x%02x\n",
198 tvp5150_read(c, TVP5150_ROM_MINOR_VER));
199 printk("tvp5150: Vertical line count MSB = 0x%02x\n",
200 tvp5150_read(c, TVP5150_VERT_LN_COUNT_MSB));
201 printk("tvp5150: Vertical line count LSB = 0x%02x\n",
202 tvp5150_read(c, TVP5150_VERT_LN_COUNT_LSB));
203 printk("tvp5150: Interrupt status register B = 0x%02x\n",
204 tvp5150_read(c, TVP5150_INT_STATUS_REG_B));
205 printk("tvp5150: Interrupt active register B = 0x%02x\n",
206 tvp5150_read(c, TVP5150_INT_ACTIVE_REG_B));
207 printk("tvp5150: Status register #1 = 0x%02x\n",
208 tvp5150_read(c, TVP5150_STATUS_REG_1));
209 printk("tvp5150: Status register #2 = 0x%02x\n",
210 tvp5150_read(c, TVP5150_STATUS_REG_2));
211 printk("tvp5150: Status register #3 = 0x%02x\n",
212 tvp5150_read(c, TVP5150_STATUS_REG_3));
213 printk("tvp5150: Status register #4 = 0x%02x\n",
214 tvp5150_read(c, TVP5150_STATUS_REG_4));
215 printk("tvp5150: Status register #5 = 0x%02x\n",
216 tvp5150_read(c, TVP5150_STATUS_REG_5));
217 printk("tvp5150: Closed caption data registers = 0x%02x\n",
218 tvp5150_read(c, TVP5150_CC_DATA_REG1));
219 printk("tvp5150: Closed caption data registers = 0x%02x\n",
220 tvp5150_read(c, TVP5150_CC_DATA_REG2));
221 printk("tvp5150: Closed caption data registers = 0x%02x\n",
222 tvp5150_read(c, TVP5150_CC_DATA_REG3));
223 printk("tvp5150: Closed caption data registers = 0x%02x\n",
224 tvp5150_read(c, TVP5150_CC_DATA_REG4));
225 printk("tvp5150: WSS data registers = 0x%02x\n",
226 tvp5150_read(c, TVP5150_WSS_DATA_REG1));
227 printk("tvp5150: WSS data registers = 0x%02x\n",
228 tvp5150_read(c, TVP5150_WSS_DATA_REG2));
229 printk("tvp5150: WSS data registers = 0x%02x\n",
230 tvp5150_read(c, TVP5150_WSS_DATA_REG3));
231 printk("tvp5150: WSS data registers = 0x%02x\n",
232 tvp5150_read(c, TVP5150_WSS_DATA_REG4));
233 printk("tvp5150: WSS data registers = 0x%02x\n",
234 tvp5150_read(c, TVP5150_WSS_DATA_REG5));
235 printk("tvp5150: WSS data registers = 0x%02x\n",
236 tvp5150_read(c, TVP5150_WSS_DATA_REG6));
237 printk("tvp5150: VPS data registers = 0x%02x\n",
238 tvp5150_read(c, TVP5150_VPS_DATA_REG1));
239 printk("tvp5150: VPS data registers = 0x%02x\n",
240 tvp5150_read(c, TVP5150_VPS_DATA_REG2));
241 printk("tvp5150: VPS data registers = 0x%02x\n",
242 tvp5150_read(c, TVP5150_VPS_DATA_REG3));
243 printk("tvp5150: VPS data registers = 0x%02x\n",
244 tvp5150_read(c, TVP5150_VPS_DATA_REG4));
245 printk("tvp5150: VPS data registers = 0x%02x\n",
246 tvp5150_read(c, TVP5150_VPS_DATA_REG5));
247 printk("tvp5150: VPS data registers = 0x%02x\n",
248 tvp5150_read(c, TVP5150_VPS_DATA_REG6));
249 printk("tvp5150: VPS data registers = 0x%02x\n",
250 tvp5150_read(c, TVP5150_VPS_DATA_REG7));
251 printk("tvp5150: VPS data registers = 0x%02x\n",
252 tvp5150_read(c, TVP5150_VPS_DATA_REG8));
253 printk("tvp5150: VPS data registers = 0x%02x\n",
254 tvp5150_read(c, TVP5150_VPS_DATA_REG9));
255 printk("tvp5150: VPS data registers = 0x%02x\n",
256 tvp5150_read(c, TVP5150_VPS_DATA_REG10));
257 printk("tvp5150: VPS data registers = 0x%02x\n",
258 tvp5150_read(c, TVP5150_VPS_DATA_REG11));
259 printk("tvp5150: VPS data registers = 0x%02x\n",
260 tvp5150_read(c, TVP5150_VPS_DATA_REG12));
261 printk("tvp5150: VPS data registers = 0x%02x\n",
262 tvp5150_read(c, TVP5150_VPS_DATA_REG13));
263 printk("tvp5150: VITC data registers = 0x%02x\n",
264 tvp5150_read(c, TVP5150_VITC_DATA_REG1));
265 printk("tvp5150: VITC data registers = 0x%02x\n",
266 tvp5150_read(c, TVP5150_VITC_DATA_REG2));
267 printk("tvp5150: VITC data registers = 0x%02x\n",
268 tvp5150_read(c, TVP5150_VITC_DATA_REG3));
269 printk("tvp5150: VITC data registers = 0x%02x\n",
270 tvp5150_read(c, TVP5150_VITC_DATA_REG4));
271 printk("tvp5150: VITC data registers = 0x%02x\n",
272 tvp5150_read(c, TVP5150_VITC_DATA_REG5));
273 printk("tvp5150: VITC data registers = 0x%02x\n",
274 tvp5150_read(c, TVP5150_VITC_DATA_REG6));
275 printk("tvp5150: VITC data registers = 0x%02x\n",
276 tvp5150_read(c, TVP5150_VITC_DATA_REG7));
277 printk("tvp5150: VITC data registers = 0x%02x\n",
278 tvp5150_read(c, TVP5150_VITC_DATA_REG8));
279 printk("tvp5150: VITC data registers = 0x%02x\n",
280 tvp5150_read(c, TVP5150_VITC_DATA_REG9));
281 printk("tvp5150: VBI FIFO read data = 0x%02x\n",
282 tvp5150_read(c, TVP5150_VBI_FIFO_READ_DATA));
283 printk("tvp5150: Teletext filter 1 = 0x%02x\n",
284 tvp5150_read(c, TVP5150_TELETEXT_FIL_1_1));
285 printk("tvp5150: Teletext filter 1 = 0x%02x\n",
286 tvp5150_read(c, TVP5150_TELETEXT_FIL_1_2));
287 printk("tvp5150: Teletext filter 1 = 0x%02x\n",
288 tvp5150_read(c, TVP5150_TELETEXT_FIL_1_3));
289 printk("tvp5150: Teletext filter 1 = 0x%02x\n",
290 tvp5150_read(c, TVP5150_TELETEXT_FIL_1_4));
291 printk("tvp5150: Teletext filter 1 = 0x%02x\n",
292 tvp5150_read(c, TVP5150_TELETEXT_FIL_1_5));
293 printk("tvp5150: Teletext filter 2 = 0x%02x\n",
294 tvp5150_read(c, TVP5150_TELETEXT_FIL_2_1));
295 printk("tvp5150: Teletext filter 2 = 0x%02x\n",
296 tvp5150_read(c, TVP5150_TELETEXT_FIL_2_2));
297 printk("tvp5150: Teletext filter 2 = 0x%02x\n",
298 tvp5150_read(c, TVP5150_TELETEXT_FIL_2_3));
299 printk("tvp5150: Teletext filter 2 = 0x%02x\n",
300 tvp5150_read(c, TVP5150_TELETEXT_FIL_2_4));
301 printk("tvp5150: Teletext filter 2 = 0x%02x\n",
302 tvp5150_read(c, TVP5150_TELETEXT_FIL_2_5));
303 printk("tvp5150: Teletext filter enable = 0x%02x\n",
304 tvp5150_read(c, TVP5150_TELETEXT_FIL_ENA));
305 printk("tvp5150: Interrupt status register A = 0x%02x\n",
306 tvp5150_read(c, TVP5150_INT_STATUS_REG_A));
307 printk("tvp5150: Interrupt enable register A = 0x%02x\n",
308 tvp5150_read(c, TVP5150_INT_ENABLE_REG_A));
309 printk("tvp5150: Interrupt configuration = 0x%02x\n",
310 tvp5150_read(c, TVP5150_INT_CONF));
311 printk("tvp5150: VDP configuration RAM data = 0x%02x\n",
312 tvp5150_read(c, TVP5150_VDP_CONF_RAM_DATA));
313 printk("tvp5150: Configuration RAM address low byte = 0x%02x\n",
314 tvp5150_read(c, TVP5150_CONF_RAM_ADDR_LOW));
315 printk("tvp5150: Configuration RAM address high byte = 0x%02x\n",
316 tvp5150_read(c, TVP5150_CONF_RAM_ADDR_HIGH));
317 printk("tvp5150: VDP status register = 0x%02x\n",
318 tvp5150_read(c, TVP5150_VDP_STATUS_REG));
319 printk("tvp5150: FIFO word count = 0x%02x\n",
320 tvp5150_read(c, TVP5150_FIFO_WORD_COUNT));
321 printk("tvp5150: FIFO interrupt threshold = 0x%02x\n",
322 tvp5150_read(c, TVP5150_FIFO_INT_THRESHOLD));
323 printk("tvp5150: FIFO reset = 0x%02x\n",
324 tvp5150_read(c, TVP5150_FIFO_RESET));
325 printk("tvp5150: Line number interrupt = 0x%02x\n",
326 tvp5150_read(c, TVP5150_LINE_NUMBER_INT));
327 printk("tvp5150: Pixel alignment register low byte = 0x%02x\n",
328 tvp5150_read(c, TVP5150_PIX_ALIGN_REG_LOW));
329 printk("tvp5150: Pixel alignment register high byte = 0x%02x\n",
330 tvp5150_read(c, TVP5150_PIX_ALIGN_REG_HIGH));
331 printk("tvp5150: FIFO output control = 0x%02x\n",
332 tvp5150_read(c, TVP5150_FIFO_OUT_CTRL));
333 printk("tvp5150: Full field enable 1 = 0x%02x\n",
334 tvp5150_read(c, TVP5150_FULL_FIELD_ENA_1));
335 printk("tvp5150: Full field enable 2 = 0x%02x\n",
336 tvp5150_read(c, TVP5150_FULL_FIELD_ENA_2));
337 printk("tvp5150: Line mode registers = 0x%02x\n",
338 tvp5150_read(c, TVP5150_LINE_MODE_REG_1));
339 printk("tvp5150: Line mode registers = 0x%02x\n",
340 tvp5150_read(c, TVP5150_LINE_MODE_REG_2));
341 printk("tvp5150: Line mode registers = 0x%02x\n",
342 tvp5150_read(c, TVP5150_LINE_MODE_REG_3));
343 printk("tvp5150: Line mode registers = 0x%02x\n",
344 tvp5150_read(c, TVP5150_LINE_MODE_REG_4));
345 printk("tvp5150: Line mode registers = 0x%02x\n",
346 tvp5150_read(c, TVP5150_LINE_MODE_REG_5));
347 printk("tvp5150: Line mode registers = 0x%02x\n",
348 tvp5150_read(c, TVP5150_LINE_MODE_REG_6));
349 printk("tvp5150: Line mode registers = 0x%02x\n",
350 tvp5150_read(c, TVP5150_LINE_MODE_REG_7));
351 printk("tvp5150: Line mode registers = 0x%02x\n",
352 tvp5150_read(c, TVP5150_LINE_MODE_REG_8));
353 printk("tvp5150: Line mode registers = 0x%02x\n",
354 tvp5150_read(c, TVP5150_LINE_MODE_REG_9));
355 printk("tvp5150: Line mode registers = 0x%02x\n",
356 tvp5150_read(c, TVP5150_LINE_MODE_REG_10));
357 printk("tvp5150: Line mode registers = 0x%02x\n",
358 tvp5150_read(c, TVP5150_LINE_MODE_REG_11));
359 printk("tvp5150: Line mode registers = 0x%02x\n",
360 tvp5150_read(c, TVP5150_LINE_MODE_REG_12));
361 printk("tvp5150: Line mode registers = 0x%02x\n",
362 tvp5150_read(c, TVP5150_LINE_MODE_REG_13));
363 printk("tvp5150: Line mode registers = 0x%02x\n",
364 tvp5150_read(c, TVP5150_LINE_MODE_REG_14));
365 printk("tvp5150: Line mode registers = 0x%02x\n",
366 tvp5150_read(c, TVP5150_LINE_MODE_REG_15));
367 printk("tvp5150: Line mode registers = 0x%02x\n",
368 tvp5150_read(c, TVP5150_LINE_MODE_REG_16));
369 printk("tvp5150: Line mode registers = 0x%02x\n",
370 tvp5150_read(c, TVP5150_LINE_MODE_REG_17));
371 printk("tvp5150: Line mode registers = 0x%02x\n",
372 tvp5150_read(c, TVP5150_LINE_MODE_REG_18));
373 printk("tvp5150: Line mode registers = 0x%02x\n",
374 tvp5150_read(c, TVP5150_LINE_MODE_REG_19));
375 printk("tvp5150: Line mode registers = 0x%02x\n",
376 tvp5150_read(c, TVP5150_LINE_MODE_REG_20));
377 printk("tvp5150: Line mode registers = 0x%02x\n",
378 tvp5150_read(c, TVP5150_LINE_MODE_REG_21));
379 printk("tvp5150: Line mode registers = 0x%02x\n",
380 tvp5150_read(c, TVP5150_LINE_MODE_REG_22));
381 printk("tvp5150: Line mode registers = 0x%02x\n",
382 tvp5150_read(c, TVP5150_LINE_MODE_REG_23));
383 printk("tvp5150: Line mode registers = 0x%02x\n",
384 tvp5150_read(c, TVP5150_LINE_MODE_REG_24));
385 printk("tvp5150: Line mode registers = 0x%02x\n",
386 tvp5150_read(c, TVP5150_LINE_MODE_REG_25));
387 printk("tvp5150: Line mode registers = 0x%02x\n",
388 tvp5150_read(c, TVP5150_LINE_MODE_REG_27));
389 printk("tvp5150: Line mode registers = 0x%02x\n",
390 tvp5150_read(c, TVP5150_LINE_MODE_REG_28));
391 printk("tvp5150: Line mode registers = 0x%02x\n",
392 tvp5150_read(c, TVP5150_LINE_MODE_REG_29));
393 printk("tvp5150: Line mode registers = 0x%02x\n",
394 tvp5150_read(c, TVP5150_LINE_MODE_REG_30));
395 printk("tvp5150: Line mode registers = 0x%02x\n",
396 tvp5150_read(c, TVP5150_LINE_MODE_REG_31));
397 printk("tvp5150: Line mode registers = 0x%02x\n",
398 tvp5150_read(c, TVP5150_LINE_MODE_REG_32));
399 printk("tvp5150: Line mode registers = 0x%02x\n",
400 tvp5150_read(c, TVP5150_LINE_MODE_REG_33));
401 printk("tvp5150: Line mode registers = 0x%02x\n",
402 tvp5150_read(c, TVP5150_LINE_MODE_REG_34));
403 printk("tvp5150: Line mode registers = 0x%02x\n",
404 tvp5150_read(c, TVP5150_LINE_MODE_REG_35));
405 printk("tvp5150: Line mode registers = 0x%02x\n",
406 tvp5150_read(c, TVP5150_LINE_MODE_REG_36));
407 printk("tvp5150: Line mode registers = 0x%02x\n",
408 tvp5150_read(c, TVP5150_LINE_MODE_REG_37));
409 printk("tvp5150: Line mode registers = 0x%02x\n",
410 tvp5150_read(c, TVP5150_LINE_MODE_REG_38));
411 printk("tvp5150: Line mode registers = 0x%02x\n",
412 tvp5150_read(c, TVP5150_LINE_MODE_REG_39));
413 printk("tvp5150: Line mode registers = 0x%02x\n",
414 tvp5150_read(c, TVP5150_LINE_MODE_REG_40));
415 printk("tvp5150: Line mode registers = 0x%02x\n",
416 tvp5150_read(c, TVP5150_LINE_MODE_REG_41));
417 printk("tvp5150: Line mode registers = 0x%02x\n",
418 tvp5150_read(c, TVP5150_LINE_MODE_REG_42));
419 printk("tvp5150: Line mode registers = 0x%02x\n",
420 tvp5150_read(c, TVP5150_LINE_MODE_REG_43));
421 printk("tvp5150: Line mode registers = 0x%02x\n",
422 tvp5150_read(c, TVP5150_LINE_MODE_REG_44));
423 printk("tvp5150: Full field mode register = 0x%02x\n",
424 tvp5150_read(c, TVP5150_FULL_FIELD_MODE_REG));
427 /****************************************************************************
429 ****************************************************************************/
431 TVP5150_ANALOG_CH0 = 0,
433 TVP5150_ANALOG_CH1 = 2,
434 TVP5150_BLACK_SCREEN = 8
437 static inline void tvp5150_selmux(struct i2c_client *c,
438 enum tvp5150_input input)
440 struct tvp5150 *decoder = i2c_get_clientdata(c);
442 if (!decoder->enable)
443 input |= TVP5150_BLACK_SCREEN;
445 tvp5150_write(c, TVP5150_VD_IN_SRC_SEL_1, input);
448 static inline void tvp5150_reset(struct i2c_client *c)
450 struct tvp5150 *decoder = i2c_get_clientdata(c);
452 tvp5150_write(c, TVP5150_CONF_SHARED_PIN, 2);
454 /* Automatic offset and AGC enabled */
455 tvp5150_write(c, TVP5150_ANAL_CHL_CTL, 0x15);
457 /* Normal Operation */
458 // tvp5150_write(c, TVP5150_OP_MODE_CTL, 0x00);
460 /* Activate YCrCb output 0x9 or 0xd ? */
461 tvp5150_write(c, TVP5150_MISC_CTL, 0x6f);
463 /* Activates video std autodetection for all standards */
464 tvp5150_write(c, TVP5150_AUTOSW_MSK, 0x0);
466 /* Default format: 0x47, 4:2:2: 0x40 */
467 tvp5150_write(c, TVP5150_DATA_RATE_SEL, 0x47);
469 tvp5150_selmux(c, decoder->input);
471 tvp5150_write(c, TVP5150_CHROMA_PROC_CTL_1, 0x0c);
472 tvp5150_write(c, TVP5150_CHROMA_PROC_CTL_2, 0x54);
474 tvp5150_write(c, 0x27, 0x20); /* ?????????? */
476 tvp5150_write(c, TVP5150_VIDEO_STD, 0x0); /* Auto switch */
478 tvp5150_write(c, TVP5150_BRIGHT_CTL, decoder->bright >> 8);
479 tvp5150_write(c, TVP5150_CONTRAST_CTL, decoder->contrast >> 8);
480 tvp5150_write(c, TVP5150_SATURATION_CTL, decoder->contrast >> 8);
481 tvp5150_write(c, TVP5150_HUE_CTL, (decoder->hue - 32768) >> 8);
484 static int tvp5150_get_ctrl(struct i2c_client *c, struct v4l2_control *ctrl)
486 /* struct tvp5150 *decoder = i2c_get_clientdata(c); */
489 case V4L2_CID_BRIGHTNESS:
490 ctrl->value = tvp5150_read(c, TVP5150_BRIGHT_CTL);
492 case V4L2_CID_CONTRAST:
493 ctrl->value = tvp5150_read(c, TVP5150_CONTRAST_CTL);
495 case V4L2_CID_SATURATION:
496 ctrl->value = tvp5150_read(c, TVP5150_SATURATION_CTL);
499 ctrl->value = tvp5150_read(c, TVP5150_HUE_CTL);
506 static int tvp5150_set_ctrl(struct i2c_client *c, struct v4l2_control *ctrl)
508 /* struct tvp5150 *decoder = i2c_get_clientdata(c); */
511 case V4L2_CID_BRIGHTNESS:
512 tvp5150_write(c, TVP5150_BRIGHT_CTL, ctrl->value);
514 case V4L2_CID_CONTRAST:
515 tvp5150_write(c, TVP5150_CONTRAST_CTL, ctrl->value);
517 case V4L2_CID_SATURATION:
518 tvp5150_write(c, TVP5150_SATURATION_CTL, ctrl->value);
521 tvp5150_write(c, TVP5150_HUE_CTL, ctrl->value);
528 /****************************************************************************
530 ****************************************************************************/
531 static int tvp5150_command(struct i2c_client *client,
532 unsigned int cmd, void *arg)
534 struct tvp5150 *decoder = i2c_get_clientdata(client);
540 tvp5150_reset(client);
547 case DECODER_GET_CAPABILITIES:
549 struct video_decoder_capability *cap = arg;
551 cap->flags = VIDEO_DECODER_PAL |
553 VIDEO_DECODER_SECAM |
554 VIDEO_DECODER_AUTO | VIDEO_DECODER_CCIR;
559 case DECODER_GET_STATUS:
564 case DECODER_SET_GPIO:
567 case DECODER_SET_VBI_BYPASS:
570 case DECODER_SET_NORM:
576 case VIDEO_MODE_NTSC:
582 case VIDEO_MODE_SECAM:
585 case VIDEO_MODE_AUTO:
592 decoder->norm = *iarg;
595 case DECODER_SET_INPUT:
598 if (*iarg < 0 || *iarg > 3) {
602 decoder->input = *iarg;
603 tvp5150_selmux(client, decoder->input);
607 case DECODER_SET_OUTPUT:
611 /* not much choice of outputs */
617 case DECODER_ENABLE_OUTPUT:
621 decoder->enable = (*iarg != 0);
623 tvp5150_selmux(client, decoder->input);
627 case VIDIOC_QUERYCTRL:
629 struct v4l2_queryctrl *qc = arg;
632 dprintk(1, KERN_DEBUG "VIDIOC_QUERYCTRL");
634 n = sizeof(tvp5150_qctrl) / sizeof(tvp5150_qctrl[0]);
635 for (i = 0; i < n; i++)
636 if (qc->id && qc->id == tvp5150_qctrl[i].id) {
637 memcpy(qc, &(tvp5150_qctrl[i]),
646 struct v4l2_control *ctrl = arg;
647 dprintk(1, KERN_DEBUG "VIDIOC_G_CTRL");
649 return tvp5150_get_ctrl(client, ctrl);
651 case VIDIOC_S_CTRL_OLD: /* ??? */
654 struct v4l2_control *ctrl = arg;
656 dprintk(1, KERN_DEBUG "VIDIOC_S_CTRL");
657 n = sizeof(tvp5150_qctrl) / sizeof(tvp5150_qctrl[0]);
658 for (i = 0; i < n; i++)
659 if (ctrl->id == tvp5150_qctrl[i].id) {
661 tvp5150_qctrl[i].minimum
663 tvp5150_qctrl[i].maximum)
667 "VIDIOC_S_CTRL: id=%d, value=%d",
668 ctrl->id, ctrl->value);
669 return tvp5150_set_ctrl(client, ctrl);
674 case DECODER_SET_PICTURE:
676 struct video_picture *pic = arg;
677 if (decoder->bright != pic->brightness) {
678 /* We want 0 to 255 we get 0-65535 */
679 decoder->bright = pic->brightness;
680 tvp5150_write(client, TVP5150_BRIGHT_CTL,
681 decoder->bright >> 8);
683 if (decoder->contrast != pic->contrast) {
684 /* We want 0 to 255 we get 0-65535 */
685 decoder->contrast = pic->contrast;
686 tvp5150_write(client, TVP5150_CONTRAST_CTL,
687 decoder->contrast >> 8);
689 if (decoder->sat != pic->colour) {
690 /* We want 0 to 255 we get 0-65535 */
691 decoder->sat = pic->colour;
692 tvp5150_write(client, TVP5150_SATURATION_CTL,
693 decoder->contrast >> 8);
695 if (decoder->hue != pic->hue) {
696 /* We want -128 to 127 we get 0-65535 */
697 decoder->hue = pic->hue;
698 tvp5150_write(client, TVP5150_HUE_CTL,
699 (decoder->hue - 32768) >> 8);
710 /****************************************************************************
712 ****************************************************************************/
713 static struct i2c_driver driver;
715 static struct i2c_client client_template = {
720 static int tvp5150_detect_client(struct i2c_adapter *adapter,
721 int address, int kind)
723 struct i2c_client *client;
724 struct tvp5150 *core;
729 "tvp5150.c: detecting tvp5150 client on address 0x%x\n",
732 client_template.adapter = adapter;
733 client_template.addr = address;
735 /* Check if the adapter supports the needed features */
736 if (!i2c_check_functionality
738 I2C_FUNC_SMBUS_READ_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
741 client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
744 memcpy(client, &client_template, sizeof(struct i2c_client));
746 core = kmalloc(sizeof(struct tvp5150), GFP_KERNEL);
751 memset(core, 0, sizeof(struct tvp5150));
752 i2c_set_clientdata(client, core);
754 rv = i2c_attach_client(client);
756 core->norm = VIDEO_MODE_AUTO;
759 core->bright = 32768;
760 core->contrast = 32768;
775 static int tvp5150_attach_adapter(struct i2c_adapter *adapter)
779 "tvp5150.c: starting probe for adapter %s (0x%x)\n",
780 adapter->name, adapter->id);
781 return i2c_probe(adapter, &addr_data, &tvp5150_detect_client);
784 static int tvp5150_detach_client(struct i2c_client *client)
786 struct tvp5150 *decoder = i2c_get_clientdata(client);
789 err = i2c_detach_client(client);
800 /* ----------------------------------------------------------------------- */
802 static struct i2c_driver driver = {
808 .id = I2C_DRIVERID_SAA7110,
810 .attach_adapter = tvp5150_attach_adapter,
811 .detach_client = tvp5150_detach_client,
813 .command = tvp5150_command,
816 static int __init tvp5150_init(void)
818 return i2c_add_driver(&driver);
821 static void __exit tvp5150_exit(void)
823 i2c_del_driver(&driver);
826 module_init(tvp5150_init);
827 module_exit(tvp5150_exit);