Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 241859
b: refs/heads/master
c: 0eec66c
h: refs/heads/master
i:
  241857: 8737aa3
  241855: d1566f4
v: v3
  • Loading branch information
Mauro Carvalho Chehab committed Mar 21, 2011
1 parent ee8f791 commit e25d34e
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 79 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: a2894e3f8ed691b4873c8122e66902fbf0e78e0b
refs/heads/master: 0eec66c0dfc1b066e6addbc6af755c779f65fd87
168 changes: 90 additions & 78 deletions trunk/drivers/media/video/tuner-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ static struct analog_demod_ops tuner_analog_ops = {
};

/*
* Functions to select between radio and TV and tuner probe functions
* Functions to select between radio and TV and tuner probe/remove functions
*/

/**
Expand Down Expand Up @@ -697,6 +697,75 @@ static int tuner_remove(struct i2c_client *client)
return 0;
}

/*
* Functions to switch between Radio and TV
*
* A few cards have a separate I2C tuner for radio. Those routines
* take care of switching between TV/Radio mode, filtering only the
* commands that apply to the Radio or TV tuner.
*/

/**
* check_mode - Verify if tuner supports the requested mode
* @t: a pointer to the module's internal struct_tuner
*
* This function checks if the tuner is capable of tuning analog TV,
* digital TV or radio, depending on what the caller wants. If the
* tuner can't support that mode, it returns -EINVAL. Otherwise, it
* returns 0.
* This function is needed for boards that have a separate tuner for
* radio (like devices with tea5767).
*/
static inline int check_mode(struct tuner *t, enum v4l2_tuner_type mode)
{
if ((1 << mode & t->mode_mask) == 0)
return -EINVAL;

return 0;
}

/**
* set_mode_freq - Switch tuner to other mode.
* @client: struct i2c_client pointer
* @t: a pointer to the module's internal struct_tuner
* @mode: enum v4l2_type (radio or TV)
* @freq: frequency to set (0 means to use the previous one)
*
* If tuner doesn't support the needed mode (radio or TV), prints a
* debug message and returns -EINVAL, changing its state to standby.
* Otherwise, changes the state and sets frequency to the last value, if
* the tuner can sleep or if it supports both Radio and TV.
*/
static int set_mode_freq(struct i2c_client *client, struct tuner *t,
enum v4l2_tuner_type mode, unsigned int freq)
{
struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops;

if (mode != t->mode) {
if (check_mode(t, mode) == -EINVAL) {
tuner_dbg("Tuner doesn't support mode %d. "
"Putting tuner to sleep\n", mode);
t->standby = true;
if (analog_ops->standby)
analog_ops->standby(&t->fe);
return -EINVAL;
}
t->mode = mode;
tuner_dbg("Changing to mode %d\n", mode);
}
if (t->mode == V4L2_TUNER_RADIO) {
if (freq)
t->radio_freq = freq;
set_radio_freq(client, t->radio_freq);
} else {
if (freq)
t->tv_freq = freq;
set_tv_freq(client, t->tv_freq);
}

return 0;
}

/*
* Functions that are specific for TV mode
*/
Expand Down Expand Up @@ -925,66 +994,9 @@ static void set_radio_freq(struct i2c_client *c, unsigned int freq)
analog_ops->set_params(&t->fe, &params);
}

/**
* check_mode - Verify if tuner supports the requested mode
* @t: a pointer to the module's internal struct_tuner
*
* This function checks if the tuner is capable of tuning analog TV,
* digital TV or radio, depending on what the caller wants. If the
* tuner can't support that mode, it returns -EINVAL. Otherwise, it
* returns 0.
* This function is needed for boards that have a separate tuner for
* radio (like devices with tea5767).
*/
static inline int check_mode(struct tuner *t, enum v4l2_tuner_type mode)
{
if ((1 << mode & t->mode_mask) == 0)
return -EINVAL;

return 0;
}

/**
* set_mode_freq - Switch tuner to other mode.
* @client: struct i2c_client pointer
* @t: a pointer to the module's internal struct_tuner
* @mode: enum v4l2_type (radio or TV)
* @freq: frequency to set (0 means to use the previous one)
*
* If tuner doesn't support the needed mode (radio or TV), prints a
* debug message and returns -EINVAL, changing internal state to T_STANDBY.
* Otherwise, changes the state and sets frequency to the last value, if
* the tuner can sleep or if it supports both Radio and TV.
/*
* Debug function for reporting tuner status to userspace
*/
static int set_mode_freq(struct i2c_client *client, struct tuner *t,
enum v4l2_tuner_type mode, unsigned int freq)
{
struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops;

if (mode != t->mode) {
if (check_mode(t, mode) == -EINVAL) {
tuner_dbg("Tuner doesn't support mode %d. "
"Putting tuner to sleep\n", mode);
t->standby = true;
if (analog_ops->standby)
analog_ops->standby(&t->fe);
return -EINVAL;
}
t->mode = mode;
tuner_dbg("Changing to mode %d\n", mode);
}
if (t->mode == V4L2_TUNER_RADIO) {
if (freq)
t->radio_freq = freq;
set_radio_freq(client, t->radio_freq);
} else {
if (freq)
t->tv_freq = freq;
set_tv_freq(client, t->tv_freq);
}

return 0;
}

/**
* tuner_status - Dumps the current tuner status at dmesg
Expand Down Expand Up @@ -1040,6 +1052,24 @@ static void tuner_status(struct dvb_frontend *fe)
analog_ops->has_signal(fe));
}

/*
* Function to splicitly change mode to radio. Probably not needed anymore
*/

static int tuner_s_radio(struct v4l2_subdev *sd)
{
struct tuner *t = to_tuner(sd);
struct i2c_client *client = v4l2_get_subdevdata(sd);

if (set_mode_freq(client, t, V4L2_TUNER_RADIO, 0) == -EINVAL)
return 0;
return 0;
}

/*
* Tuner callbacks to handle userspace ioctl's
*/

/**
* tuner_s_power - controls the power state of the tuner
* @sd: pointer to struct v4l2_subdev
Expand All @@ -1061,24 +1091,6 @@ static int tuner_s_power(struct v4l2_subdev *sd, int on)
return 0;
}

/*
* Function to splicitly change mode to radio. Probably not needed anymore
*/

static int tuner_s_radio(struct v4l2_subdev *sd)
{
struct tuner *t = to_tuner(sd);
struct i2c_client *client = v4l2_get_subdevdata(sd);

if (set_mode_freq(client, t, V4L2_TUNER_RADIO, 0) == -EINVAL)
return 0;
return 0;
}

/*
* Tuner callbacks to handle userspace ioctl's
*/

static int tuner_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
{
struct tuner *t = to_tuner(sd);
Expand Down

0 comments on commit e25d34e

Please sign in to comment.