From: Mauro Carvalho Chehab <mchehab@redhat.com>
To: unlisted-recipients:; (no To-header on input)@casper.infradead.org
Cc: Linux Media Mailing List <linux-media@vger.kernel.org>
Subject: [PATCH 07/14] [media] tuner-core: Some cleanups at check_mode/set_mode
Date: Mon, 14 Feb 2011 19:03:15 -0200 [thread overview]
Message-ID: <20110214190315.7139dfea@pedra> (raw)
In-Reply-To: <cover.1297716906.git.mchehab@redhat.com>
Properly document those functions and do some cleanups around that.
There's just one behavior change on this patchset: it will now restore
TV frequency when changing from radio to TV mode.
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
diff --git a/drivers/media/video/tuner-core.c b/drivers/media/video/tuner-core.c
index 5c3da21..7cdfe3a 100644
--- a/drivers/media/video/tuner-core.c
+++ b/drivers/media/video/tuner-core.c
@@ -841,38 +841,39 @@ static void set_radio_freq(struct i2c_client *c, unsigned int freq)
analog_ops->set_params(&t->fe, ¶ms);
}
-/*
- * Functions that should be broken into separate radio/TV functions
+/**
+ * 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, char *cmd)
+static inline int check_mode(struct tuner *t)
{
if ((1 << t->mode & t->mode_mask) == 0) {
return -EINVAL;
}
-
- switch (t->mode) {
- case V4L2_TUNER_RADIO:
- tuner_dbg("Cmd %s accepted for radio\n", cmd);
- break;
- case V4L2_TUNER_ANALOG_TV:
- tuner_dbg("Cmd %s accepted for analog TV\n", cmd);
- break;
- case V4L2_TUNER_DIGITAL_TV:
- tuner_dbg("Cmd %s accepted for digital TV\n", cmd);
- break;
- }
return 0;
}
-/*
- * Switch tuner to other mode. If tuner support both tv and radio,
- * set another frequency to some value (This is needed for some pal
- * tuners to avoid locking). Otherwise, just put second tuner in
- * standby mode.
+/**
+ * set_mode - Switch tuner to other mode.
+ * @client - struct i2c_client pointer
+ * @t - a pointer to the module's internal struct_tuner
+ * @mode - enum v4l2_type + T_STANDBY mode
+ * @cmd - string for the command to be executed (for debug messages)
+ *
+ * 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.
*/
-
-static inline int set_mode(struct i2c_client *client, struct tuner *t, int mode, char *cmd)
+static inline int set_mode(struct i2c_client *client, struct tuner *t,
+ int mode, char *cmd)
{
struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops;
@@ -881,7 +882,7 @@ static inline int set_mode(struct i2c_client *client, struct tuner *t, int mode,
t->mode = mode;
- if (check_mode(t, cmd) == -EINVAL) {
+ if (check_mode(t) == -EINVAL) {
tuner_dbg("Tuner doesn't support this mode. "
"Putting tuner to sleep\n");
t->mode = T_STANDBY;
@@ -889,9 +890,22 @@ static inline int set_mode(struct i2c_client *client, struct tuner *t, int mode,
analog_ops->standby(&t->fe);
return -EINVAL;
}
+
+ if (t->mode == V4L2_TUNER_RADIO) {
+ if (t->radio_freq)
+ set_radio_freq(client, t->radio_freq);
+ } else {
+ if (t->tv_freq)
+ set_tv_freq(client, t->tv_freq);
+ }
+
return 0;
}
+/*
+ * Functions that should be broken into separate radio/TV functions
+ */
+
static void set_freq(struct i2c_client *c, unsigned long freq)
{
struct tuner *t = to_tuner(i2c_get_clientdata(c));
@@ -959,7 +973,7 @@ static int tuner_s_power(struct v4l2_subdev *sd, int on)
tuner_dbg("Putting tuner to sleep\n");
- if (check_mode(t, "s_power") == -EINVAL)
+ if (check_mode(t) == -EINVAL)
return 0;
t->mode = T_STANDBY;
if (analog_ops->standby)
@@ -977,8 +991,6 @@ static int tuner_s_radio(struct v4l2_subdev *sd)
if (set_mode(client, t, V4L2_TUNER_RADIO, "s_radio") == -EINVAL)
return 0;
- if (t->radio_freq)
- set_freq(client, t->radio_freq);
return 0;
}
@@ -1017,7 +1029,7 @@ static int tuner_g_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *f)
struct tuner *t = to_tuner(sd);
struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops;
- if (check_mode(t, "g_frequency") == -EINVAL)
+ if (check_mode(t) == -EINVAL)
return 0;
f->type = t->mode;
if (fe_tuner_ops->get_frequency) {
@@ -1040,7 +1052,7 @@ static int tuner_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops;
struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops;
- if (check_mode(t, "g_tuner") == -EINVAL)
+ if (check_mode(t) == -EINVAL)
return 0;
vt->type = t->mode;
@@ -1081,7 +1093,7 @@ static int tuner_s_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
struct tuner *t = to_tuner(sd);
struct i2c_client *client = v4l2_get_subdevdata(sd);
- if (check_mode(t, "s_tuner") == -EINVAL)
+ if (check_mode(t) == -EINVAL)
return 0;
/* do nothing unless we're a radio tuner */
--
1.7.1
next prev parent reply other threads:[~2011-02-14 21:07 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <cover.1297716906.git.mchehab@redhat.com>
2011-02-14 21:03 ` [PATCH 03/14] [media] tuner-core: Remove V4L1/V4L2 API switch Mauro Carvalho Chehab
2011-02-14 21:03 ` [PATCH 04/14] [media] tuner-core: remove the legacy is_stereo() call Mauro Carvalho Chehab
2011-02-14 21:03 ` [PATCH 05/14] [media] tuner-core: move some messages to the proper place Mauro Carvalho Chehab
2011-02-14 21:03 ` [PATCH 06/14] [media] tuner-core: Reorganize the functions internally Mauro Carvalho Chehab
2011-02-14 21:03 ` Mauro Carvalho Chehab [this message]
2011-02-14 21:03 ` [PATCH 09/14] [media] tuner-core: do the right thing for suspend/resume Mauro Carvalho Chehab
2011-02-14 21:03 ` [PATCH 08/14] [media] tuner-core: Better implement standby mode Mauro Carvalho Chehab
2011-02-14 21:03 ` [PATCH 10/14] [media] tuner-core: CodingStyle cleanups Mauro Carvalho Chehab
2011-02-14 21:03 ` [PATCH 11/14] [media] tuner-core: Don't use a static var for xc5000_cfg Mauro Carvalho Chehab
2011-02-14 21:03 ` [PATCH 01/14] [media] cx88: use unlocked_ioctl for cx88-video Mauro Carvalho Chehab
2011-02-14 21:03 ` [PATCH 02/14] [media] cx88: Don't allow opening a device while it is not ready Mauro Carvalho Chehab
2011-02-14 21:03 ` [PATCH 14/14] [media] Remove the remaining usages for T_STANDBY Mauro Carvalho Chehab
2011-02-14 21:03 ` [PATCH 12/14] [media] tuner-core: dead code removal Mauro Carvalho Chehab
2011-02-14 21:03 ` [PATCH 13/14] [media] tuner-core: Fix a few comments on it Mauro Carvalho Chehab
2011-02-14 21:49 ` [PATCH 01/14] [media] cx88: use unlocked_ioctl for cx88-video Mauro Carvalho Chehab
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110214190315.7139dfea@pedra \
--to=mchehab@redhat.com \
--cc=linux-media@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox