diff options
author | Joonyoung Shim <jy0922.shim@samsung.com> | 2009-12-10 14:49:34 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2009-12-15 21:18:34 -0500 |
commit | 1aa925c957d37e077edb1de4553481734b8462cf (patch) | |
tree | a85e069a76a3db0fe2333d27465d3291add3ef14 /drivers/media/radio | |
parent | 31bedfa5068936b15a388842be1d03cdd1bdfb07 (diff) |
V4L/DVB (13599): radio-si470x: move some file operations to common file
The read and poll file operations of the si470x usb driver can be used
also equally on the si470x i2c driver, so they go to the common file.
Signed-off-by: Joonyoung Shim <jy0922.shim@samsung.com>
Acked-by: Tobias Lorenz <tobias.lorenz@gmx.net>
Signed-off-by: Douglas Schilling Landgraf <dougsland@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/radio')
-rw-r--r-- | drivers/media/radio/si470x/radio-si470x-common.c | 98 | ||||
-rw-r--r-- | drivers/media/radio/si470x/radio-si470x-i2c.c | 15 | ||||
-rw-r--r-- | drivers/media/radio/si470x/radio-si470x-usb.c | 97 | ||||
-rw-r--r-- | drivers/media/radio/si470x/radio-si470x.h | 3 |
4 files changed, 104 insertions, 109 deletions
diff --git a/drivers/media/radio/si470x/radio-si470x-common.c b/drivers/media/radio/si470x/radio-si470x-common.c index f33315f2c543..4da0f150c6e2 100644 --- a/drivers/media/radio/si470x/radio-si470x-common.c +++ b/drivers/media/radio/si470x/radio-si470x-common.c | |||
@@ -426,6 +426,104 @@ int si470x_rds_on(struct si470x_device *radio) | |||
426 | 426 | ||
427 | 427 | ||
428 | /************************************************************************** | 428 | /************************************************************************** |
429 | * File Operations Interface | ||
430 | **************************************************************************/ | ||
431 | |||
432 | /* | ||
433 | * si470x_fops_read - read RDS data | ||
434 | */ | ||
435 | static ssize_t si470x_fops_read(struct file *file, char __user *buf, | ||
436 | size_t count, loff_t *ppos) | ||
437 | { | ||
438 | struct si470x_device *radio = video_drvdata(file); | ||
439 | int retval = 0; | ||
440 | unsigned int block_count = 0; | ||
441 | |||
442 | /* switch on rds reception */ | ||
443 | if ((radio->registers[SYSCONFIG1] & SYSCONFIG1_RDS) == 0) | ||
444 | si470x_rds_on(radio); | ||
445 | |||
446 | /* block if no new data available */ | ||
447 | while (radio->wr_index == radio->rd_index) { | ||
448 | if (file->f_flags & O_NONBLOCK) { | ||
449 | retval = -EWOULDBLOCK; | ||
450 | goto done; | ||
451 | } | ||
452 | if (wait_event_interruptible(radio->read_queue, | ||
453 | radio->wr_index != radio->rd_index) < 0) { | ||
454 | retval = -EINTR; | ||
455 | goto done; | ||
456 | } | ||
457 | } | ||
458 | |||
459 | /* calculate block count from byte count */ | ||
460 | count /= 3; | ||
461 | |||
462 | /* copy RDS block out of internal buffer and to user buffer */ | ||
463 | mutex_lock(&radio->lock); | ||
464 | while (block_count < count) { | ||
465 | if (radio->rd_index == radio->wr_index) | ||
466 | break; | ||
467 | |||
468 | /* always transfer rds complete blocks */ | ||
469 | if (copy_to_user(buf, &radio->buffer[radio->rd_index], 3)) | ||
470 | /* retval = -EFAULT; */ | ||
471 | break; | ||
472 | |||
473 | /* increment and wrap read pointer */ | ||
474 | radio->rd_index += 3; | ||
475 | if (radio->rd_index >= radio->buf_size) | ||
476 | radio->rd_index = 0; | ||
477 | |||
478 | /* increment counters */ | ||
479 | block_count++; | ||
480 | buf += 3; | ||
481 | retval += 3; | ||
482 | } | ||
483 | mutex_unlock(&radio->lock); | ||
484 | |||
485 | done: | ||
486 | return retval; | ||
487 | } | ||
488 | |||
489 | |||
490 | /* | ||
491 | * si470x_fops_poll - poll RDS data | ||
492 | */ | ||
493 | static unsigned int si470x_fops_poll(struct file *file, | ||
494 | struct poll_table_struct *pts) | ||
495 | { | ||
496 | struct si470x_device *radio = video_drvdata(file); | ||
497 | int retval = 0; | ||
498 | |||
499 | /* switch on rds reception */ | ||
500 | if ((radio->registers[SYSCONFIG1] & SYSCONFIG1_RDS) == 0) | ||
501 | si470x_rds_on(radio); | ||
502 | |||
503 | poll_wait(file, &radio->read_queue, pts); | ||
504 | |||
505 | if (radio->rd_index != radio->wr_index) | ||
506 | retval = POLLIN | POLLRDNORM; | ||
507 | |||
508 | return retval; | ||
509 | } | ||
510 | |||
511 | |||
512 | /* | ||
513 | * si470x_fops - file operations interface | ||
514 | */ | ||
515 | static const struct v4l2_file_operations si470x_fops = { | ||
516 | .owner = THIS_MODULE, | ||
517 | .read = si470x_fops_read, | ||
518 | .poll = si470x_fops_poll, | ||
519 | .ioctl = video_ioctl2, | ||
520 | .open = si470x_fops_open, | ||
521 | .release = si470x_fops_release, | ||
522 | }; | ||
523 | |||
524 | |||
525 | |||
526 | /************************************************************************** | ||
429 | * Video4Linux Interface | 527 | * Video4Linux Interface |
430 | **************************************************************************/ | 528 | **************************************************************************/ |
431 | 529 | ||
diff --git a/drivers/media/radio/si470x/radio-si470x-i2c.c b/drivers/media/radio/si470x/radio-si470x-i2c.c index 2d53b6a9409b..4816a6d501c6 100644 --- a/drivers/media/radio/si470x/radio-si470x-i2c.c +++ b/drivers/media/radio/si470x/radio-si470x-i2c.c | |||
@@ -173,7 +173,7 @@ int si470x_disconnect_check(struct si470x_device *radio) | |||
173 | /* | 173 | /* |
174 | * si470x_fops_open - file open | 174 | * si470x_fops_open - file open |
175 | */ | 175 | */ |
176 | static int si470x_fops_open(struct file *file) | 176 | int si470x_fops_open(struct file *file) |
177 | { | 177 | { |
178 | struct si470x_device *radio = video_drvdata(file); | 178 | struct si470x_device *radio = video_drvdata(file); |
179 | int retval = 0; | 179 | int retval = 0; |
@@ -194,7 +194,7 @@ static int si470x_fops_open(struct file *file) | |||
194 | /* | 194 | /* |
195 | * si470x_fops_release - file release | 195 | * si470x_fops_release - file release |
196 | */ | 196 | */ |
197 | static int si470x_fops_release(struct file *file) | 197 | int si470x_fops_release(struct file *file) |
198 | { | 198 | { |
199 | struct si470x_device *radio = video_drvdata(file); | 199 | struct si470x_device *radio = video_drvdata(file); |
200 | int retval = 0; | 200 | int retval = 0; |
@@ -215,17 +215,6 @@ static int si470x_fops_release(struct file *file) | |||
215 | } | 215 | } |
216 | 216 | ||
217 | 217 | ||
218 | /* | ||
219 | * si470x_fops - file operations interface | ||
220 | */ | ||
221 | const struct v4l2_file_operations si470x_fops = { | ||
222 | .owner = THIS_MODULE, | ||
223 | .ioctl = video_ioctl2, | ||
224 | .open = si470x_fops_open, | ||
225 | .release = si470x_fops_release, | ||
226 | }; | ||
227 | |||
228 | |||
229 | 218 | ||
230 | /************************************************************************** | 219 | /************************************************************************** |
231 | * Video4Linux Interface | 220 | * Video4Linux Interface |
diff --git a/drivers/media/radio/si470x/radio-si470x-usb.c b/drivers/media/radio/si470x/radio-si470x-usb.c index f2d0e1ddb301..a96e1b9dd646 100644 --- a/drivers/media/radio/si470x/radio-si470x-usb.c +++ b/drivers/media/radio/si470x/radio-si470x-usb.c | |||
@@ -509,89 +509,9 @@ resubmit: | |||
509 | **************************************************************************/ | 509 | **************************************************************************/ |
510 | 510 | ||
511 | /* | 511 | /* |
512 | * si470x_fops_read - read RDS data | ||
513 | */ | ||
514 | static ssize_t si470x_fops_read(struct file *file, char __user *buf, | ||
515 | size_t count, loff_t *ppos) | ||
516 | { | ||
517 | struct si470x_device *radio = video_drvdata(file); | ||
518 | int retval = 0; | ||
519 | unsigned int block_count = 0; | ||
520 | |||
521 | /* switch on rds reception */ | ||
522 | if ((radio->registers[SYSCONFIG1] & SYSCONFIG1_RDS) == 0) | ||
523 | si470x_rds_on(radio); | ||
524 | |||
525 | /* block if no new data available */ | ||
526 | while (radio->wr_index == radio->rd_index) { | ||
527 | if (file->f_flags & O_NONBLOCK) { | ||
528 | retval = -EWOULDBLOCK; | ||
529 | goto done; | ||
530 | } | ||
531 | if (wait_event_interruptible(radio->read_queue, | ||
532 | radio->wr_index != radio->rd_index) < 0) { | ||
533 | retval = -EINTR; | ||
534 | goto done; | ||
535 | } | ||
536 | } | ||
537 | |||
538 | /* calculate block count from byte count */ | ||
539 | count /= 3; | ||
540 | |||
541 | /* copy RDS block out of internal buffer and to user buffer */ | ||
542 | mutex_lock(&radio->lock); | ||
543 | while (block_count < count) { | ||
544 | if (radio->rd_index == radio->wr_index) | ||
545 | break; | ||
546 | |||
547 | /* always transfer rds complete blocks */ | ||
548 | if (copy_to_user(buf, &radio->buffer[radio->rd_index], 3)) | ||
549 | /* retval = -EFAULT; */ | ||
550 | break; | ||
551 | |||
552 | /* increment and wrap read pointer */ | ||
553 | radio->rd_index += 3; | ||
554 | if (radio->rd_index >= radio->buf_size) | ||
555 | radio->rd_index = 0; | ||
556 | |||
557 | /* increment counters */ | ||
558 | block_count++; | ||
559 | buf += 3; | ||
560 | retval += 3; | ||
561 | } | ||
562 | mutex_unlock(&radio->lock); | ||
563 | |||
564 | done: | ||
565 | return retval; | ||
566 | } | ||
567 | |||
568 | |||
569 | /* | ||
570 | * si470x_fops_poll - poll RDS data | ||
571 | */ | ||
572 | static unsigned int si470x_fops_poll(struct file *file, | ||
573 | struct poll_table_struct *pts) | ||
574 | { | ||
575 | struct si470x_device *radio = video_drvdata(file); | ||
576 | int retval = 0; | ||
577 | |||
578 | /* switch on rds reception */ | ||
579 | if ((radio->registers[SYSCONFIG1] & SYSCONFIG1_RDS) == 0) | ||
580 | si470x_rds_on(radio); | ||
581 | |||
582 | poll_wait(file, &radio->read_queue, pts); | ||
583 | |||
584 | if (radio->rd_index != radio->wr_index) | ||
585 | retval = POLLIN | POLLRDNORM; | ||
586 | |||
587 | return retval; | ||
588 | } | ||
589 | |||
590 | |||
591 | /* | ||
592 | * si470x_fops_open - file open | 512 | * si470x_fops_open - file open |
593 | */ | 513 | */ |
594 | static int si470x_fops_open(struct file *file) | 514 | int si470x_fops_open(struct file *file) |
595 | { | 515 | { |
596 | struct si470x_device *radio = video_drvdata(file); | 516 | struct si470x_device *radio = video_drvdata(file); |
597 | int retval; | 517 | int retval; |
@@ -645,7 +565,7 @@ done: | |||
645 | /* | 565 | /* |
646 | * si470x_fops_release - file release | 566 | * si470x_fops_release - file release |
647 | */ | 567 | */ |
648 | static int si470x_fops_release(struct file *file) | 568 | int si470x_fops_release(struct file *file) |
649 | { | 569 | { |
650 | struct si470x_device *radio = video_drvdata(file); | 570 | struct si470x_device *radio = video_drvdata(file); |
651 | int retval = 0; | 571 | int retval = 0; |
@@ -688,19 +608,6 @@ done: | |||
688 | } | 608 | } |
689 | 609 | ||
690 | 610 | ||
691 | /* | ||
692 | * si470x_fops - file operations interface | ||
693 | */ | ||
694 | const struct v4l2_file_operations si470x_fops = { | ||
695 | .owner = THIS_MODULE, | ||
696 | .read = si470x_fops_read, | ||
697 | .poll = si470x_fops_poll, | ||
698 | .ioctl = video_ioctl2, | ||
699 | .open = si470x_fops_open, | ||
700 | .release = si470x_fops_release, | ||
701 | }; | ||
702 | |||
703 | |||
704 | 611 | ||
705 | /************************************************************************** | 612 | /************************************************************************** |
706 | * Video4Linux Interface | 613 | * Video4Linux Interface |
diff --git a/drivers/media/radio/si470x/radio-si470x.h b/drivers/media/radio/si470x/radio-si470x.h index d0af194d194c..f646f79d2f7a 100644 --- a/drivers/media/radio/si470x/radio-si470x.h +++ b/drivers/media/radio/si470x/radio-si470x.h | |||
@@ -212,7 +212,6 @@ struct si470x_device { | |||
212 | /************************************************************************** | 212 | /************************************************************************** |
213 | * Common Functions | 213 | * Common Functions |
214 | **************************************************************************/ | 214 | **************************************************************************/ |
215 | extern const struct v4l2_file_operations si470x_fops; | ||
216 | extern struct video_device si470x_viddev_template; | 215 | extern struct video_device si470x_viddev_template; |
217 | int si470x_get_register(struct si470x_device *radio, int regnr); | 216 | int si470x_get_register(struct si470x_device *radio, int regnr); |
218 | int si470x_set_register(struct si470x_device *radio, int regnr); | 217 | int si470x_set_register(struct si470x_device *radio, int regnr); |
@@ -221,5 +220,7 @@ int si470x_set_freq(struct si470x_device *radio, unsigned int freq); | |||
221 | int si470x_start(struct si470x_device *radio); | 220 | int si470x_start(struct si470x_device *radio); |
222 | int si470x_stop(struct si470x_device *radio); | 221 | int si470x_stop(struct si470x_device *radio); |
223 | int si470x_rds_on(struct si470x_device *radio); | 222 | int si470x_rds_on(struct si470x_device *radio); |
223 | int si470x_fops_open(struct file *file); | ||
224 | int si470x_fops_release(struct file *file); | ||
224 | int si470x_vidioc_querycap(struct file *file, void *priv, | 225 | int si470x_vidioc_querycap(struct file *file, void *priv, |
225 | struct v4l2_capability *capability); | 226 | struct v4l2_capability *capability); |