1 #include <linux/module.h>
2 #include <linux/kernel.h>
3 #include <linux/sched.h>
4 #include <linux/string.h>
5 #include <linux/timer.h>
6 #include <linux/delay.h>
7 #include <linux/errno.h>
8 #include <linux/slab.h>
9 #include <linux/poll.h>
10 #include <linux/i2c.h>
11 #include <linux/types.h>
12 #include <linux/videodev.h>
13 #include <linux/init.h>
16 #include "audiochip.h"
18 /* Addresses to scan */
19 static unsigned short normal_i2c[] = {I2C_CLIENT_END};
20 static unsigned short normal_i2c_range[] = {0x60,0x6f,I2C_CLIENT_END};
27 static char *pal = "b";
28 static int tv_range[2] = { 44, 958 };
29 static int radio_range[2] = { 65, 108 };
30 MODULE_PARM(debug,"i");
31 MODULE_PARM(type,"i");
32 MODULE_PARM(addr,"i");
33 MODULE_PARM(tv_range,"2i");
34 MODULE_PARM(radio_range,"2i");
37 #define optimize_vco 1
39 MODULE_DESCRIPTION("device driver for various TV and TV+FM radio tuners");
40 MODULE_AUTHOR("Ralph Metzler, Gerd Knorr, Gunther Mayer");
41 MODULE_LICENSE("GPL");
44 #define dprintk if (debug) printk
48 int type; /* chip type */
49 int freq; /* keep track of the current settings */
53 int mode; /* current norm for multi-norm tuners */
54 int xogc; // only for MT2032
57 static struct i2c_driver driver;
58 static struct i2c_client client_template;
60 /* ---------------------------------------------------------------------- */
62 /* tv standard selection for Temic 4046 FM5
63 this value takes the low bits of control byte 2
64 from datasheet Rev.01, Feb.00
66 picture IF 38.9 38.9 38.9 33.95 38.9
67 sound 1 33.4 32.9 32.4 40.45 32.4
69 NICAM 33.05 32.348 33.05 33.05
71 #define TEMIC_SET_PAL_I 0x05
72 #define TEMIC_SET_PAL_DK 0x09
73 #define TEMIC_SET_PAL_L 0x0a // SECAM ?
74 #define TEMIC_SET_PAL_L2 0x0b // change IF !
75 #define TEMIC_SET_PAL_BG 0x0c
77 /* tv tuner system standard selection for Philips FQ1216ME
78 this value takes the low bits of control byte 2
79 from datasheet "1999 Nov 16" (supersedes "1999 Mar 23")
81 picture carrier 38.90 38.90 38.90 38.90 33.95
82 colour 34.47 34.47 34.47 34.47 38.38
83 sound 1 33.40 32.40 32.90 32.40 40.45
85 NICAM 33.05 33.05 32.35 33.05 39.80
87 #define PHILIPS_SET_PAL_I 0x01 /* Bit 2 always zero !*/
88 #define PHILIPS_SET_PAL_BGDK 0x09
89 #define PHILIPS_SET_PAL_L2 0x0a
90 #define PHILIPS_SET_PAL_L 0x0b
92 /* system switching for Philips FI1216MF MK2
93 from datasheet "1996 Jul 09",
95 picture carrier 38.90 38.90 33.95
96 colour 34.47 34.37 38.38
97 sound 1 33.40 32.40 40.45
99 NICAM 33.05 33.05 39.80
101 #define PHILIPS_MF_SET_BG 0x01 /* Bit 2 must be zero, Bit 3 is system output */
102 #define PHILIPS_MF_SET_PAL_L 0x03 // France
103 #define PHILIPS_MF_SET_PAL_L2 0x02 // L'
106 /* ---------------------------------------------------------------------- */
111 unsigned char Vendor;
114 unsigned short thresh1; /* band switch VHF_LO <=> VHF_HI */
115 unsigned short thresh2; /* band switch VHF_HI <=> UHF */
119 unsigned char config;
120 unsigned short IFPCoff; /* 622.4=16*38.90 MHz PAL,
122 940 =58.75 NTSC-Japan */
126 * The floats in the tuner struct are computed at compile time
127 * by gcc and cast back to integers. Thus we don't violate the
128 * "no float in kernel" rule.
130 static struct tunertype tuners[] = {
131 { "Temic PAL (4002 FH5)", TEMIC, PAL,
132 16*140.25,16*463.25,0x02,0x04,0x01,0x8e,623},
133 { "Philips PAL_I (FI1246 and compatibles)", Philips, PAL_I,
134 16*140.25,16*463.25,0xa0,0x90,0x30,0x8e,623},
135 { "Philips NTSC (FI1236,FM1236 and compatibles)", Philips, NTSC,
136 16*157.25,16*451.25,0xA0,0x90,0x30,0x8e,732},
137 { "Philips (SECAM+PAL_BG) (FI1216MF, FM1216MF, FR1216MF)", Philips, SECAM,
138 16*168.25,16*447.25,0xA7,0x97,0x37,0x8e,623},
140 { "NoTuner", NoTuner, NOTUNER,
141 0,0,0x00,0x00,0x00,0x00,0x00},
142 { "Philips PAL_BG (FI1216 and compatibles)", Philips, PAL,
143 16*168.25,16*447.25,0xA0,0x90,0x30,0x8e,623},
144 { "Temic NTSC (4032 FY5)", TEMIC, NTSC,
145 16*157.25,16*463.25,0x02,0x04,0x01,0x8e,732},
146 { "Temic PAL_I (4062 FY5)", TEMIC, PAL_I,
147 16*170.00,16*450.00,0x02,0x04,0x01,0x8e,623},
149 { "Temic NTSC (4036 FY5)", TEMIC, NTSC,
150 16*157.25,16*463.25,0xa0,0x90,0x30,0x8e,732},
151 { "Alps HSBH1", TEMIC, NTSC,
152 16*137.25,16*385.25,0x01,0x02,0x08,0x8e,732},
153 { "Alps TSBE1",TEMIC,PAL,
154 16*137.25,16*385.25,0x01,0x02,0x08,0x8e,732},
155 { "Alps TSBB5", Alps, PAL_I, /* tested (UK UHF) with Modulartech MM205 */
156 16*133.25,16*351.25,0x01,0x02,0x08,0x8e,632},
158 { "Alps TSBE5", Alps, PAL, /* untested - data sheet guess. Only IF differs. */
159 16*133.25,16*351.25,0x01,0x02,0x08,0x8e,622},
160 { "Alps TSBC5", Alps, PAL, /* untested - data sheet guess. Only IF differs. */
161 16*133.25,16*351.25,0x01,0x02,0x08,0x8e,608},
162 { "Temic PAL_BG (4006FH5)", TEMIC, PAL,
163 16*170.00,16*450.00,0xa0,0x90,0x30,0x8e,623},
164 { "Alps TSCH6",Alps,NTSC,
165 16*137.25,16*385.25,0x14,0x12,0x11,0x8e,732},
167 { "Temic PAL_DK (4016 FY5)",TEMIC,PAL,
168 16*168.25,16*456.25,0xa0,0x90,0x30,0x8e,623},
169 { "Philips NTSC_M (MK2)",Philips,NTSC,
170 16*160.00,16*454.00,0xa0,0x90,0x30,0x8e,732},
171 { "Temic PAL_I (4066 FY5)", TEMIC, PAL_I,
172 16*169.00, 16*454.00, 0xa0,0x90,0x30,0x8e,623},
173 { "Temic PAL* auto (4006 FN5)", TEMIC, PAL,
174 16*169.00, 16*454.00, 0xa0,0x90,0x30,0x8e,623},
176 { "Temic PAL_BG (4009 FR5) or PAL_I (4069 FR5)", TEMIC, PAL,
177 16*141.00, 16*464.00, 0xa0,0x90,0x30,0x8e,623},
178 { "Temic NTSC (4039 FR5)", TEMIC, NTSC,
179 16*158.00, 16*453.00, 0xa0,0x90,0x30,0x8e,732},
180 { "Temic PAL/SECAM multi (4046 FM5)", TEMIC, PAL,
181 16*169.00, 16*454.00, 0xa0,0x90,0x30,0x8e,623},
182 { "Philips PAL_DK (FI1256 and compatibles)", Philips, PAL,
183 16*170.00,16*450.00,0xa0,0x90,0x30,0x8e,623},
185 { "Philips PAL/SECAM multi (FQ1216ME)", Philips, PAL,
186 16*170.00,16*450.00,0xa0,0x90,0x30,0x8e,623},
187 { "LG PAL_I+FM (TAPC-I001D)", LGINNOTEK, PAL_I,
188 16*170.00,16*450.00,0xa0,0x90,0x30,0x8e,623},
189 { "LG PAL_I (TAPC-I701D)", LGINNOTEK, PAL_I,
190 16*170.00,16*450.00,0xa0,0x90,0x30,0x8e,623},
191 { "LG NTSC+FM (TPI8NSR01F)", LGINNOTEK, NTSC,
192 16*210.00,16*497.00,0xa0,0x90,0x30,0x8e,732},
194 { "LG PAL_BG+FM (TPI8PSB01D)", LGINNOTEK, PAL,
195 16*170.00,16*450.00,0xa0,0x90,0x30,0x8e,623},
196 { "LG PAL_BG (TPI8PSB11D)", LGINNOTEK, PAL,
197 16*170.00,16*450.00,0xa0,0x90,0x30,0x8e,623},
198 { "Temic PAL* auto + FM (4009 FN5)", TEMIC, PAL,
199 16*141.00, 16*464.00, 0xa0,0x90,0x30,0x8e,623},
200 { "SHARP NTSC_JP (2U5JF5540)", SHARP, NTSC, /* 940=16*58.75 NTSC@Japan */
201 16*137.25,16*317.25,0x01,0x02,0x08,0x8e,732 }, // Corrected to NTSC=732 (was:940)
203 { "Samsung PAL TCPM9091PD27", Samsung, PAL, /* from sourceforge v3tv */
204 16*169,16*464,0xA0,0x90,0x30,0x8e,623},
205 { "MT2032 universal", Microtune,PAL|NTSC,
207 { "Temic PAL_BG (4106 FH5)", TEMIC, PAL,
208 16*141.00, 16*464.00, 0xa0,0x90,0x30,0x8e,623},
209 { "Temic PAL_DK/SECAM_L (4012 FY5)", TEMIC, PAL,
210 16*140.25, 16*463.25, 0x02,0x04,0x01,0x8e,623},
212 { "Temic NTSC (4136 FY5)", TEMIC, NTSC,
213 16*158.00, 16*453.00, 0xa0,0x90,0x30,0x8e,732},
214 { "LG PAL (newer TAPC series)", LGINNOTEK, PAL,
215 16*170.00, 16*450.00, 0x01,0x02,0x08,0x8e,623},
216 { "Philips PAL/SECAM multi (FM1216ME MK3)", Philips, PAL,
217 16*160.00,16*442.00,0x01,0x02,0x04,0x8e,623 },
218 { "LG NTSC (newer TAPC series)", LGINNOTEK, NTSC,
219 16*170.00, 16*450.00, 0x01,0x02,0x08,0x8e,732},
221 #define TUNERS (sizeof(tuners)/sizeof(struct tunertype))
223 /* ---------------------------------------------------------------------- */
225 static int tuner_getstatus(struct i2c_client *c)
229 struct tuner *t = (struct tuner*)c->data;
231 if (t->type == TUNER_MT2032)
234 if (1 != i2c_master_recv(c,&byte,1))
239 #define TUNER_POR 0x80
240 #define TUNER_FL 0x40
241 #define TUNER_MODE 0x38
242 #define TUNER_AFC 0x07
244 #define TUNER_STEREO 0x10 /* radio mode */
245 #define TUNER_SIGNAL 0x07 /* radio mode */
247 static int tuner_signal(struct i2c_client *c)
249 return (tuner_getstatus(c) & TUNER_SIGNAL)<<13;
252 static int tuner_stereo(struct i2c_client *c)
254 return (tuner_getstatus (c) & TUNER_STEREO);
258 static int tuner_islocked (struct i2c_client *c)
260 return (tuner_getstatus (c) & TUNER_FL);
263 static int tuner_afcstatus (struct i2c_client *c)
265 return (tuner_getstatus (c) & TUNER_AFC) - 2;
268 static int tuner_mode (struct i2c_client *c)
270 return (tuner_getstatus (c) & TUNER_MODE) >> 3;
274 // Initalization as described in "MT203x Programming Procedures", Rev 1.2, Feb.2001
275 static int mt2032_init(struct i2c_client *c)
277 unsigned char buf[21];
279 struct tuner *t = (struct tuner*)c->data;
282 ret=i2c_master_send(c,buf,1);
283 i2c_master_recv(c,buf,21);
285 printk("MT2032: Companycode=%02x%02x Part=%02x Revision=%02x\n",
286 buf[0x11],buf[0x12],buf[0x13],buf[0x14]);
290 printk("MT2032 hexdump:\n");
292 printk(" %02x",buf[i]);
293 if(((i+1)%8)==0) printk(" ");
294 if(((i+1)%16)==0) printk("\n ");
298 // Look for MT2032 id:
299 // part= 0x04(MT2032), 0x06(MT2030), 0x07(MT2040)
300 if((buf[0x11] != 0x4d) || (buf[0x12] != 0x54) || (buf[0x13] != 0x04)) {
301 printk("not a MT2032.\n");
306 // Initialize Registers per spec.
307 buf[1]=2; // Index to register 2
311 ret=i2c_master_send(c,buf+1,4);
313 buf[5]=6; // Index register 6
319 ret=i2c_master_send(c,buf+5,6);
321 buf[12]=13; // Index register 13
323 ret=i2c_master_send(c,buf+12,2);
325 // Adjust XOGC (register 7), wait for XOK
328 dprintk("mt2032: xogc = 0x%02x\n",xogc&0x07);
331 i2c_master_send(c,buf,1);
332 i2c_master_recv(c,buf,1);
334 dprintk("mt2032: xok = 0x%02x\n",xok);
338 dprintk("mt2032: xogc = 0x%02x\n",xogc&0x07);
340 xogc=4; // min. 4 per spec
345 ret=i2c_master_send(c,buf,2);
347 printk("mt2032_init failed with %d\n",ret);
356 static int mt2032_spurcheck(int f1, int f2, int spectrum_from,int spectrum_to)
360 f1=f1/1000; //scale to kHz to avoid 32bit overflows
365 dprintk("spurcheck f1=%d f2=%d from=%d to=%d\n",f1,f2,spectrum_from,spectrum_to);
373 dprintk(" spurtest n1=%d n2=%d ftest=%d\n",n1,n2,f);
375 if( (f>spectrum_from) && (f<spectrum_to))
376 printk("mt2032 spurcheck triggered: %d\n",n1);
377 } while ( (f>(f2-spectrum_to)) || (n2>-5));
384 static int mt2032_compute_freq(int rfin, int if1, int if2, int spectrum_from,
385 int spectrum_to, unsigned char *buf, int *ret_sel, int xogc) //all in Hz
387 int fref,lo1,lo1n,lo1a,s,sel,lo1freq, desired_lo1,
388 desired_lo2,lo2,lo2n,lo2a,lo2num,lo2freq;
390 fref= 5250 *1000; //5.25MHz
391 desired_lo1=rfin+if1;
393 lo1=(2*(desired_lo1/1000)+(fref/1000)) / (2*fref/1000);
397 s=rfin/1000/1000+1090;
401 else if(s>1720) sel=1;
402 else if(s>1530) sel=2;
403 else if(s>1370) sel=3;
407 if(s>1790) sel=0; // <1958
408 else if(s>1617) sel=1;
409 else if(s>1449) sel=2;
410 else if(s>1291) sel=3;
415 lo1freq=(lo1a+8*lo1n)*fref;
417 dprintk("mt2032: rfin=%d lo1=%d lo1n=%d lo1a=%d sel=%d, lo1freq=%d\n",
418 rfin,lo1,lo1n,lo1a,sel,lo1freq);
420 desired_lo2=lo1freq-rfin-if2;
421 lo2=(desired_lo2)/fref;
424 lo2num=((desired_lo2/1000)%(fref/1000))* 3780/(fref/1000); //scale to fit in 32bit arith
425 lo2freq=(lo2a+8*lo2n)*fref + lo2num*(fref/1000)/3780*1000;
427 dprintk("mt2032: rfin=%d lo2=%d lo2n=%d lo2a=%d num=%d lo2freq=%d\n",
428 rfin,lo2,lo2n,lo2a,lo2num,lo2freq);
430 if(lo1a<0 || lo1a>7 || lo1n<17 ||lo1n>48 || lo2a<0 ||lo2a >7 ||lo2n<17 || lo2n>30) {
431 printk("mt2032: frequency parameters out of range: %d %d %d %d\n",
432 lo1a, lo1n, lo2a,lo2n);
436 mt2032_spurcheck(lo1freq, desired_lo2, spectrum_from, spectrum_to);
437 // should recalculate lo1 (one step up/down)
439 // set up MT2032 register map for transfer over i2c
441 buf[1]=lo1a | (sel<<4);
443 buf[3]=0x0f; //reserved
445 buf[5]=(lo2n-1) | (lo2a<<5);
446 if(rfin >400*1000*1000)
449 buf[6]=0xf4; // set PKEN per rev 1.2
451 buf[8]=0xc3; //reserved
452 buf[9]=0x4e; //reserved
453 buf[10]=0xec; //reserved
454 buf[11]=(lo2num&0xff);
455 buf[12]=(lo2num>>8) |0x80; // Lo2RST
460 static int mt2032_check_lo_lock(struct i2c_client *c)
463 unsigned char buf[2];
464 for(try=0;try<10;try++) {
466 i2c_master_send(c,buf,1);
467 i2c_master_recv(c,buf,1);
468 dprintk("mt2032 Reg.E=0x%02x\n",buf[0]);
474 dprintk("mt2032: pll wait 1ms for lock (0x%2x)\n",buf[0]);
480 static int mt2032_optimize_vco(struct i2c_client *c,int sel,int lock)
482 unsigned char buf[2];
486 i2c_master_send(c,buf,1);
487 i2c_master_recv(c,buf,1);
488 dprintk("mt2032 Reg.F=0x%02x\n",buf[0]);
491 if(tad1 ==0) return lock;
492 if(tad1 ==1) return lock;
506 dprintk("mt2032 optimize_vco: sel=%d\n",sel);
510 i2c_master_send(c,buf,2);
511 lock=mt2032_check_lo_lock(c);
516 static void mt2032_set_if_freq(struct i2c_client *c,int rfin, int if1, int if2, int from, int to)
518 unsigned char buf[21];
519 int lint_try,ret,sel,lock=0;
520 struct tuner *t = (struct tuner*)c->data;
522 dprintk("mt2032_set_if_freq rfin=%d if1=%d if2=%d from=%d to=%d\n",rfin,if1,if2,from,to);
525 ret=i2c_master_send(c,buf,1);
526 i2c_master_recv(c,buf,21);
529 ret=mt2032_compute_freq(rfin,if1,if2,from,to,&buf[1],&sel,t->xogc);
533 // send only the relevant registers per Rev. 1.2
535 ret=i2c_master_send(c,buf,4);
537 ret=i2c_master_send(c,buf+5,4);
539 ret=i2c_master_send(c,buf+11,3);
541 printk("mt2032_set_if_freq failed with %d\n",ret);
543 // wait for PLLs to lock (per manual), retry LINT if not.
544 for(lint_try=0; lint_try<2; lint_try++) {
545 lock=mt2032_check_lo_lock(c);
548 lock=mt2032_optimize_vco(c,sel,lock);
551 printk("mt2032: re-init PLLs by LINT\n");
553 buf[1]=0x80 +8+t->xogc; // set LINT to re-init PLLs
554 i2c_master_send(c,buf,2);
557 i2c_master_send(c,buf,2);
561 printk("MT2032 Fatal Error: PLLs didn't lock.\n");
564 buf[1]=0x20; // LOGC for optimal phase noise
565 ret=i2c_master_send(c,buf,2);
567 printk("mt2032_set_if_freq2 failed with %d\n",ret);
571 static void mt2032_set_tv_freq(struct i2c_client *c, int freq, int norm)
575 // signal bandwidth and picture carrier
576 if(norm==VIDEO_MODE_NTSC) {
587 mt2032_set_if_freq(c,freq* 1000*1000/16, 1090*1000*1000, if2, from, to);
591 // Set tuner frequency, freq in Units of 62.5kHz = 1/16MHz
592 static void set_tv_freq(struct i2c_client *c, int freq)
596 struct tunertype *tun;
597 struct tuner *t = c->data;
598 unsigned char buffer[4];
602 printk("tuner: tuner type not set\n");
605 if (t->type == TUNER_MT2032) {
606 mt2032_set_tv_freq(c,freq,t->mode);
610 if (freq < tv_range[0]*16 || freq > tv_range[1]*16) {
611 /* FIXME: better do that chip-specific, but
612 right now we don't have that in the config
613 struct and this way is still better than no
615 printk("tuner: TV freq (%d.%02d) out of range (%d-%d)\n",
616 freq/16,freq%16*100/16,tv_range[0],tv_range[1]);
620 tun=&tuners[t->type];
621 if (freq < tun->thresh1)
623 else if (freq < tun->thresh2)
629 /* tv norm specific stuff for multi-norm tuners */
631 case TUNER_PHILIPS_SECAM: // FI1216MF
632 /* 0x01 -> ??? no change ??? */
633 /* 0x02 -> PAL BDGHI / SECAM L */
634 /* 0x04 -> ??? PAL others / SECAM others ??? */
636 if (t->mode == VIDEO_MODE_SECAM)
640 case TUNER_TEMIC_4046FM5:
645 config |= TEMIC_SET_PAL_I;
649 config |= TEMIC_SET_PAL_DK;
653 config |= TEMIC_SET_PAL_L;
660 config |= TEMIC_SET_PAL_BG;
665 case TUNER_PHILIPS_FQ1216ME:
670 config |= PHILIPS_SET_PAL_I;
674 config |= PHILIPS_SET_PAL_L;
682 config |= PHILIPS_SET_PAL_BGDK;
690 * Philips FI1216MK2 remark from specification :
691 * for channel selection involving band switching, and to ensure
692 * smooth tuning to the desired channel without causing
693 * unnecessary charge pump action, it is recommended to consider
694 * the difference between wanted channel frequency and the
695 * current channel frequency. Unnecessary charge pump action
696 * will result in very low tuning voltage which may drive the
697 * oscillator to extreme conditions.
699 * Progfou: specification says to send config data before
700 * frequency in case (wanted frequency < current frequency).
703 div=freq + tun->IFPCoff;
704 if (t->type == TUNER_PHILIPS_SECAM && freq < t->freq) {
705 buffer[0] = tun->config;
707 buffer[2] = (div>>8) & 0x7f;
708 buffer[3] = div & 0xff;
710 buffer[0] = (div>>8) & 0x7f;
711 buffer[1] = div & 0xff;
712 buffer[2] = tun->config;
715 dprintk("tuner: tv 0x%02x 0x%02x 0x%02x 0x%02x\n",
716 buffer[0],buffer[1],buffer[2],buffer[3]);
718 if (4 != (rc = i2c_master_send(c,buffer,4)))
719 printk("tuner: i2c i/o error: rc == %d (should be 4)\n",rc);
723 static void mt2032_set_radio_freq(struct i2c_client *c,int freq)
727 if2=10700*1000; // 10.7MHz FM intermediate frequency
729 // per Manual for FM tuning: first if center freq. 1085 MHz
730 mt2032_set_if_freq(c,freq* 1000*1000/16, 1085*1000*1000,if2,if2,if2);
733 static void set_radio_freq(struct i2c_client *c, int freq)
735 struct tunertype *tun;
736 struct tuner *t = (struct tuner*)c->data;
737 unsigned char buffer[4];
740 if (freq < radio_range[0]*16 || freq > radio_range[1]*16) {
741 printk("tuner: radio freq (%d.%02d) out of range (%d-%d)\n",
742 freq/16,freq%16*100/16,
743 radio_range[0],radio_range[1]);
747 printk("tuner: tuner type not set\n");
751 if (t->type == TUNER_MT2032) {
752 mt2032_set_radio_freq(c,freq);
756 tun=&tuners[t->type];
757 div = freq + (int)(16*10.7);
758 buffer[0] = (div>>8) & 0x7f;
759 buffer[1] = div & 0xff;
760 buffer[2] = tun->config;
762 case TUNER_PHILIPS_FM1216ME_MK3:
770 dprintk("tuner: radio 0x%02x 0x%02x 0x%02x 0x%02x\n",
771 buffer[0],buffer[1],buffer[2],buffer[3]);
773 if (4 != (rc = i2c_master_send(c,buffer,4)))
774 printk("tuner: i2c i/o error: rc == %d (should be 4)\n",rc);
777 /* ---------------------------------------------------------------------- */
779 static int tuner_attach(struct i2c_adapter *adap, int addr,
780 unsigned short flags, int kind)
783 struct i2c_client *client;
789 client_template.adapter = adap;
790 client_template.addr = addr;
792 printk("tuner: chip found @ 0x%x\n", addr<<1);
794 if (NULL == (client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL)))
796 memcpy(client,&client_template,sizeof(struct i2c_client));
797 client->data = t = kmalloc(sizeof(struct tuner),GFP_KERNEL);
802 memset(t,0,sizeof(struct tuner));
803 if (type >= 0 && type < TUNERS) {
805 printk("tuner(bttv): type forced to %d (%s) [insmod]\n",t->type,tuners[t->type].name);
806 strncpy(client->name, tuners[t->type].name, sizeof(client->name));
810 i2c_attach_client(client);
811 if (t->type == TUNER_MT2032)
818 static int tuner_probe(struct i2c_adapter *adap)
823 normal_i2c_range[0] = addr;
824 normal_i2c_range[1] = addr;
828 case I2C_ALGO_BIT | I2C_HW_B_BT848:
829 case I2C_ALGO_BIT | I2C_HW_B_RIVA:
830 case I2C_ALGO_SAA7134:
831 case I2C_ALGO_SAA7146:
832 printk("tuner: probing %s i2c adapter [id=0x%x]\n",
833 adap->name,adap->id);
834 rc = i2c_probe(adap, &addr_data, tuner_attach);
837 printk("tuner: ignoring %s i2c adapter [id=0x%x]\n",
838 adap->name,adap->id);
845 static int tuner_detach(struct i2c_client *client)
847 struct tuner *t = (struct tuner*)client->data;
849 i2c_detach_client(client);
857 tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
859 struct tuner *t = (struct tuner*)client->data;
860 int *iarg = (int*)arg;
862 __u16 *sarg = (__u16*)arg;
867 /* --- configuration --- */
870 printk("tuner: type already set (%d)\n",t->type);
873 if (*iarg < 0 || *iarg >= TUNERS)
876 printk("tuner: type set to %d (%s)\n",
877 t->type,tuners[t->type].name);
878 strncpy(client->name, tuners[t->type].name, sizeof(client->name));
879 if (t->type == TUNER_MT2032)
886 /* --- v4l ioctls --- */
887 /* take care: bttv does userspace copying, we'll get a
888 kernel pointer here... */
891 struct video_channel *vc = arg;
896 set_tv_freq(client,t->freq);
901 unsigned long *v = arg;
904 dprintk("tuner: radio freq set to %d.%02d\n",
905 (*iarg)/16,(*iarg)%16*100/16);
906 set_radio_freq(client,*v);
908 dprintk("tuner: tv freq set to %d.%02d\n",
909 (*iarg)/16,(*iarg)%16*100/16);
910 set_tv_freq(client,*v);
917 struct video_tuner *vt = arg;
920 vt->signal = tuner_signal(client);
925 struct video_audio *va = arg;
927 va->mode = (tuner_stereo(client) ? VIDEO_SOUND_STEREO : VIDEO_SOUND_MONO);
932 /* --- old, obsolete interface --- */
933 case TUNER_SET_TVFREQ:
934 dprintk("tuner: tv freq set to %d.%02d\n",
935 (*iarg)/16,(*iarg)%16*100/16);
936 set_tv_freq(client,*iarg);
941 case TUNER_SET_RADIOFREQ:
942 dprintk("tuner: radio freq set to %d.%02d\n",
943 (*iarg)/16,(*iarg)%16*100/16);
944 set_radio_freq(client,*iarg);
949 if (t->type != TUNER_PHILIPS_SECAM) {
950 dprintk("tuner: trying to change mode for other than TUNER_PHILIPS_SECAM\n");
952 int mode=(*sarg==VIDEO_MODE_SECAM)?1:0;
953 dprintk("tuner: mode set to %d\n", *sarg);
955 set_tv_freq(client,t->freq);
967 /* ----------------------------------------------------------------------- */
969 static struct i2c_driver driver = {
970 .name = "i2c TV tuner driver",
971 .id = I2C_DRIVERID_TUNER,
972 .flags = I2C_DF_NOTIFY,
973 .attach_adapter = tuner_probe,
974 .detach_client = tuner_detach,
975 .command = tuner_command,
977 static struct i2c_client client_template =
979 .name = "(tuner unset)",
980 .flags = I2C_CLIENT_ALLOW_USE,
984 static int tuner_init_module(void)
986 i2c_add_driver(&driver);
990 static void tuner_cleanup_module(void)
992 i2c_del_driver(&driver);
995 module_init(tuner_init_module);
996 module_exit(tuner_cleanup_module);
999 * Overrides for Emacs so that we follow Linus's tabbing style.
1000 * ---------------------------------------------------------------------------