radio-si470x: move some file operations to common file
Subsystems (3)
PATCH 2/3 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.
--- drivers/media/radio/si470x/radio-si470x-common.c | 98 ++++++++++++++++++++++ drivers/media/radio/si470x/radio-si470x-i2c.c | 15 +--- drivers/media/radio/si470x/radio-si470x-usb.c | 97 +--------------------- drivers/media/radio/si470x/radio-si470x.h | 3 +- 4 files changed, 104 insertions(+), 109 deletions(-)
drivers/media/radio/si470x/radio-si470x-common.c +98 -0
@@ -426,6 +426,104 @@ int si470x_rds_on(struct si470x_device *radio)/************************************************************************** +* File Operations Interface +**************************************************************************/ + +/* +* si470x_fops_read - read RDS data +*/ +static ssize_t si470x_fops_read (struct file *file,char __user *buf, +size_t count,loff_t *ppos) +{ +struct si470x_device *radio =video_drvdata (file); +int retval =0 ; +unsigned int block_count =0 ; + +/* switch on rds reception */ +if ((radio->registers[SYSCONFIG1 ] &SYSCONFIG1_RDS ) ==0 ) +si470x_rds_on (radio); + +/* block if no new data available */ +while (radio->wr_index == radio->rd_index) { +if (file->f_flags &O_NONBLOCK ) { + retval = -EWOULDBLOCK ; + goto done; + } +if (wait_event_interruptible (radio->read_queue, + radio->wr_index != radio->rd_index) <0 ) { + retval = -EINTR ; + goto done; + } + } + +/* calculate block count from byte count */ + count /=3 ; + +/* copy RDS block out of internal buffer and to user buffer */ +mutex_lock (&radio->lock); +while (block_count < count) { +if (radio->rd_index == radio->wr_index) +break ; + +/* always transfer rds complete blocks */ +if (copy_to_user (buf, &radio->buffer[radio->rd_index],3 )) +/* retval = -EFAULT; */ +break ; + +/* increment and wrap read pointer */ + radio->rd_index +=3 ; +if (radio->rd_index >= radio->buf_size) + radio->rd_index =0 ; + +/* increment counters */ + block_count++; + buf +=3 ; + retval +=3 ; + } +mutex_unlock (&radio->lock); + +done: +return retval; +} + + +/* +* si470x_fops_poll - poll RDS data +*/ +static unsigned int si470x_fops_poll (struct file *file, +struct poll_table_struct *pts) +{ +struct si470x_device *radio =video_drvdata (file); +int retval =0 ; + +/* switch on rds reception */ +if ((radio->registers[SYSCONFIG1 ] &SYSCONFIG1_RDS ) ==0 ) +si470x_rds_on (radio); + +poll_wait (file, &radio->read_queue, pts); + +if (radio->rd_index != radio->wr_index) + retval =POLLIN |POLLRDNORM ; + +return retval; +} + + +/* +* si470x_fops - file operations interface +*/ +static const struct v4l2_file_operations si470x_fops = { + .owner =THIS_MODULE , + .read = si470x_fops_read, + .poll = si470x_fops_poll, + .ioctl = video_ioctl2, + .open = si470x_fops_open, + .release = si470x_fops_release, +}; + + + +/************************************************************************** * Video4Linux Interface **************************************************************************/
drivers/media/radio/si470x/radio-si470x-i2c.c +2 -13
@@ -173,7 +173,7 @@ int si470x_disconnect_check(struct si470x_device *radio)/* * si470x_fops_open - file open */ -static int si470x_fops_open (struct file *file) +int si470x_fops_open (struct file *file) {struct si470x_device *radio =video_drvdata (file);int retval =0 ;
@@ -194,7 +194,7 @@ static int si470x_fops_open(struct file *file)/* * si470x_fops_release - file release */ -static int si470x_fops_release (struct file *file) +int si470x_fops_release (struct file *file) {struct si470x_device *radio =video_drvdata (file);int retval =0 ;
@@ -215,17 +215,6 @@ static int si470x_fops_release(struct file *file) } -/* -* si470x_fops - file operations interface -*/ -const struct v4l2_file_operations si470x_fops = { - .owner =THIS_MODULE , - .ioctl = video_ioctl2, - .open = si470x_fops_open, - .release = si470x_fops_release, -}; - -/************************************************************************** * Video4Linux Interface
drivers/media/radio/si470x/radio-si470x-usb.c +2 -95
117 lines not on this page · raw message
drivers/media/radio/si470x/radio-si470x.h +2 -1
@@ -212,7 +212,6 @@ struct si470x_device {/************************************************************************** * Common Functions **************************************************************************/ -extern const struct v4l2_file_operations si470x_fops;extern struct video_device si470x_viddev_template;int si470x_get_register (struct si470x_device *radio,int regnr);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);int si470x_start (struct si470x_device *radio);int si470x_stop (struct si470x_device *radio);int si470x_rds_on (struct si470x_device *radio); +int si470x_fops_open (struct file *file); +int si470x_fops_release (struct file *file);int si470x_vidioc_querycap (struct file *file,void *priv,struct v4l2_capability *capability);
Signature · 1 line
1.6.0.4
Quoted 4 lines · On Wednesday 18 November 2009 07:21:30 Joonyoung Shim wrote:
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 <[email protected]>
Why on earth is the i2c driver registering a radio device? If I understand it correctly the usb and i2c driver are both registering a radio device where there should be only one!
i2c drivers should in general never register video devices. That's the task of the bridge driver.
Does anyone know why the current driver behaves like this? I think that should be fixed first.
Regards,
Hans
Signature · 1 line
Hans Verkuil - video4linux developer - sponsored by TANDBERG Telecom
Quoted 13 lines · On Wednesday 18 November 2009 07:42:41 Hans Verkuil wrote:
Quoted 4 lines · On Wednesday 18 November 2009 07:21:30 Joonyoung Shim wrote:
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 <[email protected]>Why on earth is the i2c driver registering a radio device? If I understand it correctly the usb and i2c driver are both registering a radio device where there should be only one!
i2c drivers should in general never register video devices. That's the task of the bridge driver.
Quoted 7 lines
Does anyone know why the current driver behaves like this? I think that should be fixed first.
Regards,
Hans
It's too early in the morning. Forget what I said :-)
The two drivers are independent, the usb driver doesn't depend on the i2c driver. Now it makes a lot more sense.
Regards,
Hans
Signature · 1 line
Hans Verkuil - video4linux developer - sponsored by TANDBERG Telecom
Hi,
yes, good point.
Bye,
Toby
Am Mittwoch 18 November 2009 07:21:30 schrieb Joonyoung Shim:
Quoted 305 lines
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 <[email protected]>--- drivers/media/radio/si470x/radio-si470x-common.c | 98 ++++++++++++++++++++++ drivers/media/radio/si470x/radio-si470x-i2c.c | 15 +--- drivers/media/radio/si470x/radio-si470x-usb.c | 97 +--------------------- drivers/media/radio/si470x/radio-si470x.h | 3 +- 4 files changed, 104 insertions(+), 109 deletions(-)drivers/media/radio/si470x/radio-si470x-common.c +98
-0@@ -426,6 +426,104 @@ int si470x_rds_on(struct si470x_device *radio)/************************************************************************** +* File Operations Interface +**************************************************************************/ + +/* +* si470x_fops_read - read RDS data +*/ +static ssize_t si470x_fops_read (struct file *file,char __user *buf, +size_t count,loff_t *ppos) +{ +struct si470x_device *radio =video_drvdata (file); +int retval =0 ; +unsigned int block_count =0 ; + +/* switch on rds reception */ +if ((radio->registers[SYSCONFIG1 ] &SYSCONFIG1_RDS ) ==0 ) +si470x_rds_on (radio); + +/* block if no new data available */ +while (radio->wr_index == radio->rd_index) { +if (file->f_flags &O_NONBLOCK ) { + retval = -EWOULDBLOCK ; + goto done; + } +if (wait_event_interruptible (radio->read_queue, + radio->wr_index != radio->rd_index) <0 ) { + retval = -EINTR ; + goto done; + } + } + +/* calculate block count from byte count */ + count /=3 ; + +/* copy RDS block out of internal buffer and to user buffer */ +mutex_lock (&radio->lock); +while (block_count < count) { +if (radio->rd_index == radio->wr_index) +break ; + +/* always transfer rds complete blocks */ +if (copy_to_user (buf, &radio->buffer[radio->rd_index],3 )) +/* retval = -EFAULT; */ +break ; + +/* increment and wrap read pointer */ + radio->rd_index +=3 ; +if (radio->rd_index >= radio->buf_size) + radio->rd_index =0 ; + +/* increment counters */ + block_count++; + buf +=3 ; + retval +=3 ; + } +mutex_unlock (&radio->lock); + +done: +return retval; +} + + +/* +* si470x_fops_poll - poll RDS data +*/ +static unsigned int si470x_fops_poll (struct file *file, +struct poll_table_struct *pts) +{ +struct si470x_device *radio =video_drvdata (file); +int retval =0 ; + +/* switch on rds reception */ +if ((radio->registers[SYSCONFIG1 ] &SYSCONFIG1_RDS ) ==0 ) +si470x_rds_on (radio); + +poll_wait (file, &radio->read_queue, pts); + +if (radio->rd_index != radio->wr_index) + retval =POLLIN |POLLRDNORM ; + +return retval; +} + + +/* +* si470x_fops - file operations interface +*/ +static const struct v4l2_file_operations si470x_fops = { + .owner =THIS_MODULE , + .read = si470x_fops_read, + .poll = si470x_fops_poll, + .ioctl = video_ioctl2, + .open = si470x_fops_open, + .release = si470x_fops_release, +}; + + + +/************************************************************************** * Video4Linux Interface **************************************************************************/ drivers/media/radio/si470x/radio-si470x-i2c.c +2
-13@@ -173,7 +173,7 @@ int si470x_disconnect_check(struct si470x_device *radio)/* * si470x_fops_open - file open */ -static int si470x_fops_open (struct file *file) +int si470x_fops_open (struct file *file) {struct si470x_device *radio =video_drvdata (file);int retval =0 ;@@ -194,7 +194,7 @@ static int si470x_fops_open(struct file *file)/* * si470x_fops_release - file release */ -static int si470x_fops_release (struct file *file) +int si470x_fops_release (struct file *file) {struct si470x_device *radio =video_drvdata (file);int retval =0 ;@@ -215,17 +215,6 @@ static int si470x_fops_release(struct file *file) } -/* -* si470x_fops - file operations interface -*/ -const struct v4l2_file_operations si470x_fops = { - .owner =THIS_MODULE , - .ioctl = video_ioctl2, - .open = si470x_fops_open, - .release = si470x_fops_release, -}; - -/************************************************************************** * Video4Linux Interface drivers/media/radio/si470x/radio-si470x-usb.c +2
-95@@ -509,89 +509,9 @@ resubmit:**************************************************************************/ /* -* si470x_fops_read - read RDS data -*/ -static ssize_t si470x_fops_read (struct file *file,char __user *buf, -size_t count,loff_t *ppos) -{ -struct si470x_device *radio =video_drvdata (file); -int retval =0 ; -unsigned int block_count =0 ; - -/* switch on rds reception */ -if ((radio->registers[SYSCONFIG1 ] &SYSCONFIG1_RDS ) ==0 ) -si470x_rds_on (radio); - -/* block if no new data available */ -while (radio->wr_index == radio->rd_index) { -if (file->f_flags &O_NONBLOCK ) { - retval = -EWOULDBLOCK ; - goto done; - } -if (wait_event_interruptible (radio->read_queue, - radio->wr_index != radio->rd_index) <0 ) { - retval = -EINTR ; - goto done; - } - } - -/* calculate block count from byte count */ - count /=3 ; - -/* copy RDS block out of internal buffer and to user buffer */ -mutex_lock (&radio->lock); -while (block_count < count) { -if (radio->rd_index == radio->wr_index) -break ; - -/* always transfer rds complete blocks */ -if (copy_to_user (buf, &radio->buffer[radio->rd_index],3 )) -/* retval = -EFAULT; */ -break ; - -/* increment and wrap read pointer */ - radio->rd_index +=3 ; -if (radio->rd_index >= radio->buf_size) - radio->rd_index =0 ; - -/* increment counters */ - block_count++; - buf +=3 ; - retval +=3 ; - } -mutex_unlock (&radio->lock); - -done: -return retval; -} - - -/* -* si470x_fops_poll - poll RDS data -*/ -static unsigned int si470x_fops_poll (struct file *file, -struct poll_table_struct *pts) -{ -struct si470x_device *radio =video_drvdata (file); -int retval =0 ; - -/* switch on rds reception */ -if ((radio->registers[SYSCONFIG1 ] &SYSCONFIG1_RDS ) ==0 ) -si470x_rds_on (radio); - -poll_wait (file, &radio->read_queue, pts); - -if (radio->rd_index != radio->wr_index) - retval =POLLIN |POLLRDNORM ; - -return retval; -} - - -/* * si470x_fops_open - file open */ -static int si470x_fops_open (struct file *file) +int si470x_fops_open (struct file *file) {struct si470x_device *radio =video_drvdata (file);int retval;@@ -645,7 +565,7 @@ done:/* * si470x_fops_release - file release */ -static int si470x_fops_release (struct file *file) +int si470x_fops_release (struct file *file) {struct si470x_device *radio =video_drvdata (file);int retval =0 ;@@ -688,19 +608,6 @@ done: } -/* -* si470x_fops - file operations interface -*/ -const struct v4l2_file_operations si470x_fops = { - .owner =THIS_MODULE , - .read = si470x_fops_read, - .poll = si470x_fops_poll, - .ioctl = video_ioctl2, - .open = si470x_fops_open, - .release = si470x_fops_release, -}; - -/************************************************************************** * Video4Linux Interface drivers/media/radio/si470x/radio-si470x.h +2
-1@@ -212,7 +212,6 @@ struct si470x_device {/************************************************************************** * Common Functions **************************************************************************/ -extern const struct v4l2_file_operations si470x_fops;extern struct video_device si470x_viddev_template;int si470x_get_register (struct si470x_device *radio,int regnr);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);int si470x_start (struct si470x_device *radio);int si470x_stop (struct si470x_device *radio);int si470x_rds_on (struct si470x_device *radio); +int si470x_fops_open (struct file *file); +int si470x_fops_release (struct file *file);int si470x_vidioc_querycap (struct file *file,void *priv,struct v4l2_capability *capability);