aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/tuner-simple.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/video/tuner-simple.c')
-rw-r--r--drivers/media/video/tuner-simple.c861
1 files changed, 651 insertions, 210 deletions
diff --git a/drivers/media/video/tuner-simple.c b/drivers/media/video/tuner-simple.c
index c1db576696c6..be8d903171b7 100644
--- a/drivers/media/video/tuner-simple.c
+++ b/drivers/media/video/tuner-simple.c
@@ -13,15 +13,25 @@
13#include "tuner-i2c.h" 13#include "tuner-i2c.h"
14#include "tuner-simple.h" 14#include "tuner-simple.h"
15 15
16static int debug = 0; 16static int debug;
17module_param(debug, int, 0644); 17module_param(debug, int, 0644);
18MODULE_PARM_DESC(debug, "enable verbose debug messages"); 18MODULE_PARM_DESC(debug, "enable verbose debug messages");
19 19
20#define PREFIX "tuner-simple" 20#define TUNER_SIMPLE_MAX 64
21static unsigned int simple_devcount;
21 22
22static int offset = 0; 23static int offset;
23module_param(offset, int, 0664); 24module_param(offset, int, 0664);
24MODULE_PARM_DESC(offset,"Allows to specify an offset for tuner"); 25MODULE_PARM_DESC(offset, "Allows to specify an offset for tuner");
26
27static unsigned int atv_input[TUNER_SIMPLE_MAX] = \
28 { [0 ... (TUNER_SIMPLE_MAX-1)] = 0 };
29static unsigned int dtv_input[TUNER_SIMPLE_MAX] = \
30 { [0 ... (TUNER_SIMPLE_MAX-1)] = 0 };
31module_param_array(atv_input, int, NULL, 0644);
32module_param_array(dtv_input, int, NULL, 0644);
33MODULE_PARM_DESC(atv_input, "specify atv rf input, 0 for autoselect");
34MODULE_PARM_DESC(dtv_input, "specify dtv rf input, 0 for autoselect");
25 35
26/* ---------------------------------------------------------------------- */ 36/* ---------------------------------------------------------------------- */
27 37
@@ -36,8 +46,8 @@ MODULE_PARM_DESC(offset,"Allows to specify an offset for tuner");
36 */ 46 */
37#define TEMIC_SET_PAL_I 0x05 47#define TEMIC_SET_PAL_I 0x05
38#define TEMIC_SET_PAL_DK 0x09 48#define TEMIC_SET_PAL_DK 0x09
39#define TEMIC_SET_PAL_L 0x0a // SECAM ? 49#define TEMIC_SET_PAL_L 0x0a /* SECAM ? */
40#define TEMIC_SET_PAL_L2 0x0b // change IF ! 50#define TEMIC_SET_PAL_L2 0x0b /* change IF ! */
41#define TEMIC_SET_PAL_BG 0x0c 51#define TEMIC_SET_PAL_BG 0x0c
42 52
43/* tv tuner system standard selection for Philips FQ1216ME 53/* tv tuner system standard selection for Philips FQ1216ME
@@ -90,14 +100,21 @@ MODULE_PARM_DESC(offset,"Allows to specify an offset for tuner");
90#define TUNER_PLL_LOCKED 0x40 100#define TUNER_PLL_LOCKED 0x40
91#define TUNER_STEREO_MK3 0x04 101#define TUNER_STEREO_MK3 0x04
92 102
103static DEFINE_MUTEX(tuner_simple_list_mutex);
104static LIST_HEAD(hybrid_tuner_instance_list);
105
93struct tuner_simple_priv { 106struct tuner_simple_priv {
107 unsigned int nr;
94 u16 last_div; 108 u16 last_div;
109
95 struct tuner_i2c_props i2c_props; 110 struct tuner_i2c_props i2c_props;
111 struct list_head hybrid_tuner_instance_list;
96 112
97 unsigned int type; 113 unsigned int type;
98 struct tunertype *tun; 114 struct tunertype *tun;
99 115
100 u32 frequency; 116 u32 frequency;
117 u32 bandwidth;
101}; 118};
102 119
103/* ---------------------------------------------------------------------- */ 120/* ---------------------------------------------------------------------- */
@@ -107,7 +124,7 @@ static int tuner_read_status(struct dvb_frontend *fe)
107 struct tuner_simple_priv *priv = fe->tuner_priv; 124 struct tuner_simple_priv *priv = fe->tuner_priv;
108 unsigned char byte; 125 unsigned char byte;
109 126
110 if (1 != tuner_i2c_xfer_recv(&priv->i2c_props,&byte,1)) 127 if (1 != tuner_i2c_xfer_recv(&priv->i2c_props, &byte, 1))
111 return 0; 128 return 0;
112 129
113 return byte; 130 return byte;
@@ -121,13 +138,13 @@ static inline int tuner_signal(const int status)
121static inline int tuner_stereo(const int type, const int status) 138static inline int tuner_stereo(const int type, const int status)
122{ 139{
123 switch (type) { 140 switch (type) {
124 case TUNER_PHILIPS_FM1216ME_MK3: 141 case TUNER_PHILIPS_FM1216ME_MK3:
125 case TUNER_PHILIPS_FM1236_MK3: 142 case TUNER_PHILIPS_FM1236_MK3:
126 case TUNER_PHILIPS_FM1256_IH3: 143 case TUNER_PHILIPS_FM1256_IH3:
127 case TUNER_LG_NTSC_TAPE: 144 case TUNER_LG_NTSC_TAPE:
128 return ((status & TUNER_SIGNAL) == TUNER_STEREO_MK3); 145 return ((status & TUNER_SIGNAL) == TUNER_STEREO_MK3);
129 default: 146 default:
130 return status & TUNER_STEREO; 147 return status & TUNER_STEREO;
131 } 148 }
132} 149}
133 150
@@ -145,7 +162,12 @@ static inline int tuner_afcstatus(const int status)
145static int simple_get_status(struct dvb_frontend *fe, u32 *status) 162static int simple_get_status(struct dvb_frontend *fe, u32 *status)
146{ 163{
147 struct tuner_simple_priv *priv = fe->tuner_priv; 164 struct tuner_simple_priv *priv = fe->tuner_priv;
148 int tuner_status = tuner_read_status(fe); 165 int tuner_status;
166
167 if (priv->i2c_props.adap == NULL)
168 return -EINVAL;
169
170 tuner_status = tuner_read_status(fe);
149 171
150 *status = 0; 172 *status = 0;
151 173
@@ -162,7 +184,12 @@ static int simple_get_status(struct dvb_frontend *fe, u32 *status)
162static int simple_get_rf_strength(struct dvb_frontend *fe, u16 *strength) 184static int simple_get_rf_strength(struct dvb_frontend *fe, u16 *strength)
163{ 185{
164 struct tuner_simple_priv *priv = fe->tuner_priv; 186 struct tuner_simple_priv *priv = fe->tuner_priv;
165 int signal = tuner_signal(tuner_read_status(fe)); 187 int signal;
188
189 if (priv->i2c_props.adap == NULL)
190 return -EINVAL;
191
192 signal = tuner_signal(tuner_read_status(fe));
166 193
167 *strength = signal; 194 *strength = signal;
168 195
@@ -173,174 +200,378 @@ static int simple_get_rf_strength(struct dvb_frontend *fe, u16 *strength)
173 200
174/* ---------------------------------------------------------------------- */ 201/* ---------------------------------------------------------------------- */
175 202
176static int simple_set_tv_freq(struct dvb_frontend *fe, 203static inline char *tuner_param_name(enum param_type type)
177 struct analog_parameters *params)
178{ 204{
179 struct tuner_simple_priv *priv = fe->tuner_priv; 205 char *name;
180 u8 config, cb, tuneraddr;
181 u16 div;
182 struct tunertype *tun;
183 u8 buffer[4];
184 int rc, IFPCoff, i, j;
185 enum param_type desired_type;
186 struct tuner_params *t_params;
187 206
188 tun = priv->tun; 207 switch (type) {
208 case TUNER_PARAM_TYPE_RADIO:
209 name = "radio";
210 break;
211 case TUNER_PARAM_TYPE_PAL:
212 name = "pal";
213 break;
214 case TUNER_PARAM_TYPE_SECAM:
215 name = "secam";
216 break;
217 case TUNER_PARAM_TYPE_NTSC:
218 name = "ntsc";
219 break;
220 case TUNER_PARAM_TYPE_DIGITAL:
221 name = "digital";
222 break;
223 default:
224 name = "unknown";
225 break;
226 }
227 return name;
228}
189 229
190 /* IFPCoff = Video Intermediate Frequency - Vif: 230static struct tuner_params *simple_tuner_params(struct dvb_frontend *fe,
191 940 =16*58.75 NTSC/J (Japan) 231 enum param_type desired_type)
192 732 =16*45.75 M/N STD 232{
193 704 =16*44 ATSC (at DVB code) 233 struct tuner_simple_priv *priv = fe->tuner_priv;
194 632 =16*39.50 I U.K. 234 struct tunertype *tun = priv->tun;
195 622.4=16*38.90 B/G D/K I, L STD 235 int i;
196 592 =16*37.00 D China
197 590 =16.36.875 B Australia
198 543.2=16*33.95 L' STD
199 171.2=16*10.70 FM Radio (at set_radio_freq)
200 */
201 236
202 if (params->std == V4L2_STD_NTSC_M_JP) { 237 for (i = 0; i < tun->count; i++)
203 IFPCoff = 940; 238 if (desired_type == tun->params[i].type)
204 desired_type = TUNER_PARAM_TYPE_NTSC; 239 break;
205 } else if ((params->std & V4L2_STD_MN) &&
206 !(params->std & ~V4L2_STD_MN)) {
207 IFPCoff = 732;
208 desired_type = TUNER_PARAM_TYPE_NTSC;
209 } else if (params->std == V4L2_STD_SECAM_LC) {
210 IFPCoff = 543;
211 desired_type = TUNER_PARAM_TYPE_SECAM;
212 } else {
213 IFPCoff = 623;
214 desired_type = TUNER_PARAM_TYPE_PAL;
215 }
216 240
217 for (j = 0; j < tun->count-1; j++) { 241 /* use default tuner params if desired_type not available */
218 if (desired_type != tun->params[j].type) 242 if (i == tun->count) {
219 continue; 243 tuner_dbg("desired params (%s) undefined for tuner %d\n",
220 break; 244 tuner_param_name(desired_type), priv->type);
221 } 245 i = 0;
222 /* use default tuner_t_params if desired_type not available */
223 if (desired_type != tun->params[j].type) {
224 tuner_dbg("IFPCoff = %d: tuner_t_params undefined for tuner %d\n",
225 IFPCoff, priv->type);
226 j = 0;
227 } 246 }
228 t_params = &tun->params[j]; 247
248 tuner_dbg("using tuner params #%d (%s)\n", i,
249 tuner_param_name(tun->params[i].type));
250
251 return &tun->params[i];
252}
253
254static int simple_config_lookup(struct dvb_frontend *fe,
255 struct tuner_params *t_params,
256 int *frequency, u8 *config, u8 *cb)
257{
258 struct tuner_simple_priv *priv = fe->tuner_priv;
259 int i;
229 260
230 for (i = 0; i < t_params->count; i++) { 261 for (i = 0; i < t_params->count; i++) {
231 if (params->frequency > t_params->ranges[i].limit) 262 if (*frequency > t_params->ranges[i].limit)
232 continue; 263 continue;
233 break; 264 break;
234 } 265 }
235 if (i == t_params->count) { 266 if (i == t_params->count) {
236 tuner_dbg("TV frequency out of range (%d > %d)", 267 tuner_dbg("frequency out of range (%d > %d)\n",
237 params->frequency, t_params->ranges[i - 1].limit); 268 *frequency, t_params->ranges[i - 1].limit);
238 params->frequency = t_params->ranges[--i].limit; 269 *frequency = t_params->ranges[--i].limit;
239 } 270 }
240 config = t_params->ranges[i].config; 271 *config = t_params->ranges[i].config;
241 cb = t_params->ranges[i].cb; 272 *cb = t_params->ranges[i].cb;
242 /* i == 0 -> VHF_LO 273
243 * i == 1 -> VHF_HI 274 tuner_dbg("freq = %d.%02d (%d), range = %d, "
244 * i == 2 -> UHF */ 275 "config = 0x%02x, cb = 0x%02x\n",
245 tuner_dbg("tv: param %d, range %d\n",j,i); 276 *frequency / 16, *frequency % 16 * 100 / 16, *frequency,
277 i, *config, *cb);
278
279 return i;
280}
281
282/* ---------------------------------------------------------------------- */
283
284static void simple_set_rf_input(struct dvb_frontend *fe,
285 u8 *config, u8 *cb, unsigned int rf)
286{
287 struct tuner_simple_priv *priv = fe->tuner_priv;
246 288
247 div=params->frequency + IFPCoff + offset; 289 switch (priv->type) {
290 case TUNER_PHILIPS_TUV1236D:
291 switch (rf) {
292 case 1:
293 *cb |= 0x08;
294 break;
295 default:
296 *cb &= ~0x08;
297 break;
298 }
299 break;
300 case TUNER_PHILIPS_FCV1236D:
301 switch (rf) {
302 case 1:
303 *cb |= 0x01;
304 break;
305 default:
306 *cb &= ~0x01;
307 break;
308 }
309 break;
310 default:
311 break;
312 }
313}
248 314
249 tuner_dbg("Freq= %d.%02d MHz, V_IF=%d.%02d MHz, Offset=%d.%02d MHz, div=%0d\n", 315static int simple_std_setup(struct dvb_frontend *fe,
250 params->frequency / 16, params->frequency % 16 * 100 / 16, 316 struct analog_parameters *params,
251 IFPCoff / 16, IFPCoff % 16 * 100 / 16, 317 u8 *config, u8 *cb)
252 offset / 16, offset % 16 * 100 / 16, 318{
253 div); 319 struct tuner_simple_priv *priv = fe->tuner_priv;
320 u8 tuneraddr;
321 int rc;
254 322
255 /* tv norm specific stuff for multi-norm tuners */ 323 /* tv norm specific stuff for multi-norm tuners */
256 switch (priv->type) { 324 switch (priv->type) {
257 case TUNER_PHILIPS_SECAM: // FI1216MF 325 case TUNER_PHILIPS_SECAM: /* FI1216MF */
258 /* 0x01 -> ??? no change ??? */ 326 /* 0x01 -> ??? no change ??? */
259 /* 0x02 -> PAL BDGHI / SECAM L */ 327 /* 0x02 -> PAL BDGHI / SECAM L */
260 /* 0x04 -> ??? PAL others / SECAM others ??? */ 328 /* 0x04 -> ??? PAL others / SECAM others ??? */
261 cb &= ~0x03; 329 *cb &= ~0x03;
262 if (params->std & V4L2_STD_SECAM_L) //also valid for V4L2_STD_SECAM 330 if (params->std & V4L2_STD_SECAM_L)
263 cb |= PHILIPS_MF_SET_STD_L; 331 /* also valid for V4L2_STD_SECAM */
332 *cb |= PHILIPS_MF_SET_STD_L;
264 else if (params->std & V4L2_STD_SECAM_LC) 333 else if (params->std & V4L2_STD_SECAM_LC)
265 cb |= PHILIPS_MF_SET_STD_LC; 334 *cb |= PHILIPS_MF_SET_STD_LC;
266 else /* V4L2_STD_B|V4L2_STD_GH */ 335 else /* V4L2_STD_B|V4L2_STD_GH */
267 cb |= PHILIPS_MF_SET_STD_BG; 336 *cb |= PHILIPS_MF_SET_STD_BG;
268 break; 337 break;
269 338
270 case TUNER_TEMIC_4046FM5: 339 case TUNER_TEMIC_4046FM5:
271 cb &= ~0x0f; 340 *cb &= ~0x0f;
272 341
273 if (params->std & V4L2_STD_PAL_BG) { 342 if (params->std & V4L2_STD_PAL_BG) {
274 cb |= TEMIC_SET_PAL_BG; 343 *cb |= TEMIC_SET_PAL_BG;
275 344
276 } else if (params->std & V4L2_STD_PAL_I) { 345 } else if (params->std & V4L2_STD_PAL_I) {
277 cb |= TEMIC_SET_PAL_I; 346 *cb |= TEMIC_SET_PAL_I;
278 347
279 } else if (params->std & V4L2_STD_PAL_DK) { 348 } else if (params->std & V4L2_STD_PAL_DK) {
280 cb |= TEMIC_SET_PAL_DK; 349 *cb |= TEMIC_SET_PAL_DK;
281 350
282 } else if (params->std & V4L2_STD_SECAM_L) { 351 } else if (params->std & V4L2_STD_SECAM_L) {
283 cb |= TEMIC_SET_PAL_L; 352 *cb |= TEMIC_SET_PAL_L;
284 353
285 } 354 }
286 break; 355 break;
287 356
288 case TUNER_PHILIPS_FQ1216ME: 357 case TUNER_PHILIPS_FQ1216ME:
289 cb &= ~0x0f; 358 *cb &= ~0x0f;
290 359
291 if (params->std & (V4L2_STD_PAL_BG|V4L2_STD_PAL_DK)) { 360 if (params->std & (V4L2_STD_PAL_BG|V4L2_STD_PAL_DK)) {
292 cb |= PHILIPS_SET_PAL_BGDK; 361 *cb |= PHILIPS_SET_PAL_BGDK;
293 362
294 } else if (params->std & V4L2_STD_PAL_I) { 363 } else if (params->std & V4L2_STD_PAL_I) {
295 cb |= PHILIPS_SET_PAL_I; 364 *cb |= PHILIPS_SET_PAL_I;
296 365
297 } else if (params->std & V4L2_STD_SECAM_L) { 366 } else if (params->std & V4L2_STD_SECAM_L) {
298 cb |= PHILIPS_SET_PAL_L; 367 *cb |= PHILIPS_SET_PAL_L;
299 368
300 } 369 }
301 break; 370 break;
302 371
303 case TUNER_PHILIPS_ATSC: 372 case TUNER_PHILIPS_FCV1236D:
304 /* 0x00 -> ATSC antenna input 1 */ 373 /* 0x00 -> ATSC antenna input 1 */
305 /* 0x01 -> ATSC antenna input 2 */ 374 /* 0x01 -> ATSC antenna input 2 */
306 /* 0x02 -> NTSC antenna input 1 */ 375 /* 0x02 -> NTSC antenna input 1 */
307 /* 0x03 -> NTSC antenna input 2 */ 376 /* 0x03 -> NTSC antenna input 2 */
308 cb &= ~0x03; 377 *cb &= ~0x03;
309 if (!(params->std & V4L2_STD_ATSC)) 378 if (!(params->std & V4L2_STD_ATSC))
310 cb |= 2; 379 *cb |= 2;
311 /* FIXME: input */
312 break; 380 break;
313 381
314 case TUNER_MICROTUNE_4042FI5: 382 case TUNER_MICROTUNE_4042FI5:
315 /* Set the charge pump for fast tuning */ 383 /* Set the charge pump for fast tuning */
316 config |= TUNER_CHARGE_PUMP; 384 *config |= TUNER_CHARGE_PUMP;
317 break; 385 break;
318 386
319 case TUNER_PHILIPS_TUV1236D: 387 case TUNER_PHILIPS_TUV1236D:
388 {
320 /* 0x40 -> ATSC antenna input 1 */ 389 /* 0x40 -> ATSC antenna input 1 */
321 /* 0x48 -> ATSC antenna input 2 */ 390 /* 0x48 -> ATSC antenna input 2 */
322 /* 0x00 -> NTSC antenna input 1 */ 391 /* 0x00 -> NTSC antenna input 1 */
323 /* 0x08 -> NTSC antenna input 2 */ 392 /* 0x08 -> NTSC antenna input 2 */
324 buffer[0] = 0x14; 393 u8 buffer[4] = { 0x14, 0x00, 0x17, 0x00};
325 buffer[1] = 0x00; 394 *cb &= ~0x40;
326 buffer[2] = 0x17;
327 buffer[3] = 0x00;
328 cb &= ~0x40;
329 if (params->std & V4L2_STD_ATSC) { 395 if (params->std & V4L2_STD_ATSC) {
330 cb |= 0x40; 396 *cb |= 0x40;
331 buffer[1] = 0x04; 397 buffer[1] = 0x04;
332 } 398 }
333 /* set to the correct mode (analog or digital) */ 399 /* set to the correct mode (analog or digital) */
334 tuneraddr = priv->i2c_props.addr; 400 tuneraddr = priv->i2c_props.addr;
335 priv->i2c_props.addr = 0x0a; 401 priv->i2c_props.addr = 0x0a;
336 if (2 != (rc = tuner_i2c_xfer_send(&priv->i2c_props,&buffer[0],2))) 402 rc = tuner_i2c_xfer_send(&priv->i2c_props, &buffer[0], 2);
337 tuner_warn("i2c i/o error: rc == %d (should be 2)\n",rc); 403 if (2 != rc)
338 if (2 != (rc = tuner_i2c_xfer_send(&priv->i2c_props,&buffer[2],2))) 404 tuner_warn("i2c i/o error: rc == %d "
339 tuner_warn("i2c i/o error: rc == %d (should be 2)\n",rc); 405 "(should be 2)\n", rc);
406 rc = tuner_i2c_xfer_send(&priv->i2c_props, &buffer[2], 2);
407 if (2 != rc)
408 tuner_warn("i2c i/o error: rc == %d "
409 "(should be 2)\n", rc);
340 priv->i2c_props.addr = tuneraddr; 410 priv->i2c_props.addr = tuneraddr;
341 /* FIXME: input */
342 break; 411 break;
343 } 412 }
413 }
414 if (atv_input[priv->nr])
415 simple_set_rf_input(fe, config, cb, atv_input[priv->nr]);
416
417 return 0;
418}
419
420static int simple_post_tune(struct dvb_frontend *fe, u8 *buffer,
421 u16 div, u8 config, u8 cb)
422{
423 struct tuner_simple_priv *priv = fe->tuner_priv;
424 int rc;
425
426 switch (priv->type) {
427 case TUNER_LG_TDVS_H06XF:
428 /* Set the Auxiliary Byte. */
429 buffer[0] = buffer[2];
430 buffer[0] &= ~0x20;
431 buffer[0] |= 0x18;
432 buffer[1] = 0x20;
433 tuner_dbg("tv 0x%02x 0x%02x\n", buffer[0], buffer[1]);
434
435 rc = tuner_i2c_xfer_send(&priv->i2c_props, buffer, 2);
436 if (2 != rc)
437 tuner_warn("i2c i/o error: rc == %d "
438 "(should be 2)\n", rc);
439 break;
440 case TUNER_MICROTUNE_4042FI5:
441 {
442 /* FIXME - this may also work for other tuners */
443 unsigned long timeout = jiffies + msecs_to_jiffies(1);
444 u8 status_byte = 0;
445
446 /* Wait until the PLL locks */
447 for (;;) {
448 if (time_after(jiffies, timeout))
449 return 0;
450 rc = tuner_i2c_xfer_recv(&priv->i2c_props,
451 &status_byte, 1);
452 if (1 != rc) {
453 tuner_warn("i2c i/o read error: rc == %d "
454 "(should be 1)\n", rc);
455 break;
456 }
457 if (status_byte & TUNER_PLL_LOCKED)
458 break;
459 udelay(10);
460 }
461
462 /* Set the charge pump for optimized phase noise figure */
463 config &= ~TUNER_CHARGE_PUMP;
464 buffer[0] = (div>>8) & 0x7f;
465 buffer[1] = div & 0xff;
466 buffer[2] = config;
467 buffer[3] = cb;
468 tuner_dbg("tv 0x%02x 0x%02x 0x%02x 0x%02x\n",
469 buffer[0], buffer[1], buffer[2], buffer[3]);
470
471 rc = tuner_i2c_xfer_send(&priv->i2c_props, buffer, 4);
472 if (4 != rc)
473 tuner_warn("i2c i/o error: rc == %d "
474 "(should be 4)\n", rc);
475 break;
476 }
477 }
478
479 return 0;
480}
481
482static int simple_radio_bandswitch(struct dvb_frontend *fe, u8 *buffer)
483{
484 struct tuner_simple_priv *priv = fe->tuner_priv;
485
486 switch (priv->type) {
487 case TUNER_TENA_9533_DI:
488 case TUNER_YMEC_TVF_5533MF:
489 tuner_dbg("This tuner doesn't have FM. "
490 "Most cards have a TEA5767 for FM\n");
491 return 0;
492 case TUNER_PHILIPS_FM1216ME_MK3:
493 case TUNER_PHILIPS_FM1236_MK3:
494 case TUNER_PHILIPS_FMD1216ME_MK3:
495 case TUNER_LG_NTSC_TAPE:
496 case TUNER_PHILIPS_FM1256_IH3:
497 buffer[3] = 0x19;
498 break;
499 case TUNER_TNF_5335MF:
500 buffer[3] = 0x11;
501 break;
502 case TUNER_LG_PAL_FM:
503 buffer[3] = 0xa5;
504 break;
505 case TUNER_THOMSON_DTT761X:
506 buffer[3] = 0x39;
507 break;
508 case TUNER_MICROTUNE_4049FM5:
509 default:
510 buffer[3] = 0xa4;
511 break;
512 }
513
514 return 0;
515}
516
517/* ---------------------------------------------------------------------- */
518
519static int simple_set_tv_freq(struct dvb_frontend *fe,
520 struct analog_parameters *params)
521{
522 struct tuner_simple_priv *priv = fe->tuner_priv;
523 u8 config, cb;
524 u16 div;
525 struct tunertype *tun;
526 u8 buffer[4];
527 int rc, IFPCoff, i;
528 enum param_type desired_type;
529 struct tuner_params *t_params;
530
531 tun = priv->tun;
532
533 /* IFPCoff = Video Intermediate Frequency - Vif:
534 940 =16*58.75 NTSC/J (Japan)
535 732 =16*45.75 M/N STD
536 704 =16*44 ATSC (at DVB code)
537 632 =16*39.50 I U.K.
538 622.4=16*38.90 B/G D/K I, L STD
539 592 =16*37.00 D China
540 590 =16.36.875 B Australia
541 543.2=16*33.95 L' STD
542 171.2=16*10.70 FM Radio (at set_radio_freq)
543 */
544
545 if (params->std == V4L2_STD_NTSC_M_JP) {
546 IFPCoff = 940;
547 desired_type = TUNER_PARAM_TYPE_NTSC;
548 } else if ((params->std & V4L2_STD_MN) &&
549 !(params->std & ~V4L2_STD_MN)) {
550 IFPCoff = 732;
551 desired_type = TUNER_PARAM_TYPE_NTSC;
552 } else if (params->std == V4L2_STD_SECAM_LC) {
553 IFPCoff = 543;
554 desired_type = TUNER_PARAM_TYPE_SECAM;
555 } else {
556 IFPCoff = 623;
557 desired_type = TUNER_PARAM_TYPE_PAL;
558 }
559
560 t_params = simple_tuner_params(fe, desired_type);
561
562 i = simple_config_lookup(fe, t_params, &params->frequency,
563 &config, &cb);
564
565 div = params->frequency + IFPCoff + offset;
566
567 tuner_dbg("Freq= %d.%02d MHz, V_IF=%d.%02d MHz, "
568 "Offset=%d.%02d MHz, div=%0d\n",
569 params->frequency / 16, params->frequency % 16 * 100 / 16,
570 IFPCoff / 16, IFPCoff % 16 * 100 / 16,
571 offset / 16, offset % 16 * 100 / 16, div);
572
573 /* tv norm specific stuff for multi-norm tuners */
574 simple_std_setup(fe, params, &config, &cb);
344 575
345 if (t_params->cb_first_if_lower_freq && div < priv->last_div) { 576 if (t_params->cb_first_if_lower_freq && div < priv->last_div) {
346 buffer[0] = config; 577 buffer[0] = config;
@@ -357,8 +588,10 @@ static int simple_set_tv_freq(struct dvb_frontend *fe,
357 if (t_params->has_tda9887) { 588 if (t_params->has_tda9887) {
358 struct v4l2_priv_tun_config tda9887_cfg; 589 struct v4l2_priv_tun_config tda9887_cfg;
359 int config = 0; 590 int config = 0;
360 int is_secam_l = (params->std & (V4L2_STD_SECAM_L | V4L2_STD_SECAM_LC)) && 591 int is_secam_l = (params->std & (V4L2_STD_SECAM_L |
361 !(params->std & ~(V4L2_STD_SECAM_L | V4L2_STD_SECAM_LC)); 592 V4L2_STD_SECAM_LC)) &&
593 !(params->std & ~(V4L2_STD_SECAM_L |
594 V4L2_STD_SECAM_LC));
362 595
363 tda9887_cfg.tuner = TUNER_TDA9887; 596 tda9887_cfg.tuner = TUNER_TDA9887;
364 tda9887_cfg.priv = &config; 597 tda9887_cfg.priv = &config;
@@ -368,8 +601,7 @@ static int simple_set_tv_freq(struct dvb_frontend *fe,
368 config |= TDA9887_PORT1_ACTIVE; 601 config |= TDA9887_PORT1_ACTIVE;
369 if (t_params->port2_active ^ t_params->port2_invert_for_secam_lc) 602 if (t_params->port2_active ^ t_params->port2_invert_for_secam_lc)
370 config |= TDA9887_PORT2_ACTIVE; 603 config |= TDA9887_PORT2_ACTIVE;
371 } 604 } else {
372 else {
373 if (t_params->port1_active) 605 if (t_params->port1_active)
374 config |= TDA9887_PORT1_ACTIVE; 606 config |= TDA9887_PORT1_ACTIVE;
375 if (t_params->port2_active) 607 if (t_params->port2_active)
@@ -384,8 +616,7 @@ static int simple_set_tv_freq(struct dvb_frontend *fe,
384 config |= TDA9887_TOP(t_params->default_top_secam_mid); 616 config |= TDA9887_TOP(t_params->default_top_secam_mid);
385 else if (t_params->default_top_secam_high) 617 else if (t_params->default_top_secam_high)
386 config |= TDA9887_TOP(t_params->default_top_secam_high); 618 config |= TDA9887_TOP(t_params->default_top_secam_high);
387 } 619 } else {
388 else {
389 if (i == 0 && t_params->default_top_low) 620 if (i == 0 && t_params->default_top_low)
390 config |= TDA9887_TOP(t_params->default_top_low); 621 config |= TDA9887_TOP(t_params->default_top_low);
391 else if (i == 1 && t_params->default_top_mid) 622 else if (i == 1 && t_params->default_top_mid)
@@ -399,56 +630,14 @@ static int simple_set_tv_freq(struct dvb_frontend *fe,
399 &tda9887_cfg); 630 &tda9887_cfg);
400 } 631 }
401 tuner_dbg("tv 0x%02x 0x%02x 0x%02x 0x%02x\n", 632 tuner_dbg("tv 0x%02x 0x%02x 0x%02x 0x%02x\n",
402 buffer[0],buffer[1],buffer[2],buffer[3]); 633 buffer[0], buffer[1], buffer[2], buffer[3]);
403
404 if (4 != (rc = tuner_i2c_xfer_send(&priv->i2c_props,buffer,4)))
405 tuner_warn("i2c i/o error: rc == %d (should be 4)\n",rc);
406
407 switch (priv->type) {
408 case TUNER_LG_TDVS_H06XF:
409 /* Set the Auxiliary Byte. */
410 buffer[0] = buffer[2];
411 buffer[0] &= ~0x20;
412 buffer[0] |= 0x18;
413 buffer[1] = 0x20;
414 tuner_dbg("tv 0x%02x 0x%02x\n",buffer[0],buffer[1]);
415
416 if (2 != (rc = tuner_i2c_xfer_send(&priv->i2c_props,buffer,2)))
417 tuner_warn("i2c i/o error: rc == %d (should be 2)\n",rc);
418 break;
419 case TUNER_MICROTUNE_4042FI5:
420 {
421 // FIXME - this may also work for other tuners
422 unsigned long timeout = jiffies + msecs_to_jiffies(1);
423 u8 status_byte = 0;
424 634
425 /* Wait until the PLL locks */ 635 rc = tuner_i2c_xfer_send(&priv->i2c_props, buffer, 4);
426 for (;;) { 636 if (4 != rc)
427 if (time_after(jiffies,timeout)) 637 tuner_warn("i2c i/o error: rc == %d (should be 4)\n", rc);
428 return 0;
429 if (1 != (rc = tuner_i2c_xfer_recv(&priv->i2c_props,&status_byte,1))) {
430 tuner_warn("i2c i/o read error: rc == %d (should be 1)\n",rc);
431 break;
432 }
433 if (status_byte & TUNER_PLL_LOCKED)
434 break;
435 udelay(10);
436 }
437 638
438 /* Set the charge pump for optimized phase noise figure */ 639 simple_post_tune(fe, &buffer[0], div, config, cb);
439 config &= ~TUNER_CHARGE_PUMP;
440 buffer[0] = (div>>8) & 0x7f;
441 buffer[1] = div & 0xff;
442 buffer[2] = config;
443 buffer[3] = cb;
444 tuner_dbg("tv 0x%02x 0x%02x 0x%02x 0x%02x\n",
445 buffer[0],buffer[1],buffer[2],buffer[3]);
446 640
447 if (4 != (rc = tuner_i2c_xfer_send(&priv->i2c_props,buffer,4)))
448 tuner_warn("i2c i/o error: rc == %d (should be 4)\n",rc);
449 break;
450 }
451 }
452 return 0; 641 return 0;
453} 642}
454 643
@@ -483,37 +672,13 @@ static int simple_set_radio_freq(struct dvb_frontend *fe,
483 freq += (unsigned int)(41.3*16000); 672 freq += (unsigned int)(41.3*16000);
484 break; 673 break;
485 default: 674 default:
486 tuner_warn("Unsupported radio_if value %d\n", t_params->radio_if); 675 tuner_warn("Unsupported radio_if value %d\n",
676 t_params->radio_if);
487 return 0; 677 return 0;
488 } 678 }
489 679
490 /* Bandswitch byte */ 680 /* Bandswitch byte */
491 switch (priv->type) { 681 simple_radio_bandswitch(fe, &buffer[0]);
492 case TUNER_TENA_9533_DI:
493 case TUNER_YMEC_TVF_5533MF:
494 tuner_dbg("This tuner doesn't have FM. Most cards have a TEA5767 for FM\n");
495 return 0;
496 case TUNER_PHILIPS_FM1216ME_MK3:
497 case TUNER_PHILIPS_FM1236_MK3:
498 case TUNER_PHILIPS_FMD1216ME_MK3:
499 case TUNER_LG_NTSC_TAPE:
500 case TUNER_PHILIPS_FM1256_IH3:
501 buffer[3] = 0x19;
502 break;
503 case TUNER_TNF_5335MF:
504 buffer[3] = 0x11;
505 break;
506 case TUNER_LG_PAL_FM:
507 buffer[3] = 0xa5;
508 break;
509 case TUNER_THOMSON_DTT761X:
510 buffer[3] = 0x39;
511 break;
512 case TUNER_MICROTUNE_4049FM5:
513 default:
514 buffer[3] = 0xa4;
515 break;
516 }
517 682
518 buffer[2] = (t_params->ranges[0].config & ~TUNER_RATIO_MASK) | 683 buffer[2] = (t_params->ranges[0].config & ~TUNER_RATIO_MASK) |
519 TUNER_RATIO_SELECT_50; /* 50 kHz step */ 684 TUNER_RATIO_SELECT_50; /* 50 kHz step */
@@ -534,7 +699,7 @@ static int simple_set_radio_freq(struct dvb_frontend *fe,
534 } 699 }
535 700
536 tuner_dbg("radio 0x%02x 0x%02x 0x%02x 0x%02x\n", 701 tuner_dbg("radio 0x%02x 0x%02x 0x%02x 0x%02x\n",
537 buffer[0],buffer[1],buffer[2],buffer[3]); 702 buffer[0], buffer[1], buffer[2], buffer[3]);
538 priv->last_div = div; 703 priv->last_div = div;
539 704
540 if (t_params->has_tda9887) { 705 if (t_params->has_tda9887) {
@@ -544,9 +709,11 @@ static int simple_set_radio_freq(struct dvb_frontend *fe,
544 tda9887_cfg.tuner = TUNER_TDA9887; 709 tda9887_cfg.tuner = TUNER_TDA9887;
545 tda9887_cfg.priv = &config; 710 tda9887_cfg.priv = &config;
546 711
547 if (t_params->port1_active && !t_params->port1_fm_high_sensitivity) 712 if (t_params->port1_active &&
713 !t_params->port1_fm_high_sensitivity)
548 config |= TDA9887_PORT1_ACTIVE; 714 config |= TDA9887_PORT1_ACTIVE;
549 if (t_params->port2_active && !t_params->port2_fm_high_sensitivity) 715 if (t_params->port2_active &&
716 !t_params->port2_fm_high_sensitivity)
550 config |= TDA9887_PORT2_ACTIVE; 717 config |= TDA9887_PORT2_ACTIVE;
551 if (t_params->intercarrier_mode) 718 if (t_params->intercarrier_mode)
552 config |= TDA9887_INTERCARRIER; 719 config |= TDA9887_INTERCARRIER;
@@ -557,10 +724,11 @@ static int simple_set_radio_freq(struct dvb_frontend *fe,
557 if (t_params->radio_if == 2) 724 if (t_params->radio_if == 2)
558 config |= TDA9887_RIF_41_3; 725 config |= TDA9887_RIF_41_3;
559 i2c_clients_command(priv->i2c_props.adap, TUNER_SET_CONFIG, 726 i2c_clients_command(priv->i2c_props.adap, TUNER_SET_CONFIG,
560 &tda9887_cfg); 727 &tda9887_cfg);
561 } 728 }
562 if (4 != (rc = tuner_i2c_xfer_send(&priv->i2c_props,buffer,4))) 729 rc = tuner_i2c_xfer_send(&priv->i2c_props, buffer, 4);
563 tuner_warn("i2c i/o error: rc == %d (should be 4)\n",rc); 730 if (4 != rc)
731 tuner_warn("i2c i/o error: rc == %d (should be 4)\n", rc);
564 732
565 return 0; 733 return 0;
566} 734}
@@ -571,6 +739,9 @@ static int simple_set_params(struct dvb_frontend *fe,
571 struct tuner_simple_priv *priv = fe->tuner_priv; 739 struct tuner_simple_priv *priv = fe->tuner_priv;
572 int ret = -EINVAL; 740 int ret = -EINVAL;
573 741
742 if (priv->i2c_props.adap == NULL)
743 return -EINVAL;
744
574 switch (params->mode) { 745 switch (params->mode) {
575 case V4L2_TUNER_RADIO: 746 case V4L2_TUNER_RADIO:
576 ret = simple_set_radio_freq(fe, params); 747 ret = simple_set_radio_freq(fe, params);
@@ -582,14 +753,210 @@ static int simple_set_params(struct dvb_frontend *fe,
582 priv->frequency = params->frequency * 62500; 753 priv->frequency = params->frequency * 62500;
583 break; 754 break;
584 } 755 }
756 priv->bandwidth = 0;
585 757
586 return ret; 758 return ret;
587} 759}
588 760
761static void simple_set_dvb(struct dvb_frontend *fe, u8 *buf,
762 const struct dvb_frontend_parameters *params)
763{
764 struct tuner_simple_priv *priv = fe->tuner_priv;
765
766 switch (priv->type) {
767 case TUNER_PHILIPS_FMD1216ME_MK3:
768 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ &&
769 params->frequency >= 158870000)
770 buf[3] |= 0x08;
771 break;
772 case TUNER_PHILIPS_TD1316:
773 /* determine band */
774 buf[3] |= (params->frequency < 161000000) ? 1 :
775 (params->frequency < 444000000) ? 2 : 4;
776
777 /* setup PLL filter */
778 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ)
779 buf[3] |= 1 << 3;
780 break;
781 case TUNER_PHILIPS_TUV1236D:
782 case TUNER_PHILIPS_FCV1236D:
783 {
784 unsigned int new_rf;
785
786 if (dtv_input[priv->nr])
787 new_rf = dtv_input[priv->nr];
788 else
789 switch (params->u.vsb.modulation) {
790 case QAM_64:
791 case QAM_256:
792 new_rf = 1;
793 break;
794 case VSB_8:
795 default:
796 new_rf = 0;
797 break;
798 }
799 simple_set_rf_input(fe, &buf[2], &buf[3], new_rf);
800 break;
801 }
802 default:
803 break;
804 }
805}
806
807static u32 simple_dvb_configure(struct dvb_frontend *fe, u8 *buf,
808 const struct dvb_frontend_parameters *params)
809{
810 /* This function returns the tuned frequency on success, 0 on error */
811 struct tuner_simple_priv *priv = fe->tuner_priv;
812 struct tunertype *tun = priv->tun;
813 static struct tuner_params *t_params;
814 u8 config, cb;
815 u32 div;
816 int ret, frequency = params->frequency / 62500;
817
818 t_params = simple_tuner_params(fe, TUNER_PARAM_TYPE_DIGITAL);
819 ret = simple_config_lookup(fe, t_params, &frequency, &config, &cb);
820 if (ret < 0)
821 return 0; /* failure */
822
823 div = ((frequency + t_params->iffreq) * 62500 + offset +
824 tun->stepsize/2) / tun->stepsize;
825
826 buf[0] = div >> 8;
827 buf[1] = div & 0xff;
828 buf[2] = config;
829 buf[3] = cb;
830
831 simple_set_dvb(fe, buf, params);
832
833 tuner_dbg("%s: div=%d | buf=0x%02x,0x%02x,0x%02x,0x%02x\n",
834 tun->name, div, buf[0], buf[1], buf[2], buf[3]);
835
836 /* calculate the frequency we set it to */
837 return (div * tun->stepsize) - t_params->iffreq;
838}
839
840static int simple_dvb_calc_regs(struct dvb_frontend *fe,
841 struct dvb_frontend_parameters *params,
842 u8 *buf, int buf_len)
843{
844 struct tuner_simple_priv *priv = fe->tuner_priv;
845 u32 frequency;
846
847 if (buf_len < 5)
848 return -EINVAL;
849
850 frequency = simple_dvb_configure(fe, buf+1, params);
851 if (frequency == 0)
852 return -EINVAL;
853
854 buf[0] = priv->i2c_props.addr;
855
856 priv->frequency = frequency;
857 priv->bandwidth = (fe->ops.info.type == FE_OFDM) ?
858 params->u.ofdm.bandwidth : 0;
859
860 return 5;
861}
862
863static int simple_dvb_set_params(struct dvb_frontend *fe,
864 struct dvb_frontend_parameters *params)
865{
866 struct tuner_simple_priv *priv = fe->tuner_priv;
867 u32 prev_freq, prev_bw;
868 int ret;
869 u8 buf[5];
870
871 if (priv->i2c_props.adap == NULL)
872 return -EINVAL;
873
874 prev_freq = priv->frequency;
875 prev_bw = priv->bandwidth;
876
877 ret = simple_dvb_calc_regs(fe, params, buf, 5);
878 if (ret != 5)
879 goto fail;
880
881 /* put analog demod in standby when tuning digital */
882 if (fe->ops.analog_ops.standby)
883 fe->ops.analog_ops.standby(fe);
884
885 if (fe->ops.i2c_gate_ctrl)
886 fe->ops.i2c_gate_ctrl(fe, 1);
887
888 /* buf[0] contains the i2c address, but *
889 * we already have it in i2c_props.addr */
890 ret = tuner_i2c_xfer_send(&priv->i2c_props, buf+1, 4);
891 if (ret != 4)
892 goto fail;
893
894 return 0;
895fail:
896 /* calc_regs sets frequency and bandwidth. if we failed, unset them */
897 priv->frequency = prev_freq;
898 priv->bandwidth = prev_bw;
899
900 return ret;
901}
902
903static int simple_init(struct dvb_frontend *fe)
904{
905 struct tuner_simple_priv *priv = fe->tuner_priv;
906
907 if (priv->i2c_props.adap == NULL)
908 return -EINVAL;
909
910 if (priv->tun->initdata) {
911 int ret;
912
913 if (fe->ops.i2c_gate_ctrl)
914 fe->ops.i2c_gate_ctrl(fe, 1);
915
916 ret = tuner_i2c_xfer_send(&priv->i2c_props,
917 priv->tun->initdata + 1,
918 priv->tun->initdata[0]);
919 if (ret != priv->tun->initdata[0])
920 return ret;
921 }
922
923 return 0;
924}
925
926static int simple_sleep(struct dvb_frontend *fe)
927{
928 struct tuner_simple_priv *priv = fe->tuner_priv;
929
930 if (priv->i2c_props.adap == NULL)
931 return -EINVAL;
932
933 if (priv->tun->sleepdata) {
934 int ret;
935
936 if (fe->ops.i2c_gate_ctrl)
937 fe->ops.i2c_gate_ctrl(fe, 1);
938
939 ret = tuner_i2c_xfer_send(&priv->i2c_props,
940 priv->tun->sleepdata + 1,
941 priv->tun->sleepdata[0]);
942 if (ret != priv->tun->sleepdata[0])
943 return ret;
944 }
945
946 return 0;
947}
589 948
590static int simple_release(struct dvb_frontend *fe) 949static int simple_release(struct dvb_frontend *fe)
591{ 950{
592 kfree(fe->tuner_priv); 951 struct tuner_simple_priv *priv = fe->tuner_priv;
952
953 mutex_lock(&tuner_simple_list_mutex);
954
955 if (priv)
956 hybrid_tuner_release_state(priv);
957
958 mutex_unlock(&tuner_simple_list_mutex);
959
593 fe->tuner_priv = NULL; 960 fe->tuner_priv = NULL;
594 961
595 return 0; 962 return 0;
@@ -602,10 +969,22 @@ static int simple_get_frequency(struct dvb_frontend *fe, u32 *frequency)
602 return 0; 969 return 0;
603} 970}
604 971
972static int simple_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
973{
974 struct tuner_simple_priv *priv = fe->tuner_priv;
975 *bandwidth = priv->bandwidth;
976 return 0;
977}
978
605static struct dvb_tuner_ops simple_tuner_ops = { 979static struct dvb_tuner_ops simple_tuner_ops = {
980 .init = simple_init,
981 .sleep = simple_sleep,
606 .set_analog_params = simple_set_params, 982 .set_analog_params = simple_set_params,
983 .set_params = simple_dvb_set_params,
984 .calc_regs = simple_dvb_calc_regs,
607 .release = simple_release, 985 .release = simple_release,
608 .get_frequency = simple_get_frequency, 986 .get_frequency = simple_get_frequency,
987 .get_bandwidth = simple_get_bandwidth,
609 .get_status = simple_get_status, 988 .get_status = simple_get_status,
610 .get_rf_strength = simple_get_rf_strength, 989 .get_rf_strength = simple_get_rf_strength,
611}; 990};
@@ -613,30 +992,92 @@ static struct dvb_tuner_ops simple_tuner_ops = {
613struct dvb_frontend *simple_tuner_attach(struct dvb_frontend *fe, 992struct dvb_frontend *simple_tuner_attach(struct dvb_frontend *fe,
614 struct i2c_adapter *i2c_adap, 993 struct i2c_adapter *i2c_adap,
615 u8 i2c_addr, 994 u8 i2c_addr,
616 struct simple_tuner_config *cfg) 995 unsigned int type)
617{ 996{
618 struct tuner_simple_priv *priv = NULL; 997 struct tuner_simple_priv *priv = NULL;
998 int instance;
619 999
620 priv = kzalloc(sizeof(struct tuner_simple_priv), GFP_KERNEL); 1000 if (type >= tuner_count) {
621 if (priv == NULL) 1001 printk(KERN_WARNING "%s: invalid tuner type: %d (max: %d)\n",
1002 __func__, type, tuner_count-1);
622 return NULL; 1003 return NULL;
623 fe->tuner_priv = priv; 1004 }
624 1005
625 priv->i2c_props.addr = i2c_addr; 1006 /* If i2c_adap is set, check that the tuner is at the correct address.
626 priv->i2c_props.adap = i2c_adap; 1007 * Otherwise, if i2c_adap is NULL, the tuner will be programmed directly
627 priv->type = cfg->type; 1008 * by the digital demod via calc_regs.
628 priv->tun = cfg->tun; 1009 */
1010 if (i2c_adap != NULL) {
1011 u8 b[1];
1012 struct i2c_msg msg = {
1013 .addr = i2c_addr, .flags = I2C_M_RD,
1014 .buf = b, .len = 1,
1015 };
1016
1017 if (fe->ops.i2c_gate_ctrl)
1018 fe->ops.i2c_gate_ctrl(fe, 1);
1019
1020 if (1 != i2c_transfer(i2c_adap, &msg, 1))
1021 tuner_warn("unable to probe %s, proceeding anyway.",
1022 tuners[type].name);
1023
1024 if (fe->ops.i2c_gate_ctrl)
1025 fe->ops.i2c_gate_ctrl(fe, 0);
1026 }
629 1027
630 memcpy(&fe->ops.tuner_ops, &simple_tuner_ops, sizeof(struct dvb_tuner_ops)); 1028 mutex_lock(&tuner_simple_list_mutex);
631 1029
632 tuner_info("type set to %d (%s)\n", cfg->type, cfg->tun->name); 1030 instance = hybrid_tuner_request_state(struct tuner_simple_priv, priv,
1031 hybrid_tuner_instance_list,
1032 i2c_adap, i2c_addr,
1033 "tuner-simple");
1034 switch (instance) {
1035 case 0:
1036 mutex_unlock(&tuner_simple_list_mutex);
1037 return NULL;
1038 break;
1039 case 1:
1040 fe->tuner_priv = priv;
633 1041
634 strlcpy(fe->ops.tuner_ops.info.name, cfg->tun->name, sizeof(fe->ops.tuner_ops.info.name)); 1042 priv->type = type;
1043 priv->tun = &tuners[type];
1044 priv->nr = simple_devcount++;
1045 break;
1046 default:
1047 fe->tuner_priv = priv;
1048 break;
1049 }
635 1050
636 return fe; 1051 mutex_unlock(&tuner_simple_list_mutex);
637} 1052
1053 memcpy(&fe->ops.tuner_ops, &simple_tuner_ops,
1054 sizeof(struct dvb_tuner_ops));
1055
1056 tuner_info("type set to %d (%s)\n", type, priv->tun->name);
1057
1058 if ((debug) || ((atv_input[priv->nr] > 0) ||
1059 (dtv_input[priv->nr] > 0))) {
1060 if (0 == atv_input[priv->nr])
1061 tuner_info("tuner %d atv rf input will be "
1062 "autoselected\n", priv->nr);
1063 else
1064 tuner_info("tuner %d atv rf input will be "
1065 "set to input %d (insmod option)\n",
1066 priv->nr, atv_input[priv->nr]);
1067 if (0 == dtv_input[priv->nr])
1068 tuner_info("tuner %d dtv rf input will be "
1069 "autoselected\n", priv->nr);
1070 else
1071 tuner_info("tuner %d dtv rf input will be "
1072 "set to input %d (insmod option)\n",
1073 priv->nr, dtv_input[priv->nr]);
1074 }
638 1075
1076 strlcpy(fe->ops.tuner_ops.info.name, priv->tun->name,
1077 sizeof(fe->ops.tuner_ops.info.name));
639 1078
1079 return fe;
1080}
640EXPORT_SYMBOL_GPL(simple_tuner_attach); 1081EXPORT_SYMBOL_GPL(simple_tuner_attach);
641 1082
642MODULE_DESCRIPTION("Simple 4-control-bytes style tuner driver"); 1083MODULE_DESCRIPTION("Simple 4-control-bytes style tuner driver");