Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

V4L/DVB (12246): tvp514x: Migration to sub-device framework

This patch converts TVP514x driver to sub-device framework
from V4L2-int framework.

[hverkuil@xs4all.nl: remove inline from the dump_reg function]
Signed-off-by: Brijesh Jadav <brijesh.j@ti.com>
Signed-off-by: Hardik Shah <hardik.shah@ti.com>
Signed-off-by: Vaibhav Hiremath <hvaibhav@ti.com>
Signed-off-by: Murali Karicheri <m-karicheri2@ti.com>
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>

authored by

Muralidharan Karicheri and committed by
Mauro Carvalho Chehab
62ef80a1 6bcbc08f

+349 -540
+349 -526
drivers/media/video/tvp514x.c
··· 31 31 #include <linux/i2c.h> 32 32 #include <linux/delay.h> 33 33 #include <linux/videodev2.h> 34 - #include <media/v4l2-int-device.h> 34 + 35 + #include <media/v4l2-device.h> 36 + #include <media/v4l2-common.h> 37 + #include <media/v4l2-chip-ident.h> 35 38 #include <media/tvp514x.h> 36 39 37 40 #include "tvp514x_regs.h" ··· 52 49 module_param(debug, bool, 0644); 53 50 MODULE_PARM_DESC(debug, "Debug level (0-1)"); 54 51 55 - #define dump_reg(client, reg, val) \ 56 - do { \ 57 - val = tvp514x_read_reg(client, reg); \ 58 - v4l_info(client, "Reg(0x%.2X): 0x%.2X\n", reg, val); \ 59 - } while (0) 52 + MODULE_AUTHOR("Texas Instruments"); 53 + MODULE_DESCRIPTION("TVP514X linux decoder driver"); 54 + MODULE_LICENSE("GPL"); 60 55 61 - /** 56 + /* 62 57 * enum tvp514x_std - enum for supported standards 63 58 */ 64 59 enum tvp514x_std { ··· 65 64 STD_INVALID 66 65 }; 67 66 68 - /** 69 - * enum tvp514x_state - enum for different decoder states 70 - */ 71 - enum tvp514x_state { 72 - STATE_NOT_DETECTED, 73 - STATE_DETECTED 74 - }; 75 - 76 - /** 67 + /* 77 68 * struct tvp514x_std_info - Structure to store standard informations 78 69 * @width: Line width in pixels 79 70 * @height:Number of active lines ··· 80 87 }; 81 88 82 89 static struct tvp514x_reg tvp514x_reg_list_default[0x40]; 83 - /** 90 + /* 84 91 * struct tvp514x_decoder - TVP5146/47 decoder object 85 - * @v4l2_int_device: Slave handle 86 - * @tvp514x_slave: Slave pointer which is used by @v4l2_int_device 92 + * @sd: Subdevice Slave handle 87 93 * @tvp514x_regs: copy of hw's regs with preset values. 88 94 * @pdata: Board specific 89 - * @client: I2C client data 90 - * @id: Entry from I2C table 91 95 * @ver: Chip version 92 - * @state: TVP5146/47 decoder state - detected or not-detected 96 + * @streaming: TVP5146/47 decoder streaming - enabled or disabled. 93 97 * @pix: Current pixel format 94 98 * @num_fmts: Number of formats 95 99 * @fmt_list: Format list 96 100 * @current_std: Current standard 97 101 * @num_stds: Number of standards 98 102 * @std_list: Standards list 99 - * @route: input and output routing at chip level 103 + * @input: Input routing at chip level 104 + * @output: Output routing at chip level 100 105 */ 101 106 struct tvp514x_decoder { 102 - struct v4l2_int_device v4l2_int_device; 103 - struct v4l2_int_slave tvp514x_slave; 107 + struct v4l2_subdev sd; 104 108 struct tvp514x_reg tvp514x_regs[ARRAY_SIZE(tvp514x_reg_list_default)]; 105 109 const struct tvp514x_platform_data *pdata; 106 - struct i2c_client *client; 107 - 108 - struct i2c_device_id *id; 109 110 110 111 int ver; 111 - enum tvp514x_state state; 112 + int streaming; 112 113 113 114 struct v4l2_pix_format pix; 114 115 int num_fmts; ··· 111 124 enum tvp514x_std current_std; 112 125 int num_stds; 113 126 struct tvp514x_std_info *std_list; 114 - 115 - struct v4l2_routing route; 127 + /* 128 + * Input and Output Routing parameters 129 + */ 130 + u32 input; 131 + u32 output; 116 132 }; 117 133 118 134 /* TVP514x default register values */ ··· 181 191 {TOK_TERM, 0, 0}, 182 192 }; 183 193 184 - /* List of image formats supported by TVP5146/47 decoder 194 + /* 195 + * List of image formats supported by TVP5146/47 decoder 185 196 * Currently we are using 8 bit mode only, but can be 186 197 * extended to 10/20 bit mode. 187 198 */ ··· 231 240 }, 232 241 /* Standard: need to add for additional standard */ 233 242 }; 234 - /* 235 - * Control structure for Auto Gain 236 - * This is temporary data, will get replaced once 237 - * v4l2_ctrl_query_fill supports it. 238 - */ 239 - static const struct v4l2_queryctrl tvp514x_autogain_ctrl = { 240 - .id = V4L2_CID_AUTOGAIN, 241 - .name = "Gain, Automatic", 242 - .type = V4L2_CTRL_TYPE_BOOLEAN, 243 - .minimum = 0, 244 - .maximum = 1, 245 - .step = 1, 246 - .default_value = 1, 247 - }; 243 + 244 + 245 + static inline struct tvp514x_decoder *to_decoder(struct v4l2_subdev *sd) 246 + { 247 + return container_of(sd, struct tvp514x_decoder, sd); 248 + } 249 + 248 250 249 251 /* 250 252 * Read a value from a register in an TVP5146/47 decoder device. 251 253 * Returns value read if successful, or non-zero (-1) otherwise. 252 254 */ 253 - static int tvp514x_read_reg(struct i2c_client *client, u8 reg) 255 + static int tvp514x_read_reg(struct v4l2_subdev *sd, u8 reg) 254 256 { 255 - int err; 256 - int retry = 0; 257 + int err, retry = 0; 258 + struct i2c_client *client = v4l2_get_subdevdata(sd); 259 + 257 260 read_again: 258 261 259 262 err = i2c_smbus_read_byte_data(client, reg); 260 263 if (err == -1) { 261 264 if (retry <= I2C_RETRY_COUNT) { 262 - v4l_warn(client, "Read: retry ... %d\n", retry); 265 + v4l2_warn(sd, "Read: retry ... %d\n", retry); 263 266 retry++; 264 267 msleep_interruptible(10); 265 268 goto read_again; ··· 263 278 return err; 264 279 } 265 280 281 + static void dump_reg(struct v4l2_subdev *sd, u8 reg) 282 + { 283 + u32 val; 284 + 285 + val = tvp514x_read_reg(sd, reg); 286 + v4l2_info(sd, "Reg(0x%.2X): 0x%.2X\n", reg, val); 287 + } 288 + 266 289 /* 267 290 * Write a value to a register in an TVP5146/47 decoder device. 268 291 * Returns zero if successful, or non-zero otherwise. 269 292 */ 270 - static int tvp514x_write_reg(struct i2c_client *client, u8 reg, u8 val) 293 + static int tvp514x_write_reg(struct v4l2_subdev *sd, u8 reg, u8 val) 271 294 { 272 - int err; 273 - int retry = 0; 295 + int err, retry = 0; 296 + struct i2c_client *client = v4l2_get_subdevdata(sd); 297 + 274 298 write_again: 275 299 276 300 err = i2c_smbus_write_byte_data(client, reg, val); 277 301 if (err) { 278 302 if (retry <= I2C_RETRY_COUNT) { 279 - v4l_warn(client, "Write: retry ... %d\n", retry); 303 + v4l2_warn(sd, "Write: retry ... %d\n", retry); 280 304 retry++; 281 305 msleep_interruptible(10); 282 306 goto write_again; ··· 305 311 * reglist - list of registers to be written 306 312 * Returns zero if successful, or non-zero otherwise. 307 313 */ 308 - static int tvp514x_write_regs(struct i2c_client *client, 314 + static int tvp514x_write_regs(struct v4l2_subdev *sd, 309 315 const struct tvp514x_reg reglist[]) 310 316 { 311 317 int err; ··· 320 326 if (next->token == TOK_SKIP) 321 327 continue; 322 328 323 - err = tvp514x_write_reg(client, next->reg, (u8) next->val); 329 + err = tvp514x_write_reg(sd, next->reg, (u8) next->val); 324 330 if (err) { 325 - v4l_err(client, "Write failed. Err[%d]\n", err); 331 + v4l2_err(sd, "Write failed. Err[%d]\n", err); 326 332 return err; 327 333 } 328 334 } ··· 333 339 * tvp514x_get_current_std: 334 340 * Returns the current standard detected by TVP5146/47 335 341 */ 336 - static enum tvp514x_std tvp514x_get_current_std(struct tvp514x_decoder 337 - *decoder) 342 + static enum tvp514x_std tvp514x_get_current_std(struct v4l2_subdev *sd) 338 343 { 339 344 u8 std, std_status; 340 345 341 - std = tvp514x_read_reg(decoder->client, REG_VIDEO_STD); 342 - if ((std & VIDEO_STD_MASK) == VIDEO_STD_AUTO_SWITCH_BIT) { 346 + std = tvp514x_read_reg(sd, REG_VIDEO_STD); 347 + if ((std & VIDEO_STD_MASK) == VIDEO_STD_AUTO_SWITCH_BIT) 343 348 /* use the standard status register */ 344 - std_status = tvp514x_read_reg(decoder->client, 345 - REG_VIDEO_STD_STATUS); 346 - } else 349 + std_status = tvp514x_read_reg(sd, REG_VIDEO_STD_STATUS); 350 + else 347 351 std_status = std; /* use the standard register itself */ 348 352 349 353 switch (std_status & VIDEO_STD_MASK) { ··· 361 369 /* 362 370 * TVP5146/47 register dump function 363 371 */ 364 - static void tvp514x_reg_dump(struct tvp514x_decoder *decoder) 372 + static void tvp514x_reg_dump(struct v4l2_subdev *sd) 365 373 { 366 - u8 value; 367 - 368 - dump_reg(decoder->client, REG_INPUT_SEL, value); 369 - dump_reg(decoder->client, REG_AFE_GAIN_CTRL, value); 370 - dump_reg(decoder->client, REG_VIDEO_STD, value); 371 - dump_reg(decoder->client, REG_OPERATION_MODE, value); 372 - dump_reg(decoder->client, REG_COLOR_KILLER, value); 373 - dump_reg(decoder->client, REG_LUMA_CONTROL1, value); 374 - dump_reg(decoder->client, REG_LUMA_CONTROL2, value); 375 - dump_reg(decoder->client, REG_LUMA_CONTROL3, value); 376 - dump_reg(decoder->client, REG_BRIGHTNESS, value); 377 - dump_reg(decoder->client, REG_CONTRAST, value); 378 - dump_reg(decoder->client, REG_SATURATION, value); 379 - dump_reg(decoder->client, REG_HUE, value); 380 - dump_reg(decoder->client, REG_CHROMA_CONTROL1, value); 381 - dump_reg(decoder->client, REG_CHROMA_CONTROL2, value); 382 - dump_reg(decoder->client, REG_COMP_PR_SATURATION, value); 383 - dump_reg(decoder->client, REG_COMP_Y_CONTRAST, value); 384 - dump_reg(decoder->client, REG_COMP_PB_SATURATION, value); 385 - dump_reg(decoder->client, REG_COMP_Y_BRIGHTNESS, value); 386 - dump_reg(decoder->client, REG_AVID_START_PIXEL_LSB, value); 387 - dump_reg(decoder->client, REG_AVID_START_PIXEL_MSB, value); 388 - dump_reg(decoder->client, REG_AVID_STOP_PIXEL_LSB, value); 389 - dump_reg(decoder->client, REG_AVID_STOP_PIXEL_MSB, value); 390 - dump_reg(decoder->client, REG_HSYNC_START_PIXEL_LSB, value); 391 - dump_reg(decoder->client, REG_HSYNC_START_PIXEL_MSB, value); 392 - dump_reg(decoder->client, REG_HSYNC_STOP_PIXEL_LSB, value); 393 - dump_reg(decoder->client, REG_HSYNC_STOP_PIXEL_MSB, value); 394 - dump_reg(decoder->client, REG_VSYNC_START_LINE_LSB, value); 395 - dump_reg(decoder->client, REG_VSYNC_START_LINE_MSB, value); 396 - dump_reg(decoder->client, REG_VSYNC_STOP_LINE_LSB, value); 397 - dump_reg(decoder->client, REG_VSYNC_STOP_LINE_MSB, value); 398 - dump_reg(decoder->client, REG_VBLK_START_LINE_LSB, value); 399 - dump_reg(decoder->client, REG_VBLK_START_LINE_MSB, value); 400 - dump_reg(decoder->client, REG_VBLK_STOP_LINE_LSB, value); 401 - dump_reg(decoder->client, REG_VBLK_STOP_LINE_MSB, value); 402 - dump_reg(decoder->client, REG_SYNC_CONTROL, value); 403 - dump_reg(decoder->client, REG_OUTPUT_FORMATTER1, value); 404 - dump_reg(decoder->client, REG_OUTPUT_FORMATTER2, value); 405 - dump_reg(decoder->client, REG_OUTPUT_FORMATTER3, value); 406 - dump_reg(decoder->client, REG_OUTPUT_FORMATTER4, value); 407 - dump_reg(decoder->client, REG_OUTPUT_FORMATTER5, value); 408 - dump_reg(decoder->client, REG_OUTPUT_FORMATTER6, value); 409 - dump_reg(decoder->client, REG_CLEAR_LOST_LOCK, value); 374 + dump_reg(sd, REG_INPUT_SEL); 375 + dump_reg(sd, REG_AFE_GAIN_CTRL); 376 + dump_reg(sd, REG_VIDEO_STD); 377 + dump_reg(sd, REG_OPERATION_MODE); 378 + dump_reg(sd, REG_COLOR_KILLER); 379 + dump_reg(sd, REG_LUMA_CONTROL1); 380 + dump_reg(sd, REG_LUMA_CONTROL2); 381 + dump_reg(sd, REG_LUMA_CONTROL3); 382 + dump_reg(sd, REG_BRIGHTNESS); 383 + dump_reg(sd, REG_CONTRAST); 384 + dump_reg(sd, REG_SATURATION); 385 + dump_reg(sd, REG_HUE); 386 + dump_reg(sd, REG_CHROMA_CONTROL1); 387 + dump_reg(sd, REG_CHROMA_CONTROL2); 388 + dump_reg(sd, REG_COMP_PR_SATURATION); 389 + dump_reg(sd, REG_COMP_Y_CONTRAST); 390 + dump_reg(sd, REG_COMP_PB_SATURATION); 391 + dump_reg(sd, REG_COMP_Y_BRIGHTNESS); 392 + dump_reg(sd, REG_AVID_START_PIXEL_LSB); 393 + dump_reg(sd, REG_AVID_START_PIXEL_MSB); 394 + dump_reg(sd, REG_AVID_STOP_PIXEL_LSB); 395 + dump_reg(sd, REG_AVID_STOP_PIXEL_MSB); 396 + dump_reg(sd, REG_HSYNC_START_PIXEL_LSB); 397 + dump_reg(sd, REG_HSYNC_START_PIXEL_MSB); 398 + dump_reg(sd, REG_HSYNC_STOP_PIXEL_LSB); 399 + dump_reg(sd, REG_HSYNC_STOP_PIXEL_MSB); 400 + dump_reg(sd, REG_VSYNC_START_LINE_LSB); 401 + dump_reg(sd, REG_VSYNC_START_LINE_MSB); 402 + dump_reg(sd, REG_VSYNC_STOP_LINE_LSB); 403 + dump_reg(sd, REG_VSYNC_STOP_LINE_MSB); 404 + dump_reg(sd, REG_VBLK_START_LINE_LSB); 405 + dump_reg(sd, REG_VBLK_START_LINE_MSB); 406 + dump_reg(sd, REG_VBLK_STOP_LINE_LSB); 407 + dump_reg(sd, REG_VBLK_STOP_LINE_MSB); 408 + dump_reg(sd, REG_SYNC_CONTROL); 409 + dump_reg(sd, REG_OUTPUT_FORMATTER1); 410 + dump_reg(sd, REG_OUTPUT_FORMATTER2); 411 + dump_reg(sd, REG_OUTPUT_FORMATTER3); 412 + dump_reg(sd, REG_OUTPUT_FORMATTER4); 413 + dump_reg(sd, REG_OUTPUT_FORMATTER5); 414 + dump_reg(sd, REG_OUTPUT_FORMATTER6); 415 + dump_reg(sd, REG_CLEAR_LOST_LOCK); 410 416 } 411 417 412 418 /* 413 419 * Configure the TVP5146/47 with the current register settings 414 420 * Returns zero if successful, or non-zero otherwise. 415 421 */ 416 - static int tvp514x_configure(struct tvp514x_decoder *decoder) 422 + static int tvp514x_configure(struct v4l2_subdev *sd, 423 + struct tvp514x_decoder *decoder) 417 424 { 418 425 int err; 419 426 420 427 /* common register initialization */ 421 428 err = 422 - tvp514x_write_regs(decoder->client, decoder->tvp514x_regs); 429 + tvp514x_write_regs(sd, decoder->tvp514x_regs); 423 430 if (err) 424 431 return err; 425 432 426 433 if (debug) 427 - tvp514x_reg_dump(decoder); 434 + tvp514x_reg_dump(sd); 428 435 429 436 return 0; 430 437 } ··· 436 445 * Returns ENODEV error number if no device is detected, or zero 437 446 * if a device is detected. 438 447 */ 439 - static int tvp514x_detect(struct tvp514x_decoder *decoder) 448 + static int tvp514x_detect(struct v4l2_subdev *sd, 449 + struct tvp514x_decoder *decoder) 440 450 { 441 451 u8 chip_id_msb, chip_id_lsb, rom_ver; 452 + struct i2c_client *client = v4l2_get_subdevdata(sd); 442 453 443 - chip_id_msb = tvp514x_read_reg(decoder->client, REG_CHIP_ID_MSB); 444 - chip_id_lsb = tvp514x_read_reg(decoder->client, REG_CHIP_ID_LSB); 445 - rom_ver = tvp514x_read_reg(decoder->client, REG_ROM_VERSION); 454 + chip_id_msb = tvp514x_read_reg(sd, REG_CHIP_ID_MSB); 455 + chip_id_lsb = tvp514x_read_reg(sd, REG_CHIP_ID_LSB); 456 + rom_ver = tvp514x_read_reg(sd, REG_ROM_VERSION); 446 457 447 - v4l_dbg(1, debug, decoder->client, 458 + v4l2_dbg(1, debug, sd, 448 459 "chip id detected msb:0x%x lsb:0x%x rom version:0x%x\n", 449 460 chip_id_msb, chip_id_lsb, rom_ver); 450 461 if ((chip_id_msb != TVP514X_CHIP_ID_MSB) ··· 455 462 /* We didn't read the values we expected, so this must not be 456 463 * an TVP5146/47. 457 464 */ 458 - v4l_err(decoder->client, 459 - "chip id mismatch msb:0x%x lsb:0x%x\n", 460 - chip_id_msb, chip_id_lsb); 465 + v4l2_err(sd, "chip id mismatch msb:0x%x lsb:0x%x\n", 466 + chip_id_msb, chip_id_lsb); 461 467 return -ENODEV; 462 468 } 463 469 464 470 decoder->ver = rom_ver; 465 - decoder->state = STATE_DETECTED; 466 471 467 - v4l_info(decoder->client, 468 - "%s found at 0x%x (%s)\n", decoder->client->name, 469 - decoder->client->addr << 1, 470 - decoder->client->adapter->name); 472 + v4l2_info(sd, "%s (Version - 0x%.2x) found at 0x%x (%s)\n", 473 + client->name, decoder->ver, 474 + client->addr << 1, client->adapter->name); 471 475 return 0; 472 476 } 473 477 ··· 473 483 * TVP5146/47 decoder driver. 474 484 */ 475 485 476 - /** 477 - * ioctl_querystd - V4L2 decoder interface handler for VIDIOC_QUERYSTD ioctl 478 - * @s: pointer to standard V4L2 device structure 486 + /* 487 + * tvp514x_querystd - V4L2 decoder interface handler for VIDIOC_QUERYSTD ioctl 488 + * @sd: pointer to standard V4L2 sub-device structure 479 489 * @std_id: standard V4L2 std_id ioctl enum 480 490 * 481 491 * Returns the current standard detected by TVP5146/47. If no active input is 482 492 * detected, returns -EINVAL 483 493 */ 484 - static int ioctl_querystd(struct v4l2_int_device *s, v4l2_std_id *std_id) 494 + static int tvp514x_querystd(struct v4l2_subdev *sd, v4l2_std_id *std_id) 485 495 { 486 - struct tvp514x_decoder *decoder = s->priv; 496 + struct tvp514x_decoder *decoder = to_decoder(sd); 487 497 enum tvp514x_std current_std; 488 498 enum tvp514x_input input_sel; 489 499 u8 sync_lock_status, lock_mask; ··· 492 502 return -EINVAL; 493 503 494 504 /* get the current standard */ 495 - current_std = tvp514x_get_current_std(decoder); 505 + current_std = tvp514x_get_current_std(sd); 496 506 if (current_std == STD_INVALID) 497 507 return -EINVAL; 498 508 499 - input_sel = decoder->route.input; 509 + input_sel = decoder->input; 500 510 501 511 switch (input_sel) { 502 512 case INPUT_CVBS_VI1A: ··· 534 544 return -EINVAL; 535 545 } 536 546 /* check whether signal is locked */ 537 - sync_lock_status = tvp514x_read_reg(decoder->client, REG_STATUS1); 547 + sync_lock_status = tvp514x_read_reg(sd, REG_STATUS1); 538 548 if (lock_mask != (sync_lock_status & lock_mask)) 539 549 return -EINVAL; /* No input detected */ 540 550 541 551 decoder->current_std = current_std; 542 552 *std_id = decoder->std_list[current_std].standard.id; 543 553 544 - v4l_dbg(1, debug, decoder->client, "Current STD: %s", 554 + v4l2_dbg(1, debug, sd, "Current STD: %s", 545 555 decoder->std_list[current_std].standard.name); 546 556 return 0; 547 557 } 548 558 549 - /** 550 - * ioctl_s_std - V4L2 decoder interface handler for VIDIOC_S_STD ioctl 551 - * @s: pointer to standard V4L2 device structure 559 + /* 560 + * tvp514x_s_std - V4L2 decoder interface handler for VIDIOC_S_STD ioctl 561 + * @sd: pointer to standard V4L2 sub-device structure 552 562 * @std_id: standard V4L2 v4l2_std_id ioctl enum 553 563 * 554 564 * If std_id is supported, sets the requested standard. Otherwise, returns 555 565 * -EINVAL 556 566 */ 557 - static int ioctl_s_std(struct v4l2_int_device *s, v4l2_std_id *std_id) 567 + static int tvp514x_s_std(struct v4l2_subdev *sd, v4l2_std_id std_id) 558 568 { 559 - struct tvp514x_decoder *decoder = s->priv; 569 + struct tvp514x_decoder *decoder = to_decoder(sd); 560 570 int err, i; 561 571 562 - if (std_id == NULL) 563 - return -EINVAL; 564 - 565 572 for (i = 0; i < decoder->num_stds; i++) 566 - if (*std_id & decoder->std_list[i].standard.id) 573 + if (std_id & decoder->std_list[i].standard.id) 567 574 break; 568 575 569 576 if ((i == decoder->num_stds) || (i == STD_INVALID)) 570 577 return -EINVAL; 571 578 572 - err = tvp514x_write_reg(decoder->client, REG_VIDEO_STD, 579 + err = tvp514x_write_reg(sd, REG_VIDEO_STD, 573 580 decoder->std_list[i].video_std); 574 581 if (err) 575 582 return err; ··· 575 588 decoder->tvp514x_regs[REG_VIDEO_STD].val = 576 589 decoder->std_list[i].video_std; 577 590 578 - v4l_dbg(1, debug, decoder->client, "Standard set to: %s", 591 + v4l2_dbg(1, debug, sd, "Standard set to: %s", 579 592 decoder->std_list[i].standard.name); 580 593 return 0; 581 594 } 582 595 583 - /** 584 - * ioctl_s_routing - V4L2 decoder interface handler for VIDIOC_S_INPUT ioctl 585 - * @s: pointer to standard V4L2 device structure 596 + /* 597 + * tvp514x_s_routing - V4L2 decoder interface handler for VIDIOC_S_INPUT ioctl 598 + * @sd: pointer to standard V4L2 sub-device structure 586 599 * @index: number of the input 587 600 * 588 601 * If index is valid, selects the requested input. Otherwise, returns -EINVAL if 589 602 * the input is not supported or there is no active signal present in the 590 603 * selected input. 591 604 */ 592 - static int ioctl_s_routing(struct v4l2_int_device *s, 593 - struct v4l2_routing *route) 605 + static int tvp514x_s_routing(struct v4l2_subdev *sd, 606 + u32 input, u32 output, u32 config) 594 607 { 595 - struct tvp514x_decoder *decoder = s->priv; 608 + struct tvp514x_decoder *decoder = to_decoder(sd); 596 609 int err; 597 610 enum tvp514x_input input_sel; 598 611 enum tvp514x_output output_sel; ··· 600 613 u8 sync_lock_status, lock_mask; 601 614 int try_count = LOCK_RETRY_COUNT; 602 615 603 - if ((!route) || (route->input >= INPUT_INVALID) || 604 - (route->output >= OUTPUT_INVALID)) 616 + if ((input >= INPUT_INVALID) || 617 + (output >= OUTPUT_INVALID)) 605 618 return -EINVAL; /* Index out of bound */ 606 619 607 - input_sel = route->input; 608 - output_sel = route->output; 620 + input_sel = input; 621 + output_sel = output; 609 622 610 - err = tvp514x_write_reg(decoder->client, REG_INPUT_SEL, input_sel); 623 + err = tvp514x_write_reg(sd, REG_INPUT_SEL, input_sel); 611 624 if (err) 612 625 return err; 613 626 614 - output_sel |= tvp514x_read_reg(decoder->client, 627 + output_sel |= tvp514x_read_reg(sd, 615 628 REG_OUTPUT_FORMATTER1) & 0x7; 616 - err = tvp514x_write_reg(decoder->client, REG_OUTPUT_FORMATTER1, 629 + err = tvp514x_write_reg(sd, REG_OUTPUT_FORMATTER1, 617 630 output_sel); 618 631 if (err) 619 632 return err; ··· 624 637 /* Clear status */ 625 638 msleep(LOCK_RETRY_DELAY); 626 639 err = 627 - tvp514x_write_reg(decoder->client, REG_CLEAR_LOST_LOCK, 0x01); 640 + tvp514x_write_reg(sd, REG_CLEAR_LOST_LOCK, 0x01); 628 641 if (err) 629 642 return err; 630 643 ··· 669 682 msleep(LOCK_RETRY_DELAY); 670 683 671 684 /* get the current standard for future reference */ 672 - current_std = tvp514x_get_current_std(decoder); 685 + current_std = tvp514x_get_current_std(sd); 673 686 if (current_std == STD_INVALID) 674 687 continue; 675 688 676 - sync_lock_status = tvp514x_read_reg(decoder->client, 689 + sync_lock_status = tvp514x_read_reg(sd, 677 690 REG_STATUS1); 678 691 if (lock_mask == (sync_lock_status & lock_mask)) 679 692 break; /* Input detected */ ··· 683 696 return -EINVAL; 684 697 685 698 decoder->current_std = current_std; 686 - decoder->route.input = route->input; 687 - decoder->route.output = route->output; 699 + decoder->input = input; 700 + decoder->output = output; 688 701 689 - v4l_dbg(1, debug, decoder->client, 690 - "Input set to: %d, std : %d", 702 + v4l2_dbg(1, debug, sd, "Input set to: %d, std : %d", 691 703 input_sel, current_std); 692 704 693 705 return 0; 694 706 } 695 707 696 - /** 697 - * ioctl_queryctrl - V4L2 decoder interface handler for VIDIOC_QUERYCTRL ioctl 698 - * @s: pointer to standard V4L2 device structure 708 + /* 709 + * tvp514x_queryctrl - V4L2 decoder interface handler for VIDIOC_QUERYCTRL ioctl 710 + * @sd: pointer to standard V4L2 sub-device structure 699 711 * @qctrl: standard V4L2 v4l2_queryctrl structure 700 712 * 701 713 * If the requested control is supported, returns the control information. 702 714 * Otherwise, returns -EINVAL if the control is not supported. 703 715 */ 704 716 static int 705 - ioctl_queryctrl(struct v4l2_int_device *s, struct v4l2_queryctrl *qctrl) 717 + tvp514x_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qctrl) 706 718 { 707 - struct tvp514x_decoder *decoder = s->priv; 708 719 int err = -EINVAL; 709 720 710 721 if (qctrl == NULL) ··· 729 744 err = v4l2_ctrl_query_fill(qctrl, -180, 180, 180, 0); 730 745 break; 731 746 case V4L2_CID_AUTOGAIN: 732 - /* Autogain is either 0 or 1*/ 733 - memcpy(qctrl, &tvp514x_autogain_ctrl, 734 - sizeof(struct v4l2_queryctrl)); 735 - err = 0; 747 + /* 748 + * Auto Gain supported is - 749 + * 0 - 1 (Default - 1) 750 + */ 751 + err = v4l2_ctrl_query_fill(qctrl, 0, 1, 1, 1); 736 752 break; 737 753 default: 738 - v4l_err(decoder->client, 739 - "invalid control id %d\n", qctrl->id); 754 + v4l2_err(sd, "invalid control id %d\n", qctrl->id); 740 755 return err; 741 756 } 742 757 743 - v4l_dbg(1, debug, decoder->client, 744 - "Query Control: %s : Min - %d, Max - %d, Def - %d", 745 - qctrl->name, 746 - qctrl->minimum, 747 - qctrl->maximum, 758 + v4l2_dbg(1, debug, sd, "Query Control:%s: Min - %d, Max - %d, Def - %d", 759 + qctrl->name, qctrl->minimum, qctrl->maximum, 748 760 qctrl->default_value); 749 761 750 762 return err; 751 763 } 752 764 753 - /** 754 - * ioctl_g_ctrl - V4L2 decoder interface handler for VIDIOC_G_CTRL ioctl 755 - * @s: pointer to standard V4L2 device structure 765 + /* 766 + * tvp514x_g_ctrl - V4L2 decoder interface handler for VIDIOC_G_CTRL ioctl 767 + * @sd: pointer to standard V4L2 sub-device structure 756 768 * @ctrl: pointer to v4l2_control structure 757 769 * 758 770 * If the requested control is supported, returns the control's current ··· 757 775 * supported. 758 776 */ 759 777 static int 760 - ioctl_g_ctrl(struct v4l2_int_device *s, struct v4l2_control *ctrl) 778 + tvp514x_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 761 779 { 762 - struct tvp514x_decoder *decoder = s->priv; 780 + struct tvp514x_decoder *decoder = to_decoder(sd); 763 781 764 782 if (ctrl == NULL) 765 783 return -EINVAL; ··· 793 811 794 812 break; 795 813 default: 796 - v4l_err(decoder->client, 797 - "invalid control id %d\n", ctrl->id); 814 + v4l2_err(sd, "invalid control id %d\n", ctrl->id); 798 815 return -EINVAL; 799 816 } 800 817 801 - v4l_dbg(1, debug, decoder->client, 802 - "Get Control: ID - %d - %d", 818 + v4l2_dbg(1, debug, sd, "Get Control: ID - %d - %d", 803 819 ctrl->id, ctrl->value); 804 820 return 0; 805 821 } 806 822 807 - /** 808 - * ioctl_s_ctrl - V4L2 decoder interface handler for VIDIOC_S_CTRL ioctl 809 - * @s: pointer to standard V4L2 device structure 823 + /* 824 + * tvp514x_s_ctrl - V4L2 decoder interface handler for VIDIOC_S_CTRL ioctl 825 + * @sd: pointer to standard V4L2 sub-device structure 810 826 * @ctrl: pointer to v4l2_control structure 811 827 * 812 828 * If the requested control is supported, sets the control's current 813 829 * value in HW. Otherwise, returns -EINVAL if the control is not supported. 814 830 */ 815 831 static int 816 - ioctl_s_ctrl(struct v4l2_int_device *s, struct v4l2_control *ctrl) 832 + tvp514x_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 817 833 { 818 - struct tvp514x_decoder *decoder = s->priv; 834 + struct tvp514x_decoder *decoder = to_decoder(sd); 819 835 int err = -EINVAL, value; 820 836 821 837 if (ctrl == NULL) 822 838 return err; 823 839 824 - value = (__s32) ctrl->value; 840 + value = ctrl->value; 825 841 826 842 switch (ctrl->id) { 827 843 case V4L2_CID_BRIGHTNESS: 828 844 if (ctrl->value < 0 || ctrl->value > 255) { 829 - v4l_err(decoder->client, 830 - "invalid brightness setting %d\n", 845 + v4l2_err(sd, "invalid brightness setting %d\n", 831 846 ctrl->value); 832 847 return -ERANGE; 833 848 } 834 - err = tvp514x_write_reg(decoder->client, REG_BRIGHTNESS, 849 + err = tvp514x_write_reg(sd, REG_BRIGHTNESS, 835 850 value); 836 851 if (err) 837 852 return err; 853 + 838 854 decoder->tvp514x_regs[REG_BRIGHTNESS].val = value; 839 855 break; 840 856 case V4L2_CID_CONTRAST: 841 857 if (ctrl->value < 0 || ctrl->value > 255) { 842 - v4l_err(decoder->client, 843 - "invalid contrast setting %d\n", 858 + v4l2_err(sd, "invalid contrast setting %d\n", 844 859 ctrl->value); 845 860 return -ERANGE; 846 861 } 847 - err = tvp514x_write_reg(decoder->client, REG_CONTRAST, 848 - value); 862 + err = tvp514x_write_reg(sd, REG_CONTRAST, value); 849 863 if (err) 850 864 return err; 865 + 851 866 decoder->tvp514x_regs[REG_CONTRAST].val = value; 852 867 break; 853 868 case V4L2_CID_SATURATION: 854 869 if (ctrl->value < 0 || ctrl->value > 255) { 855 - v4l_err(decoder->client, 856 - "invalid saturation setting %d\n", 870 + v4l2_err(sd, "invalid saturation setting %d\n", 857 871 ctrl->value); 858 872 return -ERANGE; 859 873 } 860 - err = tvp514x_write_reg(decoder->client, REG_SATURATION, 861 - value); 874 + err = tvp514x_write_reg(sd, REG_SATURATION, value); 862 875 if (err) 863 876 return err; 877 + 864 878 decoder->tvp514x_regs[REG_SATURATION].val = value; 865 879 break; 866 880 case V4L2_CID_HUE: ··· 867 889 else if (value == 0) 868 890 value = 0; 869 891 else { 870 - v4l_err(decoder->client, 871 - "invalid hue setting %d\n", 872 - ctrl->value); 892 + v4l2_err(sd, "invalid hue setting %d\n", ctrl->value); 873 893 return -ERANGE; 874 894 } 875 - err = tvp514x_write_reg(decoder->client, REG_HUE, 876 - value); 895 + err = tvp514x_write_reg(sd, REG_HUE, value); 877 896 if (err) 878 897 return err; 898 + 879 899 decoder->tvp514x_regs[REG_HUE].val = value; 880 900 break; 881 901 case V4L2_CID_AUTOGAIN: ··· 882 906 else if (value == 0) 883 907 value = 0x0C; 884 908 else { 885 - v4l_err(decoder->client, 886 - "invalid auto gain setting %d\n", 909 + v4l2_err(sd, "invalid auto gain setting %d\n", 887 910 ctrl->value); 888 911 return -ERANGE; 889 912 } 890 - err = tvp514x_write_reg(decoder->client, REG_AFE_GAIN_CTRL, 891 - value); 913 + err = tvp514x_write_reg(sd, REG_AFE_GAIN_CTRL, value); 892 914 if (err) 893 915 return err; 916 + 894 917 decoder->tvp514x_regs[REG_AFE_GAIN_CTRL].val = value; 895 918 break; 896 919 default: 897 - v4l_err(decoder->client, 898 - "invalid control id %d\n", ctrl->id); 920 + v4l2_err(sd, "invalid control id %d\n", ctrl->id); 899 921 return err; 900 922 } 901 923 902 - v4l_dbg(1, debug, decoder->client, 903 - "Set Control: ID - %d - %d", 924 + v4l2_dbg(1, debug, sd, "Set Control: ID - %d - %d", 904 925 ctrl->id, ctrl->value); 905 926 906 927 return err; 907 928 } 908 929 909 - /** 910 - * ioctl_enum_fmt_cap - Implement the CAPTURE buffer VIDIOC_ENUM_FMT ioctl 911 - * @s: pointer to standard V4L2 device structure 930 + /* 931 + * tvp514x_enum_fmt_cap - Implement the CAPTURE buffer VIDIOC_ENUM_FMT ioctl 932 + * @sd: pointer to standard V4L2 sub-device structure 912 933 * @fmt: standard V4L2 VIDIOC_ENUM_FMT ioctl structure 913 934 * 914 935 * Implement the VIDIOC_ENUM_FMT ioctl to enumerate supported formats 915 936 */ 916 937 static int 917 - ioctl_enum_fmt_cap(struct v4l2_int_device *s, struct v4l2_fmtdesc *fmt) 938 + tvp514x_enum_fmt_cap(struct v4l2_subdev *sd, struct v4l2_fmtdesc *fmt) 918 939 { 919 - struct tvp514x_decoder *decoder = s->priv; 940 + struct tvp514x_decoder *decoder = to_decoder(sd); 920 941 int index; 921 942 922 943 if (fmt == NULL) ··· 929 956 memcpy(fmt, &decoder->fmt_list[index], 930 957 sizeof(struct v4l2_fmtdesc)); 931 958 932 - v4l_dbg(1, debug, decoder->client, 933 - "Current FMT: index - %d (%s)", 959 + v4l2_dbg(1, debug, sd, "Current FMT: index - %d (%s)", 934 960 decoder->fmt_list[index].index, 935 961 decoder->fmt_list[index].description); 936 962 return 0; 937 963 } 938 964 939 - /** 940 - * ioctl_try_fmt_cap - Implement the CAPTURE buffer VIDIOC_TRY_FMT ioctl 941 - * @s: pointer to standard V4L2 device structure 965 + /* 966 + * tvp514x_try_fmt_cap - Implement the CAPTURE buffer VIDIOC_TRY_FMT ioctl 967 + * @sd: pointer to standard V4L2 sub-device structure 942 968 * @f: pointer to standard V4L2 VIDIOC_TRY_FMT ioctl structure 943 969 * 944 970 * Implement the VIDIOC_TRY_FMT ioctl for the CAPTURE buffer type. This ··· 945 973 * without actually making it take effect. 946 974 */ 947 975 static int 948 - ioctl_try_fmt_cap(struct v4l2_int_device *s, struct v4l2_format *f) 976 + tvp514x_try_fmt_cap(struct v4l2_subdev *sd, struct v4l2_format *f) 949 977 { 950 - struct tvp514x_decoder *decoder = s->priv; 978 + struct tvp514x_decoder *decoder = to_decoder(sd); 951 979 int ifmt; 952 980 struct v4l2_pix_format *pix; 953 981 enum tvp514x_std current_std; ··· 961 989 pix = &f->fmt.pix; 962 990 963 991 /* Calculate height and width based on current standard */ 964 - current_std = tvp514x_get_current_std(decoder); 992 + current_std = tvp514x_get_current_std(sd); 965 993 if (current_std == STD_INVALID) 966 994 return -EINVAL; 967 995 ··· 984 1012 pix->colorspace = V4L2_COLORSPACE_SMPTE170M; 985 1013 pix->priv = 0; 986 1014 987 - v4l_dbg(1, debug, decoder->client, 988 - "Try FMT: pixelformat - %s, bytesperline - %d" 1015 + v4l2_dbg(1, debug, sd, "Try FMT: pixelformat - %s, bytesperline - %d" 989 1016 "Width - %d, Height - %d", 990 1017 decoder->fmt_list[ifmt].description, pix->bytesperline, 991 1018 pix->width, pix->height); 992 1019 return 0; 993 1020 } 994 1021 995 - /** 996 - * ioctl_s_fmt_cap - V4L2 decoder interface handler for VIDIOC_S_FMT ioctl 997 - * @s: pointer to standard V4L2 device structure 1022 + /* 1023 + * tvp514x_s_fmt_cap - V4L2 decoder interface handler for VIDIOC_S_FMT ioctl 1024 + * @sd: pointer to standard V4L2 sub-device structure 998 1025 * @f: pointer to standard V4L2 VIDIOC_S_FMT ioctl structure 999 1026 * 1000 1027 * If the requested format is supported, configures the HW to use that ··· 1001 1030 * correctly configured. 1002 1031 */ 1003 1032 static int 1004 - ioctl_s_fmt_cap(struct v4l2_int_device *s, struct v4l2_format *f) 1033 + tvp514x_s_fmt_cap(struct v4l2_subdev *sd, struct v4l2_format *f) 1005 1034 { 1006 - struct tvp514x_decoder *decoder = s->priv; 1035 + struct tvp514x_decoder *decoder = to_decoder(sd); 1007 1036 struct v4l2_pix_format *pix; 1008 1037 int rval; 1009 1038 ··· 1014 1043 return -EINVAL; /* only capture is supported */ 1015 1044 1016 1045 pix = &f->fmt.pix; 1017 - rval = ioctl_try_fmt_cap(s, f); 1046 + rval = tvp514x_try_fmt_cap(sd, f); 1018 1047 if (rval) 1019 1048 return rval; 1020 1049 ··· 1023 1052 return rval; 1024 1053 } 1025 1054 1026 - /** 1027 - * ioctl_g_fmt_cap - V4L2 decoder interface handler for ioctl_g_fmt_cap 1028 - * @s: pointer to standard V4L2 device structure 1055 + /* 1056 + * tvp514x_g_fmt_cap - V4L2 decoder interface handler for tvp514x_g_fmt_cap 1057 + * @sd: pointer to standard V4L2 sub-device structure 1029 1058 * @f: pointer to standard V4L2 v4l2_format structure 1030 1059 * 1031 1060 * Returns the decoder's current pixel format in the v4l2_format 1032 1061 * parameter. 1033 1062 */ 1034 1063 static int 1035 - ioctl_g_fmt_cap(struct v4l2_int_device *s, struct v4l2_format *f) 1064 + tvp514x_g_fmt_cap(struct v4l2_subdev *sd, struct v4l2_format *f) 1036 1065 { 1037 - struct tvp514x_decoder *decoder = s->priv; 1066 + struct tvp514x_decoder *decoder = to_decoder(sd); 1038 1067 1039 1068 if (f == NULL) 1040 1069 return -EINVAL; ··· 1044 1073 1045 1074 f->fmt.pix = decoder->pix; 1046 1075 1047 - v4l_dbg(1, debug, decoder->client, 1048 - "Current FMT: bytesperline - %d" 1076 + v4l2_dbg(1, debug, sd, "Current FMT: bytesperline - %d" 1049 1077 "Width - %d, Height - %d", 1050 1078 decoder->pix.bytesperline, 1051 1079 decoder->pix.width, decoder->pix.height); 1052 1080 return 0; 1053 1081 } 1054 1082 1055 - /** 1056 - * ioctl_g_parm - V4L2 decoder interface handler for VIDIOC_G_PARM ioctl 1057 - * @s: pointer to standard V4L2 device structure 1083 + /* 1084 + * tvp514x_g_parm - V4L2 decoder interface handler for VIDIOC_G_PARM ioctl 1085 + * @sd: pointer to standard V4L2 sub-device structure 1058 1086 * @a: pointer to standard V4L2 VIDIOC_G_PARM ioctl structure 1059 1087 * 1060 1088 * Returns the decoder's video CAPTURE parameters. 1061 1089 */ 1062 1090 static int 1063 - ioctl_g_parm(struct v4l2_int_device *s, struct v4l2_streamparm *a) 1091 + tvp514x_g_parm(struct v4l2_subdev *sd, struct v4l2_streamparm *a) 1064 1092 { 1065 - struct tvp514x_decoder *decoder = s->priv; 1093 + struct tvp514x_decoder *decoder = to_decoder(sd); 1066 1094 struct v4l2_captureparm *cparm; 1067 1095 enum tvp514x_std current_std; 1068 1096 ··· 1075 1105 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 1076 1106 1077 1107 /* get the current standard */ 1078 - current_std = tvp514x_get_current_std(decoder); 1108 + current_std = tvp514x_get_current_std(sd); 1079 1109 if (current_std == STD_INVALID) 1080 1110 return -EINVAL; 1081 1111 ··· 1089 1119 return 0; 1090 1120 } 1091 1121 1092 - /** 1093 - * ioctl_s_parm - V4L2 decoder interface handler for VIDIOC_S_PARM ioctl 1094 - * @s: pointer to standard V4L2 device structure 1122 + /* 1123 + * tvp514x_s_parm - V4L2 decoder interface handler for VIDIOC_S_PARM ioctl 1124 + * @sd: pointer to standard V4L2 sub-device structure 1095 1125 * @a: pointer to standard V4L2 VIDIOC_S_PARM ioctl structure 1096 1126 * 1097 1127 * Configures the decoder to use the input parameters, if possible. If 1098 1128 * not possible, returns the appropriate error code. 1099 1129 */ 1100 1130 static int 1101 - ioctl_s_parm(struct v4l2_int_device *s, struct v4l2_streamparm *a) 1131 + tvp514x_s_parm(struct v4l2_subdev *sd, struct v4l2_streamparm *a) 1102 1132 { 1103 - struct tvp514x_decoder *decoder = s->priv; 1133 + struct tvp514x_decoder *decoder = to_decoder(sd); 1104 1134 struct v4l2_fract *timeperframe; 1105 1135 enum tvp514x_std current_std; 1106 1136 ··· 1113 1143 timeperframe = &a->parm.capture.timeperframe; 1114 1144 1115 1145 /* get the current standard */ 1116 - current_std = tvp514x_get_current_std(decoder); 1146 + current_std = tvp514x_get_current_std(sd); 1117 1147 if (current_std == STD_INVALID) 1118 1148 return -EINVAL; 1119 1149 ··· 1125 1155 return 0; 1126 1156 } 1127 1157 1128 - /** 1129 - * ioctl_g_ifparm - V4L2 decoder interface handler for vidioc_int_g_ifparm_num 1130 - * @s: pointer to standard V4L2 device structure 1131 - * @p: pointer to standard V4L2 vidioc_int_g_ifparm_num ioctl structure 1158 + /* 1159 + * tvp514x_s_stream - V4L2 decoder interface handler for vidioc_int_s_power_num 1160 + * @sd: pointer to standard V4L2 sub-device structure 1161 + * @enable: streaming enable or disable 1132 1162 * 1133 - * Gets slave interface parameters. 1134 - * Calculates the required xclk value to support the requested 1135 - * clock parameters in p. This value is returned in the p 1136 - * parameter. 1163 + * Sets streaming to enable or disable, if possible. 1137 1164 */ 1138 - static int ioctl_g_ifparm(struct v4l2_int_device *s, struct v4l2_ifparm *p) 1165 + static int tvp514x_s_stream(struct v4l2_subdev *sd, int enable) 1139 1166 { 1140 - struct tvp514x_decoder *decoder = s->priv; 1141 - int rval; 1142 - 1143 - if (p == NULL) 1144 - return -EINVAL; 1145 - 1146 - if (NULL == decoder->pdata->ifparm) 1147 - return -EINVAL; 1148 - 1149 - rval = decoder->pdata->ifparm(p); 1150 - if (rval) { 1151 - v4l_err(decoder->client, "g_ifparm.Err[%d]\n", rval); 1152 - return rval; 1153 - } 1154 - 1155 - p->u.bt656.clock_curr = TVP514X_XCLK_BT656; 1156 - 1157 - return 0; 1158 - } 1159 - 1160 - /** 1161 - * ioctl_g_priv - V4L2 decoder interface handler for vidioc_int_g_priv_num 1162 - * @s: pointer to standard V4L2 device structure 1163 - * @p: void pointer to hold decoder's private data address 1164 - * 1165 - * Returns device's (decoder's) private data area address in p parameter 1166 - */ 1167 - static int ioctl_g_priv(struct v4l2_int_device *s, void *p) 1168 - { 1169 - struct tvp514x_decoder *decoder = s->priv; 1170 - 1171 - if (NULL == decoder->pdata->priv_data_set) 1172 - return -EINVAL; 1173 - 1174 - return decoder->pdata->priv_data_set(p); 1175 - } 1176 - 1177 - /** 1178 - * ioctl_s_power - V4L2 decoder interface handler for vidioc_int_s_power_num 1179 - * @s: pointer to standard V4L2 device structure 1180 - * @on: power state to which device is to be set 1181 - * 1182 - * Sets devices power state to requrested state, if possible. 1183 - */ 1184 - static int ioctl_s_power(struct v4l2_int_device *s, enum v4l2_power on) 1185 - { 1186 - struct tvp514x_decoder *decoder = s->priv; 1187 1167 int err = 0; 1168 + struct i2c_client *client = v4l2_get_subdevdata(sd); 1169 + struct tvp514x_decoder *decoder = to_decoder(sd); 1188 1170 1189 - switch (on) { 1190 - case V4L2_POWER_OFF: 1171 + if (decoder->streaming == enable) 1172 + return 0; 1173 + 1174 + switch (enable) { 1175 + case 0: 1176 + { 1191 1177 /* Power Down Sequence */ 1192 - err = 1193 - tvp514x_write_reg(decoder->client, REG_OPERATION_MODE, 1194 - 0x01); 1195 - /* Disable mux for TVP5146/47 decoder data path */ 1196 - if (decoder->pdata->power_set) 1197 - err |= decoder->pdata->power_set(on); 1198 - decoder->state = STATE_NOT_DETECTED; 1199 - break; 1200 - 1201 - case V4L2_POWER_STANDBY: 1202 - if (decoder->pdata->power_set) 1203 - err = decoder->pdata->power_set(on); 1204 - break; 1205 - 1206 - case V4L2_POWER_ON: 1207 - /* Enable mux for TVP5146/47 decoder data path */ 1208 - if ((decoder->pdata->power_set) && 1209 - (decoder->state == STATE_NOT_DETECTED)) { 1210 - int i; 1211 - struct tvp514x_init_seq *int_seq = 1212 - (struct tvp514x_init_seq *) 1213 - decoder->id->driver_data; 1214 - 1215 - err = decoder->pdata->power_set(on); 1216 - 1217 - /* Power Up Sequence */ 1218 - for (i = 0; i < int_seq->no_regs; i++) { 1219 - err |= tvp514x_write_reg(decoder->client, 1220 - int_seq->init_reg_seq[i].reg, 1221 - int_seq->init_reg_seq[i].val); 1222 - } 1223 - /* Detect the sensor is not already detected */ 1224 - err |= tvp514x_detect(decoder); 1225 - if (err) { 1226 - v4l_err(decoder->client, 1227 - "Unable to detect decoder\n"); 1228 - return err; 1229 - } 1178 + err = tvp514x_write_reg(sd, REG_OPERATION_MODE, 0x01); 1179 + if (err) { 1180 + v4l2_err(sd, "Unable to turn off decoder\n"); 1181 + return err; 1230 1182 } 1231 - err |= tvp514x_configure(decoder); 1183 + decoder->streaming = enable; 1232 1184 break; 1185 + } 1186 + case 1: 1187 + { 1188 + struct tvp514x_reg *int_seq = (struct tvp514x_reg *) 1189 + client->driver->id_table->driver_data; 1233 1190 1191 + /* Power Up Sequence */ 1192 + err = tvp514x_write_regs(sd, int_seq); 1193 + if (err) { 1194 + v4l2_err(sd, "Unable to turn on decoder\n"); 1195 + return err; 1196 + } 1197 + /* Detect if not already detected */ 1198 + err = tvp514x_detect(sd, decoder); 1199 + if (err) { 1200 + v4l2_err(sd, "Unable to detect decoder\n"); 1201 + return err; 1202 + } 1203 + err = tvp514x_configure(sd, decoder); 1204 + if (err) { 1205 + v4l2_err(sd, "Unable to configure decoder\n"); 1206 + return err; 1207 + } 1208 + decoder->streaming = enable; 1209 + break; 1210 + } 1234 1211 default: 1235 1212 err = -ENODEV; 1236 1213 break; ··· 1186 1269 return err; 1187 1270 } 1188 1271 1189 - /** 1190 - * ioctl_init - V4L2 decoder interface handler for VIDIOC_INT_INIT 1191 - * @s: pointer to standard V4L2 device structure 1192 - * 1193 - * Initialize the decoder device (calls tvp514x_configure()) 1194 - */ 1195 - static int ioctl_init(struct v4l2_int_device *s) 1196 - { 1197 - struct tvp514x_decoder *decoder = s->priv; 1272 + static const struct v4l2_subdev_core_ops tvp514x_core_ops = { 1273 + .queryctrl = tvp514x_queryctrl, 1274 + .g_ctrl = tvp514x_g_ctrl, 1275 + .s_ctrl = tvp514x_s_ctrl, 1276 + .s_std = tvp514x_s_std, 1277 + }; 1198 1278 1199 - /* Set default standard to auto */ 1200 - decoder->tvp514x_regs[REG_VIDEO_STD].val = 1201 - VIDEO_STD_AUTO_SWITCH_BIT; 1279 + static const struct v4l2_subdev_video_ops tvp514x_video_ops = { 1280 + .s_routing = tvp514x_s_routing, 1281 + .querystd = tvp514x_querystd, 1282 + .enum_fmt = tvp514x_enum_fmt_cap, 1283 + .g_fmt = tvp514x_g_fmt_cap, 1284 + .try_fmt = tvp514x_try_fmt_cap, 1285 + .s_fmt = tvp514x_s_fmt_cap, 1286 + .g_parm = tvp514x_g_parm, 1287 + .s_parm = tvp514x_s_parm, 1288 + .s_stream = tvp514x_s_stream, 1289 + }; 1202 1290 1203 - return tvp514x_configure(decoder); 1204 - } 1205 - 1206 - /** 1207 - * ioctl_dev_exit - V4L2 decoder interface handler for vidioc_int_dev_exit_num 1208 - * @s: pointer to standard V4L2 device structure 1209 - * 1210 - * Delinitialise the dev. at slave detach. The complement of ioctl_dev_init. 1211 - */ 1212 - static int ioctl_dev_exit(struct v4l2_int_device *s) 1213 - { 1214 - return 0; 1215 - } 1216 - 1217 - /** 1218 - * ioctl_dev_init - V4L2 decoder interface handler for vidioc_int_dev_init_num 1219 - * @s: pointer to standard V4L2 device structure 1220 - * 1221 - * Initialise the device when slave attaches to the master. Returns 0 if 1222 - * TVP5146/47 device could be found, otherwise returns appropriate error. 1223 - */ 1224 - static int ioctl_dev_init(struct v4l2_int_device *s) 1225 - { 1226 - struct tvp514x_decoder *decoder = s->priv; 1227 - int err; 1228 - 1229 - err = tvp514x_detect(decoder); 1230 - if (err < 0) { 1231 - v4l_err(decoder->client, 1232 - "Unable to detect decoder\n"); 1233 - return err; 1234 - } 1235 - 1236 - v4l_info(decoder->client, 1237 - "chip version 0x%.2x detected\n", decoder->ver); 1238 - 1239 - return 0; 1240 - } 1241 - 1242 - static struct v4l2_int_ioctl_desc tvp514x_ioctl_desc[] = { 1243 - {vidioc_int_dev_init_num, (v4l2_int_ioctl_func*) ioctl_dev_init}, 1244 - {vidioc_int_dev_exit_num, (v4l2_int_ioctl_func*) ioctl_dev_exit}, 1245 - {vidioc_int_s_power_num, (v4l2_int_ioctl_func*) ioctl_s_power}, 1246 - {vidioc_int_g_priv_num, (v4l2_int_ioctl_func*) ioctl_g_priv}, 1247 - {vidioc_int_g_ifparm_num, (v4l2_int_ioctl_func*) ioctl_g_ifparm}, 1248 - {vidioc_int_init_num, (v4l2_int_ioctl_func*) ioctl_init}, 1249 - {vidioc_int_enum_fmt_cap_num, 1250 - (v4l2_int_ioctl_func *) ioctl_enum_fmt_cap}, 1251 - {vidioc_int_try_fmt_cap_num, 1252 - (v4l2_int_ioctl_func *) ioctl_try_fmt_cap}, 1253 - {vidioc_int_g_fmt_cap_num, 1254 - (v4l2_int_ioctl_func *) ioctl_g_fmt_cap}, 1255 - {vidioc_int_s_fmt_cap_num, 1256 - (v4l2_int_ioctl_func *) ioctl_s_fmt_cap}, 1257 - {vidioc_int_g_parm_num, (v4l2_int_ioctl_func *) ioctl_g_parm}, 1258 - {vidioc_int_s_parm_num, (v4l2_int_ioctl_func *) ioctl_s_parm}, 1259 - {vidioc_int_queryctrl_num, 1260 - (v4l2_int_ioctl_func *) ioctl_queryctrl}, 1261 - {vidioc_int_g_ctrl_num, (v4l2_int_ioctl_func *) ioctl_g_ctrl}, 1262 - {vidioc_int_s_ctrl_num, (v4l2_int_ioctl_func *) ioctl_s_ctrl}, 1263 - {vidioc_int_querystd_num, (v4l2_int_ioctl_func *) ioctl_querystd}, 1264 - {vidioc_int_s_std_num, (v4l2_int_ioctl_func *) ioctl_s_std}, 1265 - {vidioc_int_s_video_routing_num, 1266 - (v4l2_int_ioctl_func *) ioctl_s_routing}, 1291 + static const struct v4l2_subdev_ops tvp514x_ops = { 1292 + .core = &tvp514x_core_ops, 1293 + .video = &tvp514x_video_ops, 1267 1294 }; 1268 1295 1269 1296 static struct tvp514x_decoder tvp514x_dev = { 1270 - .state = STATE_NOT_DETECTED, 1297 + .streaming = 0, 1271 1298 1272 1299 .fmt_list = tvp514x_fmt_list, 1273 1300 .num_fmts = ARRAY_SIZE(tvp514x_fmt_list), 1274 1301 1275 - .pix = { /* Default to NTSC 8-bit YUV 422 */ 1302 + .pix = {/* Default to NTSC 8-bit YUV 422 */ 1276 1303 .width = NTSC_NUM_ACTIVE_PIXELS, 1277 1304 .height = NTSC_NUM_ACTIVE_LINES, 1278 1305 .pixelformat = V4L2_PIX_FMT_UYVY, ··· 1230 1369 .current_std = STD_NTSC_MJ, 1231 1370 .std_list = tvp514x_std_list, 1232 1371 .num_stds = ARRAY_SIZE(tvp514x_std_list), 1233 - .v4l2_int_device = { 1234 - .module = THIS_MODULE, 1235 - .name = TVP514X_MODULE_NAME, 1236 - .type = v4l2_int_type_slave, 1237 - }, 1238 - .tvp514x_slave = { 1239 - .ioctls = tvp514x_ioctl_desc, 1240 - .num_ioctls = ARRAY_SIZE(tvp514x_ioctl_desc), 1241 - }, 1372 + 1242 1373 }; 1243 1374 1244 - /** 1375 + /* 1245 1376 * tvp514x_probe - decoder driver i2c probe handler 1246 1377 * @client: i2c driver client device structure 1378 + * @id: i2c driver id table 1247 1379 * 1248 1380 * Register decoder as an i2c client device and V4L2 1249 1381 * device. ··· 1245 1391 tvp514x_probe(struct i2c_client *client, const struct i2c_device_id *id) 1246 1392 { 1247 1393 struct tvp514x_decoder *decoder; 1248 - int err; 1394 + struct v4l2_subdev *sd; 1249 1395 1250 1396 /* Check if the adapter supports the needed features */ 1251 1397 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 1252 1398 return -EIO; 1253 1399 1400 + if (!client->dev.platform_data) { 1401 + v4l2_err(client, "No platform data!!\n"); 1402 + return -ENODEV; 1403 + } 1404 + 1254 1405 decoder = kzalloc(sizeof(*decoder), GFP_KERNEL); 1255 1406 if (!decoder) 1256 1407 return -ENOMEM; 1257 1408 1258 - if (!client->dev.platform_data) { 1259 - v4l_err(client, "No platform data!!\n"); 1260 - err = -ENODEV; 1261 - goto out_free; 1262 - } 1263 - 1409 + /* 1410 + * Initialize the tvp514x_decoder with default configuration 1411 + */ 1264 1412 *decoder = tvp514x_dev; 1265 - decoder->v4l2_int_device.priv = decoder; 1266 - decoder->pdata = client->dev.platform_data; 1267 - decoder->v4l2_int_device.u.slave = &decoder->tvp514x_slave; 1413 + /* Copy default register configuration */ 1268 1414 memcpy(decoder->tvp514x_regs, tvp514x_reg_list_default, 1269 1415 sizeof(tvp514x_reg_list_default)); 1416 + 1417 + /* 1418 + * Copy board specific information here 1419 + */ 1420 + decoder->pdata = client->dev.platform_data; 1421 + 1270 1422 /* 1271 1423 * Fetch platform specific data, and configure the 1272 1424 * tvp514x_reg_list[] accordingly. Since this is one 1273 1425 * time configuration, no need to preserve. 1274 1426 */ 1275 1427 decoder->tvp514x_regs[REG_OUTPUT_FORMATTER2].val |= 1276 - (decoder->pdata->clk_polarity << 1); 1428 + (decoder->pdata->clk_polarity << 1); 1277 1429 decoder->tvp514x_regs[REG_SYNC_CONTROL].val |= 1278 - ((decoder->pdata->hs_polarity << 2) | 1279 - (decoder->pdata->vs_polarity << 3)); 1280 - /* 1281 - * Save the id data, required for power up sequence 1282 - */ 1283 - decoder->id = (struct i2c_device_id *)id; 1284 - /* Attach to Master */ 1285 - strcpy(decoder->v4l2_int_device.u.slave->attach_to, 1286 - decoder->pdata->master); 1287 - decoder->client = client; 1288 - i2c_set_clientdata(client, decoder); 1430 + ((decoder->pdata->hs_polarity << 2) | 1431 + (decoder->pdata->vs_polarity << 3)); 1432 + /* Set default standard to auto */ 1433 + decoder->tvp514x_regs[REG_VIDEO_STD].val = 1434 + VIDEO_STD_AUTO_SWITCH_BIT; 1289 1435 1290 1436 /* Register with V4L2 layer as slave device */ 1291 - err = v4l2_int_device_register(&decoder->v4l2_int_device); 1292 - if (err) { 1293 - i2c_set_clientdata(client, NULL); 1294 - v4l_err(client, 1295 - "Unable to register to v4l2. Err[%d]\n", err); 1296 - goto out_free; 1437 + sd = &decoder->sd; 1438 + v4l2_i2c_subdev_init(sd, client, &tvp514x_ops); 1297 1439 1298 - } else 1299 - v4l_info(client, "Registered to v4l2 master %s!!\n", 1300 - decoder->pdata->master); 1440 + v4l2_info(sd, "%s decoder driver registered !!\n", sd->name); 1441 + 1301 1442 return 0; 1302 1443 1303 - out_free: 1304 - kfree(decoder); 1305 - return err; 1306 1444 } 1307 1445 1308 - /** 1446 + /* 1309 1447 * tvp514x_remove - decoder driver i2c remove handler 1310 1448 * @client: i2c driver client device structure 1311 1449 * 1312 1450 * Unregister decoder as an i2c client device and V4L2 1313 1451 * device. Complement of tvp514x_probe(). 1314 1452 */ 1315 - static int __exit tvp514x_remove(struct i2c_client *client) 1453 + static int tvp514x_remove(struct i2c_client *client) 1316 1454 { 1317 - struct tvp514x_decoder *decoder = i2c_get_clientdata(client); 1455 + struct v4l2_subdev *sd = i2c_get_clientdata(client); 1456 + struct tvp514x_decoder *decoder = to_decoder(sd); 1318 1457 1319 - if (!client->adapter) 1320 - return -ENODEV; /* our client isn't attached */ 1321 - 1322 - v4l2_int_device_unregister(&decoder->v4l2_int_device); 1323 - i2c_set_clientdata(client, NULL); 1458 + v4l2_device_unregister_subdev(sd); 1324 1459 kfree(decoder); 1325 1460 return 0; 1326 1461 } ··· 1328 1485 {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x00}, 1329 1486 {TOK_WRITE, REG_OPERATION_MODE, 0x01}, 1330 1487 {TOK_WRITE, REG_OPERATION_MODE, 0x00}, 1488 + {TOK_TERM, 0, 0}, 1331 1489 }; 1332 - static const struct tvp514x_init_seq tvp5146_init = { 1333 - .no_regs = ARRAY_SIZE(tvp5146_init_reg_seq), 1334 - .init_reg_seq = tvp5146_init_reg_seq, 1335 - }; 1490 + 1336 1491 /* 1337 1492 * TVP5147 Init/Power on Sequence 1338 1493 */ ··· 1353 1512 {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x00}, 1354 1513 {TOK_WRITE, REG_OPERATION_MODE, 0x01}, 1355 1514 {TOK_WRITE, REG_OPERATION_MODE, 0x00}, 1515 + {TOK_TERM, 0, 0}, 1356 1516 }; 1357 - static const struct tvp514x_init_seq tvp5147_init = { 1358 - .no_regs = ARRAY_SIZE(tvp5147_init_reg_seq), 1359 - .init_reg_seq = tvp5147_init_reg_seq, 1360 - }; 1517 + 1361 1518 /* 1362 1519 * TVP5146M2/TVP5147M1 Init/Power on Sequence 1363 1520 */ 1364 1521 static const struct tvp514x_reg tvp514xm_init_reg_seq[] = { 1365 1522 {TOK_WRITE, REG_OPERATION_MODE, 0x01}, 1366 1523 {TOK_WRITE, REG_OPERATION_MODE, 0x00}, 1524 + {TOK_TERM, 0, 0}, 1367 1525 }; 1368 - static const struct tvp514x_init_seq tvp514xm_init = { 1369 - .no_regs = ARRAY_SIZE(tvp514xm_init_reg_seq), 1370 - .init_reg_seq = tvp514xm_init_reg_seq, 1371 - }; 1526 + 1372 1527 /* 1373 1528 * I2C Device Table - 1374 1529 * ··· 1372 1535 * driver_data - Driver data 1373 1536 */ 1374 1537 static const struct i2c_device_id tvp514x_id[] = { 1375 - {"tvp5146", (unsigned long)&tvp5146_init}, 1376 - {"tvp5146m2", (unsigned long)&tvp514xm_init}, 1377 - {"tvp5147", (unsigned long)&tvp5147_init}, 1378 - {"tvp5147m1", (unsigned long)&tvp514xm_init}, 1538 + {"tvp5146", (unsigned long)tvp5146_init_reg_seq}, 1539 + {"tvp5146m2", (unsigned long)tvp514xm_init_reg_seq}, 1540 + {"tvp5147", (unsigned long)tvp5147_init_reg_seq}, 1541 + {"tvp5147m1", (unsigned long)tvp514xm_init_reg_seq}, 1379 1542 {}, 1380 1543 }; 1381 1544 1382 1545 MODULE_DEVICE_TABLE(i2c, tvp514x_id); 1383 1546 1384 - static struct i2c_driver tvp514x_i2c_driver = { 1547 + static struct i2c_driver tvp514x_driver = { 1385 1548 .driver = { 1386 - .name = TVP514X_MODULE_NAME, 1387 - .owner = THIS_MODULE, 1388 - }, 1549 + .owner = THIS_MODULE, 1550 + .name = TVP514X_MODULE_NAME, 1551 + }, 1389 1552 .probe = tvp514x_probe, 1390 - .remove = __exit_p(tvp514x_remove), 1553 + .remove = tvp514x_remove, 1391 1554 .id_table = tvp514x_id, 1392 1555 }; 1393 1556 1394 - /** 1395 - * tvp514x_init 1396 - * 1397 - * Module init function 1398 - */ 1399 1557 static int __init tvp514x_init(void) 1400 1558 { 1401 - return i2c_add_driver(&tvp514x_i2c_driver); 1559 + return i2c_add_driver(&tvp514x_driver); 1402 1560 } 1403 1561 1404 - /** 1405 - * tvp514x_cleanup 1406 - * 1407 - * Module exit function 1408 - */ 1409 - static void __exit tvp514x_cleanup(void) 1562 + static void __exit tvp514x_exit(void) 1410 1563 { 1411 - i2c_del_driver(&tvp514x_i2c_driver); 1564 + i2c_del_driver(&tvp514x_driver); 1412 1565 } 1413 1566 1414 1567 module_init(tvp514x_init); 1415 - module_exit(tvp514x_cleanup); 1416 - 1417 - MODULE_AUTHOR("Texas Instruments"); 1418 - MODULE_DESCRIPTION("TVP514X linux decoder driver"); 1419 - MODULE_LICENSE("GPL"); 1568 + module_exit(tvp514x_exit);
-10
drivers/media/video/tvp514x_regs.h
··· 284 284 u32 val; 285 285 }; 286 286 287 - /** 288 - * struct tvp514x_init_seq - Structure for TVP5146/47/46M2/47M1 power up 289 - * Sequence. 290 - * @ no_regs - Number of registers to write for power up sequence. 291 - * @ init_reg_seq - Array of registers and respective value to write. 292 - */ 293 - struct tvp514x_init_seq { 294 - unsigned int no_regs; 295 - const struct tvp514x_reg *init_reg_seq; 296 - }; 297 287 #endif /* ifndef _TVP514X_REGS_H */
-4
include/media/tvp514x.h
··· 104 104 * @ vs_polarity: VSYNC Polarity configuration for current interface. 105 105 */ 106 106 struct tvp514x_platform_data { 107 - char *master; 108 - int (*power_set) (enum v4l2_power on); 109 - int (*ifparm) (struct v4l2_ifparm *p); 110 - int (*priv_data_set) (void *); 111 107 /* Interface control params */ 112 108 bool clk_polarity; 113 109 bool hs_polarity;