Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 295049
b: refs/heads/master
c: bc2b395
h: refs/heads/master
i:
  295047: 832f0f9
v: v3
  • Loading branch information
Hans Verkuil authored and Mauro Carvalho Chehab committed Mar 19, 2012
1 parent 823b9c9 commit 1e80eee
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 19 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: d4ecc83b79cc290eadf1ffb33a589c3c72bbc295
refs/heads/master: bc2b395c031430639e5ad5dcb2669cfcf1fa5fd2
79 changes: 61 additions & 18 deletions trunk/sound/i2c/other/tea575x-tuner.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ static void snd_tea575x_write(struct snd_tea575x *tea, unsigned int val)
tea->ops->set_pins(tea, 0);
}

static unsigned int snd_tea575x_read(struct snd_tea575x *tea)
static u32 snd_tea575x_read(struct snd_tea575x *tea)
{
u16 l, rdata;
u32 data = 0;
Expand Down Expand Up @@ -120,6 +120,25 @@ static unsigned int snd_tea575x_read(struct snd_tea575x *tea)
return data;
}

static u32 snd_tea575x_get_freq(struct snd_tea575x *tea)
{
u32 freq = snd_tea575x_read(tea) & TEA575X_BIT_FREQ_MASK;

if (freq == 0)
return freq;

/* freq *= 12.5 */
freq *= 125;
freq /= 10;
/* crystal fixup */
if (tea->tea5759)
freq += TEA575X_FMIF;
else
freq -= TEA575X_FMIF;

return clamp(freq * 16, FREQ_LO, FREQ_HI); /* from kHz */
}

static void snd_tea575x_set_freq(struct snd_tea575x *tea)
{
u32 freq = tea->freq;
Expand Down Expand Up @@ -225,38 +244,62 @@ static int vidioc_s_hw_freq_seek(struct file *file, void *fh,
struct v4l2_hw_freq_seek *a)
{
struct snd_tea575x *tea = video_drvdata(file);
unsigned long timeout;
int i;

if (tea->cannot_read_data)
return -ENOTTY;
if (a->tuner || a->wrap_around)
return -EINVAL;

/* clear the frequency, HW will fill it in */
tea->val &= ~TEA575X_BIT_FREQ_MASK;
tea->val |= TEA575X_BIT_SEARCH;
tea->val &= ~TEA575X_BIT_UPDOWN;
if (a->seek_upward)
tea->val |= TEA575X_BIT_UPDOWN;
else
tea->val &= ~TEA575X_BIT_UPDOWN;
snd_tea575x_write(tea, tea->val);
timeout = jiffies + msecs_to_jiffies(10000);
for (;;) {
unsigned val = snd_tea575x_read(tea);

if (!(val & TEA575X_BIT_SEARCH)) {
/* Found a frequency */
val &= TEA575X_BIT_FREQ_MASK;
val = (val * 10) / 125;
if (tea->tea5759)
val += TEA575X_FMIF;
else
val -= TEA575X_FMIF;
tea->freq = clamp(val * 16, FREQ_LO, FREQ_HI);
return 0;
}
if (time_after(jiffies, timeout))
break;
if (schedule_timeout_interruptible(msecs_to_jiffies(10))) {
/* some signal arrived, stop search */
tea->val &= ~TEA575X_BIT_SEARCH;
snd_tea575x_write(tea, tea->val);
snd_tea575x_set_freq(tea);
return -ERESTARTSYS;
}
if (!(snd_tea575x_read(tea) & TEA575X_BIT_SEARCH)) {
u32 freq;

/* Found a frequency, wait until it can be read */
for (i = 0; i < 100; i++) {
msleep(10);
freq = snd_tea575x_get_freq(tea);
if (freq) /* available */
break;
}
if (freq == 0) /* shouldn't happen */
break;
/*
* if we moved by less than 50 kHz, or in the wrong
* direction, continue seeking
*/
if (abs(tea->freq - freq) < 16 * 50 ||
(a->seek_upward && freq < tea->freq) ||
(!a->seek_upward && freq > tea->freq)) {
snd_tea575x_write(tea, tea->val);
continue;
}
tea->freq = freq;
tea->val &= ~TEA575X_BIT_SEARCH;
return 0;
}
}
return 0;
tea->val &= ~TEA575X_BIT_SEARCH;
snd_tea575x_set_freq(tea);
return -EAGAIN;
}

static int tea575x_s_ctrl(struct v4l2_ctrl *ctrl)
Expand Down Expand Up @@ -320,7 +363,7 @@ int snd_tea575x_init(struct snd_tea575x *tea)
return -ENODEV;
}

tea->val = TEA575X_BIT_BAND_FM | TEA575X_BIT_SEARCH_10_40;
tea->val = TEA575X_BIT_BAND_FM | TEA575X_BIT_SEARCH_5_28;
tea->freq = 90500 * 16; /* 90.5Mhz default */
snd_tea575x_set_freq(tea);

Expand Down

0 comments on commit 1e80eee

Please sign in to comment.