aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorHans Verkuil <hans.verkuil@cisco.com>2011-06-14 02:56:09 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2011-07-07 14:00:10 -0400
commit4e4a31fb95d88518180517bae3098a23ebde9f9c (patch)
tree2b30f41f3685345c2d4750d73f412ce03329e6ef /drivers
parent98c32bcded0e249fd48726930ae9f393e0e318b4 (diff)
[media] tuner-core: fix s_std and s_tuner
Both s_std and s_tuner are broken because set_mode_freq is called before the new std (for s_std) and audmode (for s_tuner) are set. This patch splits set_mode_freq in a set_mode and a set_freq and in s_std/s_tuner first calls set_mode, and if that returns 0 (i.e. the mode is supported) then they set t->std/t->audmode and call set_freq. This fixes a bug where changing std or audmode would actually change it to the previous value. Discovered while testing analog TV standards for cx18 with a tda18271 tuner. Cc: stable@kernel.org Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/media/video/tuner-core.c59
1 files changed, 31 insertions, 28 deletions
diff --git a/drivers/media/video/tuner-core.c b/drivers/media/video/tuner-core.c
index 9363ed91a4cb..48797045321b 100644
--- a/drivers/media/video/tuner-core.c
+++ b/drivers/media/video/tuner-core.c
@@ -724,19 +724,15 @@ static inline int check_mode(struct tuner *t, enum v4l2_tuner_type mode)
724} 724}
725 725
726/** 726/**
727 * set_mode_freq - Switch tuner to other mode. 727 * set_mode - Switch tuner to other mode.
728 * @client: struct i2c_client pointer
729 * @t: a pointer to the module's internal struct_tuner 728 * @t: a pointer to the module's internal struct_tuner
730 * @mode: enum v4l2_type (radio or TV) 729 * @mode: enum v4l2_type (radio or TV)
731 * @freq: frequency to set (0 means to use the previous one)
732 * 730 *
733 * If tuner doesn't support the needed mode (radio or TV), prints a 731 * If tuner doesn't support the needed mode (radio or TV), prints a
734 * debug message and returns -EINVAL, changing its state to standby. 732 * debug message and returns -EINVAL, changing its state to standby.
735 * Otherwise, changes the state and sets frequency to the last value, if 733 * Otherwise, changes the mode and returns 0.
736 * the tuner can sleep or if it supports both Radio and TV.
737 */ 734 */
738static int set_mode_freq(struct i2c_client *client, struct tuner *t, 735static int set_mode(struct tuner *t, enum v4l2_tuner_type mode)
739 enum v4l2_tuner_type mode, unsigned int freq)
740{ 736{
741 struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops; 737 struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops;
742 738
@@ -752,17 +748,27 @@ static int set_mode_freq(struct i2c_client *client, struct tuner *t,
752 t->mode = mode; 748 t->mode = mode;
753 tuner_dbg("Changing to mode %d\n", mode); 749 tuner_dbg("Changing to mode %d\n", mode);
754 } 750 }
751 return 0;
752}
753
754/**
755 * set_freq - Set the tuner to the desired frequency.
756 * @t: a pointer to the module's internal struct_tuner
757 * @freq: frequency to set (0 means to use the current frequency)
758 */
759static void set_freq(struct tuner *t, unsigned int freq)
760{
761 struct i2c_client *client = v4l2_get_subdevdata(&t->sd);
762
755 if (t->mode == V4L2_TUNER_RADIO) { 763 if (t->mode == V4L2_TUNER_RADIO) {
756 if (freq) 764 if (!freq)
757 t->radio_freq = freq; 765 freq = t->radio_freq;
758 set_radio_freq(client, t->radio_freq); 766 set_radio_freq(client, freq);
759 } else { 767 } else {
760 if (freq) 768 if (!freq)
761 t->tv_freq = freq; 769 freq = t->tv_freq;
762 set_tv_freq(client, t->tv_freq); 770 set_tv_freq(client, freq);
763 } 771 }
764
765 return 0;
766} 772}
767 773
768/* 774/*
@@ -1058,10 +1064,9 @@ static void tuner_status(struct dvb_frontend *fe)
1058static int tuner_s_radio(struct v4l2_subdev *sd) 1064static int tuner_s_radio(struct v4l2_subdev *sd)
1059{ 1065{
1060 struct tuner *t = to_tuner(sd); 1066 struct tuner *t = to_tuner(sd);
1061 struct i2c_client *client = v4l2_get_subdevdata(sd);
1062 1067
1063 if (set_mode_freq(client, t, V4L2_TUNER_RADIO, 0) == -EINVAL) 1068 if (set_mode(t, V4L2_TUNER_RADIO) == 0)
1064 return 0; 1069 set_freq(t, 0);
1065 return 0; 1070 return 0;
1066} 1071}
1067 1072
@@ -1093,25 +1098,22 @@ static int tuner_s_power(struct v4l2_subdev *sd, int on)
1093static int tuner_s_std(struct v4l2_subdev *sd, v4l2_std_id std) 1098static int tuner_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
1094{ 1099{
1095 struct tuner *t = to_tuner(sd); 1100 struct tuner *t = to_tuner(sd);
1096 struct i2c_client *client = v4l2_get_subdevdata(sd);
1097 1101
1098 if (set_mode_freq(client, t, V4L2_TUNER_ANALOG_TV, 0) == -EINVAL) 1102 if (set_mode(t, V4L2_TUNER_ANALOG_TV))
1099 return 0; 1103 return 0;
1100 1104
1101 t->std = std; 1105 t->std = std;
1102 tuner_fixup_std(t); 1106 tuner_fixup_std(t);
1103 1107 set_freq(t, 0);
1104 return 0; 1108 return 0;
1105} 1109}
1106 1110
1107static int tuner_s_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *f) 1111static int tuner_s_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *f)
1108{ 1112{
1109 struct tuner *t = to_tuner(sd); 1113 struct tuner *t = to_tuner(sd);
1110 struct i2c_client *client = v4l2_get_subdevdata(sd);
1111
1112 if (set_mode_freq(client, t, f->type, f->frequency) == -EINVAL)
1113 return 0;
1114 1114
1115 if (set_mode(t, f->type) == 0)
1116 set_freq(t, f->frequency);
1115 return 0; 1117 return 0;
1116} 1118}
1117 1119
@@ -1180,13 +1182,13 @@ static int tuner_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
1180static int tuner_s_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt) 1182static int tuner_s_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
1181{ 1183{
1182 struct tuner *t = to_tuner(sd); 1184 struct tuner *t = to_tuner(sd);
1183 struct i2c_client *client = v4l2_get_subdevdata(sd);
1184 1185
1185 if (set_mode_freq(client, t, vt->type, 0) == -EINVAL) 1186 if (set_mode(t, vt->type))
1186 return 0; 1187 return 0;
1187 1188
1188 if (t->mode == V4L2_TUNER_RADIO) 1189 if (t->mode == V4L2_TUNER_RADIO)
1189 t->audmode = vt->audmode; 1190 t->audmode = vt->audmode;
1191 set_freq(t, 0);
1190 1192
1191 return 0; 1193 return 0;
1192} 1194}
@@ -1221,7 +1223,8 @@ static int tuner_resume(struct i2c_client *c)
1221 tuner_dbg("resume\n"); 1223 tuner_dbg("resume\n");
1222 1224
1223 if (!t->standby) 1225 if (!t->standby)
1224 set_mode_freq(c, t, t->type, 0); 1226 if (set_mode(t, t->type) == 0)
1227 set_freq(t, 0);
1225 1228
1226 return 0; 1229 return 0;
1227} 1230}