aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Krufky <mkrufky@linuxtv.org>2008-04-22 13:41:48 -0400
committerMauro Carvalho Chehab <mchehab@infradead.org>2008-04-24 12:42:21 -0400
commitbe71f7dc73d3afe6d6998a04d5c46d415c3bc62c (patch)
tree10fdf2a46f508e5641596051562780a1c777ec8f
parentff699e6bd02eb1c6d02c7c2b576c2ee6caab201c (diff)
V4L/DVB (7123): tuner-simple: create separate t_params and ranges lookup functions
Move some reuseable code out of simple_set_tv_freq into separate functions. Signed-off-by: Michael Krufky <mkrufky@linuxtv.org> Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
-rw-r--r--drivers/media/video/tuner-simple.c109
1 files changed, 80 insertions, 29 deletions
diff --git a/drivers/media/video/tuner-simple.c b/drivers/media/video/tuner-simple.c
index 770d6281c154..4854fc4a7d39 100644
--- a/drivers/media/video/tuner-simple.c
+++ b/drivers/media/video/tuner-simple.c
@@ -173,6 +173,82 @@ static int simple_get_rf_strength(struct dvb_frontend *fe, u16 *strength)
173 173
174/* ---------------------------------------------------------------------- */ 174/* ---------------------------------------------------------------------- */
175 175
176static inline char *tuner_param_name(enum param_type type)
177{
178 char *name;
179
180 switch (type) {
181 case TUNER_PARAM_TYPE_RADIO:
182 name = "radio";
183 break;
184 case TUNER_PARAM_TYPE_PAL:
185 name = "pal";
186 break;
187 case TUNER_PARAM_TYPE_SECAM:
188 name = "secam";
189 break;
190 case TUNER_PARAM_TYPE_NTSC:
191 name = "ntsc";
192 break;
193 default:
194 name = "unknown";
195 break;
196 }
197 return name;
198}
199
200static struct tuner_params *simple_tuner_params(struct dvb_frontend *fe,
201 enum param_type desired_type)
202{
203 struct tuner_simple_priv *priv = fe->tuner_priv;
204 struct tunertype *tun = priv->tun;
205 int i;
206
207 for (i = 0; i < tun->count; i++)
208 if (desired_type == tun->params[i].type)
209 break;
210
211 /* use default tuner params if desired_type not available */
212 if (i == tun->count) {
213 tuner_dbg("desired params (%s) undefined for tuner %d\n",
214 tuner_param_name(desired_type), priv->type);
215 i = 0;
216 }
217
218 tuner_dbg("using tuner params #%d (%s)\n", i,
219 tuner_param_name(tun->params[i].type));
220
221 return &tun->params[i];
222}
223
224static int simple_config_lookup(struct dvb_frontend *fe,
225 struct tuner_params *t_params,
226 int *frequency, u8 *config, u8 *cb)
227{
228 struct tuner_simple_priv *priv = fe->tuner_priv;
229 int i;
230
231 for (i = 0; i < t_params->count; i++) {
232 if (*frequency > t_params->ranges[i].limit)
233 continue;
234 break;
235 }
236 if (i == t_params->count) {
237 tuner_dbg("frequency out of range (%d > %d)\n",
238 *frequency, t_params->ranges[i - 1].limit);
239 *frequency = t_params->ranges[--i].limit;
240 }
241 *config = t_params->ranges[i].config;
242 *cb = t_params->ranges[i].cb;
243
244 tuner_dbg("freq = %d, range = %d, config = 0x%02x, cb = 0x%02x\n",
245 *frequency, i, *config, *cb);
246
247 return i;
248}
249
250/* ---------------------------------------------------------------------- */
251
176static int simple_set_tv_freq(struct dvb_frontend *fe, 252static int simple_set_tv_freq(struct dvb_frontend *fe,
177 struct analog_parameters *params) 253 struct analog_parameters *params)
178{ 254{
@@ -181,7 +257,7 @@ static int simple_set_tv_freq(struct dvb_frontend *fe,
181 u16 div; 257 u16 div;
182 struct tunertype *tun; 258 struct tunertype *tun;
183 u8 buffer[4]; 259 u8 buffer[4];
184 int rc, IFPCoff, i, j; 260 int rc, IFPCoff, i;
185 enum param_type desired_type; 261 enum param_type desired_type;
186 struct tuner_params *t_params; 262 struct tuner_params *t_params;
187 263
@@ -214,35 +290,10 @@ static int simple_set_tv_freq(struct dvb_frontend *fe,
214 desired_type = TUNER_PARAM_TYPE_PAL; 290 desired_type = TUNER_PARAM_TYPE_PAL;
215 } 291 }
216 292
217 for (j = 0; j < tun->count-1; j++) { 293 t_params = simple_tuner_params(fe, desired_type);
218 if (desired_type != tun->params[j].type)
219 continue;
220 break;
221 }
222 /* use default tuner params if desired_type not available */
223 if (desired_type != tun->params[j].type) {
224 tuner_dbg("IFPCoff = %d: params undefined for tuner %d\n",
225 IFPCoff, priv->type);
226 j = 0;
227 }
228 t_params = &tun->params[j];
229 294
230 for (i = 0; i < t_params->count; i++) { 295 i = simple_config_lookup(fe, t_params, &params->frequency,
231 if (params->frequency > t_params->ranges[i].limit) 296 &config, &cb);
232 continue;
233 break;
234 }
235 if (i == t_params->count) {
236 tuner_dbg("TV frequency out of range (%d > %d)",
237 params->frequency, t_params->ranges[i - 1].limit);
238 params->frequency = t_params->ranges[--i].limit;
239 }
240 config = t_params->ranges[i].config;
241 cb = t_params->ranges[i].cb;
242 /* i == 0 -> VHF_LO
243 * i == 1 -> VHF_HI
244 * i == 2 -> UHF */
245 tuner_dbg("tv: param %d, range %d\n", j, i);
246 297
247 div = params->frequency + IFPCoff + offset; 298 div = params->frequency + IFPCoff + offset;
248 299