Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 176812
b: refs/heads/master
c: 1aa925c
h: refs/heads/master
v: v3
  • Loading branch information
Joonyoung Shim authored and Mauro Carvalho Chehab committed Dec 16, 2009
1 parent b847d48 commit 43f4a6d
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 110 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 31bedfa5068936b15a388842be1d03cdd1bdfb07
refs/heads/master: 1aa925c957d37e077edb1de4553481734b8462cf
98 changes: 98 additions & 0 deletions trunk/drivers/media/radio/si470x/radio-si470x-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,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
**************************************************************************/
Expand Down
15 changes: 2 additions & 13 deletions trunk/drivers/media/radio/si470x/radio-si470x-i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand Down
97 changes: 2 additions & 95 deletions trunk/drivers/media/radio/si470x/radio-si470x-usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,90 +508,10 @@ static void si470x_int_in_callback(struct urb *urb)
* 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_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;
Expand Down Expand Up @@ -645,7 +565,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;
Expand Down Expand Up @@ -688,19 +608,6 @@ static int si470x_fops_release(struct file *file)
}


/*
* 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
Expand Down
3 changes: 2 additions & 1 deletion trunk/drivers/media/radio/si470x/radio-si470x.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

0 comments on commit 43f4a6d

Please sign in to comment.