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>
12 #include <media/v4l2-common.h>
14 #include "tvp5150_reg.h"
16 MODULE_DESCRIPTION("Texas Instruments TVP5150A video decoder driver"); /* standard i2c insmod options */
17 MODULE_AUTHOR("Mauro Carvalho Chehab");
18 MODULE_LICENSE("GPL");
20 static unsigned short normal_i2c[] = {
29 module_param(debug, int, 0);
30 MODULE_PARM_DESC(debug, "Debug level (0-1)");
32 #define tvp5150_info(fmt, arg...) do { \
33 printk(KERN_INFO "%s %d-%04x: " fmt, c->driver->driver.name, \
34 i2c_adapter_id(c->adapter), c->addr , ## arg); } while (0)
35 #define tvp5150_dbg(num, fmt, arg...) \
38 printk(KERN_DEBUG "%s debug %d-%04x: " fmt,\
39 c->driver->driver.name, \
40 i2c_adapter_id(c->adapter), \
41 c->addr , ## arg); } while (0)
43 /* supported controls */
44 static struct v4l2_queryctrl tvp5150_qctrl[] = {
46 .id = V4L2_CID_BRIGHTNESS,
47 .type = V4L2_CTRL_TYPE_INTEGER,
55 .id = V4L2_CID_CONTRAST,
56 .type = V4L2_CTRL_TYPE_INTEGER,
61 .default_value = 0x10,
64 .id = V4L2_CID_SATURATION,
65 .type = V4L2_CTRL_TYPE_INTEGER,
70 .default_value = 0x10,
74 .type = V4L2_CTRL_TYPE_INTEGER,
79 .default_value = 0x10,
85 struct i2c_client *client;
96 static int tvp5150_read(struct i2c_client *c, unsigned char addr)
98 unsigned char buffer[1];
102 if (1 != (rc = i2c_master_send(c, buffer, 1)))
103 tvp5150_dbg(0, "i2c i/o error: rc == %d (should be 1)\n", rc);
107 if (1 != (rc = i2c_master_recv(c, buffer, 1)))
108 tvp5150_dbg(0, "i2c i/o error: rc == %d (should be 1)\n", rc);
110 tvp5150_dbg(2, "tvp5150: read 0x%02x = 0x%02x\n", addr, buffer[0]);
115 static inline void tvp5150_write(struct i2c_client *c, unsigned char addr,
118 unsigned char buffer[2];
123 tvp5150_dbg(2, "tvp5150: writing 0x%02x 0x%02x\n", buffer[0], buffer[1]);
124 if (2 != (rc = i2c_master_send(c, buffer, 2)))
125 tvp5150_dbg(0, "i2c i/o error: rc == %d (should be 2)\n", rc);
128 static void dump_reg(struct i2c_client *c)
130 printk("tvp5150: Video input source selection #1 = 0x%02x\n",
131 tvp5150_read(c, TVP5150_VD_IN_SRC_SEL_1));
132 printk("tvp5150: Analog channel controls = 0x%02x\n",
133 tvp5150_read(c, TVP5150_ANAL_CHL_CTL));
134 printk("tvp5150: Operation mode controls = 0x%02x\n",
135 tvp5150_read(c, TVP5150_OP_MODE_CTL));
136 printk("tvp5150: Miscellaneous controls = 0x%02x\n",
137 tvp5150_read(c, TVP5150_MISC_CTL));
138 printk("tvp5150: Autoswitch mask: TVP5150A / TVP5150AM = 0x%02x\n",
139 tvp5150_read(c, TVP5150_AUTOSW_MSK));
140 printk("tvp5150: Color killer threshold control = 0x%02x\n",
141 tvp5150_read(c, TVP5150_COLOR_KIL_THSH_CTL));
142 printk("tvp5150: Luminance processing control #1 = 0x%02x\n",
143 tvp5150_read(c, TVP5150_LUMA_PROC_CTL_1));
144 printk("tvp5150: Luminance processing control #2 = 0x%02x\n",
145 tvp5150_read(c, TVP5150_LUMA_PROC_CTL_2));
146 printk("tvp5150: Brightness control = 0x%02x\n",
147 tvp5150_read(c, TVP5150_BRIGHT_CTL));
148 printk("tvp5150: Color saturation control = 0x%02x\n",
149 tvp5150_read(c, TVP5150_SATURATION_CTL));
150 printk("tvp5150: Hue control = 0x%02x\n",
151 tvp5150_read(c, TVP5150_HUE_CTL));
152 printk("tvp5150: Contrast control = 0x%02x\n",
153 tvp5150_read(c, TVP5150_CONTRAST_CTL));
154 printk("tvp5150: Outputs and data rates select = 0x%02x\n",
155 tvp5150_read(c, TVP5150_DATA_RATE_SEL));
156 printk("tvp5150: Luminance processing control #3 = 0x%02x\n",
157 tvp5150_read(c, TVP5150_LUMA_PROC_CTL_3));
158 printk("tvp5150: Configuration shared pins = 0x%02x\n",
159 tvp5150_read(c, TVP5150_CONF_SHARED_PIN));
160 printk("tvp5150: Active video cropping start MSB = 0x%02x\n",
161 tvp5150_read(c, TVP5150_ACT_VD_CROP_ST_MSB));
162 printk("tvp5150: Active video cropping start LSB = 0x%02x\n",
163 tvp5150_read(c, TVP5150_ACT_VD_CROP_ST_LSB));
164 printk("tvp5150: Active video cropping stop MSB = 0x%02x\n",
165 tvp5150_read(c, TVP5150_ACT_VD_CROP_STP_MSB));
166 printk("tvp5150: Active video cropping stop LSB = 0x%02x\n",
167 tvp5150_read(c, TVP5150_ACT_VD_CROP_STP_LSB));
168 printk("tvp5150: Genlock/RTC = 0x%02x\n",
169 tvp5150_read(c, TVP5150_GENLOCK));
170 printk("tvp5150: Horizontal sync start = 0x%02x\n",
171 tvp5150_read(c, TVP5150_HORIZ_SYNC_START));
172 printk("tvp5150: Vertical blanking start = 0x%02x\n",
173 tvp5150_read(c, TVP5150_VERT_BLANKING_START));
174 printk("tvp5150: Vertical blanking stop = 0x%02x\n",
175 tvp5150_read(c, TVP5150_VERT_BLANKING_STOP));
176 printk("tvp5150: Chrominance processing control #1 = 0x%02x\n",
177 tvp5150_read(c, TVP5150_CHROMA_PROC_CTL_1));
178 printk("tvp5150: Chrominance processing control #2 = 0x%02x\n",
179 tvp5150_read(c, TVP5150_CHROMA_PROC_CTL_2));
180 printk("tvp5150: Interrupt reset register B = 0x%02x\n",
181 tvp5150_read(c, TVP5150_INT_RESET_REG_B));
182 printk("tvp5150: Interrupt enable register B = 0x%02x\n",
183 tvp5150_read(c, TVP5150_INT_ENABLE_REG_B));
184 printk("tvp5150: Interrupt configuration register B = 0x%02x\n",
185 tvp5150_read(c, TVP5150_INTT_CONFIG_REG_B));
186 printk("tvp5150: Video standard = 0x%02x\n",
187 tvp5150_read(c, TVP5150_VIDEO_STD));
188 printk("tvp5150: Cb gain factor = 0x%02x\n",
189 tvp5150_read(c, TVP5150_CB_GAIN_FACT));
190 printk("tvp5150: Cr gain factor = 0x%02x\n",
191 tvp5150_read(c, TVP5150_CR_GAIN_FACTOR));
192 printk("tvp5150: Macrovision on counter = 0x%02x\n",
193 tvp5150_read(c, TVP5150_MACROVISION_ON_CTR));
194 printk("tvp5150: Macrovision off counter = 0x%02x\n",
195 tvp5150_read(c, TVP5150_MACROVISION_OFF_CTR));
196 printk("tvp5150: revision select (TVP5150AM1 only) = 0x%02x\n",
197 tvp5150_read(c, TVP5150_REV_SELECT));
198 printk("tvp5150: MSB of device ID = 0x%02x\n",
199 tvp5150_read(c, TVP5150_MSB_DEV_ID));
200 printk("tvp5150: LSB of device ID = 0x%02x\n",
201 tvp5150_read(c, TVP5150_LSB_DEV_ID));
202 printk("tvp5150: ROM major version = 0x%02x\n",
203 tvp5150_read(c, TVP5150_ROM_MAJOR_VER));
204 printk("tvp5150: ROM minor version = 0x%02x\n",
205 tvp5150_read(c, TVP5150_ROM_MINOR_VER));
206 printk("tvp5150: Vertical line count MSB = 0x%02x\n",
207 tvp5150_read(c, TVP5150_VERT_LN_COUNT_MSB));
208 printk("tvp5150: Vertical line count LSB = 0x%02x\n",
209 tvp5150_read(c, TVP5150_VERT_LN_COUNT_LSB));
210 printk("tvp5150: Interrupt status register B = 0x%02x\n",
211 tvp5150_read(c, TVP5150_INT_STATUS_REG_B));
212 printk("tvp5150: Interrupt active register B = 0x%02x\n",
213 tvp5150_read(c, TVP5150_INT_ACTIVE_REG_B));
214 printk("tvp5150: Status register #1 = 0x%02x\n",
215 tvp5150_read(c, TVP5150_STATUS_REG_1));
216 printk("tvp5150: Status register #2 = 0x%02x\n",
217 tvp5150_read(c, TVP5150_STATUS_REG_2));
218 printk("tvp5150: Status register #3 = 0x%02x\n",
219 tvp5150_read(c, TVP5150_STATUS_REG_3));
220 printk("tvp5150: Status register #4 = 0x%02x\n",
221 tvp5150_read(c, TVP5150_STATUS_REG_4));
222 printk("tvp5150: Status register #5 = 0x%02x\n",
223 tvp5150_read(c, TVP5150_STATUS_REG_5));
224 printk("tvp5150: Closed caption data registers = 0x%02x\n",
225 tvp5150_read(c, TVP5150_CC_DATA_REG1));
226 printk("tvp5150: Closed caption data registers = 0x%02x\n",
227 tvp5150_read(c, TVP5150_CC_DATA_REG2));
228 printk("tvp5150: Closed caption data registers = 0x%02x\n",
229 tvp5150_read(c, TVP5150_CC_DATA_REG3));
230 printk("tvp5150: Closed caption data registers = 0x%02x\n",
231 tvp5150_read(c, TVP5150_CC_DATA_REG4));
232 printk("tvp5150: WSS data registers = 0x%02x\n",
233 tvp5150_read(c, TVP5150_WSS_DATA_REG1));
234 printk("tvp5150: WSS data registers = 0x%02x\n",
235 tvp5150_read(c, TVP5150_WSS_DATA_REG2));
236 printk("tvp5150: WSS data registers = 0x%02x\n",
237 tvp5150_read(c, TVP5150_WSS_DATA_REG3));
238 printk("tvp5150: WSS data registers = 0x%02x\n",
239 tvp5150_read(c, TVP5150_WSS_DATA_REG4));
240 printk("tvp5150: WSS data registers = 0x%02x\n",
241 tvp5150_read(c, TVP5150_WSS_DATA_REG5));
242 printk("tvp5150: WSS data registers = 0x%02x\n",
243 tvp5150_read(c, TVP5150_WSS_DATA_REG6));
244 printk("tvp5150: VPS data registers = 0x%02x\n",
245 tvp5150_read(c, TVP5150_VPS_DATA_REG1));
246 printk("tvp5150: VPS data registers = 0x%02x\n",
247 tvp5150_read(c, TVP5150_VPS_DATA_REG2));
248 printk("tvp5150: VPS data registers = 0x%02x\n",
249 tvp5150_read(c, TVP5150_VPS_DATA_REG3));
250 printk("tvp5150: VPS data registers = 0x%02x\n",
251 tvp5150_read(c, TVP5150_VPS_DATA_REG4));
252 printk("tvp5150: VPS data registers = 0x%02x\n",
253 tvp5150_read(c, TVP5150_VPS_DATA_REG5));
254 printk("tvp5150: VPS data registers = 0x%02x\n",
255 tvp5150_read(c, TVP5150_VPS_DATA_REG6));
256 printk("tvp5150: VPS data registers = 0x%02x\n",
257 tvp5150_read(c, TVP5150_VPS_DATA_REG7));
258 printk("tvp5150: VPS data registers = 0x%02x\n",
259 tvp5150_read(c, TVP5150_VPS_DATA_REG8));
260 printk("tvp5150: VPS data registers = 0x%02x\n",
261 tvp5150_read(c, TVP5150_VPS_DATA_REG9));
262 printk("tvp5150: VPS data registers = 0x%02x\n",
263 tvp5150_read(c, TVP5150_VPS_DATA_REG10));
264 printk("tvp5150: VPS data registers = 0x%02x\n",
265 tvp5150_read(c, TVP5150_VPS_DATA_REG11));
266 printk("tvp5150: VPS data registers = 0x%02x\n",
267 tvp5150_read(c, TVP5150_VPS_DATA_REG12));
268 printk("tvp5150: VPS data registers = 0x%02x\n",
269 tvp5150_read(c, TVP5150_VPS_DATA_REG13));
270 printk("tvp5150: VITC data registers = 0x%02x\n",
271 tvp5150_read(c, TVP5150_VITC_DATA_REG1));
272 printk("tvp5150: VITC data registers = 0x%02x\n",
273 tvp5150_read(c, TVP5150_VITC_DATA_REG2));
274 printk("tvp5150: VITC data registers = 0x%02x\n",
275 tvp5150_read(c, TVP5150_VITC_DATA_REG3));
276 printk("tvp5150: VITC data registers = 0x%02x\n",
277 tvp5150_read(c, TVP5150_VITC_DATA_REG4));
278 printk("tvp5150: VITC data registers = 0x%02x\n",
279 tvp5150_read(c, TVP5150_VITC_DATA_REG5));
280 printk("tvp5150: VITC data registers = 0x%02x\n",
281 tvp5150_read(c, TVP5150_VITC_DATA_REG6));
282 printk("tvp5150: VITC data registers = 0x%02x\n",
283 tvp5150_read(c, TVP5150_VITC_DATA_REG7));
284 printk("tvp5150: VITC data registers = 0x%02x\n",
285 tvp5150_read(c, TVP5150_VITC_DATA_REG8));
286 printk("tvp5150: VITC data registers = 0x%02x\n",
287 tvp5150_read(c, TVP5150_VITC_DATA_REG9));
288 printk("tvp5150: VBI FIFO read data = 0x%02x\n",
289 tvp5150_read(c, TVP5150_VBI_FIFO_READ_DATA));
290 printk("tvp5150: Teletext filter 1 = 0x%02x\n",
291 tvp5150_read(c, TVP5150_TELETEXT_FIL_1_1));
292 printk("tvp5150: Teletext filter 1 = 0x%02x\n",
293 tvp5150_read(c, TVP5150_TELETEXT_FIL_1_2));
294 printk("tvp5150: Teletext filter 1 = 0x%02x\n",
295 tvp5150_read(c, TVP5150_TELETEXT_FIL_1_3));
296 printk("tvp5150: Teletext filter 1 = 0x%02x\n",
297 tvp5150_read(c, TVP5150_TELETEXT_FIL_1_4));
298 printk("tvp5150: Teletext filter 1 = 0x%02x\n",
299 tvp5150_read(c, TVP5150_TELETEXT_FIL_1_5));
300 printk("tvp5150: Teletext filter 2 = 0x%02x\n",
301 tvp5150_read(c, TVP5150_TELETEXT_FIL_2_1));
302 printk("tvp5150: Teletext filter 2 = 0x%02x\n",
303 tvp5150_read(c, TVP5150_TELETEXT_FIL_2_2));
304 printk("tvp5150: Teletext filter 2 = 0x%02x\n",
305 tvp5150_read(c, TVP5150_TELETEXT_FIL_2_3));
306 printk("tvp5150: Teletext filter 2 = 0x%02x\n",
307 tvp5150_read(c, TVP5150_TELETEXT_FIL_2_4));
308 printk("tvp5150: Teletext filter 2 = 0x%02x\n",
309 tvp5150_read(c, TVP5150_TELETEXT_FIL_2_5));
310 printk("tvp5150: Teletext filter enable = 0x%02x\n",
311 tvp5150_read(c, TVP5150_TELETEXT_FIL_ENA));
312 printk("tvp5150: Interrupt status register A = 0x%02x\n",
313 tvp5150_read(c, TVP5150_INT_STATUS_REG_A));
314 printk("tvp5150: Interrupt enable register A = 0x%02x\n",
315 tvp5150_read(c, TVP5150_INT_ENABLE_REG_A));
316 printk("tvp5150: Interrupt configuration = 0x%02x\n",
317 tvp5150_read(c, TVP5150_INT_CONF));
318 printk("tvp5150: VDP configuration RAM data = 0x%02x\n",
319 tvp5150_read(c, TVP5150_VDP_CONF_RAM_DATA));
320 printk("tvp5150: Configuration RAM address low byte = 0x%02x\n",
321 tvp5150_read(c, TVP5150_CONF_RAM_ADDR_LOW));
322 printk("tvp5150: Configuration RAM address high byte = 0x%02x\n",
323 tvp5150_read(c, TVP5150_CONF_RAM_ADDR_HIGH));
324 printk("tvp5150: VDP status register = 0x%02x\n",
325 tvp5150_read(c, TVP5150_VDP_STATUS_REG));
326 printk("tvp5150: FIFO word count = 0x%02x\n",
327 tvp5150_read(c, TVP5150_FIFO_WORD_COUNT));
328 printk("tvp5150: FIFO interrupt threshold = 0x%02x\n",
329 tvp5150_read(c, TVP5150_FIFO_INT_THRESHOLD));
330 printk("tvp5150: FIFO reset = 0x%02x\n",
331 tvp5150_read(c, TVP5150_FIFO_RESET));
332 printk("tvp5150: Line number interrupt = 0x%02x\n",
333 tvp5150_read(c, TVP5150_LINE_NUMBER_INT));
334 printk("tvp5150: Pixel alignment register low byte = 0x%02x\n",
335 tvp5150_read(c, TVP5150_PIX_ALIGN_REG_LOW));
336 printk("tvp5150: Pixel alignment register high byte = 0x%02x\n",
337 tvp5150_read(c, TVP5150_PIX_ALIGN_REG_HIGH));
338 printk("tvp5150: FIFO output control = 0x%02x\n",
339 tvp5150_read(c, TVP5150_FIFO_OUT_CTRL));
340 printk("tvp5150: Full field enable 1 = 0x%02x\n",
341 tvp5150_read(c, TVP5150_FULL_FIELD_ENA_1));
342 printk("tvp5150: Full field enable 2 = 0x%02x\n",
343 tvp5150_read(c, TVP5150_FULL_FIELD_ENA_2));
344 printk("tvp5150: Line mode registers = 0x%02x\n",
345 tvp5150_read(c, TVP5150_LINE_MODE_REG_1));
346 printk("tvp5150: Line mode registers = 0x%02x\n",
347 tvp5150_read(c, TVP5150_LINE_MODE_REG_2));
348 printk("tvp5150: Line mode registers = 0x%02x\n",
349 tvp5150_read(c, TVP5150_LINE_MODE_REG_3));
350 printk("tvp5150: Line mode registers = 0x%02x\n",
351 tvp5150_read(c, TVP5150_LINE_MODE_REG_4));
352 printk("tvp5150: Line mode registers = 0x%02x\n",
353 tvp5150_read(c, TVP5150_LINE_MODE_REG_5));
354 printk("tvp5150: Line mode registers = 0x%02x\n",
355 tvp5150_read(c, TVP5150_LINE_MODE_REG_6));
356 printk("tvp5150: Line mode registers = 0x%02x\n",
357 tvp5150_read(c, TVP5150_LINE_MODE_REG_7));
358 printk("tvp5150: Line mode registers = 0x%02x\n",
359 tvp5150_read(c, TVP5150_LINE_MODE_REG_8));
360 printk("tvp5150: Line mode registers = 0x%02x\n",
361 tvp5150_read(c, TVP5150_LINE_MODE_REG_9));
362 printk("tvp5150: Line mode registers = 0x%02x\n",
363 tvp5150_read(c, TVP5150_LINE_MODE_REG_10));
364 printk("tvp5150: Line mode registers = 0x%02x\n",
365 tvp5150_read(c, TVP5150_LINE_MODE_REG_11));
366 printk("tvp5150: Line mode registers = 0x%02x\n",
367 tvp5150_read(c, TVP5150_LINE_MODE_REG_12));
368 printk("tvp5150: Line mode registers = 0x%02x\n",
369 tvp5150_read(c, TVP5150_LINE_MODE_REG_13));
370 printk("tvp5150: Line mode registers = 0x%02x\n",
371 tvp5150_read(c, TVP5150_LINE_MODE_REG_14));
372 printk("tvp5150: Line mode registers = 0x%02x\n",
373 tvp5150_read(c, TVP5150_LINE_MODE_REG_15));
374 printk("tvp5150: Line mode registers = 0x%02x\n",
375 tvp5150_read(c, TVP5150_LINE_MODE_REG_16));
376 printk("tvp5150: Line mode registers = 0x%02x\n",
377 tvp5150_read(c, TVP5150_LINE_MODE_REG_17));
378 printk("tvp5150: Line mode registers = 0x%02x\n",
379 tvp5150_read(c, TVP5150_LINE_MODE_REG_18));
380 printk("tvp5150: Line mode registers = 0x%02x\n",
381 tvp5150_read(c, TVP5150_LINE_MODE_REG_19));
382 printk("tvp5150: Line mode registers = 0x%02x\n",
383 tvp5150_read(c, TVP5150_LINE_MODE_REG_20));
384 printk("tvp5150: Line mode registers = 0x%02x\n",
385 tvp5150_read(c, TVP5150_LINE_MODE_REG_21));
386 printk("tvp5150: Line mode registers = 0x%02x\n",
387 tvp5150_read(c, TVP5150_LINE_MODE_REG_22));
388 printk("tvp5150: Line mode registers = 0x%02x\n",
389 tvp5150_read(c, TVP5150_LINE_MODE_REG_23));
390 printk("tvp5150: Line mode registers = 0x%02x\n",
391 tvp5150_read(c, TVP5150_LINE_MODE_REG_24));
392 printk("tvp5150: Line mode registers = 0x%02x\n",
393 tvp5150_read(c, TVP5150_LINE_MODE_REG_25));
394 printk("tvp5150: Line mode registers = 0x%02x\n",
395 tvp5150_read(c, TVP5150_LINE_MODE_REG_27));
396 printk("tvp5150: Line mode registers = 0x%02x\n",
397 tvp5150_read(c, TVP5150_LINE_MODE_REG_28));
398 printk("tvp5150: Line mode registers = 0x%02x\n",
399 tvp5150_read(c, TVP5150_LINE_MODE_REG_29));
400 printk("tvp5150: Line mode registers = 0x%02x\n",
401 tvp5150_read(c, TVP5150_LINE_MODE_REG_30));
402 printk("tvp5150: Line mode registers = 0x%02x\n",
403 tvp5150_read(c, TVP5150_LINE_MODE_REG_31));
404 printk("tvp5150: Line mode registers = 0x%02x\n",
405 tvp5150_read(c, TVP5150_LINE_MODE_REG_32));
406 printk("tvp5150: Line mode registers = 0x%02x\n",
407 tvp5150_read(c, TVP5150_LINE_MODE_REG_33));
408 printk("tvp5150: Line mode registers = 0x%02x\n",
409 tvp5150_read(c, TVP5150_LINE_MODE_REG_34));
410 printk("tvp5150: Line mode registers = 0x%02x\n",
411 tvp5150_read(c, TVP5150_LINE_MODE_REG_35));
412 printk("tvp5150: Line mode registers = 0x%02x\n",
413 tvp5150_read(c, TVP5150_LINE_MODE_REG_36));
414 printk("tvp5150: Line mode registers = 0x%02x\n",
415 tvp5150_read(c, TVP5150_LINE_MODE_REG_37));
416 printk("tvp5150: Line mode registers = 0x%02x\n",
417 tvp5150_read(c, TVP5150_LINE_MODE_REG_38));
418 printk("tvp5150: Line mode registers = 0x%02x\n",
419 tvp5150_read(c, TVP5150_LINE_MODE_REG_39));
420 printk("tvp5150: Line mode registers = 0x%02x\n",
421 tvp5150_read(c, TVP5150_LINE_MODE_REG_40));
422 printk("tvp5150: Line mode registers = 0x%02x\n",
423 tvp5150_read(c, TVP5150_LINE_MODE_REG_41));
424 printk("tvp5150: Line mode registers = 0x%02x\n",
425 tvp5150_read(c, TVP5150_LINE_MODE_REG_42));
426 printk("tvp5150: Line mode registers = 0x%02x\n",
427 tvp5150_read(c, TVP5150_LINE_MODE_REG_43));
428 printk("tvp5150: Line mode registers = 0x%02x\n",
429 tvp5150_read(c, TVP5150_LINE_MODE_REG_44));
430 printk("tvp5150: Full field mode register = 0x%02x\n",
431 tvp5150_read(c, TVP5150_FULL_FIELD_MODE_REG));
434 /****************************************************************************
436 ****************************************************************************/
438 TVP5150_ANALOG_CH0 = 0,
440 TVP5150_ANALOG_CH1 = 2,
441 TVP5150_BLACK_SCREEN = 8
444 static inline void tvp5150_selmux(struct i2c_client *c,
445 enum tvp5150_input input)
449 struct tvp5150 *decoder = i2c_get_clientdata(c);
451 if (!decoder->enable)
452 input |= TVP5150_BLACK_SCREEN;
455 case TVP5150_ANALOG_CH0:
456 case TVP5150_ANALOG_CH1:
457 opmode=0x30; /* TV Mode */
460 opmode=0; /* Auto Mode */
464 tvp5150_write(c, TVP5150_OP_MODE_CTL, opmode);
465 tvp5150_write(c, TVP5150_VD_IN_SRC_SEL_1, input);
468 struct i2c_reg_value {
473 /* Default values as sugested at TVP5150AM1 datasheet */
474 static const struct i2c_reg_value tvp5150_init_default[] = {
476 TVP5150_VD_IN_SRC_SEL_1,0x00
479 TVP5150_ANAL_CHL_CTL,0x15
482 TVP5150_OP_MODE_CTL,0x00
485 TVP5150_MISC_CTL,0x01
488 TVP5150_COLOR_KIL_THSH_CTL,0x10
491 TVP5150_LUMA_PROC_CTL_1,0x60
494 TVP5150_LUMA_PROC_CTL_2,0x00
497 TVP5150_BRIGHT_CTL,0x80
500 TVP5150_SATURATION_CTL,0x80
506 TVP5150_CONTRAST_CTL,0x80
509 TVP5150_DATA_RATE_SEL,0x47
512 TVP5150_LUMA_PROC_CTL_3,0x00
515 TVP5150_CONF_SHARED_PIN,0x08
518 TVP5150_ACT_VD_CROP_ST_MSB,0x00
521 TVP5150_ACT_VD_CROP_ST_LSB,0x00
524 TVP5150_ACT_VD_CROP_STP_MSB,0x00
527 TVP5150_ACT_VD_CROP_STP_LSB,0x00
533 TVP5150_HORIZ_SYNC_START,0x80
536 TVP5150_VERT_BLANKING_START,0x00
539 TVP5150_VERT_BLANKING_STOP,0x00
542 TVP5150_CHROMA_PROC_CTL_1,0x0c
545 TVP5150_CHROMA_PROC_CTL_2,0x14
548 TVP5150_INT_RESET_REG_B,0x00
551 TVP5150_INT_ENABLE_REG_B,0x00
554 TVP5150_INTT_CONFIG_REG_B,0x00
557 TVP5150_VIDEO_STD,0x00
560 TVP5150_MACROVISION_ON_CTR,0x0f
563 TVP5150_MACROVISION_OFF_CTR,0x01
566 TVP5150_TELETEXT_FIL_ENA,0x00
569 TVP5150_INT_STATUS_REG_A,0x00
572 TVP5150_INT_ENABLE_REG_A,0x00
575 TVP5150_INT_CONF,0x04
578 TVP5150_FIFO_INT_THRESHOLD,0x80
581 TVP5150_FIFO_RESET,0x00
584 TVP5150_LINE_NUMBER_INT,0x00
587 TVP5150_PIX_ALIGN_REG_LOW,0x4e
590 TVP5150_PIX_ALIGN_REG_HIGH,0x00
593 TVP5150_FIFO_OUT_CTRL,0x01
596 TVP5150_FULL_FIELD_ENA_1,0x00
599 TVP5150_FULL_FIELD_ENA_2,0x00
602 TVP5150_FULL_FIELD_MODE_REG,0x7f
609 /* Default values as sugested at TVP5150AM1 datasheet */
610 static const struct i2c_reg_value tvp5150_init_enable[] = {
612 TVP5150_CONF_SHARED_PIN, 2
613 },{ /* Automatic offset and AGC enabled */
614 TVP5150_ANAL_CHL_CTL, 0x15
615 },{ /* Activate YCrCb output 0x9 or 0xd ? */
616 TVP5150_MISC_CTL, 0x6f
617 },{ /* Activates video std autodetection for all standards */
618 TVP5150_AUTOSW_MSK, 0x0
619 },{ /* Default format: 0x47. For 4:2:2: 0x40 */
620 TVP5150_DATA_RATE_SEL, 0x47
622 TVP5150_CHROMA_PROC_CTL_1, 0x0c
624 TVP5150_CHROMA_PROC_CTL_2, 0x54
625 },{ /* Non documented, but initialized on WinTV USB2 */
632 struct i2c_vbi_ram_value {
634 unsigned char values[26];
637 static struct i2c_vbi_ram_value vbi_ram_default[] =
639 {0x010, /* WST SECAM 6 */
640 { 0xaa, 0xaa, 0xff, 0xff , 0xe7, 0x2e, 0x20, 0x26, 0xe6, 0xb4, 0x0e, 0x0, 0x0, 0x0, 0x10, 0x0 }
642 {0x030, /* WST PAL B 6 */
643 { 0xaa, 0xaa, 0xff, 0xff , 0x27, 0x2e, 0x20, 0x2b, 0xa6, 0x72, 0x10, 0x0, 0x0, 0x0, 0x10, 0x0 }
645 {0x050, /* WST PAL C 6 */
646 { 0xaa, 0xaa, 0xff, 0xff , 0xe7, 0x2e, 0x20, 0x22, 0xa6, 0x98, 0x0d, 0x0, 0x0, 0x0, 0x10, 0x0 }
648 {0x070, /* WST NTSC 6 */
649 { 0xaa, 0xaa, 0xff, 0xff , 0x27, 0x2e, 0x20, 0x23, 0x69, 0x93, 0x0d, 0x0, 0x0, 0x0, 0x10, 0x0 }
651 {0x090, /* NABTS, NTSC 6 */
652 { 0xaa, 0xaa, 0xff, 0xff , 0xe7, 0x2e, 0x20, 0x22, 0x69, 0x93, 0x0d, 0x0, 0x0, 0x0, 0x15, 0x0 }
654 {0x0b0, /* NABTS, NTSC-J 6 */
655 { 0xaa, 0xaa, 0xff, 0xff , 0xa7, 0x2e, 0x20, 0x23, 0x69, 0x93, 0x0d, 0x0, 0x0, 0x0, 0x10, 0x0 }
657 {0x0d0, /* CC, PAL/SECAM 6 */
658 { 0xaa, 0x2a, 0xff, 0x3f , 0x04, 0x51, 0x6e, 0x02, 0xa6, 0x7b, 0x09, 0x0, 0x0, 0x0, 0x27, 0x0 }
660 {0x0f0, /* CC, NTSC 6 */
661 { 0xaa, 0x2a, 0xff, 0x3f , 0x04, 0x51, 0x6e, 0x02, 0x69, 0x8c, 0x09, 0x0, 0x0, 0x0, 0x27, 0x0 }
663 {0x110, /* WSS, PAL/SECAM 6 */
664 { 0x5b, 0x55, 0xc5, 0xff , 0x0, 0x71, 0x6e, 0x42, 0xa6, 0xcd, 0x0f, 0x0, 0x0, 0x0, 0x3a, 0x0 }
666 {0x130, /* WSS, NTSC C */
667 { 0x38, 0x00, 0x3f, 0x00 , 0x0, 0x71, 0x6e, 0x43, 0x69, 0x7c, 0x08, 0x0, 0x0, 0x0, 0x39, 0x0 }
669 {0x150, /* VITC, PAL/SECAM 6 */
670 { 0x0, 0x0, 0x0, 0x0 , 0x0, 0x8f, 0x6d, 0x49, 0xa6, 0x85, 0x08, 0x0, 0x0, 0x0, 0x4c, 0x0 }
672 {0x170, /* VITC, NTSC 6 */
673 { 0x0, 0x0, 0x0, 0x0 , 0x0, 0x8f, 0x6d, 0x49, 0x69, 0x94, 0x08, 0x0, 0x0, 0x0, 0x4c, 0x0 }
678 static int tvp5150_write_inittab(struct i2c_client *c,
679 const struct i2c_reg_value *regs)
681 while (regs->reg != 0xff) {
682 tvp5150_write(c, regs->reg, regs->value);
688 static int tvp5150_vdp_init(struct i2c_client *c,
689 const struct i2c_vbi_ram_value *regs)
693 /* Disable Full Field */
694 tvp5150_write(c, TVP5150_FULL_FIELD_ENA_1, 0);
696 /* Before programming, Line mode should be at 0xff */
697 for (i=TVP5150_FULL_FIELD_ENA_2; i<=TVP5150_LINE_MODE_REG_44; i++)
698 tvp5150_write(c, i, 0xff);
701 while (regs->reg != (u16)-1 ) {
702 tvp5150_write(c, TVP5150_CONF_RAM_ADDR_HIGH,regs->reg>>8);
703 tvp5150_write(c, TVP5150_CONF_RAM_ADDR_LOW,regs->reg);
706 tvp5150_write(c, TVP5150_VDP_CONF_RAM_DATA,regs->values[i]);
713 static int tvp5150_set_std(struct i2c_client *c, v4l2_std_id std)
715 struct tvp5150 *decoder = i2c_get_clientdata(c);
720 /* First tests should be against specific std */
722 if (std == V4L2_STD_ALL) {
723 fmt=0; /* Autodetect mode */
724 } else if (std & V4L2_STD_NTSC_443) {
726 } else if (std & V4L2_STD_PAL_M) {
728 } else if (std & (V4L2_STD_PAL_N| V4L2_STD_PAL_Nc)) {
731 /* Then, test against generic ones */
732 if (std & V4L2_STD_NTSC) {
734 } else if (std & V4L2_STD_PAL) {
736 } else if (std & V4L2_STD_SECAM) {
741 tvp5150_dbg(1,"Set video std register to %d.\n",fmt);
742 tvp5150_write(c, TVP5150_VIDEO_STD, fmt);
747 static inline void tvp5150_reset(struct i2c_client *c)
749 u8 msb_id, lsb_id, msb_rom, lsb_rom;
750 struct tvp5150 *decoder = i2c_get_clientdata(c);
752 msb_id=tvp5150_read(c,TVP5150_MSB_DEV_ID);
753 lsb_id=tvp5150_read(c,TVP5150_LSB_DEV_ID);
754 msb_rom=tvp5150_read(c,TVP5150_ROM_MAJOR_VER);
755 lsb_rom=tvp5150_read(c,TVP5150_ROM_MINOR_VER);
757 if ((msb_rom==4)&&(lsb_rom==0)) { /* Is TVP5150AM1 */
758 tvp5150_info("tvp%02x%02xam1 detected.\n",msb_id, lsb_id);
760 /* ITU-T BT.656.4 timing */
761 tvp5150_write(c,TVP5150_REV_SELECT,0);
763 if ((msb_rom==3)||(lsb_rom==0x21)) { /* Is TVP5150A */
764 tvp5150_info("tvp%02x%02xa detected.\n",msb_id, lsb_id);
766 tvp5150_info("*** unknown tvp%02x%02x chip detected.\n",msb_id,lsb_id);
767 tvp5150_info("*** Rom ver is %d.%d\n",msb_rom,lsb_rom);
771 /* Initializes TVP5150 to its default values */
772 tvp5150_write_inittab(c, tvp5150_init_default);
774 /* Initializes VDP registers */
775 tvp5150_vdp_init(c, vbi_ram_default);
777 /* Selects decoder input */
778 tvp5150_selmux(c, decoder->input);
780 /* Initializes TVP5150 to stream enabled values */
781 tvp5150_write_inittab(c, tvp5150_init_enable);
783 /* Initialize image preferences */
784 tvp5150_write(c, TVP5150_BRIGHT_CTL, decoder->bright >> 8);
785 tvp5150_write(c, TVP5150_CONTRAST_CTL, decoder->contrast >> 8);
786 tvp5150_write(c, TVP5150_SATURATION_CTL, decoder->contrast >> 8);
787 tvp5150_write(c, TVP5150_HUE_CTL, (decoder->hue - 32768) >> 8);
789 tvp5150_set_std(c, decoder->norm);
792 static int tvp5150_get_ctrl(struct i2c_client *c, struct v4l2_control *ctrl)
794 /* struct tvp5150 *decoder = i2c_get_clientdata(c); */
797 case V4L2_CID_BRIGHTNESS:
798 ctrl->value = tvp5150_read(c, TVP5150_BRIGHT_CTL);
800 case V4L2_CID_CONTRAST:
801 ctrl->value = tvp5150_read(c, TVP5150_CONTRAST_CTL);
803 case V4L2_CID_SATURATION:
804 ctrl->value = tvp5150_read(c, TVP5150_SATURATION_CTL);
807 ctrl->value = tvp5150_read(c, TVP5150_HUE_CTL);
813 static int tvp5150_set_ctrl(struct i2c_client *c, struct v4l2_control *ctrl)
815 /* struct tvp5150 *decoder = i2c_get_clientdata(c); */
818 case V4L2_CID_BRIGHTNESS:
819 tvp5150_write(c, TVP5150_BRIGHT_CTL, ctrl->value);
821 case V4L2_CID_CONTRAST:
822 tvp5150_write(c, TVP5150_CONTRAST_CTL, ctrl->value);
824 case V4L2_CID_SATURATION:
825 tvp5150_write(c, TVP5150_SATURATION_CTL, ctrl->value);
828 tvp5150_write(c, TVP5150_HUE_CTL, ctrl->value);
834 /****************************************************************************
836 ****************************************************************************/
837 static int tvp5150_command(struct i2c_client *c,
838 unsigned int cmd, void *arg)
840 struct tvp5150 *decoder = i2c_get_clientdata(c);
845 case VIDIOC_INT_RESET:
850 if (decoder->norm == *(v4l2_std_id *)arg)
852 return tvp5150_set_std(c, *(v4l2_std_id *)arg);
854 *(v4l2_std_id *)arg = decoder->norm;
857 #ifdef CONFIG_VIDEO_ADV_DEBUG
858 case VIDIOC_INT_G_REGISTER:
860 struct v4l2_register *reg = arg;
862 if (reg->i2c_id != I2C_DRIVERID_TVP5150)
864 reg->val = tvp5150_read(c, reg->reg & 0xff);
868 case VIDIOC_INT_S_REGISTER:
870 struct v4l2_register *reg = arg;
872 if (reg->i2c_id != I2C_DRIVERID_TVP5150)
874 if (!capable(CAP_SYS_ADMIN))
876 tvp5150_write(c, reg->reg & 0xff, reg->val & 0xff);
885 case DECODER_GET_CAPABILITIES:
887 struct video_decoder_capability *cap = arg;
889 cap->flags = VIDEO_DECODER_PAL |
891 VIDEO_DECODER_SECAM |
892 VIDEO_DECODER_AUTO | VIDEO_DECODER_CCIR;
897 case DECODER_GET_STATUS:
902 status = tvp5150_read(c, 0x88);
904 res |= DECODER_STATUS_COLOR;
906 if(status&0x04 && status&0x02){
907 res |= DECODER_STATUS_GOOD;
913 case DECODER_SET_GPIO:
916 case DECODER_SET_VBI_BYPASS:
919 case DECODER_SET_NORM:
925 case VIDEO_MODE_NTSC:
931 case VIDEO_MODE_SECAM:
934 case VIDEO_MODE_AUTO:
941 decoder->norm = *iarg;
944 case DECODER_SET_INPUT:
947 if (*iarg < 0 || *iarg > 3) {
951 decoder->input = *iarg;
952 tvp5150_selmux(c, decoder->input);
956 case DECODER_SET_OUTPUT:
960 /* not much choice of outputs */
966 case DECODER_ENABLE_OUTPUT:
970 decoder->enable = (*iarg != 0);
972 tvp5150_selmux(c, decoder->input);
976 case VIDIOC_QUERYCTRL:
978 struct v4l2_queryctrl *qc = arg;
981 tvp5150_dbg(1, "VIDIOC_QUERYCTRL called\n");
983 for (i = 0; i < ARRAY_SIZE(tvp5150_qctrl); i++)
984 if (qc->id && qc->id == tvp5150_qctrl[i].id) {
985 memcpy(qc, &(tvp5150_qctrl[i]),
994 struct v4l2_control *ctrl = arg;
995 tvp5150_dbg(1, "VIDIOC_G_CTRL called\n");
997 return tvp5150_get_ctrl(c, ctrl);
1001 struct v4l2_control *ctrl = arg;
1003 n = sizeof(tvp5150_qctrl) / sizeof(tvp5150_qctrl[0]);
1004 for (i = 0; i < n; i++)
1005 if (ctrl->id == tvp5150_qctrl[i].id) {
1007 tvp5150_qctrl[i].minimum
1009 tvp5150_qctrl[i].maximum)
1012 "VIDIOC_S_CTRL: id=%d, value=%d\n",
1013 ctrl->id, ctrl->value);
1014 return tvp5150_set_ctrl(c, ctrl);
1019 case DECODER_SET_PICTURE:
1021 struct video_picture *pic = arg;
1022 if (decoder->bright != pic->brightness) {
1023 /* We want 0 to 255 we get 0-65535 */
1024 decoder->bright = pic->brightness;
1025 tvp5150_write(c, TVP5150_BRIGHT_CTL,
1026 decoder->bright >> 8);
1028 if (decoder->contrast != pic->contrast) {
1029 /* We want 0 to 255 we get 0-65535 */
1030 decoder->contrast = pic->contrast;
1031 tvp5150_write(c, TVP5150_CONTRAST_CTL,
1032 decoder->contrast >> 8);
1034 if (decoder->sat != pic->colour) {
1035 /* We want 0 to 255 we get 0-65535 */
1036 decoder->sat = pic->colour;
1037 tvp5150_write(c, TVP5150_SATURATION_CTL,
1038 decoder->contrast >> 8);
1040 if (decoder->hue != pic->hue) {
1041 /* We want -128 to 127 we get 0-65535 */
1042 decoder->hue = pic->hue;
1043 tvp5150_write(c, TVP5150_HUE_CTL,
1044 (decoder->hue - 32768) >> 8);
1055 /****************************************************************************
1057 ****************************************************************************/
1058 static struct i2c_driver driver;
1060 static struct i2c_client client_template = {
1065 static int tvp5150_detect_client(struct i2c_adapter *adapter,
1066 int address, int kind)
1068 struct i2c_client *c;
1069 struct tvp5150 *core;
1074 "tvp5150.c: detecting tvp5150 client on address 0x%x\n",
1077 client_template.adapter = adapter;
1078 client_template.addr = address;
1080 /* Check if the adapter supports the needed features */
1081 if (!i2c_check_functionality
1083 I2C_FUNC_SMBUS_READ_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
1086 c = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
1089 memcpy(c, &client_template, sizeof(struct i2c_client));
1091 core = kzalloc(sizeof(struct tvp5150), GFP_KERNEL);
1096 i2c_set_clientdata(c, core);
1098 rv = i2c_attach_client(c);
1100 core->norm = V4L2_STD_ALL;
1103 core->bright = 32768;
1104 core->contrast = 32768;
1119 static int tvp5150_attach_adapter(struct i2c_adapter *adapter)
1123 "tvp5150.c: starting probe for adapter %s (0x%x)\n",
1124 adapter->name, adapter->id);
1125 return i2c_probe(adapter, &addr_data, &tvp5150_detect_client);
1128 static int tvp5150_detach_client(struct i2c_client *c)
1130 struct tvp5150 *decoder = i2c_get_clientdata(c);
1134 "tvp5150.c: removing tvp5150 adapter on address 0x%x\n",
1137 err = i2c_detach_client(c);
1148 /* ----------------------------------------------------------------------- */
1150 static struct i2c_driver driver = {
1154 .id = I2C_DRIVERID_TVP5150,
1156 .attach_adapter = tvp5150_attach_adapter,
1157 .detach_client = tvp5150_detach_client,
1159 .command = tvp5150_command,
1162 static int __init tvp5150_init(void)
1164 return i2c_add_driver(&driver);
1167 static void __exit tvp5150_exit(void)
1169 i2c_del_driver(&driver);
1172 module_init(tvp5150_init);
1173 module_exit(tvp5150_exit);