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

[media] msi2500: cleanups

Rename state to dev.
Correct some indentations.
Remove FSF address.
Fix some style issues reported by checkpatch.pl.
Correct some style issues I liked.

Signed-off-by: Antti Palosaari <crope@iki.fi>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

authored by

Antti Palosaari and committed by
Mauro Carvalho Chehab
f7e5a655 faf22b13

+304 -302
+304 -302
drivers/media/usb/msi2500/msi2500.c
··· 1 1 /* 2 + * Mirics MSi2500 driver 2 3 * Mirics MSi3101 SDR Dongle driver 3 4 * 4 5 * Copyright (C) 2013 Antti Palosaari <crope@iki.fi> ··· 13 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 14 * GNU General Public License for more details. 16 - * 17 - * You should have received a copy of the GNU General Public License along 18 - * with this program; if not, write to the Free Software Foundation, Inc., 19 - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 15 * 21 16 * That driver is somehow based of pwc driver: 22 17 * (C) 1999-2004 Nemosoft Unv. ··· 116 119 struct list_head list; 117 120 }; 118 121 119 - struct msi2500_state { 122 + struct msi2500_dev { 120 123 struct device *dev; 121 124 struct video_device vdev; 122 125 struct v4l2_device v4l2_dev; ··· 155 158 156 159 /* Private functions */ 157 160 static struct msi2500_frame_buf *msi2500_get_next_fill_buf( 158 - struct msi2500_state *s) 161 + struct msi2500_dev *dev) 159 162 { 160 163 unsigned long flags; 161 164 struct msi2500_frame_buf *buf = NULL; 162 165 163 - spin_lock_irqsave(&s->queued_bufs_lock, flags); 164 - if (list_empty(&s->queued_bufs)) 166 + spin_lock_irqsave(&dev->queued_bufs_lock, flags); 167 + if (list_empty(&dev->queued_bufs)) 165 168 goto leave; 166 169 167 - buf = list_entry(s->queued_bufs.next, struct msi2500_frame_buf, list); 170 + buf = list_entry(dev->queued_bufs.next, struct msi2500_frame_buf, list); 168 171 list_del(&buf->list); 169 172 leave: 170 - spin_unlock_irqrestore(&s->queued_bufs_lock, flags); 173 + spin_unlock_irqrestore(&dev->queued_bufs_lock, flags); 171 174 return buf; 172 175 } 173 176 ··· 253 256 * signed 14-bit sample 254 257 */ 255 258 256 - static int msi2500_convert_stream(struct msi2500_state *s, u8 *dst, u8 *src, 257 - unsigned int src_len) 259 + static int msi2500_convert_stream(struct msi2500_dev *dev, u8 *dst, u8 *src, 260 + unsigned int src_len) 258 261 { 259 262 unsigned int i, j, transactions, dst_len = 0; 260 263 u32 sample[3]; ··· 265 268 for (i = 0; i < transactions; i++) { 266 269 sample[i] = src[3] << 24 | src[2] << 16 | src[1] << 8 | 267 270 src[0] << 0; 268 - if (i == 0 && s->next_sample != sample[0]) { 269 - dev_dbg_ratelimited(s->dev, 270 - "%d samples lost, %d %08x:%08x\n", 271 - sample[0] - s->next_sample, 272 - src_len, s->next_sample, sample[0]); 271 + if (i == 0 && dev->next_sample != sample[0]) { 272 + dev_dbg_ratelimited(dev->dev, 273 + "%d samples lost, %d %08x:%08x\n", 274 + sample[0] - dev->next_sample, 275 + src_len, dev->next_sample, 276 + sample[0]); 273 277 } 274 278 275 279 /* 276 280 * Dump all unknown 'garbage' data - maybe we will discover 277 281 * someday if there is something rational... 278 282 */ 279 - dev_dbg_ratelimited(s->dev, "%*ph\n", 12, &src[4]); 283 + dev_dbg_ratelimited(dev->dev, "%*ph\n", 12, &src[4]); 280 284 281 285 src += 16; /* skip header */ 282 286 283 - switch (s->pixelformat) { 287 + switch (dev->pixelformat) { 284 288 case V4L2_SDR_FMT_CU8: /* 504 x IQ samples */ 285 289 { 286 - s8 *s8src = (s8 *) src; 287 - u8 *u8dst = (u8 *) dst; 290 + s8 *s8src = (s8 *)src; 291 + u8 *u8dst = (u8 *)dst; 288 292 289 293 for (j = 0; j < 1008; j++) 290 294 *u8dst++ = *s8src++ + 128; ··· 293 295 src += 1008; 294 296 dst += 1008; 295 297 dst_len += 1008; 296 - s->next_sample = sample[i] + 504; 298 + dev->next_sample = sample[i] + 504; 297 299 break; 298 300 } 299 301 case V4L2_SDR_FMT_CU16LE: /* 252 x IQ samples */ 300 302 { 301 - s16 *s16src = (s16 *) src; 302 - u16 *u16dst = (u16 *) dst; 303 + s16 *s16src = (s16 *)src; 304 + u16 *u16dst = (u16 *)dst; 303 305 struct {signed int x:14; } se; /* sign extension */ 304 306 unsigned int utmp; 305 307 ··· 315 317 src += 1008; 316 318 dst += 1008; 317 319 dst_len += 1008; 318 - s->next_sample = sample[i] + 252; 320 + dev->next_sample = sample[i] + 252; 319 321 break; 320 322 } 321 323 case MSI2500_PIX_FMT_SDR_MSI2500_384: /* 384 x IQ samples */ 322 324 /* Dump unknown 'garbage' data */ 323 - dev_dbg_ratelimited(s->dev, "%*ph\n", 24, &src[1000]); 325 + dev_dbg_ratelimited(dev->dev, "%*ph\n", 24, &src[1000]); 324 326 memcpy(dst, src, 984); 325 327 src += 984 + 24; 326 328 dst += 984; 327 329 dst_len += 984; 328 - s->next_sample = sample[i] + 384; 330 + dev->next_sample = sample[i] + 384; 329 331 break; 330 332 case V4L2_SDR_FMT_CS8: /* 504 x IQ samples */ 331 333 memcpy(dst, src, 1008); 332 334 src += 1008; 333 335 dst += 1008; 334 336 dst_len += 1008; 335 - s->next_sample = sample[i] + 504; 337 + dev->next_sample = sample[i] + 504; 336 338 break; 337 339 case MSI2500_PIX_FMT_SDR_S12: /* 336 x IQ samples */ 338 340 memcpy(dst, src, 1008); 339 341 src += 1008; 340 342 dst += 1008; 341 343 dst_len += 1008; 342 - s->next_sample = sample[i] + 336; 344 + dev->next_sample = sample[i] + 336; 343 345 break; 344 346 case V4L2_SDR_FMT_CS14LE: /* 252 x IQ samples */ 345 347 memcpy(dst, src, 1008); 346 348 src += 1008; 347 349 dst += 1008; 348 350 dst_len += 1008; 349 - s->next_sample = sample[i] + 252; 351 + dev->next_sample = sample[i] + 252; 350 352 break; 351 353 default: 352 354 break; ··· 354 356 } 355 357 356 358 /* calculate sample rate and output it in 10 seconds intervals */ 357 - if (unlikely(time_is_before_jiffies(s->jiffies_next))) { 359 + if (unlikely(time_is_before_jiffies(dev->jiffies_next))) { 358 360 #define MSECS 10000UL 359 361 unsigned int msecs = jiffies_to_msecs(jiffies - 360 - s->jiffies_next + msecs_to_jiffies(MSECS)); 361 - unsigned int samples = s->next_sample - s->sample; 362 + dev->jiffies_next + msecs_to_jiffies(MSECS)); 363 + unsigned int samples = dev->next_sample - dev->sample; 362 364 363 - s->jiffies_next = jiffies + msecs_to_jiffies(MSECS); 364 - s->sample = s->next_sample; 365 - dev_dbg(s->dev, "size=%u samples=%u msecs=%u sample rate=%lu\n", 366 - src_len, samples, msecs, 367 - samples * 1000UL / msecs); 365 + dev->jiffies_next = jiffies + msecs_to_jiffies(MSECS); 366 + dev->sample = dev->next_sample; 367 + dev_dbg(dev->dev, "size=%u samples=%u msecs=%u sample rate=%lu\n", 368 + src_len, samples, msecs, 369 + samples * 1000UL / msecs); 368 370 } 369 371 370 372 return dst_len; ··· 376 378 */ 377 379 static void msi2500_isoc_handler(struct urb *urb) 378 380 { 379 - struct msi2500_state *s = (struct msi2500_state *)urb->context; 381 + struct msi2500_dev *dev = (struct msi2500_dev *)urb->context; 380 382 int i, flen, fstatus; 381 383 unsigned char *iso_buf = NULL; 382 384 struct msi2500_frame_buf *fbuf; 383 385 384 - if (unlikely(urb->status == -ENOENT || urb->status == -ECONNRESET || 385 - urb->status == -ESHUTDOWN)) { 386 - dev_dbg(s->dev, "URB (%p) unlinked %ssynchronuously\n", 387 - urb, urb->status == -ENOENT ? "" : "a"); 386 + if (unlikely(urb->status == -ENOENT || 387 + urb->status == -ECONNRESET || 388 + urb->status == -ESHUTDOWN)) { 389 + dev_dbg(dev->dev, "URB (%p) unlinked %ssynchronuously\n", 390 + urb, urb->status == -ENOENT ? "" : "a"); 388 391 return; 389 392 } 390 393 391 394 if (unlikely(urb->status != 0)) { 392 - dev_dbg(s->dev, "called with status %d\n", urb->status); 395 + dev_dbg(dev->dev, "called with status %d\n", urb->status); 393 396 /* Give up after a number of contiguous errors */ 394 - if (++s->isoc_errors > MAX_ISOC_ERRORS) 395 - dev_dbg(s->dev, "Too many ISOC errors, bailing out\n"); 397 + if (++dev->isoc_errors > MAX_ISOC_ERRORS) 398 + dev_dbg(dev->dev, "Too many ISOC errors, bailing out\n"); 396 399 goto handler_end; 397 400 } else { 398 401 /* Reset ISOC error counter. We did get here, after all. */ 399 - s->isoc_errors = 0; 402 + dev->isoc_errors = 0; 400 403 } 401 404 402 405 /* Compact data */ ··· 407 408 /* Check frame error */ 408 409 fstatus = urb->iso_frame_desc[i].status; 409 410 if (unlikely(fstatus)) { 410 - dev_dbg_ratelimited(s->dev, 411 - "frame=%d/%d has error %d skipping\n", 412 - i, urb->number_of_packets, fstatus); 411 + dev_dbg_ratelimited(dev->dev, 412 + "frame=%d/%d has error %d skipping\n", 413 + i, urb->number_of_packets, fstatus); 413 414 continue; 414 415 } 415 416 ··· 421 422 iso_buf = urb->transfer_buffer + urb->iso_frame_desc[i].offset; 422 423 423 424 /* Get free framebuffer */ 424 - fbuf = msi2500_get_next_fill_buf(s); 425 + fbuf = msi2500_get_next_fill_buf(dev); 425 426 if (unlikely(fbuf == NULL)) { 426 - s->vb_full++; 427 - dev_dbg_ratelimited(s->dev, 428 - "videobuf is full, %d packets dropped\n", 429 - s->vb_full); 427 + dev->vb_full++; 428 + dev_dbg_ratelimited(dev->dev, 429 + "videobuf is full, %d packets dropped\n", 430 + dev->vb_full); 430 431 continue; 431 432 } 432 433 433 434 /* fill framebuffer */ 434 435 ptr = vb2_plane_vaddr(&fbuf->vb, 0); 435 - flen = msi2500_convert_stream(s, ptr, iso_buf, flen); 436 + flen = msi2500_convert_stream(dev, ptr, iso_buf, flen); 436 437 vb2_set_plane_payload(&fbuf->vb, 0, flen); 437 438 vb2_buffer_done(&fbuf->vb, VB2_BUF_STATE_DONE); 438 439 } ··· 440 441 handler_end: 441 442 i = usb_submit_urb(urb, GFP_ATOMIC); 442 443 if (unlikely(i != 0)) 443 - dev_dbg(s->dev, "Error (%d) re-submitting urb\n", i); 444 + dev_dbg(dev->dev, "Error (%d) re-submitting urb\n", i); 444 445 } 445 446 446 - static void msi2500_iso_stop(struct msi2500_state *s) 447 + static void msi2500_iso_stop(struct msi2500_dev *dev) 447 448 { 448 449 int i; 449 450 450 - dev_dbg(s->dev, "\n"); 451 + dev_dbg(dev->dev, "\n"); 451 452 452 453 /* Unlinking ISOC buffers one by one */ 453 454 for (i = 0; i < MAX_ISO_BUFS; i++) { 454 - if (s->urbs[i]) { 455 - dev_dbg(s->dev, "Unlinking URB %p\n", s->urbs[i]); 456 - usb_kill_urb(s->urbs[i]); 455 + if (dev->urbs[i]) { 456 + dev_dbg(dev->dev, "Unlinking URB %p\n", dev->urbs[i]); 457 + usb_kill_urb(dev->urbs[i]); 457 458 } 458 459 } 459 460 } 460 461 461 - static void msi2500_iso_free(struct msi2500_state *s) 462 + static void msi2500_iso_free(struct msi2500_dev *dev) 462 463 { 463 464 int i; 464 465 465 - dev_dbg(s->dev, "\n"); 466 + dev_dbg(dev->dev, "\n"); 466 467 467 468 /* Freeing ISOC buffers one by one */ 468 469 for (i = 0; i < MAX_ISO_BUFS; i++) { 469 - if (s->urbs[i]) { 470 - dev_dbg(s->dev, "Freeing URB\n"); 471 - if (s->urbs[i]->transfer_buffer) { 472 - usb_free_coherent(s->udev, 473 - s->urbs[i]->transfer_buffer_length, 474 - s->urbs[i]->transfer_buffer, 475 - s->urbs[i]->transfer_dma); 470 + if (dev->urbs[i]) { 471 + dev_dbg(dev->dev, "Freeing URB\n"); 472 + if (dev->urbs[i]->transfer_buffer) { 473 + usb_free_coherent(dev->udev, 474 + dev->urbs[i]->transfer_buffer_length, 475 + dev->urbs[i]->transfer_buffer, 476 + dev->urbs[i]->transfer_dma); 476 477 } 477 - usb_free_urb(s->urbs[i]); 478 - s->urbs[i] = NULL; 478 + usb_free_urb(dev->urbs[i]); 479 + dev->urbs[i] = NULL; 479 480 } 480 481 } 481 482 } 482 483 483 484 /* Both v4l2_lock and vb_queue_lock should be locked when calling this */ 484 - static void msi2500_isoc_cleanup(struct msi2500_state *s) 485 + static void msi2500_isoc_cleanup(struct msi2500_dev *dev) 485 486 { 486 - dev_dbg(s->dev, "\n"); 487 + dev_dbg(dev->dev, "\n"); 487 488 488 - msi2500_iso_stop(s); 489 - msi2500_iso_free(s); 489 + msi2500_iso_stop(dev); 490 + msi2500_iso_free(dev); 490 491 } 491 492 492 493 /* Both v4l2_lock and vb_queue_lock should be locked when calling this */ 493 - static int msi2500_isoc_init(struct msi2500_state *s) 494 + static int msi2500_isoc_init(struct msi2500_dev *dev) 494 495 { 495 496 struct urb *urb; 496 497 int i, j, ret; 497 498 498 - dev_dbg(s->dev, "\n"); 499 + dev_dbg(dev->dev, "\n"); 499 500 500 - s->isoc_errors = 0; 501 + dev->isoc_errors = 0; 501 502 502 - ret = usb_set_interface(s->udev, 0, 1); 503 + ret = usb_set_interface(dev->udev, 0, 1); 503 504 if (ret) 504 505 return ret; 505 506 ··· 507 508 for (i = 0; i < MAX_ISO_BUFS; i++) { 508 509 urb = usb_alloc_urb(ISO_FRAMES_PER_DESC, GFP_KERNEL); 509 510 if (urb == NULL) { 510 - dev_err(s->dev, "Failed to allocate urb %d\n", i); 511 - msi2500_isoc_cleanup(s); 511 + dev_err(dev->dev, "Failed to allocate urb %d\n", i); 512 + msi2500_isoc_cleanup(dev); 512 513 return -ENOMEM; 513 514 } 514 - s->urbs[i] = urb; 515 - dev_dbg(s->dev, "Allocated URB at 0x%p\n", urb); 515 + dev->urbs[i] = urb; 516 + dev_dbg(dev->dev, "Allocated URB at 0x%p\n", urb); 516 517 517 518 urb->interval = 1; 518 - urb->dev = s->udev; 519 - urb->pipe = usb_rcvisocpipe(s->udev, 0x81); 519 + urb->dev = dev->udev; 520 + urb->pipe = usb_rcvisocpipe(dev->udev, 0x81); 520 521 urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP; 521 - urb->transfer_buffer = usb_alloc_coherent(s->udev, 522 + urb->transfer_buffer = usb_alloc_coherent(dev->udev, 522 523 ISO_BUFFER_SIZE, 523 524 GFP_KERNEL, &urb->transfer_dma); 524 525 if (urb->transfer_buffer == NULL) { 525 - dev_err(s->dev, "Failed to allocate urb buffer %d\n", 526 - i); 527 - msi2500_isoc_cleanup(s); 526 + dev_err(dev->dev, 527 + "Failed to allocate urb buffer %d\n", i); 528 + msi2500_isoc_cleanup(dev); 528 529 return -ENOMEM; 529 530 } 530 531 urb->transfer_buffer_length = ISO_BUFFER_SIZE; 531 532 urb->complete = msi2500_isoc_handler; 532 - urb->context = s; 533 + urb->context = dev; 533 534 urb->start_frame = 0; 534 535 urb->number_of_packets = ISO_FRAMES_PER_DESC; 535 536 for (j = 0; j < ISO_FRAMES_PER_DESC; j++) { ··· 540 541 541 542 /* link */ 542 543 for (i = 0; i < MAX_ISO_BUFS; i++) { 543 - ret = usb_submit_urb(s->urbs[i], GFP_KERNEL); 544 + ret = usb_submit_urb(dev->urbs[i], GFP_KERNEL); 544 545 if (ret) { 545 - dev_err(s->dev, "usb_submit_urb %d failed with error %d\n", 546 - i, ret); 547 - msi2500_isoc_cleanup(s); 546 + dev_err(dev->dev, 547 + "usb_submit_urb %d failed with error %d\n", 548 + i, ret); 549 + msi2500_isoc_cleanup(dev); 548 550 return ret; 549 551 } 550 - dev_dbg(s->dev, "URB 0x%p submitted.\n", s->urbs[i]); 552 + dev_dbg(dev->dev, "URB 0x%p submitted.\n", dev->urbs[i]); 551 553 } 552 554 553 555 /* All is done... */ ··· 556 556 } 557 557 558 558 /* Must be called with vb_queue_lock hold */ 559 - static void msi2500_cleanup_queued_bufs(struct msi2500_state *s) 559 + static void msi2500_cleanup_queued_bufs(struct msi2500_dev *dev) 560 560 { 561 561 unsigned long flags; 562 562 563 - dev_dbg(s->dev, "\n"); 563 + dev_dbg(dev->dev, "\n"); 564 564 565 - spin_lock_irqsave(&s->queued_bufs_lock, flags); 566 - while (!list_empty(&s->queued_bufs)) { 565 + spin_lock_irqsave(&dev->queued_bufs_lock, flags); 566 + while (!list_empty(&dev->queued_bufs)) { 567 567 struct msi2500_frame_buf *buf; 568 568 569 - buf = list_entry(s->queued_bufs.next, struct msi2500_frame_buf, 570 - list); 569 + buf = list_entry(dev->queued_bufs.next, 570 + struct msi2500_frame_buf, list); 571 571 list_del(&buf->list); 572 572 vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR); 573 573 } 574 - spin_unlock_irqrestore(&s->queued_bufs_lock, flags); 574 + spin_unlock_irqrestore(&dev->queued_bufs_lock, flags); 575 575 } 576 576 577 577 /* The user yanked out the cable... */ 578 578 static void msi2500_disconnect(struct usb_interface *intf) 579 579 { 580 580 struct v4l2_device *v = usb_get_intfdata(intf); 581 - struct msi2500_state *s = 582 - container_of(v, struct msi2500_state, v4l2_dev); 581 + struct msi2500_dev *dev = 582 + container_of(v, struct msi2500_dev, v4l2_dev); 583 583 584 - dev_dbg(s->dev, "\n"); 584 + dev_dbg(dev->dev, "\n"); 585 585 586 - mutex_lock(&s->vb_queue_lock); 587 - mutex_lock(&s->v4l2_lock); 586 + mutex_lock(&dev->vb_queue_lock); 587 + mutex_lock(&dev->v4l2_lock); 588 588 /* No need to keep the urbs around after disconnection */ 589 - s->udev = NULL; 590 - v4l2_device_disconnect(&s->v4l2_dev); 591 - video_unregister_device(&s->vdev); 592 - spi_unregister_master(s->master); 593 - mutex_unlock(&s->v4l2_lock); 594 - mutex_unlock(&s->vb_queue_lock); 589 + dev->udev = NULL; 590 + v4l2_device_disconnect(&dev->v4l2_dev); 591 + video_unregister_device(&dev->vdev); 592 + spi_unregister_master(dev->master); 593 + mutex_unlock(&dev->v4l2_lock); 594 + mutex_unlock(&dev->vb_queue_lock); 595 595 596 - v4l2_device_put(&s->v4l2_dev); 596 + v4l2_device_put(&dev->v4l2_dev); 597 597 } 598 598 599 599 static int msi2500_querycap(struct file *file, void *fh, 600 - struct v4l2_capability *cap) 600 + struct v4l2_capability *cap) 601 601 { 602 - struct msi2500_state *s = video_drvdata(file); 602 + struct msi2500_dev *dev = video_drvdata(file); 603 603 604 - dev_dbg(s->dev, "\n"); 604 + dev_dbg(dev->dev, "\n"); 605 605 606 606 strlcpy(cap->driver, KBUILD_MODNAME, sizeof(cap->driver)); 607 - strlcpy(cap->card, s->vdev.name, sizeof(cap->card)); 608 - usb_make_path(s->udev, cap->bus_info, sizeof(cap->bus_info)); 607 + strlcpy(cap->card, dev->vdev.name, sizeof(cap->card)); 608 + usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info)); 609 609 cap->device_caps = V4L2_CAP_SDR_CAPTURE | V4L2_CAP_STREAMING | 610 610 V4L2_CAP_READWRITE | V4L2_CAP_TUNER; 611 611 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS; ··· 614 614 615 615 /* Videobuf2 operations */ 616 616 static int msi2500_queue_setup(struct vb2_queue *vq, 617 - const struct v4l2_format *fmt, unsigned int *nbuffers, 618 - unsigned int *nplanes, unsigned int sizes[], void *alloc_ctxs[]) 617 + const struct v4l2_format *fmt, 618 + unsigned int *nbuffers, 619 + unsigned int *nplanes, unsigned int sizes[], 620 + void *alloc_ctxs[]) 619 621 { 620 - struct msi2500_state *s = vb2_get_drv_priv(vq); 622 + struct msi2500_dev *dev = vb2_get_drv_priv(vq); 621 623 622 - dev_dbg(s->dev, "nbuffers=%d\n", *nbuffers); 624 + dev_dbg(dev->dev, "nbuffers=%d\n", *nbuffers); 623 625 624 626 /* Absolute min and max number of buffers available for mmap() */ 625 627 *nbuffers = clamp_t(unsigned int, *nbuffers, 8, 32); 626 628 *nplanes = 1; 627 - sizes[0] = PAGE_ALIGN(s->buffersize); 628 - dev_dbg(s->dev, "nbuffers=%d sizes[0]=%d\n", *nbuffers, sizes[0]); 629 + sizes[0] = PAGE_ALIGN(dev->buffersize); 630 + dev_dbg(dev->dev, "nbuffers=%d sizes[0]=%d\n", *nbuffers, sizes[0]); 629 631 return 0; 630 632 } 631 633 632 634 static void msi2500_buf_queue(struct vb2_buffer *vb) 633 635 { 634 - struct msi2500_state *s = vb2_get_drv_priv(vb->vb2_queue); 635 - struct msi2500_frame_buf *buf = 636 - container_of(vb, struct msi2500_frame_buf, vb); 636 + struct msi2500_dev *dev = vb2_get_drv_priv(vb->vb2_queue); 637 + struct msi2500_frame_buf *buf = container_of(vb, 638 + struct msi2500_frame_buf, 639 + vb); 637 640 unsigned long flags; 638 641 639 642 /* Check the device has not disconnected between prep and queuing */ 640 - if (unlikely(!s->udev)) { 643 + if (unlikely(!dev->udev)) { 641 644 vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR); 642 645 return; 643 646 } 644 647 645 - spin_lock_irqsave(&s->queued_bufs_lock, flags); 646 - list_add_tail(&buf->list, &s->queued_bufs); 647 - spin_unlock_irqrestore(&s->queued_bufs_lock, flags); 648 + spin_lock_irqsave(&dev->queued_bufs_lock, flags); 649 + list_add_tail(&buf->list, &dev->queued_bufs); 650 + spin_unlock_irqrestore(&dev->queued_bufs_lock, flags); 648 651 } 649 652 650 653 #define CMD_WREG 0x41 651 654 #define CMD_START_STREAMING 0x43 652 655 #define CMD_STOP_STREAMING 0x45 653 - #define CMD_READ_UNKNOW 0x48 656 + #define CMD_READ_UNKNOWN 0x48 654 657 655 658 #define msi2500_dbg_usb_control_msg(_dev, _r, _t, _v, _i, _b, _l) { \ 656 659 char *_direction; \ ··· 666 663 _l & 0xff, _l >> 8, _direction, _l, _b); \ 667 664 } 668 665 669 - static int msi2500_ctrl_msg(struct msi2500_state *s, u8 cmd, u32 data) 666 + static int msi2500_ctrl_msg(struct msi2500_dev *dev, u8 cmd, u32 data) 670 667 { 671 668 int ret; 672 669 u8 request = cmd; ··· 674 671 u16 value = (data >> 0) & 0xffff; 675 672 u16 index = (data >> 16) & 0xffff; 676 673 677 - msi2500_dbg_usb_control_msg(s->dev, 678 - request, requesttype, value, index, NULL, 0); 679 - ret = usb_control_msg(s->udev, usb_sndctrlpipe(s->udev, 0), 680 - request, requesttype, value, index, NULL, 0, 2000); 674 + msi2500_dbg_usb_control_msg(dev->dev, request, requesttype, 675 + value, index, NULL, 0); 676 + ret = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0), request, 677 + requesttype, value, index, NULL, 0, 2000); 681 678 if (ret) 682 - dev_err(s->dev, "failed %d, cmd %02x, data %04x\n", 683 - ret, cmd, data); 679 + dev_err(dev->dev, "failed %d, cmd %02x, data %04x\n", 680 + ret, cmd, data); 684 681 685 682 return ret; 686 683 } 687 684 688 - static int msi2500_set_usb_adc(struct msi2500_state *s) 685 + static int msi2500_set_usb_adc(struct msi2500_dev *dev) 689 686 { 690 687 int ret; 691 688 unsigned int f_vco, f_sr, div_n, k, k_cw, div_out; ··· 693 690 struct v4l2_ctrl *bandwidth_auto; 694 691 struct v4l2_ctrl *bandwidth; 695 692 696 - f_sr = s->f_adc; 693 + f_sr = dev->f_adc; 697 694 698 695 /* set tuner, subdev, filters according to sampling rate */ 699 - bandwidth_auto = v4l2_ctrl_find(&s->hdl, 696 + bandwidth_auto = v4l2_ctrl_find(&dev->hdl, 700 697 V4L2_CID_RF_TUNER_BANDWIDTH_AUTO); 701 698 if (v4l2_ctrl_g_ctrl(bandwidth_auto)) { 702 - bandwidth = v4l2_ctrl_find(&s->hdl, 699 + bandwidth = v4l2_ctrl_find(&dev->hdl, 703 700 V4L2_CID_RF_TUNER_BANDWIDTH); 704 - v4l2_ctrl_s_ctrl(bandwidth, s->f_adc); 701 + v4l2_ctrl_s_ctrl(bandwidth, dev->f_adc); 705 702 } 706 703 707 704 /* select stream format */ 708 - switch (s->pixelformat) { 705 + switch (dev->pixelformat) { 709 706 case V4L2_SDR_FMT_CU8: 710 707 reg7 = 0x000c9407; /* 504 */ 711 708 break; ··· 790 787 791 788 for (div_out = 4; div_out < 16; div_out += 2) { 792 789 f_vco = f_sr * div_out * DIV_LO_OUT; 793 - dev_dbg(s->dev, "div_out=%d f_vco=%d\n", div_out, f_vco); 790 + dev_dbg(dev->dev, "div_out=%u f_vco=%u\n", div_out, f_vco); 794 791 if (f_vco >= 202000000) 795 792 break; 796 793 } ··· 804 801 reg3 |= ((k_cw >> 20) & 0x000001) << 15; /* [20] */ 805 802 reg4 |= ((k_cw >> 0) & 0x0fffff) << 8; /* [19:0] */ 806 803 807 - dev_dbg(s->dev, 804 + dev_dbg(dev->dev, 808 805 "f_sr=%u f_vco=%u div_n=%u k=%u div_out=%u reg3=%08x reg4=%08x\n", 809 806 f_sr, f_vco, div_n, k, div_out, reg3, reg4); 810 807 811 - ret = msi2500_ctrl_msg(s, CMD_WREG, 0x00608008); 808 + ret = msi2500_ctrl_msg(dev, CMD_WREG, 0x00608008); 812 809 if (ret) 813 810 goto err; 814 811 815 - ret = msi2500_ctrl_msg(s, CMD_WREG, 0x00000c05); 812 + ret = msi2500_ctrl_msg(dev, CMD_WREG, 0x00000c05); 816 813 if (ret) 817 814 goto err; 818 815 819 - ret = msi2500_ctrl_msg(s, CMD_WREG, 0x00020000); 816 + ret = msi2500_ctrl_msg(dev, CMD_WREG, 0x00020000); 820 817 if (ret) 821 818 goto err; 822 819 823 - ret = msi2500_ctrl_msg(s, CMD_WREG, 0x00480102); 820 + ret = msi2500_ctrl_msg(dev, CMD_WREG, 0x00480102); 824 821 if (ret) 825 822 goto err; 826 823 827 - ret = msi2500_ctrl_msg(s, CMD_WREG, 0x00f38008); 824 + ret = msi2500_ctrl_msg(dev, CMD_WREG, 0x00f38008); 828 825 if (ret) 829 826 goto err; 830 827 831 - ret = msi2500_ctrl_msg(s, CMD_WREG, reg7); 828 + ret = msi2500_ctrl_msg(dev, CMD_WREG, reg7); 832 829 if (ret) 833 830 goto err; 834 831 835 - ret = msi2500_ctrl_msg(s, CMD_WREG, reg4); 832 + ret = msi2500_ctrl_msg(dev, CMD_WREG, reg4); 836 833 if (ret) 837 834 goto err; 838 835 839 - ret = msi2500_ctrl_msg(s, CMD_WREG, reg3); 836 + ret = msi2500_ctrl_msg(dev, CMD_WREG, reg3); 840 837 if (ret) 841 838 goto err; 842 839 err: ··· 845 842 846 843 static int msi2500_start_streaming(struct vb2_queue *vq, unsigned int count) 847 844 { 848 - struct msi2500_state *s = vb2_get_drv_priv(vq); 845 + struct msi2500_dev *dev = vb2_get_drv_priv(vq); 849 846 int ret; 850 847 851 - dev_dbg(s->dev, "\n"); 848 + dev_dbg(dev->dev, "\n"); 852 849 853 - if (!s->udev) 850 + if (!dev->udev) 854 851 return -ENODEV; 855 852 856 - if (mutex_lock_interruptible(&s->v4l2_lock)) 853 + if (mutex_lock_interruptible(&dev->v4l2_lock)) 857 854 return -ERESTARTSYS; 858 855 859 856 /* wake-up tuner */ 860 - v4l2_subdev_call(s->v4l2_subdev, core, s_power, 1); 857 + v4l2_subdev_call(dev->v4l2_subdev, core, s_power, 1); 861 858 862 - ret = msi2500_set_usb_adc(s); 859 + ret = msi2500_set_usb_adc(dev); 863 860 864 - ret = msi2500_isoc_init(s); 861 + ret = msi2500_isoc_init(dev); 865 862 if (ret) 866 - msi2500_cleanup_queued_bufs(s); 863 + msi2500_cleanup_queued_bufs(dev); 867 864 868 - ret = msi2500_ctrl_msg(s, CMD_START_STREAMING, 0); 865 + ret = msi2500_ctrl_msg(dev, CMD_START_STREAMING, 0); 869 866 870 - mutex_unlock(&s->v4l2_lock); 867 + mutex_unlock(&dev->v4l2_lock); 871 868 872 869 return ret; 873 870 } 874 871 875 872 static void msi2500_stop_streaming(struct vb2_queue *vq) 876 873 { 877 - struct msi2500_state *s = vb2_get_drv_priv(vq); 874 + struct msi2500_dev *dev = vb2_get_drv_priv(vq); 878 875 879 - dev_dbg(s->dev, "\n"); 876 + dev_dbg(dev->dev, "\n"); 880 877 881 - mutex_lock(&s->v4l2_lock); 878 + mutex_lock(&dev->v4l2_lock); 882 879 883 - if (s->udev) 884 - msi2500_isoc_cleanup(s); 880 + if (dev->udev) 881 + msi2500_isoc_cleanup(dev); 885 882 886 - msi2500_cleanup_queued_bufs(s); 883 + msi2500_cleanup_queued_bufs(dev); 887 884 888 885 /* according to tests, at least 700us delay is required */ 889 886 msleep(20); 890 - if (!msi2500_ctrl_msg(s, CMD_STOP_STREAMING, 0)) { 887 + if (!msi2500_ctrl_msg(dev, CMD_STOP_STREAMING, 0)) { 891 888 /* sleep USB IF / ADC */ 892 - msi2500_ctrl_msg(s, CMD_WREG, 0x01000003); 889 + msi2500_ctrl_msg(dev, CMD_WREG, 0x01000003); 893 890 } 894 891 895 892 /* sleep tuner */ 896 - v4l2_subdev_call(s->v4l2_subdev, core, s_power, 0); 893 + v4l2_subdev_call(dev->v4l2_subdev, core, s_power, 0); 897 894 898 - mutex_unlock(&s->v4l2_lock); 895 + mutex_unlock(&dev->v4l2_lock); 899 896 } 900 897 901 898 static struct vb2_ops msi2500_vb2_ops = { ··· 908 905 }; 909 906 910 907 static int msi2500_enum_fmt_sdr_cap(struct file *file, void *priv, 911 - struct v4l2_fmtdesc *f) 908 + struct v4l2_fmtdesc *f) 912 909 { 913 - struct msi2500_state *s = video_drvdata(file); 910 + struct msi2500_dev *dev = video_drvdata(file); 914 911 915 - dev_dbg(s->dev, "index=%d\n", f->index); 912 + dev_dbg(dev->dev, "index=%d\n", f->index); 916 913 917 - if (f->index >= s->num_formats) 914 + if (f->index >= dev->num_formats) 918 915 return -EINVAL; 919 916 920 917 strlcpy(f->description, formats[f->index].name, sizeof(f->description)); ··· 924 921 } 925 922 926 923 static int msi2500_g_fmt_sdr_cap(struct file *file, void *priv, 927 - struct v4l2_format *f) 924 + struct v4l2_format *f) 928 925 { 929 - struct msi2500_state *s = video_drvdata(file); 926 + struct msi2500_dev *dev = video_drvdata(file); 930 927 931 - dev_dbg(s->dev, "pixelformat fourcc %4.4s\n", 932 - (char *)&s->pixelformat); 928 + dev_dbg(dev->dev, "pixelformat fourcc %4.4s\n", 929 + (char *)&dev->pixelformat); 933 930 934 - f->fmt.sdr.pixelformat = s->pixelformat; 935 - f->fmt.sdr.buffersize = s->buffersize; 931 + f->fmt.sdr.pixelformat = dev->pixelformat; 932 + f->fmt.sdr.buffersize = dev->buffersize; 936 933 memset(f->fmt.sdr.reserved, 0, sizeof(f->fmt.sdr.reserved)); 937 934 938 935 return 0; 939 936 } 940 937 941 938 static int msi2500_s_fmt_sdr_cap(struct file *file, void *priv, 942 - struct v4l2_format *f) 939 + struct v4l2_format *f) 943 940 { 944 - struct msi2500_state *s = video_drvdata(file); 945 - struct vb2_queue *q = &s->vb_queue; 941 + struct msi2500_dev *dev = video_drvdata(file); 942 + struct vb2_queue *q = &dev->vb_queue; 946 943 int i; 947 944 948 - dev_dbg(s->dev, "pixelformat fourcc %4.4s\n", 949 - (char *)&f->fmt.sdr.pixelformat); 945 + dev_dbg(dev->dev, "pixelformat fourcc %4.4s\n", 946 + (char *)&f->fmt.sdr.pixelformat); 950 947 951 948 if (vb2_is_busy(q)) 952 949 return -EBUSY; 953 950 954 951 memset(f->fmt.sdr.reserved, 0, sizeof(f->fmt.sdr.reserved)); 955 - for (i = 0; i < s->num_formats; i++) { 952 + for (i = 0; i < dev->num_formats; i++) { 956 953 if (formats[i].pixelformat == f->fmt.sdr.pixelformat) { 957 - s->pixelformat = formats[i].pixelformat; 958 - s->buffersize = formats[i].buffersize; 954 + dev->pixelformat = formats[i].pixelformat; 955 + dev->buffersize = formats[i].buffersize; 959 956 f->fmt.sdr.buffersize = formats[i].buffersize; 960 957 return 0; 961 958 } 962 959 } 963 960 964 - s->pixelformat = formats[0].pixelformat; 965 - s->buffersize = formats[0].buffersize; 961 + dev->pixelformat = formats[0].pixelformat; 962 + dev->buffersize = formats[0].buffersize; 966 963 f->fmt.sdr.pixelformat = formats[0].pixelformat; 967 964 f->fmt.sdr.buffersize = formats[0].buffersize; 968 965 ··· 970 967 } 971 968 972 969 static int msi2500_try_fmt_sdr_cap(struct file *file, void *priv, 973 - struct v4l2_format *f) 970 + struct v4l2_format *f) 974 971 { 975 - struct msi2500_state *s = video_drvdata(file); 972 + struct msi2500_dev *dev = video_drvdata(file); 976 973 int i; 977 974 978 - dev_dbg(s->dev, "pixelformat fourcc %4.4s\n", 979 - (char *)&f->fmt.sdr.pixelformat); 975 + dev_dbg(dev->dev, "pixelformat fourcc %4.4s\n", 976 + (char *)&f->fmt.sdr.pixelformat); 980 977 981 978 memset(f->fmt.sdr.reserved, 0, sizeof(f->fmt.sdr.reserved)); 982 - for (i = 0; i < s->num_formats; i++) { 979 + for (i = 0; i < dev->num_formats; i++) { 983 980 if (formats[i].pixelformat == f->fmt.sdr.pixelformat) { 984 981 f->fmt.sdr.buffersize = formats[i].buffersize; 985 982 return 0; ··· 993 990 } 994 991 995 992 static int msi2500_s_tuner(struct file *file, void *priv, 996 - const struct v4l2_tuner *v) 993 + const struct v4l2_tuner *v) 997 994 { 998 - struct msi2500_state *s = video_drvdata(file); 995 + struct msi2500_dev *dev = video_drvdata(file); 999 996 int ret; 1000 997 1001 - dev_dbg(s->dev, "index=%d\n", v->index); 998 + dev_dbg(dev->dev, "index=%d\n", v->index); 1002 999 1003 1000 if (v->index == 0) 1004 1001 ret = 0; 1005 1002 else if (v->index == 1) 1006 - ret = v4l2_subdev_call(s->v4l2_subdev, tuner, s_tuner, v); 1003 + ret = v4l2_subdev_call(dev->v4l2_subdev, tuner, s_tuner, v); 1007 1004 else 1008 1005 ret = -EINVAL; 1009 1006 ··· 1012 1009 1013 1010 static int msi2500_g_tuner(struct file *file, void *priv, struct v4l2_tuner *v) 1014 1011 { 1015 - struct msi2500_state *s = video_drvdata(file); 1012 + struct msi2500_dev *dev = video_drvdata(file); 1016 1013 int ret; 1017 1014 1018 - dev_dbg(s->dev, "index=%d\n", v->index); 1015 + dev_dbg(dev->dev, "index=%d\n", v->index); 1019 1016 1020 1017 if (v->index == 0) { 1021 1018 strlcpy(v->name, "Mirics MSi2500", sizeof(v->name)); ··· 1025 1022 v->rangehigh = 15000000; 1026 1023 ret = 0; 1027 1024 } else if (v->index == 1) { 1028 - ret = v4l2_subdev_call(s->v4l2_subdev, tuner, g_tuner, v); 1025 + ret = v4l2_subdev_call(dev->v4l2_subdev, tuner, g_tuner, v); 1029 1026 } else { 1030 1027 ret = -EINVAL; 1031 1028 } ··· 1034 1031 } 1035 1032 1036 1033 static int msi2500_g_frequency(struct file *file, void *priv, 1037 - struct v4l2_frequency *f) 1034 + struct v4l2_frequency *f) 1038 1035 { 1039 - struct msi2500_state *s = video_drvdata(file); 1036 + struct msi2500_dev *dev = video_drvdata(file); 1040 1037 int ret = 0; 1041 1038 1042 - dev_dbg(s->dev, "tuner=%d type=%d\n", f->tuner, f->type); 1039 + dev_dbg(dev->dev, "tuner=%d type=%d\n", f->tuner, f->type); 1043 1040 1044 1041 if (f->tuner == 0) { 1045 - f->frequency = s->f_adc; 1042 + f->frequency = dev->f_adc; 1046 1043 ret = 0; 1047 1044 } else if (f->tuner == 1) { 1048 1045 f->type = V4L2_TUNER_RF; 1049 - ret = v4l2_subdev_call(s->v4l2_subdev, tuner, g_frequency, f); 1046 + ret = v4l2_subdev_call(dev->v4l2_subdev, tuner, g_frequency, f); 1050 1047 } else { 1051 1048 ret = -EINVAL; 1052 1049 } ··· 1055 1052 } 1056 1053 1057 1054 static int msi2500_s_frequency(struct file *file, void *priv, 1058 - const struct v4l2_frequency *f) 1055 + const struct v4l2_frequency *f) 1059 1056 { 1060 - struct msi2500_state *s = video_drvdata(file); 1057 + struct msi2500_dev *dev = video_drvdata(file); 1061 1058 int ret; 1062 1059 1063 - dev_dbg(s->dev, "tuner=%d type=%d frequency=%u\n", 1064 - f->tuner, f->type, f->frequency); 1060 + dev_dbg(dev->dev, "tuner=%d type=%d frequency=%u\n", 1061 + f->tuner, f->type, f->frequency); 1065 1062 1066 1063 if (f->tuner == 0) { 1067 - s->f_adc = clamp_t(unsigned int, f->frequency, 1068 - bands[0].rangelow, 1069 - bands[0].rangehigh); 1070 - dev_dbg(s->dev, "ADC frequency=%u Hz\n", s->f_adc); 1071 - ret = msi2500_set_usb_adc(s); 1064 + dev->f_adc = clamp_t(unsigned int, f->frequency, 1065 + bands[0].rangelow, 1066 + bands[0].rangehigh); 1067 + dev_dbg(dev->dev, "ADC frequency=%u Hz\n", dev->f_adc); 1068 + ret = msi2500_set_usb_adc(dev); 1072 1069 } else if (f->tuner == 1) { 1073 - ret = v4l2_subdev_call(s->v4l2_subdev, tuner, s_frequency, f); 1070 + ret = v4l2_subdev_call(dev->v4l2_subdev, tuner, s_frequency, f); 1074 1071 } else { 1075 1072 ret = -EINVAL; 1076 1073 } ··· 1079 1076 } 1080 1077 1081 1078 static int msi2500_enum_freq_bands(struct file *file, void *priv, 1082 - struct v4l2_frequency_band *band) 1079 + struct v4l2_frequency_band *band) 1083 1080 { 1084 - struct msi2500_state *s = video_drvdata(file); 1081 + struct msi2500_dev *dev = video_drvdata(file); 1085 1082 int ret; 1086 1083 1087 - dev_dbg(s->dev, "tuner=%d type=%d index=%d\n", 1088 - band->tuner, band->type, band->index); 1084 + dev_dbg(dev->dev, "tuner=%d type=%d index=%d\n", 1085 + band->tuner, band->type, band->index); 1089 1086 1090 1087 if (band->tuner == 0) { 1091 1088 if (band->index >= ARRAY_SIZE(bands)) { ··· 1095 1092 ret = 0; 1096 1093 } 1097 1094 } else if (band->tuner == 1) { 1098 - ret = v4l2_subdev_call(s->v4l2_subdev, tuner, 1099 - enum_freq_bands, band); 1095 + ret = v4l2_subdev_call(dev->v4l2_subdev, tuner, 1096 + enum_freq_bands, band); 1100 1097 } else { 1101 1098 ret = -EINVAL; 1102 1099 } ··· 1153 1150 1154 1151 static void msi2500_video_release(struct v4l2_device *v) 1155 1152 { 1156 - struct msi2500_state *s = 1157 - container_of(v, struct msi2500_state, v4l2_dev); 1153 + struct msi2500_dev *dev = container_of(v, struct msi2500_dev, v4l2_dev); 1158 1154 1159 - v4l2_ctrl_handler_free(&s->hdl); 1160 - v4l2_device_unregister(&s->v4l2_dev); 1161 - kfree(s); 1155 + v4l2_ctrl_handler_free(&dev->hdl); 1156 + v4l2_device_unregister(&dev->v4l2_dev); 1157 + kfree(dev); 1162 1158 } 1163 1159 1164 1160 static int msi2500_transfer_one_message(struct spi_master *master, 1165 - struct spi_message *m) 1161 + struct spi_message *m) 1166 1162 { 1167 - struct msi2500_state *s = spi_master_get_devdata(master); 1163 + struct msi2500_dev *dev = spi_master_get_devdata(master); 1168 1164 struct spi_transfer *t; 1169 1165 int ret = 0; 1170 1166 u32 data; 1171 1167 1172 1168 list_for_each_entry(t, &m->transfers, transfer_list) { 1173 - dev_dbg(s->dev, "msg=%*ph\n", t->len, t->tx_buf); 1169 + dev_dbg(dev->dev, "msg=%*ph\n", t->len, t->tx_buf); 1174 1170 data = 0x09; /* reg 9 is SPI adapter */ 1175 1171 data |= ((u8 *)t->tx_buf)[0] << 8; 1176 1172 data |= ((u8 *)t->tx_buf)[1] << 16; 1177 1173 data |= ((u8 *)t->tx_buf)[2] << 24; 1178 - ret = msi2500_ctrl_msg(s, CMD_WREG, data); 1174 + ret = msi2500_ctrl_msg(dev, CMD_WREG, data); 1179 1175 } 1180 1176 1181 1177 m->status = ret; ··· 1183 1181 } 1184 1182 1185 1183 static int msi2500_probe(struct usb_interface *intf, 1186 - const struct usb_device_id *id) 1184 + const struct usb_device_id *id) 1187 1185 { 1188 - struct msi2500_state *s; 1186 + struct msi2500_dev *dev; 1189 1187 struct v4l2_subdev *sd; 1190 1188 struct spi_master *master; 1191 1189 int ret; ··· 1196 1194 .max_speed_hz = 12000000, 1197 1195 }; 1198 1196 1199 - s = kzalloc(sizeof(struct msi2500_state), GFP_KERNEL); 1200 - if (s == NULL) { 1201 - dev_err(&intf->dev, "Could not allocate memory for state\n"); 1202 - return -ENOMEM; 1197 + dev = kzalloc(sizeof(*dev), GFP_KERNEL); 1198 + if (!dev) { 1199 + ret = -ENOMEM; 1200 + goto err; 1203 1201 } 1204 1202 1205 - mutex_init(&s->v4l2_lock); 1206 - mutex_init(&s->vb_queue_lock); 1207 - spin_lock_init(&s->queued_bufs_lock); 1208 - INIT_LIST_HEAD(&s->queued_bufs); 1209 - s->dev = &intf->dev; 1210 - s->udev = interface_to_usbdev(intf); 1211 - s->f_adc = bands[0].rangelow; 1212 - s->pixelformat = formats[0].pixelformat; 1213 - s->buffersize = formats[0].buffersize; 1214 - s->num_formats = NUM_FORMATS; 1203 + mutex_init(&dev->v4l2_lock); 1204 + mutex_init(&dev->vb_queue_lock); 1205 + spin_lock_init(&dev->queued_bufs_lock); 1206 + INIT_LIST_HEAD(&dev->queued_bufs); 1207 + dev->dev = &intf->dev; 1208 + dev->udev = interface_to_usbdev(intf); 1209 + dev->f_adc = bands[0].rangelow; 1210 + dev->pixelformat = formats[0].pixelformat; 1211 + dev->buffersize = formats[0].buffersize; 1212 + dev->num_formats = NUM_FORMATS; 1215 1213 if (!msi2500_emulated_fmt) 1216 - s->num_formats -= 2; 1214 + dev->num_formats -= 2; 1217 1215 1218 1216 /* Init videobuf2 queue structure */ 1219 - s->vb_queue.type = V4L2_BUF_TYPE_SDR_CAPTURE; 1220 - s->vb_queue.io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ; 1221 - s->vb_queue.drv_priv = s; 1222 - s->vb_queue.buf_struct_size = sizeof(struct msi2500_frame_buf); 1223 - s->vb_queue.ops = &msi2500_vb2_ops; 1224 - s->vb_queue.mem_ops = &vb2_vmalloc_memops; 1225 - s->vb_queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; 1226 - ret = vb2_queue_init(&s->vb_queue); 1217 + dev->vb_queue.type = V4L2_BUF_TYPE_SDR_CAPTURE; 1218 + dev->vb_queue.io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ; 1219 + dev->vb_queue.drv_priv = dev; 1220 + dev->vb_queue.buf_struct_size = sizeof(struct msi2500_frame_buf); 1221 + dev->vb_queue.ops = &msi2500_vb2_ops; 1222 + dev->vb_queue.mem_ops = &vb2_vmalloc_memops; 1223 + dev->vb_queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; 1224 + ret = vb2_queue_init(&dev->vb_queue); 1227 1225 if (ret) { 1228 - dev_err(s->dev, "Could not initialize vb2 queue\n"); 1226 + dev_err(dev->dev, "Could not initialize vb2 queue\n"); 1229 1227 goto err_free_mem; 1230 1228 } 1231 1229 1232 1230 /* Init video_device structure */ 1233 - s->vdev = msi2500_template; 1234 - s->vdev.queue = &s->vb_queue; 1235 - s->vdev.queue->lock = &s->vb_queue_lock; 1236 - video_set_drvdata(&s->vdev, s); 1231 + dev->vdev = msi2500_template; 1232 + dev->vdev.queue = &dev->vb_queue; 1233 + dev->vdev.queue->lock = &dev->vb_queue_lock; 1234 + video_set_drvdata(&dev->vdev, dev); 1237 1235 1238 1236 /* Register the v4l2_device structure */ 1239 - s->v4l2_dev.release = msi2500_video_release; 1240 - ret = v4l2_device_register(&intf->dev, &s->v4l2_dev); 1237 + dev->v4l2_dev.release = msi2500_video_release; 1238 + ret = v4l2_device_register(&intf->dev, &dev->v4l2_dev); 1241 1239 if (ret) { 1242 - dev_err(s->dev, "Failed to register v4l2-device (%d)\n", ret); 1240 + dev_err(dev->dev, "Failed to register v4l2-device (%d)\n", ret); 1243 1241 goto err_free_mem; 1244 1242 } 1245 1243 1246 1244 /* SPI master adapter */ 1247 - master = spi_alloc_master(s->dev, 0); 1245 + master = spi_alloc_master(dev->dev, 0); 1248 1246 if (master == NULL) { 1249 1247 ret = -ENOMEM; 1250 1248 goto err_unregister_v4l2_dev; 1251 1249 } 1252 1250 1253 - s->master = master; 1251 + dev->master = master; 1254 1252 master->bus_num = 0; 1255 1253 master->num_chipselect = 1; 1256 1254 master->transfer_one_message = msi2500_transfer_one_message; 1257 - spi_master_set_devdata(master, s); 1255 + spi_master_set_devdata(master, dev); 1258 1256 ret = spi_register_master(master); 1259 1257 if (ret) { 1260 1258 spi_master_put(master); ··· 1262 1260 } 1263 1261 1264 1262 /* load v4l2 subdevice */ 1265 - sd = v4l2_spi_new_subdev(&s->v4l2_dev, master, &board_info); 1266 - s->v4l2_subdev = sd; 1263 + sd = v4l2_spi_new_subdev(&dev->v4l2_dev, master, &board_info); 1264 + dev->v4l2_subdev = sd; 1267 1265 if (sd == NULL) { 1268 - dev_err(s->dev, "cannot get v4l2 subdevice\n"); 1266 + dev_err(dev->dev, "cannot get v4l2 subdevice\n"); 1269 1267 ret = -ENODEV; 1270 1268 goto err_unregister_master; 1271 1269 } 1272 1270 1273 1271 /* Register controls */ 1274 - v4l2_ctrl_handler_init(&s->hdl, 0); 1275 - if (s->hdl.error) { 1276 - ret = s->hdl.error; 1277 - dev_err(s->dev, "Could not initialize controls\n"); 1272 + v4l2_ctrl_handler_init(&dev->hdl, 0); 1273 + if (dev->hdl.error) { 1274 + ret = dev->hdl.error; 1275 + dev_err(dev->dev, "Could not initialize controls\n"); 1278 1276 goto err_free_controls; 1279 1277 } 1280 1278 1281 1279 /* currently all controls are from subdev */ 1282 - v4l2_ctrl_add_handler(&s->hdl, sd->ctrl_handler, NULL); 1280 + v4l2_ctrl_add_handler(&dev->hdl, sd->ctrl_handler, NULL); 1283 1281 1284 - s->v4l2_dev.ctrl_handler = &s->hdl; 1285 - s->vdev.v4l2_dev = &s->v4l2_dev; 1286 - s->vdev.lock = &s->v4l2_lock; 1282 + dev->v4l2_dev.ctrl_handler = &dev->hdl; 1283 + dev->vdev.v4l2_dev = &dev->v4l2_dev; 1284 + dev->vdev.lock = &dev->v4l2_lock; 1287 1285 1288 - ret = video_register_device(&s->vdev, VFL_TYPE_SDR, -1); 1286 + ret = video_register_device(&dev->vdev, VFL_TYPE_SDR, -1); 1289 1287 if (ret) { 1290 - dev_err(s->dev, "Failed to register as video device (%d)\n", 1291 - ret); 1288 + dev_err(dev->dev, 1289 + "Failed to register as video device (%d)\n", ret); 1292 1290 goto err_unregister_v4l2_dev; 1293 1291 } 1294 - dev_info(s->dev, "Registered as %s\n", 1295 - video_device_node_name(&s->vdev)); 1296 - dev_notice(s->dev, "SDR API is still slightly experimental and functionality changes may follow\n"); 1297 - 1292 + dev_info(dev->dev, "Registered as %s\n", 1293 + video_device_node_name(&dev->vdev)); 1294 + dev_notice(dev->dev, 1295 + "SDR API is still slightly experimental and functionality changes may follow\n"); 1298 1296 return 0; 1299 - 1300 1297 err_free_controls: 1301 - v4l2_ctrl_handler_free(&s->hdl); 1298 + v4l2_ctrl_handler_free(&dev->hdl); 1302 1299 err_unregister_master: 1303 - spi_unregister_master(s->master); 1300 + spi_unregister_master(dev->master); 1304 1301 err_unregister_v4l2_dev: 1305 - v4l2_device_unregister(&s->v4l2_dev); 1302 + v4l2_device_unregister(&dev->v4l2_dev); 1306 1303 err_free_mem: 1307 - kfree(s); 1304 + kfree(dev); 1305 + err: 1308 1306 return ret; 1309 1307 } 1310 1308 1311 1309 /* USB device ID list */ 1312 1310 static struct usb_device_id msi2500_id_table[] = { 1313 - { USB_DEVICE(0x1df7, 0x2500) }, /* Mirics MSi3101 SDR Dongle */ 1314 - { USB_DEVICE(0x2040, 0xd300) }, /* Hauppauge WinTV 133559 LF */ 1315 - { } 1311 + {USB_DEVICE(0x1df7, 0x2500)}, /* Mirics MSi3101 SDR Dongle */ 1312 + {USB_DEVICE(0x2040, 0xd300)}, /* Hauppauge WinTV 133559 LF */ 1313 + {} 1316 1314 }; 1317 1315 MODULE_DEVICE_TABLE(usb, msi2500_id_table); 1318 1316